Fields
token: Token
Current Token
from the source.
quasi: &'arena str
Implementations
sourceimpl<'arena> Lexer<'arena>
impl<'arena> Lexer<'arena>
sourcepub fn new(arena: &'arena Arena, source: &str) -> Self
pub fn new(arena: &'arena Arena, source: &str) -> Self
Create a new Lexer
from source using an existing arena.
sourcepub unsafe fn from_ptr(ptr: *const u8) -> Self
pub unsafe fn from_ptr(ptr: *const u8) -> Self
Create a new Lexer
from a raw pointer to byte string.
The source must be null terminated! Passing a pointer that is not null terminated is undefined behavior!
The source must be valid UTF8! Passing a pointer to data that is not valid UTF8 will lead to bugs or undefined behavior.
sourcepub fn consume(&mut self)
pub fn consume(&mut self)
Advances the lexer, produces a new Token
and stores it on self.token
.
sourcepub fn token_as_str(&self) -> &'arena str
pub fn token_as_str(&self) -> &'arena str
Create an &str
slice from source spanning current token.
sourcepub fn accessor_as_str(&self) -> &'arena str
pub fn accessor_as_str(&self) -> &'arena str
Specialized version of token_as_str
that crates an &str
slice for the identifier following an accessor (.
).
sourcepub fn start_then_consume(&mut self) -> u32
pub fn start_then_consume(&mut self) -> u32
Get the start position of the current token, then advance the lexer.
sourcepub fn end_then_consume(&mut self) -> u32
pub fn end_then_consume(&mut self) -> u32
Get the end position of the current token, then advance the lexer.
sourcepub fn read_template_kind(&mut self)
pub fn read_template_kind(&mut self)
On top of being called when the opening backtick (`) of a template literal occurs, this method needs to be used by the parser while parsing a complex template string expression.
Note: Parser needs to expect a BraceClose token before calling this method to ensure that the tokenizer state is not corrupted.
pub fn invalid_token(&mut self) -> Error
sourcepub fn read_accessor(&mut self)
pub fn read_accessor(&mut self)
This is a specialized method that expects the next token to be an identifier, even if it would otherwise be a keyword.
This is useful when parsing member expressions such as foo.function
, where
function
is actually allowed as a regular identifier, not a keyword.
The perf gain here comes mainly from avoiding having to first match the &str
to a keyword token, and then match that token back to a &str
.