@mark1russell7/coeval 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/build/index.d.ts +545 -233
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2619 -383
- package/build/index.js.map +1 -1
- package/package.json +3 -2
- package/src/agree.ts +128 -16
- package/src/conform.ts +75 -5
- package/src/deref.ts +76 -11
- package/src/evaluate.ts +151 -21
- package/src/facts.ts +113 -78
- package/src/formula.ts +67 -11
- package/src/index.ts +23 -1
- package/src/merge.ts +49 -14
- package/src/reference.ts +110 -15
- package/src/replay.ts +1052 -18
- package/src/static.ts +2 -2
- package/src/stdlib.ts +55 -2
- package/src/syntax.ts +357 -52
- package/src/types.ts +520 -17
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/doc.d.ts
|
|
2
1
|
/** A JSON value. A document is JSON. */
|
|
3
2
|
type Json = null | boolean | number | string | readonly Json[] | {
|
|
4
3
|
readonly [key: string]: Json;
|
|
@@ -159,8 +158,6 @@ export declare function fromJson(value: unknown): Envelope | undefined;
|
|
|
159
158
|
* @returns `true` when the values are equal.
|
|
160
159
|
*/
|
|
161
160
|
export declare function docEquals(a: unknown, b: unknown): boolean;
|
|
162
|
-
//#endregion
|
|
163
|
-
//#region src/errors.d.ts
|
|
164
161
|
/** The codes that the kernel gives. */
|
|
165
162
|
type KernelCode = "#KIND?" | "#NOEVAL" | "#PART?" | "#NAME?" | "#REF!" | "#N/A" | "#CYCLE!" | "#STEP?" | "#VALUE!" | "#NUM!" | "#ARGS" | "#CAP!" | "#CALC!" | "#DEPTH!" | "#ABORT" | "#REPLAY!" | "#TYPE!";
|
|
166
163
|
/** The code of an error value. A language can add its own codes. Each code starts with `#`. */
|
|
@@ -254,8 +251,6 @@ export declare function thrown(error: unknown, who: string): Failed;
|
|
|
254
251
|
* @returns The text.
|
|
255
252
|
*/
|
|
256
253
|
export declare function describe(value: unknown): string;
|
|
257
|
-
//#endregion
|
|
258
|
-
//#region src/deref.d.ts
|
|
259
254
|
/**
|
|
260
255
|
* The brand of a host thing: an object of the host that answers the steps of a path itself. The brand is a
|
|
261
256
|
* global symbol, thus two copies of the kernel in one program know the things of each other.
|
|
@@ -348,8 +343,31 @@ interface Context {
|
|
|
348
343
|
readonly event: Thing;
|
|
349
344
|
readonly caps: readonly Cap[];
|
|
350
345
|
}
|
|
351
|
-
/**
|
|
352
|
-
|
|
346
|
+
/**
|
|
347
|
+
* The code of a `deref` evaluator: it answers one step of a path on a document of its kind. A field that holds
|
|
348
|
+
* `undefined` also gives `undefined`. The optional function `has` of the code tells the two cases apart
|
|
349
|
+
* (DEREF.KIND-UNDEFINED). A host gives the code a `has` with `Object.assign(code, { has })`.
|
|
350
|
+
*/
|
|
351
|
+
interface DerefCode {
|
|
352
|
+
/**
|
|
353
|
+
* This function answers one step on a document.
|
|
354
|
+
*
|
|
355
|
+
* @param doc - The document.
|
|
356
|
+
* @param key - The key of the step.
|
|
357
|
+
* @returns What the step reaches, or `undefined` when it reaches nothing.
|
|
358
|
+
*/
|
|
359
|
+
(doc: Envelope, key: Key): Thing | undefined;
|
|
360
|
+
/**
|
|
361
|
+
* This optional function tells if a document has a field for a key. The kernel asks it only when the code gives
|
|
362
|
+
* `undefined`. Then `true` tells that the field holds `undefined`. A code without `has` reads `undefined` as a
|
|
363
|
+
* missing field, as a host thing does (DEREF.HOST-UNDEFINED).
|
|
364
|
+
*
|
|
365
|
+
* @param doc - The document.
|
|
366
|
+
* @param key - The key of the step.
|
|
367
|
+
* @returns `true` when the document has the field.
|
|
368
|
+
*/
|
|
369
|
+
readonly has?: (doc: Envelope, key: Key) => boolean;
|
|
370
|
+
}
|
|
353
371
|
/**
|
|
354
372
|
* The result of a step document: what it reached, or the reason of a failure. A failure can give its code, for
|
|
355
373
|
* example `#REF!` for a position outside a space. The default code is `#N/A`.
|
|
@@ -370,13 +388,24 @@ interface WalkInput {
|
|
|
370
388
|
readonly here: Thing;
|
|
371
389
|
readonly context: Context;
|
|
372
390
|
/**
|
|
373
|
-
* This function answers one step on a thing, through the ladder.
|
|
391
|
+
* This function answers one step on a thing, through the ladder. A field that holds `undefined` also gives
|
|
392
|
+
* `undefined`. The function `has` tells the two cases apart (DEREF.WALKER-UNDEFINED).
|
|
374
393
|
*
|
|
375
394
|
* @param thing - The thing.
|
|
376
395
|
* @param key - The key.
|
|
377
396
|
* @returns What the step reaches, or `undefined`.
|
|
378
397
|
*/
|
|
379
398
|
deref(thing: Thing, key: Key): Thing | undefined;
|
|
399
|
+
/**
|
|
400
|
+
* This optional function tells if a step on a thing reaches a field, through the ladder. A walker needs it only
|
|
401
|
+
* when `deref` gives `undefined`. Then `true` tells that the field holds `undefined` (DEREF.WALKER-UNDEFINED).
|
|
402
|
+
* Each resolution of the kernel gives it. The function asks the ladder again, thus a host thing answers the step again.
|
|
403
|
+
*
|
|
404
|
+
* @param thing - The thing.
|
|
405
|
+
* @param key - The key.
|
|
406
|
+
* @returns `true` when the step reaches a field, also a field that holds `undefined`.
|
|
407
|
+
*/
|
|
408
|
+
has?(thing: Thing, key: Key): boolean;
|
|
380
409
|
/**
|
|
381
410
|
* This optional function records one hop inside the walk (HOP.EACH-STEP). The resolution gives it only when it
|
|
382
411
|
* records hops. The hop of the whole walk comes after these hops, as before.
|
|
@@ -503,8 +532,6 @@ export declare function resolve(nav: Navigator, ctx: Context, path: readonly unk
|
|
|
503
532
|
* @returns The value.
|
|
504
533
|
*/
|
|
505
534
|
export declare function valueOfThing(thing: Thing): unknown;
|
|
506
|
-
//#endregion
|
|
507
|
-
//#region src/types.d.ts
|
|
508
535
|
/**
|
|
509
536
|
* A value type: a set of values that a result can have, as a JSON term.
|
|
510
537
|
*
|
|
@@ -564,6 +591,29 @@ interface Domain {
|
|
|
564
591
|
* standard extension `ext.domain`. A domain without a codec has no such document.
|
|
565
592
|
*/
|
|
566
593
|
readonly codec?: DomainCodec;
|
|
594
|
+
/**
|
|
595
|
+
* The full list of the members of the domain, when the domain holds few values, for example `true` and `false` of
|
|
596
|
+
* `bool` (TYPE.FITS-FINITE). `fits` reads it: a base type with a list fits a type that holds each member of the list.
|
|
597
|
+
* The language keeps the list complete: each member of the domain is in the list. A value that fails a test of the
|
|
598
|
+
* domain does not count. The check reads a list of at most 64 values.
|
|
599
|
+
*/
|
|
600
|
+
readonly values?: readonly unknown[];
|
|
601
|
+
/**
|
|
602
|
+
* Some members of the domain for the tests of `conforms`, for example `0` and `-1` of `number` (D99). The checks
|
|
603
|
+
* `truth` and `cover` add the samples of each domain to the palette. A sample that fails a test of a type does not
|
|
604
|
+
* count. The list is not a full list of the members, thus `fits` does not read it.
|
|
605
|
+
*/
|
|
606
|
+
readonly samples?: readonly unknown[];
|
|
607
|
+
/**
|
|
608
|
+
* The covers of the domain (TYPE.FITS-COVER, D85). A cover is a list of domains under this domain, and its domains
|
|
609
|
+
* together hold each member of this domain. An example is a domain of negative numbers and a domain of the other
|
|
610
|
+
* numbers as a cover of `number`. `fits` reads it: a base type fits a union when each domain of a cover fits it.
|
|
611
|
+
*
|
|
612
|
+
* A split of a record also narrows a field of the domain to each domain of a cover (D90).
|
|
613
|
+
* The language keeps each cover true, and `fits` trusts it, as it trusts `values`. A cover that is empty, or that
|
|
614
|
+
* names this domain or a name that is not under it, does not count. `conforms` tests each cover from samples (D94).
|
|
615
|
+
*/
|
|
616
|
+
readonly covers?: readonly (readonly string[])[];
|
|
567
617
|
}
|
|
568
618
|
/**
|
|
569
619
|
* The codec of a domain: it writes a member of the domain as JSON, and it reads the JSON again (D40). Both functions
|
|
@@ -628,9 +678,35 @@ export declare function member(value: unknown, type: ValueType, domains?: Readon
|
|
|
628
678
|
* field is `unknown`.
|
|
629
679
|
* - A function fits when it has the same or fewer parameters, each expected parameter fits its parameter, and its
|
|
630
680
|
* result fits.
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
681
|
+
* - The finite rule comes after these rules (TYPE.FITS-FINITE). A type with at most 64 members fits when each member
|
|
682
|
+
* is a member of `expected`. Thus `bool` fits `{ "one": [true, false] }`.
|
|
683
|
+
* - A base type has few members when its domain or a parent declares `values`, as `null`, `undefined` and `bool` do.
|
|
684
|
+
* A union, a `one`, a closed record of such types and a list of `never` also have few members.
|
|
685
|
+
* - The cover rule comes next (TYPE.FITS-COVER, D85). A base type fits a union or a `one` when each domain of a cover
|
|
686
|
+
* fits. The cover is in `covers` of a domain of its line. Each domain of a cover is under the covered
|
|
687
|
+
* domain. Thus a cover of `number` by `neg` and `nonneg` gives `number` a fit against `neg | nonneg`.
|
|
688
|
+
* - The split rule comes last (D84). An open record, or a closed record with more than 64 members, splits a field with
|
|
689
|
+
* few members over a union. A closed record also splits over a `one`. Each record of the split narrows the field to
|
|
690
|
+
* one member, and each record must fit.
|
|
691
|
+
* Thus `{ "record": { "a": "bool" } }` fits a union of a record for each value of `a`.
|
|
692
|
+
* - A split also narrows a field of a record in a field, by its path (TYPE.FITS-PATH, D89). The fields of the record
|
|
693
|
+
* split first, then the paths of each next depth, in the order of the keys. A path goes into a record without a
|
|
694
|
+
* finite list. Thus `{a: {x: bool}}` fits the union of `{a: {x: true}}` and `{a: {x: false}}`.
|
|
695
|
+
* - A type split comes after each value split (TYPE.FITS-SPLIT-TYPE, D90). A field of a base type with a valid cover in
|
|
696
|
+
* its line splits into the domains of a cover. A field of a union without a finite list splits into its
|
|
697
|
+
* members. A case that does not fit splits again at its path, by the same rules. A base type there uses only the
|
|
698
|
+
* covers of its own domain. Thus `{a: number}` fits `{a: neg} | {a: nonneg}` when `neg` and `nonneg` cover `number`.
|
|
699
|
+
* - A field with more than one valid cover tries each cover until one fits (TYPE.FITS-SPLIT-COVERS, D102). The order
|
|
700
|
+
* is the order of the line, then the order of the covers of each domain.
|
|
701
|
+
*
|
|
702
|
+
* The relation is sound: a member of `found` is a member of `expected` when no `unknown` is in the types
|
|
703
|
+
* (TYPE.FITS-SOUND). The finite rule trusts `values`, and the cover rule trusts `covers`. Thus a list without a member
|
|
704
|
+
* or a false cover makes the relation unsound for that domain.
|
|
705
|
+
*
|
|
706
|
+
* The relation is not complete. A split builds at most 64 records, with each split inside its work at each depth. The
|
|
707
|
+
* failed tries of covers take from these 64 records too. A domain without `values` gets no finite rule, and
|
|
708
|
+
* neither does a type with more than 64 members that is not a record. The cover rule tests at most 64 domains of
|
|
709
|
+
* covers. The function does not throw.
|
|
634
710
|
*
|
|
635
711
|
* @param found - The type that a part has.
|
|
636
712
|
* @param expected - The type that the position needs.
|
|
@@ -685,8 +761,6 @@ export declare function typeText(type: ValueType): string;
|
|
|
685
761
|
* @returns The problems. A term comes before its parts, and the parts keep their order.
|
|
686
762
|
*/
|
|
687
763
|
export declare function typeIssues(type: unknown, domains?: Readonly<Record<string, Domain>>): readonly TypeIssue[];
|
|
688
|
-
//#endregion
|
|
689
|
-
//#region src/world.d.ts
|
|
690
764
|
/** The two sides of evaluation. `derive` is pure. `run` causes effects in order. */
|
|
691
765
|
type Side = "derive" | "run";
|
|
692
766
|
/**
|
|
@@ -1050,8 +1124,6 @@ export declare function kindDocument(name: string, kind: Kind): Envelope;
|
|
|
1050
1124
|
* @returns `true` when the value has verbs.
|
|
1051
1125
|
*/
|
|
1052
1126
|
export declare function looksLikeKind(value: unknown): boolean;
|
|
1053
|
-
//#endregion
|
|
1054
|
-
//#region src/ladder.d.ts
|
|
1055
1127
|
/** The rungs of the ladder, in the order that a question visits them. */
|
|
1056
1128
|
export declare const RUNGS: readonly ["own", "kind", "default"];
|
|
1057
1129
|
/** One rung of the ladder. */
|
|
@@ -1134,8 +1206,6 @@ export declare function kindNamed(world: World, name: TypeRef): Kind | undefined
|
|
|
1134
1206
|
* @returns The answer, with the record of each rung that the question visited.
|
|
1135
1207
|
*/
|
|
1136
1208
|
export declare function ask(world: World, doc: Header, verb: string, options?: AskOptions): Answer;
|
|
1137
|
-
//#endregion
|
|
1138
|
-
//#region src/static.d.ts
|
|
1139
1209
|
/** One document that a walk visits. */
|
|
1140
1210
|
interface DocVisit {
|
|
1141
1211
|
/** The keys from the root document to this document, through the parts. It is the place of an error. */
|
|
@@ -1386,8 +1456,6 @@ interface WorldIssue {
|
|
|
1386
1456
|
* order of the verbs. The fallback kind of a namespace comes after the entries of that namespace.
|
|
1387
1457
|
*/
|
|
1388
1458
|
export declare function checkWorld(machine: Machine, verbs: readonly string[]): readonly WorldIssue[];
|
|
1389
|
-
//#endregion
|
|
1390
|
-
//#region src/typing.d.ts
|
|
1391
1459
|
/** What a type rule gets for one document. */
|
|
1392
1460
|
interface TypeInput {
|
|
1393
1461
|
/** The keys of the kind of the document, after each alias. */
|
|
@@ -1519,8 +1587,6 @@ interface Typed {
|
|
|
1519
1587
|
/** The type that the position of the document needs, when it needs one. */
|
|
1520
1588
|
readonly expected?: ValueType;
|
|
1521
1589
|
}
|
|
1522
|
-
//#endregion
|
|
1523
|
-
//#region src/facts.d.ts
|
|
1524
1590
|
/**
|
|
1525
1591
|
* One read of a document: a free reference, with its marks (FACTS.READS). A plan resolves the path of the reference
|
|
1526
1592
|
* when it evaluates the reference. The static read covers each path that the plan resolves there (FACTS.SOUND). A
|
|
@@ -1542,9 +1608,12 @@ interface StaticRead {
|
|
|
1542
1608
|
readonly address: boolean;
|
|
1543
1609
|
/** The path of the reference: its root and its steps. */
|
|
1544
1610
|
readonly path: readonly Json[];
|
|
1545
|
-
/**
|
|
1611
|
+
/**
|
|
1612
|
+
* The keys from the root document to the reference document, through the parts. A read of an equation has the
|
|
1613
|
+
* place of the first document of its tree kind (FACTS.EQUATIONS).
|
|
1614
|
+
*/
|
|
1546
1615
|
readonly place: readonly Key[];
|
|
1547
|
-
/** The keys from the root JSON value to the reference document. */
|
|
1616
|
+
/** The keys from the root JSON value to the reference document, or to the document of the kind for an equation. */
|
|
1548
1617
|
readonly at: readonly Key[];
|
|
1549
1618
|
}
|
|
1550
1619
|
/** The static facts of one document (D24). They depend only on the document and the machine, not on a context. */
|
|
@@ -1592,9 +1661,11 @@ interface FactsOptions {
|
|
|
1592
1661
|
*
|
|
1593
1662
|
* - `reads`: each free reference, with the root and the keys of its path. A read under a lazy part has the mark
|
|
1594
1663
|
* `lazy`, for example a read in a branch of `if`. A read after a step document has `exact: false`. A kind that
|
|
1595
|
-
* declares `reads` adds a read of each of its roots at each document of the kind.
|
|
1664
|
+
* declares `reads` adds a read of each of its roots at each document of the kind. The first document of a tree
|
|
1665
|
+
* kind also gets the lazy reads of the equations of its kind (FACTS.EQUATIONS). A read from `self` or from a name
|
|
1666
|
+
* of a rung is not one of them, because it is not free (READS.EQUATION).
|
|
1596
1667
|
* - `side` and `effects`: from the contract of each kind.
|
|
1597
|
-
* - `pure`: each kind declares `pure`, and the document has no effect and is not volatile.
|
|
1668
|
+
* - `pure`: each kind declares `pure`, also in an equation, and the document has no effect and is not volatile.
|
|
1598
1669
|
* - `volatile`: a kind, an operation or a step document declares `volatile`, or the host marks a read.
|
|
1599
1670
|
*
|
|
1600
1671
|
* The hook `facts` of the machine answers for a name that a fallback kind covers, for example an operation. Its
|
|
@@ -1616,8 +1687,6 @@ interface FactsOptions {
|
|
|
1616
1687
|
* @returns The facts.
|
|
1617
1688
|
*/
|
|
1618
1689
|
export declare function factsOf(machine: Machine, doc: unknown, options?: FactsOptions): DocFacts;
|
|
1619
|
-
//#endregion
|
|
1620
|
-
//#region src/evaluate.d.ts
|
|
1621
1690
|
/**
|
|
1622
1691
|
* This function makes a context with names and capabilities. The other roots are empty, and an evaluation sets
|
|
1623
1692
|
* the world.
|
|
@@ -1762,9 +1831,11 @@ interface Journal {
|
|
|
1762
1831
|
*
|
|
1763
1832
|
* @param all - The address of the `all`.
|
|
1764
1833
|
* @param waiting - The indices of the items that wait.
|
|
1834
|
+
* @param before - The number of the waits of this `all` that settled before this call. The kernel gives it, thus a
|
|
1835
|
+
* replayer keeps no state of a run (RUN.REPLAY-RUNS). An older copy of the kernel does not give it.
|
|
1765
1836
|
* @returns The index of an item that waits, or `undefined` for the order of the host.
|
|
1766
1837
|
*/
|
|
1767
|
-
readonly next?: (all: string, waiting: readonly number[]) => number | undefined;
|
|
1838
|
+
readonly next?: (all: string, waiting: readonly number[], before?: number) => number | undefined;
|
|
1768
1839
|
}
|
|
1769
1840
|
/**
|
|
1770
1841
|
* The runtime of one evaluation or run. Compiled code gets it with the context, and asks it to resolve paths and
|
|
@@ -2309,8 +2380,6 @@ export declare function flatten(trace: TraceNode): readonly TraceNode[];
|
|
|
2309
2380
|
* @returns The errors, in the order of their start.
|
|
2310
2381
|
*/
|
|
2311
2382
|
export declare function failures(trace: TraceNode): readonly EvalError[];
|
|
2312
|
-
//#endregion
|
|
2313
|
-
//#region src/merge.d.ts
|
|
2314
2383
|
/** The keys from a part of a merge to one of its entries, for example `["kinds", "ref"]`. */
|
|
2315
2384
|
type MergePath = readonly Key[];
|
|
2316
2385
|
/**
|
|
@@ -2350,25 +2419,34 @@ export declare class MergeError extends Error {
|
|
|
2350
2419
|
*/
|
|
2351
2420
|
constructor(conflicts: readonly MergeConflict[]);
|
|
2352
2421
|
}
|
|
2353
|
-
/** What `extendDomain` adds to a domain: more parents,
|
|
2422
|
+
/** What `extendDomain` adds to a domain: more parents, the types of more steps, and more covers. */
|
|
2354
2423
|
interface DomainExtension {
|
|
2355
2424
|
/** The names of the parents to add. A member of the domain then also passes the test of each new parent. */
|
|
2356
2425
|
readonly under?: readonly string[];
|
|
2357
2426
|
/** The types of the steps to add. A step with the key of an earlier step replaces its type. */
|
|
2358
2427
|
readonly steps?: Readonly<Record<string, ValueType>>;
|
|
2428
|
+
/**
|
|
2429
|
+
* The covers to add (TYPE.FITS-COVER, D85). A cover that the domain has already does not change. The language that
|
|
2430
|
+
* adds a cover keeps it true, because `fits` trusts it.
|
|
2431
|
+
*/
|
|
2432
|
+
readonly covers?: readonly (readonly string[])[];
|
|
2359
2433
|
}
|
|
2360
2434
|
/**
|
|
2361
|
-
* This function makes a part of a merge that adds parents or
|
|
2362
|
-
* example is a domain of another language. The part reads the domain from the merge before it
|
|
2363
|
-
* copy with the same test
|
|
2364
|
-
*
|
|
2435
|
+
* This function makes a part of a merge that adds parents, steps or covers to a domain of an earlier part
|
|
2436
|
+
* (TYPE.PARENTS). An example is a domain of another language. The part reads the domain from the merge before it
|
|
2437
|
+
* (`prev`). It gives a copy with the same test, summary, codec, list of values and samples, and it names
|
|
2438
|
+
* `["domains", name]` in `replaces` (D17).
|
|
2439
|
+
* A domain of the kernel that the earlier parts do not name comes from `STD_DOMAINS`.
|
|
2440
|
+
*
|
|
2441
|
+
* An extension does not change the codec. Thus each member keeps its document (D80).
|
|
2365
2442
|
*
|
|
2366
2443
|
* A new parent adds its test to the domain (TYPE.MEMBER). Thus `fits` stays sound, but a value that fails the test of
|
|
2367
2444
|
* the parent is no longer a member. The language that adds the parent keeps the signatures of the other language
|
|
2368
|
-
* true. A
|
|
2445
|
+
* true. A new parent of a domain in a cover of another domain can make that cover false (D85). A name without a
|
|
2446
|
+
* domain gives an empty part, and `typeIssues` reports each use of that name.
|
|
2369
2447
|
*
|
|
2370
2448
|
* @param name - The name of the domain.
|
|
2371
|
-
* @param more - The parents and the
|
|
2449
|
+
* @param more - The parents, the steps and the covers to add.
|
|
2372
2450
|
* @returns The part, as a function of the merge before it.
|
|
2373
2451
|
*/
|
|
2374
2452
|
export declare function extendDomain(name: string, more: DomainExtension): (prev: Machine) => MachinePart;
|
|
@@ -2440,8 +2518,6 @@ export declare function restrictWorld(world: World, paths: readonly MergePath[])
|
|
|
2440
2518
|
* @returns The machine without the entries.
|
|
2441
2519
|
*/
|
|
2442
2520
|
export declare function restrictMachine(machine: Machine, paths: readonly MergePath[]): Machine;
|
|
2443
|
-
//#endregion
|
|
2444
|
-
//#region src/classify.d.ts
|
|
2445
2521
|
/** A shape proposes a kind for each document that has all of its fields. */
|
|
2446
2522
|
interface Shape$1 {
|
|
2447
2523
|
readonly name: string;
|
|
@@ -2476,8 +2552,6 @@ export declare function classify(shapes: readonly Shape$1[], value: Json): Class
|
|
|
2476
2552
|
* @returns The envelope.
|
|
2477
2553
|
*/
|
|
2478
2554
|
export declare function tag(value: Json, kind: string): Envelope;
|
|
2479
|
-
//#endregion
|
|
2480
|
-
//#region src/parts.d.ts
|
|
2481
2555
|
/** One part of a value: its place in the value, the JSON of the part, and the type that its position declares. */
|
|
2482
2556
|
interface PartSlot {
|
|
2483
2557
|
/** The keys from the value of the document to the part. */
|
|
@@ -2564,13 +2638,219 @@ export declare function partsOf(world: World, value: unknown, declaredType?: str
|
|
|
2564
2638
|
* @returns `true` when the path matches.
|
|
2565
2639
|
*/
|
|
2566
2640
|
export declare function pathMatches(path: readonly Key[], pattern: readonly Key[]): boolean;
|
|
2567
|
-
|
|
2568
|
-
|
|
2641
|
+
/** The place of an operator: before its term, between two terms, or after its term. */
|
|
2642
|
+
type SyntaxFixity = "prefix" | "infix" | "postfix";
|
|
2643
|
+
/**
|
|
2644
|
+
* The grouping of a chain of one infix operator. `left` reads `a - b - c` as `(a - b) - c`, and `right` reads
|
|
2645
|
+
* `a ^ b ^ c` as `a ^ (b ^ c)`. `none` refuses a chain. `flat` reads a chain as one document with each term.
|
|
2646
|
+
*/
|
|
2647
|
+
type SyntaxAssoc = "left" | "right" | "none" | "flat";
|
|
2648
|
+
/** One operator of a syntax profile. */
|
|
2649
|
+
interface SyntaxOperator {
|
|
2650
|
+
/** The text of the operator, for example `+`, `<>` or `and`. A word operator is a plain name. */
|
|
2651
|
+
readonly symbol: string;
|
|
2652
|
+
/** The place of the operator. */
|
|
2653
|
+
readonly fixity: SyntaxFixity;
|
|
2654
|
+
/** The precedence. A larger number binds more tightly. */
|
|
2655
|
+
readonly prec: number;
|
|
2656
|
+
/** The grouping of a chain of an infix operator. The default is `left`. */
|
|
2657
|
+
readonly assoc?: SyntaxAssoc;
|
|
2658
|
+
/** The type of the document that the operator makes, with dots between the keys, for example `ops.add` or `and`. */
|
|
2659
|
+
readonly kind: string;
|
|
2660
|
+
}
|
|
2661
|
+
/** The literal rules of a syntax profile. */
|
|
2662
|
+
interface SyntaxLiterals {
|
|
2663
|
+
/** `false` removes the decimal numbers. The default is `true`. */
|
|
2664
|
+
readonly numbers?: boolean;
|
|
2665
|
+
/** `true` puts a minus sign right before a digit into the number, where a term starts. The default is `true`. */
|
|
2666
|
+
readonly signed?: boolean;
|
|
2667
|
+
/** The texts: the quote and the escape of a quote. `false` removes the texts. The default is `"` with backslashes. */
|
|
2668
|
+
readonly strings?: false | {
|
|
2669
|
+
readonly quote?: "\"" | "'";
|
|
2670
|
+
readonly escape?: "backslash" | "double";
|
|
2671
|
+
};
|
|
2672
|
+
/** The words that are literals, with their values. The default is `true`, `false` and `null`. */
|
|
2673
|
+
readonly words?: Readonly<Record<string, unknown>>;
|
|
2674
|
+
/**
|
|
2675
|
+
* The kinds of the data envelopes of a text, a number and a truth value, with dots between the keys (K159, D65). A
|
|
2676
|
+
* literal in a place that takes a document gets its envelope. Such a place is the whole text, the document after a
|
|
2677
|
+
* header name, or an argument that its form names in `wrap`. Thus `list(1)` gives `list(number(1))`, and `print`
|
|
2678
|
+
* writes the envelope as the bare literal there. Without this field, a literal stays bare in each place.
|
|
2679
|
+
*/
|
|
2680
|
+
readonly envelopes?: SyntaxEnvelopes;
|
|
2681
|
+
}
|
|
2682
|
+
/** The kinds of the data envelopes of the literals (K159, D65). A literal without a kind stays bare, for example `null`. */
|
|
2683
|
+
interface SyntaxEnvelopes {
|
|
2684
|
+
/** The kind of a finite number, for example `number`. */
|
|
2685
|
+
readonly number?: string;
|
|
2686
|
+
/** The kind of a text, for example `text`. */
|
|
2687
|
+
readonly text?: string;
|
|
2688
|
+
/** The kind of a truth value, for example `bool`. */
|
|
2689
|
+
readonly bool?: string;
|
|
2690
|
+
}
|
|
2691
|
+
/** A reference syntax that a pattern gives, for example the address `A1` of a cell. */
|
|
2692
|
+
interface SyntaxRefPattern {
|
|
2693
|
+
/** The pattern of the text of a reference. The parser tries it before a name. */
|
|
2694
|
+
readonly pattern: RegExp;
|
|
2695
|
+
/** This function gives the path of the reference from its text. */
|
|
2696
|
+
readonly read: (text: string) => readonly Key[];
|
|
2697
|
+
/** This function gives the text of a path, or `undefined` when the pattern does not write the path. */
|
|
2698
|
+
readonly write: (path: readonly unknown[]) => string | undefined;
|
|
2699
|
+
}
|
|
2700
|
+
/** The reference syntax of a syntax profile. */
|
|
2701
|
+
interface SyntaxRefs {
|
|
2702
|
+
/** The root of a bare name. The default is `names`. Thus `x` is the path `["names", "x"]`. */
|
|
2703
|
+
readonly bare?: string;
|
|
2704
|
+
/** The roots that the text names first, for example `self.price`. The default is `self`, `world`, `event` and `caps`. */
|
|
2705
|
+
readonly roots?: readonly string[];
|
|
2706
|
+
/** `false` removes the field steps `a.b`. The default is `true`. */
|
|
2707
|
+
readonly fields?: boolean;
|
|
2708
|
+
/** The patterns of other references. */
|
|
2709
|
+
readonly patterns?: readonly SyntaxRefPattern[];
|
|
2710
|
+
}
|
|
2711
|
+
/** A call form: a name with arguments in parentheses that makes a construct, for example `if(test, then, else)`. */
|
|
2712
|
+
interface SyntaxForm {
|
|
2713
|
+
/**
|
|
2714
|
+
* The name in the text: a plain name, or plain names with dots between them, for example `math.product` (K161). A
|
|
2715
|
+
* name with dots needs the field steps of `refs.fields`, and its first key is not a word operator.
|
|
2716
|
+
*/
|
|
2717
|
+
readonly name: string;
|
|
2718
|
+
/** The type of the document, with dots between the keys. */
|
|
2719
|
+
readonly kind: string;
|
|
2720
|
+
/**
|
|
2721
|
+
* The fields of the value, in the order of the arguments. Without them, the value is the list of the arguments. A
|
|
2722
|
+
* form `named` permits only these keys, and without them it permits each key.
|
|
2723
|
+
*/
|
|
2724
|
+
readonly fields?: readonly string[];
|
|
2725
|
+
/** The smallest number of arguments. The default is the number of the fields, or `0`. Only `list` and `fields` read it. */
|
|
2726
|
+
readonly min?: number;
|
|
2727
|
+
/**
|
|
2728
|
+
* The way that the arguments make the value (D63). The default is `fields` with fields, or `list`.
|
|
2729
|
+
*
|
|
2730
|
+
* - `list`: the value is the list of the arguments, for example `list(1, 2)`.
|
|
2731
|
+
* - `fields`: the arguments go into the fields, in order, for example `if(test, then, else)`.
|
|
2732
|
+
* - `named`: each argument is a key and a document, and the value is a record, for example `panel(width: 300)`.
|
|
2733
|
+
* - `literal`: the one argument is a literal, and the value is its data, for example `text("big")`.
|
|
2734
|
+
*/
|
|
2735
|
+
readonly args?: SyntaxFormArgs;
|
|
2736
|
+
/**
|
|
2737
|
+
* The arguments that take a document (K159, D65): `true` for each argument, or the names of some fields. A literal
|
|
2738
|
+
* in such an argument gets its data envelope of `literals.envelopes`. Without that field, `wrap` changes nothing. A
|
|
2739
|
+
* form `literal` takes no `wrap`, and a form `list` takes only `true`.
|
|
2740
|
+
*/
|
|
2741
|
+
readonly wrap?: boolean | readonly string[];
|
|
2742
|
+
}
|
|
2743
|
+
/** The way that the arguments of a call form make the value of its document (D63). */
|
|
2744
|
+
type SyntaxFormArgs = "list" | "fields" | "named" | "literal";
|
|
2745
|
+
/** The call syntax of a syntax profile. */
|
|
2746
|
+
interface SyntaxCalls {
|
|
2747
|
+
/** The operations that a call `name(args)` can name. `true` permits each name. The default is `true`. */
|
|
2748
|
+
readonly ops?: boolean | readonly string[];
|
|
2749
|
+
/** The call forms of constructs. A form wins over an operation with the same name. */
|
|
2750
|
+
readonly forms?: readonly SyntaxForm[];
|
|
2751
|
+
/** The text between two arguments. The default is `,`. */
|
|
2752
|
+
readonly separator?: string;
|
|
2753
|
+
}
|
|
2754
|
+
/** The text of the header of a document (K157, D62). */
|
|
2755
|
+
interface SyntaxHeader {
|
|
2756
|
+
/**
|
|
2757
|
+
* The symbol between a name and its document, for example `=` in `total = 2 + 3`. The text gives the document the
|
|
2758
|
+
* header `name`. Without the symbol, a document with a name has no text. The symbol is a group of symbols, and no
|
|
2759
|
+
* infix or postfix operator is the symbol or the start of it.
|
|
2760
|
+
*/
|
|
2761
|
+
readonly bind?: string;
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* The text syntax of a language (D41): an operator table, literal rules, reference syntax and call syntax. `parse`
|
|
2765
|
+
* reads a text into a document, and `print` writes a document as text. The profile is data, thus a site, an editor
|
|
2766
|
+
* and a language read the same rules.
|
|
2767
|
+
*/
|
|
2768
|
+
interface SyntaxProfile {
|
|
2769
|
+
/** The operators. */
|
|
2770
|
+
readonly operators?: readonly SyntaxOperator[];
|
|
2771
|
+
/** The literal rules. */
|
|
2772
|
+
readonly literals?: SyntaxLiterals;
|
|
2773
|
+
/** The reference syntax. */
|
|
2774
|
+
readonly refs?: SyntaxRefs;
|
|
2775
|
+
/** The call syntax. */
|
|
2776
|
+
readonly calls?: SyntaxCalls;
|
|
2777
|
+
/** The text of the header of a document. */
|
|
2778
|
+
readonly header?: SyntaxHeader;
|
|
2779
|
+
/** The deepest nesting that `parse` accepts. The default is `256`. */
|
|
2780
|
+
readonly maxDepth?: number;
|
|
2781
|
+
}
|
|
2782
|
+
/** A problem of a text: its character offset, its length and a message. */
|
|
2783
|
+
interface SyntaxIssue {
|
|
2784
|
+
/** The 0-based character offset of the problem. */
|
|
2785
|
+
readonly offset: number;
|
|
2786
|
+
/** The number of characters of the problem. `0` marks a place between two characters. */
|
|
2787
|
+
readonly length: number;
|
|
2788
|
+
/** The message. */
|
|
2789
|
+
readonly message: string;
|
|
2790
|
+
}
|
|
2791
|
+
/** The result of `parse`: a document, or the problems of the text. */
|
|
2792
|
+
type ParseResult = {
|
|
2793
|
+
readonly ok: true;
|
|
2794
|
+
readonly doc: Json;
|
|
2795
|
+
} | {
|
|
2796
|
+
readonly ok: false;
|
|
2797
|
+
readonly issues: readonly SyntaxIssue[];
|
|
2798
|
+
};
|
|
2799
|
+
/**
|
|
2800
|
+
* The standard syntax of the formula kit. It gives the site and the playground a text form. The operators are
|
|
2801
|
+
* `or`, `and`, `not`, the comparisons, `+ - * / %`, a minus sign and `^`, from the loosest to the tightest. A call
|
|
2802
|
+
* `name(args)` applies the operation `ops.name`. `if(test, then, else)` and `list(items)` make the constructs. The
|
|
2803
|
+
* text `total = 2 + 3` gives the document the header name `total` (D62).
|
|
2804
|
+
*/
|
|
2805
|
+
export declare const STD_SYNTAX: SyntaxProfile;
|
|
2806
|
+
/**
|
|
2807
|
+
* This function reads a text into a document with the rules of a profile (SYNTAX.PARSE). It does not throw for a
|
|
2808
|
+
* bad text. The issue gives the offset, the length and a message (SYNTAX.SPAN).
|
|
2809
|
+
*
|
|
2810
|
+
* @param profile - The syntax profile.
|
|
2811
|
+
* @param text - The text.
|
|
2812
|
+
* @returns The document, or the issues of the text.
|
|
2813
|
+
* @throws {TypeError} The profile is not valid, for example an operator has two entries of the same place.
|
|
2814
|
+
*/
|
|
2815
|
+
export declare function parse(profile: SyntaxProfile, text: string): ParseResult;
|
|
2816
|
+
/**
|
|
2817
|
+
* This function writes a document as text with the rules of a profile (SYNTAX.PRINT). It writes the fewest
|
|
2818
|
+
* parentheses that keep the tree. `parse` reads the text back to the same document (SYNTAX.ROUNDTRIP).
|
|
2819
|
+
*
|
|
2820
|
+
* @param profile - The syntax profile.
|
|
2821
|
+
* @param doc - The document.
|
|
2822
|
+
* @returns The text, or `#VALUE!` at the place of a document that the profile cannot write.
|
|
2823
|
+
* @throws {TypeError} The profile is not valid.
|
|
2824
|
+
*/
|
|
2825
|
+
export declare function print(profile: SyntaxProfile, doc: unknown): Result<string>;
|
|
2826
|
+
/**
|
|
2827
|
+
* This function makes the part of a merge that adds the verb `format` to a machine (D23, D41). Its default writes
|
|
2828
|
+
* each document with the printer of the profile. A part gives its own text through the ladder, thus an own entry or
|
|
2829
|
+
* a kind entry of `format` still wins.
|
|
2830
|
+
*
|
|
2831
|
+
* @param profile - The syntax profile.
|
|
2832
|
+
* @returns The part for `mergeMachines`.
|
|
2833
|
+
*/
|
|
2834
|
+
export declare function syntaxFormat(profile: SyntaxProfile): MachinePart;
|
|
2569
2835
|
/**
|
|
2570
2836
|
* The world of the examples: small kinds for numbers, lists, conditions, names, sequences and effects.
|
|
2571
2837
|
* Each kind names an evaluator for `eval` and a view for `view`. The site draws each document with its view.
|
|
2572
2838
|
*/
|
|
2573
2839
|
export declare const STD_WORLD: World;
|
|
2840
|
+
/**
|
|
2841
|
+
* The text syntax of the standard world (K162, D64). The syntax kit (D41) reads it, thus a host of `STD_WORLD` does
|
|
2842
|
+
* not write its own profile. The operators `>`, `+` and `*` make `greater`, `add` and `multiply`. A call form makes
|
|
2843
|
+
* each other kind, and `ref` uses the reference syntax of the kit.
|
|
2844
|
+
*
|
|
2845
|
+
* A literal in a place that takes a document gets its data envelope (K159, D65). Such a place is a part of `if`,
|
|
2846
|
+
* `list`, `seq` or `pure`, the value of `write`, or the whole text. The document after a header name is such a place
|
|
2847
|
+
* too. Thus `list(1, "a")` evaluates to `[1, "a"]`. The forms `add`, `multiply` and `greater` write an operator document that its operator
|
|
2848
|
+
* does not write, for example `add(5)` (K163).
|
|
2849
|
+
*
|
|
2850
|
+
* A host with more kinds spreads this profile and adds its forms to `calls.forms`. `STD_SYNTAX` stays the profile of
|
|
2851
|
+
* the formula kit.
|
|
2852
|
+
*/
|
|
2853
|
+
export declare const WORLD_SYNTAX: SyntaxProfile;
|
|
2574
2854
|
/** The code of the evaluators of the standard world, by name. */
|
|
2575
2855
|
export declare const STD_EVALUATORS: Readonly<Record<string, Evaluator>>;
|
|
2576
2856
|
/** The rungs of the ladder of an attribute, in their order (TREE.LADDER, D42). */
|
|
@@ -2641,8 +2921,6 @@ export declare const STD_RUNNERS: Readonly<Record<string, Runner>>;
|
|
|
2641
2921
|
export declare const STD_MACHINE: Machine;
|
|
2642
2922
|
/** The capabilities of the examples at the root: the two effects of the standard world. */
|
|
2643
2923
|
export declare const STD_CAPS: readonly string[];
|
|
2644
|
-
//#endregion
|
|
2645
|
-
//#region src/order.d.ts
|
|
2646
2924
|
/** One step of a sequence: its name, the names of the earlier steps that it reads, and if it has an effect. */
|
|
2647
2925
|
interface StepSpec {
|
|
2648
2926
|
readonly id: string;
|
|
@@ -2697,8 +2975,6 @@ export declare function isAllowedOrder(steps: readonly StepSpec[], order: readon
|
|
|
2697
2975
|
* @returns The layers, first to last. Each layer keeps the written order.
|
|
2698
2976
|
*/
|
|
2699
2977
|
export declare function layers(steps: readonly StepSpec[]): readonly (readonly string[])[];
|
|
2700
|
-
//#endregion
|
|
2701
|
-
//#region src/context.d.ts
|
|
2702
2978
|
/** The parts of a context. A term can reach outside itself only through these parts. */
|
|
2703
2979
|
export declare const PARTS: readonly ["self", "names", "world", "event", "caps"];
|
|
2704
2980
|
/** One part of a context. */
|
|
@@ -2742,8 +3018,6 @@ interface Construct {
|
|
|
2742
3018
|
}
|
|
2743
3019
|
/** Six constructs that show the range of the context. */
|
|
2744
3020
|
export declare const CONSTRUCTS: readonly Construct[];
|
|
2745
|
-
//#endregion
|
|
2746
|
-
//#region src/effects.d.ts
|
|
2747
3021
|
/** The options of `effectsOf`. */
|
|
2748
3022
|
interface EffectsOptions {
|
|
2749
3023
|
/** The type of a bare root value. */
|
|
@@ -2789,8 +3063,6 @@ export declare function effectsOf(machine: Machine, doc: unknown, options?: Effe
|
|
|
2789
3063
|
* @returns The issues, in the order of the body.
|
|
2790
3064
|
*/
|
|
2791
3065
|
export declare function checkLatent(machine: Machine, declared: readonly Cap[], body: unknown, options?: Omit<EffectsOptions, "caps">): readonly Issue[];
|
|
2792
|
-
//#endregion
|
|
2793
|
-
//#region src/formula.d.ts
|
|
2794
3066
|
/** An operation of a formula language: a function of the values of its arguments. */
|
|
2795
3067
|
type OpFn = (...args: never[]) => unknown;
|
|
2796
3068
|
/**
|
|
@@ -2810,8 +3082,13 @@ type ExtFn = (data: Json, context: Context, domains?: Readonly<Record<string, Do
|
|
|
2810
3082
|
* - `lazy`: the operations that evaluate their arguments themselves.
|
|
2811
3083
|
* - `ext`: the extensions of the namespace `ext`, by their name. The kit has `ext.undefined`, `ext.number` and
|
|
2812
3084
|
* `ext.domain`.
|
|
3085
|
+
* - `extTypes`: the value type of each extension of `ext`, by its name, for a check of types (TYPE.EXT, D103). An
|
|
3086
|
+
* extension without an entry gives `unknown` (TYPE.GRADUAL). An entry for a standard extension has no effect.
|
|
2813
3087
|
* - `truthy`: the truth of a value for `if`, `and` and `or`. `undefined` is an error `#VALUE!`. The default
|
|
2814
3088
|
* accepts only `true` and `false`.
|
|
3089
|
+
* - `truthType`: the value type of a truth for the own `truthy`, for a check of types (TYPE.TRUTH, D81). A test of
|
|
3090
|
+
* `if` and each term of `and` and `or` must fit it. Without it, the check accepts each type there. A profile without
|
|
3091
|
+
* `truthy` ignores it, because the default truth needs `bool`.
|
|
2815
3092
|
* - `otherwise`: the value of an `if` without `else`. The default is `null`. A profile with this key gives its value,
|
|
2816
3093
|
* also `undefined`.
|
|
2817
3094
|
* - `logic`: what `and` and `or` give: a truth value (the default), or the value that decided.
|
|
@@ -2829,13 +3106,16 @@ type ExtFn = (data: Json, context: Context, domains?: Readonly<Record<string, Do
|
|
|
2829
3106
|
* overloads. An operation without a signature takes and gives `unknown` (TYPE.GRADUAL).
|
|
2830
3107
|
*
|
|
2831
3108
|
* A check of types trusts the signatures. Each operation must give a member of the result of each signature that
|
|
2832
|
-
* its arguments match. The hook `check` must keep each result in that type.
|
|
3109
|
+
* its arguments match. The hook `check` must keep each result in that type. The function `truthy` must give a truth
|
|
3110
|
+
* for each member of `truthType`. Each extension must give a member of its type in `extTypes`.
|
|
2833
3111
|
*/
|
|
2834
3112
|
interface FormulaProfile {
|
|
2835
3113
|
readonly ops?: Readonly<Record<string, OpFn>> | ((name: string) => OpFn | undefined);
|
|
2836
3114
|
readonly lazy?: Readonly<Record<string, LazyOp>>;
|
|
2837
3115
|
readonly ext?: Readonly<Record<string, ExtFn>>;
|
|
3116
|
+
readonly extTypes?: Readonly<Record<string, ValueType>>;
|
|
2838
3117
|
readonly truthy?: (value: unknown) => boolean | undefined;
|
|
3118
|
+
readonly truthType?: ValueType;
|
|
2839
3119
|
readonly otherwise?: unknown;
|
|
2840
3120
|
readonly logic?: "boolean" | "value";
|
|
2841
3121
|
readonly omit?: (error: EvalError) => boolean;
|
|
@@ -2955,8 +3235,6 @@ export declare function formulaFacts(profile?: FormulaProfile): (path: readonly
|
|
|
2955
3235
|
* @throws {MergeError} The language and the kit have a conflict.
|
|
2956
3236
|
*/
|
|
2957
3237
|
export declare function formulaMachine(profile?: FormulaProfile, more?: MachinePart): Machine;
|
|
2958
|
-
//#endregion
|
|
2959
|
-
//#region src/codec.d.ts
|
|
2960
3238
|
/** The domains of a machine, by their names. */
|
|
2961
3239
|
type Domains = Readonly<Record<string, Domain>> | undefined;
|
|
2962
3240
|
/**
|
|
@@ -2993,153 +3271,6 @@ export declare function encodeValue(machine: Pick<Machine, "domains">, value: un
|
|
|
2993
3271
|
* @returns The value, or the error of the evaluation.
|
|
2994
3272
|
*/
|
|
2995
3273
|
export declare function decodeValue(machine: Machine, doc: unknown): Result;
|
|
2996
|
-
//#endregion
|
|
2997
|
-
//#region src/syntax.d.ts
|
|
2998
|
-
/** The place of an operator: before its term, between two terms, or after its term. */
|
|
2999
|
-
type SyntaxFixity = "prefix" | "infix" | "postfix";
|
|
3000
|
-
/**
|
|
3001
|
-
* The grouping of a chain of one infix operator. `left` reads `a - b - c` as `(a - b) - c`, and `right` reads
|
|
3002
|
-
* `a ^ b ^ c` as `a ^ (b ^ c)`. `none` refuses a chain. `flat` reads a chain as one document with each term.
|
|
3003
|
-
*/
|
|
3004
|
-
type SyntaxAssoc = "left" | "right" | "none" | "flat";
|
|
3005
|
-
/** One operator of a syntax profile. */
|
|
3006
|
-
interface SyntaxOperator {
|
|
3007
|
-
/** The text of the operator, for example `+`, `<>` or `and`. A word operator is a plain name. */
|
|
3008
|
-
readonly symbol: string;
|
|
3009
|
-
/** The place of the operator. */
|
|
3010
|
-
readonly fixity: SyntaxFixity;
|
|
3011
|
-
/** The precedence. A larger number binds more tightly. */
|
|
3012
|
-
readonly prec: number;
|
|
3013
|
-
/** The grouping of a chain of an infix operator. The default is `left`. */
|
|
3014
|
-
readonly assoc?: SyntaxAssoc;
|
|
3015
|
-
/** The type of the document that the operator makes, with dots between the keys, for example `ops.add` or `and`. */
|
|
3016
|
-
readonly kind: string;
|
|
3017
|
-
}
|
|
3018
|
-
/** The literal rules of a syntax profile. */
|
|
3019
|
-
interface SyntaxLiterals {
|
|
3020
|
-
/** `false` removes the decimal numbers. The default is `true`. */
|
|
3021
|
-
readonly numbers?: boolean;
|
|
3022
|
-
/** `true` puts a minus sign right before a digit into the number, where a term starts. The default is `true`. */
|
|
3023
|
-
readonly signed?: boolean;
|
|
3024
|
-
/** The texts: the quote and the escape of a quote. `false` removes the texts. The default is `"` with backslashes. */
|
|
3025
|
-
readonly strings?: false | {
|
|
3026
|
-
readonly quote?: "\"" | "'";
|
|
3027
|
-
readonly escape?: "backslash" | "double";
|
|
3028
|
-
};
|
|
3029
|
-
/** The words that are literals, with their values. The default is `true`, `false` and `null`. */
|
|
3030
|
-
readonly words?: Readonly<Record<string, unknown>>;
|
|
3031
|
-
}
|
|
3032
|
-
/** A reference syntax that a pattern gives, for example the address `A1` of a cell. */
|
|
3033
|
-
interface SyntaxRefPattern {
|
|
3034
|
-
/** The pattern of the text of a reference. The parser tries it before a name. */
|
|
3035
|
-
readonly pattern: RegExp;
|
|
3036
|
-
/** This function gives the path of the reference from its text. */
|
|
3037
|
-
readonly read: (text: string) => readonly Key[];
|
|
3038
|
-
/** This function gives the text of a path, or `undefined` when the pattern does not write the path. */
|
|
3039
|
-
readonly write: (path: readonly unknown[]) => string | undefined;
|
|
3040
|
-
}
|
|
3041
|
-
/** The reference syntax of a syntax profile. */
|
|
3042
|
-
interface SyntaxRefs {
|
|
3043
|
-
/** The root of a bare name. The default is `names`. Thus `x` is the path `["names", "x"]`. */
|
|
3044
|
-
readonly bare?: string;
|
|
3045
|
-
/** The roots that the text names first, for example `self.price`. The default is `self`, `world`, `event` and `caps`. */
|
|
3046
|
-
readonly roots?: readonly string[];
|
|
3047
|
-
/** `false` removes the field steps `a.b`. The default is `true`. */
|
|
3048
|
-
readonly fields?: boolean;
|
|
3049
|
-
/** The patterns of other references. */
|
|
3050
|
-
readonly patterns?: readonly SyntaxRefPattern[];
|
|
3051
|
-
}
|
|
3052
|
-
/** A call form: a name with arguments in parentheses that makes a construct, for example `if(test, then, else)`. */
|
|
3053
|
-
interface SyntaxForm {
|
|
3054
|
-
/** The name in the text. */
|
|
3055
|
-
readonly name: string;
|
|
3056
|
-
/** The type of the document, with dots between the keys. */
|
|
3057
|
-
readonly kind: string;
|
|
3058
|
-
/** The fields of the value, in the order of the arguments. Without them, the value is the list of the arguments. */
|
|
3059
|
-
readonly fields?: readonly string[];
|
|
3060
|
-
/** The smallest number of arguments. The default is the number of the fields, or `0`. */
|
|
3061
|
-
readonly min?: number;
|
|
3062
|
-
}
|
|
3063
|
-
/** The call syntax of a syntax profile. */
|
|
3064
|
-
interface SyntaxCalls {
|
|
3065
|
-
/** The operations that a call `name(args)` can name. `true` permits each name. The default is `true`. */
|
|
3066
|
-
readonly ops?: boolean | readonly string[];
|
|
3067
|
-
/** The call forms of constructs. A form wins over an operation with the same name. */
|
|
3068
|
-
readonly forms?: readonly SyntaxForm[];
|
|
3069
|
-
/** The text between two arguments. The default is `,`. */
|
|
3070
|
-
readonly separator?: string;
|
|
3071
|
-
}
|
|
3072
|
-
/**
|
|
3073
|
-
* The text syntax of a language (D41): an operator table, literal rules, reference syntax and call syntax. `parse`
|
|
3074
|
-
* reads a text into a document, and `print` writes a document as text. The profile is data, thus a site, an editor
|
|
3075
|
-
* and a language read the same rules.
|
|
3076
|
-
*/
|
|
3077
|
-
interface SyntaxProfile {
|
|
3078
|
-
/** The operators. */
|
|
3079
|
-
readonly operators?: readonly SyntaxOperator[];
|
|
3080
|
-
/** The literal rules. */
|
|
3081
|
-
readonly literals?: SyntaxLiterals;
|
|
3082
|
-
/** The reference syntax. */
|
|
3083
|
-
readonly refs?: SyntaxRefs;
|
|
3084
|
-
/** The call syntax. */
|
|
3085
|
-
readonly calls?: SyntaxCalls;
|
|
3086
|
-
/** The deepest nesting that `parse` accepts. The default is `256`. */
|
|
3087
|
-
readonly maxDepth?: number;
|
|
3088
|
-
}
|
|
3089
|
-
/** A problem of a text: its character offset, its length and a message. */
|
|
3090
|
-
interface SyntaxIssue {
|
|
3091
|
-
/** The 0-based character offset of the problem. */
|
|
3092
|
-
readonly offset: number;
|
|
3093
|
-
/** The number of characters of the problem. `0` marks a place between two characters. */
|
|
3094
|
-
readonly length: number;
|
|
3095
|
-
/** The message. */
|
|
3096
|
-
readonly message: string;
|
|
3097
|
-
}
|
|
3098
|
-
/** The result of `parse`: a document, or the problems of the text. */
|
|
3099
|
-
type ParseResult = {
|
|
3100
|
-
readonly ok: true;
|
|
3101
|
-
readonly doc: Json;
|
|
3102
|
-
} | {
|
|
3103
|
-
readonly ok: false;
|
|
3104
|
-
readonly issues: readonly SyntaxIssue[];
|
|
3105
|
-
};
|
|
3106
|
-
/**
|
|
3107
|
-
* The standard syntax of the formula kit. It gives the site and the playground a text form. The operators are
|
|
3108
|
-
* `or`, `and`, `not`, the comparisons, `+ - * / %`, a minus sign and `^`, from the loosest to the tightest. A call
|
|
3109
|
-
* `name(args)` applies the operation `ops.name`. `if(test, then, else)` and `list(items)` make the constructs.
|
|
3110
|
-
*/
|
|
3111
|
-
export declare const STD_SYNTAX: SyntaxProfile;
|
|
3112
|
-
/**
|
|
3113
|
-
* This function reads a text into a document with the rules of a profile (SYNTAX.PARSE). It does not throw for a
|
|
3114
|
-
* bad text. The issue gives the offset, the length and a message (SYNTAX.SPAN).
|
|
3115
|
-
*
|
|
3116
|
-
* @param profile - The syntax profile.
|
|
3117
|
-
* @param text - The text.
|
|
3118
|
-
* @returns The document, or the issues of the text.
|
|
3119
|
-
* @throws {TypeError} The profile is not valid, for example an operator has two entries of the same place.
|
|
3120
|
-
*/
|
|
3121
|
-
export declare function parse(profile: SyntaxProfile, text: string): ParseResult;
|
|
3122
|
-
/**
|
|
3123
|
-
* This function writes a document as text with the rules of a profile (SYNTAX.PRINT). It writes the fewest
|
|
3124
|
-
* parentheses that keep the tree. `parse` reads the text back to the same document (SYNTAX.ROUNDTRIP).
|
|
3125
|
-
*
|
|
3126
|
-
* @param profile - The syntax profile.
|
|
3127
|
-
* @param doc - The document.
|
|
3128
|
-
* @returns The text, or `#VALUE!` at the place of a document that the profile cannot write.
|
|
3129
|
-
* @throws {TypeError} The profile is not valid.
|
|
3130
|
-
*/
|
|
3131
|
-
export declare function print(profile: SyntaxProfile, doc: unknown): Result<string>;
|
|
3132
|
-
/**
|
|
3133
|
-
* This function makes the part of a merge that adds the verb `format` to a machine (D23, D41). Its default writes
|
|
3134
|
-
* each document with the printer of the profile. A part gives its own text through the ladder, thus an own entry or
|
|
3135
|
-
* a kind entry of `format` still wins.
|
|
3136
|
-
*
|
|
3137
|
-
* @param profile - The syntax profile.
|
|
3138
|
-
* @returns The part for `mergeMachines`.
|
|
3139
|
-
*/
|
|
3140
|
-
export declare function syntaxFormat(profile: SyntaxProfile): MachinePart;
|
|
3141
|
-
//#endregion
|
|
3142
|
-
//#region src/reference.d.ts
|
|
3143
3274
|
/**
|
|
3144
3275
|
* The definitional code of the reference, by evaluator name. The reference cannot read compiled code, thus each
|
|
3145
3276
|
* compiled evaluator or runner of a machine needs a definition here. A function evaluator needs none.
|
|
@@ -3163,6 +3294,12 @@ interface ReferenceOptions {
|
|
|
3163
3294
|
* each verb by the same rules (VERB.AGREE).
|
|
3164
3295
|
*/
|
|
3165
3296
|
readonly verb?: string;
|
|
3297
|
+
/**
|
|
3298
|
+
* A list that gets each read of a resolution, in its order (REF.READS). A read has the shape of a read of a plan:
|
|
3299
|
+
* the path, what it reached and the mark `free`. The reads of a closure and of an equation of a tree go in the
|
|
3300
|
+
* same list. The reference adds no kept reads, because it has no static reads of a closure.
|
|
3301
|
+
*/
|
|
3302
|
+
readonly reads?: Read[];
|
|
3166
3303
|
}
|
|
3167
3304
|
/** The options of a run of the reference: the options of an evaluation, with the host and a signal (REF.RUN). */
|
|
3168
3305
|
interface ReferenceRunOptions extends ReferenceOptions {
|
|
@@ -3219,8 +3356,6 @@ export declare const STD_DEFINITIONS: Definitions;
|
|
|
3219
3356
|
* @returns The definitions, by evaluator name.
|
|
3220
3357
|
*/
|
|
3221
3358
|
export declare function formulaDefinitions(profile?: FormulaProfile): Definitions;
|
|
3222
|
-
//#endregion
|
|
3223
|
-
//#region src/agree.d.ts
|
|
3224
3359
|
/**
|
|
3225
3360
|
* A tier that `agree` compares with the plan.
|
|
3226
3361
|
*
|
|
@@ -3302,6 +3437,11 @@ type Agreement = {
|
|
|
3302
3437
|
readonly ok: true;
|
|
3303
3438
|
readonly result: Result;
|
|
3304
3439
|
readonly effects: readonly Effect[];
|
|
3440
|
+
/**
|
|
3441
|
+
* The free reads of the plan that `agreeRun` compared with the reference run (RUN.AGREES-READS). It is absent
|
|
3442
|
+
* when no read compared, for example in `agree`.
|
|
3443
|
+
*/
|
|
3444
|
+
readonly reads?: readonly Read[];
|
|
3305
3445
|
} | {
|
|
3306
3446
|
readonly ok: false;
|
|
3307
3447
|
readonly tier: Tier;
|
|
@@ -3360,6 +3500,13 @@ interface AgreeRunOptions extends Omit<AgreeOptions, "other" | "perform"> {
|
|
|
3360
3500
|
* The rules of `agree` compare the results and the effects, with their addresses and outcomes. A tier must also
|
|
3361
3501
|
* settle the waits of each `all` in the order of the plan, thus a replay keeps the order of the waits.
|
|
3362
3502
|
*
|
|
3503
|
+
* The reference run must also give the free reads of the plan, in their order (RUN.AGREES-READS). Another replay of
|
|
3504
|
+
* the plan records these reads. A kept read does not compare. When the plan keeps each root, its reads are not known,
|
|
3505
|
+
* and no read compares.
|
|
3506
|
+
*
|
|
3507
|
+
* One replayer of the log serves each tier and the replay for the reads (RUN.AGREES-ONE-REPLAYER). The replayer keeps
|
|
3508
|
+
* no state of a run (RUN.REPLAY-RUNS), thus each tier replays the same log as with a replayer of its own.
|
|
3509
|
+
*
|
|
3363
3510
|
* @param machine - The world, the evaluators and the runners.
|
|
3364
3511
|
* @param doc - The document.
|
|
3365
3512
|
* @param context - The names and the capabilities at the root.
|
|
@@ -3367,8 +3514,6 @@ interface AgreeRunOptions extends Omit<AgreeOptions, "other" | "perform"> {
|
|
|
3367
3514
|
* @returns The result of the plan, or the first tier that disagrees and the reason.
|
|
3368
3515
|
*/
|
|
3369
3516
|
export declare function agreeRun(machine: Machine, doc: unknown, context?: Context, options?: AgreeRunOptions): Promise<Agreement>;
|
|
3370
|
-
//#endregion
|
|
3371
|
-
//#region src/conform.d.ts
|
|
3372
3517
|
/**
|
|
3373
3518
|
* An obligation that `conforms` checks. `C1` to `C8` are the obligations of host code in `docs/SEMANTICS.md`. `local`
|
|
3374
3519
|
* and `agree` are two premises of the simulation of the plan (SIM-PLAN).
|
|
@@ -3383,8 +3528,12 @@ export declare function agreeRun(machine: Machine, doc: unknown, context?: Conte
|
|
|
3383
3528
|
* - `C8`: compiled code gives the result of code that compiles again at the time of the evaluation.
|
|
3384
3529
|
* - `local`: the code keeps no state from one call to the next.
|
|
3385
3530
|
* - `agree`: compiled code gives the result of its definition for the reference interpreter.
|
|
3531
|
+
* - `truth`: the own `truthy` of a formula profile gives `true` or `false` for each member of its `truthType` (D86).
|
|
3532
|
+
* Only `formula.if`, `formula.and` and `formula.or` of the formula kit get this check.
|
|
3533
|
+
* - `cover`: each sample of a covered domain of the machine is in one domain of each cover of the domain (D94). Each
|
|
3534
|
+
* evaluator and each runner gets this check, because `fits` trusts the covers for each program.
|
|
3386
3535
|
*/
|
|
3387
|
-
type Obligation = "C1" | "C2" | "C3" | "C4" | "C5" | "C6" | "C7" | "C8" | "local" | "agree";
|
|
3536
|
+
type Obligation = "C1" | "C2" | "C3" | "C4" | "C5" | "C6" | "C7" | "C8" | "local" | "agree" | "truth" | "cover";
|
|
3388
3537
|
/** The probe of a finding: the document, the result of each probe part, the capabilities and the handler. */
|
|
3389
3538
|
interface ConformProbe {
|
|
3390
3539
|
/** The text of the type of the document. */
|
|
@@ -3461,8 +3610,11 @@ interface ConformOptions {
|
|
|
3461
3610
|
*
|
|
3462
3611
|
* The checks follow the obligations C1 to C8 of `docs/SEMANTICS.md`. Two more checks follow the premises of the
|
|
3463
3612
|
* simulation of the plan. The check `local` finds state that stays from one call to the next. The check `agree` compares
|
|
3464
|
-
* compiled code with its definition. The
|
|
3465
|
-
*
|
|
3613
|
+
* compiled code with its definition. The finding of an obligation names the first probe that breaks it. An empty list
|
|
3614
|
+
* means that each probe conforms.
|
|
3615
|
+
*
|
|
3616
|
+
* The check `truth` tests the declared truth of a formula profile (D86). The check `cover` tests the covers of the
|
|
3617
|
+
* domains of the machine from samples (D94).
|
|
3466
3618
|
*
|
|
3467
3619
|
* @param machine - The machine with the code and the world of the kinds.
|
|
3468
3620
|
* @param name - The name of the evaluator or of the runner. A runner wins over an evaluator of the same name.
|
|
@@ -3472,8 +3624,6 @@ interface ConformOptions {
|
|
|
3472
3624
|
* @throws {Error} The machine has no code with the name, or no kind names it and the options give no types.
|
|
3473
3625
|
*/
|
|
3474
3626
|
export declare function conforms(machine: Machine, name: string, options?: ConformOptions): readonly Finding[];
|
|
3475
|
-
//#endregion
|
|
3476
|
-
//#region src/same.d.ts
|
|
3477
3627
|
/**
|
|
3478
3628
|
* This function tells if two results are the same for an early cutoff (RESULT.SAME). A schedule uses it to stop the
|
|
3479
3629
|
* work when a part that evaluates again gives the same result. A wrong `true` keeps a stale value, but a wrong `false`
|
|
@@ -3495,8 +3645,6 @@ export declare function conforms(machine: Machine, name: string, options?: Confo
|
|
|
3495
3645
|
* @returns `true` when the results are the same.
|
|
3496
3646
|
*/
|
|
3497
3647
|
export declare function sameResult(a: Result<unknown>, b: Result<unknown>, equal?: (a: unknown, b: unknown) => boolean | undefined): boolean;
|
|
3498
|
-
//#endregion
|
|
3499
|
-
//#region src/reads.d.ts
|
|
3500
3648
|
/** The answer of `verifyReads`: the old result stays valid, or the first read that reaches another thing. */
|
|
3501
3649
|
type ReadsCheck = {
|
|
3502
3650
|
readonly same: true;
|
|
@@ -3545,8 +3693,6 @@ interface VerifyOptions {
|
|
|
3545
3693
|
* @returns `{ same: true }` when each free read reaches the same thing, or else the first changed read.
|
|
3546
3694
|
*/
|
|
3547
3695
|
export declare function verifyReads(target: Machine | Plan, reads: readonly Read[], context: Context, options?: VerifyOptions): ReadsCheck;
|
|
3548
|
-
//#endregion
|
|
3549
|
-
//#region src/durable.d.ts
|
|
3550
3696
|
/** The two epochs of a host (DURABLE.EPOCHS). Each epoch counts the changes of its level. */
|
|
3551
3697
|
interface Epochs {
|
|
3552
3698
|
/** The count of the changes of the structure: a new machine, or an edit of a document. */
|
|
@@ -3654,8 +3800,6 @@ interface Durable {
|
|
|
3654
3800
|
* @returns The cache.
|
|
3655
3801
|
*/
|
|
3656
3802
|
export declare function durable(machine: Machine, options?: DurableOptions): Durable;
|
|
3657
|
-
//#endregion
|
|
3658
|
-
//#region src/schedule.d.ts
|
|
3659
3803
|
/** One edge of a graph of nodes: a static read of a node from the document of another node (SCHED.EDGES). */
|
|
3660
3804
|
interface NodeEdge {
|
|
3661
3805
|
/**
|
|
@@ -3810,8 +3954,6 @@ export declare function edgesOf(facts: DocFacts): readonly NodeEdge[];
|
|
|
3810
3954
|
* @returns The schedule.
|
|
3811
3955
|
*/
|
|
3812
3956
|
export declare function schedule(machine: Machine, options?: ScheduleOptions): Schedule;
|
|
3813
|
-
//#endregion
|
|
3814
|
-
//#region src/generate.d.ts
|
|
3815
3957
|
/** A source of random numbers with a seed. The same seed gives the same numbers. */
|
|
3816
3958
|
interface Random {
|
|
3817
3959
|
/** This function gives a number from 0 up to 1, without 1. */
|
|
@@ -3891,8 +4033,6 @@ export declare function typesOf(world: World): readonly (readonly Key[])[];
|
|
|
3891
4033
|
* @returns The document, as JSON.
|
|
3892
4034
|
*/
|
|
3893
4035
|
export declare function generate(world: World, options: GenerateOptions): unknown;
|
|
3894
|
-
//#endregion
|
|
3895
|
-
//#region src/meaning.d.ts
|
|
3896
4036
|
/**
|
|
3897
4037
|
* The smallest interface of the engine of a host that `agreeSchedule` examines (SCHED.AGREES). The demand schedule of
|
|
3898
4038
|
* `schedule` has this interface.
|
|
@@ -4073,8 +4213,6 @@ type ScheduleAgreement = {
|
|
|
4073
4213
|
* @returns What the harness reached, or the first read whose answer differs from the answer from scratch.
|
|
4074
4214
|
*/
|
|
4075
4215
|
export declare function agreeSchedule(engine: ScheduleEngineFactory, options?: AgreeScheduleOptions): ScheduleAgreement;
|
|
4076
|
-
//#endregion
|
|
4077
|
-
//#region src/graph.d.ts
|
|
4078
4216
|
/** One edge of a graph of nodes: a read of a node by another node. `NodeEdge` of a schedule is such an edge. */
|
|
4079
4217
|
interface GraphEdge<Id> {
|
|
4080
4218
|
/** The node that the read reaches. It is `undefined` when the read can reach each node (GRAPH.UNKNOWN). */
|
|
@@ -4174,8 +4312,6 @@ export declare function necessary<Id>(graph: NodeGraph<Id>, observed: Iterable<I
|
|
|
4174
4312
|
* @returns The cycles, deepest first.
|
|
4175
4313
|
*/
|
|
4176
4314
|
export declare function cycles<Id>(graph: NodeGraph<Id>): readonly GraphCycle<Id>[];
|
|
4177
|
-
//#endregion
|
|
4178
|
-
//#region src/replay.d.ts
|
|
4179
4315
|
/** One effect of a log: its address, its request and its outcome. */
|
|
4180
4316
|
interface ReplayEntry {
|
|
4181
4317
|
/** The address of the effect (RUN.ADDRESS), for example `1#0` or `all0.1/1#0`. */
|
|
@@ -4218,12 +4354,21 @@ interface ReplayOptions {
|
|
|
4218
4354
|
* value, because it does not wait. The default is `true`: an effect waits when it waited in the recorded run.
|
|
4219
4355
|
*/
|
|
4220
4356
|
readonly wait?: boolean;
|
|
4357
|
+
/**
|
|
4358
|
+
* The rule of the host for two payloads that are not the same by `Object.is`: one of the run and one of the log.
|
|
4359
|
+
* It works as the rule of `sameResult`. Its `undefined` gives the rules of `docEquals`. A log from `decodeLog` holds new copies
|
|
4360
|
+
* of the members of a domain, for example of a time. The rule tells that two such copies are the same.
|
|
4361
|
+
*/
|
|
4362
|
+
readonly equal?: (a: unknown, b: unknown) => boolean | undefined;
|
|
4221
4363
|
}
|
|
4222
4364
|
/**
|
|
4223
4365
|
* This function makes a recorder (RUN.RECORD). The recorder gives each effect to the function `perform` of the host.
|
|
4224
4366
|
* Its log keeps each effect with its address, its kind, its payload and the outcome that the kernel gives it. The log
|
|
4225
4367
|
* also keeps the order in which the waits of each `all` settle.
|
|
4226
4368
|
*
|
|
4369
|
+
* The recorder gives each call of its journal to the journal of the inner function, for example of a replayer. Thus a
|
|
4370
|
+
* recording of a replay settles the waits in the order of the replayer, and it gives the same log (RUN.REPLAY-ORDER).
|
|
4371
|
+
*
|
|
4227
4372
|
* @param perform - The function of the host. Without it, each effect gives its payload, as in a run without a host.
|
|
4228
4373
|
* @returns The function `perform` for the run, and the log.
|
|
4229
4374
|
*/
|
|
@@ -4233,15 +4378,183 @@ export declare function recorder(perform?: Perform): Recorder;
|
|
|
4233
4378
|
* recorded error comes again with its code, its reason, its place and its cause. The waits of each `all` settle in the
|
|
4234
4379
|
* recorded order. An effect that the log does not have at its address gives `#REPLAY!` (RUN.REPLAY-MISMATCH).
|
|
4235
4380
|
*
|
|
4236
|
-
*
|
|
4381
|
+
* One replayer serves more than one run, also two runs at the same time (RUN.REPLAY-RUNS). The kernel tells the journal
|
|
4382
|
+
* the number of the waits of each `all` that settled before, thus the replayer keeps no state of a run. When the
|
|
4383
|
+
* recorded item of a wait does not wait in the run, that wait follows the order of the host.
|
|
4237
4384
|
*
|
|
4238
|
-
* @param log - The log of a recorder
|
|
4239
|
-
* @param options - `wait: false` for an evaluation.
|
|
4385
|
+
* @param log - The log of a recorder, or of `decodeLog`.
|
|
4386
|
+
* @param options - `wait: false` for an evaluation, and the rule of the host for payloads.
|
|
4240
4387
|
* @returns The function `perform` for the replay.
|
|
4241
4388
|
*/
|
|
4242
4389
|
export declare function replayer(log: ReplayLog, options?: ReplayOptions): Perform;
|
|
4243
|
-
|
|
4244
|
-
|
|
4390
|
+
/** The JSON form of a log (RUN.REPLAY-JSON). `encodeLog` writes it, and `decodeLog` reads it. */
|
|
4391
|
+
interface ReplayLogJson {
|
|
4392
|
+
/** The version of the form. Only the version 1 exists. */
|
|
4393
|
+
readonly version: 1;
|
|
4394
|
+
readonly effects: readonly ReplayEntryJson[];
|
|
4395
|
+
readonly settles: readonly ReplaySettle[];
|
|
4396
|
+
}
|
|
4397
|
+
/** The JSON form of one effect of a log. A value is a term document of `encodeValue` (D40). */
|
|
4398
|
+
interface ReplayEntryJson {
|
|
4399
|
+
readonly address: string;
|
|
4400
|
+
readonly kind: string;
|
|
4401
|
+
/** The term document of the payload. The value `undefined` is `ext.undefined`. */
|
|
4402
|
+
readonly payload: Json;
|
|
4403
|
+
/** The JSON form of the outcome. It is absent when the recorded run stopped before the answer came. */
|
|
4404
|
+
readonly outcome?: ReplayResultJson;
|
|
4405
|
+
readonly waited: boolean;
|
|
4406
|
+
}
|
|
4407
|
+
/** The JSON form of an outcome: the term document of the value, or the JSON form of the error. */
|
|
4408
|
+
type ReplayResultJson = {
|
|
4409
|
+
readonly ok: true;
|
|
4410
|
+
readonly value: Json;
|
|
4411
|
+
} | {
|
|
4412
|
+
readonly ok: false;
|
|
4413
|
+
readonly error: ReplayErrorJson;
|
|
4414
|
+
};
|
|
4415
|
+
/** The JSON form of an error value. It has `cause`, `exception` or `causeParts` only when the error has a cause. */
|
|
4416
|
+
interface ReplayErrorJson {
|
|
4417
|
+
readonly code: ErrorCode;
|
|
4418
|
+
readonly reason: string;
|
|
4419
|
+
readonly place?: readonly Key[];
|
|
4420
|
+
/** The term document of the cause, when `encodeValue` writes the cause. */
|
|
4421
|
+
readonly cause?: Json;
|
|
4422
|
+
/** The JSON form of a cause that is an exception, when no domain with a codec holds it. */
|
|
4423
|
+
readonly exception?: ReplayExceptionJson;
|
|
4424
|
+
/**
|
|
4425
|
+
* The JSON form of a cause without a term document that is a list or a plain record with an exception at some depth
|
|
4426
|
+
* (RUN.REPLAY-CAUSE-PARTS, D87). It is a list of parts, the part `record` or the part `share`. The index 0 of `loop` is its
|
|
4427
|
+
* first exception, and the index 0 of `share` is its first list or record. Since D101, a list or a record cause that
|
|
4428
|
+
* holds a container at two places is also `causeParts` (RUN.REPLAY-SHARED-VALUES).
|
|
4429
|
+
*/
|
|
4430
|
+
readonly causeParts?: ReplayCausePartsJson;
|
|
4431
|
+
/** The names of the items of `causeParts` without a form, for example `cause.send`. This list is only a note. */
|
|
4432
|
+
readonly dropped?: readonly string[];
|
|
4433
|
+
}
|
|
4434
|
+
/**
|
|
4435
|
+
* The JSON form of a cause without a term document that is a list or a plain record with an exception at some depth
|
|
4436
|
+
* (D87). It is a list of parts, the part `record` or the part `share`, as a field in `parts` (D82, D88).
|
|
4437
|
+
*/
|
|
4438
|
+
type ReplayCausePartsJson = readonly ReplayPartsJson[] | {
|
|
4439
|
+
readonly record: Readonly<Record<string, ReplayPartsJson>>;
|
|
4440
|
+
} | {
|
|
4441
|
+
readonly share: number;
|
|
4442
|
+
};
|
|
4443
|
+
/**
|
|
4444
|
+
* The JSON form of an exception (RUN.REPLAY-CAUSES, D76). The exceptions of an error and of their causes are a chain.
|
|
4445
|
+
* The index 0 of the chain is the exception of the error. Each field after `message` is optional, thus a log of the
|
|
4446
|
+
* version 1 without them stays correct.
|
|
4447
|
+
*/
|
|
4448
|
+
interface ReplayExceptionJson {
|
|
4449
|
+
readonly name: string;
|
|
4450
|
+
readonly message: string;
|
|
4451
|
+
/**
|
|
4452
|
+
* The term documents of the own fields of the exception that `encodeValue` writes, for example `code` or `errno`. A list
|
|
4453
|
+
* or a plain record that two places of the error share is in `parts` (RUN.REPLAY-SHARED-VALUES, D101).
|
|
4454
|
+
*/
|
|
4455
|
+
readonly fields?: Readonly<Record<string, Json>>;
|
|
4456
|
+
/**
|
|
4457
|
+
* The own enumerable fields without a term document that are an exception, a list or a plain record (RUN.REPLAY-FIELDS,
|
|
4458
|
+
* D78, D82). An example is a list `errors` on an `Error`. A list is a list of parts, and a record is the part `record`.
|
|
4459
|
+
* Each exception in them has the rule of a cause. A container without a form in it is a name in `dropped`. A container
|
|
4460
|
+
* that an earlier place holds is the part `share` (D88).
|
|
4461
|
+
*
|
|
4462
|
+
* Since D101, a shared container with a term document is in `parts` too, and so is each container that holds it.
|
|
4463
|
+
*/
|
|
4464
|
+
readonly parts?: Readonly<Record<string, ReplayPartsJson>>;
|
|
4465
|
+
/**
|
|
4466
|
+
* The names of the own fields without a form, and `cause` for a cause without a form. An item of a container has the
|
|
4467
|
+
* name of the container, a dot and its key or index, for example `errors.1` or `cause.send`. This list is only a note:
|
|
4468
|
+
* `decodeLog` does not give these fields back.
|
|
4469
|
+
*/
|
|
4470
|
+
readonly dropped?: readonly string[];
|
|
4471
|
+
/**
|
|
4472
|
+
* The own fields of the standard classes that are not enumerable (RUN.REPLAY-HIDDEN, D77): `errors` of an
|
|
4473
|
+
* `AggregateError`, `error` and `suppressed` of a `SuppressedError`. A list is a list of parts.
|
|
4474
|
+
*/
|
|
4475
|
+
readonly hidden?: Readonly<Record<string, ReplayPartsJson>>;
|
|
4476
|
+
/** The term document of the cause, when `encodeValue` writes the cause. */
|
|
4477
|
+
readonly cause?: Json;
|
|
4478
|
+
/** The JSON form of a cause that is an exception, when no domain with a codec holds it. */
|
|
4479
|
+
readonly exception?: ReplayExceptionJson;
|
|
4480
|
+
/** The index in the chain of an earlier exception that is the cause. Thus a cycle of causes stays exact. */
|
|
4481
|
+
readonly loop?: number;
|
|
4482
|
+
/**
|
|
4483
|
+
* The JSON form of a cause without a term document that is a list or a plain record with an exception at some depth
|
|
4484
|
+
* (RUN.REPLAY-CAUSE-PARTS, D87). Each exception in it has the rule of a cause, also a `loop`. Since D100, a list or a
|
|
4485
|
+
* record without an exception is also `causeParts` when an item has a form (RUN.REPLAY-CAUSE-ITEMS).
|
|
4486
|
+
*/
|
|
4487
|
+
readonly causeParts?: ReplayCausePartsJson;
|
|
4488
|
+
}
|
|
4489
|
+
/**
|
|
4490
|
+
* The JSON form of one value of a field in `parts` or `hidden` (D77, D78, D82). It is a term document, an exception, a
|
|
4491
|
+
* loop, a record of parts, or a share (D88). The walk is depth
|
|
4492
|
+
* first: the fields in `parts` in their order, the hidden fields, then the cause. The mark `dropped` keeps the place of
|
|
4493
|
+
* an item of a list without a form, and `decodeLog` gives a hole there.
|
|
4494
|
+
*
|
|
4495
|
+
* The part `share` is a list or a record of parts that an earlier place of the walk holds (RUN.REPLAY-SHARED, D88). Its
|
|
4496
|
+
* index counts the lists and the records of parts in the order of the walk. Thus `decodeLog` gives one object for both places.
|
|
4497
|
+
*/
|
|
4498
|
+
type ReplayPartJson = {
|
|
4499
|
+
readonly value: Json;
|
|
4500
|
+
} | {
|
|
4501
|
+
readonly exception: ReplayExceptionJson;
|
|
4502
|
+
} | {
|
|
4503
|
+
readonly loop: number;
|
|
4504
|
+
} | {
|
|
4505
|
+
readonly record: Readonly<Record<string, ReplayPartsJson>>;
|
|
4506
|
+
} | {
|
|
4507
|
+
readonly share: number;
|
|
4508
|
+
} | {
|
|
4509
|
+
readonly dropped: true;
|
|
4510
|
+
};
|
|
4511
|
+
/**
|
|
4512
|
+
* The JSON form of a value in `parts`, in `hidden` or in a record of parts (D82). It is one part, or a list of them. A
|
|
4513
|
+
* list in a list is a JSON list in a JSON list, thus the rule is the same at each depth.
|
|
4514
|
+
*/
|
|
4515
|
+
type ReplayPartsJson = ReplayPartJson | readonly ReplayPartsJson[];
|
|
4516
|
+
/**
|
|
4517
|
+
* This function writes a log as JSON (RUN.REPLAY-JSON, D75). Then `JSON.stringify` gives the text of a golden file.
|
|
4518
|
+
*
|
|
4519
|
+
* - Each payload and each value of an outcome is a term document of `encodeValue`. Thus `NaN`, `-0` and `undefined`
|
|
4520
|
+
* stay exact, and a member of a domain with a codec is `ext.domain`.
|
|
4521
|
+
* - An error keeps its code, its reason, its place and its cause. A cause that `encodeValue` cannot write and that is
|
|
4522
|
+
* an exception keeps its name and its message in the field `exception`.
|
|
4523
|
+
* - An exception also keeps its own fields that `encodeValue` writes, and the chain of its causes (RUN.REPLAY-CAUSES).
|
|
4524
|
+
* The list `dropped` names each other own field. A cause that is an earlier exception of the chain is its index in `loop`.
|
|
4525
|
+
* - An exception keeps the hidden fields of the standard classes in `hidden`, for example `errors` of an
|
|
4526
|
+
* `AggregateError` (RUN.REPLAY-HIDDEN, D77). Each exception in them has the rule of a cause.
|
|
4527
|
+
* - An enumerable field without a term document that is an exception, a list or a plain record is in `parts`
|
|
4528
|
+
* (RUN.REPLAY-FIELDS, D78, D82). An item of a list without a form is the mark `dropped` at its place.
|
|
4529
|
+
* - A cause without a term document that is a list or a plain record with an exception is in `causeParts`
|
|
4530
|
+
* (RUN.REPLAY-CAUSE-PARTS, D87). The rule is the same for the cause of an exception and of an error value.
|
|
4531
|
+
* - The cause of an exception is also in `causeParts` without an exception in it, when an item has a form
|
|
4532
|
+
* (RUN.REPLAY-CAUSE-ITEMS, D100). Each item without a form is a name in `dropped`, for example `cause.send`.
|
|
4533
|
+
* - A list or a record of parts that an earlier place of one error holds is the part `share` with its index
|
|
4534
|
+
* (RUN.REPLAY-SHARED, D88). This rule also covers a container that holds itself.
|
|
4535
|
+
* - A list or a plain record with a term document that two places of one error share is a container of parts
|
|
4536
|
+
* (RUN.REPLAY-SHARED-VALUES, D101). Each later place is a share. A member of a domain stays a term document.
|
|
4537
|
+
* - An outcome that the log does not have stays absent.
|
|
4538
|
+
*
|
|
4539
|
+
* @param machine - The machine of the run, or only its domains.
|
|
4540
|
+
* @param log - The log of a recorder.
|
|
4541
|
+
* @returns The JSON form. `decodeLog` gives the log again.
|
|
4542
|
+
* @throws {TypeError} A value has no term document, for example a closure, a host thing, a symbol, or a value that no
|
|
4543
|
+
* domain with a codec holds. The message names the effect and its address. A part of an exception is not a refusal.
|
|
4544
|
+
*/
|
|
4545
|
+
export declare function encodeLog(machine: Pick<Machine, "domains">, log: ReplayLog): ReplayLogJson;
|
|
4546
|
+
/**
|
|
4547
|
+
* This function reads the JSON form of a log again (RUN.REPLAY-JSON). It reads each term document with the formula kit
|
|
4548
|
+
* and the domains of the machine. A cause in the field `exception` becomes an exception with that name and message.
|
|
4549
|
+
* The exception gets its fields and the chain of its causes again, also a cycle (RUN.REPLAY-CAUSES). A list gets a
|
|
4550
|
+
* hole at the place of the mark `dropped`, thus each later item keeps its index (D78). Each share of a list or a record
|
|
4551
|
+
* gives the same object (RUN.REPLAY-SHARED).
|
|
4552
|
+
*
|
|
4553
|
+
* @param machine - The machine of the run, or only its domains.
|
|
4554
|
+
* @param data - The JSON form, for example from `JSON.parse` of a golden file.
|
|
4555
|
+
* @returns The log for `replayer`, or `#VALUE!` with the place of the first field that it cannot read.
|
|
4556
|
+
*/
|
|
4557
|
+
export declare function decodeLog(machine: Pick<Machine, "domains">, data: unknown): Result<ReplayLog>;
|
|
4245
4558
|
/** The type that a provider reads, and the problems of the reading. Each problem tells what the type does not test. */
|
|
4246
4559
|
interface TypeReading {
|
|
4247
4560
|
readonly type: ValueType;
|
|
@@ -4288,6 +4601,5 @@ interface SampleOptions {
|
|
|
4288
4601
|
* @returns The type.
|
|
4289
4602
|
*/
|
|
4290
4603
|
export declare function typeFromSamples(values: readonly unknown[], options?: SampleOptions): ValueType;
|
|
4291
|
-
|
|
4292
|
-
export type { AgreeOptions, AgreeRunOptions, AgreeScheduleOptions, Agreement, Alias, AllOptions, Answer, AskOptions, AttributeDeclaration, AttributeRung, AttributeTrace, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, ConformOptions, ConformProbe, Construct, Context, Part as ContextPart, Definitions, DerefCode, DocFacts, DocParts, DocVisit, Domain, DomainCodec, DomainExtension, Durable, DurableCounts, DurableOptions, Edge, Effect, EffectsOptions, Envelope, Epochs, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, EvaluateOptions, Evaluator, ExtFn, FactsOptions, Failed, Finding, FormulaProfile, GenerateOptions, Give, GraphCycle, GraphEdge, GraphNode, GraphOptions, Header, Hop, HopBy, HostThing, Issue, Journal, Json, JsonRecord, KernelCode, Key, Kind, KindFacts, KindSource, LazyOp, LazyRule, Lookup, Machine, MachinePart, MergeConflict, MergePath, NamesSource, Namespace, Navigator, NearestOptions, NodeEdge, NodeGraph, NodeInfo, NodeRunOptions, Obligation, OpFn, OrderProblem, Outcome, ParseResult, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartType, PartsSpec, Perform, Plan, PlanRunOptions, PrepareOptions, Random, Read, ReadsCheck, Recorder, RefUse, ReferenceOptions, ReferenceRunOptions, ReplayEntry, ReplayLog, ReplayOptions, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, RootTypes, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, SampleOptions, Schedule, ScheduleAgreement, ScheduleAgreementCounts, ScheduleCounts, ScheduleEngine, ScheduleEngineFactory, ScheduleEngineStart, ScheduleOptions, ScopeRule, Shape$1 as Shape, Side, Signature, Split, StaticRead, Step, StepSpec, Steps, StopSignal, Stored, SyntaxAssoc, SyntaxCalls, SyntaxFixity, SyntaxForm, SyntaxIssue, SyntaxLiterals, SyntaxOperator, SyntaxProfile, SyntaxRefPattern, SyntaxRefs, Thing, Tier, TierInput, TierResult, TraceNode, TreeContract, TypeInput, TypeIssue, TypeProblem, TypeReading, TypeRef, TypeRule, Typed, Typing, Use, ValueType, VerbEffects, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldIssue, WorldPart };
|
|
4604
|
+
export type { AgreeOptions, AgreeRunOptions, AgreeScheduleOptions, Agreement, Alias, AllOptions, Answer, AskOptions, AttributeDeclaration, AttributeRung, AttributeTrace, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, ConformOptions, ConformProbe, Construct, Context, Part as ContextPart, Definitions, DerefCode, DocFacts, DocParts, DocVisit, Domain, DomainCodec, DomainExtension, Durable, DurableCounts, DurableOptions, Edge, Effect, EffectsOptions, Envelope, Epochs, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, EvaluateOptions, Evaluator, ExtFn, FactsOptions, Failed, Finding, FormulaProfile, GenerateOptions, Give, GraphCycle, GraphEdge, GraphNode, GraphOptions, Header, Hop, HopBy, HostThing, Issue, Journal, Json, JsonRecord, KernelCode, Key, Kind, KindFacts, KindSource, LazyOp, LazyRule, Lookup, Machine, MachinePart, MergeConflict, MergePath, NamesSource, Namespace, Navigator, NearestOptions, NodeEdge, NodeGraph, NodeInfo, NodeRunOptions, Obligation, OpFn, OrderProblem, Outcome, ParseResult, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartType, PartsSpec, Perform, Plan, PlanRunOptions, PrepareOptions, Random, Read, ReadsCheck, Recorder, RefUse, ReferenceOptions, ReferenceRunOptions, ReplayCausePartsJson, ReplayEntry, ReplayEntryJson, ReplayErrorJson, ReplayExceptionJson, ReplayLog, ReplayLogJson, ReplayOptions, ReplayPartJson, ReplayPartsJson, ReplayResultJson, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, RootTypes, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, SampleOptions, Schedule, ScheduleAgreement, ScheduleAgreementCounts, ScheduleCounts, ScheduleEngine, ScheduleEngineFactory, ScheduleEngineStart, ScheduleOptions, ScopeRule, Shape$1 as Shape, Side, Signature, Split, StaticRead, Step, StepSpec, Steps, StopSignal, Stored, SyntaxAssoc, SyntaxCalls, SyntaxEnvelopes, SyntaxFixity, SyntaxForm, SyntaxFormArgs, SyntaxHeader, SyntaxIssue, SyntaxLiterals, SyntaxOperator, SyntaxProfile, SyntaxRefPattern, SyntaxRefs, Thing, Tier, TierInput, TierResult, TraceNode, TreeContract, TypeInput, TypeIssue, TypeProblem, TypeReading, TypeRef, TypeRule, Typed, Typing, Use, ValueType, VerbEffects, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldIssue, WorldPart };
|
|
4293
4605
|
//# sourceMappingURL=index.d.ts.map
|