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 {
|
IfConditional {
|
||||||
if_block: Box<TemplateAstExpr<'input>>,
|
if_block: Box<TemplateAstExpr<'input>>,
|
||||||
content: Vec<TemplateAstExpr<'input>>,
|
content: Vec<TemplateAstExpr<'input>>,
|
||||||
end_block: Box<TemplateAstExpr<'input>>,
|
|
||||||
},
|
},
|
||||||
ElseConditional {
|
ElseConditional {
|
||||||
expression: Vec<TemplateAstExpr<'input>>,
|
expression: Vec<TemplateAstExpr<'input>>,
|
||||||
|
|
@ -319,13 +318,10 @@ fn parse_conditional_chain<'input>(
|
||||||
let mut chain = vec![];
|
let mut chain = vec![];
|
||||||
|
|
||||||
let (content, end_block): (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 {
|
chain.push(TemplateAstExpr::IfConditional { if_block, content });
|
||||||
if_block,
|
chain.push(end_block);
|
||||||
content,
|
|
||||||
end_block,
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(TemplateAstExpr::ConditionalChain { chain })
|
Ok(TemplateAstExpr::ConditionalChain { chain })
|
||||||
})
|
})
|
||||||
|
|
@ -519,13 +515,13 @@ mod tests {
|
||||||
[Content]"Hiii" (13..17),
|
[Content]"Hiii" (13..17),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
end_block: Block {
|
},
|
||||||
prev_whitespace_content: Some(
|
Block {
|
||||||
[Whitespace]" " (17..18),
|
prev_whitespace_content: Some(
|
||||||
),
|
[Whitespace]" " (17..18),
|
||||||
expression: EndBlock,
|
),
|
||||||
post_whitespace_content: None,
|
expression: EndBlock,
|
||||||
},
|
post_whitespace_content: None,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -34,26 +34,26 @@ TemplateAst {
|
||||||
[Content]"Hiii" (54..58),
|
[Content]"Hiii" (54..58),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
end_block: Block {
|
},
|
||||||
prev_whitespace_content: Some(
|
Block {
|
||||||
[Whitespace]"\n " (58..71),
|
prev_whitespace_content: Some(
|
||||||
),
|
[Whitespace]"\n " (58..71),
|
||||||
expression: EndBlock,
|
),
|
||||||
post_whitespace_content: Some(
|
expression: EndBlock,
|
||||||
[Whitespace]"\n " (80..89),
|
post_whitespace_content: Some(
|
||||||
),
|
[Whitespace]"\n " (80..89),
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
end_block: Block {
|
},
|
||||||
prev_whitespace_content: None,
|
Block {
|
||||||
expression: EndBlock,
|
prev_whitespace_content: None,
|
||||||
post_whitespace_content: Some(
|
expression: EndBlock,
|
||||||
[Whitespace]"\n\n " (98..108),
|
post_whitespace_content: Some(
|
||||||
),
|
[Whitespace]"\n\n " (98..108),
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,6 @@ fn emit_ast_expr(
|
||||||
let Some(TemplateAstExpr::IfConditional {
|
let Some(TemplateAstExpr::IfConditional {
|
||||||
if_block: expression,
|
if_block: expression,
|
||||||
content,
|
content,
|
||||||
end_block,
|
|
||||||
}) = chain.next()
|
}) = chain.next()
|
||||||
else {
|
else {
|
||||||
unreachable!("First element in conditional chain should be an IfConditional");
|
unreachable!("First element in conditional chain should be an IfConditional");
|
||||||
|
|
@ -133,13 +132,13 @@ fn emit_ast_expr(
|
||||||
emit_ast_expr(machine, eval, ast);
|
emit_ast_expr(machine, eval, ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
let TemplateAstExpr::Block {
|
let Some(TemplateAstExpr::Block {
|
||||||
prev_whitespace_content,
|
prev_whitespace_content,
|
||||||
post_whitespace_content,
|
post_whitespace_content,
|
||||||
..
|
..
|
||||||
} = end_block.as_ref()
|
}) = chain.last()
|
||||||
else {
|
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 {
|
if let Some(ws) = prev_whitespace_content {
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,15 @@ TemplateAst {
|
||||||
[Content]"Hello World!" (18..30),
|
[Content]"Hello World!" (18..30),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
end_block: Block {
|
},
|
||||||
prev_whitespace_content: Some(
|
Block {
|
||||||
[Whitespace]"\n" (30..31),
|
prev_whitespace_content: Some(
|
||||||
),
|
[Whitespace]"\n" (30..31),
|
||||||
expression: EndBlock,
|
),
|
||||||
post_whitespace_content: Some(
|
expression: EndBlock,
|
||||||
[Whitespace]"\n\n" (40..42),
|
post_whitespace_content: Some(
|
||||||
),
|
[Whitespace]"\n\n" (40..42),
|
||||||
},
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue