@toiroakr/chisel 0.1.0 → 0.3.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 +354 -21
- package/dist/absence.d.ts +28 -0
- package/dist/absence.js +266 -0
- package/dist/absence.js.map +1 -0
- package/dist/behavior.d.ts +26 -19
- package/dist/behavior.js +193 -203
- package/dist/behavior.js.map +1 -1
- package/dist/beside.d.ts +5 -0
- package/dist/beside.js +10 -0
- package/dist/beside.js.map +1 -1
- package/dist/border.d.ts +7 -8
- package/dist/border.js +88 -36
- package/dist/border.js.map +1 -1
- package/dist/bounds.d.ts +1 -0
- package/dist/bounds.js +27 -0
- package/dist/bounds.js.map +1 -0
- package/dist/changes.d.ts +23 -0
- package/dist/changes.js +355 -0
- package/dist/changes.js.map +1 -0
- package/dist/checks.d.ts +1 -0
- package/dist/checks.js +295 -0
- package/dist/checks.js.map +1 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +351 -14
- package/dist/cli.js.map +1 -1
- package/dist/codec.js +16 -7
- package/dist/codec.js.map +1 -1
- package/dist/codegen.js +6 -8
- package/dist/codegen.js.map +1 -1
- package/dist/composition.d.ts +3 -3
- package/dist/composition.js +9 -8
- package/dist/composition.js.map +1 -1
- package/dist/conformance.d.ts +24 -0
- package/dist/conformance.js +44 -0
- package/dist/conformance.js.map +1 -0
- package/dist/data.d.ts +3 -2
- package/dist/data.js +7 -3
- package/dist/data.js.map +1 -1
- package/dist/decimal-js.d.ts +2 -0
- package/dist/decimal-js.js +5 -0
- package/dist/decimal-js.js.map +1 -0
- package/dist/decimal.d.ts +2 -0
- package/dist/decimal.js +3 -0
- package/dist/decimal.js.map +1 -0
- package/dist/dependency.d.ts +9 -6
- package/dist/dependency.js +23 -17
- package/dist/dependency.js.map +1 -1
- package/dist/domain.d.ts +6 -2
- package/dist/domain.js +65 -25
- package/dist/domain.js.map +1 -1
- package/dist/ensures.js +3 -3
- package/dist/ensures.js.map +1 -1
- package/dist/equal.d.ts +1 -0
- package/dist/equal.js +135 -0
- package/dist/equal.js.map +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/exact.d.ts +13 -1
- package/dist/exact.js +52 -3
- package/dist/exact.js.map +1 -1
- package/dist/feasibility.d.ts +5 -3
- package/dist/feasibility.js +309 -53
- package/dist/feasibility.js.map +1 -1
- package/dist/guard-borders.d.ts +14 -5
- package/dist/guard-borders.js +229 -190
- package/dist/guard-borders.js.map +1 -1
- package/dist/guard-scope.d.ts +65 -0
- package/dist/guard-scope.js +384 -0
- package/dist/guard-scope.js.map +1 -0
- package/dist/hooks.d.ts +22 -0
- package/dist/hooks.js +2 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +30 -8
- package/dist/index.js +18 -5
- package/dist/index.js.map +1 -1
- package/dist/interleave.d.ts +31 -0
- package/dist/interleave.js +202 -0
- package/dist/interleave.js.map +1 -0
- package/dist/interval.d.ts +8 -0
- package/dist/interval.js +213 -23
- package/dist/interval.js.map +1 -1
- package/dist/isolated.d.ts +7 -1
- package/dist/isolated.js +53 -5
- package/dist/isolated.js.map +1 -1
- package/dist/kinds/decimal.d.ts +1 -0
- package/dist/kinds/decimal.js +16 -0
- package/dist/kinds/decimal.js.map +1 -0
- package/dist/kinds/rational.d.ts +1 -0
- package/dist/kinds/rational.js +13 -0
- package/dist/kinds/rational.js.map +1 -0
- package/dist/kinds/temporal.d.ts +1 -0
- package/dist/kinds/temporal.js +15 -0
- package/dist/kinds/temporal.js.map +1 -0
- package/dist/lean/behavior.d.ts +29 -0
- package/dist/lean/behavior.js +76 -0
- package/dist/lean/behavior.js.map +1 -0
- package/dist/lean/given.d.ts +10 -0
- package/dist/lean/given.js +15 -0
- package/dist/lean/given.js.map +1 -0
- package/dist/lean/index.d.ts +11 -0
- package/dist/lean/index.js +8 -0
- package/dist/lean/index.js.map +1 -0
- package/dist/lean/model.d.ts +20 -0
- package/dist/lean/model.js +133 -0
- package/dist/lean/model.js.map +1 -0
- package/dist/lean/protocol.d.ts +14 -0
- package/dist/lean/protocol.js +34 -0
- package/dist/lean/protocol.js.map +1 -0
- package/dist/lean/rule.d.ts +54 -0
- package/dist/lean/rule.js +149 -0
- package/dist/lean/rule.js.map +1 -0
- package/dist/lean/schema.d.ts +46 -0
- package/dist/lean/schema.js +155 -0
- package/dist/lean/schema.js.map +1 -0
- package/dist/machine-check.d.ts +73 -0
- package/dist/machine-check.js +215 -0
- package/dist/machine-check.js.map +1 -0
- package/dist/machine.d.ts +122 -0
- package/dist/machine.js +271 -0
- package/dist/machine.js.map +1 -0
- package/dist/model.d.ts +110 -11
- package/dist/model.js +724 -80
- package/dist/model.js.map +1 -1
- package/dist/off-grid.d.ts +4 -0
- package/dist/off-grid.js +92 -0
- package/dist/off-grid.js.map +1 -0
- package/dist/outcomes.d.ts +15 -0
- package/dist/outcomes.js +120 -0
- package/dist/outcomes.js.map +1 -0
- package/dist/pairs.js +14 -5
- package/dist/pairs.js.map +1 -1
- package/dist/partition.d.ts +1 -0
- package/dist/partition.js +101 -19
- package/dist/partition.js.map +1 -1
- package/dist/placeholders.d.ts +3 -0
- package/dist/placeholders.js +44 -0
- package/dist/placeholders.js.map +1 -0
- package/dist/proof.d.ts +6 -0
- package/dist/proof.js +282 -56
- package/dist/proof.js.map +1 -1
- package/dist/protocol.d.ts +22 -0
- package/dist/protocol.js +12 -0
- package/dist/protocol.js.map +1 -0
- package/dist/relations.d.ts +30 -0
- package/dist/relations.js +235 -0
- package/dist/relations.js.map +1 -0
- package/dist/replay.d.ts +45 -0
- package/dist/replay.js +157 -0
- package/dist/replay.js.map +1 -0
- package/dist/rewrites.d.ts +41 -0
- package/dist/rewrites.js +180 -0
- package/dist/rewrites.js.map +1 -0
- package/dist/rule.d.ts +74 -11
- package/dist/rule.js +429 -22
- package/dist/rule.js.map +1 -1
- package/dist/runtime.d.ts +12 -0
- package/dist/runtime.js +8 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema.d.ts +44 -28
- package/dist/schema.js +50 -113
- package/dist/schema.js.map +1 -1
- package/dist/specification.d.ts +23 -3
- package/dist/specification.js +1001 -96
- package/dist/specification.js.map +1 -1
- package/dist/stops.d.ts +20 -0
- package/dist/stops.js +221 -0
- package/dist/stops.js.map +1 -0
- package/dist/temporal-global.d.ts +4 -0
- package/dist/temporal-global.js +11 -0
- package/dist/temporal-global.js.map +1 -0
- package/dist/temporal.d.ts +22 -0
- package/dist/temporal.js +113 -0
- package/dist/temporal.js.map +1 -0
- package/dist/tla-validate.d.ts +31 -0
- package/dist/tla-validate.js +151 -0
- package/dist/tla-validate.js.map +1 -0
- package/dist/tla.d.ts +61 -0
- package/dist/tla.js +722 -0
- package/dist/tla.js.map +1 -0
- package/dist/verification.d.ts +9 -0
- package/dist/verification.js +7 -0
- package/dist/verification.js.map +1 -0
- package/dist/ways.d.ts +11 -5
- package/dist/ways.js +51 -45
- package/dist/ways.js.map +1 -1
- package/dist/world.d.ts +98 -0
- package/dist/world.js +463 -0
- package/dist/world.js.map +1 -0
- package/package.json +49 -10
- package/schema/report.schema.json +169 -1
package/dist/guard-borders.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
const deps = { ...object(Object.fromEntries(values)) };
|
|
13
|
-
return { ...variant, shape: { ...variant.shape, [DEPS]: deps } };
|
|
14
|
-
}
|
|
1
|
+
import { MAX_DATE_TIME } from "./rule.js";
|
|
2
|
+
import { temporalNeighbor, timelineOf } from "./temporal.js";
|
|
3
|
+
import { deepEqual } from "./equal.js";
|
|
4
|
+
import { bordersOf, decimalCarrier, decimalUnitsCarrier, integerCarrier, nanosecondCarrier, normalize, numberCarrier } from "./border.js";
|
|
5
|
+
import { decimalOf, fractionOf, isOutOfRoom } from "./exact.js";
|
|
6
|
+
import { carrierOf, positionsOf, writeExactly } from "./partition.js";
|
|
7
|
+
import { DEPS, boundTermPath, conjuncts, describeRule, holds, isDecimal, isTerm, readOperand, selfTerm, shiftTerms, termData, termPaths, positionData, positionOf, positionTerm, differenceOf, sameElement, withDeps, decimalOfUnits, decimalUnits, counts, measured, measureLabel } from "./rule.js";
|
|
8
|
+
import { enumOf, int, isVariantsSchema, object, variants } from "./schema.js";
|
|
9
|
+
import { casesOnTrail, enter, everyStepsOf, framesAt, framesFor, guardScope, inheritedAt, labelsOf, locate, onTrail, pathOf, relationThresholdsIn, schemaAlong, schemaAt, segmentsOf, thresholdsIn } from "./guard-scope.js";
|
|
10
|
+
import { RELATION_LIMIT, relationClasses } from "./relations.js";
|
|
15
11
|
// The case as feasibility reads it: the invariants written on the input sum
|
|
16
12
|
// hold of every case, as the partition passes them down, and read the
|
|
17
13
|
// discriminant as the one value it has under this case.
|
|
18
|
-
export function feasibilityScope(definition, tag) {
|
|
19
|
-
const scope = guardScope(definition, tag);
|
|
14
|
+
export function feasibilityScope(definition, tag, decision, steps = []) {
|
|
15
|
+
const scope = guardScope(definition, tag, decision, steps);
|
|
20
16
|
const { discriminant } = definition.input;
|
|
21
17
|
return {
|
|
22
18
|
...scope,
|
|
@@ -29,18 +25,18 @@ export function feasibilityScope(definition, tag) {
|
|
|
29
25
|
export function guardBordersOf(implementation) {
|
|
30
26
|
const input = implementation.behavior.input;
|
|
31
27
|
const positions = positionsOf(input, { containers: true });
|
|
32
|
-
const at = (segments) => positions.find(position =>
|
|
28
|
+
const at = (segments) => positions.find(position => deepEqual(position.segments, segments));
|
|
33
29
|
return Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules"
|
|
34
30
|
? []
|
|
35
|
-
: decision.guards.flatMap(candidate => walk(candidate.condition,
|
|
31
|
+
: decision.guards.flatMap(candidate => walk(candidate.condition, framesFor(implementation.behavior, tag, decision), at, asGuard).map(drawn => ({
|
|
36
32
|
...drawn,
|
|
37
|
-
origin: { decision, scope: feasibilityScope(implementation.behavior, tag), tag },
|
|
33
|
+
origin: { decision, scope: feasibilityScope(implementation.behavior, tag, decision), tag },
|
|
38
34
|
}))));
|
|
39
35
|
}
|
|
40
36
|
export function ensuresBordersOf(definition) {
|
|
41
37
|
const input = definition.input;
|
|
42
38
|
const positions = positionsOf(input);
|
|
43
|
-
const at = (segments) => positions.find(position =>
|
|
39
|
+
const at = (segments) => positions.find(position => deepEqual(position.segments, segments));
|
|
44
40
|
return definition.ensures.flatMap(clause => conjuncts(clause.rule).flatMap(part => {
|
|
45
41
|
const onInput = unrooted(part);
|
|
46
42
|
if (onInput === undefined) {
|
|
@@ -57,7 +53,7 @@ export function ensuresBordersOf(definition) {
|
|
|
57
53
|
// no single position carries.
|
|
58
54
|
export function invariantPairBordersOf(definition) {
|
|
59
55
|
const positions = positionsOf(definition.input, { containers: true });
|
|
60
|
-
const at = (segments) => positions.find(position =>
|
|
56
|
+
const at = (segments) => positions.find(position => deepEqual(position.segments, segments));
|
|
61
57
|
const reading = {
|
|
62
58
|
source: "invariant",
|
|
63
59
|
describe: (compared, read) => describeRule(compared, read.root.label, labelsOf(read)),
|
|
@@ -214,103 +210,23 @@ export function guardPartitionsOf(implementation) {
|
|
|
214
210
|
const input = implementation.behavior.input;
|
|
215
211
|
const thresholds = Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules"
|
|
216
212
|
? []
|
|
217
|
-
: decision.guards.flatMap(candidate => thresholdsIn(candidate.condition,
|
|
218
|
-
const
|
|
213
|
+
: decision.guards.flatMap(candidate => thresholdsIn(candidate.condition, framesFor(implementation.behavior, tag, decision))));
|
|
214
|
+
const relations = Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules"
|
|
215
|
+
? []
|
|
216
|
+
: decision.guards.flatMap(candidate => relationThresholdsIn(candidate.condition, framesFor(implementation.behavior, tag, decision))));
|
|
217
|
+
const trails = [...new Set([...thresholds, ...relations].map(threshold => JSON.stringify(threshold.segments)))];
|
|
219
218
|
return trails.flatMap(trail => {
|
|
220
219
|
const atPath = thresholds.filter(threshold => JSON.stringify(threshold.segments) === trail);
|
|
221
|
-
const
|
|
222
|
-
|
|
220
|
+
const related = relations.filter(threshold => JSON.stringify(threshold.segments) === trail);
|
|
221
|
+
const first = atPath[0] ?? related[0];
|
|
222
|
+
const partition = atPath.length === 0 ? undefined : partitionAt(first.path, first.segments, first.schema, first.inherited, atPath.map(threshold => threshold.rule));
|
|
223
|
+
if (related.length === 0)
|
|
224
|
+
return partition === undefined ? [] : [partition];
|
|
225
|
+
// The relations divide the place within each class the comparisons divide it into.
|
|
226
|
+
const { classes, excluded } = relationClasses(related.map(threshold => threshold.rule), first.schema, partition?.classes ?? [], first.inherited);
|
|
227
|
+
return [{ path: first.path, segments: first.segments, classes, excluded: [...(partition?.excluded ?? []), ...excluded] }];
|
|
223
228
|
});
|
|
224
229
|
}
|
|
225
|
-
// Guards are read here rather than through offGridEquality, since a guard's
|
|
226
|
-
// terms reach the dependencies and are located through the guard's frames.
|
|
227
|
-
export function offGridEqualityIn(definition, tag, decision) {
|
|
228
|
-
const frames = framesAt(guardScope(definition, tag), `@${tag}`, "$");
|
|
229
|
-
for (const threshold of decision.guards.flatMap(candidate => thresholdsIn(candidate.condition, frames))) {
|
|
230
|
-
const { operator, bound } = normalize(threshold.rule);
|
|
231
|
-
if (holdsNoDecimal(threshold.schema, operator, bound)) {
|
|
232
|
-
const scale = threshold.schema.scale;
|
|
233
|
-
return `compares ${threshold.label} with ${String(bound)}, which no decimal(${scale}) holds: ${threshold.described}`;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
const scope = guardScope(definition, tag);
|
|
237
|
-
return decision.guards
|
|
238
|
-
.map(candidate => offGridEquality(candidate.condition, path => schemaAtPath(scope, path), "$"))
|
|
239
|
-
.find(found => found !== undefined);
|
|
240
|
-
}
|
|
241
|
-
function framesAt(scope, path, label) {
|
|
242
|
-
return { root: { scope, path, segments: [path], label }, elements: {} };
|
|
243
|
-
}
|
|
244
|
-
function locate(term, frames) {
|
|
245
|
-
const keys = positionOf(term).path;
|
|
246
|
-
const element = keys[0] === undefined ? undefined : frames.elements[keys[0]];
|
|
247
|
-
return element === undefined
|
|
248
|
-
? { frame: frames.root, keys }
|
|
249
|
-
: { frame: element, keys: keys.slice(1) };
|
|
250
|
-
}
|
|
251
|
-
function enter(rule, frames) {
|
|
252
|
-
const { frame, keys } = locate(rule.of, frames);
|
|
253
|
-
const collection = schemaAt(frame.scope, keys);
|
|
254
|
-
if (collection?.kind !== "array") {
|
|
255
|
-
return undefined;
|
|
256
|
-
}
|
|
257
|
-
const suffix = keys.map(key => `.${key}`).join("");
|
|
258
|
-
return {
|
|
259
|
-
root: frames.root,
|
|
260
|
-
elements: {
|
|
261
|
-
...frames.elements,
|
|
262
|
-
[rule.element]: {
|
|
263
|
-
scope: collection.element,
|
|
264
|
-
path: `${frame.path}${suffix}[]`,
|
|
265
|
-
segments: [...segmentsOf(frame, keys), "[]"],
|
|
266
|
-
label: `${frame.label}${suffix}[]`,
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
function labelsOf(frames) {
|
|
272
|
-
return Object.fromEntries(Object.entries(frames.elements).map(([name, frame]) => [name, frame.label]));
|
|
273
|
-
}
|
|
274
|
-
function pathOf(frame, keys) {
|
|
275
|
-
return `${frame.path}${keys.map(key => `.${key}`).join("")}`;
|
|
276
|
-
}
|
|
277
|
-
// The rendered path is for reports; positions are found by segments, since a
|
|
278
|
-
// key holding "." renders the same as the nested path it spells.
|
|
279
|
-
function segmentsOf(frame, keys) {
|
|
280
|
-
return [...frame.segments, ...keys.map(key => `.${key}`)];
|
|
281
|
-
}
|
|
282
|
-
function thresholdsIn(rule, frames) {
|
|
283
|
-
if (rule.kind === "and" || rule.kind === "or") {
|
|
284
|
-
return rule.rules.flatMap(part => thresholdsIn(part, frames));
|
|
285
|
-
}
|
|
286
|
-
if (rule.kind === "not") {
|
|
287
|
-
return thresholdsIn(rule.rule, frames);
|
|
288
|
-
}
|
|
289
|
-
if (rule.kind === "all" || rule.kind === "any") {
|
|
290
|
-
const inner = enter(rule, frames);
|
|
291
|
-
return inner === undefined ? [] : thresholdsIn(rule.each, inner);
|
|
292
|
-
}
|
|
293
|
-
const normalized = normalize(rule);
|
|
294
|
-
if (rule.kind !== "compare" || normalized === undefined || normalized.measure !== "value") {
|
|
295
|
-
return [];
|
|
296
|
-
}
|
|
297
|
-
const term = (isTerm(rule.left) ? rule.left : rule.right);
|
|
298
|
-
const { frame, keys } = locate(term, frames);
|
|
299
|
-
const schema = schemaAt(frame.scope, keys);
|
|
300
|
-
return schema === undefined
|
|
301
|
-
? []
|
|
302
|
-
: [
|
|
303
|
-
{
|
|
304
|
-
path: pathOf(frame, keys),
|
|
305
|
-
label: `${frame.label}${keys.map(key => `.${key}`).join("")}`,
|
|
306
|
-
described: describeRule(rule, frames.root.label, labelsOf(frames)),
|
|
307
|
-
segments: segmentsOf(frame, keys),
|
|
308
|
-
schema,
|
|
309
|
-
inherited: inheritedAt(frame.scope, keys),
|
|
310
|
-
rule,
|
|
311
|
-
},
|
|
312
|
-
];
|
|
313
|
-
}
|
|
314
230
|
function partitionAt(path, segments, schema, inherited, rules) {
|
|
315
231
|
const carrier = carrierOf(schema, "value");
|
|
316
232
|
if (carrier === undefined) {
|
|
@@ -349,7 +265,7 @@ function partitionAt(path, segments, schema, inherited, rules) {
|
|
|
349
265
|
(to === undefined ||
|
|
350
266
|
carrier.compare(value, to.value) < 0 ||
|
|
351
267
|
(to.inclusive && carrier.compare(value, to.value) === 0));
|
|
352
|
-
|
|
268
|
+
let witness = from === undefined
|
|
353
269
|
? to === undefined
|
|
354
270
|
? undefined
|
|
355
271
|
: to.inclusive
|
|
@@ -358,6 +274,12 @@ function partitionAt(path, segments, schema, inherited, rules) {
|
|
|
358
274
|
: from.inclusive
|
|
359
275
|
? from.value
|
|
360
276
|
: (carrier.step?.(from.value, 1) ?? carrier.past?.(from.value, 1));
|
|
277
|
+
// A bound's neighbour (or a whole unit past it) may lie beyond the other edge, where the interval still holds values between them.
|
|
278
|
+
if ((witness === undefined || !contains(witness)) && from !== undefined && to !== undefined && carrier.between !== undefined) {
|
|
279
|
+
const between = carrier.between(from.value, to.value);
|
|
280
|
+
if (between !== undefined && contains(between))
|
|
281
|
+
witness = between;
|
|
282
|
+
}
|
|
361
283
|
const single = from !== undefined &&
|
|
362
284
|
to !== undefined &&
|
|
363
285
|
from.inclusive &&
|
|
@@ -374,22 +296,20 @@ function partitionAt(path, segments, schema, inherited, rules) {
|
|
|
374
296
|
excluded.push(name);
|
|
375
297
|
continue;
|
|
376
298
|
}
|
|
377
|
-
classes.push({ name, witness, contains });
|
|
299
|
+
classes.push({ name, witness, contains, ...(single ? { only: true } : {}) });
|
|
378
300
|
}
|
|
379
301
|
return { path, segments, classes, excluded };
|
|
380
302
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
303
|
+
// A decimal past the digits exact arithmetic has room for gives no coordinate and no row, as the decimal carrier gives no run past it.
|
|
304
|
+
function withinRoom(compute) {
|
|
305
|
+
try {
|
|
306
|
+
return compute();
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
if (isOutOfRoom(error))
|
|
310
|
+
return undefined;
|
|
311
|
+
throw error;
|
|
386
312
|
}
|
|
387
|
-
const field = unwrapped.shape[key];
|
|
388
|
-
const here = unwrapped.invariants.flatMap(conjuncts).flatMap(rule => {
|
|
389
|
-
const stepped = keys.reduce((current, next) => (current === undefined ? undefined : stepInto(current, next)), rule);
|
|
390
|
-
return stepped === undefined ? [] : [stepped];
|
|
391
|
-
});
|
|
392
|
-
return field === undefined ? here : [...here, ...inheritedAt(field, rest)];
|
|
393
313
|
}
|
|
394
314
|
function admittedRange(invariants, carrier) {
|
|
395
315
|
let lower;
|
|
@@ -433,6 +353,11 @@ function walk(rule, frames, at, reading) {
|
|
|
433
353
|
const inner = enter(rule, frames);
|
|
434
354
|
return inner === undefined ? [] : walk(rule.each, inner, at, reading);
|
|
435
355
|
}
|
|
356
|
+
// A relation draws no line: its classes divide the place it reads, and its
|
|
357
|
+
// arms ask a row on each side of it.
|
|
358
|
+
if (rule.kind === "relation") {
|
|
359
|
+
return [];
|
|
360
|
+
}
|
|
436
361
|
if ([rule.left, rule.right].some(operand => isTerm(operand) && positionData(operand) === undefined)) {
|
|
437
362
|
return betweenExpression(rule, frames, at, reading);
|
|
438
363
|
}
|
|
@@ -445,48 +370,70 @@ function walk(rule, frames, at, reading) {
|
|
|
445
370
|
}
|
|
446
371
|
const { frame, keys } = locate(term, frames);
|
|
447
372
|
const { measure } = positionOf(term);
|
|
448
|
-
const
|
|
449
|
-
if (
|
|
373
|
+
const whole = schemaAt(frame.scope, keys);
|
|
374
|
+
if (whole === undefined) {
|
|
450
375
|
return [];
|
|
451
376
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
377
|
+
// A field the cases of a sum share is drawn under each, read as that case declares it.
|
|
378
|
+
return everyStepsOf(frame.scope, keys).flatMap(steps => {
|
|
379
|
+
const schema = schemaAlong(frame.scope, keys, steps) ?? whole;
|
|
380
|
+
const borders = bordersOf([rule], found => carrierOf(schema, found), {
|
|
381
|
+
source: reading.source,
|
|
382
|
+
describe: () => reading.describe(rule, frames),
|
|
383
|
+
admits: coordinate => measure !== "value" ||
|
|
384
|
+
(schema.parse(coordinate).success &&
|
|
385
|
+
inheritedAt(frame.scope, keys, steps).every(inherited => holds(inherited, coordinate))),
|
|
386
|
+
});
|
|
387
|
+
const positionPath = pathOf(frame, keys, steps);
|
|
388
|
+
const positionSegments = [...frame.segments, ...steps];
|
|
389
|
+
return borders.map(border => ({
|
|
390
|
+
path: positionPath,
|
|
391
|
+
segments: positionSegments,
|
|
392
|
+
comparison: rule,
|
|
393
|
+
border,
|
|
394
|
+
cases: casesOnTrail(frame.scope, keys, steps).map(item => ({ at: frame === frames.root ? item.at : [positionOf(term).path[0], ...item.at], discriminant: item.sum.discriminant, tag: item.tag })),
|
|
395
|
+
coordinateOf: (reached) => onTrail(frame.scope, keys, steps, frame === frames.root ? reached.scope : readOperand(positionTerm([positionOf(term).path[0]], "value"), reached.scope)) ? readOperand(term, reached.scope) : undefined,
|
|
396
|
+
compose: (given, coordinate) => {
|
|
397
|
+
const position = at(positionSegments);
|
|
398
|
+
return position === undefined ? undefined : writeExactly(position, given, measure, coordinate);
|
|
399
|
+
},
|
|
400
|
+
}));
|
|
458
401
|
});
|
|
459
|
-
const positionPath = pathOf(frame, keys);
|
|
460
|
-
const positionSegments = segmentsOf(frame, keys);
|
|
461
|
-
return borders.map(border => ({
|
|
462
|
-
path: positionPath,
|
|
463
|
-
segments: positionSegments,
|
|
464
|
-
comparison: rule,
|
|
465
|
-
border,
|
|
466
|
-
coordinateOf: reached => readOperand(term, reached.scope),
|
|
467
|
-
compose: (given, coordinate) => at(positionSegments)?.write(given, measure, coordinate),
|
|
468
|
-
}));
|
|
469
402
|
}
|
|
470
403
|
function betweenExpression(rule, frames, at, reading) {
|
|
471
404
|
const form = differenceOf(rule);
|
|
472
405
|
if (rule.operator === "==" || rule.operator === "!=" || typeof form.constant !== "number") {
|
|
473
406
|
return [];
|
|
474
407
|
}
|
|
475
|
-
|
|
408
|
+
// Every trail through the cases of the sums each part passes, the parts under one sum read under the same case of it.
|
|
409
|
+
const options = form.parts.map(part => {
|
|
476
410
|
const term = positionTerm(part.path, part.measure);
|
|
477
411
|
const { frame, keys } = locate(term, frames);
|
|
478
|
-
|
|
412
|
+
return everyStepsOf(frame.scope, keys).map(steps => ({
|
|
413
|
+
part, term, frame, keys, steps,
|
|
414
|
+
cases: casesOnTrail(frame.scope, keys, steps).map(item => ({ at: frame === frames.root ? item.at : [positionOf(term).path[0], ...item.at], discriminant: item.sum.discriminant, tag: item.tag })),
|
|
415
|
+
}));
|
|
416
|
+
});
|
|
417
|
+
const agree = (a, b) => a.every(one => b.every(other => one.at.join("\u0000") !== other.at.join("\u0000") || one.tag === other.tag));
|
|
418
|
+
const trails = options.reduce((all, choices) => all.flatMap(prefix => choices.filter(choice => prefix.every(held => agree(held.cases, choice.cases))).map(choice => [...prefix, choice])), [[]]);
|
|
419
|
+
return trails.flatMap(chosen => betweenExpressionOn(rule, form, chosen, frames, at, reading));
|
|
420
|
+
}
|
|
421
|
+
function betweenExpressionOn(rule, form, chosen, frames, at, reading) {
|
|
422
|
+
const parts = chosen.map(({ part, term, frame, keys, steps }) => {
|
|
423
|
+
const schema = schemaAlong(frame.scope, keys, steps) ?? schemaAt(frame.scope, keys);
|
|
479
424
|
const standsIn = frame === frames.root && keys[0] === DEPS;
|
|
480
425
|
return {
|
|
481
426
|
term,
|
|
482
427
|
coefficient: part.coefficient,
|
|
483
428
|
measure: part.measure,
|
|
484
429
|
standsIn,
|
|
485
|
-
path: standsIn ? ["deps", ...keys.slice(1)].join(".") : pathOf(frame, keys),
|
|
486
|
-
segments:
|
|
487
|
-
kind: part.measure
|
|
430
|
+
path: measureLabel(standsIn ? ["deps", ...keys.slice(1)].join(".") : pathOf(frame, keys, steps), part.measure),
|
|
431
|
+
segments: [...frame.segments, ...steps],
|
|
432
|
+
kind: counts(part.measure) ? "integer" : schema?.kind,
|
|
433
|
+
onTrail: (scope) => onTrail(frame.scope, keys, steps, frame === frames.root ? scope : readOperand(positionTerm([positionOf(term).path[0]], "value"), scope)),
|
|
488
434
|
};
|
|
489
435
|
});
|
|
436
|
+
const cases = chosen.flatMap(item => item.cases).filter((item, index, all) => all.findIndex(other => other.at.join("\u0000") === item.at.join("\u0000")) === index);
|
|
490
437
|
const carrier = parts.every(part => part.kind === "integer")
|
|
491
438
|
? integerCarrier
|
|
492
439
|
: parts.every(part => part.kind === "integer" || part.kind === "number")
|
|
@@ -527,6 +474,7 @@ function betweenExpression(rule, frames, at, reading) {
|
|
|
527
474
|
? {
|
|
528
475
|
parts: parts.map(part => ({
|
|
529
476
|
path: part.path,
|
|
477
|
+
identity: JSON.stringify([part.segments, part.measure]),
|
|
530
478
|
coefficient: part.coefficient,
|
|
531
479
|
valueOf: scope => valueOf(part, scope),
|
|
532
480
|
write: (given, value) => at(part.segments)?.write(given, part.measure, value),
|
|
@@ -540,7 +488,10 @@ function betweenExpression(rule, frames, at, reading) {
|
|
|
540
488
|
comparison: rule,
|
|
541
489
|
border,
|
|
542
490
|
...(weighed === undefined ? {} : { form: weighed }),
|
|
491
|
+
cases,
|
|
543
492
|
coordinateOf: reached => {
|
|
493
|
+
if (!parts.every(part => part.onTrail(reached.scope)))
|
|
494
|
+
return undefined;
|
|
544
495
|
let total = constant;
|
|
545
496
|
for (const part of parts) {
|
|
546
497
|
const value = valueOf(part, reached.scope);
|
|
@@ -558,37 +509,63 @@ function betweenExpression(rule, frames, at, reading) {
|
|
|
558
509
|
if (moving === undefined || moved === undefined) {
|
|
559
510
|
return undefined;
|
|
560
511
|
}
|
|
512
|
+
const partValue = (part, scope) => {
|
|
513
|
+
const value = part.standsIn
|
|
514
|
+
? readOperand(part.term, withDeps({}, deps))
|
|
515
|
+
: at(part.segments)?.valuesIn(scope)[0];
|
|
516
|
+
return value === undefined || part.standsIn || !counts(part.measure) ? value : measured(value, part.measure);
|
|
517
|
+
};
|
|
561
518
|
let rest = constant;
|
|
562
519
|
for (const part of parts) {
|
|
563
520
|
if (part === moving) {
|
|
564
521
|
continue;
|
|
565
522
|
}
|
|
566
|
-
const value = part
|
|
567
|
-
? readOperand(part.term, withDeps({}, deps))
|
|
568
|
-
: at(part.segments)?.valuesIn(given)[0];
|
|
523
|
+
const value = partValue(part, given);
|
|
569
524
|
if (value === undefined) {
|
|
570
525
|
return undefined;
|
|
571
526
|
}
|
|
572
|
-
rest += part.coefficient *
|
|
527
|
+
rest += part.coefficient * value;
|
|
573
528
|
}
|
|
574
|
-
|
|
529
|
+
const written = moved.write(given, moving.measure, (coordinate - rest) / moving.coefficient);
|
|
530
|
+
// Moving a part that another reads too, as `length(trim($.code))` reads
|
|
531
|
+
// `$.code`, moves both, so the row is kept only where it stands at the point.
|
|
532
|
+
const shared = parts.some(part => part !== moving && !part.standsIn && deepEqual(part.segments, moving.segments));
|
|
533
|
+
return !shared ||
|
|
534
|
+
parts.reduce((total, part) => {
|
|
535
|
+
const value = partValue(part, written);
|
|
536
|
+
return total === undefined || value === undefined ? undefined : total + part.coefficient * value;
|
|
537
|
+
}, constant) === coordinate
|
|
538
|
+
? written
|
|
539
|
+
: undefined;
|
|
575
540
|
},
|
|
576
541
|
}));
|
|
577
542
|
}
|
|
578
543
|
function between(rule, left, right, frames, at, reading) {
|
|
579
|
-
const
|
|
544
|
+
const options = [left, right].map(term => {
|
|
580
545
|
const { frame, keys } = locate(term, frames);
|
|
546
|
+
return everyStepsOf(frame.scope, keys).map((steps) => ({
|
|
547
|
+
term, frame, keys, steps,
|
|
548
|
+
cases: casesOnTrail(frame.scope, keys, steps).map(item => ({ at: frame === frames.root ? item.at : [positionOf(term).path[0], ...item.at], discriminant: item.sum.discriminant, tag: item.tag })),
|
|
549
|
+
}));
|
|
550
|
+
});
|
|
551
|
+
// Two sides under one sum are read under the same case of it.
|
|
552
|
+
const compatible = (a, b) => a.cases.every(one => b.cases.every(other => one.at.join("\u0000") !== other.at.join("\u0000") || one.tag === other.tag));
|
|
553
|
+
return options[0].flatMap(a => options[1].filter(b => compatible(a, b)).flatMap(b => betweenOn(rule, [a, b], frames, at, reading)));
|
|
554
|
+
}
|
|
555
|
+
function betweenOn(rule, options, frames, at, reading) {
|
|
556
|
+
const sides = options.map(({ term, frame, keys, steps }) => {
|
|
581
557
|
const { measure } = positionOf(term);
|
|
582
|
-
const schema = schemaAt(frame.scope, keys);
|
|
558
|
+
const schema = schemaAlong(frame.scope, keys, steps) ?? schemaAt(frame.scope, keys);
|
|
583
559
|
const standsIn = frame === frames.root && keys[0] === DEPS;
|
|
584
560
|
return {
|
|
585
561
|
term,
|
|
586
562
|
measure,
|
|
587
563
|
standsIn,
|
|
588
|
-
path: standsIn ? ["deps", ...keys.slice(1)].join(".") : pathOf(frame, keys),
|
|
589
|
-
segments:
|
|
590
|
-
kind: measure
|
|
564
|
+
path: measureLabel(standsIn ? ["deps", ...keys.slice(1)].join(".") : pathOf(frame, keys, steps), measure),
|
|
565
|
+
segments: [...frame.segments, ...steps],
|
|
566
|
+
kind: counts(measure) ? "integer" : schema?.kind,
|
|
591
567
|
scale: measure === "value" && schema?.kind === "decimal" ? schema.scale : 0,
|
|
568
|
+
onTrail: (scope) => onTrail(frame.scope, keys, steps, frame === frames.root ? scope : readOperand(positionTerm([positionOf(term).path[0]], "value"), scope)),
|
|
592
569
|
};
|
|
593
570
|
});
|
|
594
571
|
const [first, second] = sides;
|
|
@@ -596,17 +573,21 @@ function between(rule, left, right, frames, at, reading) {
|
|
|
596
573
|
if (carrier === undefined || rule.operator === "==" || rule.operator === "!=") {
|
|
597
574
|
return [];
|
|
598
575
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
576
|
+
// Two decimals one of which has no scale differ by an exact decimal, on no
|
|
577
|
+
// grid of units (ADR-0128): the border is drawn on that difference itself.
|
|
578
|
+
const exact = first.kind === "decimal" && second.kind === "decimal" && (first.scale === undefined || second.scale === undefined);
|
|
579
|
+
const moment = exact ? undefined
|
|
580
|
+
: first.kind === "decimal" || second.kind === "decimal"
|
|
581
|
+
? decimalMoment(first, second)
|
|
582
|
+
: first.kind === second.kind
|
|
583
|
+
? MOMENTS[first.kind ?? ""]
|
|
584
|
+
: undefined;
|
|
604
585
|
const difference = {
|
|
605
586
|
...(rule.name === undefined ? {} : { name: rule.name }),
|
|
606
587
|
kind: "compare",
|
|
607
588
|
operator: rule.operator,
|
|
608
589
|
left: selfTerm(),
|
|
609
|
-
right: carrier === nanosecondCarrier || first.kind === "decimal" || second.kind === "decimal" ? 0n : 0,
|
|
590
|
+
right: exact ? decimalOf(fractionOf(0)) : carrier === nanosecondCarrier || first.kind === "decimal" || second.kind === "decimal" ? 0n : 0,
|
|
610
591
|
};
|
|
611
592
|
const borders = bordersOf([difference], () => carrier, {
|
|
612
593
|
source: reading.source,
|
|
@@ -624,6 +605,7 @@ function between(rule, left, right, frames, at, reading) {
|
|
|
624
605
|
? {
|
|
625
606
|
parts: sides.map((side, index) => ({
|
|
626
607
|
path: side.path,
|
|
608
|
+
identity: JSON.stringify([side.segments, side.measure]),
|
|
627
609
|
coefficient: index === 0 ? 1 : -1,
|
|
628
610
|
valueOf: scope => read(side, scope),
|
|
629
611
|
write: (given, value) => at(side.segments)?.write(given, side.measure, value),
|
|
@@ -637,7 +619,14 @@ function between(rule, left, right, frames, at, reading) {
|
|
|
637
619
|
comparison: rule,
|
|
638
620
|
border,
|
|
639
621
|
...(form === undefined ? {} : { form }),
|
|
622
|
+
cases: [...options[0].cases, ...options[1].cases.filter(other => !options[0].cases.some(one => one.at.join("\u0000") === other.at.join("\u0000")))],
|
|
640
623
|
coordinateOf: reached => {
|
|
624
|
+
if (!first.onTrail(reached.scope) || !second.onTrail(reached.scope))
|
|
625
|
+
return undefined;
|
|
626
|
+
if (exact) {
|
|
627
|
+
const [a, b] = [readOperand(first.term, reached.scope), readOperand(second.term, reached.scope)];
|
|
628
|
+
return a === undefined || b === undefined ? undefined : withinRoom(() => decimalOf(fractionOf(a).minus(fractionOf(b))));
|
|
629
|
+
}
|
|
641
630
|
const a = read(first, reached.scope);
|
|
642
631
|
const b = read(second, reached.scope);
|
|
643
632
|
return a === undefined || b === undefined ? undefined : a - b;
|
|
@@ -646,8 +635,10 @@ function between(rule, left, right, frames, at, reading) {
|
|
|
646
635
|
const otherSide = side === 1;
|
|
647
636
|
// Move the side that can take every value of the difference: the finer of
|
|
648
637
|
// a decimal and an integer, and never a stand-in, which a row writes as given.
|
|
649
|
-
|
|
650
|
-
const
|
|
638
|
+
// A decimal of any scale is the finest of all: it takes every difference.
|
|
639
|
+
const fineness = (side) => (side.kind === "decimal" && side.scale === undefined ? Infinity : side.scale ?? 0);
|
|
640
|
+
const preferred = first.standsIn || (!second.standsIn && fineness(second) > fineness(first));
|
|
641
|
+
const swappable = !first.standsIn && !second.standsIn && fineness(first) === fineness(second);
|
|
651
642
|
const moveSecond = otherSide === true && swappable ? !preferred : preferred;
|
|
652
643
|
const [moving, fixed, sign] = moveSecond ? [second, first, -1] : [first, second, 1];
|
|
653
644
|
const moved = moving.standsIn ? undefined : at(moving.segments);
|
|
@@ -657,6 +648,18 @@ function between(rule, left, right, frames, at, reading) {
|
|
|
657
648
|
if (moved === undefined || other === undefined) {
|
|
658
649
|
return undefined;
|
|
659
650
|
}
|
|
651
|
+
if (exact) {
|
|
652
|
+
return withinRoom(() => {
|
|
653
|
+
const shifted = fractionOf(other).plus(fractionOf(coordinate).times(fractionOf(sign)));
|
|
654
|
+
const written = moved.write(given, moving.measure, decimalOf(shifted));
|
|
655
|
+
if (written === undefined || fixed.standsIn || !deepEqual(fixed.segments, moving.segments))
|
|
656
|
+
return written;
|
|
657
|
+
// Both sides read the one place moved, so the row is kept only where it
|
|
658
|
+
// stands at the point.
|
|
659
|
+
const [a, b] = [first, second].map(side => at(side.segments)?.valuesIn(written)[0]);
|
|
660
|
+
return isDecimal(a) && isDecimal(b) && fractionOf(a).minus(fractionOf(b)).comparedTo(fractionOf(coordinate)) === 0 ? written : undefined;
|
|
661
|
+
});
|
|
662
|
+
}
|
|
660
663
|
if (moment?.write !== undefined) {
|
|
661
664
|
const units = moment.read(other, fixed) + BigInt(sign) * coordinate;
|
|
662
665
|
const written = moment.write(units, moving, other);
|
|
@@ -677,29 +680,45 @@ function between(rule, left, right, frames, at, reading) {
|
|
|
677
680
|
? undefined
|
|
678
681
|
: held.write(given, fixed.measure, counter);
|
|
679
682
|
}
|
|
680
|
-
const base = fixed.measure
|
|
681
|
-
|
|
683
|
+
const base = counts(fixed.measure) && !fixed.standsIn ? measured(other, fixed.measure) : other;
|
|
684
|
+
const written = moved.write(given, moving.measure, base + sign * coordinate);
|
|
685
|
+
// Moving one side of `length(trim($.code)) < length($.code)` moves the
|
|
686
|
+
// other too, so the row is kept only where it stands at the point.
|
|
687
|
+
if (fixed.standsIn || !deepEqual(fixed.segments, moving.segments)) {
|
|
688
|
+
return written;
|
|
689
|
+
}
|
|
690
|
+
const [a, b] = [first, second].map(side => measured(at(side.segments)?.valuesIn(written)[0], side.measure));
|
|
691
|
+
return typeof a === "number" && typeof b === "number" && a - b === coordinate ? written : undefined;
|
|
682
692
|
},
|
|
683
693
|
}));
|
|
684
694
|
}
|
|
685
695
|
// Reads two decimals as whole numbers of units of the finer scale of the two, so
|
|
686
696
|
// their difference is exact, and writes one back where the other side's value
|
|
687
|
-
// plus the difference lands on its own scale.
|
|
697
|
+
// plus the difference lands on its own scale. Only two decimals of a scale
|
|
698
|
+
// have such units: differenceCarrier draws no border between others.
|
|
688
699
|
function decimalMoment(first, second) {
|
|
689
|
-
const scale = Math.max(first.scale, second.scale);
|
|
700
|
+
const scale = Math.max(first.scale ?? 0, second.scale ?? 0);
|
|
690
701
|
return {
|
|
691
702
|
read: value => decimalUnits(value, scale, "floor"),
|
|
692
703
|
shift: () => undefined,
|
|
693
704
|
write: (units, side, like) => {
|
|
694
|
-
const
|
|
695
|
-
|
|
705
|
+
const own = side.scale ?? 0;
|
|
706
|
+
const coarser = 10n ** BigInt(scale - own);
|
|
707
|
+
return units % coarser === 0n ? decimalOfUnits(like, units / coarser, own) : undefined;
|
|
696
708
|
},
|
|
697
709
|
};
|
|
698
710
|
}
|
|
699
711
|
const MOMENTS = {
|
|
712
|
+
jsDate: {
|
|
713
|
+
read: value => value.getTime(),
|
|
714
|
+
shift: (value, amount) => {
|
|
715
|
+
const moved = value.getTime() + amount;
|
|
716
|
+
return Math.abs(moved) <= MAX_DATE_TIME ? new Date(moved) : undefined;
|
|
717
|
+
},
|
|
718
|
+
},
|
|
700
719
|
instant: {
|
|
701
720
|
read: value => value.epochNanoseconds,
|
|
702
|
-
shift: (value, amount) => value
|
|
721
|
+
shift: (value, amount) => temporalNeighbor(value, { nanoseconds: amount }),
|
|
703
722
|
},
|
|
704
723
|
date: {
|
|
705
724
|
// Counted in the ISO calendar, since until refuses two dates in different
|
|
@@ -708,13 +727,12 @@ const MOMENTS = {
|
|
|
708
727
|
.from("1970-01-01")
|
|
709
728
|
.until(value.withCalendar("iso8601"), { largestUnit: "days" })
|
|
710
729
|
.total("days"),
|
|
711
|
-
shift: (value, amount) => value
|
|
730
|
+
shift: (value, amount) => temporalNeighbor(value, { days: amount }),
|
|
712
731
|
},
|
|
713
732
|
datetime: {
|
|
714
|
-
//
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
shift: (value, amount) => value.add({ nanoseconds: amount }),
|
|
733
|
+
// A date-time can lie beyond the instant range, so it is not read through a UTC instant.
|
|
734
|
+
read: value => timelineOf(value).numerator,
|
|
735
|
+
shift: (value, amount) => temporalNeighbor(value, { nanoseconds: amount }),
|
|
718
736
|
},
|
|
719
737
|
time: {
|
|
720
738
|
read: value => BigInt(value.constructor.from("00:00").until(value, { largestUnit: "hours" }).total("nanoseconds")),
|
|
@@ -733,7 +751,9 @@ function differenceCarrier({ kind: first, scale: firstScale }, { kind: second, s
|
|
|
733
751
|
// Two decimals count their difference in units of the finer scale; a decimal
|
|
734
752
|
// is not ordered against any other kind.
|
|
735
753
|
if (first === "decimal" && second === "decimal") {
|
|
736
|
-
|
|
754
|
+
// A decimal of any scale has no unit to count the difference in: it is
|
|
755
|
+
// the exact decimal difference, with no value next to another.
|
|
756
|
+
return firstScale === undefined || secondScale === undefined ? decimalCarrier(undefined) : decimalUnitsCarrier(Math.max(firstScale, secondScale));
|
|
737
757
|
}
|
|
738
758
|
if (first === "decimal" || second === "decimal") {
|
|
739
759
|
return undefined;
|
|
@@ -744,13 +764,29 @@ function differenceCarrier({ kind: first, scale: firstScale }, { kind: second, s
|
|
|
744
764
|
if (first !== second) {
|
|
745
765
|
return undefined;
|
|
746
766
|
}
|
|
747
|
-
return first === "date" ? integerCarrier : first === "instant" || first === "datetime" || first === "time" ? nanosecondCarrier : undefined;
|
|
767
|
+
return first === "date" || first === "jsDate" ? integerCarrier : first === "instant" || first === "datetime" || first === "time" ? nanosecondCarrier : undefined;
|
|
748
768
|
}
|
|
749
769
|
export function comparisonsNotReadOf(implementation) {
|
|
750
|
-
const
|
|
751
|
-
return Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules"
|
|
770
|
+
const unread = Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules"
|
|
752
771
|
? []
|
|
753
|
-
: decision.guards.flatMap(candidate => unreadIn(candidate.condition,
|
|
772
|
+
: decision.guards.flatMap(candidate => unreadIn(candidate.condition, framesFor(implementation.behavior, tag, decision)).map(text => `${decision.id}: ${text}`)));
|
|
773
|
+
// A place more relations are written against than their combinations are
|
|
774
|
+
// drawn for is divided into no partition.
|
|
775
|
+
const relations = Object.entries(implementation.cases).flatMap(([tag, decision]) => decision.kind !== "rules" ? [] : decision.guards.flatMap(candidate => relationThresholdsIn(candidate.condition, framesFor(implementation.behavior, tag, decision))));
|
|
776
|
+
// Relations counted as relationClasses counts them: one per relation and
|
|
777
|
+
// operand, operands compared by value rather than by how they render.
|
|
778
|
+
const places = new Map();
|
|
779
|
+
for (const threshold of relations) {
|
|
780
|
+
const key = JSON.stringify(threshold.segments);
|
|
781
|
+
const place = places.get(key) ?? { path: threshold.path, rules: [] };
|
|
782
|
+
if (!place.rules.some(other => other.relation === threshold.rule.relation && sameElement(other.other, threshold.rule.other)))
|
|
783
|
+
place.rules.push(threshold.rule);
|
|
784
|
+
places.set(key, place);
|
|
785
|
+
}
|
|
786
|
+
const crowded = [...places.values()]
|
|
787
|
+
.filter(place => place.rules.length > RELATION_LIMIT)
|
|
788
|
+
.map(place => `${place.path}: 関係が${place.rules.length}個あり、上限の${RELATION_LIMIT}個を超えるため組み合わせを引かない`);
|
|
789
|
+
return [...unread, ...crowded];
|
|
754
790
|
}
|
|
755
791
|
function unreadIn(rule, frames) {
|
|
756
792
|
switch (rule.kind) {
|
|
@@ -766,12 +802,18 @@ function unreadIn(rule, frames) {
|
|
|
766
802
|
? [describeRule(rule, frames.root.label, labelsOf(frames))]
|
|
767
803
|
: unreadIn(rule.each, inner);
|
|
768
804
|
}
|
|
805
|
+
// Read by the classes it divides the place into and the arms on each side, where it is a plain value of a place against a written value; one read through a transform, or against another place, divides nothing and is said unread.
|
|
806
|
+
case "relation":
|
|
807
|
+
return relationThresholdsIn(rule, frames).length > 0 ? [] : [describeRule(rule, frames.root.label, labelsOf(frames))];
|
|
769
808
|
case "compare": {
|
|
770
809
|
const terms = [rule.left, rule.right].filter(isTerm);
|
|
810
|
+
// Two constants settle without reading anything.
|
|
811
|
+
if (terms.length === 0)
|
|
812
|
+
return [];
|
|
771
813
|
if (terms.some(term => positionData(term) === undefined)) {
|
|
772
814
|
const kinds = differenceOf(rule).parts.map(part => {
|
|
773
815
|
const { frame, keys } = locate(positionTerm(part.path, part.measure), frames);
|
|
774
|
-
return part.measure
|
|
816
|
+
return counts(part.measure) ? "integer" : schemaAt(frame.scope, keys)?.kind;
|
|
775
817
|
});
|
|
776
818
|
return kinds.every(kind => kind === "integer" || kind === "number")
|
|
777
819
|
? []
|
|
@@ -781,7 +823,7 @@ function unreadIn(rule, frames) {
|
|
|
781
823
|
const { frame, keys } = locate(term, frames);
|
|
782
824
|
const schema = schemaAt(frame.scope, keys);
|
|
783
825
|
// The length of an enum is not read: see carrierOf.
|
|
784
|
-
return positionOf(term).measure
|
|
826
|
+
return counts(positionOf(term).measure) ? (schema?.kind === "enum" ? undefined : int()) : schema;
|
|
785
827
|
});
|
|
786
828
|
const sides = schemas.map((schema) => ({
|
|
787
829
|
kind: schema?.kind,
|
|
@@ -803,7 +845,4 @@ function unreadIn(rule, frames) {
|
|
|
803
845
|
}
|
|
804
846
|
}
|
|
805
847
|
}
|
|
806
|
-
function schemaAt(schema, keys) {
|
|
807
|
-
return schemaAtPath(schema, keys);
|
|
808
|
-
}
|
|
809
848
|
//# sourceMappingURL=guard-borders.js.map
|