1 // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 #![feature(globs, macro_registrar, macro_rules, quote, managed_boxes)]
17 use syntax::ast::{Name, TokenTree, Item, MetaItem};
18 use syntax::codemap::Span;
19 use syntax::ext::base::*;
20 use syntax::parse::token;
23 macro_rules! exported_macro (() => (2))
25 macro_rules! unexported_macro (() => (3))
28 pub fn macro_registrar(register: |Name, SyntaxExtension|) {
29 register(token::intern("make_a_1"),
30 NormalTT(box BasicMacroExpander {
31 expander: expand_make_a_1,
35 register(token::intern("into_foo"), ItemModifier(expand_into_foo));
38 fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
41 cx.span_fatal(sp, "make_a_1 takes no arguments");
43 MacExpr::new(quote_expr!(cx, 1i))
46 fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: @MetaItem, it: @Item)
49 attrs: it.attrs.clone(),
50 ..(*quote_item!(cx, enum Foo { Bar, Baz }).unwrap()).clone()