UNPKG

js-slang

Version:

Javascript-based implementations of Source, written in Typescript

53 lines 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SchemeParser = void 0; const src_1 = require("../../alt-langs/scheme/scm-slang/src"); const types_1 = require("../../types"); const errors_1 = require("../errors"); const utils_1 = require("../utils"); class SchemeParser { constructor(chapter) { this.chapter = getSchemeChapter(chapter); } parse(programStr, context, options, throwOnError) { try { // parse the scheme code const estree = (0, src_1.schemeParse)(programStr, this.chapter, true); return estree; } catch (error) { if (error instanceof SyntaxError) { error = new errors_1.FatalSyntaxError((0, utils_1.positionToSourceLocation)(error.loc), error.toString()); } if (throwOnError) throw error; context.errors.push(error); } return null; } validate(_ast, _context, _throwOnError) { return true; } toString() { return `SchemeParser{chapter: ${this.chapter}}`; } } exports.SchemeParser = SchemeParser; function getSchemeChapter(chapter) { switch (chapter) { case types_1.Chapter.SCHEME_1: return 1; case types_1.Chapter.SCHEME_2: return 2; case types_1.Chapter.SCHEME_3: return 3; case types_1.Chapter.SCHEME_4: return 4; case types_1.Chapter.FULL_SCHEME: return Infinity; default: // Should never happen throw new Error(`SchemeParser was not given a valid chapter!`); } } //# sourceMappingURL=index.js.map