greybel-interpreter 1.6.4 → 1.6.5

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/context.d.ts CHANGED
@@ -63,6 +63,7 @@ export interface ContextOptions {
63
63
  handler?: HandlerContainer;
64
64
  cps?: CPS;
65
65
  processState?: ProcessState;
66
+ environmentVariables?: Map<string, string>;
66
67
  }
67
68
  export interface ContextForkOptions {
68
69
  type: ContextType;
@@ -74,6 +75,7 @@ export default class OperationContext {
74
75
  target: string;
75
76
  stackItem: ASTBase;
76
77
  debugger: Debugger;
78
+ environmentVariables: Map<string, string>;
77
79
  handler: HandlerContainer;
78
80
  previous: OperationContext;
79
81
  readonly type: ContextType;
package/dist/context.js CHANGED
@@ -146,6 +146,7 @@ class OperationContext {
146
146
  this.handler = options.handler || new handler_container_1.default();
147
147
  this.cps = options.cps || null;
148
148
  this.processState = options.processState || new ProcessState();
149
+ this.environmentVariables = options.environmentVariables || new Map();
149
150
  this.api = this.lookupApi();
150
151
  this.globals = this.lookupGlobals();
151
152
  this.locals = this.lookupLocals() || this;
@@ -286,7 +287,8 @@ class OperationContext {
286
287
  debugger: this.debugger,
287
288
  handler: this.handler,
288
289
  cps: this.cps,
289
- processState: this.processState
290
+ processState: this.processState,
291
+ environmentVariables: this.environmentVariables
290
292
  });
291
293
  if (options.type !== ContextType.Function) {
292
294
  if (options.type !== ContextType.Loop) {
package/dist/cps.js CHANGED
@@ -38,6 +38,7 @@ const not_1 = __importDefault(require("./operations/not"));
38
38
  const resolve_1 = __importDefault(require("./operations/resolve"));
39
39
  const return_1 = __importDefault(require("./operations/return"));
40
40
  const while_1 = __importDefault(require("./operations/while"));
41
+ const envar_1 = __importDefault(require("./operations/envar"));
41
42
  class CPSContext {
42
43
  constructor(target, handler) {
43
44
  this.target = target;
@@ -114,6 +115,8 @@ const visit = (context, currentTarget, item) => __awaiter(void 0, void 0, void 0
114
115
  }
115
116
  case greybel_core_1.ASTType.FeatureDebuggerExpression:
116
117
  return new debugger_statement_1.default(item, currentTarget);
118
+ case greybel_core_1.ASTType.FeatureEnvarExpression:
119
+ return new envar_1.default(item, currentTarget);
117
120
  case greyscript_core_1.ASTType.BooleanLiteral:
118
121
  case greyscript_core_1.ASTType.StringLiteral:
119
122
  case greyscript_core_1.ASTType.NumericLiteral:
@@ -14,11 +14,13 @@ export interface InterpreterOptions {
14
14
  params?: Array<string>;
15
15
  handler?: HandlerContainer;
16
16
  debugger?: Debugger;
17
+ environmentVariables?: Map<string, string>;
17
18
  }
18
19
  export default class Interpreter extends EventEmitter {
19
20
  target: string;
20
21
  api: ObjectValue;
21
22
  params: Array<string>;
23
+ environmentVariables: Map<string, string>;
22
24
  handler: HandlerContainer;
23
25
  debugger: Debugger;
24
26
  apiContext: OperationContext;
@@ -56,6 +56,7 @@ class Interpreter extends events_1.default {
56
56
  this.debugger = options.debugger || new context_1.Debugger();
57
57
  this.api = options.api || new object_value_1.default();
58
58
  this.params = options.params || [];
59
+ this.environmentVariables = options.environmentVariables || new Map();
59
60
  this.apiContext = null;
60
61
  this.globalContext = null;
61
62
  this.setTarget(options.target || 'unknown');
@@ -72,7 +73,8 @@ class Interpreter extends events_1.default {
72
73
  isProtected: true,
73
74
  debugger: this.debugger,
74
75
  handler: this.handler,
75
- cps: this.cps
76
+ cps: this.cps,
77
+ environmentVariables: this.environmentVariables
76
78
  });
77
79
  this.globalContext = this.apiContext.fork({
78
80
  type: context_1.ContextType.Global,
@@ -0,0 +1,10 @@
1
+ import { ASTFeatureEnvarExpression } from 'greybel-core';
2
+ import context from '../context';
3
+ import CustomValue from '../types/base';
4
+ import Operation, { CPSVisit } from './operation';
5
+ export default class EnvarExpression extends Operation {
6
+ readonly item: ASTFeatureEnvarExpression;
7
+ constructor(item: ASTFeatureEnvarExpression, target?: string);
8
+ build(_visit: CPSVisit): Promise<Operation>;
9
+ handle(ctx: context): Promise<CustomValue>;
10
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const string_1 = __importDefault(require("../types/string"));
7
+ const operation_1 = __importDefault(require("./operation"));
8
+ class EnvarExpression extends operation_1.default {
9
+ constructor(item, target) {
10
+ super(null, target);
11
+ this.item = item;
12
+ }
13
+ build(_visit) {
14
+ return Promise.resolve(this);
15
+ }
16
+ handle(ctx) {
17
+ if (ctx.environmentVariables.has(this.item.name)) {
18
+ return Promise.resolve(new string_1.default(ctx.environmentVariables.get(this.item.name)));
19
+ }
20
+ throw new Error('Unknown environment variable.');
21
+ }
22
+ }
23
+ exports.default = EnvarExpression;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "1.6.4",
3
+ "version": "1.6.5",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",