noa_parser/
visitor.rs

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