forked from AbleScript/ablescript
Implemented negation for most types
This commit is contained in:
parent
af2fe717fb
commit
70288ae409
|
@ -133,7 +133,7 @@ pub enum Token {
|
||||||
String(String),
|
String(String),
|
||||||
|
|
||||||
/// Integer
|
/// Integer
|
||||||
#[regex(r"[0-9]+", get_int)]
|
#[regex(r"-?[0-9]+", get_int)]
|
||||||
Integer(i32),
|
Integer(i32),
|
||||||
|
|
||||||
/// A C-complaint identifier
|
/// A C-complaint identifier
|
||||||
|
|
|
@ -422,7 +422,23 @@ impl ops::Not for Value {
|
||||||
type Output = Value;
|
type Output = Value;
|
||||||
|
|
||||||
fn not(self) -> Self::Output {
|
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();
|
let other = other.clone();
|
||||||
|
|
||||||
match self {
|
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::Str(s) => *s == other.to_string(),
|
||||||
Value::Int(i) => *i == other.into_i32(),
|
Value::Int(i) => *i == other.into_i32(),
|
||||||
Value::Bool(b) => *b == other.into_bool(),
|
Value::Bool(b) => *b == other.into_bool(),
|
||||||
|
|
Loading…
Reference in a new issue