Skip to content

Commit e28a161

Browse files
committed
Merge pull request #3799 from paulstansifer/master
Add examples to the parsing limitations section of the macro tutorial.
2 parents fdd7b4d + 0f2fc71 commit e28a161

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

doc/tutorial-macros.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,22 @@ If it is under more, it'll be repeated, as appropriate.
155155

156156
## Parsing limitations
157157

158-
The macro parser will parse Rust syntax with two limitations:
159158

160-
1. The parser will always parse as much as possible. For example, if the comma
161-
were omitted from the syntax of `early_return!` above, `input_1 [` would've
162-
been interpreted as the beginning of an array index. In fact, invoking the
163-
macro would have been impossible.
164-
2. The parser must have eliminated all ambiguity by the time it reaches a
159+
For technical reasons, there are two limitations to the treatment of syntax
160+
fragments by the macro parser:
161+
162+
1. The parser will always parse as much as possible of a Rust syntactic
163+
fragment. For example, if the comma were omitted from the syntax of
164+
`early_return!` above, `input_1 [` would've been interpreted as the beginning
165+
of an array index. In fact, invoking the macro would have been impossible.
166+
2. The parser must have eliminated all ambiguity by the time it reaches a
165167
`$name:fragment_specifier` declaration. This limitation can result in parse
166168
errors when declarations occur at the beginning of, or immediately after,
167-
a `$(...)*`. Changing the invocation syntax to require a distinctive
168-
token in front can solve the problem.
169+
a `$(...)*`. For example, the grammar `$($t:ty)* $e:expr` will always fail to
170+
parse because the parser would be forced to choose between parsing `t` and
171+
parsing `e`. Changing the invocation syntax to require a distinctive token in
172+
front can solve the problem. In the above example, `$(T $t:ty)* E $e:exp`
173+
solves the problem.
169174

170175
## A final note
171176

0 commit comments

Comments
 (0)