#[macro_export]
macro_rules! term {
((!$precomp:literal, $counter:expr) / $typ:ty $(>$req_type:expr)?) => {{
use $crate::algebra::dynamic_function::TypeShape;
Term::from(term!((!$precomp, $counter) > TypeShape::of::<$typ>()))
}};
(($agent:expr, $counter:expr) / $typ:ty $(>$req_type:expr)?) => {{
use $crate::algebra::dynamic_function::TypeShape;
use $crate::algebra::Term;
Term::from(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::from(DYTerm::Variable(var))
}};
(($agent:expr, $counter:expr) $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::{DYTerm,Term};
use $crate::trace::Source;
let var = Signature::new_var($($req_type)?, Some(Source::Agent($agent)), None, $counter); Term::from(DYTerm::Variable(var))
}};
((!$precomp:literal, $counter:expr) [$message_type:expr] / $typ:ty $(>$req_type:expr)?) => {{
use $crate::algebra::dynamic_function::TypeShape;
Term::from(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::from(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::from(DYTerm::Variable(var))
}};
(($agent:expr, $counter:expr) [$message_type:expr] $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::{DYTerm,Term};
use $crate::trace::Source;
let var = Signature::new_var($($req_type)?, Some(Source::Agent($agent)), $message_type, $counter);
Term::from(DYTerm::Variable(var))
}};
($func:ident ($($args:tt),*) $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::{DYTerm,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;
Term::from($crate::term_arg!($args > argument.clone()))
} else {
panic!("too many arguments specified for function {}", func)
}
}),*];
Term::from(DYTerm::Application(func, arguments))
}};
($func:ident $(>$req_type:expr)?) => {{
use $crate::algebra::signature::Signature;
use $crate::algebra::{DYTerm,Term};
let func = Signature::new_function(&$func);
Term::from(DYTerm::Application(func, vec![]))
}};
(@$e:ident $(>$req_type:expr)?) => {{
use $crate::algebra::{DYTerm,Term};
let subterm: &Term<_> = &$e;
Term::from(subterm.clone())
}};
}
#[macro_export]
macro_rules! term_arg {
( ( $($e:tt)* ) $(>$req_type:expr)?) => {{
use $crate::algebra::{DYTerm,Term};
Term::from(term!($($e)* $(>$req_type)?))
}};
($e:tt $(>$req_type:expr)?) => {{
Term::from(term!($e $(>$req_type)?))
}};
}