pub struct Lexer<'t> {
path: Symbol,
text: &'t str,
iter: Peekable<CharIndices<'t>>,
head: u32,
tail: u32,
}Fields§
§path: Symbol§text: &'t strThe source text
iter: Peekable<CharIndices<'t>>A peekable iterator over the source text
head: u32The start of the current token
tail: u32The end of the current token
Implementations§
Source§impl<'t> Lexer<'t>
impl<'t> Lexer<'t>
Sourcepub const fn span(&self) -> Span
pub const fn span(&self) -> Span
Gets the Span of the current token.
When called from outside Lexer::scan, this will return a zero-length Span marking the current lexer location.
Sourcefn advance_tail(&mut self)
fn advance_tail(&mut self)
Advances the tail to the current character index
Sourcefn next_if(&mut self, expected: char) -> Option<char>
fn next_if(&mut self, expected: char) -> Option<char>
Takes the next character if it matches expected, else returns None.
Sourceconst fn error(&self, res: LexFailure) -> LexError
const fn error(&self, res: LexFailure) -> LexError
Produces a LexError at the start of the current token
fn produce_with_lexeme(&mut self, kind: TKind, lexeme: Lexeme) -> Token
Sourcefn skip_whitespace(&mut self) -> &mut Self
fn skip_whitespace(&mut self) -> &mut Self
Consumes 0 or more whitespace
Sourceconst fn start_token(&mut self) -> &mut Self
const fn start_token(&mut self) -> &mut Self
Sourcepub fn scan(&mut self) -> Result<Token, LexError>
pub fn scan(&mut self) -> Result<Token, LexError>
Scans forward until it finds the next Token in the input
Sourcepub fn line_comment(&mut self) -> Result<Token, LexError>
pub fn line_comment(&mut self) -> Result<Token, LexError>
Consumes characters until the lexer reaches a newline '\n'
Sourcepub fn block_comment(&mut self) -> Result<&mut Self, LexError>
pub fn block_comment(&mut self) -> Result<&mut Self, LexError>
Consumes characters until the lexer reaches the end of a nested block comment. This allows you to arbitrarily comment out code, even if that code has a block comment.
Sourcepub fn identifier(&mut self) -> Result<Token, LexError>
pub fn identifier(&mut self) -> Result<Token, LexError>
Consumes characters until it reaches a character not in is_xid_continue.
Always consumes the first character.
Maps the result to either a TKind::Identifier or a TKind keyword.
Sourcepub fn character(&mut self, as_int: bool) -> Result<Token, LexError>
pub fn character(&mut self, as_int: bool) -> Result<Token, LexError>
Eagerly parses a character literal starting at the current lexer position.
pub fn string(&mut self) -> Result<Token, LexError>
Sourcepub fn escape(&mut self) -> Result<char, LexError>
pub fn escape(&mut self) -> Result<char, LexError>
Parses a single escape sequence into its resulting char value.
Sourcepub fn hex_escape(&mut self) -> Result<char, LexError>
pub fn hex_escape(&mut self) -> Result<char, LexError>
Parses two hex-digits and constructs a char out of them.
Sourcepub fn unicode_escape(&mut self) -> Result<char, LexError>
pub fn unicode_escape(&mut self) -> Result<char, LexError>
Parses a sequence of {}-bracketed hex-digits and constructs a char out of them.