@fraczak/k 5.0.1 → 5.1.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/README.md CHANGED
@@ -54,7 +54,7 @@ the property doesn't exist. E.g.,
54
54
 
55
55
  There are three ways of combining functions:
56
56
 
57
- 1. **composition**: `(f1 f2 ...)`, e.g. `(.toto .titi)` extracts
57
+ 1. **Composition**: `(f1 f2 ...)`, e.g. `(.toto .titi)` extracts
58
58
  nested field.
59
59
 
60
60
  ```text
@@ -64,7 +64,7 @@ There are three ways of combining functions:
64
64
  {"other": {}} ... undefined
65
65
  ```
66
66
 
67
- 2. **merge**: `< f1, f2,... >`, e.g., `<.toto, .titi>` extracts field
67
+ 2. **Merge**: `< f1, f2,... >`, e.g., `<.toto, .titi>` extracts field
68
68
  `toto` if present; otherwise extracts `titi`.
69
69
 
70
70
  ```text
@@ -74,7 +74,7 @@ There are three ways of combining functions:
74
74
  {"x":{"o":{}}, "z": {"o":{}}} ... undefined
75
75
  ```
76
76
 
77
- 3. **product**: `{ f1 label1, f2 label2, ...}`, e.g., `{.toto TOTO,
77
+ 3. **Product**: `{ f1 label1, f2 label2, ...}`, e.g., `{.toto TOTO,
78
78
  .titi TITI}` extracts two fields and builds a record out of them.
79
79
 
80
80
  ```text
@@ -86,9 +86,9 @@ There are three ways of combining functions:
86
86
 
87
87
  **QUIZ**: What is:
88
88
 
89
- - empty composition: `()` ?
90
- - empty merge: `<>` ?
91
- - empty product: `{}` ?
89
+ - Empty composition: `()` ?
90
+ - Empty merge: `<>` ?
91
+ - Empty product: `{}` ?
92
92
  - `{{{{} s} s} s}` ?
93
93
  - `({{{() a} b} c} .c .b .a)` ?
94
94
 
@@ -96,9 +96,9 @@ There are three ways of combining functions:
96
96
 
97
97
  ### Syntactic sugar
98
98
 
99
- - parenthesis can be omitted, except for the empty composition `()`,
100
- - dot (`.`) in "projection" acts as a separator so the space around it
101
- can be omitted.
99
+ - Parenthesis can be omitted, except for the empty composition `()`,
100
+ - dot (`.`) in "projection" acts as a separator, so the surrounding
101
+ space can be omitted.
102
102
 
103
103
  For example, `(.toto .titi (.0 .1))` can be written as `.toto.titi.0.1`.
104
104
 
@@ -148,8 +148,8 @@ projection, via (`.`), to the canonical string representation of the value, e.g.
148
148
 
149
149
  #### Vector product
150
150
 
151
- Vector product can be seen as an abbreviation for product whose all fields
152
- have the same type, and the filed names are integers starting from zero.
151
+ The vector product can be seen as a shorthand for a product in which all fields
152
+ have the same type, and the field names are integers starting from zero.
153
153
  E.g., `{.toto 0, .titi 1, 123 2}` can be written as
154
154
  `[.toto, .titi, 123]`.
155
155
 
@@ -531,7 +531,7 @@ For example:
531
531
 
532
532
  ## k-REPL (Read-Evaluate-Print Loop)
533
533
 
534
- Also there is a REPL, `k-repl` (`./node_modules/.bin/k-repl`),
534
+ Also, there is a REPL, `k-repl` (`./node_modules/.bin/k-repl`),
535
535
  which acts like a toy shell for the language.
536
536
 
537
537
  ```k-repl
@@ -552,72 +552,74 @@ Very! experimental repl shell for 'k-language'...
552
552
 
553
553
  ## Using `k` from `javascript`
554
554
 
555
- import k from "@fraczak/k";
555
+ ```javascript
556
+ import k from "@fraczak/k";
556
557
 
557
- let k_expression = '()';
558
- k.run(k_expression,"ANYTHING...");
559
- // RETURNS: "ANYTHING..."
558
+ let k_expression = '()';
559
+ k.run(k_expression,"ANYTHING...");
560
+ // RETURNS: "ANYTHING..."
560
561
 
561
- k_expression = '{"ala" name, 23 age}';
562
- k.run(k_expression,"ANYTHING...");
563
- // RETURNS: {"name":"ala","age":23}
562
+ k_expression = '{"ala" name, 23 age}';
563
+ k.run(k_expression,"ANYTHING...");
564
+ // RETURNS: {"name":"ala","age":23}
564
565
 
565
- k_expression = '[.year, .age]';
566
- k.run(k_expression,{"year":2002,"age":19});
567
- // RETURNS: [2002,19]
566
+ k_expression = '[.year, .age]';
567
+ k.run(k_expression,{"year":2002,"age":19});
568
+ // RETURNS: [2002,19]
568
569
 
569
- k_expression = '[(), ()]';
570
- k.run(k_expression,"duplicate me");
571
- // RETURNS: ["duplicate me","duplicate me"]
570
+ k_expression = '[(), ()]';
571
+ k.run(k_expression,"duplicate me");
572
+ // RETURNS: ["duplicate me","duplicate me"]
572
573
 
573
- k_expression = '[[[()]]]';
574
- k.run(k_expression,"nesting");
575
- // RETURNS: [[["nesting"]]]
574
+ k_expression = '[[[()]]]';
575
+ k.run(k_expression,"nesting");
576
+ // RETURNS: [[["nesting"]]]
576
577
 
577
- k_expression = '[[()]] {() nested, .0.0 val}';
578
- k.run(k_expression,"nesting and accessing");
579
- // RETURNS: {"nested":[["nesting and accessing"]],"val":"nesting and accessing"}
578
+ k_expression = '[[()]] {() nested, .0.0 val}';
579
+ k.run(k_expression,"nesting and accessing");
580
+ // RETURNS: {"nested":[["nesting and accessing"]],"val":"nesting and accessing"}
580
581
 
581
- k_expression = '0000';
582
- k.run(k_expression,{"test":"parse integer"});
583
- // RETURNS: 0
582
+ k_expression = '0000';
583
+ k.run(k_expression,{"test":"parse integer"});
584
+ // RETURNS: 0
584
585
 
585
- k_expression = '[.y,.x] PLUS';
586
- k.run(k_expression,{"x":3,"y":4});
587
- // RETURNS: 7
586
+ k_expression = '[.y,.x] PLUS';
587
+ k.run(k_expression,{"x":3,"y":4});
588
+ // RETURNS: 7
588
589
 
589
- var k_fn = k.compile('{.name nom, <[.age, 18] GT .0, [.age, 12] GT "ado", "enfant"> age}');
590
+ var k_fn = k.compile('{.name nom, <[.age, 18] GT .0, [.age, 12] GT "ado", "enfant"> age}');
590
591
 
591
- k_fn({"age":23,"name":"Emily"});
592
- // RETURNS: {"nom":"Emily","age":23}
592
+ k_fn({"age":23,"name":"Emily"});
593
+ // RETURNS: {"nom":"Emily","age":23}
593
594
 
594
- k_fn({"age":16,"name":"Katrina"});
595
- // RETURNS: {"nom":"Katrina","age":"ado"}
595
+ k_fn({"age":16,"name":"Katrina"});
596
+ // RETURNS: {"nom":"Katrina","age":"ado"}
596
597
 
597
- k_fn({"age":2,"name":"Mark"});
598
- // RETURNS: {"nom":"Mark","age":"enfant"}
598
+ k_fn({"age":2,"name":"Mark"});
599
+ // RETURNS: {"nom":"Mark","age":"enfant"}
599
600
 
