resolve map parsing regression involving trailing commas in doubly nested maps

This commit is contained in:
Connor Skees 2020-08-07 20:10:49 -04:00
parent 56030f1292
commit a3a21928c0
2 changed files with 20 additions and 14 deletions

View File

@ -444,12 +444,9 @@ impl<'a> Parser<'a> {
&|c| matches!(c.peek(), Some(Token { kind: ':', .. }) | Some(Token { kind: ')', .. })),
)?;
match self.toks.peek() {
Some(Token { kind: ':', .. }) => {
self.toks.next();
}
match self.toks.next() {
Some(Token { kind: ':', .. }) => {}
Some(Token { kind: ')', .. }) => {
self.toks.next();
return Ok(Spanned {
node: IntermediateValue::Value(HigherIntermediateValue::Literal(key.node)),
span: key.span,
@ -509,18 +506,17 @@ impl<'a> Parser<'a> {
return Err(("Duplicate key.", key.span).into());
}
match self.toks.next() {
Some(Token { kind: ',', .. }) => {}
Some(Token { kind: ')', .. }) => {
break;
}
Some(..) | None => return Err(("expected \")\".", val.span).into()),
}
let found_comma = self.consume_char_if_exists(',');
self.whitespace_or_comment();
while self.consume_char_if_exists(',') {
self.whitespace_or_comment();
match self.toks.peek() {
Some(Token { kind: ')', .. }) => {
self.toks.next();
break;
}
Some(..) if found_comma => continue,
Some(..) | None => return Err(("expected \")\".", val.span).into()),
}
}
Ok(Spanned {

View File

@ -205,6 +205,16 @@ test!(
}",
"a {\n color: ();\n}\n"
);
test!(
trailing_comma_in_doubly_nested_map,
r#"$a: (
foo: (
a: b,
c: d,
)
);"#,
""
);
error!(
second_map_value_missing_colon,
"a {\n color: (a: b, c", "Error: expected \":\"."