@fraczak/k 5.1.2 → 6.0.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/Code-derivation-tests/blowup.mjs +3 -3
- package/Code-derivation-tests/bnat.mjs +2 -2
- package/Code-derivation-tests/codec-witness-pattern.mjs +50 -0
- package/Code-derivation-tests/convergence-strategy.mjs +24 -0
- package/Code-derivation-tests/dot.mjs +12 -9
- package/Code-derivation-tests/filter-syntax.mjs +21 -0
- package/Code-derivation-tests/loop.mjs +8 -2
- package/Code-derivation-tests/nat.mjs +1 -1
- package/Code-derivation-tests/not-not.mjs +3 -3
- package/Code-derivation-tests/pattern-envelope.mjs +68 -0
- package/Code-derivation-tests/rlz.mjs +2 -2
- package/{BIG_PICTURE.md → DOCS/BIG_PICTURE.md} +103 -50
- package/DOCS/REPL.md +191 -0
- package/DOCS/book/01-introduction.md +51 -0
- package/DOCS/book/02-syntax-and-values.md +111 -0
- package/DOCS/book/03-types-as-finite-automata.md +156 -0
- package/DOCS/book/04-partial-functions-and-composition.md +146 -0
- package/DOCS/book/05-typing-filters-and-normalization.md +111 -0
- package/DOCS/book.md +54 -0
- package/README.md +204 -508
- package/TypeGraph.mjs +43 -0
- package/TypePatternGraph.mjs +251 -0
- package/Value.mjs +192 -0
- package/augmentation.mjs +198 -0
- package/codecs/BINARY_FORMAT.md +53 -0
- package/codecs/POLYMORPHIC_BINARY_FORMAT.md +303 -0
- package/codecs/README.md +215 -0
- package/codecs/example-pipeline.mjs +149 -0
- package/codecs/ieee.mjs +140 -0
- package/codecs/int.mjs +104 -0
- package/codecs/json-codec.mjs +215 -0
- package/codecs/json.mjs +40 -0
- package/codecs/k-parse.mjs +90 -0
- package/codecs/k-pattern.mjs +75 -0
- package/codecs/k-print.mjs +46 -0
- package/codecs/runtime/codec.mjs +768 -0
- package/codecs/runtime/ieee-pattern.mjs +30 -0
- package/codecs/runtime/pattern-json.mjs +96 -0
- package/codecs/runtime/prefix-codec.mjs +425 -0
- package/codecs/runtime/show-value.mjs +68 -0
- package/codecs/runtime/typeFromValue.mjs +34 -0
- package/codecs/runtime/unicode-string.mjs +220 -0
- package/codecs/show.mjs +41 -0
- package/codecs/string-codec.mjs +80 -0
- package/codecs/unit.mjs +51 -0
- package/codecs/utf16.mjs +66 -0
- package/codecs/utf8.mjs +37 -0
- package/codes.mjs +146 -44
- package/compiler.mjs +111 -0
- package/convergence.mjs +197 -0
- package/core.k +197 -0
- package/export.mjs +22 -32
- package/hash.mjs +29 -31
- package/index.mjs +41 -15
- package/k-vscode/.vscode/launch.json +14 -0
- package/k-vscode/README.md +65 -0
- package/k-vscode/language-configuration.json +42 -0
- package/k-vscode/package.json +57 -0
- package/k-vscode/snippets/k.json +92 -0
- package/k-vscode/syntaxes/k.tmLanguage.json +243 -0
- package/k.mjs +56 -54
- package/object.mjs +517 -0
- package/objects/README.md +38 -0
- package/objects/compile-lib.mjs +42 -0
- package/objects/compile.mjs +42 -0
- package/objects/decompile.mjs +32 -0
- package/package.json +18 -8
- package/parser.jison +27 -46
- package/parser.mjs +68 -100
- package/pretty.mjs +21 -40
- package/repl2.mjs +652 -0
- package/run.mjs +264 -231
- package/symbol-table.mjs +3 -17
- package/test-fingerprint.mjs +7 -7
- package/test-hash-fuzz.mjs +107 -0
- package/test-hash-normalization.mjs +134 -0
- package/test-k-object.mjs +74 -0
- package/test-repl2.mjs +95 -0
- package/test.mjs +45 -70
- package/tests.sh +10 -1
- package/typing.mjs +129 -676
- package/unification.mjs +157 -0
- package/valueIO.mjs +54 -0
- package/valueParser.jison +143 -0
- package/valueParser.mjs +713 -0
- package/Code-derivation-tests/built-in.mjs +0 -19
- package/Code-derivation-tests/vector.mjs +0 -19
- package/Filters/bug.k +0 -3
- package/Filters/composing.k +0 -15
- package/Filters/filter.k +0 -9
- package/TODO.md +0 -53
- package/TYPING.md +0 -365
- package/k-repl.cast +0 -1913
- package/k.cast +0 -618
- package/my-objects.json +0 -6
- package/patterns.mjs +0 -543
- package/repl.mjs +0 -213
- package/test-filters.mjs +0 -45
- package/typing-test.mjs +0 -40
package/pretty.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TypePatternGraph } from "./typing.mjs";
|
|
1
|
+
import { TypePatternGraph } from "./TypePatternGraph.mjs";
|
|
3
2
|
|
|
4
|
-
const nameRE = /^[a-zA-Z0-9_][a-zA-Z0-9_?!]*$/;
|
|
3
|
+
// const nameRE = /^[a-zA-Z0-9_][a-zA-Z0-9_?!]*$/;
|
|
4
|
+
const nameRE = /^[a-zA-Z0-9_+-][a-zA-Z0-9_?!+-]*$/;
|
|
5
5
|
function pLabel_(label) {
|
|
6
6
|
return nameRE.test(label) ? ` ${label}` : `${JSON.stringify(label)}`;
|
|
7
7
|
}
|
|
@@ -9,11 +9,11 @@ function pLabel(label) {
|
|
|
9
9
|
return nameRE.test(label) ? `${label}` : `${JSON.stringify(label)}`;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function prettyCode_labels (representatives, label_ref_map) {
|
|
12
|
+
function prettyCode_labels (representatives, findCode, label_ref_map) {
|
|
13
13
|
return Object.keys(label_ref_map)
|
|
14
14
|
.sort()
|
|
15
15
|
.map( (label) => {
|
|
16
|
-
return `${prettyCode(representatives, {
|
|
16
|
+
return `${prettyCode(representatives, findCode, {
|
|
17
17
|
code: "ref",
|
|
18
18
|
ref: label_ref_map[label],
|
|
19
19
|
})}${pLabel_(label)}`;
|
|
@@ -21,22 +21,19 @@ function prettyCode_labels (representatives, label_ref_map) {
|
|
|
21
21
|
.join(", ");
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
function prettyCode (representatives, codeExp) {
|
|
24
|
+
function prettyCode (representatives, findCode, codeExp) {
|
|
25
25
|
switch (codeExp.code) {
|
|
26
26
|
case "ref":
|
|
27
27
|
const name = representatives[codeExp.ref] || codeExp.ref;
|
|
28
28
|
if (name.startsWith(":")) {
|
|
29
|
-
return prettyCode(representatives,
|
|
29
|
+
return prettyCode(representatives, findCode, findCode(name));
|
|
30
30
|
} else {
|
|
31
31
|
return name;
|
|
32
32
|
}
|
|
33
33
|
case "product":
|
|
34
|
-
return `{${prettyCode_labels(representatives, codeExp.product)}}`;
|
|
34
|
+
return `{${prettyCode_labels(representatives, findCode, codeExp.product)}}`;
|
|
35
35
|
case "union":
|
|
36
|
-
return `< ${prettyCode_labels(representatives, codeExp.union)} >`;
|
|
37
|
-
case "vector":
|
|
38
|
-
return `[${prettyCode(representatives, {code:'ref', ref:codeExp.vector})}]`;
|
|
39
|
-
// return `[${representatives[codeExp.vector] || codeExp.vector}]`;
|
|
36
|
+
return `< ${prettyCode_labels(representatives, findCode, codeExp.union)} >`;
|
|
40
37
|
default:
|
|
41
38
|
return ":error";
|
|
42
39
|
}
|
|
@@ -56,10 +53,11 @@ function prettyFilter ( filter ) {
|
|
|
56
53
|
return `$${filter.code}`;
|
|
57
54
|
case "name":
|
|
58
55
|
return filter.name;
|
|
59
|
-
case "vector":
|
|
60
|
-
return `[${prettyFilter(filter.vector)}]${filter.name ? "=" + filter.name : ""}`;
|
|
61
56
|
case null:
|
|
62
|
-
if (filter.
|
|
57
|
+
if (!filter.open || Object.keys(filter.fields).length !== 0) {
|
|
58
|
+
throw new Error(`Unknown-kind filters must be exactly (...): ${JSON.stringify(filter)}`);
|
|
59
|
+
}
|
|
60
|
+
if (filter.name)
|
|
63
61
|
return filter.name;
|
|
64
62
|
return `(${fieldsStr()})${filter.name ? "=" + filter.name : ""}`;
|
|
65
63
|
case "union":
|
|
@@ -77,12 +75,6 @@ function prettyRel (exp) {
|
|
|
77
75
|
case "filter":
|
|
78
76
|
if (exp.filter.type == 'code') return `$${exp.filter.code}`;
|
|
79
77
|
return `?${prettyFilter(exp.filter)}`;
|
|
80
|
-
case "pipe":
|
|
81
|
-
return `|`;
|
|
82
|
-
case "caret":
|
|
83
|
-
return `(${pretty(exp.caret)} ^)`;
|
|
84
|
-
case "vector":
|
|
85
|
-
return `[${exp.vector.map(pretty).join(", ")}]`;
|
|
86
78
|
case "union":
|
|
87
79
|
return `<${exp.union.map(pretty).join(", ")}>`;
|
|
88
80
|
case "ref":
|
|
@@ -91,15 +83,12 @@ function prettyRel (exp) {
|
|
|
91
83
|
return "()";
|
|
92
84
|
case "comp":
|
|
93
85
|
return exp.comp.map(pretty).join(" ");
|
|
94
|
-
case "str":
|
|
95
|
-
return `'${exp.str}'`;
|
|
96
|
-
case "int":
|
|
97
|
-
return exp.int;
|
|
98
86
|
case "dot":
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
87
|
+
return `.${pLabel(exp.dot)}`;
|
|
88
|
+
case "div":
|
|
89
|
+
return `/${pLabel(exp.div)}`;
|
|
90
|
+
case "vid":
|
|
91
|
+
return `|${pLabel(exp.vid)}`;
|
|
103
92
|
case "code":
|
|
104
93
|
return `$${exp.code}`;
|
|
105
94
|
case "product":
|
|
@@ -117,7 +106,7 @@ function prettyRel (exp) {
|
|
|
117
106
|
|
|
118
107
|
|
|
119
108
|
function patterns2filters(typePatternGraph, ...patternIds) {
|
|
120
|
-
const newTypePatternGraph = new TypePatternGraph();
|
|
109
|
+
const newTypePatternGraph = new TypePatternGraph(typePatternGraph.registerCodeDef, typePatternGraph.findCode);
|
|
121
110
|
const renamed = typePatternGraph.clone(patternIds, newTypePatternGraph);
|
|
122
111
|
const newPatternIds = patternIds.map((id) => newTypePatternGraph.find(renamed[id]));
|
|
123
112
|
|
|
@@ -159,20 +148,12 @@ function patterns2filters(typePatternGraph, ...patternIds) {
|
|
|
159
148
|
switch (pattern.pattern) {
|
|
160
149
|
case 'type':
|
|
161
150
|
return {type: "code", code: pattern.type, ...named_filter};
|
|
162
|
-
case '[]':
|
|
163
|
-
return {
|
|
164
|
-
type: "vector",
|
|
165
|
-
vector: buildFilter([...path, "vector-member"], Object.values(edges["vector-member"])[0], i),
|
|
166
|
-
...named_filter
|
|
167
|
-
};
|
|
168
151
|
case '(...)':
|
|
169
152
|
return { type: null, open: true, fields: fields(), ...named_filter };
|
|
170
153
|
case '{...}':
|
|
171
154
|
return { type: 'product', open: true, fields: fields(), ...named_filter };
|
|
172
155
|
case '<...>':
|
|
173
156
|
return { type: 'union', open: true, fields: fields(), ...named_filter };
|
|
174
|
-
case '()':
|
|
175
|
-
return { type: null, fields: fields(), ...named_filter };
|
|
176
157
|
case '{}':
|
|
177
158
|
return { type: 'product', fields: fields(), ...named_filter };
|
|
178
159
|
case '<>':
|
|
@@ -185,5 +166,5 @@ function patterns2filters(typePatternGraph, ...patternIds) {
|
|
|
185
166
|
|
|
186
167
|
}
|
|
187
168
|
|
|
188
|
-
export default { prettyCode, prettyRel, patterns2filters };
|
|
189
|
-
export { prettyCode, prettyRel, patterns2filters };
|
|
169
|
+
export default { prettyCode, prettyRel, prettyFilter, patterns2filters };
|
|
170
|
+
export { prettyCode, prettyRel, prettyFilter, patterns2filters };
|