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>
impl<'a> LexerState<'a>
Sourcefn add_token(&mut self, token_type: Tokentype, lexeme: String, start_pos: usize)
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 statetoken_type
- The type of token to addlexeme
- The string representation of the tokenstart_pos
- The starting position of the token in the input
Sourcefn add_error(
&mut self,
error_code: ErrorCode,
message: String,
start_pos: usize,
token_length: Option<usize>,
)
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 stateerror_code
- The error code for this errormessage
- The error messagestart_pos
- The starting position of the errortoken_length
- The length of the problematic token
Sourcefn record_line_break(&mut self)
fn record_line_break(&mut self)
Sourcefn finish(self) -> CompileResult<LexerResult<'a>>
fn finish(self) -> CompileResult<LexerResult<'a>>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more