aontu 0.3.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/aontu.ts +3 -2
- package/dist/aontu.d.ts +2 -2
- package/dist/aontu.js +3 -4
- package/dist/aontu.js.map +1 -1
- package/dist/aontu.min.js +1 -63
- package/dist/lib/lang.d.ts +1 -3
- package/dist/lib/lang.js +47 -30
- package/dist/lib/lang.js.map +1 -1
- package/dist/lib/op/disjunct.js +10 -10
- package/dist/lib/op/disjunct.js.map +1 -1
- package/dist/lib/op/op.d.ts +1 -1
- package/dist/lib/op/op.js.map +1 -1
- package/dist/lib/op/unite.js +19 -14
- package/dist/lib/op/unite.js.map +1 -1
- package/dist/lib/type.d.ts +33 -22
- package/dist/lib/type.js +22 -76
- package/dist/lib/type.js.map +1 -1
- package/dist/lib/unify.d.ts +4 -1
- package/dist/lib/unify.js +7 -5
- package/dist/lib/unify.js.map +1 -1
- package/dist/lib/val/ConjunctVal.d.ts +12 -0
- package/dist/lib/val/ConjunctVal.js +191 -0
- package/dist/lib/val/ConjunctVal.js.map +1 -0
- package/dist/lib/val/DisjunctVal.d.ts +12 -0
- package/dist/lib/val/DisjunctVal.js +85 -0
- package/dist/lib/val/DisjunctVal.js.map +1 -0
- package/dist/lib/val/ListVal.d.ts +14 -0
- package/dist/lib/val/ListVal.js +91 -0
- package/dist/lib/val/ListVal.js.map +1 -0
- package/dist/lib/val/MapVal.d.ts +14 -0
- package/dist/lib/val/MapVal.js +141 -0
- package/dist/lib/val/MapVal.js.map +1 -0
- package/dist/lib/val/Nil.d.ts +15 -0
- package/dist/lib/val/Nil.js +54 -0
- package/dist/lib/val/Nil.js.map +1 -0
- package/dist/lib/val/PrefVal.d.ts +12 -0
- package/dist/lib/val/PrefVal.js +60 -0
- package/dist/lib/val/PrefVal.js.map +1 -0
- package/dist/lib/val/RefVal.d.ts +15 -0
- package/dist/lib/val/RefVal.js +73 -0
- package/dist/lib/val/RefVal.js.map +1 -0
- package/dist/lib/val/ValBase.d.ts +22 -0
- package/dist/lib/val/ValBase.js +25 -0
- package/dist/lib/val/ValBase.js.map +1 -0
- package/dist/lib/val.d.ts +5 -90
- package/dist/lib/val.js +13 -593
- package/dist/lib/val.js.map +1 -1
- package/lib/lang.ts +77 -59
- package/lib/op/disjunct.ts +14 -8
- package/lib/op/op.ts +2 -1
- package/lib/op/unite.ts +14 -12
- package/lib/type.ts +104 -0
- package/lib/unify.ts +10 -8
- package/lib/val/ConjunctVal.ts +284 -0
- package/lib/val/DisjunctVal.ts +145 -0
- package/lib/val/ListVal.ts +154 -0
- package/lib/val/MapVal.ts +226 -0
- package/lib/val/Nil.ts +94 -0
- package/lib/val/PrefVal.ts +113 -0
- package/lib/val/RefVal.ts +126 -0
- package/lib/val/RefVal.ts~ +319 -0
- package/lib/val/ValBase.ts +76 -0
- package/lib/val.ts +15 -802
- package/package.json +27 -23
- package/lib/common.ts +0 -19
package/dist/lib/val.js
CHANGED
|
@@ -1,122 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Copyright (c) 2021 Richard Rodger, MIT License */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
5
|
-
|
|
6
|
-
// NOTES
|
|
7
|
-
// - Vals are immutable
|
|
8
|
-
// - each Val must handle all parent and child unifications explicitly
|
|
9
|
-
// - performance is not considered yet
|
|
10
|
-
/*
|
|
11
|
-
|
|
12
|
-
TOP -> Scalar/Boolean -> BooleanVal
|
|
13
|
-
-> Scalar/String -> StringVal
|
|
14
|
-
-> Scalar/Number -> NumberVal -> IntegerVal
|
|
15
|
-
-> Scalar/Integer
|
|
16
|
-
-> Scalar/Integer -> IntegerVal
|
|
17
|
-
|
|
18
|
-
*/
|
|
4
|
+
exports.IntegerVal = exports.BooleanVal = exports.StringVal = exports.NumberVal = exports.ScalarTypeVal = exports.Integer = void 0;
|
|
5
|
+
const type_1 = require("./type");
|
|
19
6
|
const unify_1 = require("./unify");
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const DONE = -1;
|
|
23
|
-
exports.DONE = DONE;
|
|
24
|
-
// There can be only one.
|
|
25
|
-
const TOP = {
|
|
26
|
-
id: 0,
|
|
27
|
-
top: true,
|
|
28
|
-
peg: undefined,
|
|
29
|
-
done: DONE,
|
|
30
|
-
path: [],
|
|
31
|
-
row: -1,
|
|
32
|
-
col: -1,
|
|
33
|
-
url: '',
|
|
34
|
-
unify(peer, _ctx) {
|
|
35
|
-
return peer;
|
|
36
|
-
},
|
|
37
|
-
get canon() { return 'top'; },
|
|
38
|
-
get site() { return new lang_1.Site(this); },
|
|
39
|
-
same(peer) {
|
|
40
|
-
return TOP === peer;
|
|
41
|
-
},
|
|
42
|
-
gen: (_ctx) => {
|
|
43
|
-
return undefined;
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
exports.TOP = TOP;
|
|
47
|
-
class Val {
|
|
48
|
-
constructor(peg, ctx) {
|
|
49
|
-
this.done = 0;
|
|
50
|
-
this.row = -1;
|
|
51
|
-
this.col = -1;
|
|
52
|
-
this.url = '';
|
|
53
|
-
this.peg = peg;
|
|
54
|
-
this.path = (ctx && ctx.path) || [];
|
|
55
|
-
this.id = (ctx && ctx.vc++) || (9e9 + Math.floor(Math.random() * (1e9)));
|
|
56
|
-
}
|
|
57
|
-
same(peer) {
|
|
58
|
-
return this === peer;
|
|
59
|
-
}
|
|
60
|
-
get site() {
|
|
61
|
-
return new lang_1.Site(this);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.Val = Val;
|
|
65
|
-
class Nil extends Val {
|
|
66
|
-
constructor(why, ctx) {
|
|
67
|
-
super(null, ctx);
|
|
68
|
-
this.nil = true;
|
|
69
|
-
this.why = why;
|
|
70
|
-
// Nil is always DONE, by definition.
|
|
71
|
-
this.done = DONE;
|
|
72
|
-
}
|
|
73
|
-
unify(_peer, _ctx) {
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
get canon() {
|
|
77
|
-
return 'nil';
|
|
78
|
-
}
|
|
79
|
-
gen(_ctx) {
|
|
80
|
-
return undefined;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.Nil = Nil;
|
|
84
|
-
// TODO: include Val generating nil, thus capture type
|
|
85
|
-
Nil.make = (ctx, why, av, bv) => {
|
|
86
|
-
let nil = new Nil(why, ctx);
|
|
87
|
-
// TODO: this should be done lazily, for multiple terms
|
|
88
|
-
// Terms later in same file are considered the primary error location.
|
|
89
|
-
if (null != av) {
|
|
90
|
-
nil.row = av.row;
|
|
91
|
-
nil.col = av.col;
|
|
92
|
-
nil.url = av.url;
|
|
93
|
-
nil.primary = av;
|
|
94
|
-
if (null != bv) {
|
|
95
|
-
nil.secondary = bv;
|
|
96
|
-
let bv_loc_wins = (nil.url === bv.url) && ((nil.row < bv.row) ||
|
|
97
|
-
(nil.row === bv.row && nil.col < bv.col));
|
|
98
|
-
if (bv_loc_wins) {
|
|
99
|
-
nil.row = bv.row;
|
|
100
|
-
nil.col = bv.col;
|
|
101
|
-
nil.url = bv.url;
|
|
102
|
-
nil.primary = bv;
|
|
103
|
-
nil.secondary = av;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (ctx) {
|
|
108
|
-
ctx.err.push(nil);
|
|
109
|
-
}
|
|
110
|
-
return nil;
|
|
111
|
-
};
|
|
7
|
+
const Nil_1 = require("./val/Nil");
|
|
8
|
+
const ValBase_1 = require("./val/ValBase");
|
|
112
9
|
// A ScalarType for integers. Number includes floats.
|
|
113
10
|
class Integer {
|
|
114
11
|
}
|
|
115
12
|
exports.Integer = Integer;
|
|
116
|
-
class ScalarTypeVal extends
|
|
13
|
+
class ScalarTypeVal extends ValBase_1.ValBase {
|
|
117
14
|
constructor(peg, ctx) {
|
|
118
15
|
super(peg, ctx);
|
|
119
|
-
this.done = DONE;
|
|
16
|
+
this.done = type_1.DONE;
|
|
120
17
|
}
|
|
121
18
|
unify(peer, ctx) {
|
|
122
19
|
if (peer instanceof ScalarVal) {
|
|
@@ -126,7 +23,7 @@ class ScalarTypeVal extends Val {
|
|
|
126
23
|
else if (Number === this.peg && Integer === peer.type) {
|
|
127
24
|
return peer;
|
|
128
25
|
}
|
|
129
|
-
return Nil.make(ctx, 'no-scalar-unify', this, peer);
|
|
26
|
+
return Nil_1.Nil.make(ctx, 'no-scalar-unify', this, peer);
|
|
130
27
|
}
|
|
131
28
|
else {
|
|
132
29
|
if (peer instanceof ScalarTypeVal) {
|
|
@@ -137,7 +34,7 @@ class ScalarTypeVal extends Val {
|
|
|
137
34
|
return this;
|
|
138
35
|
}
|
|
139
36
|
}
|
|
140
|
-
return Nil.make(ctx, 'scalar-type', this, peer);
|
|
37
|
+
return Nil_1.Nil.make(ctx, 'scalar-type', this, peer);
|
|
141
38
|
}
|
|
142
39
|
}
|
|
143
40
|
get canon() {
|
|
@@ -152,18 +49,18 @@ class ScalarTypeVal extends Val {
|
|
|
152
49
|
}
|
|
153
50
|
}
|
|
154
51
|
exports.ScalarTypeVal = ScalarTypeVal;
|
|
155
|
-
class ScalarVal extends
|
|
52
|
+
class ScalarVal extends ValBase_1.ValBase {
|
|
156
53
|
constructor(peg, type, ctx) {
|
|
157
54
|
super(peg, ctx);
|
|
158
55
|
this.type = type;
|
|
159
|
-
this.done = DONE;
|
|
56
|
+
this.done = type_1.DONE;
|
|
160
57
|
}
|
|
161
58
|
unify(peer, ctx) {
|
|
162
59
|
// Exactly equal scalars are handled in op/unite
|
|
163
60
|
if (peer instanceof ScalarTypeVal) {
|
|
164
61
|
return peer.unify(this, ctx);
|
|
165
62
|
}
|
|
166
|
-
return Nil.make(ctx, 'scalar', this, peer);
|
|
63
|
+
return Nil_1.Nil.make(ctx, 'scalar', this, peer);
|
|
167
64
|
}
|
|
168
65
|
get canon() {
|
|
169
66
|
return this.peg.toString();
|
|
@@ -233,483 +130,6 @@ class BooleanVal extends ScalarVal {
|
|
|
233
130
|
}
|
|
234
131
|
}
|
|
235
132
|
exports.BooleanVal = BooleanVal;
|
|
236
|
-
BooleanVal.TRUE = new BooleanVal(true, new unify_1.Context({ vc: 1, root: TOP }));
|
|
237
|
-
BooleanVal.FALSE = new BooleanVal(false, new unify_1.Context({ vc: 2, root: TOP }));
|
|
238
|
-
class MapVal extends Val {
|
|
239
|
-
constructor(peg, ctx) {
|
|
240
|
-
super(peg, ctx);
|
|
241
|
-
this.spread = {
|
|
242
|
-
cj: undefined,
|
|
243
|
-
};
|
|
244
|
-
let spread = this.peg[MapVal.SPREAD];
|
|
245
|
-
delete this.peg[MapVal.SPREAD];
|
|
246
|
-
if (spread) {
|
|
247
|
-
if ('&' === spread.o) {
|
|
248
|
-
// TODO: handle existing spread!
|
|
249
|
-
this.spread.cj =
|
|
250
|
-
new ConjunctVal(Array.isArray(spread.v) ? spread.v : [spread.v], ctx);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
// NOTE: order of keys is not preserved!
|
|
255
|
-
// not possible in any case - consider {a,b} unify {b,a}
|
|
256
|
-
unify(peer, ctx) {
|
|
257
|
-
let done = true;
|
|
258
|
-
let out = TOP === peer ? this : new MapVal({}, ctx);
|
|
259
|
-
out.spread.cj = this.spread.cj;
|
|
260
|
-
if (peer instanceof MapVal) {
|
|
261
|
-
out.spread.cj = null == out.spread.cj ? peer.spread.cj : (null == peer.spread.cj ? out.spread.cj : (out.spread.cj = new ConjunctVal([out.spread.cj, peer.spread.cj], ctx)));
|
|
262
|
-
}
|
|
263
|
-
out.done = this.done + 1;
|
|
264
|
-
if (this.spread.cj) {
|
|
265
|
-
//out.spread.cj =
|
|
266
|
-
// DONE !== this.spread.cj.done ? this.spread.cj.unify(TOP, ctx) :
|
|
267
|
-
// this.spread.cj
|
|
268
|
-
out.spread.cj =
|
|
269
|
-
DONE !== this.spread.cj.done ? (0, op_1.unite)(ctx, this.spread.cj) :
|
|
270
|
-
this.spread.cj;
|
|
271
|
-
}
|
|
272
|
-
// console.log(
|
|
273
|
-
// (' '.repeat(ctx.path.length)),
|
|
274
|
-
// 'MV spread', this.id, peer.id, out.id, '|',
|
|
275
|
-
// this.canon, peer.canon, out.canon, '|',
|
|
276
|
-
// (this.spread.cj || {}).done,
|
|
277
|
-
// (this.spread.cj || {}).canon, (out.spread.cj || {}).canon)
|
|
278
|
-
let spread_cj = out.spread.cj || TOP;
|
|
279
|
-
// Always unify children first
|
|
280
|
-
for (let key in this.peg) {
|
|
281
|
-
//let oval = out.peg[key] = this.peg[key].unify(spread_cj, ctx.descend(key))
|
|
282
|
-
//let oval =
|
|
283
|
-
out.peg[key] =
|
|
284
|
-
(0, op_1.unite)(ctx.descend(key), this.peg[key], spread_cj);
|
|
285
|
-
done = (done && DONE === out.peg[key].done);
|
|
286
|
-
//if (oval instanceof Nil) {
|
|
287
|
-
// ctx.err.push(oval)
|
|
288
|
-
//}
|
|
289
|
-
}
|
|
290
|
-
// console.log(
|
|
291
|
-
// (' '.repeat(ctx.path.length)),
|
|
292
|
-
// 'MV child ', this.id, peer.id, out.id, '|',
|
|
293
|
-
// this.canon, peer.canon, out.canon, '|',
|
|
294
|
-
// this.constructor.name,
|
|
295
|
-
// peer.constructor.name,
|
|
296
|
-
// out.constructor.name,
|
|
297
|
-
// )
|
|
298
|
-
if (peer instanceof MapVal) {
|
|
299
|
-
//let upeer: MapVal = (peer.unify(TOP, ctx) as MapVal)
|
|
300
|
-
let upeer = (0, op_1.unite)(ctx, peer);
|
|
301
|
-
// console.log(
|
|
302
|
-
// (' '.repeat(ctx.path.length)),
|
|
303
|
-
// 'MV peer A', this.id, peer.id, out.id, '|',
|
|
304
|
-
// Object.keys(this.peg), Object.keys(upeer.peg), Object.keys(out.peg))
|
|
305
|
-
for (let peerkey in upeer.peg) {
|
|
306
|
-
let peerchild = upeer.peg[peerkey];
|
|
307
|
-
let child = out.peg[peerkey];
|
|
308
|
-
let oval = out.peg[peerkey] =
|
|
309
|
-
undefined === child ? peerchild :
|
|
310
|
-
child instanceof Nil ? child :
|
|
311
|
-
peerchild instanceof Nil ? peerchild :
|
|
312
|
-
//child.unify(peerchild, ctx.descend(peerkey))
|
|
313
|
-
(0, op_1.unite)(ctx.descend(peerkey), child, peerchild);
|
|
314
|
-
if (this.spread.cj) {
|
|
315
|
-
//out.peg[peerkey] = out.peg[peerkey].unify(spread_cj, ctx)
|
|
316
|
-
out.peg[peerkey] = (0, op_1.unite)(ctx, out.peg[peerkey], spread_cj);
|
|
317
|
-
}
|
|
318
|
-
done = (done && DONE === oval.done);
|
|
319
|
-
if (oval instanceof Nil) {
|
|
320
|
-
// ctx.err.push(oval)
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
// console.log(
|
|
324
|
-
// (' '.repeat(ctx.path.length)),
|
|
325
|
-
// 'MV peer B', this.id, peer.id, out.id, '|',
|
|
326
|
-
// Object.keys(this.peg), Object.keys(upeer.peg), Object.keys(out.peg))
|
|
327
|
-
//out.done = done ? DONE : out.done
|
|
328
|
-
// console.log(' '.repeat(W) + 'MV OUT A', this.id, out.done, out.id, out.canon)//this.spread.cj, out.spread.cj)
|
|
329
|
-
// console.log(
|
|
330
|
-
// (' '.repeat(ctx.path.length)),
|
|
331
|
-
// 'MV out ', this.id, peer.id, out.id, '|',
|
|
332
|
-
// this.canon, peer.canon, out.canon, '|',
|
|
333
|
-
// this.constructor.name,
|
|
334
|
-
// peer.constructor.name,
|
|
335
|
-
// out.constructor.name,
|
|
336
|
-
// )
|
|
337
|
-
}
|
|
338
|
-
else if (TOP !== peer) {
|
|
339
|
-
//out.done = done ? DONE : out.done
|
|
340
|
-
//return (UNIFIER(out, peer, ctx) as MapVal)
|
|
341
|
-
return Nil.make(ctx, 'map', this, peer);
|
|
342
|
-
}
|
|
343
|
-
out.done = done ? DONE : out.done;
|
|
344
|
-
return out;
|
|
345
|
-
}
|
|
346
|
-
get canon() {
|
|
347
|
-
let keys = Object.keys(this.peg);
|
|
348
|
-
return '{' +
|
|
349
|
-
(this.spread.cj ? '&:' + this.spread.cj.canon +
|
|
350
|
-
(0 < keys.length ? ',' : '') : '') +
|
|
351
|
-
keys
|
|
352
|
-
.map(k => [JSON.stringify(k) + ':' + this.peg[k].canon]).join(',') +
|
|
353
|
-
'}';
|
|
354
|
-
}
|
|
355
|
-
gen(ctx) {
|
|
356
|
-
let out = {};
|
|
357
|
-
for (let p in this.peg) {
|
|
358
|
-
out[p] = this.peg[p].gen(ctx);
|
|
359
|
-
}
|
|
360
|
-
return out;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
exports.MapVal = MapVal;
|
|
364
|
-
MapVal.SPREAD = Symbol('spread');
|
|
365
|
-
class ListVal extends Val {
|
|
366
|
-
constructor(peg, ctx) {
|
|
367
|
-
super(peg, ctx);
|
|
368
|
-
this.spread = {
|
|
369
|
-
cj: undefined,
|
|
370
|
-
};
|
|
371
|
-
let spread = this.peg[ListVal.SPREAD];
|
|
372
|
-
delete this.peg[ListVal.SPREAD];
|
|
373
|
-
if (spread) {
|
|
374
|
-
if ('&' === spread.o) {
|
|
375
|
-
// TODO: handle existing spread!
|
|
376
|
-
this.spread.cj =
|
|
377
|
-
new ConjunctVal(Array.isArray(spread.v) ? spread.v : [spread.v], ctx);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
// NOTE: order of keys is not preserved!
|
|
382
|
-
// not possible in any case - consider {a,b} unify {b,a}
|
|
383
|
-
unify(peer, ctx) {
|
|
384
|
-
let done = true;
|
|
385
|
-
let out = TOP === peer ? this : new ListVal([], ctx);
|
|
386
|
-
out.spread.cj = this.spread.cj;
|
|
387
|
-
if (peer instanceof ListVal) {
|
|
388
|
-
out.spread.cj = null == out.spread.cj ? peer.spread.cj : (null == peer.spread.cj ? out.spread.cj : (out.spread.cj = new ConjunctVal([out.spread.cj, peer.spread.cj], ctx)));
|
|
389
|
-
}
|
|
390
|
-
out.done = this.done + 1;
|
|
391
|
-
if (this.spread.cj) {
|
|
392
|
-
out.spread.cj =
|
|
393
|
-
DONE !== this.spread.cj.done ? (0, op_1.unite)(ctx, this.spread.cj) :
|
|
394
|
-
this.spread.cj;
|
|
395
|
-
}
|
|
396
|
-
let spread_cj = out.spread.cj || TOP;
|
|
397
|
-
// Always unify children first
|
|
398
|
-
for (let key in this.peg) {
|
|
399
|
-
out.peg[key] =
|
|
400
|
-
(0, op_1.unite)(ctx.descend(key), this.peg[key], spread_cj);
|
|
401
|
-
done = (done && DONE === out.peg[key].done);
|
|
402
|
-
}
|
|
403
|
-
if (peer instanceof ListVal) {
|
|
404
|
-
let upeer = (0, op_1.unite)(ctx, peer);
|
|
405
|
-
for (let peerkey in upeer.peg) {
|
|
406
|
-
let peerchild = upeer.peg[peerkey];
|
|
407
|
-
let child = out.peg[peerkey];
|
|
408
|
-
let oval = out.peg[peerkey] =
|
|
409
|
-
undefined === child ? peerchild :
|
|
410
|
-
child instanceof Nil ? child :
|
|
411
|
-
peerchild instanceof Nil ? peerchild :
|
|
412
|
-
(0, op_1.unite)(ctx.descend(peerkey), child, peerchild);
|
|
413
|
-
if (this.spread.cj) {
|
|
414
|
-
out.peg[peerkey] = (0, op_1.unite)(ctx, out.peg[peerkey], spread_cj);
|
|
415
|
-
}
|
|
416
|
-
done = (done && DONE === oval.done);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
else if (TOP !== peer) {
|
|
420
|
-
return Nil.make(ctx, 'map', this, peer);
|
|
421
|
-
}
|
|
422
|
-
out.done = done ? DONE : out.done;
|
|
423
|
-
return out;
|
|
424
|
-
}
|
|
425
|
-
get canon() {
|
|
426
|
-
let keys = Object.keys(this.peg);
|
|
427
|
-
return '[' +
|
|
428
|
-
(this.spread.cj ? '&:' + this.spread.cj.canon +
|
|
429
|
-
(0 < keys.length ? ',' : '') : '') +
|
|
430
|
-
keys
|
|
431
|
-
// NOTE: handle array non-index key vals
|
|
432
|
-
// .map(k => [JSON.stringify(k) + ':' + this.peg[k].canon]).join(',') +
|
|
433
|
-
.map(k => [this.peg[k].canon]).join(',') +
|
|
434
|
-
']';
|
|
435
|
-
}
|
|
436
|
-
gen(ctx) {
|
|
437
|
-
let out = this.peg.map((v) => v.gen(ctx));
|
|
438
|
-
// for (let p in this.peg) {
|
|
439
|
-
// out[p] = this.peg[p].gen(ctx)
|
|
440
|
-
// }
|
|
441
|
-
return out;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
exports.ListVal = ListVal;
|
|
445
|
-
ListVal.SPREAD = Symbol('spread');
|
|
446
|
-
// TODO: move main logic to op/conjunct
|
|
447
|
-
class ConjunctVal extends Val {
|
|
448
|
-
constructor(peg, ctx) {
|
|
449
|
-
super(peg, ctx);
|
|
450
|
-
}
|
|
451
|
-
// NOTE: mutation!
|
|
452
|
-
append(peer) {
|
|
453
|
-
this.peg.push(peer);
|
|
454
|
-
return this;
|
|
455
|
-
}
|
|
456
|
-
unify(peer, ctx) {
|
|
457
|
-
let done = true;
|
|
458
|
-
// Unify each term of conjunct against peer
|
|
459
|
-
let upeer = [];
|
|
460
|
-
for (let vI = 0; vI < this.peg.length; vI++) {
|
|
461
|
-
// upeer[vI] = this.peg[vI].unify(peer, ctx)
|
|
462
|
-
upeer[vI] = (0, op_1.unite)(ctx, this.peg[vI], peer);
|
|
463
|
-
done = done && DONE === upeer[vI].done;
|
|
464
|
-
// // console.log('Ca', vI, this.peg[vI].canon, peer.canon, upeer[vI].canon)
|
|
465
|
-
if (upeer[vI] instanceof Nil) {
|
|
466
|
-
return Nil.make(ctx, '&peer[' + upeer[vI].canon + ',' + peer.canon + ']', this.peg[vI], peer);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
// // console.log('Cb', upeer.map(x => x.canon))
|
|
470
|
-
// TODO: FIX: conjuncts get replicated inside each other
|
|
471
|
-
// 1&/x => CV[CV[1&/x]]
|
|
472
|
-
// Unify each term of conjunct against following sibling,
|
|
473
|
-
// reducing to smallest conjunct or single val
|
|
474
|
-
let outvals = 0 < upeer.length ? [upeer[0]] : [];
|
|
475
|
-
let oI = 0;
|
|
476
|
-
for (let uI = 1; uI < upeer.length; uI++) {
|
|
477
|
-
// // console.log('Cu', oI, uI, outvals.map(x => x.canon))
|
|
478
|
-
if (outvals[oI] instanceof ConjunctVal) {
|
|
479
|
-
outvals.splice(oI, 0, ...outvals[oI].peg);
|
|
480
|
-
oI += outvals[oI].peg.length;
|
|
481
|
-
done = false;
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
outvals[oI] = null == outvals[oI] ? upeer[uI] :
|
|
485
|
-
//outvals[oI].unify(upeer[uI], ctx)
|
|
486
|
-
(0, op_1.unite)(ctx, outvals[oI], upeer[uI]);
|
|
487
|
-
done = done && DONE === outvals[oI].done;
|
|
488
|
-
// Conjuct fails
|
|
489
|
-
if (outvals[oI] instanceof Nil) {
|
|
490
|
-
return outvals[oI];
|
|
491
|
-
/*
|
|
492
|
-
return Nil.make(
|
|
493
|
-
ctx,
|
|
494
|
-
'&reduce[' + outvals[oI].canon + ',' + upeer[uI].canon + ']',
|
|
495
|
-
outvals[oI],
|
|
496
|
-
upeer[uI]
|
|
497
|
-
)
|
|
498
|
-
*/
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
// // console.log('Cc', outvals.map(x => x.canon), outvals)
|
|
503
|
-
let out;
|
|
504
|
-
//let why = ''
|
|
505
|
-
if (0 === outvals.length) {
|
|
506
|
-
//out = Nil.make(ctx, '&empty', this)
|
|
507
|
-
// Empty conjuncts evaporate.
|
|
508
|
-
out = TOP;
|
|
509
|
-
//why += 'A'
|
|
510
|
-
}
|
|
511
|
-
// TODO: corrects CV[CV[1&/x]] issue above, but swaps term order!
|
|
512
|
-
else if (1 === outvals.length) {
|
|
513
|
-
out = outvals[0];
|
|
514
|
-
//why += 'B'
|
|
515
|
-
}
|
|
516
|
-
else {
|
|
517
|
-
out = new ConjunctVal(outvals, ctx);
|
|
518
|
-
//why += 'C'
|
|
519
|
-
}
|
|
520
|
-
// // console.log('Cd', why, out.peg)
|
|
521
|
-
out.done = done ? DONE : this.done + 1;
|
|
522
|
-
return out;
|
|
523
|
-
}
|
|
524
|
-
// TODO: need a well-defined val order so conjunt canon is always the same
|
|
525
|
-
get canon() {
|
|
526
|
-
return this.peg.map((v) => v.canon).join('&');
|
|
527
|
-
}
|
|
528
|
-
gen(ctx) {
|
|
529
|
-
if (0 < this.peg.length) {
|
|
530
|
-
// Default is just the first term - does this work?
|
|
531
|
-
// TODO: maybe use a PrefVal() ?
|
|
532
|
-
let v = this.peg[0];
|
|
533
|
-
let out = undefined;
|
|
534
|
-
if (undefined !== v && !(v instanceof Nil)) {
|
|
535
|
-
out = v.gen(ctx);
|
|
536
|
-
}
|
|
537
|
-
return out;
|
|
538
|
-
}
|
|
539
|
-
return undefined;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
exports.ConjunctVal = ConjunctVal;
|
|
543
|
-
// TODO: move main logic to op/disjunct
|
|
544
|
-
class DisjunctVal extends Val {
|
|
545
|
-
// TODO: sites from normalization of orginal Disjuncts, as well as child pegs
|
|
546
|
-
constructor(peg, ctx, _sites) {
|
|
547
|
-
super(peg, ctx);
|
|
548
|
-
}
|
|
549
|
-
// NOTE: mutation!
|
|
550
|
-
append(peer) {
|
|
551
|
-
this.peg.push(peer);
|
|
552
|
-
return this;
|
|
553
|
-
}
|
|
554
|
-
unify(peer, ctx) {
|
|
555
|
-
let done = true;
|
|
556
|
-
let oval = [];
|
|
557
|
-
//console.log('oval', this.canon, peer.canon)
|
|
558
|
-
// Conjunction (&) distributes over disjunction (|)
|
|
559
|
-
for (let vI = 0; vI < this.peg.length; vI++) {
|
|
560
|
-
//oval[vI] = this.peg[vI].unify(peer, ctx)
|
|
561
|
-
oval[vI] = (0, op_1.unite)(ctx, this.peg[vI], peer);
|
|
562
|
-
//console.log('ovalA', vI, this.peg[vI].canon, peer.canon, oval[vI].canon)
|
|
563
|
-
done = done && DONE === oval[vI].done;
|
|
564
|
-
}
|
|
565
|
-
//console.log('ovalB', oval.map(v => v.canon))
|
|
566
|
-
// Remove duplicates, and normalize
|
|
567
|
-
if (1 < oval.length) {
|
|
568
|
-
for (let vI = 0; vI < oval.length; vI++) {
|
|
569
|
-
if (oval[vI] instanceof DisjunctVal) {
|
|
570
|
-
oval.splice(vI, 1, ...oval[vI].peg);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
//console.log('ovalC', oval.map(v => v.canon))
|
|
574
|
-
// TODO: not an error Nil!
|
|
575
|
-
let remove = new Nil();
|
|
576
|
-
for (let vI = 0; vI < oval.length; vI++) {
|
|
577
|
-
for (let kI = vI + 1; kI < oval.length; kI++) {
|
|
578
|
-
if (oval[kI].same(oval[vI])) {
|
|
579
|
-
oval[kI] = remove;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
//console.log('ovalD', oval.map(v => v.canon))
|
|
584
|
-
oval = oval.filter(v => !(v instanceof Nil));
|
|
585
|
-
}
|
|
586
|
-
let out;
|
|
587
|
-
if (1 == oval.length) {
|
|
588
|
-
out = oval[0];
|
|
589
|
-
}
|
|
590
|
-
else if (0 == oval.length) {
|
|
591
|
-
return Nil.make(ctx, '|:empty', this);
|
|
592
|
-
}
|
|
593
|
-
else {
|
|
594
|
-
out = new DisjunctVal(oval, ctx);
|
|
595
|
-
}
|
|
596
|
-
out.done = done ? DONE : this.done + 1;
|
|
597
|
-
return out;
|
|
598
|
-
}
|
|
599
|
-
get canon() {
|
|
600
|
-
return this.peg.map((v) => v.canon).join('|');
|
|
601
|
-
}
|
|
602
|
-
gen(ctx) {
|
|
603
|
-
if (0 < this.peg.length) {
|
|
604
|
-
let vals = this.peg.filter((v) => v instanceof PrefVal);
|
|
605
|
-
vals = 0 === vals.length ? this.peg : vals;
|
|
606
|
-
let val = vals[0];
|
|
607
|
-
for (let vI = 1; vI < this.peg.length; vI++) {
|
|
608
|
-
val = val.unify(this.peg[vI]);
|
|
609
|
-
}
|
|
610
|
-
return val.gen(ctx);
|
|
611
|
-
}
|
|
612
|
-
return undefined;
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
exports.DisjunctVal = DisjunctVal;
|
|
616
|
-
class RefVal extends Val {
|
|
617
|
-
constructor(peg, abs) {
|
|
618
|
-
super('');
|
|
619
|
-
this.sep = '.';
|
|
620
|
-
this.absolute = true === abs;
|
|
621
|
-
this.parts = [];
|
|
622
|
-
for (let part of peg) {
|
|
623
|
-
this.append(part);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
append(part) {
|
|
627
|
-
//console.log('APPEND 0', part)
|
|
628
|
-
if ('string' === typeof part) {
|
|
629
|
-
this.parts.push(part);
|
|
630
|
-
}
|
|
631
|
-
else if (part instanceof StringVal) {
|
|
632
|
-
this.parts.push(part.peg);
|
|
633
|
-
}
|
|
634
|
-
else if (part instanceof RefVal) {
|
|
635
|
-
this.parts.push(...part.parts);
|
|
636
|
-
if (part.absolute) {
|
|
637
|
-
this.absolute = true;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
this.peg = (this.absolute ? this.sep : '') + this.parts.join(this.sep);
|
|
641
|
-
}
|
|
642
|
-
unify(peer, ctx) {
|
|
643
|
-
let resolved = null == ctx ? this : ctx.find(this);
|
|
644
|
-
// TODO: large amount of reruns needed? why?
|
|
645
|
-
resolved = null == resolved && 999 < this.done ?
|
|
646
|
-
Nil.make(ctx, 'no-path', this, peer) : (resolved || this);
|
|
647
|
-
let out;
|
|
648
|
-
if (resolved instanceof RefVal) {
|
|
649
|
-
if (TOP === peer) {
|
|
650
|
-
out = this;
|
|
651
|
-
}
|
|
652
|
-
else if (peer instanceof Nil) {
|
|
653
|
-
out = Nil.make(ctx, 'ref[' + this.peg + ']', this, peer);
|
|
654
|
-
}
|
|
655
|
-
else {
|
|
656
|
-
// Ensure RefVal done is incremented
|
|
657
|
-
this.done = DONE === this.done ? DONE : this.done + 1;
|
|
658
|
-
out = new ConjunctVal([this, peer], ctx);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
else {
|
|
662
|
-
out = (0, op_1.unite)(ctx, resolved, peer);
|
|
663
|
-
}
|
|
664
|
-
out.done = DONE === out.done ? DONE : this.done + 1;
|
|
665
|
-
return out;
|
|
666
|
-
}
|
|
667
|
-
get canon() {
|
|
668
|
-
return this.peg;
|
|
669
|
-
}
|
|
670
|
-
gen(_ctx) {
|
|
671
|
-
return undefined;
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
exports.RefVal = RefVal;
|
|
675
|
-
class PrefVal extends Val {
|
|
676
|
-
constructor(peg, pref, ctx) {
|
|
677
|
-
super(peg, ctx);
|
|
678
|
-
this.pref = pref || peg;
|
|
679
|
-
}
|
|
680
|
-
// PrefVal unify always returns a PrefVal
|
|
681
|
-
// PrefVals can only be removed by becoming Nil in a Disjunct
|
|
682
|
-
unify(peer, ctx) {
|
|
683
|
-
let done = true;
|
|
684
|
-
let out;
|
|
685
|
-
if (peer instanceof PrefVal) {
|
|
686
|
-
out = new PrefVal((0, op_1.unite)(ctx, this.peg, peer.peg, 'Pref000'), (0, op_1.unite)(ctx, this.pref, peer.pref, 'Pref010'), ctx);
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
out = new PrefVal(
|
|
690
|
-
// TODO: find a better way to drop Nil non-errors
|
|
691
|
-
(0, op_1.unite)(ctx === null || ctx === void 0 ? void 0 : ctx.clone({ err: [] }), this.peg, peer, 'Pref020'), (0, op_1.unite)(ctx === null || ctx === void 0 ? void 0 : ctx.clone({ err: [] }), this.pref, peer, 'Pref030'), ctx);
|
|
692
|
-
}
|
|
693
|
-
done = done && DONE === out.peg.done &&
|
|
694
|
-
(null != out.pref ? DONE === out.pref.done : true);
|
|
695
|
-
if (out.peg instanceof Nil) {
|
|
696
|
-
out = out.pref;
|
|
697
|
-
}
|
|
698
|
-
else if (out.pref instanceof Nil) {
|
|
699
|
-
out = out.peg;
|
|
700
|
-
}
|
|
701
|
-
out.done = done ? DONE : this.done + 1;
|
|
702
|
-
return out;
|
|
703
|
-
}
|
|
704
|
-
get canon() {
|
|
705
|
-
return this.pref instanceof Nil ? this.peg.canon : '*' + this.pref.canon;
|
|
706
|
-
}
|
|
707
|
-
gen(ctx) {
|
|
708
|
-
let val = !(this.pref instanceof Nil) ? this.pref :
|
|
709
|
-
!(this.peg instanceof Nil) ? this.peg :
|
|
710
|
-
undefined;
|
|
711
|
-
return undefined === val ? undefined : val.gen(ctx);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
exports.PrefVal = PrefVal;
|
|
133
|
+
BooleanVal.TRUE = new BooleanVal(true, new unify_1.Context({ vc: 1, root: type_1.TOP }));
|
|
134
|
+
BooleanVal.FALSE = new BooleanVal(false, new unify_1.Context({ vc: 2, root: type_1.TOP }));
|
|
715
135
|
//# sourceMappingURL=val.js.map
|