Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass the #[plugin(...)] meta item to the registrar
- Loading branch information
Keegan McAllister
committed
Jan 6, 2015
1 parent
416137e
commit d0163d3
Showing
9 changed files
with
195 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// force-host | ||
|
||
#![feature(plugin_registrar)] | ||
|
||
extern crate syntax; | ||
extern crate rustc; | ||
|
||
use std::borrow::ToOwned; | ||
use syntax::ast; | ||
use syntax::codemap::Span; | ||
use syntax::ext::build::AstBuilder; | ||
use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacExpr, NormalTT}; | ||
use syntax::parse::token; | ||
use syntax::print::pprust; | ||
use syntax::ptr::P; | ||
use rustc::plugin::Registry; | ||
|
||
struct Expander { | ||
args: P<ast::MetaItem>, | ||
} | ||
|
||
impl TTMacroExpander for Expander { | ||
fn expand<'cx>(&self, | ||
ecx: &'cx mut ExtCtxt, | ||
sp: Span, | ||
_: &[ast::TokenTree]) -> Box<MacResult+'cx> { | ||
|
||
let attr = ecx.attribute(sp, self.args.clone()); | ||
let src = pprust::attribute_to_string(&attr); | ||
let interned = token::intern_and_get_ident(src.as_slice()); | ||
MacExpr::new(ecx.expr_str(sp, interned)) | ||
} | ||
} | ||
|
||
#[plugin_registrar] | ||
pub fn plugin_registrar(reg: &mut Registry) { | ||
let args = reg.args().clone(); | ||
reg.register_syntax_extension(token::intern("plugin_args"), | ||
NormalTT(box Expander { args: args, }, None)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[plugin] | ||
#[plugin] //~ ERROR #[plugin] specified multiple times | ||
extern crate std; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:plugin_args.rs | ||
// ignore-stage1 | ||
|
||
#![feature(plugin)] | ||
|
||
#[no_link] | ||
#[plugin] | ||
extern crate plugin_args; | ||
|
||
fn main() { | ||
assert_eq!(plugin_args!(), "#[plugin]"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:plugin_args.rs | ||
// ignore-stage1 | ||
|
||
#![feature(plugin)] | ||
|
||
#[no_link] | ||
#[plugin()] | ||
extern crate plugin_args; | ||
|
||
fn main() { | ||
assert_eq!(plugin_args!(), "#[plugin()]"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:plugin_args.rs | ||
// ignore-stage1 | ||
|
||
#![feature(plugin)] | ||
|
||
#[no_link] | ||
#[plugin(hello(there), how(are="you"))] | ||
extern crate plugin_args; | ||
|
||
fn main() { | ||
assert_eq!(plugin_args!(), "#[plugin(hello(there), how(are = \"you\"))]"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:plugin_args.rs | ||
// ignore-stage1 | ||
|
||
#![feature(plugin)] | ||
|
||
#[no_link] | ||
#[plugin="foobar"] | ||
extern crate plugin_args; | ||
|
||
fn main() { | ||
assert_eq!(plugin_args!(), "#[plugin = \"foobar\"]"); | ||
} |