600
- k_fn = k.compile('$t = < i: int, t: [ t ] > ; <$t, $int>');
601
+ k_fn = k.compile('$t = < i: int, t: [ t ] > ; <$t, $int>');
601
602
 
602
- k_fn(1);
603
- // RETURNS: 1
603
+ k_fn(1);
604
+ // RETURNS: 1
604
605
 
605
- k_fn({"i":1});
606
- // RETURNS: {"i":1}
606
+ k_fn({"i":1});
607
+ // RETURNS: {"i":1}
607
608
 
608
- k_fn([{"i":2},{"i":3},{"t":[]}]);
609
- // RETURNS: undefined
609
+ k_fn([{"i":2},{"i":3},{"t":[]}]);
610
+ // RETURNS: undefined
610
611
 
611
- k_fn({"t":[{"i":2},{"i":3},{"t":[]}]});
612
- // RETURNS: {"t":[{"i":2},{"i":3},{"t":[]}]}
612
+ k_fn({"t":[{"i":2},{"i":3},{"t":[]}]});
613
+ // RETURNS: {"t":[{"i":2},{"i":3},{"t":[]}]}
613
614
 
614
- k_fn = k.compile('$ < < [ int ] ints, [ bool ] bools > list, string None>');
615
+ k_fn = k.compile('$ < < [ int ] ints, [ bool ] bools > list, string None>');
615
616
 
616
- k_fn({"None":"None"});
617
- // RETURNS: {"None":"None"}
617
+ k_fn({"None":"None"});
618
+ // RETURNS: {"None":"None"}
618
619
 
619
- k_fn({"list":{"ints":[]}});
620
- // RETURNS: {"list":{"ints":[]}}
620
+ k_fn({"list":{"ints":[]}});
621
+ // RETURNS: {"list":{"ints":[]}}
621
622
 
622
- k_fn({"list":{"ints":[1,2,3]}});
623
- // RETURNS: {"list":{"ints":[1,2,3]}}
623
+ k_fn({"list":{"ints":[1,2,3]}});
624
+ // RETURNS: {"list":{"ints":[1,2,3]}}
625
+ ```
package/TODO.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # To do list for canonical names
2
2
 
3
3
  - [ ] Write a script to search for conflicting names
4
- - [ ] Export a relation. i.e., rewrite it as a list of all
4
+ - [*] Export a relation. i.e., rewrite it as a list of all
5
5
  dependency definitions using canonical names
6
6
  - [ ] Find a way of adding 'comments' or some way of 'tagging' the definitions
7
7
  - [X] The definitions should be simplied by removing useless filters
@@ -16,3 +16,38 @@ filters corresponding to the patterns. [DONE]
16
16
 
17
17
  The filer variables have to be renamed for normalization if they take part of
18
18
  the canonical name calculation. [DONE]
19
+
20
+ ## DESER
21
+
22
+ Serialization and deserialization of values.
23
+
24
+ ### Can we define byte-array via prefix-free codes?
25
+
26
+ ### Non prefix-free de/serialization
27
+
28
+ How programatically change encoding of a value? Is it possible to add some
29
+ annotations on the type graph?
30
+
31
+ Maybe it belongs to "execution environment", e.g., `k --deser JSON`,
32
+ `k --deser AVRO/UTF8`, where `JSON`, `AVRO`, `UTF8` are provided
33
+ by some external spec?
34
+
35
+ E.g.:
36
+
37
+ ```DESER:
38
+ $ BsAqRMv = < BsAqRMv 0, BsAqRMv 1, KL _ >; -- $C0=<C0"0",C0"1",C1"_">;$C1={};
39
+
40
+ $ bnat = < {} _ @as '', bnat 0 @as '0' , bnat 1 >;
41
+ ::UTF8::
42
+ {{} _} => ()
43
+ {$bnat 0} => \u2602
44
+
45
+ Ok, it looks for me like what we need is the "Monad", i.e., a set of
46
+ functions with side-effects (like `_log!`).
47
+ Get straight, we have `write_0!`, `write_1!`, `read_0!`, and `read_1!`,
48
+ or whatever is supported by the target.
49
+
50
+ #### How to implement `JSON`?
51
+
52
+
53
+
package/codes.mjs CHANGED
@@ -103,6 +103,7 @@ function minimize(codes) {
103
103
  for (const name1 in classes) {
104
104
  const [eq_names, dif_names] = classes[name1].reduce(
105
105
  ([eq_names, dif_names], name2) => {
106
+ // console.log(JSON.stringify({classes,codes,representatives,name1,name2},null,2));
106
107
  if (are_different(classes, representatives, name1, name2, codes)) {
107
108
  dif_names.push(name2);
108
109
  } else {
@@ -152,6 +153,9 @@ function normalizeAll(codes, representatives) {
152
153
  ...code,
153
154
  vector: representatives[code.vector] || code.vector,
154
155
  };
156
+ break;
157
+ default:
158
+ throw new Error(`Unexpected code ${code.code}`);
155
159
  }
156
160
  }
157
161
 
@@ -190,7 +194,7 @@ function finalize(codes) {
190
194
  }
191
195
 
192
196
  function register(newCodes) {
193
- const { codes, representatives } = finalize( {...newCodes,...theRepository.codes});
197
+ const { codes, representatives } = finalize( {...theRepository.codes,...newCodes});
194
198
  const reps = Object.values(representatives).reduce((reps,rep) =>
195
199
  ({...reps, [rep]:rep})
196
200
  , {});
package/hash.mjs CHANGED
@@ -33,7 +33,7 @@ function hash(inputString) {
33
33
  hashValue = (hashValue * prime + charCode) % mod;
34
34
  }
35
35
 
36
- return shifString(hashValue.toString(base));
36
+ return "@"+shifString(hashValue.toString(base));
37
37
  }
38
38
 
39
39
  export default hash;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraczak/k",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "description": "k-language for JSON-like data transformation",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
package/parser.jison CHANGED
@@ -63,6 +63,7 @@ function fromEscString(escString) {
63
63
  "?" return 'QMARK';
64
64
  "|" return 'PIPE';
65
65
  "^" return 'CARET';
66
+ "@" return 'AT';
66
67
  \"([^"\\]|\\(.|\n))*\"|\'([^'\\]|\\(.|\n))*\' return 'STRING';
67
68
  [a-zA-Z_][a-zA-Z0-9_?!]* return 'NAME';
68
69
  0|[-]?[1-9][0-9]* return 'INT';
@@ -72,7 +73,7 @@ function fromEscString(escString) {
72
73
  /lex
73
74
 
74
75
  %token NAME STRING INT
75
- %token LA LC LB LP RA RP RB RC EQ DOT COMMA SC COL DOLLAR PIPE CARET QMARK DOTS
76
+ %token LA LC LB LP RA RP RB RC EQ DOT COMMA SC COL DOLLAR PIPE CARET AT QMARK DOTS
76
77
  %token EOF
77
78
 
78
79
  %start input_with_eof
@@ -119,6 +120,7 @@ defs: { }
119
120
 
120
121
  code
121
122
  : name { $$ = { code: "ref", ref: $1.value, start: $1.start, end: $1.end}; }
123
+ | AT name { $$ = { code: "ref", ref: "@" + $2.value, start: $1.start, end: $2.end}; }
122
124
  | codeDef { $$ = $1; }
123
125
  ;
124
126
 
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,62],$V1=[1,10],$V2=[1,25],$V3=[1,26],$V4=[1,23],$V5=[1,21],$V6=[1,22],$V7=[1,24],$V8=[1,27],$V9=[1,11],$Va=[1,28],$Vb=[1,20],$Vc=[1,31],$Vd=[4,6,8,10,12,14,16,30,38,40,47,59,62],$Ve=[2,67],$Vf=[1,35],$Vg=[4,6,8,10,12,14,16,18,20,22,24,30,32,34,38,40,47,59,62],$Vh=[2,88],$Vi=[1,55],$Vj=[2,70],$Vk=[2,71],$Vl=[4,6,8,10,12,14,16,18,20,22,24,30,32,34,36,38,40,47,59,62],$Vm=[4,6,8],$Vn=[2,27],$Vo=[4,6,8,10,12,14,16,18,20,22,24,26,30,32,34,38,40,47,59,62],$Vp=[2,32],$Vq=[1,80],$Vr=[1,82],$Vs=[20,32],$Vt=[4,6,8,10,12,14,16,30,38,40,59,62],$Vu=[1,87],$Vv=[1,91],$Vw=[18,22,32],$Vx=[1,94],$Vy=[2,49],$Vz=[2,50],$VA=[1,106],$VB=[18,20,32],$VC=[2,82],$VD=[2,83],$VE=[2,84],$VF=[18,20,24,32];
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,25],$V3=[1,26],$V4=[1,23],$V5=[1,21],$V6=[1,22],$V7=[1,24],$V8=[1,27],$V9=[1,11],$Va=[1,28],$Vb=[1,20],$Vc=[1,31],$Vd=[4,6,8,10,12,14,16,30,38,40,47,60,63],$Ve=[2,68],$Vf=[1,35],$Vg=[1,38],$Vh=[4,6,8,10,12,14,16,18,20,22,24,30,32,34,38,40,47,60,63],$Vi=[2,89],$Vj=[1,56],$Vk=[2,71],$Vl=[2,72],$Vm=[4,6,8,10,12,14,16,18,20,22,24,30,32,34,36,38,40,47,60,63],$Vn=[4,6,8],$Vo=[2,27],$Vp=[4,6,8,10,12,14,16,18,20,22,24,26,30,32,34,38,40,47,60,63],$Vq=[2,33],$Vr=[1,82],$Vs=[1,84],$Vt=[20,32],$Vu=[4,6,8,10,12,14,16,30,38,40,60,63],$Vv=[1,89],$Vw=[1,93],$Vx=[18,22,32],$Vy=[1,96],$Vz=[2,50],$VA=[2,51],$VB=[1,108],$VC=[18,20,32],$VD=[2,83],$VE=[2,84],$VF=[2,85],$VG=[18,20,24,32];
119
119
  var parser = {trace: function trace () { },
120
120
  yy: {},
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,"labelled_codes":50,"non_empty_labelled_codes":51,"code_label":52,"filter_":53,"labelled_filters":54,"filter":55,"non_empty_labelled_filters":56,"filter_label":57,"exp":58,"CARET":59,"labelled":60,"list":61,"PIPE":62,"non_empty_labelled":63,"comp_label":64,"non_empty_list":65,"$accept":0,"$end":1},
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",59:"CARET",62:"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,1],[48,3],[48,3],[48,3],[50,0],[50,1],[51,1],[51,3],[52,2],[52,2],[52,2],[52,3],[52,3],[52,3],[53,2],[53,3],[53,3],[53,3],[53,3],[55,1],[55,3],[55,1],[54,0],[54,1],[56,1],[56,3],[57,1],[57,2],[57,2],[57,2],[57,3],[57,3],[57,3],[46,1],[46,2],[46,2],[58,3],[58,3],[58,3],[58,1],[58,2],[58,3],[58,1],[58,1],[58,2],[58,2],[58,2],[58,2],[58,2],[58,1],[60,0],[60,1],[63,1],[63,3],[64,2],[64,2],[64,2],[64,3],[64,3],[64,3],[61,0],[61,1],[65,1],[65,3]],
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
+ 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]],
124
124
  performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
