Skip to content

bug: not parsing well pointer to an array #288

Open

Description

@uriyay-jfrog

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)[];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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