aontu 0.3.0 → 0.6.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 (65) hide show
  1. package/aontu.ts +3 -2
  2. package/dist/aontu.d.ts +2 -2
  3. package/dist/aontu.js +3 -4
  4. package/dist/aontu.js.map +1 -1
  5. package/dist/aontu.min.js +1 -63
  6. package/dist/lib/lang.d.ts +1 -3
  7. package/dist/lib/lang.js +47 -30
  8. package/dist/lib/lang.js.map +1 -1
  9. package/dist/lib/op/disjunct.js +10 -10
  10. package/dist/lib/op/disjunct.js.map +1 -1
  11. package/dist/lib/op/op.d.ts +1 -1
  12. package/dist/lib/op/op.js.map +1 -1
  13. package/dist/lib/op/unite.js +19 -14
  14. package/dist/lib/op/unite.js.map +1 -1
  15. package/dist/lib/type.d.ts +33 -22
  16. package/dist/lib/type.js +22 -76
  17. package/dist/lib/type.js.map +1 -1
  18. package/dist/lib/unify.d.ts +4 -1
  19. package/dist/lib/unify.js +7 -5
  20. package/dist/lib/unify.js.map +1 -1
  21. package/dist/lib/val/ConjunctVal.d.ts +12 -0
  22. package/dist/lib/val/ConjunctVal.js +191 -0
  23. package/dist/lib/val/ConjunctVal.js.map +1 -0
  24. package/dist/lib/val/DisjunctVal.d.ts +12 -0
  25. package/dist/lib/val/DisjunctVal.js +85 -0
  26. package/dist/lib/val/DisjunctVal.js.map +1 -0
  27. package/dist/lib/val/ListVal.d.ts +14 -0
  28. package/dist/lib/val/ListVal.js +91 -0
  29. package/dist/lib/val/ListVal.js.map +1 -0
  30. package/dist/lib/val/MapVal.d.ts +14 -0
  31. package/dist/lib/val/MapVal.js +141 -0
  32. package/dist/lib/val/MapVal.js.map +1 -0
  33. package/dist/lib/val/Nil.d.ts +15 -0
  34. package/dist/lib/val/Nil.js +54 -0
  35. package/dist/lib/val/Nil.js.map +1 -0
  36. package/dist/lib/val/PrefVal.d.ts +12 -0
  37. package/dist/lib/val/PrefVal.js +60 -0
  38. package/dist/lib/val/PrefVal.js.map +1 -0
  39. package/dist/lib/val/RefVal.d.ts +15 -0
  40. package/dist/lib/val/RefVal.js +73 -0
  41. package/dist/lib/val/RefVal.js.map +1 -0
  42. package/dist/lib/val/ValBase.d.ts +22 -0
  43. package/dist/lib/val/ValBase.js +25 -0
  44. package/dist/lib/val/ValBase.js.map +1 -0
  45. package/dist/lib/val.d.ts +5 -90
  46. package/dist/lib/val.js +13 -593
  47. package/dist/lib/val.js.map +1 -1
  48. package/lib/lang.ts +77 -59
  49. package/lib/op/disjunct.ts +14 -8
  50. package/lib/op/op.ts +2 -1
  51. package/lib/op/unite.ts +14 -12
  52. package/lib/type.ts +104 -0
  53. package/lib/unify.ts +10 -8
  54. package/lib/val/ConjunctVal.ts +284 -0
  55. package/lib/val/DisjunctVal.ts +145 -0
  56. package/lib/val/ListVal.ts +154 -0
  57. package/lib/val/MapVal.ts +226 -0
  58. package/lib/val/Nil.ts +94 -0
  59. package/lib/val/PrefVal.ts +113 -0
  60. package/lib/val/RefVal.ts +126 -0
  61. package/lib/val/RefVal.ts~ +319 -0
  62. package/lib/val/ValBase.ts +76 -0
  63. package/lib/val.ts +15 -802
  64. package/package.json +27 -23
  65. package/lib/common.ts +0 -19
