From 751dee3fbabb35a8ad30ebdaee8e4dd4120c289a Mon Sep 17 00:00:00 2001 From: Anthony Nowell Date: Thu, 5 Oct 2017 01:10:10 -0600 Subject: support else in match block --- askama_shared/src/parser.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'askama_shared') 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, do_parse!( }) )); +named!(match_else_block, 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, do_parse!( tag_s!("{%") >> pws: opt!(tag_s!("-")) >> @@ -387,11 +397,16 @@ named!(block_match, 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(), -- cgit