Add parsing of simple conditionals
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
ffb5c92b89
commit
974086a877
7 changed files with 392 additions and 119 deletions
|
|
@ -24,19 +24,10 @@ pub struct VariableSlot {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub enum Instruction {
|
||||
AppendContent {
|
||||
content: NomoInput,
|
||||
},
|
||||
LoadFromContextToSlot {
|
||||
name: NomoInput,
|
||||
slot: VariableSlot,
|
||||
},
|
||||
EmitFromSlot {
|
||||
slot: VariableSlot,
|
||||
},
|
||||
PushScope {
|
||||
inherit_parent: bool,
|
||||
},
|
||||
AppendContent { content: NomoInput },
|
||||
LoadFromContextToSlot { name: NomoInput, slot: VariableSlot },
|
||||
EmitFromSlot { slot: VariableSlot },
|
||||
PushScope { inherit_parent: bool },
|
||||
Abort,
|
||||
}
|
||||
|
||||
|
|
@ -64,10 +55,10 @@ fn emit_ast_expr(
|
|||
});
|
||||
}
|
||||
TemplateAstExpr::Interpolation {
|
||||
prev_whitespace,
|
||||
prev_whitespace_content: prev_whitespace,
|
||||
wants_output,
|
||||
expression,
|
||||
post_whitespace,
|
||||
post_whitespace_content: post_whitespace,
|
||||
} => {
|
||||
if let Some(ws) = prev_whitespace {
|
||||
eval.push(Instruction::AppendContent {
|
||||
|
|
@ -77,10 +68,7 @@ fn emit_ast_expr(
|
|||
|
||||
let emit_slot = machine.reserve_slot();
|
||||
emit_expr(machine, eval, emit_slot, expression);
|
||||
|
||||
if wants_output.is_some() {
|
||||
eval.push(Instruction::EmitFromSlot { slot: emit_slot });
|
||||
}
|
||||
eval.push(Instruction::EmitFromSlot { slot: emit_slot });
|
||||
|
||||
if let Some(ws) = post_whitespace {
|
||||
eval.push(Instruction::AppendContent {
|
||||
|
|
@ -91,6 +79,24 @@ fn emit_ast_expr(
|
|||
TemplateAstExpr::Invalid { .. } | TemplateAstExpr::VariableAccess { .. } => {
|
||||
eval.push(Instruction::Abort)
|
||||
}
|
||||
TemplateAstExpr::ConditionalChain { chain } => todo!(),
|
||||
TemplateAstExpr::ElseConditional { expression } => todo!(),
|
||||
TemplateAstExpr::Action {
|
||||
prev_whitespace_content,
|
||||
expression,
|
||||
post_whitespace_content,
|
||||
} => todo!(),
|
||||
TemplateAstExpr::EndBlock => todo!(),
|
||||
TemplateAstExpr::Block {
|
||||
prev_whitespace_content,
|
||||
expression,
|
||||
post_whitespace_content,
|
||||
} => todo!(),
|
||||
TemplateAstExpr::IfConditional {
|
||||
expression,
|
||||
content,
|
||||
end_block,
|
||||
} => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,6 +117,24 @@ fn emit_expr(
|
|||
TemplateAstExpr::StaticContent { .. } | TemplateAstExpr::Interpolation { .. } => {
|
||||
unreachable!("Invalid AST here")
|
||||
}
|
||||
TemplateAstExpr::ConditionalChain { chain } => todo!(),
|
||||
TemplateAstExpr::ElseConditional { expression } => todo!(),
|
||||
TemplateAstExpr::Action {
|
||||
prev_whitespace_content,
|
||||
expression,
|
||||
post_whitespace_content,
|
||||
} => todo!(),
|
||||
TemplateAstExpr::EndBlock => todo!(),
|
||||
TemplateAstExpr::Block {
|
||||
prev_whitespace_content,
|
||||
expression,
|
||||
post_whitespace_content,
|
||||
} => todo!(),
|
||||
TemplateAstExpr::IfConditional {
|
||||
expression,
|
||||
content,
|
||||
end_block,
|
||||
} => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue