Open stadelmanma opened 6 years ago
One thing to keep in mind for testing is how preprocessor directives in terrible locations are handled such as tweaking the call signature of a subroutine. I belive this is supported in the C grammar but I'm not sure if that method will work for me.
I'm using your excelent plugin. It works perfect except for the highlight of preprocessor. Are you considering just support preprocessor highlights? I think it's easier, maybe.
tree-sitter-cpp does something clever where it imports the C grammar: https://github.com/tree-sitter/tree-sitter-cpp/blob/56cec4c2eb5d6af3d2942e69e35db15ae2433740/grammar.js#L1
const C = require("tree-sitter-c/grammar")
I tried to do this and then we could just use their rules directly, but I couldn't find any documentation on how to automatically bring in this dependency. npm install tree-sitter-c
gives me some errors, so I couldn't even try it manually.
Probably our best bet is to just copy-paste all the preprocessor rules into the Fortran grammar
I agree copying out the rules would probably be the best place to start, pulling in the whole C grammar might be overkill and could have unintended side-effects.
What is going on with this? I would highly value this feature as I am working on a project that is littered with directives.
I am also willing to implement this feature myself. But i would probably need some guidance...
What do you think?
It's been awhile since I looked at this, but I think it's is going to be quite tricky. If you look at how the C grammar implements preprocessor directives, they can appear anywhere and have anything as child nodes. For C this isn't much of a problem because there's not many top-level nodes, but with Fortran there's lots of potential kinds of child nodes.
I'd probably start with some of the standalone directives like #define
, #line
. Actually, it would be especially useful to have the directives that come from preprocessed source: # <line number> <filename>
. This would allow running the preprocessor and then parsing the result at least.
@ZedThree yeah it’s a tricky problem since you can do literally anything with preprocessor directives.
Alright, thanks for your responses.
I think i will fork it, create a PR and start working on the easy directives like #if
etc. first. Then we will see where this is going.
Given that fortran and C both use the same preprocessor I can probably copy these over directly without too many changes.