From 3ad915cafd8b0726460078720c40d2c589d98c30 Mon Sep 17 00:00:00 2001 From: rvcas Date: Mon, 3 Oct 2022 17:00:26 -0400 Subject: [PATCH] fix: list spread allowing no comma before spread --- crates/lang/src/lexer.rs | 2 +- crates/lang/src/parser.rs | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/lang/src/lexer.rs b/crates/lang/src/lexer.rs index 75d2ddba..431b532f 100644 --- a/crates/lang/src/lexer.rs +++ b/crates/lang/src/lexer.rs @@ -8,7 +8,7 @@ pub fn lexer() -> impl Parser, Error = ParseError> { let op = choice(( just("==").to(Token::EqualEqual), just('=').to(Token::Equal), - just("..").to(Token::Dot), + just("..").to(Token::DotDot), just('.').to(Token::Dot), just("!=").to(Token::NotEqual), just('!').to(Token::Bang), diff --git a/crates/lang/src/parser.rs b/crates/lang/src/parser.rs index ce91c04c..bbbf04eb 100644 --- a/crates/lang/src/parser.rs +++ b/crates/lang/src/parser.rs @@ -326,13 +326,16 @@ pub fn expr_parser( }); let list_parser = just(Token::LeftSquare) - .ignore_then(r.clone().separated_by(just(Token::Comma)).allow_trailing()) - .then( - just(Token::DotDot) - .ignore_then(r.clone()) - .map(Box::new) - .or_not(), - ) + .ignore_then(r.clone().separated_by(just(Token::Comma))) + .then(choice(( + just(Token::Comma).ignore_then( + just(Token::DotDot) + .ignore_then(r.clone()) + .map(Box::new) + .or_not(), + ), + just(Token::Comma).ignored().or_not().map(|_| None), + ))) .then_ignore(just(Token::RightSquare)) // TODO: check if tail.is_some and elements.is_empty then return ListSpreadWithoutElements error .map_with_span(|(elements, tail), span| expr::UntypedExpr::List {