@@ -19,15 +19,15 @@ use token::*;
19
19
pub mod rt {
20
20
pub use ast:: * ;
21
21
pub use parse:: token:: * ;
22
- pub use parse:: new_parser_from_tt ;
22
+ pub use parse:: new_parser_from_tts ;
23
23
pub use codemap:: BytePos ;
24
24
pub use codemap:: span;
25
25
}
26
26
27
27
pub fn expand_quote_tokens ( cx : ext_ctxt ,
28
28
sp : span ,
29
29
tts : ~[ ast:: token_tree ] ) -> base:: mac_result {
30
- base:: mr_expr ( expand_tt ( cx, sp, tts) )
30
+ base:: mr_expr ( expand_tts ( cx, sp, tts) )
31
31
}
32
32
33
33
pub fn expand_quote_expr ( cx : ext_ctxt ,
@@ -121,8 +121,7 @@ fn mk_span(cx: ext_ctxt, qsp: span, sp: span) -> @ast::expr {
121
121
}
122
122
} ;
123
123
124
- let span_path = ids_ext (
125
- cx, ~[ ~"syntax", ~"ext", ~"quote", ~"rt", ~"span"] ) ;
124
+ let span_path = ids_ext ( cx, ~[ ~"span"] ) ;
126
125
127
126
build:: mk_struct_e ( cx, qsp,
128
127
span_path,
@@ -150,7 +149,7 @@ fn mk_ident(cx: ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr {
150
149
}
151
150
152
151
fn mk_bytepos ( cx : ext_ctxt , sp : span , bpos : BytePos ) -> @ast:: expr {
153
- let path = ids_ext ( cx, ~[ ~"syntax" , ~"ext" , ~"quote" , ~"rt" , ~" BytePos "] ) ;
152
+ let path = ids_ext ( cx, ~[ ~"BytePos "] ) ;
154
153
let arg = build:: mk_uint ( cx, sp, bpos. to_uint ( ) ) ;
155
154
build:: mk_call ( cx, sp, path, ~[ arg] )
156
155
}
@@ -318,17 +317,21 @@ fn mk_token(cx: ext_ctxt, sp: span, tok: token::Token) -> @ast::expr {
318
317
319
318
fn mk_tt( cx : ext_ctxt , sp : span , tt : & ast:: token_tree ) -> @ast:: expr {
320
319
match * tt {
321
- ast:: tt_tok( sp, tok) =>
322
- build:: mk_call ( cx, sp,
323
- ids_ext ( cx, ~[ ~"tt_tok"] ) ,
324
- ~[ mk_span ( cx, sp, sp) ,
325
- mk_token ( cx, sp, tok) ] ) ,
320
+ ast:: tt_tok( sp, tok) => {
321
+ let e_tok =
322
+ build:: mk_call ( cx, sp,
323
+ ids_ext ( cx, ~[ ~"tt_tok"] ) ,
324
+ ~[ mk_span ( cx, sp, sp) ,
325
+ mk_token ( cx, sp, tok) ] ) ;
326
+ build:: mk_uniq_vec_e ( cx, sp, ~[ e_tok] )
327
+ }
326
328
327
329
ast:: tt_delim( tts) => {
328
- let e_tts = tts. map ( |tt| mk_tt ( cx, sp, tt) ) ;
329
- build:: mk_call ( cx, sp,
330
- ids_ext ( cx, ~[ ~"tt_delim"] ) ,
331
- ~[ build:: mk_uniq_vec_e ( cx, sp, e_tts) ] )
330
+ let e_delim =
331
+ build:: mk_call ( cx, sp,
332
+ ids_ext ( cx, ~[ ~"tt_delim"] ) ,
333
+ ~[ mk_tts ( cx, sp, tts) ] ) ;
334
+ build:: mk_uniq_vec_e ( cx, sp, ~[ e_delim] )
332
335
}
333
336
334
337
ast:: tt_seq( * ) => fail ~"tt_seq in quote!",
@@ -338,39 +341,41 @@ fn mk_tt(cx: ext_ctxt, sp: span, tt: &ast::token_tree) -> @ast::expr {
338
341
}
339
342
}
340
343
344
+ fn mk_tts(cx: ext_ctxt, sp: span, tts: &[ast::token_tree]) -> @ast::expr {
345
+ let e_tts = tts.map(|tt| mk_tt(cx, sp, tt));
346
+ build::mk_call(cx, sp,
347
+ ids_ext(cx, ~[~" vec", ~"concat"] ) ,
348
+ ~[ build:: mk_slice_vec_e( cx, sp, e_tts) ] )
349
+ }
341
350
342
- fn expand_tt (cx: ext_ctxt,
343
- sp: span,
344
- tts: ~[ast::token_tree]) -> @ast::expr {
351
+ fn expand_tts ( cx: ext_ctxt,
352
+ sp: span,
353
+ tts: ~[ ast:: token_tree] ) -> @ast:: expr {
345
354
// NB: It appears that the main parser loses its mind if we consider
346
355
// $foo as a tt_nonterminal during the main parse, so we have to re-parse
347
356
// under quote_depth > 0. This is silly and should go away; the _guess_ is
348
357
// it has to do with transition away from supporting old-style macros, so
349
358
// try removing it when enough of them are gone.
350
- let p = parse::new_parser_from_tt (cx.parse_sess(), cx.cfg(), tts);
359
+ let p = parse : : new_parser_from_tts ( cx. parse_sess( ) , cx. cfg( ) , tts) ;
351
360
p. quote_depth += 1 u;
352
- let tq = dvec::DVec();
353
- while p.token != token::EOF {
354
- tq.push(p.parse_token_tree());
355
- }
356
- let tts = tq.get();
361
+ let tts = p. parse_all_token_trees( ) ;
362
+ p. abort_if_errors( ) ;
357
363
358
364
// We want to emit a block expression that does a sequence of 'use's to
359
365
// import the runtime module, followed by a tt expression.
360
366
let uses = ~[ build:: mk_glob_use( cx, sp, ids_ext( cx, ~[ ~"syntax",
361
367
~"ext",
362
368
~"quote",
363
369
~"rt"] ) ) ] ;
364
- build:: mk_block( cx, sp, uses, ~[ ] ,
365
- Some ( mk_tt( cx, sp, & ast:: tt_delim( tts) ) ) )
370
+ build:: mk_block( cx, sp, uses, ~[ ] , Some ( mk_tts( cx, sp, tts) ) )
366
371
}
367
372
368
373
fn expand_parse_call( cx: ext_ctxt,
369
374
sp : span,
370
375
parse_method : ~str,
371
376
arg_exprs : ~[ @ast:: expr] ,
372
377
tts : ~[ ast:: token_tree] ) -> @ast:: expr {
373
- let tt_expr = expand_tt ( cx, sp, tts) ;
378
+ let tts_expr = expand_tts ( cx, sp, tts) ;
374
379
375
380
let cfg_call = || build:: mk_call_(
376
381
cx, sp, build:: mk_access( cx, sp, ids_ext( cx, ~[ ~"ext_cx"] ) ,
@@ -386,10 +391,10 @@ fn expand_parse_call(cx: ext_ctxt,
386
391
~"ext",
387
392
~"quote",
388
393
~"rt",
389
- ~"new_parser_from_tt "] ) ,
394
+ ~"new_parser_from_tts "] ) ,
390
395
~[ parse_sess_call( ) ,
391
396
cfg_call( ) ,
392
- build :: mk_uniq_vec_e ( cx , sp , ~ [ tt_expr ] ) ] ) ;
397
+ tts_expr ] ) ;
393
398
394
399
build:: mk_call_( cx, sp,
395
400
build:: mk_access_( cx, sp, new_parser_call,
0 commit comments