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

Class Specifier Does Not Include Semicolon

Open
#150 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The following is the code I'm using:

class Dummy {​​​​​​​​​​
public:
  int foo();
  int bar(int val);
}​​​​​​​​​​​;

class DummyTwo;
translation_unit [0, 0] - [7, 0]
  class_specifier [0, 0] - [4, 1]
    name: type_identifier [0, 6] - [0, 11]
    body: field_declaration_list [0, 12] - [4, 1]
      access_specifier [1, 0] - [1, 7]
      field_declaration [2, 2] - [2, 12]
        type: primitive_type [2, 2] - [2, 5]
        declarator: function_declarator [2, 6] - [2, 11]
          declarator: field_identifier [2, 6] - [2, 9]
          parameters: parameter_list [2, 9] - [2, 11]
      field_declaration [3, 2] - [3, 19]
        type: primitive_type [3, 2] - [3, 5]
        declarator: function_declarator [3, 6] - [3, 18]
          declarator: field_identifier [3, 6] - [3, 9]
          parameters: parameter_list [3, 9] - [3, 18]
            parameter_declaration [3, 10] - [3, 17]
              type: primitive_type [3, 10] - [3, 13]
              declarator: identifier [3, 14] - [3, 17]
  class_specifier [6, 0] - [6, 14]
    name: type_identifier [6, 6] - [6, 14]

Notice that neither class specifier includes the semicolon. The semicolon is instead a sibling of the class_specifier subtree. This is due to the usage of empty_declaration in _top_level_item.

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

The issue points to _top_level_item and empty_declaration; start by reproducing the provided C++ snippet and inspecting that grammar path. Done means the class_specifier nodes for both definitions include the terminating semicolon rather than leaving it as a sibling, with the resulting parser output matching that expectation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.