1 // Copyright 2015 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(plugin_registrar)]
14 #![feature(box_syntax)]
19 use std
::borrow
::ToOwned
;
21 use syntax
::codemap
::Span
;
22 use syntax
::ext
::build
::AstBuilder
;
23 use syntax
::ext
::base
::{TTMacroExpander, ExtCtxt, MacResult, MacExpr, NormalTT}
;
24 use syntax
::parse
::token
;
25 use syntax
::print
::pprust
;
27 use rustc
::plugin
::Registry
;
30 args
: P
<ast
::MetaItem
>,
33 impl TTMacroExpander
for Expander
{
35 ecx
: &'cx
mut ExtCtxt
,
37 _
: &[ast
::TokenTree
]) -> Box
<MacResult
+'cx
> {
39 let attr
= ecx
.attribute(sp
, self.args
.clone());
40 let src
= pprust
::attribute_to_string(&attr
);
41 let interned
= token
::intern_and_get_ident(src
.as_slice());
42 MacExpr
::new(ecx
.expr_str(sp
, interned
))
47 pub fn plugin_registrar(reg
: &mut Registry
) {
48 let args
= reg
.args().clone();
49 reg
.register_syntax_extension(token
::intern("plugin_args"),
50 NormalTT(box Expander { args: args, }
, None
));