fuck floats

imagine #[derive(Eq)] for anything that has a float anywhere... HAH
This commit is contained in:
Schrottkatze 2022-01-07 20:29:16 +01:00
parent 8e8d54c4b5
commit 72a8791111
7 changed files with 58 additions and 2 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
.vscode/
.idea

0
src/error.rs Normal file
View file

View file

@ -21,6 +21,7 @@ fn main() {
let file = fs::read_to_string(path).expect("Couldnt read file:");
let code = preprocess(file);
println!("{}", code);
}
}

View file

@ -29,7 +29,7 @@ impl Lexer {
};
}
pub fn tokenize(&mut self) {
pub fn tokenize(&mut self) -> Vec<Token> {
let mut tokens: Vec<Token> = 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]);
}

View file

@ -1,3 +1,4 @@
pub mod lexer;
pub mod preprocessor;
pub mod token;
pub mod parser;

16
src/parsing/parser.rs Normal file
View file

@ -0,0 +1,16 @@
use super::token::Token;
pub struct Parser {
tokens: Vec<Token>,
}
impl Parser {
pub fn new(tokens: Vec<Token>) -> Parser {
Parser {
tokens
}
}
fn analyze_math(&self, tokens: Vec<Token>) {
}
}

View file

@ -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");
}