From 2ec365ddfc738779285f350534e6923f8803d99f Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Tue, 20 Jul 2021 11:15:19 -0400 Subject: [PATCH] simplify lookahead in variable flag parsing --- src/lexer.rs | 5 ----- src/parse/variable.rs | 2 -- tests/variables.rs | 4 ++++ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index 5d95592..4b4fc2e 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -53,11 +53,6 @@ impl Lexer { self.peek() } - pub fn truncate_iterator_to_cursor(&mut self) { - self.cursor += self.amt_peeked; - self.amt_peeked = 0; - } - /// Set cursor to position and reset peek pub fn set_cursor(&mut self, cursor: usize) { self.cursor = cursor; diff --git a/src/parse/variable.rs b/src/parse/variable.rs index d6c4af5..8c592b1 100644 --- a/src/parse/variable.rs +++ b/src/parse/variable.rs @@ -132,11 +132,9 @@ impl<'a> Parser<'a> { match flag.node.as_str() { "global" => { - self.toks.truncate_iterator_to_cursor(); global = true; } "default" => { - self.toks.truncate_iterator_to_cursor(); default = true; } _ => { diff --git a/tests/variables.rs b/tests/variables.rs index 47a8e25..97bc66f 100644 --- a/tests/variables.rs +++ b/tests/variables.rs @@ -385,6 +385,10 @@ error!( no_value_only_flag, "$a: !default;", "Error: Expected expression." ); +error!( + variable_value_after_flag, + "$a: !default red;", "Error: Expected expression." +); error!( uppercase_flag, "$a: 1 !GLOBAL;", "Error: Invalid flag name."