Function logos::skip

source ·
pub fn skip<'source, Token: Logos<'source>>(
    _: &mut Lexer<'source, Token>
) -> Skip
Expand description

Predefined callback that will inform the Lexer to skip a definition.

Example

use logos::Logos;

#[derive(Logos, Debug, PartialEq)]
enum Token<'a> {
    // We will treat "abc" as if it was whitespace
    #[regex(" |abc", logos::skip, priority = 3)]
    Ignored,

    #[regex("[a-zA-Z]+")]
    Text(&'a str),
}

let tokens: Vec<_> = Token::lexer("Hello abc world").collect();

assert_eq!(
    tokens,
    &[
        Ok(Token::Text("Hello")),
        Ok(Token::Text("world")),
    ],
);