aontu 0.11.0 → 0.13.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/aontu.ts +13 -6
- package/dist/aontu.d.ts +3 -0
- package/dist/aontu.js +10 -4
- package/dist/aontu.js.map +1 -1
- package/dist/aontu.min.js +1 -1
- package/dist/lib/err.js +1 -1
- package/dist/lib/err.js.map +1 -1
- package/dist/lib/lang.d.ts +1 -2
- package/dist/lib/lang.js +130 -38
- package/dist/lib/lang.js.map +1 -1
- package/dist/lib/op/disjunct.js +2 -2
- package/dist/lib/op/disjunct.js.map +1 -1
- package/dist/lib/op/op.js +1 -1
- package/dist/lib/op/op.js.map +1 -1
- package/dist/lib/op/unite.js +36 -6
- package/dist/lib/op/unite.js.map +1 -1
- package/dist/lib/type.d.ts +10 -8
- package/dist/lib/type.js +2 -27
- package/dist/lib/type.js.map +1 -1
- package/dist/lib/unify.d.ts +7 -4
- package/dist/lib/unify.js +17 -29
- package/dist/lib/unify.js.map +1 -1
- package/dist/lib/val/ConjunctVal.d.ts +7 -4
- package/dist/lib/val/ConjunctVal.js +62 -31
- package/dist/lib/val/ConjunctVal.js.map +1 -1
- package/dist/lib/val/DisjunctVal.d.ts +5 -2
- package/dist/lib/val/DisjunctVal.js +15 -7
- package/dist/lib/val/DisjunctVal.js.map +1 -1
- package/dist/lib/val/ListVal.d.ts +5 -2
- package/dist/lib/val/ListVal.js +39 -19
- package/dist/lib/val/ListVal.js.map +1 -1
- package/dist/lib/val/MapVal.d.ts +5 -2
- package/dist/lib/val/MapVal.js +59 -30
- package/dist/lib/val/MapVal.js.map +1 -1
- package/dist/lib/val/Nil.d.ts +3 -2
- package/dist/lib/val/Nil.js +19 -5
- package/dist/lib/val/Nil.js.map +1 -1
- package/dist/lib/val/PrefVal.d.ts +6 -2
- package/dist/lib/val/PrefVal.js +18 -8
- package/dist/lib/val/PrefVal.js.map +1 -1
- package/dist/lib/val/RefVal.d.ts +11 -5
- package/dist/lib/val/RefVal.js +187 -39
- package/dist/lib/val/RefVal.js.map +1 -1
- package/dist/lib/val/ValBase.d.ts +10 -9
- package/dist/lib/val/ValBase.js +25 -6
- package/dist/lib/val/ValBase.js.map +1 -1
- package/dist/lib/val/VarVal.d.ts +14 -0
- package/dist/lib/val/VarVal.js +68 -0
- package/dist/lib/val/VarVal.js.map +1 -0
- package/dist/lib/val.d.ts +42 -8
- package/dist/lib/val.js +64 -18
- package/dist/lib/val.js.map +1 -1
- package/lib/err.ts +1 -1
- package/lib/lang.ts +168 -43
- package/lib/op/disjunct.ts +10 -3
- package/lib/op/op.ts +1 -1
- package/lib/op/unite.ts +44 -4
- package/lib/type.ts +12 -40
- package/lib/unify.ts +70 -29
- package/lib/val/ConjunctVal.ts +83 -46
- package/lib/val/DisjunctVal.ts +35 -12
- package/lib/val/ListVal.ts +57 -22
- package/lib/val/MapVal.ts +82 -51
- package/lib/val/Nil.ts +29 -9
- package/lib/val/PrefVal.ts +38 -14
- package/lib/val/RefVal.ts +254 -55
- package/lib/val/ValBase.ts +33 -28
- package/lib/val/VarVal.ts +139 -0
- package/lib/val.ts +116 -25
- package/package.json +8 -8
- package/dist/lib/common.d.ts +0 -8
- package/dist/lib/common.js +0 -3
- package/dist/lib/common.js.map +0 -1
package/lib/val.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Copyright (c) 2021 Richard Rodger, MIT License */
|
|
1
|
+
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
2
|
|
|
3
3
|
// TODO: infinite recursion protection
|
|
4
4
|
|
|
@@ -21,13 +21,14 @@ TOP -> Scalar/Boolean -> BooleanVal
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
|
|
24
25
|
import type {
|
|
25
26
|
Val,
|
|
27
|
+
ValSpec,
|
|
26
28
|
} from './type'
|
|
27
29
|
|
|
28
30
|
import {
|
|
29
31
|
DONE,
|
|
30
|
-
TOP,
|
|
31
32
|
} from './type'
|
|
32
33
|
|
|
33
34
|
import {
|
|
@@ -41,19 +42,62 @@ import {
|
|
|
41
42
|
|
|
42
43
|
|
|
43
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'
|
|
44
49
|
import { Nil } from './val/Nil'
|
|
50
|
+
import { PrefVal } from './val/PrefVal'
|
|
51
|
+
import { RefVal } from './val/RefVal'
|
|
52
|
+
import { ValBase } from './val/ValBase'
|
|
45
53
|
|
|
46
|
-
import {
|
|
47
|
-
ValBase,
|
|
48
|
-
} from './val/ValBase'
|
|
49
54
|
|
|
55
|
+
// There can be only one.
|
|
56
|
+
class TopVal extends ValBase {
|
|
57
|
+
isVal = true
|
|
58
|
+
|
|
59
|
+
id = 0
|
|
60
|
+
top = true
|
|
61
|
+
peg = undefined
|
|
62
|
+
done = DONE
|
|
63
|
+
path = []
|
|
64
|
+
row = -1
|
|
65
|
+
col = -1
|
|
66
|
+
url = ''
|
|
67
|
+
|
|
68
|
+
constructor() {
|
|
69
|
+
super(null)
|
|
70
|
+
|
|
71
|
+
// TOP is always DONE, by definition.
|
|
72
|
+
this.done = DONE
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
unify(peer: Val, _ctx: Context): Val {
|
|
76
|
+
return peer
|
|
77
|
+
}
|
|
50
78
|
|
|
79
|
+
get canon() { return 'top' }
|
|
51
80
|
|
|
81
|
+
get site(): Site { return new Site(this) }
|
|
52
82
|
|
|
83
|
+
same(peer: Val): boolean {
|
|
84
|
+
return this === peer
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
clone() {
|
|
88
|
+
return this
|
|
89
|
+
}
|
|
53
90
|
|
|
91
|
+
gen(_ctx?: Context) {
|
|
92
|
+
return undefined
|
|
93
|
+
}
|
|
94
|
+
}
|
|
54
95
|
|
|
55
96
|
|
|
56
97
|
|
|
98
|
+
const TOP = new TopVal()
|
|
99
|
+
|
|
100
|
+
|
|
57
101
|
// A ScalarType for integers. Number includes floats.
|
|
58
102
|
class Integer { }
|
|
59
103
|
|
|
@@ -67,8 +111,14 @@ type ScalarConstructor =
|
|
|
67
111
|
|
|
68
112
|
|
|
69
113
|
class ScalarTypeVal extends ValBase {
|
|
70
|
-
|
|
71
|
-
|
|
114
|
+
|
|
115
|
+
constructor(
|
|
116
|
+
spec: {
|
|
117
|
+
peg: ScalarConstructor
|
|
118
|
+
},
|
|
119
|
+
ctx?: Context
|
|
120
|
+
) {
|
|
121
|
+
super(spec, ctx)
|
|
72
122
|
this.done = DONE
|
|
73
123
|
}
|
|
74
124
|
|
|
@@ -111,23 +161,46 @@ class ScalarTypeVal extends ValBase {
|
|
|
111
161
|
}
|
|
112
162
|
|
|
113
163
|
|
|
164
|
+
|
|
114
165
|
class ScalarVal<T> extends ValBase {
|
|
115
166
|
type: any
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
167
|
+
|
|
168
|
+
constructor(
|
|
169
|
+
spec: {
|
|
170
|
+
peg: T,
|
|
171
|
+
type: ScalarConstructor
|
|
172
|
+
},
|
|
173
|
+
ctx?: Context
|
|
174
|
+
) {
|
|
175
|
+
super(spec, ctx)
|
|
176
|
+
this.type = spec.type
|
|
119
177
|
this.done = DONE
|
|
120
178
|
}
|
|
179
|
+
|
|
180
|
+
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
181
|
+
let out = (super.clone({
|
|
182
|
+
peg: this.peg,
|
|
183
|
+
type: this.type,
|
|
184
|
+
...(spec || {})
|
|
185
|
+
}, ctx) as RefVal)
|
|
186
|
+
return out
|
|
187
|
+
}
|
|
188
|
+
|
|
121
189
|
unify(peer: Val, ctx: Context): Val {
|
|
122
190
|
// Exactly equal scalars are handled in op/unite
|
|
123
191
|
if (peer instanceof ScalarTypeVal) {
|
|
124
192
|
return peer.unify(this, ctx)
|
|
125
193
|
}
|
|
194
|
+
else if (peer.top) {
|
|
195
|
+
return this
|
|
196
|
+
}
|
|
126
197
|
return Nil.make(ctx, 'scalar', this, peer)
|
|
127
198
|
}
|
|
199
|
+
|
|
128
200
|
get canon() {
|
|
129
201
|
return (this.peg as any).toString()
|
|
130
202
|
}
|
|
203
|
+
|
|
131
204
|
same(peer: Val): boolean {
|
|
132
205
|
return peer instanceof ScalarVal ? peer.peg === this.peg : super.same(peer)
|
|
133
206
|
}
|
|
@@ -139,8 +212,13 @@ class ScalarVal<T> extends ValBase {
|
|
|
139
212
|
|
|
140
213
|
|
|
141
214
|
class NumberVal extends ScalarVal<number> {
|
|
142
|
-
constructor(
|
|
143
|
-
|
|
215
|
+
constructor(
|
|
216
|
+
spec: {
|
|
217
|
+
peg: number
|
|
218
|
+
},
|
|
219
|
+
ctx?: Context
|
|
220
|
+
) {
|
|
221
|
+
super({ peg: spec.peg, type: Number }, ctx)
|
|
144
222
|
}
|
|
145
223
|
unify(peer: Val, ctx: Context): Val {
|
|
146
224
|
if (peer instanceof ScalarVal && peer.type === Integer) {
|
|
@@ -154,12 +232,17 @@ class NumberVal extends ScalarVal<number> {
|
|
|
154
232
|
|
|
155
233
|
|
|
156
234
|
class IntegerVal extends ScalarVal<number> {
|
|
157
|
-
constructor(
|
|
158
|
-
|
|
235
|
+
constructor(
|
|
236
|
+
spec: {
|
|
237
|
+
peg: number
|
|
238
|
+
},
|
|
239
|
+
ctx?: Context
|
|
240
|
+
) {
|
|
241
|
+
if (!Number.isInteger(spec.peg)) {
|
|
159
242
|
// TODO: use Nil?
|
|
160
243
|
throw new Error('not-integer')
|
|
161
244
|
}
|
|
162
|
-
super(peg, Integer, ctx)
|
|
245
|
+
super({ peg: spec.peg, type: Integer }, ctx)
|
|
163
246
|
}
|
|
164
247
|
unify(peer: Val, ctx: Context): Val {
|
|
165
248
|
if (peer instanceof ScalarTypeVal && peer.peg === Number) {
|
|
@@ -171,6 +254,7 @@ class IntegerVal extends ScalarVal<number> {
|
|
|
171
254
|
return this
|
|
172
255
|
}
|
|
173
256
|
else {
|
|
257
|
+
// console.log('IntegerVal Q', peer.canon)
|
|
174
258
|
return super.unify(peer, ctx)
|
|
175
259
|
}
|
|
176
260
|
}
|
|
@@ -178,8 +262,13 @@ class IntegerVal extends ScalarVal<number> {
|
|
|
178
262
|
|
|
179
263
|
|
|
180
264
|
class StringVal extends ScalarVal<string> {
|
|
181
|
-
constructor(
|
|
182
|
-
|
|
265
|
+
constructor(
|
|
266
|
+
spec: {
|
|
267
|
+
peg: string
|
|
268
|
+
},
|
|
269
|
+
ctx?: Context
|
|
270
|
+
) {
|
|
271
|
+
super({ peg: spec.peg, type: String }, ctx)
|
|
183
272
|
}
|
|
184
273
|
unify(peer: Val, ctx: Context): Val {
|
|
185
274
|
return super.unify(peer, ctx)
|
|
@@ -192,24 +281,26 @@ class StringVal extends ScalarVal<string> {
|
|
|
192
281
|
|
|
193
282
|
|
|
194
283
|
class BooleanVal extends ScalarVal<boolean> {
|
|
195
|
-
constructor(
|
|
196
|
-
|
|
284
|
+
constructor(
|
|
285
|
+
spec: {
|
|
286
|
+
peg: boolean
|
|
287
|
+
},
|
|
288
|
+
ctx?: Context
|
|
289
|
+
) {
|
|
290
|
+
super({ peg: spec.peg, type: Boolean }, ctx)
|
|
197
291
|
}
|
|
198
292
|
unify(peer: Val, ctx: Context): Val {
|
|
199
293
|
return super.unify(peer, ctx)
|
|
200
294
|
}
|
|
201
295
|
|
|
202
|
-
static TRUE = new BooleanVal(true, new Context({ vc: 1, root: TOP }))
|
|
203
|
-
static FALSE = new BooleanVal(false, new Context({ vc: 2, root: TOP }))
|
|
296
|
+
static TRUE = new BooleanVal({ peg: true }, new Context({ vc: 1, root: TOP }))
|
|
297
|
+
static FALSE = new BooleanVal({ peg: false }, new Context({ vc: 2, root: TOP }))
|
|
204
298
|
}
|
|
205
299
|
|
|
206
300
|
|
|
207
301
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
302
|
export {
|
|
303
|
+
TOP,
|
|
213
304
|
Integer,
|
|
214
305
|
ScalarTypeVal,
|
|
215
306
|
NumberVal,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aontu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"main": "dist/aontu.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"browser": "dist/aontu.min.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"build": "tsc -d",
|
|
28
28
|
"build-web": "tsc -d && npm run build-browser",
|
|
29
29
|
"build-browser": "cp dist/aontu.js dist/aontu.min.js && browserify -o dist/aontu.min.js -e dist/aontu.js -s Aontu -im -i assert -p tinyify",
|
|
30
|
-
"clean": "rm -rf node_modules yarn.lock package-lock.json",
|
|
30
|
+
"clean": "rm -rf dist node_modules yarn.lock package-lock.json",
|
|
31
31
|
"reset": "npm run clean && npm i && npm run build && npm test",
|
|
32
32
|
"version": "node -r fs -e \"v=require('./package.json').version;s=fs.readFileSync('./aontu.ts').toString();if(!s.includes('VERSION = \\''+v+'\\'')){s=s.replace(/VERSION = '.*?'/,'VERSION = \\''+v+'\\'');fs.writeFileSync('./aontu.ts',s)}\"",
|
|
33
33
|
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
|
|
@@ -46,19 +46,19 @@
|
|
|
46
46
|
"@jsonic/directive": "^0.11.0",
|
|
47
47
|
"@jsonic/expr": "^0.8.0",
|
|
48
48
|
"@jsonic/jsonic-next": "^2.10.0",
|
|
49
|
-
"@jsonic/multisource": "^0.
|
|
49
|
+
"@jsonic/multisource": "^1.0.1",
|
|
50
50
|
"@jsonic/path": "^0.6.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/jest": "^29.5.
|
|
53
|
+
"@types/jest": "^29.5.2",
|
|
54
54
|
"browserify": "^17.0.0",
|
|
55
|
-
"esbuild": "^0.17.
|
|
55
|
+
"esbuild": "^0.17.19",
|
|
56
56
|
"es-jest": "^2.1.0",
|
|
57
57
|
"jest": "^29.5.0",
|
|
58
|
-
"prettier": "^2.8.
|
|
58
|
+
"prettier": "^2.8.8",
|
|
59
59
|
"serve": "^14.2.0",
|
|
60
60
|
"tinyify": "^4.0.0",
|
|
61
|
-
"typescript": "^5.
|
|
62
|
-
"@types/node": "^
|
|
61
|
+
"typescript": "^5.1.3",
|
|
62
|
+
"@types/node": "^20.2.5"
|
|
63
63
|
}
|
|
64
64
|
}
|
package/dist/lib/common.d.ts
DELETED
package/dist/lib/common.js
DELETED
package/dist/lib/common.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../lib/common.ts"],"names":[],"mappings":""}
|