aontu 0.0.9 → 0.2.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/lib/op/unite.ts CHANGED
@@ -5,7 +5,6 @@
5
5
  import { Context } from '../unify'
6
6
  import {
7
7
  Val,
8
- MapVal,
9
8
  ConjunctVal,
10
9
  DisjunctVal,
11
10
  RefVal,
@@ -19,10 +18,13 @@ import { Operation } from './op'
19
18
 
20
19
  // Vals should only have to unify downwards (in .unify) over Vals they understand.
21
20
  // and for complex Vals, TOP, which means self unify if not yet done
22
- const unite: Operation = (ctx: Context, a?: Val, b?: Val) => {
21
+ const unite: Operation = (ctx: Context, a?: Val, b?: Val, whence?: string) => {
23
22
  let out = a
24
23
 
25
- //console.log('Ua', a && a.canon, b && b.canon)
24
+ // console.log('AA OP unite IN', a?.canon, b?.canon,
25
+ // 'W', whence,
26
+ // 'E', 0 < ctx?.err?.length ? ctx.err.map((e: Val) => e.canon) : '')
27
+
26
28
 
27
29
  if (b && (TOP === a || !a)) {
28
30
  //console.log('Utb', b.canon)
@@ -51,9 +53,12 @@ const unite: Operation = (ctx: Context, a?: Val, b?: Val) => {
51
53
  //console.log('U', a.canon, b.canon)
52
54
  return b.unify(a, ctx)
53
55
  }
56
+
57
+ // Exactly equal scalars.
54
58
  else if (a.constructor === b.constructor && a.peg === b.peg) {
55
59
  out = update(a, b)
56
60
  }
61
+
57
62
  else {
58
63
  out = a.unify(b, ctx)
59
64
  }
@@ -67,6 +72,9 @@ const unite: Operation = (ctx: Context, a?: Val, b?: Val) => {
67
72
  out = out.unify(TOP, ctx)
68
73
  }
69
74
 
75
+ // console.log('AA OP unite OUT', a?.canon, b?.canon, '->', out && out.canon,
76
+ // 0 < ctx?.err?.length ? ctx.err.map((e: Val) => e.canon) : '')
77
+
70
78
  return out
71
79
  }
72
80
 
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: Val,
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
  }
@@ -112,11 +112,8 @@ class Unify {
112
112
  // perhaps parse should count intial vals, paths, etc?
113
113
 
114
114
 
115
-
116
-
117
115
  let maxdc = 999
118
116
  for (this.dc = 0; this.dc < maxdc && DONE !== res.done; this.dc++) {
119
- //res = res.unify(TOP, ctx)
120
117
  res = unite(ctx, res, TOP)
121
118
  ctx = ctx.clone({ root: res })
122
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 ? '&=' + this.spread.cj.canon +
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,16 +750,51 @@ 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
- super(peg, ctx)
755
- this.parts = peg.split('/').filter(p => '' != p)
756
- this.absolute = peg.startsWith('/')
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
- append(part: string) {
760
- this.parts.push(part)
761
- this.peg = (this.absolute ? '/' : '') + this.parts.join('/')
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 {
@@ -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
- // PrevVals can only be removed by becoming Nil in a Disjunct
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
- //this.peg.unify(peer.peg, ctx),
838
- //this.pref.unify(peer.pref, ctx),
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
- //this.peg.unify(peer, ctx),
847
- //this.pref.unify(peer, ctx),
848
- unite(ctx, this.peg, peer),
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.0.9",
3
+ "version": "0.2.0",
4
4
  "main": "dist/aontu.js",
5
5
  "type": "commonjs",
6
6
  "browser": "dist/aontu.min.js",
@@ -23,12 +23,13 @@
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 && 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",
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 http://registry.npmjs.org "
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/multisource": "0.0.8",
42
- "@types/node": "^16.3.1",
43
- "jsonic": "jsonicjs/jsonic#4edd639987b75ef62a74e3904fb890f59d21379c"
42
+ "@jsonic/directive": "^0.6.0",
43
+ "@jsonic/expr": "^0.2.0",
44
+ "@jsonic/multisource": "0.5.0",
45
+ "@types/node": "^17.0.35",
46
+ "@jsonic/jsonic-next": "2.0.1"
44
47
  },
45
48
  "devDependencies": {
46
- "@hapi/code": "^8.0.3",
47
- "@hapi/lab": "^24.3.0",
49
+ "@hapi/code": "^9.0.0",
50
+ "@hapi/lab": "^25.0.1",
48
51
  "benchmark": "^2.1.4",
49
52
  "coveralls": "^3.1.1",
50
53
  "hapi-lab-shim": "0.0.2",
51
54
  "lab-transform-typescript": "^3.0.1",
52
- "prettier": "^2.3.2",
53
- "serve": "^12.0.0",
55
+ "prettier": "^2.6.2",
56
+ "serve": "^13.0.2",
54
57
  "tinyify": "^3.0.0",
55
- "typescript": "^4.3.5"
58
+ "typescript": "^4.7.2"
56
59
  }
57
60
  }