diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2021-10-04 22:51:42 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2021-10-04 22:51:42 +0200 |
commit | 4f6dd49df3f19204694fcea55f38efd9c5118bf2 (patch) | |
tree | 119d4fa88f6f744ecdb1eb9a833c316f5932b0c1 /src/lexer.rs | |
parent | a3dee93989b9fdd99b8a22a2da7f72bcd2ba50c2 (diff) | |
download | llvm-kaleidoscope-rs-4f6dd49df3f19204694fcea55f38efd9c5118bf2.tar.gz llvm-kaleidoscope-rs-4f6dd49df3f19204694fcea55f38efd9c5118bf2.zip |
ch5: added if/then/else
Diffstat (limited to 'src/lexer.rs')
-rw-r--r-- | src/lexer.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/lexer.rs b/src/lexer.rs index a25f0ab..fdab5b4 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -6,6 +6,9 @@ pub enum Token { Identifier(String), Number(f64), Char(char), + If, + Then, + Else, } pub struct Lexer<I> @@ -62,6 +65,9 @@ where match ident.as_ref() { "def" => return Token::Def, "extern" => return Token::Extern, + "if" => return Token::If, + "then" => return Token::Then, + "else" => return Token::Else, _ => {} } @@ -178,4 +184,12 @@ mod test { assert_eq!(Token::Identifier("c".into()), lex.gettok()); assert_eq!(Token::Eof, lex.gettok()); } + + #[test] + fn test_ite() { + let mut lex = Lexer::new("if then else".chars()); + assert_eq!(Token::If, lex.gettok()); + assert_eq!(Token::Then, lex.gettok()); + assert_eq!(Token::Else, lex.gettok()); + } } |