diff options
author | Christian Vallentin <mail@vallentin.dev> | 2020-12-12 18:01:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-12 18:01:22 +0100 |
commit | 3b57663b5b626a322e81f9399f0ab39a88411fd4 (patch) | |
tree | fa9ee7c09dd869a4183d012006f59215e39e07a8 /askama_shared/src/parser.rs | |
parent | 5b01e605914a49f0b9e71e7dbe7c17ef1de2c522 (diff) | |
download | askama-3b57663b5b626a322e81f9399f0ab39a88411fd4.tar.gz askama-3b57663b5b626a322e81f9399f0ab39a88411fd4.tar.bz2 askama-3b57663b5b626a322e81f9399f0ab39a88411fd4.zip |
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
Diffstat (limited to 'askama_shared/src/parser.rs')
-rw-r--r-- | askama_shared/src/parser.rs | 12 |
1 files changed, 5 insertions, 7 deletions
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<Expr<'a>>, Vec<Node<'a>>)>, WS), - Match(WS, Expr<'a>, Option<&'a str>, Vec<When<'a>>, WS), + Match(WS, Expr<'a>, Vec<When<'a>>, WS), Loop(WS, Target<'a>, Expr<'a>, Vec<Node<'a>>, WS), Extends(Expr<'a>), BlockDef(WS, &'a str, Vec<Node<'a>>, 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()), ), |