SPECIFICATIONS AND SCOPE

Distinguish modules, values, and ASTs.

In Grammar v0.3, parsing and evaluation are separate operations. Parsing returns a MatraModule that preserves source structure, not a single document node or an evaluated AST.

Specification v0.3, individual npm package versions, and compiler ABI are managed separately.

01 / PARSE

parse reads the entire source

parse(source) parses the whole source and returns a MatraModule containing declarations and expressions. It does not require one root node and never returns a partial result as success after a syntax error. Syntax and evaluated document values are distinct stages.

const module = parse(source)
// module is syntax, not the evaluated document AST

02 / STATIC

evaluateStatic only retrieves static values

Literals, arrays, objects, preceding static lets, nodes built only from these, and child spreads of static arrays can be retrieved statically. Unresolved references, members, calls, operators, control expressions, assignments, and other expressions requiring execution produce a static-evaluation error. There is no implicit execution fallback.

const value = evaluateStatic(module)

03 / EVALUATE

Execution is explicit with evaluate

When a dynamic expression must run, call evaluate(module) explicitly. This keeps parsing distinct from execution and prevents static retrieval from behaving like a silent fallback. It does not provide a sandbox for safely running untrusted source.

const result = evaluate(module)
const ast = staticValueToAST(result)

04 / AST

Convert evaluated values to AST

The object-form AST passed to a document renderer is produced from an evaluated value with staticValueToAST(). MatraModule, runtime value, and document AST have different roles. The old Parser v0.2 syntaxMode contract does not apply to current v0.3.

Keep distinct

This page is an overview.

This page is a summary. Refer to the linked Matra specification for normative definitions, complete API contracts, and verification fixtures.

Primary source