-
-
Notifications
You must be signed in to change notification settings - Fork 123
Open
Labels
Description
Did you check existing issues?
- I have read all the tree-sitter docs if it relates to using the parser
- I have searched the existing issues of tree-sitter-cpp
Tree-Sitter CLI Version, if relevant (output of tree-sitter --version
)
tree-sitter 0.25.3
Describe the bug
In this grammar, typedef
s are considered specific standalone statements, requiring the statement to start with typedef
, but in the official C++ grammar, typedef
is just one of many possible decl-specifier
s.
This means that while e.g. typedef int x, y;
is parsed correctly, int typedef x, y;
is not, despite both compiling to the same effect in gcc
and clang
.
This is actually used in the wild, but it seems very rare. Nonetheless, I thought I'd report it in case someone's willing to bother themselves with strange and unknown C++ quirks :)
Steps To Reproduce/Bad Parse Tree
Output for int typedef x, y;
:
(translation_unit [0, 0] - [1, 0]
(declaration [0, 0] - [0, 17]
type: (primitive_type [0, 0] - [0, 3])
declarator: (identifier [0, 4] - [0, 11])
(ERROR [0, 12] - [0, 13]
(identifier [0, 12] - [0, 13]))
declarator: (identifier [0, 15] - [0, 16])))
Expected Behavior/Parse Tree
The expected parse tree is the same as with typedef
at the start, only with different locations:
(translation_unit
(type_definition
type: (primitive_type)
declarator: (type_identifier)
declarator: (type_identifier)))