Skip to content

bug: macro causes comments to be swallowed into declarator instead of function_declaration #317

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

Open
2 tasks done
krystalgamer opened this issue May 14, 2025 · 0 comments
Labels

Comments

@krystalgamer
Copy link

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

Using tree-sitter-cpp to validate all functions in my repository have comments. One of the macros, causes the comments to be swallowed

Steps To Reproduce/Bad Parse Tree

In my script I find all function_declarator and iterate through the prev_sibling collecting all immidiate nodes of type comment. The macro INLINE causes the constructor to be considered declaration and thus it swallowed the comments before the destructor.

declaration b'INLINE CWibbling3DExplosion::CWibbling3DExplosion(\n\t\tconst CVector * a2,\n\t\tchar * a3,\n\t\ti32 a4,\n\t\ti32 a5,\n\t\ ti32 a6,\n\t\ti32 a7,\n\t\ti32 a8,\n\t\ti32 a9,\n\t\ti32 a10,\n\t\ti32 a11,\n\t\ti32 a12)\n\t: C3DExplosion(a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)\n{\n\tgWibblingExpCount++;\n}\n\n// @Ok\n// @Matching'

Expected Behavior/Parse Tree

Comments not be inside the declaration node.

Repro

// @Ok
// @Matching
INLINE CWibbling3DExplosion::CWibbling3DExplosion(
		const CVector * a2,
		char * a3,
		i32 a4,
		i32 a5,
		i32 a6,
		i32 a7,
		i32 a8,
		i32 a9,
		i32 a10,
		i32 a11,
		i32 a12)
	: C3DExplosion(a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
{
	gWibblingExpCount++;
}

// @Ok
// @Matching
CWibbling3DExplosion::~CWibbling3DExplosion(void)
{
	gWibblingExpCount--;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant