LexerBuilder

Struct LexerBuilder 

Source
pub struct LexerBuilder<'s, TokenType> {
    pub actions: Vec<LexAction<'s, TokenType>>,
}
Expand description

Struct used to generate a Lexer

It can either be initialised with an array of LexActions, or using the push method(recommended).

Fields§

§actions: Vec<LexAction<'s, TokenType>>

List of all tokens including conversions used by the resulting Lexer

Implementations§

Source§

impl<'s, TokenType> LexerBuilder<'s, TokenType>

Source

pub fn new() -> Self

Returns an empty LexerBuilder

Source

pub fn push( &mut self, token: &'s str, action: fn(&str) -> TokenType, ) -> &mut Self

Adds a new token to the LexerBuilder

token is the regex representation of the string
action is a method converting the &str representation of the token to a Token

Source

pub fn build(&self) -> Lexer<TokenType>

Builds a new Lexer from the Actions configured in the Builder

Trait Implementations§

Source§

impl<'s, TokenType: Default> Default for LexerBuilder<'s, TokenType>

Source§

fn default() -> LexerBuilder<'s, TokenType>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'s, TokenType> Freeze for LexerBuilder<'s, TokenType>

§

impl<'s, TokenType> RefUnwindSafe for LexerBuilder<'s, TokenType>

§

impl<'s, TokenType> Send for LexerBuilder<'s, TokenType>

§

impl<'s, TokenType> Sync for LexerBuilder<'s, TokenType>

§

impl<'s, TokenType> Unpin for LexerBuilder<'s, TokenType>

§

impl<'s, TokenType> UnwindSafe for LexerBuilder<'s, TokenType>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.