From 4653b2e2d88f4f234753ee1addeef4e8b53b9569 Mon Sep 17 00:00:00 2001 From: Chris Wong <lambda.fairy@gmail.com> Date: Mon, 13 Apr 2015 20:20:02 +1200 Subject: [PATCH] Add html_debug! macro; remove print-expansion feature --- .travis.yml | 2 +- maud_macros/Cargo.toml | 3 --- maud_macros/src/lib.rs | 17 ++++++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 73a0e4b..b67e5f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: rust script: - - ( cd maud_macros && cargo test --features print-expansion --verbose ) + - ( cd maud_macros && cargo test --verbose ) diff --git a/maud_macros/Cargo.toml b/maud_macros/Cargo.toml index 4f50219..e682a62 100644 --- a/maud_macros/Cargo.toml +++ b/maud_macros/Cargo.toml @@ -12,9 +12,6 @@ description = """ Compile-time HTML templates. """ -[features] -print-expansion = [] - [dependencies.maud] path = "../maud" version = "=0.4.0" diff --git a/maud_macros/src/lib.rs b/maud_macros/src/lib.rs index 49ecf90..2f27d9b 100644 --- a/maud_macros/src/lib.rs +++ b/maud_macros/src/lib.rs @@ -16,15 +16,26 @@ use rustc::plugin::Registry; mod parse; 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); - if cfg!(feature = "print-expansion") { - println!("{}", pprust::expr_to_string(&expr)); + if debug { + cx.span_note(sp, &format!("expansion:\n{}", + pprust::expr_to_string(&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] pub fn plugin_registrar(reg: &mut Registry) { reg.register_macro("html", expand_html); + reg.register_macro("html_debug", expand_html_debug); }