> { match *tt { + ast::TtToken(sp, SubstNt(ident, _)) => { + // tt.extend($ident.to_tokens(ext_cx).into_iter()) + + let e_to_toks = + cx.expr_method_call(sp, + cx.expr_ident(sp, ident), + id_ext("to_tokens"), + vec!(cx.expr_ident(sp, id_ext("ext_cx")))); + let e_to_toks = + cx.expr_method_call(sp, e_to_toks, id_ext("into_iter"), vec![]); + + let e_push = + cx.expr_method_call(sp, + cx.expr_ident(sp, id_ext("tt")), + id_ext("extend"), + vec!(e_to_toks)); + + vec!(cx.stmt_expr(e_push)) + } ast::TtToken(sp, ref tok) => { let e_sp = cx.expr_ident(sp, id_ext("_sp")); let e_tok = cx.expr_call(sp, @@ -673,25 +706,6 @@ fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec
> {
.collect()
},
ast::TtSequence(..) => panic!("TtSequence in quote!"),
- ast::TtNonterminal(sp, ident) => {
- // tt.extend($ident.to_tokens(ext_cx).into_iter())
-
- let e_to_toks =
- cx.expr_method_call(sp,
- cx.expr_ident(sp, ident),
- id_ext("to_tokens"),
- vec!(cx.expr_ident(sp, id_ext("ext_cx"))));
- let e_to_toks =
- cx.expr_method_call(sp, e_to_toks, id_ext("into_iter"), vec![]);
-
- let e_push =
- cx.expr_method_call(sp,
- cx.expr_ident(sp, id_ext("tt")),
- id_ext("extend"),
- vec!(e_to_toks));
-
- vec!(cx.stmt_expr(e_push))
- },
}
}
diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs
index b522d5881d762..1f0b667259473 100644
--- a/src/libsyntax/ext/tt/macro_parser.rs
+++ b/src/libsyntax/ext/tt/macro_parser.rs
@@ -78,126 +78,165 @@
use ast;
-use ast::{Matcher, MatchTok, MatchSeq, MatchNonterminal, Ident};
+use ast::{TokenTree, Ident};
+use ast::{TtDelimited, TtSequence, TtToken};
use codemap::{BytePos, mk_sp};
use codemap;
use parse::lexer::*; //resolve bug?
use parse::ParseSess;
use parse::attr::ParserAttr;
use parse::parser::{LifetimeAndTypesWithoutColons, Parser};
+use parse::token::{Eof, DocComment, MatchNt, SubstNt};
use parse::token::{Token, Nonterminal};
use parse::token;
use print::pprust;
use ptr::P;
+use std::mem;
use std::rc::Rc;
use std::collections::HashMap;
+use std::collections::hash_map::{Vacant, Occupied};
-/* to avoid costly uniqueness checks, we require that `MatchSeq` always has a
-nonempty body. */
+// To avoid costly uniqueness checks, we require that `MatchSeq` always has
+// a nonempty body.
+#[deriving(Clone)]
+enum TokenTreeOrTokenTreeVec {
+ Tt(ast::TokenTree),
+ TtSeq(Rc