aontu 0.29.0 → 0.30.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/dist/aontu.d.ts +17 -13
- package/dist/aontu.js +145 -60
- package/dist/aontu.js.map +1 -1
- package/package.json +18 -34
- package/aontu.ts +0 -92
- package/dist/lib/err.d.ts +0 -4
- package/dist/lib/err.js +0 -61
- package/dist/lib/err.js.map +0 -1
- package/dist/lib/lang.d.ts +0 -15
- package/dist/lib/lang.js +0 -409
- package/dist/lib/lang.js.map +0 -1
- package/dist/lib/op/disjunct.d.ts +0 -3
- package/dist/lib/op/disjunct.js +0 -28
- package/dist/lib/op/disjunct.js.map +0 -1
- package/dist/lib/op/op.d.ts +0 -6
- package/dist/lib/op/op.js +0 -9
- package/dist/lib/op/op.js.map +0 -1
- package/dist/lib/op/unite.d.ts +0 -3
- package/dist/lib/op/unite.js +0 -100
- package/dist/lib/op/unite.js.map +0 -1
- package/dist/lib/type.d.ts +0 -49
- package/dist/lib/type.js +0 -7
- package/dist/lib/type.js.map +0 -1
- package/dist/lib/unify.d.ts +0 -38
- package/dist/lib/unify.js +0 -67
- package/dist/lib/unify.js.map +0 -1
- package/dist/lib/utility.d.ts +0 -3
- package/dist/lib/utility.js +0 -16
- package/dist/lib/utility.js.map +0 -1
- package/dist/lib/val/ConjunctVal.d.ts +0 -17
- package/dist/lib/val/ConjunctVal.js +0 -171
- package/dist/lib/val/ConjunctVal.js.map +0 -1
- package/dist/lib/val/DisjunctVal.d.ts +0 -17
- package/dist/lib/val/DisjunctVal.js +0 -95
- package/dist/lib/val/DisjunctVal.js.map +0 -1
- package/dist/lib/val/ListVal.d.ts +0 -18
- package/dist/lib/val/ListVal.js +0 -120
- package/dist/lib/val/ListVal.js.map +0 -1
- package/dist/lib/val/MapVal.d.ts +0 -18
- package/dist/lib/val/MapVal.js +0 -117
- package/dist/lib/val/MapVal.js.map +0 -1
- package/dist/lib/val/Nil.d.ts +0 -22
- package/dist/lib/val/Nil.js +0 -84
- package/dist/lib/val/Nil.js.map +0 -1
- package/dist/lib/val/NullVal.d.ts +0 -15
- package/dist/lib/val/NullVal.js +0 -38
- package/dist/lib/val/NullVal.js.map +0 -1
- package/dist/lib/val/OpVal.d.ts +0 -17
- package/dist/lib/val/OpVal.js +0 -89
- package/dist/lib/val/OpVal.js.map +0 -1
- package/dist/lib/val/PlusVal.d.ts +0 -12
- package/dist/lib/val/PlusVal.js +0 -32
- package/dist/lib/val/PlusVal.js.map +0 -1
- package/dist/lib/val/PrefVal.d.ts +0 -17
- package/dist/lib/val/PrefVal.js +0 -87
- package/dist/lib/val/PrefVal.js.map +0 -1
- package/dist/lib/val/RefVal.d.ts +0 -22
- package/dist/lib/val/RefVal.js +0 -247
- package/dist/lib/val/RefVal.js.map +0 -1
- package/dist/lib/val/ValBase.d.ts +0 -26
- package/dist/lib/val/ValBase.js +0 -77
- package/dist/lib/val/ValBase.js.map +0 -1
- package/dist/lib/val/VarVal.d.ts +0 -15
- package/dist/lib/val/VarVal.js +0 -84
- package/dist/lib/val/VarVal.js.map +0 -1
- package/dist/lib/val.d.ts +0 -81
- package/dist/lib/val.js +0 -191
- package/dist/lib/val.js.map +0 -1
- package/lib/err.ts +0 -83
- package/lib/lang.ts +0 -585
- package/lib/op/disjunct.ts +0 -51
- package/lib/op/op.ts +0 -18
- package/lib/op/unite.ts +0 -143
- package/lib/type.ts +0 -95
- package/lib/unify.ts +0 -128
- package/lib/utility.ts +0 -24
- package/lib/val/ConjunctVal.ts +0 -265
- package/lib/val/DisjunctVal.ts +0 -160
- package/lib/val/ListVal.ts +0 -196
- package/lib/val/MapVal.ts +0 -181
- package/lib/val/Nil.ts +0 -144
- package/lib/val/NullVal.ts +0 -72
- package/lib/val/OpVal.ts +0 -159
- package/lib/val/PlusVal.ts +0 -76
- package/lib/val/PrefVal.ts +0 -154
- package/lib/val/RefVal.ts +0 -362
- package/lib/val/ValBase.ts +0 -109
- package/lib/val/VarVal.ts +0 -157
- package/lib/val.ts +0 -327
package/lib/val/DisjunctVal.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
Val,
|
|
7
|
-
ValSpec,
|
|
8
|
-
} from '../type'
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
DONE,
|
|
12
|
-
} from '../type'
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
Context,
|
|
16
|
-
} from '../unify'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
Site
|
|
21
|
-
} from '../lang'
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
unite
|
|
26
|
-
} from '../op/op'
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// import { TOP } from '../val'
|
|
32
|
-
// import { ConjunctVal } from '../val/ConjunctVal'
|
|
33
|
-
// import { ListVal } from '../val/ListVal'
|
|
34
|
-
// import { MapVal } from '../val/MapVal'
|
|
35
|
-
import { Nil } from '../val/Nil'
|
|
36
|
-
import { PrefVal } from '../val/PrefVal'
|
|
37
|
-
// import { RefVal } from '../val/RefVal'
|
|
38
|
-
import { ValBase } from '../val/ValBase'
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// TODO: move main logic to op/disjunct
|
|
44
|
-
class DisjunctVal extends ValBase {
|
|
45
|
-
isDisjunctVal = true
|
|
46
|
-
isBinaryOp = true
|
|
47
|
-
|
|
48
|
-
// TODO: sites from normalization of orginal Disjuncts, as well as child pegs
|
|
49
|
-
constructor(
|
|
50
|
-
spec: {
|
|
51
|
-
peg: Val[]
|
|
52
|
-
},
|
|
53
|
-
ctx?: Context,
|
|
54
|
-
_sites?: Site[]
|
|
55
|
-
) {
|
|
56
|
-
super(spec, ctx)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// NOTE: mutation!
|
|
60
|
-
append(peer: Val): DisjunctVal {
|
|
61
|
-
this.peg.push(peer)
|
|
62
|
-
return this
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
unify(peer: Val, ctx: Context): Val {
|
|
66
|
-
let done = true
|
|
67
|
-
|
|
68
|
-
let oval: Val[] = []
|
|
69
|
-
|
|
70
|
-
// Conjunction (&) distributes over disjunction (|)
|
|
71
|
-
for (let vI = 0; vI < this.peg.length; vI++) {
|
|
72
|
-
//oval[vI] = this.peg[vI].unify(peer, ctx)
|
|
73
|
-
oval[vI] = unite(ctx, this.peg[vI], peer)
|
|
74
|
-
done = done && DONE === oval[vI].done
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Remove duplicates, and normalize
|
|
78
|
-
if (1 < oval.length) {
|
|
79
|
-
for (let vI = 0; vI < oval.length; vI++) {
|
|
80
|
-
if (oval[vI] instanceof DisjunctVal) {
|
|
81
|
-
oval.splice(vI, 1, ...oval[vI].peg)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// TODO: not an error Nil!
|
|
86
|
-
let remove = new Nil()
|
|
87
|
-
for (let vI = 0; vI < oval.length; vI++) {
|
|
88
|
-
for (let kI = vI + 1; kI < oval.length; kI++) {
|
|
89
|
-
if (oval[kI].same(oval[vI])) {
|
|
90
|
-
oval[kI] = remove
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
oval = oval.filter(v => !(v instanceof Nil))
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let out: Val
|
|
99
|
-
|
|
100
|
-
if (1 == oval.length) {
|
|
101
|
-
out = oval[0]
|
|
102
|
-
}
|
|
103
|
-
else if (0 == oval.length) {
|
|
104
|
-
return Nil.make(ctx, '|:empty', this)
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
out = new DisjunctVal({ peg: oval }, ctx)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
out.done = done ? DONE : this.done + 1
|
|
111
|
-
|
|
112
|
-
return out
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
117
|
-
let out = (super.clone(spec, ctx) as DisjunctVal)
|
|
118
|
-
out.peg = this.peg.map((entry: Val) => entry.clone(null, ctx))
|
|
119
|
-
return out
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
get canon() {
|
|
124
|
-
return this.peg.map((v: Val) => {
|
|
125
|
-
return (v as any).isBinaryOp && Array.isArray(v.peg) && 1 < v.peg.length ?
|
|
126
|
-
'(' + v.canon + ')' : v.canon
|
|
127
|
-
}).join('|')
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
gen(ctx?: Context) {
|
|
132
|
-
|
|
133
|
-
// TODO: this is not right - unresolved Disjuncts eval to undef
|
|
134
|
-
if (0 < this.peg.length) {
|
|
135
|
-
|
|
136
|
-
let vals = this.peg.filter((v: Val) => v instanceof PrefVal)
|
|
137
|
-
|
|
138
|
-
vals = 0 === vals.length ? this.peg : vals
|
|
139
|
-
|
|
140
|
-
let val = vals[0]
|
|
141
|
-
|
|
142
|
-
for (let vI = 1; vI < this.peg.length; vI++) {
|
|
143
|
-
let valnext = val.unify(this.peg[vI], ctx)
|
|
144
|
-
val = valnext
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return val.gen(ctx)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return undefined
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
export {
|
|
159
|
-
DisjunctVal,
|
|
160
|
-
}
|
package/lib/val/ListVal.ts
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2021-2022 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
Val,
|
|
6
|
-
ValList,
|
|
7
|
-
ValSpec,
|
|
8
|
-
} from '../type'
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
DONE,
|
|
12
|
-
} from '../type'
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
Context,
|
|
16
|
-
} from '../unify'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
Site
|
|
21
|
-
} from '../lang'
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
unite
|
|
26
|
-
} from '../op/op'
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
import { TOP } from '../val'
|
|
32
|
-
import { ConjunctVal } from '../val/ConjunctVal'
|
|
33
|
-
// import { DisjunctVal } from '../val/DisjunctVal'
|
|
34
|
-
// import { MapVal } from '../val/MapVal'
|
|
35
|
-
import { Nil } from '../val/Nil'
|
|
36
|
-
// import { PrefVal } from '../val/PrefVal'
|
|
37
|
-
// import { RefVal } from '../val/RefVal'
|
|
38
|
-
import { ValBase } from '../val/ValBase'
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
class ListVal extends ValBase {
|
|
45
|
-
isListVal = true
|
|
46
|
-
|
|
47
|
-
static SPREAD = Symbol('spread')
|
|
48
|
-
|
|
49
|
-
spread = {
|
|
50
|
-
cj: (undefined as Val | undefined),
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
constructor(
|
|
54
|
-
spec: {
|
|
55
|
-
peg: ValList
|
|
56
|
-
},
|
|
57
|
-
ctx?: Context
|
|
58
|
-
) {
|
|
59
|
-
super(spec, ctx)
|
|
60
|
-
|
|
61
|
-
if (null == this.peg) {
|
|
62
|
-
throw new Error('ListVal spec.peg undefined')
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let spread = (this.peg as any)[ListVal.SPREAD]
|
|
66
|
-
delete (this.peg as any)[ListVal.SPREAD]
|
|
67
|
-
|
|
68
|
-
if (spread) {
|
|
69
|
-
if ('&' === spread.o) {
|
|
70
|
-
|
|
71
|
-
// TODO: handle existing spread!
|
|
72
|
-
this.spread.cj =
|
|
73
|
-
Array.isArray(spread.v) ?
|
|
74
|
-
1 < spread.v.length ?
|
|
75
|
-
new ConjunctVal({ peg: spread.v }, ctx) :
|
|
76
|
-
spread.v :
|
|
77
|
-
spread.v
|
|
78
|
-
|
|
79
|
-
// let tmv = Array.isArray(spread.v) ? spread.v : [spread.v]
|
|
80
|
-
// this.spread.cj = new ConjunctVal({ peg: tmv }, ctx)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// NOTE: order of keys is not preserved!
|
|
87
|
-
// not possible in any case - consider {a,b} unify {b,a}
|
|
88
|
-
unify(peer: Val, ctx: Context): Val {
|
|
89
|
-
let done: boolean = true
|
|
90
|
-
let out: ListVal = TOP === peer ? this : new ListVal({ peg: [] }, ctx)
|
|
91
|
-
|
|
92
|
-
out.spread.cj = this.spread.cj
|
|
93
|
-
|
|
94
|
-
if (peer instanceof ListVal) {
|
|
95
|
-
out.spread.cj = null == out.spread.cj ? peer.spread.cj : (
|
|
96
|
-
null == peer.spread.cj ? out.spread.cj : (
|
|
97
|
-
out.spread.cj =
|
|
98
|
-
// new ConjunctVal({ peg: [out.spread.cj, peer.spread.cj] }, ctx)
|
|
99
|
-
unite(ctx, out.spread.cj, peer.spread.cj)
|
|
100
|
-
)
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
out.done = this.done + 1
|
|
106
|
-
|
|
107
|
-
// if (this.spread.cj) {
|
|
108
|
-
// out.spread.cj =
|
|
109
|
-
// DONE !== this.spread.cj.done ? unite(ctx, this.spread.cj) :
|
|
110
|
-
// this.spread.cj
|
|
111
|
-
// }
|
|
112
|
-
|
|
113
|
-
let spread_cj = out.spread.cj || TOP
|
|
114
|
-
|
|
115
|
-
// Always unify children first
|
|
116
|
-
for (let key in this.peg) {
|
|
117
|
-
let keyctx = ctx.descend(key)
|
|
118
|
-
let key_spread_cj = spread_cj.clone(null, keyctx)
|
|
119
|
-
|
|
120
|
-
out.peg[key] = unite(keyctx, this.peg[key], key_spread_cj, 'list-own')
|
|
121
|
-
done = (done && DONE === out.peg[key].done)
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (peer instanceof ListVal) {
|
|
126
|
-
let upeer: ListVal = (unite(ctx, peer, undefined, 'list-peer-list') as ListVal)
|
|
127
|
-
|
|
128
|
-
// NOTE: peerkey is the index
|
|
129
|
-
for (let peerkey in upeer.peg) {
|
|
130
|
-
let peerchild = upeer.peg[peerkey]
|
|
131
|
-
let child = out.peg[peerkey]
|
|
132
|
-
|
|
133
|
-
let oval = out.peg[peerkey] =
|
|
134
|
-
undefined === child ? peerchild :
|
|
135
|
-
child instanceof Nil ? child :
|
|
136
|
-
peerchild instanceof Nil ? peerchild :
|
|
137
|
-
unite(ctx.descend(peerkey), child, peerchild, 'list-peer')
|
|
138
|
-
|
|
139
|
-
if (this.spread.cj) {
|
|
140
|
-
let key_ctx = ctx.descend(peerkey)
|
|
141
|
-
let key_spread_cj = spread_cj.clone(null, key_ctx)
|
|
142
|
-
|
|
143
|
-
// out.peg[peerkey] = unite(ctx, out.peg[peerkey], spread_cj)
|
|
144
|
-
oval = out.peg[peerkey] =
|
|
145
|
-
// new ConjunctVal({ peg: [out.peg[peerkey], key_spread_cj] }, key_ctx)
|
|
146
|
-
// done = false
|
|
147
|
-
unite(key_ctx, out.peg[peerkey], key_spread_cj)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
done = (done && DONE === oval.done)
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else if (TOP !== peer) {
|
|
155
|
-
return Nil.make(ctx, 'map', this, peer)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
out.done = done ? DONE : out.done
|
|
159
|
-
return out
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
164
|
-
let out = (super.clone(spec, ctx) as ListVal)
|
|
165
|
-
out.peg = this.peg.map((entry: Val) => entry.clone(null, ctx))
|
|
166
|
-
if (this.spread.cj) {
|
|
167
|
-
out.spread.cj = this.spread.cj.clone(null, ctx)
|
|
168
|
-
}
|
|
169
|
-
return out
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
get canon() {
|
|
174
|
-
let keys = Object.keys(this.peg)
|
|
175
|
-
return '[' +
|
|
176
|
-
(this.spread.cj ? '&:' + this.spread.cj.canon +
|
|
177
|
-
(0 < keys.length ? ',' : '') : '') +
|
|
178
|
-
keys
|
|
179
|
-
// NOTE: handle array non-index key vals
|
|
180
|
-
.map(k => [this.peg[k].canon]).join(',') +
|
|
181
|
-
']'
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
gen(ctx?: Context) {
|
|
185
|
-
let out: any = this.peg.map((v: Val) => v.gen(ctx))
|
|
186
|
-
|
|
187
|
-
return out
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
export {
|
|
195
|
-
ListVal,
|
|
196
|
-
}
|
package/lib/val/MapVal.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
Val,
|
|
7
|
-
ValMap,
|
|
8
|
-
ValSpec,
|
|
9
|
-
} from '../type'
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
DONE,
|
|
13
|
-
} from '../type'
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
Context,
|
|
17
|
-
} from '../unify'
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
unite
|
|
23
|
-
} from '../op/op'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
import { TOP } from '../val'
|
|
28
|
-
import { ConjunctVal } from '../val/ConjunctVal'
|
|
29
|
-
// import { DisjunctVal } from '../val/DisjunctVal'
|
|
30
|
-
// import { ListVal } from '../val/ListVal'
|
|
31
|
-
import { Nil } from '../val/Nil'
|
|
32
|
-
// import { PrefVal } from '../val/PrefVal'
|
|
33
|
-
// import { RefVal } from '../val/RefVal'
|
|
34
|
-
import { ValBase } from '../val/ValBase'
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class MapVal extends ValBase {
|
|
38
|
-
isMapVal = true
|
|
39
|
-
|
|
40
|
-
static SPREAD = Symbol('spread')
|
|
41
|
-
|
|
42
|
-
spread = {
|
|
43
|
-
cj: (undefined as Val | undefined),
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
constructor(
|
|
47
|
-
spec: {
|
|
48
|
-
peg: ValMap
|
|
49
|
-
},
|
|
50
|
-
ctx?: Context
|
|
51
|
-
) {
|
|
52
|
-
super(spec, ctx)
|
|
53
|
-
|
|
54
|
-
if (null == this.peg) {
|
|
55
|
-
throw new Error('MapVal spec.peg undefined')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let spread = (this.peg as any)[MapVal.SPREAD]
|
|
59
|
-
delete (this.peg as any)[MapVal.SPREAD]
|
|
60
|
-
|
|
61
|
-
if (spread) {
|
|
62
|
-
if ('&' === spread.o) {
|
|
63
|
-
// TODO: handle existing spread!
|
|
64
|
-
this.spread.cj =
|
|
65
|
-
Array.isArray(spread.v) ?
|
|
66
|
-
1 < spread.v.length ?
|
|
67
|
-
new ConjunctVal({ peg: spread.v }, ctx) :
|
|
68
|
-
spread.v[0] :
|
|
69
|
-
spread.v
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// NOTE: order of keys is not preserved!
|
|
76
|
-
// not possible in any case - consider {a,b} unify {b,a}
|
|
77
|
-
unify(peer: Val, ctx: Context): Val {
|
|
78
|
-
// let mark = Math.random()
|
|
79
|
-
|
|
80
|
-
let done: boolean = true
|
|
81
|
-
let out: MapVal = TOP === peer ? this : new MapVal({ peg: {} }, ctx)
|
|
82
|
-
|
|
83
|
-
out.spread.cj = this.spread.cj
|
|
84
|
-
|
|
85
|
-
if (peer instanceof MapVal) {
|
|
86
|
-
out.spread.cj = null == out.spread.cj ? peer.spread.cj : (
|
|
87
|
-
null == peer.spread.cj ? out.spread.cj : (
|
|
88
|
-
out.spread.cj =
|
|
89
|
-
// new ConjunctVal({ peg: [out.spread.cj, peer.spread.cj] }, ctx)
|
|
90
|
-
unite(ctx, out.spread.cj, peer.spread.cj)
|
|
91
|
-
)
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
out.done = this.done + 1
|
|
97
|
-
|
|
98
|
-
let spread_cj = out.spread.cj || TOP
|
|
99
|
-
|
|
100
|
-
// Always unify own children first
|
|
101
|
-
for (let key in this.peg) {
|
|
102
|
-
let keyctx = ctx.descend(key)
|
|
103
|
-
let key_spread_cj = spread_cj.clone(null, keyctx)
|
|
104
|
-
|
|
105
|
-
out.peg[key] = unite(keyctx, this.peg[key], key_spread_cj, 'map-own')
|
|
106
|
-
done = (done && DONE === out.peg[key].done)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (peer instanceof MapVal) {
|
|
111
|
-
let upeer: MapVal = (unite(ctx, peer, undefined, 'map-peer-map') as MapVal)
|
|
112
|
-
|
|
113
|
-
for (let peerkey in upeer.peg) {
|
|
114
|
-
let peerchild = upeer.peg[peerkey]
|
|
115
|
-
let child = out.peg[peerkey]
|
|
116
|
-
|
|
117
|
-
let oval = out.peg[peerkey] =
|
|
118
|
-
undefined === child ? peerchild :
|
|
119
|
-
child instanceof Nil ? child :
|
|
120
|
-
peerchild instanceof Nil ? peerchild :
|
|
121
|
-
unite(ctx.descend(peerkey), child, peerchild, 'map-peer')
|
|
122
|
-
|
|
123
|
-
if (this.spread.cj) {
|
|
124
|
-
let key_ctx = ctx.descend(peerkey)
|
|
125
|
-
let key_spread_cj = spread_cj.clone(null, key_ctx)
|
|
126
|
-
oval = out.peg[peerkey] =
|
|
127
|
-
unite(key_ctx, out.peg[peerkey], key_spread_cj)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
done = (done && DONE === oval.done)
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else if (TOP !== peer) {
|
|
134
|
-
return Nil.make(ctx, 'map', this, peer)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
out.uh.push(peer.id)
|
|
138
|
-
|
|
139
|
-
out.done = done ? DONE : out.done
|
|
140
|
-
return out
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
145
|
-
let out = (super.clone(spec, ctx) as MapVal)
|
|
146
|
-
out.peg = {}
|
|
147
|
-
for (let entry of Object.entries(this.peg)) {
|
|
148
|
-
out.peg[entry[0]] =
|
|
149
|
-
entry[1] instanceof ValBase ? entry[1].clone(null, ctx) : entry[1]
|
|
150
|
-
}
|
|
151
|
-
if (this.spread.cj) {
|
|
152
|
-
out.spread.cj = this.spread.cj.clone(null, ctx)
|
|
153
|
-
}
|
|
154
|
-
return out
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
get canon() {
|
|
159
|
-
let keys = Object.keys(this.peg)
|
|
160
|
-
return '{' +
|
|
161
|
-
(this.spread.cj ? '&:' + this.spread.cj.canon +
|
|
162
|
-
(0 < keys.length ? ',' : '') : '') +
|
|
163
|
-
keys
|
|
164
|
-
.map(k => [JSON.stringify(k) + ':' + this.peg[k].canon]).join(',') +
|
|
165
|
-
'}'
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
gen(ctx?: Context) {
|
|
170
|
-
let out: any = {}
|
|
171
|
-
for (let p in this.peg) {
|
|
172
|
-
out[p] = this.peg[p].gen(ctx)
|
|
173
|
-
}
|
|
174
|
-
return out
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
export {
|
|
180
|
-
MapVal
|
|
181
|
-
}
|
package/lib/val/Nil.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
Val,
|
|
6
|
-
ValSpec,
|
|
7
|
-
} from '../type'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
DONE,
|
|
11
|
-
} from '../type'
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
descErr
|
|
15
|
-
} from '../err'
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
Context,
|
|
19
|
-
} from '../unify'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import { ValBase } from '../val/ValBase'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class Nil extends ValBase {
|
|
26
|
-
isNil = true
|
|
27
|
-
|
|
28
|
-
nil = true
|
|
29
|
-
why: any
|
|
30
|
-
primary?: Val
|
|
31
|
-
secondary?: Val
|
|
32
|
-
msg: string = ''
|
|
33
|
-
|
|
34
|
-
// TODO: include Val generating nil, thus capture type
|
|
35
|
-
|
|
36
|
-
// A Nil is an error - should not happen - unify failed
|
|
37
|
-
// refactor ,make(spec,ctx)
|
|
38
|
-
static make = (ctx?: Context, why?: any, av?: Val, bv?: Val) => {
|
|
39
|
-
let nil = new Nil({ why }, ctx)
|
|
40
|
-
|
|
41
|
-
// TODO: this should be done lazily, for multiple terms
|
|
42
|
-
|
|
43
|
-
// Terms later in same file are considered the primary error location.
|
|
44
|
-
if (null != av) {
|
|
45
|
-
nil.row = av.row
|
|
46
|
-
nil.col = av.col
|
|
47
|
-
nil.url = av.url
|
|
48
|
-
|
|
49
|
-
nil.primary = av
|
|
50
|
-
|
|
51
|
-
if (null != bv) {
|
|
52
|
-
nil.secondary = bv
|
|
53
|
-
|
|
54
|
-
let bv_loc_wins =
|
|
55
|
-
(nil.url === bv.url) && (
|
|
56
|
-
(nil.row < bv.row) ||
|
|
57
|
-
(nil.row === bv.row && nil.col < bv.col)
|
|
58
|
-
)
|
|
59
|
-
|
|
60
|
-
if (bv_loc_wins) {
|
|
61
|
-
nil.row = bv.row
|
|
62
|
-
nil.col = bv.col
|
|
63
|
-
nil.url = bv.url
|
|
64
|
-
nil.primary = bv
|
|
65
|
-
nil.secondary = av
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (ctx) {
|
|
71
|
-
ctx.err.push(nil)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return nil
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
constructor(
|
|
79
|
-
spec?: {
|
|
80
|
-
why?: string
|
|
81
|
-
msg?: string
|
|
82
|
-
err?: Nil | Nil[] | Error | Error[]
|
|
83
|
-
} | string,
|
|
84
|
-
ctx?: Context
|
|
85
|
-
) {
|
|
86
|
-
super(spec && 'string' !== typeof spec ? spec : {}, ctx)
|
|
87
|
-
|
|
88
|
-
if (spec && 'object' === typeof spec) {
|
|
89
|
-
this.why = spec?.why
|
|
90
|
-
this.msg = 'string' === typeof spec?.msg ? spec.msg : this.msg
|
|
91
|
-
this.err = spec ? (Array.isArray(spec.err) ? [...spec.err] : [spec.err]) : []
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Nil is always DONE, by definition.
|
|
95
|
-
this.done = DONE
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
unify(_peer: Val, _ctx: Context) {
|
|
100
|
-
return this
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
105
|
-
let out = (super.clone(spec, ctx) as Nil)
|
|
106
|
-
out.why = this.why
|
|
107
|
-
|
|
108
|
-
// Should these clone?
|
|
109
|
-
// out.primary = this.primary?.clone()
|
|
110
|
-
// out.secondary = this.secondary?.clone()
|
|
111
|
-
out.primary = this.primary
|
|
112
|
-
out.secondary = this.secondary
|
|
113
|
-
|
|
114
|
-
out.msg = this.msg
|
|
115
|
-
return out
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
get canon() {
|
|
120
|
-
return 'nil'
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
gen(ctx?: Context) {
|
|
124
|
-
// Unresolved nil cannot be generated, so always an error.
|
|
125
|
-
|
|
126
|
-
descErr(this, ctx)
|
|
127
|
-
|
|
128
|
-
if (Array.isArray(ctx?.err)) {
|
|
129
|
-
ctx.err.push(this)
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
const err: any = new Error(this.msg)
|
|
133
|
-
err.aontu = true
|
|
134
|
-
throw err
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return undefined
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
export {
|
|
143
|
-
Nil,
|
|
144
|
-
}
|