bulloak_syntax/visitor.rs
1//! Defines a trait for visiting a bulloak tree AST in depth-first order.
2
3use crate::ast;
4
5/// A trait for visiting a tree AST in depth-first order.
6///
7/// All implementors of `Visitor` must provide a `visit_root` implementation.
8/// This is usually the entry point of the visitor, though it is best if this
9/// assumption is not held.
10pub trait Visitor {
11 /// The result of visiting the AST.
12 type Output;
13 /// An error that might occur when visiting the AST.
14 type Error;
15
16 /// This method is called on a root node.
17 fn visit_root(
18 &mut self,
19 root: &ast::Root,
20 ) -> Result<Self::Output, Self::Error>;
21 /// This method is called on a condition node.
22 fn visit_condition(
23 &mut self,
24 condition: &ast::Condition,
25 ) -> Result<Self::Output, Self::Error>;
26 /// This method is called on an action node.
27 fn visit_action(
28 &mut self,
29 action: &ast::Action,
30 ) -> Result<Self::Output, Self::Error>;
31 /// This method is called on an action description node.
32 fn visit_description(
33 &mut self,
34 description: &ast::Description,
35 ) -> Result<Self::Output, Self::Error>;
36}