Crates.io | ecp |
lib.rs | ecp |
version | 0.1.1 |
source | src |
created_at | 2016-11-26 13:11:05.831226 |
updated_at | 2016-11-26 13:33:02.893628 |
description | easily build compiler plugins. |
homepage | https://github.com/fengcen/ecp |
repository | https://github.com/fengcen/ecp.git |
max_upload_size | |
id | 7368 |
size | 11,245 |
easily build compiler plugins.
Sorry, you need to build the document with cargo doc
.
ecp required latest Nightly Rust.
I need not only "custom derive", but also more "compiler plugin" features. Currently "Macros 1.1" is also unstable.
Add dependencies to Cargo.toml
[dependencies]
ecp = "^0.1"
In your main.rs
or lib.rs
:
#![feature(quote, plugin_registrar, rustc_private)]
extern crate syntax;
extern crate ecp;
Create a simple macro which prints "Hello world!":
#![feature(quote, plugin_registrar, rustc_private)]
extern crate syntax;
extern crate ecp;
use ecp::prelude::*;
#[plugin_registrar]
pub fn register(reg: &mut Registry) {
reg.register_macro("test", test);
}
pub fn test(cx: &mut ExtCtxt, _: Span, _: &[TokenTree]) -> Box<MacResult + 'static> {
MacEager::expr(quote_expr!(cx, println!("Hello world!")))
}
ecp is primarily distributed under the terms of the MIT license. See LICENSE for details.