pub trait VisitAny<'ast, 'text: 'ast> {
// Provided methods
fn before(&mut self, _node: AnyNode<'ast, 'text>) { ... }
fn after(&mut self, _node: AnyNode<'ast, 'text>) { ... }
}Expand description
The VisitAny trait is used to visit the AST without having to know the specific shape of each node. There are two methods, VisitAny::before and VisitAny::after, which are called before and after visiting the children of a given node, respectively.
The AnyNode enum is used to represent any node in the AST.
§Example
use mf2_parser::ast::*;
use mf2_parser::VisitAny;
use mf2_parser::Visitable as _;
use mf2_parser::parse;
struct MyVisitor;
impl<'ast, 'text: 'ast> VisitAny<'ast, 'text> for MyVisitor {
fn before(&mut self, node: AnyNode<'ast, 'text>) {
println!("Start visiting node: {:?}", node);
}
fn after(&mut self, node: AnyNode<'ast, 'text>) {
println!("Finished visiting node: {:?}", node);
}
}
let (ast, _, _) = parse("Hello, {$name}!");
let mut visitor = MyVisitor;
ast.apply_visitor(&mut visitor);