Prep for parser

This commit is contained in:
Yura Dupyn 2026-02-05 00:23:27 +01:00
parent a478542c2a
commit 99cd517a58
3 changed files with 598 additions and 14 deletions

View file

@ -1,15 +1,15 @@
// === Identifiers ===
type VariableName = string
type FunctionName = string
export type VariableName = string
export type FunctionName = string
// type CellName = string
type Tag = string
type FieldName = string
export type Tag = string
export type FieldName = string
// === Program ===
type Timestamp = number;
export type Timestamp = number;
type Program = {
export type Program = {
function_definitions: Map<FunctionName, FunctionDefinition>,
function_definition_order: FunctionName[],
// TODO: Perhaps include the story and the environment?
@ -34,11 +34,11 @@ type Program = {
// | "dirty"
// | "error"
type FunctionDefinition =
export type FunctionDefinition =
| { tag: "user", def: UserFunctionDefinition }
| { tag: "primitive", def: PrimitiveFunctionDefinition }
type UserFunctionDefinition = {
export type UserFunctionDefinition = {
// Raw user input (authoritative)
name: FunctionName,
raw_parameters: string;
@ -54,7 +54,7 @@ type UserFunctionDefinition = {
last_modified_at: Timestamp;
}
type PrimitiveFunctionDefinition = {
export type PrimitiveFunctionDefinition = {
name: FunctionName,
implementation: (args: Value[]) => Value,
}
@ -136,7 +136,7 @@ export namespace Program {
// === Expressions ===
type Expr =
export type Expr =
| { tag: "literal", literal: Literal }
| { tag: "var_use", name: VariableName }
// | { tag: "cell_ref", name: CellName }
@ -150,21 +150,21 @@ type Expr =
| { tag: "lambda", parameters: ProductPattern[], body: Expr }
| { tag: "apply", callee: Expr, args: Expr[] }
type Literal =
export type Literal =
| { tag: "number", value: number }
| { tag: "string", value: string }
type ExprBinding = {
export type ExprBinding = {
var: ProductPattern,
expr: Expr,
}
type ProductPattern =
export type ProductPattern =
| { tag: "any", name: VariableName }
| { tag: "tuple", patterns: ProductPattern[] }
| { tag: "record", fields: { field_name: FieldName, pattern: ProductPattern }[] }
type Pattern =
export type Pattern =
| ProductPattern
| { tag: "tag", tag_name: Tag }
| { tag: "tagged", tag_name: Tag, pattern: Pattern }