about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorPaul Stansifer <paul.stansifer@gmail.com>2012-07-06 14:29:50 -0700
committerPaul Stansifer <paul.stansifer@gmail.com>2012-07-09 17:44:46 -0700
commitcabee6391d599be867b80f81de219d9f982585f5 (patch)
treec877eeeac1aae5a971f6d7a996f422bb73767443 /src/libsyntax
parent579768baa56e1344ef541cca6fef673b5e9eb683 (diff)
Enable item macros to define macros.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/base.rs7
-rw-r--r--src/libsyntax/ext/expand.rs12
-rw-r--r--src/libsyntax/ext/pipes.rs4
3 files changed, 17 insertions, 6 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 0e6cce27b2b..afc47d2ecfc 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -20,7 +20,12 @@ type syntax_expander_tt_ = fn@(ext_ctxt, span, ast::token_tree) -> @ast::expr;
 type syntax_expander_tt_item
     = {expander: syntax_expander_tt_item_, span: option<span>};
 type syntax_expander_tt_item_
-    = fn@(ext_ctxt, span, ast::ident, ast::token_tree) -> @ast::item;
+    = fn@(ext_ctxt, span, ast::ident, ast::token_tree) -> mac_result;
+
+enum mac_result {
+    mr_item(@ast::item),
+    mr_def(macro_def)
+}
 
 enum syntax_extension {
     normal(syntax_expander),
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 9cb610f486c..c6110fbe1a7 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -170,10 +170,16 @@ fn expand_item_mac(exts: hashmap<str, syntax_extension>,
             cx.bt_push(expanded_from({call_site: it.span,
                                       callie: {name: *extname,
                                                span: expand.span}}));
-            let it = fld.fold_item(
-                expand.expander(cx, it.span, it.ident, tt));
+            let maybe_it =
+                alt expand.expander(cx, it.span, it.ident, tt) {
+                  mr_item(it) { fld.fold_item(it) }
+                  mr_def(mdef) {
+                    exts.insert(*mdef.ident, mdef.ext);
+                    none
+                  }
+                };
             cx.bt_pop();
-            ret it
+            ret maybe_it
           }
           _ { cx.span_fatal(it.span,
                             #fmt("%s is not a legal here", *extname)) }
diff --git a/src/libsyntax/ext/pipes.rs b/src/libsyntax/ext/pipes.rs
index 9a7bcc0e171..61c154ab15e 100644
--- a/src/libsyntax/ext/pipes.rs
+++ b/src/libsyntax/ext/pipes.rs
@@ -11,7 +11,7 @@ import pipes::parse_proto::proto_parser;
 import pipes::pipec::methods;
 
 fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident, tt: ast::token_tree)
-    -> @ast::item
+    -> base::mac_result
 {
     let sess = cx.parse_sess();
     let cfg = cx.cfg();
@@ -25,5 +25,5 @@ fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident, tt: ast::token_tree)
 
     let proto = rust_parser.parse_proto(id);
 
-    proto.compile(cx)
+    base::mr_item(proto.compile(cx))
 }