@fraczak/k 6.10.6 → 7.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/CHANGELOG.md +41 -0
- package/CLAUDE.md +1 -1
- package/DOCS/BIG_PICTURE.md +156 -172
- package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
- package/DOCS/CODEC_ARCHITECTURE.md +2 -2
- package/DOCS/DICTIONARY.md +243 -250
- package/DOCS/DIVERGENCE_DETECTION.md +0 -1
- package/DOCS/FILE_FORMATS.md +5 -5
- package/DOCS/KIR_SPECIALIZATION_DESIGN.md +1 -1
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +12 -12
- package/DOCS/PATTERNS.md +17 -17
- package/DOCS/PATTERNS_AND_TYPED_VALUES.md +1 -1
- package/DOCS/REPL.md +9 -19
- package/DOCS/TYPE_DERIVATION.md +2 -8
- package/DOCS/WEB_REPL_REQUIREMENTS.md +8 -8
- package/DOCS/book/01-introduction.md +8 -11
- package/DOCS/book/02-syntax-and-values.md +19 -20
- package/DOCS/book/03-types-as-finite-automata.md +42 -43
- package/DOCS/book/04-partial-functions-and-composition.md +2 -3
- package/DOCS/book/05-typing-filters-and-normalization.md +44 -46
- package/DOCS/book/06-values-in-memory.md +10 -10
- package/DOCS/book/08-operational-semantics-and-execution.md +21 -26
- package/DOCS/book/09-compiler-architecture.md +11 -11
- package/DOCS/book/10-from-ast-to-intermediate-representation.md +6 -7
- package/DOCS/book/14-canonical-serialization.md +2 -2
- package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +17 -17
- package/DOCS/book.md +5 -5
- package/Examples/arithmetics.k +49 -153
- package/Examples/bnat.k +13 -13
- package/Examples/byte.k +2 -50
- package/Examples/ieee.k +408 -423
- package/Examples/karatsuba-mult.k +30 -34
- package/Examples/nat.k +5 -6
- package/README.md +54 -49
- package/TODO.md +13 -18
- package/browser/vfs-data.mjs +11 -11
- package/codecs/BINARY_FORMAT.md +4 -4
- package/codecs/POLYMORPHIC_BINARY_FORMAT.md +4 -4
- package/codecs/README.md +6 -6
- package/codecs/ieee.mjs +15 -11
- package/codecs/int.mjs +9 -5
- package/codecs/string-codec.mjs +46 -47
- package/core.k +123 -95
- package/object.mjs +0 -7
- package/package.json +5 -2
- package/parser.jison +2 -41
- package/parser.mjs +55 -95
- package/pretty.mjs +11 -4
- package/repl.mjs +8 -63
- package/scripts/build-repl-html.mjs +8 -38
- package/tests/code-derivation/blowup.mjs +2 -4
- package/tests/code-derivation/bnat.mjs +2 -3
- package/tests/code-derivation/dot.mjs +5 -11
- package/tests/code-derivation/nat.mjs +2 -2
- package/tests/code-derivation/not-not.mjs +6 -6
- package/tests/code-derivation/pattern-envelope.mjs +4 -6
- package/tests/code-derivation/product.mjs +3 -6
- package/tests/code-derivation/rlz.mjs +4 -5
- package/tests/test-codecs.mjs +1 -1
- package/tests/test-fingerprint.mjs +36 -41
- package/tests/test-hash-normalization.mjs +4 -6
- package/tests/test-ieee-arithmetic.mjs +6 -7
- package/tests/test-k-object.mjs +11 -15
- package/tests/test-kir.mjs +0 -1
- package/tests/test-kvm-polymorphic.mjs +1 -2
- package/tests/test-kvm.mjs +8 -11
- package/tests/test-repl-html.mjs +5 -2
- package/tests/test-repl.mjs +38 -53
- package/tests/test.mjs +2 -3
package/parser.mjs
CHANGED
|
@@ -116,12 +116,12 @@ function fromEscString(escString) {
|
|
|
116
116
|
|
|
117
117
|
|
|
118
118
|
var parser = (function(){
|
|
119
|
-
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[6,8,10,12,14,26,28,30,38
|
|
119
|
+
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[6,8,10,12,14,26,28,30,38],$V1=[1,9],$V2=[1,20],$V3=[1,19],$V4=[1,18],$V5=[1,21],$V6=[1,22],$V7=[1,23],$V8=[1,24],$V9=[1,25],$Va=[2,47],$Vb=[4,6,8,10,12,14,16,18,20,26,28,30,32,34,38,45],$Vc=[1,37],$Vd=[1,44],$Ve=[4,6],$Vf=[1,59],$Vg=[1,61],$Vh=[18,32],$Vi=[4,6,8,10,12,14,26,28,30,38],$Vj=[1,65],$Vk=[1,68],$Vl=[16,32],$Vm=[4,6,8,10,12,14,16,18,20,22,26,28,30,32,34,38,45],$Vn=[2,30],$Vo=[1,73],$Vp=[2,31],$Vq=[2,59],$Vr=[16,18,32];
|
|
120
120
|
var parser = {trace: function trace () { },
|
|
121
121
|
yy: {},
|
|
122
|
-
symbols_: {"error":2,"str":3,"STRING":4,"name":5,"NAME":6,"at":7,"AT":8,"la":9,"LA":10,"lc":11,"LC":12,"lp":13,"LP":14,"ra":15,"RA":16,"rc":17,"RC":18,"rp":19,"RP":20,"eq":21,"EQ":22,"dots":23,"DOTS":24,"dot":25,"DOT":26,"div":27,"DIV":28,"vid":29,"VID":30,"comma":31,"COMMA":32,"sc":33,"SC":34,"col":35,"COL":36,"
|
|
123
|
-
terminals_: {2:"error",4:"STRING",6:"NAME",8:"AT",10:"LA",12:"LC",14:"LP",16:"RA",18:"RC",20:"RP",22:"EQ",24:"DOTS",26:"DOT",28:"DIV",30:"VID",32:"COMMA",34:"SC",36:"COL",38:"
|
|
124
|
-
productions_: [0,[3,1],[5,1],[7,1],[9,1],[11,1],[13,1],[15,1],[17,1],[19,1],[21,1],[23,1],[25,1],[27,1],[29,1],[31,1],[33,1],[35,1],[37,1],[39,1],[41,
|
|
122
|
+
symbols_: {"error":2,"str":3,"STRING":4,"name":5,"NAME":6,"at":7,"AT":8,"la":9,"LA":10,"lc":11,"LC":12,"lp":13,"LP":14,"ra":15,"RA":16,"rc":17,"RC":18,"rp":19,"RP":20,"eq":21,"EQ":22,"dots":23,"DOTS":24,"dot":25,"DOT":26,"div":27,"DIV":28,"vid":29,"VID":30,"comma":31,"COMMA":32,"sc":33,"SC":34,"col":35,"COL":36,"qmark":37,"QMARK":38,"incremental":39,"INCREMENTAL":40,"input_with_eof":41,"initialize_symbol_table":42,"defs":43,"comp":44,"EOF":45,"filter_":46,"labelled_filters":47,"filter":48,"non_empty_labelled_filters":49,"filter_label":50,"exp":51,"labelled":52,"list":53,"non_empty_labelled":54,"comp_label":55,"non_empty_list":56,"$accept":0,"$end":1},
|
|
123
|
+
terminals_: {2:"error",4:"STRING",6:"NAME",8:"AT",10:"LA",12:"LC",14:"LP",16:"RA",18:"RC",20:"RP",22:"EQ",24:"DOTS",26:"DOT",28:"DIV",30:"VID",32:"COMMA",34:"SC",36:"COL",38:"QMARK",40:"INCREMENTAL",45:"EOF"},
|
|
124
|
+
productions_: [0,[3,1],[5,1],[7,1],[9,1],[11,1],[13,1],[15,1],[17,1],[19,1],[21,1],[23,1],[25,1],[27,1],[29,1],[31,1],[33,1],[35,1],[37,1],[39,1],[41,4],[42,0],[42,1],[43,0],[43,5],[46,3],[46,3],[46,3],[48,1],[48,3],[48,1],[47,0],[47,1],[49,1],[49,3],[50,1],[50,2],[50,2],[50,3],[50,3],[44,1],[44,2],[51,3],[51,3],[51,2],[51,2],[51,3],[51,1],[51,2],[51,2],[51,2],[51,2],[51,2],[51,2],[51,2],[52,0],[52,1],[54,1],[54,3],[55,2],[55,2],[55,3],[55,3],[53,0],[53,1],[56,1],[56,3]],
|
|
125
125
|
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
|
|
126
126
|
/* this == yyval */
|
|
127
127
|
|
|
@@ -130,10 +130,10 @@ switch (yystate) {
|
|
|
130
130
|
case 1:
|
|
131
131
|
this.$ = getToken(yytext,yy,_$); this.$.value = fromEscString(this.$.value);
|
|
132
132
|
break;
|
|
133
|
-
case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19:
|
|
133
|
+
case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19:
|
|
134
134
|
this.$ = getToken(yytext,yy,_$);
|
|
135
135
|
break;
|
|
136
|
-
case
|
|
136
|
+
case 20:
|
|
137
137
|
|
|
138
138
|
const result = {defs: {rels: s.rels, codes: s.codes}, exp: $$[$0-1]};
|
|
139
139
|
// console.log(JSON.stringify(result, "", 2));
|
|
@@ -141,78 +141,37 @@ case 21:
|
|
|
141
141
|
return result;
|
|
142
142
|
|
|
143
143
|
break;
|
|
144
|
-
case
|
|
144
|
+
case 21:
|
|
145
145
|
s = new SymbolTable();
|
|
146
146
|
break;
|
|
147
|
-
case
|
|
147
|
+
case 22: case 23:
|
|
148
148
|
|
|
149
149
|
break;
|
|
150
|
-
case
|
|
150
|
+
case 24:
|
|
151
151
|
s.add_rel($$[$0-3].value,$$[$0-1]);
|
|
152
152
|
break;
|
|
153
|
+
case 25:
|
|
154
|
+
this.$ = { type: null, open: true, fields: {}, start: $$[$0-2].start, end: $$[$0].end};
|
|
155
|
+
break;
|
|
153
156
|
case 26:
|
|
154
|
-
|
|
157
|
+
this.$ = { type: "union", open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
|
|
155
158
|
break;
|
|
156
159
|
case 27:
|
|
157
|
-
this.$ = {
|
|
160
|
+
this.$ = { type: "product", open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
|
|
158
161
|
break;
|
|
159
|
-
case 28: case
|
|
162
|
+
case 28: case 40: case 64:
|
|
160
163
|
this.$ = $$[$0];
|
|
161
164
|
break;
|
|
162
165
|
case 29:
|
|
163
|
-
this.$ = { code: "product", product: $$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
|
|
164
|
-
break;
|
|
165
|
-
case 30:
|
|
166
|
-
this.$ = { code: "union", union: $$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
|
|
167
|
-
break;
|
|
168
|
-
case 31:
|
|
169
|
-
this.$ = { code: "ref", ref: "@" + $$[$0].value, start: $$[$0-1].start, end: $$[$0].end};
|
|
170
|
-
break;
|
|
171
|
-
case 32:
|
|
172
|
-
this.$ = {};
|
|
173
|
-
break;
|
|
174
|
-
case 33:
|
|
175
|
-
this.$ = $$[$0].reduce((r, lc) => {
|
|
176
|
-
if (r[lc.label])
|
|
177
|
-
anError(this._$,`Duplicate label '${lc.label}'.`);
|
|
178
|
-
r[lc.label] = s.as_ref(lc.code);
|
|
179
|
-
return r }
|
|
180
|
-
, {});
|
|
181
|
-
break;
|
|
182
|
-
case 34: case 49: case 82:
|
|
183
|
-
this.$ = [$$[$0]];
|
|
184
|
-
break;
|
|
185
|
-
case 35: case 50: case 83:
|
|
186
|
-
this.$ = [].concat($$[$0-2],$$[$0]);
|
|
187
|
-
break;
|
|
188
|
-
case 36: case 37:
|
|
189
|
-
this.$ = {label: $$[$0].value, code: $$[$0-1]};
|
|
190
|
-
break;
|
|
191
|
-
case 38: case 39:
|
|
192
|
-
this.$ = {label: $$[$0-2].value, code: $$[$0]};
|
|
193
|
-
break;
|
|
194
|
-
case 40:
|
|
195
|
-
this.$ = { type: "code", code: s.as_ref($$[$0]), start: $$[$0-1].start, end: $$[$0].end};
|
|
196
|
-
break;
|
|
197
|
-
case 41:
|
|
198
|
-
this.$ = { type: null, open: true, fields: {}, start: $$[$0-2].start, end: $$[$0].end};
|
|
199
|
-
break;
|
|
200
|
-
case 42:
|
|
201
|
-
this.$ = { type: "union", open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
|
|
202
|
-
break;
|
|
203
|
-
case 43:
|
|
204
|
-
this.$ = { type: "product", open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
|
|
205
|
-
break;
|
|
206
|
-
case 45:
|
|
207
166
|
this.$ = { name: $$[$0].value, ...$$[$0-2], start: $$[$0-2].start, end: $$[$0].end };
|
|
208
167
|
break;
|
|
209
|
-
case
|
|
168
|
+
case 30:
|
|
210
169
|
this.$ = { type: 'name', name: $$[$0].value, open: true, start: $$[$0].start, end: $$[$0].end};
|
|
211
170
|
break;
|
|
212
|
-
case
|
|
171
|
+
case 31:
|
|
213
172
|
this.$ = { fields: {}};
|
|
214
173
|
break;
|
|
215
|
-
case
|
|
174
|
+
case 32:
|
|
216
175
|
this.$ = $$[$0].reduce((r, lc) => {
|
|
217
176
|
if (lc.dots) {
|
|
218
177
|
r.open = true;
|
|
@@ -224,55 +183,58 @@ case 48:
|
|
|
224
183
|
return r }
|
|
225
184
|
, { fields: {} });
|
|
226
185
|
break;
|
|
227
|
-
case
|
|
186
|
+
case 33: case 65:
|
|
187
|
+
this.$ = [$$[$0]];
|
|
188
|
+
break;
|
|
189
|
+
case 34: case 66:
|
|
190
|
+
this.$ = [].concat($$[$0-2],$$[$0]);
|
|
191
|
+
break;
|
|
192
|
+
case 35:
|
|
228
193
|
this.$ = {dots: true };
|
|
229
194
|
break;
|
|
230
|
-
case
|
|
195
|
+
case 36: case 37:
|
|
231
196
|
this.$ = {label: $$[$0].value, filter: $$[$0-1]};
|
|
232
197
|
break;
|
|
233
|
-
case
|
|
198
|
+
case 38: case 39:
|
|
234
199
|
this.$ = {label: $$[$0-2].value, filter: $$[$0]};
|
|
235
200
|
break;
|
|
236
|
-
case
|
|
201
|
+
case 41:
|
|
237
202
|
this.$ = {...comp($$[$0-1], $$[$0]), start: $$[$0-1].start, end:$$[$0].end};
|
|
238
203
|
break;
|
|
239
|
-
case
|
|
204
|
+
case 42:
|
|
240
205
|
this.$ = {...$$[$0-1], start: $$[$0-2].start, end: $$[$0].end};
|
|
241
206
|
break;
|
|
242
|
-
case
|
|
207
|
+
case 43:
|
|
243
208
|
this.$ = {...union($$[$0-1]), start: $$[$0-2].start, end: $$[$0].end};
|
|
244
209
|
break;
|
|
245
|
-
case
|
|
210
|
+
case 44:
|
|
246
211
|
this.$ = {op: "ref", ref: "@" + $$[$0].value, start: $$[$0-1].start, end: $$[$0].end};
|
|
247
212
|
break;
|
|
248
|
-
case
|
|
213
|
+
case 45:
|
|
249
214
|
this.$ = {...identity, start: $$[$0-1].start, end: $$[$0].end};
|
|
250
215
|
break;
|
|
251
|
-
case
|
|
216
|
+
case 46:
|
|
252
217
|
this.$ = {...$$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
|
|
253
218
|
break;
|
|
254
|
-
case
|
|
219
|
+
case 47:
|
|
255
220
|
this.$ = {op: "ref", ref: $$[$0].value, start: $$[$0].start, end: $$[$0].end};
|
|
256
221
|
break;
|
|
257
|
-
case
|
|
222
|
+
case 48: case 49:
|
|
258
223
|
this.$ = {op: "dot", dot: $$[$0].value, start: $$[$0-1].start, end: $$[$0].end };
|
|
259
224
|
break;
|
|
260
|
-
case
|
|
225
|
+
case 50: case 51:
|
|
261
226
|
this.$ = {op: "div", div: $$[$0].value, start: $$[$0-1].start, end: $$[$0].end };
|
|
262
227
|
break;
|
|
263
|
-
case
|
|
228
|
+
case 52: case 53:
|
|
264
229
|
this.$ = {op: "vid", vid: $$[$0].value, start: $$[$0-1].start, end: $$[$0].end };
|
|
265
230
|
break;
|
|
266
|
-
case
|
|
267
|
-
this.$ = {op: "code", code: s.as_ref($$[$0]), start: $$[$0-1].start, end: $$[$0].end};
|
|
268
|
-
break;
|
|
269
|
-
case 71:
|
|
231
|
+
case 54:
|
|
270
232
|
this.$ = {op: "filter", filter: $$[$0], start: $$[$0-1].start, end:$$[$0].end};
|
|
271
233
|
break;
|
|
272
|
-
case
|
|
234
|
+
case 55:
|
|
273
235
|
this.$ = {op: "product", product: []};
|
|
274
236
|
break;
|
|
275
|
-
case
|
|
237
|
+
case 56:
|
|
276
238
|
$$[$0].product.reduce( (labels, {label}) =>
|
|
277
239
|
{ if (labels[label])
|
|
278
240
|
anError(this._$,`Duplicate label '${label}'.`)
|
|
@@ -280,25 +242,25 @@ case 73:
|
|
|
280
242
|
return labels; }, {});
|
|
281
243
|
this.$ = $$[$0];
|
|
282
244
|
break;
|
|
283
|
-
case
|
|
245
|
+
case 57:
|
|
284
246
|
this.$ = {op: "product", product: [$$[$0]]};
|
|
285
247
|
break;
|
|
286
|
-
case
|
|
248
|
+
case 58:
|
|
287
249
|
$$[$0-2].product = [].concat($$[$0-2].product,$$[$0]); this.$ = $$[$0-2];
|
|
288
250
|
break;
|
|
289
|
-
case
|
|
251
|
+
case 59: case 60:
|
|
290
252
|
this.$ = {label: $$[$0].value, exp: $$[$0-1]};
|
|
291
253
|
break;
|
|
292
|
-
case
|
|
254
|
+
case 61: case 62:
|
|
293
255
|
this.$ = {label: $$[$0-2].value, exp: $$[$0]};
|
|
294
256
|
break;
|
|
295
|
-
case
|
|
257
|
+
case 63:
|
|
296
258
|
this.$ = [];
|
|
297
259
|
break;
|
|
298
260
|
}
|
|
299
261
|
},
|
|
300
|
-
table: [o($V0,[2,
|
|
301
|
-
defaultActions: {
|
|
262
|
+
table: [o($V0,[2,21],{41:1,42:2,39:3,40:[1,4]}),{1:[3]},o($V0,[2,23],{43:5}),o($V0,[2,22]),o($V0,[2,19]),{5:7,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:6,51:8},{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,45:[1,26],51:27},o([6,8,10,12,14,26,28,30,38,45],$Va,{21:29,22:[1,30]}),o($Vb,[2,40]),o([4,6,8,10,12,14,16,18,20,22,26,28,30,32,34,36,38,45],[2,2]),{3:36,4:$Vc,5:35,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,18:[2,55],25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:34,51:8,52:31,54:32,55:33},{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,16:[2,63],25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:40,51:8,53:38,56:39},{5:41,6:$V1},{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,19:42,20:$Vd,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:43,51:8},{3:46,4:$Vc,5:45,6:$V1},{3:48,4:$Vc,5:47,6:$V1},{3:50,4:$Vc,5:49,6:$V1},{5:53,6:$V1,9:55,10:$V3,11:56,12:$V4,13:54,14:$V5,46:52,48:51},o([4,6,8,10,12,14,18,24,26,28,30,38],[2,5]),o([4,6,8,10,12,14,16,24,26,28,30,38],[2,4]),{6:[2,3]},o([6,8,10,12,14,20,24,26,28,30,38],[2,6]),o($Ve,[2,12]),o($Ve,[2,13]),o($Ve,[2,14]),o([6,10,12,14],[2,18]),{1:[2,20]},o($Vb,[2,41]),o([6,8,10,12,14,16,18,20,26,28,30,32,34,38,45],$Va),{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:57,51:8},o($V0,[2,10]),{17:58,18:$Vf},{18:[2,56],31:60,32:$Vg},o($Vh,[2,57]),{3:63,4:$Vc,5:62,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,51:27},o($Vi,$Va,{35:64,36:$Vj}),{35:66,36:$Vj},o([4,6,8,10,12,14,16,18,20,26,28,30,32,34,36,38,45],[2,1]),{15:67,16:$Vk},{16:[2,64],31:69,32:$Vg},o($Vl,[2,65],{11:10,9:11,7:12,13:13,25:14,27:15,29:16,37:17,51:27,5:28,6:$V1,8:$V2,10:$V3,12:$V4,14:$V5,26:$V6,28:$V7,30:$V8,38:$V9}),o($Vb,[2,44]),o($Vb,[2,45]),{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,19:70,20:$Vd,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,51:27},o($Vm,[2,9]),o($Vb,[2,48]),o($Vb,[2,49]),o($Vb,[2,50]),o($Vb,[2,51]),o($Vb,[2,52]),o($Vb,[2,53]),o($Vb,[2,54]),o($Vb,[2,28],{22:[1,71]}),o($Vb,$Vn),{23:72,24:$Vo},{3:80,4:$Vc,5:79,6:$V1,9:55,10:$V3,11:56,12:$V4,13:54,14:$V5,16:$Vp,23:77,24:$Vo,46:52,47:74,48:78,49:75,50:76},{3:80,4:$Vc,5:79,6:$V1,9:55,10:$V3,11:56,12:$V4,13:54,14:$V5,18:$Vp,23:77,24:$Vo,46:52,47:81,48:78,49:75,50:76},{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,33:82,34:[1,83],37:17,38:$V9,51:27},o($Vb,[2,42]),o($Vm,[2,8]),{3:36,4:$Vc,5:35,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:34,51:8,55:84},o([4,6,8,10,12,14,24,26,28,30,38],[2,15]),o($Vi,$Va,{18:$Vq,32:$Vq}),o($Vh,[2,60]),{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:85,51:8},o($V0,[2,17]),{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:86,51:8},o($Vb,[2,43]),o($Vm,[2,7]),{5:28,6:$V1,7:12,8:$V2,9:11,10:$V3,11:10,12:$V4,13:13,14:$V5,25:14,26:$V6,27:15,28:$V7,29:16,30:$V8,37:17,38:$V9,44:87,51:8},o($Vb,[2,46]),{5:88,6:$V1},{19:89,20:$Vd},o([16,18,20,32],[2,11]),{15:90,16:$Vk},o([16,18],[2,32],{31:91,32:$Vg}),o($Vr,[2,33]),o($Vr,[2,35]),{3:93,4:$Vc,5:92,6:$V1},o($Ve,$Vn,{35:94,36:$Vj}),{35:95,36:$Vj},{17:96,18:$Vf},o($V0,[2,24]),o($V0,[2,16]),o($Vh,[2,58]),o($Vh,[2,61],{11:10,9:11,7:12,13:13,25:14,27:15,29:16,37:17,51:27,5:28,6:$V1,8:$V2,10:$V3,12:$V4,14:$V5,26:$V6,28:$V7,30:$V8,38:$V9}),o($Vh,[2,62],{11:10,9:11,7:12,13:13,25:14,27:15,29:16,37:17,51:27,5:28,6:$V1,8:$V2,10:$V3,12:$V4,14:$V5,26:$V6,28:$V7,30:$V8,38:$V9}),o($Vl,[2,66],{11:10,9:11,7:12,13:13,25:14,27:15,29:16,37:17,51:27,5:28,6:$V1,8:$V2,10:$V3,12:$V4,14:$V5,26:$V6,28:$V7,30:$V8,38:$V9}),o($Vb,[2,29]),o($Vm,[2,25]),o($Vm,[2,26]),{3:80,4:$Vc,5:79,6:$V1,9:55,10:$V3,11:56,12:$V4,13:54,14:$V5,23:77,24:$Vo,46:52,48:78,50:97},o($Vr,[2,36]),o($Vr,[2,37]),{5:53,6:$V1,9:55,10:$V3,11:56,12:$V4,13:54,14:$V5,46:52,48:98},{5:53,6:$V1,9:55,10:$V3,11:56,12:$V4,13:54,14:$V5,46:52,48:99},o($Vm,[2,27]),o($Vr,[2,34]),o($Vr,[2,38]),o($Vr,[2,39])],
|
|
263
|
+
defaultActions: {20:[2,3],26:[2,20]},
|
|
302
264
|
parseError: function parseError (str, hash) {
|
|
303
265
|
if (hash.recoverable) {
|
|
304
266
|
this.trace(str);
|
|
@@ -806,24 +768,22 @@ case 15:return 34;
|
|
|
806
768
|
break;
|
|
807
769
|
case 16:return 36;
|
|
808
770
|
break;
|
|
809
|
-
case 17:return 38;
|
|
810
|
-
break;
|
|
811
|
-
case 18:return 40;
|
|
771
|
+
case 17:return 38;
|
|
812
772
|
break;
|
|
813
|
-
case
|
|
773
|
+
case 18:return 8;
|
|
814
774
|
break;
|
|
815
|
-
case
|
|
775
|
+
case 19:return 4;
|
|
816
776
|
break;
|
|
817
|
-
case
|
|
777
|
+
case 20:return 6;
|
|
818
778
|
break;
|
|
819
|
-
case
|
|
779
|
+
case 21:return 40;
|
|
820
780
|
break;
|
|
821
|
-
case
|
|
781
|
+
case 22:return 45;
|
|
822
782
|
break;
|
|
823
783
|
}
|
|
824
784
|
},
|
|
825
|
-
rules: [/^(?:[/][*]([^*]*[*]+[^*/])*[^*]*[*]+[/])/,/^(?:(\/\/|#|%|--|\\\\)[^\n]*)/,/^(?:\s+)/,/^(?:<)/,/^(?:\{)/,/^(?:\()/,/^(?:>)/,/^(?:\})/,/^(?:\))/,/^(?:=)/,/^(?:\.\.\.)/,/^(?:\.)/,/^(?:\/)/,/^(?:(\\|\|))/,/^(?:,)/,/^(?:;)/,/^(?::)/,/^(
|
|
826
|
-
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
|
|
785
|
+
rules: [/^(?:[/][*]([^*]*[*]+[^*/])*[^*]*[*]+[/])/,/^(?:(\/\/|#|%|--|\\\\)[^\n]*)/,/^(?:\s+)/,/^(?:<)/,/^(?:\{)/,/^(?:\()/,/^(?:>)/,/^(?:\})/,/^(?:\))/,/^(?:=)/,/^(?:\.\.\.)/,/^(?:\.)/,/^(?:\/)/,/^(?:(\\|\|))/,/^(?:,)/,/^(?:;)/,/^(?::)/,/^(?:\?)/,/^(?:@)/,/^(?:"([^"\\]|\\(.|\n))*"|'([^'\\]|\\(.|\n))*')/,/^(?:[a-zA-Z0-9_+-][a-zA-Z0-9_?!+-]*)/,/^(?:~)/,/^(?:$)/],
|
|
786
|
+
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22],"inclusive":true}}
|
|
827
787
|
});
|
|
828
788
|
return lexer;
|
|
829
789
|
})();
|
package/pretty.mjs
CHANGED
|
@@ -131,14 +131,14 @@ function patterns2filters(typePatternGraph, ...patternIds) {
|
|
|
131
131
|
const buildFilter = (path, patternId, i) => {
|
|
132
132
|
let named_filter = {};
|
|
133
133
|
const pattern = newTypePatternGraph.get_pattern(patternId);
|
|
134
|
-
if (variables[patternId]
|
|
134
|
+
if (variables[patternId]) {
|
|
135
135
|
if (filterVars[patternId])
|
|
136
136
|
return { type: 'name', name: filterVars[patternId] };
|
|
137
137
|
filterVars[patternId] = `X${Object.keys(filterVars).length}`;
|
|
138
138
|
named_filter = { name: filterVars[patternId] };
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
const edges = newTypePatternGraph.edges[patternId];
|
|
141
|
+
const edges = newTypePatternGraph.edges[patternId] || {};
|
|
142
142
|
const fields = () =>
|
|
143
143
|
Object.keys(edges).sort().reduce( (fields, key) =>{
|
|
144
144
|
fields[key] = buildFilter([...path, key], Object.values(edges[key])[0], i);
|
|
@@ -146,8 +146,15 @@ function patterns2filters(typePatternGraph, ...patternIds) {
|
|
|
146
146
|
}, {});
|
|
147
147
|
|
|
148
148
|
switch (pattern.pattern) {
|
|
149
|
-
case 'type':
|
|
150
|
-
|
|
149
|
+
case 'type': {
|
|
150
|
+
const code = newTypePatternGraph.findCode(pattern.type);
|
|
151
|
+
if (code?.code === "product") {
|
|
152
|
+
return { type: 'product', fields: fields(), ...named_filter };
|
|
153
|
+
} else if (code?.code === "union") {
|
|
154
|
+
return { type: 'union', fields: fields(), ...named_filter };
|
|
155
|
+
}
|
|
156
|
+
return { type: "code", code: pattern.type, ...named_filter };
|
|
157
|
+
}
|
|
151
158
|
case '(...)':
|
|
152
159
|
return { type: null, open: true, fields: fields(), ...named_filter };
|
|
153
160
|
case '{...}':
|
package/repl.mjs
CHANGED
|
@@ -48,8 +48,8 @@ import {
|
|
|
48
48
|
|
|
49
49
|
const NAME_RE = /^[a-zA-Z0-9_+-][a-zA-Z0-9_?!+-]*$/;
|
|
50
50
|
const COMMAND_NAMES = [
|
|
51
|
-
"help", "
|
|
52
|
-
"
|
|
51
|
+
"help", "rel",
|
|
52
|
+
"codecs", "rels", "codec", "input", "reset", "klib", "ko", "load",
|
|
53
53
|
"engine", "wasm", "js",
|
|
54
54
|
"quit", "exit"
|
|
55
55
|
];
|
|
@@ -115,14 +115,11 @@ function restoreCodes(state) {
|
|
|
115
115
|
function aliasLine(kind, name, hash) {
|
|
116
116
|
if (!NAME_RE.test(name)) return null;
|
|
117
117
|
const body = hash.startsWith("@") ? hash.slice(1) : hash;
|
|
118
|
-
return
|
|
118
|
+
return `${name} = @${body};`;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
function aliasPreamble(state, omitName = null) {
|
|
122
122
|
const lines = [];
|
|
123
|
-
for (const [name, hash] of Object.entries(state.typeAliases).sort()) {
|
|
124
|
-
if (name !== omitName) lines.push(aliasLine("code", name, hash));
|
|
125
|
-
}
|
|
126
123
|
for (const [name, hash] of Object.entries(state.relAliases).sort()) {
|
|
127
124
|
if (name !== omitName) lines.push(aliasLine("rel", name, hash));
|
|
128
125
|
}
|
|
@@ -457,13 +454,6 @@ function canonicalNames(state) {
|
|
|
457
454
|
])].filter((name) => name.startsWith("@")).sort();
|
|
458
455
|
}
|
|
459
456
|
|
|
460
|
-
function canonicalCodeNames(state) {
|
|
461
|
-
return [...new Set([
|
|
462
|
-
...Object.keys(state.codes),
|
|
463
|
-
...Object.values(state.typeAliases)
|
|
464
|
-
])].filter((name) => name.startsWith("@")).sort();
|
|
465
|
-
}
|
|
466
|
-
|
|
467
457
|
function aliasNames(state) {
|
|
468
458
|
return [...new Set([
|
|
469
459
|
...Object.keys(state.typeAliases),
|
|
@@ -513,42 +503,16 @@ function completeCanonical(line, state) {
|
|
|
513
503
|
return [matches, line];
|
|
514
504
|
}
|
|
515
505
|
|
|
516
|
-
function
|
|
517
|
-
const match = line.match(/^(.*?)(
|
|
506
|
+
function completeIdentifier(line, state) {
|
|
507
|
+
const match = line.match(/^(.*?)([A-Za-z0-9_+-][A-Za-z0-9_?!+-]*)$/);
|
|
518
508
|
if (!match) return [[], line];
|
|
519
509
|
const [, prefix, partial] = match;
|
|
520
|
-
const matches =
|
|
510
|
+
const matches = aliasNames(state)
|
|
521
511
|
.filter((name) => name.startsWith(partial))
|
|
522
512
|
.map((name) => `${prefix}${name}`);
|
|
523
513
|
return [matches, line];
|
|
524
514
|
}
|
|
525
515
|
|
|
526
|
-
function completeIdentifier(line, state) {
|
|
527
|
-
const match = line.match(/^(.*?)(\$?[A-Za-z0-9_+-][A-Za-z0-9_?!+-]*)$/);
|
|
528
|
-
if (!match) return [[], line];
|
|
529
|
-
const [, prefix, partial] = match;
|
|
530
|
-
const isTypeToken = partial.startsWith("$");
|
|
531
|
-
const barePartial = isTypeToken ? partial.slice(1) : partial;
|
|
532
|
-
const names = isTypeToken ? Object.keys(state.typeAliases).sort() : aliasNames(state);
|
|
533
|
-
const matches = names
|
|
534
|
-
.filter((name) => name.startsWith(barePartial))
|
|
535
|
-
.map((name) => `${prefix}${isTypeToken ? "$" : ""}${name}`);
|
|
536
|
-
return [matches, line];
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
function completeTypeIdentifier(line, state) {
|
|
540
|
-
const match = line.match(/^(.*?)(\$?[A-Za-z0-9_+-][A-Za-z0-9_?!+-]*)$/);
|
|
541
|
-
if (!match) return [[], line];
|
|
542
|
-
const [, prefix, partial] = match;
|
|
543
|
-
const isTypeToken = partial.startsWith("$");
|
|
544
|
-
const barePartial = isTypeToken ? partial.slice(1) : partial;
|
|
545
|
-
const matches = Object.keys(state.typeAliases)
|
|
546
|
-
.sort()
|
|
547
|
-
.filter((name) => name.startsWith(barePartial))
|
|
548
|
-
.map((name) => `${prefix}${isTypeToken ? "$" : ""}${name}`);
|
|
549
|
-
return [matches, line];
|
|
550
|
-
}
|
|
551
|
-
|
|
552
516
|
function completePath(line, tokenStart) {
|
|
553
517
|
const token = line.slice(tokenStart);
|
|
554
518
|
const quote = token[0] === "\"" || token[0] === "'" ? token[0] : "";
|
|
@@ -825,7 +789,7 @@ function completeCommandArgument(line, state) {
|
|
|
825
789
|
return completeCanonical(line, state);
|
|
826
790
|
}
|
|
827
791
|
|
|
828
|
-
if (
|
|
792
|
+
if (/[A-Za-z0-9_+-][A-Za-z0-9_?!+-]*$/.test(line)) {
|
|
829
793
|
return completeIdentifier(line, state);
|
|
830
794
|
}
|
|
831
795
|
|
|
@@ -839,7 +803,7 @@ function completeInput(line, state) {
|
|
|
839
803
|
if (/@[A-Za-z0-9_?!+-]*$/.test(line)) {
|
|
840
804
|
return completeCanonical(line, state);
|
|
841
805
|
}
|
|
842
|
-
if (
|
|
806
|
+
if (/[A-Za-z0-9_+-][A-Za-z0-9_?!+-]*$/.test(line)) {
|
|
843
807
|
return completeIdentifier(line, state);
|
|
844
808
|
}
|
|
845
809
|
return [[], line];
|
|
@@ -1255,15 +1219,6 @@ async function evaluateCommand(line, state) {
|
|
|
1255
1219
|
return [helpText()];
|
|
1256
1220
|
case "timing":
|
|
1257
1221
|
throw new Error(":timing has been removed; timing is now always enabled");
|
|
1258
|
-
case "type": {
|
|
1259
|
-
if (!arg) throw new Error(":type requires a type name");
|
|
1260
|
-
if (arg.includes("=")) {
|
|
1261
|
-
throw new Error("Type definitions use syntax: $ name = typeExpr; Use :type <name> to show a type definition");
|
|
1262
|
-
}
|
|
1263
|
-
return evaluateCommand(`:C ${arg}`, state);
|
|
1264
|
-
}
|
|
1265
|
-
case "code":
|
|
1266
|
-
return evaluateCommand(`:C ${arg}`, state);
|
|
1267
1222
|
case "def":
|
|
1268
1223
|
throw new Error("Relation definitions use syntax: name = relExpr;");
|
|
1269
1224
|
case "rel": {
|
|
@@ -1275,8 +1230,6 @@ async function evaluateCommand(line, state) {
|
|
|
1275
1230
|
if (!rel) throw new Error(`Unknown relation '${arg}'`);
|
|
1276
1231
|
return [`${arg} = ${prettyRelation(rel, displayAliases(state), state.relAliases)}; -- ${hash}`];
|
|
1277
1232
|
}
|
|
1278
|
-
case "types":
|
|
1279
|
-
return [listAliases(state.typeAliases)];
|
|
1280
1233
|
case "rels":
|
|
1281
1234
|
return [listAliases(state.relAliases)];
|
|
1282
1235
|
case "codec":
|
|
@@ -1330,12 +1283,6 @@ async function evaluateCommand(line, state) {
|
|
|
1330
1283
|
loadSourceOrKlib(state, loadPath, { loadAliases });
|
|
1331
1284
|
return [`loaded ${loadPath}`];
|
|
1332
1285
|
}
|
|
1333
|
-
case "C": {
|
|
1334
|
-
if (!arg) throw new Error(`${usagePrefix}C requires a type name`);
|
|
1335
|
-
const hash = state.typeAliases[arg] || (arg.startsWith("@") ? arg : null);
|
|
1336
|
-
if (!hash || !(hash in state.codes)) throw new Error(`Unknown type '${arg}'`);
|
|
1337
|
-
return [`$ ${arg} = ${prettyCode(displayAliases(state), codes.find, codes.find(hash))}; -- ${hash}`];
|
|
1338
|
-
}
|
|
1339
1286
|
default:
|
|
1340
1287
|
throw new Error(`Unknown command ':${command}'. Try :help`);
|
|
1341
1288
|
}
|
|
@@ -1345,8 +1292,6 @@ function helpText() {
|
|
|
1345
1292
|
return [
|
|
1346
1293
|
":engine [wasm|js] display or switch evaluation engine (wasm or js)",
|
|
1347
1294
|
":rel name show relation definition",
|
|
1348
|
-
":type name show type definition",
|
|
1349
|
-
":types list type aliases",
|
|
1350
1295
|
":rels list relation aliases",
|
|
1351
1296
|
":codec load file load a codec module from file (e.g. :codec load codecs/int.mjs)",
|
|
1352
1297
|
":codec unload name unload a registered codec",
|
|
@@ -1666,12 +1666,10 @@ const htmlContent = `<!DOCTYPE html>
|
|
|
1666
1666
|
</optgroup>
|
|
1667
1667
|
<optgroup label="Quick Expressions">
|
|
1668
1668
|
<option value="expr:{} | ok">{} | ok</option>
|
|
1669
|
-
<option value="expr:
|
|
1670
|
-
<option value="expr:$ bool = < {} true, {} false >; not = $ bool < / true | false, {} | true > $ bool; {} | true not">not (boolean relation with fallback)</option>
|
|
1669
|
+
<option value="expr:not = < / true | false, / false | true >; {} | true not">not (boolean relation)</option>
|
|
1671
1670
|
<option value="expr:1 succ">1 succ</option>
|
|
1672
1671
|
<option value="expr:{10 int x, 5 int y} plus">{10 int x, 5 int y} plus (int)</option>
|
|
1673
1672
|
<option value="expr:{10 int x, 5 int y} karatsuba">{10 int x, 5 int y} karatsuba</option>
|
|
1674
|
-
<option value="expr::types">:types (list types)</option>
|
|
1675
1673
|
<option value="expr::rels">:rels (list relations)</option>
|
|
1676
1674
|
<option value="expr::engine">:engine (show engine)</option>
|
|
1677
1675
|
<option value="expr::engine wasm">:engine wasm</option>
|
|
@@ -1803,10 +1801,10 @@ const htmlContent = `<!DOCTYPE html>
|
|
|
1803
1801
|
<div class="help-section">
|
|
1804
1802
|
<h4>Language Overview</h4>
|
|
1805
1803
|
<p style="margin-bottom: 8px; color: var(--text-muted); line-height: 1.45;">
|
|
1806
|
-
<b>k</b> is a concise language of <b>
|
|
1804
|
+
<b>k</b> is a concise language of <b>relations</b> (functions) over tree-like (JSON-like) documents. Every expression denotes a relation that transforms an input document into an output document.
|
|
1807
1805
|
</p>
|
|
1808
1806
|
<p style="margin-bottom: 10px; color: var(--text-muted); line-height: 1.45;">
|
|
1809
|
-
<b>Content-Addressed:</b>
|
|
1807
|
+
<b>Content-Addressed:</b> Relations are identified by their canonical content hash (<code>@...</code>) derived directly from their structure. Local names are just temporary aliases used for recursion and readability.
|
|
1810
1808
|
</p>
|
|
1811
1809
|
|
|
1812
1810
|
<div class="help-category-title">1. Definitions (Local Aliases)</div>
|
|
@@ -1820,36 +1818,10 @@ const htmlContent = `<!DOCTYPE html>
|
|
|
1820
1818
|
<td><code>name = relExpr;</code></td>
|
|
1821
1819
|
<td><b>Relation Alias:</b> Defines a local alias for a relation expression.<br><i>e.g.</i> <code>swap = { . y x, . x y };</code></td>
|
|
1822
1820
|
</tr>
|
|
1823
|
-
<tr>
|
|
1824
|
-
<td><code>$ name = typeExpr;</code></td>
|
|
1825
|
-
<td><b>Type Alias:</b> Defines a local alias for a type schema.<br><i>e.g.</i> <code>$ bool = < {} true, {} false >;</code></td>
|
|
1826
|
-
</tr>
|
|
1827
|
-
</tbody>
|
|
1828
|
-
</table>
|
|
1829
|
-
|
|
1830
|
-
<div class="help-category-title">2. Type Expressions (<code>typeExpr</code>)</div>
|
|
1831
|
-
<p style="margin-bottom: 6px; color: var(--text-muted); font-size: 12px;">Schemas describing tree-like documents:</p>
|
|
1832
|
-
<table class="help-table">
|
|
1833
|
-
<thead>
|
|
1834
|
-
<tr><th style="width: 45%;">Syntax</th><th>Description</th></tr>
|
|
1835
|
-
</thead>
|
|
1836
|
-
<tbody>
|
|
1837
|
-
<tr>
|
|
1838
|
-
<td><code>{ Type_1 label_1, ..., Type_k label_k }</code></td>
|
|
1839
|
-
<td><b>Product Type:</b> Labeled record of arity <i>k</i> (e.g. <code>{float64 x, string n}</code>; special case: <code>{}</code> is the 0-ary product)</td>
|
|
1840
|
-
</tr>
|
|
1841
|
-
<tr>
|
|
1842
|
-
<td><code>< Type_1 tag_1, ..., Type_k tag_k ></code></td>
|
|
1843
|
-
<td><b>Union Type:</b> Tagged sum of <i>k</i> variants (e.g. <code><int ok, string err></code>)</td>
|
|
1844
|
-
</tr>
|
|
1845
|
-
<tr>
|
|
1846
|
-
<td><code>name</code> / <code>@hash</code></td>
|
|
1847
|
-
<td><b>Type Reference:</b> References a type by local alias or canonical content hash</td>
|
|
1848
|
-
</tr>
|
|
1849
1821
|
</tbody>
|
|
1850
1822
|
</table>
|
|
1851
1823
|
|
|
1852
|
-
<div class="help-category-title">
|
|
1824
|
+
<div class="help-category-title">2. Relation Expressions (<code>relExpr</code>)</div>
|
|
1853
1825
|
<p style="margin-bottom: 6px; color: var(--text-muted); font-size: 12px;">Functions transforming an input document to an output document:</p>
|
|
1854
1826
|
<table class="help-table">
|
|
1855
1827
|
<thead>
|
|
@@ -1881,8 +1853,8 @@ const htmlContent = `<!DOCTYPE html>
|
|
|
1881
1853
|
<td><b>Variant Constructor:</b> Wraps document into variant <code>tag</code></td>
|
|
1882
1854
|
</tr>
|
|
1883
1855
|
<tr>
|
|
1884
|
-
<td><code
|
|
1885
|
-
<td><b>
|
|
1856
|
+
<td><code>? filterExpr</code></td>
|
|
1857
|
+
<td><b>Pattern Filter:</b> Asserts input matches pattern; acts as partial identity and inductive termination witness (<i>e.g.</i> <code>?< {} true, {} false ></code>)</td>
|
|
1886
1858
|
</tr>
|
|
1887
1859
|
<tr>
|
|
1888
1860
|
<td><code>name</code> / <code>@hash</code></td>
|
|
@@ -1898,8 +1870,6 @@ const htmlContent = `<!DOCTYPE html>
|
|
|
1898
1870
|
<tr><td><code>:engine [wasm|js]</code></td><td>Display or switch evaluation engine (<code>wasm</code> or <code>js</code>)</td></tr>
|
|
1899
1871
|
<tr><td><code>:load <file></code></td><td>Load a <code>.k</code> source or <code>.klib</code> library into current state</td></tr>
|
|
1900
1872
|
<tr><td><code>:rel <name></code></td><td>Display definition of relation <code><name></code></td></tr>
|
|
1901
|
-
<tr><td><code>:type <name></code></td><td>Display definition of type <code><name></code></td></tr>
|
|
1902
|
-
<tr><td><code>:types</code></td><td>List all type aliases and canonical hashes</td></tr>
|
|
1903
1873
|
<tr><td><code>:rels</code></td><td>List all relation aliases</td></tr>
|
|
1904
1874
|
<tr><td><code>:codecs</code></td><td>List all loaded format codecs</td></tr>
|
|
1905
1875
|
<tr><td><code>:codec load <file.mjs></code></td><td>Load a codec from file (or load through Files)</td></tr>
|
|
@@ -1918,8 +1888,8 @@ const htmlContent = `<!DOCTYPE html>
|
|
|
1918
1888
|
<li><code>{} | ok</code> — Constant relation producing variant <code>ok</code> with empty document payload <code>{}</code></li>
|
|
1919
1889
|
<li><code>not = < / true | false, / false | true >;</code> — Polymorphic negation via branch projections and ordered choice</li>
|
|
1920
1890
|
<li><code>{} | true not</code> — Compose constant relation <code>{} | true</code> with <code>not</code> (evaluates to <code>{} | false</code>)</li>
|
|
1921
|
-
<li><code
|
|
1922
|
-
<li><code>not =
|
|
1891
|
+
<li><code>bool = ?< {} true, {} false >;</code> — Define a boolean pattern filter relation</li>
|
|
1892
|
+
<li><code>not = bool ?X < / true | false, {} | true > ?X;</code> — Filtered boolean negation: guarded by <code>bool</code>, defaulting to <code>{} | true</code></li>
|
|
1923
1893
|
<li><code>swap = { . y x, . x y };</code> — Define a product field-swapping relation</li>
|
|
1924
1894
|
<li><code>{ {} | ok x, {} | nil y } swap</code> — Construct a product and pass it through <code>swap</code></li>
|
|
1925
1895
|
</ul>
|
|
@@ -19,9 +19,7 @@ t(`
|
|
|
19
19
|
`, (annotated) => {
|
|
20
20
|
// console.log(JSON.stringify(annotated,null,2));
|
|
21
21
|
const {input,output} = in_out(annotated);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
assert.equal(output.type, annotated.representatives["bnat"]);
|
|
25
|
-
assert.equal(input.type, annotated.representatives["pair"]);
|
|
22
|
+
assert.equal(output.pattern, '(...)');
|
|
23
|
+
assert.equal(input.pattern, '<...>');
|
|
26
24
|
console.log("OK");
|
|
27
25
|
});
|
|
@@ -5,8 +5,7 @@ import assert from 'assert';
|
|
|
5
5
|
t(fs.readFileSync("./Examples/bnat.k", "utf8"), (annotated) => {
|
|
6
6
|
// console.log(JSON.stringify(annotated,null,2));
|
|
7
7
|
const {input,output} = in_out(annotated);
|
|
8
|
-
|
|
9
|
-
assert.equal(
|
|
10
|
-
assert.equal(input.type, annotated.representatives["pair"]);
|
|
8
|
+
assert.equal(output.type, "@VtPHxGf5GNMzzyVFxtv7gegFfJRYapBGtCeyV56bs5Zb");
|
|
9
|
+
assert.equal(input.type, "@R7RD2sgu6yPqpCQBBcJqkzxHQMZfEJLcNW4UKBcTiC3m");
|
|
11
10
|
console.log("OK");
|
|
12
11
|
});
|