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::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<Token> = 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 {

View file

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