From fb84361fae0c796ac334157bccb8c8c57b4cbd56 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Fri, 20 Mar 2020 10:59:16 -0400 Subject: [PATCH] parse comma separated lists (somewhat) properly --- src/value/parse.rs | 8 +++++++- tests/list.rs | 20 ++++++++++++++++++++ tests/values.rs | 10 ---------- 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 tests/list.rs diff --git a/src/value/parse.rs b/src/value/parse.rs index f5e0928..525ea25 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -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) diff --git a/tests/list.rs b/tests/list.rs new file mode 100644 index 0000000..0dbe1c0 --- /dev/null +++ b/tests/list.rs @@ -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" +); diff --git a/tests/values.rs b/tests/values.rs index 0a8403b..5956b61 100644 --- a/tests/values.rs +++ b/tests/values.rs @@ -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" -);