-
Notifications
You must be signed in to change notification settings - Fork 566
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
Question: why is the Visitor trait limited to statements, relations & expressions? #934
Comments
The core reasons are to keep this crate easy to extend with new sql syntax by casual contributors and limited maintenance bandwidth. The current visitor pattern / macros require a single new In terms of your proposed implementation, it seems reasonable. I would be interested in knowing how it would work when a contributor added a new node, like #897 How would we ensure that these new nodes were added to the perhaps @lovasoa and @tustvold have some other perspectives Basically I think a general purpose rewriter / visitor would be a great addition, as long as we don't make it too hard to add new code to this repo |
@freshtonic AST visiting in sqlparser-rs has a long history. It took very long for a design to be agreed on and merged. I had proposed an alternative, more general, approach that would have allowed to do what you wanted: #601 But it was rejected, by fear it would take too much work to maintain. My proposition to embark new maintainers for the feature (myself and @nikis05) was rejected. sqlparser-rs is at the very core of SQLPage, so I can reiterate my proposition: I wouldn't mind being added as a maintainer here :) |
Indeed -- I am looking for help maintaining it for sure. I think you can do all the time consuming parts of maintenance (PR reviews, answering questions / tickets, etc) without having write access to the repository. I am waiting for someone to actually show the initiative to do this work (there are plenty of people willing to write code). I had a promising candidate in @AugustoFKL (see #808) but sadly there were some circumstances that required them to stop working here I will write up a discussion explaining the current state of affairs Update: #940 |
That's a great question. Assuming the parent node of the new node has a derived Visitor instance then compilation would fail due to the derived code not being able to find a matching Ideally, the |
You don't need to create a huge enum. You can use the built in Any trait. Have a look at my PR ;) |
@lovasoa depends on if you want to |
FWIW #951 added visiting TableFactor as well |
Update: I've been experimenting with various implementation strategies to generalise the AST visitor. Nothing to ready to show yet, but this is business critical for my company so it's a high priority to figure out something that works well. I'll update this issue with a link to a draft PR hopefully in a matter of days. |
Progress update - I have a working generalised visitor implementation. I'll put up a PR later this week when I've done some more testing. |
Is this still happening? Generalised visitor implementation would be appreciated. |
@osaton @alamb yes this is still happening. Apologies for the lack of comms. TL;DR I ended up taking quite a different approach to what I originally planned, due to our (the company I work for) evolving needs. The comprehensive Visitor implementation will be initially released as its own crate. My original intention was to release a PR against Summary of features so far:
In order to pull that off, I needed to write a I need to write up some docs but I would love some feedback on the code and general approach before I publicly publish the repo. I can share it privately if either of you are interested in taking a look. |
Three features that I really wanted from
It's possible for multiple AST nodes at different places in the tree that have the same type to have the same hash and compare as equal. This seems counter intuitive, but two syntactically identical nodes can be different semantically. Not having robust (and cheap) means of uniquely identifying a node makes building HashMaps of derived metadata keyed by node particularly tricky.
This would be super useful for debugging and reporting errors nicely (like
It would be nice to not have to match an enum in order to pluck out a variant. Instead I'd like be able to implement 1 & 2 could be solved by wrapping every struct field or enum variant field in a |
@freshtonic Your visitor crate sounds perfect for my use case. I would love to try it but I'm not sure if I'm able to give any constructive criticism about the code as I'm fairly new to Rust and systems programming languages in general.
I don't know if this can be done without breaking changes, but having both 1 and 2 would be amazing. |
+1 to this – would be curious to try out your crate @freshtonic if/when it gets to a publishable state :) |
What is the reason for that particular design decision versus providing a more general
Visitor
implementation?Two options for a generalised Visitor trait come to mind:
pre_visit
+post_visit
) with signatures likefn pre_visit(&mut self, node: &AstNode) -> ControlFlow<Self::Break>
- whereAstNode
is an enum with a wrapper variant for every AST node type found insrc/ast/mod.rs
and can bematch
ed against.Would the maintainers be interested in a PR that implements one of the above two approaches?
My preference would be for option 2 because it would not break the trait when node types are added/removed.
Suggested approach:
RawVisitor
trait (andRawVisitorMut
trait) like this:RawVisitorAdapter
?) that accepts aV: Visitor
generic argument and implementsRawVisitor
&RawVisitorMut
, which calls the appropriate method onV
(or none at all)Visit
derivation macros to generate code in terms ofRawVisitor
&RawVisitorMut
instead ofVisitor
, like this:The text was updated successfully, but these errors were encountered: