allow trailing commas

This commit is contained in:
ConnorSkees 2020-03-24 00:17:18 -04:00
parent 0ded248e1e
commit c29088b558
2 changed files with 37 additions and 1 deletions

View File

@ -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))

View File

@ -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"
);