simplify lookahead in variable flag parsing

This commit is contained in:
Connor Skees 2021-07-20 11:15:19 -04:00
parent 2969f08e43
commit 2ec365ddfc
3 changed files with 4 additions and 7 deletions

View File

@ -53,11 +53,6 @@ impl Lexer {
self.peek() 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 /// Set cursor to position and reset peek
pub fn set_cursor(&mut self, cursor: usize) { pub fn set_cursor(&mut self, cursor: usize) {
self.cursor = cursor; self.cursor = cursor;

View File

@ -132,11 +132,9 @@ impl<'a> Parser<'a> {
match flag.node.as_str() { match flag.node.as_str() {
"global" => { "global" => {
self.toks.truncate_iterator_to_cursor();
global = true; global = true;
} }
"default" => { "default" => {
self.toks.truncate_iterator_to_cursor();
default = true; default = true;
} }
_ => { _ => {

View File

@ -385,6 +385,10 @@ error!(
no_value_only_flag, no_value_only_flag,
"$a: !default;", "Error: Expected expression." "$a: !default;", "Error: Expected expression."
); );
error!(
variable_value_after_flag,
"$a: !default red;", "Error: Expected expression."
);
error!( error!(
uppercase_flag, uppercase_flag,
"$a: 1 !GLOBAL;", "Error: Invalid flag name." "$a: 1 !GLOBAL;", "Error: Invalid flag name."