joelspadin / tree-sitter-devicetree

Tree-sitter grammar for Devicetree files
MIT License
28 stars 6 forks source link

Support `#include` directives in nodes #8

Closed mskelton closed 12 months ago

mskelton commented 1 year ago

I'm using this for a Kinesis advantage 360 keyboard which uses ZMK. It is possible to use #include directives inside of nodes so that you can write code like this:

/ {
  behaviors {
    #include "macros.dtsi"
  };
  keymap {
    ...
  }
}
mskelton commented 1 year ago

@joelspadin Anything that needs additional updates in this PR or can it be merged?

joelspadin commented 1 year ago

Sorry, I was busy with other things and forgot about this. Is there a reason you chose to only allow #include? Other preprocessor commands like #define, #if, etc. can be used anywhere in a file as well.

mskelton commented 1 year ago

Sorry, I was busy with other things and forgot about this. Is there a reason you chose to only allow #include? Other preprocessor commands like #define, #if, etc. can be used anywhere in a file as well.

No specific reason other than I'm not super familiar with the language spec. Added the other preproc nodes.

mskelton commented 1 year ago

@joelspadin any chance we can get this PR merged? I think I addressed all of the feedback at this point

joelspadin commented 1 year ago

I don't think the previous conversation on grammar.js has been resolved? It's fine if a preprocessor command doesn't parse unless there's whitespace after the first token, but including the whitespace in the token itself isn't ideal. For example, if code using this parser were to change the background color of #if tokens, then I expect it would extend to the first whitespace character after the #if as well.

mskelton commented 12 months ago

@joelspadin I was able to figure it out finally and re-opened this pull request as I had some of my branches messed up https://github.com/joelspadin/tree-sitter-devicetree/pull/11