tree-sitter / tree-sitter/tree-sitter-cpp
bug: not parsing well pointer to an array
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 453
- Forks
- 185
- PR merge metrics
- No merged PRs in 30d
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)
No response
Describe the bug
tree-sitter-cpp doesn't parse well pointer to array (Repro and the resulting Bad Parse Tree).
Worth to mention that parsing it as part of multi declaration statement is actually done right:
int (*x)[] = 0, y = 1;
Will be parsed to:
declaration [0, 0] - [0, 22]
type: primitive_type [0, 0] - [0, 3]
declarator: init_declarator [0, 4] - [0, 14]
declarator: array_declarator [0, 4] - [0, 10]
declarator: parenthesized_declarator [0, 4] - [0, 8]
pointer_declarator [0, 5] - [0, 7]
declarator: identifier [0, 6] - [0, 7]
value: number_literal [0, 13] - [0, 14]
declarator: init_declarator [0, 16] - [0, 21]
declarator: identifier [0, 16] - [0, 17]
value: number_literal [0, 20] - [0, 21]
Steps To Reproduce/Bad Parse Tree
expression_statement [1, 0] - [1, 11]
subscript_expression [1, 0] - [1, 10]
argument: call_expression [1, 0] - [1, 8]
function: primitive_type [1, 0] - [1, 3]
arguments: argument_list [1, 4] - [1, 8]
pointer_expression [1, 5] - [1, 7]
argument: identifier [1, 6] - [1, 7]
indices: subscript_argument_list [1, 8] - [1, 10]
Expected Behavior/Parse Tree
declaration [0, 0] - [0, 27]
type: primitive_type [0, 0] - [0, 3]
declarator: init_declarator [0, 4] - [0, 14]
declarator: array_declarator [0, 4] - [0, 10]
declarator: parenthesized_declarator [0, 4] - [0, 8]
pointer_declarator [0, 5] - [0, 7]
declarator: identifier [0, 6] - [0, 7]
value: number_literal [0, 13] - [0, 14]
Repro
int (*x)[];
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported Repro, int (*x)[];, and compare its current parse tree with the expected declaration tree. Trace the C++ grammar rules involved in pointer and array declarators, then confirm that this input produces the expected tree without regressing the multi-declaration example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100