-
-
Notifications
You must be signed in to change notification settings - Fork 169
Open
Labels
Description
Did you check existing issues?
- I have read all the tree-sitter docs if it relates to using the parser
- I have searched the existing issues of tree-sitter-c
Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)
No response
Describe the bug
The following code snippet produces a parse tree that seems to suggest the if is inside the preproc_if:
#if 0
if (false) {
#endif
}Steps To Reproduce/Bad Parse Tree
Produces the following tree (copied from Playground):
translation_unit [0, 0] - [4, 0]
preproc_if [0, 0] - [3, 1]
condition: number_literal [0, 4] - [0, 5]
if_statement [1, 0] - [3, 1]
condition: parenthesized_expression [1, 3] - [1, 10]
false [1, 4] - [1, 9]
consequence: compound_statement [1, 11] - [3, 1]
preproc_call [2, 0] - [3, 0]
directive: preproc_directive [2, 0] - [2, 6]
MISSING "#endif" [3, 1] - [3, 1]
Expected Behavior/Parse Tree
However, I would expect the macro to take the highest precedence. Meaning the parse tree I would expect would include everything inside the #if 0 / #endif and then have a single dangling } brace as an error at the end.
Example parse tree:
translation_unit [0, 0] - [4, 0]
ERROR [0, 0] - [3, 0]
number_literal [0, 4] - [0, 5]
parenthesized_expression [1, 3] - [1, 10]
false [1, 4] - [1, 9]
preproc_call [2, 0] - [3, 0]
directive: preproc_directive [2, 0] - [2, 6]
ERROR [3, 0] - [3, 1]