aontu 0.30.2 → 0.31.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.
Files changed (57) hide show
  1. package/dist/ctx.d.ts +2 -2
  2. package/dist/ctx.js +2 -2
  3. package/dist/ctx.js.map +1 -1
  4. package/dist/hints.js +7 -1
  5. package/dist/hints.js.map +1 -1
  6. package/dist/unify.js +12 -6
  7. package/dist/unify.js.map +1 -1
  8. package/dist/utility.js +13 -7
  9. package/dist/utility.js.map +1 -1
  10. package/dist/val/ConjunctVal.js +4 -4
  11. package/dist/val/ConjunctVal.js.map +1 -1
  12. package/dist/val/CopyFuncVal.d.ts +2 -1
  13. package/dist/val/CopyFuncVal.js +14 -6
  14. package/dist/val/CopyFuncVal.js.map +1 -1
  15. package/dist/val/FuncBaseVal.d.ts +2 -2
  16. package/dist/val/FuncBaseVal.js +22 -18
  17. package/dist/val/FuncBaseVal.js.map +1 -1
  18. package/dist/val/JunctionVal.js +2 -2
  19. package/dist/val/JunctionVal.js.map +1 -1
  20. package/dist/val/KeyFuncVal.d.ts +1 -0
  21. package/dist/val/KeyFuncVal.js +36 -6
  22. package/dist/val/KeyFuncVal.js.map +1 -1
  23. package/dist/val/MapVal.d.ts +1 -1
  24. package/dist/val/MapVal.js +27 -5
  25. package/dist/val/MapVal.js.map +1 -1
  26. package/dist/val/MoveFuncVal.d.ts +1 -0
  27. package/dist/val/MoveFuncVal.js +11 -8
  28. package/dist/val/MoveFuncVal.js.map +1 -1
  29. package/dist/val/PrefVal.js +19 -11
  30. package/dist/val/PrefVal.js.map +1 -1
  31. package/dist/val/RefVal.js +50 -16
  32. package/dist/val/RefVal.js.map +1 -1
  33. package/dist/val/ScalarVal.js +1 -0
  34. package/dist/val/ScalarVal.js.map +1 -1
  35. package/dist/val/TopVal.d.ts +1 -1
  36. package/dist/val/TopVal.js +2 -2
  37. package/dist/val/TopVal.js.map +1 -1
  38. package/dist/val/Val.d.ts +3 -2
  39. package/dist/val/Val.js +37 -18
  40. package/dist/val/Val.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/ctx.ts +4 -4
  43. package/src/hints.ts +11 -1
  44. package/src/unify.ts +15 -7
  45. package/src/utility.ts +15 -9
  46. package/src/val/ConjunctVal.ts +5 -5
  47. package/src/val/CopyFuncVal.ts +20 -7
  48. package/src/val/FuncBaseVal.ts +30 -24
  49. package/src/val/JunctionVal.ts +2 -2
  50. package/src/val/KeyFuncVal.ts +42 -6
  51. package/src/val/MapVal.ts +39 -6
  52. package/src/val/MoveFuncVal.ts +12 -8
  53. package/src/val/PrefVal.ts +25 -14
  54. package/src/val/RefVal.ts +69 -17
  55. package/src/val/ScalarVal.ts +2 -0
  56. package/src/val/TopVal.ts +2 -2
  57. package/src/val/Val.ts +42 -18
