Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different parsing results for enums #187

Closed
0x28 opened this issue Jan 8, 2023 · 0 comments
Closed

Different parsing results for enums #187

0x28 opened this issue Jan 8, 2023 · 0 comments

Comments

@0x28
Copy link

0x28 commented Jan 8, 2023

Hi,

depending on the location of an enumeration, the resulting AST is different. For example:

enum Type {
    A,
    B,
    C
};

results in the following AST:

translation_unit [0, 0] - [5, 0]
  enum_specifier [0, 0] - [4, 1]
    name: type_identifier [0, 5] - [0, 9]
    body: enumerator_list [0, 10] - [4, 1]
      enumerator [1, 1] - [1, 2]
        name: identifier [1, 1] - [1, 2]
      enumerator [2, 1] - [2, 2]
        name: identifier [2, 1] - [2, 2]
      enumerator [3, 1] - [3, 2]
        name: identifier [3, 1] - [3, 2]

When the same enum is delcared inside a class, the AST is different:

class Test {
  enum Type {
      A,
      B,
      C
  };
};

AST:

translation_unit [0, 0] - [7, 0]
  class_specifier [0, 0] - [6, 1]
    name: type_identifier [0, 6] - [0, 10]
    body: field_declaration_list [0, 11] - [6, 1]
      field_declaration [1, 2] - [5, 4]
        type: enum_specifier [1, 2] - [1, 11]
          name: type_identifier [1, 7] - [1, 11]
        default_value: initializer_list [1, 12] - [5, 3]
          identifier [2, 6] - [2, 7]
          identifier [3, 6] - [3, 7]
          identifier [4, 6] - [4, 7]

The enumerator_list is no longer under the enum_specifier node. Instead it's interpreted as a initializer_list.

Is this the intended parsing result or is this a bug? I used the Tree-sitter playground to generate the AST.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant