greybel-interpreter 3.1.0 → 3.1.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.
@@ -36,9 +36,11 @@ export declare class Interpreter extends EventEmitter {
36
36
  setDebugger(dbgr: Debugger): Interpreter;
37
37
  setApi(newApi: ObjectValue): Interpreter;
38
38
  setHandler(handler: HandlerContainer): Interpreter;
39
+ parse(code: string): import("miniscript-core").ASTBase | import("greybel-core").ASTChunkAdvanced;
39
40
  prepare(code: string): Promise<Operation>;
40
41
  inject(code: string, context?: OperationContext): Promise<Interpreter>;
41
42
  injectInLastContext(code: string): Promise<Interpreter>;
43
+ createCPS(): CPS;
42
44
  private initScopes;
43
45
  private start;
44
46
  run({ customCode, ctxOptions }?: InterpreterRunOptions): Promise<Interpreter>;
@@ -68,10 +68,13 @@ class Interpreter extends events_1.EventEmitter {
68
68
  this.handler = handler;
69
69
  return this;
70
70
  }
71
+ parse(code) {
72
+ const parser = new greybel_core_1.Parser(code);
73
+ return parser.parseChunk();
74
+ }
71
75
  prepare(code) {
72
76
  try {
73
- const parser = new greybel_core_1.Parser(code);
74
- const chunk = parser.parseChunk();
77
+ const chunk = this.parse(code);
75
78
  return this.cps.visit(chunk);
76
79
  }
77
80
  catch (err) {
@@ -118,9 +121,12 @@ class Interpreter extends events_1.EventEmitter {
118
121
  throw new Error('Unable to inject into last context.');
119
122
  });
120
123
  }
121
- initScopes(ctxOptions) {
124
+ createCPS() {
122
125
  const cpsCtx = new cps_1.CPSContext(this.target, this.handler);
123
- this.cps = new cps_1.CPS(cpsCtx);
126
+ return new cps_1.CPS(cpsCtx);
127
+ }
128
+ initScopes(ctxOptions) {
129
+ this.cps = this.createCPS();
124
130
  const apiContext = new context_1.OperationContext(Object.assign({ target: this.target, isProtected: true, debugger: this.debugger, handler: this.handler, cps: this.cps, environmentVariables: this.environmentVariables, contextTypeIntrinsics: {
125
131
  string: string_1.CustomString.getIntrinsics().fork(),
126
132
  number: number_1.CustomNumber.getIntrinsics().fork(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",