macro_rules! token_parser {
    (
        token: $token_ty:ty $(,)?
    ) => { ... };
    (
        token: $token_ty:ty,
        error: $error_ty:ty = $error:expr $(,)?
    ) => { ... };
    (
        token: $token_ty:ty,
        error<$lt:lifetime>($input:ident, $token:ident): $error_ty:ty = $error:expr $(,)?
    ) => { ... };
}
Expand description

Automatically implements nom::Parser for your token type.

Example

#[derive(Clone, Debug, PartialEq, Eq, logos::Logos)]
enum Token {
    #[token("test")]
    Test,

    #[error]
    Error,
}

logos_nom_bridge::token_parser!(token: Token);

You can use your own error type:

logos_nom_bridge::token_parser!(
    token: Token,
    error: MyError = MyError::WrongToken,
);

enum MyError {
    WrongToken,
}

It’s possible to store the input and/or the expected token in the error:

logos_nom_bridge::token_parser!(
    token: Token,
    error<'src>(input, token): MyError<'src> = MyError::WrongToken {
        input,
        expected: *token,
    }
);

enum MyError<'src> {
    WrongToken {
        input: logos_nom_bridge::Tokens<'src, Token>,
        expected: Token,
    },
}