@@ -0,0 +1,226 @@
1
+ /* Copyright (c) 2021 Richard Rodger, MIT License */
2
+
3
+
4
+
5
+ import type {
6
+ Val,
7
+ ValMap,
8
+ } from '../type'
9
+
10
+ import {
11
+ DONE,
12
+ TOP,
13
+ } from '../type'
14
+
15
+ import {
16
+ Context,
17
+ } from '../unify'
18
+
19
+
20
+ import {
21
+ Site
22
+ } from '../lang'
23
+
24
+
25
+ import {
26
+ unite
27
+ } from '../op/op'
28
+
29
+ import {
30
+ ValBase,
31
+ } from '../val/ValBase'
32
+
33
+ import {
34
+ Nil,
35
+ } from './Nil'
36
+
37
+ import {
38
+ ConjunctVal,
39
+ } from './ConjunctVal'
40
+
41
+
42
+
43
+
44
+
45
+
46
+ class MapVal extends ValBase {
47
+ static SPREAD = Symbol('spread')
48
+
49
+ spread = {
50
+ cj: (undefined as Val | undefined),
51
+ }
52
+
53
+ constructor(peg: ValMap, ctx?: Context) {
54
+ super(peg, ctx)
55
+
56
+ let spread = (this.peg as any)[MapVal.SPREAD]
57
+ delete (this.peg as any)[MapVal.SPREAD]
58
+
59
+ if (spread) {
60
+ if ('&' === spread.o) {
61
+ // TODO: handle existing spread!
62
+ this.spread.cj =
63
+ new ConjunctVal(Array.isArray(spread.v) ? spread.v : [spread.v], ctx)
64
+ }
65
+ }
66
+ }
67
+
68
+ // NOTE: order of keys is not preserved!
69
+ // not possible in any case - consider {a,b} unify {b,a}
70
+ unify(peer: Val, ctx: Context): Val {
71
+ // console.log('QQQ ctx', !!ctx)
72
+ if (null == ctx) {
73
+ console.trace()
74
+ }
75
+
76
+ let done: boolean = true
77
+ let out: MapVal = TOP === peer ? this : new MapVal({}, ctx)
78
+
79
+ out.spread.cj = this.spread.cj
80
+
81
+ if (peer instanceof MapVal) {
82
+ out.spread.cj = null == out.spread.cj ? peer.spread.cj : (
83
+ null == peer.spread.cj ? out.spread.cj : (
84
+ out.spread.cj = new ConjunctVal([out.spread.cj, peer.spread.cj], ctx)
85
+ )
86
+ )
87
+ }
88
+
89
+
90
+ out.done = this.done + 1
91
+
92
+ if (this.spread.cj) {
93
+ //out.spread.cj =
94
+ // DONE !== this.spread.cj.done ? this.spread.cj.unify(TOP, ctx) :
95
+ // this.spread.cj
96
+ out.spread.cj =
97
+ DONE !== this.spread.cj.done ? unite(ctx, this.spread.cj) :
98
+ this.spread.cj
99
+
100
+ }
101
+
102
+
103
+ // console.log(
104
+ // (' '.repeat(ctx.path.length)),
105
+ // 'MV spread', this.id, peer.id, out.id, '|',
106
+ // this.canon, peer.canon, out.canon, '|',
107
+ // (this.spread.cj || {}).done,
108
+ // (this.spread.cj || {}).canon, (out.spread.cj || {}).canon)
109
+
110
+ let spread_cj = out.spread.cj || TOP
111
+
112
+ // Always unify children first
113
+ for (let key in this.peg) {
114
+ //let oval = out.peg[key] = this.peg[key].unify(spread_cj, ctx.descend(key))
115
+ //let oval =
116
+
117
+ out.peg[key] =
118
+ unite(ctx.descend(key), this.peg[key], spread_cj)
119
+
120
+ done = (done && DONE === out.peg[key].done)
121
+
122
+ //if (oval instanceof Nil) {
123
+ // ctx.err.push(oval)
124
+ //}
125
+ }
126
+
127
+ // console.log(
128
+ // (' '.repeat(ctx.path.length)),
129
+ // 'MV child ', this.id, peer.id, out.id, '|',
130
+ // this.canon, peer.canon, out.canon, '|',
131
+ // this.constructor.name,
132
+ // peer.constructor.name,
133
+ // out.constructor.name,
134
+ // )
135
+
136
+ if (peer instanceof MapVal) {
137
+ //let upeer: MapVal = (peer.unify(TOP, ctx) as MapVal)
138
+ let upeer: MapVal = (unite(ctx, peer) as MapVal)
139
+
140
+ // console.log(
141
+ // (' '.repeat(ctx.path.length)),
142
+ // 'MV peer A', this.id, peer.id, out.id, '|',
143
+ // Object.keys(this.peg), Object.keys(upeer.peg), Object.keys(out.peg))
144
+
145
+ for (let peerkey in upeer.peg) {
146
+ let peerchild = upeer.peg[peerkey]
147
+ let child = out.peg[peerkey]
148
+
149
+ let oval = out.peg[peerkey] =
150
+ undefined === child ? peerchild :
151
+ child instanceof Nil ? child :
152
+ peerchild instanceof Nil ? peerchild :
153
+ //child.unify(peerchild, ctx.descend(peerkey))
154
+ unite(ctx.descend(peerkey), child, peerchild)
155
+
156
+ if (this.spread.cj) {
157
+ //out.peg[peerkey] = out.peg[peerkey].unify(spread_cj, ctx)
158
+ out.peg[peerkey] = unite(ctx, out.peg[peerkey], spread_cj)
159
+ }
160
+
161
+ done = (done && DONE === oval.done)
162
+
163
+ if (oval instanceof Nil) {
164
+ // ctx.err.push(oval)
165
+ }
166
+
167
+ }
168
+
169
+ // console.log(
170
+ // (' '.repeat(ctx.path.length)),
171
+ // 'MV peer B', this.id, peer.id, out.id, '|',
172
+ // Object.keys(this.peg), Object.keys(upeer.peg), Object.keys(out.peg))
173
+
174
+ //out.done = done ? DONE : out.done
175
+
176
+ // console.log(' '.repeat(W) + 'MV OUT A', this.id, out.done, out.id, out.canon)//this.spread.cj, out.spread.cj)
177
+
178
+ // console.log(
179
+ // (' '.repeat(ctx.path.length)),
180
+ // 'MV out ', this.id, peer.id, out.id, '|',
181
+ // this.canon, peer.canon, out.canon, '|',
182
+ // this.constructor.name,
183
+ // peer.constructor.name,
184
+ // out.constructor.name,
185
+ // )
186
+
187
+
188
+ }
189
+ else if (TOP !== peer) {
190
+ //out.done = done ? DONE : out.done
191
+
192
+ //return (UNIFIER(out, peer, ctx) as MapVal)
193
+
194
+ return Nil.make(ctx, 'map', this, peer)
195
+ }
196
+
197
+ out.done = done ? DONE : out.done
198
+ return out
199
+ }
200
+
201
+ get canon() {
202
+ let keys = Object.keys(this.peg)
203
+ return '{' +
204
+ (this.spread.cj ? '&:' + this.spread.cj.canon +
205
+ (0 < keys.length ? ',' : '') : '') +
206
+ keys
207
+ .map(k => [JSON.stringify(k) + ':' + this.peg[k].canon]).join(',') +
208
+ '}'
209
+ }
210
+
211
+ gen(ctx: Context) {
212
+ let out: any = {}
213
+ for (let p in this.peg) {
214
+ out[p] = this.peg[p].gen(ctx)
215
+ }
216
+ return out
217
+ }
218
+ }
219
+
220
+
221
+
222
+
223
+
224
+ export {
225
+ MapVal
226
+ }
package/lib/val/Nil.ts ADDED
@@ -0,0 +1,94 @@
1
+ /* Copyright (c) 2021-2022 Richard Rodger, MIT License */
2
+
3
+
4
+ import type {
5
+ Val,
6
+ } from '../type'
7
+
8
+ import {
9
+ DONE,
10
+ } from '../type'
11
+
12
+ import {
13
+ Context,
14
+ } from '../unify'
15
+
16
+
17
+ import {
18
+ ValBase,
19
+ } from '../val/ValBase'
20
+
21
+
22
+
23
+
24
+
25
+ class Nil extends ValBase {
26
+ nil = true
27
+ why: any
28
+ primary?: Val
29
+ secondary?: Val
30
+
31
+ // TODO: include Val generating nil, thus capture type
32
+ static make = (ctx?: Context, why?: any, av?: Val, bv?: Val) => {
33
+ let nil = new Nil(why, ctx)
34
+
35
+ // TODO: this should be done lazily, for multiple terms
36
+
37
+ // Terms later in same file are considered the primary error location.
38
+ if (null != av) {
39
+ nil.row = av.row
40
+ nil.col = av.col
41
+ nil.url = av.url
42
+
43
+ nil.primary = av
44
+
45
+ if (null != bv) {
46
+ nil.secondary = bv
47
+
48
+ let bv_loc_wins =
49
+ (nil.url === bv.url) && (
50
+ (nil.row < bv.row) ||
51
+ (nil.row === bv.row && nil.col < bv.col)
52
+ )
53
+
54
+ if (bv_loc_wins) {
55
+ nil.row = bv.row
56
+ nil.col = bv.col
57
+ nil.url = bv.url
58
+ nil.primary = bv
59
+ nil.secondary = av
60
+ }
61
+ }
62
+ }
63
+
64
+ if (ctx) {
65
+ ctx.err.push(nil)
66
+ }
67
+
68
+ return nil
69
+ }
70
+
71
+ constructor(why?: any, ctx?: Context) {
72
+ super(null, ctx)
73
+ this.why = why
74
+
75
+ // Nil is always DONE, by definition.
76
+ this.done = DONE
77
+ }
78
+
79
+ unify(_peer: Val, _ctx: Context) {
80
+ return this
81
+ }
82
+
83
+ get canon() {
84
+ return 'nil'
85
+ }
86
+
87
+ gen(_ctx?: Context) {
88
+ return undefined
89
+ }
90
+ }
91
+
92
+ export {
93
+ Nil,
94
+ }
@@ -0,0 +1,113 @@
1
+ /* Copyright (c) 2021-2022 Richard Rodger, MIT License */
2
+
3
+
4
+ import type {
5
+ Val,
6
+ } from '../type'
7
+
8
+ import {
9
+ DONE,
10
+ } from '../type'
11
+
12
+ import {
13
+ Context,
14
+ } from '../unify'
15
+
16
+
17
+ import {
18
+ Site
19
+ } from '../lang'
20
+
21
+
22
+ import {
23
+ unite
24
+ } from '../op/op'
25
+
26
+ import { Nil } from '../val/Nil'
27
+
28
+ import {
29
+ ValBase,
30
+ } from '../val/ValBase'
31
+
32
+
33
+
34
+ class PrefVal extends ValBase {
35
+ pref: Val
36
+ constructor(peg: any, pref?: any, ctx?: Context) {
37
+ super(peg, ctx)
38
+ this.pref = pref || peg
39
+ }
40
+
41
+ // PrefVal unify always returns a PrefVal
42
+ // PrefVals can only be removed by becoming Nil in a Disjunct
43
+ unify(peer: Val, ctx: Context): Val {
44
+ let done = true
45
+ let out: Val
46
+
47
+ if (peer instanceof PrefVal) {
48
+ out = new PrefVal(
49
+ unite(ctx, this.peg, peer.peg, 'Pref000'),
50
+ unite(ctx, this.pref, peer.pref, 'Pref010'),
51
+ ctx
52
+ )
53
+
54
+ }
55
+ else {
56
+ out = new PrefVal(
57
+ // TODO: find a better way to drop Nil non-errors
58
+ unite(ctx?.clone({ err: [] }), this.peg, peer, 'Pref020'),
59
+ unite(ctx?.clone({ err: [] }), this.pref, peer, 'Pref030'),
60
+ ctx
61
+ )
62
+ }
63
+
64
+ done = done && DONE === out.peg.done &&
65
+ (null != (out as PrefVal).pref ? DONE === (out as PrefVal).pref.done : true)
66
+
67
+ if (out.peg instanceof Nil) {
68
+ out = (out as PrefVal).pref
69
+ }
70
+ else if ((out as PrefVal).pref instanceof Nil) {
71
+ out = out.peg
72
+ }
73
+
74
+ out.done = done ? DONE : this.done + 1
75
+
76
+ return out
77
+ }
78
+
79
+
80
+ same(peer: Val): boolean {
81
+ if (null == peer) {
82
+ return false
83
+ }
84
+
85
+ let pegsame = (this.peg === peer.peg) ||
86
+ (this.peg instanceof ValBase && this.peg.same(peer.peg))
87
+
88
+ let prefsame = peer instanceof PrefVal &&
89
+ ((this.pref === peer.pref) ||
90
+ (this.pref instanceof ValBase && this.pref.same(peer.pref)))
91
+
92
+ return pegsame && prefsame
93
+ }
94
+
95
+
96
+ get canon() {
97
+ return this.pref instanceof Nil ? this.peg.canon : '*' + this.pref.canon
98
+ }
99
+
100
+ gen(ctx?: Context) {
101
+ let val = !(this.pref instanceof Nil) ? this.pref :
102
+ !(this.peg instanceof Nil) ? this.peg :
103
+ undefined
104
+
105
+ return undefined === val ? undefined : val.gen(ctx)
106
+ }
107
+ }
108
+
109
+
110
+
111
+ export {
112
+ PrefVal,
113
+ }
@@ -0,0 +1,126 @@
1
+ /* Copyright (c) 2021 Richard Rodger, MIT License */
2
+
3
+
4
+
5
+ import type {
6
+ Val,
7
+ ValMap,
8
+ ValList,
9
+ } from '../type'
10
+
11
+ import {
12
+ DONE,
13
+ TOP,
14
+ } from '../type'
15
+
16
+ import {
17
+ Context,
18
+ } from '../unify'
19
+
20
+
21
+ import {
22
+ Site
23
+ } from '../lang'
24
+
25
+
26
+ import {
27
+ unite
28
+ } from '../op/op'
29
+
30
+ import { Nil } from '../val/Nil'
31
+
32
+ import { ValBase } from '../val/ValBase'
33
+ import { ConjunctVal } from '../val/ConjunctVal'
34
+
35
+ import { StringVal } from '../val'
36
+
37
+
38
+
39
+ class RefVal extends ValBase {
40
+ parts: string[]
41
+ absolute: boolean
42
+ sep = '.'
43
+
44
+ constructor(peg: any[], abs?: boolean) {
45
+ super('')
46
+ this.absolute = true === abs
47
+ this.parts = []
48
+
49
+ for (let part of peg) {
50
+ this.append(part)
51
+ }
52
+ }
53
+
54
+
55
+ append(part: any) {
56
+ //console.log('APPEND 0', part)
57
+
58
+ if ('string' === typeof part) {
59
+ this.parts.push(part)
60
+ }
61
+
62
+ else if (part instanceof StringVal) {
63
+ this.parts.push(part.peg)
64
+ }
65
+
66
+ else if (part instanceof RefVal) {
67
+ this.parts.push(...part.parts)
68
+
69
+ if (part.absolute) {
70
+ this.absolute = true
71
+ }
72
+ }
73
+
74
+ this.peg = (this.absolute ? this.sep : '') + this.parts.join(this.sep)
75
+ }
76
+
77
+ unify(peer: Val, ctx: Context): Val {
78
+ let resolved: Val | undefined = null == ctx ? this : ctx.find(this)
79
+
80
+ // TODO: large amount of reruns needed? why?
81
+ resolved = null == resolved && 999 < this.done ?
82
+ Nil.make(ctx, 'no-path', this, peer) : (resolved || this)
83
+ let out: Val
84
+
85
+ if (resolved instanceof RefVal) {
86
+ if (TOP === peer) {
87
+ out = this
88
+ }
89
+ else if (peer instanceof Nil) {
90
+ out = Nil.make(ctx, 'ref[' + this.peg + ']', this, peer)
91
+ }
92
+ else {
93
+ // Ensure RefVal done is incremented
94
+ this.done = DONE === this.done ? DONE : this.done + 1
95
+ out = new ConjunctVal([this, peer], ctx)
96
+ }
97
+ }
98
+ else {
99
+ out = unite(ctx, resolved, peer)
100
+ }
101
+
102
+ out.done = DONE === out.done ? DONE : this.done + 1
103
+
104
+ return out
105
+ }
106
+
107
+
108
+ same(peer: Val): boolean {
109
+ return null == peer ? false : this.peg === peer.peg
110
+ }
111
+
112
+
113
+ get canon() {
114
+ return this.peg
115
+ }
116
+
117
+
118
+ gen(_ctx?: Context) {
119
+ return undefined
120
+ }
121
+ }
122
+
123
+
124
+ export {
125
+ RefVal,
126
+ }