about summary refs log tree commit diff
path: root/src/lex
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2021-11-21 14:52:50 +0100
committerMel <einebeere@gmail.com>2021-11-21 14:52:50 +0100
commitabaa72af8a1be00f3f84d7771a7994bfbbccf719 (patch)
treeb47edcef38cf7bdebae99428510b9fc8857f41bd /src/lex
parent395d086f0dce355ccdcf3da149c309826c539b48 (diff)
downloadrabbithole-abaa72af8a1be00f3f84d7771a7994bfbbccf719.tar.zst
rabbithole-abaa72af8a1be00f3f84d7771a7994bfbbccf719.zip
Rename all Variants to Kinds
Diffstat (limited to 'src/lex')
-rw-r--r--src/lex/lexer.rs62
-rw-r--r--src/lex/token.rs10
2 files changed, 36 insertions, 36 deletions
diff --git a/src/lex/lexer.rs b/src/lex/lexer.rs
index a4818fe..276702a 100644
--- a/src/lex/lexer.rs
+++ b/src/lex/lexer.rs
@@ -1,6 +1,6 @@
 use std::{collections::VecDeque, iter::Peekable, str::Chars};
 
-use super::token::{Location, Token, TokenVariant};
+use super::token::{Location, Token, TokenKind};
 
 pub struct Lexer<'source> {
     location: Location,
@@ -14,7 +14,7 @@ impl Iterator for Lexer<'_> {
     type Item = Token;
 
     fn next(&mut self) -> Option<Self::Item> {
-        use super::token::TokenVariant::*;
+        use super::token::TokenKind::*;
 
         if self.done {
             return None;
@@ -31,7 +31,7 @@ impl Iterator for Lexer<'_> {
             self.done = true;
             return Some(Token {
                 location: self.location,
-                variant: Eof,
+                kind: Eof,
             });
         }
 
@@ -47,7 +47,7 @@ impl Iterator for Lexer<'_> {
             let location = self.location;
 
             // Fixed length tokens
-            let variant = match self.advance().unwrap() {
+            let kind = match self.advance().unwrap() {
                 '+' => OpPlus,
                 '-' => {
                     if self.advance_if('>') {
@@ -119,7 +119,7 @@ impl Iterator for Lexer<'_> {
                 _ => Unknown(c),
             };
 
-            Token { location, variant }
+            Token { location, kind }
         };
 
         Some(token)
@@ -188,15 +188,15 @@ impl<'s> Lexer<'s> {
             buffer.push(c);
         }
 
-        let variant = if is_integer {
+        let kind = if is_integer {
             let int = buffer.parse().expect("Failed lexing integer token.");
-            TokenVariant::Int(int)
+            TokenKind::Int(int)
         } else {
             let float = buffer.parse().expect("Failed lexing float token.");
-            TokenVariant::Float(float)
+            TokenKind::Float(float)
         };
 
-        Token { location, variant }
+        Token { location, kind }
     }
 
     fn identifier(&mut self) -> Token {
@@ -209,25 +209,25 @@ impl<'s> Lexer<'s> {
             buffer.push(c);
         }
 
-        let variant = match buffer.as_str() {
-            "fn" => TokenVariant::KeywordFn,
-            "if" => TokenVariant::KeywordIf,
-            "elif" => TokenVariant::KeywordElif,
-            "else" => TokenVariant::KeywordElse,
-            "loop" => TokenVariant::KeywordLoop,
-            "type" => TokenVariant::KeywordType,
-            "form" => TokenVariant::KeywordForm,
-            "self" => TokenVariant::KeywordSelf,
-            "true" => TokenVariant::KeywordTrue,
-            "false" => TokenVariant::KeywordFalse,
-            "return" => TokenVariant::KeywordReturn,
-            "break" => TokenVariant::KeywordBreak,
-            "continue" => TokenVariant::KeywordContinue,
-            "print" => TokenVariant::KeywordPrint,
-            _ => TokenVariant::Ident(buffer),
+        let kind = match buffer.as_str() {
+            "fn" => TokenKind::KeywordFn,
+            "if" => TokenKind::KeywordIf,
+            "elif" => TokenKind::KeywordElif,
+            "else" => TokenKind::KeywordElse,
+            "loop" => TokenKind::KeywordLoop,
+            "type" => TokenKind::KeywordType,
+            "form" => TokenKind::KeywordForm,
+            "self" => TokenKind::KeywordSelf,
+            "true" => TokenKind::KeywordTrue,
+            "false" => TokenKind::KeywordFalse,
+            "return" => TokenKind::KeywordReturn,
+            "break" => TokenKind::KeywordBreak,
+            "continue" => TokenKind::KeywordContinue,
+            "print" => TokenKind::KeywordPrint,
+            _ => TokenKind::Ident(buffer),
         };
 
-        Token { location, variant }
+        Token { location, kind }
     }
 
     fn str(&mut self) -> Token {
@@ -247,7 +247,7 @@ impl<'s> Lexer<'s> {
                 if !str_buffer.is_empty() {
                     self.preempted.push_back(Token {
                         location: location_str,
-                        variant: TokenVariant::Str(str_buffer),
+                        kind: TokenKind::Str(str_buffer),
                     });
                 }
                 str_buffer = String::new();
@@ -265,7 +265,7 @@ impl<'s> Lexer<'s> {
         if !str_buffer.is_empty() {
             self.preempted.push_back(Token {
                 location: location_str,
-                variant: TokenVariant::Str(str_buffer),
+                kind: TokenKind::Str(str_buffer),
             });
         }
 
@@ -276,12 +276,12 @@ impl<'s> Lexer<'s> {
                 col: self.location.col - 1,
                 row: self.location.row,
             },
-            variant: TokenVariant::StrClose,
+            kind: TokenKind::StrClose,
         });
 
         Token {
             location: location_start,
-            variant: TokenVariant::StrOpen,
+            kind: TokenKind::StrOpen,
         }
     }
 
@@ -314,7 +314,7 @@ impl<'s> Lexer<'s> {
         // Finish embed
         self.preempted.push_back(Token {
             location: location_embed,
-            variant: TokenVariant::StrEmbed(embed_buffer),
+            kind: TokenKind::StrEmbed(embed_buffer),
         });
     }
 
diff --git a/src/lex/token.rs b/src/lex/token.rs
index c771b4a..f3dafa7 100644
--- a/src/lex/token.rs
+++ b/src/lex/token.rs
@@ -7,11 +7,11 @@ pub struct Location {
 #[derive(Clone, Debug)]
 pub struct Token {
     pub location: Location,
-    pub variant: TokenVariant,
+    pub kind: TokenKind,
 }
 
 #[derive(Clone, Debug, PartialEq)]
-pub enum TokenVariant {
+pub enum TokenKind {
     // Basic math operators
     OpPlus,
     OpMinus,
@@ -49,7 +49,7 @@ pub enum TokenVariant {
     // Literals
     Int(u32),
     Float(f32),
-    
+
     // String Literal Tokens
     Str(String),
     // StrOpen and StrClose are necessary for string embeds.
@@ -59,7 +59,7 @@ pub enum TokenVariant {
     StrClose,
     // The string embed has to be lexed by a *seperate* lexer.
     StrEmbed(String),
-    
+
     Ident(String),
 
     // Keywords
@@ -80,4 +80,4 @@ pub enum TokenVariant {
 
     Unknown(char),
     Eof,
-}
\ No newline at end of file
+}