Move EndBlock to own element
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
08b480705b
commit
383f543119
4 changed files with 38 additions and 43 deletions
|
|
@ -229,7 +229,6 @@ pub enum TemplateAstExpr<'input> {
|
|||
IfConditional {
|
||||
if_block: Box<TemplateAstExpr<'input>>,
|
||||
content: Vec<TemplateAstExpr<'input>>,
|
||||
end_block: Box<TemplateAstExpr<'input>>,
|
||||
},
|
||||
ElseConditional {
|
||||
expression: Vec<TemplateAstExpr<'input>>,
|
||||
|
|
@ -319,13 +318,10 @@ fn parse_conditional_chain<'input>(
|
|||
let mut chain = vec![];
|
||||
|
||||
let (content, end_block): (Vec<_>, _) =
|
||||
repeat_till(0.., parse_ast, parse_end.map(Box::new)).parse_next(input)?;
|
||||
repeat_till(0.., parse_ast, parse_end).parse_next(input)?;
|
||||
|
||||
chain.push(TemplateAstExpr::IfConditional {
|
||||
if_block,
|
||||
content,
|
||||
end_block,
|
||||
});
|
||||
chain.push(TemplateAstExpr::IfConditional { if_block, content });
|
||||
chain.push(end_block);
|
||||
|
||||
Ok(TemplateAstExpr::ConditionalChain { chain })
|
||||
})
|
||||
|
|
@ -519,14 +515,14 @@ mod tests {
|
|||
[Content]"Hiii" (13..17),
|
||||
),
|
||||
],
|
||||
end_block: Block {
|
||||
},
|
||||
Block {
|
||||
prev_whitespace_content: Some(
|
||||
[Whitespace]" " (17..18),
|
||||
),
|
||||
expression: EndBlock,
|
||||
post_whitespace_content: None,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ TemplateAst {
|
|||
[Content]"Hiii" (54..58),
|
||||
),
|
||||
],
|
||||
end_block: Block {
|
||||
},
|
||||
Block {
|
||||
prev_whitespace_content: Some(
|
||||
[Whitespace]"\n " (58..71),
|
||||
),
|
||||
|
|
@ -43,18 +44,17 @@ TemplateAst {
|
|||
[Whitespace]"\n " (80..89),
|
||||
),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
end_block: Block {
|
||||
},
|
||||
Block {
|
||||
prev_whitespace_content: None,
|
||||
expression: EndBlock,
|
||||
post_whitespace_content: Some(
|
||||
[Whitespace]"\n\n " (98..108),
|
||||
),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
Interpolation {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,6 @@ fn emit_ast_expr(
|
|||
let Some(TemplateAstExpr::IfConditional {
|
||||
if_block: expression,
|
||||
content,
|
||||
end_block,
|
||||
}) = chain.next()
|
||||
else {
|
||||
unreachable!("First element in conditional chain should be an IfConditional");
|
||||
|
|
@ -133,13 +132,13 @@ fn emit_ast_expr(
|
|||
emit_ast_expr(machine, eval, ast);
|
||||
}
|
||||
|
||||
let TemplateAstExpr::Block {
|
||||
let Some(TemplateAstExpr::Block {
|
||||
prev_whitespace_content,
|
||||
post_whitespace_content,
|
||||
..
|
||||
} = end_block.as_ref()
|
||||
}) = chain.last()
|
||||
else {
|
||||
unreachable!("The end of an IfConditional must be a Block");
|
||||
unreachable!("The end of an IfConditional must be a End Block");
|
||||
};
|
||||
|
||||
if let Some(ws) = prev_whitespace_content {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ TemplateAst {
|
|||
[Content]"Hello World!" (18..30),
|
||||
),
|
||||
],
|
||||
end_block: Block {
|
||||
},
|
||||
Block {
|
||||
prev_whitespace_content: Some(
|
||||
[Whitespace]"\n" (30..31),
|
||||
),
|
||||
|
|
@ -31,7 +32,6 @@ TemplateAst {
|
|||
[Whitespace]"\n\n" (40..42),
|
||||
),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
Interpolation {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue