Lexer

Struct Lexer 

Source
pub struct Lexer<'a, T> {
    pub source: &'a Source<'a>,
    pub position: usize,
    pub current_char: Option<char>,
    /* private fields */
}
Expand description

Tokenizes the source code.

Fields§

§source: &'a Source<'a>

The source code to be tokenized.

§position: usize

The current position in the source code.

§current_char: Option<char>

The current character being processed.

Implementations§

Source§

impl<'a, T> Lexer<'a, T>

Source

pub fn new( source: &'a Source<'a>, rules: Vec<Box<dyn LexerRule<'a, T>>>, ) -> Self

Creates a new Lexer instance with the given source code and rules.

Source

pub fn advance(&mut self)

Advances the lexer to the next character in the source code.

Source

pub fn jump_to(&mut self, position: usize)

Jumps to a specific position in the source code.

Source

pub fn get_token(&mut self) -> Result<Option<Token<T>>, Error<'_>>

Attempts to get the next token from the lexer using the defined rules.

If a token is found, it returns Ok(Some(token)). If no token is found, it returns Ok(None). If an error occurs, it returns Err(error).

Auto Trait Implementations§

§

impl<'a, T> Freeze for Lexer<'a, T>

§

impl<'a, T> !RefUnwindSafe for Lexer<'a, T>

§

impl<'a, T> !Send for Lexer<'a, T>

§

impl<'a, T> !Sync for Lexer<'a, T>

§

impl<'a, T> Unpin for Lexer<'a, T>

§

impl<'a, T> !UnwindSafe for Lexer<'a, T>

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.