aontu 0.11.0 → 0.13.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/aontu.ts +13 -6
- package/dist/aontu.d.ts +3 -0
- package/dist/aontu.js +10 -4
- package/dist/aontu.js.map +1 -1
- package/dist/aontu.min.js +1 -1
- package/dist/lib/err.js +1 -1
- package/dist/lib/err.js.map +1 -1
- package/dist/lib/lang.d.ts +1 -2
- package/dist/lib/lang.js +130 -38
- package/dist/lib/lang.js.map +1 -1
- package/dist/lib/op/disjunct.js +2 -2
- package/dist/lib/op/disjunct.js.map +1 -1
- package/dist/lib/op/op.js +1 -1
- package/dist/lib/op/op.js.map +1 -1
- package/dist/lib/op/unite.js +36 -6
- package/dist/lib/op/unite.js.map +1 -1
- package/dist/lib/type.d.ts +10 -8
- package/dist/lib/type.js +2 -27
- package/dist/lib/type.js.map +1 -1
- package/dist/lib/unify.d.ts +7 -4
- package/dist/lib/unify.js +17 -29
- package/dist/lib/unify.js.map +1 -1
- package/dist/lib/val/ConjunctVal.d.ts +7 -4
- package/dist/lib/val/ConjunctVal.js +62 -31
- package/dist/lib/val/ConjunctVal.js.map +1 -1
- package/dist/lib/val/DisjunctVal.d.ts +5 -2
- package/dist/lib/val/DisjunctVal.js +15 -7
- package/dist/lib/val/DisjunctVal.js.map +1 -1
- package/dist/lib/val/ListVal.d.ts +5 -2
- package/dist/lib/val/ListVal.js +39 -19
- package/dist/lib/val/ListVal.js.map +1 -1
- package/dist/lib/val/MapVal.d.ts +5 -2
- package/dist/lib/val/MapVal.js +59 -30
- package/dist/lib/val/MapVal.js.map +1 -1
- package/dist/lib/val/Nil.d.ts +3 -2
- package/dist/lib/val/Nil.js +19 -5
- package/dist/lib/val/Nil.js.map +1 -1
- package/dist/lib/val/PrefVal.d.ts +6 -2
- package/dist/lib/val/PrefVal.js +18 -8
- package/dist/lib/val/PrefVal.js.map +1 -1
- package/dist/lib/val/RefVal.d.ts +11 -5
- package/dist/lib/val/RefVal.js +187 -39
- package/dist/lib/val/RefVal.js.map +1 -1
- package/dist/lib/val/ValBase.d.ts +10 -9
- package/dist/lib/val/ValBase.js +25 -6
- package/dist/lib/val/ValBase.js.map +1 -1
- package/dist/lib/val/VarVal.d.ts +14 -0
- package/dist/lib/val/VarVal.js +68 -0
- package/dist/lib/val/VarVal.js.map +1 -0
- package/dist/lib/val.d.ts +42 -8
- package/dist/lib/val.js +64 -18
- package/dist/lib/val.js.map +1 -1
- package/lib/err.ts +1 -1
- package/lib/lang.ts +168 -43
- package/lib/op/disjunct.ts +10 -3
- package/lib/op/op.ts +1 -1
- package/lib/op/unite.ts +44 -4
- package/lib/type.ts +12 -40
- package/lib/unify.ts +70 -29
- package/lib/val/ConjunctVal.ts +83 -46
- package/lib/val/DisjunctVal.ts +35 -12
- package/lib/val/ListVal.ts +57 -22
- package/lib/val/MapVal.ts +82 -51
- package/lib/val/Nil.ts +29 -9
- package/lib/val/PrefVal.ts +38 -14
- package/lib/val/RefVal.ts +254 -55
- package/lib/val/ValBase.ts +33 -28
- package/lib/val/VarVal.ts +139 -0
- package/lib/val.ts +116 -25
- package/package.json +8 -8
- package/dist/lib/common.d.ts +0 -8
- package/dist/lib/common.js +0 -3
- package/dist/lib/common.js.map +0 -1
package/lib/val/MapVal.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/* Copyright (c) 2021 Richard Rodger, MIT License */
|
|
1
|
+
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
import type {
|
|
6
6
|
Val,
|
|
7
7
|
ValMap,
|
|
8
|
+
ValSpec,
|
|
8
9
|
} from '../type'
|
|
9
10
|
|
|
10
11
|
import {
|
|
11
12
|
DONE,
|
|
12
|
-
TOP,
|
|
13
13
|
} from '../type'
|
|
14
14
|
|
|
15
15
|
import {
|
|
@@ -17,30 +17,21 @@ import {
|
|
|
17
17
|
} from '../unify'
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
Site
|
|
22
|
-
} from '../lang'
|
|
23
|
-
|
|
24
20
|
|
|
25
21
|
import {
|
|
26
22
|
unite
|
|
27
23
|
} from '../op/op'
|
|
28
24
|
|
|
29
|
-
import {
|
|
30
|
-
ValBase,
|
|
31
|
-
} from '../val/ValBase'
|
|
32
|
-
|
|
33
|
-
import {
|
|
34
|
-
Nil,
|
|
35
|
-
} from './Nil'
|
|
36
|
-
|
|
37
|
-
import {
|
|
38
|
-
ConjunctVal,
|
|
39
|
-
} from './ConjunctVal'
|
|
40
|
-
|
|
41
|
-
|
|
42
25
|
|
|
43
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'
|
|
44
35
|
|
|
45
36
|
|
|
46
37
|
class MapVal extends ValBase {
|
|
@@ -50,37 +41,48 @@ class MapVal extends ValBase {
|
|
|
50
41
|
cj: (undefined as Val | undefined),
|
|
51
42
|
}
|
|
52
43
|
|
|
53
|
-
constructor(
|
|
54
|
-
|
|
44
|
+
constructor(
|
|
45
|
+
spec: {
|
|
46
|
+
peg: ValMap
|
|
47
|
+
},
|
|
48
|
+
ctx?: Context
|
|
49
|
+
) {
|
|
50
|
+
super(spec, ctx)
|
|
51
|
+
|
|
52
|
+
if (null == this.peg) {
|
|
53
|
+
throw new Error('MapVal spec.peg undefined')
|
|
54
|
+
}
|
|
55
|
+
|
|
55
56
|
|
|
56
57
|
let spread = (this.peg as any)[MapVal.SPREAD]
|
|
57
58
|
delete (this.peg as any)[MapVal.SPREAD]
|
|
58
59
|
|
|
60
|
+
// console.log('MC', this.id, peg, spread)
|
|
61
|
+
|
|
59
62
|
if (spread) {
|
|
60
63
|
if ('&' === spread.o) {
|
|
61
|
-
|
|
62
|
-
this.spread.cj =
|
|
63
|
-
new ConjunctVal(Array.isArray(spread.v) ? spread.v : [spread.v], ctx)
|
|
64
|
+
let tmv = Array.isArray(spread.v) ? spread.v : [spread.v]
|
|
65
|
+
this.spread.cj = new ConjunctVal({ peg: tmv }, ctx)
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
|
|
68
71
|
// NOTE: order of keys is not preserved!
|
|
69
72
|
// not possible in any case - consider {a,b} unify {b,a}
|
|
70
73
|
unify(peer: Val, ctx: Context): Val {
|
|
71
|
-
//
|
|
72
|
-
// console.trace()
|
|
73
|
-
// }
|
|
74
|
+
// let mark = Math.random()
|
|
74
75
|
|
|
75
76
|
let done: boolean = true
|
|
76
|
-
let out: MapVal = TOP === peer ? this : new MapVal({}, ctx)
|
|
77
|
+
let out: MapVal = TOP === peer ? this : new MapVal({ peg: {} }, ctx)
|
|
77
78
|
|
|
78
79
|
out.spread.cj = this.spread.cj
|
|
79
80
|
|
|
80
81
|
if (peer instanceof MapVal) {
|
|
81
82
|
out.spread.cj = null == out.spread.cj ? peer.spread.cj : (
|
|
82
83
|
null == peer.spread.cj ? out.spread.cj : (
|
|
83
|
-
out.spread.cj =
|
|
84
|
+
out.spread.cj =
|
|
85
|
+
new ConjunctVal({ peg: [out.spread.cj, peer.spread.cj] }, ctx)
|
|
84
86
|
)
|
|
85
87
|
)
|
|
86
88
|
}
|
|
@@ -88,32 +90,37 @@ class MapVal extends ValBase {
|
|
|
88
90
|
|
|
89
91
|
out.done = this.done + 1
|
|
90
92
|
|
|
91
|
-
if (this.spread.cj) {
|
|
92
|
-
out.spread.cj =
|
|
93
|
-
DONE !== this.spread.cj.done ? unite(ctx, this.spread.cj) :
|
|
94
|
-
this.spread.cj
|
|
95
|
-
done = (done && DONE === out.spread.cj.done)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
93
|
let spread_cj = out.spread.cj || TOP
|
|
100
94
|
|
|
101
|
-
// Always unify children first
|
|
95
|
+
// Always unify own children first
|
|
102
96
|
for (let key in this.peg) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
|
|
97
|
+
let keyctx = ctx.descend(key)
|
|
98
|
+
let key_spread_cj = spread_cj.clone(null, keyctx)
|
|
99
|
+
|
|
100
|
+
// console.log('M0', this.id, mark, Object.keys(this.peg).join('~'),
|
|
101
|
+
// 'p=', this.path.join('.'),
|
|
102
|
+
// 'k=', key, peer.top || peer.constructor.name,
|
|
103
|
+
// 'pp=', this.peg[key].path.join('.'),
|
|
104
|
+
// this.peg[key].canon,
|
|
105
|
+
// 'sp=', key_spread_cj.path.join('.'),
|
|
106
|
+
// key_spread_cj.canon)
|
|
107
|
+
|
|
108
|
+
// if (1000000000 === this.id) {
|
|
109
|
+
// console.dir(key_spread_cj, { depth: null })
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
out.peg[key] = unite(keyctx, this.peg[key], key_spread_cj, 'map-own')
|
|
110
113
|
done = (done && DONE === out.peg[key].done)
|
|
111
114
|
}
|
|
112
115
|
|
|
116
|
+
|
|
113
117
|
if (peer instanceof MapVal) {
|
|
114
|
-
let upeer: MapVal = (unite(ctx, peer) as MapVal)
|
|
118
|
+
let upeer: MapVal = (unite(ctx, peer, undefined, 'map-peer-map') as MapVal)
|
|
115
119
|
|
|
116
120
|
for (let peerkey in upeer.peg) {
|
|
121
|
+
// console.log('M1', this.id, mark, Object.keys(this.peg).join('~'),
|
|
122
|
+
// 'pk=', peerkey)
|
|
123
|
+
|
|
117
124
|
let peerchild = upeer.peg[peerkey]
|
|
118
125
|
let child = out.peg[peerkey]
|
|
119
126
|
|
|
@@ -121,14 +128,19 @@ class MapVal extends ValBase {
|
|
|
121
128
|
undefined === child ? peerchild :
|
|
122
129
|
child instanceof Nil ? child :
|
|
123
130
|
peerchild instanceof Nil ? peerchild :
|
|
124
|
-
unite(ctx.descend(peerkey), child, peerchild)
|
|
131
|
+
unite(ctx.descend(peerkey), child, peerchild, 'map-peer')
|
|
125
132
|
|
|
126
133
|
if (this.spread.cj) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
done = (done && DONE === oval.done)
|
|
134
|
+
let key_ctx = ctx.descend(peerkey)
|
|
135
|
+
let key_spread_cj = spread_cj.clone(null, key_ctx)
|
|
131
136
|
|
|
137
|
+
out.peg[peerkey] =
|
|
138
|
+
new ConjunctVal({ peg: [out.peg[peerkey], key_spread_cj] }, key_ctx)
|
|
139
|
+
done = false
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
done = (done && DONE === oval.done)
|
|
143
|
+
}
|
|
132
144
|
}
|
|
133
145
|
}
|
|
134
146
|
else if (TOP !== peer) {
|
|
@@ -140,6 +152,20 @@ class MapVal extends ValBase {
|
|
|
140
152
|
}
|
|
141
153
|
|
|
142
154
|
|
|
155
|
+
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
156
|
+
let out = (super.clone(spec, ctx) as MapVal)
|
|
157
|
+
out.peg = {}
|
|
158
|
+
for (let entry of Object.entries(this.peg)) {
|
|
159
|
+
out.peg[entry[0]] =
|
|
160
|
+
entry[1] instanceof ValBase ? entry[1].clone(null, ctx) : entry[1]
|
|
161
|
+
}
|
|
162
|
+
if (this.spread.cj) {
|
|
163
|
+
out.spread.cj = this.spread.cj.clone(null, ctx)
|
|
164
|
+
}
|
|
165
|
+
return out
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
143
169
|
get canon() {
|
|
144
170
|
let keys = Object.keys(this.peg)
|
|
145
171
|
return '{' +
|
|
@@ -156,6 +182,11 @@ class MapVal extends ValBase {
|
|
|
156
182
|
for (let p in this.peg) {
|
|
157
183
|
out[p] = this.peg[p].gen(ctx)
|
|
158
184
|
}
|
|
185
|
+
|
|
186
|
+
// if (0 === Object.keys(out).length) {
|
|
187
|
+
// console.log('MapVal-gen 0', this.path, this.done)
|
|
188
|
+
// }
|
|
189
|
+
|
|
159
190
|
return out
|
|
160
191
|
}
|
|
161
192
|
}
|
package/lib/val/Nil.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
/* Copyright (c) 2021-
|
|
1
|
+
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
import type {
|
|
5
5
|
Val,
|
|
6
|
+
ValSpec,
|
|
6
7
|
} from '../type'
|
|
7
8
|
|
|
8
9
|
import {
|
|
@@ -14,10 +15,7 @@ import {
|
|
|
14
15
|
} from '../unify'
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
import {
|
|
18
|
-
ValBase,
|
|
19
|
-
} from '../val/ValBase'
|
|
20
|
-
|
|
18
|
+
import { ValBase } from '../val/ValBase'
|
|
21
19
|
|
|
22
20
|
|
|
23
21
|
|
|
@@ -32,8 +30,9 @@ class Nil extends ValBase {
|
|
|
32
30
|
// TODO: include Val generating nil, thus capture type
|
|
33
31
|
|
|
34
32
|
// A Nil is an error - should not happen - unify failed
|
|
33
|
+
// refactor ,make(spec,ctx)
|
|
35
34
|
static make = (ctx?: Context, why?: any, av?: Val, bv?: Val) => {
|
|
36
|
-
let nil = new Nil(why, ctx)
|
|
35
|
+
let nil = new Nil({ why }, ctx)
|
|
37
36
|
|
|
38
37
|
// TODO: this should be done lazily, for multiple terms
|
|
39
38
|
|
|
@@ -71,27 +70,48 @@ class Nil extends ValBase {
|
|
|
71
70
|
return nil
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
|
|
74
|
+
constructor(spec?: any, ctx?: Context) {
|
|
75
|
+
super(spec, ctx)
|
|
76
|
+
this.why = spec?.why
|
|
77
77
|
|
|
78
78
|
// Nil is always DONE, by definition.
|
|
79
79
|
this.done = DONE
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
|
|
82
83
|
unify(_peer: Val, _ctx: Context) {
|
|
83
84
|
return this
|
|
84
85
|
}
|
|
85
86
|
|
|
87
|
+
|
|
88
|
+
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
89
|
+
let out = (super.clone(spec, ctx) as Nil)
|
|
90
|
+
out.why = this.why
|
|
91
|
+
|
|
92
|
+
// Should these clone?
|
|
93
|
+
// out.primary = this.primary?.clone()
|
|
94
|
+
// out.secondary = this.secondary?.clone()
|
|
95
|
+
out.primary = this.primary
|
|
96
|
+
out.secondary = this.secondary
|
|
97
|
+
|
|
98
|
+
out.msg = this.msg
|
|
99
|
+
return out
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
86
103
|
get canon() {
|
|
87
104
|
return 'nil'
|
|
88
105
|
}
|
|
89
106
|
|
|
90
107
|
gen(_ctx?: Context) {
|
|
108
|
+
// TODO: proper gen error
|
|
109
|
+
throw new Error('Nil-gen: ' + this.why)
|
|
91
110
|
return undefined
|
|
92
111
|
}
|
|
93
112
|
}
|
|
94
113
|
|
|
114
|
+
|
|
95
115
|
export {
|
|
96
116
|
Nil,
|
|
97
117
|
}
|
package/lib/val/PrefVal.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
/* Copyright (c) 2021-
|
|
1
|
+
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
|
+
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
import type {
|
|
5
6
|
Val,
|
|
7
|
+
ValSpec,
|
|
6
8
|
} from '../type'
|
|
7
9
|
|
|
8
10
|
import {
|
|
@@ -23,19 +25,30 @@ import {
|
|
|
23
25
|
unite
|
|
24
26
|
} from '../op/op'
|
|
25
27
|
|
|
26
|
-
import { Nil } from '../val/Nil'
|
|
27
28
|
|
|
28
|
-
import {
|
|
29
|
-
ValBase,
|
|
30
|
-
} from '../val/ValBase'
|
|
31
29
|
|
|
30
|
+
import { TOP } from '../val'
|
|
31
|
+
import { ConjunctVal } from '../val/ConjunctVal'
|
|
32
|
+
import { DisjunctVal } from '../val/DisjunctVal'
|
|
33
|
+
import { ListVal } from '../val/ListVal'
|
|
34
|
+
import { MapVal } from '../val/MapVal'
|
|
35
|
+
import { Nil } from '../val/Nil'
|
|
36
|
+
import { RefVal } from '../val/RefVal'
|
|
37
|
+
import { ValBase } from '../val/ValBase'
|
|
32
38
|
|
|
33
39
|
|
|
34
40
|
class PrefVal extends ValBase {
|
|
35
41
|
pref: Val
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
|
|
43
|
+
constructor(
|
|
44
|
+
spec: {
|
|
45
|
+
peg: any,
|
|
46
|
+
pref?: any
|
|
47
|
+
},
|
|
48
|
+
ctx?: Context
|
|
49
|
+
) {
|
|
50
|
+
super(spec, ctx)
|
|
51
|
+
this.pref = spec.pref || spec.peg
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
// PrefVal unify always returns a PrefVal
|
|
@@ -46,17 +59,21 @@ class PrefVal extends ValBase {
|
|
|
46
59
|
|
|
47
60
|
if (peer instanceof PrefVal) {
|
|
48
61
|
out = new PrefVal(
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
{
|
|
63
|
+
peg: unite(ctx, this.peg, peer.peg, 'Pref000'),
|
|
64
|
+
pref: unite(ctx, this.pref, peer.pref, 'Pref010'),
|
|
65
|
+
},
|
|
51
66
|
ctx
|
|
52
67
|
)
|
|
53
|
-
|
|
54
68
|
}
|
|
69
|
+
|
|
55
70
|
else {
|
|
56
71
|
out = new PrefVal(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
{
|
|
73
|
+
// TODO: find a better way to drop Nil non-errors
|
|
74
|
+
peg: unite(ctx?.clone({ err: [] }), this.peg, peer, 'Pref020'),
|
|
75
|
+
pref: unite(ctx?.clone({ err: [] }), this.pref, peer, 'Pref030'),
|
|
76
|
+
},
|
|
60
77
|
ctx
|
|
61
78
|
)
|
|
62
79
|
}
|
|
@@ -93,6 +110,13 @@ class PrefVal extends ValBase {
|
|
|
93
110
|
}
|
|
94
111
|
|
|
95
112
|
|
|
113
|
+
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
114
|
+
let out = (super.clone(spec, ctx) as PrefVal)
|
|
115
|
+
out.pref = this.pref.clone(null, ctx)
|
|
116
|
+
return out
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
96
120
|
get canon() {
|
|
97
121
|
return this.pref instanceof Nil ? this.peg.canon : '*' + this.pref.canon
|
|
98
122
|
}
|