TokenFactory

Trait TokenFactory 

Source
pub trait TokenFactory<'a>: TidAble<'a> + Sized {
    type Inner: Token<Data = Self::Data> + ?Sized + 'a;
    type Tok: Borrow<Self::Inner> + Clone + 'a + Debug;
    type Data: InputData + ?Sized;
    type From;

    // Required methods
    fn create<T>(
        &'a self,
        source: Option<&mut T>,
        ttype: isize,
        text: Option<<Self::Data as ToOwned>::Owned>,
        channel: isize,
        start: isize,
        stop: isize,
        line: isize,
        column: isize,
    ) -> Self::Tok
       where T: CharStream<Self::From> + ?Sized;
    fn create_invalid() -> Self::Tok;
    fn get_data(from: Self::From) -> Cow<'a, Self::Data>;
}
Expand description

Trait for creating tokens.

Required Associated Types§

Source

type Inner: Token<Data = Self::Data> + ?Sized + 'a

Type of tokens emitted by this factory.

Source

type Tok: Borrow<Self::Inner> + Clone + 'a + Debug

Ownership of the emitted tokens

Source

type Data: InputData + ?Sized

Type of the underlying storage

Source

type From

Type of the CharStream that factory can produce tokens from

Required Methods§

Source

fn create<T>( &'a self, source: Option<&mut T>, ttype: isize, text: Option<<Self::Data as ToOwned>::Owned>, channel: isize, start: isize, stop: isize, line: isize, column: isize, ) -> Self::Tok
where T: CharStream<Self::From> + ?Sized,

Creates token either from sourse or from pure data in text Either source or text are not None

Source

fn create_invalid() -> Self::Tok

Creates invalid token Invalid tokens must have TOKEN_INVALID_TYPE token type.

Source

fn get_data(from: Self::From) -> Cow<'a, Self::Data>

Creates Self::Data representation for from for lexer to work with when it does not need to create full token

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§

Source§

impl<'a> TokenFactory<'a> for CommonTokenFactory

Source§

impl<'a> TokenFactory<'a> for OwningTokenFactory

Source§

impl<'input, TF, Tok> TokenFactory<'input> for ArenaFactory<'input, TF, Tok>
where TF: TokenFactory<'input, Tok = Box<Tok>, Inner = Tok>, Tok: Token<Data = TF::Data> + Clone + TidAble<'input>, for<'a> &'a Tok: Default,

Source§

type Inner = Tok

Source§

type Tok = &'input Tok

Source§

type Data = <TF as TokenFactory<'input>>::Data

Source§

type From = <TF as TokenFactory<'input>>::From