about summary refs log tree commit diff
path: root/src/lex
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2021-10-20 22:15:08 +0200
committerMel <einebeere@gmail.com>2021-10-20 22:15:08 +0200
commita4980b8dbf1394c2b302f1de7c72d2264426b86e (patch)
tree97160332c53d8036ea3f6865ff60dabb2c55ef49 /src/lex
parent8d5a74566beba45f4642838102c5a066ef2aa18d (diff)
downloadrabbithole-a4980b8dbf1394c2b302f1de7c72d2264426b86e.tar.zst
rabbithole-a4980b8dbf1394c2b302f1de7c72d2264426b86e.zip
Statement parsing.
Diffstat (limited to 'src/lex')
-rw-r--r--src/lex/lexer.rs7
-rw-r--r--src/lex/token.rs10
2 files changed, 14 insertions, 3 deletions
diff --git a/src/lex/lexer.rs b/src/lex/lexer.rs
index 6e188a0..b6fee0d 100644
--- a/src/lex/lexer.rs
+++ b/src/lex/lexer.rs
@@ -181,10 +181,15 @@ impl<'s> Lexer<'s> {
 
         let variant = match buffer.as_str() {
             "fn" => TokenVariant::KeywordFn,
+            "if" => TokenVariant::KeywordIf,
+            "elif" => TokenVariant::KeywordElif,
+            "else" => TokenVariant::KeywordElse,
             "type" => TokenVariant::KeywordType,
             "form" => TokenVariant::KeywordForm,
             "self" => TokenVariant::KeywordSelf,
-            _ => TokenVariant::Identifier(buffer),
+            "return" => TokenVariant::KeywordReturn,
+            "print" => TokenVariant::KeywordPrint,
+            _ => TokenVariant::Ident(buffer),
         };
 
         Token { location, variant }
diff --git a/src/lex/token.rs b/src/lex/token.rs
index 3694525..efd4c5a 100644
--- a/src/lex/token.rs
+++ b/src/lex/token.rs
@@ -10,7 +10,7 @@ pub struct Token {
     pub variant: TokenVariant,
 }
 
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
 pub enum TokenVariant {
     // Basic math operators
     OpPlus,
@@ -45,13 +45,19 @@ pub enum TokenVariant {
     Int(u32),
     Float(f32),
     Str(String),
-    Identifier(String),
+
+    Ident(String),
 
     // Keywords
     KeywordFn,
+    KeywordIf,
+    KeywordElif,
+    KeywordElse,
     KeywordForm,
     KeywordType,
     KeywordSelf,
+    KeywordReturn,
+    KeywordPrint,
 
     Unknown(char),
     Eof,