From 3b57663b5b626a322e81f9399f0ab39a88411fd4 Mon Sep 17 00:00:00 2001 From: Christian Vallentin Date: Sat, 12 Dec 2020 18:01:22 +0100 Subject: Fixed whitespace issue when generating match (#399) * Fixed #397 * Updated parser to ignore whitespace between match and when * Updated test cases * Updated Python script to generate match ws tests * Added match ws tests * Resolved rustfmt lint --- askama_shared/src/parser.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'askama_shared/src/parser.rs') diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 8210ed0..a40e967 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -19,7 +19,7 @@ pub enum Node<'a> { LetDecl(WS, Target<'a>), Let(WS, Target<'a>, Expr<'a>), Cond(Vec<(WS, Option>, Vec>)>, WS), - Match(WS, Expr<'a>, Option<&'a str>, Vec>, WS), + Match(WS, Expr<'a>, Vec>, WS), Loop(WS, Target<'a>, Expr<'a>, Vec>, WS), Extends(Expr<'a>), BlockDef(WS, &'a str, Vec>, WS), @@ -771,8 +771,8 @@ fn block_match<'a>(i: &'a [u8], s: &'a Syntax<'a>) -> IResult<&'a [u8], Node<'a> arms.push(arm); } - let inter = match inter { - Some(Node::Lit(lws, val, rws)) => { + match inter { + Some(Node::Lit(_, val, rws)) => { assert!( val.is_empty(), "only whitespace allowed between match and first when, found {}", @@ -783,18 +783,16 @@ fn block_match<'a>(i: &'a [u8], s: &'a Syntax<'a>) -> IResult<&'a [u8], Node<'a> "only whitespace allowed between match and first when, found {}", rws ); - Some(lws) } - None => None, + None => {} _ => panic!("only literals allowed between match and first when"), - }; + } Ok(( i, Node::Match( WS(pws1.is_some(), nws1.is_some()), expr, - inter, arms, WS(pws2.is_some(), nws2.is_some()), ), -- cgit