simplified syntax rules

This commit is contained in:
Erin 2022-08-06 21:28:12 +02:00 committed by ondra05
parent a592cf80f2
commit cb20383f08

View file

@ -33,24 +33,22 @@ fn parser<'s>() -> impl Parser<Token<'s>, Vec<Spanned<Expr<'s>>>, Error = Simple
let list = list.map(Expr::List);
let quote = just(Token::Quote)
.ignore_then(expr)
.ignore_then(expr.clone())
.map(Box::new)
.map(Expr::Quote);
let without_pair = atom
let pair = expr
.clone()
.then_ignore(just(Token::Dot))
.then(expr)
.delimited_by(just(Token::LeftParen), just(Token::RightParen))
.map(|(l, r)| Expr::Pair((Box::new(l), Box::new(r))));
atom.or(pair)
.or(list)
.or(vector)
.or(quote)
.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)
.map_with_span(Spanned::new)
})
.repeated()
.then_ignore(end())