sabir-akhadov-localstack opened a new pull request, #2370:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2370
The `Visitor` / `VisitorMut` traits had no hook for individual identifiers:
`Ident` derived a no-op `Visit`, so identifiers could not be observed or
rewritten during a traversal. This makes it impossible to, e.g., collect
every
identifier in a statement or rewrite identifiers in place.
This adds `pre_visit_ident` / `post_visit_ident` (default no-op) to both
`Visitor` and `VisitorMut`, and gives `Ident` a manual `Visit` / `VisitMut`
impl that invokes them.
Example — collect identifiers:
struct IdentVisitor { idents: Vec<String> }
impl Visitor for IdentVisitor {
type Break = ();
fn pre_visit_ident(&mut self, ident: &Ident) -> ControlFlow<()> {
self.idents.push(ident.value.clone());
ControlFlow::Continue(())
}
}
// "SELECT a, b FROM t" -> ["a", "b", "t"]
Tests added in `src/ast/visitor.rs` for both the immutable and mutable hooks.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]