Skip to content

Add pre_visit_ident / post_visit_ident hooks to the Visitor trait#2370

Open
sabir-akhadov-localstack wants to merge 1 commit into
apache:mainfrom
localstack:pr/01-visit-ident-hooks
Open

Add pre_visit_ident / post_visit_ident hooks to the Visitor trait#2370
sabir-akhadov-localstack wants to merge 1 commit into
apache:mainfrom
localstack:pr/01-visit-ident-hooks

Conversation

@sabir-akhadov-localstack
Copy link
Copy Markdown

@sabir-akhadov-localstack sabir-akhadov-localstack commented Jun 8, 2026

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.

@sabir-akhadov-localstack sabir-akhadov-localstack marked this pull request as draft June 8, 2026 14:35
@sabir-akhadov-localstack sabir-akhadov-localstack marked this pull request as ready for review June 8, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant