@fraczak/k 5.1.2 → 6.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.
Files changed (115) hide show
  1. package/.codex +0 -0
  2. package/Code-derivation-tests/blowup.mjs +3 -3
  3. package/Code-derivation-tests/bnat.mjs +2 -2
  4. package/Code-derivation-tests/codec-witness-pattern.mjs +50 -0
  5. package/Code-derivation-tests/convergence-strategy.mjs +24 -0
  6. package/Code-derivation-tests/dot.mjs +12 -9
  7. package/Code-derivation-tests/filter-syntax.mjs +21 -0
  8. package/Code-derivation-tests/loop.mjs +8 -2
  9. package/Code-derivation-tests/nat.mjs +1 -1
  10. package/Code-derivation-tests/not-not.mjs +3 -3
  11. package/Code-derivation-tests/pattern-envelope.mjs +68 -0
  12. package/Code-derivation-tests/rlz.mjs +2 -2
  13. package/{BIG_PICTURE.md → DOCS/BIG_PICTURE.md} +103 -50
  14. package/DOCS/REPL.md +191 -0
  15. package/DOCS/a.html +398 -0
  16. package/DOCS/book/01-introduction.md +51 -0
  17. package/DOCS/book/02-syntax-and-values.md +111 -0
  18. package/DOCS/book/03-types-as-finite-automata.md +156 -0
  19. package/DOCS/book/04-partial-functions-and-composition.md +146 -0
  20. package/DOCS/book/05-typing-filters-and-normalization.md +111 -0
  21. package/DOCS/book-combined.html +3798 -0
  22. package/DOCS/book-combined.md +3745 -0
  23. package/DOCS/book-combined.pdf +0 -0
  24. package/DOCS/book-combined.tex +5682 -0
  25. package/DOCS/book.html +65 -0
  26. package/DOCS/book.md +54 -0
  27. package/DOCS/book.pdf +0 -0
  28. package/DOCS/book.tex +150 -0
  29. package/NAT.k~ +452 -0
  30. package/README.md +204 -508
  31. package/TypeGraph.mjs +43 -0
  32. package/TypePatternGraph.mjs +251 -0
  33. package/Value.mjs +192 -0
  34. package/augmentation.mjs +198 -0
  35. package/codecs/BINARY_FORMAT.html +471 -0
  36. package/codecs/BINARY_FORMAT.md +53 -0
  37. package/codecs/POLYMORPHIC_BINARY_FORMAT.html +355 -0
  38. package/codecs/POLYMORPHIC_BINARY_FORMAT.md +303 -0
  39. package/codecs/README.md +215 -0
  40. package/codecs/example-pipeline.mjs +149 -0
  41. package/codecs/ieee.mjs +140 -0
  42. package/codecs/int.mjs +104 -0
  43. package/codecs/json-codec.mjs +215 -0
  44. package/codecs/json.mjs +40 -0
  45. package/codecs/k-parse.mjs +90 -0
  46. package/codecs/k-pattern.mjs +75 -0
  47. package/codecs/k-print.mjs +46 -0
  48. package/codecs/runtime/codec.mjs +768 -0
  49. package/codecs/runtime/ieee-pattern.mjs +30 -0
  50. package/codecs/runtime/pattern-json.mjs +96 -0
  51. package/codecs/runtime/prefix-codec.mjs +425 -0
  52. package/codecs/runtime/show-value.mjs +68 -0
  53. package/codecs/runtime/typeFromValue.mjs +34 -0
  54. package/codecs/runtime/unicode-string.mjs +220 -0
  55. package/codecs/show.mjs +41 -0
  56. package/codecs/string-codec.mjs +80 -0
  57. package/codecs/unit.mjs +51 -0
  58. package/codecs/utf16.mjs +66 -0
  59. package/codecs/utf8.mjs +37 -0
  60. package/codes.mjs +146 -44
  61. package/compiler.mjs +111 -0
  62. package/convergence.mjs +197 -0
  63. package/core.k +197 -0
  64. package/export.mjs +22 -32
  65. package/hash.mjs +29 -31
  66. package/ieee.klib +0 -0
  67. package/index.mjs +41 -15
  68. package/k-vscode/.vscode/launch.json +14 -0
  69. package/k-vscode/README.md +65 -0
  70. package/k-vscode/language-configuration.json +42 -0
  71. package/k-vscode/package-lock.json +4176 -0
  72. package/k-vscode/package.json +57 -0
  73. package/k-vscode/snippets/k.json +92 -0
  74. package/k-vscode/syntaxes/k.tmLanguage.json +243 -0
  75. package/k.mjs +56 -54
  76. package/object.mjs +517 -0
  77. package/objects/README.md +38 -0
  78. package/objects/compile-lib.mjs +42 -0
  79. package/objects/compile.mjs +42 -0
  80. package/objects/decompile.mjs +32 -0
  81. package/package.json +13 -6
  82. package/parser.jison +27 -46
  83. package/parser.mjs +68 -100
  84. package/pretty.mjs +21 -40
  85. package/repl2.mjs +662 -0
  86. package/run.mjs +264 -231
  87. package/symbol-table.mjs +3 -17
  88. package/test-fingerprint.mjs +7 -7
  89. package/test-hash-fuzz.mjs +107 -0
  90. package/test-hash-normalization.mjs +134 -0
  91. package/test-k-object.mjs +74 -0
  92. package/test-repl2.mjs +106 -0
  93. package/test.mjs +45 -70
  94. package/tests.sh +10 -1
  95. package/type_registry/registry.mjs~ +105 -0
  96. package/type_registry/typeParser.jison~ +132 -0
  97. package/typing.mjs +129 -676
  98. package/unification.mjs +157 -0
  99. package/valueIO.mjs +54 -0
  100. package/valueParser.jison +143 -0
  101. package/valueParser.mjs +713 -0
  102. package/Code-derivation-tests/built-in.mjs +0 -19
  103. package/Code-derivation-tests/vector.mjs +0 -19
  104. package/Filters/bug.k +0 -3
  105. package/Filters/composing.k +0 -15
  106. package/Filters/filter.k +0 -9
  107. package/TODO.md +0 -53
  108. package/TYPING.md +0 -365
  109. package/k-repl.cast +0 -1913
  110. package/k.cast +0 -618
  111. package/my-objects.json +0 -6
  112. package/patterns.mjs +0 -543
  113. package/repl.mjs +0 -213
  114. package/test-filters.mjs +0 -45
  115. package/typing-test.mjs +0 -40
