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