pub struct Lexer<'t> {
pub(crate) path: Symbol,
pub(crate) text: &'t str,
pub(crate) iter: Peekable<CharIndices<'t>>,
pub(crate) head: u32,
pub(crate) 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 [struct@Span] of the current token.
When called from outside Lexer::scan, this will return a zero-sized span marking the current lexer location.
Sourcepub(crate) fn advance_tail(&mut self)
pub(crate) fn advance_tail(&mut self)
Advances the tail to the current character index
pub(crate) fn next_if(&mut self, expected: char) -> Option<char>
Sourcepub(crate) fn consume(&mut self) -> &mut Self
pub(crate) fn consume(&mut self) -> &mut Self
Consumes the last-peeked character, advancing the tail
Sourcepub(crate) const fn error(&self, res: LexFailure) -> LexError
pub(crate) const fn error(&self, res: LexFailure) -> LexError
Produces a LexError at the start of the current token
Sourcepub(crate) fn as_str(&self) -> (&'t str, Span)
pub(crate) fn as_str(&self) -> (&'t str, Span)
Gets the Lexer’s current &str lexeme and [struct@Span]
pub(crate) fn produce_with_lexeme( &mut self, kind: TKind, lexeme: Lexeme, ) -> Token
Sourcepub(crate) fn skip_whitespace(&mut self) -> &mut Self
pub(crate) fn skip_whitespace(&mut self) -> &mut Self
Consumes 0 or more whitespace
pub(crate) 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 trailing(&mut self, kind: TKind) -> Result<Token, LexError>
pub fn trailing(&mut self, kind: TKind) -> Result<Token, LexError>
Elides the trailing Token kind when it comes before a list terminator.
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) -> Result<Token, LexError>
pub fn character(&mut self) -> 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.