You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(A `sep_token` is any token other than `*` and `+`. A `non_special_token` is
495
+
any token other than a delimiter or `$`.)
496
+
497
+
Macro invocations are looked up by name, and each macro rule is tried in turn;
498
+
the first successful match is transcribed. The matching and transcribing
499
+
processes are close cousins, and will be described together:
500
+
501
+
### Macro By Example
502
+
503
+
Everything that does not begin with a `$` is matched and transcirbed
504
+
literally, including delimiters. For parsing reasons, they must be matched,
505
+
but they are otherwise not special.
506
+
507
+
In the matcher, `$`_name_`:`_designator_ matches the nonterminal in the
508
+
Rust syntax named by _designator_. Valid designators are `item`, `block`,
509
+
`stmt`, `pat`, `expr`, `ty`, `ident`, `path`, `tt`, `matchers`. The last two
510
+
are the right-hand side and the left-hand side respectively of the `=>` in
511
+
macro rules. In the transcriber, the designator is already known, and so only
512
+
the name of a matched nonterminal comes after the dollar sign.
513
+
514
+
In bothe the matcher and transcriber, the Kleene star-like operator,
515
+
consisting of `$` and parens, optionally followed by a separator token,
516
+
followed by `*` or `+`, indicates repetition. (`*` means zero or more
517
+
repetitions, `+` means at least one repetition. The parens are not matched or
518
+
transcribed). On the matcher side, a name is bound to _all_ of the names it
519
+
matches, in a structure that mimics the structure of the repetition
520
+
encountered on a successful match. The job of the transcriber is to sort that
521
+
structure out.
522
+
523
+
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
524
+
them must be discharged by the time a name is transcribed. Therefore,
525
+
`( $( $i:ident ),* ) => ( $i )` is an invalid macro, but
0 commit comments