@fraczak/k 6.10.5 → 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.
Files changed (71) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/CLAUDE.md +1 -1
  3. package/DOCS/BIG_PICTURE.md +156 -172
  4. package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
  5. package/DOCS/CODEC_ARCHITECTURE.md +2 -2
  6. package/DOCS/DICTIONARY.md +243 -250
  7. package/DOCS/DIVERGENCE_DETECTION.md +0 -1
  8. package/DOCS/FILE_FORMATS.md +5 -5
  9. package/DOCS/KIR_SPECIALIZATION_DESIGN.md +1 -1
  10. package/DOCS/OBJECT_FILE_AND_PATTERN.md +12 -12
  11. package/DOCS/PATTERNS.md +17 -17
  12. package/DOCS/PATTERNS_AND_TYPED_VALUES.md +1 -1
  13. package/DOCS/REPL.md +9 -19
  14. package/DOCS/TYPE_DERIVATION.md +2 -8
  15. package/DOCS/WEB_REPL_REQUIREMENTS.md +8 -8
  16. package/DOCS/book/01-introduction.md +8 -11
  17. package/DOCS/book/02-syntax-and-values.md +19 -20
  18. package/DOCS/book/03-types-as-finite-automata.md +42 -43
  19. package/DOCS/book/04-partial-functions-and-composition.md +2 -3
  20. package/DOCS/book/05-typing-filters-and-normalization.md +44 -46
  21. package/DOCS/book/06-values-in-memory.md +10 -10
  22. package/DOCS/book/08-operational-semantics-and-execution.md +21 -26
  23. package/DOCS/book/09-compiler-architecture.md +11 -11
  24. package/DOCS/book/10-from-ast-to-intermediate-representation.md +6 -7
  25. package/DOCS/book/14-canonical-serialization.md +2 -2
  26. package/DOCS/book/appendix-b-incorporating-external-predefined-types-and-functions.md +17 -17
  27. package/DOCS/book.md +5 -5
  28. package/Examples/arithmetics.k +49 -153
  29. package/Examples/bnat.k +13 -13
  30. package/Examples/byte.k +2 -50
  31. package/Examples/ieee.k +408 -423
  32. package/Examples/karatsuba-mult.k +30 -34
  33. package/Examples/nat.k +5 -6
  34. package/README.md +54 -49
  35. package/TODO.md +13 -18
  36. package/browser/repl-browser.mjs +40 -22
  37. package/browser/shims/fs.mjs +7 -10
  38. package/browser/vfs-data.mjs +12 -12
  39. package/codecs/BINARY_FORMAT.md +4 -4
  40. package/codecs/POLYMORPHIC_BINARY_FORMAT.md +4 -4
  41. package/codecs/README.md +6 -6
  42. package/codecs/ieee.mjs +15 -11
  43. package/codecs/int.mjs +9 -5
  44. package/codecs/string-codec.mjs +46 -47
  45. package/core.k +124 -175
  46. package/object.mjs +0 -7
  47. package/package.json +5 -2
  48. package/parser.jison +2 -41
  49. package/parser.mjs +55 -95
  50. package/pretty.mjs +11 -4
  51. package/repl.mjs +8 -63
  52. package/scripts/build-repl-html.mjs +18 -49
  53. package/tests/code-derivation/blowup.mjs +2 -4
  54. package/tests/code-derivation/bnat.mjs +2 -3
  55. package/tests/code-derivation/dot.mjs +5 -11
  56. package/tests/code-derivation/nat.mjs +2 -2
  57. package/tests/code-derivation/not-not.mjs +6 -6
  58. package/tests/code-derivation/pattern-envelope.mjs +4 -6
  59. package/tests/code-derivation/product.mjs +3 -6
  60. package/tests/code-derivation/rlz.mjs +4 -5
  61. package/tests/test-codecs.mjs +1 -1
  62. package/tests/test-fingerprint.mjs +36 -41
  63. package/tests/test-hash-normalization.mjs +4 -6
  64. package/tests/test-ieee-arithmetic.mjs +6 -7
  65. package/tests/test-k-object.mjs +11 -15
  66. package/tests/test-kir.mjs +0 -1
  67. package/tests/test-kvm-polymorphic.mjs +1 -2
  68. package/tests/test-kvm.mjs +8 -11
  69. package/tests/test-repl-html.mjs +86 -9
  70. package/tests/test-repl.mjs +38 -53
  71. package/tests/test.mjs +2 -3
