From 31fd8f81274245c338d1dd4d0d54cc1871ed8f56 Mon Sep 17 00:00:00 2001 From: ConnorSkees <39542938+ConnorSkees@users.noreply.github.com> Date: Sun, 5 Jan 2020 19:10:43 -0500 Subject: [PATCH] Stop infinite loop when lexing variables --- src/lexer.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index 61ddb11..5e7788d 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -94,6 +94,8 @@ impl<'a> Lexer<'a> { if !is_whitespace(*c) { break; } + self.buf.next(); + self.pos.next_char(); } } @@ -282,7 +284,9 @@ impl<'a> Lexer<'a> { } fn lex_variable(&mut self) -> TokenKind { - let mut string = String::with_capacity(99); + self.buf.next(); + self.pos.next_char(); + let mut name = String::with_capacity(99); while let Some(c) = self.buf.peek() { if !c.is_alphabetic() && c != &'-' { break; @@ -292,9 +296,9 @@ impl<'a> Lexer<'a> { .next() .expect("this is impossible because we have already peeked"); self.pos.next_char(); - string.push(tok); + name.push(tok); } - TokenKind::Variable(string) + TokenKind::Variable(name) } fn lex_ident(&mut self) -> TokenKind {