pub struct Lexer<'a> { /* private fields */ }Expand description
A streaming lexer over one source text.
Clone is implemented deliberately: the parser snapshots the lexer to
backtrack (arrow-function cover grammar), and cloning is a handful of words.
Implementations§
Source§impl<'a> Lexer<'a>
impl<'a> Lexer<'a>
Sourcepub fn set_strict(&mut self, strict: bool)
pub fn set_strict(&mut self, strict: bool)
Enable strict-mode lexical rules (octal escapes become syntax errors).
Sourcepub fn had_legacy_octal(&self) -> bool
pub fn had_legacy_octal(&self) -> bool
Whether the token most recently returned by Lexer::next_token
contained an Annex B legacy octal escape ("\101").
The flag is reset by every next_token call, so it always describes the
token currently held by the caller. The parser uses it because strictness
is only known once the directive prologue has been read, which happens
after the offending literal was already scanned.
Sourcepub fn legacy_octal_count(&self) -> u64
pub fn legacy_octal_count(&self) -> u64
How many legacy octal escapes have been scanned since [Lexer::reset_mode].
A counter rather than a flag because the same question is asked at two scopes: a function body starts its own count so that its own escapes are separable from the enclosing function’s.
Sourcepub fn reset_legacy_octal_count(&mut self)
pub fn reset_legacy_octal_count(&mut self)
Begin a fresh legacy-escape count, for a scope that is about to parse its own body.
Sourcepub fn next_token(&mut self) -> Result<Token>
pub fn next_token(&mut self) -> Result<Token>
Scan the next token.
Sourcepub fn tokenize(self) -> Result<Vec<Token>>
pub fn tokenize(self) -> Result<Vec<Token>>
Scan every remaining token (tests and tooling; the parser drives the lexer one token at a time).
Sourcepub fn re_scan_template_continue(&mut self, brace: Position) -> Result<Token>
pub fn re_scan_template_continue(&mut self, brace: Position) -> Result<Token>
Resume a template literal after the } closing a substitution.
brace is the position of that } (the parser keeps the token span).
Sourcepub fn re_scan_regex(&mut self, start: Position) -> Result<Token>
pub fn re_scan_regex(&mut self, start: Position) -> Result<Token>
Re-scan the token starting at start (the /) as a regular expression
literal. Called by the parser when it expects an expression.