Skip to content

Commit 393aea7

Browse files
committed
only diffs in edition notes
1 parent 0b50be9 commit 393aea7

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/macros-by-example.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,23 @@ designator is already known, and so only the name of a matched nonterminal comes
5151
after the dollar sign.
5252

5353
In both the matcher and transcriber, the Kleene star-like operator indicates
54-
repetition. The Kleene star operator consists of `$` and parentheses, optionally
55-
followed by a separator token, followed by `*` or `+`. `*` means zero or more
56-
repetitions, `+` means at least one repetition. The parentheses are not matched or
57-
transcribed. On the matcher side, a name is bound to _all_ of the names it
58-
matches, in a structure that mimics the structure of the repetition encountered
59-
on a successful match. The job of the transcriber is to sort that structure
60-
out.
61-
62-
> **Edition Differences**: In the 2018 edition, a new Kleene operator was
63-
> added: `?` means "at most once". This operator only works in edition 2018 and
64-
> onward. `?` does not accept a repetition separator, unlike `+` and `*`.
54+
repetition. The Kleene star operator consists of `$` and parentheses,
55+
optionally followed by a separator token, followed by `*`, `+`, or `?`. `*`
56+
means zero or more repetitions; `+` means _at least_ one repetition; `?` means
57+
at most one repetition. The parentheses are not matched or transcribed. On the
58+
matcher side, a name is bound to _all_ of the names it matches, in a structure
59+
that mimics the structure of the repetition encountered on a successful match.
60+
The job of the transcriber is to sort that structure out. Also, `?`, unlike `*`
61+
and `+`, does _not_ allow a separator, since one could never match against it
62+
anyway.
63+
64+
> **Edition Differences**: The `?` Kleene operator did not exist before the
65+
> 2018 edition.
66+
67+
> **Edition Differences**: Prior to the 2018 Edition, `?` was an allowed
68+
> separator token, rather than a Kleene operator. It is no longer allowed as a
69+
> separator as of the 2018 edition. This avoids ambiguity with the `?` Kleene
70+
> operator.
6571
6672
The rules for transcription of these repetitions are called "Macro By Example".
6773
Essentially, one "layer" of repetition is discharged at a time, and all of them
@@ -93,8 +99,4 @@ Rust syntax is restricted in two ways:
9399
pairs when they occur at the beginning of, or immediately after, a `$(...)*`;
94100
requiring a distinctive token in front can solve the problem.
95101

96-
> **Edition Differences**: As of the 2018 edition, `?` is not allowed as a
97-
> repetition separator. This is to remove ambiguity with the new `?` Kleene
98-
> operator.
99-
100102
[RFC 550]: https://github.com/rust-lang/rfcs/blob/master/text/0550-macro-future-proofing.md

0 commit comments

Comments
 (0)