theprogrammablemind_4wp 7.10.0-beta.15 → 7.10.0-beta.17
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +256 -259
- package/demo.js +24 -24
- package/lines.js +2 -2
- package/package.json +1 -1
- package/runtime.js +12 -12
- package/src/config.js +233 -239
- package/src/digraph.js +9 -9
- package/src/digraph_internal.js +6 -6
- package/src/flatten.js +1 -1
- package/src/generators.js +41 -43
- package/src/helpers.js +57 -58
- package/src/project.js +6 -8
- package/src/semantics.js +40 -42
- package/src/unflatten.js +7 -7
package/src/digraph.js
CHANGED
@@ -14,7 +14,7 @@ class Digraph {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
// BFS
|
17
|
-
path(from, to) {
|
17
|
+
path (from, to) {
|
18
18
|
debugger
|
19
19
|
const frontier = { [from]: [[]] }
|
20
20
|
const done = new Set()
|
@@ -29,12 +29,12 @@ class Digraph {
|
|
29
29
|
continue
|
30
30
|
}
|
31
31
|
done.add(n)
|
32
|
-
for (
|
32
|
+
for (const edge of this._edges) {
|
33
33
|
if (edge.child == n) {
|
34
34
|
if (!frontier[edge.parent]) {
|
35
35
|
frontier[edge.parent] = []
|
36
36
|
}
|
37
|
-
for (
|
37
|
+
for (const path of ps) {
|
38
38
|
if (edge.parent == to) {
|
39
39
|
return [...path, edge]
|
40
40
|
}
|
@@ -45,26 +45,26 @@ class Digraph {
|
|
45
45
|
}
|
46
46
|
}
|
47
47
|
|
48
|
-
addEdges(edges) {
|
49
|
-
for (
|
48
|
+
addEdges (edges) {
|
49
|
+
for (const edge of edges) {
|
50
50
|
this.addEdge(edge)
|
51
51
|
}
|
52
52
|
}
|
53
53
|
|
54
|
-
addEdge(edge) {
|
54
|
+
addEdge (edge) {
|
55
55
|
edge = toA(edge)
|
56
56
|
this._edges.push(edge)
|
57
57
|
}
|
58
58
|
|
59
|
-
get edges() {
|
59
|
+
get edges () {
|
60
60
|
return this._edges
|
61
61
|
}
|
62
62
|
|
63
|
-
set edges(edges) {
|
63
|
+
set edges (edges) {
|
64
64
|
this._edges = edges
|
65
65
|
}
|
66
66
|
|
67
|
-
/*
|
67
|
+
/*
|
68
68
|
set edges(edges) {
|
69
69
|
this._edges = edges.map( toA )
|
70
70
|
}
|
package/src/digraph_internal.js
CHANGED
@@ -13,26 +13,26 @@ class DigraphInternal {
|
|
13
13
|
this._edges = edges
|
14
14
|
}
|
15
15
|
|
16
|
-
addEdges(edges) {
|
17
|
-
for (
|
16
|
+
addEdges (edges) {
|
17
|
+
for (const edge of edges) {
|
18
18
|
this.addEdge(edge)
|
19
19
|
}
|
20
20
|
}
|
21
21
|
|
22
|
-
addEdge(edge) {
|
22
|
+
addEdge (edge) {
|
23
23
|
edge = toA(edge)
|
24
24
|
this._edges.push(edge)
|
25
25
|
}
|
26
26
|
|
27
|
-
get edges() {
|
27
|
+
get edges () {
|
28
28
|
return this._edges
|
29
29
|
}
|
30
30
|
|
31
|
-
set edges(edges) {
|
31
|
+
set edges (edges) {
|
32
32
|
this._edges = edges
|
33
33
|
}
|
34
34
|
|
35
|
-
/*
|
35
|
+
/*
|
36
36
|
set edges(edges) {
|
37
37
|
this._edges = edges.map( toA )
|
38
38
|
}
|
package/src/flatten.js
CHANGED
@@ -93,7 +93,7 @@ const flatten = (markers, value) => {
|
|
93
93
|
if (split) {
|
94
94
|
if ('value' in properties) {
|
95
95
|
flattenedValues = []
|
96
|
-
for (
|
96
|
+
for (const v of properties.value) {
|
97
97
|
if (v.flatten) {
|
98
98
|
flattenedValues = flattenedValues.concat(flatten(markers, v)[0])
|
99
99
|
} else {
|
package/src/generators.js
CHANGED
@@ -50,24 +50,23 @@ class Generator {
|
|
50
50
|
}
|
51
51
|
// return this.match({ ...args, args: contextArgs(context, hierarchy), objects, global: objects, hierarchy, context, api: this.getAPI(config) })
|
52
52
|
const callId = baseArgs.calls.current()
|
53
|
-
const moreArgs = {
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
53
|
+
const moreArgs = {
|
54
|
+
uuid: this.uuid,
|
55
|
+
args: contextArgs(context, hierarchy),
|
56
|
+
objects,
|
57
|
+
global: objects,
|
58
|
+
// hierarchy,
|
59
|
+
context,
|
60
|
+
callId,
|
61
|
+
api: this.getAPI(config),
|
62
|
+
apis: this.getAPIs(config)
|
63
|
+
}
|
64
64
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
65
65
|
// return this.match(args)
|
66
66
|
const matches = this.match(args)
|
67
|
-
if ((matches && (options.debug || {}).match)
|
68
|
-
||
|
67
|
+
if ((matches && (options.debug || {}).match) ||
|
69
68
|
callId == this.callId) {
|
70
|
-
debugger
|
69
|
+
debugger // next line is the matcher
|
71
70
|
this.match(args)
|
72
71
|
}
|
73
72
|
return matches
|
@@ -83,7 +82,7 @@ class Generator {
|
|
83
82
|
}
|
84
83
|
|
85
84
|
if (config && config.debugLoops) {
|
86
|
-
console.log(
|
85
|
+
console.log('apply', this.toLabel())
|
87
86
|
}
|
88
87
|
// this.getAPI(config)
|
89
88
|
let n = (id) => id
|
@@ -95,26 +94,26 @@ class Generator {
|
|
95
94
|
}
|
96
95
|
const km = (name) => config.getConfig(name)
|
97
96
|
const callId = baseArgs.calls.current()
|
98
|
-
const moreArgs = {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
objects,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
97
|
+
const moreArgs = {
|
98
|
+
callId,
|
99
|
+
uuid: this.uuid,
|
100
|
+
// km,
|
101
|
+
args: contextArgs(context, hierarchy),
|
102
|
+
objects,
|
103
|
+
log,
|
104
|
+
global:
|
105
|
+
objects,
|
106
|
+
// g,
|
107
|
+
n,
|
108
|
+
hierarchy,
|
109
|
+
context,
|
110
|
+
uuid: this.uuid,
|
111
|
+
// gs,
|
112
|
+
config,
|
113
|
+
response,
|
114
|
+
api: this.getAPI(config),
|
115
|
+
apis: this.getAPIs(config)
|
116
|
+
}
|
118
117
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
119
118
|
if (this.property == 'generatorp') {
|
120
119
|
args.g = args.gp
|
@@ -126,8 +125,7 @@ class Generator {
|
|
126
125
|
debugger;
|
127
126
|
}
|
128
127
|
*/
|
129
|
-
if ((options.debug || {}).apply
|
130
|
-
||
|
128
|
+
if ((options.debug || {}).apply ||
|
131
129
|
callId == this.callId) {
|
132
130
|
debugger
|
133
131
|
}
|
@@ -169,7 +167,7 @@ class Generators {
|
|
169
167
|
// assumed - properties added to context before the generators are called. For setting paraphrase property
|
170
168
|
apply (args, context, assumed = {}, options = {}) {
|
171
169
|
if (Array.isArray(context)) {
|
172
|
-
throw new Error(
|
170
|
+
throw new Error('Expected a context not an array')
|
173
171
|
}
|
174
172
|
if (typeof context !== 'object') {
|
175
173
|
return String(context)
|
@@ -179,9 +177,9 @@ class Generators {
|
|
179
177
|
const objects = args.objects
|
180
178
|
const hierarchy = args.hierarchy
|
181
179
|
const response = args.response
|
182
|
-
|
180
|
+
|
183
181
|
// args = { ...args, ...args.getAssumedScoped(assumed) }
|
184
|
-
args.addAssumedScoped(args, assumed)
|
182
|
+
args.addAssumedScoped(args, assumed)
|
185
183
|
context = Object.assign({}, context, args.assumed)
|
186
184
|
let generated = ''
|
187
185
|
let applied = false
|
@@ -193,8 +191,8 @@ class Generators {
|
|
193
191
|
// this.logs.push(`Generators: applied ${generator.toString()}\n to\n ${JSON.stringify(context)}`)
|
194
192
|
let errorMessage = 'The apply function did not return a value'
|
195
193
|
try {
|
196
|
-
generated= generator.apply(args, objects, context, hierarchy, config, response, log)
|
197
|
-
} catch(
|
194
|
+
generated = generator.apply(args, objects, context, hierarchy, config, response, log)
|
195
|
+
} catch (e) {
|
198
196
|
// the next if handle this
|
199
197
|
generated = null
|
200
198
|
e.retryCall = () => generator.apply(args, objects, context, hierarchy, config, response, log)
|
@@ -283,7 +281,7 @@ class Generators {
|
|
283
281
|
lines.setElement(0, 2, JSON.stringify(context, null, 2))
|
284
282
|
this.logs.push(lines.toString())
|
285
283
|
}
|
286
|
-
return ((config || {}).parenthesized ?
|
284
|
+
return ((config || {}).parenthesized ? '(' + generated + ')' : generated)
|
287
285
|
}
|
288
286
|
}
|
289
287
|
|
package/src/helpers.js
CHANGED
@@ -69,7 +69,7 @@ const safeEquals = (v1, v2) => {
|
|
69
69
|
if (v1.length != v2.length) {
|
70
70
|
return false
|
71
71
|
}
|
72
|
-
for (
|
72
|
+
for (const key in v1) {
|
73
73
|
if (!safeEquals(v1[key], v2[key])) {
|
74
74
|
return false
|
75
75
|
}
|
@@ -183,72 +183,71 @@ const isCompound = (value) => {
|
|
183
183
|
}
|
184
184
|
|
185
185
|
class InitCalls {
|
186
|
-
|
187
|
-
constructor(name) {
|
186
|
+
constructor (name) {
|
188
187
|
this.nextCallId = 0
|
189
188
|
this.nextContextId = 0
|
190
189
|
this.stack = []
|
191
190
|
this.name = name
|
192
191
|
}
|
193
192
|
|
194
|
-
start() {
|
193
|
+
start () {
|
195
194
|
return this.nextCallId
|
196
195
|
}
|
197
196
|
|
198
|
-
next() {
|
197
|
+
next () {
|
199
198
|
// this.nextContextId += 1
|
200
199
|
this.nextContextId += 1
|
201
200
|
}
|
202
201
|
|
203
|
-
push() {
|
202
|
+
push () {
|
204
203
|
this.nextCallId += 1
|
205
204
|
// this.nextCallId += 1
|
206
205
|
// this.stack.push(this.nextCallId)
|
207
206
|
this.stack.push(this.nextCallId)
|
208
207
|
// TODO put the nextContextId in the context for debugging
|
209
|
-
const calls = this.stack.map(
|
208
|
+
const calls = this.stack.map((call) => `${this.name}#call${call}`)
|
210
209
|
// return `Context#${this.nextContextId}: ${calls}`
|
211
210
|
return `Context#${this.nextContextId}: ${calls}`
|
212
211
|
}
|
213
212
|
|
214
|
-
current() {
|
215
|
-
return `${this.name}#call${this.stack[this.stack.length-1]}`
|
213
|
+
current () {
|
214
|
+
return `${this.name}#call${this.stack[this.stack.length - 1]}`
|
216
215
|
}
|
217
216
|
|
218
|
-
touch(context) {
|
217
|
+
touch (context) {
|
219
218
|
if (!context.touchedBy) {
|
220
219
|
context.touchedBy = []
|
221
220
|
}
|
222
|
-
if (!context.touchedBy.includes(
|
223
|
-
context.touchedBy.push(
|
221
|
+
if (!context.touchedBy.includes(this.current())) {
|
222
|
+
context.touchedBy.push(this.current())
|
224
223
|
}
|
225
224
|
}
|
226
225
|
|
227
|
-
pop() {
|
226
|
+
pop () {
|
228
227
|
this.stack.pop()
|
229
228
|
}
|
230
229
|
}
|
231
230
|
|
232
231
|
const hashCode = (str) => {
|
233
|
-
|
234
|
-
if (str.length === 0) return hash
|
232
|
+
let hash = 0; let i; let ch
|
233
|
+
if (str.length === 0) return hash
|
235
234
|
for (i = 0; i < str.length; i++) {
|
236
|
-
ch
|
237
|
-
hash
|
238
|
-
hash |= 0
|
235
|
+
ch = str.charCodeAt(i)
|
236
|
+
hash = ((hash << 5) - hash) + ch
|
237
|
+
hash |= 0 // Convert to 32bit integer
|
239
238
|
}
|
240
|
-
return hash
|
241
|
-
}
|
239
|
+
return hash
|
240
|
+
}
|
242
241
|
|
243
242
|
const sortJson = (json) => {
|
244
243
|
return json
|
245
244
|
}
|
246
245
|
|
247
246
|
const validProps = (valids, object, type) => {
|
248
|
-
for (
|
247
|
+
for (const prop of Object.keys(object)) {
|
249
248
|
let okay = false
|
250
249
|
for (valid of valids) {
|
251
|
-
if (typeof valid
|
250
|
+
if (typeof valid === 'string') {
|
252
251
|
okay = prop == valid
|
253
252
|
} else {
|
254
253
|
okay = prop.match(valid)
|
@@ -265,14 +264,14 @@ const validProps = (valids, object, type) => {
|
|
265
264
|
|
266
265
|
const mapInPlace = (list, fn) => {
|
267
266
|
for (let i = 0; i < list.length; ++i) {
|
268
|
-
list[i] =fn(list[i])
|
267
|
+
list[i] = fn(list[i])
|
269
268
|
}
|
270
269
|
}
|
271
270
|
|
272
271
|
const updateQueries = (queryOrConfig) => {
|
273
|
-
if (typeof queryOrConfig
|
272
|
+
if (typeof queryOrConfig === 'string' || queryOrConfig.query) {
|
274
273
|
return queryOrConfig
|
275
|
-
} else if (typeof queryOrConfig
|
274
|
+
} else if (typeof queryOrConfig === 'function') {
|
276
275
|
return { apply: queryOrConfig.toString() }
|
277
276
|
} else {
|
278
277
|
const config = queryOrConfig
|
@@ -281,34 +280,34 @@ const updateQueries = (queryOrConfig) => {
|
|
281
280
|
}
|
282
281
|
|
283
282
|
const functionsToStrings = (config) => {
|
284
|
-
config = {...config}
|
283
|
+
config = { ...config }
|
285
284
|
const mapGenerator = (generator) => {
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
}
|
285
|
+
if (generator.apply) {
|
286
|
+
return { ...generator, match: generator.match.toString(), apply: generator.apply.toString() }
|
287
|
+
} else {
|
288
|
+
return [generator[0].toString(), generator[1].toString()]
|
291
289
|
}
|
290
|
+
}
|
292
291
|
if (config.generators) {
|
293
|
-
config.generators = config.generators.map(
|
292
|
+
config.generators = config.generators.map(mapGenerator)
|
294
293
|
}
|
295
294
|
if (config.semantics) {
|
296
|
-
config.semantics = config.semantics.map(
|
295
|
+
config.semantics = config.semantics.map((semantic) => {
|
297
296
|
if (semantic.apply) {
|
298
297
|
return { ...semantic, match: semantic.match.toString(), apply: semantic.apply.toString() }
|
299
298
|
} else {
|
300
|
-
return [
|
299
|
+
return [semantic[0].toString(), semantic[1].toString()]
|
301
300
|
}
|
302
301
|
})
|
303
302
|
}
|
304
303
|
if (config.bridges) {
|
305
|
-
config.bridges = config.bridges.map(
|
306
|
-
bridge = {...bridge}
|
304
|
+
config.bridges = config.bridges.map((bridge) => {
|
305
|
+
bridge = { ...bridge }
|
307
306
|
if (bridge.generator) {
|
308
307
|
bridge.generator = bridge.generator.toString()
|
309
308
|
}
|
310
309
|
if (bridge.generators) {
|
311
|
-
bridge.generators = bridge.generators.map(
|
310
|
+
bridge.generators = bridge.generators.map(mapGenerator)
|
312
311
|
}
|
313
312
|
if (bridge.generatorp) {
|
314
313
|
bridge.generatorp = bridge.generatorp.toString()
|
@@ -331,7 +330,7 @@ const functionsToStrings = (config) => {
|
|
331
330
|
const ecatch = (where, call) => {
|
332
331
|
try {
|
333
332
|
return call()
|
334
|
-
} catch(
|
333
|
+
} catch (e) {
|
335
334
|
throw new Error(`${where} ${e.stack}`)
|
336
335
|
}
|
337
336
|
}
|
@@ -346,9 +345,9 @@ const subPriority = (sub, sup) => {
|
|
346
345
|
if (Array.isArray(sub)) {
|
347
346
|
const subChoosen = sub[0]
|
348
347
|
const subOther = sub[1]
|
349
|
-
const hasChoosen = sup.choose.find(
|
350
|
-
const hasOtherChosen = sup.choose.find(
|
351
|
-
const hasOther = sup.context.find(
|
348
|
+
const hasChoosen = sup.choose.find((index) => equalKey(sup.context[index], subChoosen)) != undefined
|
349
|
+
const hasOtherChosen = sup.choose.find((index) => equalKey(sup.context[index], subOther)) != undefined
|
350
|
+
const hasOther = sup.context.find((other) => equalKey(other, subOther)) !== undefined
|
352
351
|
return !!(hasChoosen && hasOther) && !hasOtherChosen
|
353
352
|
}
|
354
353
|
|
@@ -367,7 +366,7 @@ const subPriority = (sub, sup) => {
|
|
367
366
|
const chosen2 = choose(sup)
|
368
367
|
const sameId = (id1, id2) => id1[0] == id2[0] && id1[1] == id2[1]
|
369
368
|
// same length so only need one way
|
370
|
-
const missing1 = chosen1.find(
|
369
|
+
const missing1 = chosen1.find((id1) => !chosen2.find((id2) => sameId(id1, id2)))
|
371
370
|
if (missing1) {
|
372
371
|
return false
|
373
372
|
}
|
@@ -375,26 +374,26 @@ const subPriority = (sub, sup) => {
|
|
375
374
|
return true
|
376
375
|
}
|
377
376
|
|
378
|
-
module.exports = {
|
377
|
+
module.exports = {
|
379
378
|
ecatch,
|
380
379
|
functionsToStrings,
|
381
380
|
updateQueries,
|
382
381
|
mapInPlace,
|
383
|
-
validProps,
|
384
|
-
args,
|
382
|
+
validProps,
|
383
|
+
args,
|
385
384
|
safeNoDups,
|
386
|
-
safeEquals,
|
387
|
-
appendNoDups,
|
388
|
-
hashIndexesGet,
|
389
|
-
hashIndexesSet,
|
390
|
-
translationMapping,
|
391
|
-
normalizeGenerator,
|
392
|
-
normalizeSemantic,
|
393
|
-
isArray,
|
394
|
-
isObject,
|
395
|
-
isCompound,
|
396
|
-
InitCalls,
|
397
|
-
hashCode,
|
385
|
+
safeEquals,
|
386
|
+
appendNoDups,
|
387
|
+
hashIndexesGet,
|
388
|
+
hashIndexesSet,
|
389
|
+
translationMapping,
|
390
|
+
normalizeGenerator,
|
391
|
+
normalizeSemantic,
|
392
|
+
isArray,
|
393
|
+
isObject,
|
394
|
+
isCompound,
|
395
|
+
InitCalls,
|
396
|
+
hashCode,
|
398
397
|
sortJson,
|
399
|
-
subPriority
|
398
|
+
subPriority
|
400
399
|
}
|
package/src/project.js
CHANGED
@@ -4,7 +4,7 @@ const project = (object, filter) => {
|
|
4
4
|
return
|
5
5
|
}
|
6
6
|
|
7
|
-
|
7
|
+
const projection = {}
|
8
8
|
const set = (property, value) => {
|
9
9
|
if (value === null || value === undefined) {
|
10
10
|
return
|
@@ -13,13 +13,13 @@ const project = (object, filter) => {
|
|
13
13
|
}
|
14
14
|
if (Array.isArray(filter)) {
|
15
15
|
if (Array.isArray(object)) {
|
16
|
-
return object.map(
|
16
|
+
return object.map(element => project(element, filter))
|
17
17
|
} else {
|
18
18
|
for (let properties of filter) {
|
19
|
-
if (typeof properties
|
19
|
+
if (typeof properties === 'function') {
|
20
20
|
properties = properties(object)
|
21
21
|
}
|
22
|
-
if (typeof properties
|
22
|
+
if (typeof properties === 'object') {
|
23
23
|
if (properties.propertyLists) {
|
24
24
|
for (const propertyList in properties.propertyLists) {
|
25
25
|
if (object[propertyList]) {
|
@@ -28,7 +28,7 @@ const project = (object, filter) => {
|
|
28
28
|
}
|
29
29
|
}
|
30
30
|
}
|
31
|
-
}
|
31
|
+
}
|
32
32
|
if (properties.valueLists) {
|
33
33
|
for (const listProperty in properties.valueLists) {
|
34
34
|
const old = object[listProperty]
|
@@ -70,7 +70,7 @@ const project = (object, filter) => {
|
|
70
70
|
}
|
71
71
|
}
|
72
72
|
}
|
73
|
-
} else if (typeof filter
|
73
|
+
} else if (typeof filter === 'object') {
|
74
74
|
for (const property of Object.keys(filter)) {
|
75
75
|
set(property, project(object[property], filter[property]))
|
76
76
|
}
|
@@ -79,5 +79,3 @@ const project = (object, filter) => {
|
|
79
79
|
}
|
80
80
|
|
81
81
|
module.exports = { project }
|
82
|
-
|
83
|
-
|
package/src/semantics.js
CHANGED
@@ -25,7 +25,7 @@ class Semantic {
|
|
25
25
|
toLabel () {
|
26
26
|
const where = (this.where) ? `where: "${this.where}"` : ''
|
27
27
|
if (!this.km) {
|
28
|
-
return where
|
28
|
+
return where
|
29
29
|
}
|
30
30
|
return `KM '${this.km}' ordinal: ${this.index} ${where}`
|
31
31
|
}
|
@@ -55,24 +55,23 @@ class Semantic {
|
|
55
55
|
|
56
56
|
// return this.matcher(Object.assign({}, argsBase, {args: contextArgs(context, hierarchy), objects: objects, global: objects, context: context, hierarchy: hierarchy, api: this.getAPI(config)})
|
57
57
|
const callId = baseArgs.calls.current()
|
58
|
-
const moreArgs = {
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
58
|
+
const moreArgs = {
|
59
|
+
uuid: this.uuid,
|
60
|
+
args: contextArgs(context, hierarchy),
|
61
|
+
objects,
|
62
|
+
global: objects,
|
63
|
+
context: context,
|
64
|
+
// hierarchy: hierarchy,
|
65
|
+
callId,
|
66
|
+
api: this.getAPI(config),
|
67
|
+
apis: this.getAPIs(config)
|
68
|
+
}
|
69
69
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
70
70
|
|
71
71
|
const matches = this.matcher(args)
|
72
|
-
if (matches && (options.debug || {}).match
|
73
|
-
||
|
72
|
+
if (matches && (options.debug || {}).match ||
|
74
73
|
callId == this.callId) {
|
75
|
-
debugger
|
74
|
+
debugger // next line is the matcher
|
76
75
|
this.matcher(args)
|
77
76
|
}
|
78
77
|
return matches
|
@@ -82,7 +81,7 @@ class Semantic {
|
|
82
81
|
const { hierarchy, config, response } = baseArgs
|
83
82
|
const objects = baseArgs.getObjects(this.uuid)
|
84
83
|
if (config && config.debugLoops) {
|
85
|
-
console.log(
|
84
|
+
console.log('apply', this.toLabel())
|
86
85
|
}
|
87
86
|
if (baseArgs.calls && config && baseArgs.calls.stack.length > config.maxDepth) {
|
88
87
|
throw new Error(`Max depth of ${config.maxDepth} for calls has been exceeded. maxDepth can be set on the config object. To see the calls run with the --dl or set the debugLoops property on the config`)
|
@@ -99,26 +98,25 @@ class Semantic {
|
|
99
98
|
n = (id) => config.nsToString(id)
|
100
99
|
}
|
101
100
|
const callId = baseArgs.calls.current()
|
102
|
-
const moreArgs = {
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
101
|
+
const moreArgs = {
|
102
|
+
uuid: this.uuid,
|
103
|
+
callId,
|
104
|
+
args: contextArgs(context, hierarchy),
|
105
|
+
objects,
|
106
|
+
log,
|
107
|
+
global: objects,
|
108
|
+
n,
|
109
|
+
context: contextPrime,
|
110
|
+
uuid: this.uuid,
|
111
|
+
// config,
|
112
|
+
response,
|
113
|
+
api: this.getAPI(config),
|
114
|
+
apis: this.getAPIs(config)
|
116
115
|
}
|
117
116
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
118
|
-
if ((options.debug || {}).apply
|
119
|
-
||
|
117
|
+
if ((options.debug || {}).apply ||
|
120
118
|
callId == this.callId) {
|
121
|
-
debugger
|
119
|
+
debugger
|
122
120
|
}
|
123
121
|
if (args.breakOnSemantics) {
|
124
122
|
debugger
|
@@ -161,10 +159,10 @@ class Semantics {
|
|
161
159
|
this.calls = {}
|
162
160
|
};
|
163
161
|
|
164
|
-
getMostCalled() {
|
162
|
+
getMostCalled () {
|
165
163
|
let maxOrdinal = 0
|
166
164
|
let maxCounter = 0
|
167
|
-
for (
|
165
|
+
for (const ordinal in this.calls) {
|
168
166
|
const counter = this.calls[ordinal]
|
169
167
|
if (counter > maxCounter) {
|
170
168
|
maxOrdinal = ordinal
|
@@ -185,24 +183,24 @@ class Semantics {
|
|
185
183
|
const s = (context, options) => this.apply(args, context, options)
|
186
184
|
let applied = false
|
187
185
|
const stack = args.calls.push()
|
188
|
-
let counter = 0
|
186
|
+
let counter = 0
|
189
187
|
for (const isemantic in this.semantics) {
|
190
188
|
const semantic = this.semantics[isemantic]
|
191
189
|
if (!semantic) {
|
192
|
-
debugger
|
190
|
+
debugger
|
193
191
|
}
|
194
192
|
if (semantic.matches(args, context, options)) {
|
195
193
|
if (!this.calls[counter]) {
|
196
|
-
this.calls[counter] = 0
|
194
|
+
this.calls[counter] = 0
|
197
195
|
}
|
198
|
-
this.calls[counter] += 1
|
196
|
+
this.calls[counter] += 1
|
199
197
|
const log = (message) => { this.logs.push(message) }
|
200
198
|
try {
|
201
199
|
contextPrime = semantic.apply(args, context, s, log, options)
|
202
200
|
if (!contextPrime.controlKeepMotivation && semantic.oneShot) {
|
203
201
|
args.config.removeSemantic(semantic)
|
204
202
|
}
|
205
|
-
} catch(
|
203
|
+
} catch (e) {
|
206
204
|
contextPrime = null
|
207
205
|
let errorMessage
|
208
206
|
e.retryCall = () => semantic.apply(args, context, s, log, options)
|
@@ -214,8 +212,8 @@ class Semantics {
|
|
214
212
|
const info = `${semantic.notes ? semantic.notes : ''}${semantic.where ? semantic.where : ''}`
|
215
213
|
errorMessage = `Error applying semantics '${info}'. Error is ${e.error.join()}. Semantic is ${semantic.toString()}. ${help}`
|
216
214
|
} else {
|
217
|
-
errorMessage = e.toString()
|
218
|
-
|
215
|
+
errorMessage = e.toString()
|
216
|
+
}
|
219
217
|
|
220
218
|
const widths = [10, 10, 90]
|
221
219
|
const lines = new Lines(widths)
|