parse comma separated lists (somewhat) properly

This commit is contained in:
ConnorSkees 2020-03-20 10:59:16 -04:00
parent ef480ad1f8
commit fb84361fae
3 changed files with 27 additions and 11 deletions

View File

@ -92,7 +92,13 @@ impl Value {
Ok(x) => x,
Err(_) => return Ok(left),
};
Ok(Value::List(vec![left, right], ListSeparator::Comma))
if let Value::List(v, ListSeparator::Comma) = right {
let mut v2 = vec![left];
v2.extend(v);
Ok(Value::List(v2, ListSeparator::Comma))
} else {
Ok(Value::List(vec![left, right], ListSeparator::Comma))
}
}
TokenKind::Symbol(Symbol::Plus)
| TokenKind::Symbol(Symbol::Minus)

20
tests/list.rs Normal file
View File

@ -0,0 +1,20 @@
#![cfg(test)]
#[macro_use]
mod macros;
test!(
length_of_list_as_var,
"$a: 1 2 3 4 5;a {\n color: length($a);\n}\n",
"a {\n color: 5;\n}\n"
);
test!(
length_of_list,
"a {\n color: length(1 2 3 4 5);\n}\n",
"a {\n color: 5;\n}\n"
);
test!(
length_of_comma_list,
"a {\n color: length((1, 2, 3, 4, 5));\n}\n",
"a {\n color: 5;\n}\n"
);

View File

@ -463,13 +463,3 @@ test!(
"a {\n color: (a b) - (1 2);\n}\n",
"a {\n color: a b-1 2;\n}\n"
);
test!(
length_of_list_as_var,
"$a: 1 2 3 4 5;a {\n color: length($a);\n}\n",
"a {\n color: 5;\n}\n"
);
test!(
length_of_list,
"a {\n color: length(1 2 3 4 5);\n}\n",
"a {\n color: 5;\n}\n"
);