zen_tmpl/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mod error;
mod interpreter;
mod lexer;
mod parser;

use crate::interpreter::Interpreter;
use crate::lexer::Lexer;
use crate::parser::Parser;
use zen_expression::variable::Variable;

pub use crate::error::{ParserError, TemplateRenderError};

pub fn render(template: &str, context: Variable) -> Result<Variable, TemplateRenderError> {
    let tokens = Lexer::from(template.trim()).collect();
    let nodes = Parser::from(tokens.as_slice()).collect()?;

    Interpreter::from(nodes.as_slice()).collect_for(context)
}