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

Error when initializing an `auto const&` via parenthesis with a singleton getter

Open
#230 1 comment 0 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

Example code:

void f() {
	auto const& ref(Namespace::Class::instance().getter());

	char const *sql = R""(
select JOHN
from DOE
)"";
}

Produces AST with an error that messes up syntax highlighting (see getter() not highlighted and weird highlighting attempts on words inside of a raw string):
image

According to Tree-sitter playground produces AST with an error, but is able to recognize the raw string correctly:

[translation_unit](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [8, 0]
  [function_definition](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [7, 1]
    type: [primitive_type](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [0, 4]
    declarator: [function_declarator](https://tree-sitter.github.io/tree-sitter/playground#) [0, 5] - [0, 8]
      declarator: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 5] - [0, 6]
      parameters: [parameter_list](https://tree-sitter.github.io/tree-sitter/playground#) [0, 6] - [0, 8]
    body: [compound_statement](https://tree-sitter.github.io/tree-sitter/playground#) [0, 9] - [7, 1]
      [declaration](https://tree-sitter.github.io/tree-sitter/playground#) [1, 1] - [1, 56]
        type: [placeholder_type_specifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 1] - [1, 5]
          [auto](https://tree-sitter.github.io/tree-sitter/playground#) [1, 1] - [1, 5]
        [type_qualifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 6] - [1, 11]
        declarator: [reference_declarator](https://tree-sitter.github.io/tree-sitter/playground#) [1, 11] - [1, 55]
          [function_declarator](https://tree-sitter.github.io/tree-sitter/playground#) [1, 13] - [1, 55]
            declarator: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 13] - [1, 16]
            parameters: [parameter_list](https://tree-sitter.github.io/tree-sitter/playground#) [1, 16] - [1, 55]
              [parameter_declaration](https://tree-sitter.github.io/tree-sitter/playground#) [1, 17] - [1, 54]
                type: [qualified_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 17] - [1, 43]
                  scope: [namespace_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 17] - [1, 26]
                  name: [qualified_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 28] - [1, 43]
                    scope: [namespace_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 28] - [1, 33]
                    name: [type_identifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 35] - [1, 43]
                [ERROR](https://tree-sitter.github.io/tree-sitter/playground#) [1, 43] - [1, 46]
                  [parameter_list](https://tree-sitter.github.io/tree-sitter/playground#) [1, 43] - [1, 45]
                declarator: [function_declarator](https://tree-sitter.github.io/tree-sitter/playground#) [1, 46] - [1, 54]
                  declarator: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [1, 46] - [1, 52]
                  parameters: [parameter_list](https://tree-sitter.github.io/tree-sitter/playground#) [1, 52] - [1, 54]
      [declaration](https://tree-sitter.github.io/tree-sitter/playground#) [3, 1] - [6, 4]
        type: [primitive_type](https://tree-sitter.github.io/tree-sitter/playground#) [3, 1] - [3, 5]
        [type_qualifier](https://tree-sitter.github.io/tree-sitter/playground#) [3, 6] - [3, 11]
        declarator: [init_declarator](https://tree-sitter.github.io/tree-sitter/playground#) [3, 12] - [6, 3]
          declarator: [pointer_declarator](https://tree-sitter.github.io/tree-sitter/playground#) [3, 12] - [3, 16]
            declarator: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [3, 13] - [3, 16]
          value: [raw_string_literal](https://tree-sitter.github.io/tree-sitter/playground#) [3, 19] - [6, 3]

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

Reproduce the C++ snippet in the Tree-sitter playground and inspect the AST around the auto const& declaration and the following raw string literal. Start with the C++ grammar entry points for declarations and declarators. Done means the getter call parses without an ERROR node and the raw string remains correctly recognized for syntax highlighting.

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.