Debugging was interesting. I started with the simplest input and worked from there. I found that I had problems with the print functions (rewrite so that it just prints the inputs and doesnβt come back!).
I also added rules that were more explicit, and then deleted them as soon as everything worked (one by one, of course, testing along the way). As soon as I realized that every single part compiles and the print functions work, I was able to check the output of the macros. This macro sometimes runs when it shouldn't, but it compiles, prints, and debugs. I am happy enough with the current state to post it here.
fn main() { // "Bitwise Cyclic Tag" automation through macros macro_rules! bct { // cmd 0: 0 ... => ... (0, $($program:tt),* ; $_head:tt) => (pbct!($($program),*, 0 ; )); (0, $($program:tt),* ; $_head:tt, $($tail:tt),*) => (pbct!($($program),*, 0 ; $($tail),*)); // cmd 1x: 1 ... => 1 ... x (1, $x:tt, $($program:tt),* ; 1) => (pbct!($($program),*, 1, $x ; 1, $x)); (1, $x:tt, $($program:tt),* ; 1, $($tail:tt),*) => (pbct!($($program),*, 1, $x ; 1, $($tail),*, $x)); // cmd 1x: 0 ... => 0 ... (1, $x:tt, $($program:tt),* ; $($tail:tt),*) => (pbct!($($program),*, 1, $x ; $($tail),*)); // halt on empty data string ( $($program:tt),* ; ) => (()); } macro_rules! println_bct { () => (println!("")); (;) => (println!(":")); ($d:tt) => (println!("{}", stringify!($d))); ($d:tt, $($data:tt),*) => { print!("{}", stringify!($d)); println_bct!($($data),*); }; ( ; $($data:tt),*) => { print!(":"); println_bct!($($data),*); }; ($x:tt ; $($data:tt),*) => { print!("{}", stringify!($x)); println_bct!( ; $($data),*); }; ($x:tt, $($program:tt),* ; $($data:tt),*) => { print!("{}", stringify!($x)); println_bct!($($program),* ; $($data),*); }; } macro_rules! pbct { ($($program:tt),* ; $($data:tt),*) => { println_bct!($($program),* ; $($data),*); bct!($($program),* ; $($data),*); }; } pbct!(0, 0, 1, 1, 1, 0, 0, 0 ; 1, 0, 1); // This one causes the compiler to hit recursion limits, heh // pbct!(0, 0, 1, 1, 1, 1, 1, 0 ; 1, 0, 1); }