Struct LexerState

Source
struct LexerState<'a> {
    input: &'a str,
    chars: Peekable<Chars<'a>>,
    current_pos: usize,
    current_line: usize,
    tokens_on_current_line: usize,
    tokens: Vec<Token>,
    line_tokens: Vec<(u16, u16)>,
    errors: Vec<CompilerError>,
}
Expand description

Lexer state for tracking position during tokenization

Fields§

§input: &'a str

Source text being tokenized

§chars: Peekable<Chars<'a>>

Iterator over source characters

§current_pos: usize

Current position in source

§current_line: usize

Current line number

§tokens_on_current_line: usize

Number of tokens on current line

§tokens: Vec<Token>

Tokens generated so far

§line_tokens: Vec<(u16, u16)>

Line token counts for line info

§errors: Vec<CompilerError>

Collected lexer errors

Implementations§

Source§

impl<'a> LexerState<'a>

Source

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

Creates a new lexer state for the given input

§Arguments
  • input - The source code to tokenize
§Returns

A new LexerState object

Source

fn advance(&mut self) -> Option<char>

Advances to the next character in the input

§Arguments
  • state - The current lexer state
Source

fn peek(&mut self) -> Option<&char>

Peeks at the next character without consuming it

§Arguments
  • state - The current lexer state
Source

fn add_token(&mut self, token_type: Tokentype, lexeme: String, start_pos: usize)

Adds a token to the token list

§Arguments
  • state - The current lexer state
  • token_type - The type of token to add
  • lexeme - The string representation of the token
  • start_pos - The starting position of the token in the input
Source

fn add_error( &mut self, error_code: ErrorCode, message: String, start_pos: usize, token_length: Option<usize>, )

Adds an error to the error list

§Arguments
  • state - The current lexer state
  • error_code - The error code for this error
  • message - The error message
  • start_pos - The starting position of the error
  • token_length - The length of the problematic token
Source

fn record_line_break(&mut self)

Records a line break, updating line counts

§Arguments
  • state - The current lexer state
Source

fn finish(self) -> CompileResult<LexerResult<'a>>

Finishes tokenization and returns the result

§Arguments
  • state - The current lexer state

Auto Trait Implementations§

§

impl<'a> Freeze for LexerState<'a>

§

impl<'a> RefUnwindSafe for LexerState<'a>

§

impl<'a> Send for LexerState<'a>

§

impl<'a> Sync for LexerState<'a>

§

impl<'a> Unpin for LexerState<'a>

§

impl<'a> UnwindSafe for LexerState<'a>

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.