#[macro_export(local_inner_macros)]
macro_rules! value {
($($value:tt)+) => {
value_internal!($($value)+)
};
}
#[macro_export(local_inner_macros)]
#[doc(hidden)]
macro_rules! value_internal {
(nil) => {
$crate::model::Value::Nil
};
(true) => {
$crate::model::Value::scalar(true)
};
(false) => {
$crate::model::Value::scalar(false)
};
([]) => {
$crate::model::Value::Array(::std::default::Default::default())
};
([ $($tt:tt)+ ]) => {
$crate::model::Value::Array(array_internal!(@array [] $($tt)+))
};
({}) => {
$crate::model::Value::Object(::std::default::Default::default())
};
({ $($tt:tt)+ }) => {
$crate::model::Value::Object({
let mut object = $crate::model::Object::new();
object_internal!(@object object () ($($tt)+) ($($tt)+));
object
})
};
($other:ident) => {
$other
};
($other:expr) => {
$crate::model::to_value(&$other).unwrap()
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! value_unexpected {
() => {};
}
#[macro_export(local_inner_macros)]
macro_rules! object {
($($value:tt)+) => {
object_internal!($($value)+)
};
}
#[macro_export(local_inner_macros)]
#[doc(hidden)]
macro_rules! object_internal {
(@object $object:ident () () ()) => {};
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {
let _ = $object.insert(($($key)+).into(), $value);
object_internal!(@object $object () ($($rest)*) ($($rest)*));
};
(@object $object:ident [$($key:tt)+] ($value:expr) $unexpected:tt $($rest:tt)*) => {
object_unexpected!($unexpected);
};
(@object $object:ident [$($key:tt)+] ($value:expr)) => {
let _ = $object.insert(($($key)+).into(), $value);
};
(@object $object:ident ($($key:tt)+) (: nil $($rest:tt)*) $copy:tt) => {
object_internal!(@object $object [$($key)+] (value_internal!(nil)) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: true $($rest:tt)*) $copy:tt) => {
object_internal!(@object $object [$($key)+] (value_internal!(true)) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: false $($rest:tt)*) $copy:tt) => {
object_internal!(@object $object [$($key)+] (value_internal!(false)) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
object_internal!(@object $object [$($key)+] (value_internal!([$($array)*])) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
object_internal!(@object $object [$($key)+] (value_internal!({$($map)*})) $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => {
object_internal!(@object $object [$($key)+] (value_internal!($value)) , $($rest)*);
};
(@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => {
object_internal!(@object $object [$($key)+] (value_internal!($value)));
};
(@object $object:ident ($($key:tt)+) (:) $copy:tt) => {
object_internal!();
};
(@object $object:ident ($($key:tt)+) () $copy:tt) => {
object_internal!();
};
(@object $object:ident () (: $($rest:tt)*) ($colon:tt $($copy:tt)*)) => {
object_unexpected!($colon);
};
(@object $object:ident ($($key:tt)*) (, $($rest:tt)*) ($comma:tt $($copy:tt)*)) => {
object_unexpected!($comma);
};
(@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => {
object_internal!(@object $object ($key) (: $($rest)*) (: $($rest)*));
};
(@object $object:ident ($($key:tt)*) ($tt:tt $($rest:tt)*) $copy:tt) => {
object_internal!(@object $object ($($key)* $tt) ($($rest)*) ($($rest)*));
};
({}) => {
$crate::model::Object::new()
};
({ $($tt:tt)+ }) => {
{
let mut object = $crate::model::Object::new();
object_internal!(@object object () ($($tt)+) ($($tt)+));
object
}
};
($other:ident) => {
$other
};
($other:expr) => {
$crate::model::to_object(&$other).unwrap()
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! object_unexpected {
() => {};
}
#[macro_export(local_inner_macros)]
macro_rules! array {
($($value:tt)+) => {
array_internal!($($value)+)
};
}
#[macro_export(local_inner_macros)]
#[doc(hidden)]
macro_rules! array_internal {
(@array [$($elems:expr,)*]) => {
array_internal_vec![$($elems,)*]
};
(@array [$($elems:expr),*]) => {
array_internal_vec![$($elems),*]
};
(@array [$($elems:expr,)*] nil $($rest:tt)*) => {
array_internal!(@array [$($elems,)* value_internal!(nil)] $($rest)*)
};
(@array [$($elems:expr,)*] true $($rest:tt)*) => {
array_internal!(@array [$($elems,)* value_internal!(true)] $($rest)*)
};
(@array [$($elems:expr,)*] false $($rest:tt)*) => {
array_internal!(@array [$($elems,)* value_internal!(false)] $($rest)*)
};
(@array [$($elems:expr,)*] [$($array:tt)*] $($rest:tt)*) => {
array_internal!(@array [$($elems,)* value_internal!([$($array)*])] $($rest)*)
};
(@array [$($elems:expr,)*] {$($map:tt)*} $($rest:tt)*) => {
array_internal!(@array [$($elems,)* value_internal!({$($map)*})] $($rest)*)
};
(@array [$($elems:expr,)*] $next:expr, $($rest:tt)*) => {
array_internal!(@array [$($elems,)* value_internal!($next),] $($rest)*)
};
(@array [$($elems:expr,)*] $last:expr) => {
array_internal!(@array [$($elems,)* value_internal!($last)])
};
(@array [$($elems:expr),*] , $($rest:tt)*) => {
array_internal!(@array [$($elems,)*] $($rest)*)
};
(@array [$($elems:expr),*] $unexpected:tt $($rest:tt)*) => {
array_unexpected!($unexpected)
};
([]) => {
$crate::model::Array::default()
};
([ $($tt:tt)+ ]) => {
array_internal!(@array [] $($tt)+)
};
($other:ident) => {
$other
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! array_internal_vec {
($($content:tt)*) => {
vec![$($content)*]
};
}
#[macro_export]
#[doc(hidden)]
macro_rules! array_unexpected {
() => {};
}
#[macro_export]
macro_rules! scalar {
($value:literal) => {
$crate::model::Scalar::new($value)
};
($other:ident) => {
$other
};
($other:expr) => {
$crate::model::to_scalar(&$other).unwrap()
};
}
#[allow(unused_macros)]
#[macro_export]
macro_rules! call_filter {
($filter:expr, $input:expr) => {{
$crate::call_filter!($filter, $input, )
}};
($filter:expr, $input:expr, $($args:expr),*) => {{
let positional = Box::new(vec![$($crate::Expression::Literal($crate::value!($args))),*].into_iter());
let keyword = Box::new(Vec::new().into_iter());
let args = $crate::parser::FilterArguments { positional, keyword };
let runtime = $crate::runtime::RuntimeBuilder::new().build();
let input = $crate::value!($input);
$crate::ParseFilter::parse(&$filter, args)
.and_then(|filter| $crate::Filter::evaluate(&*filter, &input, &runtime))
}};
}