#[macro_export]
macro_rules! term {
((!$precomp:literal, $counter:expr) / $typ:ty $(>$req_type:expr)?) => {{
use $crate::algebra::dynamic_function::TypeShape;
term!((!$precomp, $counter) > TypeShape::of::<$typ>())
}};
(($agent:expr, $counter:expr) / $typ:ty $(>$req_type:expr)?) => {{
use $crate::algebra::dynamic_function::TypeShape;
term!(($agent, $counter) > TypeShape::of::<$typ>())
}};
((!$precomp:literal, $counter:expr) $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::Term;
use $crate::trace::Source;
let var = Signature::new_var($($req_type)?, Some(Source::Label(Some($precomp.into()))), None, $counter); Term::Variable(var)
}};
(($agent:expr, $counter:expr) $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::Term;
use $crate::trace::Source;
let var = Signature::new_var($($req_type)?, Some(Source::Agent($agent)), None, $counter); Term::Variable(var)
}};
((!$precomp:literal, $counter:expr) [$message_type:expr] / $typ:ty $(>$req_type:expr)?) => {{
use $crate::algebra::dynamic_function::TypeShape;
term!((!$precomp, $counter) [$message_type] > TypeShape::of::<$typ>())
}};
(($agent:expr, $counter:expr) [$message_type:expr] / $typ:ty $(>$req_type:expr)?) => {{
use $crate::algebra::dynamic_function::TypeShape;
term!(($agent, $counter) [$message_type] > TypeShape::of::<$typ>())
}};
((!$precomp:literal, $counter:expr) [$message_type:expr] $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::Term;
use $crate::trace::Source;
let var = Signature::new_var($($req_type)?, Some(Source::Label(Some($precomp.into()))), $message_type, $counter);
Term::Variable(var)
}};
(($agent:expr, $counter:expr) [$message_type:expr] $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::Term;
use $crate::trace::Source;
let var = Signature::new_var($($req_type)?, Some(Source::Agent($agent)), $message_type, $counter);
Term::Variable(var)
}};
($func:ident ($($args:tt),*) $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::Term;
let func = Signature::new_function(&$func);
#[allow(unused_assignments, unused_variables, unused_mut)]
let mut i = 0;
#[allow(unused_assignments)]
#[allow(clippy::mixed_read_write_in_expression)]
let arguments = vec![$({
#[allow(unused)]
if let Some(argument) = func.shape().argument_types.get(i) {
i += 1;
$crate::term_arg!($args > argument.clone())
} else {
panic!("too many arguments specified for function {}", func)
}
}),*];
Term::Application(func, arguments)
}};
($func:ident $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::Term;
let func = Signature::new_function(&$func);
Term::Application(func, vec![])
}};
(@$e:ident $(>$req_type:expr)?) => {{
use $crate::algebra::Term;
let subterm: &Term<_> = &$e;
subterm.clone()
}};
}
#[macro_export]
macro_rules! term_arg {
( ( $($e:tt)* ) $(>$req_type:expr)?) => (term!($($e)* $(>$req_type)?));
($e:tt $(>$req_type:expr)?) => (term!($e $(>$req_type)?));
}