tree-sitter / tree-sitter/tree-sitter-cpp
bug: macro causes comments to be swallowed into declarator instead of function_declaration
Nobody has claimed this yet.
- 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
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--;
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided C++ input with tree-sitter-cpp and inspect the nodes around the macro-prefixed constructor, its comments, and the destructor. Trace the grammar entry points for declaration, function_declarator, and function_declaration; done means the comments are no longer contained in the constructor's declaration 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
- 35/100