Comparing version 0.1.1 to 0.1.2
@@ -70,2 +70,3 @@ "use strict"; | ||
op: { | ||
// disjunct > conjunct: c & b|a -> c & (b|a) | ||
'conjunct': { | ||
@@ -75,3 +76,4 @@ infix: true, src: '&', left: 14000, right: 15000 | ||
'disjunct': { | ||
infix: true, src: '|', left: 14000, right: 15000 | ||
// infix: true, src: '|', left: 14000, right: 15000 | ||
infix: true, src: '|', left: 16000, right: 17000 | ||
}, | ||
@@ -78,0 +80,0 @@ 'dot-infix': { |
@@ -5,3 +5,3 @@ import { Context } from '../unify'; | ||
import { unite } from './unite'; | ||
declare type Operation = (ctx: Context, a?: Val, b?: Val) => Val; | ||
declare type Operation = (ctx: Context, a?: Val, b?: Val, whence?: string) => Val; | ||
export { Operation, disjunct, unite, }; |
@@ -8,5 +8,7 @@ "use strict"; | ||
// and for complex Vals, TOP, which means self unify if not yet done | ||
const unite = (ctx, a, b) => { | ||
const unite = (ctx, a, b, whence) => { | ||
let out = a; | ||
//console.log('Ua', a && a.canon, b && b.canon) | ||
// console.log('AA OP unite IN', a?.canon, b?.canon, | ||
// 'W', whence, | ||
// 'E', 0 < ctx?.err?.length ? ctx.err.map((e: Val) => e.canon) : '') | ||
if (b && (val_1.TOP === a || !a)) { | ||
@@ -34,2 +36,3 @@ //console.log('Utb', b.canon) | ||
} | ||
// Exactly equal scalars. | ||
else if (a.constructor === b.constructor && a.peg === b.peg) { | ||
@@ -48,2 +51,4 @@ out = update(a, b); | ||
} | ||
// console.log('AA OP unite OUT', a?.canon, b?.canon, '->', out && out.canon, | ||
// 0 < ctx?.err?.length ? ctx.err.map((e: Val) => e.canon) : '') | ||
return out; | ||
@@ -50,0 +55,0 @@ }; |
@@ -15,4 +15,5 @@ import { Val, RefVal, MapVal, Nil } from './val'; | ||
clone(cfg: { | ||
root: Val; | ||
root?: Val; | ||
path?: Path; | ||
err?: Nil[]; | ||
}): Context; | ||
@@ -19,0 +20,0 @@ descend(key: string): Context; |
@@ -18,4 +18,4 @@ "use strict"; | ||
return new Context({ | ||
root: cfg.root, | ||
err: this.err, | ||
root: cfg.root || this.root, | ||
err: cfg.err || this.err, | ||
vc: this.vc, | ||
@@ -64,3 +64,2 @@ }); | ||
for (this.dc = 0; this.dc < maxdc && val_1.DONE !== res.done; this.dc++) { | ||
//res = res.unify(TOP, ctx) | ||
res = (0, op_1.unite)(ctx, res, val_1.TOP); | ||
@@ -67,0 +66,0 @@ ctx = ctx.clone({ root: res }); |
@@ -176,2 +176,3 @@ "use strict"; | ||
unify(peer, ctx) { | ||
// Exactly equal scalars are handled in op/unite | ||
if (peer instanceof ScalarTypeVal) { | ||
@@ -626,26 +627,13 @@ return peer.unify(this, ctx); | ||
// PrefVal unify always returns a PrefVal | ||
// PrevVals can only be removed by becoming Nil in a Disjunct | ||
// PrefVals can only be removed by becoming Nil in a Disjunct | ||
unify(peer, ctx) { | ||
let done = true; | ||
//let peer_peg = peer instanceof PrefVal ? peer.peg : peer | ||
//let peer_pref = peer instanceof PrefVal ? peer.pref : peer | ||
let out; | ||
/* | ||
= new PrefVal( | ||
this.peg.unify(peer_peg, ctx), | ||
this.pref.unify(peer_pref, ctx), | ||
ctx | ||
) | ||
*/ | ||
if (peer instanceof PrefVal) { | ||
out = new PrefVal( | ||
//this.peg.unify(peer.peg, ctx), | ||
//this.pref.unify(peer.pref, ctx), | ||
(0, op_1.unite)(ctx, this.peg, peer.peg), (0, op_1.unite)(ctx, this.pref, peer.pref), ctx); | ||
out = new PrefVal((0, op_1.unite)(ctx, this.peg, peer.peg, 'Pref000'), (0, op_1.unite)(ctx, this.pref, peer.pref, 'Pref010'), ctx); | ||
} | ||
else { | ||
out = new PrefVal( | ||
//this.peg.unify(peer, ctx), | ||
//this.pref.unify(peer, ctx), | ||
(0, op_1.unite)(ctx, this.peg, peer), (0, op_1.unite)(ctx, this.pref, peer), ctx); | ||
// TODO: find a better way to drop Nil non-errors | ||
(0, op_1.unite)(ctx === null || ctx === void 0 ? void 0 : ctx.clone({ err: [] }), this.peg, peer, 'Pref020'), (0, op_1.unite)(ctx === null || ctx === void 0 ? void 0 : ctx.clone({ err: [] }), this.pref, peer, 'Pref030'), ctx); | ||
} | ||
@@ -652,0 +640,0 @@ done = done && DONE === out.peg.done && |
@@ -123,2 +123,3 @@ /* Copyright (c) 2021 Richard Rodger, MIT License */ | ||
op: { | ||
// disjunct > conjunct: c & b|a -> c & (b|a) | ||
'conjunct': { | ||
@@ -128,3 +129,4 @@ infix: true, src: '&', left: 14000, right: 15000 | ||
'disjunct': { | ||
infix: true, src: '|', left: 14000, right: 15000 | ||
// infix: true, src: '|', left: 14000, right: 15000 | ||
infix: true, src: '|', left: 16000, right: 17000 | ||
}, | ||
@@ -131,0 +133,0 @@ |
@@ -11,3 +11,3 @@ /* Copyright (c) 2021 Richard Rodger, MIT License. */ | ||
type Operation = (ctx: Context, a?: Val, b?: Val) => Val | ||
type Operation = (ctx: Context, a?: Val, b?: Val, whence?: string) => Val | ||
@@ -19,1 +19,2 @@ export { | ||
} | ||
@@ -8,3 +8,2 @@ /* Copyright (c) 2021 Richard Rodger, MIT License */ | ||
Val, | ||
MapVal, | ||
ConjunctVal, | ||
@@ -23,7 +22,10 @@ DisjunctVal, | ||
// and for complex Vals, TOP, which means self unify if not yet done | ||
const unite: Operation = (ctx: Context, a?: Val, b?: Val) => { | ||
const unite: Operation = (ctx: Context, a?: Val, b?: Val, whence?: string) => { | ||
let out = a | ||
//console.log('Ua', a && a.canon, b && b.canon) | ||
// console.log('AA OP unite IN', a?.canon, b?.canon, | ||
// 'W', whence, | ||
// 'E', 0 < ctx?.err?.length ? ctx.err.map((e: Val) => e.canon) : '') | ||
if (b && (TOP === a || !a)) { | ||
@@ -56,5 +58,8 @@ //console.log('Utb', b.canon) | ||
} | ||
// Exactly equal scalars. | ||
else if (a.constructor === b.constructor && a.peg === b.peg) { | ||
out = update(a, b) | ||
} | ||
else { | ||
@@ -73,2 +78,5 @@ out = a.unify(b, ctx) | ||
// console.log('AA OP unite OUT', a?.canon, b?.canon, '->', out && out.canon, | ||
// 0 < ctx?.err?.length ? ctx.err.map((e: Val) => e.canon) : '') | ||
return out | ||
@@ -75,0 +83,0 @@ } |
@@ -33,3 +33,2 @@ /* Copyright (c) 2021 Richard Rodger, MIT License */ | ||
constructor(cfg: { | ||
@@ -50,8 +49,9 @@ root: Val | ||
clone(cfg: { | ||
root: Val, | ||
path?: Path | ||
root?: Val, | ||
path?: Path, | ||
err?: Nil[], | ||
}): Context { | ||
return new Context({ | ||
root: cfg.root, | ||
err: this.err, | ||
root: cfg.root || this.root, | ||
err: cfg.err || this.err, | ||
vc: this.vc, | ||
@@ -117,7 +117,4 @@ }) | ||
let maxdc = 999 | ||
for (this.dc = 0; this.dc < maxdc && DONE !== res.done; this.dc++) { | ||
//res = res.unify(TOP, ctx) | ||
res = unite(ctx, res, TOP) | ||
@@ -124,0 +121,0 @@ ctx = ctx.clone({ root: res }) |
@@ -44,3 +44,2 @@ /* Copyright (c) 2021 Richard Rodger, MIT License */ | ||
// There can be only one. | ||
@@ -265,2 +264,3 @@ const TOP: Val = { | ||
unify(peer: Val, ctx: Context): Val { | ||
// Exactly equal scalars are handled in op/unite | ||
if (peer instanceof ScalarTypeVal) { | ||
@@ -848,3 +848,2 @@ return peer.unify(this, ctx) | ||
class PrefVal extends Val { | ||
@@ -858,33 +857,20 @@ pref: Val | ||
// PrefVal unify always returns a PrefVal | ||
// PrevVals can only be removed by becoming Nil in a Disjunct | ||
// PrefVals can only be removed by becoming Nil in a Disjunct | ||
unify(peer: Val, ctx: Context): Val { | ||
let done = true | ||
//let peer_peg = peer instanceof PrefVal ? peer.peg : peer | ||
//let peer_pref = peer instanceof PrefVal ? peer.pref : peer | ||
let out: Val | ||
/* | ||
= new PrefVal( | ||
this.peg.unify(peer_peg, ctx), | ||
this.pref.unify(peer_pref, ctx), | ||
ctx | ||
) | ||
*/ | ||
if (peer instanceof PrefVal) { | ||
out = new PrefVal( | ||
//this.peg.unify(peer.peg, ctx), | ||
//this.pref.unify(peer.pref, ctx), | ||
unite(ctx, this.peg, peer.peg), | ||
unite(ctx, this.pref, peer.pref), | ||
unite(ctx, this.peg, peer.peg, 'Pref000'), | ||
unite(ctx, this.pref, peer.pref, 'Pref010'), | ||
ctx | ||
) | ||
} | ||
else { | ||
out = new PrefVal( | ||
//this.peg.unify(peer, ctx), | ||
//this.pref.unify(peer, ctx), | ||
unite(ctx, this.peg, peer), | ||
unite(ctx, this.pref, peer), | ||
// TODO: find a better way to drop Nil non-errors | ||
unite(ctx?.clone({ err: [] }), this.peg, peer, 'Pref020'), | ||
unite(ctx?.clone({ err: [] }), this.pref, peer, 'Pref030'), | ||
ctx | ||
@@ -894,3 +880,2 @@ ) | ||
done = done && DONE === out.peg.done && | ||
@@ -925,2 +910,3 @@ (null != (out as PrefVal).pref ? DONE === (out as PrefVal).pref.done : true) | ||
export { | ||
@@ -927,0 +913,0 @@ DONE, |
{ | ||
"name": "aontu", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "dist/aontu.js", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
131654
3018