UNPKG

js-slang

Version:

Javascript-based implementations of Source, written in Typescript

47 lines 2.01 kB
"use strict"; /** * The main entry point of the scheme transpiler. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.schemeParse = exports.ParserError = exports.LexerError = void 0; const lexer_1 = require("./lexer"); const parser_1 = require("./parser"); const visitors_1 = require("./visitors"); const __1 = require(".."); var lexer_2 = require("./lexer"); Object.defineProperty(exports, "LexerError", { enumerable: true, get: function () { return lexer_2.LexerError; } }); var parser_2 = require("./parser"); Object.defineProperty(exports, "ParserError", { enumerable: true, get: function () { return parser_2.ParserError; } }); /** * Transpiles Scheme source code into an ESTree program. * @param source The Scheme source code * @param chapter The chapter of the Scheme language. * If not provided, defaults to the latest version. * @returns */ function schemeParse(source, chapter, encode) { // Instantiate the lexer const lexer = new lexer_1.SchemeLexer(source); // Generate tokens const tokens = lexer.scanTokens(); // Instantiate the parser const parser = new parser_1.SchemeParser(source, tokens, chapter); // The Scheme AST is represented as an // array of expressions, which is all top-level expressions // Generate the first AST const firstAST = parser.parse(); // We instantiate all the visitors const simplifier = visitors_1.Simplifier.create(); const redefiner = visitors_1.Redefiner.create(); const transpiler = visitors_1.Transpiler.create(); // TODO: Then we macro-expand the AST // Then we simplify the AST const simplifiedAST = simplifier.simplify(firstAST); // Then we redefine the AST const redefinedAST = redefiner.redefine(simplifiedAST); // Finally we transpile the AST const program = transpiler.transpile(redefinedAST); return encode ? (0, __1.estreeEncode)(program) : program; } exports.schemeParse = schemeParse; //# sourceMappingURL=index.js.map