freshtonic commented on issue #934:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/issues/934#issuecomment-2841810444

   @ramnes thank you for clarifying!
   
   I'm 100% in favour of any style of `Visitor` implementation that covers all 
AST node types in `sqlparser`. I'm less fussy than I used to be about the 
particular approach taken. These are the "obvious" approaches to me:
   
   1. Big `Visitor` trait (enter/exit or pre/post methods for _every_ AST node 
type)
   2. Small `Visitor` trait (just enter/exit methods, e.g. `fn enter<N: 
Visitable>(&mut self, node: &N) -> ControlFlow`
   3. Small generic `Visitor<N: Visitable>` trait (just enter/exit methods, 
e.g. `fn enter(&mut self, node: &N) -> ControlFlow` 
   
   Option 1 is (subjectively) ugly but gets the job done.
   
   Option 2 has a cleaner trait but implementations must downcast the node to 
do anything useful with it.
   
   Option 3 is just as clean as 2 and downcasting is no longer required in 
every implementation, _but_ `Visitor` dispatch no longer works because the AST 
traversal has to be able to dispatch _any_ node type to a `Visitor`, so you 
still need an additional dispatch mechanism. This is where the enum based 
dispatch could help.
   
   The approach to `Visitor` I ended up going with in `sqltk` is essentially 
Option 2 above and looks like 
[this](https://docs.rs/sqltk/latest/sqltk/trait.Visitor.html).
   
   I have been thinking about alternative approach to avoid all of the explicit 
casting and just generate the code.
   
   Here's the 
[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=f1d842d0b5a9d4af39a4684ffc41265a)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to