aontu 0.30.1 → 0.30.2
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 +51 -0
- package/dist/ctx.js +105 -0
- package/dist/ctx.js.map +1 -0
- package/dist/err.d.ts +12 -0
- package/dist/err.js +123 -0
- package/dist/err.js.map +1 -0
- package/dist/hints.d.ts +8 -0
- package/dist/hints.js +84 -0
- package/dist/hints.js.map +1 -0
- package/dist/lang.d.ts +11 -0
- package/dist/lang.js +569 -0
- package/dist/lang.js.map +1 -0
- package/dist/site.d.ts +12 -0
- package/dist/site.js +27 -0
- package/dist/site.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/type.d.ts +32 -0
- package/dist/type.js +16 -0
- package/dist/type.js.map +1 -0
- package/dist/unify.d.ts +14 -0
- package/dist/unify.js +156 -0
- package/dist/unify.js.map +1 -0
- package/dist/utility.d.ts +14 -0
- package/dist/utility.js +122 -0
- package/dist/utility.js.map +1 -0
- package/dist/val/BagVal.d.ts +10 -0
- package/dist/val/BagVal.js +15 -0
- package/dist/val/BagVal.js.map +1 -0
- package/dist/val/BooleanVal.d.ts +9 -0
- package/dist/val/BooleanVal.js +16 -0
- package/dist/val/BooleanVal.js.map +1 -0
- package/dist/val/CloseFuncVal.d.ts +11 -0
- package/dist/val/CloseFuncVal.js +32 -0
- package/dist/val/CloseFuncVal.js.map +1 -0
- package/dist/val/ConjunctVal.d.ts +14 -0
- package/dist/val/ConjunctVal.js +187 -0
- package/dist/val/ConjunctVal.js.map +1 -0
- package/dist/val/CopyFuncVal.d.ts +13 -0
- package/dist/val/CopyFuncVal.js +35 -0
- package/dist/val/CopyFuncVal.js.map +1 -0
- package/dist/val/DisjunctVal.d.ts +19 -0
- package/dist/val/DisjunctVal.js +194 -0
- package/dist/val/DisjunctVal.js.map +1 -0
- package/dist/val/FeatureVal.d.ts +10 -0
- package/dist/val/FeatureVal.js +29 -0
- package/dist/val/FeatureVal.js.map +1 -0
- package/dist/val/FuncBaseVal.d.ts +15 -0
- package/dist/val/FuncBaseVal.js +127 -0
- package/dist/val/FuncBaseVal.js.map +1 -0
- package/dist/val/HideFuncVal.d.ts +12 -0
- package/dist/val/HideFuncVal.js +48 -0
- package/dist/val/HideFuncVal.js.map +1 -0
- package/dist/val/IntegerVal.d.ts +9 -0
- package/dist/val/IntegerVal.js +46 -0
- package/dist/val/IntegerVal.js.map +1 -0
- package/dist/val/JunctionVal.d.ts +12 -0
- package/dist/val/JunctionVal.js +31 -0
- package/dist/val/JunctionVal.js.map +1 -0
- package/dist/val/KeyFuncVal.d.ts +12 -0
- package/dist/val/KeyFuncVal.js +34 -0
- package/dist/val/KeyFuncVal.js.map +1 -0
- package/dist/val/ListVal.d.ts +17 -0
- package/dist/val/ListVal.js +186 -0
- package/dist/val/ListVal.js.map +1 -0
- package/dist/val/LowerFuncVal.d.ts +12 -0
- package/dist/val/LowerFuncVal.js +40 -0
- package/dist/val/LowerFuncVal.js.map +1 -0
- package/dist/val/MapVal.d.ts +16 -0
- package/dist/val/MapVal.js +211 -0
- package/dist/val/MapVal.js.map +1 -0
- package/dist/val/MoveFuncVal.d.ts +11 -0
- package/dist/val/MoveFuncVal.js +41 -0
- package/dist/val/MoveFuncVal.js.map +1 -0
- package/dist/val/NilVal.d.ts +25 -0
- package/dist/val/NilVal.js +92 -0
- package/dist/val/NilVal.js.map +1 -0
- package/dist/val/NullVal.d.ts +9 -0
- package/dist/val/NullVal.js +18 -0
- package/dist/val/NullVal.js.map +1 -0
- package/dist/val/NumberVal.d.ts +9 -0
- package/dist/val/NumberVal.js +44 -0
- package/dist/val/NumberVal.js.map +1 -0
- package/dist/val/OpBaseVal.d.ts +18 -0
- package/dist/val/OpBaseVal.js +152 -0
- package/dist/val/OpBaseVal.js.map +1 -0
- package/dist/val/OpenFuncVal.d.ts +11 -0
- package/dist/val/OpenFuncVal.js +30 -0
- package/dist/val/OpenFuncVal.js.map +1 -0
- package/dist/val/PathFuncVal.d.ts +13 -0
- package/dist/val/PathFuncVal.js +42 -0
- package/dist/val/PathFuncVal.js.map +1 -0
- package/dist/val/PlusOpVal.d.ts +16 -0
- package/dist/val/PlusOpVal.js +59 -0
- package/dist/val/PlusOpVal.js.map +1 -0
- package/dist/val/PrefFuncVal.d.ts +11 -0
- package/dist/val/PrefFuncVal.js +39 -0
- package/dist/val/PrefFuncVal.js.map +1 -0
- package/dist/val/PrefVal.d.ts +15 -0
- package/dist/val/PrefVal.js +104 -0
- package/dist/val/PrefVal.js.map +1 -0
- package/dist/val/RefVal.d.ts +22 -0
- package/dist/val/RefVal.js +276 -0
- package/dist/val/RefVal.js.map +1 -0
- package/dist/val/ScalarKindVal.d.ts +16 -0
- package/dist/val/ScalarKindVal.js +76 -0
- package/dist/val/ScalarKindVal.js.map +1 -0
- package/dist/val/ScalarVal.d.ts +16 -0
- package/dist/val/ScalarVal.js +61 -0
- package/dist/val/ScalarVal.js.map +1 -0
- package/dist/val/StringVal.d.ts +10 -0
- package/dist/val/StringVal.js +19 -0
- package/dist/val/StringVal.js.map +1 -0
- package/dist/val/SuperFuncVal.d.ts +11 -0
- package/dist/val/SuperFuncVal.js +22 -0
- package/dist/val/SuperFuncVal.js.map +1 -0
- package/dist/val/TopVal.d.ts +16 -0
- package/dist/val/TopVal.js +38 -0
- package/dist/val/TopVal.js.map +1 -0
- package/dist/val/TypeFuncVal.d.ts +12 -0
- package/dist/val/TypeFuncVal.js +35 -0
- package/dist/val/TypeFuncVal.js.map +1 -0
- package/dist/val/UpperFuncVal.d.ts +12 -0
- package/dist/val/UpperFuncVal.js +40 -0
- package/dist/val/UpperFuncVal.js.map +1 -0
- package/dist/val/Val.d.ts +89 -0
- package/dist/val/Val.js +186 -0
- package/dist/val/Val.js.map +1 -0
- package/dist/val/VarVal.d.ts +13 -0
- package/dist/val/VarVal.js +109 -0
- package/dist/val/VarVal.js.map +1 -0
- package/dist/val/top.d.ts +2 -0
- package/dist/val/top.js +10 -0
- package/dist/val/top.js.map +1 -0
- package/dist/val/valutil.d.ts +2 -0
- package/dist/val/valutil.js +30 -0
- package/dist/val/valutil.js.map +1 -0
- package/package.json +3 -5
- package/src/aontu.ts +218 -0
- package/src/ctx.ts +201 -0
- package/src/err.ts +172 -0
- package/src/hints.ts +119 -0
- package/src/lang.ts +782 -0
- package/src/site.ts +34 -0
- package/src/tsconfig.json +16 -0
- package/src/type.ts +72 -0
- package/src/unify.ts +225 -0
- package/src/utility.ts +179 -0
- package/src/val/BagVal.ts +33 -0
- package/src/val/BooleanVal.ts +32 -0
- package/src/val/CloseFuncVal.ts +61 -0
- package/src/val/ConjunctVal.ts +285 -0
- package/src/val/CopyFuncVal.ts +69 -0
- package/src/val/DisjunctVal.ts +288 -0
- package/src/val/FeatureVal.ts +56 -0
- package/src/val/FuncBaseVal.ts +198 -0
- package/src/val/HideFuncVal.ts +85 -0
- package/src/val/IntegerVal.ts +75 -0
- package/src/val/JunctionVal.ts +54 -0
- package/src/val/KeyFuncVal.ts +67 -0
- package/src/val/ListVal.ts +286 -0
- package/src/val/LowerFuncVal.ts +73 -0
- package/src/val/MapVal.ts +316 -0
- package/src/val/MoveFuncVal.ts +79 -0
- package/src/val/NilVal.ts +156 -0
- package/src/val/NullVal.ts +38 -0
- package/src/val/NumberVal.ts +75 -0
- package/src/val/OpBaseVal.ts +231 -0
- package/src/val/OpenFuncVal.ts +60 -0
- package/src/val/PathFuncVal.ts +75 -0
- package/src/val/PlusOpVal.ts +92 -0
- package/src/val/PrefFuncVal.ts +73 -0
- package/src/val/PrefVal.ts +159 -0
- package/src/val/RefVal.ts +384 -0
- package/src/val/ScalarKindVal.ts +125 -0
- package/src/val/ScalarVal.ts +105 -0
- package/src/val/StringVal.ts +37 -0
- package/src/val/SuperFuncVal.ts +46 -0
- package/src/val/TopVal.ts +69 -0
- package/src/val/TypeFuncVal.ts +69 -0
- package/src/val/UpperFuncVal.ts +72 -0
- package/src/val/Val.ts +294 -0
- package/src/val/VarVal.ts +171 -0
- package/src/val/top.ts +12 -0
- package/src/val/valutil.ts +31 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 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 { AontuContext } from '../ctx'
|
|
14
|
+
import { unite } from '../unify'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
propagateMarks,
|
|
19
|
+
ec,
|
|
20
|
+
explainClose,
|
|
21
|
+
explainOpen,
|
|
22
|
+
} from '../utility'
|
|
23
|
+
|
|
24
|
+
import { makeNilErr, AontuError } from '../err'
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
top
|
|
28
|
+
} from './top'
|
|
29
|
+
|
|
30
|
+
import { NilVal } from '../val/NilVal'
|
|
31
|
+
import { ConjunctVal } from '../val/ConjunctVal'
|
|
32
|
+
import { FeatureVal } from '../val/FeatureVal'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class FuncBaseVal extends FeatureVal {
|
|
36
|
+
isFunc = true
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
spec: ValSpec,
|
|
40
|
+
ctx?: AontuContext
|
|
41
|
+
) {
|
|
42
|
+
super(spec, ctx)
|
|
43
|
+
// console.log('FBV', this.id, this.constructor.name, this.peg?.[0]?.canon)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
validateArgs(args: Val[], min: number) {
|
|
48
|
+
if (min < args.length) {
|
|
49
|
+
// TODO: this is an error as as a parse error, needs to be handled same way
|
|
50
|
+
throw new AontuError('The ' + this.funcname() + ' function needs at least ' +
|
|
51
|
+
min + ' argument' + (1 === min ? '' : 's') + '.')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
make(ctx: AontuContext, _spec: ValSpec): Val {
|
|
57
|
+
return makeNilErr(ctx, 'func:' + this.funcname(), this, undefined, 'make')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
unify(peer: Val, ctx: AontuContext): Val {
|
|
62
|
+
const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Func:' + this.funcname(), this, peer)
|
|
63
|
+
|
|
64
|
+
// const sc = this.id + '=' + this.canon
|
|
65
|
+
// const pc = peer.id + '=' + peer.canon
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
let why = ''
|
|
69
|
+
let out: Val = this
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
// console.log('FBV', this.id, this.constructor.name, this.mark.type, this.peg?.canon, 'PEER', peer.id, peer.canon)
|
|
73
|
+
|
|
74
|
+
if (this.id !== peer.id) {
|
|
75
|
+
|
|
76
|
+
if (peer.isTop && (this.mark.type || this.mark.hide)) {
|
|
77
|
+
this.dc = DONE
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
else {
|
|
81
|
+
let pegdone = true
|
|
82
|
+
let newpeg: Val[] = []
|
|
83
|
+
let newtype = this.mark.type
|
|
84
|
+
let newhide = this.mark.hide
|
|
85
|
+
|
|
86
|
+
this.peg = this.prepare(ctx, this.peg)
|
|
87
|
+
|
|
88
|
+
for (let arg of this.peg) {
|
|
89
|
+
// console.log('FUNCBASE-UNIFY-PEG-A', arg.canon)
|
|
90
|
+
|
|
91
|
+
let newarg = arg
|
|
92
|
+
if (!arg.done) {
|
|
93
|
+
newarg = arg.unify(top(), ctx.clone({ explain: ec(te, 'ARG') }))
|
|
94
|
+
newtype = newtype || newarg.mark.type
|
|
95
|
+
newhide = newhide || newarg.mark.hide
|
|
96
|
+
// console.log('FUNCBASE-UNIFY-PEG-B', arg.canon, '->', newarg.canon)
|
|
97
|
+
}
|
|
98
|
+
pegdone &&= arg.done
|
|
99
|
+
newpeg.push(newarg)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// console.log('FUNCBASE-PEG', this.id, pegdone, this.peg.map((p: any) => p?.canon))
|
|
103
|
+
|
|
104
|
+
if (pegdone) {
|
|
105
|
+
const resolved = this.resolve(ctx, newpeg)
|
|
106
|
+
// console.log('FUNC-RESOLVED', ctx.cc, resolved?.canon)
|
|
107
|
+
|
|
108
|
+
out = resolved.done && peer.isTop ? resolved :
|
|
109
|
+
unite(ctx.clone({ explain: ec(te, 'PEG') }), resolved, peer, 'func-' + this.funcname() + '/' + this.id)
|
|
110
|
+
propagateMarks(this, out)
|
|
111
|
+
|
|
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
|
+
// TODO: make should handle this using ctx?
|
|
119
|
+
out.site.row = this.site.row
|
|
120
|
+
out.site.col = this.site.col
|
|
121
|
+
out.site.url = this.site.url
|
|
122
|
+
out.path = this.path
|
|
123
|
+
|
|
124
|
+
why += 'pegdone'
|
|
125
|
+
}
|
|
126
|
+
else if (peer.isTop) {
|
|
127
|
+
this.notdone()
|
|
128
|
+
out = this.make(ctx, { peg: newpeg, mark: { type: newtype, hide: newhide } })
|
|
129
|
+
|
|
130
|
+
// TODO: make should handle this using ctx?
|
|
131
|
+
out.site.row = this.site.row
|
|
132
|
+
out.site.col = this.site.col
|
|
133
|
+
out.site.url = this.site.url
|
|
134
|
+
out.path = this.path
|
|
135
|
+
|
|
136
|
+
why += 'top'
|
|
137
|
+
}
|
|
138
|
+
else if (peer.isNil) {
|
|
139
|
+
this.notdone()
|
|
140
|
+
out = peer
|
|
141
|
+
why += 'nil'
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.notdone()
|
|
145
|
+
out = new ConjunctVal({
|
|
146
|
+
peg: [this, peer], mark: { type: newtype, hide: newhide }
|
|
147
|
+
}, ctx)
|
|
148
|
+
|
|
149
|
+
// TODO: make should handle this using ctx?
|
|
150
|
+
out.site.row = this.site.row
|
|
151
|
+
out.site.col = this.site.col
|
|
152
|
+
out.site.url = this.site.url
|
|
153
|
+
out.path = this.path
|
|
154
|
+
|
|
155
|
+
why += 'defer'
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
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)
|
|
161
|
+
|
|
162
|
+
explainClose(te, out)
|
|
163
|
+
|
|
164
|
+
return out
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
get canon() {
|
|
170
|
+
return '' +
|
|
171
|
+
// (this.type ? '<type>' : '') +
|
|
172
|
+
// (this.done ? '<done>' : '') +
|
|
173
|
+
// (this.id + '=') +
|
|
174
|
+
this.funcname() + '(' + (this.peg.map((p: any) => p.canon).join(',')) + ')'
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
funcname() {
|
|
179
|
+
return 'func'
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
prepare(_ctx: AontuContext | undefined, args: Val[]): Val[] {
|
|
184
|
+
return args
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
resolve(ctx: AontuContext | undefined, _args: Val[]): Val {
|
|
189
|
+
return makeNilErr(ctx, 'func:' + this.funcname(), this, undefined, 'resolve')
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
export {
|
|
197
|
+
FuncBaseVal,
|
|
198
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
Val,
|
|
6
|
+
ValSpec,
|
|
7
|
+
} from '../type'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AontuContext,
|
|
11
|
+
} from '../ctx'
|
|
12
|
+
|
|
13
|
+
import { makeNilErr } from '../err'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
walk,
|
|
18
|
+
explainOpen,
|
|
19
|
+
explainClose,
|
|
20
|
+
} from '../utility'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
import { FuncBaseVal } from './FuncBaseVal'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class HideFuncVal extends FuncBaseVal {
|
|
27
|
+
isHideFunc = true
|
|
28
|
+
|
|
29
|
+
resolved?: Val
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
spec: ValSpec,
|
|
33
|
+
ctx?: AontuContext
|
|
34
|
+
) {
|
|
35
|
+
super(spec, ctx)
|
|
36
|
+
|
|
37
|
+
// The function does not mark itself!
|
|
38
|
+
this.mark.type = false
|
|
39
|
+
this.mark.hide = false
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
make(_ctx: AontuContext, spec: ValSpec): Val {
|
|
44
|
+
return new HideFuncVal(spec)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
funcname() {
|
|
48
|
+
return 'hide'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
/*
|
|
53
|
+
unify(peer: Val, ctx: AontuContext): Val {
|
|
54
|
+
const te = ctx.explain && explainOpen(ctx, ctx.explain, 'HideFunc', this, peer)
|
|
55
|
+
let out: Val | undefined = this.resolved
|
|
56
|
+
|
|
57
|
+
if (null == out) {
|
|
58
|
+
out = this.resolve(ctx, this.peg)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
explainClose(te, out)
|
|
62
|
+
return out
|
|
63
|
+
}
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
resolve(ctx: AontuContext, args: Val[]) {
|
|
68
|
+
let out = args[0] ?? makeNilErr(ctx, 'arg', this)
|
|
69
|
+
if (!out.isNil) {
|
|
70
|
+
out = out.clone(ctx)
|
|
71
|
+
|
|
72
|
+
walk(out, (_key: string | number | undefined, val: Val) => {
|
|
73
|
+
val.mark.hide = true
|
|
74
|
+
return val
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return out
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
HideFuncVal,
|
|
85
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2023 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Val,
|
|
5
|
+
ValSpec,
|
|
6
|
+
} from '../type'
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
AontuContext,
|
|
10
|
+
} from '../ctx'
|
|
11
|
+
|
|
12
|
+
import { makeNilErr, AontuError } from '../err'
|
|
13
|
+
|
|
14
|
+
import { ScalarVal } from './ScalarVal'
|
|
15
|
+
import { Integer } from './ScalarKindVal'
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
explainOpen,
|
|
19
|
+
ec,
|
|
20
|
+
explainClose,
|
|
21
|
+
} from '../utility'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class IntegerVal extends ScalarVal {
|
|
25
|
+
isInteger = true
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
spec: ValSpec,
|
|
29
|
+
ctx?: AontuContext
|
|
30
|
+
) {
|
|
31
|
+
if (!Number.isInteger(spec.peg)) {
|
|
32
|
+
// TODO: use Nil?
|
|
33
|
+
throw new AontuError('not-integer: ' + spec.peg)
|
|
34
|
+
}
|
|
35
|
+
// super({ peg: spec.peg, kind: Integer }, ctx)
|
|
36
|
+
super({ ...spec, kind: Integer }, ctx)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
unify(peer: any, ctx: AontuContext): Val {
|
|
40
|
+
const te = ctx.explain && explainOpen(ctx, ctx.explain, 'Integer', this, peer)
|
|
41
|
+
|
|
42
|
+
let out: Val = this
|
|
43
|
+
|
|
44
|
+
if (null != peer) {
|
|
45
|
+
if (peer.isScalarKind) {
|
|
46
|
+
out = peer.unify(this, ctx.clone({ explain: ec(te, 'KND') }))
|
|
47
|
+
}
|
|
48
|
+
else if (
|
|
49
|
+
peer.isScalar &&
|
|
50
|
+
peer.peg === this.peg
|
|
51
|
+
) {
|
|
52
|
+
out = this
|
|
53
|
+
}
|
|
54
|
+
else if (peer.isTop) {
|
|
55
|
+
out = this
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
out = makeNilErr(ctx, 'scalar_' +
|
|
59
|
+
((peer as any).kind === this.kind ? 'value' : 'kind'), this, peer)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
out = super.unify(peer, ctx)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
explainClose(te, out)
|
|
67
|
+
|
|
68
|
+
return out
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
IntegerVal,
|
|
75
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
Val,
|
|
6
|
+
ValSpec,
|
|
7
|
+
} from '../type'
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
AontuContext,
|
|
11
|
+
} from '../ctx'
|
|
12
|
+
|
|
13
|
+
import { FeatureVal } from './FeatureVal'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// Abstract base class for binary operations that work with arrays of Val objects
|
|
17
|
+
// (ConjunctVal and DisjunctVal)
|
|
18
|
+
abstract class JunctionVal extends FeatureVal {
|
|
19
|
+
isJunction = true
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
spec: ValSpec,
|
|
23
|
+
ctx?: AontuContext
|
|
24
|
+
) {
|
|
25
|
+
super(spec, ctx)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// NOTE: mutation!
|
|
29
|
+
append(peer: Val): JunctionVal {
|
|
30
|
+
this.peg.push(peer)
|
|
31
|
+
return this
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
clone(ctx: AontuContext, spec?: ValSpec): Val {
|
|
35
|
+
let out = (super.clone(ctx, spec) as JunctionVal)
|
|
36
|
+
out.peg = this.peg.map((entry: Val) => entry.clone(ctx, spec?.mark ? { mark: spec.mark } : {}))
|
|
37
|
+
return out
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get canon() {
|
|
41
|
+
return this.peg.map((v: Val) => {
|
|
42
|
+
return (v as any).isJunction && Array.isArray(v.peg) && 1 < v.peg.length ?
|
|
43
|
+
'(' + v.canon + ')' : v.canon
|
|
44
|
+
}).join(this.getJunctionSymbol())
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Abstract method to be implemented by subclasses to define their junction symbol
|
|
48
|
+
abstract getJunctionSymbol(): string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
JunctionVal,
|
|
54
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* Copyright (c) 2021-2025 Richard Rodger, MIT License */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
Val,
|
|
7
|
+
ValSpec,
|
|
8
|
+
} from '../type'
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
AontuContext,
|
|
12
|
+
} from '../ctx'
|
|
13
|
+
|
|
14
|
+
import { StringVal } from '../val/StringVal'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import { FuncBaseVal } from './FuncBaseVal'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class KeyFuncVal extends FuncBaseVal {
|
|
22
|
+
isKeyFunc = true
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
spec: ValSpec,
|
|
26
|
+
ctx?: AontuContext
|
|
27
|
+
) {
|
|
28
|
+
super(spec, ctx)
|
|
29
|
+
// this.dc = DONE
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
make(_ctx: AontuContext, spec: ValSpec): Val {
|
|
34
|
+
return new KeyFuncVal(spec)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
funcname() {
|
|
38
|
+
return 'key'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
resolve(_ctx: AontuContext, _args: Val[]) {
|
|
44
|
+
let out: Val = this
|
|
45
|
+
|
|
46
|
+
if (!this.mark.type && !this.mark.hide) {
|
|
47
|
+
let move = this.peg?.[0]?.peg
|
|
48
|
+
move = isNaN(move) ? 1 : +move
|
|
49
|
+
const key = this.path[this.path.length - (1 + move)] ?? ''
|
|
50
|
+
|
|
51
|
+
out = new StringVal({ peg: key })
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return out
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
gen(_ctx: AontuContext): any {
|
|
59
|
+
return undefined
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
KeyFuncVal,
|
|
67
|
+
}
|