tree-sitter / tree-sitter-c

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

Adding support for alignas type qualifier #207

Closed touzeauv closed 3 months ago

touzeauv commented 4 months ago

This commit adds support for alignas type qualifier, as asked in issue #206.

I do not fully understand the current state of the tree-sitter-c grammar, I might have done some mistake. In particular, please double check the following point:

The commit includes a small modification of the test corpus to avoid future regressions.

PS: Thanks for your work maintaining tree-sitter

amaanq commented 4 months ago

Ah interesting - I added support for this in CPP, but I think your change makes sense to have in C and have C++ inherit it. There's one lingering question though, should the second choice be type_descriptor, or would _type_specifier suffice? If there can be qualifiers in the type inside the alignas type qualifier then this is good, but just want to double check

touzeauv commented 4 months ago

I think type_descriptor is required for the second choice. cppreference the argument of alignas is a type-id, which might include qualifiers I believe. Testing gcc and clang, both accept things such as alignas(volatile const int) char c;

Regarding C++, it seems the language only allows alignas, but not _Alignas. clang++ is permissive and will parse it without complaining, but g++ complains that _Alignas is not declared.

amaanq commented 3 months ago

thank you very much for the contribution, and sorry for the delay in getting this in. i just rebased for you & i'll merge afterwards