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

View File

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