From 5bbf10b05f45fbe2e01484d5a7cfcc4b7212b048 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 29 Mar 2020 22:17:56 -0400 Subject: [PATCH] allow idents to begin with hyphen --- src/value/parse.rs | 26 +++++++++++++++++++++++--- tests/misc.rs | 13 ++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/value/parse.rs b/src/value/parse.rs index a279456..6741600 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -165,12 +165,10 @@ impl Value { )) } } - '+' | '-' | '*' | '%' => { + '+' | '*' | '%' => { let op = match next.kind { '+' => Op::Plus, - '-' => Op::Minus, '*' => Op::Mul, - '/' => Op::Div, '%' => Op::Rem, _ => unsafe { std::hint::unreachable_unchecked() }, }; @@ -215,6 +213,28 @@ impl Value { return Err("Expected \"important\".".into()); } } + '-' => { + toks.next(); + if devour_whitespace(toks) { + let right = Self::from_tokens(toks, scope, super_selector)?; + Ok(Value::BinaryOp(Box::new(left), Op::Minus, Box::new(right))) + } else { + let right = Self::from_tokens(toks, scope, super_selector)?; + if let Value::List(mut v, ListSeparator::Space, ..) = right { + let mut v2 = vec![left]; + let val = v.remove(0); + v2.push((-val)?); + v2.extend(v); + Ok(Value::List(v2, ListSeparator::Space, Brackets::None)) + } else { + Ok(Value::List( + vec![left, (-right)?], + ListSeparator::Space, + Brackets::None, + )) + } + } + } '/' => { toks.next(); match toks.peek().unwrap().kind { diff --git a/tests/misc.rs b/tests/misc.rs index c526133..dfccddb 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -71,8 +71,19 @@ test!( "@charset \"UTF-8\";\na {\n color: red😁;\n}\n" ); test!( - #[ignore] no_space_before_style, "a {\n color:red\n}\n", "a {\n color: red;\n}\n" ); +test!( + does_not_combine_idents_with_leading_hyphen, + "a {\n color: a -b;\n}\n" +); +test!( + does_not_combine_idents_with_leading_hyphen_list, + "a {\n color: a -b c;\n}\n" +); +test!( + does_not_combine_idents_with_leading_hyphen_all, + "a {\n color: -a -b -c;\n}\n" +);