tree-sitter / tree-sitter/tree-sitter-cpp

bug: Parse error with function annotations

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

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
453
Forks
185
PR merge metrics
No merged PRs in 30d

Description

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 (2a835ee029dca1c325e6f1c01dbce40396f6123e)

Describe the bug

When parsing code that uses function annotations, the parse tree incorrectly reports an ERROR node.
For example, given the following snippet that contains a function annotated with EXPORT:

#define EXPORT __attribute__((visibility("default")))

EXPORT
void foo() {}

The following error appears in the parse tree: (ERROR [3, 0] - [3, 4].

Steps To Reproduce/Bad Parse Tree
  1. Write the code above in a C++ file.
  2. Run tree-sitter parse on the file.
  3. Observe the obtained parse tree:
(translation_unit [0, 0] - [4, 0]
  (preproc_def [0, 0] - [1, 0]
    name: (identifier [0, 8] - [0, 14])
    value: (preproc_arg [0, 15] - [0, 53]))
  (function_definition [2, 0] - [3, 13]
    type: (type_identifier [2, 0] - [2, 6])
    (ERROR [3, 0] - [3, 4]
      (identifier [3, 0] - [3, 4]))
    declarator: (function_declarator [3, 5] - [3, 10]
      declarator: (identifier [3, 5] - [3, 8])
      parameters: (parameter_list [3, 8] - [3, 10]))
    body: (compound_statement [3, 11] - [3, 13])))
Expected Behavior/Parse Tree

The parse tree should not have errors.

Repro
#define EXPORT __attribute__((visibility("default")))

EXPORT
void foo() {}

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.

Research direction

Start by running the provided C++ snippet with tree-sitter 0.25.3 and inspecting the parse output from tree-sitter parse. Trace the grammar path for the function definition and its annotation, then verify that the resulting tree no longer contains the reported ERROR node.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.