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
Copy file name to clipboardExpand all lines: doc/rust.md
+13-17Lines changed: 13 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -501,14 +501,13 @@ only be invoked in expression position.
501
501
any token other than a delimiter or `$`.)
502
502
503
503
Macro invocations are looked up by name, and each macro rule is tried in turn;
504
-
the first successful match is transcribed. The matching and transcribing
504
+
the first successful match is transcribed. The matching and transcription
505
505
processes are closely related, and will be described together:
506
506
507
507
### Macro By Example
508
508
509
-
Everything that does not begin with a `$` is matched and transcirbed
510
-
literally, including delimiters. For parsing reasons, they must be matched,
511
-
but they are otherwise not special.
509
+
The macro expander matches and transcribes every token that does not begin with a `$` literally, including delimiters.
510
+
For parsing reasons, delimiters must be balanced, but they are otherwise not special.
512
511
513
512
In the matcher, `$`_name_`:`_designator_ matches the nonterminal in the
514
513
Rust syntax named by _designator_. Valid designators are `item`, `block`,
@@ -517,11 +516,11 @@ are the right-hand side and the left-hand side respectively of the `=>` in
517
516
macro rules. In the transcriber, the designator is already known, and so only
518
517
the name of a matched nonterminal comes after the dollar sign.
519
518
520
-
In bothe the matcher and transcriber, the Kleene star-like operator,
521
-
consisting of `$` and parens, optionally followed by a separator token,
522
-
followed by `*`or `+`, indicates repetition. (`*` means zero or more
523
-
repetitions, `+` means at least one repetition. The parens are not matched or
524
-
transcribed). On the matcher side, a name is bound to _all_ of the names it
519
+
In both the matcher and transcriber, the Kleene star-like operator indicates repetition.
520
+
The Kleene star operator consists of `$` and parens, optionally followed by a separator token, followed by `*` or `+`.
521
+
`*`means zero or more repetitions, `+` means at least one repetition.
522
+
The parens are not matched or transcribed.
523
+
On the matcher side, a name is bound to _all_ of the names it
525
524
matches, in a structure that mimics the structure of the repetition
526
525
encountered on a successful match. The job of the transcriber is to sort that
527
526
structure out.
@@ -550,19 +549,16 @@ Rust syntax is restricted in two ways:
550
549
1. The parser will always parse as much as possible. If it attempts to match
551
550
`$i:expr [ , ]` against `8 [ , ]`, it will attempt to parse `i` as an array
552
551
index operation and fail. Adding a separator can solve this problem.
553
-
2. The parser must have eliminated all ambiguity by the time it reaches a
554
-
`$`_name_`:`_designator_. This most often affects them when they occur in
555
-
the beginning of, or immediately after, a `$(...)*`; requiring a distinctive
556
-
token in front can solve the problem.
552
+
2. The parser must have eliminated all ambiguity by the time it reaches a `$`_name_`:`_designator_.
553
+
This requirement most often affects name-designator pairs when they occur at the beginning of, or immediately after, a `$(...)*`; requiring a distinctive token in front can solve the problem.
557
554
558
555
559
556
## Syntax extensions useful for the macro author
560
557
561
558
*`log_syntax!` : print out the arguments at compile time
562
-
*`trace_macros!` : supply `true` or `false` to enable or disable printing
563
-
of the macro expansion process.
564
-
*`ident_to_str!` : turns the identifier argument into a string literal
565
-
*`concat_idents!` : creates a new identifier by concatenating its arguments
559
+
*`trace_macros!` : supply `true` or `false` to enable or disable printing of the macro expansion process.
560
+
*`ident_to_str!` : turn the identifier argument into a string literal
561
+
*`concat_idents!` : create a new identifier by concatenating the arguments
0 commit comments