Skip to main content

parse_template_expr

Function parse_template_expr 

Source
pub fn parse_template_expr(content: &str) -> Result<TemplateExpr, NikaError>
Expand description

Parse the content inside {{ ... }} into a TemplateExpr.

Grammar:

  expr := "context." path             → Context
        | "inputs." path              → Input
        | "with." alias_path ("|" t)* → Alias (with. prefix stripped)
        | alias_path ("|" transform)* → Alias

This replaces the buggy negative-lookahead regex approach:

  1. No negative lookahead bugs — exact strip_prefix("context.") is unambiguous
  2. Arbitrary transform chains — split('|') handles any number of pipes
  3. Better error messages — parser can report exactly what’s wrong
  4. Simpler to maintain — no complex regex to debug