package/parser.jison CHANGED
@@ -60,7 +60,6 @@ function fromEscString(escString) {
60
60
  "," return 'COMMA';
61
61
  ";" return 'SC';
62
62
  ":" return 'COL';
63
- "$" return 'DOLLAR';
64
63
  "?" return 'QMARK';
65
64
  "@" return 'AT';
66
65
  \"([^"\\]|\\(.|\n))*\"|\'([^'\\]|\\(.|\n))*\' return 'STRING';
@@ -72,7 +71,7 @@ function fromEscString(escString) {
72
71
  /lex
73
72
 
74
73
  %token NAME STRING
75
- %token LA LC LP RA RP RC EQ DOT COMMA SC COL DOLLAR AT QMARK DOTS DIV VID
74
+ %token LA LC LP RA RP RC EQ DOT COMMA SC COL AT QMARK DOTS DIV VID
76
75
  %token INCREMENTAL
77
76
  %token EOF
78
77
 
@@ -97,7 +96,6 @@ vid: VID { $$ = getToken(yytext,yy,_$); };
97
96
  comma: COMMA { $$ = getToken(yytext,yy,_$); };
98
97
  sc: SC { $$ = getToken(yytext,yy,_$); };
99
98
  col: COL { $$ = getToken(yytext,yy,_$); };
100
- dollar: DOLLAR { $$ = getToken(yytext,yy,_$); };
101
99
  qmark: QMARK { $$ = getToken(yytext,yy,_$); };
102
100
  incremental: INCREMENTAL { $$ = getToken(yytext,yy,_$); };
103
101
 
@@ -115,46 +113,10 @@ initialize_symbol_table
115
113
 
116
114
  defs: { }
117
115
  | defs name eq comp sc { s.add_rel($2.value,$4); }
118
- | defs dollar name eq codeDef SC { s.add_code($3.value,$5); }
119
- ;
120
-
121
- code
122
- : name { $$ = { code: "ref", ref: $1.value, start: $1.start, end: $1.end}; }
123
- | codeDef { $$ = $1; }
124
- ;
125
-
126
- codeDef
127
- : lc labelled_codes rc { $$ = { code: "product", product: $2, start: $1.start, end: $3.end }; }
128
- | la labelled_codes ra { $$ = { code: "union", union: $2, start: $1.start, end: $3.end }; }
129
- | at name { $$ = { code: "ref", ref: "@" + $2.value, start: $1.start, end: $2.end}; }
130
- ;
131
-
132
- labelled_codes
133
- : { $$ = {}; }
134
- | non_empty_labelled_codes { $$ = $1.reduce((r, lc) => {
135
- if (r[lc.label])
136
- anError(@0,`Duplicate label '${lc.label}'.`);
137
- r[lc.label] = s.as_ref(lc.code);
138
- return r }
139
- , {}); }
140
- ;
141
-
142
- non_empty_labelled_codes
143
- : code_label { $$ = [$1]; }
144
- | non_empty_labelled_codes comma code_label
145
- { $$ = [].concat($1,$3); }
146
- ;
147
-
148
- code_label
149
- : code name { $$ = {label: $2.value, code: $1}; }
150
- | code str { $$ = {label: $2.value, code: $1}; }
151
- | name col code { $$ = {label: $1.value, code: $3}; }
152
- | str col code { $$ = {label: $1.value, code: $3}; }
153
116
  ;
154
117
 
155
118
  filter_
156
- : dollar code { $$ = { type: "code", code: s.as_ref($2), start: $1.start, end: $2.end}; }
157
- | lp dots rp { $$ = { type: null, open: true, fields: {}, start: $1.start, end: $3.end}; }
119
+ : lp dots rp { $$ = { type: null, open: true, fields: {}, start: $1.start, end: $3.end}; }
158
120
  | la labelled_filters ra { $$ = { type: "union", open: $2.open, fields: $2.fields, start: $1.start, end: $3.end}; }
159
121
  | lc labelled_filters rc { $$ = { type: "product", open: $2.open, fields: $2.fields, start: $1.start, end: $3.end}; }
160
122
  ;
@@ -210,7 +172,6 @@ exp
210
172
  | div str { $$ = {op: "div", div: $2.value, start: $1.start, end: $2.end }; }
211
173
  | vid name { $$ = {op: "vid", vid: $2.value, start: $1.start, end: $2.end }; }
212
174
  | vid str { $$ = {op: "vid", vid: $2.value, start: $1.start, end: $2.end }; }
213
- | dollar code { $$ = {op: "code", code: s.as_ref($2), start: $1.start, end: $2.end}; }
214
175
  | qmark filter { $$ = {op: "filter", filter: $2, start: $1.start, end:$2.end}; }
215
176
  ;
216
177
 
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,40],$V1=[1,10],$V2=[1,22],$V3=[1,21],$V4=[1,20],$V5=[1,23],$V6=[1,24],$V7=[1,25],$V8=[1,26],$V9=[1,11],$Va=[1,27],$Vb=[6,8,10,12,14,26,28,30,38,40,47],$Vc=[2,63],$Vd=[1,33],$Ve=[4,6,8,10,12,14,16,18,20,26,28,30,32,34,38,40,47],$Vf=[1,46],$Vg=[1,53],$Vh=[4,6],$Vi=[2,27],$Vj=[4,6,8,10,12,14,16,18,20,22,26,28,30,32,34,38,40,47],$Vk=[2,32],$Vl=[1,79],$Vm=[1,81],$Vn=[18,32],$Vo=[4,6,8,10,12,14,26,28,30,38,40],$Vp=[1,85],$Vq=[1,88],$Vr=[16,32],$Vs=[2,46],$Vt=[1,94],$Vu=[2,47],$Vv=[16,18],$Vw=[16,18,32],$Vx=[2,76];
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,"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,"labelled":59,"list":60,"non_empty_labelled":61,"comp_label":62,"non_empty_list":63,"$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:"DOLLAR",40:"QMARK",42:"INCREMENTAL",47:"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,1],[43,4],[44,0],[44,1],[45,0],[45,5],[45,6],[49,1],[49,1],[48,3],[48,3],[48,2],[50,0],[50,1],[51,1],[51,3],[52,2],[52,2],[52,3],[52,3],[53,2],[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,3],[57,3],[46,1],[46,2],[58,3],[58,3],[58,2],[58,2],[58,3],[58,1],[58,2],[58,2],[58,2],[58,2],[58,2],[58,2],[58,2],[58,2],[59,0],[59,1],[61,1],[61,3],[62,2],[62,2],[62,3],[62,3],[60,0],[60,1],[63,1],[63,3]],
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: case 20:
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 21:
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 22:
144
+ case 21:
145
145
  s = new SymbolTable();
