diff --git a/src/parse/value/parse.rs b/src/parse/value/parse.rs index 6eea8aa..d58bfd8 100644 --- a/src/parse/value/parse.rs +++ b/src/parse/value/parse.rs @@ -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 { diff --git a/tests/map.rs b/tests/map.rs index 5161c42..902b03b 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -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 \":\"."