Okay, that makes sense. I figured it was probably just non-trivial to
implement, but I figured I'd ask. Something else I was wondering about was
the lack of alternation or option (0:1 repetition) syntax. I was writing a
macro that would expand to a match, replacing short form patterns with
their long forms, and ended up going with this:

macro_rules! match_list (
($value:expr :
$(
$(Cons!($v1:pat, $n1:pat) => $e1:expr)*
 $(MT!() => $e2:expr)*
$(!$p:pat => $e3:expr)*
),*
 ) => (match $value {
$(
$(List(Some(~($v1, $n1))) => $e1)*
 $(List(None) => $e2)*
$($p => $e3)*
),*
 });
)

Here I'm simulating alternation by concatenating 0:n repetitions. It
happens to work in this case, since the macro will expand to a syntax error
if it matches two or more arms that aren't separated by commas. Is there
any plan to add alternation and option syntax to macro_rules in the future,
or is simulating them with 0:n repetition seen as being sufficient?


On Mon, Feb 18, 2013 at 9:23 AM, Paul Stansifer <[email protected]>wrote:

> It's just a matter of not having implemented it yet. Each new macro
> invocation location unfortunately requires modifying the AST, which affects
> all the code that is interested in that part of the AST. It's not a huge
> amount of work, but it does inflict lots of "can't happen" error cases on
> unrelated code, which is kinda sad.
>
> Paul
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to