DotPrompt. Compiler
(anantha_dot_prompt v1.1.0)
Copy Markdown
Compiles DotPrompt (.prompt) template files into rendered output.
Purpose
The Compiler is the core of the DotPrompt system. It takes a .prompt file
path or raw content, tokenizes it via DotPrompt.Parser.Lexer, parses it
into an AST, validates the structure, and compiles the AST into rendered
prompt text with interpolated parameters.
Key Functions
do_parse_schema/5— Parses a prompt file and returns its schema (params, fragments, docs, response contract) without renderingcompile_fresh_with_content/8— Full compile pipeline: tokenize, parse, validate, compile, and resolve vary blockscompile_ast/2— Recursively compiles AST nodes (text, if, case, vary, fragments) into rendered outputstale?/1— Checks if cached compiled output is stale by comparing file mtimes
Compilation Pipeline
- Tokenize → parse → validate (structural validation)
- Apply parameter defaults
- Validate params against declarations
- Resolve response contracts across blocks
- Compile AST with
@paraminterpolation - Resolve
{vary}blocks (at-runtime variation) - Cache parsed schema and compiled structural output