From 18cc75fe709d844032c111efdd43b9de5772c9ea Mon Sep 17 00:00:00 2001 From: kether667 Date: Sun, 31 May 2015 10:30:32 -0700 Subject: [PATCH 1/7] adding angular module --- lib/jison.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/jison.js b/lib/jison.js index 789307f6e..1203f78c0 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -936,6 +936,9 @@ lrGeneratorMixin.generate = function parser_generate (opt) { case "js": code = this.generateModule(opt); break; + case "angular": + code = this.generateAngularModule(opt); + break; case "amd": code = this.generateAMDModule(opt); break; @@ -947,7 +950,22 @@ lrGeneratorMixin.generate = function parser_generate (opt) { return code; }; -lrGeneratorMixin.generateAMDModule = function generateAMDModule(opt){ +lrGeneratorMixin.generateAngularModule = function generateAngularModule(opt){ + opt = typal.mix.call({}, this.options, opt); + var module = this.generateModule_(); + var out = 'angular.module("dupa", [])' + + '.factory("parser", function(require){\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_(); var out = '\n\ndefine(function(require){\n' @@ -1339,6 +1357,7 @@ lrGeneratorMixin.createParser = function createParser () { // backwards compatability p.generate = bind('generate'); + p.generateAngularModule = bind('generateAngularModule'); p.generateAMDModule = bind('generateAMDModule'); p.generateModule = bind('generateModule'); p.generateCommonJSModule = bind('generateCommonJSModule'); From 8e4e2d67907b46e1a33ed1faf4d3e84429991d83 Mon Sep 17 00:00:00 2001 From: kether667 Date: Sun, 31 May 2015 10:46:56 -0700 Subject: [PATCH 2/7] setting proper module name --- lib/jison.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/jison.js b/lib/jison.js index 1203f78c0..80a5ba0b5 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -953,8 +953,10 @@ lrGeneratorMixin.generate = function parser_generate (opt) { lrGeneratorMixin.generateAngularModule = function generateAngularModule(opt){ opt = typal.mix.call({}, this.options, opt); var module = this.generateModule_(); - var out = 'angular.module("dupa", [])' + - '.factory("parser", function(require){\n' + var moduleName = opt.moduleName || "parser"; + + var out = 'angular.module(jison.'+moduleName+', [])' + + '.factory('+moduleName+'"parser", function(require){\n' + module.commonCode + '\nvar parser = '+ module.moduleCode + "\n"+this.moduleInclude From 52fd5376b3c6bbca98ec5690608b7f8f88253491 Mon Sep 17 00:00:00 2001 From: kether667 Date: Sun, 31 May 2015 10:48:33 -0700 Subject: [PATCH 3/7] missed quotes --- lib/jison.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jison.js b/lib/jison.js index 80a5ba0b5..9a08b78b1 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -955,8 +955,8 @@ lrGeneratorMixin.generateAngularModule = function generateAngularModule(opt){ var module = this.generateModule_(); var moduleName = opt.moduleName || "parser"; - var out = 'angular.module(jison.'+moduleName+', [])' + - '.factory('+moduleName+'"parser", function(require){\n' + var out = 'angular.module("jison.'+moduleName+'", [])' + + '.factory("'+moduleName+'Parser", function(require){\n' + module.commonCode + '\nvar parser = '+ module.moduleCode + "\n"+this.moduleInclude From aeee03b8ebb9cac8cc2760c829948a4999c595ab Mon Sep 17 00:00:00 2001 From: kether667 Date: Sun, 31 May 2015 10:50:50 -0700 Subject: [PATCH 4/7] no need for require --- lib/jison.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jison.js b/lib/jison.js index 9a08b78b1..f32a28ff8 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -956,7 +956,7 @@ lrGeneratorMixin.generateAngularModule = function generateAngularModule(opt){ var moduleName = opt.moduleName || "parser"; var out = 'angular.module("jison.'+moduleName+'", [])' + - '.factory("'+moduleName+'Parser", function(require){\n' + '.factory("'+moduleName+'Parser", function(){\n' + module.commonCode + '\nvar parser = '+ module.moduleCode + "\n"+this.moduleInclude From 9eabc2fba678e2f4fcc2ab58665eb68b8867d7c9 Mon Sep 17 00:00:00 2001 From: kether667 Date: Sun, 31 May 2015 23:45:00 -0700 Subject: [PATCH 5/7] parse error is on current object not it's prototype, if it's not set on share object it's unnecessary to assign to itself --- lib/jison.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/jison.js b/lib/jison.js index 5c5f1af50..51dba760f 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -1426,8 +1426,6 @@ 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) { From 1d441ab7aa2fd1daf2190222b07f9689cb68b778 Mon Sep 17 00:00:00 2001 From: kether667 Date: Sun, 31 May 2015 23:48:25 -0700 Subject: [PATCH 6/7] added a generated comment and jshint ignore --- lib/jison.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jison.js b/lib/jison.js index 51dba760f..02ffcc2e1 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -955,7 +955,7 @@ lrGeneratorMixin.generateAngularModule = function generateAngularModule(opt){ var module = this.generateModule_(); var moduleName = opt.moduleName || "parser"; - var out = 'angular.module("jison.'+moduleName+'", [])' + + var out = '// generated by jison\n// jshint ignore: start\nangular.module("jison.'+moduleName+'", [])' + '.factory("'+moduleName+'Parser", function(){\n' + module.commonCode + '\nvar parser = '+ module.moduleCode From c56324c07cb9ce7b72b810e129e3261508db6cf9 Mon Sep 17 00:00:00 2001 From: kether667 Date: Tue, 2 Jun 2015 16:07:42 -0700 Subject: [PATCH 7/7] ignore .idea --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3f1af7895..18b0bbc2d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ node_modules # Editor backup files *.bak *~ -web/content/assets/js/jison.js \ No newline at end of file +web/content/assets/js/jison.js +.idea/ \ No newline at end of file