Skip to content

Commit

Permalink
integrated pull request zaach#286: adding angular module
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Lehmann committed Feb 23, 2016
1 parent 6ecb980 commit 66756fd
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_();
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 66756fd

Please sign in to comment.