aontu 0.28.0 → 0.30.1

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 (89) hide show
  1. package/dist/aontu.d.ts +17 -10
  2. package/dist/aontu.js +149 -57
  3. package/dist/aontu.js.map +1 -1
  4. package/package.json +18 -34
  5. package/aontu.ts +0 -81
  6. package/dist/lib/err.d.ts +0 -3
  7. package/dist/lib/err.js +0 -91
  8. package/dist/lib/err.js.map +0 -1
  9. package/dist/lib/lang.d.ts +0 -15
  10. package/dist/lib/lang.js +0 -409
  11. package/dist/lib/lang.js.map +0 -1
  12. package/dist/lib/op/disjunct.d.ts +0 -3
  13. package/dist/lib/op/disjunct.js +0 -28
  14. package/dist/lib/op/disjunct.js.map +0 -1
  15. package/dist/lib/op/op.d.ts +0 -6
  16. package/dist/lib/op/op.js +0 -9
  17. package/dist/lib/op/op.js.map +0 -1
  18. package/dist/lib/op/unite.d.ts +0 -3
  19. package/dist/lib/op/unite.js +0 -100
  20. package/dist/lib/op/unite.js.map +0 -1
  21. package/dist/lib/type.d.ts +0 -40
  22. package/dist/lib/type.js +0 -7
  23. package/dist/lib/type.js.map +0 -1
  24. package/dist/lib/unify.d.ts +0 -35
  25. package/dist/lib/unify.js +0 -72
  26. package/dist/lib/unify.js.map +0 -1
  27. package/dist/lib/utility.d.ts +0 -3
  28. package/dist/lib/utility.js +0 -16
  29. package/dist/lib/utility.js.map +0 -1
  30. package/dist/lib/val/ConjunctVal.d.ts +0 -17
  31. package/dist/lib/val/ConjunctVal.js +0 -196
  32. package/dist/lib/val/ConjunctVal.js.map +0 -1
  33. package/dist/lib/val/DisjunctVal.d.ts +0 -17
  34. package/dist/lib/val/DisjunctVal.js +0 -100
  35. package/dist/lib/val/DisjunctVal.js.map +0 -1
  36. package/dist/lib/val/ListVal.d.ts +0 -18
  37. package/dist/lib/val/ListVal.js +0 -120
  38. package/dist/lib/val/ListVal.js.map +0 -1
  39. package/dist/lib/val/MapVal.d.ts +0 -18
  40. package/dist/lib/val/MapVal.js +0 -144
  41. package/dist/lib/val/MapVal.js.map +0 -1
  42. package/dist/lib/val/Nil.d.ts +0 -22
  43. package/dist/lib/val/Nil.js +0 -84
  44. package/dist/lib/val/Nil.js.map +0 -1
  45. package/dist/lib/val/NullVal.d.ts +0 -15
  46. package/dist/lib/val/NullVal.js +0 -39
  47. package/dist/lib/val/NullVal.js.map +0 -1
  48. package/dist/lib/val/OpVal.d.ts +0 -17
  49. package/dist/lib/val/OpVal.js +0 -89
  50. package/dist/lib/val/OpVal.js.map +0 -1
  51. package/dist/lib/val/PlusVal.d.ts +0 -12
  52. package/dist/lib/val/PlusVal.js +0 -32
  53. package/dist/lib/val/PlusVal.js.map +0 -1
  54. package/dist/lib/val/PrefVal.d.ts +0 -17
  55. package/dist/lib/val/PrefVal.js +0 -87
  56. package/dist/lib/val/PrefVal.js.map +0 -1
  57. package/dist/lib/val/RefVal.d.ts +0 -22
  58. package/dist/lib/val/RefVal.js +0 -256
  59. package/dist/lib/val/RefVal.js.map +0 -1
  60. package/dist/lib/val/ValBase.d.ts +0 -26
  61. package/dist/lib/val/ValBase.js +0 -77
  62. package/dist/lib/val/ValBase.js.map +0 -1
  63. package/dist/lib/val/VarVal.d.ts +0 -15
  64. package/dist/lib/val/VarVal.js +0 -84
  65. package/dist/lib/val/VarVal.js.map +0 -1
  66. package/dist/lib/val.d.ts +0 -81
  67. package/dist/lib/val.js +0 -191
  68. package/dist/lib/val.js.map +0 -1
  69. package/lib/err.ts +0 -111
  70. package/lib/lang.ts +0 -586
  71. package/lib/op/disjunct.ts +0 -52
  72. package/lib/op/op.ts +0 -19
  73. package/lib/op/unite.ts +0 -143
  74. package/lib/type.ts +0 -83
  75. package/lib/unify.ts +0 -144
  76. package/lib/utility.ts +0 -23
  77. package/lib/val/ConjunctVal.ts +0 -300
  78. package/lib/val/DisjunctVal.ts +0 -170
  79. package/lib/val/ListVal.ts +0 -196
  80. package/lib/val/MapVal.ts +0 -217
  81. package/lib/val/Nil.ts +0 -144
  82. package/lib/val/NullVal.ts +0 -74
  83. package/lib/val/OpVal.ts +0 -159
  84. package/lib/val/PlusVal.ts +0 -76
  85. package/lib/val/PrefVal.ts +0 -154
  86. package/lib/val/RefVal.ts +0 -380
  87. package/lib/val/ValBase.ts +0 -109
  88. package/lib/val/VarVal.ts +0 -156
  89. package/lib/val.ts +0 -326
