@mark1russell7/coeval 0.4.0 → 0.4.2
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 +4 -3
- package/build/index.d.ts +597 -331
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1195 -41
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/agree.ts +231 -0
- package/src/errors.ts +6 -1
- package/src/evaluate.ts +96 -11
- package/src/formula.ts +10 -8
- package/src/generate.ts +367 -0
- package/src/index.ts +6 -0
- package/src/reference.ts +571 -0
- package/src/static.ts +39 -7
- package/src/stdlib.ts +6 -2
- package/src/world.ts +24 -0
package/build/index.d.ts
CHANGED
|
@@ -247,285 +247,6 @@ export declare function thrown(error: unknown, who: string): Failed;
|
|
|
247
247
|
*/
|
|
248
248
|
export declare function describe(value: unknown): string;
|
|
249
249
|
//#endregion
|
|
250
|
-
//#region src/world.d.ts
|
|
251
|
-
/** The two sides of evaluation. `derive` is pure. `run` causes effects in order. */
|
|
252
|
-
type Side = "derive" | "run";
|
|
253
|
-
/**
|
|
254
|
-
* Where the parts of a value are: the shape of the value. A part is a typed document that the evaluator gets
|
|
255
|
-
* sealed. `of` is the type of a bare part: a part without an envelope gets this type from its position.
|
|
256
|
-
*
|
|
257
|
-
* - `none`: the value is data. It has no parts.
|
|
258
|
-
* - `term`: the value itself is one part.
|
|
259
|
-
* - `list`: the value is a list. Each item has the shape `item` (the default is a part).
|
|
260
|
-
* - `map`: the value is a record. Each field has the shape `item` (the default is a part).
|
|
261
|
-
* - `record`: the value is a record. Each named field has its shape. A list of names makes each named field a
|
|
262
|
-
* part. The other fields have the shape `rest` (the default is data). `required` names the fields that must be.
|
|
263
|
-
* - `deep`: each envelope at any depth of the value is a part, and the rest is data.
|
|
264
|
-
* - `text`, `number` and `one`: the value is data of that type. `one` names the values that it permits.
|
|
265
|
-
*
|
|
266
|
-
* A `term` with `address: true` is an address: a reference there gives what its path reaches, not the value. A
|
|
267
|
-
* `term` with `kinds` permits only a part whose type starts with one of the paths. A `record` with `closed: true`
|
|
268
|
-
* permits only its named fields. A `list` with `distinct: true` permits no two equal items.
|
|
269
|
-
*/
|
|
270
|
-
type Shape = {
|
|
271
|
-
readonly shape: "none";
|
|
272
|
-
} | {
|
|
273
|
-
readonly shape: "term";
|
|
274
|
-
readonly of?: string;
|
|
275
|
-
readonly address?: boolean;
|
|
276
|
-
readonly kinds?: readonly (readonly Key[])[];
|
|
277
|
-
} | {
|
|
278
|
-
readonly shape: "list";
|
|
279
|
-
readonly of?: string;
|
|
280
|
-
readonly item?: Shape;
|
|
281
|
-
readonly distinct?: boolean;
|
|
282
|
-
} | {
|
|
283
|
-
readonly shape: "map";
|
|
284
|
-
readonly of?: string;
|
|
285
|
-
readonly item?: Shape;
|
|
286
|
-
} | {
|
|
287
|
-
readonly shape: "record";
|
|
288
|
-
readonly fields: readonly string[] | Readonly<Record<string, Shape>>;
|
|
289
|
-
readonly of?: string;
|
|
290
|
-
readonly required?: readonly string[];
|
|
291
|
-
readonly rest?: Shape;
|
|
292
|
-
readonly closed?: boolean;
|
|
293
|
-
} | {
|
|
294
|
-
readonly shape: "deep";
|
|
295
|
-
readonly of?: string;
|
|
296
|
-
} | {
|
|
297
|
-
readonly shape: "text";
|
|
298
|
-
} | {
|
|
299
|
-
readonly shape: "number";
|
|
300
|
-
readonly whole?: boolean;
|
|
301
|
-
readonly min?: number;
|
|
302
|
-
readonly max?: number;
|
|
303
|
-
} | {
|
|
304
|
-
readonly shape: "one";
|
|
305
|
-
readonly values: readonly Json[];
|
|
306
|
-
};
|
|
307
|
-
/** The former name of `Shape`. */
|
|
308
|
-
type PartsSpec = Shape;
|
|
309
|
-
/**
|
|
310
|
-
* Where the names of a scope rule come from.
|
|
311
|
-
*
|
|
312
|
-
* - `fixed`: the names in the list.
|
|
313
|
-
* - `keysAt`: the keys of the record at this path of the value, for example the bindings of a `let`.
|
|
314
|
-
* - `listAt`: the texts of the list at this path of the value, for example the parameters of a `fn`.
|
|
315
|
-
* - `textAt`: the text at this path of the value, or `otherwise` when the value has no text there.
|
|
316
|
-
* - `headers`: the binding name (`name`) of each part that the rule covers.
|
|
317
|
-
*/
|
|
318
|
-
type NamesSource = {
|
|
319
|
-
readonly fixed: readonly string[];
|
|
320
|
-
} | {
|
|
321
|
-
readonly keysAt: readonly Key[];
|
|
322
|
-
} | {
|
|
323
|
-
readonly listAt: readonly Key[];
|
|
324
|
-
} | {
|
|
325
|
-
readonly textAt: readonly Key[];
|
|
326
|
-
readonly otherwise?: string;
|
|
327
|
-
} | {
|
|
328
|
-
readonly headers: true;
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* A scope rule of a kind: names that the kind binds, and the parts that see them. The static kit reads the rules,
|
|
332
|
-
* and the evaluator of the kind binds the same names when it evaluates the parts.
|
|
333
|
-
*/
|
|
334
|
-
interface ScopeRule {
|
|
335
|
-
readonly names: NamesSource;
|
|
336
|
-
/** The parts that see the names, as patterns of their paths in the value. The key `"*"` matches each key. */
|
|
337
|
-
readonly in: readonly (readonly Key[])[];
|
|
338
|
-
/** `true`: a part sees only the names of the parts before it, as in a sequence. */
|
|
339
|
-
readonly sequential?: boolean;
|
|
340
|
-
}
|
|
341
|
-
/** A kind gives the name of an evaluator for each verb, and the contract of its value. */
|
|
342
|
-
interface Kind {
|
|
343
|
-
readonly verbs: Readonly<Record<string, string>>;
|
|
344
|
-
/** Where the parts of the value are. The default is `none`. */
|
|
345
|
-
readonly parts?: Shape;
|
|
346
|
-
/** The names that the kind binds for its parts. */
|
|
347
|
-
readonly scope?: readonly ScopeRule[];
|
|
348
|
-
/** The side of the kind. A kind of the run side causes effects. The default is `derive`. */
|
|
349
|
-
readonly side?: Side;
|
|
350
|
-
/**
|
|
351
|
-
* The effects that a document of this kind can cause. It is a list of the kinds of the effects. The text
|
|
352
|
-
* `"type"` means that the kind of the effect is the type of the document itself, as for a call.
|
|
353
|
-
*/
|
|
354
|
-
readonly effects?: "type" | readonly string[];
|
|
355
|
-
/** One sentence that tells what the kind is. */
|
|
356
|
-
readonly summary?: string;
|
|
357
|
-
}
|
|
358
|
-
/** A namespace: a group of entries under one key of the world. `fallback` is the kind of each other key in it. */
|
|
359
|
-
interface Namespace {
|
|
360
|
-
readonly kinds: Readonly<Record<string, WorldEntry>>;
|
|
361
|
-
readonly fallback?: Kind;
|
|
362
|
-
}
|
|
363
|
-
/** An alias: a reference to another entry of the world. The lookup follows it (collapse). */
|
|
364
|
-
type Alias = {
|
|
365
|
-
readonly type: "ref";
|
|
366
|
-
readonly value: readonly Json[];
|
|
367
|
-
};
|
|
368
|
-
/** One entry of the world: a kind, a namespace, or an alias. */
|
|
369
|
-
type WorldEntry = Kind | Namespace | Alias;
|
|
370
|
-
/**
|
|
371
|
-
* A world holds the kinds and the defaults that answer the questions. `fallback` is the kind of each first key that
|
|
372
|
-
* the world does not have. A world with a fallback is open: each path that starts with an unknown key names a kind.
|
|
373
|
-
*/
|
|
374
|
-
interface World {
|
|
375
|
-
readonly kinds: Readonly<Record<string, WorldEntry>>;
|
|
376
|
-
readonly defaults: Readonly<Record<string, string>>;
|
|
377
|
-
readonly fallback?: Kind;
|
|
378
|
-
}
|
|
379
|
-
/** The result of a lookup of a type in the world. */
|
|
380
|
-
type Lookup = {
|
|
381
|
-
readonly ok: true;
|
|
382
|
-
readonly kind: Kind;
|
|
383
|
-
readonly path: readonly Key[];
|
|
384
|
-
readonly aliases: number;
|
|
385
|
-
} | {
|
|
386
|
-
readonly ok: false;
|
|
387
|
-
readonly reason: "unknown" | "cycle" | "not-a-kind" | "computed";
|
|
388
|
-
readonly path: readonly Key[];
|
|
389
|
-
};
|
|
390
|
-
/**
|
|
391
|
-
* This function tells if an entry of the world is a kind.
|
|
392
|
-
*
|
|
393
|
-
* @param entry - The entry.
|
|
394
|
-
* @returns `true` for a kind.
|
|
395
|
-
*/
|
|
396
|
-
export declare function isKind(entry: WorldEntry | undefined): entry is Kind;
|
|
397
|
-
/**
|
|
398
|
-
* This function tells if an entry of the world is an alias.
|
|
399
|
-
*
|
|
400
|
-
* @param entry - The entry.
|
|
401
|
-
* @returns `true` for an alias.
|
|
402
|
-
*/
|
|
403
|
-
export declare function isAlias(entry: WorldEntry | undefined): entry is Alias;
|
|
404
|
-
/**
|
|
405
|
-
* This function tells if an entry of the world is a namespace.
|
|
406
|
-
*
|
|
407
|
-
* @param entry - The entry.
|
|
408
|
-
* @returns `true` for a namespace.
|
|
409
|
-
*/
|
|
410
|
-
export declare function isNamespace(entry: WorldEntry | undefined): entry is Namespace;
|
|
411
|
-
/**
|
|
412
|
-
* This function finds the kind that a type names. It walks the path from the root of the world, one key at a
|
|
413
|
-
* time. An alias on the way is followed until a kind answers (collapse). A cycle of aliases stops the lookup. In a
|
|
414
|
-
* namespace with a fallback, a key that the namespace does not have gets the fallback kind. In an open world, a first
|
|
415
|
-
* key that the world does not have gets the fallback kind of the world.
|
|
416
|
-
*
|
|
417
|
-
* @param world - The world.
|
|
418
|
-
* @param type - The reference to the type.
|
|
419
|
-
* @returns The kind and the path of the kind after each alias, or the reason of a failure.
|
|
420
|
-
*/
|
|
421
|
-
export declare function lookupKind(world: World, type: TypeRef): Lookup;
|
|
422
|
-
/**
|
|
423
|
-
* This function gives the entries of a world as a JSON record, so that a reference can walk it. A kind is a
|
|
424
|
-
* record with its verbs, an alias is a reference document, and a namespace is a record of its entries.
|
|
425
|
-
*
|
|
426
|
-
* @param entries - The entries.
|
|
427
|
-
* @returns The JSON form.
|
|
428
|
-
*/
|
|
429
|
-
export declare function entriesAsJson(entries: Readonly<Record<string, WorldEntry>>): Json;
|
|
430
|
-
/**
|
|
431
|
-
* This function makes the document of a kind, so that a view can draw it as each other document.
|
|
432
|
-
*
|
|
433
|
-
* @param name - The name of the kind.
|
|
434
|
-
* @param kind - The kind.
|
|
435
|
-
* @returns The document of type `kind`.
|
|
436
|
-
*/
|
|
437
|
-
export declare function kindDocument(name: string, kind: Kind): Envelope;
|
|
438
|
-
/**
|
|
439
|
-
* This function tells if a JSON value is the record of a kind.
|
|
440
|
-
*
|
|
441
|
-
* @param value - The value.
|
|
442
|
-
* @returns `true` when the value has verbs.
|
|
443
|
-
*/
|
|
444
|
-
export declare function looksLikeKind(value: unknown): boolean;
|
|
445
|
-
//#endregion
|
|
446
|
-
//#region src/ladder.d.ts
|
|
447
|
-
/** The rungs of the ladder, in the order that a question visits them. */
|
|
448
|
-
export declare const RUNGS: readonly ["own", "kind", "default"];
|
|
449
|
-
/** One rung of the ladder. */
|
|
450
|
-
type Rung = (typeof RUNGS)[number];
|
|
451
|
-
/** The place where the ladder found the type. */
|
|
452
|
-
type KindSource = "document" | "container";
|
|
453
|
-
/**
|
|
454
|
-
* The outcome of one rung.
|
|
455
|
-
*
|
|
456
|
-
* - `answers`: the rung gives an evaluator.
|
|
457
|
-
* - `no-entry`: the rung has nothing for this verb, thus the question goes to the next rung.
|
|
458
|
-
* - `skipped`: the rung does not apply, because no type is known.
|
|
459
|
-
* - `unknown-kind`: the type is not a kind of the world. The question stops.
|
|
460
|
-
*/
|
|
461
|
-
type Outcome = "answers" | "no-entry" | "skipped" | "unknown-kind";
|
|
462
|
-
/** The record of one rung that a question visited. */
|
|
463
|
-
interface Step {
|
|
464
|
-
readonly rung: Rung;
|
|
465
|
-
readonly outcome: Outcome;
|
|
466
|
-
/** The evaluator, when the outcome is `answers`. */
|
|
467
|
-
readonly evaluator?: string;
|
|
468
|
-
/** The text of the type, at the kind rung. */
|
|
469
|
-
readonly kind?: string;
|
|
470
|
-
/** The place of the type, at the kind rung. */
|
|
471
|
-
readonly source?: KindSource;
|
|
472
|
-
}
|
|
473
|
-
/** The answer to a question. It keeps the record of each rung that the question visited. */
|
|
474
|
-
interface Answer {
|
|
475
|
-
readonly verb: string;
|
|
476
|
-
/** The evaluator that answers. A question that stops with an error has no evaluator. */
|
|
477
|
-
readonly evaluator?: string;
|
|
478
|
-
/** The rung that answered. */
|
|
479
|
-
readonly rung?: Rung;
|
|
480
|
-
/** The reason when no rung answers. */
|
|
481
|
-
readonly error?: "unknown-kind" | "no-answer";
|
|
482
|
-
readonly steps: readonly Step[];
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* The header that the ladder reads: the type and the own entries. An envelope is a header. A bare value has an
|
|
486
|
-
* empty header, and its position can declare its type.
|
|
487
|
-
*/
|
|
488
|
-
interface Header {
|
|
489
|
-
readonly type?: TypeRef;
|
|
490
|
-
readonly own?: Readonly<Record<string, string>>;
|
|
491
|
-
}
|
|
492
|
-
/** The options of a question. */
|
|
493
|
-
interface AskOptions {
|
|
494
|
-
/** The type that the position of a bare value declares. The type of an envelope wins. */
|
|
495
|
-
readonly declaredType?: string;
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* This function finds the kind that a type names, and follows each alias. It gives `undefined` for an unknown
|
|
499
|
-
* type.
|
|
500
|
-
*
|
|
501
|
-
* @param world - The world.
|
|
502
|
-
* @param type - The reference to the type.
|
|
503
|
-
* @returns The kind, or `undefined`.
|
|
504
|
-
*/
|
|
505
|
-
export declare function kindOf(world: World, type: TypeRef): Kind | undefined;
|
|
506
|
-
/**
|
|
507
|
-
* This function finds a kind by a text type. It is the same as `kindOf` for a one-key reference.
|
|
508
|
-
*
|
|
509
|
-
* @param world - The world.
|
|
510
|
-
* @param name - The text of the type.
|
|
511
|
-
* @returns The kind, or `undefined`.
|
|
512
|
-
*/
|
|
513
|
-
export declare function kindNamed(world: World, name: TypeRef): Kind | undefined;
|
|
514
|
-
/**
|
|
515
|
-
* This function asks a document a question, and gives the evaluator that answers it.
|
|
516
|
-
*
|
|
517
|
-
* The question visits the rungs in order: the own entry of the envelope, then its kind, then the default of the
|
|
518
|
-
* world. The type comes from the envelope, or else from the type that the position declares. The type is a
|
|
519
|
-
* reference into the world. The ladder does not guess a type from the shape of a value.
|
|
520
|
-
*
|
|
521
|
-
* @param world - The kinds and the defaults.
|
|
522
|
-
* @param doc - The header of the document: an envelope, or `{}` for a bare value.
|
|
523
|
-
* @param verb - The verb of the question, for example `eval` or `view`.
|
|
524
|
-
* @param options - The type that the position declares.
|
|
525
|
-
* @returns The answer, with the record of each rung that the question visited.
|
|
526
|
-
*/
|
|
527
|
-
export declare function ask(world: World, doc: Header, verb: string, options?: AskOptions): Answer;
|
|
528
|
-
//#endregion
|
|
529
250
|
//#region src/deref.d.ts
|
|
530
251
|
/**
|
|
531
252
|
* The brand of a host thing: an object of the host that answers the steps of a path itself. The brand is a
|
|
@@ -674,74 +395,382 @@ interface ResolveOptions {
|
|
|
674
395
|
readonly hops?: boolean;
|
|
675
396
|
}
|
|
676
397
|
/**
|
|
677
|
-
* This function answers one step of a path on a thing, through the ladder of the verb `deref`. A host thing
|
|
678
|
-
* answers for itself (own). A document asks its own entry, then its kind. The default goes into the value: an own
|
|
679
|
-
* field of an object, or an item of a list.
|
|
398
|
+
* This function answers one step of a path on a thing, through the ladder of the verb `deref`. A host thing
|
|
399
|
+
* answers for itself (own). A document asks its own entry, then its kind. The default goes into the value: an own
|
|
400
|
+
* field of an object, or an item of a list.
|
|
401
|
+
*
|
|
402
|
+
* @param nav - The world and the code of the evaluators.
|
|
403
|
+
* @param thing - The thing that the path reached.
|
|
404
|
+
* @param key - The key of the step.
|
|
405
|
+
* @returns What the step reaches and the rung that answered, or `undefined` when it reaches nothing.
|
|
406
|
+
*/
|
|
407
|
+
export declare function derefStep(nav: Navigator, thing: Thing, key: Key): {
|
|
408
|
+
readonly thing: Thing;
|
|
409
|
+
readonly by: HopBy;
|
|
410
|
+
} | undefined;
|
|
411
|
+
/**
|
|
412
|
+
* This function tells if a thing is a reference document: an envelope of the type `ref` with a list for its path.
|
|
413
|
+
*
|
|
414
|
+
* @param thing - The thing.
|
|
415
|
+
* @returns `true` for a reference document.
|
|
416
|
+
*/
|
|
417
|
+
export declare function isRef(thing: unknown): thing is Envelope & {
|
|
418
|
+
readonly value: readonly Json[];
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* This function makes the thing of the root `world`: the entries of the world as JSON. An alias is a reference
|
|
422
|
+
* document in it, thus a walk through the world follows each alias (collapse). The thing of a world is made one
|
|
423
|
+
* time.
|
|
424
|
+
*
|
|
425
|
+
* @param world - The world.
|
|
426
|
+
* @returns The thing.
|
|
427
|
+
*/
|
|
428
|
+
export declare function worldThing(world: World): Json;
|
|
429
|
+
/**
|
|
430
|
+
* This function makes a context. The world comes from the navigator when the call gives none.
|
|
431
|
+
*
|
|
432
|
+
* @param parts - The roots to set.
|
|
433
|
+
* @returns The context.
|
|
434
|
+
*/
|
|
435
|
+
export declare function context(parts?: Partial<Context>): Context;
|
|
436
|
+
/**
|
|
437
|
+
* This function resolves a path from a context, and records each hop.
|
|
438
|
+
*
|
|
439
|
+
* 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
|
|
440
|
+
* of the verb `deref` on the thing that the path reached. A step document is evaluated by the walker of its kind,
|
|
441
|
+
* with the thing that the path reached. After each hop, a reference document is followed until the path reaches
|
|
442
|
+
* something else (collapse), except in a plain navigation.
|
|
443
|
+
*
|
|
444
|
+
* The codes of a failure:
|
|
445
|
+
*
|
|
446
|
+
* - `#REF!`: the path has no root, or a root that is not open here.
|
|
447
|
+
* - `#NAME?`: the root `names` has no such name.
|
|
448
|
+
* - `#N/A`: a step reaches nothing.
|
|
449
|
+
* - `#STEP?`: a step is not a key and not a step document.
|
|
450
|
+
* - `#CYCLE!`: the references form a cycle.
|
|
451
|
+
*
|
|
452
|
+
* @param nav - The world and the code of the evaluators.
|
|
453
|
+
* @param ctx - The context.
|
|
454
|
+
* @param path - The steps.
|
|
455
|
+
* @param options - `hops: false` does not record the hops.
|
|
456
|
+
* @returns What the path reached and each hop, or an error.
|
|
457
|
+
*/
|
|
458
|
+
export declare function resolve(nav: Navigator, ctx: Context, path: readonly unknown[], options?: ResolveOptions): Resolution;
|
|
459
|
+
/**
|
|
460
|
+
* This function gives the value of a thing: the value that a host thing gives, or else the thing itself.
|
|
461
|
+
*
|
|
462
|
+
* @param thing - The thing.
|
|
463
|
+
* @returns The value.
|
|
464
|
+
*/
|
|
465
|
+
export declare function valueOfThing(thing: Thing): unknown;
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/world.d.ts
|
|
468
|
+
/** The two sides of evaluation. `derive` is pure. `run` causes effects in order. */
|
|
469
|
+
type Side = "derive" | "run";
|
|
470
|
+
/**
|
|
471
|
+
* Where the parts of a value are: the shape of the value. A part is a typed document that the evaluator gets
|
|
472
|
+
* sealed. `of` is the type of a bare part: a part without an envelope gets this type from its position.
|
|
473
|
+
*
|
|
474
|
+
* - `none`: the value is data. It has no parts.
|
|
475
|
+
* - `term`: the value itself is one part.
|
|
476
|
+
* - `list`: the value is a list. Each item has the shape `item` (the default is a part).
|
|
477
|
+
* - `map`: the value is a record. Each field has the shape `item` (the default is a part).
|
|
478
|
+
* - `record`: the value is a record. Each named field has its shape. A list of names makes each named field a
|
|
479
|
+
* part. The other fields have the shape `rest` (the default is data). `required` names the fields that must be.
|
|
480
|
+
* - `deep`: each envelope at any depth of the value is a part, and the rest is data.
|
|
481
|
+
* - `text`, `number` and `one`: the value is data of that type. `one` names the values that it permits.
|
|
482
|
+
*
|
|
483
|
+
* A `term` with `address: true` is an address: a reference there gives what its path reaches, not the value. A
|
|
484
|
+
* `term` with `kinds` permits only a part whose type starts with one of the paths. A `record` with `closed: true`
|
|
485
|
+
* permits only its named fields. A `list` with `distinct: true` permits no two equal items.
|
|
486
|
+
*/
|
|
487
|
+
type Shape = {
|
|
488
|
+
readonly shape: "none";
|
|
489
|
+
} | {
|
|
490
|
+
readonly shape: "term";
|
|
491
|
+
readonly of?: string;
|
|
492
|
+
readonly address?: boolean;
|
|
493
|
+
readonly kinds?: readonly (readonly Key[])[];
|
|
494
|
+
} | {
|
|
495
|
+
readonly shape: "list";
|
|
496
|
+
readonly of?: string;
|
|
497
|
+
readonly item?: Shape;
|
|
498
|
+
readonly distinct?: boolean;
|
|
499
|
+
} | {
|
|
500
|
+
readonly shape: "map";
|
|
501
|
+
readonly of?: string;
|
|
502
|
+
readonly item?: Shape;
|
|
503
|
+
} | {
|
|
504
|
+
readonly shape: "record";
|
|
505
|
+
readonly fields: readonly string[] | Readonly<Record<string, Shape>>;
|
|
506
|
+
readonly of?: string;
|
|
507
|
+
readonly required?: readonly string[];
|
|
508
|
+
readonly rest?: Shape;
|
|
509
|
+
readonly closed?: boolean;
|
|
510
|
+
} | {
|
|
511
|
+
readonly shape: "deep";
|
|
512
|
+
readonly of?: string;
|
|
513
|
+
} | {
|
|
514
|
+
readonly shape: "text";
|
|
515
|
+
} | {
|
|
516
|
+
readonly shape: "number";
|
|
517
|
+
readonly whole?: boolean;
|
|
518
|
+
readonly min?: number;
|
|
519
|
+
readonly max?: number;
|
|
520
|
+
} | {
|
|
521
|
+
readonly shape: "one";
|
|
522
|
+
readonly values: readonly Json[];
|
|
523
|
+
};
|
|
524
|
+
/** The former name of `Shape`. */
|
|
525
|
+
type PartsSpec = Shape;
|
|
526
|
+
/**
|
|
527
|
+
* Where the names of a scope rule come from.
|
|
528
|
+
*
|
|
529
|
+
* - `fixed`: the names in the list.
|
|
530
|
+
* - `keysAt`: the keys of the record at this path of the value, for example the bindings of a `let`.
|
|
531
|
+
* - `listAt`: the texts of the list at this path of the value, for example the parameters of a `fn`.
|
|
532
|
+
* - `textAt`: the text at this path of the value, or `otherwise` when the value has no text there.
|
|
533
|
+
* - `headers`: the binding name (`name`) of each part that the rule covers.
|
|
534
|
+
*/
|
|
535
|
+
type NamesSource = {
|
|
536
|
+
readonly fixed: readonly string[];
|
|
537
|
+
} | {
|
|
538
|
+
readonly keysAt: readonly Key[];
|
|
539
|
+
} | {
|
|
540
|
+
readonly listAt: readonly Key[];
|
|
541
|
+
} | {
|
|
542
|
+
readonly textAt: readonly Key[];
|
|
543
|
+
readonly otherwise?: string;
|
|
544
|
+
} | {
|
|
545
|
+
readonly headers: true;
|
|
546
|
+
};
|
|
547
|
+
/**
|
|
548
|
+
* A scope rule of a kind: names that the kind binds, and the parts that see them. The static kit reads the rules,
|
|
549
|
+
* and the evaluator of the kind binds the same names when it evaluates the parts.
|
|
550
|
+
*/
|
|
551
|
+
interface ScopeRule {
|
|
552
|
+
readonly names: NamesSource;
|
|
553
|
+
/** The parts that see the names, as patterns of their paths in the value. The key `"*"` matches each key. */
|
|
554
|
+
readonly in: readonly (readonly Key[])[];
|
|
555
|
+
/** `true`: a part sees only the names of the parts before it, as in a sequence. */
|
|
556
|
+
readonly sequential?: boolean;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* A capability rule of a kind: what the kind gives some of its parts from the capabilities of its document. A rule
|
|
560
|
+
* only narrows. A part does not get a capability that its document does not have (CAP.NARROW).
|
|
561
|
+
*
|
|
562
|
+
* - `same`: the parts get the capabilities of the document. This is the default.
|
|
563
|
+
* - `mask`: the parts get no capabilities, as the part of `pure`.
|
|
564
|
+
* - `only`: the parts get only the effects that the capabilities of the document and the list `caps` both permit.
|
|
565
|
+
*
|
|
566
|
+
* `in` names the parts that the rule covers, as patterns of their paths in the value. The key `"*"` matches each
|
|
567
|
+
* key. A rule without `in` covers each part.
|
|
568
|
+
*/
|
|
569
|
+
type CapsRule = {
|
|
570
|
+
readonly rule: "same";
|
|
571
|
+
readonly in?: readonly (readonly Key[])[];
|
|
572
|
+
} | {
|
|
573
|
+
readonly rule: "mask";
|
|
574
|
+
readonly in?: readonly (readonly Key[])[];
|
|
575
|
+
} | {
|
|
576
|
+
readonly rule: "only";
|
|
577
|
+
readonly caps: readonly Cap[];
|
|
578
|
+
readonly in?: readonly (readonly Key[])[];
|
|
579
|
+
};
|
|
580
|
+
/** A kind gives the name of an evaluator for each verb, and the contract of its value. */
|
|
581
|
+
interface Kind {
|
|
582
|
+
readonly verbs: Readonly<Record<string, string>>;
|
|
583
|
+
/** Where the parts of the value are. The default is `none`. */
|
|
584
|
+
readonly parts?: Shape;
|
|
585
|
+
/** The names that the kind binds for its parts. */
|
|
586
|
+
readonly scope?: readonly ScopeRule[];
|
|
587
|
+
/**
|
|
588
|
+
* The capabilities that the kind gives its parts, as rules. A part that no rule covers gets the capabilities of
|
|
589
|
+
* the document. A part that several rules cover gets only what each rule permits. The static kit reads the rules,
|
|
590
|
+
* and the kernel narrows the context of each part by them. Thus an evaluator does not narrow the capabilities
|
|
591
|
+
* itself.
|
|
592
|
+
*/
|
|
593
|
+
readonly caps?: readonly CapsRule[];
|
|
594
|
+
/** The side of the kind. A kind of the run side causes effects. The default is `derive`. */
|
|
595
|
+
readonly side?: Side;
|
|
596
|
+
/**
|
|
597
|
+
* The effects that a document of this kind can cause. It is a list of the kinds of the effects. The text
|
|
598
|
+
* `"type"` means that the kind of the effect is the type of the document itself, as for a call.
|
|
599
|
+
*/
|
|
600
|
+
readonly effects?: "type" | readonly string[];
|
|
601
|
+
/** One sentence that tells what the kind is. */
|
|
602
|
+
readonly summary?: string;
|
|
603
|
+
}
|
|
604
|
+
/** A namespace: a group of entries under one key of the world. `fallback` is the kind of each other key in it. */
|
|
605
|
+
interface Namespace {
|
|
606
|
+
readonly kinds: Readonly<Record<string, WorldEntry>>;
|
|
607
|
+
readonly fallback?: Kind;
|
|
608
|
+
}
|
|
609
|
+
/** An alias: a reference to another entry of the world. The lookup follows it (collapse). */
|
|
610
|
+
type Alias = {
|
|
611
|
+
readonly type: "ref";
|
|
612
|
+
readonly value: readonly Json[];
|
|
613
|
+
};
|
|
614
|
+
/** One entry of the world: a kind, a namespace, or an alias. */
|
|
615
|
+
type WorldEntry = Kind | Namespace | Alias;
|
|
616
|
+
/**
|
|
617
|
+
* A world holds the kinds and the defaults that answer the questions. `fallback` is the kind of each first key that
|
|
618
|
+
* the world does not have. A world with a fallback is open: each path that starts with an unknown key names a kind.
|
|
619
|
+
*/
|
|
620
|
+
interface World {
|
|
621
|
+
readonly kinds: Readonly<Record<string, WorldEntry>>;
|
|
622
|
+
readonly defaults: Readonly<Record<string, string>>;
|
|
623
|
+
readonly fallback?: Kind;
|
|
624
|
+
}
|
|
625
|
+
/** The result of a lookup of a type in the world. */
|
|
626
|
+
type Lookup = {
|
|
627
|
+
readonly ok: true;
|
|
628
|
+
readonly kind: Kind;
|
|
629
|
+
readonly path: readonly Key[];
|
|
630
|
+
readonly aliases: number;
|
|
631
|
+
} | {
|
|
632
|
+
readonly ok: false;
|
|
633
|
+
readonly reason: "unknown" | "cycle" | "not-a-kind" | "computed";
|
|
634
|
+
readonly path: readonly Key[];
|
|
635
|
+
};
|
|
636
|
+
/**
|
|
637
|
+
* This function tells if an entry of the world is a kind.
|
|
680
638
|
*
|
|
681
|
-
* @param
|
|
682
|
-
* @
|
|
683
|
-
* @param key - The key of the step.
|
|
684
|
-
* @returns What the step reaches and the rung that answered, or `undefined` when it reaches nothing.
|
|
639
|
+
* @param entry - The entry.
|
|
640
|
+
* @returns `true` for a kind.
|
|
685
641
|
*/
|
|
686
|
-
export declare function
|
|
687
|
-
readonly thing: Thing;
|
|
688
|
-
readonly by: HopBy;
|
|
689
|
-
} | undefined;
|
|
642
|
+
export declare function isKind(entry: WorldEntry | undefined): entry is Kind;
|
|
690
643
|
/**
|
|
691
|
-
* This function tells if
|
|
644
|
+
* This function tells if an entry of the world is an alias.
|
|
692
645
|
*
|
|
693
|
-
* @param
|
|
694
|
-
* @returns `true` for
|
|
646
|
+
* @param entry - The entry.
|
|
647
|
+
* @returns `true` for an alias.
|
|
695
648
|
*/
|
|
696
|
-
export declare function
|
|
697
|
-
readonly value: readonly Json[];
|
|
698
|
-
};
|
|
649
|
+
export declare function isAlias(entry: WorldEntry | undefined): entry is Alias;
|
|
699
650
|
/**
|
|
700
|
-
* This function
|
|
701
|
-
*
|
|
702
|
-
*
|
|
651
|
+
* This function tells if an entry of the world is a namespace.
|
|
652
|
+
*
|
|
653
|
+
* @param entry - The entry.
|
|
654
|
+
* @returns `true` for a namespace.
|
|
655
|
+
*/
|
|
656
|
+
export declare function isNamespace(entry: WorldEntry | undefined): entry is Namespace;
|
|
657
|
+
/**
|
|
658
|
+
* This function finds the kind that a type names. It walks the path from the root of the world, one key at a
|
|
659
|
+
* time. An alias on the way is followed until a kind answers (collapse). A cycle of aliases stops the lookup. In a
|
|
660
|
+
* namespace with a fallback, a key that the namespace does not have gets the fallback kind. In an open world, a first
|
|
661
|
+
* key that the world does not have gets the fallback kind of the world.
|
|
703
662
|
*
|
|
704
663
|
* @param world - The world.
|
|
705
|
-
* @
|
|
664
|
+
* @param type - The reference to the type.
|
|
665
|
+
* @returns The kind and the path of the kind after each alias, or the reason of a failure.
|
|
706
666
|
*/
|
|
707
|
-
export declare function
|
|
667
|
+
export declare function lookupKind(world: World, type: TypeRef): Lookup;
|
|
708
668
|
/**
|
|
709
|
-
* This function
|
|
669
|
+
* This function gives the entries of a world as a JSON record, so that a reference can walk it. A kind is a
|
|
670
|
+
* record with its verbs, an alias is a reference document, and a namespace is a record of its entries.
|
|
710
671
|
*
|
|
711
|
-
* @param
|
|
712
|
-
* @returns The
|
|
672
|
+
* @param entries - The entries.
|
|
673
|
+
* @returns The JSON form.
|
|
713
674
|
*/
|
|
714
|
-
export declare function
|
|
675
|
+
export declare function entriesAsJson(entries: Readonly<Record<string, WorldEntry>>): Json;
|
|
715
676
|
/**
|
|
716
|
-
* This function
|
|
677
|
+
* This function makes the document of a kind, so that a view can draw it as each other document.
|
|
717
678
|
*
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
721
|
-
|
|
679
|
+
* @param name - The name of the kind.
|
|
680
|
+
* @param kind - The kind.
|
|
681
|
+
* @returns The document of type `kind`.
|
|
682
|
+
*/
|
|
683
|
+
export declare function kindDocument(name: string, kind: Kind): Envelope;
|
|
684
|
+
/**
|
|
685
|
+
* This function tells if a JSON value is the record of a kind.
|
|
722
686
|
*
|
|
723
|
-
*
|
|
687
|
+
* @param value - The value.
|
|
688
|
+
* @returns `true` when the value has verbs.
|
|
689
|
+
*/
|
|
690
|
+
export declare function looksLikeKind(value: unknown): boolean;
|
|
691
|
+
//#endregion
|
|
692
|
+
//#region src/ladder.d.ts
|
|
693
|
+
/** The rungs of the ladder, in the order that a question visits them. */
|
|
694
|
+
export declare const RUNGS: readonly ["own", "kind", "default"];
|
|
695
|
+
/** One rung of the ladder. */
|
|
696
|
+
type Rung = (typeof RUNGS)[number];
|
|
697
|
+
/** The place where the ladder found the type. */
|
|
698
|
+
type KindSource = "document" | "container";
|
|
699
|
+
/**
|
|
700
|
+
* The outcome of one rung.
|
|
724
701
|
*
|
|
725
|
-
* -
|
|
726
|
-
* -
|
|
727
|
-
* -
|
|
728
|
-
* -
|
|
729
|
-
|
|
702
|
+
* - `answers`: the rung gives an evaluator.
|
|
703
|
+
* - `no-entry`: the rung has nothing for this verb, thus the question goes to the next rung.
|
|
704
|
+
* - `skipped`: the rung does not apply, because no type is known.
|
|
705
|
+
* - `unknown-kind`: the type is not a kind of the world. The question stops.
|
|
706
|
+
*/
|
|
707
|
+
type Outcome = "answers" | "no-entry" | "skipped" | "unknown-kind";
|
|
708
|
+
/** The record of one rung that a question visited. */
|
|
709
|
+
interface Step {
|
|
710
|
+
readonly rung: Rung;
|
|
711
|
+
readonly outcome: Outcome;
|
|
712
|
+
/** The evaluator, when the outcome is `answers`. */
|
|
713
|
+
readonly evaluator?: string;
|
|
714
|
+
/** The text of the type, at the kind rung. */
|
|
715
|
+
readonly kind?: string;
|
|
716
|
+
/** The place of the type, at the kind rung. */
|
|
717
|
+
readonly source?: KindSource;
|
|
718
|
+
}
|
|
719
|
+
/** The answer to a question. It keeps the record of each rung that the question visited. */
|
|
720
|
+
interface Answer {
|
|
721
|
+
readonly verb: string;
|
|
722
|
+
/** The evaluator that answers. A question that stops with an error has no evaluator. */
|
|
723
|
+
readonly evaluator?: string;
|
|
724
|
+
/** The rung that answered. */
|
|
725
|
+
readonly rung?: Rung;
|
|
726
|
+
/** The reason when no rung answers. */
|
|
727
|
+
readonly error?: "unknown-kind" | "no-answer";
|
|
728
|
+
readonly steps: readonly Step[];
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* The header that the ladder reads: the type and the own entries. An envelope is a header. A bare value has an
|
|
732
|
+
* empty header, and its position can declare its type.
|
|
733
|
+
*/
|
|
734
|
+
interface Header {
|
|
735
|
+
readonly type?: TypeRef;
|
|
736
|
+
readonly own?: Readonly<Record<string, string>>;
|
|
737
|
+
}
|
|
738
|
+
/** The options of a question. */
|
|
739
|
+
interface AskOptions {
|
|
740
|
+
/** The type that the position of a bare value declares. The type of an envelope wins. */
|
|
741
|
+
readonly declaredType?: string;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* This function finds the kind that a type names, and follows each alias. It gives `undefined` for an unknown
|
|
745
|
+
* type.
|
|
730
746
|
*
|
|
731
|
-
* @param
|
|
732
|
-
* @param
|
|
733
|
-
* @
|
|
734
|
-
* @param options - `hops: false` does not record the hops.
|
|
735
|
-
* @returns What the path reached and each hop, or an error.
|
|
747
|
+
* @param world - The world.
|
|
748
|
+
* @param type - The reference to the type.
|
|
749
|
+
* @returns The kind, or `undefined`.
|
|
736
750
|
*/
|
|
737
|
-
export declare function
|
|
751
|
+
export declare function kindOf(world: World, type: TypeRef): Kind | undefined;
|
|
738
752
|
/**
|
|
739
|
-
* This function
|
|
753
|
+
* This function finds a kind by a text type. It is the same as `kindOf` for a one-key reference.
|
|
740
754
|
*
|
|
741
|
-
* @param
|
|
742
|
-
* @
|
|
755
|
+
* @param world - The world.
|
|
756
|
+
* @param name - The text of the type.
|
|
757
|
+
* @returns The kind, or `undefined`.
|
|
743
758
|
*/
|
|
744
|
-
export declare function
|
|
759
|
+
export declare function kindNamed(world: World, name: TypeRef): Kind | undefined;
|
|
760
|
+
/**
|
|
761
|
+
* This function asks a document a question, and gives the evaluator that answers it.
|
|
762
|
+
*
|
|
763
|
+
* The question visits the rungs in order: the own entry of the envelope, then its kind, then the default of the
|
|
764
|
+
* world. The type comes from the envelope, or else from the type that the position declares. The type is a
|
|
765
|
+
* reference into the world. The ladder does not guess a type from the shape of a value.
|
|
766
|
+
*
|
|
767
|
+
* @param world - The kinds and the defaults.
|
|
768
|
+
* @param doc - The header of the document: an envelope, or `{}` for a bare value.
|
|
769
|
+
* @param verb - The verb of the question, for example `eval` or `view`.
|
|
770
|
+
* @param options - The type that the position declares.
|
|
771
|
+
* @returns The answer, with the record of each rung that the question visited.
|
|
772
|
+
*/
|
|
773
|
+
export declare function ask(world: World, doc: Header, verb: string, options?: AskOptions): Answer;
|
|
745
774
|
//#endregion
|
|
746
775
|
//#region src/classify.d.ts
|
|
747
776
|
/** A shape proposes a kind for each document that has all of its fields. */
|
|
@@ -866,6 +895,25 @@ export declare function permits(caps: readonly Cap[], kind: Cap): boolean;
|
|
|
866
895
|
* @returns The context of the part.
|
|
867
896
|
*/
|
|
868
897
|
export declare function narrow(parent: Context, next: Context): Context;
|
|
898
|
+
/**
|
|
899
|
+
* This function gives the capabilities that two lists both permit. An effect is permitted by the result when each
|
|
900
|
+
* list permits it. When the list `b` permits each capability of `a`, the result is the list `a` itself.
|
|
901
|
+
*
|
|
902
|
+
* @param a - The first list, for example the capabilities of a document.
|
|
903
|
+
* @param b - The second list, for example the list of a rule `only`.
|
|
904
|
+
* @returns The capabilities that both lists permit.
|
|
905
|
+
*/
|
|
906
|
+
export declare function intersectCaps(a: readonly Cap[], b: readonly Cap[]): readonly Cap[];
|
|
907
|
+
/**
|
|
908
|
+
* This function gives the capabilities that a kind gives one of its parts, by the capability rules of its contract.
|
|
909
|
+
* The kernel and the static kit both use it, thus a run and a check narrow the same way.
|
|
910
|
+
*
|
|
911
|
+
* @param rules - The capability rules of the kind (`Kind.caps`).
|
|
912
|
+
* @param path - The path of the part in the value of the document.
|
|
913
|
+
* @param caps - The capabilities of the document.
|
|
914
|
+
* @returns The capabilities of the part: the same list or a smaller one.
|
|
915
|
+
*/
|
|
916
|
+
export declare function partCaps(rules: readonly CapsRule[] | undefined, path: readonly Key[], caps: readonly Cap[]): readonly Cap[];
|
|
869
917
|
/**
|
|
870
918
|
* The steps of an evaluation that can wait. It yields a promise only when the host makes it wait. A runner takes the
|
|
871
919
|
* result of a part with `yield*`, thus a run goes on at once until an effect waits. A runner does not yield a
|
|
@@ -1486,6 +1534,11 @@ interface DocVisit {
|
|
|
1486
1534
|
readonly later: ReadonlySet<string>;
|
|
1487
1535
|
/** `true` when the position of the document declares an address: a reference there is not a read of a value. */
|
|
1488
1536
|
readonly address?: true | undefined;
|
|
1537
|
+
/**
|
|
1538
|
+
* The capabilities of the document: the capabilities of the walk, narrowed by the capability rules of the kinds
|
|
1539
|
+
* around it (`Kind.caps`). A walk without capabilities gives none here.
|
|
1540
|
+
*/
|
|
1541
|
+
readonly caps?: readonly Cap[] | undefined;
|
|
1489
1542
|
}
|
|
1490
1543
|
/** A position that a walk cannot read as a document. */
|
|
1491
1544
|
interface WalkProblem {
|
|
@@ -1502,6 +1555,8 @@ interface WalkOptions {
|
|
|
1502
1555
|
readonly declaredType?: string;
|
|
1503
1556
|
/** The names that the host binds at the root. */
|
|
1504
1557
|
readonly names?: readonly string[];
|
|
1558
|
+
/** The capabilities at the root. With them, each visit gets the capabilities of its document. */
|
|
1559
|
+
readonly caps?: readonly Cap[];
|
|
1505
1560
|
/**
|
|
1506
1561
|
* This function gets each position that is not a document.
|
|
1507
1562
|
*
|
|
@@ -1511,14 +1566,15 @@ interface WalkOptions {
|
|
|
1511
1566
|
}
|
|
1512
1567
|
/**
|
|
1513
1568
|
* This function visits each document of a document: the root and each part at each depth, by the contracts of the
|
|
1514
|
-
* kinds. A part of a kind that the world does not have is not visited.
|
|
1569
|
+
* kinds. A part of a kind that the world does not have is not visited. With capabilities in the options, the walk
|
|
1570
|
+
* narrows them for each part by the rules of its kind, as a run does. The walk uses no stack of the host for the
|
|
1515
1571
|
* depth, thus a deep document cannot overflow it. The time and the memory of a walk are linear in the size of the
|
|
1516
1572
|
* document. A visit makes the keys of its place and of its path only when a reader asks for them.
|
|
1517
1573
|
*
|
|
1518
1574
|
* @param world - The world of the kinds.
|
|
1519
1575
|
* @param doc - The document, as JSON.
|
|
1520
1576
|
* @param visit - The function that gets each document. It gives `"skip"` to not visit the parts of a document.
|
|
1521
|
-
* @param options - The type of a bare root value, the names
|
|
1577
|
+
* @param options - The type of a bare root value, the names, the capabilities and a function for the problems.
|
|
1522
1578
|
*/
|
|
1523
1579
|
export declare function walk(world: World, doc: unknown, visit: (visit: DocVisit) => void | "skip", options?: WalkOptions): void;
|
|
1524
1580
|
/** One reference of a document. */
|
|
@@ -1574,7 +1630,10 @@ interface CheckOptions {
|
|
|
1574
1630
|
readonly declaredType?: string;
|
|
1575
1631
|
/** The names that the host binds at the root. `"any"` does not check the names. The default is no names. */
|
|
1576
1632
|
readonly names?: readonly string[] | "any";
|
|
1577
|
-
/**
|
|
1633
|
+
/**
|
|
1634
|
+
* The capabilities at the root. Without them, the check does not check the effects. The check narrows them for
|
|
1635
|
+
* each part by the capability rules of the kinds, as a run does.
|
|
1636
|
+
*/
|
|
1578
1637
|
readonly caps?: readonly Cap[];
|
|
1579
1638
|
}
|
|
1580
1639
|
/**
|
|
@@ -1588,7 +1647,7 @@ interface CheckOptions {
|
|
|
1588
1647
|
* - `#DEPTH!`: too much nesting.
|
|
1589
1648
|
* - `#REF!` and `#STEP?`: a bad path.
|
|
1590
1649
|
* - `#NAME?`: a name that nothing binds.
|
|
1591
|
-
* - `#CAP!`: an effect that the capabilities do not permit.
|
|
1650
|
+
* - `#CAP!`: an effect that the capabilities of its document do not permit. A kind around the document can narrow them.
|
|
1592
1651
|
*
|
|
1593
1652
|
* @param machine - The world and the code of the evaluators.
|
|
1594
1653
|
* @param doc - The document, as JSON.
|
|
@@ -1684,5 +1743,212 @@ export declare function formulaEvaluators(profile?: FormulaProfile): Readonly<Re
|
|
|
1684
1743
|
*/
|
|
1685
1744
|
export declare function formulaMachine(profile?: FormulaProfile, more?: Partial<Machine>): Machine;
|
|
1686
1745
|
//#endregion
|
|
1687
|
-
|
|
1746
|
+
//#region src/reference.d.ts
|
|
1747
|
+
/**
|
|
1748
|
+
* The definitional code of the reference, by evaluator name. The reference cannot read compiled code, thus each
|
|
1749
|
+
* compiled evaluator or runner of a machine needs a definition here. A function evaluator needs none.
|
|
1750
|
+
*/
|
|
1751
|
+
interface Definitions {
|
|
1752
|
+
readonly evaluators?: Readonly<Record<string, EvalFn>>;
|
|
1753
|
+
readonly runners?: Readonly<Record<string, RunFn>>;
|
|
1754
|
+
}
|
|
1755
|
+
/** The options of the reference interpreter. */
|
|
1756
|
+
interface ReferenceOptions {
|
|
1757
|
+
/** The type of a bare root value. */
|
|
1758
|
+
readonly declaredType?: string;
|
|
1759
|
+
/** The definitional code of the compiled evaluators and runners of the machine. */
|
|
1760
|
+
readonly definitions?: Definitions;
|
|
1761
|
+
/** A list that gets each effect, in its order. */
|
|
1762
|
+
readonly effects?: Effect[];
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* This function evaluates a document by the rules, without a compilation. It is the reference of the plans: a plan,
|
|
1766
|
+
* a traced plan and the second tier of a language must give its results. It covers evaluations, not runs: an effect
|
|
1767
|
+
* gives its payload, and a part that waits gives `#CALC!`.
|
|
1768
|
+
*
|
|
1769
|
+
* @param machine - The world and the code of the evaluators.
|
|
1770
|
+
* @param doc - The document.
|
|
1771
|
+
* @param context - The names and the capabilities at the root.
|
|
1772
|
+
* @param options - The type of a bare root value, the definitions of compiled code, and a list for the effects.
|
|
1773
|
+
* @returns The result.
|
|
1774
|
+
*/
|
|
1775
|
+
export declare function reference(machine: Machine, doc: unknown, context?: Context, options?: ReferenceOptions): Result;
|
|
1776
|
+
/**
|
|
1777
|
+
* This function gives the definitions of the formula kit for one profile. Each construct is a function evaluator in
|
|
1778
|
+
* the most direct style. It shares no code with the compilers of `formulaEvaluators`, thus the two readings of the
|
|
1779
|
+
* rules can disagree, and a test finds it.
|
|
1780
|
+
*
|
|
1781
|
+
* @param profile - The operations and the rules of the language.
|
|
1782
|
+
* @returns The definitions, by evaluator name.
|
|
1783
|
+
*/
|
|
1784
|
+
export declare function formulaDefinitions(profile?: FormulaProfile): Definitions;
|
|
1785
|
+
//#endregion
|
|
1786
|
+
//#region src/agree.d.ts
|
|
1787
|
+
/**
|
|
1788
|
+
* A tier that `agree` compares with the plan.
|
|
1789
|
+
*
|
|
1790
|
+
* - `reference`: the reference interpreter, which compiles nothing.
|
|
1791
|
+
* - `traced`: the traced evaluation, `evaluate`.
|
|
1792
|
+
* - `again`: a second evaluation of the same plan.
|
|
1793
|
+
* - `other`: the second tier of a language, from the option `other`.
|
|
1794
|
+
*/
|
|
1795
|
+
type Tier = "reference" | "traced" | "again" | "other";
|
|
1796
|
+
/** What a second tier gives: its result, and its effects when it records them. */
|
|
1797
|
+
interface TierResult {
|
|
1798
|
+
readonly result: Result;
|
|
1799
|
+
readonly effects?: readonly Effect[];
|
|
1800
|
+
}
|
|
1801
|
+
/** The options of `agree`. */
|
|
1802
|
+
interface AgreeOptions {
|
|
1803
|
+
/** The type of a bare root value. */
|
|
1804
|
+
readonly declaredType?: string;
|
|
1805
|
+
/** The definitional code of the compiled evaluators of the machine, for the reference. */
|
|
1806
|
+
readonly definitions?: Definitions;
|
|
1807
|
+
/** The tiers to compare with the plan. The default is the reference, the traced evaluation and a second evaluation. */
|
|
1808
|
+
readonly tiers?: readonly Exclude<Tier, "other">[];
|
|
1809
|
+
/**
|
|
1810
|
+
* This function gives the result of the second tier of a language, for example a compiler to loops.
|
|
1811
|
+
*
|
|
1812
|
+
* @param doc - The document.
|
|
1813
|
+
* @param context - The context.
|
|
1814
|
+
* @returns The result, or the result with the effects.
|
|
1815
|
+
*/
|
|
1816
|
+
readonly other?: (doc: unknown, context: Context) => Result | TierResult;
|
|
1817
|
+
/**
|
|
1818
|
+
* This function compares two values that the rules of `sameValue` do not know, for example two dates.
|
|
1819
|
+
*
|
|
1820
|
+
* @param a - The value of the plan.
|
|
1821
|
+
* @param b - The value of the other tier.
|
|
1822
|
+
* @returns `true` or `false`, or `undefined` to use the rules of `sameValue`.
|
|
1823
|
+
*/
|
|
1824
|
+
readonly equal?: (a: unknown, b: unknown) => boolean | undefined;
|
|
1825
|
+
/** `true`: two errors must also have the same reason, and each error must have a place. */
|
|
1826
|
+
readonly strict?: boolean;
|
|
1827
|
+
/**
|
|
1828
|
+
* This function gives what the host saw since its last call, for example the calls of an operation. `agree` uses
|
|
1829
|
+
* it before the plan and after each tier, and compares the results. Thus a tier that evaluates a part that the plan
|
|
1830
|
+
* does not evaluate fails.
|
|
1831
|
+
*
|
|
1832
|
+
* @returns What the host saw.
|
|
1833
|
+
*/
|
|
1834
|
+
readonly observe?: () => unknown;
|
|
1835
|
+
}
|
|
1836
|
+
/** The outcome of `agree`: the result of the plan, or the first tier that disagrees with it. */
|
|
1837
|
+
type Agreement = {
|
|
1838
|
+
readonly ok: true;
|
|
1839
|
+
readonly result: Result;
|
|
1840
|
+
readonly effects: readonly Effect[];
|
|
1841
|
+
} | {
|
|
1842
|
+
readonly ok: false;
|
|
1843
|
+
readonly tier: Tier;
|
|
1844
|
+
/** The result of the plan. */
|
|
1845
|
+
readonly plan: Result;
|
|
1846
|
+
/** The result of the tier that disagrees. */
|
|
1847
|
+
readonly other: Result;
|
|
1848
|
+
/** One sentence that tells the difference. */
|
|
1849
|
+
readonly reason: string;
|
|
1850
|
+
};
|
|
1851
|
+
/**
|
|
1852
|
+
* This function tells if two values are the same for `agree`. Lists and plain records compare item by item and field
|
|
1853
|
+
* by field, and the order of the fields does not matter. Each other leaf compares with `Object.is`, thus `-0` is not
|
|
1854
|
+
* `0`, and `NaN` is `NaN`. Two closures of `fn` are the same when they have the same parameters. Two `Held` values
|
|
1855
|
+
* are the same when their errors have the same code and place. Identity is not compared.
|
|
1856
|
+
*
|
|
1857
|
+
* @param a - The first value.
|
|
1858
|
+
* @param b - The second value.
|
|
1859
|
+
* @param equal - The rule of the caller for other values. It answers first, and `undefined` gives the rules above.
|
|
1860
|
+
* @returns `true` when the values are the same.
|
|
1861
|
+
*/
|
|
1862
|
+
export declare function sameValue(a: unknown, b: unknown, equal?: (a: unknown, b: unknown) => boolean | undefined): boolean;
|
|
1863
|
+
/**
|
|
1864
|
+
* This function evaluates a document with a plan and with other tiers, and compares the results (PLAN.AGREES). Two
|
|
1865
|
+
* results agree when they have the same value by `sameValue`, or errors with the same code, and the same place when
|
|
1866
|
+
* both have one. The effects must have the same kinds, places and payloads, in the same order. A language gives its
|
|
1867
|
+
* own tier with the option `other`.
|
|
1868
|
+
*
|
|
1869
|
+
* @param machine - The world and the code of the evaluators.
|
|
1870
|
+
* @param doc - The document.
|
|
1871
|
+
* @param context - The names and the capabilities at the root.
|
|
1872
|
+
* @param options - The tiers, the definitions for the reference, the rules of the comparison and the second tier.
|
|
1873
|
+
* @returns The result of the plan, or the first tier that disagrees and the reason.
|
|
1874
|
+
*/
|
|
1875
|
+
export declare function agree(machine: Machine, doc: unknown, context?: Context, options?: AgreeOptions): Agreement;
|
|
1876
|
+
//#endregion
|
|
1877
|
+
//#region src/generate.d.ts
|
|
1878
|
+
/** A source of random numbers with a seed. The same seed gives the same numbers. */
|
|
1879
|
+
interface Random {
|
|
1880
|
+
/** This function gives a number from 0 up to 1, without 1. */
|
|
1881
|
+
next(): number;
|
|
1882
|
+
/** This function gives a whole number from 0 up to `below`, without `below`. */
|
|
1883
|
+
int(below: number): number;
|
|
1884
|
+
/** This function gives `true` with the chance `p`. */
|
|
1885
|
+
chance(p: number): boolean;
|
|
1886
|
+
/** This function gives one item of a list that is not empty. */
|
|
1887
|
+
pick<T>(items: readonly T[]): T;
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* This function makes a source of random numbers with a seed (the algorithm mulberry32). It needs no package.
|
|
1891
|
+
*
|
|
1892
|
+
* @param seed - The seed: a whole number.
|
|
1893
|
+
* @returns The source.
|
|
1894
|
+
*/
|
|
1895
|
+
export declare function random(seed: number): Random;
|
|
1896
|
+
/** The options of `generate`. */
|
|
1897
|
+
interface GenerateOptions {
|
|
1898
|
+
/** The seed. The same seed and the same options give the same document. */
|
|
1899
|
+
readonly seed: number;
|
|
1900
|
+
/** The types that a document can have. The default is `typesOf(world)`. A namespace with a fallback needs its keys here. */
|
|
1901
|
+
readonly types?: readonly (readonly Key[])[];
|
|
1902
|
+
/** The type of a bare root value. */
|
|
1903
|
+
readonly declaredType?: string;
|
|
1904
|
+
/** The names that the host binds at the root. */
|
|
1905
|
+
readonly names?: readonly string[];
|
|
1906
|
+
/** The deepest nesting of documents. The default is 4. */
|
|
1907
|
+
readonly maxDepth?: number;
|
|
1908
|
+
/** The most documents in one document. The default is 24. */
|
|
1909
|
+
readonly maxSize?: number;
|
|
1910
|
+
/** The chance of a malformed choice at each document. The default is 0.05. */
|
|
1911
|
+
readonly malformed?: number;
|
|
1912
|
+
/**
|
|
1913
|
+
* This function gives the data of a document of a type without parts, for example a number for the kind `number`.
|
|
1914
|
+
*
|
|
1915
|
+
* @param type - The keys of the type.
|
|
1916
|
+
* @param random - The source of random numbers.
|
|
1917
|
+
* @returns The data, or `undefined` for a random JSON value.
|
|
1918
|
+
*/
|
|
1919
|
+
readonly data?: (type: readonly Key[], random: Random) => Json | undefined;
|
|
1920
|
+
/**
|
|
1921
|
+
* This function gives the types to prefer for a part, for example a function for the field `fn` of `call`.
|
|
1922
|
+
*
|
|
1923
|
+
* @param type - The keys of the type of the parent.
|
|
1924
|
+
* @param path - The path of the part in the value of the parent.
|
|
1925
|
+
* @returns The types, or `undefined` for no preference.
|
|
1926
|
+
*/
|
|
1927
|
+
readonly hints?: (type: readonly Key[], path: readonly Key[]) => readonly (readonly Key[])[] | undefined;
|
|
1928
|
+
/** The evaluator names for own entries. The default is none. */
|
|
1929
|
+
readonly own?: readonly string[];
|
|
1930
|
+
/** The keys for the steps of a path after its root and its name. */
|
|
1931
|
+
readonly keys?: readonly Key[];
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* This function lists the types of a world: each kind and each alias, also in a namespace. A namespace with a
|
|
1935
|
+
* fallback gives no types, because each key names a kind.
|
|
1936
|
+
*
|
|
1937
|
+
* @param world - The world.
|
|
1938
|
+
* @returns The keys of each type.
|
|
1939
|
+
*/
|
|
1940
|
+
export declare function typesOf(world: World): readonly (readonly Key[])[];
|
|
1941
|
+
/**
|
|
1942
|
+
* This function builds a random document for a world from the contracts of its kinds. It reads the shapes of the
|
|
1943
|
+
* parts, the declared types, the permitted kinds and the names that the scope rules bind. Some choices are malformed
|
|
1944
|
+
* on purpose. Examples are an unknown kind, a value without its shape, a bare value without a type and a name that
|
|
1945
|
+
* nothing binds. The depth and the size have limits.
|
|
1946
|
+
*
|
|
1947
|
+
* @param world - The world.
|
|
1948
|
+
* @param options - The seed, the types, the limits and the data of the leaves.
|
|
1949
|
+
* @returns The document, as JSON.
|
|
1950
|
+
*/
|
|
1951
|
+
export declare function generate(world: World, options: GenerateOptions): unknown;
|
|
1952
|
+
//#endregion
|
|
1953
|
+
export type { AgreeOptions, Agreement, Alias, AllOptions, Answer, AskOptions, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, Construct, Context, Part as ContextPart, Definitions, DerefCode, DocVisit, Edge, Effect, Envelope, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, Evaluator, ExtFn, Failed, FormulaProfile, GenerateOptions, Give, Header, Hop, HopBy, HostThing, Issue, Json, JsonRecord, KernelCode, Key, Kind, KindSource, LazyOp, Lookup, Machine, NamesSource, Namespace, Navigator, NearestOptions, OpFn, OrderProblem, Outcome, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartsSpec, Perform, Plan, PrepareOptions, Random, RefUse, ReferenceOptions, Resolution, ResolveCode, ResolveOptions, Result, Root, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, ScopeRule, Shape$1 as Shape, Side, Split, Step, StepSpec, Steps, StopSignal, Stored, Thing, Tier, TierResult, TraceNode, TypeRef, Use, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry };
|
|
1688
1954
|
//# sourceMappingURL=index.d.ts.map
|