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

bug: Parsing fails when identifiers are split across lines

Open
#290 0 comments 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)

No response

Describe the bug

When splitting identifiers across multiple lines tree-sitter fails to parse them, see the example code below. (As far as I know this is technically valid C++~)

Steps To Reproduce/Bad Parse Tree
  1. Go to https://tree-sitter.github.io/tree-sitter/playground
  2. Pase the sample code
  3. Observe the "ERROR" node in the declaration [1, 0] - [9, 2]
    image
Expected Behavior/Parse Tree

As far as I know this is valid C++ code and all three major compilers compile it without any warning, I would have expected tree-sitter being able to parse it.

Repro
// https://godbolt.org/z/z5Mjjhnq1

extern "C" {
static 
i\
n\
t 
FOO\
Ba\
r
=
3;

int qux();
int qux() {
    return FOOBar;
}
}

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 with the reproduced C++ example in the tree-sitter playground and compare its parse tree with the behavior of the compilers linked in the issue. Trace how the tree-sitter-cpp grammar handles identifiers split across escaped lines; done means the sample parses without an 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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.