Add html_debug! macro; remove print-expansion feature
This commit is contained in:
parent
86c6edafae
commit
4653b2e2d8
3 changed files with 15 additions and 7 deletions
|
@ -1,3 +1,3 @@
|
||||||
language: rust
|
language: rust
|
||||||
script:
|
script:
|
||||||
- ( cd maud_macros && cargo test --features print-expansion --verbose )
|
- ( cd maud_macros && cargo test --verbose )
|
||||||
|
|
|
@ -12,9 +12,6 @@ description = """
|
||||||
Compile-time HTML templates.
|
Compile-time HTML templates.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
[features]
|
|
||||||
print-expansion = []
|
|
||||||
|
|
||||||
[dependencies.maud]
|
[dependencies.maud]
|
||||||
path = "../maud"
|
path = "../maud"
|
||||||
version = "=0.4.0"
|
version = "=0.4.0"
|
||||||
|
|
|
@ -16,15 +16,26 @@ use rustc::plugin::Registry;
|
||||||
mod parse;
|
mod parse;
|
||||||
mod render;
|
mod render;
|
||||||
|
|
||||||
fn expand_html<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree]) -> Box<MacResult + 'cx> {
|
fn expand_html_common<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree],
|
||||||
|
debug: bool) -> Box<MacResult + 'cx> {
|
||||||
let expr = parse::parse(cx, args, sp);
|
let expr = parse::parse(cx, args, sp);
|
||||||
if cfg!(feature = "print-expansion") {
|
if debug {
|
||||||
println!("{}", pprust::expr_to_string(&expr));
|
cx.span_note(sp, &format!("expansion:\n{}",
|
||||||
|
pprust::expr_to_string(&expr)));
|
||||||
}
|
}
|
||||||
MacEager::expr(expr)
|
MacEager::expr(expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn expand_html<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree]) -> Box<MacResult + 'cx> {
|
||||||
|
expand_html_common(cx, sp, args, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn expand_html_debug<'cx>(cx: &'cx mut ExtCtxt, sp: Span, args: &[TokenTree]) -> Box<MacResult + 'cx> {
|
||||||
|
expand_html_common(cx, sp, args, true)
|
||||||
|
}
|
||||||
|
|
||||||
#[plugin_registrar]
|
#[plugin_registrar]
|
||||||
pub fn plugin_registrar(reg: &mut Registry) {
|
pub fn plugin_registrar(reg: &mut Registry) {
|
||||||
reg.register_macro("html", expand_html);
|
reg.register_macro("html", expand_html);
|
||||||
|
reg.register_macro("html_debug", expand_html_debug);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue