-
Notifications
You must be signed in to change notification settings - Fork 91
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
Macro prevents correct parsing of class #85
Comments
Simillar behavior can be caused by the following code: class EXPORT_API MyClass
{
MyClass();
}; Where |
I'll add something as well: #include "doctest/doctest.h"
TEST_CASE_TEMPLATE("Some Test", T, float, double)
{
} Generates this: translation_unit [0, 0] - [5, 0]
preproc_include [0, 0] - [1, 0]
path: string_literal [0, 9] - [0, 28]
ERROR [2, 0] - [4, 1]
identifier [2, 0] - [2, 18]
string_literal [2, 19] - [2, 30]
identifier [2, 32] - [2, 33]
ERROR [2, 35] - [2, 49]
primitive_type [2, 35] - [2, 40]
primitive_type [2, 42] - [2, 48]
initializer_list [3, 0] - [4, 1] I'm not sure if that is in any way detectable. But I wanted to report it, as it breaks my syntax highlighting in some cases. |
I understand thst its impossible to detect macros in such a grammar since it's not hooked into the preprocessor. Would there be any way to let the end user manually define a list of strings that are always macros? My company only uses a handful, so it would be easy to define, and it would be great to have them not break the rest of the file. |
@maxbrunsfeld would be nice indeed for C/C++ to provide a way to customize the parser to accept those macros. |
Would it be possible to do this with an injection? |
Hey, is there any update? This behavior is really annoying, I work in repos where a namespace macro is common, thus breaking all the highlighting there is. It would already be nice if we could ignore those macros somehow. Is there any solution? |
@deeedob The best solution I found was to fork the project and add support for some hard-coded macros. Hopefully something better will come like #85 (comment) |
Well, i ditched tree-sitter-based features for the most part and use LSP semantic tokens instead. It's probably slower, but also nicer. You can have different Highlight groups for local variables vs. global variables vs. fields and such. All i had to do to make it work is use a color scheme with semantic token support. I still have tree-sitter around for some other plugins, like |
@ImmanuelHaffner What LSP do you use? I haven't found a good one for c++ |
@maxbrunsfeld @amaanq do you have any idea why the error recovery mechanism of tree-sitter does not skip those macros and at least parse correctly the rest of the code? I don't mind having the macro itself not parsed, but I mind if the presence of a macro makes almost the whole file to fail to parse. |
For example on this simple example:
tree-sitter-cpp is not able to parse anything. It does not recover from the error. |
Weirdly, when I try it on the playground https://tree-sitter.github.io/tree-sitter/playground with this example, it actually recovers well from the error: @amaanq which version of tree-sitter-cpp is running in the playground? The latest? |
hmm, after a few tests the issue for my example seems to be in ocaml-tree-sitter-semgrep, not tree-sitter itself. tree-sitter-c and tree-sitter-cpp with tree-sitter generate and tree-sitter parse seems to recover correctly from such macros. semgrep itself does not apparently. |
@MarcelRobitaille simply clangd, with |
this is quite the pain for c++ when you have export macros in front of class declarations:
For me this ends up being interpreted as a function instead of a class by treesitter. This of course messes with treesitter based text objects. |
An imported marco (I simplified the source file), prevented the correct parsing of the following class.
I know that in the presence of macro a parser almost has no chance to understand C++, but I hope that this failure case may be useful for improving the parser.
The text was updated successfully, but these errors were encountered: