@fraczak/k 8.6.0 → 8.6.1
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/CHANGELOG.md +22 -0
- package/DOCS/REPL.md +2 -1
- package/canonical-pattern.mjs +134 -25
- package/object.mjs +1 -1
- package/package.json +1 -1
- package/repl.mjs +199 -16
- package/scripts/build-repl-html.mjs +8 -1
- package/tests/test-repl.mjs +106 -21
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,28 @@ All notable changes to this project will be documented here.
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [8.6.1] — 2026-11-04 — REPL `:all-patterns` and Shared-Graph Boundary Pattern Printing
|
|
9
|
+
|
|
10
|
+
- **REPL `:all-patterns` (alias `:all-pat`)**:
|
|
11
|
+
- Add `:all-patterns` / `:all-pat` to list all canonical patterns keyed by
|
|
12
|
+
hash — including patterns derived from relation definitions without named
|
|
13
|
+
aliases — along with any aliases and their routing bindings
|
|
14
|
+
(`-- p[X] = @[X,(...)], q[ZZZ] = @[ZZZ,ZZZ]`).
|
|
15
|
+
- **Canonical `:pat` Display**:
|
|
16
|
+
- Update `:pat <name>` to always display the canonicalized pattern body with
|
|
17
|
+
the alias's routing arguments (`aliasArgs`) substituted via
|
|
18
|
+
`instantiateCanonicalFilter`.
|
|
19
|
+
- **Shared-Graph `:rel` Boundary Pattern Rendering & Default `max-pat-length`**:
|
|
20
|
+
- When neither boundary pattern exceeds `max-pat-length`, `:rel <name>` prints
|
|
21
|
+
the input and output boundary patterns from a single shared pattern graph
|
|
22
|
+
(`patterns2filters`) so shared nodes reuse knot variables across input and
|
|
23
|
+
output (e.g., `ww = ?<{}=X1 x, X1 y, X0 z>=X0 () ?X0;`).
|
|
24
|
+
- When either boundary pattern exceeds `max-pat-length`, render both boundary
|
|
25
|
+
patterns (unless a bare wildcard `?(...)` or bare open variable `?X0`) as
|
|
26
|
+
standalone canonical `@hash[...]` pattern applications.
|
|
27
|
+
- Increase default `max-pat-length` from `30` to `45` (the length of a
|
|
28
|
+
`@hash` name).
|
|
29
|
+
|
|
8
30
|
## [8.6.0] — 2026-11-03 — Native JSON Parser, IEEE Library Split, and REPL Pattern Inspection
|
|
9
31
|
|
|
10
32
|
- **Native JSON Parsing & IEEE Library Split**:
|
package/DOCS/REPL.md
CHANGED
|
@@ -28,6 +28,7 @@ shows compilation and execution costs for the selected engine.
|
|
|
28
28
|
| `:rel name` / `:rels` | Inspect a relation / list relation aliases |
|
|
29
29
|
| `:pat name` / `:pats` | Inspect a pattern / list pattern aliases |
|
|
30
30
|
| `:pattern` / `:patterns` | Long forms of the preceding pattern commands |
|
|
31
|
+
| `:all-patterns` / `:all-pat` | List all canonical patterns keyed by hash with their aliases |
|
|
31
32
|
| `:load [--no-alias] file` | Load source or a compiled library |
|
|
32
33
|
| `:codec load file` | Register a codec module |
|
|
33
34
|
| `:codec unload name` | Remove a codec |
|
|
@@ -36,7 +37,7 @@ shows compilation and execution costs for the selected engine.
|
|
|
36
37
|
| `:engine [wasm\|pkir\|js]` | Show or select the evaluation engine |
|
|
37
38
|
| `:wasm` / `:pkir` / `:js` | Engine shortcuts |
|
|
38
39
|
| `:limit [number\|none]` | Show or change the output limit (default: 4096 characters) |
|
|
39
|
-
| `:max-pat-length [number\|none]` | Show or change max inline pattern length in `:rel` (default:
|
|
40
|
+
| `:max-pat-length [number\|none]` | Show or change max inline pattern length in `:rel` (default: 45, alias `:maxPatLength`) |
|
|
40
41
|
| `:klib file` | Export the current library |
|
|
41
42
|
| `:ko file expression` | Export an executable object |
|
|
42
43
|
| `:reset` | Clear session state |
|
package/canonical-pattern.mjs
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import { annotate } from "./index.mjs";
|
|
5
5
|
import { TypePatternGraph } from "./TypePatternGraph.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
patternGraphToCanonical,
|
|
8
|
+
patterns2filters,
|
|
9
|
+
prettyFilter
|
|
10
|
+
} from "./pretty.mjs";
|
|
7
11
|
import { patternToPropertyList } from "./codecs/runtime/pattern-json.mjs";
|
|
8
12
|
import { exportPatternGraph } from "./codecs/runtime/codec.mjs";
|
|
9
13
|
import { closedPatternToCodeHash } from "./repl-codecs.mjs";
|
|
@@ -163,6 +167,88 @@ function toAstFilter(node, canonicalParams = []) {
|
|
|
163
167
|
return res;
|
|
164
168
|
}
|
|
165
169
|
|
|
170
|
+
export function instantiateCanonicalFilter(
|
|
171
|
+
canonicalFilterAst,
|
|
172
|
+
canonicalParams = [],
|
|
173
|
+
aliasArgs = []
|
|
174
|
+
) {
|
|
175
|
+
if (!canonicalFilterAst) return canonicalFilterAst;
|
|
176
|
+
const paramMap = new Map();
|
|
177
|
+
for (let i = 0; i < canonicalParams.length; i++) {
|
|
178
|
+
paramMap.set(
|
|
179
|
+
canonicalParams[i],
|
|
180
|
+
aliasArgs[i] ?? canonicalParams[i]
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
const usedArgNames = new Set(
|
|
184
|
+
aliasArgs.filter((a) => a && a !== "(...)")
|
|
185
|
+
);
|
|
186
|
+
const knotNames = new Set();
|
|
187
|
+
function collectKnots(node) {
|
|
188
|
+
if (!node || typeof node !== "object") return;
|
|
189
|
+
if (
|
|
190
|
+
node.name &&
|
|
191
|
+
node.type !== "name" &&
|
|
192
|
+
!paramMap.has(node.name)
|
|
193
|
+
) {
|
|
194
|
+
knotNames.add(node.name);
|
|
195
|
+
}
|
|
196
|
+
if (node.fields) {
|
|
197
|
+
for (const child of Object.values(node.fields)) {
|
|
198
|
+
collectKnots(child);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
collectKnots(canonicalFilterAst);
|
|
203
|
+
|
|
204
|
+
const knotRename = new Map();
|
|
205
|
+
let nextIdx = 0;
|
|
206
|
+
for (const k of knotNames) {
|
|
207
|
+
if (usedArgNames.has(k)) {
|
|
208
|
+
while (
|
|
209
|
+
usedArgNames.has(`X${nextIdx}`) ||
|
|
210
|
+
knotNames.has(`X${nextIdx}`)
|
|
211
|
+
) {
|
|
212
|
+
nextIdx++;
|
|
213
|
+
}
|
|
214
|
+
knotRename.set(k, `X${nextIdx++}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function walk(node) {
|
|
219
|
+
if (!node || typeof node !== "object") return node;
|
|
220
|
+
if (
|
|
221
|
+
(node.type === "name" || node.type === null) &&
|
|
222
|
+
paramMap.has(node.name)
|
|
223
|
+
) {
|
|
224
|
+
const arg = paramMap.get(node.name);
|
|
225
|
+
if (arg === "(...)") {
|
|
226
|
+
return { type: null, open: true, fields: {} };
|
|
227
|
+
}
|
|
228
|
+
return { type: "name", name: arg, open: true };
|
|
229
|
+
}
|
|
230
|
+
if (
|
|
231
|
+
(node.type === "name" || node.type === null) &&
|
|
232
|
+
knotRename.has(node.name)
|
|
233
|
+
) {
|
|
234
|
+
return { ...node, name: knotRename.get(node.name) };
|
|
235
|
+
}
|
|
236
|
+
const res = { ...node };
|
|
237
|
+
if (res.name && knotRename.has(res.name)) {
|
|
238
|
+
res.name = knotRename.get(res.name);
|
|
239
|
+
}
|
|
240
|
+
if (res.fields) {
|
|
241
|
+
res.fields = {};
|
|
242
|
+
for (const [k, v] of Object.entries(node.fields)) {
|
|
243
|
+
res.fields[k] = walk(v);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return res;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return walk(canonicalFilterAst);
|
|
250
|
+
}
|
|
251
|
+
|
|
166
252
|
export function resolvePatternCanonicalInfo(name, pat, options = {}) {
|
|
167
253
|
if (!pat) return { hash: null, def: null, params: null };
|
|
168
254
|
if (
|
|
@@ -435,7 +521,7 @@ export function buildExportPreamble(exports = [], libraries = []) {
|
|
|
435
521
|
return lines.join("\n") + "\n";
|
|
436
522
|
}
|
|
437
523
|
|
|
438
|
-
const DEFAULT_MAX_PAT_LENGTH =
|
|
524
|
+
const DEFAULT_MAX_PAT_LENGTH = 45;
|
|
439
525
|
|
|
440
526
|
export function canonicalBoundaryFilterSources(
|
|
441
527
|
typePatternGraph,
|
|
@@ -444,9 +530,9 @@ export function canonicalBoundaryFilterSources(
|
|
|
444
530
|
) {
|
|
445
531
|
const maxPatLength = options.maxPatLength ?? DEFAULT_MAX_PAT_LENGTH;
|
|
446
532
|
const leafOccurrences = [];
|
|
447
|
-
const knotEntries = [];
|
|
448
533
|
|
|
449
534
|
function buildSingleRootFilter(rawRootId) {
|
|
535
|
+
const filterKnots = [];
|
|
450
536
|
const subGraph = new TypePatternGraph(
|
|
451
537
|
typePatternGraph.registerCodeDef,
|
|
452
538
|
typePatternGraph.findCode
|
|
@@ -532,7 +618,7 @@ export function canonicalBoundaryFilterSources(
|
|
|
532
618
|
target: null,
|
|
533
619
|
refs: []
|
|
534
620
|
};
|
|
535
|
-
|
|
621
|
+
filterKnots.push(knotEntry);
|
|
536
622
|
const nextAncestors = new Map(ancestorKnots);
|
|
537
623
|
nextAncestors.set(patternId, knotEntry);
|
|
538
624
|
if (shareAcrossDag && inDegree[patternId] > 1) {
|
|
@@ -590,10 +676,11 @@ export function canonicalBoundaryFilterSources(
|
|
|
590
676
|
knot.target.name = knot.name;
|
|
591
677
|
}
|
|
592
678
|
}
|
|
593
|
-
return built;
|
|
679
|
+
return { filter: built, filterKnots };
|
|
594
680
|
}
|
|
595
681
|
|
|
596
|
-
const
|
|
682
|
+
const builtFilters = patternIds.map((id) => buildSingleRootFilter(id));
|
|
683
|
+
const filters = builtFilters.map((b) => b.filter);
|
|
597
684
|
|
|
598
685
|
const origCounts = new Map();
|
|
599
686
|
for (const { origId } of leafOccurrences) {
|
|
@@ -613,34 +700,48 @@ export function canonicalBoundaryFilterSources(
|
|
|
613
700
|
}
|
|
614
701
|
const sharedVars = [...sharedVarByOrig.values()];
|
|
615
702
|
|
|
616
|
-
for (const
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
knot.
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
703
|
+
for (const { filterKnots } of builtFilters) {
|
|
704
|
+
let knotVar = sharedVars.length;
|
|
705
|
+
for (const knot of filterKnots) {
|
|
706
|
+
if (knot.used && knot.target) {
|
|
707
|
+
const knotName = `X${knotVar++}`;
|
|
708
|
+
knot.name = knotName;
|
|
709
|
+
knot.target.name = knotName;
|
|
710
|
+
for (const refNode of knot.refs) {
|
|
711
|
+
refNode.name = knotName;
|
|
712
|
+
}
|
|
623
713
|
}
|
|
624
714
|
}
|
|
625
715
|
}
|
|
626
716
|
|
|
627
|
-
|
|
717
|
+
const useCanonicalNames = filters.some(
|
|
718
|
+
(filter) => prettyFilter(filter).length > maxPatLength
|
|
719
|
+
);
|
|
720
|
+
|
|
721
|
+
const resolvedByInline = new Map();
|
|
722
|
+
const canonicalSources = filters.map((filter) => {
|
|
628
723
|
const inlineStr = prettyFilter(filter);
|
|
629
|
-
|
|
724
|
+
const isBareWildcard =
|
|
630
725
|
(filter.type === null &&
|
|
631
726
|
filter.open &&
|
|
632
727
|
Object.keys(filter.fields || {}).length === 0 &&
|
|
633
728
|
!filter.name) ||
|
|
634
|
-
(filter.type === "name" && filter.open)
|
|
635
|
-
|
|
636
|
-
) {
|
|
729
|
+
(filter.type === "name" && filter.open);
|
|
730
|
+
if (isBareWildcard) {
|
|
637
731
|
return `?${inlineStr}`;
|
|
638
732
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
)
|
|
733
|
+
if (!useCanonicalNames && !options.registerPatterns) {
|
|
734
|
+
return `?${inlineStr}`;
|
|
735
|
+
}
|
|
736
|
+
let info = resolvedByInline.get(inlineStr);
|
|
737
|
+
if (!info) {
|
|
738
|
+
info = resolvePatternCanonicalInfo(
|
|
739
|
+
null,
|
|
740
|
+
{ params: sharedVars, filter },
|
|
741
|
+
options
|
|
742
|
+
);
|
|
743
|
+
resolvedByInline.set(inlineStr, info);
|
|
744
|
+
}
|
|
644
745
|
if (
|
|
645
746
|
info.hash &&
|
|
646
747
|
options.registerPatterns &&
|
|
@@ -653,18 +754,26 @@ export function canonicalBoundaryFilterSources(
|
|
|
653
754
|
_canonicalDef: info.def,
|
|
654
755
|
_canonicalParams: info.canonicalParams,
|
|
655
756
|
_graphParams: info.canonicalParams,
|
|
656
|
-
_aliasArgs: info.
|
|
757
|
+
_aliasArgs: info.canonicalParams || [],
|
|
657
758
|
_canonicalFilterAst: info.canonicalFilterAst
|
|
658
759
|
};
|
|
659
760
|
}
|
|
660
761
|
const args = (info.aliasArgs || []).join(", ");
|
|
661
762
|
return `?${info.hash}[${args}]`;
|
|
662
763
|
});
|
|
764
|
+
|
|
765
|
+
if (!useCanonicalNames) {
|
|
766
|
+
return patterns2filters(typePatternGraph, ...patternIds).map(
|
|
767
|
+
(f) => `?${prettyFilter(f)}`
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
return canonicalSources;
|
|
663
771
|
}
|
|
664
772
|
|
|
665
773
|
export default {
|
|
666
774
|
resolvePatternCanonicalInfo,
|
|
667
775
|
canonicalPatternHash,
|
|
668
776
|
buildExportPreamble,
|
|
669
|
-
canonicalBoundaryFilterSources
|
|
777
|
+
canonicalBoundaryFilterSources,
|
|
778
|
+
instantiateCanonicalFilter
|
|
670
779
|
};
|
package/object.mjs
CHANGED
|
@@ -593,7 +593,7 @@ function compileLibrary(script, options = {}) {
|
|
|
593
593
|
_canonicalDef: info.def,
|
|
594
594
|
_canonicalParams: info.canonicalParams,
|
|
595
595
|
_graphParams: info.canonicalParams,
|
|
596
|
-
_aliasArgs: info.
|
|
596
|
+
_aliasArgs: info.canonicalParams || [],
|
|
597
597
|
_canonicalFilterAst: info.canonicalFilterAst
|
|
598
598
|
};
|
|
599
599
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraczak/k",
|
|
3
|
-
"version": "8.6.
|
|
3
|
+
"version": "8.6.1",
|
|
4
4
|
"description": "k — a language for content-addressable schemas and data transformations over algebraic data types (products and tagged unions); includes runtime, contract derivation, REPL, and codec toolchain",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
package/repl.mjs
CHANGED
|
@@ -28,6 +28,8 @@ import {
|
|
|
28
28
|
prettyFilter
|
|
29
29
|
} from "./pretty.mjs";
|
|
30
30
|
import {
|
|
31
|
+
canonicalBoundaryFilterSources,
|
|
32
|
+
instantiateCanonicalFilter,
|
|
31
33
|
resolvePatternCanonicalInfo as canonicalPatternInfo
|
|
32
34
|
} from "./canonical-pattern.mjs";
|
|
33
35
|
import {
|
|
@@ -61,6 +63,7 @@ import {
|
|
|
61
63
|
const NAME_RE = /^[a-zA-Z0-9_+-][a-zA-Z0-9_?!+-]*$/;
|
|
62
64
|
const COMMAND_NAMES = [
|
|
63
65
|
"help", "rel", "pattern", "pat", "patterns", "pats",
|
|
66
|
+
"all-patterns", "all-pat",
|
|
64
67
|
"codecs", "rels", "codec", "input", "reset", "klib", "ko", "load",
|
|
65
68
|
"engine", "wasm", "pkir", "js", "limit",
|
|
66
69
|
"max-pat-length", "maxPatLength",
|
|
@@ -112,7 +115,7 @@ function createState(options = {}) {
|
|
|
112
115
|
lastTiming: null,
|
|
113
116
|
showTiming: true,
|
|
114
117
|
printLimit: options.printLimit ?? Infinity,
|
|
115
|
-
maxPatLength: options.maxPatLength ??
|
|
118
|
+
maxPatLength: options.maxPatLength ?? 45
|
|
116
119
|
};
|
|
117
120
|
}
|
|
118
121
|
|
|
@@ -285,6 +288,20 @@ function recoverAliasesFromMeta(state, lib) {
|
|
|
285
288
|
state.typeAliases[origin.name] = hash;
|
|
286
289
|
} else if (type === "pattern") {
|
|
287
290
|
state.patternAliases[origin.name] = hash;
|
|
291
|
+
if (!state.patterns[origin.name] && state.patterns[hash]) {
|
|
292
|
+
const canonPat = state.patterns[hash];
|
|
293
|
+
state.patterns[origin.name] = {
|
|
294
|
+
params: origin.params || [],
|
|
295
|
+
filter: canonPat.filter,
|
|
296
|
+
_canonical: hash,
|
|
297
|
+
_canonicalDef: canonPat._canonicalDef,
|
|
298
|
+
_canonicalParams: origin.params || [],
|
|
299
|
+
_graphParams: entry.params || canonPat._graphParams || [],
|
|
300
|
+
_aliasArgs: origin.aliasArgs || origin.params || [],
|
|
301
|
+
_canonicalFilterAst:
|
|
302
|
+
canonPat._canonicalFilterAst || canonPat.filter
|
|
303
|
+
};
|
|
304
|
+
}
|
|
288
305
|
} else if (type === "rel" || hash in state.rels) {
|
|
289
306
|
state.relAliases[origin.name] = hash;
|
|
290
307
|
}
|
|
@@ -504,10 +521,6 @@ function resolvePatternCanonicalName(state, name, pat) {
|
|
|
504
521
|
function prettyPattern(name, pat, state = null) {
|
|
505
522
|
const info = resolvePatternCanonicalInfo(state, name, pat);
|
|
506
523
|
const isHash = typeof name === "string" && name.startsWith("@");
|
|
507
|
-
const isDirectAlias =
|
|
508
|
-
pat?.filter?.type === "pattern_apply" &&
|
|
509
|
-
typeof pat.filter.pattern === "string" &&
|
|
510
|
-
pat.filter.pattern.startsWith("@");
|
|
511
524
|
|
|
512
525
|
const paramList =
|
|
513
526
|
isHash && (info.canonicalParams || pat?.params)
|
|
@@ -515,18 +528,28 @@ function prettyPattern(name, pat, state = null) {
|
|
|
515
528
|
: (pat?.params || info.params || []);
|
|
516
529
|
const params = paramList.join(", ");
|
|
517
530
|
|
|
531
|
+
const aliasArgs = info.aliasArgs || pat?.params || [];
|
|
532
|
+
const canonicalAst =
|
|
533
|
+
info.canonicalFilterAst ||
|
|
534
|
+
(info.hash ? state?.patterns?.[info.hash]?._canonicalFilterAst : null);
|
|
535
|
+
const canonicalParams =
|
|
536
|
+
info.canonicalParams ||
|
|
537
|
+
(info.hash ? state?.patterns?.[info.hash]?._graphParams : null) ||
|
|
538
|
+
[];
|
|
539
|
+
|
|
518
540
|
let filterStr;
|
|
519
541
|
if (isHash) {
|
|
520
542
|
filterStr =
|
|
521
543
|
info.def || (pat?.filter ? prettyFilter(pat.filter) : "()");
|
|
522
|
-
} else if (
|
|
523
|
-
filterStr = prettyFilter(
|
|
544
|
+
} else if (canonicalAst) {
|
|
545
|
+
filterStr = prettyFilter(
|
|
546
|
+
instantiateCanonicalFilter(canonicalAst, canonicalParams, aliasArgs)
|
|
547
|
+
);
|
|
524
548
|
} else {
|
|
525
549
|
filterStr =
|
|
526
550
|
info.def || (pat?.filter ? prettyFilter(pat.filter) : "()");
|
|
527
551
|
}
|
|
528
552
|
|
|
529
|
-
const aliasArgs = info.aliasArgs || pat?.params || [];
|
|
530
553
|
const argStr = aliasArgs.join(", ");
|
|
531
554
|
const suffix =
|
|
532
555
|
info.hash && !isHash ? ` -- ${info.hash}[${argStr}]` : "";
|
|
@@ -568,6 +591,142 @@ function listPatternAliases(state) {
|
|
|
568
591
|
return aliases.join("\n");
|
|
569
592
|
}
|
|
570
593
|
|
|
594
|
+
function collectRelFilterPairs(exp, pairs = []) {
|
|
595
|
+
if (!exp) return pairs;
|
|
596
|
+
switch (exp.op) {
|
|
597
|
+
case "filter":
|
|
598
|
+
if (exp.patterns?.length >= 2) {
|
|
599
|
+
pairs.push([exp.patterns[0], exp.patterns[1]]);
|
|
600
|
+
}
|
|
601
|
+
break;
|
|
602
|
+
case "comp":
|
|
603
|
+
exp.comp.forEach((child) => collectRelFilterPairs(child, pairs));
|
|
604
|
+
break;
|
|
605
|
+
case "union":
|
|
606
|
+
exp.union.forEach((child) => collectRelFilterPairs(child, pairs));
|
|
607
|
+
break;
|
|
608
|
+
case "product":
|
|
609
|
+
exp.product.forEach(({ exp: child }) =>
|
|
610
|
+
collectRelFilterPairs(child, pairs)
|
|
611
|
+
);
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
return pairs;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function registerRelationPatterns(state) {
|
|
618
|
+
if (!state?.rels) return;
|
|
619
|
+
if (!state.patterns) state.patterns = {};
|
|
620
|
+
const rels = reachableRelations(
|
|
621
|
+
state.rels,
|
|
622
|
+
Object.values(state.relAliases || {})
|
|
623
|
+
);
|
|
624
|
+
let registeredAny = false;
|
|
625
|
+
for (const rel of Object.values(rels)) {
|
|
626
|
+
if (rel._patternsRegistered) continue;
|
|
627
|
+
if (rel.typePatternGraph && rel.def?.patterns?.length >= 2) {
|
|
628
|
+
const pairs = [
|
|
629
|
+
[rel.def.patterns[0], rel.def.patterns[1]],
|
|
630
|
+
...collectRelFilterPairs(rel.def)
|
|
631
|
+
];
|
|
632
|
+
for (const pair of pairs) {
|
|
633
|
+
canonicalBoundaryFilterSources(rel.typePatternGraph, pair, {
|
|
634
|
+
libraries: [stateLibrary(state)],
|
|
635
|
+
patterns: state.patterns,
|
|
636
|
+
registerPatterns: state.patterns,
|
|
637
|
+
maxPatLength: state.maxPatLength
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
registeredAny = true;
|
|
641
|
+
}
|
|
642
|
+
Object.defineProperty(rel, "_patternsRegistered", {
|
|
643
|
+
value: true,
|
|
644
|
+
configurable: true
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
if (registeredAny) {
|
|
648
|
+
state.codes = codes.dump();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function listAllPatterns(state) {
|
|
653
|
+
registerRelationPatterns(state);
|
|
654
|
+
const byHash = new Map();
|
|
655
|
+
const names = [
|
|
656
|
+
...new Set([
|
|
657
|
+
...Object.keys(state?.patternAliases || {}),
|
|
658
|
+
...Object.keys(state?.patterns || {})
|
|
659
|
+
])
|
|
660
|
+
].filter((name) => !name.startsWith("@")).sort();
|
|
661
|
+
|
|
662
|
+
for (const name of names) {
|
|
663
|
+
const pat =
|
|
664
|
+
state?.patterns?.[name] ||
|
|
665
|
+
(state?.patternAliases?.[name]
|
|
666
|
+
? state?.patterns?.[state.patternAliases[name]]
|
|
667
|
+
: null);
|
|
668
|
+
const info = resolvePatternCanonicalInfo(state, name, pat);
|
|
669
|
+
const hash =
|
|
670
|
+
info?.hash || state?.patternAliases?.[name] || null;
|
|
671
|
+
if (!hash) continue;
|
|
672
|
+
const canonicalPat = state?.patterns?.[hash];
|
|
673
|
+
if (!byHash.has(hash)) {
|
|
674
|
+
const canonicalParams =
|
|
675
|
+
info?.canonicalParams ||
|
|
676
|
+
canonicalPat?._graphParams ||
|
|
677
|
+
canonicalPat?.params ||
|
|
678
|
+
state?.meta?.[hash]?.params ||
|
|
679
|
+
[];
|
|
680
|
+
const def =
|
|
681
|
+
info?.def ||
|
|
682
|
+
canonicalPat?._canonicalDef ||
|
|
683
|
+
(canonicalPat?.filter ? prettyFilter(canonicalPat.filter) : "()");
|
|
684
|
+
byHash.set(hash, { canonicalParams, def, aliases: [] });
|
|
685
|
+
}
|
|
686
|
+
const formalParams = pat?.params || [];
|
|
687
|
+
const paramStr =
|
|
688
|
+
formalParams.length > 0
|
|
689
|
+
? `[${formalParams.join(",")}]`
|
|
690
|
+
: "[]";
|
|
691
|
+
const args = info?.aliasArgs || formalParams;
|
|
692
|
+
const argStr =
|
|
693
|
+
args.length > 0
|
|
694
|
+
? `[${args.join(",")}]`
|
|
695
|
+
: "[]";
|
|
696
|
+
byHash.get(hash).aliases.push(`${name}${paramStr} = @${argStr}`);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
for (const [key, pat] of Object.entries(state?.patterns || {})) {
|
|
700
|
+
if (!key.startsWith("@") || byHash.has(key)) continue;
|
|
701
|
+
const info = resolvePatternCanonicalInfo(state, key, pat);
|
|
702
|
+
const canonicalParams =
|
|
703
|
+
info?.canonicalParams ||
|
|
704
|
+
pat?._graphParams ||
|
|
705
|
+
pat?.params ||
|
|
706
|
+
state?.meta?.[key]?.params ||
|
|
707
|
+
[];
|
|
708
|
+
const def =
|
|
709
|
+
info?.def ||
|
|
710
|
+
pat?._canonicalDef ||
|
|
711
|
+
(pat?.filter ? prettyFilter(pat.filter) : "()");
|
|
712
|
+
byHash.set(key, { canonicalParams, def, aliases: [] });
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
if (byHash.size === 0) return "(none)";
|
|
716
|
+
const lines = [];
|
|
717
|
+
for (const hash of [...byHash.keys()].sort()) {
|
|
718
|
+
const { canonicalParams, def, aliases } = byHash.get(hash);
|
|
719
|
+
const paramStr =
|
|
720
|
+
canonicalParams.length > 0
|
|
721
|
+
? `[${canonicalParams.join(",")}]`
|
|
722
|
+
: "[]";
|
|
723
|
+
const suffix =
|
|
724
|
+
aliases.length > 0 ? ` -- ${aliases.join(", ")}` : "";
|
|
725
|
+
lines.push(`${hash}${paramStr} = ${def};${suffix}`);
|
|
726
|
+
}
|
|
727
|
+
return lines.join("\n");
|
|
728
|
+
}
|
|
729
|
+
|
|
571
730
|
function listPatterns(stateOrPatterns) {
|
|
572
731
|
if (
|
|
573
732
|
stateOrPatterns &&
|
|
@@ -1230,13 +1389,22 @@ function loadSourceOrKlib(state, targetPath, options = {}) {
|
|
|
1230
1389
|
lib,
|
|
1231
1390
|
compileOptions
|
|
1232
1391
|
);
|
|
1392
|
+
const { patternNames } = userDefinedNames(source);
|
|
1393
|
+
const definedSet = new Set(patternNames);
|
|
1394
|
+
const patterns = { ...(state.patterns || {}) };
|
|
1395
|
+
for (const [k, v] of Object.entries(lib.patterns || {})) {
|
|
1396
|
+
if (k.startsWith("@") || definedSet.has(k) || !(k in patterns)) {
|
|
1397
|
+
patterns[k] = v;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1233
1400
|
mergeLibrary(
|
|
1234
1401
|
state,
|
|
1235
1402
|
{
|
|
1236
1403
|
...lib,
|
|
1237
1404
|
relAlias,
|
|
1238
1405
|
patternAlias,
|
|
1239
|
-
meta
|
|
1406
|
+
meta,
|
|
1407
|
+
patterns
|
|
1240
1408
|
},
|
|
1241
1409
|
targetPath,
|
|
1242
1410
|
{ loadAliases }
|
|
@@ -1312,10 +1480,13 @@ function compileSnippetArtifacts(source, state, sourceName = "<repl>") {
|
|
|
1312
1480
|
);
|
|
1313
1481
|
const annotated = annotateWithOptionalIdentity(fullSource, options);
|
|
1314
1482
|
const { patternNames } = userDefinedNames(source);
|
|
1315
|
-
const
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1483
|
+
const definedSet = new Set(patternNames);
|
|
1484
|
+
const patterns = { ...(state.patterns || {}) };
|
|
1485
|
+
for (const [k, v] of Object.entries(lib.patterns || {})) {
|
|
1486
|
+
if (k.startsWith("@") || definedSet.has(k) || !(k in patterns)) {
|
|
1487
|
+
patterns[k] = v;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1319
1490
|
return {
|
|
1320
1491
|
annotated,
|
|
1321
1492
|
lib: {
|
|
@@ -1641,6 +1812,10 @@ async function evaluateCommand(line, state) {
|
|
|
1641
1812
|
}
|
|
1642
1813
|
}
|
|
1643
1814
|
}
|
|
1815
|
+
if (!pat) {
|
|
1816
|
+
registerRelationPatterns(state);
|
|
1817
|
+
pat = state.patterns?.[patternName];
|
|
1818
|
+
}
|
|
1644
1819
|
} else {
|
|
1645
1820
|
pat = state.patterns?.[patternName];
|
|
1646
1821
|
if (!pat && state.patternAliases?.[patternName]) {
|
|
@@ -1654,7 +1829,13 @@ async function evaluateCommand(line, state) {
|
|
|
1654
1829
|
}
|
|
1655
1830
|
case "patterns":
|
|
1656
1831
|
case "pats":
|
|
1832
|
+
restoreCodes(state);
|
|
1657
1833
|
return [listPatternAliases(state)];
|
|
1834
|
+
case "all-patterns":
|
|
1835
|
+
case "all-pats":
|
|
1836
|
+
case "all-pat":
|
|
1837
|
+
restoreCodes(state);
|
|
1838
|
+
return [listAllPatterns(state)];
|
|
1658
1839
|
case "codec":
|
|
1659
1840
|
case "codecs":
|
|
1660
1841
|
return loadCodec(arg, state);
|
|
@@ -1774,8 +1955,9 @@ function helpText() {
|
|
|
1774
1955
|
":rels list relation aliases",
|
|
1775
1956
|
":pattern name show named pattern definition (alias :pat)",
|
|
1776
1957
|
":patterns list pattern aliases (alias :pats)",
|
|
1958
|
+
":all-patterns list canonical patterns and aliases (alias :all-pat)",
|
|
1777
1959
|
":limit [num|none] set maximum characters for value output",
|
|
1778
|
-
":max-pat-length [n|none] max inline pattern length in :rel (default
|
|
1960
|
+
":max-pat-length [n|none] max inline pattern length in :rel (default 45)",
|
|
1779
1961
|
":codec load file load a codec module from file",
|
|
1780
1962
|
":codec unload name unload a registered codec",
|
|
1781
1963
|
":codec list list loaded codecs (or simply :codecs)",
|
|
@@ -1814,7 +1996,7 @@ function cliUsage() {
|
|
|
1814
1996
|
console.log(" --js Shortcut for --engine=js.");
|
|
1815
1997
|
console.log(" --limit=<num> Set maximum characters for output.");
|
|
1816
1998
|
console.log(" --max-pat-length=<num> Set max inline pattern length in :rel");
|
|
1817
|
-
console.log(" (default:
|
|
1999
|
+
console.log(" (default: 45).");
|
|
1818
2000
|
console.log(" -h, --help Show this help.");
|
|
1819
2001
|
}
|
|
1820
2002
|
|
|
@@ -2031,5 +2213,6 @@ export {
|
|
|
2031
2213
|
patternFromFilter,
|
|
2032
2214
|
prettyPattern,
|
|
2033
2215
|
resolvePatternCanonicalName,
|
|
2034
|
-
listPatterns
|
|
2216
|
+
listPatterns,
|
|
2217
|
+
listAllPatterns
|
|
2035
2218
|
};
|
|
@@ -1936,10 +1936,17 @@ const htmlContent = `<!DOCTYPE html>
|
|
|
1936
1936
|
(alias <code>:pats</code>)
|
|
1937
1937
|
</td>
|
|
1938
1938
|
</tr>
|
|
1939
|
+
<tr>
|
|
1940
|
+
<td><code>:all-patterns</code></td>
|
|
1941
|
+
<td>
|
|
1942
|
+
List canonical patterns keyed by hash with their aliases
|
|
1943
|
+
(alias <code>:all-pat</code>)
|
|
1944
|
+
</td>
|
|
1945
|
+
</tr>
|
|
1939
1946
|
<tr><td><code>:rel <name></code></td><td>Display definition of relation <code><name></code></td></tr>
|
|
1940
1947
|
<tr><td><code>:rels</code></td><td>List all relation aliases</td></tr>
|
|
1941
1948
|
<tr><td><code>:limit [num|none]</code></td><td>Display or set maximum characters for value output</td></tr>
|
|
1942
|
-
<tr><td><code>:max-pat-length [num|none]</code></td><td>Display or set max inline pattern length in <code>:rel</code> (default <code>
|
|
1949
|
+
<tr><td><code>:max-pat-length [num|none]</code></td><td>Display or set max inline pattern length in <code>:rel</code> (default <code>45</code>, alias <code>:maxPatLength</code>)</td></tr>
|
|
1943
1950
|
<tr><td><code>:codecs</code></td><td>List all loaded format codecs</td></tr>
|
|
1944
1951
|
<tr><td><code>:codec load <file.mjs></code></td><td>Load a codec from file (or load through Files)</td></tr>
|
|
1945
1952
|
<tr><td><code>:codec unload <file.mjs></code></td><td>Unload a loaded codec</td></tr>
|
package/tests/test-repl.mjs
CHANGED
|
@@ -314,19 +314,13 @@ assert.equal(output[0], "loaded Examples/arithmetics.k");
|
|
|
314
314
|
output = await evaluateInput(":pat bits", arithState);
|
|
315
315
|
assert.equal(
|
|
316
316
|
output[0],
|
|
317
|
-
"bits[] = <
|
|
317
|
+
"bits[] = <X0 0, X0 1, {} _>=X0; -- " +
|
|
318
318
|
"@VtPHxGf5GNMzzyVFxtv7gegFfJRYapBGtCeyV56bs5Zb[]"
|
|
319
319
|
);
|
|
320
|
-
// output = await evaluateInput(":pat bit", arithState);
|
|
321
|
-
// assert.equal(
|
|
322
|
-
// output[0],
|
|
323
|
-
// "bit[] = <{} 0, {} 1>; -- " +
|
|
324
|
-
// "@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[]"
|
|
325
|
-
// );
|
|
326
320
|
output = await evaluateInput(":pat int[]", arithState);
|
|
327
321
|
assert.equal(
|
|
328
322
|
output[0],
|
|
329
|
-
"int[] =
|
|
323
|
+
"int[] = <<X0 0, X0 1, {} _>=X0 +, X0 ->; -- " +
|
|
330
324
|
"@Nws3vysWqC9PznraTP4kWPp44Rd77NAqrx9dgbtHAjGA[]"
|
|
331
325
|
);
|
|
332
326
|
output = await evaluateInput("10", arithState);
|
|
@@ -686,19 +680,19 @@ assert.equal(
|
|
|
686
680
|
output = await evaluateInput(":pattern bit", patState);
|
|
687
681
|
assert.equal(
|
|
688
682
|
output[0],
|
|
689
|
-
"bit[] = <{} 0,
|
|
683
|
+
"bit[] = <{}=X0 0, X0 1>; -- " +
|
|
690
684
|
"@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[]"
|
|
691
685
|
);
|
|
692
686
|
output = await evaluateInput(":pattern bit[]", patState);
|
|
693
687
|
assert.equal(
|
|
694
688
|
output[0],
|
|
695
|
-
"bit[] = <{} 0,
|
|
689
|
+
"bit[] = <{}=X0 0, X0 1>; -- " +
|
|
696
690
|
"@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[]"
|
|
697
691
|
);
|
|
698
692
|
output = await evaluateInput(":pat bit", patState);
|
|
699
693
|
assert.equal(
|
|
700
694
|
output[0],
|
|
701
|
-
"bit[] = <{} 0,
|
|
695
|
+
"bit[] = <{}=X0 0, X0 1>; -- " +
|
|
702
696
|
"@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[]"
|
|
703
697
|
);
|
|
704
698
|
output = await evaluateInput(
|
|
@@ -720,8 +714,8 @@ output = await evaluateInput(
|
|
|
720
714
|
output = await evaluateInput(":pattern byte", patState);
|
|
721
715
|
assert.equal(
|
|
722
716
|
output[0],
|
|
723
|
-
"byte[] = {
|
|
724
|
-
"
|
|
717
|
+
"byte[] = {<{}=X1 0, X1 1>=X0 b0, X0 b1, X0 b2, X0 b3, " +
|
|
718
|
+
"X0 b4, X0 b5, X0 b6, X0 b7}; -- " +
|
|
725
719
|
"@4ukq2gpiEBFa7WXxcfRm8pfdr2kgYLTTnwsmLHeMd9i5[]"
|
|
726
720
|
);
|
|
727
721
|
|
|
@@ -784,7 +778,7 @@ assert(output[0].includes("pair[A,B] = @KqTB"));
|
|
|
784
778
|
output = await evaluateInput(":pattern list", patState);
|
|
785
779
|
assert.equal(
|
|
786
780
|
output[0],
|
|
787
|
-
"list[X] = <{
|
|
781
|
+
"list[X] = <{X car, X0 cdr} cons, {} nil>=X0; -- " +
|
|
788
782
|
"@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X]"
|
|
789
783
|
);
|
|
790
784
|
|
|
@@ -812,13 +806,13 @@ assert.equal(
|
|
|
812
806
|
output = await evaluateInput(":pattern pair", freshState);
|
|
813
807
|
assert.equal(
|
|
814
808
|
output[0],
|
|
815
|
-
"pair[A, B] = {
|
|
809
|
+
"pair[A, B] = {A first, B second}; -- " +
|
|
816
810
|
"@KqTBNkznjWWwync2Mm94XjCez63neJBJtgYcJJEE5kEm[A, B]"
|
|
817
811
|
);
|
|
818
812
|
output = await evaluateInput(":pattern list", freshState);
|
|
819
813
|
assert.equal(
|
|
820
814
|
output[0],
|
|
821
|
-
"list[X] = <{
|
|
815
|
+
"list[X] = <{X car, X0 cdr} cons, {} nil>=X0; -- " +
|
|
822
816
|
"@JagVexzgseRr4rVZRmVpsMbr2AKXDjzZnz6Qnf8a9SNe[X]"
|
|
823
817
|
);
|
|
824
818
|
output = await evaluateInput(
|
|
@@ -838,7 +832,7 @@ output = await evaluateInput("a[] = x;", freshState);
|
|
|
838
832
|
output = await evaluateInput(":pattern a", freshState);
|
|
839
833
|
assert.equal(
|
|
840
834
|
output[0],
|
|
841
|
-
"a[] =
|
|
835
|
+
"a[] = (...); -- " +
|
|
842
836
|
"@QfyLpmn56wuppuGvrrUJz8LKtgaXfbMtad7RnzBcFk2S[(...)]"
|
|
843
837
|
);
|
|
844
838
|
output = await evaluateInput(
|
|
@@ -860,13 +854,13 @@ output = await evaluateInput(
|
|
|
860
854
|
output = await evaluateInput(":pat a", freshState);
|
|
861
855
|
assert.equal(
|
|
862
856
|
output[0],
|
|
863
|
-
"a[] = {
|
|
857
|
+
"a[] = {(...) x, (...) y}; -- " +
|
|
864
858
|
"@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[(...), (...)]"
|
|
865
859
|
);
|
|
866
860
|
output = await evaluateInput(":pat b", freshState);
|
|
867
861
|
assert.equal(
|
|
868
862
|
output[0],
|
|
869
|
-
"b[X] = {X x,
|
|
863
|
+
"b[X] = {X x, (...) y}; -- " +
|
|
870
864
|
"@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[X, (...)]"
|
|
871
865
|
);
|
|
872
866
|
output = await evaluateInput(":pat c", freshState);
|
|
@@ -980,7 +974,15 @@ assert(
|
|
|
980
974
|
)
|
|
981
975
|
);
|
|
982
976
|
|
|
983
|
-
// Verify :rel prints canonical pattern names
|
|
977
|
+
// Verify :rel prints inline when <= 45 and canonical pattern names when > maxPatLength
|
|
978
|
+
output = await evaluateInput(":rel reverse", polyExplicitState);
|
|
979
|
+
assert.equal(
|
|
980
|
+
output[0],
|
|
981
|
+
"reverse = ?<{(...) car, X0 cdr} cons, {} nil>=X0 " +
|
|
982
|
+
"{() xs, nil acc} _reverse ?X0; " +
|
|
983
|
+
"-- @JbJ2aQugNct2GGeCJ65zKjN55Bf5YPyGHzsikTCjx82w"
|
|
984
|
+
);
|
|
985
|
+
await evaluateInput(":max-pat-length 30", polyExplicitState);
|
|
984
986
|
output = await evaluateInput(":rel car", polyExplicitState);
|
|
985
987
|
assert.equal(
|
|
986
988
|
output[0],
|
|
@@ -1015,7 +1017,7 @@ assert.equal(
|
|
|
1015
1017
|
);
|
|
1016
1018
|
const shortThresholdState = createState();
|
|
1017
1019
|
output = await evaluateInput(":max-pat-length", shortThresholdState);
|
|
1018
|
-
assert.equal(output[0], "Current max pattern length:
|
|
1020
|
+
assert.equal(output[0], "Current max pattern length: 45");
|
|
1019
1021
|
output = await evaluateInput(":maxPatLength 10", shortThresholdState);
|
|
1020
1022
|
assert.equal(output[0], "max pattern length set to 10");
|
|
1021
1023
|
output = await evaluateInput(":max-pat-length", shortThresholdState);
|
|
@@ -1072,6 +1074,89 @@ completions = completeInput(":max", shortThresholdState)[0];
|
|
|
1072
1074
|
assert(completions.includes(":max-pat-length"));
|
|
1073
1075
|
assert(completions.includes(":maxPatLength"));
|
|
1074
1076
|
|
|
1077
|
+
// Verify canonical :pat output and :all-patterns / :all-pats
|
|
1078
|
+
const allPatState = createState();
|
|
1079
|
+
output = await evaluateInput(":all-patterns", allPatState);
|
|
1080
|
+
assert.equal(output[0], "(none)");
|
|
1081
|
+
await evaluateInput("p[X,Y] = {X x, Y y};", allPatState);
|
|
1082
|
+
await evaluateInput("bit[] = <{} 1, {} 0>;", allPatState);
|
|
1083
|
+
await evaluateInput("u[] = p[bit[], bit[]];", allPatState);
|
|
1084
|
+
await evaluateInput("w[] = {<{} 0, {} 1>=X x, X y};", allPatState);
|
|
1085
|
+
output = await evaluateInput(":pat u", allPatState);
|
|
1086
|
+
assert.equal(
|
|
1087
|
+
output[0],
|
|
1088
|
+
"u[] = {<{}=X1 0, X1 1>=X0 x, X0 y}; " +
|
|
1089
|
+
"-- @akFfWqqyH7nALkFxD2ixhF46W2FMeymuhAGxtbN2hPew[]"
|
|
1090
|
+
);
|
|
1091
|
+
output = await evaluateInput(":pat w", allPatState);
|
|
1092
|
+
assert.equal(
|
|
1093
|
+
output[0],
|
|
1094
|
+
"w[] = {<{}=X1 0, X1 1>=X0 x, X0 y}; " +
|
|
1095
|
+
"-- @akFfWqqyH7nALkFxD2ixhF46W2FMeymuhAGxtbN2hPew[]"
|
|
1096
|
+
);
|
|
1097
|
+
output = await evaluateInput(":all-patterns", allPatState);
|
|
1098
|
+
assert.equal(
|
|
1099
|
+
output[0],
|
|
1100
|
+
[
|
|
1101
|
+
"@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[] = " +
|
|
1102
|
+
"<{}=X0 0, X0 1>; -- bit[] = @[]",
|
|
1103
|
+
"@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[X0,X1] = " +
|
|
1104
|
+
"{X0 x, X1 y}; -- p[X,Y] = @[X,Y]",
|
|
1105
|
+
"@akFfWqqyH7nALkFxD2ixhF46W2FMeymuhAGxtbN2hPew[] = " +
|
|
1106
|
+
"{<{}=X1 0, X1 1>=X0 x, X0 y}; -- u[] = @[], w[] = @[]"
|
|
1107
|
+
].join("\n")
|
|
1108
|
+
);
|
|
1109
|
+
output = await evaluateInput(":all-pats", allPatState);
|
|
1110
|
+
assert.equal(
|
|
1111
|
+
output[0],
|
|
1112
|
+
[
|
|
1113
|
+
"@MjusyRWZnVj8TR4BhFCCcMRrQbdKp9gPtC29LT9nZvjg[] = " +
|
|
1114
|
+
"<{}=X0 0, X0 1>; -- bit[] = @[]",
|
|
1115
|
+
"@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[X0,X1] = " +
|
|
1116
|
+
"{X0 x, X1 y}; -- p[X,Y] = @[X,Y]",
|
|
1117
|
+
"@akFfWqqyH7nALkFxD2ixhF46W2FMeymuhAGxtbN2hPew[] = " +
|
|
1118
|
+
"{<{}=X1 0, X1 1>=X0 x, X0 y}; -- u[] = @[], w[] = @[]"
|
|
1119
|
+
].join("\n")
|
|
1120
|
+
);
|
|
1121
|
+
|
|
1122
|
+
const pqState = createState();
|
|
1123
|
+
await evaluateInput("p[X] = {X x, Y y};", pqState);
|
|
1124
|
+
await evaluateInput("q[ZZZ] = {ZZZ x, ZZZ y};", pqState);
|
|
1125
|
+
output = await evaluateInput(":all-pat", pqState);
|
|
1126
|
+
assert.equal(
|
|
1127
|
+
output[0],
|
|
1128
|
+
"@NPSHm9HbPgXmGHVGMJGJFq7rq4LiFiavPX27mUwyE26x[X0,X1] = " +
|
|
1129
|
+
"{X0 x, X1 y}; -- p[X] = @[X,(...)], q[ZZZ] = @[ZZZ,ZZZ]"
|
|
1130
|
+
);
|
|
1131
|
+
completions = completeInput(":all", allPatState)[0];
|
|
1132
|
+
assert(completions.includes(":all-patterns"));
|
|
1133
|
+
assert(completions.includes(":all-pat"));
|
|
1134
|
+
|
|
1135
|
+
const relPatState = createState();
|
|
1136
|
+
await evaluateInput("ww = ?<{} x, {}y, Z z > = Z;", relPatState);
|
|
1137
|
+
output = await evaluateInput(":pats", relPatState);
|
|
1138
|
+
assert.equal(output[0], "(none)");
|
|
1139
|
+
output = await evaluateInput(":all-pats", relPatState);
|
|
1140
|
+
assert.equal(
|
|
1141
|
+
output[0],
|
|
1142
|
+
"@zJ4APgx8cLrV6EeNJjePDU25sEkNH5AX7CUjFWmCAwhY[] = " +
|
|
1143
|
+
"<{}=X1 x, X1 y, X0 z>=X0;"
|
|
1144
|
+
);
|
|
1145
|
+
output = await evaluateInput(":rel ww", relPatState);
|
|
1146
|
+
assert.equal(
|
|
1147
|
+
output[0],
|
|
1148
|
+
"ww = ?<{}=X1 x, X1 y, X0 z>=X0 () ?X0; " +
|
|
1149
|
+
"-- @VmhPa6q6x9eeN8pnyJnz89w9GVjNhWtz5zZghJb4zjUx"
|
|
1150
|
+
);
|
|
1151
|
+
await evaluateInput(":max-pat-length 10", relPatState);
|
|
1152
|
+
output = await evaluateInput(":rel ww", relPatState);
|
|
1153
|
+
assert.equal(
|
|
1154
|
+
output[0],
|
|
1155
|
+
"ww = ?@zJ4APgx8cLrV6EeNJjePDU25sEkNH5AX7CUjFWmCAwhY[] () " +
|
|
1156
|
+
"?@zJ4APgx8cLrV6EeNJjePDU25sEkNH5AX7CUjFWmCAwhY[]; " +
|
|
1157
|
+
"-- @VmhPa6q6x9eeN8pnyJnz89w9GVjNhWtz5zZghJb4zjUx"
|
|
1158
|
+
);
|
|
1159
|
+
|
|
1075
1160
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
1076
1161
|
fs.rmSync(symlinkPath, { force: true });
|
|
1077
1162
|
console.log("OK");
|