Skip to content

Commit 9297d1f

Browse files
committed
Minor doc updates.
1 parent 7669032 commit 9297d1f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

doc/rust.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ matches, in a structure that mimics the structure of the repetition
522522
encountered on a successful match. The job of the transcriber is to sort that
523523
structure out.
524524

525-
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
525+
The rules for transcription of these repetitions are called "Macro By Example".
526+
Essentially, one "layer" of repetition is discharged at a time, and all of
526527
them must be discharged by the time a name is transcribed. Therefore,
527528
`( $( $i:ident ),* ) => ( $i )` is an invalid macro, but
528529
`( $( $i:ident ),* ) => ( $( $i:ident ),* )` is acceptable (if trivial).
@@ -537,6 +538,20 @@ transcribes to `( (a,d), (b,e), (c,f) )`.
537538

538539
Nested repetitions are allowed.
539540

541+
### Parsing limitations
542+
543+
The parser used by the macro system is reasonably powerful, but the parsing of
544+
Rust syntax is restricted in two ways:
545+
546+
1. The parser will always parse as much as possible. If it attempts to match
547+
`$i:expr [ , ]` against `8 [ , ]`, it will attempt to parse `i` as an array
548+
index operation and fail. Adding a separator can solve this problem.
549+
2. The parser must have eliminated all ambiguity by the time it reaches a
550+
`$` _name_ `:` _designator_. This most often affects them when they occur in
551+
the beginning of, or immediately after, a `$(...)*`; requiring a distinctive
552+
token in front can solve the problem.
553+
554+
540555
## Syntax extensions useful for the macro author
541556

542557
* `log_syntax!` : print out the arguments at compile time

doc/tutorial.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,8 +2481,9 @@ Macros, as currently implemented, are not for the faint of heart. Even
24812481
ordinary syntax errors can be more difficult to debug when they occur inside
24822482
a macro, and errors caused by parse problems in generated code can be very
24832483
tricky. Invoking the `log_syntax!` macro can help elucidate intermediate
2484-
states, and using `--pretty expanded` as an argument to the compiler will
2485-
show the result of expansion.
2484+
states, using `trace_macros!(true)` will automatically print those
2485+
intermediate states out, and using `--pretty expanded` as an argument to the
2486+
compiler will show the result of expansion.
24862487

24872488
# Traits
24882489

0 commit comments

Comments
 (0)