]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass-fulldeps/auxiliary/plugin_args.rs
New upstream version 1.28.0~beta.14+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / auxiliary / plugin_args.rs
CommitLineData
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
16extern crate syntax;
3157f602 17extern crate syntax_pos;
1a4d82fc 18extern crate rustc;
92a42be0 19extern crate rustc_plugin;
1a4d82fc
JJ
20
21use std::borrow::ToOwned;
22use syntax::ast;
94b46f34 23use syntax::ext::hygiene;
1a4d82fc 24use syntax::ext::build::AstBuilder;
c34b1796 25use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacEager, NormalTT};
1a4d82fc
JJ
26use syntax::print::pprust;
27use syntax::ptr::P;
476ff2be 28use syntax::symbol::Symbol;
3157f602 29use syntax_pos::Span;
8bb4bdeb 30use syntax::tokenstream::TokenStream;
92a42be0 31use rustc_plugin::Registry;
1a4d82fc
JJ
32
33struct Expander {
9e0c209e 34 args: Vec<ast::NestedMetaItem>,
1a4d82fc
JJ
35}
36
37impl 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]
49pub 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}