LexerRule

Trait LexerRule 

Source
pub trait LexerRule<'a, T> {
    // Required method
    fn get_token(
        &self,
        lexer: &mut Lexer<'a, T>,
    ) -> Result<Option<Token<T>>, Error<'_>>;

    // Provided method
    fn generates_token(&self) -> bool { ... }
}
Expand description

Defines the interface for lexer rules.

Required Methods§

Source

fn get_token( &self, lexer: &mut Lexer<'a, T>, ) -> Result<Option<Token<T>>, Error<'_>>

This method is called to get a token from the lexer. It should return Ok(Some(token)) if a token is found, Ok(None) if no token is found, or Err(error) if an error occurs.

If an error occurs, the lexer will stop processing and return the error. Otherwise, it will continue to the next rule.

Provided Methods§

Source

fn generates_token(&self) -> bool

This method returns true if the rule generates a token, and false if it does not.

This is used to determine whether the lexer should jump back to the previous position if the rule does not generate a token.

For example, a rule that skips whitespace does not generate a token, so the lexer will jump back to the previous position if it does not find a token.

Implementors§

Source§

impl<'a, T> LexerRule<'a, T> for SkipWhitespaceRule