tree-sitter / tree-sitter-c

C grammar for tree-sitter
MIT License
237 stars 106 forks source link

fix: rework translation-unit top-level items to disallow binary expressions #146

Closed amaanq closed 1 year ago

amaanq commented 1 year ago

Closes #48

I don't like how this looks with the nearly repeated rule, but it's the best option I could think of that didn't impact state count too much, maybe some JS-magic could make it look prettier with manipulating top_level_item

@XVilka if you have some more test cases I could add them

cc @ahlinc

XVilka commented 1 year ago

@amaanq no additional testcases, sorry, but this one should be sufficient.

XVilka commented 1 year ago

@amaanq actually, I might have one - char (*ptr_to_array)[];

amaanq commented 1 year ago

That one seems to work on master, but good to add

amaanq commented 1 year ago

reworked

XVilka commented 1 year ago

@amaanq as you rework top level statement, I wonder if it makes sense to also target this case: https://github.com/tree-sitter/tree-sitter-c/issues/129

amaanq commented 1 year ago

I'm not sure about that one, I think it is correct to associate the pointer declarator with a function name/identifier

amaanq commented 1 year ago

I reworked it anyways just for top level functions..if that proves to be incorrect/disputed I will revert @XVilka

amaanq commented 1 year ago

Actually, that breaks error recovery a bit in upstream tests and still doesn't fit fully right w/ me, so I reverted it, sorry. That needs a better solution than what I had