146
146
  break;
147
- case 23: case 24:
147
+ case 22: case 23:
148
148
 
149
149
  break;
150
- case 25:
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
- s.add_code($$[$0-3].value,$$[$0-1]);
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.$ = { code: "ref", ref: $$[$0].value, start: $$[$0].start, end: $$[$0].end};
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 44: case 56: case 81:
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 46:
168
+ case 30:
210
169
  this.$ = { type: 'name', name: $$[$0].value, open: true, start: $$[$0].start, end: $$[$0].end};
211
170
  break;
212
- case 47:
171
+ case 31:
213
172
  this.$ = { fields: {}};
214
173
  break;
215
- case 48:
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 51:
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 52: case 53:
195
+ case 36: case 37:
231
196
  this.$ = {label: $$[$0].value, filter: $$[$0-1]};
232
197
  break;
233
- case 54: case 55:
198
+ case 38: case 39:
234
199
  this.$ = {label: $$[$0-2].value, filter: $$[$0]};
235
200
  break;
236
- case 57:
201
+ case 41:
237
202
  this.$ = {...comp($$[$0-1], $$[$0]), start: $$[$0-1].start, end:$$[$0].end};
238
203
  break;
239
- case 58:
204
+ case 42:
240
205
  this.$ = {...$$[$0-1], start: $$[$0-2].start, end: $$[$0].end};
