Use custom Arc backed input

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-06 12:40:02 +01:00
parent 1ea15f0e49
commit 1ee7611981
6 changed files with 283 additions and 77 deletions

View file

@ -1,4 +1,5 @@
use crate::ast::TemplateAstExpr;
use crate::input::TempleInput;
pub struct EmitMachine {
current_index: usize,
@ -23,10 +24,19 @@ pub struct VariableSlot {
#[derive(Debug)]
pub enum Instruction {
AppendContent { content: String },
LoadFromContextToSlot { name: String, slot: VariableSlot },
EmitFromSlot { slot: VariableSlot },
PushScope { inherit_parent: bool },
AppendContent {
content: TempleInput,
},
LoadFromContextToSlot {
name: TempleInput,
slot: VariableSlot,
},
EmitFromSlot {
slot: VariableSlot,
},
PushScope {
inherit_parent: bool,
},
Abort,
}
@ -42,11 +52,15 @@ pub fn emit_machine(input: crate::ast::TemplateAst<'_>) -> Vec<Instruction> {
eval
}
fn emit_ast_expr(machine: &mut EmitMachine, eval: &mut Vec<Instruction>, ast: &TemplateAstExpr<'_>) {
fn emit_ast_expr(
machine: &mut EmitMachine,
eval: &mut Vec<Instruction>,
ast: &TemplateAstExpr<'_>,
) {
match ast {
TemplateAstExpr::StaticContent(template_token) => {
eval.push(Instruction::AppendContent {
content: template_token.source().to_string(),
content: template_token.source().clone(),
});
}
TemplateAstExpr::Interpolation {
@ -57,7 +71,7 @@ fn emit_ast_expr(machine: &mut EmitMachine, eval: &mut Vec<Instruction>, ast: &T
} => {
if let Some(ws) = prev_whitespace {
eval.push(Instruction::AppendContent {
content: ws.source().to_string(),
content: ws.source().clone(),
});
}
@ -70,7 +84,7 @@ fn emit_ast_expr(machine: &mut EmitMachine, eval: &mut Vec<Instruction>, ast: &T
if let Some(ws) = post_whitespace {
eval.push(Instruction::AppendContent {
content: ws.source().to_string(),
content: ws.source().clone(),
});
}
}
@ -89,7 +103,7 @@ fn emit_expr(
match expression {
TemplateAstExpr::VariableAccess(template_token) => {
eval.push(Instruction::LoadFromContextToSlot {
name: template_token.source().to_string(),
name: template_token.source().clone(),
slot: emit_slot,
});
}