summaryrefslogtreecommitdiff
path: root/src/eval/value.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-02-18 15:02:02 +0100
committerLaurenz <laurmaedje@gmail.com>2022-02-18 16:57:53 +0100
commite01970b20a058ab1b4ebea916f229c9b706c84e4 (patch)
tree5c5efc75abd6e607bd45a0602603231edf520503 /src/eval/value.rs
parent05ec0f993b4a1b8481e494ee16285d23f000872f (diff)
Basic show rules
Diffstat (limited to 'src/eval/value.rs')
-rw-r--r--src/eval/value.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/eval/value.rs b/src/eval/value.rs
index 2de210d5..952c7293 100644
--- a/src/eval/value.rs
+++ b/src/eval/value.rs
@@ -336,7 +336,7 @@ pub trait Cast<V = Value>: Sized {
macro_rules! primitive {
(
$type:ty: $name:literal, $variant:ident
- $(, $other:ident($binding:ident) => $out:expr)*
+ $(, $other:ident$(($binding:ident))? => $out:expr)*
) => {
impl Type for $type {
const TYPE_NAME: &'static str = $name;
@@ -344,13 +344,14 @@ macro_rules! primitive {
impl Cast for $type {
fn is(value: &Value) -> bool {
- matches!(value, Value::$variant(_) $(| Value::$other(_))*)
+ matches!(value, Value::$variant(_)
+ $(| primitive!(@$other $(($binding))?))*)
}
fn cast(value: Value) -> StrResult<Self> {
match value {
Value::$variant(v) => Ok(v),
- $(Value::$other($binding) => Ok($out),)*
+ $(Value::$other$(($binding))? => Ok($out),)*
v => Err(format!(
"expected {}, found {}",
Self::TYPE_NAME,
@@ -366,6 +367,9 @@ macro_rules! primitive {
}
}
};
+
+ (@$other:ident($binding:ident)) => { Value::$other(_) };
+ (@$other:ident) => { Value::$other };
}
/// Implement traits for dynamic types.
@@ -440,7 +444,7 @@ primitive! { Color: "color", Color }
primitive! { EcoString: "string", Str }
primitive! { Array: "array", Array }
primitive! { Dict: "dictionary", Dict }
-primitive! { Template: "template", Template }
+primitive! { Template: "template", Template, None => Template::new() }
primitive! { Func: "function", Func, Class(v) => v.constructor() }
primitive! { Args: "arguments", Args }
primitive! { Class: "class", Class }