reset to only read in file
This commit is contained in:
parent
f6fca262c6
commit
b37eee1fe1
|
@ -2,41 +2,6 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aho-corasick"
|
|
||||||
version = "0.7.20"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memchr"
|
|
||||||
version = "2.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex"
|
|
||||||
version = "1.7.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
|
|
||||||
dependencies = [
|
|
||||||
"aho-corasick",
|
|
||||||
"memchr",
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-syntax"
|
|
||||||
version = "0.6.28"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "skill-oxide"
|
name = "skill-oxide"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
|
||||||
"regex",
|
|
||||||
]
|
|
||||||
|
|
|
@ -6,4 +6,3 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
regex = "1"
|
|
||||||
|
|
|
@ -1,17 +1,8 @@
|
||||||
use std::{env, fs, io::Read};
|
use std::{env, fs, io::Read};
|
||||||
use regex::Regex;
|
|
||||||
use states::Tokenizer;
|
|
||||||
|
|
||||||
mod states;
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<String> = env::args().collect();
|
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 file = fs::File::open(args[1].as_str()).expect("msg");
|
||||||
let mut data = String::new();
|
let mut data = String::new();
|
||||||
file.read_to_string(&mut data).expect("msg");
|
|
||||||
|
|
||||||
let mut tokenizer = Tokenizer::new();
|
|
||||||
tokenizer.read_in(data);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue