tree-sitter-cpp icon indicating copy to clipboard operation
tree-sitter-cpp copied to clipboard

bug: Macro prefix to local variable creation leads to "missing semicolon"

Open BrickBee opened this issue 1 year ago • 0 comments

Did you check existing issues?

  • [X] I have read all the tree-sitter docs if it relates to using the parser
  • [X] I have searched the existing issues of tree-sitter-cpp

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

Playground (0.23.4?)

Describe the bug

Using the macro SET_ALIGN(16) as prefix instead of the direct struct alignas(16) leads to a "missing semicolon" error.

Steps To Reproduce/Bad Parse Tree

translation_unit [0, 0] - [1, 0]
  expression_statement [0, 0] - [0, 13]
    call_expression [0, 0] - [0, 13]
      function: identifier [0, 0] - [0, 9]
      arguments: argument_list [0, 9] - [0, 13]
        number_literal [0, 10] - [0, 12]
    MISSING ; [0, 13] - [0, 13]
  declaration [0, 14] - [0, 27]
    type: type_identifier [0, 14] - [0, 17]
    declarator: init_declarator [0, 18] - [0, 26]
      declarator: identifier [0, 18] - [0, 21]
      value: initializer_list [0, 24] - [0, 26]

Expected Behavior/Parse Tree

This might be difficult to handle, as the macro could be a regular function call that just happened to have no newline after it and is indeed missing a semicolon. A heuristic based on the missing line-break would work but be rather hacky. The parser recovers from this though.

Repro

SET_ALIGN(16) Foo bar = {};

BrickBee avatar Dec 10 '24 12:12 BrickBee