@mark1russell7/coeval 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/build/index.d.ts +916 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1856 -0
- package/build/index.js.map +1 -0
- package/package.json +49 -3
- package/src/classify.ts +54 -0
- package/src/context.ts +189 -0
- package/src/deref.ts +290 -0
- package/src/doc.ts +182 -0
- package/src/evaluate.ts +553 -0
- package/src/index.ts +118 -0
- package/src/ladder.ts +141 -0
- package/src/order.ts +111 -0
- package/src/parts.ts +43 -0
- package/src/stdlib.ts +283 -0
- package/src/world.ts +163 -0
- package/README.md +0 -3
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,916 @@
|
|
|
1
|
+
//#region src/doc.d.ts
|
|
2
|
+
/** A JSON value. */
|
|
3
|
+
type Json = null | boolean | number | string | readonly Json[] | {
|
|
4
|
+
readonly [key: string]: Json;
|
|
5
|
+
};
|
|
6
|
+
/** A JSON record. */
|
|
7
|
+
type JsonRecord = {
|
|
8
|
+
readonly [key: string]: Json;
|
|
9
|
+
};
|
|
10
|
+
/** One step of a path that is a plain key: a name, or an index of a list. */
|
|
11
|
+
type Key = string | number;
|
|
12
|
+
/**
|
|
13
|
+
* The type of a document is a reference into the world (the registry of kinds).
|
|
14
|
+
*
|
|
15
|
+
* - A text is a base reference with one key: `"add"`.
|
|
16
|
+
* - A list of keys is a base reference with a path: `["git", "push"]`.
|
|
17
|
+
* - A document of type `ref` is the same reference, expanded. Its path starts at the root `world`.
|
|
18
|
+
*
|
|
19
|
+
* The kernel resolves a base reference itself. The expanded form is necessary only to attach more to the
|
|
20
|
+
* reference. Thus the chain of types stops at a base reference.
|
|
21
|
+
*/
|
|
22
|
+
type TypeRef = string | readonly Key[] | {
|
|
23
|
+
readonly type: "ref";
|
|
24
|
+
readonly value: readonly Json[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A typed document: an envelope with a header and a value. The header names the type of the value. The value is
|
|
28
|
+
* not changed by the envelope at any time. Thus any JSON value can have a type: a number, a list, a text or a record.
|
|
29
|
+
*/
|
|
30
|
+
type Envelope = {
|
|
31
|
+
/** The type: a reference to a kind of the world. */
|
|
32
|
+
readonly type: TypeRef;
|
|
33
|
+
/** The value. */
|
|
34
|
+
readonly value: Json;
|
|
35
|
+
/** The name of a binding. A sequence gives the result of this document to the later steps under this name. */
|
|
36
|
+
readonly name?: string;
|
|
37
|
+
/** The own entries: one evaluator name for each verb. An own entry changes only this document. */
|
|
38
|
+
readonly own?: Readonly<Record<string, string>>;
|
|
39
|
+
};
|
|
40
|
+
/** The keys that an envelope can have. */
|
|
41
|
+
export declare const ENVELOPE_KEYS: readonly ["type", "value", "name", "own"];
|
|
42
|
+
/**
|
|
43
|
+
* This function tells if a value is a JSON record (not an array and not null).
|
|
44
|
+
*
|
|
45
|
+
* @param value - The value to examine.
|
|
46
|
+
* @returns `true` for a record.
|
|
47
|
+
*/
|
|
48
|
+
export declare function isRecord(value: Json | undefined): value is JsonRecord;
|
|
49
|
+
/**
|
|
50
|
+
* This function reads a field of a record. It reads only the own fields, thus `constructor` is not a field.
|
|
51
|
+
*
|
|
52
|
+
* @param record - The record.
|
|
53
|
+
* @param key - The name of the field.
|
|
54
|
+
* @returns The value of the field, or `undefined` when the record has no such field.
|
|
55
|
+
*/
|
|
56
|
+
export declare function field(record: JsonRecord, key: string): Json | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* This function tells if a value is a key of a path: a text, or a whole number from 0.
|
|
59
|
+
*
|
|
60
|
+
* @param value - The value to examine.
|
|
61
|
+
* @returns `true` for a key.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isKey(value: Json | undefined): value is Key;
|
|
64
|
+
/**
|
|
65
|
+
* This function tells if a value is a reference to a type. The reference is a text, a list of keys, or a document
|
|
66
|
+
* of type `ref` whose path starts at the root `world`.
|
|
67
|
+
*
|
|
68
|
+
* @param value - The value to examine.
|
|
69
|
+
* @returns `true` for a reference to a type.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isTypeRef(value: Json | undefined): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* This function gives the path of a reference to a type, from the root of the world.
|
|
74
|
+
*
|
|
75
|
+
* @param type - The reference.
|
|
76
|
+
* @returns The keys from the root of the world, or `undefined` for a computed step that has no fixed key.
|
|
77
|
+
*/
|
|
78
|
+
export declare function typePath(type: TypeRef): readonly Key[] | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* This function gives the text of a type for a reader: its keys, joined with a dot.
|
|
81
|
+
*
|
|
82
|
+
* @param type - The reference to the type.
|
|
83
|
+
* @returns The text, for example `git.push`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function typeName(type: TypeRef): string;
|
|
86
|
+
/**
|
|
87
|
+
* This function tells if a value has the form of an envelope. That form is a record with a reference to a type
|
|
88
|
+
* and a `value`. It has no other keys than the keys of an envelope. A contract decides where an envelope is
|
|
89
|
+
* expected. This function only checks the form.
|
|
90
|
+
*
|
|
91
|
+
* @param value - The value to examine.
|
|
92
|
+
* @returns `true` when the value has the form of an envelope.
|
|
93
|
+
*/
|
|
94
|
+
export declare function isEnvelope(value: Json | undefined): value is JsonRecord & Envelope;
|
|
95
|
+
/**
|
|
96
|
+
* This function makes an envelope.
|
|
97
|
+
*
|
|
98
|
+
* @param type - The reference to the kind.
|
|
99
|
+
* @param value - The value.
|
|
100
|
+
* @param header - The optional name and own entries.
|
|
101
|
+
* @returns The envelope.
|
|
102
|
+
*/
|
|
103
|
+
export declare function typed(type: TypeRef, value: Json, header?: {
|
|
104
|
+
readonly name?: string;
|
|
105
|
+
readonly own?: Record<string, string>;
|
|
106
|
+
}): Envelope;
|
|
107
|
+
/**
|
|
108
|
+
* This function makes a reference document: a path from a root of the context.
|
|
109
|
+
*
|
|
110
|
+
* @param path - The steps. The first step is a root: `self`, `names`, `world`, `event` or `caps`.
|
|
111
|
+
* @returns The document of type `ref`.
|
|
112
|
+
*/
|
|
113
|
+
export declare function ref(...path: readonly Json[]): Envelope;
|
|
114
|
+
/**
|
|
115
|
+
* This function gives an envelope as a JSON record, for a store or for a view.
|
|
116
|
+
*
|
|
117
|
+
* @param doc - The envelope.
|
|
118
|
+
* @returns The same envelope as JSON.
|
|
119
|
+
*/
|
|
120
|
+
export declare function toJson(doc: Envelope): JsonRecord;
|
|
121
|
+
/**
|
|
122
|
+
* This function reads an envelope from JSON. A value without the form of an envelope gives `undefined`.
|
|
123
|
+
*
|
|
124
|
+
* @param value - The JSON value.
|
|
125
|
+
* @returns The envelope, or `undefined`.
|
|
126
|
+
*/
|
|
127
|
+
export declare function fromJson(value: Json | undefined): Envelope | undefined;
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/world.d.ts
|
|
130
|
+
/** The two sides of evaluation. `derive` is pure. `run` causes effects in order. */
|
|
131
|
+
type Side = "derive" | "run";
|
|
132
|
+
/**
|
|
133
|
+
* Where the parts of a value are. A part is a typed document that the evaluator gets sealed.
|
|
134
|
+
*
|
|
135
|
+
* - `none`: the value is data. It has no parts.
|
|
136
|
+
* - `list`: the value is a list, and each item is a part.
|
|
137
|
+
* - `record`: the value is a record. The named fields are parts, and the other fields are data.
|
|
138
|
+
*
|
|
139
|
+
* `of` is the type of a bare item. An item without an envelope gets this type from its container.
|
|
140
|
+
*/
|
|
141
|
+
type PartsSpec = {
|
|
142
|
+
readonly shape: "none";
|
|
143
|
+
} | {
|
|
144
|
+
readonly shape: "list";
|
|
145
|
+
readonly of?: string;
|
|
146
|
+
} | {
|
|
147
|
+
readonly shape: "record";
|
|
148
|
+
readonly fields: readonly string[];
|
|
149
|
+
readonly of?: string;
|
|
150
|
+
};
|
|
151
|
+
/** A kind gives the name of an evaluator for each verb, and the contract of its value. */
|
|
152
|
+
interface Kind {
|
|
153
|
+
readonly verbs: Readonly<Record<string, string>>;
|
|
154
|
+
/** Where the parts of the value are. The default is `none`. */
|
|
155
|
+
readonly parts?: PartsSpec;
|
|
156
|
+
/** The side of the kind. A kind of the run side causes effects. The default is `derive`. */
|
|
157
|
+
readonly side?: Side;
|
|
158
|
+
/** One sentence that tells what the kind is. */
|
|
159
|
+
readonly summary?: string;
|
|
160
|
+
}
|
|
161
|
+
/** A namespace: a group of entries under one key of the world. */
|
|
162
|
+
interface Namespace {
|
|
163
|
+
readonly kinds: Readonly<Record<string, WorldEntry>>;
|
|
164
|
+
}
|
|
165
|
+
/** An alias: a reference to another entry of the world. The lookup follows it (collapse). */
|
|
166
|
+
type Alias = {
|
|
167
|
+
readonly type: "ref";
|
|
168
|
+
readonly value: readonly Json[];
|
|
169
|
+
};
|
|
170
|
+
/** One entry of the world: a kind, a namespace, or an alias. */
|
|
171
|
+
type WorldEntry = Kind | Namespace | Alias;
|
|
172
|
+
/** A world holds the kinds and the defaults that answer the questions. */
|
|
173
|
+
interface World {
|
|
174
|
+
readonly kinds: Readonly<Record<string, WorldEntry>>;
|
|
175
|
+
readonly defaults: Readonly<Record<string, string>>;
|
|
176
|
+
}
|
|
177
|
+
/** The result of a lookup of a type in the world. */
|
|
178
|
+
type Lookup = {
|
|
179
|
+
readonly ok: true;
|
|
180
|
+
readonly kind: Kind;
|
|
181
|
+
readonly path: readonly Key[];
|
|
182
|
+
readonly aliases: number;
|
|
183
|
+
} | {
|
|
184
|
+
readonly ok: false;
|
|
185
|
+
readonly reason: "unknown" | "cycle" | "not-a-kind" | "computed";
|
|
186
|
+
readonly path: readonly Key[];
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* This function tells if an entry of the world is a kind.
|
|
190
|
+
*
|
|
191
|
+
* @param entry - The entry.
|
|
192
|
+
* @returns `true` for a kind.
|
|
193
|
+
*/
|
|
194
|
+
export declare function isKind(entry: WorldEntry | undefined): entry is Kind;
|
|
195
|
+
/**
|
|
196
|
+
* This function tells if an entry of the world is an alias.
|
|
197
|
+
*
|
|
198
|
+
* @param entry - The entry.
|
|
199
|
+
* @returns `true` for an alias.
|
|
200
|
+
*/
|
|
201
|
+
export declare function isAlias(entry: WorldEntry | undefined): entry is Alias;
|
|
202
|
+
/**
|
|
203
|
+
* This function finds the kind that a type names. It walks the path from the root of the world, one key at a
|
|
204
|
+
* time. An alias on the way is followed until a kind answers (collapse). A cycle of aliases stops the lookup.
|
|
205
|
+
*
|
|
206
|
+
* @param world - The world.
|
|
207
|
+
* @param type - The reference to the type.
|
|
208
|
+
* @returns The kind and the path of the kind after each alias, or the reason of a failure.
|
|
209
|
+
*/
|
|
210
|
+
export declare function lookupKind(world: World, type: TypeRef): Lookup;
|
|
211
|
+
/**
|
|
212
|
+
* This function gives the entries of a world as a JSON record, so that a reference can walk it. A kind is a
|
|
213
|
+
* record with its verbs, an alias is a reference document, and a namespace is a record of its entries.
|
|
214
|
+
*
|
|
215
|
+
* @param entries - The entries.
|
|
216
|
+
* @returns The JSON form.
|
|
217
|
+
*/
|
|
218
|
+
export declare function entriesAsJson(entries: Readonly<Record<string, WorldEntry>>): Json;
|
|
219
|
+
/**
|
|
220
|
+
* This function makes the document of a kind, so that a view can draw it as each other document.
|
|
221
|
+
*
|
|
222
|
+
* @param name - The name of the kind.
|
|
223
|
+
* @param kind - The kind.
|
|
224
|
+
* @returns The document of type `kind`.
|
|
225
|
+
*/
|
|
226
|
+
export declare function kindDocument(name: string, kind: Kind): Envelope;
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/ladder.d.ts
|
|
229
|
+
/** The rungs of the ladder, in the order that a question visits them. */
|
|
230
|
+
export declare const RUNGS: readonly ["own", "kind", "default"];
|
|
231
|
+
/** One rung of the ladder. */
|
|
232
|
+
type Rung = (typeof RUNGS)[number];
|
|
233
|
+
/** The place where the ladder found the type. */
|
|
234
|
+
type KindSource = "document" | "container";
|
|
235
|
+
/**
|
|
236
|
+
* The outcome of one rung.
|
|
237
|
+
*
|
|
238
|
+
* - `answers`: the rung gives an evaluator.
|
|
239
|
+
* - `no-entry`: the rung has nothing for this verb, thus the question goes to the next rung.
|
|
240
|
+
* - `skipped`: the rung does not apply, because no type is known.
|
|
241
|
+
* - `unknown-kind`: the type is not a kind of the world. The question stops.
|
|
242
|
+
*/
|
|
243
|
+
type Outcome = "answers" | "no-entry" | "skipped" | "unknown-kind";
|
|
244
|
+
/** The record of one rung that a question visited. */
|
|
245
|
+
interface Step {
|
|
246
|
+
readonly rung: Rung;
|
|
247
|
+
readonly outcome: Outcome;
|
|
248
|
+
/** The evaluator, when the outcome is `answers`. */
|
|
249
|
+
readonly evaluator?: string;
|
|
250
|
+
/** The text of the type, at the kind rung. */
|
|
251
|
+
readonly kind?: string;
|
|
252
|
+
/** The place of the type, at the kind rung. */
|
|
253
|
+
readonly source?: KindSource;
|
|
254
|
+
}
|
|
255
|
+
/** The answer to a question. It keeps the record of each rung that the question visited. */
|
|
256
|
+
interface Answer {
|
|
257
|
+
readonly verb: string;
|
|
258
|
+
/** The evaluator that answers. A question that stops with an error has no evaluator. */
|
|
259
|
+
readonly evaluator?: string;
|
|
260
|
+
/** The rung that answered. */
|
|
261
|
+
readonly rung?: Rung;
|
|
262
|
+
/** The reason when no rung answers. */
|
|
263
|
+
readonly error?: "unknown-kind" | "no-answer";
|
|
264
|
+
readonly steps: readonly Step[];
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The header that the ladder reads: the type and the own entries. An envelope is a header. A bare value has an
|
|
268
|
+
* empty header, and its position can declare its type.
|
|
269
|
+
*/
|
|
270
|
+
interface Header {
|
|
271
|
+
readonly type?: TypeRef;
|
|
272
|
+
readonly own?: Readonly<Record<string, string>>;
|
|
273
|
+
}
|
|
274
|
+
/** The options of a question. */
|
|
275
|
+
interface AskOptions {
|
|
276
|
+
/** The type that the position of a bare value declares. The type of an envelope wins. */
|
|
277
|
+
readonly declaredType?: string;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* This function finds the kind that a type names, and follows each alias. It gives `undefined` for an unknown
|
|
281
|
+
* type.
|
|
282
|
+
*
|
|
283
|
+
* @param world - The world.
|
|
284
|
+
* @param type - The reference to the type.
|
|
285
|
+
* @returns The kind, or `undefined`.
|
|
286
|
+
*/
|
|
287
|
+
export declare function kindOf(world: World, type: TypeRef): Kind | undefined;
|
|
288
|
+
/**
|
|
289
|
+
* This function finds a kind by a text type. It is the same as `kindOf` for a one-key reference.
|
|
290
|
+
*
|
|
291
|
+
* @param world - The world.
|
|
292
|
+
* @param name - The text of the type.
|
|
293
|
+
* @returns The kind, or `undefined`.
|
|
294
|
+
*/
|
|
295
|
+
export declare function kindNamed(world: World, name: TypeRef): Kind | undefined;
|
|
296
|
+
/**
|
|
297
|
+
* This function asks a document a question, and gives the evaluator that answers it.
|
|
298
|
+
*
|
|
299
|
+
* The question visits the rungs in order: the own entry of the envelope, then its kind, then the default of the
|
|
300
|
+
* world. The type comes from the envelope, or else from the type that the position declares. The type is a
|
|
301
|
+
* reference into the world. The ladder does not guess a type from the shape of a value.
|
|
302
|
+
*
|
|
303
|
+
* @param world - The kinds and the defaults.
|
|
304
|
+
* @param doc - The header of the document: an envelope, or `{}` for a bare value.
|
|
305
|
+
* @param verb - The verb of the question, for example `eval` or `view`.
|
|
306
|
+
* @param options - The type that the position declares.
|
|
307
|
+
* @returns The answer, with the record of each rung that the question visited.
|
|
308
|
+
*/
|
|
309
|
+
export declare function ask(world: World, doc: Header, verb: string, options?: AskOptions): Answer;
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/deref.d.ts
|
|
312
|
+
/** The brand of a host thing: an object of the host that answers the steps of a path itself. */
|
|
313
|
+
export declare const THING: unique symbol;
|
|
314
|
+
/**
|
|
315
|
+
* A host thing: an object that answers the steps of a path itself, for example a node of a live tree. It is the
|
|
316
|
+
* own entry of the ladder for the verb `deref`.
|
|
317
|
+
*/
|
|
318
|
+
interface HostThing {
|
|
319
|
+
readonly [THING]: true;
|
|
320
|
+
/** A short text for a reader, for example `node card`. */
|
|
321
|
+
readonly label: string;
|
|
322
|
+
/**
|
|
323
|
+
* This function answers one step.
|
|
324
|
+
*
|
|
325
|
+
* @param key - The key of the step.
|
|
326
|
+
* @returns What the step reaches, or `undefined`.
|
|
327
|
+
*/
|
|
328
|
+
deref(key: Key): Thing | undefined;
|
|
329
|
+
/**
|
|
330
|
+
* This function gives the thing as a value, when a reference ends on it.
|
|
331
|
+
*
|
|
332
|
+
* @returns The value.
|
|
333
|
+
*/
|
|
334
|
+
toJson(): Json;
|
|
335
|
+
}
|
|
336
|
+
/** Something that a path can reach: a JSON value, or a host thing. */
|
|
337
|
+
type Thing = Json | HostThing;
|
|
338
|
+
/**
|
|
339
|
+
* This function tells if a thing is a host thing.
|
|
340
|
+
*
|
|
341
|
+
* @param thing - The thing.
|
|
342
|
+
* @returns `true` for a host thing.
|
|
343
|
+
*/
|
|
344
|
+
export declare function isHostThing(thing: Thing | undefined): thing is HostThing;
|
|
345
|
+
/** The roots of a context. Each path starts with one of them. */
|
|
346
|
+
export declare const ROOTS: readonly ["self", "names", "world", "event", "caps"];
|
|
347
|
+
/** One root of a context. */
|
|
348
|
+
type Root = (typeof ROOTS)[number];
|
|
349
|
+
/**
|
|
350
|
+
* The context of a term: a record with five roots. A reference reaches outside its term only through them.
|
|
351
|
+
*
|
|
352
|
+
* - `self`: the node that the term is part of.
|
|
353
|
+
* - `names`: the values that the evaluators around the term bound.
|
|
354
|
+
* - `world`: the registry of kinds.
|
|
355
|
+
* - `event`: the event that started a run.
|
|
356
|
+
* - `caps`: the effects that the term can cause.
|
|
357
|
+
*/
|
|
358
|
+
interface Context {
|
|
359
|
+
readonly self: Thing;
|
|
360
|
+
readonly names: Readonly<Record<string, Json>>;
|
|
361
|
+
readonly world: Thing;
|
|
362
|
+
readonly event: Thing;
|
|
363
|
+
readonly caps: readonly string[];
|
|
364
|
+
}
|
|
365
|
+
/** The code of a `deref` evaluator: it answers one step of a path on a document of its kind. */
|
|
366
|
+
type DerefCode = (doc: Envelope, key: Key) => Thing | undefined;
|
|
367
|
+
/** The result of a step document: what it reached, or the reason of a failure. */
|
|
368
|
+
type WalkResult = {
|
|
369
|
+
readonly ok: true;
|
|
370
|
+
readonly thing: Thing;
|
|
371
|
+
} | {
|
|
372
|
+
readonly ok: false;
|
|
373
|
+
readonly reason: string;
|
|
374
|
+
};
|
|
375
|
+
/** The input of a walker: the code of a step document, for example `nearest`. */
|
|
376
|
+
interface WalkInput {
|
|
377
|
+
/** The value of the step document. */
|
|
378
|
+
readonly data: Json;
|
|
379
|
+
/** The thing that the path reached before this step. */
|
|
380
|
+
readonly here: Thing;
|
|
381
|
+
readonly context: Context;
|
|
382
|
+
/**
|
|
383
|
+
* This function answers one step on a thing, through the ladder.
|
|
384
|
+
*
|
|
385
|
+
* @param thing - The thing.
|
|
386
|
+
* @param key - The key.
|
|
387
|
+
* @returns What the step reaches, or `undefined`.
|
|
388
|
+
*/
|
|
389
|
+
deref(thing: Thing, key: Key): Thing | undefined;
|
|
390
|
+
}
|
|
391
|
+
/** A walker: the code of the verb `step` of a kind of step documents. */
|
|
392
|
+
type Walker = (input: WalkInput) => WalkResult;
|
|
393
|
+
/** What a resolution needs: the world, and the code of the `deref` evaluators and of the walkers. */
|
|
394
|
+
interface Navigator {
|
|
395
|
+
readonly world: World;
|
|
396
|
+
readonly derefs?: Readonly<Record<string, DerefCode>>;
|
|
397
|
+
readonly walkers?: Readonly<Record<string, Walker>>;
|
|
398
|
+
}
|
|
399
|
+
/** The way that one hop of a path was answered. */
|
|
400
|
+
type HopBy = "root" | "own" | "kind" | "default" | "step" | "collapse";
|
|
401
|
+
/** One hop of a path: the step, what it reached, and who answered it. */
|
|
402
|
+
interface Hop {
|
|
403
|
+
readonly step: Json;
|
|
404
|
+
readonly thing: Thing;
|
|
405
|
+
readonly by: HopBy;
|
|
406
|
+
}
|
|
407
|
+
/** The result of a resolution: what the path reached, with each hop, or an error with the hops before it. */
|
|
408
|
+
type Resolution = {
|
|
409
|
+
readonly ok: true;
|
|
410
|
+
readonly thing: Thing;
|
|
411
|
+
readonly hops: readonly Hop[];
|
|
412
|
+
} | {
|
|
413
|
+
readonly ok: false;
|
|
414
|
+
readonly code: "#REF!" | "#CYCLE!" | "#STEP?";
|
|
415
|
+
readonly reason: string;
|
|
416
|
+
readonly hops: readonly Hop[];
|
|
417
|
+
};
|
|
418
|
+
/**
|
|
419
|
+
* This function answers one step of a path on a thing, through the ladder of the verb `deref`. A host thing
|
|
420
|
+
* answers for itself (own). A document asks its own entry, then its kind. The default goes into the value: a field
|
|
421
|
+
* of a record, or an item of a list.
|
|
422
|
+
*
|
|
423
|
+
* @param nav - The world and the code of the evaluators.
|
|
424
|
+
* @param thing - The thing that the path reached.
|
|
425
|
+
* @param key - The key of the step.
|
|
426
|
+
* @returns What the step reaches and the rung that answered, or `undefined`.
|
|
427
|
+
*/
|
|
428
|
+
export declare function derefStep(nav: Navigator, thing: Thing, key: Key): {
|
|
429
|
+
readonly thing: Thing;
|
|
430
|
+
readonly by: HopBy;
|
|
431
|
+
} | undefined;
|
|
432
|
+
/**
|
|
433
|
+
* This function tells if a thing is a reference document: an envelope of the type `ref`.
|
|
434
|
+
*
|
|
435
|
+
* @param thing - The thing.
|
|
436
|
+
* @returns `true` for a reference document.
|
|
437
|
+
*/
|
|
438
|
+
export declare function isRef(thing: Thing | undefined): thing is Envelope & {
|
|
439
|
+
readonly value: readonly Json[];
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* This function makes the thing of the root `world`: the entries of the world as JSON. An alias is a reference
|
|
443
|
+
* document in it, thus a walk through the world follows each alias (collapse).
|
|
444
|
+
*
|
|
445
|
+
* @param world - The world.
|
|
446
|
+
* @returns The thing.
|
|
447
|
+
*/
|
|
448
|
+
export declare function worldThing(world: World): Json;
|
|
449
|
+
/**
|
|
450
|
+
* This function makes a context. The world comes from the navigator when the call gives none.
|
|
451
|
+
*
|
|
452
|
+
* @param parts - The roots to set.
|
|
453
|
+
* @returns The context.
|
|
454
|
+
*/
|
|
455
|
+
export declare function context(parts?: Partial<Context>): Context;
|
|
456
|
+
/**
|
|
457
|
+
* This function resolves a path from a context, and records each hop.
|
|
458
|
+
*
|
|
459
|
+
* The first step is a root of the context. Each later step is a key or a step document. A key goes up the ladder
|
|
460
|
+
* of the verb `deref` on the thing that the path reached. A step document is evaluated by the walker of its kind,
|
|
461
|
+
* with the thing that the path reached. After each hop, a reference document is followed until the path reaches
|
|
462
|
+
* something else (collapse).
|
|
463
|
+
*
|
|
464
|
+
* @param nav - The world and the code of the evaluators.
|
|
465
|
+
* @param ctx - The context.
|
|
466
|
+
* @param path - The steps.
|
|
467
|
+
* @returns What the path reached and each hop, or an error.
|
|
468
|
+
*/
|
|
469
|
+
export declare function resolve(nav: Navigator, ctx: Context, path: readonly Json[]): Resolution;
|
|
470
|
+
/**
|
|
471
|
+
* This function gives the value of a thing: the thing itself for JSON, or the value that a host thing gives.
|
|
472
|
+
*
|
|
473
|
+
* @param thing - The thing.
|
|
474
|
+
* @returns The value.
|
|
475
|
+
*/
|
|
476
|
+
export declare function valueOfThing(thing: Thing): Json;
|
|
477
|
+
//#endregion
|
|
478
|
+
//#region src/classify.d.ts
|
|
479
|
+
/** A shape proposes a kind for each document that has all of its fields. */
|
|
480
|
+
interface Shape {
|
|
481
|
+
readonly name: string;
|
|
482
|
+
readonly fields: readonly string[];
|
|
483
|
+
readonly kind: string;
|
|
484
|
+
}
|
|
485
|
+
/** The result of a classification. */
|
|
486
|
+
interface Classification {
|
|
487
|
+
/** The kind of the one most specific shape. */
|
|
488
|
+
readonly kind?: string;
|
|
489
|
+
/** The names of the most specific shapes. */
|
|
490
|
+
readonly candidates: readonly string[];
|
|
491
|
+
/** `no-match`: no shape applies. `ambiguous`: two or more shapes match equally well. */
|
|
492
|
+
readonly error?: "no-match" | "ambiguous";
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* This function proposes a kind for a value without a type, from the fields that the value has.
|
|
496
|
+
* A shape applies when the value has each field of the shape. The most specific shapes are the ones that
|
|
497
|
+
* no other applicable shape contains. A host uses a classifier when data comes in, and then tags the data.
|
|
498
|
+
* The ladder does not call a classifier.
|
|
499
|
+
*
|
|
500
|
+
* @param shapes - The shapes to examine.
|
|
501
|
+
* @param value - The value without a type.
|
|
502
|
+
* @returns The proposed kind, or an error with the candidates.
|
|
503
|
+
*/
|
|
504
|
+
export declare function classify(shapes: readonly Shape[], value: Json): Classification;
|
|
505
|
+
/**
|
|
506
|
+
* This function puts a value in an envelope with a type. The value does not change.
|
|
507
|
+
*
|
|
508
|
+
* @param value - The value.
|
|
509
|
+
* @param kind - The name of the kind.
|
|
510
|
+
* @returns The envelope.
|
|
511
|
+
*/
|
|
512
|
+
export declare function tag(value: Json, kind: string): Envelope;
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/parts.d.ts
|
|
515
|
+
/** One part of a value: its key, the JSON of the part, and the type that its position declares. */
|
|
516
|
+
interface PartSlot {
|
|
517
|
+
readonly key: string;
|
|
518
|
+
readonly item: Json;
|
|
519
|
+
readonly of?: string;
|
|
520
|
+
}
|
|
521
|
+
/** The value of a document, split into its data and its parts. */
|
|
522
|
+
type Split = {
|
|
523
|
+
readonly ok: true;
|
|
524
|
+
readonly data: Json;
|
|
525
|
+
readonly parts: readonly PartSlot[];
|
|
526
|
+
} | {
|
|
527
|
+
readonly ok: false;
|
|
528
|
+
readonly reason: string;
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
531
|
+
* This function splits a value into its data and its parts, by the contract of its kind. The evaluator and the
|
|
532
|
+
* view use the same split, thus a picture shows the parts that the evaluation gets.
|
|
533
|
+
*
|
|
534
|
+
* @param spec - The contract of the parts.
|
|
535
|
+
* @param value - The value of the document.
|
|
536
|
+
* @returns The data and the parts, or the reason why the value does not obey the contract.
|
|
537
|
+
*/
|
|
538
|
+
export declare function splitParts(spec: PartsSpec | undefined, value: Json): Split;
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region src/evaluate.d.ts
|
|
541
|
+
/** The code of an error value. */
|
|
542
|
+
type ErrorCode = "#KIND?" | "#NOEVAL" | "#PART?" | "#NAME?" | "#REF!" | "#CYCLE!" | "#STEP?" | "#VALUE!" | "#ARGS" | "#CAP!" | "#CALC!" | "#DEPTH!";
|
|
543
|
+
/** An error value: a code and a reason. An evaluation gives an error value, and it does not throw. */
|
|
544
|
+
interface EvalError {
|
|
545
|
+
readonly code: ErrorCode;
|
|
546
|
+
readonly reason: string;
|
|
547
|
+
}
|
|
548
|
+
/** The result of an evaluation: a value, or an error value. */
|
|
549
|
+
type Result = {
|
|
550
|
+
readonly ok: true;
|
|
551
|
+
readonly value: Json;
|
|
552
|
+
} | {
|
|
553
|
+
readonly ok: false;
|
|
554
|
+
readonly error: EvalError;
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* This function makes a result with a value.
|
|
558
|
+
*
|
|
559
|
+
* @param value - The value.
|
|
560
|
+
* @returns The result.
|
|
561
|
+
*/
|
|
562
|
+
export declare function ok(value: Json): Result;
|
|
563
|
+
/**
|
|
564
|
+
* This function makes a result with an error value.
|
|
565
|
+
*
|
|
566
|
+
* @param code - The code of the error.
|
|
567
|
+
* @param reason - One sentence that tells the cause.
|
|
568
|
+
* @returns The result.
|
|
569
|
+
*/
|
|
570
|
+
export declare function fail(code: ErrorCode, reason: string): Result;
|
|
571
|
+
/**
|
|
572
|
+
* This function makes a context with names and capabilities. The other roots are empty, and an evaluation sets
|
|
573
|
+
* the world.
|
|
574
|
+
*
|
|
575
|
+
* @param names - The names and their values.
|
|
576
|
+
* @param caps - The effects that the term can cause.
|
|
577
|
+
* @param self - The node of the term, if it has one.
|
|
578
|
+
* @returns The context.
|
|
579
|
+
*/
|
|
580
|
+
export declare function makeContext(names?: Readonly<Record<string, Json>>, caps?: readonly string[], self?: Thing): Context;
|
|
581
|
+
/**
|
|
582
|
+
* A sealed part. An evaluator can read the binding name of a part and evaluate it. It cannot read the value of the
|
|
583
|
+
* part, thus two parts that give the same results can replace each other.
|
|
584
|
+
*/
|
|
585
|
+
interface Part$1 {
|
|
586
|
+
/** The position of the part in its parent: an index of a list, or a field of a record. */
|
|
587
|
+
readonly key: string;
|
|
588
|
+
/** The binding name from the header of the part. */
|
|
589
|
+
readonly name?: string;
|
|
590
|
+
/**
|
|
591
|
+
* This function evaluates the part. Each call is a new evaluation.
|
|
592
|
+
*
|
|
593
|
+
* @param context - The context for the part. The default is the context of the parent.
|
|
594
|
+
* @returns The result of the part.
|
|
595
|
+
*/
|
|
596
|
+
evaluate(context?: Context): Result;
|
|
597
|
+
}
|
|
598
|
+
/** The input of an evaluator. */
|
|
599
|
+
interface EvalInput {
|
|
600
|
+
/** The text of the type of the document, for example `add` or `math.sum` after its alias. */
|
|
601
|
+
readonly kind: string;
|
|
602
|
+
/** The value of the document without its parts. */
|
|
603
|
+
readonly data: Json;
|
|
604
|
+
/** The parts, in the order of the value. */
|
|
605
|
+
readonly parts: readonly Part$1[];
|
|
606
|
+
/** The context of the document. */
|
|
607
|
+
readonly context: Context;
|
|
608
|
+
/**
|
|
609
|
+
* This function resolves a path from the context of the document.
|
|
610
|
+
*
|
|
611
|
+
* @param path - The steps. The first step is a root.
|
|
612
|
+
* @returns What the path reached, with each hop.
|
|
613
|
+
*/
|
|
614
|
+
resolve(path: readonly Json[]): Resolution;
|
|
615
|
+
/**
|
|
616
|
+
* This function causes an effect. The context must have the capability for the kind of the effect. In a run, an
|
|
617
|
+
* evaluator cannot cause an effect: the host does each effect, thus only a runner can wait for it.
|
|
618
|
+
*
|
|
619
|
+
* @param kind - The kind of the effect, for example `log`.
|
|
620
|
+
* @param payload - The data of the effect.
|
|
621
|
+
* @returns The payload, or the error `#CAP!`.
|
|
622
|
+
*/
|
|
623
|
+
effect(kind: string, payload: Json): Result;
|
|
624
|
+
}
|
|
625
|
+
/** An evaluator: a function from the input of a document to a result. */
|
|
626
|
+
type Evaluator = (input: EvalInput) => Result;
|
|
627
|
+
/**
|
|
628
|
+
* The steps of an evaluation that can wait. It yields a promise only when the host makes it wait. A runner takes the
|
|
629
|
+
* result of a part with `yield*`, thus a run goes on at once until an effect waits.
|
|
630
|
+
*/
|
|
631
|
+
type Steps = Generator<Promise<Result>, Result, Result>;
|
|
632
|
+
/** A part for a runner. Its evaluation can wait for the effects in it. */
|
|
633
|
+
interface RunPart {
|
|
634
|
+
/** The position of the part in its parent: an index of a list, or a field of a record. */
|
|
635
|
+
readonly key: string;
|
|
636
|
+
/** The binding name from the header of the part. */
|
|
637
|
+
readonly name?: string;
|
|
638
|
+
/**
|
|
639
|
+
* This function evaluates the part. Each call is a new evaluation. Take its result with `yield*`.
|
|
640
|
+
*
|
|
641
|
+
* @param context - The context for the part. The default is the context of the parent.
|
|
642
|
+
* @returns The steps of the evaluation of the part.
|
|
643
|
+
*/
|
|
644
|
+
evaluate(context?: Context): Steps;
|
|
645
|
+
}
|
|
646
|
+
/** The input of a runner: the input of an evaluator, with parts and effects that can wait. */
|
|
647
|
+
interface RunInput {
|
|
648
|
+
/** The text of the type of the document. */
|
|
649
|
+
readonly kind: string;
|
|
650
|
+
/** The value of the document without its parts. */
|
|
651
|
+
readonly data: Json;
|
|
652
|
+
/** The parts, in the order of the value. */
|
|
653
|
+
readonly parts: readonly RunPart[];
|
|
654
|
+
/** The context of the document. */
|
|
655
|
+
readonly context: Context;
|
|
656
|
+
/**
|
|
657
|
+
* This function resolves a path from the context of the document.
|
|
658
|
+
*
|
|
659
|
+
* @param path - The steps. The first step is a root.
|
|
660
|
+
* @returns What the path reached, with each hop.
|
|
661
|
+
*/
|
|
662
|
+
resolve(path: readonly Json[]): Resolution;
|
|
663
|
+
/**
|
|
664
|
+
* This function causes an effect. The context must have the capability. In a run, the host does the effect,
|
|
665
|
+
* and the steps wait when the host waits. In an evaluation, the effect gives its payload. Take its result with
|
|
666
|
+
* `yield*`.
|
|
667
|
+
*
|
|
668
|
+
* @param kind - The kind of the effect, for example `log`.
|
|
669
|
+
* @param payload - The data of the effect.
|
|
670
|
+
* @returns The steps that give the result of the host, or an error value.
|
|
671
|
+
*/
|
|
672
|
+
effect(kind: string, payload: Json): Steps;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* A runner: the code of a kind whose parts or effects can wait, as a generator function. The same runner serves an
|
|
676
|
+
* evaluation, which does not wait at any time, and a run, in which the host does each effect.
|
|
677
|
+
*/
|
|
678
|
+
type Runner = (input: RunInput) => Steps;
|
|
679
|
+
/** A machine: a world of kinds, and the code of each evaluator name, of each `deref` and of each walker. */
|
|
680
|
+
interface Machine extends Navigator {
|
|
681
|
+
readonly evaluators: Readonly<Record<string, Evaluator>>;
|
|
682
|
+
/** The runners, by evaluator name. A runner wins over an evaluator of the same name. */
|
|
683
|
+
readonly runners?: Readonly<Record<string, Runner>>;
|
|
684
|
+
/** The deepest nesting of evaluations. The default is 200. */
|
|
685
|
+
readonly maxDepth?: number;
|
|
686
|
+
}
|
|
687
|
+
/** An effect that an evaluation caused, in the order of the effects. */
|
|
688
|
+
interface Effect {
|
|
689
|
+
readonly index: number;
|
|
690
|
+
readonly kind: string;
|
|
691
|
+
readonly payload: Json;
|
|
692
|
+
/** The ID of the trace node that caused the effect. */
|
|
693
|
+
readonly node: number;
|
|
694
|
+
/** The number of events before the effect. The effect comes before the end of its node. */
|
|
695
|
+
readonly at: number;
|
|
696
|
+
}
|
|
697
|
+
/** The host side of a run: it does one effect, and gives its result. A throw or a rejection is an error value. */
|
|
698
|
+
type Perform = (effect: Effect) => Json | Promise<Json>;
|
|
699
|
+
/** The options of a run. */
|
|
700
|
+
interface RunOptions {
|
|
701
|
+
/** The host code that does each effect. Without it, an effect gives its payload, as in an evaluation. */
|
|
702
|
+
readonly perform?: Perform;
|
|
703
|
+
/** The type of a bare root value. */
|
|
704
|
+
readonly declaredType?: string;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* This function tells if the capabilities permit an effect. A capability permits the kind of its name, and each kind
|
|
708
|
+
* in its namespace: `store` permits `store.update`.
|
|
709
|
+
*
|
|
710
|
+
* @param caps - The capabilities of the context.
|
|
711
|
+
* @param kind - The kind of the effect.
|
|
712
|
+
* @returns `true` when one capability permits it.
|
|
713
|
+
*/
|
|
714
|
+
export declare function permits(caps: readonly string[], kind: string): boolean;
|
|
715
|
+
/** One evaluation in a trace. The children are the evaluations of its parts, in the order that they started. */
|
|
716
|
+
interface TraceNode {
|
|
717
|
+
readonly id: number;
|
|
718
|
+
/** The keys from the root document to this document. */
|
|
719
|
+
readonly path: readonly string[];
|
|
720
|
+
/** The document. A bare value has the type that its position declares. */
|
|
721
|
+
readonly doc: Envelope;
|
|
722
|
+
/** `true` when the type came from the container and not from an envelope. */
|
|
723
|
+
readonly declared: boolean;
|
|
724
|
+
/** The answer of the ladder to the verb `eval`. */
|
|
725
|
+
readonly answer: Answer;
|
|
726
|
+
readonly side: Side;
|
|
727
|
+
/** The names that the document could read when its evaluation started. */
|
|
728
|
+
readonly names: readonly string[];
|
|
729
|
+
/** The names and their values when the evaluation started. */
|
|
730
|
+
readonly scope: Readonly<Record<string, Json>>;
|
|
731
|
+
/** The capabilities that the document had when its evaluation started. */
|
|
732
|
+
readonly caps: readonly string[];
|
|
733
|
+
/** A short text for the root `self` when the evaluation started. */
|
|
734
|
+
readonly self: string;
|
|
735
|
+
/** The time of the start. Each start and each end takes one tick. */
|
|
736
|
+
readonly enter: number;
|
|
737
|
+
/** The time of the end. */
|
|
738
|
+
readonly exit: number;
|
|
739
|
+
readonly result: Result;
|
|
740
|
+
readonly children: readonly TraceNode[];
|
|
741
|
+
/** The indices of the effects that this document caused itself. */
|
|
742
|
+
readonly effects: readonly number[];
|
|
743
|
+
}
|
|
744
|
+
/** The record of one evaluation of a document. */
|
|
745
|
+
interface Run {
|
|
746
|
+
readonly result: Result;
|
|
747
|
+
readonly trace: TraceNode;
|
|
748
|
+
readonly effects: readonly Effect[];
|
|
749
|
+
/** The number of ticks. */
|
|
750
|
+
readonly time: number;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* This function evaluates a document, and records each evaluation in a trace.
|
|
754
|
+
*
|
|
755
|
+
* The verb `eval` goes up the ladder for each document. The kind of the document tells where its parts are. The
|
|
756
|
+
* evaluator gets each part sealed: it can evaluate the part, and it cannot read its value. A failure gives an error
|
|
757
|
+
* value, and the function does not throw. An effect is recorded in its order, and nothing does it.
|
|
758
|
+
*
|
|
759
|
+
* @param machine - The world and the code of the evaluators.
|
|
760
|
+
* @param doc - The document, as JSON.
|
|
761
|
+
* @param context - The names and the capabilities at the root.
|
|
762
|
+
* @param declaredType - The type of a bare root value.
|
|
763
|
+
* @returns The result, the trace and the effects in their order.
|
|
764
|
+
*/
|
|
765
|
+
export declare function evaluate(machine: Machine, doc: Json, context?: Context, declaredType?: string): Run;
|
|
766
|
+
/**
|
|
767
|
+
* This function runs a document: an evaluation in which the host does each effect. A runner waits for its
|
|
768
|
+
* parts and for its effects, thus a step can read the result of the step before. The part of the run before the
|
|
769
|
+
* first wait happens at once, in the call.
|
|
770
|
+
*
|
|
771
|
+
* @param machine - The world, the evaluators and the runners.
|
|
772
|
+
* @param doc - The document, as JSON.
|
|
773
|
+
* @param context - The names and the capabilities at the root.
|
|
774
|
+
* @param options - The host code that does the effects, and the type of a bare root value.
|
|
775
|
+
* @returns The result, the trace and the effects in their order, when the run ends.
|
|
776
|
+
*/
|
|
777
|
+
export declare function run(machine: Machine, doc: Json, context?: Context, options?: RunOptions): Promise<Run>;
|
|
778
|
+
/**
|
|
779
|
+
* This function finds a node of a trace by its path.
|
|
780
|
+
*
|
|
781
|
+
* @param trace - The root of the trace.
|
|
782
|
+
* @param path - The keys from the root.
|
|
783
|
+
* @returns The first evaluation at that path, or `undefined` when the document did not evaluate.
|
|
784
|
+
*/
|
|
785
|
+
export declare function nodeAt(trace: TraceNode, path: readonly string[]): TraceNode | undefined;
|
|
786
|
+
/**
|
|
787
|
+
* This function lists the nodes of a trace in the order of their start.
|
|
788
|
+
*
|
|
789
|
+
* @param trace - The root of the trace.
|
|
790
|
+
* @returns Each node, the root first.
|
|
791
|
+
*/
|
|
792
|
+
export declare function flatten(trace: TraceNode): readonly TraceNode[];
|
|
793
|
+
//#endregion
|
|
794
|
+
//#region src/stdlib.d.ts
|
|
795
|
+
/**
|
|
796
|
+
* The world of the examples: small kinds for numbers, lists, conditions, names, sequences and effects.
|
|
797
|
+
* Each kind names an evaluator for `eval` and a view for `view`. The site draws each document with its view.
|
|
798
|
+
*/
|
|
799
|
+
export declare const STD_WORLD: World;
|
|
800
|
+
/** The code of the evaluators of the standard world, by name. */
|
|
801
|
+
export declare const STD_EVALUATORS: Readonly<Record<string, Evaluator>>;
|
|
802
|
+
/** The walkers of the standard world, by name. */
|
|
803
|
+
export declare const STD_WALKERS: Readonly<Record<string, Walker>>;
|
|
804
|
+
/**
|
|
805
|
+
* The runners of the standard world, by name: the kinds that can hold effects. Each one evaluates its parts in
|
|
806
|
+
* order. In a run, an effect ends before the next step starts.
|
|
807
|
+
*/
|
|
808
|
+
export declare const STD_RUNNERS: Readonly<Record<string, Runner>>;
|
|
809
|
+
/** The machine of the examples: the standard world, its evaluators, its runners and its walkers. */
|
|
810
|
+
export declare const STD_MACHINE: Machine;
|
|
811
|
+
/** The capabilities of the examples at the root: the two effects of the standard world. */
|
|
812
|
+
export declare const STD_CAPS: readonly string[];
|
|
813
|
+
//#endregion
|
|
814
|
+
//#region src/order.d.ts
|
|
815
|
+
/** One step of a sequence: its name, the names of the earlier steps that it reads, and if it has an effect. */
|
|
816
|
+
interface StepSpec {
|
|
817
|
+
readonly id: string;
|
|
818
|
+
readonly reads: readonly string[];
|
|
819
|
+
readonly effect: boolean;
|
|
820
|
+
}
|
|
821
|
+
/** An edge from a step that must come first to a step that must come after it. */
|
|
822
|
+
type Edge = readonly [before: string, after: string];
|
|
823
|
+
/** A reference that a sequence cannot resolve. */
|
|
824
|
+
interface OrderProblem {
|
|
825
|
+
readonly step: string;
|
|
826
|
+
readonly reads: string;
|
|
827
|
+
/** `unknown-name`: no step has this name. `read-before-defined`: the step with this name comes later. */
|
|
828
|
+
readonly problem: "unknown-name" | "read-before-defined";
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* This function finds the references that a sequence cannot resolve. A step can read only the steps before it.
|
|
832
|
+
*
|
|
833
|
+
* @param steps - The steps, in the written order.
|
|
834
|
+
* @returns One problem for each bad reference, in the written order.
|
|
835
|
+
*/
|
|
836
|
+
export declare function checkSteps(steps: readonly StepSpec[]): readonly OrderProblem[];
|
|
837
|
+
/**
|
|
838
|
+
* This function gives the data edges: a step comes after each earlier step that it reads.
|
|
839
|
+
*
|
|
840
|
+
* @param steps - The steps, in the written order.
|
|
841
|
+
* @returns The edges. A bad reference gives no edge.
|
|
842
|
+
*/
|
|
843
|
+
export declare function dataEdges(steps: readonly StepSpec[]): readonly Edge[];
|
|
844
|
+
/**
|
|
845
|
+
* This function gives the effect edges: each step with an effect comes after the previous step with an effect.
|
|
846
|
+
* Effects keep their written order. Steps without an effect get no effect edge.
|
|
847
|
+
*
|
|
848
|
+
* @param steps - The steps, in the written order.
|
|
849
|
+
* @returns The edges, one for each pair of consecutive effect steps.
|
|
850
|
+
*/
|
|
851
|
+
export declare function effectEdges(steps: readonly StepSpec[]): readonly Edge[];
|
|
852
|
+
/**
|
|
853
|
+
* This function tells if an order of the steps gives the same meaning as the written order.
|
|
854
|
+
* The order must contain each step one time, and it must obey the data edges and the effect edges.
|
|
855
|
+
*
|
|
856
|
+
* @param steps - The steps, in the written order.
|
|
857
|
+
* @param order - The names of the steps in the order to examine.
|
|
858
|
+
* @returns `true` when the order is permitted.
|
|
859
|
+
*/
|
|
860
|
+
export declare function isAllowedOrder(steps: readonly StepSpec[], order: readonly string[]): boolean;
|
|
861
|
+
/**
|
|
862
|
+
* This function puts the steps in layers. Each step goes one layer after the last step that it must follow.
|
|
863
|
+
* The steps of one layer do not depend on each other, thus they can run at the same time.
|
|
864
|
+
*
|
|
865
|
+
* @param steps - The steps, in the written order.
|
|
866
|
+
* @returns The layers, first to last. Each layer keeps the written order.
|
|
867
|
+
*/
|
|
868
|
+
export declare function layers(steps: readonly StepSpec[]): readonly (readonly string[])[];
|
|
869
|
+
//#endregion
|
|
870
|
+
//#region src/context.d.ts
|
|
871
|
+
/** The parts of a context. A term can reach outside itself only through these parts. */
|
|
872
|
+
export declare const PARTS: readonly ["names", "focus", "world", "event", "caps"];
|
|
873
|
+
/** One part of a context. */
|
|
874
|
+
type Part = (typeof PARTS)[number];
|
|
875
|
+
/** The description of one part of a context. */
|
|
876
|
+
interface PartInfo {
|
|
877
|
+
readonly part: Part;
|
|
878
|
+
readonly title: string;
|
|
879
|
+
/** What a reference through this part reaches. */
|
|
880
|
+
readonly reaches: string;
|
|
881
|
+
/** The direction in which a reference through this part goes. */
|
|
882
|
+
readonly direction: string;
|
|
883
|
+
}
|
|
884
|
+
/** The descriptions of the parts, in the order of `PARTS`. */
|
|
885
|
+
export declare const PART_INFO: readonly PartInfo[];
|
|
886
|
+
/**
|
|
887
|
+
* What a construct gives the parts of its body, for one part of the context.
|
|
888
|
+
*
|
|
889
|
+
* - `same`: the parts get the same value.
|
|
890
|
+
* - `extends`: the parts get the value with more names.
|
|
891
|
+
* - `moves`: the parts get a new position.
|
|
892
|
+
* - `narrows`: the parts get a smaller set.
|
|
893
|
+
* - `sets`: the parts get a new value.
|
|
894
|
+
* - `none`: the parts get nothing.
|
|
895
|
+
*/
|
|
896
|
+
type Give = "same" | "extends" | "moves" | "narrows" | "sets" | "none";
|
|
897
|
+
/** How a construct uses one part of the context. */
|
|
898
|
+
interface Use {
|
|
899
|
+
readonly reads: boolean;
|
|
900
|
+
readonly gives: Give;
|
|
901
|
+
readonly note: string;
|
|
902
|
+
}
|
|
903
|
+
/** A construct of a language, and how it uses each part of the context. */
|
|
904
|
+
interface Construct {
|
|
905
|
+
readonly id: string;
|
|
906
|
+
readonly title: string;
|
|
907
|
+
readonly side: Side;
|
|
908
|
+
readonly summary: string;
|
|
909
|
+
readonly example: Envelope;
|
|
910
|
+
readonly uses: Readonly<Record<Part, Use>>;
|
|
911
|
+
}
|
|
912
|
+
/** Six constructs that show the range of the context. */
|
|
913
|
+
export declare const CONSTRUCTS: readonly Construct[];
|
|
914
|
+
//#endregion
|
|
915
|
+
export type { Alias, Answer, AskOptions, Classification, Construct, Context, Part as ContextPart, DerefCode, Edge, Effect, Envelope, ErrorCode, EvalError, EvalInput, Evaluator, Give, Header, Hop, HopBy, HostThing, Json, JsonRecord, Key, Kind, KindSource, Lookup, Machine, Namespace, Navigator, OrderProblem, Outcome, Part$1 as Part, PartInfo, PartSlot, PartsSpec, Perform, Resolution, Result, Root, Run, RunInput, RunOptions, RunPart, Rung, Runner, Shape, Side, Split, Step, StepSpec, Thing, TraceNode, TypeRef, Use, WalkInput, WalkResult, Walker, World, WorldEntry };
|
|
916
|
+
//# sourceMappingURL=index.d.ts.map
|