In a macro_rules! transcriber, nested repetitions are not handled properly. This works fine:
macro_rules! demo_macro {
($op:tt; $($arg:tt),*) {
($($op * $arg),*)
}
}
fn main() {
println!("{?:}", demo_macro!(2; 1,2,3));
}
and outputs (2, 4, 6), but this does not compile:
macro_rules! demo_macro {
([$($op:tt)*] $($arg:tt),*) {
($($($op)* $arg),*)
}
}
fn main() {
println!("{?:}", demo_macro!([2*] 1,2,3));
}
and results in this error message:
error: meta-variable `op` repeats 2 times, but `arg` repeats 3 times
--> src/main.rs:3:11
|
3 | ($($($op)* $arg),*)
| ^^^^^^^^^^^^^^
If I change 1,2,3 to 1,2 so the repetition counts match up, I get this error message:
error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
--> src/main.rs:3:13
|
3 | ($($($op)* $arg),*)
| ^^^^^
Any idea how to make demo_macro!([2*] 1,2,3) result in (2, 4, 6)?