From b65d6c07bd028a4f25912b407c8e91bffd0196d2 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 5 Sep 2017 19:54:15 +0200 Subject: Refactor handling of macros --- askama_shared/src/parser.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'askama_shared/src/parser.rs') diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 1156b68..677b86a 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -21,6 +21,14 @@ pub enum Target<'a> { #[derive(Clone, Copy, Debug)] pub struct WS(pub bool, pub bool); +#[derive(Debug)] +pub struct Macro<'a> { + pub ws1: WS, + pub args: Vec<&'a str>, + pub nodes: Vec>, + pub ws2: WS, +} + #[derive(Debug)] pub enum Node<'a> { Lit(&'a str, &'a str, &'a str), @@ -35,7 +43,7 @@ pub enum Node<'a> { BlockDef(WS, &'a str, Vec>, WS), Block(WS, &'a str, WS), Include(WS, &'a str), - Macro(WS, &'a str, Vec<&'a str>, Vec>, WS), + Macro(&'a str, Macro<'a>), } pub type Cond<'a> = (WS, Option>, Vec>); @@ -390,11 +398,13 @@ named!(block_macro, do_parse!( ws!(tag_s!("endmacro")) >> nws2: opt!(tag_s!("-")) >> (Node::Macro( - WS(pws1.is_some(), nws1.is_some()), name, - params, - contents, - WS(pws2.is_some(), nws2.is_some()) + Macro { + ws1: WS(pws1.is_some(), nws1.is_some()), + args: params, + nodes: contents, + ws2: WS(pws2.is_some(), nws2.is_some()) + } )) )); -- cgit