bug: Parses `[[deprecated]]` on enumerator incorrectly

Open
#314 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp
Domain
compilers

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.

Description

bug
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,
};
Dominant language
JavaScript
Stars
453
Forks
185
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tree-sitter/tree-sitter-cpp

All issues in tree-sitter/tree-sitter-cpp

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.