small fixes and cleaning up

removed debug statement from shell.rs
fixed casing for constants
added flag to make sure reading works correctly
This commit is contained in:
Schrottkatze 2021-12-21 08:05:02 +01:00
parent 73e7b1b7c7
commit 8e8d54c4b5
2 changed files with 11 additions and 7 deletions

View file

@ -1,9 +1,9 @@
use super::preprocessor::preprocess; use super::preprocessor::preprocess;
use super::token::Token; use super::token::Token;
const digits: &str = "0123456789"; const DIGITS: &str = "0123456789";
const alphabet: &str = "abcdefghijklmnopqrstuvwxyz"; const ALPHABET: &str = "abcdefghijklmnopqrstuvwxyz";
const alphabet_c: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const ALPHABET_C: &str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
pub struct Lexer { pub struct Lexer {
code: String, code: String,
@ -34,6 +34,7 @@ impl Lexer {
self.code = preprocess(self.code.clone()); self.code = preprocess(self.code.clone());
loop { loop {
let mut jump_next: bool = false;
let token: Option<Token> = match self.current { let token: Option<Token> = match self.current {
// SKIP OR BREAK // SKIP OR BREAK
Some(' ') => None, Some(' ') => None,
@ -50,7 +51,8 @@ impl Lexer {
// REST // REST
Some(c) => { Some(c) => {
if digits.contains(c) { if DIGITS.contains(c) {
jump_next = true;
Some(self.make_nr_token()) Some(self.make_nr_token())
} else { } else {
None None
@ -61,7 +63,9 @@ impl Lexer {
match token { match token {
Some(token) => { Some(token) => {
tokens.push(token); tokens.push(token);
self.next(); if !jump_next {
self.next();
}
}, },
None => self.next(), None => self.next(),
} }
@ -74,7 +78,7 @@ impl Lexer {
let mut nr: String = String::new(); let mut nr: String = String::new();
let mut dot_amount: u8 = 0; 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 self.current.unwrap() == '.' {
if dot_amount == 1 { if dot_amount == 1 {
panic!("Unexpected additional '.' in Number."); panic!("Unexpected additional '.' in Number.");
@ -83,6 +87,7 @@ impl Lexer {
} }
nr.push(self.current.unwrap()); nr.push(self.current.unwrap());
self.next(); self.next();
println!("{:?}", self.current.unwrap());
} }
if dot_amount == 1 { if dot_amount == 1 {

View file

@ -10,7 +10,6 @@ pub fn run_shell() {
} }
let mut lexer = Lexer::new(string); let mut lexer = Lexer::new(string);
lexer.tokenize(); lexer.tokenize();
//println!("{}", string);
} }
} }