noa_parser/visitor.rs
1use crate::errors::ParseResult;
2use crate::scanner::Scanner;
3
4/// A `Visitor` is a trait that allows to define how to visit a `Scanner`.
5///
6/// When a `Visitor` is used on a `Scanner`, it will consume the input from the
7/// scanner and return the result of the visit.
8///
9/// # Type Parameters
10///
11/// * `T` - The type of the data to visit.
12///
13/// # Associated Functions
14///
15/// * `accept` - Try to accept the `Scanner` and return the result of the visit.
16pub trait Visitor<'a, T>: Sized {
17 /// Try to accept the `Scanner` and return the result of the visit.
18 ///
19 /// # Arguments
20 ///
21 /// * `scanner` - The scanner to accept.
22 ///
23 /// # Returns
24 ///
25 /// The result of the visit.
26 fn accept(scanner: &mut Scanner<'a, T>) -> ParseResult<Self>;
27}