made it cooler

This commit is contained in:
xomf 2024-05-26 18:18:01 -04:00
parent 9aa15dfbab
commit 93b1fe5979

View File

@ -1,4 +1,4 @@
use types::{token::Token, Loc}; use types::{token::Token, token::TokenType, Loc};
@ -25,8 +25,29 @@ impl Parser {
self.loc.line = 0; self.loc.line = 0;
self.chars = code.chars().collect(); self.chars = code.chars().collect();
self.chars.reverse();
// Parse here // Parse here :3
while let Some(c) = self.next() {
let typ = match c {
'+' => TokenType::Add,
'-' => TokenType::Sub,
'<' => TokenType::Left,
'>' => TokenType::Right,
'[' => TokenType::LoopL,
']' => TokenType::LoopR,
'.' => TokenType::Print,
',' => TokenType::Input,
_ => continue
};
self.tokens.push(Token {
typ,
loc: self.loc.clone()
});
}
Ok(()) Ok(())
} }