Add proper impl for templating
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
1ee7611981
commit
4470af3926
5 changed files with 85 additions and 27 deletions
|
|
@ -8,14 +8,14 @@ use crate::emit::Instruction;
|
|||
use crate::input::TempleInput;
|
||||
|
||||
#[derive(Debug, Error, Display)]
|
||||
enum EvalError {
|
||||
pub enum EvaluationError {
|
||||
/// An unknown variable was encountered: .0
|
||||
UnknownVariable(TempleInput),
|
||||
/// An explicit abort was requested
|
||||
ExplicitAbort,
|
||||
}
|
||||
|
||||
fn execute(instructions: &[Instruction], global_context: &Context) -> Result<String, EvalError> {
|
||||
pub fn execute(instructions: &[Instruction], global_context: &Context) -> Result<String, EvaluationError> {
|
||||
let mut output = String::new();
|
||||
|
||||
let mut scopes: HashMap<crate::emit::VariableSlot, serde_json::Value> = HashMap::new();
|
||||
|
|
@ -27,7 +27,7 @@ fn execute(instructions: &[Instruction], global_context: &Context) -> Result<Str
|
|||
let value = global_context
|
||||
.values
|
||||
.get(name.as_str())
|
||||
.ok_or(EvalError::UnknownVariable(name.clone()))?;
|
||||
.ok_or(EvaluationError::UnknownVariable(name.clone()))?;
|
||||
|
||||
scopes.insert(*slot, value.clone());
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ fn execute(instructions: &[Instruction], global_context: &Context) -> Result<Str
|
|||
output.push_str(value);
|
||||
}
|
||||
Instruction::PushScope { inherit_parent: _ } => todo!(),
|
||||
Instruction::Abort => return Err(EvalError::ExplicitAbort),
|
||||
Instruction::Abort => return Err(EvaluationError::ExplicitAbort),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ mod tests {
|
|||
fn check_simple_variable_interpolation() {
|
||||
let input = "Hello {{= world }}";
|
||||
|
||||
let parsed = crate::parser::parse(input).unwrap();
|
||||
let parsed = crate::parser::parse(input.into()).unwrap();
|
||||
|
||||
let ast = crate::ast::parse(parsed.tokens()).unwrap();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue