From 82239be1600eacc569cb4cfa80e97185f91e2bb4 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 30 Aug 2021 22:55:31 +0200 Subject: [PATCH] Not is now lexing and parsing correctly --- ablescript/src/interpret.rs | 8 ++++---- ablescript/src/lexer.rs | 2 +- ablescript/src/parser.rs | 1 + ablescript/src/variables.rs | 8 ++++++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index 21e023a5..b22eedc6 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -151,7 +151,7 @@ impl ExecEnv { NotEqual => Value::Bool(lhs != rhs), } } - Not(expr) => Bool(!self.eval_expr(expr)?.into_bool()), + Not(expr) => !self.eval_expr(expr)?, Literal(value) => value.clone(), ExprKind::Cart(members) => Value::Cart( members @@ -539,7 +539,7 @@ mod tests { span: 1..1 }) .unwrap(), - Value::Int(42) + Value::Int(-2147483648) ); // And the same for divide by zero. @@ -547,7 +547,7 @@ mod tests { env.eval_expr(&Expr { kind: ExprKind::BinOp { lhs: Box::new(Expr { - kind: ExprKind::Literal(Value::Int(1)), + kind: ExprKind::Literal(Value::Int(84)), span: 1..1, }), rhs: Box::new(Expr { @@ -559,7 +559,7 @@ mod tests { span: 1..1 }) .unwrap(), - Value::Int(42) + Value::Int(2) ); } diff --git a/ablescript/src/lexer.rs b/ablescript/src/lexer.rs index c32d9367..612d0e99 100644 --- a/ablescript/src/lexer.rs +++ b/ablescript/src/lexer.rs @@ -64,7 +64,7 @@ pub enum Token { #[token("!=")] NotEqual, - #[token("!|aint")] // also add aint as a not keyword + #[regex("!|aint")] // also add aint as a not keyword Not, // Keywords diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index e2873b07..49ade13e 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -99,6 +99,7 @@ impl<'source> Parser<'source> { | Token::Abool(_) | Token::Bool(_) | Token::Nul + | Token::Not | Token::LeftBracket | Token::LeftParen => Ok(Stmt::new( self.value_flow(token)?, diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 25b9217a..8b2c7881 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -418,6 +418,14 @@ impl ops::Div for Value { } } +impl ops::Not for Value { + type Output = Value; + + fn not(self) -> Self::Output { + todo!() + } +} + impl PartialEq for Value { fn eq(&self, other: &Self) -> bool { let other = other.clone();