The Interpreter of Jsonnet
Evaluating a bespoke syntax tree.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Rune Reading
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// JSONNET PATTERN //
local Interpret(ast) =
if ast.type == "Number" then ast.value
else if ast.type == "Add" then Interpret(ast.left) + Interpret(ast.right)
else if ast.type == "Mul" then Interpret(ast.left) * Interpret(ast.right)
else error "Unknown AST node";
local Expr = {
type: "Add",
left: { type: "Number", value: 10 },
right: {
type: "Mul",
left: { type: "Number", value: 5 },
right: { type: "Number", value: 2 }
}
};
{
result: Interpret(Expr)
}
Jsonnet functions can traverse Abstract Syntax Trees, evaluating custom mathematical or logical runes to compute deeply nested outcomes.
Runic Tags:
#behavioral
#interpreter
#jsonnet