aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Anthony Nowell <anowell@gmail.com>2017-10-05 01:10:10 -0600
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-11-02 14:57:11 +0100
commit751dee3fbabb35a8ad30ebdaee8e4dd4120c289a (patch)
treee2a3283a7fe696a9701875080c5faa4c4b78fab1
parent468f376bfc2cf3e09addac37cd144de56b5f93bf (diff)
downloadaskama-751dee3fbabb35a8ad30ebdaee8e4dd4120c289a.tar.gz
askama-751dee3fbabb35a8ad30ebdaee8e4dd4120c289a.tar.bz2
askama-751dee3fbabb35a8ad30ebdaee8e4dd4120c289a.zip
support else in match block
-rw-r--r--askama_shared/src/parser.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs
index ec4dcbd..6ea5ffd 100644
--- a/askama_shared/src/parser.rs
+++ b/askama_shared/src/parser.rs
@@ -367,6 +367,16 @@ named!(block_if<Node>, do_parse!(
})
));
+named!(match_else_block<When>, do_parse!(
+ tag_s!("{%") >>
+ pws: opt!(tag_s!("-")) >>
+ ws!(tag_s!("else")) >>
+ nws: opt!(tag_s!("-")) >>
+ tag_s!("%}") >>
+ block: parse_template >>
+ (WS(pws.is_some(), nws.is_some()), "_", vec![], block)
+));
+
named!(when_block<When>, do_parse!(
tag_s!("{%") >>
pws: opt!(tag_s!("-")) >>
@@ -387,11 +397,16 @@ named!(block_match<Node>, do_parse!(
tag_s!("%}") >>
inter: take_content >>
arms: many1!(when_block) >>
+ else_arm: opt!(match_else_block) >>
ws!(tag_s!("{%")) >>
pws2: opt!(tag_s!("-")) >>
ws!(tag_s!("endmatch")) >>
nws2: opt!(tag_s!("-")) >>
({
+ let mut arms = arms;
+ if let Some(arm) = else_arm {
+ arms.push(arm);
+ }
let inter = match inter {
Node::Lit(lws, val, rws) => {
assert!(val.is_empty(),