From 8518098e89f5d11a44a480a1ba6436c09ef09c27 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 26 Jul 2022 19:45:50 +0200 Subject: [PATCH] Added dotted pairs --- src/syntax/parser.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/syntax/parser.rs b/src/syntax/parser.rs index 07fb92e..c08cd5e 100644 --- a/src/syntax/parser.rs +++ b/src/syntax/parser.rs @@ -29,7 +29,7 @@ fn parser<'a>() -> impl Parser, Vec>>, 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, Vec>>, 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())