From cb20383f0839e7ec471131aa9e724e151136b6af Mon Sep 17 00:00:00 2001 From: Erin Date: Sat, 6 Aug 2022 21:28:12 +0200 Subject: [PATCH] simplified syntax rules --- src/syntax/parser.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 7d1acf1..9ece3cb 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -33,24 +33,22 @@ fn parser<'s>() -> impl Parser, Vec>>, 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())