Skip to content

Commit b61c42a

Browse files
committed
Algorithm and follow tweaks to match what landed
1 parent 5db222a commit b61c42a

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

text/0000-macro-future-proofing.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,21 @@ allowed tokens for the given NT's fragment specifier, and is defined below.
8181

8282
*output*: whether M is valid
8383

84-
1. If there are no tokens in `M`, accept.
85-
2. For each token `T` in `M`:
86-
1. If `T` is not an NT, continue.
87-
2. If `T` is a simple NT, look ahead to the next token `T'` in `M`. If
88-
`T'` is `EOF` or a close delimiter of a token tree, replace `T'` with
89-
`F`. If `T'` is in the set `FOLLOW(NT)`, `T'` is EOF, `T'` is any NT,
90-
or `T'` is any close delimiter, continue. Else, reject.
91-
3. Else, `T` is a complex NT.
92-
1. If `T` has the form `$(...)+` or `$(...)*`, run the algorithm on
93-
the contents with `F` set to `EOF`. If it accepts, continue, else,
94-
reject.
95-
2. If `T` has the form `$(...)U+` or `$(...)U*` for some token `U`, run
96-
the algorithm on the contents with `F` set to `U`. If it accepts,
97-
continue, else, reject.
84+
For each token `T` in `M`:
85+
86+
1. If `T` is not an NT, continue.
87+
2. If `T` is a simple NT, look ahead to the next token `T'` in `M`. If
88+
`T'` is `EOF` or a close delimiter of a token tree, replace `T'` with
89+
`F`. If `T'` is in the set `FOLLOW(NT)`, `T'` is EOF, or `T'` is any close
90+
delimiter, continue. Otherwise, reject.
91+
3. Else, `T` is a complex NT.
92+
1. If `T` has the form `$(...)+` or `$(...)*`, run the algorithm on the
93+
contents with `F` set to the token following `T`. If it accepts,
94+
continue, else, reject.
95+
2. If `T` has the form `$(...)U+` or `$(...)U*` for some token `U`, run
96+
the algorithm on the contents with `F` set to `U`. If it accepts,
97+
check that the last token in the sequence can be followed by `F`. If
98+
so, accept. Otherwise, reject.
9899

99100
This algorithm should be run on every matcher in every `macro_rules`
100101
invocation, with `F` as `EOF`. If it rejects a matcher, an error should be
@@ -103,11 +104,11 @@ emitted and compilation should not complete.
103104
The current legal fragment specifiers are: `item`, `block`, `stmt`, `pat`,
104105
`expr`, `ty`, `ident`, `path`, `meta`, and `tt`.
105106

106-
- `FOLLOW(stmt)` = `FOLLOW(expr)`
107107
- `FOLLOW(pat)` = `{FatArrow, Comma, Eq}`
108-
- `FOLLOW(expr)` = `{Comma, Semicolon}`
108+
- `FOLLOW(expr)` = `{FatArrow, Comma, Semicolon}`
109+
- `FOLLOW(ty)` = `{Comma, FatArrow, Colon, Eq, Gt, Ident(as)}`
110+
- `FOLLOW(stmt)` = `FOLLOW(expr)`
109111
- `FOLLOW(path)` = `FOLLOW(ty)`
110-
- `FOLLOW(ty)` = `{Comma, RArrow, Colon, Eq, Gt, Ident(as)}`
111112
- `FOLLOW(block)` = any token
112113
- `FOLLOW(ident)` = any token
113114
- `FOLLOW(tt)` = any token
@@ -119,7 +120,7 @@ The current legal fragment specifiers are: `item`, `block`, `stmt`, `pat`,
119120
# Drawbacks
120121

121122
It does restrict the input to a MBE, but the choice of delimiters provides
122-
reasonable freedom.
123+
reasonable freedom and can be extended in the future.
123124

124125
# Alternatives
125126

0 commit comments

Comments
 (0)