@@ -19,15 +19,15 @@ use token::*;
1919pub mod rt {
2020 pub use ast:: * ;
2121 pub use parse:: token:: * ;
22- pub use parse:: new_parser_from_tt ;
22+ pub use parse:: new_parser_from_tts ;
2323 pub use codemap:: BytePos ;
2424 pub use codemap:: span;
2525}
2626
2727pub fn expand_quote_tokens ( cx : ext_ctxt ,
2828 sp : span ,
2929 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) )
3131}
3232
3333pub fn expand_quote_expr ( cx : ext_ctxt ,
@@ -121,8 +121,7 @@ fn mk_span(cx: ext_ctxt, qsp: span, sp: span) -> @ast::expr {
121121 }
122122 } ;
123123
124- let span_path = ids_ext (
125- cx, ~[ ~"syntax", ~"ext", ~"quote", ~"rt", ~"span"] ) ;
124+ let span_path = ids_ext ( cx, ~[ ~"span"] ) ;
126125
127126 build:: mk_struct_e ( cx, qsp,
128127 span_path,
@@ -150,7 +149,7 @@ fn mk_ident(cx: ext_ctxt, sp: span, ident: ast::ident) -> @ast::expr {
150149}
151150
152151fn 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 "] ) ;
154153 let arg = build:: mk_uint ( cx, sp, bpos. to_uint ( ) ) ;
155154 build:: mk_call ( cx, sp, path, ~[ arg] )
156155}
@@ -318,17 +317,21 @@ fn mk_token(cx: ext_ctxt, sp: span, tok: token::Token) -> @ast::expr {
318317
319318fn mk_tt( cx : ext_ctxt , sp : span , tt : & ast:: token_tree ) -> @ast:: expr {
320319 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+ }
326328
327329 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] )
332335 }
333336
334337 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 {
338341 }
339342}
340343
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+ }
341350
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 {
345354 // NB: It appears that the main parser loses its mind if we consider
346355 // $foo as a tt_nonterminal during the main parse, so we have to re-parse
347356 // under quote_depth > 0. This is silly and should go away; the _guess_ is
348357 // it has to do with transition away from supporting old-style macros, so
349358 // 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) ;
351360 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( ) ;
357363
358364 // We want to emit a block expression that does a sequence of 'use's to
359365 // import the runtime module, followed by a tt expression.
360366 let uses = ~[ build:: mk_glob_use( cx, sp, ids_ext( cx, ~[ ~"syntax",
361367 ~"ext",
362368 ~"quote",
363369 ~"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) ) )
366371}
367372
368373fn expand_parse_call( cx: ext_ctxt,
369374 sp : span,
370375 parse_method : ~str,
371376 arg_exprs : ~[ @ast:: expr] ,
372377 tts : ~[ ast:: token_tree] ) -> @ast:: expr {
373- let tt_expr = expand_tt ( cx, sp, tts) ;
378+ let tts_expr = expand_tts ( cx, sp, tts) ;
374379
375380 let cfg_call = || build:: mk_call_(
376381 cx, sp, build:: mk_access( cx, sp, ids_ext( cx, ~[ ~"ext_cx"] ) ,
@@ -386,10 +391,10 @@ fn expand_parse_call(cx: ext_ctxt,
386391 ~"ext",
387392 ~"quote",
388393 ~"rt",
389- ~"new_parser_from_tt "] ) ,
394+ ~"new_parser_from_tts "] ) ,
390395 ~[ parse_sess_call( ) ,
391396 cfg_call( ) ,
392- build :: mk_uniq_vec_e ( cx , sp , ~ [ tt_expr ] ) ] ) ;
397+ tts_expr ] ) ;
393398
394399 build:: mk_call_( cx, sp,
395400 build:: mk_access_( cx, sp, new_parser_call,
0 commit comments