pub trait Lexer<StorageT: Hash + PrimInt + Unsigned> {
fn next(&mut self) -> Option<Result<Lexeme<StorageT>, LexError>>;
fn lexeme_str(&self, _: &Lexeme<StorageT>) -> &str;
fn offset_line_col(&self, _: usize) -> (usize, usize);
fn all_lexemes(&mut self) -> Result<Vec<Lexeme<StorageT>>, LexError> { ... }
}
Expand description
Roughly speaking, Lexer
is an iterator which collectively produces Lexeme
s, as well as
collecting the newlines encountered so that it can later optionally answer queries of the form
“what’s the line and column number of lexeme L”.
Required Methods
sourcefn next(&mut self) -> Option<Result<Lexeme<StorageT>, LexError>>
fn next(&mut self) -> Option<Result<Lexeme<StorageT>, LexError>>
Return the next Lexeme
in the input or a LexError
. Returns None
if the input has been
fully lexed (or if an error occurred which prevents further lexing).
sourcefn lexeme_str(&self, _: &Lexeme<StorageT>) -> &str
fn lexeme_str(&self, _: &Lexeme<StorageT>) -> &str
Return the user input associated with a lexeme. Panics if the lexeme is invalid (i.e. was not produced by next()).
sourcefn offset_line_col(&self, _: usize) -> (usize, usize)
fn offset_line_col(&self, _: usize) -> (usize, usize)
Return the line and column number of a given offset. Panics if the offset exceeds the known input.