I have a macro rule that defines two kinds of rules.
macro_rules! export_functions {
($(($FUNC:ident, $($arg:ident)*, $DOC:expr)),*) => {
pub mod expr_fn {
$(
#[doc = $DOC]
/// Return $name(arg)
pub fn $FUNC($($arg: datafusion_expr::Expr),*) -> datafusion_expr::Expr {
super::$FUNC().call(vec![$($arg),*],)
}
)*
}
};
($(($FUNC:ident, $DOC:expr)),*) => {
pub mod expr_fn {
$(
#[doc = $DOC]
/// Return $name(arg)
pub fn $FUNC(args: Vec<datafusion_expr::Expr>) -> datafusion_expr::Expr {
super::$FUNC().call(args)
}
)*
}
}
}
I have two macro rules with repetitions allowed, it only works if all the rule is the same type, but I don't know how can I mix these two rules in the group.
I would like this caller to work
export_functions!(
(nullif, arg_1 arg_2, "returns NULL if value1 equals value2; otherwise it returns value1. This can be used to perform the inverse operation of the COALESCE expression."),
(coalesce, "Returns `coalesce(args...)`, which evaluates to the value of the first expr which is not NULL"),
);
Is mixing rules in repetition possible to do?
compiler complains with
no rules expected the token `"Returns `coalesce(args...)`, which evaluates to the value of the first expr which is not NULL"`
no rules expected this token in macro call