@mark1russell7/coeval 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/build/index.d.ts +399 -100
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1818 -172
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/src/agree.ts +26 -5
- package/src/codec.ts +185 -0
- package/src/conform.ts +2 -3
- package/src/doc.ts +2 -2
- package/src/evaluate.ts +281 -9
- package/src/formula.ts +19 -8
- package/src/index.ts +36 -2
- package/src/parts.ts +70 -1
- package/src/reference.ts +143 -18
- package/src/static.ts +54 -74
- package/src/stdlib.ts +220 -18
- package/src/syntax.ts +846 -0
- package/src/types.ts +28 -1
- package/src/world.ts +50 -0
package/src/types.ts
CHANGED
|
@@ -54,6 +54,33 @@ export interface Domain {
|
|
|
54
54
|
* a step with the key into a member reaches a member of the type. A key without a type gives `unknown`.
|
|
55
55
|
*/
|
|
56
56
|
readonly steps?: Readonly<Record<string, ValueType>>;
|
|
57
|
+
/**
|
|
58
|
+
* The codec of the members: it writes a member as JSON and reads it again (D40). A document holds a member as the
|
|
59
|
+
* standard extension `ext.domain`. A domain without a codec has no such document.
|
|
60
|
+
*/
|
|
61
|
+
readonly codec?: DomainCodec;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The codec of a domain: it writes a member of the domain as JSON, and it reads the JSON again (D40). Both functions
|
|
66
|
+
* must be pure. `decode(encode(v))` must equal `v` by `sameValue` (EXT.ROUNDTRIP). The codec must give one JSON
|
|
67
|
+
* value for each member, thus the same value has the same document in each language (D12).
|
|
68
|
+
*/
|
|
69
|
+
export interface DomainCodec {
|
|
70
|
+
/**
|
|
71
|
+
* This function writes a member of the domain as JSON.
|
|
72
|
+
*
|
|
73
|
+
* @param value - A member of the domain.
|
|
74
|
+
* @returns The JSON of the member.
|
|
75
|
+
*/
|
|
76
|
+
readonly encode: (value: unknown) => Json;
|
|
77
|
+
/**
|
|
78
|
+
* This function reads the JSON of a member again. It throws for JSON that does not write a member.
|
|
79
|
+
*
|
|
80
|
+
* @param data - The JSON that `encode` gave.
|
|
81
|
+
* @returns The member.
|
|
82
|
+
*/
|
|
83
|
+
readonly decode: (data: Json) => unknown;
|
|
57
84
|
}
|
|
58
85
|
|
|
59
86
|
/** A problem of a value type: the keys from the root of the term to the problem, and the reason. */
|
|
@@ -102,7 +129,7 @@ const TOP: Form = { t: "top" };
|
|
|
102
129
|
const BOTTOM: Form = { t: "bottom" };
|
|
103
130
|
|
|
104
131
|
/** This function gives the domain of a base type: the domain of the machine, or else the domain of the kernel. */
|
|
105
|
-
function domainOf(name: string, domains: Readonly<Record<string, Domain>> | undefined): Domain | undefined {
|
|
132
|
+
export function domainOf(name: string, domains: Readonly<Record<string, Domain>> | undefined): Domain | undefined {
|
|
106
133
|
// The top and the bottom are not domains. A table entry with their names has no effect.
|
|
107
134
|
if (name === "unknown" || name === "never") return undefined;
|
|
108
135
|
const found = domains !== undefined && Object.hasOwn(domains, name) ? domains[name] : Object.hasOwn(STD_DOMAINS, name) ? STD_DOMAINS[name] : undefined;
|
package/src/world.ts
CHANGED
|
@@ -121,6 +121,51 @@ export interface KindFacts {
|
|
|
121
121
|
readonly lazy?: readonly LazyRule[];
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* The declaration of one attribute of the nodes of a kind (D42). The last two rungs of the ladder of an attribute
|
|
126
|
+
* read it (TREE.LADDER). Each term is a document. A bare term gets the type `of` of the parts of the kind.
|
|
127
|
+
*
|
|
128
|
+
* - `copy`: `true` gives a node without an answer of the first three rungs the same attribute of its parent
|
|
129
|
+
* (TREE.COPY).
|
|
130
|
+
* - `fold`: the value of a node without an answer of the first four rungs. The fold starts with the term `unit`.
|
|
131
|
+
* Then the term `combine` adds the attribute of each node in the list `children`, one at a time (TREE.FOLD).
|
|
132
|
+
* `combine` sees the names `acc` and `item`.
|
|
133
|
+
* - `default`: the term that gives the value when no rung before it answers and the declaration has no fold.
|
|
134
|
+
*/
|
|
135
|
+
export interface AttributeDeclaration {
|
|
136
|
+
readonly copy?: boolean;
|
|
137
|
+
readonly fold?: { readonly unit: Json; readonly combine: Json };
|
|
138
|
+
readonly default?: Json;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The tree contract of a kind (D42): the equations of the attributes of its nodes. Each equation is a document that
|
|
143
|
+
* evaluates with the node as `self` and without capabilities. A bare equation gets the type `of` of the parts of the
|
|
144
|
+
* kind.
|
|
145
|
+
*
|
|
146
|
+
* - `equations`: the attributes of the node itself. An equation sees no names.
|
|
147
|
+
* - `down`: the attributes of each child of the node. `self` is this node. An equation sees the names `child`,
|
|
148
|
+
* `index` and `prev` (TREE.DOWN).
|
|
149
|
+
* - `attributes`: the declarations of the attributes of the node, for the rungs `copy` and `default`.
|
|
150
|
+
*/
|
|
151
|
+
export interface TreeContract {
|
|
152
|
+
readonly equations?: Readonly<Record<string, Json>>;
|
|
153
|
+
readonly down?: Readonly<Record<string, Json>>;
|
|
154
|
+
readonly attributes?: Readonly<Record<string, AttributeDeclaration>>;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* This function gives the type of a bare equation of a kind (D42). It is the type `of` of the shape of its parts, or
|
|
159
|
+
* else the type `of` of the shape `rest` of a record. The plan, the reference and `check` read it with this one function.
|
|
160
|
+
*
|
|
161
|
+
* @param kind - The kind.
|
|
162
|
+
* @returns The type, or `undefined` when the shape declares none.
|
|
163
|
+
*/
|
|
164
|
+
export function equationType(kind: Kind): string | undefined {
|
|
165
|
+
const parts = kind.parts as { readonly of?: string; readonly rest?: { readonly of?: string } } | undefined;
|
|
166
|
+
return parts?.of ?? parts?.rest?.of;
|
|
167
|
+
}
|
|
168
|
+
|
|
124
169
|
/**
|
|
125
170
|
* A kind gives the name of an evaluator for each verb, and the contract of its value. The contract serves each verb.
|
|
126
171
|
* For each verb, the kernel splits the parts and narrows their capabilities by it, and `check` reads its scope rules.
|
|
@@ -157,6 +202,11 @@ export interface Kind extends KindFacts {
|
|
|
157
202
|
* document of the kind, in the place of the type that the rule of the evaluator synthesizes.
|
|
158
203
|
*/
|
|
159
204
|
readonly result?: ValueType;
|
|
205
|
+
/**
|
|
206
|
+
* The equations and the declarations of the attributes of a node of the decorated tree (D42). Only the evaluator
|
|
207
|
+
* `tree.node` reads them, and `check` checks each equation one time (TREE.LADDER).
|
|
208
|
+
*/
|
|
209
|
+
readonly tree?: TreeContract;
|
|
160
210
|
/** One sentence that tells what the kind is. */
|
|
161
211
|
readonly summary?: string;
|
|
162
212
|
}
|