aontu 0.2.0 → 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.js +77 -238
- package/dist/lib/lang.js.map +1 -1
- package/dist/lib/op/unite.js +1 -1
- package/dist/lib/op/unite.js.map +1 -1
- package/dist/lib/unify.js +1 -0
- package/dist/lib/unify.js.map +1 -1
- package/dist/lib/val.d.ts +12 -1
- package/dist/lib/val.js +83 -28
- package/dist/lib/val.js.map +1 -1
- package/lib/lang.ts +117 -276
- package/lib/op/unite.ts +1 -1
- package/lib/unify.ts +1 -0
- package/lib/val.ts +118 -34
- package/package.json +10 -9
package/lib/val.ts
CHANGED
|
@@ -37,6 +37,8 @@ import {
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
type ValMap = { [key: string]: Val }
|
|
40
|
+
type ValList = Val[]
|
|
41
|
+
|
|
40
42
|
|
|
41
43
|
const DONE = -1
|
|
42
44
|
|
|
@@ -54,21 +56,6 @@ const TOP: Val = {
|
|
|
54
56
|
|
|
55
57
|
unify(peer: Val, _ctx: Context): Val {
|
|
56
58
|
return peer
|
|
57
|
-
|
|
58
|
-
/*
|
|
59
|
-
if (peer instanceof DisjunctVal) {
|
|
60
|
-
return peer.unify(this, ctx)
|
|
61
|
-
}
|
|
62
|
-
else if (peer instanceof ConjunctVal) {
|
|
63
|
-
return peer.unify(this, ctx)
|
|
64
|
-
}
|
|
65
|
-
else if (peer instanceof RefVal) {
|
|
66
|
-
return peer.unify(this, ctx)
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
return peer
|
|
70
|
-
}
|
|
71
|
-
*/
|
|
72
59
|
},
|
|
73
60
|
|
|
74
61
|
get canon() { return 'top' },
|
|
@@ -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,10 +914,12 @@ 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
|
}
|
|
@@ -915,6 +998,7 @@ export {
|
|
|
915
998
|
BooleanVal,
|
|
916
999
|
IntegerVal,
|
|
917
1000
|
MapVal,
|
|
1001
|
+
ListVal,
|
|
918
1002
|
ConjunctVal,
|
|
919
1003
|
DisjunctVal,
|
|
920
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": "^9.0.
|
|
50
|
+
"@hapi/code": "^9.0.1",
|
|
50
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
|
}
|