Trait Logos

Source
pub trait Logos<'source>: Sized {
    type Extras;
    type Source: Source + ?Sized + 'source;
    type Error: Default + Clone + PartialEq + Debug + 'source;

    // Required method
    fn lex(lexer: &mut Lexer<'source, Self>);

    // Provided methods
    fn lexer(source: &'source Self::Source) -> Lexer<'source, Self> 
       where Self::Extras: Default { ... }
    fn lexer_with_extras(
        source: &'source Self::Source,
        extras: Self::Extras,
    ) -> Lexer<'source, Self>  { ... }
}
Expand description

Trait implemented for an enum representing all tokens. You should never have to implement it manually, use the #[derive(Logos)] attribute on your enum.

Required Associated Types§

Source

type Extras

Associated type Extras for the particular lexer. This can be set using #[logos(extras = MyExtras)] and accessed inside callbacks.

Source

type Source: Source + ?Sized + 'source

Source type this token can be lexed from. This will default to str, unless one of the defined patterns explicitly uses non-unicode byte values or byte slices, in which case that implementation will use [u8].

Source

type Error: Default + Clone + PartialEq + Debug + 'source

Error type returned by the lexer. This can be set using #[logos(error = MyError)]. Defaults to () if not set.

Required Methods§

Source

fn lex(lexer: &mut Lexer<'source, Self>)

The heart of Logos. Called by the Lexer. The implementation for this function is generated by the logos-derive crate.

Provided Methods§

Source

fn lexer(source: &'source Self::Source) -> Lexer<'source, Self>
where Self::Extras: Default,

Create a new instance of a Lexer that will produce tokens implementing this Logos.

Source

fn lexer_with_extras( source: &'source Self::Source, extras: Self::Extras, ) -> Lexer<'source, Self>

Create a new instance of a Lexer with the provided Extras that will produce tokens implementing this Logos.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§