Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ Parser Not Recognizing Comments in Macro Definitions #165

Open
gsxhnd opened this issue Jul 2, 2024 · 0 comments
Open

C++ Parser Not Recognizing Comments in Macro Definitions #165

gsxhnd opened this issue Jul 2, 2024 · 0 comments

Comments

@gsxhnd
Copy link

gsxhnd commented Jul 2, 2024

I am currently using tree-sitter for parsing C++ files, and I have encountered an issue where the parser is not consistently recognizing comments in macro definitions.

Steps to Reproduce:

A C++ file containing the following lines:

#define TEST_1 // comment
#define TEST_2 1 // comment

Here is go test code

func Test_testComment(t *testing.T) {
	var parser = sitter.NewParser()
	parser.SetLanguage(cpp.GetLanguage())
	content := `#define TEST_1 // comment
#define TEST_2 1 // comment`

	tree, _ := parser.ParseCtx(context.Background(), nil, []byte(content))

	iter := sitter.NewIterator(tree.RootNode(), sitter.BFSMode)

	iter.ForEach(func(n *sitter.Node) error {
		if n.Type() == "comment" {
			fmt.Println("StartPoint: ", n.StartPoint())
			fmt.Println("EndPoint:", n.EndPoint())
		}
		return nil
	})
}

Output:

=== RUN   Test_testComment
StartPoint:  {0 15}
EndPoint: {0 25}

Expected Result:

Output two inline comment.

Actual Result:

got one inline comment.

Environment:
os: linux ubuntu 22 and macos
go version: 1.22.4
go-tree-sitter version: v0.0.0-20240625050157-a31a98a7c0f6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant