aontu 0.1.1 → 0.3.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 +5 -1
- package/dist/aontu.js +3 -1
- package/dist/aontu.js.map +1 -1
- package/dist/lib/lang.d.ts +1 -1
- package/dist/lib/lang.js +82 -241
- package/dist/lib/lang.js.map +1 -1
- package/dist/lib/op/op.d.ts +1 -1
- package/dist/lib/op/unite.js +8 -3
- package/dist/lib/op/unite.js.map +1 -1
- package/dist/lib/unify.d.ts +2 -1
- package/dist/lib/unify.js +3 -3
- package/dist/lib/unify.js.map +1 -1
- package/dist/lib/val.d.ts +12 -1
- package/dist/lib/val.js +88 -45
- package/dist/lib/val.js.map +1 -1
- package/lib/lang.ts +121 -278
- package/lib/op/op.ts +2 -1
- package/lib/op/unite.ts +12 -4
- package/lib/unify.ts +6 -8
- package/lib/val.ts +127 -57
- package/package.json +11 -10
package/lib/val.ts
CHANGED
|
@@ -37,9 +37,10 @@ import {
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
type ValMap = { [key: string]: Val }
|
|
40
|
+
type ValList = Val[]
|
|
40
41
|
|
|
41
|
-
const DONE = -1
|
|
42
42
|
|
|
43
|
+
const DONE = -1
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
// There can be only one.
|
|
@@ -55,21 +56,6 @@ const TOP: Val = {
|
|
|
55
56
|
|
|
56
57
|
unify(peer: Val, _ctx: Context): Val {
|
|
57
58
|
return peer
|
|
58
|
-
|
|
59
|
-
/*
|
|
60
|
-
if (peer instanceof DisjunctVal) {
|
|
61
|
-
return peer.unify(this, ctx)
|
|
62
|
-
}
|
|
63
|
-
else if (peer instanceof ConjunctVal) {
|
|
64
|
-
return peer.unify(this, ctx)
|
|
65
|
-
}
|
|
66
|
-
else if (peer instanceof RefVal) {
|
|
67
|
-
return peer.unify(this, ctx)
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
return peer
|
|
71
|
-
}
|
|
72
|
-
*/
|
|
73
59
|
},
|
|
74
60
|
|
|
75
61
|
get canon() { return 'top' },
|
|
@@ -261,6 +247,7 @@ class ScalarVal<T> extends Val {
|
|
|
261
247
|
this.done = DONE
|
|
262
248
|
}
|
|
263
249
|
unify(peer: Val, ctx: Context): Val {
|
|
250
|
+
// Exactly equal scalars are handled in op/unite
|
|
264
251
|
if (peer instanceof ScalarTypeVal) {
|
|
265
252
|
return peer.unify(this, ctx)
|
|
266
253
|
}
|
|
@@ -518,6 +505,118 @@ class MapVal extends Val {
|
|
|
518
505
|
}
|
|
519
506
|
|
|
520
507
|
|
|
508
|
+
|
|
509
|
+
class ListVal extends Val {
|
|
510
|
+
static SPREAD = Symbol('spread')
|
|
511
|
+
|
|
512
|
+
spread = {
|
|
513
|
+
cj: (undefined as Val | undefined),
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
constructor(peg: ValList, ctx?: Context) {
|
|
517
|
+
super(peg, ctx)
|
|
518
|
+
|
|
519
|
+
let spread = (this.peg as any)[ListVal.SPREAD]
|
|
520
|
+
delete (this.peg as any)[ListVal.SPREAD]
|
|
521
|
+
|
|
522
|
+
if (spread) {
|
|
523
|
+
if ('&' === spread.o) {
|
|
524
|
+
// TODO: handle existing spread!
|
|
525
|
+
this.spread.cj =
|
|
526
|
+
new ConjunctVal(Array.isArray(spread.v) ? spread.v : [spread.v], ctx)
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// NOTE: order of keys is not preserved!
|
|
532
|
+
// not possible in any case - consider {a,b} unify {b,a}
|
|
533
|
+
unify(peer: Val, ctx: Context): Val {
|
|
534
|
+
let done: boolean = true
|
|
535
|
+
let out: ListVal = TOP === peer ? this : new ListVal([], ctx)
|
|
536
|
+
|
|
537
|
+
out.spread.cj = this.spread.cj
|
|
538
|
+
|
|
539
|
+
if (peer instanceof ListVal) {
|
|
540
|
+
out.spread.cj = null == out.spread.cj ? peer.spread.cj : (
|
|
541
|
+
null == peer.spread.cj ? out.spread.cj : (
|
|
542
|
+
out.spread.cj = new ConjunctVal([out.spread.cj, peer.spread.cj], ctx)
|
|
543
|
+
)
|
|
544
|
+
)
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
out.done = this.done + 1
|
|
549
|
+
|
|
550
|
+
if (this.spread.cj) {
|
|
551
|
+
out.spread.cj =
|
|
552
|
+
DONE !== this.spread.cj.done ? unite(ctx, this.spread.cj) :
|
|
553
|
+
this.spread.cj
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
let spread_cj = out.spread.cj || TOP
|
|
557
|
+
|
|
558
|
+
// Always unify children first
|
|
559
|
+
for (let key in this.peg) {
|
|
560
|
+
out.peg[key] =
|
|
561
|
+
unite(ctx.descend(key), this.peg[key], spread_cj)
|
|
562
|
+
|
|
563
|
+
done = (done && DONE === out.peg[key].done)
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (peer instanceof ListVal) {
|
|
567
|
+
let upeer: ListVal = (unite(ctx, peer) as ListVal)
|
|
568
|
+
|
|
569
|
+
for (let peerkey in upeer.peg) {
|
|
570
|
+
let peerchild = upeer.peg[peerkey]
|
|
571
|
+
let child = out.peg[peerkey]
|
|
572
|
+
|
|
573
|
+
let oval = out.peg[peerkey] =
|
|
574
|
+
undefined === child ? peerchild :
|
|
575
|
+
child instanceof Nil ? child :
|
|
576
|
+
peerchild instanceof Nil ? peerchild :
|
|
577
|
+
unite(ctx.descend(peerkey), child, peerchild)
|
|
578
|
+
|
|
579
|
+
if (this.spread.cj) {
|
|
580
|
+
out.peg[peerkey] = unite(ctx, out.peg[peerkey], spread_cj)
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
done = (done && DONE === oval.done)
|
|
584
|
+
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
else if (TOP !== peer) {
|
|
588
|
+
return Nil.make(ctx, 'map', this, peer)
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
out.done = done ? DONE : out.done
|
|
592
|
+
return out
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
get canon() {
|
|
596
|
+
let keys = Object.keys(this.peg)
|
|
597
|
+
return '[' +
|
|
598
|
+
(this.spread.cj ? '&:' + this.spread.cj.canon +
|
|
599
|
+
(0 < keys.length ? ',' : '') : '') +
|
|
600
|
+
keys
|
|
601
|
+
// NOTE: handle array non-index key vals
|
|
602
|
+
// .map(k => [JSON.stringify(k) + ':' + this.peg[k].canon]).join(',') +
|
|
603
|
+
.map(k => [this.peg[k].canon]).join(',') +
|
|
604
|
+
']'
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
gen(ctx?: Context) {
|
|
608
|
+
let out: any = this.peg.map((v: Val) => v.gen(ctx))
|
|
609
|
+
// for (let p in this.peg) {
|
|
610
|
+
// out[p] = this.peg[p].gen(ctx)
|
|
611
|
+
// }
|
|
612
|
+
|
|
613
|
+
return out
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
521
620
|
// TODO: move main logic to op/conjunct
|
|
522
621
|
class ConjunctVal extends Val {
|
|
523
622
|
constructor(peg: Val[], ctx?: Context) {
|
|
@@ -750,23 +849,13 @@ class DisjunctVal extends Val {
|
|
|
750
849
|
class RefVal extends Val {
|
|
751
850
|
parts: string[]
|
|
752
851
|
absolute: boolean
|
|
753
|
-
sep = '.'
|
|
754
|
-
|
|
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
|
-
|
|
852
|
+
sep = '.'
|
|
762
853
|
|
|
763
854
|
constructor(peg: any[], abs?: boolean) {
|
|
764
855
|
super('')
|
|
765
856
|
this.absolute = true === abs
|
|
766
857
|
this.parts = []
|
|
767
858
|
|
|
768
|
-
// console.log('RV', peg)
|
|
769
|
-
|
|
770
859
|
for (let part of peg) {
|
|
771
860
|
this.append(part)
|
|
772
861
|
}
|
|
@@ -793,8 +882,6 @@ class RefVal extends Val {
|
|
|
793
882
|
}
|
|
794
883
|
|
|
795
884
|
this.peg = (this.absolute ? this.sep : '') + this.parts.join(this.sep)
|
|
796
|
-
|
|
797
|
-
// console.log('APPEND 1', this.parts)
|
|
798
885
|
}
|
|
799
886
|
|
|
800
887
|
unify(peer: Val, ctx: Context): Val {
|
|
@@ -805,12 +892,9 @@ class RefVal extends Val {
|
|
|
805
892
|
Nil.make(ctx, 'no-path', this, peer) : (resolved || this)
|
|
806
893
|
let out: Val
|
|
807
894
|
|
|
808
|
-
// console.log('RV', this.id, this.done, this.canon, peer.canon, !!resolved, resolved instanceof RefVal, resolved && resolved.canon)
|
|
809
|
-
|
|
810
895
|
if (resolved instanceof RefVal) {
|
|
811
896
|
if (TOP === peer) {
|
|
812
897
|
out = this
|
|
813
|
-
//out = new RefVal(this.peg, ctx)
|
|
814
898
|
}
|
|
815
899
|
else if (peer instanceof Nil) {
|
|
816
900
|
out = Nil.make(ctx, 'ref[' + this.peg + ']', this, peer)
|
|
@@ -822,9 +906,6 @@ class RefVal extends Val {
|
|
|
822
906
|
}
|
|
823
907
|
}
|
|
824
908
|
else {
|
|
825
|
-
//console.log('RVr', resolved.canon, peer.canon)
|
|
826
|
-
|
|
827
|
-
//out = resolved.unify(peer, ctx)
|
|
828
909
|
out = unite(ctx, resolved, peer)
|
|
829
910
|
}
|
|
830
911
|
|
|
@@ -833,17 +914,18 @@ class RefVal extends Val {
|
|
|
833
914
|
return out
|
|
834
915
|
}
|
|
835
916
|
|
|
917
|
+
|
|
836
918
|
get canon() {
|
|
837
919
|
return this.peg
|
|
838
920
|
}
|
|
839
921
|
|
|
922
|
+
|
|
840
923
|
gen(_ctx?: Context) {
|
|
841
924
|
return undefined
|
|
842
925
|
}
|
|
843
926
|
}
|
|
844
927
|
|
|
845
928
|
|
|
846
|
-
|
|
847
929
|
class PrefVal extends Val {
|
|
848
930
|
pref: Val
|
|
849
931
|
constructor(peg: any, pref?: any, ctx?: Context) {
|
|
@@ -852,42 +934,28 @@ class PrefVal extends Val {
|
|
|
852
934
|
}
|
|
853
935
|
|
|
854
936
|
// PrefVal unify always returns a PrefVal
|
|
855
|
-
//
|
|
937
|
+
// PrefVals can only be removed by becoming Nil in a Disjunct
|
|
856
938
|
unify(peer: Val, ctx: Context): Val {
|
|
857
939
|
let done = true
|
|
858
|
-
|
|
859
|
-
//let peer_peg = peer instanceof PrefVal ? peer.peg : peer
|
|
860
|
-
//let peer_pref = peer instanceof PrefVal ? peer.pref : peer
|
|
861
|
-
|
|
862
940
|
let out: Val
|
|
863
|
-
/*
|
|
864
|
-
= new PrefVal(
|
|
865
|
-
this.peg.unify(peer_peg, ctx),
|
|
866
|
-
this.pref.unify(peer_pref, ctx),
|
|
867
|
-
ctx
|
|
868
|
-
)
|
|
869
|
-
*/
|
|
870
941
|
|
|
871
942
|
if (peer instanceof PrefVal) {
|
|
872
943
|
out = new PrefVal(
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
unite(ctx, this.peg, peer.peg),
|
|
876
|
-
unite(ctx, this.pref, peer.pref),
|
|
944
|
+
unite(ctx, this.peg, peer.peg, 'Pref000'),
|
|
945
|
+
unite(ctx, this.pref, peer.pref, 'Pref010'),
|
|
877
946
|
ctx
|
|
878
947
|
)
|
|
948
|
+
|
|
879
949
|
}
|
|
880
950
|
else {
|
|
881
951
|
out = new PrefVal(
|
|
882
|
-
//
|
|
883
|
-
|
|
884
|
-
unite(ctx, this.
|
|
885
|
-
unite(ctx, this.pref, peer),
|
|
952
|
+
// TODO: find a better way to drop Nil non-errors
|
|
953
|
+
unite(ctx?.clone({ err: [] }), this.peg, peer, 'Pref020'),
|
|
954
|
+
unite(ctx?.clone({ err: [] }), this.pref, peer, 'Pref030'),
|
|
886
955
|
ctx
|
|
887
956
|
)
|
|
888
957
|
}
|
|
889
958
|
|
|
890
|
-
|
|
891
959
|
done = done && DONE === out.peg.done &&
|
|
892
960
|
(null != (out as PrefVal).pref ? DONE === (out as PrefVal).pref.done : true)
|
|
893
961
|
|
|
@@ -917,6 +985,7 @@ class PrefVal extends Val {
|
|
|
917
985
|
}
|
|
918
986
|
|
|
919
987
|
|
|
988
|
+
|
|
920
989
|
export {
|
|
921
990
|
DONE,
|
|
922
991
|
Integer,
|
|
@@ -929,6 +998,7 @@ export {
|
|
|
929
998
|
BooleanVal,
|
|
930
999
|
IntegerVal,
|
|
931
1000
|
MapVal,
|
|
1001
|
+
ListVal,
|
|
932
1002
|
ConjunctVal,
|
|
933
1003
|
DisjunctVal,
|
|
934
1004
|
RefVal,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aontu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"main": "dist/aontu.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"browser": "dist/aontu.min.js",
|
|
@@ -39,22 +39,23 @@
|
|
|
39
39
|
"LICENSE"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@jsonic/directive": "^0.
|
|
43
|
-
"@jsonic/expr": "^0.
|
|
44
|
-
"@jsonic/
|
|
45
|
-
"@
|
|
46
|
-
"jsonic": "
|
|
42
|
+
"@jsonic/directive": "^0.7.0",
|
|
43
|
+
"@jsonic/expr": "^0.4.1",
|
|
44
|
+
"@jsonic/jsonic-next": "2.1.0",
|
|
45
|
+
"@jsonic/multisource": "0.6.0",
|
|
46
|
+
"@jsonic/path": "^0.1.0",
|
|
47
|
+
"@types/node": "^18.0.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"@hapi/code": "^
|
|
50
|
-
"@hapi/lab": "^
|
|
50
|
+
"@hapi/code": "^9.0.1",
|
|
51
|
+
"@hapi/lab": "^25.0.1",
|
|
51
52
|
"benchmark": "^2.1.4",
|
|
52
53
|
"coveralls": "^3.1.1",
|
|
53
54
|
"hapi-lab-shim": "0.0.2",
|
|
54
55
|
"lab-transform-typescript": "^3.0.1",
|
|
55
|
-
"prettier": "^2.
|
|
56
|
+
"prettier": "^2.7.1",
|
|
56
57
|
"serve": "^13.0.2",
|
|
57
58
|
"tinyify": "^3.0.0",
|
|
58
|
-
"typescript": "^4.7.
|
|
59
|
+
"typescript": "^4.7.3"
|
|
59
60
|
}
|
|
60
61
|
}
|