aontu 0.32.1 → 0.33.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/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,97 @@ 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?: 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
+
45
+ gen(ctx: AontuContext) {
46
+ let out: any = this.isMap ? {} : []
47
+
48
+ if (this.mark.type || this.mark.hide) {
49
+ return undefined
50
+ }
51
+
52
+ for (let item of items(this.peg)) {
53
+ const p = item[0]
54
+ const child = item[1]
55
+
56
+ if (child.mark.type || child.mark.hide) {
57
+ continue
58
+ }
59
+
60
+ const optional = this.optionalKeys.includes('' + p)
61
+
62
+ // Optional unresolved disjuncts are not an error, just dropped.
63
+ if (child.isDisjunct && optional) {
64
+ const dctx = ctx.clone({ err: [], collect: true })
65
+
66
+ let cval = child.gen(dctx)
67
+
68
+ if (undefined === cval) {
69
+ continue
70
+ }
71
+
72
+ out[p] = cval
73
+ }
74
+
75
+ else if (child.isScalar
76
+ || child.isMap
77
+ || child.isList
78
+ || child.isPref
79
+ || child.isRef
80
+ || child.isDisjunct
81
+ || child.isNil
82
+ ) {
83
+ let cval = child.gen(ctx)
84
+
85
+ if (optional && (undefined === cval || empty(cval))) {
86
+ continue
87
+ }
88
+
89
+ out[p] = cval
90
+ }
91
+ else if (child.isNil) {
92
+ ctx.adderr(child)
93
+ }
94
+ else if (!optional) {
95
+ const prefix = this.isMap ? 'map' : 'list'
96
+ let code = this.closed ? prefix + 'val_required' : prefix + 'val_no_gen'
97
+ let va = child
98
+ let vb = undefined
99
+
100
+ if (this.from) {
101
+ code = prefix + 'val_spread_required'
102
+ vb = new NilVal()
103
+ vb.path = child.path
104
+ vb.site = this.site
105
+ vb.primary = this
106
+ }
107
+
108
+ const details = { key: p }
109
+
110
+ makeNilErr(ctx, code, va, vb, undefined, details)
111
+
112
+ break
113
+ }
114
+
115
+ // else optional so we can ignore it
116
+ }
117
+
118
+ return out
119
+ }
120
+
28
121
  }
29
122
 
30
123
 
@@ -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 = this.from
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_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 = this.from
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
@@ -32,16 +32,11 @@ import {
32
32
  import { ConjunctVal } from './ConjunctVal'
33
33
  import { NilVal } from './NilVal'
34
34
  import { BagVal } from './BagVal'
35
- import { empty } from './Val'
36
35
 
37
36
 
38
37
  class MapVal extends BagVal {
39
38
  isMap = true
40
39
 
41
- spread = {
42
- cj: (undefined as Val | undefined),
43
- }
44
-
45
40
  constructor(
46
41
  spec: ValSpec,
47
42
  ctx?: AontuContext
@@ -91,22 +86,11 @@ class MapVal extends BagVal {
91
86
 
92
87
  out.closed = this.closed
93
88
  out.optionalKeys = [...this.optionalKeys]
94
-
95
89
  out.spread.cj = this.spread.cj
96
-
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)
104
- }
105
- */
90
+ out.site = this.site
91
+ out.from = this.from
106
92
 
107
93
  if (peer instanceof MapVal) {
108
- // console.log('MAPVAL-PEER-MAPVAL', this.id, this.canon, this.done, peer.id, peer.canon, peer.done)
109
-
110
94
  if (!this.closed && peer.closed) {
111
95
  out = peer.unify(this, ctx.clone({ explain: ec(te, 'PMC') })) as MapVal
112
96
  exit = true
@@ -207,11 +191,11 @@ class MapVal extends BagVal {
207
191
  let key_ctx = ctx.descend(peerkey)
208
192
  let key_spread_cj = spread_cj.clone(key_ctx)
209
193
 
210
- // console.log('MAPVAL-PEER-SPR', peerkey, key_spread_cj.id, key_spread_cj.canon, key_spread_cj.done)
211
-
212
194
  oval = out.peg[peerkey] =
213
195
  unite(key_ctx.clone({ explain: ec(te, 'PSP:' + peerkey) }),
214
196
  oval, key_spread_cj, 'map-peer-spread')
197
+
198
+ oval.from = spread_cj
215
199
  }
216
200
 
217
201
  propagateMarks(this, oval)
@@ -236,6 +220,10 @@ class MapVal extends BagVal {
236
220
  }
237
221
  }
238
222
 
223
+ if (out.isBag) {
224
+ (out as BagVal).from = this.from
225
+ }
226
+
239
227
  // console.log('MAPVAL-OUT', this.id, this.closed, this.canon, 'P=', (peer as any).closed, peer.canon, '->', (out as any).closed, out.canon)
240
228
 
241
229
  ctx.explain && explainClose(te, out)
@@ -265,6 +253,8 @@ class MapVal extends BagVal {
265
253
  out.closed = this.closed
266
254
  out.optionalKeys = [...this.optionalKeys]
267
255
 
256
+ // out.from = this.from
257
+
268
258
  // console.log('MAPVAL-CLONE', this.canon, '->', out.canon)
269
259
  return out
270
260
  }
@@ -296,72 +286,6 @@ class MapVal extends BagVal {
296
286
  return this.spread.cj ? '&:' + this.spread.cj.inspect(null == d ? 0 : d + 1) : ''
297
287
  }
298
288
 
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
289
  }
366
290
 
367
291
 
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([