pub struct Parser<'t> { /* private fields */ }Expand description
the parser state.
tokens is the lexer’s output (assumed to end in TokenKind::Eof, which
lexer::Lexer::tokenize guarantees). pos indexes into it. depth counts
active recursive productions for the stack-overflow guard. open_delims
stacks the still-open opener tokens and their spans: on a delimiter
mismatch the innermost (top) is blamed – its span is the error’s span,
per the “blame the opener” rule.
Implementations§
Source§impl<'t> Parser<'t>
impl<'t> Parser<'t>
Sourcepub fn parse(tokens: &'t [Token]) -> Result<Ast, QalaError>
pub fn parse(tokens: &'t [Token]) -> Result<Ast, QalaError>
parse a token stream into an untyped Ast, or return the first
syntax error.
the input is expected to be a well-formed token stream ending in
TokenKind::Eof (what crate::lexer::Lexer::tokenize produces).
an empty program (just [Eof]) parses to an empty item list with no
error. fail-fast: the first parse error stops the parse and is
returned; later errors are not collected.
Sourcepub fn parse_expr(&mut self) -> Result<Expr, QalaError>
pub fn parse_expr(&mut self) -> Result<Expr, QalaError>
parse a single expression at the loosest precedence. a thin alias for
expr_bp(0, ExprCtx::Normal); statements call this to read the leaves
of the grammar.