package/lib/val/RefVal.ts DELETED
@@ -1,380 +0,0 @@
1
- /* Copyright (c) 2021-2023 Richard Rodger, MIT License */
2
-
3
-
4
- /* TODO
5
- Rename ot PathVal
6
-
7
- $SELF.a - path starting at self
8
- $PARENT.b === .b - sibling
9
-
10
- implement $ as a prefix operator
11
- this allows "$AString" to be used for literal part names
12
- */
13
-
14
-
15
-
16
- import type {
17
- Val,
18
- ValSpec,
19
- } from '../type'
20
-
21
- import {
22
- DONE,
23
- } from '../type'
24
-
25
- import {
26
- descErr
27
- } from '../err'
28
-
29
- import {
30
- Context,
31
- } from '../unify'
32
-
33
- import {
34
- unite
35
- } from '../op/op'
36
-
37
- import {
38
- TOP,
39
- StringVal,
40
- } from '../val'
41
-
42
-
43
- import { ConjunctVal } from '../val/ConjunctVal'
44
- import { MapVal } from '../val/MapVal'
45
- import { Nil } from '../val/Nil'
46
- import { VarVal } from '../val/VarVal'
47
- import { ValBase } from '../val/ValBase'
48
-
49
-
50
-
51
-
52
-
53
- class RefVal extends ValBase {
54
- isRefVal = true
55
-
56
- absolute: boolean = false
57
- prefix: boolean = false
58
-
59
- constructor(
60
- spec: {
61
- peg: any[],
62
- absolute?: boolean,
63
- prefix?: boolean
64
- },
65
- ctx?: Context
66
- ) {
67
- super(spec, ctx)
68
- this.peg = []
69
-
70
- this.absolute = true === this.absolute ? true : // absolute sticks
71
- true === spec.absolute ? true : false
72
-
73
- this.prefix = true === spec.prefix
74
-
75
- for (let pI = 0; pI < spec.peg.length; pI++) {
76
- this.append(spec.peg[pI])
77
- }
78
- }
79
-
80
-
81
- append(part: any) {
82
- // console.log('APPEND', part, this)
83
- let partval
84
-
85
- if ('string' === typeof part) {
86
- partval = part
87
- this.peg.push(partval)
88
- }
89
-
90
- else if (part instanceof StringVal) {
91
- partval = part.peg
92
- this.peg.push(partval)
93
- }
94
-
95
- else if (part instanceof VarVal) {
96
- partval = part
97
- this.peg.push(partval)
98
- }
99
-
100
- else if (part instanceof RefVal) {
101
- if (part.absolute) {
102
- this.absolute = true
103
- }
104
-
105
- if (this.prefix) {
106
- if (part.prefix) {
107
- this.peg.push('.')
108
- }
109
- }
110
- else {
111
- if (part.prefix) {
112
- if (0 === this.peg.length) {
113
- this.prefix = true
114
- }
115
-
116
- else if (0 < this.peg.length) {
117
- this.peg.push('.')
118
- }
119
- }
120
- }
121
-
122
- this.peg.push(...part.peg)
123
- }
124
- }
125
-
126
-
127
- unify(peer: Val, ctx: Context): Val {
128
- let out: Val = this
129
- // let why = 'id'
130
-
131
- if (this.id !== peer.id) {
132
-
133
- // TODO: not resolved when all Vals in path are done is an error
134
- // as path cannot be found
135
- // let resolved: Val | undefined = null == ctx ? this : ctx.find(this)
136
- let resolved: Val | undefined = null == ctx ? this : this.find(ctx)
137
-
138
- // console.log('UR', this.peg, resolved)
139
-
140
- resolved = resolved || this
141
-
142
- if (null == resolved && this.canon === peer.canon) {
143
- out = this
144
- }
145
- else if (resolved instanceof RefVal) {
146
- if (TOP === peer) {
147
- out = this
148
- // why = 'pt'
149
- }
150
- else if (peer instanceof Nil) {
151
- out = Nil.make(ctx, 'ref[' + this.peg + ']', this, peer)
152
- // why = 'pn'
153
- }
154
-
155
- // same path
156
- // else if (this.peg === peer.peg) {
157
- else if (this.canon === peer.canon) {
158
- out = this
159
- // why = 'pp'
160
- }
161
-
162
- else {
163
- // Ensure RefVal done is incremented
164
- this.done = DONE === this.done ? DONE : this.done + 1
165
- out = new ConjunctVal({ peg: [this, peer] }, ctx)
166
- // why = 'cj'
167
- }
168
- }
169
- else {
170
- out = unite(ctx, resolved, peer, 'ref')
171
- // why = 'u'
172
- }
173
-
174
- out.done = DONE === out.done ? DONE : this.done + 1
175
- }
176
-
177
- // console.log('RV', why, this.id, this.canon, '&', peer.canon, '->', out.canon)
178
-
179
- return out
180
- }
181
-
182
-
183
- find(ctx: Context) {
184
- // TODO: relative paths
185
- // if (this.root instanceof MapVal && ref.absolute) {
186
-
187
- // NOTE: path *to* the ref, not the ref itself!
188
- let fullpath = this.path
189
-
190
- let parts: string[] = []
191
-
192
- let modes: string[] = []
193
-
194
- // console.log('REF', this.id, this.path, this.done, 'PEG', this.peg.map((p: any) => p.canon))
195
- // console.dir(this.peg, { depth: null })
196
-
197
-
198
- for (let pI = 0; pI < this.peg.length; pI++) {
199
- let part = this.peg[pI]
200
- if (part instanceof VarVal) {
201
- let strval = (part as VarVal).peg
202
- let name = strval ? '' + strval.peg : ''
203
-
204
- if ('KEY' === name) {
205
- if (pI === this.peg.length - 1) {
206
- modes.push(name)
207
- }
208
- else {
209
- // TODO: return a Nil explaining error
210
- return
211
- }
212
- }
213
-
214
- if ('SELF' === name) {
215
- if (pI === 0) {
216
- modes.push(name)
217
- }
218
- else {
219
- // TODO: return a Nil explaining error
220
- return
221
- }
222
- }
223
- else if ('PARENT' === name) {
224
- if (pI === 0) {
225
- modes.push(name)
226
- }
227
- else {
228
- // TODO: return a Nil explaining error
229
- return
230
- }
231
- }
232
- else if (0 === modes.length) {
233
- part = (part as VarVal).unify(TOP, ctx)
234
- if (part instanceof Nil) {
235
- // TODO: var not found, so can't find path
236
- return
237
- }
238
- else {
239
- part = '' + part.peg
240
- }
241
- }
242
- }
243
- else {
244
- parts.push(part)
245
- }
246
- }
247
-
248
- // console.log('modes', modes)
249
-
250
-
251
- if (this.absolute) {
252
- fullpath = parts
253
- }
254
- else {
255
- fullpath = fullpath.slice(
256
- 0,
257
- (
258
- modes.includes('SELF') ? 0 :
259
- modes.includes('PARENT') ? -1 :
260
- -1 // siblings
261
- )
262
- ).concat(parts)
263
- }
264
-
265
- let sep = '.'
266
- fullpath = fullpath
267
- .reduce(((a: string[], p: string) =>
268
- (p === sep ? a.length = a.length - 1 : a.push(p), a)), [])
269
-
270
- // console.log('REF', this.id, this.path, this.done, 'FULLPATH', fullpath)
271
-
272
-
273
- if (modes.includes('KEY')) {
274
- let key = this.path[this.path.length - 2]
275
- let sv = new StringVal({ peg: null == key ? '' : key }, ctx)
276
-
277
- // TODO: other props?
278
- sv.done = DONE
279
- sv.path = this.path
280
-
281
- return sv
282
- }
283
-
284
-
285
-
286
- let node = ctx.root
287
- let pI = 0
288
- for (; pI < fullpath.length; pI++) {
289
- // console.log('RefVal DESCEND', pI, node)
290
- let part = fullpath[pI]
291
-
292
- if (node instanceof MapVal) {
293
- node = node.peg[part]
294
- }
295
- else {
296
- break;
297
- }
298
- }
299
-
300
- // console.log('RefVal KEY', modes, pI, fullpath)
301
-
302
- if (pI === fullpath.length) {
303
- // if (this.attr && 'KEY' === this.attr.kind) {
304
- // if (modes.includes('KEY')) {
305
- // let key = fullpath[fullpath.length - 1]
306
- // let sv = new StringVal({ peg: null == key ? '' : key }, ctx)
307
-
308
- // // TODO: other props?
309
- // sv.done = DONE
310
- // sv.path = this.path
311
-
312
- // return sv
313
- // }
314
- // else {
315
- // console.log('REF', this.id, this.path, this.done, 'FOUND', node.canon)
316
- return node
317
- // }
318
- }
319
- }
320
-
321
-
322
- same(peer: Val): boolean {
323
- return null == peer ? false : this.peg === peer.peg
324
- }
325
-
326
-
327
- clone(spec?: ValSpec, ctx?: Context): Val {
328
- let out = (super.clone({
329
- peg: this.peg,
330
- absolute: this.absolute,
331
- ...(spec || {})
332
- }, ctx) as RefVal)
333
- return out
334
- }
335
-
336
-
337
- get canon() {
338
- let str =
339
- (this.absolute ? '$' : '') +
340
- (0 < this.peg.length ? '.' : '') +
341
- // this.peg.join(this.sep)
342
- this.peg.map((p: any) => '.' === p ? '' :
343
- (p.isVal ? p.canon : '' + p))
344
- .join('.')
345
- return str
346
- }
347
-
348
-
349
- gen(ctx?: Context) {
350
- // Unresolved ref cannot be generated, so always an error.
351
- let nil = Nil.make(
352
- ctx,
353
- 'ref',
354
- this, // (formatPath(this.peg, this.absolute) as any),
355
- undefined
356
- )
357
-
358
- // TODO: refactor to use Site
359
- nil.path = this.path
360
- nil.url = this.url
361
- nil.row = this.row
362
- nil.col = this.col
363
-
364
- descErr(nil, ctx)
365
-
366
- if (ctx) {
367
- ctx.err.push(nil)
368
- }
369
- else {
370
- throw new Error(nil.msg)
371
- }
372
-
373
- return undefined
374
- }
375
- }
376
-
377
-
378
- export {
379
- RefVal,
380
- }
@@ -1,109 +0,0 @@
1
- /* Copyright (c) 2021-2024 Richard Rodger, MIT License */
2
-
3
-
4
-
5
- import type {
6
- Val,
7
- ValSpec,
8
- } from '../type'
9
-
10
-
11
- import {
12
- Context,
13
- } from '../unify'
14
-
15
-
16
- import {
17
- Site
18
- } from '../lang'
19
-
20
-
21
- let ID = 0
22
-
23
-
24
- class ValBase implements Val {
25
- isVal = true
26
-
27
- id: number
28
- done: number = 0
29
- path: string[] = []
30
- row: number = -1
31
- col: number = -1
32
- url: string = ''
33
-
34
- top: boolean = false
35
-
36
- // Actual native value.
37
- peg: any = undefined
38
-
39
- // TODO: used for top level result - not great
40
- err: any[] = []
41
- // deps?: any
42
-
43
- uh: number[]
44
-
45
- // TODO: implement!
46
- // site: Site
47
-
48
- #ctx: any
49
-
50
- // TODO: Site needed in ctor
51
- constructor(spec: ValSpec, ctx?: Context) {
52
- this.#ctx = ctx
53
-
54
- this.peg = spec?.peg
55
- this.path = ctx?.path || []
56
- // this.id = (9e9 + Math.floor(Math.random() * (1e9)))
57
- this.id = ++ID // (9e9 + Math.floor(Math.random() * (1e5)))
58
- this.uh = []
59
- }
60
-
61
-
62
- ctx() {
63
- return this.#ctx
64
- }
65
-
66
- same(peer: Val): boolean {
67
- return null == peer ? false : this.id === peer.id
68
- }
69
-
70
-
71
- clone(spec?: ValSpec, ctx?: Context): Val {
72
- let cloneCtx
73
-
74
- if (ctx) {
75
- let cut = this.path.indexOf('&')
76
- cut = -1 < cut ? cut + 1 : ctx.path.length
77
- cloneCtx = ctx.clone({
78
- path: ctx.path.concat(this.path.slice(cut))
79
- })
80
- }
81
-
82
- let out = new (this as any)
83
- .constructor(spec || { peg: this.peg }, cloneCtx)
84
-
85
- out.row = spec?.row || this.row || -1
86
- out.col = spec?.col || this.col || -1
87
- out.url = spec?.url || this.url || ''
88
-
89
- if (null == cloneCtx) {
90
- out.path = this.path.slice(0)
91
- }
92
-
93
- return out
94
- }
95
-
96
-
97
- get site(): Site {
98
- return new Site(this)
99
- }
100
-
101
- unify(_peer: Val, _ctx?: Context): Val { return this }
102
- get canon(): string { return '' }
103
- gen(_ctx?: Context): any { return null }
104
-
105
- }
106
-
107
- export {
108
- ValBase,
109
- }
package/lib/val/VarVal.ts DELETED
@@ -1,156 +0,0 @@
1
- /* Copyright (c) 2021-2023 Richard Rodger, MIT License */
2
-
3
-
4
- /* TODO
5
-
6
- $SELF.a - path starting at self
7
- $PARENT.b === .b - sibling
8
-
9
- implement $ as a prefix operator
10
- this allows "$AString" to be used for literal part names
11
- */
12
-
13
-
14
-
15
- import type {
16
- Val,
17
- ValSpec,
18
- } from '../type'
19
-
20
- import {
21
- DONE,
22
- } from '../type'
23
-
24
- import {
25
- descErr
26
- } from '../err'
27
-
28
- import {
29
- Context,
30
- } from '../unify'
31
-
32
-
33
-
34
- import {
35
- unite
36
- } from '../op/op'
37
-
38
-
39
-
40
- import {
41
- TOP,
42
- StringVal,
43
- } from '../val'
44
-
45
- // import { ConjunctVal } from '../val/ConjunctVal'
46
- // import { DisjunctVal } from '../val/DisjunctVal'
47
- // import { ListVal } from '../val/ListVal'
48
- // import { MapVal } from '../val/MapVal'
49
- import { Nil } from '../val/Nil'
50
- import { RefVal } from '../val/RefVal'
51
- import { ValBase } from '../val/ValBase'
52
-
53
-
54
-
55
- // TODO: KEY, SELF, PARENT are reserved names - error
56
-
57
- class VarVal extends ValBase {
58
- isVarVal = true
59
-
60
- constructor(
61
- spec: {
62
- peg: string | Val
63
- },
64
- ctx?: Context
65
- ) {
66
- super(spec, ctx)
67
- }
68
-
69
-
70
- unify(peer: Val, ctx: Context): Val {
71
- let out: Val
72
-
73
- let nameVal
74
-
75
- if (this.peg.isVal) {
76
- // $.a.b.c - convert path to absolute
77
- if (this.peg instanceof RefVal) {
78
- this.peg.absolute = true
79
- nameVal = this.peg
80
- }
81
- else {
82
- nameVal = this.peg.unify(peer)
83
- }
84
- }
85
- else {
86
- // TODO: how to pass row+col?
87
- nameVal = new StringVal({ peg: '' + this.peg }, ctx)
88
- }
89
-
90
- if (!(nameVal instanceof RefVal) && DONE === nameVal.done) {
91
- if (nameVal instanceof StringVal) {
92
- out = ctx.var[nameVal.peg]
93
- if (null == out) {
94
- out = Nil.make(ctx, 'var[' + nameVal.peg + ']', this, peer)
95
- }
96
- }
97
- else {
98
- out = Nil.make(ctx, 'var[' + typeof nameVal + ']', this, peer)
99
- }
100
- }
101
- else {
102
- out = nameVal
103
- }
104
-
105
- return out
106
- }
107
-
108
-
109
- same(peer: Val): boolean {
110
- return null == peer ? false : peer instanceof VarVal && this.peg === peer.peg
111
- }
112
-
113
-
114
- clone(spec?: ValSpec, ctx?: Context): Val {
115
- let out = (super.clone(spec, ctx) as VarVal)
116
- return out
117
- }
118
-
119
-
120
- get canon() {
121
- return '$' + (this.peg?.isVal ? this.peg.canon : '' + this.peg)
122
- }
123
-
124
-
125
- gen(ctx?: Context) {
126
- // Unresolved var cannot be generated, so always an error.
127
- let nil = Nil.make(
128
- ctx,
129
- 'var',
130
- this,
131
- undefined
132
- )
133
-
134
- // TODO: refactor to use Site
135
- nil.path = this.path
136
- nil.url = this.url
137
- nil.row = this.row
138
- nil.col = this.col
139
-
140
- descErr(nil, ctx)
141
-
142
- if (ctx) {
143
- ctx.err.push(nil)
144
- }
145
- else {
146
- throw new Error(nil.msg)
147
- }
148
-
149
- return undefined
150
- }
151
- }
152
-
153
-
154
- export {
155
- VarVal,
156
- }