From 72a8791111d261c6874fc088bc4d97f10833fca7 Mon Sep 17 00:00:00 2001 From: Gabriel <68819302+obsidianical@users.noreply.github.com> Date: Fri, 7 Jan 2022 20:29:16 +0100 Subject: [PATCH] fuck floats imagine #[derive(Eq)] for anything that has a float anywhere... HAH --- .gitignore | 1 + src/error.rs | 0 src/main.rs | 1 + src/parsing/lexer.rs | 10 ++++++++-- src/parsing/mod.rs | 1 + src/parsing/parser.rs | 16 ++++++++++++++++ src/parsing/preprocessor.rs | 31 +++++++++++++++++++++++++++++++ 7 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/error.rs create mode 100644 src/parsing/parser.rs diff --git a/.gitignore b/.gitignore index de358ff..e2e4c2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target .vscode/ +.idea diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index 46bb143..60a9c2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,7 @@ fn main() { let file = fs::read_to_string(path).expect("Couldnt read file:"); let code = preprocess(file); + println!("{}", code); } } diff --git a/src/parsing/lexer.rs b/src/parsing/lexer.rs index f01ba0f..cf779f1 100644 --- a/src/parsing/lexer.rs +++ b/src/parsing/lexer.rs @@ -29,7 +29,7 @@ impl Lexer { }; } - pub fn tokenize(&mut self) { + pub fn tokenize(&mut self) -> Vec { let mut tokens: Vec = vec![]; self.code = preprocess(self.code.clone()); @@ -72,6 +72,7 @@ impl Lexer { } println!("{:?}", tokens); + tokens } fn make_nr_token(&mut self) -> Token { @@ -87,7 +88,6 @@ impl Lexer { } nr.push(self.current.unwrap()); self.next(); - println!("{:?}", self.current.unwrap()); } if dot_amount == 1 { @@ -97,3 +97,9 @@ impl Lexer { } } } + +#[test] +fn test_operators() { + let mut lexer = Lexer::new("+-*/".to_string()); + assert_eq!(lexer.tokenize(), vec![Token::ADD, Token::SUBTRACT, Token::MULTIPLY, Token::DIVIDE]); +} diff --git a/src/parsing/mod.rs b/src/parsing/mod.rs index 20299d9..6f98c7d 100644 --- a/src/parsing/mod.rs +++ b/src/parsing/mod.rs @@ -1,3 +1,4 @@ pub mod lexer; pub mod preprocessor; pub mod token; +pub mod parser; diff --git a/src/parsing/parser.rs b/src/parsing/parser.rs new file mode 100644 index 0000000..504f53d --- /dev/null +++ b/src/parsing/parser.rs @@ -0,0 +1,16 @@ +use super::token::Token; + +pub struct Parser { + tokens: Vec, +} + +impl Parser { + pub fn new(tokens: Vec) -> Parser { + Parser { + tokens + } + } + + fn analyze_math(&self, tokens: Vec) { + } +} diff --git a/src/parsing/preprocessor.rs b/src/parsing/preprocessor.rs index 0241f57..57edd5d 100644 --- a/src/parsing/preprocessor.rs +++ b/src/parsing/preprocessor.rs @@ -25,4 +25,35 @@ pub fn remove_empty_lines(text: String) -> String { out } +#[test] +fn test_preprocessor() { + let code = preprocess(" +&& line comment test + +¡<= ]] inline comment example [[ /\"inline comments work\"\\! + +`` + big ass block comment! + ye boiiiii +´´ + +&& declare variable out as string +¡}}string{{ out! + +&& take input and take it into var +¡=> /out\\! + +&& log out +¡<= /out\\! + + ".to_string()); + + println!("{:?}", code); + + assert_eq!(code, "\ +¡<= /\"inline comments work\"\\! +¡}}string{{ out! +¡=> /out\\! +¡<= /out\\!\n"); +}