about summary refs log tree commit diff
path: root/src/parse
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/ast/nodes.rs3
-rw-r--r--src/parse/parser.rs38
2 files changed, 36 insertions, 5 deletions
diff --git a/src/parse/ast/nodes.rs b/src/parse/ast/nodes.rs
index 2347d5b..36b15c8 100644
--- a/src/parse/ast/nodes.rs
+++ b/src/parse/ast/nodes.rs
@@ -63,6 +63,7 @@ pub enum Literal {
     Int(u32),
     Float(f32),
     Str(String),
+    Bool(bool),
 }
 
 impl Literal {
@@ -71,6 +72,8 @@ impl Literal {
             Int(int) => Self::Int(int),
             Float(float) => Self::Float(float),
             Str(string) => Self::Str(string),
+            KeywordTrue => Self::Bool(true),
+            KeywordFalse => Self::Bool(false),
             _ => panic!("Can't create literal from '{:?}'.", token.variant),
         }
     }
diff --git a/src/parse/parser.rs b/src/parse/parser.rs
index 41fd954..219065b 100644
--- a/src/parse/parser.rs
+++ b/src/parse/parser.rs
@@ -76,7 +76,7 @@ impl<T: Iterator<Item = Token>> Parser<T> {
 
     fn assignment_expression(&mut self) -> Result<Expression> {
         // Parse any expressions as l-values for now.
-        let left = self.term_expression()?;
+        let left = self.equality_expression()?;
 
         if let Some(op) = consume_if!(self, Assign | ConstAssign) {
             let right = self.assignment_expression()?;
@@ -91,6 +91,38 @@ impl<T: Iterator<Item = Token>> Parser<T> {
         }
     }
 
+    fn equality_expression(&mut self) -> Result<Expression> {
+        let mut left = self.comparison_expression()?;
+
+        while let Some(op) = consume_if!(self, OpEq | OpNeq) {
+            let right = self.comparison_expression()?;
+
+            left = Expression::Binary {
+                left: Box::new(left),
+                op: BinaryOperator::from_token(op),
+                right: Box::new(right),
+            };
+        }
+
+        Ok(left)
+    }
+
+    fn comparison_expression(&mut self) -> Result<Expression> {
+        let mut left = self.term_expression()?;
+
+        while let Some(op) = consume_if!(self, OpGt | OpGte | OpLt | OpLte) {
+            let right = self.term_expression()?;
+
+            left = Expression::Binary {
+                left: Box::new(left),
+                op: BinaryOperator::from_token(op),
+                right: Box::new(right),
+            };
+        }
+
+        Ok(left)
+    }
+
     fn term_expression(&mut self) -> Result<Expression> {
         let mut left = self.factor_expression()?;
 
@@ -143,10 +175,6 @@ impl<T: Iterator<Item = Token>> Parser<T> {
                     let literal = self.tokens.next().unwrap();
                     Ok(Expression::Literal(Literal::from_token(literal)))
                 }
-                // Identifier(_) => match self.tokens.next().unwrap().variant {
-                //     Identifier(identifier) => Ok(Expression::Identifier(identifier)),
-                //     _ => unreachable!(),
-                // },
                 Ident(_) => Ok(Expression::Identifier(inner!(
                     self.tokens.next().unwrap(),
                     Ident