@fraczak/k 5.1.1 → 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.
Files changed (99) hide show
  1. package/Code-derivation-tests/blowup.mjs +3 -3
  2. package/Code-derivation-tests/bnat.mjs +2 -2
  3. package/Code-derivation-tests/codec-witness-pattern.mjs +50 -0
  4. package/Code-derivation-tests/convergence-strategy.mjs +24 -0
  5. package/Code-derivation-tests/dot.mjs +12 -9
  6. package/Code-derivation-tests/filter-syntax.mjs +21 -0
  7. package/Code-derivation-tests/loop.mjs +8 -2
  8. package/Code-derivation-tests/nat.mjs +1 -1
  9. package/Code-derivation-tests/not-not.mjs +3 -3
  10. package/Code-derivation-tests/pattern-envelope.mjs +68 -0
  11. package/Code-derivation-tests/rlz.mjs +2 -2
  12. package/{BIG_PICTURE.md → DOCS/BIG_PICTURE.md} +103 -50
  13. package/DOCS/REPL.md +191 -0
  14. package/DOCS/book/01-introduction.md +51 -0
  15. package/DOCS/book/02-syntax-and-values.md +111 -0
  16. package/DOCS/book/03-types-as-finite-automata.md +156 -0
  17. package/DOCS/book/04-partial-functions-and-composition.md +146 -0
  18. package/DOCS/book/05-typing-filters-and-normalization.md +111 -0
  19. package/DOCS/book.md +54 -0
  20. package/README.md +204 -508
  21. package/TypeGraph.mjs +43 -0
  22. package/TypePatternGraph.mjs +251 -0
  23. package/Value.mjs +192 -0
  24. package/augmentation.mjs +198 -0
  25. package/codecs/BINARY_FORMAT.md +53 -0
  26. package/codecs/POLYMORPHIC_BINARY_FORMAT.md +303 -0
  27. package/codecs/README.md +215 -0
  28. package/codecs/example-pipeline.mjs +149 -0
  29. package/codecs/ieee.mjs +140 -0
  30. package/codecs/int.mjs +104 -0
  31. package/codecs/json-codec.mjs +215 -0
  32. package/codecs/json.mjs +40 -0
  33. package/codecs/k-parse.mjs +90 -0
  34. package/codecs/k-pattern.mjs +75 -0
  35. package/codecs/k-print.mjs +46 -0
  36. package/codecs/runtime/codec.mjs +768 -0
  37. package/codecs/runtime/ieee-pattern.mjs +30 -0
  38. package/codecs/runtime/pattern-json.mjs +96 -0
  39. package/codecs/runtime/prefix-codec.mjs +425 -0
  40. package/codecs/runtime/show-value.mjs +68 -0
  41. package/codecs/runtime/typeFromValue.mjs +34 -0
  42. package/codecs/runtime/unicode-string.mjs +220 -0
  43. package/codecs/show.mjs +41 -0
  44. package/codecs/string-codec.mjs +80 -0
  45. package/codecs/unit.mjs +51 -0
  46. package/codecs/utf16.mjs +66 -0
  47. package/codecs/utf8.mjs +37 -0
  48. package/codes.mjs +146 -44
  49. package/compiler.mjs +111 -0
  50. package/convergence.mjs +197 -0
  51. package/core.k +197 -0
  52. package/export.mjs +22 -32
  53. package/hash.mjs +29 -31
  54. package/index.mjs +41 -15
  55. package/k-vscode/.vscode/launch.json +14 -0
  56. package/k-vscode/README.md +65 -0
  57. package/k-vscode/language-configuration.json +42 -0
  58. package/k-vscode/package.json +57 -0
  59. package/k-vscode/snippets/k.json +92 -0
  60. package/k-vscode/syntaxes/k.tmLanguage.json +243 -0
  61. package/k.mjs +56 -54
  62. package/object.mjs +517 -0
  63. package/objects/README.md +38 -0
  64. package/objects/compile-lib.mjs +42 -0
  65. package/objects/compile.mjs +42 -0
  66. package/objects/decompile.mjs +32 -0
  67. package/package.json +18 -8
  68. package/parser.jison +27 -46
  69. package/parser.mjs +68 -100
  70. package/pretty.mjs +21 -40
  71. package/repl2.mjs +652 -0
  72. package/run.mjs +264 -231
  73. package/symbol-table.mjs +3 -17
  74. package/test-fingerprint.mjs +7 -7
  75. package/test-hash-fuzz.mjs +107 -0
  76. package/test-hash-normalization.mjs +134 -0
  77. package/test-k-object.mjs +74 -0
  78. package/test-repl2.mjs +95 -0
  79. package/test.mjs +45 -70
  80. package/tests.sh +10 -1
  81. package/typing.mjs +129 -676
  82. package/unification.mjs +157 -0
  83. package/valueIO.mjs +54 -0
  84. package/valueParser.jison +143 -0
  85. package/valueParser.mjs +713 -0
  86. package/Code-derivation-tests/built-in.mjs +0 -19
  87. package/Code-derivation-tests/vector.mjs +0 -19
  88. package/Filters/bug.k +0 -3
  89. package/Filters/composing.k +0 -15
  90. package/Filters/filter.k +0 -9
  91. package/TODO.md +0 -53
  92. package/TYPING.md +0 -365
  93. package/k-repl.cast +0 -1913
  94. package/k.cast +0 -618
  95. package/my-objects.json +0 -6
  96. package/patterns.mjs +0 -543
  97. package/repl.mjs +0 -213
  98. package/test-filters.mjs +0 -45
  99. package/typing-test.mjs +0 -40
package/pretty.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import { find } from "./codes.mjs";
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, find(name));
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.name && Object.keys(filter.fields).length == 0)
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
- if ("number" === typeof exp.dot) {
100
- return `.${exp.dot}`;
101
- } else
102
- return `.${pLabel(exp.dot)}`;
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 };