Closed mskelton closed 9 months ago
The Zephyr docs don't specify because it's not actually devicetree. It's just the C preprocessor, so if we add any of them, we should add all of
#if
#ifdef
#ifndef
#elif
#else
#endif
@joelspadin I updated the PR to use the full preprocessor conditional grammar from tree-sitter-c along with more tests.
How are the *_in_node
versions used?
@nickcoutsos Because the list of possible members is different for top level items and nodes, the preprocessor rules need to be separate to account for that difference. The _in_node
stuff is aliases so it produces the same resulting types.
Hope that makes sense.
Because the list of possible members is different for top level items and nodes
Maybe I'm misunderstanding what you mean, but the C preprocessor doesn't know or care whether preprocessor commands are at the top level or inside a node. I would expect all the preprocessor commands to work everywhere. (They could even appear inside of a multi-line parameter, but I don't think it's worth the effort to support that.)
Okay, the distinction I think I'm seeing is that preproc statements appearing at the top level can wrap other _top_level_item
elements whereas the in-node variety is expected to contain other elements of _node_members
.
Does this need to account for preprocessor statements "interrupting" devicetree grammar? Or is that a question to be answered down the road?
@joelspadin Any additional thoughts on this PR? @nickcoutsos is correct about the reason for the top level and node level preprocessor nodes due to the possible children for top level and nodes being different.
Okay, that does make sense. I think I was originally thinking about this as each #if
line being its own isolated thing rather than a scope inside which other things would fit. I'll try to find some time to review this later.
Sorry for the long wait on this. This all looks good to me. Thanks!
Adds support for preprocessor conditionals
#ifdef
and#ifndef
. Borrowed the grammar structure from tree-sitter-c.One question I have is which preprocessor conditionals are supported by the grammar spec. I don't know where specifically you look for the official spec, I tried looking at the Zephyr docs but didn't find anything super specific. Basically do we need to support
#else
,#elif
, etc.?