[][src]Trait logos::Logos

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

    const SIZE: usize;
    const ERROR: Self;

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

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

Notable traits for Lexer<'source, Token>

impl<'source, Token> Iterator for Lexer<'source, Token> where
    Token: Logos<'source>, 
type Item = Token;
{ ... } }
[]

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: Default[]

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

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].

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 ERROR: Self[]

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

Required methods

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

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

Notable traits for Lexer<'source, Token>

impl<'source, Token> Iterator for Lexer<'source, Token> where
    Token: Logos<'source>, 
type Item = Token;
[]

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

Implementors

impl<'s> Logos<'s> for SyntaxKind