tree-sitter-cpp
tree-sitter-cpp copied to clipboard
bug: #ifdef causes "else" to be treated as error
Did you check existing issues?
- [X] I have read all the tree-sitter docs if it relates to using the parser
- [X] I have searched the existing issues of tree-sitter-cpp
Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)
Playground (0.23.4?)
Describe the bug
When "interrupting" an if/else with an #ifdef then the else is treated as an error. This might be tricky to turn into a proper tree, as the "ifdef" can separate the "else" branch content from the "if".
Steps To Reproduce/Bad Parse Tree
translation_unit [0, 0] - [6, 0]
preproc_ifdef [0, 0] - [4, 6]
name: identifier [0, 7] - [0, 20]
if_statement [1, 1] - [2, 8]
condition: condition_clause [1, 4] - [1, 9]
value: identifier [1, 5] - [1, 8]
consequence: expression_statement [2, 2] - [2, 8]
call_expression [2, 2] - [2, 7]
function: identifier [2, 2] - [2, 5]
arguments: argument_list [2, 5] - [2, 7]
ERROR [3, 1] - [3, 5]
expression_statement [5, 2] - [5, 8]
call_expression [5, 2] - [5, 7]
function: identifier [5, 2] - [5, 5]
arguments: argument_list [5, 5] - [5, 7]
Expected Behavior/Parse Tree
A solution might be difficult to do with the current structure. Here's a workaround that would preserve the logic and could be supported with the current structure. Maybe it could be treated like that automatically?
#ifdef DO_THIS_CHECK
if (bar)
baz();
else
qux();
#else
qux();
#endif
Repro
#ifdef DO_THIS_CHECK
if (bar)
baz();
else
#endif
qux();