aontu 0.0.8 → 0.1.2
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 +11 -12
- package/dist/aontu.d.ts +3 -3
- package/dist/aontu.js +11 -8
- package/dist/aontu.js.map +1 -1
- package/dist/aontu.min.js +63 -1
- package/dist/lib/lang.d.ts +2 -1
- package/dist/lib/lang.js +276 -212
- package/dist/lib/lang.js.map +1 -1
- package/dist/lib/op/op.d.ts +1 -1
- package/dist/lib/op/unite.js +7 -2
- package/dist/lib/op/unite.js.map +1 -1
- package/dist/lib/unify.d.ts +2 -1
- package/dist/lib/unify.js +4 -5
- package/dist/lib/unify.js.map +1 -1
- package/dist/lib/val.d.ts +4 -3
- package/dist/lib/val.js +47 -34
- package/dist/lib/val.js.map +1 -1
- package/lib/lang.ts +318 -229
- package/lib/op/op.ts +2 -1
- package/lib/op/unite.ts +11 -3
- package/lib/unify.ts +10 -32
- package/lib/val.ts +54 -32
- package/package.json +15 -12
package/lib/unify.ts
CHANGED
|
@@ -30,7 +30,6 @@ class Context {
|
|
|
30
30
|
err: Nil[] // Nil error log of current unify.
|
|
31
31
|
vc: number // Val counter to create unique val ids.
|
|
32
32
|
|
|
33
|
-
|
|
34
33
|
constructor(cfg: {
|
|
35
34
|
root: Val
|
|
36
35
|
err?: Nil[],
|
|
@@ -46,12 +45,13 @@ class Context {
|
|
|
46
45
|
|
|
47
46
|
|
|
48
47
|
clone(cfg: {
|
|
49
|
-
root
|
|
50
|
-
path?: Path
|
|
48
|
+
root?: Val,
|
|
49
|
+
path?: Path,
|
|
50
|
+
err?: Nil[],
|
|
51
51
|
}): Context {
|
|
52
52
|
return new Context({
|
|
53
|
-
root: cfg.root,
|
|
54
|
-
err: this.err,
|
|
53
|
+
root: cfg.root || this.root,
|
|
54
|
+
err: cfg.err || this.err,
|
|
55
55
|
vc: this.vc,
|
|
56
56
|
})
|
|
57
57
|
}
|
|
@@ -102,40 +102,18 @@ class Unify {
|
|
|
102
102
|
this.err = []
|
|
103
103
|
|
|
104
104
|
let res = root
|
|
105
|
-
let ctx: Context
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
while (this.dc < 111 && DONE !== res.done) {
|
|
110
|
-
ctx = new Context({
|
|
111
|
-
root: res,
|
|
112
|
-
err: this.err,
|
|
113
|
-
// map: this.map
|
|
114
|
-
})
|
|
115
|
-
res = res.unify(TOP, ctx)
|
|
116
|
-
|
|
117
|
-
// console.log('U', this.dc, this.map)
|
|
118
|
-
|
|
119
|
-
this.dc++
|
|
120
|
-
}
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
= new Context({
|
|
125
|
-
root: res,
|
|
126
|
-
err: this.err,
|
|
127
|
-
})
|
|
105
|
+
let ctx: Context = new Context({
|
|
106
|
+
root: res,
|
|
107
|
+
err: this.err,
|
|
108
|
+
})
|
|
128
109
|
|
|
129
110
|
|
|
130
111
|
// TODO: derive maxdc from res deterministically
|
|
131
112
|
// perhaps parse should count intial vals, paths, etc?
|
|
132
113
|
|
|
133
114
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
let maxdc = 111
|
|
115
|
+
let maxdc = 999
|
|
137
116
|
for (this.dc = 0; this.dc < maxdc && DONE !== res.done; this.dc++) {
|
|
138
|
-
//res = res.unify(TOP, ctx)
|
|
139
117
|
res = unite(ctx, res, TOP)
|
|
140
118
|
ctx = ctx.clone({ root: res })
|
|
141
119
|
}
|
package/lib/val.ts
CHANGED
|
@@ -41,7 +41,6 @@ type ValMap = { [key: string]: Val }
|
|
|
41
41
|
const DONE = -1
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
|
|
45
44
|
// There can be only one.
|
|
46
45
|
const TOP: Val = {
|
|
47
46
|
id: 0,
|
|
@@ -261,6 +260,7 @@ class ScalarVal<T> extends Val {
|
|
|
261
260
|
this.done = DONE
|
|
262
261
|
}
|
|
263
262
|
unify(peer: Val, ctx: Context): Val {
|
|
263
|
+
// Exactly equal scalars are handled in op/unite
|
|
264
264
|
if (peer instanceof ScalarTypeVal) {
|
|
265
265
|
return peer.unify(this, ctx)
|
|
266
266
|
}
|
|
@@ -363,6 +363,7 @@ class MapVal extends Val {
|
|
|
363
363
|
|
|
364
364
|
if (spread) {
|
|
365
365
|
if ('&' === spread.o) {
|
|
366
|
+
// TODO: handle existing spread!
|
|
366
367
|
this.spread.cj =
|
|
367
368
|
new ConjunctVal(Array.isArray(spread.v) ? spread.v : [spread.v], ctx)
|
|
368
369
|
}
|
|
@@ -500,7 +501,7 @@ class MapVal extends Val {
|
|
|
500
501
|
get canon() {
|
|
501
502
|
let keys = Object.keys(this.peg)
|
|
502
503
|
return '{' +
|
|
503
|
-
(this.spread.cj ? '
|
|
504
|
+
(this.spread.cj ? '&:' + this.spread.cj.canon +
|
|
504
505
|
(0 < keys.length ? ',' : '') : '') +
|
|
505
506
|
keys
|
|
506
507
|
.map(k => [JSON.stringify(k) + ':' + this.peg[k].canon]).join(',') +
|
|
@@ -749,23 +750,58 @@ class DisjunctVal extends Val {
|
|
|
749
750
|
class RefVal extends Val {
|
|
750
751
|
parts: string[]
|
|
751
752
|
absolute: boolean
|
|
753
|
+
sep = '.' // was '/'
|
|
752
754
|
|
|
753
|
-
constructor(peg: string, ctx?: Context) {
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
755
|
+
// constructor(peg: string | string[], ctx?: Context) {
|
|
756
|
+
// super(peg, ctx)
|
|
757
|
+
// this.parts = 'string' === typeof peg ? peg.split(this.sep) : peg
|
|
758
|
+
// this.parts = this.parts.filter(p => '' != p)
|
|
759
|
+
// // this.absolute = peg.startsWith(this.sep)
|
|
760
|
+
// }
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
constructor(peg: any[], abs?: boolean) {
|
|
764
|
+
super('')
|
|
765
|
+
this.absolute = true === abs
|
|
766
|
+
this.parts = []
|
|
767
|
+
|
|
768
|
+
// console.log('RV', peg)
|
|
769
|
+
|
|
770
|
+
for (let part of peg) {
|
|
771
|
+
this.append(part)
|
|
772
|
+
}
|
|
757
773
|
}
|
|
758
774
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
775
|
+
|
|
776
|
+
append(part: any) {
|
|
777
|
+
//console.log('APPEND 0', part)
|
|
778
|
+
|
|
779
|
+
if ('string' === typeof part) {
|
|
780
|
+
this.parts.push(part)
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
else if (part instanceof StringVal) {
|
|
784
|
+
this.parts.push(part.peg)
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
else if (part instanceof RefVal) {
|
|
788
|
+
this.parts.push(...part.parts)
|
|
789
|
+
|
|
790
|
+
if (part.absolute) {
|
|
791
|
+
this.absolute = true
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
this.peg = (this.absolute ? this.sep : '') + this.parts.join(this.sep)
|
|
796
|
+
|
|
797
|
+
// console.log('APPEND 1', this.parts)
|
|
762
798
|
}
|
|
763
799
|
|
|
764
800
|
unify(peer: Val, ctx: Context): Val {
|
|
765
801
|
let resolved: Val | undefined = null == ctx ? this : ctx.find(this)
|
|
766
802
|
|
|
767
803
|
// TODO: large amount of reruns needed? why?
|
|
768
|
-
resolved = null == resolved &&
|
|
804
|
+
resolved = null == resolved && 999 < this.done ?
|
|
769
805
|
Nil.make(ctx, 'no-path', this, peer) : (resolved || this)
|
|
770
806
|
let out: Val
|
|
771
807
|
|
|
@@ -807,7 +843,6 @@ class RefVal extends Val {
|
|
|
807
843
|
}
|
|
808
844
|
|
|
809
845
|
|
|
810
|
-
|
|
811
846
|
class PrefVal extends Val {
|
|
812
847
|
pref: Val
|
|
813
848
|
constructor(peg: any, pref?: any, ctx?: Context) {
|
|
@@ -816,42 +851,28 @@ class PrefVal extends Val {
|
|
|
816
851
|
}
|
|
817
852
|
|
|
818
853
|
// PrefVal unify always returns a PrefVal
|
|
819
|
-
//
|
|
854
|
+
// PrefVals can only be removed by becoming Nil in a Disjunct
|
|
820
855
|
unify(peer: Val, ctx: Context): Val {
|
|
821
856
|
let done = true
|
|
822
|
-
|
|
823
|
-
//let peer_peg = peer instanceof PrefVal ? peer.peg : peer
|
|
824
|
-
//let peer_pref = peer instanceof PrefVal ? peer.pref : peer
|
|
825
|
-
|
|
826
857
|
let out: Val
|
|
827
|
-
/*
|
|
828
|
-
= new PrefVal(
|
|
829
|
-
this.peg.unify(peer_peg, ctx),
|
|
830
|
-
this.pref.unify(peer_pref, ctx),
|
|
831
|
-
ctx
|
|
832
|
-
)
|
|
833
|
-
*/
|
|
834
858
|
|
|
835
859
|
if (peer instanceof PrefVal) {
|
|
836
860
|
out = new PrefVal(
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
unite(ctx, this.peg, peer.peg),
|
|
840
|
-
unite(ctx, this.pref, peer.pref),
|
|
861
|
+
unite(ctx, this.peg, peer.peg, 'Pref000'),
|
|
862
|
+
unite(ctx, this.pref, peer.pref, 'Pref010'),
|
|
841
863
|
ctx
|
|
842
864
|
)
|
|
865
|
+
|
|
843
866
|
}
|
|
844
867
|
else {
|
|
845
868
|
out = new PrefVal(
|
|
846
|
-
//
|
|
847
|
-
|
|
848
|
-
unite(ctx, this.
|
|
849
|
-
unite(ctx, this.pref, peer),
|
|
869
|
+
// TODO: find a better way to drop Nil non-errors
|
|
870
|
+
unite(ctx?.clone({ err: [] }), this.peg, peer, 'Pref020'),
|
|
871
|
+
unite(ctx?.clone({ err: [] }), this.pref, peer, 'Pref030'),
|
|
850
872
|
ctx
|
|
851
873
|
)
|
|
852
874
|
}
|
|
853
875
|
|
|
854
|
-
|
|
855
876
|
done = done && DONE === out.peg.done &&
|
|
856
877
|
(null != (out as PrefVal).pref ? DONE === (out as PrefVal).pref.done : true)
|
|
857
878
|
|
|
@@ -881,6 +902,7 @@ class PrefVal extends Val {
|
|
|
881
902
|
}
|
|
882
903
|
|
|
883
904
|
|
|
905
|
+
|
|
884
906
|
export {
|
|
885
907
|
DONE,
|
|
886
908
|
Integer,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aontu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/aontu.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"browser": "dist/aontu.min.js",
|
|
@@ -17,18 +17,19 @@
|
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"watch": "tsc -w -d",
|
|
20
|
-
"test": "lab -v -
|
|
20
|
+
"test": "lab -v -P test -t 70 --sourcemaps --transform node_modules/lab-transform-typescript -r console -o stdout -r html -o test/coverage.html",
|
|
21
21
|
"test-some": "lab -v -P test --sourcemaps --transform node_modules/lab-transform-typescript -g",
|
|
22
22
|
"test-web": "echo no-test-web",
|
|
23
23
|
"xtest-web": "browserify -o test-web/test-web.js -e test/aontu.test.js -s Aontu -im -i assert -i @hapi/lab && open test-web/index.html",
|
|
24
24
|
"coveralls": "lab -s -P test -r lcov -I URL,URLSearchParams | coveralls",
|
|
25
25
|
"prettier": "prettier --write --no-semi --single-quote *.ts test/*.js",
|
|
26
|
-
"build": "tsc -d
|
|
26
|
+
"build": "tsc -d",
|
|
27
|
+
"build-web": "tsc -d && 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",
|
|
27
28
|
"clean": "rm -rf node_modules yarn.lock package-lock.json",
|
|
28
29
|
"reset": "npm run clean && npm i && npm run build && npm test",
|
|
29
30
|
"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;",
|
|
30
31
|
"repo-publish": "npm run clean && npm i && npm run repo-publish-quick",
|
|
31
|
-
"repo-publish-quick": "npm run prettier && npm run build && npm run test && npm run test-web && npm run repo-tag && npm publish --registry
|
|
32
|
+
"repo-publish-quick": "npm run prettier && npm run build && npm run test && npm run test-web && npm run repo-tag && npm publish --registry https://registry.npmjs.org "
|
|
32
33
|
},
|
|
33
34
|
"license": "MIT",
|
|
34
35
|
"files": [
|
|
@@ -38,20 +39,22 @@
|
|
|
38
39
|
"LICENSE"
|
|
39
40
|
],
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@jsonic/
|
|
42
|
-
"@
|
|
42
|
+
"@jsonic/directive": "^0.5.0",
|
|
43
|
+
"@jsonic/expr": "^0.1.1",
|
|
44
|
+
"@jsonic/multisource": "0.4.0",
|
|
45
|
+
"@types/node": "^17.0.35",
|
|
43
46
|
"jsonic": "jsonicjs/jsonic#nextgen"
|
|
44
47
|
},
|
|
45
48
|
"devDependencies": {
|
|
46
|
-
"@hapi/code": "^8.0.
|
|
47
|
-
"@hapi/lab": "^24.
|
|
49
|
+
"@hapi/code": "^8.0.7",
|
|
50
|
+
"@hapi/lab": "^24.5.1",
|
|
48
51
|
"benchmark": "^2.1.4",
|
|
49
|
-
"coveralls": "^3.1.
|
|
52
|
+
"coveralls": "^3.1.1",
|
|
50
53
|
"hapi-lab-shim": "0.0.2",
|
|
51
54
|
"lab-transform-typescript": "^3.0.1",
|
|
52
|
-
"prettier": "^2.
|
|
53
|
-
"serve": "^
|
|
55
|
+
"prettier": "^2.6.2",
|
|
56
|
+
"serve": "^13.0.2",
|
|
54
57
|
"tinyify": "^3.0.0",
|
|
55
|
-
"typescript": "^4.
|
|
58
|
+
"typescript": "^4.7.2"
|
|
56
59
|
}
|
|
57
60
|
}
|