aontu 0.29.0 → 0.30.1
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/aontu.d.ts +17 -13
- package/dist/aontu.js +145 -60
- package/dist/aontu.js.map +1 -1
- package/package.json +18 -34
- package/aontu.ts +0 -92
- package/dist/lib/err.d.ts +0 -4
- package/dist/lib/err.js +0 -61
- package/dist/lib/err.js.map +0 -1
- package/dist/lib/lang.d.ts +0 -15
- package/dist/lib/lang.js +0 -409
- package/dist/lib/lang.js.map +0 -1
- package/dist/lib/op/disjunct.d.ts +0 -3
- package/dist/lib/op/disjunct.js +0 -28
- package/dist/lib/op/disjunct.js.map +0 -1
- package/dist/lib/op/op.d.ts +0 -6
- package/dist/lib/op/op.js +0 -9
- package/dist/lib/op/op.js.map +0 -1
- package/dist/lib/op/unite.d.ts +0 -3
- package/dist/lib/op/unite.js +0 -100
- package/dist/lib/op/unite.js.map +0 -1
- package/dist/lib/type.d.ts +0 -49
- package/dist/lib/type.js +0 -7
- package/dist/lib/type.js.map +0 -1
- package/dist/lib/unify.d.ts +0 -38
- package/dist/lib/unify.js +0 -67
- package/dist/lib/unify.js.map +0 -1
- package/dist/lib/utility.d.ts +0 -3
- package/dist/lib/utility.js +0 -16
- package/dist/lib/utility.js.map +0 -1
- package/dist/lib/val/ConjunctVal.d.ts +0 -17
- package/dist/lib/val/ConjunctVal.js +0 -171
- package/dist/lib/val/ConjunctVal.js.map +0 -1
- package/dist/lib/val/DisjunctVal.d.ts +0 -17
- package/dist/lib/val/DisjunctVal.js +0 -95
- package/dist/lib/val/DisjunctVal.js.map +0 -1
- package/dist/lib/val/ListVal.d.ts +0 -18
- package/dist/lib/val/ListVal.js +0 -120
- package/dist/lib/val/ListVal.js.map +0 -1
- package/dist/lib/val/MapVal.d.ts +0 -18
- package/dist/lib/val/MapVal.js +0 -117
- package/dist/lib/val/MapVal.js.map +0 -1
- package/dist/lib/val/Nil.d.ts +0 -22
- package/dist/lib/val/Nil.js +0 -84
- package/dist/lib/val/Nil.js.map +0 -1
- package/dist/lib/val/NullVal.d.ts +0 -15
- package/dist/lib/val/NullVal.js +0 -38
- package/dist/lib/val/NullVal.js.map +0 -1
- package/dist/lib/val/OpVal.d.ts +0 -17
- package/dist/lib/val/OpVal.js +0 -89
- package/dist/lib/val/OpVal.js.map +0 -1
- package/dist/lib/val/PlusVal.d.ts +0 -12
- package/dist/lib/val/PlusVal.js +0 -32
- package/dist/lib/val/PlusVal.js.map +0 -1
- package/dist/lib/val/PrefVal.d.ts +0 -17
- package/dist/lib/val/PrefVal.js +0 -87
- package/dist/lib/val/PrefVal.js.map +0 -1
- package/dist/lib/val/RefVal.d.ts +0 -22
- package/dist/lib/val/RefVal.js +0 -247
- package/dist/lib/val/RefVal.js.map +0 -1
- package/dist/lib/val/ValBase.d.ts +0 -26
- package/dist/lib/val/ValBase.js +0 -77
- package/dist/lib/val/ValBase.js.map +0 -1
- package/dist/lib/val/VarVal.d.ts +0 -15
- package/dist/lib/val/VarVal.js +0 -84
- package/dist/lib/val/VarVal.js.map +0 -1
- package/dist/lib/val.d.ts +0 -81
- package/dist/lib/val.js +0 -191
- package/dist/lib/val.js.map +0 -1
- package/lib/err.ts +0 -83
- package/lib/lang.ts +0 -585
- package/lib/op/disjunct.ts +0 -51
- package/lib/op/op.ts +0 -18
- package/lib/op/unite.ts +0 -143
- package/lib/type.ts +0 -95
- package/lib/unify.ts +0 -128
- package/lib/utility.ts +0 -24
- package/lib/val/ConjunctVal.ts +0 -265
- package/lib/val/DisjunctVal.ts +0 -160
- package/lib/val/ListVal.ts +0 -196
- package/lib/val/MapVal.ts +0 -181
- package/lib/val/Nil.ts +0 -144
- package/lib/val/NullVal.ts +0 -72
- package/lib/val/OpVal.ts +0 -159
- package/lib/val/PlusVal.ts +0 -76
- package/lib/val/PrefVal.ts +0 -154
- package/lib/val/RefVal.ts +0 -362
- package/lib/val/ValBase.ts +0 -109
- package/lib/val/VarVal.ts +0 -157
- package/lib/val.ts +0 -327
package/lib/op/unite.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type { Val } from '../type'
|
|
6
|
-
|
|
7
|
-
import { DONE } from '../type'
|
|
8
|
-
import { Context } from '../unify'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { ConjunctVal } from '../val/ConjunctVal'
|
|
12
|
-
import { DisjunctVal } from '../val/DisjunctVal'
|
|
13
|
-
import { ListVal } from '../val/ListVal'
|
|
14
|
-
import { MapVal } from '../val/MapVal'
|
|
15
|
-
import { Nil } from '../val/Nil'
|
|
16
|
-
import { PrefVal } from '../val/PrefVal'
|
|
17
|
-
import { RefVal } from '../val/RefVal'
|
|
18
|
-
import { ValBase } from '../val/ValBase'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
TOP,
|
|
23
|
-
} from '../val'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
import { Operation } from './op'
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let uc = 0
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// Vals should only have to unify downwards (in .unify) over Vals they understand.
|
|
33
|
-
// and for complex Vals, TOP, which means self unify if not yet done
|
|
34
|
-
const unite: Operation = (ctx: Context, a?: any, b?: any, whence?: string) => {
|
|
35
|
-
let out = a
|
|
36
|
-
let why = 'u'
|
|
37
|
-
// console.log('AA OP unite IN', a?.canon, b?.canon,
|
|
38
|
-
// 'W', whence,
|
|
39
|
-
// 'E', 0 < ctx?.err?.length ? ctx.err.map((e: Val) => e.canon) : '')
|
|
40
|
-
|
|
41
|
-
let unified = false
|
|
42
|
-
|
|
43
|
-
if (b && (TOP === a || !a)) {
|
|
44
|
-
//console.log('Utb', b.canon)
|
|
45
|
-
out = b
|
|
46
|
-
why = 'b'
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
else if (a && (TOP === b || !b)) {
|
|
50
|
-
//console.log('Uta', a.canon)
|
|
51
|
-
out = a
|
|
52
|
-
why = 'a'
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
else if (a && b && TOP !== b) {
|
|
56
|
-
if (a.isNil) {
|
|
57
|
-
out = update(a, b)
|
|
58
|
-
why = 'an'
|
|
59
|
-
}
|
|
60
|
-
else if (b.isNil) {
|
|
61
|
-
out = update(b, a)
|
|
62
|
-
why = 'bn'
|
|
63
|
-
}
|
|
64
|
-
else if (a.isConjunctVal) {
|
|
65
|
-
// console.log('Q', a.canon, b.canon)
|
|
66
|
-
out = a.unify(b, ctx)
|
|
67
|
-
unified = true
|
|
68
|
-
why = 'acj'
|
|
69
|
-
}
|
|
70
|
-
else if (
|
|
71
|
-
b.isConjunctVal ||
|
|
72
|
-
b.isDisjunctVal ||
|
|
73
|
-
b.isRefVal ||
|
|
74
|
-
b.isPrefVal
|
|
75
|
-
) {
|
|
76
|
-
|
|
77
|
-
// console.log('U', a.canon, b.canon)
|
|
78
|
-
// return b.unify(a, ctx)
|
|
79
|
-
out = b.unify(a, ctx)
|
|
80
|
-
unified = true
|
|
81
|
-
// console.log('UO', out.canon)
|
|
82
|
-
why = 'bv'
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Exactly equal scalars.
|
|
86
|
-
else if (a.constructor === b.constructor && a.peg === b.peg) {
|
|
87
|
-
out = update(a, b)
|
|
88
|
-
why = 'up'
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
else {
|
|
92
|
-
// console.log('QQQ')
|
|
93
|
-
out = a.unify(b, ctx)
|
|
94
|
-
unified = true
|
|
95
|
-
why = 'ab'
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (!out || !out.unify) {
|
|
100
|
-
out = Nil.make(ctx, 'unite', a, b)
|
|
101
|
-
why += 'N'
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (DONE !== out.done && !unified) {
|
|
105
|
-
out = out.unify(TOP, ctx)
|
|
106
|
-
why += 'T'
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// console.log('AA OP unite OUT', a?.canon, b?.canon, '->', out && out.canon,
|
|
110
|
-
// 0 < ctx?.err?.length ? ctx.err.map((e: Val) => e.canon) : '')
|
|
111
|
-
|
|
112
|
-
uc++
|
|
113
|
-
|
|
114
|
-
// TODO: KEEP THIS! print in debug mode! push to ctx.log?
|
|
115
|
-
/*
|
|
116
|
-
console.log(
|
|
117
|
-
'U',
|
|
118
|
-
('' + ctx.cc).padStart(2),
|
|
119
|
-
('' + uc).padStart(4),
|
|
120
|
-
(whence || '').substring(0, 16).padEnd(16),
|
|
121
|
-
why.padEnd(6),
|
|
122
|
-
ctx.path.join('.').padEnd(16),
|
|
123
|
-
(a || '').constructor.name.substring(0, 3),
|
|
124
|
-
'&',
|
|
125
|
-
(b || '').constructor.name.substring(0, 3),
|
|
126
|
-
'|',
|
|
127
|
-
' '.repeat(ctx.path.length),
|
|
128
|
-
a?.canon, '&', b?.canon, '->', out.canon)
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
return out
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
function update(x: Val, _y: Val) {
|
|
136
|
-
// TODO: update x with y.site
|
|
137
|
-
return x
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
export {
|
|
142
|
-
unite
|
|
143
|
-
}
|
package/lib/type.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2022-2023 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
import * as Fs from 'node:fs'
|
|
4
|
-
|
|
5
|
-
// TODO: refactor these out
|
|
6
|
-
|
|
7
|
-
import { Resolver } from '@jsonic/multisource'
|
|
8
|
-
|
|
9
|
-
import { Context } from './unify'
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
Site
|
|
13
|
-
} from './lang'
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
type FST = typeof Fs
|
|
18
|
-
|
|
19
|
-
type Options = {
|
|
20
|
-
src: string // Source text.
|
|
21
|
-
print: number // Print debug verbosity
|
|
22
|
-
resolver?: Resolver // Source resolver
|
|
23
|
-
base?: string // Base path for resolver
|
|
24
|
-
path?: string // Path of entry file
|
|
25
|
-
debug?: boolean
|
|
26
|
-
trace?: boolean
|
|
27
|
-
fs?: FST
|
|
28
|
-
deps?: any
|
|
29
|
-
log?: any
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
interface Val {
|
|
35
|
-
isVal: boolean
|
|
36
|
-
|
|
37
|
-
id: number
|
|
38
|
-
done: number
|
|
39
|
-
path: string[]
|
|
40
|
-
row: number
|
|
41
|
-
col: number
|
|
42
|
-
url: string
|
|
43
|
-
|
|
44
|
-
top: boolean
|
|
45
|
-
|
|
46
|
-
// Actual native value.
|
|
47
|
-
peg: any
|
|
48
|
-
|
|
49
|
-
// TODO: used for top level result - not great
|
|
50
|
-
err: any[]
|
|
51
|
-
deps?: any
|
|
52
|
-
|
|
53
|
-
same(peer: Val): boolean
|
|
54
|
-
|
|
55
|
-
// TODO: reverse args, as spec is mostly only used internally?
|
|
56
|
-
clone(spec?: ValSpec, ctx?: Context): Val
|
|
57
|
-
|
|
58
|
-
// get site(): Site
|
|
59
|
-
unify(peer: Val, ctx?: Context): Val
|
|
60
|
-
get canon(): string
|
|
61
|
-
gen(ctx?: Context): any
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
type ValSpec = {
|
|
65
|
-
peg?: any,
|
|
66
|
-
[name: string]: any,
|
|
67
|
-
} | null
|
|
68
|
-
type ValMap = { [key: string]: Val }
|
|
69
|
-
type ValList = Val[]
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const DONE = -1
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
type ErrContext = {
|
|
77
|
-
src?: string,
|
|
78
|
-
fs?: FST
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export type {
|
|
82
|
-
Val,
|
|
83
|
-
ValSpec,
|
|
84
|
-
ValMap,
|
|
85
|
-
ValList,
|
|
86
|
-
Options,
|
|
87
|
-
ErrContext,
|
|
88
|
-
FST,
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export {
|
|
92
|
-
DONE,
|
|
93
|
-
Resolver,
|
|
94
|
-
}
|
|
95
|
-
|
package/lib/unify.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type { Val } from './type'
|
|
5
|
-
|
|
6
|
-
import { DONE, FST } from './type'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
TOP
|
|
11
|
-
} from './val'
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
Lang
|
|
15
|
-
} from './lang'
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
unite
|
|
19
|
-
} from './op/op'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
import { Nil } from '../lib/val/Nil'
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
type Path = string[]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class Context {
|
|
29
|
-
root: Val // Starting Val, root of paths.
|
|
30
|
-
path: Path // Path to current Val.
|
|
31
|
-
err: Nil[] // Nil error log of current unify.
|
|
32
|
-
vc: number // Val counter to create unique val ids.
|
|
33
|
-
cc: number = -1
|
|
34
|
-
var: Record<string, Val> = {}
|
|
35
|
-
src?: string
|
|
36
|
-
fs?: FST
|
|
37
|
-
|
|
38
|
-
constructor(cfg: {
|
|
39
|
-
root: Val,
|
|
40
|
-
path?: Path,
|
|
41
|
-
err?: Nil[],
|
|
42
|
-
vc?: number,
|
|
43
|
-
cc?: number,
|
|
44
|
-
var?: Record<string, Val>
|
|
45
|
-
}) {
|
|
46
|
-
this.root = cfg.root
|
|
47
|
-
this.path = cfg.path || []
|
|
48
|
-
this.err = cfg.err || []
|
|
49
|
-
|
|
50
|
-
// Multiple unify passes will keep incrementing Val counter.
|
|
51
|
-
this.vc = null == cfg.vc ? 1_000_000_000 : cfg.vc
|
|
52
|
-
|
|
53
|
-
this.cc = null == cfg.cc ? this.cc : cfg.cc
|
|
54
|
-
|
|
55
|
-
this.var = cfg.var || this.var
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
clone(cfg: {
|
|
60
|
-
root?: Val,
|
|
61
|
-
path?: Path,
|
|
62
|
-
err?: Nil[],
|
|
63
|
-
}): Context {
|
|
64
|
-
return new Context({
|
|
65
|
-
root: cfg.root || this.root,
|
|
66
|
-
path: cfg.path,
|
|
67
|
-
err: cfg.err || this.err,
|
|
68
|
-
vc: this.vc,
|
|
69
|
-
cc: this.cc,
|
|
70
|
-
var: { ...this.var },
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
descend(key: string): Context {
|
|
76
|
-
return this.clone({
|
|
77
|
-
root: this.root,
|
|
78
|
-
path: this.path.concat(key),
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class Unify {
|
|
85
|
-
root: Val
|
|
86
|
-
res: Val
|
|
87
|
-
err: Nil[]
|
|
88
|
-
cc: number
|
|
89
|
-
lang: Lang
|
|
90
|
-
|
|
91
|
-
constructor(root: Val | string, lang?: Lang, ctx?: Context) {
|
|
92
|
-
this.lang = lang || new Lang()
|
|
93
|
-
if ('string' === typeof root) {
|
|
94
|
-
root = this.lang.parse(root)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
this.cc = 0
|
|
98
|
-
this.root = root
|
|
99
|
-
this.res = root
|
|
100
|
-
this.err = root.err || []
|
|
101
|
-
|
|
102
|
-
let res = root
|
|
103
|
-
|
|
104
|
-
// Only unify if no syntax errors
|
|
105
|
-
if (!(root as Nil).nil) {
|
|
106
|
-
ctx = ctx || new Context({
|
|
107
|
-
root: res,
|
|
108
|
-
err: this.err,
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
let maxdc = 9 // 99
|
|
112
|
-
for (; this.cc < maxdc && DONE !== res.done; this.cc++) {
|
|
113
|
-
ctx.cc = this.cc
|
|
114
|
-
res = unite(ctx, res, TOP)
|
|
115
|
-
ctx = ctx.clone({ root: res })
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
this.res = res
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
export {
|
|
125
|
-
Context,
|
|
126
|
-
Path,
|
|
127
|
-
Unify,
|
|
128
|
-
}
|
package/lib/utility.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2023 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type { Val } from './type'
|
|
6
|
-
|
|
7
|
-
function formatPath(path: Val | string[], absolute?: boolean) {
|
|
8
|
-
let parts: string[]
|
|
9
|
-
if (Array.isArray(path)) {
|
|
10
|
-
parts = path
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
parts = path.path
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let pathstr = (0 < parts.length && false !== absolute ? '$.' : '') + parts.join('.')
|
|
17
|
-
|
|
18
|
-
return pathstr
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
formatPath
|
|
23
|
-
}
|
|
24
|
-
|
package/lib/val/ConjunctVal.ts
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import type {
|
|
5
|
-
Val,
|
|
6
|
-
ValSpec,
|
|
7
|
-
} from '../type'
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
DONE,
|
|
11
|
-
} from '../type'
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
descErr
|
|
15
|
-
} from '../err'
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
Context,
|
|
19
|
-
} from '../unify'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
unite
|
|
25
|
-
} from '../op/op'
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
import { TOP } from '../val'
|
|
29
|
-
// import { DisjunctVal } from '../val/DisjunctVal'
|
|
30
|
-
import { ListVal } from '../val/ListVal'
|
|
31
|
-
import { MapVal } from '../val/MapVal'
|
|
32
|
-
import { Nil } from '../val/Nil'
|
|
33
|
-
// import { PrefVal } from '../val/PrefVal'
|
|
34
|
-
import { RefVal } from '../val/RefVal'
|
|
35
|
-
import { ValBase } from '../val/ValBase'
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
// TODO: move main logic to op/conjunct
|
|
39
|
-
class ConjunctVal extends ValBase {
|
|
40
|
-
isBinaryOp = true
|
|
41
|
-
isConjunctVal = true
|
|
42
|
-
|
|
43
|
-
constructor(
|
|
44
|
-
spec: {
|
|
45
|
-
peg: Val[]
|
|
46
|
-
},
|
|
47
|
-
ctx?: Context
|
|
48
|
-
) {
|
|
49
|
-
super(spec, ctx)
|
|
50
|
-
// console.log('NEWCJ')
|
|
51
|
-
// console.trace()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// NOTE: mutation!
|
|
55
|
-
append(peer: Val): ConjunctVal {
|
|
56
|
-
this.peg.push(peer)
|
|
57
|
-
return this
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
unify(peer: Val, ctx: Context): Val {
|
|
61
|
-
const mark = (Math.random() * 1e7) % 1e6 | 0
|
|
62
|
-
let done = true
|
|
63
|
-
|
|
64
|
-
// Unify each term of conjunct against peer
|
|
65
|
-
let upeer: Val[] = []
|
|
66
|
-
|
|
67
|
-
for (let vI = 0; vI < this.peg.length; vI++) {
|
|
68
|
-
upeer[vI] = unite(ctx, this.peg[vI], peer, 'cj-own' + mark)
|
|
69
|
-
|
|
70
|
-
// let prevdone = done
|
|
71
|
-
done = done && (DONE === upeer[vI].done)
|
|
72
|
-
|
|
73
|
-
if (upeer[vI] instanceof Nil) {
|
|
74
|
-
return Nil.make(
|
|
75
|
-
ctx,
|
|
76
|
-
'&peer[' + upeer[vI].canon + ',' + peer.canon + ']',
|
|
77
|
-
this.peg[vI],
|
|
78
|
-
peer
|
|
79
|
-
)
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
upeer = norm(upeer)
|
|
84
|
-
|
|
85
|
-
upeer.sort((a: Val, b: Val) => {
|
|
86
|
-
return (a.constructor.name === b.constructor.name) ? 0 :
|
|
87
|
-
(a.constructor.name < b.constructor.name ? -1 : 1)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
// Unify terms against each other
|
|
91
|
-
|
|
92
|
-
let outvals: Val[] = []
|
|
93
|
-
let val: Val
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// for (let pI = 0; pI < upeer.length; pI++) {
|
|
97
|
-
// let pt = upeer[pI]
|
|
98
|
-
// for (let qI = pI; qI < upeer.length; qI++) {
|
|
99
|
-
// let qt = upeer[pI]
|
|
100
|
-
|
|
101
|
-
// let pq = unite(ctx, pt, qt, 'cj-pq')
|
|
102
|
-
|
|
103
|
-
// }
|
|
104
|
-
// }
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
let t0 = upeer[0]
|
|
108
|
-
|
|
109
|
-
next_term:
|
|
110
|
-
for (let pI = 0; pI < upeer.length; pI++) {
|
|
111
|
-
// console.log('CJ TERM t0', pI, t0.done, t0.canon)
|
|
112
|
-
|
|
113
|
-
if (DONE !== t0.done) {
|
|
114
|
-
let u0 = unite(ctx, t0, TOP, 'cj-peer-t0')
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
DONE !== u0.done
|
|
118
|
-
|
|
119
|
-
// Maps and Lists are still unified so that path refs will work
|
|
120
|
-
// TODO: || ListVal - test!
|
|
121
|
-
&& !(
|
|
122
|
-
u0 instanceof MapVal
|
|
123
|
-
|| u0 instanceof ListVal
|
|
124
|
-
|| u0 instanceof RefVal
|
|
125
|
-
)
|
|
126
|
-
) {
|
|
127
|
-
|
|
128
|
-
outvals.push(u0)
|
|
129
|
-
continue next_term
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
t0 = u0
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
let t1 = upeer[pI + 1]
|
|
137
|
-
|
|
138
|
-
if (null == t1) {
|
|
139
|
-
outvals.push(t0)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Can't unite with a RefVal, unless also a RefVal with same path.
|
|
143
|
-
else if (t0 instanceof RefVal && !(t1 instanceof RefVal)) {
|
|
144
|
-
outvals.push(t0)
|
|
145
|
-
t0 = t1
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
else if (t1 instanceof RefVal && !(t0 instanceof RefVal)) {
|
|
149
|
-
outvals.push(t0)
|
|
150
|
-
t0 = t1
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
else {
|
|
155
|
-
val = unite(ctx, t0, t1, 'cj-peer-t0t1')
|
|
156
|
-
done = done && DONE === val.done
|
|
157
|
-
|
|
158
|
-
// Unite was just a conjunt anyway, so discard.
|
|
159
|
-
if (val instanceof ConjunctVal) {
|
|
160
|
-
outvals.push(t0)
|
|
161
|
-
t0 = t1
|
|
162
|
-
}
|
|
163
|
-
else if (val instanceof Nil) {
|
|
164
|
-
return val
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
t0 = val
|
|
168
|
-
}
|
|
169
|
-
// TODO: t0 should become this to avoid unnecessary repasses
|
|
170
|
-
// outvals.push(val)
|
|
171
|
-
|
|
172
|
-
// pI++
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let out: Val
|
|
177
|
-
|
|
178
|
-
if (0 === outvals.length) {
|
|
179
|
-
|
|
180
|
-
// Empty conjuncts evaporate.
|
|
181
|
-
out = TOP
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// TODO: corrects CV[CV[1&/x]] issue above, but swaps term order!
|
|
185
|
-
else if (1 === outvals.length) {
|
|
186
|
-
out = outvals[0]
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
out = new ConjunctVal({ peg: outvals }, ctx)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
out.done = done ? DONE : this.done + 1
|
|
193
|
-
|
|
194
|
-
return out
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
clone(spec?: ValSpec, ctx?: Context): Val {
|
|
199
|
-
let out = (super.clone(spec, ctx) as ConjunctVal)
|
|
200
|
-
out.peg = this.peg.map((entry: Val) => entry.clone(null, ctx))
|
|
201
|
-
return out
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// TODO: need a well-defined val order so conjunt canon is always the same
|
|
206
|
-
get canon() {
|
|
207
|
-
return this.peg.map((v: Val) => {
|
|
208
|
-
return (v as any).isBinaryOp && Array.isArray(v.peg) && 1 < v.peg.length ?
|
|
209
|
-
'(' + v.canon + ')' : v.canon
|
|
210
|
-
}).join('&')
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
gen(ctx?: Context) {
|
|
215
|
-
// Unresolved conjunct cannot be generated, so always an error.
|
|
216
|
-
let nil = Nil.make(
|
|
217
|
-
ctx,
|
|
218
|
-
'conjunct',
|
|
219
|
-
this, // (formatPath(this.peg, this.absolute) as any),
|
|
220
|
-
undefined
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
// TODO: refactor to use Site
|
|
224
|
-
nil.path = this.path
|
|
225
|
-
nil.url = this.url
|
|
226
|
-
nil.row = this.row
|
|
227
|
-
nil.col = this.col
|
|
228
|
-
|
|
229
|
-
descErr(nil, ctx)
|
|
230
|
-
|
|
231
|
-
if (ctx) {
|
|
232
|
-
ctx.err.push(nil)
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
throw new Error(nil.msg)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return undefined
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
// Normalize Conjuct:
|
|
244
|
-
// - flatten child conjuncts
|
|
245
|
-
function norm(terms: Val[]): Val[] {
|
|
246
|
-
|
|
247
|
-
let expand: Val[] = []
|
|
248
|
-
for (let tI = 0, pI = 0; tI < terms.length; tI++, pI++) {
|
|
249
|
-
if (terms[tI] instanceof ConjunctVal) {
|
|
250
|
-
expand.push(...terms[tI].peg)
|
|
251
|
-
pI += terms[tI].peg.length - 1
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
expand[pI] = terms[tI]
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return expand
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
export {
|
|
263
|
-
norm,
|
|
264
|
-
ConjunctVal,
|
|
265
|
-
}
|