It is easy to write a macro that calls itself on all suffixes of the argument list:
macro_rules! suffixes {
() => {};
($first:ident, $($tail:ident),*) => {
suffixes!($($tail),*);
}
}
Is it possible to write a macro that calls itself for all the prefixes?
That is, a call to prefixes!(a0, a1, a2)
should actually call:
prefixes!(a0, a1, a2);
prefixes!(a0, a1);
prefixes!(a0);
prefixes!();
The naive way of doing it by just swapping the order of matching does not work, because it creates parsing ambiguity.