package/src/val/MapVal.ts CHANGED
@@ -77,6 +77,8 @@ class MapVal extends BagVal {
77
77
  // NOTE: order of keys is not preserved!
78
78
  // not possible in any case - consider {a,b} unify {b,a}
79
79
  unify(peer: Val, ctx: AontuContext): Val {
80
+ // console.log('MAPVAL-UNIFY', this.id, this.canon, peer.id, peer.canon)
81
+
80
82
  const TOP = top()
81
83
  peer = peer ?? TOP
82
84
  const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Map', this, peer)
@@ -92,7 +94,19 @@ class MapVal extends BagVal {
92
94
 
93
95
  out.spread.cj = this.spread.cj
94
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
+ */
106
+
95
107
  if (peer instanceof MapVal) {
108
+ // console.log('MAPVAL-PEER-MAPVAL', this.id, this.canon, this.done, peer.id, peer.canon, peer.done)
109
+
96
110
  if (!this.closed && peer.closed) {
97
111
  out = peer.unify(this, ctx.clone({ explain: ec(te, 'PMC') })) as MapVal
98
112
  exit = true
@@ -119,11 +133,16 @@ class MapVal extends BagVal {
119
133
  out.spread.cj = null == out.spread.cj ? peer.spread.cj : (
120
134
  null == peer.spread.cj ? out.spread.cj : (
121
135
  out.spread.cj =
122
- unite(ctx.clone({ explain: ec(te, 'SPR') }), out.spread.cj, peer.spread.cj, 'map-self')
136
+ unite(ctx.clone({ explain: ec(te, 'SPR') }),
137
+ out.spread.cj, peer.spread.cj, 'map-self')
123
138
  )
124
139
  )
125
140
  }
126
141
  }
142
+ else {
143
+ // console.log('MAPVAL-PEER-OTHER', this.id, this.canon, this.done, peer.id, peer.canon, peer.done)
144
+ }
145
+
127
146
 
128
147
  if (!exit) {
129
148
  out.dc = this.dc + 1
@@ -135,7 +154,10 @@ class MapVal extends BagVal {
135
154
  // Always unify own children first
136
155
  for (let key in this.peg) {
137
156
  const keyctx = ctx.descend(key)
157
+
138
158
  const key_spread_cj = spread_cj.clone(keyctx)
159
+ // console.log('MAPVAL-SPREAD', this.id, key, key_spread_cj.id, key_spread_cj.canon, key_spread_cj.done)
160
+
139
161
  const child = this.peg[key]
140
162
 
141
163
  propagateMarks(this, child)
@@ -146,7 +168,7 @@ class MapVal extends BagVal {
146
168
  key_spread_cj.isNil ? key_spread_cj :
147
169
  key_spread_cj.isTop && child.done ? child :
148
170
  child.isTop && key_spread_cj.done ? key_spread_cj :
149
- unite(keyctx.clone({ explain: ec(te, 'PEG:' + key) }),
171
+ unite(keyctx.clone({ explain: ec(te, 'KEY:' + key) }),
150
172
  child, key_spread_cj, 'map-own')
151
173
 
152
174
  done = (done && DONE === out.peg[key].dc)
@@ -184,6 +206,9 @@ class MapVal extends BagVal {
184
206
  if (this.spread.cj) {
185
207
  let key_ctx = ctx.descend(peerkey)
186
208
  let key_spread_cj = spread_cj.clone(key_ctx)
209
+
210
+ // console.log('MAPVAL-PEER-SPR', peerkey, key_spread_cj.id, key_spread_cj.canon, key_spread_cj.done)
211
+
187
212
  oval = out.peg[peerkey] =
188
213
  unite(key_ctx.clone({ explain: ec(te, 'PSP:' + peerkey) }),
189
214
  oval, key_spread_cj, 'map-peer-spread')
@@ -222,9 +247,16 @@ class MapVal extends BagVal {
222
247
  clone(ctx: AontuContext, spec?: ValSpec): Val {
223
248
  let out = (super.clone(ctx, spec) as MapVal)
224
249
  out.peg = {}
250
+
225
251
  for (let entry of Object.entries(this.peg)) {
226
252
  out.peg[entry[0]] =
227
- (entry[1] as any)?.isVal ? (entry[1] as Val).clone(ctx, spec?.mark ? { mark: spec.mark } : {}) : entry[1]
253
+ (entry[1] as any)?.isVal ?
254
+ // (entry[1] as Val).clone(ctx, spec?.mark ? { mark: spec.mark } : {}) :
255
+ (entry[1] as Val).clone(ctx, {
256
+ mark: spec?.mark ?? {},
257
+ path: [...out.path, entry[0]]
258
+ }) :
259
+ entry[1]
228
260
  }
229
261
  if (this.spread.cj) {
230
262
  out.spread.cj = this.spread.cj.clone(ctx, spec?.mark ? { mark: spec.mark } : {})
@@ -255,12 +287,13 @@ class MapVal extends BagVal {
255
287
  (this.peg[k]?.canon ?? this.peg[k])
256
288
  ])
257
289
  .join(',') +
258
- '}'
290
+ '}' // + '<' + (this.mark.hide ? 'H' : '') + '>'
291
+
259
292
  }
260
293
 
261
294
 
262
- inspection(inspect: Function) {
263
- return this.spread.cj ? '&:' + inspect(this.spread.cj) : ''
295
+ inspection(d?: number) {
296
+ return this.spread.cj ? '&:' + this.spread.cj.inspect(null == d ? 0 : d + 1) : ''
264
297
  }
265
298
 
266
299
 
@@ -22,6 +22,7 @@ import {
22
22
 
23
23
  import { FuncBaseVal } from './FuncBaseVal'
24
24
  import { CopyFuncVal } from './CopyFuncVal'
25
+ import { PrefFuncVal } from './PrefFuncVal'
25
26
 
26
27
 
27
28
 
@@ -44,30 +45,33 @@ class MoveFuncVal extends FuncBaseVal {
44
45
  return 'move'
45
46
  }
46
47
 
48
+ prepare(_ctx: AontuContext, _args: Val[]) {
49
+ return null
50
+ }
47
51
 
48
52
  resolve(ctx: AontuContext, args: Val[]) {
49
53
  let out = args[0] ?? makeNilErr(ctx, 'arg', this)
50
54
 
51
55
  const orig = out
52
- const origcanon = orig.canon
53
56
 
54
57
  if (!orig.isNil) {
55
58
  const src = orig.clone(ctx)
56
59
 
60
+ if (src.isRef) {
61
+ src.mark._hide_found = true
62
+ }
63
+
57
64
  walk(orig, (_key: string | number | undefined, val: Val) => {
58
65
  val.mark.hide = true
59
66
  return val
60
67
  })
61
68
 
62
- out = new CopyFuncVal({ peg: [src] }, ctx)
69
+ // out = new CopyFuncVal({ peg: [src] }, ctx)
70
+ out = new PrefFuncVal({ peg: [src] }, ctx)
71
+ // out = src
63
72
  }
64
73
 
65
- Object.defineProperty(out, 'canon', {
66
- get: () => 'move(' + origcanon + ')',
67
- configurable: true
68
- })
69
-
70
- // console.log('MOVE-resolve', out)
74
+ // console.log('MOVE-resolve', orig, out)
71
75
 
72
76
  return out
73
77
  }
@@ -59,17 +59,27 @@ class PrefVal extends FeatureVal {
59
59
  let out: Val = this
60
60
  let why = ''
61
61
 
62
-
63
62
  if (!this.peg.done) {
64
- const resolved = unite(ctx.clone({ explain: ec(te, 'RES') }), this.peg, top(), 'pref/resolve')
63
+ const resolved = unite(ctx.clone({ explain: ctx.explain && ec(te, 'RES') }),
64
+ this.peg, top(), 'pref/resolve')
65
65
  // console.log('PREF-RESOLVED', this.peg.canon, '->', resolved)
66
66
  this.peg = resolved
67
67
  }
68
68
 
69
-
70
69
  if (peer instanceof PrefVal) {
71
70
  why += 'pref-'
72
- if (this.rank < peer.rank) {
71
+ if (this.id === peer.id) {
72
+ out = this
73
+ why += 'same'
74
+ }
75
+
76
+ // Avoid MAXCYCLE errors
77
+ else if (this.peg.id === peer.peg.id) {
78
+ out = this
79
+ why += 'same-peg'
80
+ }
81
+
82
+ else if (this.rank < peer.rank) {
73
83
  out = this
74
84
  why += 'rank-win'
75
85
  }
@@ -78,22 +88,23 @@ class PrefVal extends FeatureVal {
78
88
  why += 'rank-lose'
79
89
  }
80
90
  else {
81
- let peg = unite(ctx.clone({ explain: ec(te, 'PEER') }), this.peg, peer.peg, 'pref-peer/' + this.id)
91
+ // console.log('PREF-PEER',
92
+ // this.peg.id, this.peg, this.peg.done,
93
+ // peer.peg.id, peer.peg, peer.peg.done,
94
+ // )
95
+
96
+ let peg = unite(ctx.clone({ explain: ctx.explain && ec(te, 'PREF-PEER') }),
97
+ this.peg, peer.peg, 'pref-peer/' + this.id)
82
98
  out = new PrefVal({ peg }, ctx)
99
+ // console.log('PREF-RANK-SAME-OUT', peg, peg.done, out, out.done)
83
100
  why += 'rank-same'
84
101
  }
85
102
  }
86
103
  else if (!peer.isTop) {
87
104
  why += 'super-'
88
105
 
89
- // if (this.superpeg instanceof Nil) {
90
- // out = peer
91
- // why += 'nil'
92
- // }
93
- // else {
94
- // why += 'unify'
95
-
96
- out = unite(ctx.clone({ explain: ec(te, 'SUPER') }), this.superpeg, peer, 'pref-super/' + this.id)
106
+ out = unite(ctx.clone({ explain: ctx.explain && ec(te, 'SUPER') }),
107
+ this.superpeg, peer, 'pref-super/' + this.id)
97
108
  if (out.same(this.superpeg)) {
98
109
  out = this.peg
99
110
  why += 'same'
@@ -109,7 +120,7 @@ class PrefVal extends FeatureVal {
109
120
 
110
121
  // console.log('PREFVAL-OUT', why, this.canon, peer.canon, '->', out.canon, out.done)
111
122
 
112
- explainClose(te, out)
123
+ ctx.explain && explainClose(te, out)
113
124
 
114
125
  return out
115
126
  }
package/src/val/RefVal.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /* Copyright (c) 2021-2025 Richard Rodger, MIT License */
2
2
 
3
3
 
4
+ import Util from 'node:util'
5
+
4
6
  import {
5
7
  walk,
6
8
  explainOpen,
@@ -135,7 +137,7 @@ class RefVal extends FeatureVal {
135
137
 
136
138
  const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Ref', this, peer)
137
139
  let out: Val = this
138
- // let why = 'id'
140
+ let why = 'id'
139
141
 
140
142
  if (this.id !== peer.id) {
141
143
 
@@ -152,35 +154,36 @@ class RefVal extends FeatureVal {
152
154
  else if (resolved instanceof RefVal) {
153
155
  if (peer.isTop) {
154
156
  out = this
155
- // why = 'pt'
157
+ why = 'pt'
156
158
  }
157
159
  else if (peer.isNil) {
158
160
  out = makeNilErr(ctx, 'ref[' + this.peg + ']', this, peer)
159
- // why = 'pn'
161
+ why = 'pn'
160
162
  }
161
163
 
162
164
  // same path
163
- // else if (this.peg === peer.peg) {
164
165
  else if (this.canon === peer.canon) {
165
166
  out = this
166
- // why = 'pp'
167
+ why = 'pp'
167
168
  }
168
169
 
169
170
  else {
170
171
  // Ensure RefVal done is incremented
171
172
  this.dc = DONE === this.dc ? DONE : this.dc + 1
172
173
  out = new ConjunctVal({ peg: [this, peer] }, ctx)
173
- // why = 'cj'
174
+ why = 'cj'
174
175
  }
175
176
  }
176
177
  else {
177
178
  out = unite(ctx.clone({ explain: ec(te, 'RES') }), resolved, peer, 'ref')
178
- // why = 'u'
179
+ why = 'u'
179
180
  }
180
181
 
181
182
  out.dc = DONE === out.dc ? DONE : this.dc + 1
182
183
  }
183
184
 
185
+ // console.log('REFVAL-UNIFY-OUT', ctx.cc, this.id, this.canon, this.done, 'P=', peer.id, peer.canon, peer.done, '->', out.id, out.canon, out.done)
186
+
184
187
  explainClose(te, out)
185
188
  return out
186
189
  }
@@ -189,7 +192,15 @@ class RefVal extends FeatureVal {
189
192
  find(ctx: AontuContext) {
190
193
  let out: Val | undefined = undefined
191
194
 
192
- if (this.path.join('.').startsWith(this.peg.join('.'))) {
195
+ const selfpath = this.path.join('.')
196
+ const pegpath = this.peg.join('.')
197
+ const isprefixpath = selfpath.startsWith(pegpath)
198
+
199
+ let refpath: string[] = []
200
+ let pI = 0
201
+ // let descent = ''
202
+
203
+ if (isprefixpath) {
193
204
  out = makeNilErr(ctx, 'path_cycle', this)
194
205
  }
195
206
  else {
@@ -248,8 +259,6 @@ class RefVal extends FeatureVal {
248
259
  }
249
260
  }
250
261
 
251
- let refpath: string[] = []
252
-
253
262
  if (this.absolute) {
254
263
  refpath = parts
255
264
  }
@@ -282,43 +291,86 @@ class RefVal extends FeatureVal {
282
291
  }
283
292
 
284
293
  let node = ctx.root as Val
285
- let pI = 0
294
+
295
+ let nopath = false
286
296
 
287
297
  if (null != node) {
288
298
  for (; pI < refpath.length; pI++) {
289
299
  let part = refpath[pI]
300
+ // console.log('PART', pI, part, node)
290
301
 
291
- if (null == node) {
292
- break
293
- }
294
- else if (node.isMap) {
302
+ // descent += (' | ' + pI + '=' + node.canon) // Util.inspect(node))
303
+
304
+ if (node.isMap) {
295
305
  node = node.peg[part]
296
306
  }
297
307
  else if (node.isList) {
298
308
  node = node.peg[part]
299
309
  }
310
+ else if (node.done) {
311
+ nopath = true
312
+ break;
313
+ }
300
314
  else {
301
315
  break;
302
316
  }
317
+
318
+ if (null == node) {
319
+ nopath = true
320
+ break
321
+ }
322
+
303
323
  }
304
324
  }
305
325
 
306
- if (pI === refpath.length) {
326
+ // console.log('REFPATH', ctx.cc, pI, refpath, nopath, ctx.root, node)
327
+
328
+
329
+ if (nopath) {
330
+ out = makeNilErr(ctx, 'no_path', this)
331
+ }
332
+ else if (pI === refpath.length) {
307
333
  out = node
308
334
 
309
335
  // Types and hidden values are cloned and made concrete
310
- if (null != out && (out.mark.type || out.mark.hide)) {
336
+ if (null != out) { // && (out.mark.type || out.mark.hide)) {
337
+
338
+ // console.log('FOUND-A', out)
339
+
340
+ if (this.mark.type || this.mark.hide) {
341
+ out.mark.type = this.mark.type
342
+ out.mark.hide = this.mark.hide
343
+
344
+ // walk(out, (_key: string | number | undefined, val: Val) => {
345
+ // val.mark.type = this.mark.type
346
+ // val.mark.hide = this.mark.hide
347
+ // return val
348
+ // })
349
+ }
350
+
351
+ if (this.mark._hide_found) {
352
+ out.mark.hide = true
353
+ }
354
+
355
+ // console.log('FOUND-B', out)
356
+
311
357
  out = out.clone(ctx)
312
358
 
359
+ // if (this.mark.type || this.mark.hide) {
313
360
  walk(out, (_key: string | number | undefined, val: Val) => {
314
361
  val.mark.type = false
315
362
  val.mark.hide = false
316
363
  return val
317
364
  })
365
+ //}
366
+
367
+ // onsole.log('FOUND-C', out)
318
368
  }
319
369
  }
320
370
  }
321
371
 
372
+ // console.log('REF-FIND', ctx.cc, this.id, selfpath, 'PEG=', pegpath, 'RP', pI, refpath.join('.'), descent, 'O=', out?.id, out?.canon, out?.done)
373
+
322
374
  return out
323
375
  }
324
376
 
@@ -68,6 +68,8 @@ class ScalarVal extends Val {
68
68
  ((peer as any).kind === this.kind ? 'value' : 'kind'), this, peer)
69
69
  }
70
70
 
71
+ // console.log('SCALAR', this.canon, peer.canon, '->', out.canon)
72
+
71
73
  explainClose(te, out)
72
74
 
73
75
  return out
package/src/val/TopVal.ts CHANGED
@@ -43,8 +43,8 @@ class TopVal extends Val {
43
43
  return peer.isTop
44
44
  }
45
45
 
46
- unify(peer: Val, _ctx?: AontuContext): Val {
47
- return peer
46
+ unify(peer: Val, ctx: AontuContext): Val {
47
+ return peer.unify(this, ctx)
48
48
  }
49
49
 
50
50
  get canon() { return 'top' }
package/src/val/Val.ts CHANGED
@@ -38,8 +38,6 @@ type ValSpec = {
38
38
  prefix?: boolean,
39
39
  }
40
40
 
41
- // import { AontuError, descErr, makeNilErr } from '../err'
42
- // import { AontuError } from '../err'
43
41
 
44
42
 
45
43
  const DONE = -1
@@ -155,11 +153,16 @@ abstract class Val {
155
153
  clone(ctx: AontuContext, spec?: ValSpec): Val {
156
154
  let cloneCtx
157
155
 
158
- let cut = this.path.indexOf('&')
159
- cut = -1 < cut ? cut + 1 : ctx.path.length
160
- cloneCtx = ctx.clone({
161
- path: ctx.path.concat(this.path.slice(cut))
162
- })
156
+ let path = spec?.path
157
+ if (null == path) {
158
+ let cut = this.path.indexOf('&')
159
+ cut = -1 < cut ? cut + 1 : ctx.path.length
160
+ path = ctx.path.concat(this.path.slice(cut))
161
+ }
162
+ // console.log('CLONE', path, this.canon)
163
+ // console.trace()
164
+
165
+ cloneCtx = ctx.clone({ path })
163
166
 
164
167
  let fullspec = {
165
168
  peg: this.peg,
@@ -170,11 +173,13 @@ abstract class Val {
170
173
  let out = new (this as any)
171
174
  .constructor(fullspec, cloneCtx)
172
175
 
176
+ out.dc = this.done ? DONE : out.dc
177
+
173
178
  out.site.row = spec?.row ?? this.site.row ?? -1
174
179
  out.site.col = spec?.col ?? this.site.col ?? -1
175
180
  out.site.url = spec?.url ?? this.site.url ?? ''
176
181
 
177
- // TODO: should not be needed - update all VAL ctors to handle spec.mark
182
+ out.mark = Object.assign({}, this.mark, fullspec.mark ?? {})
178
183
  out.mark.type = this.mark.type && (fullspec.mark?.type ?? true)
179
184
  out.mark.hide = this.mark.hide && (fullspec.mark?.hide ?? true)
180
185
 
@@ -215,7 +220,12 @@ abstract class Val {
215
220
  abstract superior(): Val
216
221
 
217
222
 
218
- [inspect.custom](_d: number, _o: any, _inspect: any): string {
223
+ [inspect.custom](d: number, _opts: any, _inspect: any) {
224
+ return this.inspect(d)
225
+ }
226
+
227
+ inspect(d?: number): string {
228
+ d = null == d ? -1 : d
219
229
  let s = ['<' + this.constructor.name.replace(/Val$/, '') + '/' + this.id]
220
230
 
221
231
  s.push('/' + this.path.join('.') + '/')
@@ -225,21 +235,26 @@ abstract class Val {
225
235
  ...Object.entries(this.mark).filter(n => n[1]).map(n => n[0]).sort()
226
236
  ].filter(n => null != n).join(','))
227
237
 
228
- let insp = this.inspection(inspect)
238
+ // let insp = this.inspection(inspect)
239
+ let insp = this.inspection(1 + d)
229
240
  if (null != insp && '' != insp) {
230
241
  s.push('/' + insp)
231
242
  }
232
243
 
233
244
  s.push('/')
234
245
 
235
- if ('object' === typeof this.peg) {
236
- s.push(inspectpeg(this.peg))
246
+ if (this.peg?.isVal) {
247
+ s.push(this.peg.inspect(1 + d))
248
+ }
249
+ else if (null != this.peg && 'object' === typeof this.peg &&
250
+ (Object.entries(this.peg)[0]?.[1] as any)?.isVal) {
251
+ s.push(inspectpeg(this.peg, 1 + d))
237
252
  }
238
253
  else if ('function' === typeof this.peg) {
239
254
  s.push(this.peg.name)
240
255
  }
241
256
  else {
242
- s.push(this.peg)
257
+ s.push(this.peg?.toString?.() ?? '')
243
258
  }
244
259
 
245
260
  s.push('>')
@@ -250,23 +265,32 @@ abstract class Val {
250
265
  }
251
266
 
252
267
 
253
- inspection(_inspect: Function) {
268
+ inspection(_d?: number) {
254
269
  return ''
255
270
  }
256
271
 
257
272
  }
258
273
 
259
274
 
260
- function inspectpeg(peg: any) {
261
- return pretty(!Array.isArray(peg) ? inspect(peg) :
262
- ('[' + peg.map(n => inspect(n)).join(',\n') + ']'))
275
+ function inspectpeg(peg: any, d: number) {
276
+ const indent = ' '.repeat(d)
277
+ return pretty(Array.isArray(peg) ?
278
+ ('[' + peg.map(n => '\n ' + indent + (n.inspect?.(d) ?? n)).join(',') +
279
+ '\n' + indent + ']') :
280
+ ('{' +
281
+ Object.entries(peg).map((n: any) =>
282
+ '\n ' + indent + n[0] + ': ' + // n[1].inspect(d)
283
+ (n[1].inspect(d) ?? '' + n[1])
284
+ ).join(',') +
285
+ '\n' + indent + '}')
286
+ )
263
287
  }
264
288
 
265
289
  function pretty(s: string) {
266
290
  return (
267
291
  (String(s))
268
292
  .replace(/\[Object: null prototype\]/g, '')
269
- .replace(/\s+/g, '')
293
+ // .replace(/([^\n]) +/g, '$1')
270
294
  )
271
295
  }
272
296