125
125
  /* this == yyval */
126
126
 
@@ -158,25 +158,28 @@ break;
158
158
  case 27:
159
159
  this.$ = { code: "ref", ref: $$[$0].value, start: $$[$0].start, end: $$[$0].end};
160
160
  break;
161
- case 28: case 47: case 61: case 89:
161
+ case 28:
162
+ this.$ = { code: "ref", ref: "@" + $$[$0].value, start: $$[$0-1].start, end: $$[$0].end};
163
+ break;
164
+ case 29: case 48: case 62: case 90:
162
165
  this.$ = $$[$0];
163
166
  break;
164
- case 29:
167
+ case 30:
165
168
  if (Object.keys($$[$0-1]).length == 1)
166
169
  this.$ = { code: "union", union: $$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
167
170
  else
168
171
  this.$ = { code: "product", product: $$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
169
172
  break;
170
- case 30:
173
+ case 31:
171
174
  this.$ = { code: "vector", vector: s.as_ref($$[$0-1]), start: $$[$0-2].start, end: $$[$0].end };
172
175
  break;
173
- case 31:
176
+ case 32:
174
177
  this.$ = { code: "union", union: $$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
175
178
  break;
176
- case 32:
179
+ case 33:
177
180
  this.$ = {};
178
181
  break;
179
- case 33:
182
+ case 34:
180
183
  this.$ = $$[$0].reduce((r, lc) => {
181
184
  if (r[lc.label])
182
185
  anError(this._$,`Duplicate label '${lc.label}'.`);
@@ -184,49 +187,49 @@ case 33:
184
187
  return r }
185
188
  , {});
186
189
  break;
187
- case 34: case 52: case 90:
190
+ case 35: case 53: case 91:
188
191
  this.$ = [$$[$0]];
189
192
  break;
190
- case 35: case 53: case 91:
193
+ case 36: case 54: case 92:
191
194
  this.$ = [].concat($$[$0-2],$$[$0]);
192
195
  break;
193
- case 36: case 37: case 38:
196
+ case 37: case 38: case 39:
194
197
  this.$ = {label: $$[$0].value, code: $$[$0-1]};
195
198
  break;
196
- case 39: case 40: case 41:
199
+ case 40: case 41: case 42:
197
200
  this.$ = {label: $$[$0-2].value, code: $$[$0]};
198
201
  break;
199
- case 42:
202
+ case 43:
200
203
  this.$ = { type: "code", code: s.as_ref($$[$0]), start: $$[$0-1].start, end: $$[$0].end};
201
204
  break;
202
- case 43:
205
+ case 44:
203
206
  if ( !$$[$0-1].open && (Object.keys($$[$0-1].fields).length == 1))
204
207
  this.$ = { type: "union", open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
205
208
  else
206
209
  this.$ = { type: null, open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
207
210
  break;
208
- case 44:
211
+ case 45:
209
212
  this.$ = { type: "union", open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
210
213
  break;
211
- case 45:
214
+ case 46:
212
215
  if ( !$$[$0-1].open && (Object.keys($$[$0-1].fields).length == 1))
213
216
  this.$ = { type: "union", open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
214
217
  else
215
218
  this.$ = { type: "product", open: $$[$0-1].open, fields: $$[$0-1].fields, start: $$[$0-2].start, end: $$[$0].end};
216
219
  break;
217
- case 46:
220
+ case 47:
218
221
  this.$ = { type: "vector", vector: $$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
219
222
  break;
220
- case 48:
223
+ case 49:
221
224
  this.$ = { name: $$[$0].value, ...$$[$0-2], start: $$[$0-2].start, end: $$[$0].end };
222
225
  break;
223
- case 49:
226
+ case 50:
224
227
  this.$ = { type: 'name', name: $$[$0].value, open: true, start: $$[$0].start, end: $$[$0].end};
225
228
  break;
226
- case 50:
229
+ case 51:
227
230
  this.$ = { fields: {}};
228
231
  break;
229
- case 51:
232
+ case 52:
230
233
  this.$ = $$[$0].reduce((r, lc) => {
231
234
  if (lc.dots) {
232
235
  r.open = true;
@@ -238,61 +241,61 @@ case 51:
238
241
  return r }
239
242
  , { fields: {} });
240
243
  break;
241
- case 54:
244
+ case 55:
242
245
  this.$ = {dots: true };
243
246
  break;
244
- case 55: case 56: case 57:
247
+ case 56: case 57: case 58:
245
248
  this.$ = {label: $$[$0].value, filter: $$[$0-1]};
246
249
  break;
247
- case 58: case 59: case 60:
250
+ case 59: case 60: case 61:
248
251
  this.$ = {label: $$[$0-2].value, filter: $$[$0]};
249
252
  break;
250
- case 62:
253
+ case 63:
251
254
  this.$ = {...comp($$[$0-1], $$[$0]), start: $$[$0-1].start, end:$$[$0].end};
252
255
  break;
253
- case 63:
256
+ case 64:
254
257
  this.$ = {op: 'caret', caret: $$[$0-1], start: $$[$0-1].start, end:$$[$0].end};
255
258
  break;
256
- case 64:
259
+ case 65:
257
260
  this.$ = {...$$[$0-1], start: $$[$0-2].start, end: $$[$0].end};
258
261
  break;
259
- case 65:
262
+ case 66:
260
263
  this.$ = {op: "vector", vector: $$[$0-1], start: $$[$0-2].start, end: $$[$0].end};
261
264
  break;
262
- case 66:
265
+ case 67:
263
266
  this.$ = {...union($$[$0-1]), start: $$[$0-2].start, end: $$[$0].end};
264
267
  break;
265
- case 67:
268
+ case 68:
266
269
  this.$ = {op: "ref", ref: $$[$0].value, start: $$[$0].start, end: $$[$0].end};
267
270
  break;
268
- case 68:
271
+ case 69:
269
272
  this.$ = {...identity, start: $$[$0-1].start, end: $$[$0].end};
270
273
  break;
271
- case 69:
274
+ case 70:
272
275
  this.$ = {...$$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
273
276
  break;
274
- case 70:
277
+ case 71:
275
278
  this.$ = {op: "str", str: $$[$0].value, start: $$[$0].start, end: $$[$0].end };
276
279
  break;
277
- case 71:
280
+ case 72:
278
281
  this.$ = {op: "int", int: $$[$0].value, start: $$[$0].start, end: $$[$0].end };
279
282
  break;
280
- case 72: case 73: case 74:
283
+ case 73: case 74: case 75:
281
284
  this.$ = {op: "dot", dot: $$[$0].value, start: $$[$0-1].start, end: $$[$0].end };
282
285
  break;
283
- case 75:
286
+ case 76:
284
287
  this.$ = {op: "code", code: s.as_ref($$[$0]), start: $$[$0-1].start, end: $$[$0].end};
285
288
  break;
286
- case 76:
289
+ case 77:
287
290
  this.$ = {op: "filter", filter: $$[$0], start: $$[$0-1].start, end:$$[$0].end};
288
291
  break;
289
- case 77:
292
+ case 78:
290
293
  this.$ = {op: "pipe", start: $$[$0].start, end: $$[$0].end};
291
294
  break;
292
- case 78:
295
+ case 79:
293
296
  this.$ = {op: "product", product: []};
294
297
  break;
295
- case 79:
298
+ case 80:
296
299
  $$[$0].product.reduce( (labels, {label}) =>
297
300
  { if (labels[label])
298
301
  anError(this._$,`Duplicate label '${label}'.`)
@@ -300,24 +303,24 @@ case 79:
300
303
  return labels; }, {});
301
304
  this.$ = $$[$0];
302
305
  break;
303
- case 80:
306
+ case 81:
304
307
  this.$ = {op: "product", product: [$$[$0]]};
305
308
  break;
306
- case 81:
309
+ case 82:
307
310
  $$[$0-2].product = [].concat($$[$0-2].product,$$[$0]); this.$ = $$[$0-2];
308
311
  break;
309
- case 82: case 83: case 84:
312
+ case 83: case 84: case 85:
310
313
  this.$ = {label: $$[$0].value, exp: $$[$0-1]};
311
314
  break;
312
- case 85: case 86: case 87:
315
+ case 86: case 87: case 88:
313
316
  this.$ = {label: $$[$0-2].value, exp: $$[$0]};
314
317
  break;
315
- case 88:
318
+ case 89:
316
319
  this.$ = [];
317
320
  break;
318
321
  }
319
322
  },
320
- 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:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:8,38:$V9,39:19,40:$Va,46:6,58:9,62:$Vb},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,47:[1,29],58:30,59:$Vc,62:$Vb},o($Vd,$Ve,{25:34,26:$Vf}),{3:36,4:$V1,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:38,49:37},o($Vg,[2,61]),o([4,6,8,10,12,14,16,18,20,22,24,26,30,32,34,36,38,40,47,59,62],[2,1]),o([4,10,12,14],[2,18]),{3:46,4:$V1,5:47,6:$V2,7:48,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,20:[2,78],29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:45,58:9,60:42,62:$Vb,63:43,64:44},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,22:$Vh,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:51,58:9,61:49,62:$Vb,65:50},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,18:$Vh,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:51,58:9,61:52,62:$Vb,65:50},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,23:53,24:$Vi,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:54,58:9,62:$Vb},o($Vg,$Vj),o($Vg,$Vk),{3:58,4:$V1,5:57,6:$V2,7:56,8:$V3},{3:61,4:$V1,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,37:62,38:$V9,53:60,55:59},o($Vg,[2,77]),o([4,6,8,10,12,14,16,20,28,30,38,40,62],[2,5]),o([4,6,8,10,12,14,16,22,30,38,40,62],[2,6]),o([4,6,8,10,12,14,16,18,28,30,38,40,62],[2,4]),o([4,6,8,10,12,14,16,24,28,30,38,40,62],[2,7]),o($Vl,[2,2]),o($Vl,[2,3]),o($Vm,[2,14]),o([4,10,12,14,16,38],[2,19]),{1:[2,21]},o($Vg,[2,62]),o($Vg,[2,63]),o($Vg,$Ve),{3:67,4:$V1,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:38,49:37},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:68,58:9,62:$Vb},o($V0,[2,12]),o($Vd,$Vn,{25:69,26:$Vf}),o($Vg,[2,75]),o($Vo,[2,28]),{3:74,4:$V1,5:75,6:$V2,7:76,8:$V3,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,20:$Vp,48:38,49:73,50:70,51:71,52:72},{3:67,4:$V1,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:38,49:77},{3:74,4:$V1,5:75,6:$V2,7:76,8:$V3,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,18:$Vp,48:38,49:73,50:78,51:71,52:72},{19:79,20:$Vq},{20:[2,79],31:81,32:$Vr},o($Vs,[2,80]),{3:83,4:$V1,5:84,6:$V2,7:85,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,58:30,59:$Vc,62:$Vb},o($Vt,$Ve,{35:86,36:$Vu}),o($Vt,$Vj,{35:88,36:$Vu}),o($Vt,$Vk,{35:89,36:$Vu}),{21:90,22:$Vv},o([18,22],[2,89],{31:92,32:$Vr}),o($Vw,[2,90],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,58:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,59:$Vc,62:$Vb}),{17:93,18:$Vx},o($Vg,[2,68]),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,23:95,24:$Vi,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,58:30,59:$Vc,62:$Vb},o($Vo,[2,11]),o($Vg,[2,72]),o($Vg,[2,73]),o($Vg,[2,74]),o($Vg,[2,76]),o($Vg,[2,47],{26:[1,96]}),o($Vg,$Vy),{3:67,4:$V1,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:38,49:97},{3:103,4:$V1,5:104,6:$V2,7:105,8:$V3,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,24:$Vz,27:101,28:$VA,37:62,38:$V9,53:60,54:98,55:102,56:99,57:100},{3:103,4:$V1,5:104,6:$V2,7:105,8:$V3,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,18:$Vz,27:101,28:$VA,37:62,38:$V9,53:60,54:107,55:102,56:99,57:100},{3:103,4:$V1,5:104,6:$V2,7:105,8:$V3,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,20:$Vz,27:101,28:$VA,37:62,38:$V9,53:60,54:108,55:102,56:99,57:100},{3:61,4:$V1,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,37:62,38:$V9,53:60,55:109},o($Vo,$Vn),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,33:110,34:[1,111],37:33,38:$V9,39:19,40:$Va,58:30,59:$Vc,62:$Vb},{9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:112},{19:113,20:$Vq},o([18,20],[2,33],{31:114,32:$Vr}),o($VB,[2,34]),{3:115,4:$V1,5:116,6:$V2,7:117,8:$V3},o($Vm,$Vn,{35:118,36:$Vu}),{35:119,36:$Vu},{35:120,36:$Vu},{21:121,22:$Vv},{17:122,18:$Vx},o($Vg,[2,64]),o($Vo,[2,9]),{3:46,4:$V1,5:47,6:$V2,7:48,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:45,58:9,62:$Vb,64:123},o([4,6,8,10,12,14,16,28,30,38,40,62],[2,15]),o($Vt,$Ve,{20:$VC,32:$VC}),o($Vt,$Vj,{20:$VD,32:$VD}),o($Vt,$Vk,{20:$VE,32:$VE}),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:124,58:9,62:$Vb},o($V0,[2,17]),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:125,58:9,62:$Vb},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:126,58:9,62:$Vb},o($Vg,[2,65]),o($Vo,[2,10]),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:127,58:9,62:$Vb},o($Vg,[2,66]),o($Vo,[2,8]),o($Vg,[2,69]),{3:128,4:$V1},o($Vo,[2,42]),{23:129,24:$Vi},o([18,20,24],[2,51],{31:130,32:$Vr}),o($VF,[2,52]),o($VF,[2,54]),{3:131,4:$V1,5:132,6:$V2,7:133,8:$V3},o($Vm,$Vy,{35:134,36:$Vu}),{35:135,36:$Vu},{35:136,36:$Vu},o($VF,[2,13]),{17:137,18:$Vx},{19:138,20:$Vq},{21:139,22:$Vv},o($V0,[2,25]),o($V0,[2,16]),{34:[1,140]},o($Vo,[2,29]),{3:74,4:$V1,5:75,6:$V2,7:76,8:$V3,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:38,49:73,52:141},o($VB,[2,36]),o($VB,[2,37]),o($VB,[2,38]),{3:67,4:$V1,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:38,49:142},{3:67,4:$V1,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:38,49:143},{3:67,4:$V1,9:41,10:$V4,11:39,12:$V5,13:40,14:$V6,48:38,49:144},o($Vo,[2,30]),o($Vo,[2,31]),o($Vs,[2,81]),o($Vs,[2,85],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,58:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,59:$Vc,62:$Vb}),o($Vs,[2,86],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,58:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,59:$Vc,62:$Vb}),o($Vs,[2,87],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,58:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,59:$Vc,62:$Vb}),o($Vw,[2,91],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,58:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,59:$Vc,62:$Vb}),o($Vg,[2,48]),o($Vo,[2,43]),{3:103,4:$V1,5:104,6:$V2,7:105,8:$V3,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,27:101,28:$VA,37:62,38:$V9,53:60,55:102,57:145},o($VF,[2,55]),o($VF,[2,56]),o($VF,[2,57]),{3:61,4:$V1,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,37:62,38:$V9,53:60,55:146},{3:61,4:$V1,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,37:62,38:$V9,53:60,55:147},{3:61,4:$V1,9:64,10:$V4,11:65,12:$V5,13:66,14:$V6,15:63,16:$V7,37:62,38:$V9,53:60,55:148},o($Vo,[2,44]),o($Vo,[2,45]),o($Vo,[2,46]),o($V0,[2,26]),o($VB,[2,35]),o($VB,[2,39]),o($VB,[2,40]),o($VB,[2,41]),o($VF,[2,53]),o($VF,[2,58]),o($VF,[2,59]),o($VF,[2,60])],
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:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:8,38:$V9,39:19,40:$Va,46:6,59:9,63:$Vb},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,47:[1,29],59:30,60:$Vc,63:$Vb},o($Vd,$Ve,{25:34,26:$Vf}),{3:36,4:$V1,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:39,49:37,50:$Vg},o($Vh,[2,62]),o([4,6,8,10,12,14,16,18,20,22,24,26,30,32,34,36,38,40,47,60,63],[2,1]),o([4,10,12,14,50],[2,18]),{3:47,4:$V1,5:48,6:$V2,7:49,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,20:[2,79],29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:46,59:9,61:43,63:$Vb,64:44,65:45},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,22:$Vi,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:52,59:9,62:50,63:$Vb,66:51},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,18:$Vi,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:52,59:9,62:53,63:$Vb,66:51},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,23:54,24:$Vj,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:55,59:9,63:$Vb},o($Vh,$Vk),o($Vh,$Vl),{3:59,4:$V1,5:58,6:$V2,7:57,8:$V3},{3:62,4:$V1,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,37:63,38:$V9,54:61,56:60},o($Vh,[2,78]),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,63],[2,7]),o($Vm,[2,2]),o($Vm,[2,3]),o($Vn,[2,14]),o([4,10,12,14,16,38],[2,19]),{1:[2,21]},o($Vh,[2,63]),o($Vh,[2,64]),o($Vh,$Ve),{3:68,4:$V1,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:39,49:37,50:$Vg},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:69,59:9,63:$Vb},o($V0,[2,12]),o($Vd,$Vo,{25:70,26:$Vf}),o($Vh,[2,76]),{3:71,4:$V1},o($Vp,[2,29]),{3:76,4:$V1,5:77,6:$V2,7:78,8:$V3,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,20:$Vq,48:39,49:75,50:$Vg,51:72,52:73,53:74},{3:68,4:$V1,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:39,49:79,50:$Vg},{3:76,4:$V1,5:77,6:$V2,7:78,8:$V3,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,18:$Vq,48:39,49:75,50:$Vg,51:80,52:73,53:74},{19:81,20:$Vr},{20:[2,80],31:83,32:$Vs},o($Vt,[2,81]),{3:85,4:$V1,5:86,6:$V2,7:87,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,59:30,60:$Vc,63:$Vb},o($Vu,$Ve,{35:88,36:$Vv}),o($Vu,$Vk,{35:90,36:$Vv}),o($Vu,$Vl,{35:91,36:$Vv}),{21:92,22:$Vw},o([18,22],[2,90],{31:94,32:$Vs}),o($Vx,[2,91],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,59:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,60:$Vc,63:$Vb}),{17:95,18:$Vy},o($Vh,[2,69]),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,23:97,24:$Vj,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,59:30,60:$Vc,63:$Vb},o($Vp,[2,11]),o($Vh,[2,73]),o($Vh,[2,74]),o($Vh,[2,75]),o($Vh,[2,77]),o($Vh,[2,48],{26:[1,98]}),o($Vh,$Vz),{3:68,4:$V1,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:39,49:99,50:$Vg},{3:105,4:$V1,5:106,6:$V2,7:107,8:$V3,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,24:$VA,27:103,28:$VB,37:63,38:$V9,54:61,55:100,56:104,57:101,58:102},{3:105,4:$V1,5:106,6:$V2,7:107,8:$V3,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,18:$VA,27:103,28:$VB,37:63,38:$V9,54:61,55:109,56:104,57:101,58:102},{3:105,4:$V1,5:106,6:$V2,7:107,8:$V3,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,20:$VA,27:103,28:$VB,37:63,38:$V9,54:61,55:110,56:104,57:101,58:102},{3:62,4:$V1,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,37:63,38:$V9,54:61,56:111},o($Vp,$Vo),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,33:112,34:[1,113],37:33,38:$V9,39:19,40:$Va,59:30,60:$Vc,63:$Vb},{9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:114},o($Vp,[2,28]),{19:115,20:$Vr},o([18,20],[2,34],{31:116,32:$Vs}),o($VC,[2,35]),{3:117,4:$V1,5:118,6:$V2,7:119,8:$V3},o($Vn,$Vo,{35:120,36:$Vv}),{35:121,36:$Vv},{35:122,36:$Vv},{21:123,22:$Vw},{17:124,18:$Vy},o($Vh,[2,65]),o($Vp,[2,9]),{3:47,4:$V1,5:48,6:$V2,7:49,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:46,59:9,63:$Vb,65:125},o([4,6,8,10,12,14,16,28,30,38,40,50,63],[2,15]),o($Vu,$Ve,{20:$VD,32:$VD}),o($Vu,$Vk,{20:$VE,32:$VE}),o($Vu,$Vl,{20:$VF,32:$VF}),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:126,59:9,63:$Vb},o([4,6,8,10,12,14,16,30,38,40,50,63],[2,17]),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:127,59:9,63:$Vb},{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:128,59:9,63:$Vb},o($Vh,[2,66]),o($Vp,[2,10]),{3:32,4:$V1,5:16,6:$V2,7:17,8:$V3,9:14,10:$V4,11:12,12:$V5,13:13,14:$V6,15:15,16:$V7,29:18,30:$V8,37:33,38:$V9,39:19,40:$Va,46:129,59:9,63:$Vb},o($Vh,[2,67]),o($Vp,[2,8]),o($Vh,[2,70]),{3:130,4:$V1},o($Vp,[2,43]),{23:131,24:$Vj},o([18,20,24],[2,52],{31:132,32:$Vs}),o($VG,[2,53]),o($VG,[2,55]),{3:133,4:$V1,5:134,6:$V2,7:135,8:$V3},o($Vn,$Vz,{35:136,36:$Vv}),{35:137,36:$Vv},{35:138,36:$Vv},o($VG,[2,13]),{17:139,18:$Vy},{19:140,20:$Vr},{21:141,22:$Vw},o($V0,[2,25]),o($V0,[2,16]),{34:[1,142]},o($Vp,[2,30]),{3:76,4:$V1,5:77,6:$V2,7:78,8:$V3,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:39,49:75,50:$Vg,53:143},o($VC,[2,37]),o($VC,[2,38]),o($VC,[2,39]),{3:68,4:$V1,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:39,49:144,50:$Vg},{3:68,4:$V1,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:39,49:145,50:$Vg},{3:68,4:$V1,9:42,10:$V4,11:40,12:$V5,13:41,14:$V6,48:39,49:146,50:$Vg},o($Vp,[2,31]),o($Vp,[2,32]),o($Vt,[2,82]),o($Vt,[2,86],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,59:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,60:$Vc,63:$Vb}),o($Vt,[2,87],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,59:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,60:$Vc,63:$Vb}),o($Vt,[2,88],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,59:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,60:$Vc,63:$Vb}),o($Vx,[2,92],{11:12,13:13,9:14,15:15,5:16,7:17,29:18,39:19,59:30,3:32,37:33,4:$V1,6:$V2,8:$V3,10:$V4,12:$V5,14:$V6,16:$V7,30:$V8,38:$V9,40:$Va,60:$Vc,63:$Vb}),o($Vh,[2,49]),o($Vp,[2,44]),{3:105,4:$V1,5:106,6:$V2,7:107,8:$V3,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,27:103,28:$VB,37:63,38:$V9,54:61,56:104,58:147},o($VG,[2,56]),o($VG,[2,57]),o($VG,[2,58]),{3:62,4:$V1,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,37:63,38:$V9,54:61,56:148},{3:62,4:$V1,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,37:63,38:$V9,54:61,56:149},{3:62,4:$V1,9:65,10:$V4,11:66,12:$V5,13:67,14:$V6,15:64,16:$V7,37:63,38:$V9,54:61,56:150},o($Vp,[2,45]),o($Vp,[2,46]),o($Vp,[2,47]),o($V0,[2,26]),o($VC,[2,36]),o($VC,[2,40]),o($VC,[2,41]),o($VC,[2,42]),o($VG,[2,54]),o($VG,[2,59]),o($VG,[2,60]),o($VG,[2,61])],
321
324
  defaultActions: {29:[2,21]},
