pub trait Visitor {
    type Output;
    type Err;

    fn finish(self) -> Result<Self::Output, Self::Err>;

    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_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 its corresponding Visitor trait instead.

Required Associated Types

The result of visiting an AST.

An error that visiting an AST might return.

Required Methods

All implementors of Visitor must provide a finish method, which yields the result of visiting the AST or an error.

Provided Methods

This method is called before beginning traversal of the AST.

This method is called on an Ast before descending into child Ast nodes.

fn visit_post(&mut self, _ast: &Ast) -> Result<(), Self::Err>

This method is called on an Ast after descending all of its child Ast nodes.

This method is called between child nodes of an Alternation.

This method is called on every ClassSetItem before descending into child nodes.

fn visit_class_set_item_post(
    &mut self,
    _ast: &ClassSetItem
) -> Result<(), Self::Err>

This method is called on every ClassSetItem after descending into child nodes.

This method is called on every ClassSetBinaryOp before descending into child nodes.

fn visit_class_set_binary_op_post(
    &mut self,
    _ast: &ClassSetBinaryOp
) -> Result<(), Self::Err>

This method is called on every ClassSetBinaryOp after descending into child nodes.

This method is called between the left hand and right hand child nodes of a ClassSetBinaryOp.

Implementors