pub struct Lexer { /* private fields */ }Expand description
The main component of this crate, the lexer.
Implementations§
Source§impl Lexer
impl Lexer
Sourcepub fn with_input(self, input: &str) -> Lexer
pub fn with_input(self, input: &str) -> Lexer
Set the lexer’s input. Meant to be chained.
Sourcepub fn save_state(&self) -> State
pub fn save_state(&self) -> State
Save the current State. To be used with Lexer::set_state.
Sourcepub fn set_state(&mut self, state: State)
pub fn set_state(&mut self, state: State)
Set the current State. To be paired with Lexer::save_state.
Sourcepub fn next_token(&mut self) -> Token
pub fn next_token(&mut self) -> Token
Lex the next token. This will return any errors met while parsing the previous token before lexing a new one.
Sourcepub fn current_char(&self) -> Option<char>
pub fn current_char(&self) -> Option<char>
Get the current character.
Sourcepub fn consume(&mut self, character: char) -> bool
pub fn consume(&mut self, character: char) -> bool
Move the lexer after the current character if it matches the passed one, and return if it did so.
Sourcepub fn consume_with_next(&mut self, character: char) -> bool
pub fn consume_with_next(&mut self, character: char) -> bool
Like Lexer::consume but checks for the next character instead. Moves
the lexer after both the current and next character.
Sourcepub fn consume_identifier(&mut self) -> SmolStr
pub fn consume_identifier(&mut self) -> SmolStr
Consume the next identifier and return it. This assumes there’s at least one character to form a valid identifier at the current position,
Sourcepub fn skip_trivia(&mut self) -> Vec<Trivia>
pub fn skip_trivia(&mut self) -> Vec<Trivia>
Get the trivia after the current position and move the lexer to after them.
Sourcepub fn skip_whitespace(&mut self) -> SmolStr
pub fn skip_whitespace(&mut self) -> SmolStr
Get the whitespaces after the current positive and move the lexer to after them.
Methods from Deref<Target = State>§
Sourcepub fn increment_position_by_char(&mut self, character: char)
pub fn increment_position_by_char(&mut self, character: char)
Move the state by the passed character.
Sourcepub fn increment_position(&mut self, amount: u32)
pub fn increment_position(&mut self, amount: u32)
Move th state ahead by the passed amount of characters.
Sourcepub fn lexer_position(&self) -> Position
pub fn lexer_position(&self) -> Position
Get the current file position.