Parsing
The Parse Function
Marwood's parser is a direct consumer of Vec<Token>
returned by the lexer.
parse::parse()
takes an iterator over &Token
, the original source &str that was supplied to lex::scan
, and returns a Cell
.
pub fn parse<'a, T: Iterator<Item = &'a Token>>(
text: &str,
cur: &mut Peekable<T>,
) -> Result<Cell, Error>
parse
will only consume one expression from cur
. If cur
may contain multiple expressions, the cursor position that parse
left off at can be used to determine the cursor position of the next expression.
For example, this scheme source contains five expressions and would require five separate calls to parse
.
1 2 3
(+ 1 2)(+ 3 4)
Error::Incomplete
Similarly to scan, parse() will return Error::Incomplete if the token stream does not contain a complete expression.
Some examples of incomplete expressions:
'(1 2 3
'(1 2 3)'(4 5
#(1 2 3)