Skip to content

Instantly share code, notes, and snippets.

@azyobuzin

azyobuzin/Cargo.toml

Created Jan 25, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.