-
Notifications
You must be signed in to change notification settings - Fork 86
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 annotations #40
Comments
I'm not sure. Currently, when we using Just curious - what kind of task are you using |
I haven't fully thought through whether it's possible to handle this as part of the grammar. If you're interested in trying it out, I'd be open to that. I'm just concerned that parsing that kind of preprocessor usage might add a ton of ambiguity to the grammar. |
My goal is to analyze the code itself, for example to compute code metrics (like mccabe) or to have more granularity on what the patches are doing (e.g. touch function foo or just rename function foo to bar, ...), compute a callgraph... |
yeah or just add MOZ_[A-Z_]+ in extras... or if it leads to ambiguities then just update the grammar for them. |
That seems like it would work (and it wouldn't introduce any ambiguities), although you'd have to fork the grammar, because I don't think we should add mozilla-specific stuff to the mainline grammar. Alternatively you could just replace those words with whitespace before passing the file to Tree-sitter. |
Ideally I don't want to fork and I'd prefer to contribute and improve things. |
Yeah we don't have a built-in way right now to handle configuration files at runtime right now, but you could handle it at parser-generation time by checking for some environment variable in the grammar and adding some let customExtras = [];
if (process.env.TREE_SITTER_CPP_CUSTOM_EXTRAS) {
customExtras = process.env.TREE_SITTER_CPP_CUSTOM_EXTRAS.split(' ');
}
// ...
module.exports = grammar({
// ...
extras: $ => [$.comment, /\s/, ...customExtras],
} And then you'd have to regenerate the parser yourself export TREE_SITTER_CPP_CUSTOM_EXTRAS="MOZ_IMPLICIT MOZ_FOO"
tree-sitter generate Not sure how useful that is, but I'd be ok with adding some hook like that to the grammar. |
Could be interesting. |
I also think that it might be simpler to just strip them with |
In firefox code, we use some macros to make annotations (for clang static analysis for example).
For example:
https://searchfox.org/mozilla-central/source/dom/animation/AnimationTarget.h#54
or
https://searchfox.org/mozilla-central/source/mfbt/CheckedInt.h#510
Such annotations lead to parse errors and I understand that (because likely this comment itself is valid C++/C: we just have to define some good macros).
So is it something tree-sitter-c/cpp could handle or should I have my own grammar for this code ?
I'd prefer of course the former.
The text was updated successfully, but these errors were encountered: