fix: list spread allowing no comma before spread

This commit is contained in:
rvcas 2022-10-03 17:00:26 -04:00 committed by Lucas
parent fb1ff759e1
commit 3ad915cafd
2 changed files with 11 additions and 8 deletions

View File

@ -8,7 +8,7 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, 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),

View File

@ -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(
.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 {