Running the code below (Rust Playground) the first macro invocation below "A" matches the "nested" arm, while the second macro invocation below "B" first matches the split ("car") arm, but then the recursive call ends up matching the "non-nested" arm. I'm trying to get a deeper understanding of why.
My guess is that, somewhere in the process, the second expression gets parsed as a tuple, and then becomes a single token literal instead of a token-tree.
Is this guess right? And how do I stop that or somehow re-parse the code? Or do I just have a dumb bug in the macro.
tt: a TokenTree (a single token or tokens in matching delimiters (), [], or {})
And you have a , in the nested expr!($($cdr,)*) which is matched against the second branch because nothing appears after the comma. Rust Playground
You may remove the comma and the expansion is what you expect it to be. Rust Playground
P.S. obviously, if you want to specify tt to match tokens except (), you should use ( $($stuff:tt)* )
Here is an updated playground with the additional cases, switching tt to expr, and it would do what I want if I could understand why the recursive invocation won't go down the "nested" path.