From 8e8d54c4b55e379cd4e11b575735288ef7c4069c Mon Sep 17 00:00:00 2001 From: Gabriel <68819302+obsidianical@users.noreply.github.com> Date: Tue, 21 Dec 2021 08:05:02 +0100 Subject: [PATCH] small fixes and cleaning up removed debug statement from shell.rs fixed casing for constants added flag to make sure reading works correctly --- src/parsing/lexer.rs | 17 +++++++++++------ src/shell.rs | 1 - 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/parsing/lexer.rs b/src/parsing/lexer.rs index 88860c4..f01ba0f 100644 --- a/src/parsing/lexer.rs +++ b/src/parsing/lexer.rs @@ -1,9 +1,9 @@ use super::preprocessor::preprocess; use super::token::Token; -const digits: &str = "0123456789"; -const alphabet: &str = "abcdefghijklmnopqrstuvwxyz"; -const alphabet_c: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +const DIGITS: &str = "0123456789"; +const ALPHABET: &str = "abcdefghijklmnopqrstuvwxyz"; +const ALPHABET_C: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; pub struct Lexer { code: String, @@ -34,6 +34,7 @@ impl Lexer { self.code = preprocess(self.code.clone()); loop { + let mut jump_next: bool = false; let token: Option = match self.current { // SKIP OR BREAK Some(' ') => None, @@ -50,7 +51,8 @@ impl Lexer { // REST Some(c) => { - if digits.contains(c) { + if DIGITS.contains(c) { + jump_next = true; Some(self.make_nr_token()) } else { None @@ -61,7 +63,9 @@ impl Lexer { match token { Some(token) => { tokens.push(token); - self.next(); + if !jump_next { + self.next(); + } }, None => self.next(), } @@ -74,7 +78,7 @@ impl Lexer { let mut nr: String = String::new(); let mut dot_amount: u8 = 0; - while (self.current != None) && (digits.contains(self.current.unwrap()) || self.current.unwrap() == '.') { + while (self.current != None) && (DIGITS.contains(self.current.unwrap()) || self.current.unwrap() == '.') { if self.current.unwrap() == '.' { if dot_amount == 1 { panic!("Unexpected additional '.' in Number."); @@ -83,6 +87,7 @@ impl Lexer { } nr.push(self.current.unwrap()); self.next(); + println!("{:?}", self.current.unwrap()); } if dot_amount == 1 { diff --git a/src/shell.rs b/src/shell.rs index e2d566f..4d4f0c6 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -10,7 +10,6 @@ pub fn run_shell() { } let mut lexer = Lexer::new(string); lexer.tokenize(); - //println!("{}", string); } }