aontu 0.32.1 → 0.33.2

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/src/val/BagVal.ts CHANGED
@@ -9,7 +9,15 @@ import {
9
9
  AontuContext,
10
10
  } from '../ctx'
11
11
 
12
+ import {
13
+ items,
14
+ } from '../utility'
15
+
16
+ import { makeNilErr } from '../err'
17
+ import { empty } from './Val'
12
18
 
19
+ import { Val } from './Val'
20
+ import { NilVal } from './NilVal'
13
21
  import { FeatureVal } from './FeatureVal'
14
22
 
15
23
 
@@ -19,12 +27,105 @@ abstract class BagVal extends FeatureVal {
19
27
  closed: boolean = false
20
28
  optionalKeys: string[] = []
21
29
 
30
+ spread = {
31
+ cj: (undefined as Val | undefined),
32
+ }
33
+
34
+ from_spread?: Val
35
+
36
+
22
37
  constructor(
23
38
  spec: ValSpec,
24
39
  ctx?: AontuContext
25
40
  ) {
26
41
  super(spec, ctx)
27
42
  }
43
+
44
+ clone(ctx: AontuContext, spec?: ValSpec): Val {
45
+ const bag = super.clone(ctx, spec) as BagVal
46
+ bag.spread = this.spread
47
+ bag.from_spread = this.from_spread
48
+ return bag
49
+ }
50
+
51
+
52
+ gen(ctx: AontuContext) {
53
+ let out: any = this.isMap ? {} : []
54
+
55
+ if (this.mark.type || this.mark.hide) {
56
+ return undefined
57
+ }
58
+
59
+ for (let item of items(this.peg)) {
60
+ const p = item[0]
61
+ const child = item[1]
62
+
63
+ if (child.mark.type || child.mark.hide) {
64
+ continue
65
+ }
66
+
67
+ const optional = this.optionalKeys.includes('' + p)
68
+
69
+ // Optional unresolved disjuncts are not an error, just dropped.
70
+ if (child.isDisjunct && optional) {
71
+ const dctx = ctx.clone({ err: [], collect: true })
72
+
73
+ let cval = child.gen(dctx)
74
+
75
+ if (undefined === cval) {
76
+ continue
77
+ }
78
+
79
+ out[p] = cval
80
+ }
81
+
82
+ else if (child.isScalar
83
+ || child.isMap
84
+ || child.isList
85
+ || child.isPref
86
+ || child.isRef
87
+ || child.isDisjunct
88
+ || child.isNil
89
+ ) {
90
+ let cval = child.gen(ctx)
91
+
92
+ if (optional && (undefined === cval || empty(cval))) {
93
+ continue
94
+ }
95
+
96
+ out[p] = cval
97
+ }
98
+ else if (child.isNil) {
99
+ ctx.adderr(child)
100
+ }
101
+ else if (!optional) {
102
+ const prefix = this.isMap ? 'map' : 'list'
103
+ let code = this.closed ? prefix + 'val_required' : prefix + 'val_no_gen'
104
+ let va = child
105
+ let vb = undefined
106
+
107
+ // TODO from_spread only works for first level, fix it for deeper children
108
+ if (this.from_spread) {
109
+ code = prefix + 'val_spread_required'
110
+ vb = new NilVal()
111
+ vb.path = child.path
112
+ vb.site = this.site
113
+ vb.primary = this
114
+ }
115
+
116
+ const details = { key: p }
117
+
118
+ makeNilErr(ctx, code, va, vb, undefined, details)
119
+
120
+ break
121
+ }
122
+
123
+ // else optional so we can ignore it
124
+ }
125
+
126
+ return out
127
+ }
128
+
28
129
  }
29
130
 
30
131
 
@@ -20,6 +20,7 @@ import {
20
20
  explainOpen,
21
21
  ec,
22
22
  explainClose,
23
+ items,
23
24
  } from '../utility'
24
25
 
25
26
  import { makeNilErr, AontuError } from '../err'
