@fraczak/k 2.1.5 → 3.0.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/Code-derivation-tests/bnat.mjs +10 -0
- package/Code-derivation-tests/built-in.mjs +19 -0
- package/Code-derivation-tests/dot.mjs +15 -0
- package/Code-derivation-tests/index.mjs +20 -0
- package/Code-derivation-tests/loop.mjs +11 -0
- package/Code-derivation-tests/nat.mjs +10 -0
- package/Code-derivation-tests/not-not.mjs +14 -0
- package/Code-derivation-tests/product.mjs +21 -0
- package/Code-derivation-tests/rlz.mjs +14 -0
- package/Code-derivation-tests/vector.mjs +28 -0
- package/INTRO.md +88 -0
- package/README.md +68 -14
- package/TODO.md +54 -0
- package/TYPES.md +32 -0
- package/bug.json +419 -0
- package/chatGPT.md +235 -0
- package/chatGPT.md~ +119 -0
- package/code-resolution.md +121 -0
- package/code-resolution.mjs +51 -0
- package/codes.mjs +59 -4
- package/filters.mjs +59 -0
- package/hash.mjs +39 -0
- package/index.mjs +55 -12
- package/package.json +2 -2
- package/parser.jison +111 -44
- package/parser.mjs +146 -88
- package/patterns.mjs +601 -0
- package/pretty.mjs +31 -0
- package/repl.mjs +6 -3
- package/run.mjs +4 -1
- package/symbol-table.mjs +2 -2
- package/test-filters.mjs +45 -0
- package/test-fingerprint.mjs +38 -0
- package/test.mjs +1 -43
package/symbol-table.mjs
CHANGED
|
@@ -56,7 +56,7 @@ function comp_first(e1, e2) {
|
|
|
56
56
|
if (is_identity_rel(e1)) return e2;
|
|
57
57
|
if (is_identity_rel(e2)) return e1;
|
|
58
58
|
if (is_empty_rel(e1)) return e1;
|
|
59
|
-
if (is_empty_rel(e2)) return e2;
|
|
59
|
+
// if (is_empty_rel(e2)) return e2;
|
|
60
60
|
if (e1.op === "comp" && e2.op === "comp") {
|
|
61
61
|
return {
|
|
62
62
|
op: "comp",
|
|
@@ -97,7 +97,7 @@ function union (rels) {
|
|
|
97
97
|
const new_rels = rel.op === "union" ? rel.union : [rel];
|
|
98
98
|
for (const new_rel of new_rels) {
|
|
99
99
|
list.push(new_rel);
|
|
100
|
-
if (is_full_rel(new_rel)) break label;
|
|
100
|
+
// if (is_full_rel(new_rel)) break label;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
if (list.length === 1) return list[0];
|
package/test-filters.mjs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { unify_with_code } from './filters.mjs';
|
|
2
|
+
import k from './index.mjs';
|
|
3
|
+
// { compile, run, parse, annotate };
|
|
4
|
+
|
|
5
|
+
const annotated = k.annotate(`
|
|
6
|
+
$nat = < {} _, nat s >;
|
|
7
|
+
$pair = { nat x, nat y };
|
|
8
|
+
$list = < {} empty, { nat x, list xs } list>;
|
|
9
|
+
z = {{} _} $nat;
|
|
10
|
+
s = { $nat s} $nat;
|
|
11
|
+
f1 = ? { n x, ...};
|
|
12
|
+
f2 = ? { <...> y, ...};
|
|
13
|
+
f3 = ? < x empty, { $MWqNxWxHMy xs, ...} list >;
|
|
14
|
+
{}
|
|
15
|
+
`);
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// console.log(JSON.stringify(annotated, null, 2));
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
const test1 = unify_with_code(
|
|
24
|
+
annotated.codes,
|
|
25
|
+
annotated.representatives["pair"],
|
|
26
|
+
annotated.rels['f1'][0].filter,
|
|
27
|
+
{}
|
|
28
|
+
);
|
|
29
|
+
console.log(JSON.stringify(test1, null, 2));
|
|
30
|
+
|
|
31
|
+
const test2 = unify_with_code(
|
|
32
|
+
annotated.codes,
|
|
33
|
+
annotated.representatives["pair"],
|
|
34
|
+
annotated.rels['f2'][0].filter,
|
|
35
|
+
{}
|
|
36
|
+
);
|
|
37
|
+
console.log(JSON.stringify(test2, null, 2));
|
|
38
|
+
|
|
39
|
+
const test3 = unify_with_code(
|
|
40
|
+
annotated.codes,
|
|
41
|
+
annotated.representatives["list"],
|
|
42
|
+
annotated.rels['f3'][0].filter,
|
|
43
|
+
{}
|
|
44
|
+
);
|
|
45
|
+
console.log(JSON.stringify(test3, null, 2));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import k from './index.mjs';
|
|
2
|
+
import { encodeCodeToString } from './codes.mjs';
|
|
3
|
+
import hash from './hash.mjs';
|
|
4
|
+
[
|
|
5
|
+
`
|
|
6
|
+
$nat = < {} zero, nat succ>;
|
|
7
|
+
$pair = {nat x, nat y};
|
|
8
|
+
$b = {int"x", bool y};
|
|
9
|
+
$vector = [int];
|
|
10
|
+
$tree = <{nat value, tree left, tree right} binary, {nat value} leaf, {nat value, tree tree} unary, [tree] list_of_trees>;
|
|
11
|
+
|
|
12
|
+
succ = { $nat succ} $nat;
|
|
13
|
+
plus = $pair <
|
|
14
|
+
{.x.zero stop, .y result} .result,
|
|
15
|
+
{.x.succ x, .y succ y } plus
|
|
16
|
+
> $nat;
|
|
17
|
+
{{} zero} succ succ {() x, () y} plus
|
|
18
|
+
`
|
|
19
|
+
].map(function (script) {
|
|
20
|
+
console.log(`k_expression = '${script}';`);
|
|
21
|
+
const annotated = k.annotate(script);
|
|
22
|
+
for (const code in annotated.codes) {
|
|
23
|
+
console.log(`CODE: ${code}`);
|
|
24
|
+
const s = encodeCodeToString(code,annotated.codes);
|
|
25
|
+
console.log(` - DEFS: ${s}`);;
|
|
26
|
+
const annotated2 = k.annotate(s+" {}");;
|
|
27
|
+
const s2 = encodeCodeToString(annotated2.representatives["C0"],annotated2.codes);
|
|
28
|
+
console.log(` - reparsed FINGERPRINT: ${hash(s2)}`);
|
|
29
|
+
if ((s === s2) && (hash(s) === hash(s2))) {
|
|
30
|
+
console.log('--- OK');
|
|
31
|
+
} else {
|
|
32
|
+
console.log('--- ERROR');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
console.log('-------------------');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
package/test.mjs
CHANGED
|
@@ -34,7 +34,7 @@ import k from "./index.mjs";
|
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
let k_expression =
|
|
37
|
-
'{.name nom, <[.age, 18] GT
|
|
37
|
+
'{.name nom, <[.age, 18] GT "old", [.age, 12] GT "ado", "enfant"> age}';
|
|
38
38
|
|
|
39
39
|
let k_fn = k.compile(k_expression);
|
|
40
40
|
|
|
@@ -61,48 +61,6 @@ console.log("");
|
|
|
61
61
|
return console.log("");
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
k_expression = "$t = < i: int, t: [ t ] > ; <$t, $int>";
|
|
65
|
-
|
|
66
|
-
k_fn = k.compile(k_expression);
|
|
67
|
-
|
|
68
|
-
console.log(`var k_fn = k.compile('${k_expression}');`);
|
|
69
|
-
|
|
70
|
-
console.log("");
|
|
71
|
-
|
|
72
|
-
[
|
|
73
|
-
1,
|
|
74
|
-
{
|
|
75
|
-
i: 1,
|
|
76
|
-
},
|
|
77
|
-
[
|
|
78
|
-
{
|
|
79
|
-
i: 2,
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
i: 3,
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
t: [],
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
{
|
|
89
|
-
t: [
|
|
90
|
-
{
|
|
91
|
-
i: 2,
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
i: 3,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
t: [],
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
},
|
|
101
|
-
].map(function (data) {
|
|
102
|
-
console.log(`k_fn(${JSON.stringify(data)});`);
|
|
103
|
-
console.log(`// RETURNS: ${JSON.stringify(k_fn(data))}`);
|
|
104
|
-
return console.log("");
|
|
105
|
-
});
|
|
106
64
|
|
|
107
65
|
k_expression = "$ < < [ int ] ints, [ bool ] bools > list, string None>";
|
|
108
66
|
|