Module

Tramaj.Eval

Package
purescript-tramaj-purs
Repository
lucasdicioccio/purescript-tramaj-purs

Evaluates a Tramaj.Ast Program against an input context, producing either a Tramaj.Node document or an ordinary JSON value.

There is one evaluator. v1 had two — an expression evaluator and a template-node evaluator — because it had two ASTs; now that documents are expressions, evalExpr handles everything, and the only rule the document side adds is how a child value becomes children (childNodes).

Value is the language's full value domain, not JSON with extras bolted on: an array or object may contain document nodes, which is what makes the JSX-children pattern — passing a fragment to a component as an ordinary parameter — work without a separate template-value category. JSON is what you get at the boundaries (toJson), where a node would be meaningless: an attribute value, an action payload, an element's value slot.

Evaluation is eager and deterministic everywhere except Branch, which evaluates only the arm it selects.

Kept in lockstep with ../tramaj-hs/src/Tramaj/Eval.hs.

#EvalError Source

data EvalError

Constructors

  • UnboundName String
  • PathNotFound (Array String)
  • TypeMismatch String
  • UnknownLibrary String
  • ImportCycle String
  • ConcatMismatch String String

    a <> b where the two sides are not the same concatenable type.

  • InLibrary String EvalError

    Whatever went wrong inside an imported library, tagged with which library it was. Nests, so a failure three imports deep reads as the chain that reached it. This matters most for the parameter a library needs and the import never supplied: that surfaces as this library's own PathNotFound ["ctx", ...], and without the tag there would be nothing on it to say whose context was short.

  • SymbolsUnavailable

    A symbol would have to be minted in concrete mode: an allocation (?(k), v3-symbols §4) or an unsupplied ?ctx.path demand at the root (§1.3). Concrete mode has no way to represent either. Symbolic mode never raises it: that is the one mode where a symbol is representable.

  • NotConcrete String

    A symbolic value where the language requires a concrete one (§1.5's table, and a symbol used as an allocation key).

  • AllocationInLibrary String

    A program containing ?(k) is loaded as a library (§1.4): only the root may allocate, because the root runs exactly once and a library does not. Lexical, not data-flow — raised because the library's own source contains an allocation site, whether or not evaluation would ever reach it.

  • TypeErr TypeError

    A static v4-types failure (v4-types §10), surfaced from either the erasure pass every entry point below runs before evaluating anything (§7, roadmap Phase 11) or from building the symbolic envelope's "types"/"type-constraints" lists (§8, Phase 13). Not a new evaluation failure mode — nothing here is raised during evaluation — but Tramaj.Types.TypeError still needs a home in the one error type every entry point already returns.

Instances

#Output Source

data Output

What a program produced. Which one it is follows from the value the root actually evaluated to, not from how the root was written: a program whose root is $header yields a document if that binding holds one.

Constructors

Instances

#Mode Source

data Mode

A host parameter, not a property of the program (v3-symbols §5): what an interpreter is willing to read back out, not anything the template itself declares. Concrete is reference.md exactly — Node JSON or a plain value, byte for byte. Symbolic wraps the same evaluation in the v3 envelope (§5.2); until §3/§4 land, that envelope's "symbols" and "constraints" are always empty, because nothing yet produces either.

Constructors

Instances

#LibraryTable Source

type LibraryTable = Map String Program

Host-supplied library store. Where a library came from — a file, an embedded string, a fetch — is entirely the host's business; the evaluator only ever sees an already-parsed Program.

#evalProgram Source

evalProgram :: Mode -> LibraryTable -> Json -> Program -> Either EvalError Output

Evaluation now depends on the mode (v3-symbols §5): an allocation or an unsupplied root demand mints a symbol in symbolic mode and raises SymbolsUnavailable in concrete mode. There is no mode-independent evaluation any more, so every entry point takes one.

#runProgram Source

runProgram :: Mode -> LibraryTable -> Json -> Program -> Either EvalError Json

The mode-aware entry point: what a host actually serializes. Concrete mode is evalProgram unchanged, projected down to plain JSON — Node JSON for a document, the value itself for an expression, with any emissions discarded (v3-symbols §5.1). Symbolic mode wraps the same Output in the v3 envelope (§5.2), including the deduplicated symbol table and constraint list.

#builtinNames Source

builtinNames :: Array String

The fixed builtin vocabulary. Builtins are ordinary values in the initial environment rather than a separate call form, so cardinality($xs), $f($x) and map($xs, $not) all go through Call.