Created
January 25, 2015 08:44
-
-
Save azyobuzin/bfa77d9cc3ab25a3843b to your computer and use it in GitHub Desktop.
NormalTT
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
[package] | |
name = "normaltt" | |
version = "0.0.1" | |
[lib] | |
name = "normaltt_ext" | |
path = "lib.rs" | |
plugin = true | |
crate-type = ["dylib"] | |
[[bin]] | |
name = "normaltt" | |
path = "main.rs" |
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
#![allow(unstable)] | |
#![feature(plugin_registrar)] | |
extern crate rustc; | |
extern crate syntax; | |
use rustc::plugin::Registry; | |
use syntax::ast; | |
use syntax::codemap::Span; | |
use syntax::ext::base; | |
use syntax::ext::quote::rt::ExtParseUtils; | |
use syntax::ext::quote::rt::ToSource; | |
use syntax::parse::token; | |
#[plugin_registrar] | |
pub fn plugin_registrar(reg: &mut Registry) { | |
reg.register_macro("homu", expand_homu); | |
} | |
fn expand_homu(cx: &mut base::ExtCtxt, sp: Span, args: &[ast::TokenTree]) -> Box<base::MacResult + 'static> { | |
if let [ast::TtToken(_, token::Ident(ident, _))] = args { | |
base::MacExpr::new( | |
//手抜き感 | |
cx.parse_expr(ident.as_str().to_source()) | |
) | |
} else { | |
cx.span_err(sp, "the argument must be a identifier"); | |
base::DummyResult::any(sp) | |
} | |
} |
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
#![feature(plugin)] | |
#[plugin] | |
#[no_link] | |
extern crate normaltt_ext; | |
fn main() { | |
println!(homu!(grief_seed)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment