From 7fe9da3d2c5527aaad5093f57d2f869c6261ce60 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sat, 25 Jan 2020 10:11:46 -0500 Subject: [PATCH] Initial implementation of parens in `Value` --- src/lib.rs | 15 +++++++++++++++ src/value.rs | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6f5afcf..23c390f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1312,4 +1312,19 @@ mod test_values { "a {\n color: 1, 2, 3;\n}\n" ); test!(number, "a {\n color: 1;\n}\n"); + test!( + removes_paren_around_single_value, + "a {\n color: (red);\n}\n", + "a {\n color: red;\n}\n" + ); + test!( + removes_paren_around_space_list, + "a {\n color: (red blue);\n}\n", + "a {\n color: red blue;\n}\n" + ); + test!( + removes_paren_around_item_in_list, + "a {\n color: 1 (red blue);\n}\n", + "a {\n color: 1 red blue;\n}\n" + ); } diff --git a/src/value.rs b/src/value.rs index 74534ec..70dd20a 100644 --- a/src/value.rs +++ b/src/value.rs @@ -127,7 +127,7 @@ impl Display for Value { .join(sep.as_str()) ), Self::Color(c) => write!(f, "{}", c), - Self::Paren(val) => write!(f, "({})", val), + Self::Paren(val) => write!(f, "{}", val), Self::Ident(val, kind) => write!(f, "{}{}{}", kind.as_str(), val, kind.as_str()), Self::True => write!(f, "true"), Self::False => write!(f, "false"), @@ -165,6 +165,7 @@ impl Value { }; Some(Value::List(vec![left, right], ListSeparator::Comma)) } + TokenKind::Symbol(Symbol::CloseParen) => Some(left), TokenKind::Symbol(Symbol::Plus) => { toks.next(); devour_whitespace_or_comment(toks); @@ -222,6 +223,15 @@ impl Value { unit, )) } + TokenKind::Symbol(Symbol::OpenParen) => { + devour_whitespace_or_comment(toks); + let val = Self::from_tokens(toks, scope)?; + assert_eq!( + toks.next().unwrap().kind, + TokenKind::Symbol(Symbol::CloseParen) + ); + Some(Value::Paren(Box::new(val))) + } TokenKind::Ident(mut s) => { while let Some(tok) = toks.peek() { match tok.kind.clone() {