(note that you should wrap your second RHS in `{}` in order to avoid
hitting the following bugs: https://github.com/mozilla/rust/issues/8012
https://github.com/mozilla/rust/issues/4375)
I had misunderstood your original question: now I see that, by "operate
on", you meant that you wanted to run the macro parser on code that has
already been parsed from tokens into AST. There isn't a mechanism to do
this in the Rust macro system. However, you have discovered a potential
workaround: capture the tokens as a token tree and pass them as an argument
to a macro (which, after all, accepts token trees as arguments).
The parse error is caused by the fact that (perhaps unintuitively), `tt`
only matches a single token if it doesn't see a `(`, `[`, or `{`. I have
not tested the following code (I fear it may run afoul of macro parser
limitations), but this may work:
macro_rules! stmt_list(
( while $cond:expr { $($body:tt)+ } ) =>
( while $cond { stmt_list!( $($body)+ ) } );
( $head:stmt ; $($rest:tt)+ ) =>
( $head ; stmt_list!( $($rest)+ ) );
( $head:stmt ) =>
( $head );
)
Paul
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev