Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some notes on repetition #424

Merged
merged 2 commits into from
Sep 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/macros-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,23 @@ designator is already known, and so only the name of a matched nonterminal comes
after the dollar sign.

In both the matcher and transcriber, the Kleene star-like operator indicates
repetition. The Kleene star operator consists of `$` and parentheses, optionally
followed by a separator token, followed by `*` or `+`. `*` means zero or more
repetitions, `+` means at least one repetition. The parentheses are not matched or
transcribed. On the matcher side, a name is bound to _all_ of the names it
matches, in a structure that mimics the structure of the repetition encountered
on a successful match. The job of the transcriber is to sort that structure
out.
repetition. The Kleene star operator consists of `$` and parentheses,
optionally followed by a separator token, followed by `*`, `+`, or `?`. `*`
means zero or more repetitions; `+` means _at least_ one repetition; `?` means
at most one repetition. The parentheses are not matched or transcribed. On the
matcher side, a name is bound to _all_ of the names it matches, in a structure
that mimics the structure of the repetition encountered on a successful match.
The job of the transcriber is to sort that structure out. Also, `?`, unlike `*`
and `+`, does _not_ allow a separator, since one could never match against it
anyway.

> **Edition Differences**: The `?` Kleene operator did not exist before the
> 2018 edition.

> **Edition Differences**: Prior to the 2018 Edition, `?` was an allowed
> separator token, rather than a Kleene operator. It is no longer allowed as a
> separator as of the 2018 edition. This avoids ambiguity with the `?` Kleene
> operator.

The rules for transcription of these repetitions are called "Macro By Example".
Essentially, one "layer" of repetition is discharged at a time, and all of them
Expand Down