Skip to main content

Visitor

Trait Visitor 

Source
pub trait Visitor<'arena, 'src> {
Show 13 methods // Provided methods fn visit_program( &mut self, program: &Program<'arena, 'src>, ) -> ControlFlow<()> { ... } fn visit_stmt(&mut self, stmt: &Stmt<'arena, 'src>) -> ControlFlow<()> { ... } fn visit_expr(&mut self, expr: &Expr<'arena, 'src>) -> ControlFlow<()> { ... } fn visit_param(&mut self, param: &Param<'arena, 'src>) -> ControlFlow<()> { ... } fn visit_arg(&mut self, arg: &Arg<'arena, 'src>) -> ControlFlow<()> { ... } fn visit_class_member( &mut self, member: &ClassMember<'arena, 'src>, ) -> ControlFlow<()> { ... } fn visit_enum_member( &mut self, member: &EnumMember<'arena, 'src>, ) -> ControlFlow<()> { ... } fn visit_property_hook( &mut self, hook: &PropertyHook<'arena, 'src>, ) -> ControlFlow<()> { ... } fn visit_type_hint( &mut self, type_hint: &TypeHint<'arena, 'src>, ) -> ControlFlow<()> { ... } fn visit_attribute( &mut self, attribute: &Attribute<'arena, 'src>, ) -> ControlFlow<()> { ... } fn visit_catch_clause( &mut self, catch: &CatchClause<'arena, 'src>, ) -> ControlFlow<()> { ... } fn visit_match_arm( &mut self, arm: &MatchArm<'arena, 'src>, ) -> ControlFlow<()> { ... } fn visit_closure_use_var( &mut self, _var: &ClosureUseVar<'src>, ) -> ControlFlow<()> { ... }
}
Expand description

Visitor trait for immutable AST traversal.

All methods return ControlFlow<()>:

  • ControlFlow::Continue(()) — keep walking.
  • ControlFlow::Break(()) — stop the entire traversal immediately.

Default implementations recursively walk child nodes, so implementors only need to override the node types they care about.

To skip a subtree, override the method and return Continue(()) without calling the corresponding walk_* function.

§Example

use php_ast::visitor::{Visitor, walk_expr};
use php_ast::ast::*;
use std::ops::ControlFlow;

struct VarCounter { count: usize }

impl<'arena, 'src> Visitor<'arena, 'src> for VarCounter {
    fn visit_expr(&mut self, expr: &Expr<'arena, 'src>) -> ControlFlow<()> {
        if matches!(&expr.kind, ExprKind::Variable(_)) {
            self.count += 1;
        }
        walk_expr(self, expr)
    }
}

Provided Methods§

Source

fn visit_program(&mut self, program: &Program<'arena, 'src>) -> ControlFlow<()>

Source

fn visit_stmt(&mut self, stmt: &Stmt<'arena, 'src>) -> ControlFlow<()>

Source

fn visit_expr(&mut self, expr: &Expr<'arena, 'src>) -> ControlFlow<()>

Source

fn visit_param(&mut self, param: &Param<'arena, 'src>) -> ControlFlow<()>

Source

fn visit_arg(&mut self, arg: &Arg<'arena, 'src>) -> ControlFlow<()>

Source

fn visit_class_member( &mut self, member: &ClassMember<'arena, 'src>, ) -> ControlFlow<()>

Source

fn visit_enum_member( &mut self, member: &EnumMember<'arena, 'src>, ) -> ControlFlow<()>

Source

fn visit_property_hook( &mut self, hook: &PropertyHook<'arena, 'src>, ) -> ControlFlow<()>

Source

fn visit_type_hint( &mut self, type_hint: &TypeHint<'arena, 'src>, ) -> ControlFlow<()>

Source

fn visit_attribute( &mut self, attribute: &Attribute<'arena, 'src>, ) -> ControlFlow<()>

Source

fn visit_catch_clause( &mut self, catch: &CatchClause<'arena, 'src>, ) -> ControlFlow<()>

Source

fn visit_match_arm(&mut self, arm: &MatchArm<'arena, 'src>) -> ControlFlow<()>

Source

fn visit_closure_use_var( &mut self, _var: &ClosureUseVar<'src>, ) -> ControlFlow<()>

Implementors§

Source§

impl<'arena, 'src, V: ScopeVisitor<'arena, 'src>> Visitor<'arena, 'src> for ScopeWalker<'src, V>