UNPKG

chevrotain

Version:

Chevrotain is a high performance fault tolerant javascript parsing DSL for building recursive decent parsers

40 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var generate_1 = require("./generate"); /** * Will Create a factory function that once invoked with a IParserConfig will return * a Parser Object. * * - Note that this happens using the Function constructor (a type of "eval") so it will not work in environments * where content security policy is enabled, such as certain websites, Chrome extensions ect... * * This means this function is best used for development flows to reduce the feedback loops * or for productive flows targeting node.js only. * * For productive flows targeting a browser runtime see @link {generation.generateParserModule} */ function generateParserFactory(options) { var wrapperText = generate_1.genWrapperFunction({ name: options.name, rules: options.rules }); var constructorWrapper = new Function("tokenVocabulary", "config", "chevrotain", wrapperText); return function (config) { return constructorWrapper(options.tokenVocabulary, config, // TODO: check how the require is transpiled/webpacked require("../api")); }; } exports.generateParserFactory = generateParserFactory; /** * This would generate the string literal for a UMD module (@link {https://github.com/umdjs/umd}) * That exports a Parser Constructor. * * Note that the constructor exposed by the generated module must receive the TokenVocabulary as the first * argument, the IParser config can be passed as the second argument. */ function generateParserModule(options) { return generate_1.genUmdModule({ name: options.name, rules: options.rules }); } exports.generateParserModule = generateParserModule; //# sourceMappingURL=generate_public.js.map