From 14e9eb5c6b0c3cb70f3f901aff891a03c4920458 Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 30 Aug 2021 23:19:25 +0200 Subject: [PATCH] Implemented negation for most types --- ablescript/src/lexer.rs | 2 +- ablescript/src/variables.rs | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ablescript/src/lexer.rs b/ablescript/src/lexer.rs index 612d0e99..e75414d9 100644 --- a/ablescript/src/lexer.rs +++ b/ablescript/src/lexer.rs @@ -133,7 +133,7 @@ pub enum Token { String(String), /// Integer - #[regex(r"[0-9]+", get_int)] + #[regex(r"-?[0-9]+", get_int)] Integer(i32), /// A C-complaint identifier diff --git a/ablescript/src/variables.rs b/ablescript/src/variables.rs index 8b2c7881..8ff96ca8 100644 --- a/ablescript/src/variables.rs +++ b/ablescript/src/variables.rs @@ -422,7 +422,23 @@ impl ops::Not for Value { type Output = Value; fn not(self) -> Self::Output { - todo!() + match self { + Value::Nul => Value::Nul, + Value::Str(s) => Value::Str(s.chars().rev().collect()), + Value::Int(i) => Value::Int(i.swap_bytes()), + Value::Bool(b) => Value::Bool(!b), + Value::Abool(a) => Value::Abool(match a { + Abool::Never => Abool::Always, + Abool::Sometimes => Abool::Sometimes, + Abool::Always => Abool::Never, + }), + Value::Functio(_) => todo!(), + Value::Cart(c) => Value::Cart( + c.into_iter() + .map(|(k, v)| (v.borrow().clone(), Rc::new(RefCell::new(k)))) + .collect(), + ), + } } } @@ -431,7 +447,13 @@ impl PartialEq for Value { let other = other.clone(); match self { - Value::Nul => other == Value::Nul, + Value::Nul => { + if let Value::Nul = other { + true + } else { + false + } + } Value::Str(s) => *s == other.to_string(), Value::Int(i) => *i == other.into_i32(), Value::Bool(b) => *b == other.into_bool(),