@@ -81,20 +81,21 @@ allowed tokens for the given NT's fragment specifier, and is defined below.
81
81
82
82
* output* : whether M is valid
83
83
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.
98
99
99
100
This algorithm should be run on every matcher in every ` macro_rules `
100
101
invocation, with ` F ` as ` EOF ` . If it rejects a matcher, an error should be
@@ -103,11 +104,11 @@ emitted and compilation should not complete.
103
104
The current legal fragment specifiers are: ` item ` , ` block ` , ` stmt ` , ` pat ` ,
104
105
` expr ` , ` ty ` , ` ident ` , ` path ` , ` meta ` , and ` tt ` .
105
106
106
- - ` FOLLOW(stmt) ` = ` FOLLOW(expr) `
107
107
- ` 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) `
109
111
- ` FOLLOW(path) ` = ` FOLLOW(ty) `
110
- - ` FOLLOW(ty) ` = ` {Comma, RArrow, Colon, Eq, Gt, Ident(as)} `
111
112
- ` FOLLOW(block) ` = any token
112
113
- ` FOLLOW(ident) ` = any token
113
114
- ` FOLLOW(tt) ` = any token
@@ -119,7 +120,7 @@ The current legal fragment specifiers are: `item`, `block`, `stmt`, `pat`,
119
120
# Drawbacks
120
121
121
122
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 .
123
124
124
125
# Alternatives
125
126
0 commit comments