aontu 0.44.0 → 0.46.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/dist/cli.d.ts +9 -0
- package/dist/cli.js +203 -0
- package/dist/cli.js.map +1 -0
- package/dist/ctx.d.ts +2 -5
- package/dist/ctx.js +1 -2
- package/dist/ctx.js.map +1 -1
- package/dist/lang.d.ts +1 -5
- package/dist/lang.js +24 -100
- package/dist/lang.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +0 -5
- package/dist/type.js.map +1 -1
- package/dist/unify.js +13 -292
- package/dist/unify.js.map +1 -1
- package/dist/utility.js +2 -6
- package/dist/utility.js.map +1 -1
- package/dist/val/BagVal.d.ts +3 -0
- package/dist/val/BagVal.js +6 -6
- package/dist/val/BagVal.js.map +1 -1
- package/dist/val/ConjunctVal.d.ts +1 -1
- package/dist/val/ConjunctVal.js +14 -137
- package/dist/val/ConjunctVal.js.map +1 -1
- package/dist/val/CopyFuncVal.js +2 -3
- package/dist/val/CopyFuncVal.js.map +1 -1
- package/dist/val/DisjunctVal.js +0 -4
- package/dist/val/DisjunctVal.js.map +1 -1
- package/dist/val/ExpectVal.js +3 -16
- package/dist/val/ExpectVal.js.map +1 -1
- package/dist/val/JunctionVal.d.ts +0 -1
- package/dist/val/JunctionVal.js +1 -6
- package/dist/val/JunctionVal.js.map +1 -1
- package/dist/val/KeyFuncVal.js +2 -0
- package/dist/val/KeyFuncVal.js.map +1 -1
- package/dist/val/ListVal.d.ts +0 -1
- package/dist/val/ListVal.js +66 -33
- package/dist/val/ListVal.js.map +1 -1
- package/dist/val/MapVal.d.ts +2 -3
- package/dist/val/MapVal.js +95 -67
- package/dist/val/MapVal.js.map +1 -1
- package/dist/val/MoveFuncVal.d.ts +1 -2
- package/dist/val/MoveFuncVal.js +13 -78
- package/dist/val/MoveFuncVal.js.map +1 -1
- package/dist/val/PathFuncVal.js +4 -25
- package/dist/val/PathFuncVal.js.map +1 -1
- package/dist/val/PlusOpVal.d.ts +1 -1
- package/dist/val/PrefVal.js +5 -18
- package/dist/val/PrefVal.js.map +1 -1
- package/dist/val/{PathVal.d.ts → RefVal.d.ts} +3 -4
- package/dist/val/{PathVal.js → RefVal.js} +77 -75
- package/dist/val/RefVal.js.map +1 -0
- package/dist/val/Val.d.ts +1 -2
- package/dist/val/Val.js +8 -7
- package/dist/val/Val.js.map +1 -1
- package/dist/val/VarVal.js +2 -2
- package/dist/val/VarVal.js.map +1 -1
- package/package.json +9 -4
- package/src/cli.ts +193 -0
- package/src/ctx.ts +3 -16
- package/src/lang.ts +23 -113
- package/src/type.ts +0 -5
- package/src/unify.ts +13 -310
- package/src/utility.ts +2 -5
- package/src/val/BagVal.ts +7 -6
- package/src/val/ConjunctVal.ts +13 -131
- package/src/val/CopyFuncVal.ts +2 -3
- package/src/val/DisjunctVal.ts +0 -6
- package/src/val/ExpectVal.ts +4 -18
- package/src/val/JunctionVal.ts +1 -5
- package/src/val/KeyFuncVal.ts +3 -0
- package/src/val/ListVal.ts +88 -38
- package/src/val/MapVal.ts +124 -75
- package/src/val/MoveFuncVal.ts +14 -79
- package/src/val/PathFuncVal.ts +4 -29
- package/src/val/PrefVal.ts +6 -19
- package/src/val/{RefVal.ts.old → RefVal.ts} +19 -30
- package/src/val/Val.ts +9 -9
- package/src/val/VarVal.ts +2 -2
- package/README.md +0 -18
- package/dist/val/PathVal.js.map +0 -1
- package/dist/val/SpreadVal.d.ts +0 -20
- package/dist/val/SpreadVal.js +0 -194
- package/dist/val/SpreadVal.js.map +0 -1
- package/src/val/PathVal.ts +0 -435
- package/src/val/SpreadVal.ts +0 -275
package/src/val/SpreadVal.ts
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2025 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
// SpreadVal represents a spread constraint (&:{...}).
|
|
4
|
-
// It owns all spread application logic — MapVal and ListVal know
|
|
5
|
-
// nothing about spreads. A parsed `{a:1, &:{x:2}}` becomes
|
|
6
|
-
// `ConjunctVal([MapVal({a:1}), SpreadVal({x:2})])`.
|
|
7
|
-
//
|
|
8
|
-
// SpreadVal.unify applies the constraint to a peer MapVal/ListVal
|
|
9
|
-
// by unifying each of the peer's children with a per-key clone of
|
|
10
|
-
// the spread constraint.
|
|
11
|
-
|
|
12
|
-
import type {
|
|
13
|
-
Val,
|
|
14
|
-
ValSpec,
|
|
15
|
-
} from '../type'
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
DONE,
|
|
19
|
-
} from '../type'
|
|
20
|
-
|
|
21
|
-
import { AontuContext } from '../ctx'
|
|
22
|
-
import { unite } from '../unify'
|
|
23
|
-
|
|
24
|
-
import {
|
|
25
|
-
propagateMarks,
|
|
26
|
-
walk,
|
|
27
|
-
explainOpen,
|
|
28
|
-
ec,
|
|
29
|
-
explainClose,
|
|
30
|
-
} from '../utility'
|
|
31
|
-
|
|
32
|
-
import { makeNilErr } from '../err'
|
|
33
|
-
|
|
34
|
-
import {
|
|
35
|
-
top
|
|
36
|
-
} from './top'
|
|
37
|
-
|
|
38
|
-
import { FeatureVal } from './FeatureVal'
|
|
39
|
-
import { ConjunctVal } from './ConjunctVal'
|
|
40
|
-
import { NilVal } from './NilVal'
|
|
41
|
-
import { MapVal } from './MapVal'
|
|
42
|
-
import { ListVal } from './ListVal'
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class SpreadVal extends FeatureVal {
|
|
46
|
-
isSpread = true
|
|
47
|
-
isGenable = true
|
|
48
|
-
cjo = 110000 // Sorts after MapVal/ListVal in ConjunctVal norm
|
|
49
|
-
|
|
50
|
-
constructor(spec: ValSpec, ctx?: AontuContext) {
|
|
51
|
-
super(spec, ctx)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
unify(peer: Val, ctx: AontuContext): Val {
|
|
56
|
-
peer = peer ?? top()
|
|
57
|
-
|
|
58
|
-
const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Spread', this, peer)
|
|
59
|
-
|
|
60
|
-
let out: Val
|
|
61
|
-
|
|
62
|
-
if (peer.isTop) {
|
|
63
|
-
// Self-unify: spread is a constraint, not a value that converges.
|
|
64
|
-
// Mark done to prevent fixpoint cycling.
|
|
65
|
-
out = this
|
|
66
|
-
out.dc = DONE
|
|
67
|
-
}
|
|
68
|
-
else if ((peer as any).isSpread) {
|
|
69
|
-
// SpreadVal + SpreadVal: unify the two constraints
|
|
70
|
-
const merged = unite(
|
|
71
|
-
te ? ctx.clone({ explain: ec(te, 'SPR') }) : ctx,
|
|
72
|
-
this.peg, peer.peg, 'spread-merge')
|
|
73
|
-
out = new SpreadVal({ peg: merged }, ctx)
|
|
74
|
-
out.dc = merged.done ? DONE : this.dc + 1
|
|
75
|
-
}
|
|
76
|
-
else if (peer.isMap) {
|
|
77
|
-
// SpreadVal + MapVal: apply spread to each map key
|
|
78
|
-
out = this.applyToMap(peer as any, ctx, te)
|
|
79
|
-
}
|
|
80
|
-
else if (peer.isList) {
|
|
81
|
-
// SpreadVal + ListVal: apply spread to each list element
|
|
82
|
-
out = this.applyToList(peer as any, ctx, te)
|
|
83
|
-
}
|
|
84
|
-
else if (peer.isConjunct) {
|
|
85
|
-
// SpreadVal + ConjunctVal: unify with the conjunct.
|
|
86
|
-
// The conjunct fold will place us last (high cjo).
|
|
87
|
-
out = peer.unify(this, te ? ctx.clone({ explain: ec(te, 'SCJ') }) : ctx)
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
// SpreadVal + other: defer by wrapping in ConjunctVal
|
|
91
|
-
out = new ConjunctVal({ peg: [peer, this] }, ctx)
|
|
92
|
-
out.dc = this.dc + 1
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Track unresolved spread count.
|
|
96
|
-
// cc=0: increment for spreads that don't vanish.
|
|
97
|
-
// cc>0: decrement when a spread vanishes.
|
|
98
|
-
if (0 === ctx.cc) {
|
|
99
|
-
if (out.isSpread && !out.done) {
|
|
100
|
-
ctx.sc++
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else if (ctx.sc > 0) {
|
|
104
|
-
if (!(out.isSpread && !out.done)) {
|
|
105
|
-
ctx.sc--
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
ctx.explain && explainClose(te, out)
|
|
110
|
-
return out
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
// Apply this spread constraint to each key in a MapVal.
|
|
115
|
-
// Uses unite() per key with the correct descended context.
|
|
116
|
-
applyToMap(map: MapVal, ctx: AontuContext, te: any): Val {
|
|
117
|
-
const spread = this.peg
|
|
118
|
-
|
|
119
|
-
const mapKeys = Object.keys(map.peg)
|
|
120
|
-
|
|
121
|
-
// If map has no keys, preserve the spread for future merges.
|
|
122
|
-
// Mark as DONE to prevent fixpoint cycling.
|
|
123
|
-
if (mapKeys.length === 0) {
|
|
124
|
-
const out = new ConjunctVal({ peg: [map, this] }, ctx)
|
|
125
|
-
out.dc = DONE
|
|
126
|
-
return out
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const out = new MapVal({ peg: {} }, ctx)
|
|
130
|
-
out.closed = map.closed
|
|
131
|
-
out.optionalKeys = 0 < map.optionalKeys.length
|
|
132
|
-
? [...map.optionalKeys] : map.optionalKeys
|
|
133
|
-
out.site = map.site
|
|
134
|
-
|
|
135
|
-
let done = true
|
|
136
|
-
|
|
137
|
-
for (const key of mapKeys) {
|
|
138
|
-
const child = map.peg[key]
|
|
139
|
-
const keyctx = ctx.descend(key)
|
|
140
|
-
// Clone the spread for this key's context, then resolve any
|
|
141
|
-
// path-dependent functions (key(), path(), etc.) by unifying
|
|
142
|
-
// with TOP. This ensures the spread values are concrete before
|
|
143
|
-
// being merged as peer keys into the child map.
|
|
144
|
-
let key_spread = spread.spreadClone(keyctx)
|
|
145
|
-
if (!key_spread.done) {
|
|
146
|
-
key_spread = unite(keyctx, key_spread, top(), 'spread-resolve')
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Clear type marks on the spread constraint root and its
|
|
150
|
-
// direct children — type() constrains but should not mark
|
|
151
|
-
// children as type-invisible.
|
|
152
|
-
key_spread.mark.type = false
|
|
153
|
-
key_spread.mark.hide = false
|
|
154
|
-
if (key_spread.isMap) {
|
|
155
|
-
for (const k in key_spread.peg) {
|
|
156
|
-
if (key_spread.peg[k]?.isVal) {
|
|
157
|
-
key_spread.peg[k].mark.type = false
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
propagateMarks(map, child)
|
|
163
|
-
|
|
164
|
-
out.peg[key] =
|
|
165
|
-
undefined === child ? key_spread :
|
|
166
|
-
child.isNil ? child :
|
|
167
|
-
key_spread.isNil ? key_spread :
|
|
168
|
-
key_spread.isTop && child.done ? child :
|
|
169
|
-
child.isTop && key_spread.done ? key_spread :
|
|
170
|
-
unite(te ? keyctx.clone({ explain: ec(te, 'SK:' + key) }) : keyctx,
|
|
171
|
-
child, key_spread, 'spread-apply')
|
|
172
|
-
|
|
173
|
-
done = done && (DONE === out.peg[key].dc)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
out.dc = done ? DONE : map.dc + 1
|
|
177
|
-
|
|
178
|
-
propagateMarks(map, out)
|
|
179
|
-
// NOTE: do not propagate type/hide marks from the spread constraint
|
|
180
|
-
// to the output — a type spread constrains children but doesn't
|
|
181
|
-
// make them type-invisible.
|
|
182
|
-
|
|
183
|
-
return out
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// Apply this spread constraint to each element in a ListVal.
|
|
188
|
-
applyToList(list: ListVal, ctx: AontuContext, te: any): Val {
|
|
189
|
-
const spread = this.peg
|
|
190
|
-
|
|
191
|
-
const listKeys = Object.keys(list.peg)
|
|
192
|
-
|
|
193
|
-
if (listKeys.length === 0) {
|
|
194
|
-
const out = new ConjunctVal({ peg: [list, this] }, ctx)
|
|
195
|
-
out.dc = DONE
|
|
196
|
-
return out
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const out = new ListVal({ peg: [] }, ctx)
|
|
200
|
-
out.closed = list.closed
|
|
201
|
-
out.optionalKeys = 0 < list.optionalKeys.length
|
|
202
|
-
? [...list.optionalKeys] : list.optionalKeys
|
|
203
|
-
out.site = list.site
|
|
204
|
-
|
|
205
|
-
let done = true
|
|
206
|
-
|
|
207
|
-
for (const key of listKeys) {
|
|
208
|
-
const child = list.peg[key]
|
|
209
|
-
const keyctx = ctx.descend(key)
|
|
210
|
-
const key_spread = spread.spreadClone(keyctx)
|
|
211
|
-
|
|
212
|
-
propagateMarks(list, child)
|
|
213
|
-
|
|
214
|
-
out.peg[key as any] =
|
|
215
|
-
undefined === child ? key_spread :
|
|
216
|
-
child.isNil ? child :
|
|
217
|
-
key_spread.isNil ? key_spread :
|
|
218
|
-
key_spread.isTop && child.done ? child :
|
|
219
|
-
child.isTop && key_spread.done ? key_spread :
|
|
220
|
-
unite(te ? keyctx.clone({ explain: ec(te, 'SL:' + key) }) : keyctx,
|
|
221
|
-
child, key_spread, 'spread-apply-list')
|
|
222
|
-
|
|
223
|
-
done = done && (DONE === out.peg[key as any]?.dc)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
out.dc = done ? DONE : list.dc + 1
|
|
227
|
-
|
|
228
|
-
propagateMarks(list, out)
|
|
229
|
-
|
|
230
|
-
return out
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
clone(ctx: AontuContext, spec?: ValSpec): Val {
|
|
235
|
-
const out = new SpreadVal({
|
|
236
|
-
peg: this.peg.clone(ctx, spec),
|
|
237
|
-
...(spec || {}),
|
|
238
|
-
}, ctx)
|
|
239
|
-
out.dc = this.done ? DONE : out.dc
|
|
240
|
-
out.site = this.site
|
|
241
|
-
return out
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
spreadClone(ctx: AontuContext): Val {
|
|
246
|
-
if (!this.isPathDependent) return this
|
|
247
|
-
return this.clone(ctx)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
get canon(): string {
|
|
252
|
-
// Use {&:...} for map spreads, [&:...] for list spreads, {&:X} for scalars
|
|
253
|
-
const pc = this.peg.canon
|
|
254
|
-
if (this.peg.isMap) return '{&:' + pc.slice(1, -1) + '}' // {&:k:v,...}
|
|
255
|
-
if (this.peg.isList) return '[&:' + pc.slice(1, -1) + ']' // [&:v,...]
|
|
256
|
-
return '{&:' + pc + '}'
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
gen(_ctx: AontuContext) {
|
|
261
|
-
// Unresolved spread (never applied to a map/list) generates
|
|
262
|
-
// as undefined — the spread is a constraint, not a value.
|
|
263
|
-
return undefined
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
inspection() {
|
|
268
|
-
return 'spread'
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
export {
|
|
274
|
-
SpreadVal,
|
|
275
|
-
}
|