diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-07-03 09:27:04 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-07-31 10:27:15 +0200 |
commit | f16ddb14f09e470f902ea5cb93e749685dd89d6a (patch) | |
tree | d12d2de512549b5f1917e9a823c467136a41cb4f /askama_parser | |
parent | cdbe8ef39f74fa978f4f2e8ac25acfee2c4432aa (diff) | |
download | askama-f16ddb14f09e470f902ea5cb93e749685dd89d6a.tar.gz askama-f16ddb14f09e470f902ea5cb93e749685dd89d6a.tar.bz2 askama-f16ddb14f09e470f902ea5cb93e749685dd89d6a.zip |
parser: define a struct for Cond
Diffstat (limited to '')
-rw-r--r-- | askama_parser/src/node.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs index cd71efc..84b4911 100644 --- a/askama_parser/src/node.rs +++ b/askama_parser/src/node.rs @@ -149,7 +149,11 @@ impl<'a> Node<'a> { )); let (i, (pws1, cond, (nws1, _, (block, elifs, (_, pws2, _, nws2))))) = p(i)?; - let mut res = vec![(Ws(pws1, nws1), Some(cond), block)]; + let mut res = vec![Cond { + ws: Ws(pws1, nws1), + cond: Some(cond), + block, + }]; res.extend(elifs); Ok((i, Self::Cond(res, Ws(pws2, nws2)))) } @@ -593,7 +597,12 @@ pub struct Macro<'a> { #[derive(Clone, Copy, Debug, PartialEq)] pub struct Ws(pub Option<Whitespace>, pub Option<Whitespace>); -pub type Cond<'a> = (Ws, Option<CondTest<'a>>, Vec<Node<'a>>); +#[derive(Debug, PartialEq)] +pub struct Cond<'a> { + pub ws: Ws, + pub cond: Option<CondTest<'a>>, + pub block: Vec<Node<'a>>, +} #[derive(Debug, PartialEq)] pub struct CondTest<'a> { @@ -638,7 +647,14 @@ fn cond_block<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, Cond<'a>> { ))), )); let (i, (_, pws, _, (cond, nws, _, block))) = p(i)?; - Ok((i, (Ws(pws, nws), cond, block))) + Ok(( + i, + Cond { + ws: Ws(pws, nws), + cond, + block, + }, + )) } fn match_else_block<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, When<'a>> { |