aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/lexer.rs
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2022-03-27 22:20:06 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2022-03-27 22:20:06 +0200
commit21ea78e57fa480d472d3660881e91813f7b18820 (patch)
tree476b2721ba44d41d9b2faf003701fdc647c9259e /src/lexer.rs
parent4f6dd49df3f19204694fcea55f38efd9c5118bf2 (diff)
downloadllvm-kaleidoscope-rs-21ea78e57fa480d472d3660881e91813f7b18820.tar.gz
llvm-kaleidoscope-rs-21ea78e57fa480d472d3660881e91813f7b18820.zip
ch5: added for loop
Diffstat (limited to 'src/lexer.rs')
-rw-r--r--src/lexer.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/lexer.rs b/src/lexer.rs
index fdab5b4..365b8bf 100644
--- a/src/lexer.rs
+++ b/src/lexer.rs
@@ -9,6 +9,8 @@ pub enum Token {
If,
Then,
Else,
+ For,
+ In,
}
pub struct Lexer<I>
@@ -68,6 +70,8 @@ where
"if" => return Token::If,
"then" => return Token::Then,
"else" => return Token::Else,
+ "for" => return Token::For,
+ "in" => return Token::In,
_ => {}
}
@@ -192,4 +196,11 @@ mod test {
assert_eq!(Token::Then, lex.gettok());
assert_eq!(Token::Else, lex.gettok());
}
+
+ #[test]
+ fn test_for() {
+ let mut lex = Lexer::new("for in".chars());
+ assert_eq!(Token::For, lex.gettok());
+ assert_eq!(Token::In, lex.gettok());
+ }
}