From 65fb5630825b62ca959fcb55252d1657aefea0f3 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 3 Jul 2023 09:30:28 +0200 Subject: parser: define a struct for Match --- askama_parser/src/node.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'askama_parser') diff --git a/askama_parser/src/node.rs b/askama_parser/src/node.rs index 84b4911..54dc333 100644 --- a/askama_parser/src/node.rs +++ b/askama_parser/src/node.rs @@ -581,7 +581,12 @@ pub struct Loop<'a> { pub ws3: Ws, } -pub type When<'a> = (Ws, Target<'a>, Vec>); +#[derive(Debug, PartialEq)] +pub struct When<'a> { + pub ws: Ws, + pub target: Target<'a>, + pub block: Vec>, +} #[derive(Debug, PartialEq)] pub struct Macro<'a> { @@ -669,7 +674,14 @@ fn match_else_block<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, When<'a>> ))), )); let (i, (_, pws, _, (nws, _, block))) = p(i)?; - Ok((i, (Ws(pws, nws), Target::Name("_"), block))) + Ok(( + i, + When { + ws: Ws(pws, nws), + target: Target::Name("_"), + block, + }, + )) } fn when_block<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, When<'a>> { @@ -685,7 +697,14 @@ fn when_block<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, When<'a>> { ))), )); let (i, (_, pws, _, (target, nws, _, block))) = p(i)?; - Ok((i, (Ws(pws, nws), target, block))) + Ok(( + i, + When { + ws: Ws(pws, nws), + target, + block, + }, + )) } fn parse_loop_content<'a>(i: &'a str, s: &State<'_>) -> IResult<&'a str, Vec>> { -- cgit