2019-05-11 22:59:57 +00:00
|
|
|
use crate::errors::ShellError;
|
2019-05-24 19:35:22 +00:00
|
|
|
use crate::object::DataDescriptor;
|
2019-05-26 06:54:41 +00:00
|
|
|
use crate::parser::tokens::{self, Operator};
|
2019-05-23 04:30:43 +00:00
|
|
|
use crate::prelude::*;
|
2019-05-15 22:23:36 +00:00
|
|
|
use ansi_term::Color;
|
2019-05-15 18:14:51 +00:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use chrono_humanize::Humanize;
|
2019-05-26 06:54:41 +00:00
|
|
|
use derive_new::new;
|
2019-05-17 16:59:25 +00:00
|
|
|
use ordered_float::OrderedFloat;
|
2019-05-15 18:14:51 +00:00
|
|
|
use std::time::SystemTime;
|
2019-05-10 16:59:12 +00:00
|
|
|
|
2019-05-28 02:01:37 +00:00
|
|
|
use serde::{Serialize, Serializer};
|
|
|
|
use serde_derive::Serialize;
|
|
|
|
|
2019-05-17 16:59:25 +00:00
|
|
|
type OF64 = OrderedFloat<f64>;
|
|
|
|
|
2019-05-17 15:55:50 +00:00
|
|
|
#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
|
2019-05-10 16:59:12 +00:00
|
|
|
pub enum Primitive {
|
|
|
|
Nothing,
|
|
|
|
Int(i64),
|
2019-05-15 22:58:44 +00:00
|
|
|
#[allow(unused)]
|
2019-05-17 16:59:25 +00:00
|
|
|
Float(OF64),
|
2019-05-15 18:14:51 +00:00
|
|
|
Bytes(u128),
|
2019-05-10 16:59:12 +00:00
|
|
|
String(String),
|
|
|
|
Boolean(bool),
|
2019-05-15 18:14:51 +00:00
|
|
|
Date(DateTime<Utc>),
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 02:01:37 +00:00
|
|
|
impl Serialize for Primitive {
|
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
match self {
|
|
|
|
Primitive::Nothing => serializer.serialize_i32(0),
|
|
|
|
Primitive::Int(i) => serializer.serialize_i64(*i),
|
|
|
|
Primitive::Float(f) => serializer.serialize_f64(f.into_inner()),
|
|
|
|
Primitive::Bytes(b) => serializer.serialize_u128(*b),
|
|
|
|
Primitive::String(ref s) => serializer.serialize_str(s),
|
|
|
|
Primitive::Boolean(b) => serializer.serialize_bool(*b),
|
|
|
|
Primitive::Date(d) => serializer.serialize_str(&d.to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 16:59:12 +00:00
|
|
|
impl Primitive {
|
2019-05-15 18:14:51 +00:00
|
|
|
crate fn format(&self, field_name: Option<&str>) -> String {
|
2019-05-10 16:59:12 +00:00
|
|
|
match self {
|
2019-05-15 22:23:36 +00:00
|
|
|
Primitive::Nothing => format!("{}", Color::Black.bold().paint("-")),
|
2019-05-15 18:14:51 +00:00
|
|
|
Primitive::Bytes(b) => {
|
|
|
|
let byte = byte_unit::Byte::from_bytes(*b);
|
2019-05-15 22:23:36 +00:00
|
|
|
|
|
|
|
if byte.get_bytes() == 0u128 {
|
|
|
|
return Color::Black.bold().paint("Empty".to_string()).to_string();
|
|
|
|
}
|
|
|
|
|
2019-05-28 05:05:14 +00:00
|
|
|
let byte = byte.get_appropriate_unit(false);
|
2019-05-15 18:14:51 +00:00
|
|
|
|
|
|
|
match byte.get_unit() {
|
|
|
|
byte_unit::ByteUnit::B => format!("{}", byte.format(0)),
|
|
|
|
_ => format!("{}", byte.format(1)),
|
|
|
|
}
|
|
|
|
}
|
2019-05-10 16:59:12 +00:00
|
|
|
Primitive::Int(i) => format!("{}", i),
|
2019-05-17 16:59:25 +00:00
|
|
|
Primitive::Float(f) => format!("{:.*}", 2, f.into_inner()),
|
2019-05-15 18:14:51 +00:00
|
|
|
Primitive::String(s) => format!("{}", s),
|
|
|
|
Primitive::Boolean(b) => match (b, field_name) {
|
|
|
|
(true, None) => format!("Yes"),
|
|
|
|
(false, None) => format!("No"),
|
|
|
|
(true, Some(s)) => format!("{}", s),
|
2019-05-15 22:58:44 +00:00
|
|
|
(false, Some(_)) => format!(""),
|
2019-05-15 18:14:51 +00:00
|
|
|
},
|
2019-05-15 22:23:36 +00:00
|
|
|
Primitive::Date(d) => format!("{}", d.humanize()),
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 02:01:37 +00:00
|
|
|
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone, new, Serialize)]
|
2019-05-26 06:54:41 +00:00
|
|
|
pub struct Operation {
|
|
|
|
crate left: Value,
|
|
|
|
crate operator: Operator,
|
|
|
|
crate right: Value,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone)]
|
2019-05-10 16:59:12 +00:00
|
|
|
pub enum Value {
|
|
|
|
Primitive(Primitive),
|
2019-05-15 21:44:06 +00:00
|
|
|
Object(crate::object::Dictionary),
|
2019-05-10 16:59:12 +00:00
|
|
|
List(Vec<Value>),
|
2019-05-26 06:54:41 +00:00
|
|
|
Operation(Box<Operation>),
|
2019-05-17 15:30:10 +00:00
|
|
|
|
|
|
|
#[allow(unused)]
|
2019-05-15 18:14:51 +00:00
|
|
|
Error(Box<ShellError>),
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 02:01:37 +00:00
|
|
|
impl Serialize for Value {
|
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
match self {
|
|
|
|
Value::Primitive(p) => p.serialize(serializer),
|
|
|
|
Value::Object(o) => o.serialize(serializer),
|
|
|
|
Value::List(l) => l.serialize(serializer),
|
|
|
|
Value::Operation(o) => o.serialize(serializer),
|
|
|
|
Value::Error(e) => e.serialize(serializer),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 22:23:36 +00:00
|
|
|
impl Value {
|
2019-05-26 06:54:41 +00:00
|
|
|
crate fn from_leaf(leaf: &tokens::Leaf) -> Value {
|
|
|
|
use tokens::*;
|
|
|
|
|
|
|
|
match leaf {
|
|
|
|
Leaf::String(s) => Value::string(s),
|
|
|
|
Leaf::Bare(s) => Value::string(s),
|
|
|
|
Leaf::Boolean(b) => Value::boolean(*b),
|
|
|
|
Leaf::Int(i) => Value::int(*i),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
crate fn from_expr(expr: &tokens::Expression) -> Value {
|
|
|
|
use tokens::*;
|
|
|
|
|
|
|
|
match expr {
|
|
|
|
Expression::Leaf(leaf) => Value::from_leaf(leaf),
|
|
|
|
|
|
|
|
Expression::Binary(Binary {
|
|
|
|
left,
|
|
|
|
operator,
|
|
|
|
right,
|
|
|
|
}) => Value::Operation(Box::new(Operation::new(
|
|
|
|
Value::from_leaf(left),
|
|
|
|
*operator,
|
|
|
|
Value::from_leaf(right),
|
|
|
|
))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 22:23:36 +00:00
|
|
|
crate fn data_descriptors(&self) -> Vec<DataDescriptor> {
|
2019-05-10 16:59:12 +00:00
|
|
|
match self {
|
2019-05-24 18:48:33 +00:00
|
|
|
Value::Primitive(_) => vec![DataDescriptor::value_of()],
|
2019-05-10 16:59:12 +00:00
|
|
|
Value::Object(o) => o.data_descriptors(),
|
2019-05-15 22:58:44 +00:00
|
|
|
Value::List(_) => vec![],
|
2019-05-26 06:54:41 +00:00
|
|
|
Value::Operation(_) => vec![],
|
2019-05-15 22:58:44 +00:00
|
|
|
Value::Error(_) => vec![],
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 04:30:43 +00:00
|
|
|
crate fn get_data_by_key(&'a self, name: &str) -> MaybeOwned<'a, Value> {
|
2019-05-17 15:55:50 +00:00
|
|
|
match self {
|
2019-05-23 04:30:43 +00:00
|
|
|
Value::Primitive(_) => MaybeOwned::Owned(Value::nothing()),
|
2019-05-17 15:55:50 +00:00
|
|
|
Value::Object(o) => o.get_data_by_key(name),
|
2019-05-23 04:30:43 +00:00
|
|
|
Value::List(_) => MaybeOwned::Owned(Value::nothing()),
|
2019-05-26 06:54:41 +00:00
|
|
|
Value::Operation(_) => MaybeOwned::Owned(Value::nothing()),
|
2019-05-23 04:30:43 +00:00
|
|
|
Value::Error(_) => MaybeOwned::Owned(Value::nothing()),
|
2019-05-17 15:55:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-23 04:30:43 +00:00
|
|
|
crate fn get_data(&'a self, desc: &DataDescriptor) -> MaybeOwned<'a, Value> {
|
2019-05-10 16:59:12 +00:00
|
|
|
match self {
|
2019-05-24 18:48:33 +00:00
|
|
|
p @ Value::Primitive(_) => MaybeOwned::Borrowed(p),
|
2019-05-10 16:59:12 +00:00
|
|
|
Value::Object(o) => o.get_data(desc),
|
2019-05-23 04:30:43 +00:00
|
|
|
Value::List(_) => MaybeOwned::Owned(Value::nothing()),
|
2019-05-26 06:54:41 +00:00
|
|
|
Value::Operation(_) => MaybeOwned::Owned(Value::nothing()),
|
2019-05-23 04:30:43 +00:00
|
|
|
Value::Error(_) => MaybeOwned::Owned(Value::nothing()),
|
2019-05-15 18:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 22:23:36 +00:00
|
|
|
crate fn copy(&self) -> Value {
|
2019-05-15 18:14:51 +00:00
|
|
|
match self {
|
|
|
|
Value::Primitive(p) => Value::Primitive(p.clone()),
|
2019-05-15 21:44:06 +00:00
|
|
|
Value::Object(o) => Value::Object(o.copy_dict()),
|
2019-05-15 18:14:51 +00:00
|
|
|
Value::List(l) => {
|
|
|
|
let list = l.iter().map(|i| i.copy()).collect();
|
|
|
|
Value::List(list)
|
|
|
|
}
|
2019-05-26 06:54:41 +00:00
|
|
|
Value::Operation(o) => Value::Operation(o.clone()),
|
2019-05-15 18:14:51 +00:00
|
|
|
Value::Error(e) => Value::Error(Box::new(e.copy_error())),
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-15 18:14:51 +00:00
|
|
|
|
|
|
|
crate fn format_leaf(&self, field_name: Option<&str>) -> String {
|
2019-05-10 16:59:12 +00:00
|
|
|
match self {
|
2019-05-15 18:14:51 +00:00
|
|
|
Value::Primitive(p) => p.format(field_name),
|
2019-05-15 22:58:44 +00:00
|
|
|
Value::Object(_) => format!("[object Object]"),
|
|
|
|
Value::List(_) => format!("[list List]"),
|
2019-05-26 06:54:41 +00:00
|
|
|
Value::Operation(_) => format!("[operation Operation]"),
|
2019-05-15 18:14:51 +00:00
|
|
|
Value::Error(e) => format!("{}", e),
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 22:59:57 +00:00
|
|
|
crate fn as_string(&self) -> Result<String, ShellError> {
|
|
|
|
match self {
|
|
|
|
Value::Primitive(Primitive::String(s)) => Ok(s.to_string()),
|
|
|
|
|
|
|
|
// TODO: this should definitely be more general with better errors
|
2019-05-13 17:30:51 +00:00
|
|
|
other => Err(ShellError::string(format!(
|
|
|
|
"Expected string, got {:?}",
|
|
|
|
other
|
|
|
|
))),
|
2019-05-11 22:59:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-26 06:54:41 +00:00
|
|
|
crate fn as_operation(&self) -> Result<Operation, ShellError> {
|
|
|
|
match self {
|
|
|
|
Value::Operation(o) => Ok(*o.clone()),
|
|
|
|
|
|
|
|
// TODO: this should definitely be more general with better errors
|
|
|
|
other => Err(ShellError::string(format!(
|
|
|
|
"Expected operation, got {:?}",
|
|
|
|
other
|
|
|
|
))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 16:12:38 +00:00
|
|
|
crate fn as_int(&self) -> Result<i64, ShellError> {
|
|
|
|
match self {
|
|
|
|
Value::Primitive(Primitive::Int(i)) => Ok(*i),
|
|
|
|
// TODO: this should definitely be more general with better errors
|
|
|
|
other => Err(ShellError::string(format!(
|
|
|
|
"Expected integer, got {:?}",
|
|
|
|
other
|
|
|
|
))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-16 21:43:36 +00:00
|
|
|
#[allow(unused)]
|
2019-05-16 02:42:44 +00:00
|
|
|
crate fn as_bool(&self) -> Result<bool, ShellError> {
|
|
|
|
match self {
|
|
|
|
Value::Primitive(Primitive::Boolean(b)) => Ok(*b),
|
|
|
|
// TODO: this should definitely be more general with better errors
|
|
|
|
other => Err(ShellError::string(format!(
|
|
|
|
"Expected integer, got {:?}",
|
|
|
|
other
|
|
|
|
))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 16:59:12 +00:00
|
|
|
crate fn string(s: impl Into<String>) -> Value {
|
|
|
|
Value::Primitive(Primitive::String(s.into()))
|
|
|
|
}
|
|
|
|
|
2019-05-15 18:14:51 +00:00
|
|
|
crate fn bytes(s: impl Into<u128>) -> Value {
|
|
|
|
Value::Primitive(Primitive::Bytes(s.into()))
|
|
|
|
}
|
|
|
|
|
2019-05-10 16:59:12 +00:00
|
|
|
crate fn int(s: impl Into<i64>) -> Value {
|
|
|
|
Value::Primitive(Primitive::Int(s.into()))
|
|
|
|
}
|
|
|
|
|
2019-05-17 16:59:25 +00:00
|
|
|
crate fn float(s: impl Into<OF64>) -> Value {
|
|
|
|
Value::Primitive(Primitive::Float(s.into()))
|
|
|
|
}
|
|
|
|
|
2019-05-16 21:43:36 +00:00
|
|
|
#[allow(unused)]
|
2019-05-16 02:42:44 +00:00
|
|
|
crate fn bool(s: impl Into<bool>) -> Value {
|
|
|
|
Value::Primitive(Primitive::Boolean(s.into()))
|
|
|
|
}
|
|
|
|
|
2019-05-15 18:14:51 +00:00
|
|
|
crate fn system_date(s: SystemTime) -> Value {
|
|
|
|
Value::Primitive(Primitive::Date(s.into()))
|
|
|
|
}
|
|
|
|
|
2019-05-17 15:30:10 +00:00
|
|
|
#[allow(unused)]
|
2019-05-15 18:14:51 +00:00
|
|
|
crate fn system_date_result(s: Result<SystemTime, std::io::Error>) -> Value {
|
|
|
|
match s {
|
|
|
|
Ok(time) => Value::Primitive(Primitive::Date(time.into())),
|
|
|
|
Err(err) => Value::Error(Box::new(ShellError::string(format!("{}", err)))),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-10 16:59:12 +00:00
|
|
|
crate fn boolean(s: impl Into<bool>) -> Value {
|
|
|
|
Value::Primitive(Primitive::Boolean(s.into()))
|
|
|
|
}
|
|
|
|
|
|
|
|
crate fn nothing() -> Value {
|
|
|
|
Value::Primitive(Primitive::Nothing)
|
|
|
|
}
|
|
|
|
|
2019-05-15 22:58:44 +00:00
|
|
|
#[allow(unused)]
|
2019-05-10 16:59:12 +00:00
|
|
|
crate fn list(values: impl Into<Vec<Value>>) -> Value {
|
|
|
|
Value::List(values.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-22 07:12:03 +00:00
|
|
|
crate fn select_fields(obj: &Value, fields: &[String]) -> crate::object::Dictionary {
|
2019-05-15 18:14:51 +00:00
|
|
|
let mut out = crate::object::Dictionary::default();
|
|
|
|
|
|
|
|
let descs = obj.data_descriptors();
|
|
|
|
|
|
|
|
for field in fields {
|
2019-05-24 18:48:33 +00:00
|
|
|
match descs.iter().find(|d| d.name.is_string(field)) {
|
|
|
|
None => out.add(DataDescriptor::for_string_name(field), Value::nothing()),
|
|
|
|
Some(desc) => out.add(desc.copy(), obj.get_data(desc).borrow().copy()),
|
2019-05-15 18:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out
|
2019-05-10 16:59:12 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 07:12:03 +00:00
|
|
|
crate fn reject_fields(obj: &Value, fields: &[String]) -> crate::object::Dictionary {
|
2019-05-15 21:44:06 +00:00
|
|
|
let mut out = crate::object::Dictionary::default();
|
|
|
|
|
|
|
|
let descs = obj.data_descriptors();
|
|
|
|
|
|
|
|
for desc in descs {
|
2019-05-24 18:48:33 +00:00
|
|
|
match desc.name.as_string() {
|
|
|
|
None => continue,
|
|
|
|
Some(s) if fields.iter().any(|field| field == s) => continue,
|
2019-05-24 19:35:22 +00:00
|
|
|
Some(_) => out.add(desc.copy(), obj.get_data(&desc).borrow().copy()),
|
2019-05-15 21:44:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out
|
|
|
|
}
|
2019-05-16 02:42:44 +00:00
|
|
|
|
2019-05-18 01:27:31 +00:00
|
|
|
crate fn find(obj: &Value, field: &str, op: &Operator, rhs: &Value) -> bool {
|
2019-05-16 02:42:44 +00:00
|
|
|
let descs = obj.data_descriptors();
|
2019-05-24 18:48:33 +00:00
|
|
|
match descs.iter().find(|d| d.name.is_string(field)) {
|
2019-05-16 02:42:44 +00:00
|
|
|
None => false,
|
|
|
|
Some(desc) => {
|
|
|
|
let v = obj.get_data(desc).borrow().copy();
|
2019-05-18 01:27:31 +00:00
|
|
|
//println!("'{:?}' '{:?}' '{:?}'", v, op, rhs);
|
2019-05-16 02:42:44 +00:00
|
|
|
|
|
|
|
match v {
|
2019-05-16 21:43:36 +00:00
|
|
|
Value::Primitive(Primitive::Boolean(b)) => match (op, rhs) {
|
2019-05-18 01:27:31 +00:00
|
|
|
(Operator::Equal, Value::Primitive(Primitive::Boolean(b2))) => b == *b2,
|
|
|
|
(Operator::NotEqual, Value::Primitive(Primitive::Boolean(b2))) => b != *b2,
|
2019-05-16 21:43:36 +00:00
|
|
|
_ => false,
|
|
|
|
},
|
|
|
|
Value::Primitive(Primitive::Bytes(i)) => match (op, rhs) {
|
2019-05-18 01:27:31 +00:00
|
|
|
(Operator::LessThan, Value::Primitive(Primitive::Int(i2))) => i < (*i2 as u128),
|
2019-05-22 07:12:03 +00:00
|
|
|
(Operator::GreaterThan, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i > (*i2 as u128)
|
|
|
|
}
|
|
|
|
(Operator::LessThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i <= (*i2 as u128)
|
|
|
|
}
|
|
|
|
(Operator::GreaterThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i >= (*i2 as u128)
|
|
|
|
}
|
2019-05-18 01:27:31 +00:00
|
|
|
(Operator::Equal, Value::Primitive(Primitive::Int(i2))) => i == (*i2 as u128),
|
2019-05-22 07:12:03 +00:00
|
|
|
(Operator::NotEqual, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i != (*i2 as u128)
|
|
|
|
}
|
2019-05-16 21:43:36 +00:00
|
|
|
_ => false,
|
|
|
|
},
|
|
|
|
Value::Primitive(Primitive::Int(i)) => match (op, rhs) {
|
2019-05-18 01:27:31 +00:00
|
|
|
(Operator::LessThan, Value::Primitive(Primitive::Int(i2))) => i < *i2,
|
|
|
|
(Operator::GreaterThan, Value::Primitive(Primitive::Int(i2))) => i > *i2,
|
|
|
|
(Operator::LessThanOrEqual, Value::Primitive(Primitive::Int(i2))) => i <= *i2,
|
2019-05-22 07:12:03 +00:00
|
|
|
(Operator::GreaterThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i >= *i2
|
|
|
|
}
|
2019-05-18 01:27:31 +00:00
|
|
|
(Operator::Equal, Value::Primitive(Primitive::Int(i2))) => i == *i2,
|
|
|
|
(Operator::NotEqual, Value::Primitive(Primitive::Int(i2))) => i != *i2,
|
2019-05-16 21:43:36 +00:00
|
|
|
_ => false,
|
|
|
|
},
|
2019-05-17 16:59:25 +00:00
|
|
|
Value::Primitive(Primitive::Float(i)) => match (op, rhs) {
|
2019-05-18 01:27:31 +00:00
|
|
|
(Operator::LessThan, Value::Primitive(Primitive::Float(i2))) => i < *i2,
|
|
|
|
(Operator::GreaterThan, Value::Primitive(Primitive::Float(i2))) => i > *i2,
|
|
|
|
(Operator::LessThanOrEqual, Value::Primitive(Primitive::Float(i2))) => i <= *i2,
|
2019-05-22 07:12:03 +00:00
|
|
|
(Operator::GreaterThanOrEqual, Value::Primitive(Primitive::Float(i2))) => {
|
|
|
|
i >= *i2
|
|
|
|
}
|
2019-05-18 01:27:31 +00:00
|
|
|
(Operator::Equal, Value::Primitive(Primitive::Float(i2))) => i == *i2,
|
|
|
|
(Operator::NotEqual, Value::Primitive(Primitive::Float(i2))) => i != *i2,
|
2019-05-22 07:12:03 +00:00
|
|
|
(Operator::LessThan, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
(i.into_inner()) < *i2 as f64
|
|
|
|
}
|
|
|
|
(Operator::GreaterThan, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i.into_inner() > *i2 as f64
|
|
|
|
}
|
|
|
|
(Operator::LessThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i.into_inner() <= *i2 as f64
|
|
|
|
}
|
|
|
|
(Operator::GreaterThanOrEqual, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i.into_inner() >= *i2 as f64
|
|
|
|
}
|
|
|
|
(Operator::Equal, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i.into_inner() == *i2 as f64
|
|
|
|
}
|
|
|
|
(Operator::NotEqual, Value::Primitive(Primitive::Int(i2))) => {
|
|
|
|
i.into_inner() != *i2 as f64
|
|
|
|
}
|
2019-05-17 16:59:25 +00:00
|
|
|
|
|
|
|
_ => false,
|
|
|
|
},
|
2019-05-16 21:43:36 +00:00
|
|
|
Value::Primitive(Primitive::String(s)) => match (op, rhs) {
|
2019-05-18 01:27:31 +00:00
|
|
|
(Operator::Equal, Value::Primitive(Primitive::String(s2))) => s == *s2,
|
|
|
|
(Operator::NotEqual, Value::Primitive(Primitive::String(s2))) => s != *s2,
|
2019-05-16 21:43:36 +00:00
|
|
|
_ => false,
|
|
|
|
},
|
2019-05-16 02:42:44 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|