diff --git a/src/renderer/parameters_context.rs b/src/renderer/parameters_context.rs index 3e6725e..128bd21 100644 --- a/src/renderer/parameters_context.rs +++ b/src/renderer/parameters_context.rs @@ -45,6 +45,22 @@ impl From<&RValue<'_>> for OwnedRValue { } } +#[derive(Clone, Debug)] +pub enum OwnedLiteral { + LString(String), + LPositiveInteger(u64), +} + +impl From<&OwnedRValue> for OwnedLiteral { + fn from(original: &OwnedRValue) -> Self { + match original { + OwnedRValue::RVPath(_) => panic!("Cannot convert a path to a literal"), + OwnedRValue::RVString(text) => OwnedLiteral::LString(text.clone()), + OwnedRValue::RVPositiveInteger(num) => OwnedLiteral::LPositiveInteger(num.clone()), + } + } +} + #[derive(Debug)] pub struct ParametersContext { params: HashMap, @@ -129,6 +145,50 @@ impl CompareContextElement for ParametersContext { } } +impl ContextElement for OwnedLiteral {} + +impl Renderable for OwnedLiteral { + fn render(&self, _filters: &Vec) -> Result { + match self { + OwnedLiteral::LString(text) => Ok(text.clone()), + OwnedLiteral::LPositiveInteger(num) => Ok(num.to_string()), + } + } +} + +impl Loopable for OwnedLiteral { + fn get_loop_elements(&self) -> Vec<&dyn ContextElement> { + match self { + OwnedLiteral::LString(text) => { + if text.is_empty() { + Vec::new() + } else { + vec![text] + } + } + OwnedLiteral::LPositiveInteger(num) => vec![num], + } + } +} + +impl Walkable for OwnedLiteral { + fn walk(&self, segment: &str) -> Result<&dyn ContextElement, WalkError> { + Err(WalkError::CantWalk) + } +} + +impl CompareContextElement for OwnedLiteral { + fn equals(&self, other: &dyn ContextElement) -> bool { + // TODO + false + } + + fn partial_compare(&self, other: &dyn ContextElement) -> Option { + // TODO + None + } +} + impl ContextElement for String {} impl Renderable for String {