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, plugin_registrar, macro_rules, quote, managed_boxes)]
18 use syntax::ast::{TokenTree, Item, MetaItem};
19 use syntax::codemap::Span;
20 use syntax::ext::base::*;
21 use syntax::parse::token;
22 use rustc::plugin::Registry;
24 use std::gc::{Gc, GC};
27 macro_rules! exported_macro (() => (2))
29 macro_rules! unexported_macro (() => (3))
32 pub fn plugin_registrar(reg: &mut Registry) {
33 reg.register_macro("make_a_1", expand_make_a_1);
34 reg.register_syntax_extension(
35 token::intern("into_foo"),
36 ItemModifier(expand_into_foo));
39 fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
42 cx.span_fatal(sp, "make_a_1 takes no arguments");
44 MacExpr::new(quote_expr!(cx, 1i))
47 fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: Gc<MetaItem>, it: Gc<Item>)
50 attrs: it.attrs.clone(),
51 ..(*quote_item!(cx, enum Foo { Bar, Baz }).unwrap()).clone()