From 4607163a62addd360cf49bfdae724434dd7cc622 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Tue, 21 Apr 2020 15:44:22 -0400 Subject: [PATCH] more robustly handle - as start of identifier --- README.md | 1 + src/value/parse.rs | 20 +++++++------------- tests/null.rs | 5 +++++ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 0b7a27b..b408f3e 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ a special parser for plain css @forward (~400 tests) @keyframes (~30 tests) @supports (~128 tests) +aribtrary control flow in @function and @mixin ``` To run the official test suite, diff --git a/src/value/parse.rs b/src/value/parse.rs index 1134239..fe23359 100644 --- a/src/value/parse.rs +++ b/src/value/parse.rs @@ -245,12 +245,6 @@ fn eat_op>( Op::Minus => { if devour_whitespace(iter) || !last_was_whitespace { let right = single_value(iter, scope, super_selector, op.span)?; - if !last_was_whitespace && right.node == Value::Null { - space_separated.push( - right.map_node(|_| Value::Ident("-null".to_string(), QuoteKind::None)), - ); - return Ok(()); - } if let Some(left) = space_separated.pop() { space_separated.push(Spanned { node: Value::BinaryOp(Box::new(left.node), op.node, Box::new(right.node)), @@ -261,12 +255,6 @@ fn eat_op>( } } else { let right = single_value(iter, scope, super_selector, op.span)?; - if right.node == Value::Null { - space_separated.push( - right.map_node(|_| Value::Ident("-null".to_string(), QuoteKind::None)), - ); - return Ok(()); - } space_separated.push(right.map_node(|n| Value::UnaryOp(op.node, Box::new(n)))); } } @@ -601,6 +589,11 @@ impl Value { Some(v) => (v.kind, v.pos()), None => panic!("unexpected eof"), }; + + let next_is_hypen = |toks: &mut PeekMoreIterator| { + toks.peek_forward(1).is_some() + && matches!(toks.peek().unwrap().kind, '-' | '_' | 'a'..='z' | 'A'..='Z') + }; match kind { ',' => { toks.next(); @@ -689,7 +682,8 @@ impl Value { _ if kind.is_ascii_alphabetic() || kind == '_' || kind == '\\' - || (!kind.is_ascii() && !kind.is_control()) => + || (!kind.is_ascii() && !kind.is_control()) + || (kind == '-' && next_is_hypen(toks)) => { Self::ident(toks, scope, super_selector) } diff --git a/tests/null.rs b/tests/null.rs index e3d3cf8..bc155d7 100644 --- a/tests/null.rs +++ b/tests/null.rs @@ -28,3 +28,8 @@ test!( "a {\n color: [null null null];\n}\n", "" ); +test!( + negative_null_in_var, + "a {\n $x: null;\n color: -$x;\n}\n", + "a {\n color: -;\n}\n" +);