about summary refs log tree commit diff
path: root/src/parse
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/parse
parent395d086f0dce355ccdcf3da149c309826c539b48 (diff)
downloadrabbithole-abaa72af8a1be00f3f84d7771a7994bfbbccf719.tar.zst
rabbithole-abaa72af8a1be00f3f84d7771a7994bfbbccf719.zip
Rename all Variants to Kinds
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/ast/nodes.rs16
-rw-r--r--src/parse/macros.rs22
-rw-r--r--src/parse/parser.rs14
3 files changed, 26 insertions, 26 deletions
diff --git a/src/parse/ast/nodes.rs b/src/parse/ast/nodes.rs
index c4bb1e8..16d0eaa 100644
--- a/src/parse/ast/nodes.rs
+++ b/src/parse/ast/nodes.rs
@@ -1,4 +1,4 @@
-use crate::lex::token::{Token, TokenVariant::*};
+use crate::lex::token::{Token, TokenKind::*};
 
 use super::{expression::Expression, statement::Statement};
 
@@ -23,7 +23,7 @@ pub enum BinaryOperator {
 
 impl BinaryOperator {
     pub fn from_token(token: Token) -> Self {
-        match token.variant {
+        match token.kind {
             OpPlus => Self::Plus,
             OpMinus => Self::Minus,
             OpStar => Self::Star,
@@ -39,7 +39,7 @@ impl BinaryOperator {
             Assign => Self::Assign,
             ConstAssign => Self::ConstAssign,
             Dot => Self::Dot,
-            _ => panic!("Can't create binary operator from '{:?}'.", token.variant),
+            _ => panic!("Can't create binary operator from '{:?}'.", token.kind),
         }
     }
 }
@@ -52,10 +52,10 @@ pub enum UnaryOperator {
 
 impl UnaryOperator {
     pub fn from_token(token: Token) -> Self {
-        match token.variant {
+        match token.kind {
             OpMinus => Self::Minus,
             OpNot => Self::Not,
-            _ => panic!("Can't create unary operator from '{:?}'.", token.variant),
+            _ => panic!("Can't create unary operator from '{:?}'.", token.kind),
         }
     }
 }
@@ -69,12 +69,12 @@ pub enum SimpleLiteral {
 
 impl SimpleLiteral {
     pub fn from_token(token: Token) -> Self {
-        match token.variant {
+        match token.kind {
             Int(int) => Self::Int(int),
             Float(float) => Self::Float(float),
             KeywordTrue => Self::Bool(true),
             KeywordFalse => Self::Bool(false),
-            _ => panic!("Can't create literal from '{:?}'.", token.variant),
+            _ => panic!("Can't create literal from '{:?}'.", token.kind),
         }
     }
 }
@@ -115,7 +115,7 @@ pub struct StrNode {
 #[derive(Debug, Clone)]
 pub enum StrPart {
     Literal(String),
-    Embed(Expression)
+    Embed(Expression),
 }
 
 #[derive(Debug, Clone)]
diff --git a/src/parse/macros.rs b/src/parse/macros.rs
index 156bdb8..97e0104 100644
--- a/src/parse/macros.rs
+++ b/src/parse/macros.rs
@@ -1,7 +1,7 @@
 #[macro_export]
 macro_rules! check {
-    ($self:ident, $($variant:pat_param)|+) => {
-        if let Some(Token {variant: $( $variant )|+, ..}) = $self.tokens.peek() {
+    ($self:ident, $($kind:pat_param)|+) => {
+        if let Some(Token {kind: $( $kind )|+, ..}) = $self.tokens.peek() {
             true
         } else {
             false
@@ -11,15 +11,15 @@ macro_rules! check {
 
 #[macro_export]
 macro_rules! consume {
-    ($self:ident, $($variant:pat_param)|+) => {
+    ($self:ident, $($kind:pat_param)|+) => {
         if let Some(token) = $self.tokens.next() {
-            if let Token {variant: $( $variant )|+, ..} = token {
+            if let Token {kind: $( $kind )|+, ..} = token {
                 Ok(token)
             } else {
                 Err(anyhow!(
                     // Make a better error message
                     "Received unexpected token: '{:?}'.",
-                    token.variant
+                    token.kind
                 ))
             }
         } else {
@@ -31,8 +31,8 @@ macro_rules! consume {
 
 #[macro_export]
 macro_rules! consume_if {
-    ($self:ident, $($variant:pat_param)|+) => {
-        if let Some(Token {variant: $( $variant )|+, ..}) = $self.tokens.peek() {
+    ($self:ident, $($kind:pat_param)|+) => {
+        if let Some(Token {kind: $( $kind )|+, ..}) = $self.tokens.peek() {
             Some($self.tokens.next().unwrap())
         } else {
             None
@@ -42,10 +42,10 @@ macro_rules! consume_if {
 
 #[macro_export]
 macro_rules! inner {
-    ($token:expr, $variant:path ) => {
-        match $token.variant {
-            $variant(inner) => inner,
-            _ => panic!("Tried getting inner content of incorrect variant."),
+    ($token:expr, $kind:path ) => {
+        match $token.kind {
+            $kind(inner) => inner,
+            _ => panic!("Tried getting inner content of incorrect kind."),
         }
     };
 }
diff --git a/src/parse/parser.rs b/src/parse/parser.rs
index ee83293..8b43a74 100644
--- a/src/parse/parser.rs
+++ b/src/parse/parser.rs
@@ -3,7 +3,7 @@ use super::ast::nodes::{ArrayNode, LoopNode, StrNode, UnaryOperator};
 use super::ast::statement::Statement;
 use super::ast::Program;
 use crate::lex::lexer::Lexer;
-use crate::lex::token::TokenVariant::*;
+use crate::lex::token::TokenKind::*;
 use crate::parse::ast::nodes::{
     ArrayAccessNode, BinaryOperator, BlockNode, CallNode, ConditionalBlock, FnHeader, FnNode,
     IfNode, MemberAccessNode, SimpleLiteral, StrPart, TypedIdentifier,
@@ -35,7 +35,7 @@ impl<T: Iterator<Item = Token>> Parser<T> {
 
     fn statement(&mut self) -> Result<Statement> {
         let token = self.tokens.peek().expect("Expected token.");
-        match token.variant {
+        match token.kind {
             KeywordPrint => self.print_statement(),
             KeywordReturn => self.return_statement(),
             KeywordBreak => self.break_statement(),
@@ -216,7 +216,7 @@ impl<T: Iterator<Item = Token>> Parser<T> {
         let mut left = self.unit_expression()?;
 
         while let Some(token) = consume_if!(self, GroupOpen | ArrayOpen | Dot) {
-            match token.variant {
+            match token.kind {
                 GroupOpen => {
                     let mut arguments = Vec::new();
 
@@ -257,7 +257,7 @@ impl<T: Iterator<Item = Token>> Parser<T> {
 
     fn unit_expression(&mut self) -> Result<Expression> {
         if let Some(token) = self.tokens.peek() {
-            match token.variant {
+            match token.kind {
                 Int(_) | Float(_) | Str(_) | KeywordTrue | KeywordFalse => {
                     let literal = self.tokens.next().unwrap();
                     Ok(Expression::SimpleLiteral(SimpleLiteral::from_token(
@@ -275,7 +275,7 @@ impl<T: Iterator<Item = Token>> Parser<T> {
                 KeywordFn => Ok(Expression::FnLiteral(Box::new(self.function()?))),
                 KeywordIf => Ok(Expression::If(Box::new(self.conditional()?))),
                 KeywordLoop => Ok(Expression::Loop(Box::new(self.repeating()?))),
-                _ => Err(anyhow!("Unexpected token: {:?}", token.variant)),
+                _ => Err(anyhow!("Unexpected token: {:?}", token.kind)),
             }
         } else {
             Err(anyhow!("Expected expression."))
@@ -313,7 +313,7 @@ impl<T: Iterator<Item = Token>> Parser<T> {
         loop {
             let token = self.tokens.next().expect("Unclosed str.");
 
-            let part = match token.variant {
+            let part = match token.kind {
                 Str(literal) => StrPart::Literal(literal),
                 StrEmbed(code) => {
                     let embed_lexer = Lexer::new(&code);
@@ -440,7 +440,7 @@ impl<T: Iterator<Item = Token>> Parser<T> {
 
         loop {
             let token = self.tokens.peek().expect("Unclosed block.");
-            match token.variant {
+            match token.kind {
                 KeywordReturn | KeywordPrint | KeywordContinue | KeywordBreak => {
                     statements.push(self.statement()?);
                 }