aontu 0.30.2 → 0.31.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/dist/ctx.d.ts +2 -2
- package/dist/ctx.js +2 -2
- package/dist/ctx.js.map +1 -1
- package/dist/hints.js +7 -1
- package/dist/hints.js.map +1 -1
- package/dist/unify.js +12 -6
- package/dist/unify.js.map +1 -1
- package/dist/utility.js +13 -7
- package/dist/utility.js.map +1 -1
- package/dist/val/ConjunctVal.js +4 -4
- package/dist/val/ConjunctVal.js.map +1 -1
- package/dist/val/CopyFuncVal.d.ts +2 -1
- package/dist/val/CopyFuncVal.js +14 -6
- package/dist/val/CopyFuncVal.js.map +1 -1
- package/dist/val/FuncBaseVal.d.ts +2 -2
- package/dist/val/FuncBaseVal.js +22 -18
- package/dist/val/FuncBaseVal.js.map +1 -1
- package/dist/val/JunctionVal.js +2 -2
- package/dist/val/JunctionVal.js.map +1 -1
- package/dist/val/KeyFuncVal.d.ts +1 -0
- package/dist/val/KeyFuncVal.js +36 -6
- package/dist/val/KeyFuncVal.js.map +1 -1
- package/dist/val/MapVal.d.ts +1 -1
- package/dist/val/MapVal.js +27 -5
- package/dist/val/MapVal.js.map +1 -1
- package/dist/val/MoveFuncVal.d.ts +1 -0
- package/dist/val/MoveFuncVal.js +11 -8
- package/dist/val/MoveFuncVal.js.map +1 -1
- package/dist/val/PrefVal.js +19 -11
- package/dist/val/PrefVal.js.map +1 -1
- package/dist/val/RefVal.js +50 -16
- package/dist/val/RefVal.js.map +1 -1
- package/dist/val/ScalarVal.js +1 -0
- package/dist/val/ScalarVal.js.map +1 -1
- package/dist/val/TopVal.d.ts +1 -1
- package/dist/val/TopVal.js +2 -2
- package/dist/val/TopVal.js.map +1 -1
- package/dist/val/Val.d.ts +3 -2
- package/dist/val/Val.js +37 -18
- package/dist/val/Val.js.map +1 -1
- package/package.json +1 -1
- package/src/ctx.ts +4 -4
- package/src/hints.ts +11 -1
- package/src/unify.ts +15 -7
- package/src/utility.ts +15 -9
- package/src/val/ConjunctVal.ts +5 -5
- package/src/val/CopyFuncVal.ts +20 -7
- package/src/val/FuncBaseVal.ts +30 -24
- package/src/val/JunctionVal.ts +2 -2
- package/src/val/KeyFuncVal.ts +42 -6
- package/src/val/MapVal.ts +39 -6
- package/src/val/MoveFuncVal.ts +12 -8
- package/src/val/PrefVal.ts +25 -14
- package/src/val/RefVal.ts +69 -17
- package/src/val/ScalarVal.ts +2 -0
- package/src/val/TopVal.ts +2 -2
- package/src/val/Val.ts +42 -18
package/dist/val/Val.js
CHANGED
|
@@ -17,8 +17,6 @@ exports.SPREAD = exports.DONE = exports.Val = void 0;
|
|
|
17
17
|
exports.empty = empty;
|
|
18
18
|
const node_util_1 = require("node:util");
|
|
19
19
|
const site_1 = require("../site");
|
|
20
|
-
// import { AontuError, descErr, makeNilErr } from '../err'
|
|
21
|
-
// import { AontuError } from '../err'
|
|
22
20
|
const DONE = -1;
|
|
23
21
|
exports.DONE = DONE;
|
|
24
22
|
const SPREAD = Symbol('spread');
|
|
@@ -99,11 +97,15 @@ class Val {
|
|
|
99
97
|
}
|
|
100
98
|
clone(ctx, spec) {
|
|
101
99
|
let cloneCtx;
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
let path = spec?.path;
|
|
101
|
+
if (null == path) {
|
|
102
|
+
let cut = this.path.indexOf('&');
|
|
103
|
+
cut = -1 < cut ? cut + 1 : ctx.path.length;
|
|
104
|
+
path = ctx.path.concat(this.path.slice(cut));
|
|
105
|
+
}
|
|
106
|
+
// console.log('CLONE', path, this.canon)
|
|
107
|
+
// console.trace()
|
|
108
|
+
cloneCtx = ctx.clone({ path });
|
|
107
109
|
let fullspec = {
|
|
108
110
|
peg: this.peg,
|
|
109
111
|
mark: { type: this.mark.type, hide: this.mark.hide },
|
|
@@ -111,10 +113,11 @@ class Val {
|
|
|
111
113
|
};
|
|
112
114
|
let out = new this
|
|
113
115
|
.constructor(fullspec, cloneCtx);
|
|
116
|
+
out.dc = this.done ? DONE : out.dc;
|
|
114
117
|
out.site.row = spec?.row ?? this.site.row ?? -1;
|
|
115
118
|
out.site.col = spec?.col ?? this.site.col ?? -1;
|
|
116
119
|
out.site.url = spec?.url ?? this.site.url ?? '';
|
|
117
|
-
|
|
120
|
+
out.mark = Object.assign({}, this.mark, fullspec.mark ?? {});
|
|
118
121
|
out.mark.type = this.mark.type && (fullspec.mark?.type ?? true);
|
|
119
122
|
out.mark.hide = this.mark.hide && (fullspec.mark?.hide ?? true);
|
|
120
123
|
return out;
|
|
@@ -139,44 +142,60 @@ class Val {
|
|
|
139
142
|
notdone() {
|
|
140
143
|
this.dc = DONE === this.dc ? DONE : this.dc + 1;
|
|
141
144
|
}
|
|
142
|
-
[(_Val_ctx = new WeakMap(), node_util_1.inspect.custom)](
|
|
145
|
+
[(_Val_ctx = new WeakMap(), node_util_1.inspect.custom)](d, _opts, _inspect) {
|
|
146
|
+
return this.inspect(d);
|
|
147
|
+
}
|
|
148
|
+
inspect(d) {
|
|
149
|
+
d = null == d ? -1 : d;
|
|
143
150
|
let s = ['<' + this.constructor.name.replace(/Val$/, '') + '/' + this.id];
|
|
144
151
|
s.push('/' + this.path.join('.') + '/');
|
|
145
152
|
s.push([
|
|
146
153
|
DONE === this.dc ? 'D' : 'd' + this.dc,
|
|
147
154
|
...Object.entries(this.mark).filter(n => n[1]).map(n => n[0]).sort()
|
|
148
155
|
].filter(n => null != n).join(','));
|
|
149
|
-
let insp = this.inspection(
|
|
156
|
+
// let insp = this.inspection(inspect)
|
|
157
|
+
let insp = this.inspection(1 + d);
|
|
150
158
|
if (null != insp && '' != insp) {
|
|
151
159
|
s.push('/' + insp);
|
|
152
160
|
}
|
|
153
161
|
s.push('/');
|
|
154
|
-
if (
|
|
155
|
-
s.push(
|
|
162
|
+
if (this.peg?.isVal) {
|
|
163
|
+
s.push(this.peg.inspect(1 + d));
|
|
164
|
+
}
|
|
165
|
+
else if (null != this.peg && 'object' === typeof this.peg &&
|
|
166
|
+
Object.entries(this.peg)[0]?.[1]?.isVal) {
|
|
167
|
+
s.push(inspectpeg(this.peg, 1 + d));
|
|
156
168
|
}
|
|
157
169
|
else if ('function' === typeof this.peg) {
|
|
158
170
|
s.push(this.peg.name);
|
|
159
171
|
}
|
|
160
172
|
else {
|
|
161
|
-
s.push(this.peg);
|
|
173
|
+
s.push(this.peg?.toString?.() ?? '');
|
|
162
174
|
}
|
|
163
175
|
s.push('>');
|
|
164
176
|
const out = s.join('');
|
|
165
177
|
return out;
|
|
166
178
|
}
|
|
167
|
-
inspection(
|
|
179
|
+
inspection(_d) {
|
|
168
180
|
return '';
|
|
169
181
|
}
|
|
170
182
|
}
|
|
171
183
|
exports.Val = Val;
|
|
172
|
-
function inspectpeg(peg) {
|
|
173
|
-
|
|
174
|
-
|
|
184
|
+
function inspectpeg(peg, d) {
|
|
185
|
+
const indent = ' '.repeat(d);
|
|
186
|
+
return pretty(Array.isArray(peg) ?
|
|
187
|
+
('[' + peg.map(n => '\n ' + indent + (n.inspect?.(d) ?? n)).join(',') +
|
|
188
|
+
'\n' + indent + ']') :
|
|
189
|
+
('{' +
|
|
190
|
+
Object.entries(peg).map((n) => '\n ' + indent + n[0] + ': ' + // n[1].inspect(d)
|
|
191
|
+
(n[1].inspect(d) ?? '' + n[1])).join(',') +
|
|
192
|
+
'\n' + indent + '}'));
|
|
175
193
|
}
|
|
176
194
|
function pretty(s) {
|
|
177
195
|
return ((String(s))
|
|
178
196
|
.replace(/\[Object: null prototype\]/g, '')
|
|
179
|
-
|
|
197
|
+
// .replace(/([^\n]) +/g, '$1')
|
|
198
|
+
);
|
|
180
199
|
}
|
|
181
200
|
function empty(o) {
|
|
182
201
|
return ((Array.isArray(o) && 0 === o.length)
|
package/dist/val/Val.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Val.js","sourceRoot":"","sources":["../../src/val/Val.ts"],"names":[],"mappings":";AAA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AAC;YACX,IAAI,GAAG,MAAM,GAAG,GAAG,CAAC,CACvB,CAAA;AACH,CAAC;AAED,SAAS,MAAM,CAAC,CAAS;IACvB,OAAO,CACL,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;SACR,OAAO,CAAC,6BAA6B,EAAE,EAAE,CAAC;IAC7C,+BAA+B;KAChC,CAAA;AACH,CAAC;AAGD,SAAS,KAAK,CAAC,CAAM;IACnB,OAAO,CACL,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;WACjC,CAAC,IAAI,IAAI,CAAC,IAAI,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;WACnE,KAAK,CACT,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
package/src/ctx.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
type AontuContextConfig = {
|
|
21
21
|
cc?: number
|
|
22
22
|
err?: any[] // Omit<NilVal[], "push">
|
|
23
|
-
explain?: any[]
|
|
23
|
+
explain?: any[] | boolean | null
|
|
24
24
|
fs?: any
|
|
25
25
|
path?: string[]
|
|
26
26
|
root?: Val
|
|
@@ -71,7 +71,7 @@ class AontuContext {
|
|
|
71
71
|
this.collect = cfg.collect ?? null != cfg.err
|
|
72
72
|
|
|
73
73
|
this.err = cfg.err ?? []
|
|
74
|
-
this.explain = cfg.explain
|
|
74
|
+
this.explain = Array.isArray(cfg.explain) ? cfg.explain : null
|
|
75
75
|
|
|
76
76
|
this.fs = cfg.fs ?? null
|
|
77
77
|
|
|
@@ -97,7 +97,7 @@ class AontuContext {
|
|
|
97
97
|
root?: Val,
|
|
98
98
|
path?: string[],
|
|
99
99
|
err?: any[],
|
|
100
|
-
explain?: any[]
|
|
100
|
+
explain?: any[] | boolean | null
|
|
101
101
|
}): AontuContext {
|
|
102
102
|
const ctx = Object.create(this)
|
|
103
103
|
ctx.path = cfg.path ?? this.path
|
|
@@ -105,7 +105,7 @@ class AontuContext {
|
|
|
105
105
|
ctx.var = Object.create(this.vars)
|
|
106
106
|
|
|
107
107
|
ctx.err = cfg.err ?? ctx.err
|
|
108
|
-
ctx.explain = cfg.explain
|
|
108
|
+
ctx.explain = Array.isArray(cfg.explain) ? cfg.explain : ctx.explain
|
|
109
109
|
|
|
110
110
|
ctx._pathstr = undefined
|
|
111
111
|
|
package/src/hints.ts
CHANGED
|
@@ -53,6 +53,16 @@ const hints: Record<string, string> = {
|
|
|
53
53
|
literal_nil:
|
|
54
54
|
'A literal nil cannot unify with any other value.',
|
|
55
55
|
|
|
56
|
+
unify_cycle: 'Circular reference detected during unification.',
|
|
57
|
+
|
|
58
|
+
conjunct:
|
|
59
|
+
'This conjunction (& operator) could not be completed as some terms\n' +
|
|
60
|
+
'could not be resolved.',
|
|
61
|
+
|
|
62
|
+
no_path: 'The path reference could not be found.' +
|
|
63
|
+
'\n \nExamples:\n' +
|
|
64
|
+
' a:1 b:$.a -> a:1,b:1 # $.a is a valid path reference as a is a key of root ($).\n' +
|
|
65
|
+
' a:$.b -> nil # $.b is not a valid path reference as there is no key b in root ($).\n',
|
|
56
66
|
|
|
57
67
|
// Parsing errors
|
|
58
68
|
'parse_bad_src': 'Invalid source provided for parsing. The source must be a non-empty string.',
|
|
@@ -61,7 +71,7 @@ const hints: Record<string, string> = {
|
|
|
61
71
|
'unify_no_src': 'No source provided for unification. Cannot unify without source values.',
|
|
62
72
|
'unify_no_res': 'Unification produced no result. The values could not be unified.',
|
|
63
73
|
'unite': 'Failed to unite two values. The values are incompatible and cannot be unified.',
|
|
64
|
-
|
|
74
|
+
|
|
65
75
|
'internal': 'Internal error during unification. This indicates an unexpected error in the unification process.',
|
|
66
76
|
|
|
67
77
|
// Type mismatch errors
|
package/src/unify.ts
CHANGED
|
@@ -39,22 +39,24 @@ const unite = (ctx: AontuContext, a: any, b: any, whence: string) => {
|
|
|
39
39
|
let out = a
|
|
40
40
|
let why = 'u'
|
|
41
41
|
|
|
42
|
-
// const saw = a?.isTop && b?.isTop ? '' :
|
|
43
|
-
// (a ? a.id + (a.done ? '' : '*') : '') + '~' + (b ? b.id + (b.done ? '' : '*') : '')
|
|
44
|
-
|
|
45
42
|
const saw =
|
|
46
43
|
(a ? a.id + (a.done ? '' : '*') : '') + '~' + (b ? b.id + (b.done ? '' : '*') : '') +
|
|
47
44
|
'@' + ctx.pathstr
|
|
48
45
|
|
|
46
|
+
|
|
49
47
|
/*
|
|
50
|
-
if (
|
|
48
|
+
if (1 < ctx.seen[saw]) {
|
|
51
49
|
console.log('UNITE-SAW', ctx.cc, saw, ctx.seen[saw], 1 < ctx.seen[saw] ? (a?.canon + ' ~ ' + b?.canon) : '')
|
|
52
|
-
console.trace()
|
|
50
|
+
// console.trace()
|
|
51
|
+
// process.exit()
|
|
53
52
|
}
|
|
54
53
|
*/
|
|
55
54
|
|
|
55
|
+
// NOTE: if this error occurs "unreasonably", attemp to avoid unnecesary unification
|
|
56
|
+
// See for example PrefVal peg.id equality inspection.
|
|
56
57
|
if (MAXCYCLE < ctx.seen[saw]) {
|
|
57
|
-
|
|
58
|
+
// console.log('SAW', ctx.seen[saw], saw, a?.id, a?.canon, b?.id, b?.canon, ctx.cc)
|
|
59
|
+
out = makeNilErr(ctx, 'unify_cycle', a, b)
|
|
58
60
|
}
|
|
59
61
|
else {
|
|
60
62
|
ctx.seen[saw] = 1 + (ctx.seen[saw] ?? 0)
|
|
@@ -118,15 +120,21 @@ const unite = (ctx: AontuContext, a: any, b: any, whence: string) => {
|
|
|
118
120
|
why += 'N'
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
|
|
123
|
+
// console.log('UNITE-DONE', out.id, out.canon, out.done)
|
|
124
|
+
|
|
125
|
+
// if (DONE !== out.dc && !unified) {
|
|
126
|
+
if (!out.done && !unified) {
|
|
122
127
|
let nout = out.unify(top(), ctx.clone({ explain: ec(te, 'ND') }))
|
|
123
128
|
out = nout
|
|
124
129
|
why += 'T'
|
|
125
130
|
}
|
|
126
131
|
|
|
132
|
+
// console.log('UNITE', why, a?.id, a?.canon, a?.done, b?.id, b?.canon, b?.done, '->', out?.id, out?.canon, out?.done)
|
|
133
|
+
|
|
127
134
|
uc++
|
|
128
135
|
}
|
|
129
136
|
catch (err: any) {
|
|
137
|
+
// console.log(err)
|
|
130
138
|
// TODO: handle unexpected
|
|
131
139
|
out = makeNilErr(ctx, 'internal', a, b)
|
|
132
140
|
}
|
package/src/utility.ts
CHANGED
|
@@ -73,14 +73,18 @@ function walk(
|
|
|
73
73
|
if (null != child && !child.isVal) {
|
|
74
74
|
if ('object' === typeof child) {
|
|
75
75
|
for (let ckey in child) {
|
|
76
|
-
child[ckey]
|
|
77
|
-
child[ckey]
|
|
76
|
+
if (child[ckey] && child[ckey].isVal) {
|
|
77
|
+
child[ckey] = walk(
|
|
78
|
+
child[ckey], before, after, maxdepth, ckey, out, [...(path || []), ckey])
|
|
79
|
+
}
|
|
78
80
|
}
|
|
79
81
|
}
|
|
80
82
|
else if (Array.isArray(child)) {
|
|
81
83
|
for (let i = 0; i < child.length; i++) {
|
|
82
|
-
child[i]
|
|
83
|
-
child[i]
|
|
84
|
+
if (child[i] && child[i].isVal) {
|
|
85
|
+
child[i] = walk(
|
|
86
|
+
child[i], before, after, maxdepth, i, out, [...(path || []), '' + i])
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
89
|
}
|
|
86
90
|
}
|
|
@@ -93,10 +97,11 @@ function walk(
|
|
|
93
97
|
|
|
94
98
|
const T_NOTE = 0
|
|
95
99
|
const T_WHY = 1
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
+
const T_PATH = 2
|
|
101
|
+
const T_AVAL = 3
|
|
102
|
+
const T_BVAL = 4
|
|
103
|
+
const T_OVAL = 5
|
|
104
|
+
const T_CHILDREN = 6
|
|
100
105
|
|
|
101
106
|
|
|
102
107
|
function explainOpen(
|
|
@@ -111,6 +116,7 @@ function explainOpen(
|
|
|
111
116
|
t = t ?? [null, 'root', null, null, null, null]
|
|
112
117
|
t[T_WHY] = t[T_WHY] ?? ''
|
|
113
118
|
t[T_NOTE] = (0 <= ctx.cc ? ctx.cc + '~' : '') + note
|
|
119
|
+
t[T_PATH] = ['$', ctx.path.join('.')].filter(p => '' != p).join('.') + ' '
|
|
114
120
|
if (ac) {
|
|
115
121
|
t[T_AVAL] = ac.id + (ac.done ? '' : '!') + '=' + ac.canon
|
|
116
122
|
}
|
|
@@ -136,7 +142,7 @@ function explainClose(t: any[] | undefined | null, out?: Val) {
|
|
|
136
142
|
if (null == t) return;
|
|
137
143
|
|
|
138
144
|
if (out) {
|
|
139
|
-
t[T_OVAL] = out.id + (out.done ? '' : '!') + '=' + out.canon
|
|
145
|
+
t[T_OVAL] = '-> ' + out.id + (out.done ? '' : '!') + '=' + out.canon
|
|
140
146
|
}
|
|
141
147
|
}
|
|
142
148
|
|
package/src/val/ConjunctVal.ts
CHANGED
|
@@ -84,6 +84,7 @@ class ConjunctVal extends JunctionVal {
|
|
|
84
84
|
|
|
85
85
|
this.peg = norm(this.peg)
|
|
86
86
|
|
|
87
|
+
// console.log('\nCONJUNCT', ctx.cc, this.id, this.canon, peer.id, peer.canon)
|
|
87
88
|
|
|
88
89
|
// Unify each term of conjunct against peer
|
|
89
90
|
let upeer: Val[] = []
|
|
@@ -92,6 +93,7 @@ class ConjunctVal extends JunctionVal {
|
|
|
92
93
|
let newhide = this.mark.hide || peer.mark.hide
|
|
93
94
|
|
|
94
95
|
for (let vI = 0; vI < this.peg.length; vI++) {
|
|
96
|
+
// console.log('CONJUNCT-peg', vI, this.peg[vI].canon, this.peg[vI].mark)
|
|
95
97
|
newtype = this.peg[vI].mark.type || newtype
|
|
96
98
|
newhide = this.peg[vI].mark.hide || newhide
|
|
97
99
|
}
|
|
@@ -103,6 +105,7 @@ class ConjunctVal extends JunctionVal {
|
|
|
103
105
|
|
|
104
106
|
upeer[vI] = (this.peg[vI].done && peer.isTop) ? this.peg[vI] :
|
|
105
107
|
unite(ctx.clone({ explain: ec(te, 'OWN') }), this.peg[vI], peer, 'cj-own')
|
|
108
|
+
|
|
106
109
|
upeer[vI].mark.type = newtype = newtype || upeer[vI].mark.type
|
|
107
110
|
upeer[vI].mark.hide = newhide = newhide || upeer[vI].mark.hide
|
|
108
111
|
|
|
@@ -135,7 +138,7 @@ class ConjunctVal extends JunctionVal {
|
|
|
135
138
|
for (let pI = 0; pI < upeer.length; pI++) {
|
|
136
139
|
let t1 = upeer[pI + 1]
|
|
137
140
|
|
|
138
|
-
// console.log('CONJUNCT-TERMS-C', this.id, pI, t0, t1, 'OV=', outvals.map((v: Val) => v))
|
|
141
|
+
// console.log('CONJUNCT-TERMS-C', ctx.cc, this.id, pI, t0.id, t0.canon, t1?.id, t1?.canon, 'OV=', outvals.map((v: Val) => v.canon))
|
|
139
142
|
|
|
140
143
|
if (null == t1) {
|
|
141
144
|
outvals.push(t0)
|
|
@@ -158,6 +161,7 @@ class ConjunctVal extends JunctionVal {
|
|
|
158
161
|
|
|
159
162
|
else {
|
|
160
163
|
val = unite(ctx.clone({ explain: ec(te, 'DEF') }), t0, t1, 'cj-peer-t0t1')
|
|
164
|
+
// console.log('CONJUNCT-T', t0.canon, t1?.canon, '->', val.canon)
|
|
161
165
|
done = done && DONE === val.dc
|
|
162
166
|
newtype = this.mark.type || val.mark.type
|
|
163
167
|
newhide = this.mark.hide || val.mark.hide
|
|
@@ -173,10 +177,6 @@ class ConjunctVal extends JunctionVal {
|
|
|
173
177
|
else {
|
|
174
178
|
t0 = val
|
|
175
179
|
}
|
|
176
|
-
// TODO: t0 should become this to avoid unnecessary repasses
|
|
177
|
-
// outvals.push(val)
|
|
178
|
-
|
|
179
|
-
// pI++
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
package/src/val/CopyFuncVal.ts
CHANGED
|
@@ -43,21 +43,34 @@ class CopyFuncVal extends FuncBaseVal {
|
|
|
43
43
|
return new CopyFuncVal(spec)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
|
|
46
47
|
funcname() {
|
|
47
48
|
return 'copy'
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
prepare(_ctx: AontuContext, _args: Val[]) {
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
resolve(ctx: AontuContext, args: Val[]) {
|
|
51
57
|
const val = args?.[0]
|
|
52
58
|
const out = null == val || null == ctx ?
|
|
53
59
|
makeNilErr(ctx, 'invalid-arg', this) :
|
|
54
|
-
val.clone(ctx
|
|
60
|
+
val.clone(ctx)
|
|
61
|
+
|
|
62
|
+
// console.log('CR', out)
|
|
63
|
+
|
|
64
|
+
if (!out.isRef) {
|
|
65
|
+
walk(out, (_key: string | number | undefined, val: Val) => {
|
|
66
|
+
// console.log('WALK', val)
|
|
67
|
+
val.mark.type = false
|
|
68
|
+
val.mark.hide = false
|
|
69
|
+
return val
|
|
70
|
+
})
|
|
71
|
+
}
|
|
55
72
|
|
|
56
|
-
|
|
57
|
-
val.mark.type = false
|
|
58
|
-
val.mark.hide = false
|
|
59
|
-
return val
|
|
60
|
-
})
|
|
73
|
+
// console.log('COPY-RESOLVE', ctx.cc, val, out)
|
|
61
74
|
|
|
62
75
|
return out
|
|
63
76
|
}
|
package/src/val/FuncBaseVal.ts
CHANGED
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
top
|
|
28
28
|
} from './top'
|
|
29
29
|
|
|
30
|
-
import { NilVal } from '../val/NilVal'
|
|
31
30
|
import { ConjunctVal } from '../val/ConjunctVal'
|
|
32
31
|
import { FeatureVal } from '../val/FeatureVal'
|
|
33
32
|
|
|
@@ -59,6 +58,7 @@ class FuncBaseVal extends FeatureVal {
|
|
|
59
58
|
|
|
60
59
|
|
|
61
60
|
unify(peer: Val, ctx: AontuContext): Val {
|
|
61
|
+
const TOP = top()
|
|
62
62
|
const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Func:' + this.funcname(), this, peer)
|
|
63
63
|
|
|
64
64
|
// const sc = this.id + '=' + this.canon
|
|
@@ -71,6 +71,8 @@ class FuncBaseVal extends FeatureVal {
|
|
|
71
71
|
|
|
72
72
|
// console.log('FBV', this.id, this.constructor.name, this.mark.type, this.peg?.canon, 'PEER', peer.id, peer.canon)
|
|
73
73
|
|
|
74
|
+
let pegdone = true
|
|
75
|
+
|
|
74
76
|
if (this.id !== peer.id) {
|
|
75
77
|
|
|
76
78
|
if (peer.isTop && (this.mark.type || this.mark.hide)) {
|
|
@@ -78,25 +80,34 @@ class FuncBaseVal extends FeatureVal {
|
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
else {
|
|
81
|
-
|
|
83
|
+
|
|
82
84
|
let newpeg: Val[] = []
|
|
83
85
|
let newtype = this.mark.type
|
|
84
86
|
let newhide = this.mark.hide
|
|
85
87
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
for (let arg of this.peg) {
|
|
89
|
-
// console.log('FUNCBASE-UNIFY-PEG-A', arg.canon)
|
|
88
|
+
let pegprep = this.prepare(ctx, this.peg)
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
if (null === pegprep) {
|
|
91
|
+
pegdone = true
|
|
92
|
+
newpeg = this.peg
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.peg = pegprep
|
|
96
|
+
|
|
97
|
+
for (let arg of this.peg) {
|
|
98
|
+
// console.log('FUNCBASE-UNIFY-PEG-A', arg.canon)
|
|
99
|
+
|
|
100
|
+
let newarg = arg
|
|
101
|
+
if (!arg.done) {
|
|
102
|
+
newarg = arg.unify(TOP, ctx.clone({ explain: ec(te, 'ARG') }))
|
|
103
|
+
newtype = newtype || newarg.mark.type
|
|
104
|
+
newhide = newhide || newarg.mark.hide
|
|
105
|
+
// console.log('FUNCBASE-UNIFY-PEG-B', arg.canon, arg.done, '->', newarg.canon, newarg.done)
|
|
106
|
+
}
|
|
107
|
+
// pegdone &&= arg.done
|
|
108
|
+
pegdone &&= newarg.done
|
|
109
|
+
newpeg.push(newarg)
|
|
97
110
|
}
|
|
98
|
-
pegdone &&= arg.done
|
|
99
|
-
newpeg.push(newarg)
|
|
100
111
|
}
|
|
101
112
|
|
|
102
113
|
// console.log('FUNCBASE-PEG', this.id, pegdone, this.peg.map((p: any) => p?.canon))
|
|
@@ -106,15 +117,10 @@ class FuncBaseVal extends FeatureVal {
|
|
|
106
117
|
// console.log('FUNC-RESOLVED', ctx.cc, resolved?.canon)
|
|
107
118
|
|
|
108
119
|
out = resolved.done && peer.isTop ? resolved :
|
|
109
|
-
unite(ctx.clone({ explain: ec(te, 'PEG') }),
|
|
120
|
+
unite(ctx.clone({ explain: ec(te, 'PEG') }),
|
|
121
|
+
resolved, peer, 'func-' + this.funcname() + '/' + this.id)
|
|
110
122
|
propagateMarks(this, out)
|
|
111
123
|
|
|
112
|
-
// const unified =
|
|
113
|
-
// unite(ctx, resolved, peer, 'func-' + this.funcname() + '/' + this.id)
|
|
114
|
-
// out = unified
|
|
115
|
-
// propagateMarks(unified, out)
|
|
116
|
-
// propagateMarks(this, out)
|
|
117
|
-
|
|
118
124
|
// TODO: make should handle this using ctx?
|
|
119
125
|
out.site.row = this.site.row
|
|
120
126
|
out.site.col = this.site.col
|
|
@@ -157,7 +163,7 @@ class FuncBaseVal extends FeatureVal {
|
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
165
|
|
|
160
|
-
// console.log('FUNC-UNIFY-OUT', this.funcname(), this.id, this.canon, 'W=', why, peer.id, peer.canon, 'O=', out.dc, out.id, out.canon)
|
|
166
|
+
// console.log('FUNC-UNIFY-OUT', ctx.cc, this.funcname(), this.id, this.canon, 'D=', pegdone, 'W=', why, peer.id, peer.canon, 'O=', out.dc, out.id, out.canon)
|
|
161
167
|
|
|
162
168
|
explainClose(te, out)
|
|
163
169
|
|
|
@@ -180,12 +186,12 @@ class FuncBaseVal extends FeatureVal {
|
|
|
180
186
|
}
|
|
181
187
|
|
|
182
188
|
|
|
183
|
-
prepare(_ctx: AontuContext
|
|
189
|
+
prepare(_ctx: AontuContext, args: Val[]): Val[] | null {
|
|
184
190
|
return args
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
|
|
188
|
-
resolve(ctx: AontuContext
|
|
194
|
+
resolve(ctx: AontuContext, _args: Val[]): Val {
|
|
189
195
|
return makeNilErr(ctx, 'func:' + this.funcname(), this, undefined, 'resolve')
|
|
190
196
|
}
|
|
191
197
|
|
package/src/val/JunctionVal.ts
CHANGED
|
@@ -40,8 +40,8 @@ abstract class JunctionVal extends FeatureVal {
|
|
|
40
40
|
get canon() {
|
|
41
41
|
return this.peg.map((v: Val) => {
|
|
42
42
|
return (v as any).isJunction && Array.isArray(v.peg) && 1 < v.peg.length ?
|
|
43
|
-
'(' + v.canon + ')' : v.canon
|
|
44
|
-
}).join(this.getJunctionSymbol())
|
|
43
|
+
'(' + v.canon + ')' : v.canon // v.id + '=' + v.canon
|
|
44
|
+
}).join(this.getJunctionSymbol()) // + '<' + (this.mark.hide ? 'H' : '') + '>'
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// Abstract method to be implemented by subclasses to define their junction symbol
|
package/src/val/KeyFuncVal.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '../ctx'
|
|
13
13
|
|
|
14
14
|
import { StringVal } from '../val/StringVal'
|
|
15
|
+
import { ConjunctVal } from '../val/ConjunctVal'
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
|
|
@@ -39,17 +40,52 @@ class KeyFuncVal extends FuncBaseVal {
|
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
|
|
43
|
+
unify(peer: Val, ctx: AontuContext): Val {
|
|
44
|
+
// TODO: this delay makes keys in spreads and refs work, but it is a hack - find a better way.
|
|
45
|
+
let out: Val = this
|
|
46
|
+
|
|
47
|
+
if (ctx.cc < 3) {
|
|
48
|
+
this.notdone()
|
|
49
|
+
|
|
50
|
+
if (peer.isTop || (peer.id === this.id)) {
|
|
51
|
+
// TODO: clone needed to avoid triggering unify_cycle - find a better way
|
|
52
|
+
out = this.clone(ctx)
|
|
53
|
+
}
|
|
54
|
+
else if (peer.isNil) {
|
|
55
|
+
out = peer
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
if (
|
|
59
|
+
peer.isKeyFunc
|
|
60
|
+
&& peer.path.join('.') === this.path.join('.')
|
|
61
|
+
&& peer.peg?.[0]?.peg === this.peg?.[0]?.peg
|
|
62
|
+
) {
|
|
63
|
+
out = this
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
out = new ConjunctVal({ peg: [this, peer] }, ctx)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
out = super.unify(peer, ctx)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return out
|
|
75
|
+
}
|
|
76
|
+
|
|
42
77
|
|
|
43
78
|
resolve(_ctx: AontuContext, _args: Val[]) {
|
|
44
79
|
let out: Val = this
|
|
45
80
|
|
|
46
|
-
if (!this.mark.type && !this.mark.hide) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
81
|
+
// if (!this.mark.type && !this.mark.hide) {
|
|
82
|
+
let move = this.peg?.[0]?.peg
|
|
83
|
+
move = isNaN(move) ? 1 : +move
|
|
84
|
+
const key = this.path[this.path.length - (1 + move)] ?? ''
|
|
85
|
+
// console.log('KEY', this.path, move, key)
|
|
50
86
|
|
|
51
|
-
|
|
52
|
-
}
|
|
87
|
+
out = new StringVal({ peg: key })
|
|
88
|
+
// }
|
|
53
89
|
|
|
54
90
|
return out
|
|
55
91
|
}
|