Trait regex_syntax::ast::Visitor

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

Required Associated Types§

source

type Output

The result of visiting an AST.

source

type Err

An error that visiting an AST might return.

Required Methods§

source

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

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

Provided Methods§

source

fn start(&mut self)

This method is called before beginning traversal of the AST.

source

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

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

source

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.

source

fn visit_alternation_in(&mut self) -> Result<(), Self::Err>

This method is called between child nodes of an Alternation.

source

fn visit_concat_in(&mut self) -> Result<(), Self::Err>

This method is called between child nodes of a concatenation.

source

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

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

source

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.

source

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

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

source

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.

source

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

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

Implementors§

source§

impl<'p, 's, P: Borrow<Parser>> Visitor for NestLimiter<'p, 's, P>

§

type Output = ()

§

type Err = Error

source§

impl<'t, 'p> Visitor for TranslatorI<'t, 'p>

§

type Output = Hir

§

type Err = Error

source§

impl<W: Write> Visitor for Writer<W>

§

type Output = ()

§

type Err = Error