diff --git a/bfox-parser/src/lib.rs b/bfox-parser/src/lib.rs index 03806f6..67fc0ec 100644 --- a/bfox-parser/src/lib.rs +++ b/bfox-parser/src/lib.rs @@ -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.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(()) }