@@ -18,8 +18,7 @@ use errors::DiagnosticBuilder;
18
18
use ext:: expand:: { self , Invocation , Expansion } ;
19
19
use ext:: hygiene:: Mark ;
20
20
use fold:: { self , Folder } ;
21
- use parse;
22
- use parse:: parser:: { self , Parser } ;
21
+ use parse:: { self , parser} ;
23
22
use parse:: token;
24
23
use parse:: token:: { InternedString , str_to_ident} ;
25
24
use ptr:: P ;
@@ -188,146 +187,6 @@ impl<F> AttrProcMacro for F
188
187
}
189
188
}
190
189
191
- pub struct TokResult < ' a > {
192
- pub parser : Parser < ' a > ,
193
- pub span : Span ,
194
- }
195
-
196
- impl < ' a > TokResult < ' a > {
197
- // There is quite a lot of overlap here with ParserAnyMacro in ext/tt/macro_rules.rs
198
- // We could probably share more code.
199
- // FIXME(#36641) Unify TokResult and ParserAnyMacro.
200
- fn ensure_complete_parse ( & mut self , allow_semi : bool ) {
201
- let macro_span = & self . span ;
202
- self . parser . ensure_complete_parse ( allow_semi, |parser| {
203
- let token_str = parser. this_token_to_string ( ) ;
204
- let msg = format ! ( "macro expansion ignores token `{}` and any following" , token_str) ;
205
- let span = parser. span ;
206
- parser. diagnostic ( )
207
- . struct_span_err ( span, & msg)
208
- . span_note ( * macro_span, "caused by the macro expansion here" )
209
- . emit ( ) ;
210
- } ) ;
211
- }
212
- }
213
-
214
- impl < ' a > MacResult for TokResult < ' a > {
215
- fn make_items ( mut self : Box < Self > ) -> Option < SmallVector < P < ast:: Item > > > {
216
- if self . parser . sess . span_diagnostic . has_errors ( ) {
217
- return Some ( SmallVector :: zero ( ) ) ;
218
- }
219
-
220
- let mut items = SmallVector :: zero ( ) ;
221
- loop {
222
- match self . parser . parse_item ( ) {
223
- Ok ( Some ( item) ) => items. push ( item) ,
224
- Ok ( None ) => {
225
- self . ensure_complete_parse ( false ) ;
226
- return Some ( items) ;
227
- }
228
- Err ( mut e) => {
229
- e. emit ( ) ;
230
- return Some ( SmallVector :: zero ( ) ) ;
231
- }
232
- }
233
- }
234
- }
235
-
236
- fn make_impl_items ( mut self : Box < Self > ) -> Option < SmallVector < ast:: ImplItem > > {
237
- let mut items = SmallVector :: zero ( ) ;
238
- loop {
239
- if self . parser . token == token:: Eof {
240
- break ;
241
- }
242
- match self . parser . parse_impl_item ( ) {
243
- Ok ( item) => items. push ( item) ,
244
- Err ( mut e) => {
245
- e. emit ( ) ;
246
- return Some ( SmallVector :: zero ( ) ) ;
247
- }
248
- }
249
- }
250
- self . ensure_complete_parse ( false ) ;
251
- Some ( items)
252
- }
253
-
254
- fn make_trait_items ( mut self : Box < Self > ) -> Option < SmallVector < ast:: TraitItem > > {
255
- let mut items = SmallVector :: zero ( ) ;
256
- loop {
257
- if self . parser . token == token:: Eof {
258
- break ;
259
- }
260
- match self . parser . parse_trait_item ( ) {
261
- Ok ( item) => items. push ( item) ,
262
- Err ( mut e) => {
263
- e. emit ( ) ;
264
- return Some ( SmallVector :: zero ( ) ) ;
265
- }
266
- }
267
- }
268
- self . ensure_complete_parse ( false ) ;
269
- Some ( items)
270
- }
271
-
272
- fn make_expr ( mut self : Box < Self > ) -> Option < P < ast:: Expr > > {
273
- match self . parser . parse_expr ( ) {
274
- Ok ( e) => {
275
- self . ensure_complete_parse ( true ) ;
276
- Some ( e)
277
- }
278
- Err ( mut e) => {
279
- e. emit ( ) ;
280
- Some ( DummyResult :: raw_expr ( self . span ) )
281
- }
282
- }
283
- }
284
-
285
- fn make_pat ( mut self : Box < Self > ) -> Option < P < ast:: Pat > > {
286
- match self . parser . parse_pat ( ) {
287
- Ok ( e) => {
288
- self . ensure_complete_parse ( false ) ;
289
- Some ( e)
290
- }
291
- Err ( mut e) => {
292
- e. emit ( ) ;
293
- Some ( P ( DummyResult :: raw_pat ( self . span ) ) )
294
- }
295
- }
296
- }
297
-
298
- fn make_stmts ( mut self : Box < Self > ) -> Option < SmallVector < ast:: Stmt > > {
299
- let mut stmts = SmallVector :: zero ( ) ;
300
- loop {
301
- if self . parser . token == token:: Eof {
302
- break ;
303
- }
304
- match self . parser . parse_full_stmt ( false ) {
305
- Ok ( Some ( stmt) ) => stmts. push ( stmt) ,
306
- Ok ( None ) => { /* continue */ }
307
- Err ( mut e) => {
308
- e. emit ( ) ;
309
- return Some ( SmallVector :: zero ( ) ) ;
310
- }
311
- }
312
- }
313
- self . ensure_complete_parse ( false ) ;
314
- Some ( stmts)
315
- }
316
-
317
- fn make_ty ( mut self : Box < Self > ) -> Option < P < ast:: Ty > > {
318
- match self . parser . parse_ty ( ) {
319
- Ok ( e) => {
320
- self . ensure_complete_parse ( false ) ;
321
- Some ( e)
322
- }
323
- Err ( mut e) => {
324
- e. emit ( ) ;
325
- Some ( DummyResult :: raw_ty ( self . span ) )
326
- }
327
- }
328
- }
329
- }
330
-
331
190
/// Represents a thing that maps token trees to Macro Results
332
191
pub trait TTMacroExpander {
333
192
fn expand < ' cx > ( & self ,
0 commit comments