aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/parser.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-09-05 19:54:15 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-09-05 19:54:15 +0200
commitb65d6c07bd028a4f25912b407c8e91bffd0196d2 (patch)
tree4e3d29d4b0556e51a7c9d6a36edda4109b606992 /askama_shared/src/parser.rs
parent6911e1d86caa9fa87457f99b76eb456cb6fd394c (diff)
downloadaskama-b65d6c07bd028a4f25912b407c8e91bffd0196d2.tar.gz
askama-b65d6c07bd028a4f25912b407c8e91bffd0196d2.tar.bz2
askama-b65d6c07bd028a4f25912b407c8e91bffd0196d2.zip
Refactor handling of macros
Diffstat (limited to 'askama_shared/src/parser.rs')
-rw-r--r--askama_shared/src/parser.rs20
1 files changed, 15 insertions, 5 deletions
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
@@ -22,6 +22,14 @@ pub enum Target<'a> {
pub struct WS(pub bool, pub bool);
#[derive(Debug)]
+pub struct Macro<'a> {
+ pub ws1: WS,
+ pub args: Vec<&'a str>,
+ pub nodes: Vec<Node<'a>>,
+ pub ws2: WS,
+}
+
+#[derive(Debug)]
pub enum Node<'a> {
Lit(&'a str, &'a str, &'a str),
Comment(),
@@ -35,7 +43,7 @@ pub enum Node<'a> {
BlockDef(WS, &'a str, Vec<Node<'a>>, WS),
Block(WS, &'a str, WS),
Include(WS, &'a str),
- Macro(WS, &'a str, Vec<&'a str>, Vec<Node<'a>>, WS),
+ Macro(&'a str, Macro<'a>),
}
pub type Cond<'a> = (WS, Option<Expr<'a>>, Vec<Node<'a>>);
@@ -390,11 +398,13 @@ named!(block_macro<Node>, 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())
+ }
))
));