From 1ef93c082bafd27b9e04e748ded174e30151826e Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Thu, 2 Jul 2020 15:54:33 -0400 Subject: [PATCH] allow != in variables --- src/parse/variable.rs | 14 ++++++++++---- tests/variables.rs | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/parse/variable.rs b/src/parse/variable.rs index 18b703d..89d98ea 100644 --- a/src/parse/variable.rs +++ b/src/parse/variable.rs @@ -155,19 +155,25 @@ impl<'a> Parser<'a> { } '!' => { let pos = tok.pos(); - if self.toks.peek_forward(1).is_none() { - return Err(("Expected identifier.", pos).into()); + match self.toks.peek_forward(1) { + Some(Token { kind: '=', .. }) => { + self.toks.reset_cursor(); + val_toks.push(self.toks.next().unwrap()); + continue; + } + Some(..) => {} + None => return Err(("Expected identifier.", pos).into()), } // todo: it should not be possible to declare the same flag more than once let mut ident = peek_ident_no_interpolation(self.toks, false, pos)?; ident.node.make_ascii_lowercase(); match ident.node.as_str() { "global" => { - self.toks.take(7).for_each(drop); + self.toks.truncate_iterator_to_cursor(); global = true; } "default" => { - self.toks.take(8).for_each(drop); + self.toks.truncate_iterator_to_cursor(); default = true; } "important" => { diff --git a/tests/variables.rs b/tests/variables.rs index b697a48..3046065 100644 --- a/tests/variables.rs +++ b/tests/variables.rs @@ -133,6 +133,11 @@ test!( "$a: red;\n\na {\n $a: green !\\67 lobal;\n}\n\na {\n color: $a;\n}\n", "a {\n color: green;\n}\n" ); +test!( + not_equal_in_variable_decl, + "$a: red != blue;\n\na {\n color: $a;\n}\n", + "a {\n color: true;\n}\n" +); error!(ends_with_bang, "$a: red !;", "Error: Expected identifier."); error!(unknown_flag, "$a: red !foo;", "Error: Invalid flag name."); error!(