From 2ebb3d89ae72151555c33870a89e432a78a3d3a5 Mon Sep 17 00:00:00 2001 From: Pawel Defee Date: Wed, 3 Sep 2014 22:18:01 +0300 Subject: [PATCH 1/2] Moved mandatory modules from devDependencies to dependencies section of package.json. Changed path to jison module to point to latest official release instead of GitHub URL. --- package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 76f52d4..2b26a46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ebnf-parser", - "version": "0.1.10", + "version": "0.1.11", "description": "A parser for BNF and EBNF grammars used by jison", "main": "ebnf-parser.js", "scripts": { @@ -19,9 +19,11 @@ ], "author": "Zach Carter", "license": "MIT", + "dependencies": { + "jison": "~0.4.15", + "lex-parser": "0.1.0" + }, "devDependencies": { - "jison": "git://github.com/zaach/jison.git#ef2647", - "lex-parser": "0.1.0", "test": "*" } } From 2cc107c243e1ed9f55177fa861438d7796f55913 Mon Sep 17 00:00:00 2001 From: Pawel Defee Date: Thu, 4 Sep 2014 07:42:02 +0300 Subject: [PATCH 2/2] Added newly generated transform-parser.js due to updated jison parser generator dependency. --- transform-parser.js | 117 +++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 50 deletions(-) diff --git a/transform-parser.js b/transform-parser.js index 4ef7195..0940fb1 100644 --- a/transform-parser.js +++ b/transform-parser.js @@ -1,4 +1,4 @@ -/* parser generated by jison 0.4.11 */ +/* parser generated by jison 0.4.15 */ /* Returns a Parser object of the following structure: @@ -71,7 +71,8 @@ recoverable: (boolean: TRUE when the parser has a error recovery rule available for this particular error) } */ -var ebnf = (function(){ +var parser = (function(){ +var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[2,4],$V1=[1,6],$V2=[1,7],$V3=[5,7,12,13,14],$V4=[5,7,11,12,13,14],$V5=[5,7,11,12,13,14,15,16,17],$V6=[7,12,13,14],$V7=[7,14]; var parser = {trace: function trace() { }, yy: {}, symbols_: {"error":2,"production":3,"handle":4,"EOF":5,"handle_list":6,"|":7,"expression_suffix":8,"expression":9,"suffix":10,"ALIAS":11,"symbol":12,"(":13,")":14,"*":15,"?":16,"+":17,"$accept":0,"$end":1}, @@ -82,27 +83,36 @@ performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* actio var $0 = $$.length - 1; switch (yystate) { -case 1: return $$[$0-1]; +case 1: + return $$[$0-1]; break; -case 2: this.$ = [$$[$0]]; +case 2: + this.$ = [$$[$0]]; break; -case 3: $$[$0-2].push($$[$0]); +case 3: + $$[$0-2].push($$[$0]); break; -case 4: this.$ = []; +case 4: + this.$ = []; break; -case 5: $$[$0-1].push($$[$0]); +case 5: + $$[$0-1].push($$[$0]); break; -case 6: this.$ = ['xalias', $$[$0-1], $$[$0-2], $$[$0]]; +case 6: + this.$ = ['xalias', $$[$0-1], $$[$0-2], $$[$0]]; break; -case 7: if ($$[$0]) this.$ = [$$[$0], $$[$0-1]]; else this.$ = $$[$0-1]; +case 7: + if ($$[$0]) this.$ = [$$[$0], $$[$0-1]]; else this.$ = $$[$0-1]; break; -case 8: this.$ = ['symbol', $$[$0]]; +case 8: + this.$ = ['symbol', $$[$0]]; break; -case 9: this.$ = ['()', $$[$0-1]]; +case 9: + this.$ = ['()', $$[$0-1]]; break; } }, -table: [{3:1,4:2,5:[2,4],12:[2,4],13:[2,4]},{1:[3]},{5:[1,3],8:4,9:5,12:[1,6],13:[1,7]},{1:[2,1]},{5:[2,5],7:[2,5],12:[2,5],13:[2,5],14:[2,5]},{5:[2,10],7:[2,10],10:8,11:[2,10],12:[2,10],13:[2,10],14:[2,10],15:[1,9],16:[1,10],17:[1,11]},{5:[2,8],7:[2,8],11:[2,8],12:[2,8],13:[2,8],14:[2,8],15:[2,8],16:[2,8],17:[2,8]},{4:13,6:12,7:[2,4],12:[2,4],13:[2,4],14:[2,4]},{5:[2,7],7:[2,7],11:[1,14],12:[2,7],13:[2,7],14:[2,7]},{5:[2,11],7:[2,11],11:[2,11],12:[2,11],13:[2,11],14:[2,11]},{5:[2,12],7:[2,12],11:[2,12],12:[2,12],13:[2,12],14:[2,12]},{5:[2,13],7:[2,13],11:[2,13],12:[2,13],13:[2,13],14:[2,13]},{7:[1,16],14:[1,15]},{7:[2,2],8:4,9:5,12:[1,6],13:[1,7],14:[2,2]},{5:[2,6],7:[2,6],12:[2,6],13:[2,6],14:[2,6]},{5:[2,9],7:[2,9],11:[2,9],12:[2,9],13:[2,9],14:[2,9],15:[2,9],16:[2,9],17:[2,9]},{4:17,7:[2,4],12:[2,4],13:[2,4],14:[2,4]},{7:[2,3],8:4,9:5,12:[1,6],13:[1,7],14:[2,3]}], +table: [o([5,12,13],$V0,{3:1,4:2}),{1:[3]},{5:[1,3],8:4,9:5,12:$V1,13:$V2},{1:[2,1]},o($V3,[2,5]),o($V4,[2,10],{10:8,15:[1,9],16:[1,10],17:[1,11]}),o($V5,[2,8]),o($V6,$V0,{6:12,4:13}),o($V3,[2,7],{11:[1,14]}),o($V4,[2,11]),o($V4,[2,12]),o($V4,[2,13]),{7:[1,16],14:[1,15]},o($V7,[2,2],{8:4,9:5,12:$V1,13:$V2}),o($V3,[2,6]),o($V5,[2,9]),o($V6,$V0,{4:17}),o($V7,[2,3],{8:4,9:5,12:$V1,13:$V2})], defaultActions: {3:[2,1]}, parseError: function parseError(str, hash) { if (hash.recoverable) { @@ -112,20 +122,26 @@ parseError: function parseError(str, hash) { } }, parse: function parse(input) { - var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; + var self = this, stack = [0], tstack = [], vstack = [null], lstack = [], table = this.table, yytext = '', yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; var args = lstack.slice.call(arguments, 1); - this.lexer.setInput(input); - this.lexer.yy = this.yy; - this.yy.lexer = this.lexer; - this.yy.parser = this; - if (typeof this.lexer.yylloc == 'undefined') { - this.lexer.yylloc = {}; + var lexer = Object.create(this.lexer); + var sharedState = { yy: {} }; + for (var k in this.yy) { + if (Object.prototype.hasOwnProperty.call(this.yy, k)) { + sharedState.yy[k] = this.yy[k]; + } + } + lexer.setInput(input, sharedState.yy); + sharedState.yy.lexer = lexer; + sharedState.yy.parser = this; + if (typeof lexer.yylloc == 'undefined') { + lexer.yylloc = {}; } - var yyloc = this.lexer.yylloc; + var yyloc = lexer.yylloc; lstack.push(yyloc); - var ranges = this.lexer.options && this.lexer.options.ranges; - if (typeof this.yy.parseError === 'function') { - this.parseError = this.yy.parseError; + var ranges = lexer.options && lexer.options.ranges; + if (typeof sharedState.yy.parseError === 'function') { + this.parseError = sharedState.yy.parseError; } else { this.parseError = Object.getPrototypeOf(this).parseError; } @@ -134,14 +150,15 @@ parse: function parse(input) { vstack.length = vstack.length - n; lstack.length = lstack.length - n; } - function lex() { - var token; - token = self.lexer.lex() || EOF; - if (typeof token !== 'number') { - token = self.symbols_[token] || token; + _token_stack: + function lex() { + var token; + token = lexer.lex() || EOF; + if (typeof token !== 'number') { + token = self.symbols_[token] || token; + } + return token; } - return token; - } var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; while (true) { state = stack[stack.length - 1]; @@ -161,15 +178,15 @@ parse: function parse(input) { expected.push('\'' + this.terminals_[p] + '\''); } } - if (this.lexer.showPosition) { - errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + this.lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\''; + if (lexer.showPosition) { + errStr = 'Parse error on line ' + (yylineno + 1) + ':\n' + lexer.showPosition() + '\nExpecting ' + expected.join(', ') + ', got \'' + (this.terminals_[symbol] || symbol) + '\''; } else { errStr = 'Parse error on line ' + (yylineno + 1) + ': Unexpected ' + (symbol == EOF ? 'end of input' : '\'' + (this.terminals_[symbol] || symbol) + '\''); } this.parseError(errStr, { - text: this.lexer.match, + text: lexer.match, token: this.terminals_[symbol] || symbol, - line: this.lexer.yylineno, + line: lexer.yylineno, loc: yyloc, expected: expected }); @@ -180,15 +197,15 @@ parse: function parse(input) { switch (action[0]) { case 1: stack.push(symbol); - vstack.push(this.lexer.yytext); - lstack.push(this.lexer.yylloc); + vstack.push(lexer.yytext); + lstack.push(lexer.yylloc); stack.push(action[1]); symbol = null; if (!preErrorSymbol) { - yyleng = this.lexer.yyleng; - yytext = this.lexer.yytext; - yylineno = this.lexer.yylineno; - yyloc = this.lexer.yylloc; + yyleng = lexer.yyleng; + yytext = lexer.yytext; + yylineno = lexer.yylineno; + yyloc = lexer.yylloc; if (recovering > 0) { recovering--; } @@ -216,7 +233,7 @@ parse: function parse(input) { yytext, yyleng, yylineno, - this.yy, + sharedState.yy, action[1], vstack, lstack @@ -241,9 +258,9 @@ parse: function parse(input) { } return true; }}; -/* generated by jison-lex 0.2.1 */ +/* generated by jison-lex 0.3.4 */ var lexer = (function(){ -var lexer = { +var lexer = ({ EOF:1, @@ -256,7 +273,8 @@ parseError:function parseError(str, hash) { }, // resets the lexer, sets new input -setInput:function (input) { +setInput:function (input, yy) { + this.yy = yy || this.yy || {}; this._input = input; this._more = this._backtrack = this.done = false; this.yylineno = this.yyleng = 0; @@ -304,7 +322,7 @@ unput:function (ch) { var lines = ch.split(/(?:\r\n?|\n)/g); this._input = ch + this._input; - this.yytext = this.yytext.substr(0, this.yytext.length - len - 1); + this.yytext = this.yytext.substr(0, this.yytext.length - len); //this.yyleng -= len; this.offset -= len; var oldLines = this.match.split(/(?:\r\n?|\n)/g); @@ -566,7 +584,6 @@ stateStackSize:function stateStackSize() { }, options: {}, performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { - var YYSTATE=YY_START; switch($avoiding_name_collisions) { case 0:/* skip whitespace */ @@ -599,7 +616,7 @@ break; }, rules: [/^(?:\s+)/,/^(?:([a-zA-Z][a-zA-Z0-9_-]*))/,/^(?:\[([a-zA-Z][a-zA-Z0-9_-]*)\])/,/^(?:'[^']*')/,/^(?:\.)/,/^(?:bar\b)/,/^(?:\()/,/^(?:\))/,/^(?:\*)/,/^(?:\?)/,/^(?:\|)/,/^(?:\+)/,/^(?:$)/], conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12],"inclusive":true}} -}; +}); return lexer; })(); parser.lexer = lexer; @@ -612,9 +629,9 @@ return new Parser; if (typeof require !== 'undefined' && typeof exports !== 'undefined') { -exports.parser = ebnf; -exports.Parser = ebnf.Parser; -exports.parse = function () { return ebnf.parse.apply(ebnf, arguments); }; +exports.parser = parser; +exports.Parser = parser.Parser; +exports.parse = function () { return parser.parse.apply(parser, arguments); }; exports.main = function commonjsMain(args) { if (!args[1]) { console.log('Usage: '+args[0]+' FILE');