-
I'm trying to improve the Robot tree-sitter grammar by adding support for parsing the built-in conditional keywords. Basically I'm trying to parse this: Example
IF ${rc} > 0
Some keyword
Another keyword
END This is my attempt at matching the conditional statement: conditional_statement: $ => seq(
"IF",
$._separator,
$.argument,
$._line_break,
repeat1(choice($.statement, $._empty_line)),
"END",
), (For context, here is the full grammar) The issue is, This means that with the above code, the The "exclude" rule would have been perfect in this situation, since I could just exclude built-in keywords like "IF" and "END" from being valid keyword names, but that PR was abandoned 😞 I have peppered my code with every combination of Is there any way I can get Tree-sitter to prioritize matching something after the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
tree-sitter will prioritize matching literals over a regex that could match END, however, if "END" is a valid choice in statement then that can be matched too |
Beta Was this translation helpful? Give feedback.
-
Dang, turns out I just banged my head against this problem for too long. After a good night's sleep, it seemed obvious immediately. This grammar matches leading indentation as a token, and I forgot to match one before the |
Beta Was this translation helpful? Give feedback.
Dang, turns out I just banged my head against this problem for too long. After a good night's sleep, it seemed obvious immediately. This grammar matches leading indentation as a token, and I forgot to match one before the
"END"
rule. Replacing"END"
withseq($._indentation, "END")
fixes the problem.