[][src]Trait logos::Logos

pub trait Logos: Sized {
    type Extras: Extras;

    const SIZE: usize;
    const END: Self;
    const ERROR: Self;

    fn lex<'source, Source>(lexer: &mut Lexer<Self, Source>)
    where
        Source: Source<'source>,
        Self: WithSource<Source>
; fn lexer<'source, Source>(source: Source) -> Lexer<Self, Source>
    where
        Source: Source<'source>,
        Self: WithSource<Source>
, { ... } }

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

Associated Types

type Extras: Extras

Associated type Extras for the particular lexer. Those can handle things that aren't necessarily tokens, such as comments or Automatic Semicolon Insertion in JavaScript.

Loading content...

Associated Constants

const SIZE: usize

SIZE is simply a number of possible variants of the Logos enum. The derive macro will make sure that all variants don't hold values larger or equal to SIZE.

This can be extremely useful for creating Logos Lookup Tables.

const END: Self

Helper const of the variant marked as #[end].

const ERROR: Self

Helper const of the variant marked as #[error].

Loading content...

Required methods

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

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

Loading content...

Provided methods

fn lexer<'source, Source>(source: Source) -> Lexer<Self, Source> where
    Source: Source<'source>,
    Self: WithSource<Source>, 

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

Loading content...

Implementors

Loading content...