Skip to content

Instantly share code, notes, and snippets.

@azyobuzin
Created January 25, 2015 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azyobuzin/bfa77d9cc3ab25a3843b to your computer and use it in GitHub Desktop.
Save azyobuzin/bfa77d9cc3ab25a3843b to your computer and use it in GitHub Desktop.
NormalTT
[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"
#![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)
}
}
#![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