From 21ea78e57fa480d472d3660881e91813f7b18820 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Sun, 27 Mar 2022 22:20:06 +0200 Subject: ch5: added for loop --- src/lexer.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/lexer.rs') 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 @@ -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()); + } } -- cgit v1.2.3