Skip to main content

ParseTreeVisitor

Trait ParseTreeVisitor 

Source
pub trait ParseTreeVisitor {
    type Result;

    // Required method
    fn default_result(&mut self) -> Self::Result;

    // Provided methods
    fn visit(&mut self, tree: Node<'_>) -> Self::Result { ... }
    fn visit_rule(&mut self, node: RuleNodeView<'_>) -> Self::Result { ... }
    fn visit_children(&mut self, node: RuleNodeView<'_>) -> Self::Result { ... }
    fn visit_terminal(&mut self, _node: TerminalNodeView<'_>) -> Self::Result { ... }
    fn visit_error_node(&mut self, _node: ErrorNodeView<'_>) -> Self::Result { ... }
    fn aggregate_result(
        &mut self,
        _aggregate: Self::Result,
        next_result: Self::Result,
    ) -> Self::Result { ... }
    fn should_visit_next_child(
        &mut self,
        _node: RuleNodeView<'_>,
        _current_result: &Self::Result,
    ) -> bool { ... }
}
Expand description

Value-returning, caller-directed traversal over a completed parse tree.

Generated grammar visitors adapt typed rule and alternative callbacks to this runtime contract. The default traversal returns the latest child’s result, matching ANTLR’s base visitor behavior.

Required Associated Types§

Required Methods§

Source

fn default_result(&mut self) -> Self::Result

Provided Methods§

Source

fn visit(&mut self, tree: Node<'_>) -> Self::Result

Source

fn visit_rule(&mut self, node: RuleNodeView<'_>) -> Self::Result

Source

fn visit_children(&mut self, node: RuleNodeView<'_>) -> Self::Result

Source

fn visit_terminal(&mut self, _node: TerminalNodeView<'_>) -> Self::Result

Source

fn visit_error_node(&mut self, _node: ErrorNodeView<'_>) -> Self::Result

Source

fn aggregate_result( &mut self, _aggregate: Self::Result, next_result: Self::Result, ) -> Self::Result

Source

fn should_visit_next_child( &mut self, _node: RuleNodeView<'_>, _current_result: &Self::Result, ) -> bool

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§