322
325
  parseError: function parseError (str, hash) {
323
326
  if (hash.recoverable) {
@@ -830,24 +833,26 @@ case 17:return 38;
830
833
  break;
831
834
  case 18:return 40;
832
835
  break;
833
- case 19:return 62;
836
+ case 19:return 63;
837
+ break;
838
+ case 20:return 60;
834
839
  break;
835
- case 20:return 59;
840
+ case 21:return 50;
836
841
  break;
837
- case 21:return 6;
842
+ case 22:return 6;
838
843
  break;
839
- case 22:return 4;
844
+ case 23:return 4;
840
845
  break;
841
- case 23:return 8;
846
+ case 24:return 8;
842
847
  break;
843
- case 24:return 42;
848
+ case 25:return 42;
844
849
  break;
845
- case 25:return 47;
850
+ case 26:return 47;
846
851
  break;
847
852
  }
848
853
  },
849
- rules: [/^(?:[/][*]([^*]*[*]+[^*/])*[^*]*[*]+[/])/,/^(?:(\/\/|#|%|--|\\)[^\n]*)/,/^(?:\s+)/,/^(?:<)/,/^(?:\{)/,/^(?:\[)/,/^(?:\()/,/^(?:>)/,/^(?:\})/,/^(?:\])/,/^(?:\))/,/^(?:=)/,/^(?:\.\.\.)/,/^(?:\.)/,/^(?:,)/,/^(?:;)/,/^(?::)/,/^(?:\$)/,/^(?:\?)/,/^(?:\|)/,/^(?:\^)/,/^(?:"([^"\\]|\\(.|\n))*"|'([^'\\]|\\(.|\n))*')/,/^(?:[a-zA-Z_][a-zA-Z0-9_?!]*)/,/^(?:0|[-]?[1-9][0-9]*)/,/^(?:\+\+\+)/,/^(?:$)/],
850
- 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,23,24,25],"inclusive":true}}
854
+ rules: [/^(?:[/][*]([^*]*[*]+[^*/])*[^*]*[*]+[/])/,/^(?:(\/\/|#|%|--|\\)[^\n]*)/,/^(?:\s+)/,/^(?:<)/,/^(?:\{)/,/^(?:\[)/,/^(?:\()/,/^(?:>)/,/^(?:\})/,/^(?:\])/,/^(?:\))/,/^(?:=)/,/^(?:\.\.\.)/,/^(?:\.)/,/^(?:,)/,/^(?:;)/,/^(?::)/,/^(?:\$)/,/^(?:\?)/,/^(?:\|)/,/^(?:\^)/,/^(?:@)/,/^(?:"([^"\\]|\\(.|\n))*"|'([^'\\]|\\(.|\n))*')/,/^(?:[a-zA-Z_][a-zA-Z0-9_?!]*)/,/^(?:0|[-]?[1-9][0-9]*)/,/^(?:\+\+\+)/,/^(?:$)/],
855
+ 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,23,24,25,26],"inclusive":true}}
851
856
  });
