]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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. | |
4 | // | |
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. | |
10 | ||
11 | // force-host | |
12 | ||
13 | #![feature(plugin_registrar)] | |
c34b1796 | 14 | #![feature(box_syntax, rustc_private)] |
1a4d82fc JJ |
15 | |
16 | extern crate syntax; | |
3157f602 | 17 | extern crate syntax_pos; |
1a4d82fc | 18 | extern crate rustc; |
92a42be0 | 19 | extern crate rustc_plugin; |
1a4d82fc JJ |
20 | |
21 | use std::borrow::ToOwned; | |
22 | use syntax::ast; | |
94b46f34 | 23 | use syntax::ext::hygiene; |
1a4d82fc | 24 | use syntax::ext::build::AstBuilder; |
c34b1796 | 25 | use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacEager, NormalTT}; |
1a4d82fc JJ |
26 | use syntax::print::pprust; |
27 | use syntax::ptr::P; | |
476ff2be | 28 | use syntax::symbol::Symbol; |
3157f602 | 29 | use syntax_pos::Span; |
8bb4bdeb | 30 | use syntax::tokenstream::TokenStream; |
92a42be0 | 31 | use rustc_plugin::Registry; |
1a4d82fc JJ |
32 | |
33 | struct Expander { | |
9e0c209e | 34 | args: Vec<ast::NestedMetaItem>, |
1a4d82fc JJ |
35 | } |
36 | ||
37 | impl TTMacroExpander for Expander { | |
38 | fn expand<'cx>(&self, | |
39 | ecx: &'cx mut ExtCtxt, | |
40 | sp: Span, | |
8bb4bdeb | 41 | _: TokenStream) -> Box<MacResult+'cx> { |
9e0c209e | 42 | let args = self.args.iter().map(|i| pprust::meta_list_item_to_string(i)) |
c1a9b12d | 43 | .collect::<Vec<_>>().join(", "); |
476ff2be | 44 | MacEager::expr(ecx.expr_str(sp, Symbol::intern(&args))) |
1a4d82fc JJ |
45 | } |
46 | } | |
47 | ||
48 | #[plugin_registrar] | |
49 | pub fn plugin_registrar(reg: &mut Registry) { | |
a7813a04 | 50 | let args = reg.args().to_owned(); |
476ff2be | 51 | reg.register_syntax_extension(Symbol::intern("plugin_args"), |
3b2f2976 XL |
52 | NormalTT { |
53 | expander: Box::new(Expander { args: args, }), | |
54 | def_info: None, | |
55 | allow_internal_unstable: false, | |
56 | allow_internal_unsafe: false, | |
0531ce1d | 57 | unstable_feature: None, |
94b46f34 | 58 | edition: hygiene::default_edition(), |
3b2f2976 | 59 | }); |
1a4d82fc | 60 | } |