241
206
  break;
242
- case 59:
207
+ case 43:
243
208
  this.$ = {...union($$[$0-1]), start: $$[$0-2].start, end: $$[$0].end};
244
209
  break;
245
- case 60:
210
+ case 44:
246
211
  this.$ = {op: "ref", ref: "@" + $$[$0].value, start: $$[$0-1].start, end: $$[$0].end};
247
212
  break;
248
- case 61:
213
+ case 45:
249
214
  this.$ = {...identity, start: $$[$0-1].start, end: $$[$0].end};
250
215
  break;
251
- case 62:
216
+ case 46:
252
217
  this.$ = {...$$[$0-1], start: $$[$0-2].start, end: $$[$0].end };
253
218
  break;
254
- case 63:
219
+ case 47:
255
220
  this.$ = {op: "ref", ref: $$[$0].value, start: $$[$0].start, end: $$[$0].end};
256
221
  break;
257
- case 64: case 65:
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 66: case 67:
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 68: case 69:
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 70:
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 72:
234
+ case 55:
273
235
  this.$ = {op: "product", product: []};
274
236
  break;
275
- case 73:
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 74:
245
+ case 57:
284
246
  this.$ = {op: "product", product: [$$[$0]]};
285
247
  break;
286
- case 75:
248
+ case 58:
287
249
  $$[$0-2].product = [].concat($$[$0-2].product,$$[$0]); this.$ = $$[$0-2];
288
250
  break;
289
- case 76: case 77:
251
+ case 59: case 60:
290
252
  this.$ = {label: $$[$0].value, exp: $$[$0-1]};
291
253
  break;
292
- case 78: case 79:
254
+ case 61: case 62:
293
255
  this.$ = {label: $$[$0-2].value, exp: $$[$0]};
294
256
  break;
295
- case 80:
257
+ case 63:
296
258
  this.$ = [];
297
259
  break;
298
260
  }
299
261
  },
