DotPrompt.AST (anantha_dot_prompt v1.1.0)

Copy Markdown

AST node handlers for the DotPrompt compiler.

Purpose

Provides recursive compilation functions for each AST node type produced by the DotPrompt parser. Each handle_* function processes a specific node (text, if, case, vary, fragment) and returns compiled output along with tracking state (vary map, used variables, file metadata).

Key Functions

  • handle_text_node/3 — Interpolates @param references in raw text
  • handle_if_node/6 — Compiles conditional branches and emits section annotations for traceability
  • handle_case_node/4 — Compiles case/match branches with section annotations
  • handle_vary_node/4 — Compiles all vary branches for at-runtime selection
  • handle_static_fragment/3 — Expands static {fragment} includes
  • handle_dynamic_fragment/3 — Expands dynamic {{fragment}} includes
  • extract_vary_vars/1 — Collects all vary variable names from the AST

Internal Use

This module is called by DotPrompt.Compiler.compile_ast/2 during the compilation phase. Each handler recursively compiles child nodes and accumulates state through a reduce-while pattern.