FOUNDATION 02 / AST

AST — the object form of the Data Model.

AST v0.2 is the in-memory object representation that lets visitors, transformers, and renderers work with the document nodes and values defined by the Data Model. It is distinct from the syntax tree for Matra source (MatraModule), and it is not a separate kind of language value. Conversion to and from MatraJSON preserves the same document structure.

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

01 / SHAPE

Node shape

The semantic fields are tag, props, and children. Values inside props and children follow the data model. Implementations may add metadata such as source positions, but must not change semantic values.

type MatraScalar = string | number | boolean | null
type MatraValue =
  | MatraScalar
  | MatraValue[]
  | { [key: string]: MatraValue }

interface MatraAST {
  tag: string
  props: Record<string, MatraValue>
  children: Array<MatraAST | MatraValue>
}

02 / CONVERSION

Convert to and from MatraJSON

The object form {tag, props, children} and MatraJSON [tag, props, children] must convert recursively without losing information. Preserve tag, values, scalar types, nested nodes, and child order. Copying mutable lists and maps is recommended to avoid accidental sharing.

{ tag: "item", props: {}, children: ["one"] }
// MatraJSON: ["item", {}, ["one"]]

03 / SOURCE POSITION

Positions are metadata

An AST node may carry a position. Start/end offsets are zero-based; line and column are one-based. Positions are excluded from document-value equality and omitted from the three-element MatraJSON form.

04 / VALIDATION

Validate nodes

A validator rejects nodes whose tag is not a string, props is not a string-keyed value map, children is not a list, or child is neither an AST node nor a model value.

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