Struct Lexer

Source
pub struct Lexer<'lexer> { /* private fields */ }
Expand description

Lexer for tokenising input strings.

The Lexer provides methods for tokenising input strings into individual tokens. It supports various token types such as identifiers, numbers, strings, and operators. The Lexer uses a cursor-based approach to iterate over the input string and extract tokens.

Implementations§

Source§

impl<'lexer> Lexer<'lexer>

Source

pub fn new(input: &'lexer str) -> Self

Creates a new Lexer instance.

§Arguments
  • input - The input string to be tokenised.
Source

pub fn next_token(&mut self) -> Token

Advances the lexer to the next token in the input stream and returns the token.

This function is essentially a large switch statement, containing branches corresponding to every token type. This function skips any whitespace and comments before identifying the next token. The token is represented by a Token struct, which contains information about its kind (e.g., identifier, operator, literal) and its span in the input stream.

§Returns

The next token in the sequence, and will continue to return an Eof token once the end is reached.

Auto Trait Implementations§

§

impl<'lexer> Freeze for Lexer<'lexer>

§

impl<'lexer> RefUnwindSafe for Lexer<'lexer>

§

impl<'lexer> Send for Lexer<'lexer>

§

impl<'lexer> Sync for Lexer<'lexer>

§

impl<'lexer> Unpin for Lexer<'lexer>

§

impl<'lexer> UnwindSafe for Lexer<'lexer>

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.