tree-sitter / tree-sitter-c

C grammar for tree-sitter
MIT License
225 stars 100 forks source link

bug: Incorrectly handling declarations in expressions #218

Closed ashamedbit closed 1 week ago

ashamedbit commented 4 weeks ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

0.22.3

Describe the bug

Treesitter incorrectly parses this expression, although it is valid legal code. char* x =({char* y = malloc(10); strcpy(y,"aaaaa");}); It follows the coding construct described here: https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html

Steps To Reproduce/Bad Parse Tree

The code that treesitter cant parse correctly:

int main(){
char* x =({char* y = malloc(10); strcpy(y,"aaaaa");});
return 0;
}

Expected Behavior/Parse Tree

The ({ characters should be in a new node and following compund statements as children of that node

Repro

int main(){
char* x =({char* y = malloc(10); strcpy(y,"aaaaa");});
return 0;
}