-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conditional directives can break parsing #6
Comments
That will only allow arbitrary placement of the conditionals, though. It won't fix the fact that the resulting AST still looks broken. Mhmm. |
I had a look at how this is tackled by the pros in the C grammar provided by the tree-sitter org, but it looks like preprocessor macros as general as the ones supported by C or Zeek might just be nasty and hard to deal with; I filed tree-sitter/tree-sitter-c#108 to gather some feedback. As far as zeek-format is concerned I do not see incorrect formatting for above snippet; in fact, nothing is formatted which I think is acceptable. Could we just fix the test you mentioned (CI is still ✅?) as things are "working"? |
Yeah I saw that that ticket too :-) ... and agree re. the testing — we can update it so it covers this error as expected. I wonder if we could extend the grammar somewhat so it covers "reasonable" uses of conditionals (like in the above — a |
Two more thoughts: We could offer two parsers — one for the directives (perhaps just the "code-structural" ones), and one for the scripting language. The former could then understand the syntax of the conditionals ( It'd be cool if there's a tree-sitter level fix for this. If you could make the grammar aware of preprocessing, AST nodes could offer alternative node subtrees to cover the options. |
Yeah, this is exactly what I would learn in the issue I filed, but I fear this is not possible in tree-sitter right now and might also be hard to add, we'll see.
That sounds technically possible, but I wonder how one would use such a setup. E.g., thinking about The tree-sitter grammar for C seems to solve by modelling preprocessor macros only in some places, but then directly add them to the AST, e.g., see this explicit handling of My gut still tells me: just ignore this issue, but make sure we don't mutilate sources on format (I think this should already work). |
I think you're right. It goes to the heart of the matter: the conditionals essentially represent multiple scripts. If we want to keep the distribution working, we could sidestep this particular issue by keeping the AST intact despite the conditionals — a redundant The Github action is running again, and it passes ... because the Zeek disto clone isn't recursive and so doesn't pull in the Spicy file. Hah. :-) |
There is now a construct in the Zeek distribution (technically, in the Spicy plugin) that breaks the tree-sitter parsing tests:
It breaks because the grammar currently allows "preprocessor-style" directives in a handful places, but still expects an otherwise normal AST, and in the above example that's not the case — you have two
func_hdr
s in direct succession.We could fix this by breaking apart the current set of
preproc_directive
choices and make the conditional ones like comments, allowing them to appear anywhere.(CI should have notified us about this, btw ... but Github disabled it after 60 days of inactivity in this repo and we missed the notification. 🤦 I've re-enabled CI.)
The text was updated successfully, but these errors were encountered: