@mark1russell7/coeval 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/build/index.d.ts +399 -100
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1818 -172
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/src/agree.ts +26 -5
- package/src/codec.ts +185 -0
- package/src/conform.ts +2 -3
- package/src/doc.ts +2 -2
- package/src/evaluate.ts +281 -9
- package/src/formula.ts +19 -8
- package/src/index.ts +36 -2
- package/src/parts.ts +70 -1
- package/src/reference.ts +143 -18
- package/src/static.ts +54 -74
- package/src/stdlib.ts +220 -18
- package/src/syntax.ts +846 -0
- package/src/types.ts +28 -1
- package/src/world.ts +50 -0
package/build/index.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ type TypeRef = string | readonly Key[] | {
|
|
|
24
24
|
readonly value: readonly Json[];
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
|
-
* A typed document: an envelope with a header and a value. The header names the type of the value. The
|
|
28
|
-
* not
|
|
27
|
+
* A typed document: an envelope with a header and a value. The header names the type of the value. The envelope
|
|
28
|
+
* does not change the value at any time. Thus any JSON value can have a type: a number, a list, a text or a record.
|
|
29
29
|
*/
|
|
30
30
|
type Envelope = {
|
|
31
31
|
/** The type: a reference to a kind of the world. */
|
|
@@ -539,6 +539,32 @@ interface Domain {
|
|
|
539
539
|
* a step with the key into a member reaches a member of the type. A key without a type gives `unknown`.
|
|
540
540
|
*/
|
|
541
541
|
readonly steps?: Readonly<Record<string, ValueType>>;
|
|
542
|
+
/**
|
|
543
|
+
* The codec of the members: it writes a member as JSON and reads it again (D40). A document holds a member as the
|
|
544
|
+
* standard extension `ext.domain`. A domain without a codec has no such document.
|
|
545
|
+
*/
|
|
546
|
+
readonly codec?: DomainCodec;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* The codec of a domain: it writes a member of the domain as JSON, and it reads the JSON again (D40). Both functions
|
|
550
|
+
* must be pure. `decode(encode(v))` must equal `v` by `sameValue` (EXT.ROUNDTRIP). The codec must give one JSON
|
|
551
|
+
* value for each member, thus the same value has the same document in each language (D12).
|
|
552
|
+
*/
|
|
553
|
+
interface DomainCodec {
|
|
554
|
+
/**
|
|
555
|
+
* This function writes a member of the domain as JSON.
|
|
556
|
+
*
|
|
557
|
+
* @param value - A member of the domain.
|
|
558
|
+
* @returns The JSON of the member.
|
|
559
|
+
*/
|
|
560
|
+
readonly encode: (value: unknown) => Json;
|
|
561
|
+
/**
|
|
562
|
+
* This function reads the JSON of a member again. It throws for JSON that does not write a member.
|
|
563
|
+
*
|
|
564
|
+
* @param data - The JSON that `encode` gave.
|
|
565
|
+
* @returns The member.
|
|
566
|
+
*/
|
|
567
|
+
readonly decode: (data: Json) => unknown;
|
|
542
568
|
}
|
|
543
569
|
/** A problem of a value type: the keys from the root of the term to the problem, and the reason. */
|
|
544
570
|
interface TypeIssue {
|
|
@@ -789,6 +815,48 @@ interface KindFacts {
|
|
|
789
815
|
readonly volatile?: boolean;
|
|
790
816
|
readonly lazy?: readonly LazyRule[];
|
|
791
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* The declaration of one attribute of the nodes of a kind (D42). The last two rungs of the ladder of an attribute
|
|
820
|
+
* read it (TREE.LADDER). Each term is a document. A bare term gets the type `of` of the parts of the kind.
|
|
821
|
+
*
|
|
822
|
+
* - `copy`: `true` gives a node without an answer of the first three rungs the same attribute of its parent
|
|
823
|
+
* (TREE.COPY).
|
|
824
|
+
* - `fold`: the value of a node without an answer of the first four rungs. The fold starts with the term `unit`.
|
|
825
|
+
* Then the term `combine` adds the attribute of each node in the list `children`, one at a time (TREE.FOLD).
|
|
826
|
+
* `combine` sees the names `acc` and `item`.
|
|
827
|
+
* - `default`: the term that gives the value when no rung before it answers and the declaration has no fold.
|
|
828
|
+
*/
|
|
829
|
+
interface AttributeDeclaration {
|
|
830
|
+
readonly copy?: boolean;
|
|
831
|
+
readonly fold?: {
|
|
832
|
+
readonly unit: Json;
|
|
833
|
+
readonly combine: Json;
|
|
834
|
+
};
|
|
835
|
+
readonly default?: Json;
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* The tree contract of a kind (D42): the equations of the attributes of its nodes. Each equation is a document that
|
|
839
|
+
* evaluates with the node as `self` and without capabilities. A bare equation gets the type `of` of the parts of the
|
|
840
|
+
* kind.
|
|
841
|
+
*
|
|
842
|
+
* - `equations`: the attributes of the node itself. An equation sees no names.
|
|
843
|
+
* - `down`: the attributes of each child of the node. `self` is this node. An equation sees the names `child`,
|
|
844
|
+
* `index` and `prev` (TREE.DOWN).
|
|
845
|
+
* - `attributes`: the declarations of the attributes of the node, for the rungs `copy` and `default`.
|
|
846
|
+
*/
|
|
847
|
+
interface TreeContract {
|
|
848
|
+
readonly equations?: Readonly<Record<string, Json>>;
|
|
849
|
+
readonly down?: Readonly<Record<string, Json>>;
|
|
850
|
+
readonly attributes?: Readonly<Record<string, AttributeDeclaration>>;
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* This function gives the type of a bare equation of a kind (D42). It is the type `of` of the shape of its parts, or
|
|
854
|
+
* else the type `of` of the shape `rest` of a record. The plan, the reference and `check` read it with this one function.
|
|
855
|
+
*
|
|
856
|
+
* @param kind - The kind.
|
|
857
|
+
* @returns The type, or `undefined` when the shape declares none.
|
|
858
|
+
*/
|
|
859
|
+
export declare function equationType(kind: Kind): string | undefined;
|
|
792
860
|
/**
|
|
793
861
|
* A kind gives the name of an evaluator for each verb, and the contract of its value. The contract serves each verb.
|
|
794
862
|
* For each verb, the kernel splits the parts and narrows their capabilities by it, and `check` reads its scope rules.
|
|
@@ -825,6 +893,11 @@ interface Kind extends KindFacts {
|
|
|
825
893
|
* document of the kind, in the place of the type that the rule of the evaluator synthesizes.
|
|
826
894
|
*/
|
|
827
895
|
readonly result?: ValueType;
|
|
896
|
+
/**
|
|
897
|
+
* The equations and the declarations of the attributes of a node of the decorated tree (D42). Only the evaluator
|
|
898
|
+
* `tree.node` reads them, and `check` checks each equation one time (TREE.LADDER).
|
|
899
|
+
*/
|
|
900
|
+
readonly tree?: TreeContract;
|
|
828
901
|
/** One sentence that tells what the kind is. */
|
|
829
902
|
readonly summary?: string;
|
|
830
903
|
}
|
|
@@ -1004,94 +1077,6 @@ export declare function kindNamed(world: World, name: TypeRef): Kind | undefined
|
|
|
1004
1077
|
*/
|
|
1005
1078
|
export declare function ask(world: World, doc: Header, verb: string, options?: AskOptions): Answer;
|
|
1006
1079
|
//#endregion
|
|
1007
|
-
//#region src/parts.d.ts
|
|
1008
|
-
/** One part of a value: its place in the value, the JSON of the part, and the type that its position declares. */
|
|
1009
|
-
interface PartSlot {
|
|
1010
|
-
/** The keys from the value of the document to the part. */
|
|
1011
|
-
readonly path: readonly Key[];
|
|
1012
|
-
/** The path as one text, with a dot between the keys, for example `bind.x`. A part of a list has its index. */
|
|
1013
|
-
readonly key: string;
|
|
1014
|
-
readonly item: Json;
|
|
1015
|
-
readonly of?: string;
|
|
1016
|
-
/** `true` when the position of the part declares an address: a reference there gives what its path reaches. */
|
|
1017
|
-
readonly address?: true;
|
|
1018
|
-
/** The value type that the shape declares for the part (`expect`). Only a check of types reads it. */
|
|
1019
|
-
readonly expect?: ValueType;
|
|
1020
|
-
}
|
|
1021
|
-
/** The value of a document, split into its parts, by the shape that its kind declares. */
|
|
1022
|
-
type Split = {
|
|
1023
|
-
readonly ok: true;
|
|
1024
|
-
/** The parts, in the order of the value. */
|
|
1025
|
-
readonly parts: readonly PartSlot[];
|
|
1026
|
-
/** The value without the parts: a field that holds a part is not in it, and a list of parts gives `null`. */
|
|
1027
|
-
readonly data: Json;
|
|
1028
|
-
/**
|
|
1029
|
-
* This function gives the value with a handle in the place of each part.
|
|
1030
|
-
*
|
|
1031
|
-
* @param handles - One handle for each part, in the order of `parts`.
|
|
1032
|
-
* @returns The value with the handles.
|
|
1033
|
-
*/
|
|
1034
|
-
fill<P>(handles: readonly P[]): unknown;
|
|
1035
|
-
} | {
|
|
1036
|
-
readonly ok: false;
|
|
1037
|
-
readonly reason: string;
|
|
1038
|
-
readonly at: readonly Key[];
|
|
1039
|
-
};
|
|
1040
|
-
/**
|
|
1041
|
-
* This function splits a value into its parts, by the shape that its kind declares. The evaluator, the view and
|
|
1042
|
-
* the static kit use the same split, thus each one sees the same parts.
|
|
1043
|
-
*
|
|
1044
|
-
* @param shape - The shape of the value. The default is data.
|
|
1045
|
-
* @param value - The value of the document.
|
|
1046
|
-
* @returns The parts and a way to fill their places, or the reason why the value does not have the shape.
|
|
1047
|
-
*/
|
|
1048
|
-
export declare function splitParts(shape: Shape | undefined, value: Json): Split;
|
|
1049
|
-
/**
|
|
1050
|
-
* The kind and the parts of one document: what `partsOf` gives. `ok` is `false` only when the value is not a
|
|
1051
|
-
* document: it has no envelope, and its position declares no type. A value without the shape of its kind gives a
|
|
1052
|
-
* failed `split`.
|
|
1053
|
-
*/
|
|
1054
|
-
type DocParts = {
|
|
1055
|
-
readonly ok: true;
|
|
1056
|
-
/** The document. A bare value gets the type that its position declares. */
|
|
1057
|
-
readonly doc: Envelope;
|
|
1058
|
-
/** `true` when the type came from the position and not from an envelope. */
|
|
1059
|
-
readonly declared: boolean;
|
|
1060
|
-
/** The kind, or `undefined` when the world has no kind for the type. Then the value is data. */
|
|
1061
|
-
readonly kind: Kind | undefined;
|
|
1062
|
-
/** The keys of the kind after each alias, or `undefined` without a kind. */
|
|
1063
|
-
readonly typePath: readonly Key[] | undefined;
|
|
1064
|
-
/**
|
|
1065
|
-
* The split of the value by the shape of the kind. The reason of a failed split is the reason of the `#VALUE!`
|
|
1066
|
-
* of an evaluation: it names the kind. Its `at` gives the keys from the value to the problem.
|
|
1067
|
-
*/
|
|
1068
|
-
readonly split: Split;
|
|
1069
|
-
} | {
|
|
1070
|
-
readonly ok: false;
|
|
1071
|
-
readonly code: "#PART?";
|
|
1072
|
-
readonly reason: string;
|
|
1073
|
-
};
|
|
1074
|
-
/**
|
|
1075
|
-
* This function reads one document by the contracts of the world. It finds the kind of the type. A bare value gets
|
|
1076
|
-
* the type that its position declares. Then the function splits the value by the shape of the kind. The plan, the
|
|
1077
|
-
* reference interpreter and the static kit read each document with this function. Thus they see the same parts.
|
|
1078
|
-
*
|
|
1079
|
-
* @param world - The world of the kinds.
|
|
1080
|
-
* @param value - The document, or a bare value.
|
|
1081
|
-
* @param declaredType - The type that the position of a bare value declares.
|
|
1082
|
-
* @returns The document, its kind and its parts, or the reason why the value is not a document.
|
|
1083
|
-
*/
|
|
1084
|
-
export declare function partsOf(world: World, value: unknown, declaredType?: string): DocParts;
|
|
1085
|
-
/**
|
|
1086
|
-
* This function tells if the path of a part matches a pattern of a scope rule. The key `"*"` of a pattern matches
|
|
1087
|
-
* each key.
|
|
1088
|
-
*
|
|
1089
|
-
* @param path - The path of the part.
|
|
1090
|
-
* @param pattern - The pattern.
|
|
1091
|
-
* @returns `true` when the path matches.
|
|
1092
|
-
*/
|
|
1093
|
-
export declare function pathMatches(path: readonly Key[], pattern: readonly Key[]): boolean;
|
|
1094
|
-
//#endregion
|
|
1095
1080
|
//#region src/static.d.ts
|
|
1096
1081
|
/** One document that a walk visits. */
|
|
1097
1082
|
interface DocVisit {
|
|
@@ -1743,6 +1728,8 @@ interface EvalInput {
|
|
|
1743
1728
|
readonly context: Context;
|
|
1744
1729
|
/** The keys from the root document to this document. */
|
|
1745
1730
|
readonly place: readonly Key[];
|
|
1731
|
+
/** The machine of the evaluation, for example for its domains (D40). The kernel sets it. */
|
|
1732
|
+
readonly machine?: Machine;
|
|
1746
1733
|
/** `true` when the position of the document declares an address. */
|
|
1747
1734
|
readonly address?: boolean;
|
|
1748
1735
|
/**
|
|
@@ -1798,6 +1785,8 @@ interface RunInput {
|
|
|
1798
1785
|
readonly parts: readonly RunPart[];
|
|
1799
1786
|
readonly context: Context;
|
|
1800
1787
|
readonly place: readonly Key[];
|
|
1788
|
+
/** The machine of the evaluation, for example for its domains (D40). The kernel sets it. */
|
|
1789
|
+
readonly machine?: Machine;
|
|
1801
1790
|
resolve(path: readonly unknown[], options?: ResolveOptions): Resolution;
|
|
1802
1791
|
/**
|
|
1803
1792
|
* This function causes an effect. In a run, the host does the effect, and the steps wait when the host waits. In
|
|
@@ -2006,6 +1995,11 @@ interface PrepareOptions {
|
|
|
2006
1995
|
* The default is `eval` (VERB.PREPARE).
|
|
2007
1996
|
*/
|
|
2008
1997
|
readonly verb?: string;
|
|
1998
|
+
/**
|
|
1999
|
+
* `false`: no part of the plan folds. The default is `true`. Then a closed pure part of a plan without a trace
|
|
2000
|
+
* evaluates one time, when the plan compiles. Its result is one frozen value for each evaluation (PLAN.FOLD).
|
|
2001
|
+
*/
|
|
2002
|
+
readonly fold?: boolean;
|
|
2009
2003
|
}
|
|
2010
2004
|
/** A compiled document. It evaluates many times, and it does the work of the ladder one time. */
|
|
2011
2005
|
interface Plan {
|
|
@@ -2062,8 +2056,8 @@ export declare function planner(machine: Machine, options?: PrepareOptions): (do
|
|
|
2062
2056
|
* tells where its parts are. The evaluator gets each part sealed: it can evaluate the part, and it cannot read its
|
|
2063
2057
|
* value.
|
|
2064
2058
|
*
|
|
2065
|
-
* A failure gives an error value, and the function does not throw.
|
|
2066
|
-
* does not do it. A mock can answer each effect at once (RUN.MOCK).
|
|
2059
|
+
* A failure gives an error value, and the function does not throw. The function records each effect in its order,
|
|
2060
|
+
* and the host does not do it. A mock can answer each effect at once (RUN.MOCK).
|
|
2067
2061
|
*
|
|
2068
2062
|
* @param machine - The world and the code of the evaluators.
|
|
2069
2063
|
* @param doc - The document, as JSON.
|
|
@@ -2275,6 +2269,94 @@ export declare function classify(shapes: readonly Shape$1[], value: Json): Class
|
|
|
2275
2269
|
*/
|
|
2276
2270
|
export declare function tag(value: Json, kind: string): Envelope;
|
|
2277
2271
|
//#endregion
|
|
2272
|
+
//#region src/parts.d.ts
|
|
2273
|
+
/** One part of a value: its place in the value, the JSON of the part, and the type that its position declares. */
|
|
2274
|
+
interface PartSlot {
|
|
2275
|
+
/** The keys from the value of the document to the part. */
|
|
2276
|
+
readonly path: readonly Key[];
|
|
2277
|
+
/** The path as one text, with a dot between the keys, for example `bind.x`. A part of a list has its index. */
|
|
2278
|
+
readonly key: string;
|
|
2279
|
+
readonly item: Json;
|
|
2280
|
+
readonly of?: string;
|
|
2281
|
+
/** `true` when the position of the part declares an address: a reference there gives what its path reaches. */
|
|
2282
|
+
readonly address?: true;
|
|
2283
|
+
/** The value type that the shape declares for the part (`expect`). Only a check of types reads it. */
|
|
2284
|
+
readonly expect?: ValueType;
|
|
2285
|
+
}
|
|
2286
|
+
/** The value of a document, split into its parts, by the shape that its kind declares. */
|
|
2287
|
+
type Split = {
|
|
2288
|
+
readonly ok: true;
|
|
2289
|
+
/** The parts, in the order of the value. */
|
|
2290
|
+
readonly parts: readonly PartSlot[];
|
|
2291
|
+
/** The value without the parts: a field that holds a part is not in it, and a list of parts gives `null`. */
|
|
2292
|
+
readonly data: Json;
|
|
2293
|
+
/**
|
|
2294
|
+
* This function gives the value with a handle in the place of each part.
|
|
2295
|
+
*
|
|
2296
|
+
* @param handles - One handle for each part, in the order of `parts`.
|
|
2297
|
+
* @returns The value with the handles.
|
|
2298
|
+
*/
|
|
2299
|
+
fill<P>(handles: readonly P[]): unknown;
|
|
2300
|
+
} | {
|
|
2301
|
+
readonly ok: false;
|
|
2302
|
+
readonly reason: string;
|
|
2303
|
+
readonly at: readonly Key[];
|
|
2304
|
+
};
|
|
2305
|
+
/**
|
|
2306
|
+
* This function splits a value into its parts, by the shape that its kind declares. The evaluator, the view and
|
|
2307
|
+
* the static kit use the same split, thus each one sees the same parts.
|
|
2308
|
+
*
|
|
2309
|
+
* @param shape - The shape of the value. The default is data.
|
|
2310
|
+
* @param value - The value of the document.
|
|
2311
|
+
* @returns The parts and a way to fill their places, or the reason why the value does not have the shape.
|
|
2312
|
+
*/
|
|
2313
|
+
export declare function splitParts(shape: Shape | undefined, value: Json): Split;
|
|
2314
|
+
/**
|
|
2315
|
+
* The kind and the parts of one document: what `partsOf` gives. `ok` is `false` only when the value is not a
|
|
2316
|
+
* document: it has no envelope, and its position declares no type. A value without the shape of its kind gives a
|
|
2317
|
+
* failed `split`.
|
|
2318
|
+
*/
|
|
2319
|
+
type DocParts = {
|
|
2320
|
+
readonly ok: true;
|
|
2321
|
+
/** The document. A bare value gets the type that its position declares. */
|
|
2322
|
+
readonly doc: Envelope;
|
|
2323
|
+
/** `true` when the type came from the position and not from an envelope. */
|
|
2324
|
+
readonly declared: boolean;
|
|
2325
|
+
/** The kind, or `undefined` when the world has no kind for the type. Then the value is data. */
|
|
2326
|
+
readonly kind: Kind | undefined;
|
|
2327
|
+
/** The keys of the kind after each alias, or `undefined` without a kind. */
|
|
2328
|
+
readonly typePath: readonly Key[] | undefined;
|
|
2329
|
+
/**
|
|
2330
|
+
* The split of the value by the shape of the kind. The reason of a failed split is the reason of the `#VALUE!`
|
|
2331
|
+
* of an evaluation: it names the kind. Its `at` gives the keys from the value to the problem.
|
|
2332
|
+
*/
|
|
2333
|
+
readonly split: Split;
|
|
2334
|
+
} | {
|
|
2335
|
+
readonly ok: false;
|
|
2336
|
+
readonly code: "#PART?";
|
|
2337
|
+
readonly reason: string;
|
|
2338
|
+
};
|
|
2339
|
+
/**
|
|
2340
|
+
* This function reads one document by the contracts of the world. It finds the kind of the type. A bare value gets
|
|
2341
|
+
* the type that its position declares. Then the function splits the value by the shape of the kind. The plan, the
|
|
2342
|
+
* reference interpreter and the static kit read each document with this function. Thus they see the same parts.
|
|
2343
|
+
*
|
|
2344
|
+
* @param world - The world of the kinds.
|
|
2345
|
+
* @param value - The document, or a bare value.
|
|
2346
|
+
* @param declaredType - The type that the position of a bare value declares.
|
|
2347
|
+
* @returns The document, its kind and its parts, or the reason why the value is not a document.
|
|
2348
|
+
*/
|
|
2349
|
+
export declare function partsOf(world: World, value: unknown, declaredType?: string): DocParts;
|
|
2350
|
+
/**
|
|
2351
|
+
* This function tells if the path of a part matches a pattern of a scope rule. The key `"*"` of a pattern matches
|
|
2352
|
+
* each key.
|
|
2353
|
+
*
|
|
2354
|
+
* @param path - The path of the part.
|
|
2355
|
+
* @param pattern - The pattern.
|
|
2356
|
+
* @returns `true` when the path matches.
|
|
2357
|
+
*/
|
|
2358
|
+
export declare function pathMatches(path: readonly Key[], pattern: readonly Key[]): boolean;
|
|
2359
|
+
//#endregion
|
|
2278
2360
|
//#region src/stdlib.d.ts
|
|
2279
2361
|
/**
|
|
2280
2362
|
* The world of the examples: small kinds for numbers, lists, conditions, names, sequences and effects.
|
|
@@ -2283,6 +2365,27 @@ export declare function tag(value: Json, kind: string): Envelope;
|
|
|
2283
2365
|
export declare const STD_WORLD: World;
|
|
2284
2366
|
/** The code of the evaluators of the standard world, by name. */
|
|
2285
2367
|
export declare const STD_EVALUATORS: Readonly<Record<string, Evaluator>>;
|
|
2368
|
+
/** The rungs of the ladder of an attribute, in their order (TREE.LADDER, D42). */
|
|
2369
|
+
type AttributeRung = "own" | "kind" | "parent" | "copy" | "default";
|
|
2370
|
+
/** The rungs of the ladder of an attribute, in their order (TREE.LADDER, D42). */
|
|
2371
|
+
export declare const ATTRIBUTE_RUNGS: readonly AttributeRung[];
|
|
2372
|
+
/** The record of the demand of one attribute of a node (TREE.RUNGS). */
|
|
2373
|
+
interface AttributeTrace {
|
|
2374
|
+
readonly attribute: string;
|
|
2375
|
+
/** The rungs that the demand visited, in their order. The last one answered, unless no rung answered. */
|
|
2376
|
+
readonly rungs: readonly AttributeRung[];
|
|
2377
|
+
/** The rung that answered. It is `undefined` when no rung answered. */
|
|
2378
|
+
readonly by?: AttributeRung;
|
|
2379
|
+
}
|
|
2380
|
+
/**
|
|
2381
|
+
* This function gives the record of the demand of an attribute of a node of the decorated tree (TREE.RUNGS). The
|
|
2382
|
+
* record holds the rungs that the demand visited, and the rung that answered. An explorer draws the ladder with it.
|
|
2383
|
+
*
|
|
2384
|
+
* @param node - The thing of a node.
|
|
2385
|
+
* @param attribute - The name of the attribute.
|
|
2386
|
+
* @returns The record, or `undefined` for a thing that is not a node or an attribute that no demand reached.
|
|
2387
|
+
*/
|
|
2388
|
+
export declare function attributeTrace(node: Thing, attribute: string): AttributeTrace | undefined;
|
|
2286
2389
|
/** The options of a walker `nearest`. */
|
|
2287
2390
|
interface NearestOptions {
|
|
2288
2391
|
/**
|
|
@@ -2565,14 +2668,18 @@ type OpFn = (...args: never[]) => unknown;
|
|
|
2565
2668
|
* example a default for an error.
|
|
2566
2669
|
*/
|
|
2567
2670
|
type LazyOp = (args: readonly (() => Result)[]) => Result;
|
|
2568
|
-
/**
|
|
2569
|
-
|
|
2671
|
+
/**
|
|
2672
|
+
* The code of an extension: it gives the value of the data of an extension document, in the context of the document.
|
|
2673
|
+
* It also gets the domains of the machine, for the codecs of `ext.domain` (D40).
|
|
2674
|
+
*/
|
|
2675
|
+
type ExtFn = (data: Json, context: Context, domains?: Readonly<Record<string, Domain>>) => Result;
|
|
2570
2676
|
/**
|
|
2571
2677
|
* The rules of one formula language: its operations, and the rules that differ between languages.
|
|
2572
2678
|
*
|
|
2573
2679
|
* - `ops`: the operations of the namespace `ops`, by their name (the keys after `ops`, with dots between them).
|
|
2574
2680
|
* - `lazy`: the operations that evaluate their arguments themselves.
|
|
2575
|
-
* - `ext`: the extensions of the namespace `ext`, by their name. The kit has `ext.undefined
|
|
2681
|
+
* - `ext`: the extensions of the namespace `ext`, by their name. The kit has `ext.undefined`, `ext.number` and
|
|
2682
|
+
* `ext.domain`.
|
|
2576
2683
|
* - `truthy`: the truth of a value for `if`, `and` and `or`. `undefined` is an error `#VALUE!`. The default
|
|
2577
2684
|
* accepts only `true` and `false`.
|
|
2578
2685
|
* - `otherwise`: the value of an `if` without `else`. The default is `null`. A profile with this key gives its value,
|
|
@@ -2639,7 +2746,10 @@ type Closure = ((...args: readonly unknown[]) => unknown) & {
|
|
|
2639
2746
|
* @returns `true` for a closure.
|
|
2640
2747
|
*/
|
|
2641
2748
|
export declare function isClosure(value: unknown): value is Closure;
|
|
2642
|
-
/**
|
|
2749
|
+
/**
|
|
2750
|
+
* The standard extensions: the values that JSON cannot write. `ext.domain` reads a member of a domain through the
|
|
2751
|
+
* codec of the domain (EXT.DOMAIN, D40).
|
|
2752
|
+
*/
|
|
2643
2753
|
export declare const STD_EXT: Readonly<Record<string, ExtFn>>;
|
|
2644
2754
|
/** The truth of a value in the rules of JavaScript: `0`, `""`, `null`, `undefined` and `NaN` are false. */
|
|
2645
2755
|
export declare function jsTruthy(value: unknown): boolean;
|
|
@@ -2701,6 +2811,189 @@ export declare function formulaFacts(profile?: FormulaProfile): (path: readonly
|
|
|
2701
2811
|
*/
|
|
2702
2812
|
export declare function formulaMachine(profile?: FormulaProfile, more?: MachinePart): Machine;
|
|
2703
2813
|
//#endregion
|
|
2814
|
+
//#region src/codec.d.ts
|
|
2815
|
+
/** The domains of a machine, by their names. */
|
|
2816
|
+
type Domains = Readonly<Record<string, Domain>> | undefined;
|
|
2817
|
+
/**
|
|
2818
|
+
* This function reads the value of an extension `ext.domain` (EXT.DOMAIN). The value is a record with only the text
|
|
2819
|
+
* `domain` and the JSON `data`. The codec of the named domain reads the data, and the result must be a member of the
|
|
2820
|
+
* domain.
|
|
2821
|
+
*
|
|
2822
|
+
* @param data - The value of the extension document.
|
|
2823
|
+
* @param domains - The domains of the machine.
|
|
2824
|
+
* @returns The member, `#NAME?` for a domain without a codec, or `#VALUE!` for data that the codec cannot read.
|
|
2825
|
+
*/
|
|
2826
|
+
export declare function decodeDomain(data: Json, domains: Domains): Result;
|
|
2827
|
+
/**
|
|
2828
|
+
* This function writes a host value as a term document of the formula kit (EXT.ENCODE, D40). Thus the same value has
|
|
2829
|
+
* the same document in each language (D12).
|
|
2830
|
+
*
|
|
2831
|
+
* - A value that JSON writes exactly stays as it is. A literal with the shape of an envelope goes into `lit`.
|
|
2832
|
+
* - `NaN`, an infinity and `-0` become `ext.number`, and `undefined` becomes `ext.undefined`.
|
|
2833
|
+
* - A member of a domain with a codec becomes `ext.domain`. The domains go in the order of their names.
|
|
2834
|
+
* - A list or a plain record with such a value becomes the construct `list` or `record`.
|
|
2835
|
+
*
|
|
2836
|
+
* @param machine - The machine, or only its domains.
|
|
2837
|
+
* @param value - The host value.
|
|
2838
|
+
* @returns The document. `decodeValue` gives the value again (EXT.ROUNDTRIP).
|
|
2839
|
+
* @throws {TypeError} The value has a cycle, or it is not JSON and no domain with a codec holds it.
|
|
2840
|
+
*/
|
|
2841
|
+
export declare function encodeValue(machine: Pick<Machine, "domains">, value: unknown): Json;
|
|
2842
|
+
/**
|
|
2843
|
+
* This function reads a document of `encodeValue` again: it evaluates the document as a term, in an empty context.
|
|
2844
|
+
* A bare root value is a literal.
|
|
2845
|
+
*
|
|
2846
|
+
* @param machine - A machine of the formula kit, with the domains of the document.
|
|
2847
|
+
* @param doc - The document.
|
|
2848
|
+
* @returns The value, or the error of the evaluation.
|
|
2849
|
+
*/
|
|
2850
|
+
export declare function decodeValue(machine: Machine, doc: unknown): Result;
|
|
2851
|
+
//#endregion
|
|
2852
|
+
//#region src/syntax.d.ts
|
|
2853
|
+
/** The place of an operator: before its term, between two terms, or after its term. */
|
|
2854
|
+
type SyntaxFixity = "prefix" | "infix" | "postfix";
|
|
2855
|
+
/**
|
|
2856
|
+
* The grouping of a chain of one infix operator. `left` reads `a - b - c` as `(a - b) - c`, and `right` reads
|
|
2857
|
+
* `a ^ b ^ c` as `a ^ (b ^ c)`. `none` refuses a chain. `flat` reads a chain as one document with each term.
|
|
2858
|
+
*/
|
|
2859
|
+
type SyntaxAssoc = "left" | "right" | "none" | "flat";
|
|
2860
|
+
/** One operator of a syntax profile. */
|
|
2861
|
+
interface SyntaxOperator {
|
|
2862
|
+
/** The text of the operator, for example `+`, `<>` or `and`. A word operator is a plain name. */
|
|
2863
|
+
readonly symbol: string;
|
|
2864
|
+
/** The place of the operator. */
|
|
2865
|
+
readonly fixity: SyntaxFixity;
|
|
2866
|
+
/** The precedence. A larger number binds more tightly. */
|
|
2867
|
+
readonly prec: number;
|
|
2868
|
+
/** The grouping of a chain of an infix operator. The default is `left`. */
|
|
2869
|
+
readonly assoc?: SyntaxAssoc;
|
|
2870
|
+
/** The type of the document that the operator makes, with dots between the keys, for example `ops.add` or `and`. */
|
|
2871
|
+
readonly kind: string;
|
|
2872
|
+
}
|
|
2873
|
+
/** The literal rules of a syntax profile. */
|
|
2874
|
+
interface SyntaxLiterals {
|
|
2875
|
+
/** `false` removes the decimal numbers. The default is `true`. */
|
|
2876
|
+
readonly numbers?: boolean;
|
|
2877
|
+
/** `true` puts a minus sign right before a digit into the number, where a term starts. The default is `true`. */
|
|
2878
|
+
readonly signed?: boolean;
|
|
2879
|
+
/** The texts: the quote and the escape of a quote. `false` removes the texts. The default is `"` with backslashes. */
|
|
2880
|
+
readonly strings?: false | {
|
|
2881
|
+
readonly quote?: "\"" | "'";
|
|
2882
|
+
readonly escape?: "backslash" | "double";
|
|
2883
|
+
};
|
|
2884
|
+
/** The words that are literals, with their values. The default is `true`, `false` and `null`. */
|
|
2885
|
+
readonly words?: Readonly<Record<string, unknown>>;
|
|
2886
|
+
}
|
|
2887
|
+
/** A reference syntax that a pattern gives, for example the address `A1` of a cell. */
|
|
2888
|
+
interface SyntaxRefPattern {
|
|
2889
|
+
/** The pattern of the text of a reference. The parser tries it before a name. */
|
|
2890
|
+
readonly pattern: RegExp;
|
|
2891
|
+
/** This function gives the path of the reference from its text. */
|
|
2892
|
+
readonly read: (text: string) => readonly Key[];
|
|
2893
|
+
/** This function gives the text of a path, or `undefined` when the pattern does not write the path. */
|
|
2894
|
+
readonly write: (path: readonly unknown[]) => string | undefined;
|
|
2895
|
+
}
|
|
2896
|
+
/** The reference syntax of a syntax profile. */
|
|
2897
|
+
interface SyntaxRefs {
|
|
2898
|
+
/** The root of a bare name. The default is `names`. Thus `x` is the path `["names", "x"]`. */
|
|
2899
|
+
readonly bare?: string;
|
|
2900
|
+
/** The roots that the text names first, for example `self.price`. The default is `self`, `world`, `event` and `caps`. */
|
|
2901
|
+
readonly roots?: readonly string[];
|
|
2902
|
+
/** `false` removes the field steps `a.b`. The default is `true`. */
|
|
2903
|
+
readonly fields?: boolean;
|
|
2904
|
+
/** The patterns of other references. */
|
|
2905
|
+
readonly patterns?: readonly SyntaxRefPattern[];
|
|
2906
|
+
}
|
|
2907
|
+
/** A call form: a name with arguments in parentheses that makes a construct, for example `if(test, then, else)`. */
|
|
2908
|
+
interface SyntaxForm {
|
|
2909
|
+
/** The name in the text. */
|
|
2910
|
+
readonly name: string;
|
|
2911
|
+
/** The type of the document, with dots between the keys. */
|
|
2912
|
+
readonly kind: string;
|
|
2913
|
+
/** The fields of the value, in the order of the arguments. Without them, the value is the list of the arguments. */
|
|
2914
|
+
readonly fields?: readonly string[];
|
|
2915
|
+
/** The smallest number of arguments. The default is the number of the fields, or `0`. */
|
|
2916
|
+
readonly min?: number;
|
|
2917
|
+
}
|
|
2918
|
+
/** The call syntax of a syntax profile. */
|
|
2919
|
+
interface SyntaxCalls {
|
|
2920
|
+
/** The operations that a call `name(args)` can name. `true` permits each name. The default is `true`. */
|
|
2921
|
+
readonly ops?: boolean | readonly string[];
|
|
2922
|
+
/** The call forms of constructs. A form wins over an operation with the same name. */
|
|
2923
|
+
readonly forms?: readonly SyntaxForm[];
|
|
2924
|
+
/** The text between two arguments. The default is `,`. */
|
|
2925
|
+
readonly separator?: string;
|
|
2926
|
+
}
|
|
2927
|
+
/**
|
|
2928
|
+
* The text syntax of a language (D41): an operator table, literal rules, reference syntax and call syntax. `parse`
|
|
2929
|
+
* reads a text into a document, and `print` writes a document as text. The profile is data, thus a site, an editor
|
|
2930
|
+
* and a language read the same rules.
|
|
2931
|
+
*/
|
|
2932
|
+
interface SyntaxProfile {
|
|
2933
|
+
/** The operators. */
|
|
2934
|
+
readonly operators?: readonly SyntaxOperator[];
|
|
2935
|
+
/** The literal rules. */
|
|
2936
|
+
readonly literals?: SyntaxLiterals;
|
|
2937
|
+
/** The reference syntax. */
|
|
2938
|
+
readonly refs?: SyntaxRefs;
|
|
2939
|
+
/** The call syntax. */
|
|
2940
|
+
readonly calls?: SyntaxCalls;
|
|
2941
|
+
/** The deepest nesting that `parse` accepts. The default is `256`. */
|
|
2942
|
+
readonly maxDepth?: number;
|
|
2943
|
+
}
|
|
2944
|
+
/** A problem of a text: its character offset, its length and a message. */
|
|
2945
|
+
interface SyntaxIssue {
|
|
2946
|
+
/** The 0-based character offset of the problem. */
|
|
2947
|
+
readonly offset: number;
|
|
2948
|
+
/** The number of characters of the problem. `0` marks a place between two characters. */
|
|
2949
|
+
readonly length: number;
|
|
2950
|
+
/** The message. */
|
|
2951
|
+
readonly message: string;
|
|
2952
|
+
}
|
|
2953
|
+
/** The result of `parse`: a document, or the problems of the text. */
|
|
2954
|
+
type ParseResult = {
|
|
2955
|
+
readonly ok: true;
|
|
2956
|
+
readonly doc: Json;
|
|
2957
|
+
} | {
|
|
2958
|
+
readonly ok: false;
|
|
2959
|
+
readonly issues: readonly SyntaxIssue[];
|
|
2960
|
+
};
|
|
2961
|
+
/**
|
|
2962
|
+
* The standard syntax of the formula kit. It gives the site and the playground a text form. The operators are
|
|
2963
|
+
* `or`, `and`, `not`, the comparisons, `+ - * / %`, a minus sign and `^`, from the loosest to the tightest. A call
|
|
2964
|
+
* `name(args)` applies the operation `ops.name`. `if(test, then, else)` and `list(items)` make the constructs.
|
|
2965
|
+
*/
|
|
2966
|
+
export declare const STD_SYNTAX: SyntaxProfile;
|
|
2967
|
+
/**
|
|
2968
|
+
* This function reads a text into a document with the rules of a profile (SYNTAX.PARSE). It does not throw for a
|
|
2969
|
+
* bad text. The issue gives the offset, the length and a message (SYNTAX.SPAN).
|
|
2970
|
+
*
|
|
2971
|
+
* @param profile - The syntax profile.
|
|
2972
|
+
* @param text - The text.
|
|
2973
|
+
* @returns The document, or the issues of the text.
|
|
2974
|
+
* @throws {TypeError} The profile is not valid, for example an operator has two entries of the same place.
|
|
2975
|
+
*/
|
|
2976
|
+
export declare function parse(profile: SyntaxProfile, text: string): ParseResult;
|
|
2977
|
+
/**
|
|
2978
|
+
* This function writes a document as text with the rules of a profile (SYNTAX.PRINT). It writes the fewest
|
|
2979
|
+
* parentheses that keep the tree. `parse` reads the text back to the same document (SYNTAX.ROUNDTRIP).
|
|
2980
|
+
*
|
|
2981
|
+
* @param profile - The syntax profile.
|
|
2982
|
+
* @param doc - The document.
|
|
2983
|
+
* @returns The text, or `#VALUE!` at the place of a document that the profile cannot write.
|
|
2984
|
+
* @throws {TypeError} The profile is not valid.
|
|
2985
|
+
*/
|
|
2986
|
+
export declare function print(profile: SyntaxProfile, doc: unknown): Result<string>;
|
|
2987
|
+
/**
|
|
2988
|
+
* This function makes the part of a merge that adds the verb `format` to a machine (D23, D41). Its default writes
|
|
2989
|
+
* each document with the printer of the profile. A part gives its own text through the ladder, thus an own entry or
|
|
2990
|
+
* a kind entry of `format` still wins.
|
|
2991
|
+
*
|
|
2992
|
+
* @param profile - The syntax profile.
|
|
2993
|
+
* @returns The part for `mergeMachines`.
|
|
2994
|
+
*/
|
|
2995
|
+
export declare function syntaxFormat(profile: SyntaxProfile): MachinePart;
|
|
2996
|
+
//#endregion
|
|
2704
2997
|
//#region src/reference.d.ts
|
|
2705
2998
|
/**
|
|
2706
2999
|
* The definitional code of the reference, by evaluator name. The reference cannot read compiled code, thus each
|
|
@@ -2763,9 +3056,11 @@ export declare function formulaDefinitions(profile?: FormulaProfile): Definition
|
|
|
2763
3056
|
* - `reference`: the reference interpreter, which compiles nothing.
|
|
2764
3057
|
* - `traced`: the traced evaluation, `evaluate`.
|
|
2765
3058
|
* - `again`: a second evaluation of the same plan.
|
|
3059
|
+
* - `folds`: a second plan with the other choice of folds (PLAN.FOLD). It has no folds when the plan has them, and
|
|
3060
|
+
* it has folds when the option `observe` stops the folds of the plan.
|
|
2766
3061
|
* - `other`: the second tier of a language, from the option `other`.
|
|
2767
3062
|
*/
|
|
2768
|
-
type Tier = "reference" | "traced" | "again" | "other";
|
|
3063
|
+
type Tier = "reference" | "traced" | "again" | "folds" | "other";
|
|
2769
3064
|
/** What a second tier gives: its result, and its effects when it records them. */
|
|
2770
3065
|
interface TierResult {
|
|
2771
3066
|
readonly result: Result;
|
|
@@ -2790,7 +3085,10 @@ interface AgreeOptions {
|
|
|
2790
3085
|
readonly verb?: string;
|
|
2791
3086
|
/** The definitional code of the compiled evaluators of the machine, for the reference. */
|
|
2792
3087
|
readonly definitions?: Definitions;
|
|
2793
|
-
/**
|
|
3088
|
+
/**
|
|
3089
|
+
* The tiers to compare with the plan. The default is the reference, the traced evaluation, a second evaluation and
|
|
3090
|
+
* the plan with the other choice of folds.
|
|
3091
|
+
*/
|
|
2794
3092
|
readonly tiers?: readonly Exclude<Tier, "other">[];
|
|
2795
3093
|
/**
|
|
2796
3094
|
* This function gives the result of the second tier of a language, for example a compiler to loops.
|
|
@@ -2819,7 +3117,8 @@ interface AgreeOptions {
|
|
|
2819
3117
|
/**
|
|
2820
3118
|
* This function gives what the host saw since its last call, for example the calls of an operation. `agree` uses
|
|
2821
3119
|
* it before the plan and after each tier, and compares the results. Thus a tier that evaluates a part that the plan
|
|
2822
|
-
* does not evaluate fails.
|
|
3120
|
+
* does not evaluate fails. A fold moves the calls of a part to the compilation, thus with this option the plan has
|
|
3121
|
+
* no folds. The tier `folds` then has folds, and `agree` does not compare its calls.
|
|
2823
3122
|
*
|
|
2824
3123
|
* @returns What the host saw.
|
|
2825
3124
|
*/
|
|
@@ -3611,5 +3910,5 @@ interface SampleOptions {
|
|
|
3611
3910
|
*/
|
|
3612
3911
|
export declare function typeFromSamples(values: readonly unknown[], options?: SampleOptions): ValueType;
|
|
3613
3912
|
//#endregion
|
|
3614
|
-
export type { AgreeOptions, Agreement, Alias, AllOptions, Answer, AskOptions, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, ConformOptions, ConformProbe, Construct, Context, Part as ContextPart, Definitions, DerefCode, DocFacts, DocParts, DocVisit, Domain, 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, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartType, PartsSpec, Perform, Plan, PrepareOptions, Random, Read, ReadsCheck, Recorder, RefUse, ReferenceOptions, ReplayEntry, ReplayLog, ReplayOptions, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, RootTypes, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, SampleOptions, Schedule, ScheduleCounts, ScheduleOptions, ScopeRule, Shape$1 as Shape, Side, Signature, Split, StaticRead, Step, StepSpec, Steps, StopSignal, Stored, Thing, Tier, TierInput, TierResult, TraceNode, TypeInput, TypeIssue, TypeProblem, TypeReading, TypeRef, TypeRule, Typed, Typing, Use, ValueType, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldPart };
|
|
3913
|
+
export type { AgreeOptions, 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, PrepareOptions, Random, Read, ReadsCheck, Recorder, RefUse, ReferenceOptions, ReplayEntry, ReplayLog, ReplayOptions, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, RootTypes, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, SampleOptions, Schedule, ScheduleCounts, 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, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldPart };
|
|
3615
3914
|
//# sourceMappingURL=index.d.ts.map
|