Add high-precedence macro token to prevent @for matching in @format!
This commit is contained in:
parent
eeb333acbd
commit
ce7162699f
|
|
@ -211,7 +211,12 @@ module.exports = grammar({
|
||||||
template_expression: ($) =>
|
template_expression: ($) =>
|
||||||
choice($.simple_expression, $.complex_expression, $.safe_expression),
|
choice($.simple_expression, $.complex_expression, $.safe_expression),
|
||||||
|
|
||||||
simple_expression: ($) => seq("@", $.expression_path),
|
// High-precedence token to match @identifier before @for/@if etc keywords
|
||||||
|
simple_expression: ($) =>
|
||||||
|
choice(
|
||||||
|
token(prec(2, /@[a-zA-Z_][a-zA-Z0-9_]*!/)), // Macro calls: @format!
|
||||||
|
seq("@", $.expression_path), // Regular expressions: @foo.bar
|
||||||
|
),
|
||||||
|
|
||||||
complex_expression: ($) => seq("@", "(", $.expression, ")"),
|
complex_expression: ($) => seq("@", "(", $.expression, ")"),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,32 +8,19 @@
|
||||||
(raw_block) @string.special
|
(raw_block) @string.special
|
||||||
|
|
||||||
; Keywords - only in proper syntactic contexts
|
; Keywords - only in proper syntactic contexts
|
||||||
(use_statement "@" @keyword)
|
(use_statement "@use" @keyword)
|
||||||
(use_statement "use" @keyword)
|
(import_statement "@import" @keyword)
|
||||||
(import_statement "@" @keyword)
|
(struct_definition "@struct" @keyword)
|
||||||
(import_statement "import" @keyword)
|
(enum_definition "@enum" @keyword)
|
||||||
(struct_definition "@" @keyword)
|
(function_definition "@fn" @keyword)
|
||||||
(struct_definition "struct" @keyword)
|
(let_statement "@let" @keyword)
|
||||||
(enum_definition "@" @keyword)
|
(if_statement "@if" @keyword)
|
||||||
(enum_definition "enum" @keyword)
|
(for_loop "@for" @keyword)
|
||||||
(function_definition "@" @keyword)
|
(match_statement "@match" @keyword)
|
||||||
(function_definition "fn" @keyword)
|
(break_statement "@break" @keyword)
|
||||||
(let_statement "@" @keyword)
|
(continue_statement "@continue" @keyword)
|
||||||
(let_statement "let" @keyword)
|
(attribute_if_statement "@if" @keyword)
|
||||||
(if_statement "@" @keyword)
|
(attribute_for_loop "@for" @keyword)
|
||||||
(if_statement "if" @keyword)
|
|
||||||
(for_loop "@" @keyword)
|
|
||||||
(for_loop "for" @keyword)
|
|
||||||
(match_statement "@" @keyword)
|
|
||||||
(match_statement "match" @keyword)
|
|
||||||
(break_statement "@" @keyword)
|
|
||||||
(break_statement "break" @keyword)
|
|
||||||
(continue_statement "@" @keyword)
|
|
||||||
(continue_statement "continue" @keyword)
|
|
||||||
(attribute_if_statement "@" @keyword)
|
|
||||||
(attribute_if_statement "if" @keyword)
|
|
||||||
(attribute_for_loop "@" @keyword)
|
|
||||||
(attribute_for_loop "for" @keyword)
|
|
||||||
(else_if_branch "else" @keyword)
|
(else_if_branch "else" @keyword)
|
||||||
(else_if_branch "if" @keyword)
|
(else_if_branch "if" @keyword)
|
||||||
(else_branch "else" @keyword)
|
(else_branch "else" @keyword)
|
||||||
|
|
|
||||||
|
|
@ -1023,6 +1023,20 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"simple_expression": {
|
"simple_expression": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "TOKEN",
|
||||||
|
"content": {
|
||||||
|
"type": "PREC",
|
||||||
|
"value": 2,
|
||||||
|
"content": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "@[a-zA-Z_][a-zA-Z0-9_]*!"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
|
@ -1034,6 +1048,8 @@
|
||||||
"name": "expression_path"
|
"name": "expression_path"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"complex_expression": {
|
"complex_expression": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue