pub struct Parser<'run, 'src> { /* private fields */ }
Expand description
Just language parser
The parser is a (hopefully) straightforward recursive descent parser.
It uses a few tokens of lookahead to disambiguate different constructs.
The expect_*
and presume_
* methods are similar in that they assert the
type of unparsed tokens and consume them. However, upon encountering an
unexpected token, the expect_*
methods return an unexpected token error,
whereas the presume_*
tokens return an internal error.
The presume_*
methods are used when the token stream has been inspected in
some other way, and thus encountering an unexpected token is a bug in Just,
and not a syntax error.
All methods starting with parse_*
parse and return a language construct.
The parser tracks an expected set of tokens as it parses. This set contains all tokens which would have been accepted at the current point in the parse. Whenever the parser tests for a token that would be accepted, but does not find it, it adds that token to the set. When the parser accepts a token, the set is cleared. If the parser finds a token which is unexpected, the elements of the set are printed in the resultant error message.