tree-sitter / tree-sitter/tree-sitter-cpp
bug: Parses `[[deprecated]]` on enumerator incorrectly
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)
tree-sitter 0.25.3
Describe the bug
tree-sitter doesn't seem to know what to do with [[deprecated]] on an enumerator (enumeration value), and it breaks the parser out of enum_specifier
Steps To Reproduce/Bad Parse Tree
(translation_unit [0, 0] - [6, 0]
(declaration [0, 0] - [5, 2]
type: (enum_specifier [0, 0] - [3, 6]
name: (type_identifier [0, 11] - [0, 18])
body: (enumerator_list [0, 19] - [3, 6]
(enumerator [1, 2] - [1, 9]
name: (identifier [1, 2] - [1, 5])
value: (number_literal [1, 8] - [1, 9]))
(enumerator [2, 2] - [2, 9]
name: (identifier [2, 2] - [2, 5])
value: (number_literal [2, 8] - [2, 9]))
(enumerator [3, 2] - [3, 6]
name: (identifier [3, 2] - [3, 6]))))
(attribute_declaration [3, 7] - [3, 21]
(attribute [3, 9] - [3, 19]
name: (identifier [3, 9] - [3, 19])))
declarator: (init_declarator [3, 21] - [3, 25]
declarator: (identifier [3, 21] - [3, 21])
value: (number_literal [3, 24] - [3, 25]))
declarator: (init_declarator [4, 2] - [4, 10]
declarator: (identifier [4, 2] - [4, 6])
value: (number_literal [4, 9] - [4, 10]))
(ERROR [4, 10] - [5, 1])))
Obviously ERRORs on valid c++(17) code are a problem, but also notice that the attribute_declaration is not a part of the enum
Expected Behavior/Parse Tree
I will try to make a valid valid parse tree, but please don't hold me to it:
(translation_unit [0, 0] - [6, 0]
(enum_specifier [0, 0] - [5, 1]
name: (type_identifier [0, 11] - [0, 18])
body: (enumerator_list [0, 19] - [5, 1]
(enumerator [1, 2] - [1, 9]
name: (identifier [1, 2] - [1, 5])
value: (number_literal [1, 8] - [1, 9]))
(enumerator [2, 2] - [2, 9]
name: (identifier [2, 2] - [2, 5])
value: (number_literal [2, 8] - [2, 9]))
(enumerator [3, 2] - [3, 10]
name: (identifier [3, 2] - [3, 6])
(attribute_declaration [3, 6] - [3, 20]
(attribute [3, 8] - [3, 18]
name: (identifier [3, 8] - [3, 18])))
value: (number_literal [3, 9] - [3, 10]))
(enumerator [4, 2] - [4, 10]
name: (identifier [4, 2] - [4, 6])
value: (number_literal [4, 9] - [4, 10])))))
Repro
enum class Numbers {
One = 1,
Two = 2,
Tres [[deprecated]] = 3,
Four = 4,
};
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 by running the supplied C++17 reproduction with tree-sitter 0.25.3 and compare its parse tree with the expected tree. Trace the grammar entry points for enum_specifier, enumerator_list, and attribute_declaration, then add coverage for the shown enum. Done means the attribute belongs to Tres and the valid input produces no ERROR node.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100