Closed Raghava-Ch closed 7 months ago
custom macros won't generally have great parsing output since tree-sitter isn't context aware, sorry.
Hi amaanq, Sorry for writing again. I actually observed this pattern of function definitions in most embedded systems code bases. Companies usually prepend module name for function definitions. Ex:
#define MODULE_NAME
#define LOCAL static
MODULE_NAME LOCAL int foo() {
}
I understand tree-sitter don’t know the context, but expected at-least to parse without errors.
the workaround I provided at-least parse without errors and it didn’t break any existing test cases.
I kindly request again to reconsider.
We can't cherry pick conventions used in specific sectors - that'll just open the gates for anyone in any environment/sector to pitch for their own popular macros that are used. If I were you, and I've done this before for specific C parsing needs, like with IDA Pro's decompiler output of C code, I would fork this, edit in the qualifiers/modifiers you need, and use that.
Did you check existing issues?
Tree-Sitter CLI Version, if relevant (output of
tree-sitter --version
)No response
Describe the bug
While parsing the function with STATIC, INLINE, BOOL, MODULE_NAME, which are defined showing semicolon missing error example is given below.
However I have done some work around which can be used until this issue is fixed.
Function definition grammar
Conflicts entries:
Steps To Reproduce/Bad Parse Tree
Just paste the given code in the tree-sitter playground, And observe the AST for the parse error.
Expected Behavior/Parse Tree
Expected to parse the code without errors, like below example.
Repro