bug: size and signedness modifiers can't be mixed with other type specifiers/qualifiers
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-c
Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)
tree-sitter 0.25.2
Describe the bug
These are valid C and C++, but the tree-sitter-c grammar gets ERROR tokens (and fails to pick up the correct declarator identifier):
unsigned const int x;
unsigned const int f() {
return 0;
}
A quick fix for these would be to allow type_qualifiers inside sized_type_specifier, but this actually doesn't capture the full extent of the issue because basically any type qualifier/specifier can be mixed with size and signedness modifiers, e.g. storage_class_specifiers: const int static long inline long volatile f();
So, possibly a better fix is to leave sized_type_specifier alone, but also allow signed/unsigned/long/short as type_qualifiers, somehow with lower precedence than the sized_type_specifier rule. This way, tree-sitter will parse the more common, contiguous sized_type_specifiers the same way as before, but can also handle less-sane interspersing of size & signedness modifiers with other sorts of qualifiers/specifiers.
Steps To Reproduce/Bad Parse Tree
Run tree-sitter-c on unsigned const int x;, see:
translation_unit [0, 0] - [1, 0]
declaration [0, 0] - [0, 21]
type: sized_type_specifier [0, 0] - [0, 8]
unsigned [0, 0] - [0, 8]
type_qualifier [0, 9] - [0, 14]
const [0, 9] - [0, 14]
declarator: identifier [0, 15] - [0, 18]
ERROR [0, 19] - [0, 20]
identifier [0, 19] - [0, 20]
; [0, 20] - [0, 21]
Expected Behavior/Parse Tree
At the very least: there should be no ERROR, and the declaration's declarator should be identifier [0, 19] - [0, 20]
Repro
unsigned const int x;