1234567891011121314151617181920212223242526272829303132333435 |
- import * as AST from './ast';
- import { Error } from './error';
- import Token from './token';
-
- export class EnvError implements Error {
- public line: number;
- public message: string;
- public module?: string;
-
- public constructor(line: number, message: string, module?: string) {
- this.line = line;
- this.message = message;
- this.module = module;
- }
- }
-
- export default class Env {
- public data: { [name: string]: AST.Node };
-
- public constructor(parent?: Env) {
- this.data = parent ? Object.assign({}, parent.data) : {};
- }
-
- public get(name: Token): AST.Node | EnvError {
- if (this.data[name.value]) return this.data[name.value];
- return new EnvError(
- name.line,
- `Reference to unbound variable ${name.value}`
- );
- }
-
- public set(name: string, value: AST.Node): void {
- this.data[name] = value;
- }
- }
|