[parser] ListParser can handle lists of more than 2 elements 😮

As ListParser sees items within its list, it assembles a vector of Pairs. When
the parser encounters ')', it assembles the pairs into an actual linked list and
returns the root Pair.

This work also revealed that I was asserting incorrectly in my single_pair test.
It should return Null instead of an empty Pair. Neat.

Closes #17.
This commit is contained in:
Eryn Wells 2018-08-26 22:24:17 -07:00
parent c02706e36f
commit c14c939ad3
2 changed files with 29 additions and 24 deletions

View file

@ -27,7 +27,7 @@ fn single_pair() {
let tokens = vec![Ok(Lex::new(Token::LeftParen, "(", 0, 0)),
Ok(Lex::new(Token::RightParen, ")", 0, 0))].into_iter();
let mut parser = Parser::new(tokens);
assert_eq!(parser.next(), Some(Ok(Obj::new(Pair::empty()))));
assert_eq!(parser.next(), Some(Ok(Obj::Null)));
assert_eq!(parser.next(), None);
}