@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.
- package/.codex +0 -0
- 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/a.html +398 -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-combined.html +3798 -0
- package/DOCS/book-combined.md +3745 -0
- package/DOCS/book-combined.pdf +0 -0
- package/DOCS/book-combined.tex +5682 -0
- package/DOCS/book.html +65 -0
- package/DOCS/book.md +54 -0
- package/DOCS/book.pdf +0 -0
- package/DOCS/book.tex +150 -0
- package/NAT.k~ +452 -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.html +471 -0
- package/codecs/BINARY_FORMAT.md +53 -0
- package/codecs/POLYMORPHIC_BINARY_FORMAT.html +355 -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/ieee.klib +0 -0
- 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-lock.json +4176 -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 +13 -6
- package/parser.jison +27 -46
- package/parser.mjs +68 -100
- package/pretty.mjs +21 -40
- package/repl2.mjs +662 -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 +106 -0
- package/test.mjs +45 -70
- package/tests.sh +10 -1
- package/type_registry/registry.mjs~ +105 -0
- package/type_registry/typeParser.jison~ +132 -0
- 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
|
@@ -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
|
+
|