reset to only read in file

This commit is contained in:
2023-03-11 15:51:45 +01:00
parent f6fca262c6
commit b37eee1fe1
4 changed files with 0 additions and 141 deletions
-9
View File
@@ -1,17 +1,8 @@
use std::{env, fs, io::Read};
use regex::Regex;
use states::Tokenizer;
mod states;
fn main() {
let args: Vec<String> = env::args().collect();
let re = Regex::new(r"((?P<comment>;)|(?P<word>\b\w+\b))").unwrap();
let mut file = fs::File::open(args[1].as_str()).expect("msg");
let mut data = String::new();
file.read_to_string(&mut data).expect("msg");
let mut tokenizer = Tokenizer::new();
tokenizer.read_in(data);
}
-96
View File
@@ -1,96 +0,0 @@
#[derive(Debug)]
pub enum CursorState {
Comment,
List,
Token,
Literal,
Operator
}
pub struct Token {
typ: CursorState,
content: Vec<Token>,
}
pub struct Tokenizer {
stateStack: Vec<CursorState>,
tokenTree: Vec<Token>,
}
impl Tokenizer {
pub fn new() -> Tokenizer {
Tokenizer {
stateStack: Vec::new(),
tokenTree: Vec::new(),
}
}
fn match_char(&mut self, c: char) {
match self.stateStack.last() {
None => match c {
c if c.is_whitespace() => {}
';' => {
self.stateStack.push(CursorState::Comment);
}
'(' => {
self.stateStack.push(CursorState::List);
}
c if c.is_alphanumeric() => {}
_ => {
println!("{}", c);
panic!("not a comment, list or symbol ");
}
},
Some(CursorState::Comment) => match c {
c if c.is_control() => {
self.stateStack.pop();
}
c if c.is_alphanumeric() => {}
c if c.is_whitespace() => {}
_ => {}
},
Some(CursorState::List) => match c {
'(' => {
self.stateStack.push(CursorState::List);
}
')' => {
self.stateStack.pop();
}
c if c.is_alphabetic() => {
self.stateStack.push(CursorState::Token);
}
c if c.is_numeric() => {
self.stateStack.push(CursorState::Literal);
}
'"' => {
self.stateStack.push(CursorState::Literal);
}
_ => {}
},
Some(CursorState::Token) => match c {
c if !c.is_alphanumeric() => {
self.stateStack.pop();
self.match_char(c);
}
_ => {}
},
Some(CursorState::Literal) => match c {
c if c.is_whitespace() => {
self.stateStack.pop();
}
'"' => {
self.stateStack.pop();
}
_ => {}
},
_ => {}
}
}
pub fn read_in(&mut self, content: String) {
for c in content.chars() {
self.match_char(c);
println!("{} -> {}: {:?}", c, self.stateStack.len(), self.stateStack.last().clone());
}
}
}