fix: list spread allowing no comma before spread
This commit is contained in:
parent
fb1ff759e1
commit
3ad915cafd
|
@ -8,7 +8,7 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = ParseError> {
|
||||||
let op = choice((
|
let op = choice((
|
||||||
just("==").to(Token::EqualEqual),
|
just("==").to(Token::EqualEqual),
|
||||||
just('=').to(Token::Equal),
|
just('=').to(Token::Equal),
|
||||||
just("..").to(Token::Dot),
|
just("..").to(Token::DotDot),
|
||||||
just('.').to(Token::Dot),
|
just('.').to(Token::Dot),
|
||||||
just("!=").to(Token::NotEqual),
|
just("!=").to(Token::NotEqual),
|
||||||
just('!').to(Token::Bang),
|
just('!').to(Token::Bang),
|
||||||
|
|
|
@ -326,13 +326,16 @@ pub fn expr_parser(
|
||||||
});
|
});
|
||||||
|
|
||||||
let list_parser = just(Token::LeftSquare)
|
let list_parser = just(Token::LeftSquare)
|
||||||
.ignore_then(r.clone().separated_by(just(Token::Comma)).allow_trailing())
|
.ignore_then(r.clone().separated_by(just(Token::Comma)))
|
||||||
.then(
|
.then(choice((
|
||||||
just(Token::DotDot)
|
just(Token::Comma).ignore_then(
|
||||||
.ignore_then(r.clone())
|
just(Token::DotDot)
|
||||||
.map(Box::new)
|
.ignore_then(r.clone())
|
||||||
.or_not(),
|
.map(Box::new)
|
||||||
)
|
.or_not(),
|
||||||
|
),
|
||||||
|
just(Token::Comma).ignored().or_not().map(|_| None),
|
||||||
|
)))
|
||||||
.then_ignore(just(Token::RightSquare))
|
.then_ignore(just(Token::RightSquare))
|
||||||
// TODO: check if tail.is_some and elements.is_empty then return ListSpreadWithoutElements error
|
// TODO: check if tail.is_some and elements.is_empty then return ListSpreadWithoutElements error
|
||||||
.map_with_span(|(elements, tail), span| expr::UntypedExpr::List {
|
.map_with_span(|(elements, tail), span| expr::UntypedExpr::List {
|
||||||
|
|
Loading…
Reference in New Issue