Skip to content

Commit

Permalink
Merge remote-tracking branch 'kether667/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
deathcap committed Feb 9, 2016
2 parents 8eb33eb + c56324c commit 213319c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,10 @@ generatorMixin.generate = function parser_generate (opt) {
case 'js':
code = this.generateModule(opt);
break;
case 'amd':
case "angular":
code = this.generateAngularModule(opt);
break;
case "amd":
code = this.generateAMDModule(opt);
break;
default:
Expand All @@ -1365,8 +1368,25 @@ generatorMixin.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;
};

generatorMixin.generateAMDModule = function generateAMDModule (opt) {
lrGeneratorMixin.generateAMDModule = function generateAMDModule(opt){
opt = typal.mix.call({}, this.options, opt);
var module = this.generateModule_();
var out = [
Expand Down Expand Up @@ -1857,6 +1877,7 @@ generatorMixin.createParser = function createParser () {
// backwards compatibility
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

0 comments on commit 213319c

Please sign in to comment.