tree-sitter / tree-sitter/tree-sitter-cpp
feature: Alternative handling of trailing backslashes in macro definitions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 453
- Forks
- 185
- PR merge metrics
- No merged PRs in 30d
Description
Did you check the tree-sitter docs?
- I have read all the tree-sitter docs if it relates to using the parser
Is your feature request related to a problem? Please describe.
Currently, when defining a macro with a trailing backslash \ at the end of the last line, the parse tree extends the preproc_arg end position to the next line.
For example, given:
#define ADD(x, y) \
((x) + (y)) \
The parse tree is:
translation_unit [0, 0] - [2, 0]
preproc_function_def [0, 0] - [2, 0]
#define [0, 0] - [0, 7]
name: identifier [0, 8] - [0, 11]
parameters: preproc_params [0, 11] - [0, 17]
( [0, 11] - [0, 12]
identifier [0, 12] - [0, 13]
, [0, 13] - [0, 14]
identifier [0, 15] - [0, 16]
) [0, 16] - [0, 17]
value: preproc_arg [1, 4] - [2, 0] // Ends at position [2, 0]
Describe the solution you'd like
I was instead wondering if it would be possible to ensure that, in the parse tree, even with a \ at the end of the last line of the macro, the final position of the preproc_arg node matches the following case:
#define ADD(x, y) \
((x) + (y))
Where the resulting parse tree is:
translation_unit [0, 0] - [2, 0]
preproc_function_def [0, 0] - [2, 0]
#define [0, 0] - [0, 7]
name: identifier [0, 8] - [0, 11]
parameters: preproc_params [0, 11] - [0, 17]
( [0, 11] - [0, 12]
identifier [0, 12] - [0, 13]
, [0, 13] - [0, 14]
identifier [0, 15] - [0, 16]
) [0, 16] - [0, 17]
value: preproc_arg [1, 4] - [1, 16] // Ends at position [1, 16]
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
The issue names no source file or test. Start with the two C++ macro examples and compare their parse-tree endpoints, then read the linked tree-sitter parser documentation and trace how the preproc_arg node is produced. Done means the trailing-backslash case ends at [1, 16], matching the no-trailing-backslash example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100