pub struct Parser<'a> { /* private fields */ }Expand description
The parser state.
Implementations§
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
Sourcepub fn over(source: &'a str, tokens: Vec<Token>) -> Self
pub fn over(source: &'a str, tokens: Vec<Token>) -> Self
A parser over an already-lexed stream.
The preprocessor produces one: its tokens index into text it assembled from every file that contributed, so the parser lexes nothing and reads spans into that text instead.
Sourcepub fn parse_file(self) -> Parse
pub fn parse_file(self) -> Parse
Parse the whole file.
Sourcepub fn current_span(&self) -> Span
pub fn current_span(&self) -> Span
Where the current token is.
Sourcepub fn current_text(&self) -> &str
pub fn current_text(&self) -> &str
The text of the current token.
Sourcepub fn bump(&mut self)
pub fn bump(&mut self)
Consume the current token into the tree, trivia first.
Trivia reaches the tree through Parser::emit_leading_trivia
and nowhere else, which is what keeps the round trip exact
without every rule having to think about it.
Sourcepub fn expect(&mut self, kind: TokenKind, what: &str) -> bool
pub fn expect(&mut self, kind: TokenKind, what: &str) -> bool
Consume kind, or diagnose that it was missing.
Does not consume anything on failure: the caller’s recovery decides what to skip.
Sourcepub fn checkpoint(&self) -> Checkpoint
pub fn checkpoint(&self) -> Checkpoint
Mark the current position, for wrapping already-emitted children.
Sourcepub fn start_at(&mut self, checkpoint: Checkpoint, kind: CstKind)
pub fn start_at(&mut self, checkpoint: Checkpoint, kind: CstKind)
Wrap everything since checkpoint in a node.
Sourcepub fn tokens_left(&self) -> usize
pub fn tokens_left(&self) -> usize
How many tokens are left.
Sourcepub fn split_shift_right(&mut self)
pub fn split_shift_right(&mut self)
Consume the first half of a >> token, leaving the second.
sequence<sequence<long>> ends in one token that closes two
argument lists. The tree records two > covering one source
token, so text() still reproduces the input. Spec §2.3.
Sourcepub fn diagnose(
&mut self,
code: DiagnosticCode,
message: &str,
spec_reference: &'static str,
)
pub fn diagnose( &mut self, code: DiagnosticCode, message: &str, spec_reference: &'static str, )
Record a diagnostic without consuming anything.
Sourcepub fn error_token(&mut self, message: &str)
pub fn error_token(&mut self, message: &str)
Wrap the current token in an error node and move past it.
Sourcepub fn recover_to_declaration(&mut self)
pub fn recover_to_declaration(&mut self)
Skip to the next place a declaration can begin.
Recovery points are ;, } and the top-level keywords. The
skipped range becomes an error node so the round trip holds.
Spec §3.2.
Sourcepub fn at_recovery_point(&self) -> bool
pub fn at_recovery_point(&self) -> bool
Whether the current token can begin a declaration.
Sourcepub fn diagnostics(&self) -> &[Diagnostic]
pub fn diagnostics(&self) -> &[Diagnostic]
The diagnostics gathered so far.