Trait Visitor
trait Visitor
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 its
corresponding Visitor trait instead.
Associated Types
type OutputThe result of visiting an AST.
type ErrAn error that visiting an AST might return.
Required Methods
fn finish(self: Self) -> Result<<Self as >::Output, <Self as >::Err>All implementors of
Visitormust provide afinishmethod, which yields the result of visiting the AST or an error.
Provided Methods
fn start(self: &mut Self)This method is called before beginning traversal of the AST.
fn visit_pre(self: &mut Self, _ast: &Ast) -> Result<(), <Self as >::Err>This method is called on an
Astbefore descending into childAstnodes.fn visit_post(self: &mut Self, _ast: &Ast) -> Result<(), <Self as >::Err>This method is called on an
Astafter descending all of its childAstnodes.fn visit_alternation_in(self: &mut Self) -> Result<(), <Self as >::Err>This method is called between child nodes of an
Alternation.fn visit_concat_in(self: &mut Self) -> Result<(), <Self as >::Err>This method is called between child nodes of a concatenation.
fn visit_class_set_item_pre(self: &mut Self, _ast: &ClassSetItem) -> Result<(), <Self as >::Err>This method is called on every
ClassSetItembefore descending into child nodes.fn visit_class_set_item_post(self: &mut Self, _ast: &ClassSetItem) -> Result<(), <Self as >::Err>This method is called on every
ClassSetItemafter descending into child nodes.fn visit_class_set_binary_op_pre(self: &mut Self, _ast: &ClassSetBinaryOp) -> Result<(), <Self as >::Err>This method is called on every
ClassSetBinaryOpbefore descending into child nodes.fn visit_class_set_binary_op_post(self: &mut Self, _ast: &ClassSetBinaryOp) -> Result<(), <Self as >::Err>This method is called on every
ClassSetBinaryOpafter descending into child nodes.fn visit_class_set_binary_op_in(self: &mut Self, _ast: &ClassSetBinaryOp) -> Result<(), <Self as >::Err>This method is called between the left hand and right hand child nodes of a
ClassSetBinaryOp.