allow trailing commas
This commit is contained in:
parent
0ded248e1e
commit
c29088b558
@ -88,6 +88,27 @@ impl Value {
|
|||||||
TokenKind::Symbol(Symbol::Comma) => {
|
TokenKind::Symbol(Symbol::Comma) => {
|
||||||
toks.next();
|
toks.next();
|
||||||
devour_whitespace_or_comment(toks);
|
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)?;
|
let right = Self::from_tokens(toks, scope, super_selector)?;
|
||||||
if let Value::List(v, ListSeparator::Comma, Brackets::None) = right {
|
if let Value::List(v, ListSeparator::Comma, Brackets::None) = right {
|
||||||
let mut v2 = vec![left];
|
let mut v2 = vec![left];
|
||||||
@ -124,7 +145,7 @@ impl Value {
|
|||||||
_ => {
|
_ => {
|
||||||
devour_whitespace_or_comment(toks);
|
devour_whitespace_or_comment(toks);
|
||||||
let right = Self::from_tokens(toks, scope, super_selector)?;
|
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];
|
let mut v2 = vec![left];
|
||||||
v2.extend(v);
|
v2.extend(v);
|
||||||
Ok(Value::List(v2, ListSeparator::Space, Brackets::None))
|
Ok(Value::List(v2, ListSeparator::Space, Brackets::None))
|
||||||
|
@ -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_space_list, "a {\n color: [a b];\n}\n");
|
||||||
test!(bracketed_comma_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!(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"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user