theprogrammablemind_4wp 9.6.3-beta.24 → 9.6.3-beta.25

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/package.json CHANGED
@@ -73,6 +73,6 @@
73
73
  "scriptjs": "^2.5.9",
74
74
  "uuid": "^8.3.2"
75
75
  },
76
- "version": "9.6.3-beta.24",
76
+ "version": "9.6.3-beta.25",
77
77
  "license": "UNLICENSED"
78
78
  }
@@ -86,6 +86,30 @@ const cleanAssign = (dest, ...srcs) => {
86
86
  Object.assign(dest, ...srcs)
87
87
  }
88
88
 
89
+ // handler is a semantic or a generator
90
+ class HandlerStack {
91
+ constructor(handlers = []) {
92
+ this.handlers = [...handlers]
93
+ }
94
+
95
+ push(handler) {
96
+ this.handlers.push(handler)
97
+ }
98
+
99
+ pop() {
100
+ this.handlers.pop()
101
+ }
102
+
103
+ toString() {
104
+ let str = ''
105
+ for (let i = this.handlers.length - 1; i >= 0; --i) {
106
+ str += this.handlers[i].toLabel() + '\n'
107
+ str += this.handlers[i].toString() + '\n\n'
108
+ }
109
+ return str
110
+ }
111
+ }
112
+
89
113
  class ContextHierarchy {
90
114
  constructor(contexts = []) {
91
115
  this.contexts = [...contexts]
@@ -139,6 +163,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
139
163
  }
140
164
  }
141
165
  args.contextHierarchy = new ContextHierarchy()
166
+ args.handlerStack = new HandlerStack()
142
167
  args.cleanAssign = cleanAssign
143
168
  args.km = (name) => config.getConfig(name)
144
169
  args.api = (name) => config.getConfig(name).api
@@ -591,4 +616,5 @@ module.exports = {
591
616
  loadInstance,
592
617
  isA,
593
618
  ContextHierarchy,
619
+ HandlerStack,
594
620
  }
package/src/semantics.js CHANGED
@@ -103,7 +103,13 @@ class Semantic {
103
103
  if (args.breakOnSemantics) {
104
104
  debugger // eslint-disable-line no-debugger
105
105
  }
106
- await this._apply(args)
106
+ try {
107
+ args.handlerStack.push(this)
108
+ await this._apply(args)
109
+ args.handlerStack.pop()
110
+ } catch( e ) {
111
+ args.handlerStack.pop()
112
+ }
107
113
  return contextPrime
108
114
  }
109
115
  }