From c29088b558582af099a239dc17f78201f17dc7cb Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 24 Mar 2020 00:17:18 -0400 Subject: [PATCH] allow trailing commas --- src/value/parse.rs | 23 ++++++++++++++++++++++- tests/list.rs | 15 +++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/value/parse.rs b/src/value/parse.rs index 711f57b..83a275d 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -88,6 +88,27 @@ impl Value { TokenKind::Symbol(Symbol::Comma) => { toks.next(); devour_whitespace_or_comment(toks); + if toks.peek() == None { + return Ok(Value::List( + vec![left], + ListSeparator::Comma, + Brackets::None, + )); + } else if let Some(tok) = toks.peek() { + if tok.is_symbol(Symbol::CloseParen) { + return Ok(Value::List( + vec![left], + ListSeparator::Comma, + Brackets::None, + )); + } else if tok.is_symbol(Symbol::CloseSquareBrace) { + return Ok(Value::List( + vec![left], + ListSeparator::Comma, + Brackets::Bracketed, + )); + } + } let right = Self::from_tokens(toks, scope, super_selector)?; if let Value::List(v, ListSeparator::Comma, Brackets::None) = right { let mut v2 = vec![left]; @@ -124,7 +145,7 @@ impl Value { _ => { devour_whitespace_or_comment(toks); let right = Self::from_tokens(toks, scope, super_selector)?; - if let Value::List(v, ListSeparator::Space, Brackets::None) = right { + if let Value::List(v, ListSeparator::Space, ..) = right { let mut v2 = vec![left]; v2.extend(v); Ok(Value::List(v2, ListSeparator::Space, Brackets::None)) diff --git a/tests/list.rs b/tests/list.rs index c0d7328..f32c415 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -149,3 +149,18 @@ test!(bracketed_ident, "a {\n color: [a];\n}\n"); test!(bracketed_space_list, "a {\n color: [a b];\n}\n"); test!(bracketed_comma_list, "a {\n color: [a, b];\n}\n"); test!(bracketed_as_space_list, "a {\n color: [a b] c;\n}\n"); +test!( + trailing_comma_bare, + "a {\n color: 1,;\n}\n", + "a {\n color: 1;\n}\n" +); +test!( + trailing_comma_paren, + "a {\n color: (1,);\n}\n", + "a {\n color: 1;\n}\n" +); +test!( + trailing_comma_bracket, + "a {\n color: [1,];\n}\n", + "a {\n color: [1];\n}\n" +);