Skip to main content

Visitor

Trait Visitor 

Source
pub trait Visitor {
    // Provided methods
    fn enter_node(&mut self, _node: &SyntaxNode) -> ControlFlow<()> { ... }
    fn leave_node(&mut self, _node: &SyntaxNode) -> ControlFlow<()> { ... }
    fn visit_token(&mut self, _token: &SyntaxToken) -> ControlFlow<()> { ... }
}
Expand description

Trait for visiting a sipha syntax tree.

Override only the methods you need; default implementations do nothing and return WalkResult::Continue(()). Use node.kind() or node.kind_as::<YourKind>() to dispatch on node type.

§Order of calls

For each node, enter_node is called first (pre-order), then children are visited, then leave_node (post-order). This supports scoping: push scope in enter_node for block/function nodes, pop in leave_node.

§Early termination

Return WalkResult::Break(()) from any callback to stop the walk; the break propagates to the caller of walk.

§Collecting results

Store any result in your visitor struct and read it after walk returns.

Provided Methods§

Source

fn enter_node(&mut self, _node: &SyntaxNode) -> ControlFlow<()>

Called before visiting this node’s children (pre-order).

Source

fn leave_node(&mut self, _node: &SyntaxNode) -> ControlFlow<()>

Called after visiting this node’s children (post-order).

Source

fn visit_token(&mut self, _token: &SyntaxToken) -> ControlFlow<()>

Called for each token when WalkOptions::visit_tokens is true. Trivia is included only when WalkOptions::visit_trivia is true.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Visitor for ScopeBuilder

Source§

fn enter_node(&mut self, node: &SyntaxNode) -> ControlFlow<()>

Source§

fn leave_node(&mut self, node: &SyntaxNode) -> ControlFlow<()>

Source§

impl Visitor for TypeChecker<'_>

Source§

fn enter_node(&mut self, node: &SyntaxNode) -> ControlFlow<()>

Source§

fn leave_node(&mut self, node: &SyntaxNode) -> ControlFlow<()>

Source§

impl Visitor for Validator<'_>

Source§

fn enter_node(&mut self, node: &SyntaxNode) -> ControlFlow<()>

Source§

fn leave_node(&mut self, node: &SyntaxNode) -> ControlFlow<()>

Implementors§