diff --git a/lib/jison.js b/lib/jison.js index b47f80a49..b54ce49b9 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -936,6 +936,8 @@ lrGeneratorMixin.generate = function parser_generate (opt) { case "js": code = this.generateModule(opt); break; + case "angular": + code = this.generateAngularModule(opt); case "amd": code = this.generateAMDModule(opt); break; @@ -947,6 +949,24 @@ lrGeneratorMixin.generate = function parser_generate (opt) { return code; }; +lrGeneratorMixin.generateAngularModule = function generateAngularModule(opt){ + opt = typal.mix.call({}, this.options, opt); + var module = this.generateModule_(); + var moduleName = opt.moduleName || "parser"; + + var out = '// generated by jison\n// jshint ignore: start\nangular.module("jison.'+moduleName+'", [])' + + '.factory("'+moduleName+'Parser", function(){\n' + + module.commonCode + + '\nvar parser = '+ module.moduleCode + + "\n"+this.moduleInclude + + (this.lexer && this.lexer.generateModule ? + '\n' + this.lexer.generateModule() + + '\nparser.lexer = lexer;' : '') + + '\nreturn parser;' + + '\n});'; + return out; +}; + lrGeneratorMixin.generateAMDModule = function generateAMDModule(opt){ opt = typal.mix.call({}, this.options, opt); var module = this.generateModule_(); @@ -1340,6 +1360,7 @@ lrGeneratorMixin.createParser = function createParser () { // backwards compatability p.lexer = this.lexer; p.generate = bind('generate'); + p.generateAngularModule = bind('generateAngularModule'); p.generateAMDModule = bind('generateAMDModule'); p.generateModule = bind('generateModule'); p.generateCommonJSModule = bind('generateCommonJSModule'); @@ -1411,8 +1432,10 @@ parser.parse = function parse (input) { if (typeof sharedState.yy.parseError === 'function') { this.parseError = sharedState.yy.parseError; + /* } else { this.parseError = Object.getPrototypeOf(this).parseError; + */ } function popStack (n) {