Skip to content

bug: Parses [[deprecated]] on enumerator incorrectly #314

@arijun

Description

@arijun

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,
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions