Visitor in regex_syntax::ast - Rust (original) (raw)
pub trait Visitor {
type Output;
type Err;
// Required method
fn finish(self) -> Result<Self::Output, Self::Err>;
// Provided methods
fn start(&mut self) { ... }
fn visit_pre(&mut self, _ast: &Ast) -> Result<(), Self::Err> { ... }
fn visit_post(&mut self, _ast: &Ast) -> Result<(), Self::Err> { ... }
fn visit_alternation_in(&mut self) -> Result<(), Self::Err> { ... }
fn visit_concat_in(&mut self) -> Result<(), Self::Err> { ... }
fn visit_class_set_item_pre(
&mut self,
_ast: &ClassSetItem,
) -> Result<(), Self::Err> { ... }
fn visit_class_set_item_post(
&mut self,
_ast: &ClassSetItem,
) -> Result<(), Self::Err> { ... }
fn visit_class_set_binary_op_pre(
&mut self,
_ast: &ClassSetBinaryOp,
) -> Result<(), Self::Err> { ... }
fn visit_class_set_binary_op_post(
&mut self,
_ast: &ClassSetBinaryOp,
) -> Result<(), Self::Err> { ... }
fn visit_class_set_binary_op_in(
&mut self,
_ast: &ClassSetBinaryOp,
) -> Result<(), Self::Err> { ... }
}
Expand description
A trait for visiting an abstract syntax tree (AST) in depth first order.
The principle aim of this trait is to enable callers to perform case analysis on an abstract syntax tree without necessarily using recursion. In particular, this permits callers to do case analysis with constant stack usage, which can be important since the size of an abstract syntax tree may be proportional to end user input.
Typical usage of this trait involves providing an implementation and then running it using the visit function.
Note that the abstract syntax tree for a regular expression is quite complex. Unless you specifically need it, you might be able to use the much simpler high-level intermediate representation and itscorresponding Visitor trait instead.
The result of visiting an AST.
An error that visiting an AST might return.
All implementors of Visitor
must provide a finish
method, which yields the result of visiting the AST or an error.
This method is called before beginning traversal of the AST.
This method is called on an Ast
before descending into child Ast
nodes.
This method is called on an Ast
after descending all of its childAst
nodes.
This method is called between child nodes of anAlternation.
This method is called between child nodes of a concatenation.
This method is called on every ClassSetItembefore descending into child nodes.
This method is called on every ClassSetItemafter descending into child nodes.
This method is called on everyClassSetBinaryOp before descending into child nodes.
This method is called on everyClassSetBinaryOp after descending into child nodes.
This method is called between the left hand and right hand child nodes of a ClassSetBinaryOp.