Added dotted pairs

main
ondra05 2022-07-26 19:45:50 +02:00
parent a42454026f
commit 7432f5097d
1 changed files with 13 additions and 3 deletions

View File

@ -29,7 +29,7 @@ fn parser<'a>() -> impl Parser<Token<'a>, Vec<Spanned<Expr<'a>>>, Error = Simple
let vector = just(Token::Octothrope)
.ignore_then(list.clone())
.map(Expr::Vector);
let list = list.map(Expr::List);
let quote = just(Token::Quote)
@ -37,10 +37,20 @@ fn parser<'a>() -> impl Parser<Token<'a>, Vec<Spanned<Expr<'a>>>, Error = Simple
.map(Box::new)
.map(Expr::Quote);
atom.or(list)
let without_pair = atom
.or(list)
.or(vector)
.or(quote)
.map_with_span(Spanned::new)
.map_with_span(Spanned::new);
let pair = without_pair
.clone()
.then_ignore(just(Token::Dot))
.then(without_pair.clone())
.map(|(l, r)| Expr::Pair((Box::new(l), Box::new(r))))
.map_with_span(Spanned::new);
pair.or(without_pair)
})
.repeated()
.then_ignore(end())