300
- 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]),{5:7,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:8,38:$V9,39:19,40:$Va,46:6,58:9},{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,47:[1,28],58:29},o($Vb,$Vc,{21:32,22:$Vd}),{5:34,6:$V1,7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,48:36,49:35},o($Ve,[2,56]),o([4,6,8,10,12,14,16,18,20,22,26,28,30,32,34,36,38,40,47],[2,2]),o([6,8,10,12],[2,18]),{3:45,4:$Vf,5:44,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,18:[2,72],25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,46:43,58:9,59:40,61:41,62:42},{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,16:[2,80],25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,46:49,58:9,60:47,63:48},{5:50,6:$V1},{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,19:51,20:$Vg,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,46:52,58:9},{3:55,4:$Vf,5:54,6:$V1},{3:57,4:$Vf,5:56,6:$V1},{3:59,4:$Vf,5:58,6:$V1},{5:62,6:$V1,9:65,10:$V3,11:66,12:$V4,13:64,14:$V5,37:63,38:$V9,53:61,55:60},o([4,6,8,10,12,14,18,24,26,28,30,38,40],[2,5]),o([4,6,8,10,12,14,16,24,26,28,30,38,40],[2,4]),{6:[2,3]},o([6,8,10,12,14,20,24,26,28,30,38,40],[2,6]),o($Vh,[2,12]),o($Vh,[2,13]),o($Vh,[2,14]),o([6,10,12,14,38],[2,19]),{1:[2,21]},o($Ve,[2,57]),o([6,8,10,12,14,16,18,20,26,28,30,32,34,38,40,47],$Vc),{5:67,6:$V1,7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,48:36,49:35},{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,46:68,58:9},o($V0,[2,10]),o($Vb,$Vi,{21:69,22:$Vd}),o($Ve,[2,70]),o($Vj,[2,28]),{3:75,4:$Vf,5:74,6:$V1,7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,18:$Vk,48:36,49:73,50:70,51:71,52:72},{3:75,4:$Vf,5:74,6:$V1,7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,16:$Vk,48:36,49:73,50:76,51:71,52:72},{5:77,6:$V1},{17:78,18:$Vl},{18:[2,73],31:80,32:$Vm},o($Vn,[2,74]),{3:83,4:$Vf,5:82,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,58:29},o($Vo,$Vc,{35:84,36:$Vp}),{35:86,36:$Vp},o([4,6,8,10,12,14,16,18,20,26,28,30,32,34,36,38,40,47],[2,1]),{15:87,16:$Vq},{16:[2,81],31:89,32:$Vm},o($Vr,[2,82],{11:12,9:13,7:14,13:15,25:16,27:17,29:18,39:19,58:29,5:30,37:31,6:$V1,8:$V2,10:$V3,12:$V4,14:$V5,26:$V6,28:$V7,30:$V8,38:$V9,40:$Va}),o($Ve,[2,60]),o($Ve,[2,61]),{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,19:90,20:$Vg,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,58:29},o($Vj,[2,9]),o($Ve,[2,64]),o($Ve,[2,65]),o($Ve,[2,66]),o($Ve,[2,67]),o($Ve,[2,68]),o($Ve,[2,69]),o($Ve,[2,71]),o($Ve,[2,44],{22:[1,91]}),o($Ve,$Vs),{5:67,6:$V1,7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,48:36,49:92},{23:93,24:$Vt},{3:101,4:$Vf,5:100,6:$V1,9:65,10:$V3,11:66,12:$V4,13:64,14:$V5,16:$Vu,23:98,24:$Vt,37:63,38:$V9,53:61,54:95,55:99,56:96,57:97},{3:101,4:$Vf,5:100,6:$V1,9:65,10:$V3,11:66,12:$V4,13:64,14:$V5,18:$Vu,23:98,24:$Vt,37:63,38:$V9,53:61,54:102,55:99,56:96,57:97},o($Vj,$Vi),{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,33:103,34:[1,104],37:31,38:$V9,39:19,40:$Va,58:29},{7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,48:105},{17:106,18:$Vl},o($Vv,[2,33],{31:107,32:$Vm}),o($Vw,[2,34]),{3:109,4:$Vf,5:108,6:$V1},o($Vh,$Vi,{35:110,36:$Vp}),{35:111,36:$Vp},{15:112,16:$Vq},o($Vj,[2,31]),o($Ve,[2,58]),o($Vj,[2,8]),{3:45,4:$Vf,5:44,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,46:43,58:9,62:113},o([4,6,8,10,12,14,24,26,28,30,38,40],[2,15]),o($Vo,$Vc,{18:$Vx,32:$Vx}),o($Vn,[2,77]),{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,46:114,58:9},o($V0,[2,17]),{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,46:115,58:9},o($Ve,[2,59]),o($Vj,[2,7]),{5:30,6:$V1,7:14,8:$V2,9:13,10:$V3,11:12,12:$V4,13:15,14:$V5,25:16,26:$V6,27:17,28:$V7,29:18,30:$V8,37:31,38:$V9,39:19,40:$Va,46:116,58:9},o($Ve,[2,62]),{5:117,6:$V1},o($Vj,[2,40]),{19:118,20:$Vg},o([16,18,20,32],[2,11]),{15:119,16:$Vq},o($Vv,[2,48],{31:120,32:$Vm}),o($Vw,[2,49]),o($Vw,[2,51]),{3:122,4:$Vf,5:121,6:$V1},o($Vh,$Vs,{35:123,36:$Vp}),{35:124,36:$Vp},{17:125,18:$Vl},o($V0,[2,25]),o($V0,[2,16]),{34:[1,126]},o($Vj,[2,29]),{3:75,4:$Vf,5:74,6:$V1,7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,48:36,49:73,52:127},o($Vw,[2,36]),o($Vw,[2,37]),{5:67,6:$V1,7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,48:36,49:128},{5:67,6:$V1,7:39,8:$V2,9:38,10:$V3,11:37,12:$V4,48:36,49:129},o($Vj,[2,30]),o($Vn,[2,75]),o($Vn,[2,78],{11:12,9:13,7:14,13:15,25:16,27:17,29:18,39:19,58:29,5:30,37:31,6:$V1,8:$V2,10:$V3,12:$V4,14:$V5,26:$V6,28:$V7,30:$V8,38:$V9,40:$Va}),o($Vn,[2,79],{11:12,9:13,7:14,13:15,25:16,27:17,29:18,39:19,58:29,5:30,37:31,6:$V1,8:$V2,10:$V3,12:$V4,14:$V5,26:$V6,28:$V7,30:$V8,38:$V9,40:$Va}),o($Vr,[2,83],{11:12,9:13,7:14,13:15,25:16,27:17,29:18,39:19,58:29,5:30,37:31,6:$V1,8:$V2,10:$V3,12:$V4,14:$V5,26:$V6,28:$V7,30:$V8,38:$V9,40:$Va}),o($Ve,[2,45]),o($Vj,[2,41]),o($Vj,[2,42]),{3:101,4:$Vf,5:100,6:$V1,9:65,10:$V3,11:66,12:$V4,13:64,14:$V5,23:98,24:$Vt,37:63,38:$V9,53:61,55:99,57:130},o($Vw,[2,52]),o($Vw,[2,53]),{5:62,6:$V1,9:65,10:$V3,11:66,12:$V4,13:64,14:$V5,37:63,38:$V9,53:61,55:131},{5:62,6:$V1,9:65,10:$V3,11:66,12:$V4,13:64,14:$V5,37:63,38:$V9,53:61,55:132},o($Vj,[2,43]),o($V0,[2,26]),o($Vw,[2,35]),o($Vw,[2,38]),o($Vw,[2,39]),o($Vw,[2,50]),o($Vw,[2,54]),o($Vw,[2,55])],
301
- defaultActions: {22:[2,3],28:[2,21]},
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 19:return 8;
773
+ case 18:return 8;
814
774
  break;
