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 list = list.map(Expr::List);
let quote = just(Token::Quote) let quote = just(Token::Quote)
.ignore_then(expr) .ignore_then(expr.clone())
.map(Box::new) .map(Box::new)
.map(Expr::Quote); .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(list)
.or(vector) .or(vector)
.or(quote) .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() .repeated()
.then_ignore(end()) .then_ignore(end())