@@ -0,0 +1,132 @@
1
+ %{
2
+
3
+ let defs = {};
4
+ let genCount = 0;
5
+ let genNameId;
6
+
7
+ function genName() {
8
+ return `_gen_${genCount++}`;
9
+ }
10
+
11
+ function fromEscString(escString) {
12
+ const isSingleQuoted = escString.startsWith("'");
13
+ let str = escString.substring(1, escString.length - 1);
14
+ if (isSingleQuoted) {
15
+ str = str.replace(/\\'/g, "'");
16
+ } else {
17
+ str = str.replace(/\\"/g, '"');
18
+ }
19
+ str = str.replace(/\\\\/g, '\\');
20
+ str = str.replace(/\\\//g, '/');
21
+ str = str.replace(/\\b/g, '\b');
22
+ str = str.replace(/\\f/g, '\f');
23
+ str = str.replace(/\\n/g, '\n');
24
+ str = str.replace(/\\r/g, '\r');
25
+ str = str.replace(/\\t/g, '\t');
26
+ str = str.replace(/\\u([\dA-F]{4})/gi, (match, p1) => String.fromCharCode(parseInt(p1, 16)));
27
+
28
+ return str;
29
+ }
30
+
31
+ %}
32
+
33
+ %lex
34
+
35
+ %%
36
+ \s+ /* blanks */
37
+ "<" return 'LA';
38
+ ">" return 'RA';
39
+ "{" return 'LC';
40
+ "}" return 'RC';
41
+ "=" return 'EQ';
42
+ "," return 'COMMA';
43
+ ";" return 'SC';
44
+ "@" return 'AT';
45
+ "$" return 'DOLLAR';
46
+ \"([^"\\]|\\(.|\n))*\"|\'([^'\\]|\\(.|\n))*\' return 'STRING';
47
+ [a-zA-Z0-9_+-][a-zA-Z0-9_?!+-]* return 'NAME';
48
+ <<EOF>> return 'EOF';
49
+ . return 'INVALID';
50
+
51
+ /lex
52
+
53
+ %token NAME STRING
54
+ %token LA RA LC RC EQ COMMA SC AT DOLLAR
55
+ %token EOF
56
+
57
+ %start expressions
58
+
59
+ %%
60
+
61
+ expressions
62
+ : initialize_defs definitions EOF
63
+ { return defs; }
64
+ ;
65
+
66
+ initialize_defs
67
+ : /* empty */
68
+ { defs = {}; genCount = 0; }
69
+ ;
70
+
71
+ definitions
72
+ : definition
73
+ | definitions definition
74
+ ;
75
+
76
+ definition
77
+ : DOLLAR name EQ LA field_list RA SC
78
+ { defs[$2] = { code: 'union', union: $5 }; }
79
+ | DOLLAR name EQ LC field_list RC SC
80
+ { defs[$2] = { code: 'product', product: $5 }; }
81
+ ;
82
+
83
+ type_expr
84
+ : LA field_list RA
85
+ {
86
+ genNameId = genName();
87
+ defs[genNameId] = { code: 'union', union: $2 };
88
+ $$ = genNameId;
89
+ }
90
+ | LC field_list RC
91
+ {
92
+ genNameId = genName();
93
+ defs[genNameId] = { code: 'product', product: $2 };
94
+ $$ = genNameId;
95
+ }
96
+ | ref
97
+ { $$ = $1; }
98
+ ;
99
+
100
+ ref
101
+ : name
102
+ { $$ = $1; }
103
+ | AT name
104
+ { $$ = '@' + $2; }
105
+ ;
106
+
107
+ field_list
108
+ : /* empty */
109
+ { $$ = {}; }
110
+ | field
111
+ { $$ = {}; $$[$1.label] = $1.type; }
112
+ | field_list COMMA field
113
+ { $$ = $1; $$[$3.label] = $3.type; }
114
+ ;
115
+
116
+ field
117
+ : type_expr label
118
+ { $$ = { type: $1, label: $2 }; }
119
+ ;
120
+
121
+ label
122
+ : name
123
+ { $$ = $1; }
124
+ | str
125
+ { $$ = $1; }
126
+ ;
127
+
128
+ name: NAME { $$ = yytext; };
129
+ str: STRING { $$ = fromEscString(yytext); };
130
+
131
+ %%
132
+