@@ -38,10 +39,6 @@ import { empty } from './Val'
38
39
  class ListVal extends BagVal {
39
40
  isList = true
40
41
 
41
- spread = {
42
- cj: (undefined as Val | undefined),
43
- }
44
-
45
42
  constructor(
46
43
  spec: {
47
44
  peg: ValList
@@ -90,8 +87,9 @@ class ListVal extends BagVal {
90
87
 
91
88
  out.closed = this.closed
92
89
  out.optionalKeys = [...this.optionalKeys]
93
-
94
90
  out.spread.cj = this.spread.cj
91
+ out.site = this.site
92
+ out.from_spread = this.from_spread
95
93
 
96
94
  if (peer instanceof ListVal) {
97
95
  if (!this.closed && peer.closed) {
@@ -168,6 +166,8 @@ class ListVal extends BagVal {
168
166
  oval = out.peg[peerkey] =
169
167
  unite(key_ctx.clone({ explain: ec(te, 'PSP:' + peerkey) }),
170
168
  out.peg[peerkey], key_spread_cj, 'list-spread')
169
+
170
+ oval.from_spread = spread_cj
171
171
  }
172
172
 
173
173
  propagateMarks(this, oval)
@@ -192,6 +192,10 @@ class ListVal extends BagVal {
192
192
  }
193
193
  }
194
194
 
195
+ if (out.isBag) {
196
+ (out as BagVal).from_spread = this.from_spread
197
+ }
198
+
195
199
  ctx.explain && explainClose(te, out)
196
200
 
197
201
  return out
@@ -231,64 +235,68 @@ class ListVal extends BagVal {
231
235
  ']'
232
236
  }
233
237
 
234
-
235
- gen(ctx: AontuContext) {
236
- let out: any = []
237
- if (this.mark.type || this.mark.hide) {
238
- return undefined
239
- }
240
-
241
- for (let i = 0; i < this.peg.length; i++) {
242
- const child = this.peg[i]
243
-
244
- const optional = this.optionalKeys.includes('' + i)
245
-
246
- // Optional unresolved disjuncts are not an error, just dropped.
247
- if (child.isDisjunct && optional) {
248
- const dctx = ctx.clone({ err: [] })
249
-
250
- let cval = child.gen(dctx)
251
-
252
- if (undefined === cval) {
253
- continue
254
- }
255
-
256
- out.push(cval)
238
+ /*
239
+ gen(ctx: AontuContext) {
240
+ let out: any = []
241
+ if (this.mark.type || this.mark.hide) {
242
+ return undefined
257
243
  }
258
-
259
- else if (child.isScalar
260
- || child.isMap
261
- || child.isList
262
- || child.isPref
263
- || child.isRef
264
- || child.isDisjunct
265
- || child.isNil
266
- ) {
267
- const cval = child.gen(ctx)
268
-
269
- if (optional && empty(cval)) {
270
- continue
244
+
245
+ // for (let i = 0; i < this.peg.length; i++) {
246
+ // const child = this.peg[i]
247
+ for (let item of items(this.peg)) {
248
+ const i = item[0]
249
+ const child = item[1]
250
+
251
+ const optional = this.optionalKeys.includes('' + i)
252
+
253
+ // Optional unresolved disjuncts are not an error, just dropped.
254
+ if (child.isDisjunct && optional) {
255
+ const dctx = ctx.clone({ err: [] })
256
+
257
+ let cval = child.gen(dctx)
258
+
259
+ if (undefined === cval) {
260
+ continue
261
+ }
262
+
263
+ out.push(cval)
271
264
  }
272
-
273
- out.push(cval)
274
- }
275
- else if (child.isNil) {
276
- ctx.adderr(child)
265
+
266
+ else if (child.isScalar
267
+ || child.isMap
268
+ || child.isList
269
+ || child.isPref
270
+ || child.isRef
271
+ || child.isDisjunct
272
+ || child.isNil
273
+ ) {
274
+ const cval = child.gen(ctx)
275
+
276
+ if (optional && empty(cval)) {
277
+ continue
278
+ }
279
+
280
+ out.push(cval)
281
+ }
282
+ else if (child.isNil) {
283
+ ctx.adderr(child)
284
+ }
285
+ else if (!this.optionalKeys.includes('' + i)) {
286
+ makeNilErr(
287
+ ctx,
288
+ this.closed ? 'listval_required' : 'listval_no_gen',
289
+ child, undefined
290
+ )
291
+ break
292
+ }
293
+
294
+ // else optional so we can ignore it
277
295
  }
278
- else if (!this.optionalKeys.includes('' + i)) {
279
- makeNilErr(
280
- ctx,
281
- this.closed ? 'listval_required' : 'listval_no_gen',
282
- child, undefined
283
- )
284
- break
296
+
297
+ return out
285
298
  }
286
-
287
- // else optional so we can ignore it
288
- }
289
-
290
- return out
291
- }
299
+ */
292
300
  }
293
301
 
294
302
 
package/src/val/MapVal.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /* Copyright (c) 2021-2025 Richard Rodger, MIT License */
2
2
 
3
3
 
4
-
5
4
  import type {
6
5
  Val,
7
6
  ValSpec,
@@ -32,16 +31,11 @@ import {
32
31
  import { ConjunctVal } from './ConjunctVal'
33
32
  import { NilVal } from './NilVal'
34
33
  import { BagVal } from './BagVal'
35
- import { empty } from './Val'
36
34
 
37
35
 
38
36
  class MapVal extends BagVal {
39
37
  isMap = true
40
38
 
41
- spread = {
42
- cj: (undefined as Val | undefined),
43
- }
44
-
45
39
  constructor(
46
40
  spec: ValSpec,
47
41
  ctx?: AontuContext
@@ -91,22 +85,15 @@ class MapVal extends BagVal {
91
85
 
92
86
  out.closed = this.closed
93
87
  out.optionalKeys = [...this.optionalKeys]
94
-
95
88
  out.spread.cj = this.spread.cj
89
+ out.site = this.site
90
+ out.from_spread = this.from_spread
96
91
 
97
- // TODO: some spreads (no path refs etc) could self unified
98
- /*
99
- if (out.spread.cj && !out.spread.cj.mark._self_unified) {
100
- // console.log('MAPVAL-SPR-START', out.spread.cj.mark)
101
- out.spread.cj = out.spread.cj.unify(TOP, ctx.clone({ explain: ec(te, 'SPR-SELF-UNIFY') }))
102
- out.spread.cj.mark._self_unified = true
103
- // console.log('MAPVAL-SU', out.spread.cj.id, out.spread.cj.canon, out.spread.cj.done)
92
+ if (this.spread.cj && null == out.from_spread) {
93
+ out.from_spread = this.spread.cj
104
94
  }
105
- */
106
95
 
107
96
  if (peer instanceof MapVal) {
108
- // console.log('MAPVAL-PEER-MAPVAL', this.id, this.canon, this.done, peer.id, peer.canon, peer.done)
109
-
110
97
  if (!this.closed && peer.closed) {
111
98
  out = peer.unify(this, ctx.clone({ explain: ec(te, 'PMC') })) as MapVal
112
99
  exit = true
@@ -171,6 +158,12 @@ class MapVal extends BagVal {
171
158
  unite(keyctx.clone({ explain: ec(te, 'KEY:' + key) }),
172
159
  child, key_spread_cj, 'map-own')
173
160
 
161
+
162
+
163
+ if (this.spread.cj) {
164
+ out.from_spread = this.spread.cj
165
+ }
166
+
174
167
  done = (done && DONE === out.peg[key].dc)
175
168
  }
176
169
 
@@ -207,11 +200,11 @@ class MapVal extends BagVal {
207
200
  let key_ctx = ctx.descend(peerkey)
208
201
  let key_spread_cj = spread_cj.clone(key_ctx)
209
202
 
210
- // console.log('MAPVAL-PEER-SPR', peerkey, key_spread_cj.id, key_spread_cj.canon, key_spread_cj.done)
211
-
212
203
  oval = out.peg[peerkey] =
213
204
  unite(key_ctx.clone({ explain: ec(te, 'PSP:' + peerkey) }),
214
205
  oval, key_spread_cj, 'map-peer-spread')
206
+
207
+ oval.from_spread = this.spread.cj
215
208
  }
216
209
 
217
210
  propagateMarks(this, oval)
@@ -236,7 +229,17 @@ class MapVal extends BagVal {
236
229
  }
237
230
  }
238
231
 
239
- // console.log('MAPVAL-OUT', this.id, this.closed, this.canon, 'P=', (peer as any).closed, peer.canon, '->', (out as any).closed, out.canon)
232
+ if (out.isBag) {
233
+ (out as BagVal).from_spread = this.from_spread
234
+ }
235
+
236
+ // console.log(
237
+ // 'MAPVAL-OUT', out.canon,
238
+ // '\n SELF', this,
239
+ // '\n PEER', peer,
240
+ // '\n OUT', out,
241
+ // '\n FROM', (out as any).spread.cj
242
+ // )
240
243
 
241
244
  ctx.explain && explainClose(te, out)
242
245
 
@@ -265,6 +268,8 @@ class MapVal extends BagVal {
265
268
  out.closed = this.closed
266
269
  out.optionalKeys = [...this.optionalKeys]
267
270
 
271
+ // out.from = this.from
272
+
268
273
  // console.log('MAPVAL-CLONE', this.canon, '->', out.canon)
269
274
  return out
270
275
  }
@@ -296,72 +301,6 @@ class MapVal extends BagVal {
296
301
  return this.spread.cj ? '&:' + this.spread.cj.inspect(null == d ? 0 : d + 1) : ''
297
302
  }
298
303
 
299
-
300
- gen(ctx: AontuContext) {
301
- // console.log('MAPVAL-gen')
302
-
303
- let out: any = {}
304
- if (this.mark.type || this.mark.hide) {
305
- return undefined
306
- }
307
-
308
- for (let p in this.peg) {
309
- const child = this.peg[p]
310
-
311
- if (child.mark.type || child.mark.hide) {
312
- continue
313
- }
314
-
315
- const optional = this.optionalKeys.includes(p)
316
-
317
- // console.log('MAPVAL-gen-p', p, optional, child.isDisjunct, child)
318
-
319
-
320
- // Optional unresolved disjuncts are not an error, just dropped.
321
- if (child.isDisjunct && optional) {
322
- const dctx = ctx.clone({ err: [], collect: true })
323
-
324
- let cval = child.gen(dctx)
325
-
326
- // console.log('CVAL', cval, ctx.err, dctx.err, child.err)
327
-
328
- if (undefined === cval) {
329
- continue
330
- }
331
-
332
- out[p] = cval
333
- }
334
-
335
- else if (child.isScalar
336
- || child.isMap
337
- || child.isList
338
- || child.isPref
339
- || child.isRef
340
- || child.isDisjunct
341
- || child.isNil
342
- ) {
343
- let cval = child.gen(ctx)
344
-
345
- if (optional && (undefined === cval || empty(cval))) {
346
- continue
347
- }
348
-
349
- out[p] = cval
350
- }
351
- else if (!optional) {
352
- makeNilErr(
353
- ctx,
354
- this.closed ? 'mapval_required' : 'mapval_no_gen',
355
- child, undefined
356
- )
357
- break
358
- }
359
-
360
- // else optional so we can ignore it
361
- }
362
-
363
- return out
364
- }
365
304
  }
366
305
 
367
306
 
package/src/val/NilVal.ts CHANGED
@@ -16,7 +16,7 @@ import {
16
16
 
17
17
  import { Val } from './Val'
18
18
 
19
- import { AontuError, descErr } from '../err'
19
+ import { AontuError } from '../err'
20
20
 
21
21
 
22
22
  class NilVal extends Val {
@@ -28,16 +28,24 @@ class NilVal extends Val {
28
28
  secondary?: Val
29
29
  msg: string = ''
30
30
  attempt?: string
31
+ details?: Record<string, any>
31
32
 
32
33
  // TODO: include Val generating nil, thus capture type
33
34
 
34
35
  // A Nil is an error - should not happen - unify failed
35
36
  // refactor ,make(spec,ctx)
36
- static make = (ctx?: AontuContext, why?: any, av?: Val, bv?: Val, attempt?: string) => {
37
+ static make = (
38
+ ctx?: AontuContext,
39
+ why?: any,
40
+ av?: Val,
41
+ bv?: Val,
42
+ attempt?: string,
43
+ details?: Record<string, any>
44
+ ) => {
37
45
  let nil = new NilVal({ why }, ctx)
38
46
 
39
47
  nil.attempt = attempt
40
- // TODO: this should be done lazily, for multiple terms
48
+ nil.details = details
41
49
 
42
50
  // Terms later in same file are considered the primary error location.
43
51
  if (null != av) {
@@ -46,6 +54,7 @@ class NilVal extends Val {
46
54
  nil.site.url = av.site.url
47
55
 
48
56
  nil.primary = av
57
+ nil.path = av.path
49
58
 
50
59
  if (null != bv) {
51
60
  nil.secondary = bv
@@ -62,6 +71,7 @@ class NilVal extends Val {
62
71
  nil.site.url = bv.site.url
63
72
  nil.primary = bv
64
73
  nil.secondary = av
74
+ nil.path = bv.path
65
75
  }
66
76
  }
67
77
  }
@@ -74,7 +74,7 @@ class ScalarKindVal extends FeatureVal {
74
74
  out = peer
75
75
  }
76
76
  else {
77
- out = makeNilErr(ctx, 'no-scalar-unify', this, peer)
77
+ out = makeNilErr(ctx, 'no_scalar_unify', this, peer)
78
78
  }
79
79
  }
80
80
  else if (peerIsScalarKind) {
package/src/val/Val.ts CHANGED
@@ -21,9 +21,12 @@ type ValSpec = {
21
21
  peg?: any,
22
22
  mark?: Partial<ValMark>,
23
23
  kind?: any,
24
+
25
+
24
26
  row?: number,
25
27
  col?: number,
26
28
  url?: string,
29
+
27
30
  path?: string[],
28
31
  id?: number,
29
32
  src?: string,
@@ -92,7 +95,10 @@ abstract class Val {
92
95
  site: Site = new Site()
93
96
 
94
97
  // Map of boolean flags.
95
- mark: ValMark = { type: false, hide: false }
98
+ mark: ValMark = {
99
+ type: false,
100
+ hide: false,
101
+ }
96
102
 
97
103
  // Actual native value.
98
104
  peg: any = undefined
@@ -228,6 +234,8 @@ abstract class Val {
228
234
  d = null == d ? -1 : d
229
235
  let s = ['<' + this.constructor.name.replace(/Val$/, '') + '/' + this.id]
230
236
 
237
+ s.push('/@' + this.site?.row + ',' + this.site?.col)
238
+
231
239
  s.push('/' + this.path.join('.') + '/')
232
240
 
233
241
  s.push([