Transition to new literals compiling.
Tests still need work, as does the implementation for json.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::parser::KVPair;
|
||||
use crate::parser::{Filter, RValue};
|
||||
use crate::parser::{Filter, OwnedLiteral, RValue};
|
||||
use crate::renderer::context_element::CompareContextElement;
|
||||
use crate::renderer::context_element::ContextElement;
|
||||
use crate::renderer::walking::owned_walk_path;
|
||||
@@ -35,25 +35,14 @@ pub struct OwnedPath {
|
||||
impl From<&RValue<'_>> for OwnedRValue {
|
||||
fn from(original: &RValue<'_>) -> Self {
|
||||
match original {
|
||||
RValue::RVString(text) => {
|
||||
OwnedRValue::RVLiteral(OwnedLiteral::LString(text.to_owned()))
|
||||
}
|
||||
RValue::RVLiteral(literal) => OwnedRValue::RVLiteral(literal.clone()),
|
||||
RValue::RVPath(path) => OwnedRValue::RVPath(OwnedPath {
|
||||
keys: path.keys.iter().map(|k| k.to_string()).collect(),
|
||||
}),
|
||||
RValue::RVPositiveInteger(num) => {
|
||||
OwnedRValue::RVLiteral(OwnedLiteral::LPositiveInteger(num.clone()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum OwnedLiteral {
|
||||
LString(String),
|
||||
LPositiveInteger(u64),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ParametersContext {
|
||||
params: HashMap<String, OwnedRValue>,
|
||||
@@ -196,7 +185,7 @@ impl CompareContextElement for OwnedLiteral {
|
||||
}
|
||||
|
||||
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
|
||||
println!("partial_compare literal {:?} | {:?}", self, other);
|
||||
// println!("partial_compare literal {:?} | {:?}", self, other);
|
||||
// If its an OwnedLiteral then compare them directly,
|
||||
// otherwise defer to the other type's implementation of
|
||||
// CompareContextElement since the end user could add any
|
||||
@@ -228,107 +217,3 @@ impl CompareContextElement for OwnedLiteral {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// impl ContextElement for String {}
|
||||
|
||||
// impl Renderable for String {
|
||||
// fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// Ok(self.clone())
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl Loopable for String {
|
||||
// fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||
// if self.is_empty() {
|
||||
// Vec::new()
|
||||
// } else {
|
||||
// vec![self]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl Walkable for String {
|
||||
// fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||
// Err(WalkError::CantWalk)
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl CompareContextElement for String {
|
||||
// fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||
// // If its a String then compare them directly, otherwise defer
|
||||
// // to the other type's implementation of CompareContextElement
|
||||
// // since the end user could add any type.
|
||||
// match other.to_any().downcast_ref::<Self>() {
|
||||
// None => other.equals(self),
|
||||
// Some(other_string) => self == other_string,
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
|
||||
// println!("partial_compare String {:?} | {:?}", self, other);
|
||||
// // If its a string then compare them directly, otherwise defer
|
||||
// // to the other type's implementation of CompareContextElement
|
||||
// // since the end user could add any type.
|
||||
// match other.to_any().downcast_ref::<Self>() {
|
||||
// None => match other.partial_compare(self) {
|
||||
// None => None,
|
||||
// Some(ord) => match ord {
|
||||
// Ordering::Equal => Some(Ordering::Equal),
|
||||
// Ordering::Greater => Some(Ordering::Less),
|
||||
// Ordering::Less => Some(Ordering::Greater),
|
||||
// },
|
||||
// },
|
||||
// Some(other_string) => self.partial_cmp(other_string),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl ContextElement for u64 {}
|
||||
|
||||
// impl Renderable for u64 {
|
||||
// fn render(&self, _filters: &Vec<Filter>) -> Result<String, RenderError> {
|
||||
// Ok(self.to_string())
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl Loopable for u64 {
|
||||
// fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
|
||||
// vec![self]
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl Walkable for u64 {
|
||||
// fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> {
|
||||
// Err(WalkError::CantWalk)
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl CompareContextElement for u64 {
|
||||
// fn equals(&self, other: &dyn ContextElement) -> bool {
|
||||
// // If its a u64 then compare them directly, otherwise defer
|
||||
// // to the other type's implementation of CompareContextElement
|
||||
// // since the end user could add any type.
|
||||
// match other.to_any().downcast_ref::<Self>() {
|
||||
// None => other.equals(self),
|
||||
// Some(other_num) => self == other_num,
|
||||
// }
|
||||
// }
|
||||
|
||||
// fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
|
||||
// println!("partial_compare u64 {:?} | {:?}", self, other);
|
||||
// // If its a u64 then compare them directly, otherwise defer
|
||||
// // to the other type's implementation of CompareContextElement
|
||||
// // since the end user could add any type.
|
||||
// match other.to_any().downcast_ref::<Self>() {
|
||||
// None => match other.partial_compare(self) {
|
||||
// None => None,
|
||||
// Some(ord) => match ord {
|
||||
// Ordering::Equal => Some(Ordering::Equal),
|
||||
// Ordering::Greater => Some(Ordering::Less),
|
||||
// Ordering::Less => Some(Ordering::Greater),
|
||||
// },
|
||||
// },
|
||||
// Some(other_num) => self.partial_cmp(other_num),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -477,9 +477,8 @@ impl<'a> DustRenderer<'a> {
|
||||
match param_map.get(key) {
|
||||
None => None,
|
||||
Some(rval) => match rval {
|
||||
RValue::RVString(text) => Some(Ok(text)),
|
||||
RValue::RVLiteral(literal) => Some(Ok(literal)),
|
||||
RValue::RVPath(path) => Some(walk_path(breadcrumbs, &path.keys)),
|
||||
RValue::RVPositiveInteger(num) => Some(Ok(num)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user