Trait logos::Logos

source ·
pub trait Logos: Sized {
    type Extras: Extras;

    const SIZE: usize;
    const ERROR: Self;

    fn lexicon<S: Source>() -> Lexicon<Lexer<Self, S>>;

    fn lexer<S: Source>(source: S) -> Lexer<Self, S> { ... }
}
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

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

Required Associated Constants

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.

Helper const pointing to the variant marked as #[error].

Required Methods

Returns a lookup table for the Lexer

Provided Methods

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

Implementors