# Pre-RFC: at most one repetition macro patterns

**URL:** <https://internals.rust-lang.org/t/pre-rfc-at-most-one-repetition-macro-patterns/6557>\
**Category:** language design\
**Created:** [January 15, 2018, 5:44am UTC](https://internals.rust-lang.org/t/pre-rfc-at-most-one-repetition-macro-patterns/6557 "2018-01-15T05:44:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![kennytm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kennytm/32/161_2.png) [@kennytm](https://internals.rust-lang.org/u/kennytm)\
**Post date:** [January 15, 2018, 4:45pm UTC](https://internals.rust-lang.org/t/pre-rfc-at-most-one-repetition-macro-patterns/6557/2 "2018-01-15T16:45:01Z")

</div>

> [@mark-i-m](#):
>
> Under this RFC, one would simply write:
> 
> ```rust
> macro_rules! foo {
> (do $b1:block $(and $b2:block)?) => {
> $b1
> $($b2)*
> }
> }
> 
> ```

Why is `$b2` expanded using `*`?

> [@mark-i-m](#):
>
> I don’t think it has grammar ambiguities

There **is** ambiguity: `$($x:ident)?+` today matches `a?b?c` and not `a+`. Fortunately this is easy to resolve: you just look one more token ahead and always treat `?*` and `?+` to mean separate by the question mark token.

> [@mark-i-m](#):
>
> Finally, we could consider adding something more general, such as “at most N repetitions”. It’s not clear what syntax we could use for this. Perhaps something like $(pat)N?, where N is replaced with an integer. I’m not sure if this retains syntactic disambiguity. Also, it’s not clear how useful such a pattern would be.

`$($x:tt){2,7}` 😉

---

_[View the full topic](https://internals.rust-lang.org/t/pre-rfc-at-most-one-repetition-macro-patterns/6557)._
