Skip to content

Commit e09454d

Browse files
authored
Merge pull request #424 from mark-i-m/macro_at_most_once_rep
Add some notes on repetition
2 parents cf32d63 + 393aea7 commit e09454d

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/macros-by-example.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +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.
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.
6171
6272
The rules for transcription of these repetitions are called "Macro By Example".
6373
Essentially, one "layer" of repetition is discharged at a time, and all of them

0 commit comments

Comments
 (0)