852
857
  return lexer;
853
858
  })();
package/patterns.mjs CHANGED
@@ -8,7 +8,7 @@ import { assignCanonicalNames } from "./export.mjs";
8
8
  const unitCode = codes.unitCode;
9
9
 
10
10
  function relDefToString(relDef) {
11
-
11
+ const start = new Date().getTime();
12
12
  const dumpPatterns = (rel) => {
13
13
  switch (rel.op) {
14
14
  case "product":
@@ -39,14 +39,20 @@ function relDefToString(relDef) {
39
39
  // console.log(relDef.typePatternGraph.edges);
40
40
  // console.log(relDef.def);
41
41
 
42
- return JSON.stringify(dumpPatterns(relDef.def).map((x) => {
42
+ const result = JSON.stringify(dumpPatterns(relDef.def).map((x) => {
43
43
  const { pattern, fields, type} = relDef.typePatternGraph.get_pattern(x);
44
44
  return {pattern, fields, type};
45
45
  }));
46
+
47
+ let took = new Date().getTime() - start;
48
+ if (took > 200) {
49
+ console.log(` -- RelDefToString: size=${result.length}, took ${took} msecs`);
50
+ }
51
+ return result;
46
52
  }
47
53
 
48
54
  function compactRel(relDef, name = "") {
49
- // console.log("********************************* compacting", name);
55
+ const start = new Date().getTime();
50
56
  const {def, typePatternGraph, varRefs } = relDef;
51
57
  // console.log("COMPACTING typePatternGraph of size", typePatternGraph.size());
52
58
 
@@ -92,7 +98,10 @@ function compactRel(relDef, name = "") {
92
98
  outputPatternId: renumbering[x.outputPatternId]
93
99
  }));;
94
100
 
95
- // console.log(`COMPACTED ${name}.typePatternGraph`, typePatternGraph.size(), '->', newTypePatternGraph.size());
101
+ const time = new Date().getTime() - start;
102
+ if (time > 500 ) {
103
+ console.log(`[${new Date().getTime() - start} msecs] - COMPACTED ${name}.typePatternGraph [${typePatternGraph.size()}->${newTypePatternGraph.size()}]`);
104
+ }
96
105
  return {def: newDef, typePatternGraph: newTypePatternGraph, varRefs: newVarRefs};
97
106
  }
98
107
 
@@ -462,7 +471,7 @@ function patterns(representatives, rels) {
462
471
  // we will also generate the canonical representation of the relations in C and replace
463
472
  // the name to the relation by the hash of the canonical representation
464
473
 
465
- // console.log("----- SCC in order", sccInOrder);
474
+ // console.log("- SCC in order", sccInOrder);
466
475
 
467
476
  for (const scc of sccInOrder) {
468
477
 
@@ -470,7 +479,7 @@ function patterns(representatives, rels) {
470
479
 
471
480
  for (let iteration = 1; iteration <= maxNumberOfIterations; iteration++) {
472
481
 
473
- // console.log(`>>>>>> Iteration ${iteration} for SCC: { ${DAGnodes[scc].scc} }`);
482
+ // console.log(`-- Iteration ${iteration}/${maxNumberOfIterations} for SCC: { ${DAGnodes[scc].scc} }`);
474
483
  // 4.1 For every r in C, compute the new typePatternGraph of r, i.e.:
475
484
 
476
485
  let before = JSON.stringify(DAGnodes[scc].scc.map( relName => {
@@ -481,11 +490,11 @@ function patterns(representatives, rels) {
481
490
  // console.log(relDefToString(rels[relName]));
482
491
  return relDefToString(rels[relName]);
483
492
  }));
484
-
493
+
485
494
  let after = JSON.stringify(DAGnodes[scc].scc.map( relName => {
486
495
  const relDef = compactRel(rels[relName],relName);
487
496
  for (let i = 0; i < relDef.varRefs.length; i++) {
488
- // console.log(` ####### Processing ${relName}(..x${i}=${relDef.varRefs[i].varName}..)`);
497
+ const start = new Date().getTime();
489
498
  let varRel = relDef.varRefs[i];
490
499
  let { varName } = varRel;
491
500
  try {
@@ -493,7 +502,6 @@ function patterns(representatives, rels) {
493
502
  let varInputPatternId = varRootDef.typePatternGraph.find(varRootDef.def.patterns[0]);
494
503
  let varOutputPatternId = varRootDef.typePatternGraph.find(varRootDef.def.patterns[1]);
495
504
  let cloned = varRootDef.typePatternGraph.clone([varInputPatternId, varOutputPatternId], relDef.typePatternGraph);
496
-
497
505
  relDef.typePatternGraph.unify(`ref:input ${relName}(${varName})`, varRel.inputPatternId, cloned[varInputPatternId]);
498
506
  relDef.typePatternGraph.unify("ref:output", varRel.outputPatternId, cloned[varOutputPatternId]);
499
507
  } catch (e) {
@@ -502,6 +510,10 @@ function patterns(representatives, rels) {
502
510
  - ${e.message}`;
503
511
  throw e;
504
512
  }
513
+ const tookMs = new Date().getTime() - start;
514
+ if (tookMs > 200) {
515
+ console.log(` ---- Processing ${relName}(.., x${i}=${relDef.varRefs[i].varName}, ..) took: ${tookMs} ms`);
516
+ }
505
517
  }
506
518
  rels[relName] = compactRel(relDef,relName);
507
519
  return relDefToString(rels[relName]);
package/typing.mjs CHANGED
@@ -3,20 +3,36 @@ import codes from "./codes.mjs";
3
3
 
4
4
  const unitCode = codes.unitCode;
5
5
 
6
- function asMapSet(vector) {
7
- return vector.reduce( (mapSet, x) => ({...mapSet, [JSON.stringify(x)]: x}), {})
6
+ function asSet(vector) {
7
+ return Array.from(new Set(vector));
8
8
  };
9
9
 
10
10
  function setUnion(...vectors) {
11
- return Object.values(asMapSet([].concat(...vectors)));
11
+ const unionSet = new Set();
12
+ for (const v of vectors) {
13
+ for (const element of v) {
14
+ unionSet.add(element);
15
+ }
16
+ }
17
+ return Array.from(unionSet);
12
18
  }
13
19
 
14
20
  function subsetP(v1,v2) {
15
- const v2Set = asMapSet(v2);
16
- return Object.keys(asMapSet(v1)).every(x => x in v2Set);
21
+ const v2Set = new Set(v2);
22
+ return v1.every(x => v2Set.has(x));
17
23
  }
24
+
18
25
  function eqsetP(v1,v2) {
19
- return subsetP(v1,v2) && subsetP(v2,v1);
26
+ const v1Set = new Set(v1);
27
+ const v2Set = new Set(v2);
28
+ if (v1Set.size != v2Set.size) return false;
29
+
30
+ for (const value of v1Set) {
31
+ if (!v2Set.has(value)) {
32
+ return false;
33
+ }
34
+ }
35
+ return true;
20
36
  }
21
37
 
22
38
  const matchAllPattern = {pattern: '(...)', fields: []};
@@ -76,7 +92,7 @@ class TypePatternForest {
76
92
  // const node = {...flatTypePattern, _id: id};
77
93
  const node = {...flatTypePattern}
78
94
  that.nodes.push(node);
79
- Object.values(asMapSet(children.map(that.find.bind(that))))
95
+ Array.from(new Set(children.map(that.find.bind(that))))
80
96
  .forEach(rep => {that.parent[rep] = id});
81
97
  return id;
82
98
  }
@@ -139,7 +155,6 @@ class TypePatternGraph {
139
155
  for( const id of singletonPatterns) {
140
156
  this.unify('singleton', id, this.getTypeId(representatives[`-${id}-`]));
141
157
  }
142
-
143
158
  }
144
159
 
145
160
 
@@ -165,27 +180,29 @@ class TypePatternGraph {
165
180
  )
166
181
  );
167
182
 
168
- const gEdgesWithoutParrallelEdges = Object.values(asMapSet(gEdges));
169
-
183
+ const gEdgesWithoutParrallelEdges = Array.from(new Set(gEdges));
170
184
  const gGraph = new Graph(gEdgesWithoutParrallelEdges);
171
185
  const queue = gNodes.filter(x =>
172
186
  this.patterns.nodes[x].pattern in {'()':1, '(...)':1,'{...}':1, '<...>':1});
173
- const excluded = asMapSet(queue);
187
+ const excludedSet = new Set(queue);
188
+
174
189
  while (queue.length > 0) {
175
190
  const x = queue.pop();
176
191
  for (const e of gGraph.dst[x] || []) {
177
192
  const y = gGraph.edges[e].src;
178
- if (y in excluded) continue;
179
- excluded[y] = y;
193
+ if (excludedSet.has(y)) continue;
194
+ excludedSet.add(y);
180
195
  queue.push(y);
181
196
  }
182
197
  }
183
- return gNodes.filter(x => !((x in excluded) || (this.patterns.nodes[x].pattern == 'type')));
198
+
199
+ return gNodes.filter(x => !((excludedSet.has(x)) || (this.patterns.nodes[x].pattern == 'type')));
184
200
  }
185
201
 
186
202
  getCompressed() {
187
203
  const newTypePatternGraph = new TypePatternGraph();
188
204
  const renamed = this.cloneAll(newTypePatternGraph);
205
+
189
206
  newTypePatternGraph.turnSingletonPatternsIntoCodes();
190
207
 
191
208
  Object.keys(renamed).forEach( id => {
@@ -223,7 +240,9 @@ class TypePatternGraph {
223
240
 
224
241
  // console.log("equivalence", equivalence);
225
242
 
243
+ let count = 0;
226
244
  const areDifferent = (i1,i2) => {
245
+ count++;
227
246
  const p1 = newTypePatternGraph.get_pattern(i1);
228
247
  const p2 = newTypePatternGraph.get_pattern(i2);
229
248
  if (p1.pattern != p2.pattern) return true;
@@ -239,7 +258,9 @@ class TypePatternGraph {
239
258
  return false;
240
259
  }
241
260
  let changed = true;
261
+ let count2 = 0;
242
262
  while (changed) {
263
+ count2++;
243
264
  changed = false;
244
265
  const equivalenceSize = equivalence.length;
245
266
  for (let eqClassPos = 0; eqClassPos < equivalenceSize; eqClassPos++) {
@@ -285,7 +306,7 @@ class TypePatternGraph {
285
306
  for (const oldId in newIds) {
286
307
  const newId = newIds[oldId];
287
308
  const pattern = newTypePatternGraph.get_pattern(oldId);
288
- const newPattern = compressedTypePatternGraph.get_pattern(newId);
309
+ // const newPattern = compressedTypePatternGraph.get_pattern(newId);
289
310
  // console.log("patterns", pattern, newPattern);
290
311
  if (pattern.pattern == 'type')
291
312
  continue;
@@ -294,7 +315,7 @@ class TypePatternGraph {
294
315
  compressedTypePatternGraph.edges[newId] = {};
295
316
  for (const lab in edges) {
296
317
  // console.log("edges[lab]", edges[lab]);
297
- compressedTypePatternGraph.edges[newId][lab] = asMapSet(Object.values(edges[lab]).map(x =>
318
+ compressedTypePatternGraph.edges[newId][lab] = asSet(edges[lab].map(x =>
298
319
  newIds[reps[newTypePatternGraph.find(x)][0]]));
299
320
  }
300
321
  }
@@ -308,6 +329,7 @@ class TypePatternGraph {
308
329
  // console.log("nodes", compressedTypePatternGraph.patterns.nodes);
309
330
  // console.log("edges", compressedTypePatternGraph.edges);
310
331
  // console.log("--------------------")
332
+
311
333
  return {typePatternGraph: compressedTypePatternGraph, remapping};
312
334
  }
313
335
 
@@ -343,7 +365,7 @@ class TypePatternGraph {
343
365
  const new_id = result[i];
344
366
  targetGraph.edges[new_id] = {};
345
367
  for (const lab in edges) {
346
- targetGraph.edges[new_id][lab] = asMapSet(Object.values(edges[lab]).map(x => result[find(x)]));
368
+ targetGraph.edges[new_id][lab] = asSet(edges[lab].map(x => result[find(x)]));
347
369
  }
348
370
  }
349
371
  return result;
@@ -584,7 +606,7 @@ class TypePatternGraph {
584
606
 
585
607
  unify(rule, ...ids) {
586
608
  const find = (x) => this.find(x);
587
- const reps = Object.values(asMapSet(ids.map(find)));
609
+ const reps = Array.from(new Set(ids.map(find)));
588
610
  if (reps.length < 2) return false;
589
611
  const rep_patters = reps.map(x => {
590
612
  const pattern = this.get_pattern(x);
@@ -615,8 +637,8 @@ class TypePatternGraph {
615
637
  for (const lab in edges) {
616
638
  // if the pattern is [] all labels are treated as 'vector-member'
617
639
  const new_lab = new_pattern.pattern == '[]' ? 'vector-member' : lab;
618
- const dests = asMapSet(Object.values(edges[lab]).map(find));
619
- this.edges[new_id][new_lab] = {...this.edges[new_id][new_lab], ...dests};
640
+ const dests = asSet(edges[lab].map(find));
641
+ this.edges[new_id][new_lab] = asSet([...(this.edges[new_id][new_lab] || []), ...dests]);
620
642
  }
621
643
  }
622
644
  // add stuff for types
@@ -629,7 +651,7 @@ class TypePatternGraph {
629
651
  // all edges are goin to unit type
630
652
  const unit_id = this.getTypeId(unitCode);
631
653
  for (const lab in this.edges[new_id]) {
632
- this.edges[new_id][lab][unit_id] = unit_id;
654
+ this.edges[new_id][lab] = asSet([unit_id]);
633
655
  }
634
656
  }; break;
635
657
  case 'product':
@@ -637,7 +659,7 @@ class TypePatternGraph {
637
659
  const type_fields = Object.keys(code[code.code]);
638
660
  for (const lab of type_fields) {
639
661
  const target_type_id = this.getTypeId(code[code.code][lab]);
640
- this.edges[new_id][lab]= {...this.edges[new_id][lab], [target_type_id]: target_type_id};
662
+ this.edges[new_id][lab]= asSet([...(this.edges[new_id][lab] ||[]), target_type_id]);
641
663
  }
642
664
  }; break;
643
665
  case 'vector': {
@@ -645,18 +667,13 @@ class TypePatternGraph {
645
667
  const target_type_id = this.getTypeId(code.vector);
646
668
 
647
669
  this.edges[new_id] = {
648
- 'vector-member': {
649
- [target_type_id]: target_type_id,
650
- ...asMapSet(
651
- setUnion(...Object.values(this.edges[new_id]).map(aSet => Object.values(aSet)))
652
- )
653
- }
670
+ 'vector-member': asSet([ target_type_id, ...Object.values(this.edges[new_id])])
654
671
  }
655
672
  }
656
673
  }
657
674
  }
658
675
  for ( const lab of Object.keys(this.edges[new_id]) ) {
659
- this.unify(rule+'.', ...Object.values(this.edges[new_id][lab]));
676
+ this.unify(rule+'.', ...this.edges[new_id][lab]);
660
677
  }
661
678
 
662
679
  return true;
@@ -667,7 +684,7 @@ class TypePatternGraph {
667
684
  const find = (x) => this.patterns.find(x);
668
685
  this.edges[id] = {};
669
686
  for (const [lab,dest] of Object.entries(fields)) {
670
- this.edges[id][lab] = asMapSet(dest.map(find));
687
+ this.edges[id][lab] = asSet(dest.map(find));
671
688
  }
672
689
  return id;
673
690
  }