@fraczak/k 5.1.0 → 5.1.2
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/built-in.mjs +7 -7
- package/Code-derivation-tests/dot.mjs +3 -3
- package/Code-derivation-tests/vector.mjs +4 -4
- package/codes.mjs +1 -1
- package/package.json +2 -2
- package/parser.jison +2 -1
- package/parser.mjs +24 -21
- package/patterns.mjs +12 -12
- package/run.mjs +3 -3
- package/test-fingerprint.mjs +2 -2
- package/test.mjs +1 -1
- package/tests.sh +6 -0
- package/typing.mjs +13 -13
|
@@ -9,11 +9,11 @@ function is_result_code(code) {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
t('true', is_result_code('bool'));
|
|
13
|
-
t('false
|
|
14
|
-
t('1', is_result_code('int'));
|
|
15
|
-
t('12
|
|
16
|
-
t('"ala"', is_result_code('string'));
|
|
17
|
-
t('"a"
|
|
12
|
+
t('true', is_result_code('@bool'));
|
|
13
|
+
t('false $@bool', is_result_code('@bool'));
|
|
14
|
+
t('1', is_result_code('@int'));
|
|
15
|
+
t('12 $@int', is_result_code('@int'));
|
|
16
|
+
t('"ala"', is_result_code('@string'));
|
|
17
|
+
t('"a" $@string', is_result_code('@string'));
|
|
18
18
|
|
|
19
|
-
t('${} true
|
|
19
|
+
t('${} true $@bool 1 $@int "a" $@string', is_result_code('@string'));
|
|
@@ -11,12 +11,12 @@ $b {1 one, () two, () c} .one
|
|
|
11
11
|
const {input,output} = in_out(annotated);
|
|
12
12
|
// console.log({input,output});
|
|
13
13
|
assert.equal(input.type, annotated.representatives["b"]);
|
|
14
|
-
assert.equal(output.type, "int");
|
|
14
|
+
assert.equal(output.type, "@int");
|
|
15
15
|
console.log("OK");
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
t(`
|
|
19
|
-
$a = < int true, bool false > ;
|
|
19
|
+
$a = < @int true, @bool false > ;
|
|
20
20
|
$a .true
|
|
21
21
|
`, (annotated) => {
|
|
22
22
|
const {input,output} = in_out(annotated);
|
|
@@ -35,6 +35,6 @@ t(`
|
|
|
35
35
|
const {input,output} = in_out(annotated);
|
|
36
36
|
console.log({input,output});
|
|
37
37
|
assert.equal(input.pattern, '(...)');
|
|
38
|
-
assert.equal(output.type, "bool");
|
|
38
|
+
assert.equal(output.type, "@bool");
|
|
39
39
|
console.log("OK");
|
|
40
40
|
});
|
|
@@ -8,12 +8,12 @@ t('[]', (annotated) => {
|
|
|
8
8
|
console.log("OK");
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
t("
|
|
11
|
+
t("$@int [ $@int true, false ] .0", (annotated) => {
|
|
12
12
|
const {input,output} = in_out(annotated);
|
|
13
|
-
assert.equal(input.type, "int");
|
|
14
|
-
assert.equal(output.type, "bool");
|
|
13
|
+
assert.equal(input.type, "@int");
|
|
14
|
+
assert.equal(output.type, "@bool");
|
|
15
15
|
console.log("OK");
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
assert.throws(() => t(
|
|
18
|
+
assert.throws(() => t(`$@int [ $@int true, 12 ]`), /Error/);
|
|
19
19
|
console.log("OK");
|
package/codes.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fraczak/k",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.2",
|
|
4
4
|
"description": "k-language for JSON-like data transformation",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepare": "jiwson -m es6 parser.jison -o parser.mjs",
|
|
8
|
-
"test": "node test.mjs; for f in Code-derivation-tests/*.mjs; do echo $f; node $f; done; node test-fingerprint.mjs"
|
|
8
|
+
"test": "node test.mjs; for f in Code-derivation-tests/*.mjs; do echo $f; node $f; done; node test-fingerprint.mjs; ./tests.sh"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
package/parser.jison
CHANGED
|
@@ -120,7 +120,7 @@ defs: { }
|
|
|
120
120
|
|
|
121
121
|
code
|
|
122
122
|
: name { $$ = { code: "ref", ref: $1.value, start: $1.start, end: $1.end}; }
|
|
123
|
-
| AT name
|
|
123
|
+
| AT name { $$ = { code: "ref", ref: "@" + $2.value, start: $1.start, end: $2.end}; }
|
|
124
124
|
| codeDef { $$ = $1; }
|
|
125
125
|
;
|
|
126
126
|
|
|
@@ -218,6 +218,7 @@ exp
|
|
|
218
218
|
| lb list rb { $$ = {op: "vector", vector: $2, start: $1.start, end: $3.end}; }
|
|
219
219
|
| la list ra { $$ = {...union($2), start: $1.start, end: $3.end}; }
|
|
220
220
|
| name { $$ = {op: "ref", ref: $1.value, start: $1.start, end: $1.end}; }
|
|
221
|
+
| AT name { $$ = {op: "ref", ref: "@" + $2.value, start: $1.start, end: $2.end}; }
|
|
221
222
|
| lp rp { $$ = {...identity, start: $1.start, end: $2.end}; }
|
|
222
223
|
| lp comp rp { $$ = {...$2, start: $1.start, end: $3.end }; }
|
|
223
224
|
| str { $$ = {op: "str", str: $1.value, start: $1.start, end: $1.end }; }
|
package/parser.mjs
CHANGED
|
@@ -115,12 +115,12 @@ function fromEscString(escString) {
|
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
var parser = (function(){
|
|
118
|
-
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[4,6,8,10,12,14,16,30,38,40,63],$V1=[1,10],$V2=[1,
|
|
118
|
+
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[4,6,8,10,12,14,16,30,38,40,50,63],$V1=[1,10],$V2=[1,26],$V3=[1,27],$V4=[1,24],$V5=[1,22],$V6=[1,23],$V7=[1,25],$V8=[1,28],$V9=[1,11],$Va=[1,29],$Vb=[1,15],$Vc=[1,21],$Vd=[1,32],$Ve=[4,6,8,10,12,14,16,30,38,40,47,50,60,63],$Vf=[2,68],$Vg=[1,36],$Vh=[1,39],$Vi=[4,6,8,10,12,14,16,18,20,22,24,30,32,34,38,40,47,50,60,63],$Vj=[2,90],$Vk=[1,58],$Vl=[2,72],$Vm=[2,73],$Vn=[4,6,8,10,12,14,16,18,20,22,24,30,32,34,36,38,40,47,50,60,63],$Vo=[4,6,8],$Vp=[2,27],$Vq=[4,6,8,10,12,14,16,18,20,22,24,26,30,32,34,38,40,47,50,60,63],$Vr=[2,33],$Vs=[1,84],$Vt=[1,86],$Vu=[20,32],$Vv=[4,6,8,10,12,14,16,30,38,40,50,60,63],$Vw=[1,91],$Vx=[1,95],$Vy=[18,22,32],$Vz=[1,98],$VA=[2,50],$VB=[2,51],$VC=[1,110],$VD=[18,20,32],$VE=[2,84],$VF=[2,85],$VG=[2,86],$VH=[18,20,24,32];
|
|
119
119
|
var parser = {trace: function trace () { },
|
|
120
120
|
yy: {},
|
|
121
121
|
symbols_: {"error":2,"name":3,"NAME":4,"str":5,"STRING":6,"int":7,"INT":8,"la":9,"LA":10,"lc":11,"LC":12,"lb":13,"LB":14,"lp":15,"LP":16,"ra":17,"RA":18,"rc":19,"RC":20,"rb":21,"RB":22,"rp":23,"RP":24,"eq":25,"EQ":26,"dots":27,"DOTS":28,"dot":29,"DOT":30,"comma":31,"COMMA":32,"sc":33,"SC":34,"col":35,"COL":36,"dollar":37,"DOLLAR":38,"qmark":39,"QMARK":40,"incremental":41,"INCREMENTAL":42,"input_with_eof":43,"initialize_symbol_table":44,"defs":45,"comp":46,"EOF":47,"codeDef":48,"code":49,"AT":50,"labelled_codes":51,"non_empty_labelled_codes":52,"code_label":53,"filter_":54,"labelled_filters":55,"filter":56,"non_empty_labelled_filters":57,"filter_label":58,"exp":59,"CARET":60,"labelled":61,"list":62,"PIPE":63,"non_empty_labelled":64,"comp_label":65,"non_empty_list":66,"$accept":0,"$end":1},
|
|
122
122
|
terminals_: {2:"error",4:"NAME",6:"STRING",8:"INT",10:"LA",12:"LC",14:"LB",16:"LP",18:"RA",20:"RC",22:"RB",24:"RP",26:"EQ",28:"DOTS",30:"DOT",32:"COMMA",34:"SC",36:"COL",38:"DOLLAR",40:"QMARK",42:"INCREMENTAL",47:"EOF",50:"AT",60:"CARET",63:"PIPE"},
|
|
123
|
-
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,1],[43,4],[44,0],[44,1],[45,0],[45,5],[45,6],[49,1],[49,2],[49,1],[48,3],[48,3],[48,3],[51,0],[51,1],[52,1],[52,3],[53,2],[53,2],[53,2],[53,3],[53,3],[53,3],[54,2],[54,3],[54,3],[54,3],[54,3],[56,1],[56,3],[56,1],[55,0],[55,1],[57,1],[57,3],[58,1],[58,2],[58,2],[58,2],[58,3],[58,3],[58,3],[46,1],[46,2],[46,2],[59,3],[59,3],[59,3],[59,1],[59,2],[59,3],[59,1],[59,1],[59,2],[59,2],[59,2],[59,2],[59,2],[59,1],[61,0],[61,1],[64,1],[64,3],[65,2],[65,2],[65,2],[65,3],[65,3],[65,3],[62,0],[62,1],[66,1],[66,3]],
|
|
123
|
+
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,1],[43,4],[44,0],[44,1],[45,0],[45,5],[45,6],[49,1],[49,2],[49,1],[48,3],[48,3],[48,3],[51,0],[51,1],[52,1],[52,3],[53,2],[53,2],[53,2],[53,3],[53,3],[53,3],[54,2],[54,3],[54,3],[54,3],[54,3],[56,1],[56,3],[56,1],[55,0],[55,1],[57,1],[57,3],[58,1],[58,2],[58,2],[58,2],[58,3],[58,3],[58,3],[46,1],[46,2],[46,2],[59,3],[59,3],[59,3],[59,1],[59,2],[59,2],[59,3],[59,1],[59,1],[59,2],[59,2],[59,2],[59,2],[59,2],[59,1],[61,0],[61,1],[64,1],[64,3],[65,2],[65,2],[65,2],[65,3],[65,3],[65,3],[62,0],[62,1],[66,1],[66,3]],
|
|
124
124
|
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
|
|
125
125
|
/* this == yyval */
|
|
126
126
|
|
|
@@ -161,7 +161,7 @@ break;
|
|
|
161
161
|
case 28:
|
|
162
162
|
this.$ = { code: "ref", ref: "@" + $$[$0].value, start: $$[$0-1].start, end: $$[$0].end};
|
|
163
163
|
break;
|
|
164
|
-
case 29: case 48: case 62: case
|
|
164
|
+
case 29: case 48: case 62: case 91:
|
|
165
165
|
this.$ = $$[$0];
|
|
166
166
|
break;
|
|
167
167
|
case 30:
|
|
@@ -187,10 +187,10 @@ case 34:
|
|
|
187
187
|
return r }
|
|
188
188
|
, {});
|
|
189
189
|
break;
|
|
190
|
-
case 35: case 53: case
|
|
190
|
+
case 35: case 53: case 92:
|
|
191
191
|
this.$ = [$$[$0]];
|
|
192
192
|
break;
|
|
193
|
-
case 36: case 54: case
|
|
193
|
+
case 36: case 54: case 93:
|
|
194
194
|
this.$ = [].concat($$[$0-2],$$[$0]);
|
|
195
195
|
break;
|
|
196
196
|
case 37: case 38: case 39:
|
|
@@ -269,33 +269,36 @@ case 68:
|
|
|
269
269
|
this.$ = {op: "ref", ref: $$[$0].value, start: $$[$0].start, end: $$[$0].end};
|
|
270
270
|
break;
|
|
271
271
|
case 69:
|
|
272
|
-
this.$ = {
|
|
272
|
+
this.$ = {op: "ref", ref: "@" + $$[$0].value, start: $$[$0-1].start, end: $$[$0].end};
|
|
273
273
|
break;
|
|
274
274
|
case 70:
|
|
275
|
-
this.$ = {
|
|
275
|
+
this.$ = {...identity, start: $$[$0-1].start, end: $$[$0].end};
|
|
276
276
|
break;
|
|
277
277
|
case 71:
|
|
278
|
-
this.$ = {
|
|
278
|
+
this.$ = {...$$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
|
|
279
279
|
break;
|
|
280
280
|
case 72:
|
|
281
|
+
this.$ = {op: "str", str: $$[$0].value, start: $$[$0].start, end: $$[$0].end };
|
|
282
|
+
break;
|
|
283
|
+
case 73:
|
|
281
284
|
this.$ = {op: "int", int: $$[$0].value, start: $$[$0].start, end: $$[$0].end };
|
|
282
285
|
break;
|
|
283
|
-
case
|
|
286
|
+
case 74: case 75: case 76:
|
|
284
287
|
this.$ = {op: "dot", dot: $$[$0].value, start: $$[$0-1].start, end: $$[$0].end };
|
|
285
288
|
break;
|
|
286
|
-
case
|
|
289
|
+
case 77:
|
|
287
290
|
this.$ = {op: "code", code: s.as_ref($$[$0]), start: $$[$0-1].start, end: $$[$0].end};
|
|
288
291
|
break;
|
|
289
|
-
case
|
|
292
|
+
case 78:
|
|
290
293
|
this.$ = {op: "filter", filter: $$[$0], start: $$[$0-1].start, end:$$[$0].end};
|
|
291
294
|
break;
|
|
292
|
-
case
|
|
295
|
+
case 79:
|
|
293
296
|
this.$ = {op: "pipe", start: $$[$0].start, end: $$[$0].end};
|
|
294
297
|
break;
|
|
295
|
-
case
|
|
298
|
+
case 80:
|
|
296
299
|
this.$ = {op: "product", product: []};
|
|
297
300
|
break;
|
|
298
|
-
case
|
|
301
|
+
case 81:
|
|
299
302
|
$$[$0].product.reduce( (labels, {label}) =>
|
|
300
303
|
{ if (labels[label])
|
|
301
304
|
anError(this._$,`Duplicate label '${label}'.`)
|
|
@@ -303,25 +306,25 @@ case 80:
|
|
|
303
306
|
return labels; }, {});
|
|
304
307
|
this.$ = $$[$0];
|
|
305
308
|
break;
|
|
306
|
-
case
|
|
309
|
+
case 82:
|
|
307
310
|
this.$ = {op: "product", product: [$$[$0]]};
|
|
308
311
|
break;
|
|
309
|
-
case
|
|
312
|
+
case 83:
|
|
310
313
|
$$[$0-2].product = [].concat($$[$0-2].product,$$[$0]); this.$ = $$[$0-2];
|
|
311
314
|
break;
|
|
312
|
-
case
|
|
315
|
+
case 84: case 85: case 86:
|
|
313
316
|
this.$ = {label: $$[$0].value, exp: $$[$0-1]};
|
|
314
317
|
break;
|
|
315
|
-
case
|
|
318
|
+
case 87: case 88: case 89:
|
|
316
319
|
this.$ = {label: $$[$0-2].value, exp: $$[$0]};
|
|
317
320
|
break;
|
|
318
|
-
case
|
|
321
|
+
case 90:
|
|
319
322
|
this.$ = [];
|
|
320
323
|
break;
|
|
321
324
|
}
|
|
322
325
|
},
|
|
323
|
-
table: [o($V0,[2,22],{43:1,44:2,41:3,42:[1,4]}),{1:[3]},o($V0,[2,24],{45:5}),o($V0,[2,23]),o($V0,[2,20]),{3:7,4:$V1,5:
|
|
324
|
-
defaultActions: {
|
|
326
|
+
table: [o($V0,[2,22],{43:1,44:2,41:3,42:[1,4]}),{1:[3]},o($V0,[2,24],{45:5}),o($V0,[2,23]),o($V0,[2,20]),{3:7,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:8,38:$V9,39:20,40:$Va,46:6,50:$Vb,59:9,63:$Vc},{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,47:[1,30],50:$Vb,59:31,60:$Vd,63:$Vc},o($Ve,$Vf,{25:35,26:$Vg}),{3:37,4:$V1,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:40,49:38,50:$Vh},o($Vi,[2,62]),o([4,6,8,10,12,14,16,18,20,22,24,26,30,32,34,36,38,40,47,50,60,63],[2,1]),o([4,10,12,14,50],[2,18]),{3:48,4:$V1,5:49,6:$V2,7:50,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,20:[2,80],29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:47,50:$Vb,59:9,61:44,63:$Vc,64:45,65:46},{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,22:$Vj,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:53,50:$Vb,59:9,62:51,63:$Vc,66:52},{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,18:$Vj,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:53,50:$Vb,59:9,62:54,63:$Vc,66:52},{3:55,4:$V1},{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,23:56,24:$Vk,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:57,50:$Vb,59:9,63:$Vc},o($Vi,$Vl),o($Vi,$Vm),{3:61,4:$V1,5:60,6:$V2,7:59,8:$V3},{3:64,4:$V1,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,37:65,38:$V9,54:63,56:62},o($Vi,[2,79]),o([4,6,8,10,12,14,16,20,28,30,38,40,50,63],[2,5]),o([4,6,8,10,12,14,16,22,30,38,40,50,63],[2,6]),o([4,6,8,10,12,14,16,18,28,30,38,40,50,63],[2,4]),o([4,6,8,10,12,14,16,24,28,30,38,40,50,63],[2,7]),o($Vn,[2,2]),o($Vn,[2,3]),o($Vo,[2,14]),o([4,10,12,14,16,38],[2,19]),{1:[2,21]},o($Vi,[2,63]),o($Vi,[2,64]),o($Vi,$Vf),{3:70,4:$V1,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:40,49:38,50:$Vh},{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:71,50:$Vb,59:9,63:$Vc},o($V0,[2,12]),o($Ve,$Vp,{25:72,26:$Vg}),o($Vi,[2,77]),{3:73,4:$V1},o($Vq,[2,29]),{3:78,4:$V1,5:79,6:$V2,7:80,8:$V3,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,20:$Vr,48:40,49:77,50:$Vh,51:74,52:75,53:76},{3:70,4:$V1,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:40,49:81,50:$Vh},{3:78,4:$V1,5:79,6:$V2,7:80,8:$V3,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,18:$Vr,48:40,49:77,50:$Vh,51:82,52:75,53:76},{19:83,20:$Vs},{20:[2,81],31:85,32:$Vt},o($Vu,[2,82]),{3:87,4:$V1,5:88,6:$V2,7:89,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,50:$Vb,59:31,60:$Vd,63:$Vc},o($Vv,$Vf,{35:90,36:$Vw}),o($Vv,$Vl,{35:92,36:$Vw}),o($Vv,$Vm,{35:93,36:$Vw}),{21:94,22:$Vx},o([18,22],[2,91],{31:96,32:$Vt}),o($Vy,[2,92],{11:12,13:13,9:14,15:16,5:17,7:18,29:19,39:20,59:31,3:33,37:34,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,50:$Vb,60:$Vd,63:$Vc}),{17:97,18:$Vz},o($Vi,[2,69]),o($Vi,[2,70]),{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,23:99,24:$Vk,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,50:$Vb,59:31,60:$Vd,63:$Vc},o($Vq,[2,11]),o($Vi,[2,74]),o($Vi,[2,75]),o($Vi,[2,76]),o($Vi,[2,78]),o($Vi,[2,48],{26:[1,100]}),o($Vi,$VA),{3:70,4:$V1,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:40,49:101,50:$Vh},{3:107,4:$V1,5:108,6:$V2,7:109,8:$V3,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,24:$VB,27:105,28:$VC,37:65,38:$V9,54:63,55:102,56:106,57:103,58:104},{3:107,4:$V1,5:108,6:$V2,7:109,8:$V3,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,18:$VB,27:105,28:$VC,37:65,38:$V9,54:63,55:111,56:106,57:103,58:104},{3:107,4:$V1,5:108,6:$V2,7:109,8:$V3,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,20:$VB,27:105,28:$VC,37:65,38:$V9,54:63,55:112,56:106,57:103,58:104},{3:64,4:$V1,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,37:65,38:$V9,54:63,56:113},o($Vq,$Vp),{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,33:114,34:[1,115],37:34,38:$V9,39:20,40:$Va,50:$Vb,59:31,60:$Vd,63:$Vc},{9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:116},o($Vq,[2,28]),{19:117,20:$Vs},o([18,20],[2,34],{31:118,32:$Vt}),o($VD,[2,35]),{3:119,4:$V1,5:120,6:$V2,7:121,8:$V3},o($Vo,$Vp,{35:122,36:$Vw}),{35:123,36:$Vw},{35:124,36:$Vw},{21:125,22:$Vx},{17:126,18:$Vz},o($Vi,[2,65]),o($Vq,[2,9]),{3:48,4:$V1,5:49,6:$V2,7:50,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:47,50:$Vb,59:9,63:$Vc,65:127},o([4,6,8,10,12,14,16,28,30,38,40,50,63],[2,15]),o($Vv,$Vf,{20:$VE,32:$VE}),o($Vv,$Vl,{20:$VF,32:$VF}),o($Vv,$Vm,{20:$VG,32:$VG}),{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:128,50:$Vb,59:9,63:$Vc},o($V0,[2,17]),{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:129,50:$Vb,59:9,63:$Vc},{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:130,50:$Vb,59:9,63:$Vc},o($Vi,[2,66]),o($Vq,[2,10]),{3:33,4:$V1,5:17,6:$V2,7:18,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:16,16:$V7,29:19,30:$V8,37:34,38:$V9,39:20,40:$Va,46:131,50:$Vb,59:9,63:$Vc},o($Vi,[2,67]),o($Vq,[2,8]),o($Vi,[2,71]),{3:132,4:$V1},o($Vq,[2,43]),{23:133,24:$Vk},o([18,20,24],[2,52],{31:134,32:$Vt}),o($VH,[2,53]),o($VH,[2,55]),{3:135,4:$V1,5:136,6:$V2,7:137,8:$V3},o($Vo,$VA,{35:138,36:$Vw}),{35:139,36:$Vw},{35:140,36:$Vw},o($VH,[2,13]),{17:141,18:$Vz},{19:142,20:$Vs},{21:143,22:$Vx},o($V0,[2,25]),o($V0,[2,16]),{34:[1,144]},o($Vq,[2,30]),{3:78,4:$V1,5:79,6:$V2,7:80,8:$V3,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:40,49:77,50:$Vh,53:145},o($VD,[2,37]),o($VD,[2,38]),o($VD,[2,39]),{3:70,4:$V1,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:40,49:146,50:$Vh},{3:70,4:$V1,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:40,49:147,50:$Vh},{3:70,4:$V1,9:43,10:$V4,11:41,12:$V5,13:42,14:$V6,48:40,49:148,50:$Vh},o($Vq,[2,31]),o($Vq,[2,32]),o($Vu,[2,83]),o($Vu,[2,87],{11:12,13:13,9:14,15:16,5:17,7:18,29:19,39:20,59:31,3:33,37:34,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,50:$Vb,60:$Vd,63:$Vc}),o($Vu,[2,88],{11:12,13:13,9:14,15:16,5:17,7:18,29:19,39:20,59:31,3:33,37:34,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,50:$Vb,60:$Vd,63:$Vc}),o($Vu,[2,89],{11:12,13:13,9:14,15:16,5:17,7:18,29:19,39:20,59:31,3:33,37:34,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,50:$Vb,60:$Vd,63:$Vc}),o($Vy,[2,93],{11:12,13:13,9:14,15:16,5:17,7:18,29:19,39:20,59:31,3:33,37:34,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,50:$Vb,60:$Vd,63:$Vc}),o($Vi,[2,49]),o($Vq,[2,44]),{3:107,4:$V1,5:108,6:$V2,7:109,8:$V3,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,27:105,28:$VC,37:65,38:$V9,54:63,56:106,58:149},o($VH,[2,56]),o($VH,[2,57]),o($VH,[2,58]),{3:64,4:$V1,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,37:65,38:$V9,54:63,56:150},{3:64,4:$V1,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,37:65,38:$V9,54:63,56:151},{3:64,4:$V1,9:67,10:$V4,11:68,12:$V5,13:69,14:$V6,15:66,16:$V7,37:65,38:$V9,54:63,56:152},o($Vq,[2,45]),o($Vq,[2,46]),o($Vq,[2,47]),o($V0,[2,26]),o($VD,[2,36]),o($VD,[2,40]),o($VD,[2,41]),o($VD,[2,42]),o($VH,[2,54]),o($VH,[2,59]),o($VH,[2,60]),o($VH,[2,61])],
|
|
327
|
+
defaultActions: {30:[2,21]},
|
|
325
328
|
parseError: function parseError (str, hash) {
|
|
326
329
|
if (hash.recoverable) {
|
|
327
330
|
this.trace(str);
|
package/patterns.mjs
CHANGED
|
@@ -174,12 +174,12 @@ function patterns(representatives, rels) {
|
|
|
174
174
|
case "int":
|
|
175
175
|
rel.patterns = [];
|
|
176
176
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode();
|
|
177
|
-
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('int');
|
|
177
|
+
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('@int');
|
|
178
178
|
break;
|
|
179
179
|
case "str":
|
|
180
180
|
rel.patterns = [];
|
|
181
181
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode();
|
|
182
|
-
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('string');
|
|
182
|
+
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('@string');
|
|
183
183
|
break;
|
|
184
184
|
case "identity":
|
|
185
185
|
rel.patterns = [];
|
|
@@ -286,7 +286,7 @@ function patterns(representatives, rels) {
|
|
|
286
286
|
rel.patterns = [];
|
|
287
287
|
if (rel.union.length == 0) {
|
|
288
288
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode();
|
|
289
|
-
rel.patterns[1] = rootDef.typePatternGraph.addNewNode(
|
|
289
|
+
rel.patterns[1] = rootDef.typePatternGraph.addNewNode();
|
|
290
290
|
} else {
|
|
291
291
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode();
|
|
292
292
|
rootDef.typePatternGraph.unify(
|
|
@@ -359,39 +359,39 @@ function patterns(representatives, rels) {
|
|
|
359
359
|
case "true":
|
|
360
360
|
case "false":
|
|
361
361
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode();
|
|
362
|
-
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('bool');
|
|
362
|
+
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('@bool');
|
|
363
363
|
break;
|
|
364
364
|
case "PLUS":
|
|
365
365
|
case "TIMES":
|
|
366
|
-
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('int');
|
|
366
|
+
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('@int');
|
|
367
367
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode({pattern: '[]'}, {"vector-member": [rel.patterns[1]]});
|
|
368
368
|
break;
|
|
369
369
|
case "CONCAT":
|
|
370
|
-
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('string');
|
|
370
|
+
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('@string');
|
|
371
371
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode({pattern: '[]'}, {"vector-member": [rel.patterns[1]]});
|
|
372
372
|
break;
|
|
373
373
|
case "toVEC":
|
|
374
|
-
rel.patterns[0] = rootDef.typePatternGraph.getTypeId('string')
|
|
374
|
+
rel.patterns[0] = rootDef.typePatternGraph.getTypeId('@string')
|
|
375
375
|
rel.patterns[1] = rootDef.typePatternGraph.addNewNode({pattern: '[]'}, {"vector-member": [rel.patterns[0]]});
|
|
376
376
|
break;
|
|
377
377
|
case "toDateMsec":
|
|
378
378
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode();
|
|
379
|
-
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('int');
|
|
379
|
+
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('@int');
|
|
380
380
|
break;
|
|
381
381
|
case "toJSON":
|
|
382
382
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode();
|
|
383
|
-
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('string');
|
|
383
|
+
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('@string');
|
|
384
384
|
break;
|
|
385
385
|
case "toDateStr":
|
|
386
386
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode();
|
|
387
|
-
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('string');
|
|
387
|
+
rel.patterns[1] = rootDef.typePatternGraph.getTypeId('@string');
|
|
388
388
|
break;
|
|
389
389
|
case "GT":
|
|
390
390
|
case "EQ":
|
|
391
391
|
rel.patterns[0] = rel.patterns[1] = rootDef.typePatternGraph.addNewNode({pattern: '[]'}, {"vector-member": [rootDef.typePatternGraph.addNewNode()]});
|
|
392
392
|
break;
|
|
393
393
|
case "fromJSON":
|
|
394
|
-
rel.patterns[0] = rootDef.typePatternGraph.getTypeId('string');
|
|
394
|
+
rel.patterns[0] = rootDef.typePatternGraph.getTypeId('@string');
|
|
395
395
|
rel.patterns[1] = rootDef.typePatternGraph.addNewNode();
|
|
396
396
|
break;
|
|
397
397
|
case "CONS": {
|
|
@@ -405,7 +405,7 @@ function patterns(representatives, rels) {
|
|
|
405
405
|
rel.patterns[1] = rootDef.typePatternGraph.addNewNode({pattern: '{}'}, {"car": [member], "cdr": [rel.patterns[0]]});
|
|
406
406
|
}; break;
|
|
407
407
|
case "DIV": {
|
|
408
|
-
const intId = rootDef.typePatternGraph.getTypeId('int');
|
|
408
|
+
const intId = rootDef.typePatternGraph.getTypeId('@int');
|
|
409
409
|
rel.patterns[0] = rootDef.typePatternGraph.addNewNode({pattern: '[]'}, {"vector-member": [intId]});
|
|
410
410
|
rel.patterns[1] = rootDef.typePatternGraph.addNewNode({pattern: '{}'}, {"div": [intId], "rem": [intId]});
|
|
411
411
|
}; break;
|
package/run.mjs
CHANGED
|
@@ -68,9 +68,9 @@ const builtin = {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
const codes = {
|
|
71
|
-
int: (x) => Number.isInteger(x),
|
|
72
|
-
string: (x) => x instanceof String || "string" === typeof x,
|
|
73
|
-
bool: (x) => x === true || x === false,
|
|
71
|
+
"@int": (x) => Number.isInteger(x),
|
|
72
|
+
"@string": (x) => x instanceof String || "string" === typeof x,
|
|
73
|
+
"@bool": (x) => x === true || x === false,
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
function verify(code, value) {
|
package/test-fingerprint.mjs
CHANGED
|
@@ -5,8 +5,8 @@ import hash from './hash.mjs';
|
|
|
5
5
|
`
|
|
6
6
|
$nat = < {} zero, nat succ>;
|
|
7
7
|
$pair = {nat x, nat y};
|
|
8
|
-
$b = {int"x", bool y};
|
|
9
|
-
$vector = [int];
|
|
8
|
+
$b = {@int"x", @bool y};
|
|
9
|
+
$vector = [@int];
|
|
10
10
|
$tree = <{nat value, tree left, tree right} binary, nat leaf, {nat value, tree tree} unary, [tree] list_of_trees>;
|
|
11
11
|
|
|
12
12
|
succ = { $nat succ} $nat;
|
package/test.mjs
CHANGED
package/tests.sh
ADDED
package/typing.mjs
CHANGED
|
@@ -401,14 +401,14 @@ class TypePatternGraph {
|
|
|
401
401
|
case 'type': {
|
|
402
402
|
const code = codes.find(p2.type);
|
|
403
403
|
switch (code.code) {
|
|
404
|
-
case 'int':
|
|
404
|
+
case '@int':
|
|
405
405
|
// supports (2 .2) which returns unit
|
|
406
406
|
if (p1.fields.every(x => `${x}`.match(/^[0-9]+$/)))
|
|
407
407
|
return p2;
|
|
408
408
|
break;
|
|
409
|
-
case 'string':
|
|
409
|
+
case '@string':
|
|
410
410
|
return p2;
|
|
411
|
-
case 'bool':
|
|
411
|
+
case '@bool':
|
|
412
412
|
if (p1.fields.every(x => `${x}`.match(/^true|false$/)))
|
|
413
413
|
return p2;
|
|
414
414
|
break;
|
|
@@ -471,14 +471,14 @@ class TypePatternGraph {
|
|
|
471
471
|
case 'type':{
|
|
472
472
|
const code = codes.find(p2.type);
|
|
473
473
|
switch (code.code) {
|
|
474
|
-
case 'int':
|
|
474
|
+
case '@int':
|
|
475
475
|
// supports (2 .2) which returns unit
|
|
476
476
|
if (p1.fields.every(x => `${x}`.match(/^[0-9]+$/)))
|
|
477
477
|
return p2;
|
|
478
478
|
break;
|
|
479
|
-
case 'string':
|
|
479
|
+
case '@string':
|
|
480
480
|
return p2;
|
|
481
|
-
case 'bool':
|
|
481
|
+
case '@bool':
|
|
482
482
|
if (p1.fields.every(x => `${x}`.match(/^true|false$/)))
|
|
483
483
|
return p2;
|
|
484
484
|
break;
|
|
@@ -508,13 +508,13 @@ class TypePatternGraph {
|
|
|
508
508
|
case 'type':{
|
|
509
509
|
const code = codes.find(p2.type);
|
|
510
510
|
switch (code.code) {
|
|
511
|
-
case 'int':
|
|
511
|
+
case '@int':
|
|
512
512
|
if (p1.fields.every(x => `${x}`.match(/^[0-9]+$/)))
|
|
513
513
|
return p2;
|
|
514
514
|
break;
|
|
515
|
-
case 'string':
|
|
515
|
+
case '@string':
|
|
516
516
|
return p2;
|
|
517
|
-
case 'bool':
|
|
517
|
+
case '@bool':
|
|
518
518
|
if (p1.fields.every(x => `${x}`.match(/^true|false$/)))
|
|
519
519
|
return p2;
|
|
520
520
|
break;
|
|
@@ -645,9 +645,9 @@ class TypePatternGraph {
|
|
|
645
645
|
if (new_pattern.pattern == 'type') {
|
|
646
646
|
const code = codes.find(new_pattern.type);
|
|
647
647
|
switch (code.code) {
|
|
648
|
-
case 'int':
|
|
649
|
-
case 'string':
|
|
650
|
-
case 'bool': {
|
|
648
|
+
case '@int':
|
|
649
|
+
case '@string':
|
|
650
|
+
case '@bool': {
|
|
651
651
|
// all edges are goin to unit type
|
|
652
652
|
const unit_id = this.getTypeId(unitCode);
|
|
653
653
|
for (const lab in this.edges[new_id]) {
|
|
@@ -667,7 +667,7 @@ class TypePatternGraph {
|
|
|
667
667
|
const target_type_id = this.getTypeId(code.vector);
|
|
668
668
|
|
|
669
669
|
this.edges[new_id] = {
|
|
670
|
-
'vector-member': asSet([ target_type_id, ...Object.values(this.edges[new_id])])
|
|
670
|
+
'vector-member': asSet([ target_type_id, ...[].concat(...Object.values(this.edges[new_id]))])
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
673
|
}
|