mf2_parser

Trait Visit

source
pub trait Visit<'ast, 'text> {
Show 31 methods // Provided methods fn visit_message(&mut self, message: &'ast Message<'text>) { ... } fn visit_pattern(&mut self, msg: &'ast Pattern<'text>) { ... } fn visit_pattern_part(&mut self, part: &'ast PatternPart<'text>) { ... } fn visit_text(&mut self, text: &'ast Text<'text>) { ... } fn visit_escape(&mut self, escape: &'ast Escape) { ... } fn visit_expression(&mut self, expr: &'ast Expression<'text>) { ... } fn visit_literal_expression(&mut self, expr: &'ast LiteralExpression<'text>) { ... } fn visit_literal(&mut self, literal: &'ast Literal<'text>) { ... } fn visit_quoted(&mut self, quoted: &'ast Quoted<'text>) { ... } fn visit_quoted_part(&mut self, part: &'ast QuotedPart<'text>) { ... } fn visit_number(&mut self, num: &'ast Number<'text>) { ... } fn visit_annotation(&mut self, ann: &'ast Annotation<'text>) { ... } fn visit_function(&mut self, func: &'ast Function<'text>) { ... } fn visit_identifier(&mut self, ident: &'ast Identifier<'text>) { ... } fn visit_fn_or_markup_option(&mut self, opt: &'ast FnOrMarkupOption<'text>) { ... } fn visit_literal_or_variable( &mut self, lit_or_var: &'ast LiteralOrVariable<'text>, ) { ... } fn visit_variable(&mut self, var: &'ast Variable<'text>) { ... } fn visit_attribute(&mut self, attr: &'ast Attribute<'text>) { ... } fn visit_variable_expression( &mut self, expr: &'ast VariableExpression<'text>, ) { ... } fn visit_annotation_expression( &mut self, expr: &'ast AnnotationExpression<'text>, ) { ... } fn visit_markup(&mut self, markup: &'ast Markup<'text>) { ... } fn visit_complex_message(&mut self, msg: &'ast ComplexMessage<'text>) { ... } fn visit_declaration(&mut self, decl: &'ast Declaration<'text>) { ... } fn visit_input_declaration(&mut self, decl: &'ast InputDeclaration<'text>) { ... } fn visit_local_declaration(&mut self, decl: &'ast LocalDeclaration<'text>) { ... } fn visit_complex_message_body( &mut self, body: &'ast ComplexMessageBody<'text>, ) { ... } fn visit_quoted_pattern(&mut self, pattern: &'ast QuotedPattern<'text>) { ... } fn visit_matcher(&mut self, matcher: &'ast Matcher<'text>) { ... } fn visit_variant(&mut self, variant: &'ast Variant<'text>) { ... } fn visit_key(&mut self, key: &'ast Key<'text>) { ... } fn visit_star(&mut self, star: &'ast Star) { ... }
}
Expand description

The Visit trait is used to traverse the AST. You can implement this trait to visit each node in the AST in source text order.

Each method in the trait corresponds to a node type in the AST. The method is called with a reference to the node. The default implementation of each method calls Visitable::apply_visitor_to_children on the node, which then recursively applies the visitor to the node’s children. To implement a recursive visitor, you must also call Visitable::apply_visitor_to_children on any overridden visit methods.

§Example

use mf2_parser::ast::*;
use mf2_parser::Visit;
use mf2_parser::Visitable as _;
use mf2_parser::parse;

struct MyVisitor;

impl<'ast, 'text> Visit<'ast, 'text> for MyVisitor {
  fn visit_variable(&mut self, var: &'ast Variable<'text>) {
    println!("Found variable: {}", var.name);
    var.apply_visitor_to_children(self);
  }
}


let (ast, _, _) = parse("Hello, {$name}!");
let mut visitor = MyVisitor;
ast.apply_visitor(&mut visitor);

Provided Methods§

source

fn visit_message(&mut self, message: &'ast Message<'text>)

source

fn visit_pattern(&mut self, msg: &'ast Pattern<'text>)

source

fn visit_pattern_part(&mut self, part: &'ast PatternPart<'text>)

source

fn visit_text(&mut self, text: &'ast Text<'text>)

source

fn visit_escape(&mut self, escape: &'ast Escape)

source

fn visit_expression(&mut self, expr: &'ast Expression<'text>)

source

fn visit_literal_expression(&mut self, expr: &'ast LiteralExpression<'text>)

source

fn visit_literal(&mut self, literal: &'ast Literal<'text>)

source

fn visit_quoted(&mut self, quoted: &'ast Quoted<'text>)

source

fn visit_quoted_part(&mut self, part: &'ast QuotedPart<'text>)

source

fn visit_number(&mut self, num: &'ast Number<'text>)

source

fn visit_annotation(&mut self, ann: &'ast Annotation<'text>)

source

fn visit_function(&mut self, func: &'ast Function<'text>)

source

fn visit_identifier(&mut self, ident: &'ast Identifier<'text>)

source

fn visit_fn_or_markup_option(&mut self, opt: &'ast FnOrMarkupOption<'text>)

source

fn visit_literal_or_variable( &mut self, lit_or_var: &'ast LiteralOrVariable<'text>, )

source

fn visit_variable(&mut self, var: &'ast Variable<'text>)

source

fn visit_attribute(&mut self, attr: &'ast Attribute<'text>)

source

fn visit_variable_expression(&mut self, expr: &'ast VariableExpression<'text>)

source

fn visit_annotation_expression( &mut self, expr: &'ast AnnotationExpression<'text>, )

source

fn visit_markup(&mut self, markup: &'ast Markup<'text>)

source

fn visit_complex_message(&mut self, msg: &'ast ComplexMessage<'text>)

source

fn visit_declaration(&mut self, decl: &'ast Declaration<'text>)

source

fn visit_input_declaration(&mut self, decl: &'ast InputDeclaration<'text>)

source

fn visit_local_declaration(&mut self, decl: &'ast LocalDeclaration<'text>)

source

fn visit_complex_message_body(&mut self, body: &'ast ComplexMessageBody<'text>)

source

fn visit_quoted_pattern(&mut self, pattern: &'ast QuotedPattern<'text>)

source

fn visit_matcher(&mut self, matcher: &'ast Matcher<'text>)

source

fn visit_variant(&mut self, variant: &'ast Variant<'text>)

source

fn visit_key(&mut self, key: &'ast Key<'text>)

source

fn visit_star(&mut self, star: &'ast Star)

Implementors§

source§

impl<'ast, 'text: 'ast, T: VisitAny<'ast, 'text>> Visit<'ast, 'text> for T