815
- case 20:return 4;
775
+ case 19:return 4;
816
776
  break;
817
- case 21:return 6;
777
+ case 20:return 6;
818
778
  break;
819
- case 22:return 42;
779
+ case 21:return 40;
820
780
  break;
821
- case 23:return 47;
781
+ case 22:return 45;
822
782
  break;
823
783
  }
824
784
  },
825
- rules: [/^(?:[/][*]([^*]*[*]+[^*/])*[^*]*[*]+[/])/,/^(?:(\/\/|#|%|--|\\\\)[^\n]*)/,/^(?:\s+)/,/^(?:<)/,/^(?:\{)/,/^(?:\()/,/^(?:>)/,/^(?:\})/,/^(?:\))/,/^(?:=)/,/^(?:\.\.\.)/,/^(?:\.)/,/^(?:\/)/,/^(?:(\\|\|))/,/^(?:,)/,/^(?:;)/,/^(?::)/,/^(?:\$)/,/^(?:\?)/,/^(?:@)/,/^(?:"([^"\\]|\\(.|\n))*"|'([^'\\]|\\(.|\n))*')/,/^(?:[a-zA-Z0-9_+-][a-zA-Z0-9_?!+-]*)/,/^(?:~)/,/^(?:$)/],
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,23],"inclusive":true}}
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] && pattern.pattern != 'type') {
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
- return {type: "code", code: pattern.type, ...named_filter};
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", "type", "code", "rel", "C",
52
- "types", "codecs", "rels", "codec", "input", "reset", "klib", "ko", "load",
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 kind === "code" ? `$ ${name} = @${body};` : `${name} = @${body};`;
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 completeCanonicalCode(line, state) {
517
- const match = line.match(/^(.*?)(@[A-Za-z0-9_?!+-]*)$/);
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 = canonicalCodeNames(state)
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 (/\$?[A-Za-z0-9_+-][A-Za-z0-9_?!+-]*$/.test(line)) {
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 (/\$?[A-Za-z0-9_+-][A-Za-z0-9_?!+-]*$/.test(line)) {
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",