Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add '+' operator for EBNF syntax

  • Loading branch information...
commit 06d01d48307bb7606c5605ed9d533fd1ce7f3e6d 1 parent 27bac25
@zaach authored
View
16 lib/jison/ebnf.js
@@ -10,6 +10,7 @@ var EBNF = (function(){
["\\(", "return '(';"],
["\\)", "return ')';"],
["\\*", "return '*';"],
+ ["\\+", "return '+';"],
["\\?", "return '?';"],
["\\|", "return '|';"],
["$", "return 'EOF';"]
@@ -35,7 +36,7 @@ var EBNF = (function(){
["symbol", "$$ = ['symbol', $symbol];"],
["( handle_list )", "$$ = ['()', $handle_list];"]
],
- "suffix": ["", "*", "?"]
+ "suffix": ["", "*", "?", "+"]
}
};
@@ -48,6 +49,19 @@ var EBNF = (function(){
if (e[1][0] === '\\') emit (e[1][1])
else if (e[1][0] === '\'') emit (e[1].substring(1, e[1].length-1))
else emit (e[1])
+ } else if (type === "+") {
+ var name = opts.production + "_repetition_plus" + opts.repid++;
+ emit(name)
+
+ opts = optsForProduction(name, opts.grammar)
+ var list = transformExpressionList([value], opts);
+ var production = opts.grammar[name] = [
+ [list, "$$ = [$1];"],
+ [
+ name + " " + list,
+ "$1.push($2);"
+ ]
+ ];
} else if (type === "*") {
var name = opts.production + "_repetition" + opts.repid++;
emit(name)
View
152 lib/jison/util/bnf-parser.js
@@ -1,15 +1,10 @@
/* Jison generated parser */
var bnf = (function(){
-
-var ebnf = false;
-
-
-
var parser = {trace: function trace() { },
yy: {},
-symbols_: {"error":2,"spec":3,"declaration_list":4,"%%":5,"grammar":6,"optional_end_block":7,"EOF":8,"CODE":9,"declaration":10,"START":11,"id":12,"LEX_BLOCK":13,"operator":14,"ACTION":15,"associativity":16,"token_list":17,"LEFT":18,"RIGHT":19,"NONASSOC":20,"symbol":21,"production_list":22,"production":23,":":24,"handle_list":25,";":26,"|":27,"handle_action":28,"handle":29,"prec":30,"action":31,"expression_suffix":32,"handle_sublist":33,"expression":34,"suffix":35,"ID":36,"STRING":37,"(":38,")":39,"*":40,"?":41,"PREC":42,"{":43,"action_body":44,"}":45,"ARROW_ACTION":46,"ACTION_BODY":47,"$accept":0,"$end":1},
-terminals_: {2:"error",5:"%%",8:"EOF",9:"CODE",11:"START",13:"LEX_BLOCK",15:"ACTION",18:"LEFT",19:"RIGHT",20:"NONASSOC",24:":",26:";",27:"|",36:"ID",37:"STRING",38:"(",39:")",40:"*",41:"?",42:"PREC",43:"{",45:"}",46:"ARROW_ACTION",47:"ACTION_BODY"},
-productions_: [0,[3,5],[3,6],[7,0],[7,1],[4,2],[4,0],[10,2],[10,1],[10,1],[10,1],[14,2],[16,1],[16,1],[16,1],[17,2],[17,1],[6,1],[22,2],[22,1],[23,4],[25,3],[25,1],[28,3],[29,2],[29,0],[33,3],[33,1],[32,2],[34,1],[34,1],[34,3],[35,0],[35,1],[35,1],[30,2],[30,0],[21,1],[21,1],[12,1],[31,3],[31,1],[31,1],[31,0],[44,0],[44,1],[44,5],[44,4]],
+symbols_: {"error":2,"spec":3,"declaration_list":4,"%%":5,"grammar":6,"optional_end_block":7,"EOF":8,"CODE":9,"declaration":10,"START":11,"id":12,"LEX_BLOCK":13,"operator":14,"ACTION":15,"associativity":16,"token_list":17,"LEFT":18,"RIGHT":19,"NONASSOC":20,"symbol":21,"production_list":22,"production":23,":":24,"handle_list":25,";":26,"|":27,"handle_action":28,"handle":29,"prec":30,"action":31,"expression_suffix":32,"handle_sublist":33,"expression":34,"suffix":35,"ID":36,"STRING":37,"(":38,")":39,"*":40,"?":41,"+":42,"PREC":43,"{":44,"action_body":45,"}":46,"ARROW_ACTION":47,"ACTION_BODY":48,"$accept":0,"$end":1},
+terminals_: {2:"error",5:"%%",8:"EOF",9:"CODE",11:"START",13:"LEX_BLOCK",15:"ACTION",18:"LEFT",19:"RIGHT",20:"NONASSOC",24:":",26:";",27:"|",36:"ID",37:"STRING",38:"(",39:")",40:"*",41:"?",42:"+",43:"PREC",44:"{",46:"}",47:"ARROW_ACTION",48:"ACTION_BODY"},
+productions_: [0,[3,5],[3,6],[7,0],[7,1],[4,2],[4,0],[10,2],[10,1],[10,1],[10,1],[14,2],[16,1],[16,1],[16,1],[17,2],[17,1],[6,1],[22,2],[22,1],[23,4],[25,3],[25,1],[28,3],[29,2],[29,0],[33,3],[33,1],[32,2],[34,1],[34,1],[34,3],[35,0],[35,1],[35,1],[35,1],[30,2],[30,0],[21,1],[21,1],[12,1],[31,3],[31,1],[31,1],[31,0],[45,0],[45,1],[45,5],[45,4]],
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
var $0 = $$.length - 1;
@@ -80,35 +75,35 @@ case 31:this.$ = '(' + $$[$0-1].join(' | ') + ')';
break;
case 32:this.$ = ''
break;
-case 35:this.$ = {prec: $$[$0]};
-break;
-case 36:this.$ = null;
+case 36:this.$ = {prec: $$[$0]};
break;
-case 37:this.$ = $$[$0];
+case 37:this.$ = null;
break;
-case 38:this.$ = yytext;
+case 38:this.$ = $$[$0];
break;
case 39:this.$ = yytext;
break;
-case 40:this.$ = $$[$0-1];
+case 40:this.$ = yytext;
break;
-case 41:this.$ = $$[$0];
+case 41:this.$ = $$[$0-1];
break;
-case 42:this.$ = '$$ ='+$$[$0]+';';
+case 42:this.$ = $$[$0];
break;
-case 43:this.$ = '';
+case 43:this.$ = '$$ ='+$$[$0]+';';
break;
case 44:this.$ = '';
break;
-case 45:this.$ = yytext;
+case 45:this.$ = '';
break;
-case 46:this.$ = $$[$0-4]+$$[$0-3]+$$[$0-2]+$$[$0-1]+$$[$0];
+case 46:this.$ = yytext;
break;
-case 47:this.$ = $$[$0-3]+$$[$0-2]+$$[$0-1]+$$[$0];
+case 47:this.$ = $$[$0-4]+$$[$0-3]+$$[$0-2]+$$[$0-1]+$$[$0];
+break;
+case 48:this.$ = $$[$0-3]+$$[$0-2]+$$[$0-1]+$$[$0];
break;
}
},
-table: [{3:1,4:2,5:[2,6],11:[2,6],13:[2,6],15:[2,6],18:[2,6],19:[2,6],20:[2,6]},{1:[3]},{5:[1,3],10:4,11:[1,5],13:[1,6],14:7,15:[1,8],16:9,18:[1,10],19:[1,11],20:[1,12]},{6:13,12:16,22:14,23:15,36:[1,17]},{5:[2,5],11:[2,5],13:[2,5],15:[2,5],18:[2,5],19:[2,5],20:[2,5]},{12:18,36:[1,17]},{5:[2,8],11:[2,8],13:[2,8],15:[2,8],18:[2,8],19:[2,8],20:[2,8]},{5:[2,9],11:[2,9],13:[2,9],15:[2,9],18:[2,9],19:[2,9],20:[2,9]},{5:[2,10],11:[2,10],13:[2,10],15:[2,10],18:[2,10],19:[2,10],20:[2,10]},{12:21,17:19,21:20,36:[1,17],37:[1,22]},{36:[2,12],37:[2,12]},{36:[2,13],37:[2,13]},{36:[2,14],37:[2,14]},{5:[1,24],7:23,8:[2,3]},{5:[2,17],8:[2,17],12:16,23:25,36:[1,17]},{5:[2,19],8:[2,19],36:[2,19]},{24:[1,26]},{5:[2,39],11:[2,39],13:[2,39],15:[2,39],18:[2,39],19:[2,39],20:[2,39],24:[2,39],26:[2,39],27:[2,39],36:[2,39],37:[2,39],43:[2,39],46:[2,39]},{5:[2,7],11:[2,7],13:[2,7],15:[2,7],18:[2,7],19:[2,7],20:[2,7]},{5:[2,11],11:[2,11],12:21,13:[2,11],15:[2,11],18:[2,11],19:[2,11],20:[2,11],21:27,36:[1,17],37:[1,22]},{5:[2,16],11:[2,16],13:[2,16],15:[2,16],18:[2,16],19:[2,16],20:[2,16],36:[2,16],37:[2,16]},{5:[2,37],11:[2,37],13:[2,37],15:[2,37],18:[2,37],19:[2,37],20:[2,37],26:[2,37],27:[2,37],36:[2,37],37:[2,37],43:[2,37],46:[2,37]},{5:[2,38],11:[2,38],13:[2,38],15:[2,38],18:[2,38],19:[2,38],20:[2,38],26:[2,38],27:[2,38],36:[2,38],37:[2,38],43:[2,38],46:[2,38]},{8:[1,28]},{8:[2,4],9:[1,29]},{5:[2,18],8:[2,18],36:[2,18]},{15:[2,25],25:30,26:[2,25],27:[2,25],28:31,29:32,36:[2,25],37:[2,25],38:[2,25],42:[2,25],43:[2,25],46:[2,25]},{5:[2,15],11:[2,15],13:[2,15],15:[2,15],18:[2,15],19:[2,15],20:[2,15],36:[2,15],37:[2,15]},{1:[2,1]},{8:[1,33]},{26:[1,34],27:[1,35]},{26:[2,22],27:[2,22]},{15:[2,36],26:[2,36],27:[2,36],30:36,32:37,34:39,36:[1,40],37:[1,41],38:[1,42],42:[1,38],43:[2,36],46:[2,36]},{1:[2,2]},{5:[2,20],8:[2,20],36:[2,20]},{15:[2,25],26:[2,25],27:[2,25],28:43,29:32,36:[2,25],37:[2,25],38:[2,25],42:[2,25],43:[2,25],46:[2,25]},{15:[1,46],26:[2,43],27:[2,43],31:44,43:[1,45],46:[1,47]},{15:[2,24],26:[2,24],27:[2,24],36:[2,24],37:[2,24],38:[2,24],39:[2,24],42:[2,24],43:[2,24],46:[2,24]},{12:21,21:48,36:[1,17],37:[1,22]},{15:[2,32],26:[2,32],27:[2,32],35:49,36:[2,32],37:[2,32],38:[2,32],39:[2,32],40:[1,50],41:[1,51],42:[2,32],43:[2,32],46:[2,32]},{15:[2,29],26:[2,29],27:[2,29],36:[2,29],37:[2,29],38:[2,29],39:[2,29],40:[2,29],41:[2,29],42:[2,29],43:[2,29],46:[2,29]},{15:[2,30],26:[2,30],27:[2,30],36:[2,30],37:[2,30],38:[2,30],39:[2,30],40:[2,30],41:[2,30],42:[2,30],43:[2,30],46:[2,30]},{27:[2,25],29:53,33:52,36:[2,25],37:[2,25],38:[2,25],39:[2,25]},{26:[2,21],27:[2,21]},{26:[2,23],27:[2,23]},{43:[2,44],44:54,45:[2,44],47:[1,55]},{26:[2,41],27:[2,41]},{26:[2,42],27:[2,42]},{15:[2,35],26:[2,35],27:[2,35],43:[2,35],46:[2,35]},{15:[2,28],26:[2,28],27:[2,28],36:[2,28],37:[2,28],38:[2,28],39:[2,28],42:[2,28],43:[2,28],46:[2,28]},{15:[2,33],26:[2,33],27:[2,33],36:[2,33],37:[2,33],38:[2,33],39:[2,33],42:[2,33],43:[2,33],46:[2,33]},{15:[2,34],26:[2,34],27:[2,34],36:[2,34],37:[2,34],38:[2,34],39:[2,34],42:[2,34],43:[2,34],46:[2,34]},{27:[1,57],39:[1,56]},{27:[2,27],32:37,34:39,36:[1,40],37:[1,41],38:[1,42],39:[2,27]},{43:[1,59],45:[1,58]},{43:[2,45],45:[2,45]},{15:[2,31],26:[2,31],27:[2,31],36:[2,31],37:[2,31],38:[2,31],39:[2,31],40:[2,31],41:[2,31],42:[2,31],43:[2,31],46:[2,31]},{27:[2,25],29:60,36:[2,25],37:[2,25],38:[2,25],39:[2,25]},{26:[2,40],27:[2,40]},{43:[2,44],44:61,45:[2,44],47:[1,55]},{27:[2,26],32:37,34:39,36:[1,40],37:[1,41],38:[1,42],39:[2,26]},{43:[1,59],45:[1,62]},{43:[2,47],45:[2,47],47:[1,63]},{43:[2,46],45:[2,46]}],
+table: [{3:1,4:2,5:[2,6],11:[2,6],13:[2,6],15:[2,6],18:[2,6],19:[2,6],20:[2,6]},{1:[3]},{5:[1,3],10:4,11:[1,5],13:[1,6],14:7,15:[1,8],16:9,18:[1,10],19:[1,11],20:[1,12]},{6:13,12:16,22:14,23:15,36:[1,17]},{5:[2,5],11:[2,5],13:[2,5],15:[2,5],18:[2,5],19:[2,5],20:[2,5]},{12:18,36:[1,17]},{5:[2,8],11:[2,8],13:[2,8],15:[2,8],18:[2,8],19:[2,8],20:[2,8]},{5:[2,9],11:[2,9],13:[2,9],15:[2,9],18:[2,9],19:[2,9],20:[2,9]},{5:[2,10],11:[2,10],13:[2,10],15:[2,10],18:[2,10],19:[2,10],20:[2,10]},{12:21,17:19,21:20,36:[1,17],37:[1,22]},{36:[2,12],37:[2,12]},{36:[2,13],37:[2,13]},{36:[2,14],37:[2,14]},{5:[1,24],7:23,8:[2,3]},{5:[2,17],8:[2,17],12:16,23:25,36:[1,17]},{5:[2,19],8:[2,19],36:[2,19]},{24:[1,26]},{5:[2,40],11:[2,40],13:[2,40],15:[2,40],18:[2,40],19:[2,40],20:[2,40],24:[2,40],26:[2,40],27:[2,40],36:[2,40],37:[2,40],44:[2,40],47:[2,40]},{5:[2,7],11:[2,7],13:[2,7],15:[2,7],18:[2,7],19:[2,7],20:[2,7]},{5:[2,11],11:[2,11],12:21,13:[2,11],15:[2,11],18:[2,11],19:[2,11],20:[2,11],21:27,36:[1,17],37:[1,22]},{5:[2,16],11:[2,16],13:[2,16],15:[2,16],18:[2,16],19:[2,16],20:[2,16],36:[2,16],37:[2,16]},{5:[2,38],11:[2,38],13:[2,38],15:[2,38],18:[2,38],19:[2,38],20:[2,38],26:[2,38],27:[2,38],36:[2,38],37:[2,38],44:[2,38],47:[2,38]},{5:[2,39],11:[2,39],13:[2,39],15:[2,39],18:[2,39],19:[2,39],20:[2,39],26:[2,39],27:[2,39],36:[2,39],37:[2,39],44:[2,39],47:[2,39]},{8:[1,28]},{8:[2,4],9:[1,29]},{5:[2,18],8:[2,18],36:[2,18]},{15:[2,25],25:30,26:[2,25],27:[2,25],28:31,29:32,36:[2,25],37:[2,25],38:[2,25],43:[2,25],44:[2,25],47:[2,25]},{5:[2,15],11:[2,15],13:[2,15],15:[2,15],18:[2,15],19:[2,15],20:[2,15],36:[2,15],37:[2,15]},{1:[2,1]},{8:[1,33]},{26:[1,34],27:[1,35]},{26:[2,22],27:[2,22]},{15:[2,37],26:[2,37],27:[2,37],30:36,32:37,34:39,36:[1,40],37:[1,41],38:[1,42],43:[1,38],44:[2,37],47:[2,37]},{1:[2,2]},{5:[2,20],8:[2,20],36:[2,20]},{15:[2,25],26:[2,25],27:[2,25],28:43,29:32,36:[2,25],37:[2,25],38:[2,25],43:[2,25],44:[2,25],47:[2,25]},{15:[1,46],26:[2,44],27:[2,44],31:44,44:[1,45],47:[1,47]},{15:[2,24],26:[2,24],27:[2,24],36:[2,24],37:[2,24],38:[2,24],39:[2,24],43:[2,24],44:[2,24],47:[2,24]},{12:21,21:48,36:[1,17],37:[1,22]},{15:[2,32],26:[2,32],27:[2,32],35:49,36:[2,32],37:[2,32],38:[2,32],39:[2,32],40:[1,50],41:[1,51],42:[1,52],43:[2,32],44:[2,32],47:[2,32]},{15:[2,29],26:[2,29],27:[2,29],36:[2,29],37:[2,29],38:[2,29],39:[2,29],40:[2,29],41:[2,29],42:[2,29],43:[2,29],44:[2,29],47:[2,29]},{15:[2,30],26:[2,30],27:[2,30],36:[2,30],37:[2,30],38:[2,30],39:[2,30],40:[2,30],41:[2,30],42:[2,30],43:[2,30],44:[2,30],47:[2,30]},{27:[2,25],29:54,33:53,36:[2,25],37:[2,25],38:[2,25],39:[2,25]},{26:[2,21],27:[2,21]},{26:[2,23],27:[2,23]},{44:[2,45],45:55,46:[2,45],48:[1,56]},{26:[2,42],27:[2,42]},{26:[2,43],27:[2,43]},{15:[2,36],26:[2,36],27:[2,36],44:[2,36],47:[2,36]},{15:[2,28],26:[2,28],27:[2,28],36:[2,28],37:[2,28],38:[2,28],39:[2,28],43:[2,28],44:[2,28],47:[2,28]},{15:[2,33],26:[2,33],27:[2,33],36:[2,33],37:[2,33],38:[2,33],39:[2,33],43:[2,33],44:[2,33],47:[2,33]},{15:[2,34],26:[2,34],27:[2,34],36:[2,34],37:[2,34],38:[2,34],39:[2,34],43:[2,34],44:[2,34],47:[2,34]},{15:[2,35],26:[2,35],27:[2,35],36:[2,35],37:[2,35],38:[2,35],39:[2,35],43:[2,35],44:[2,35],47:[2,35]},{27:[1,58],39:[1,57]},{27:[2,27],32:37,34:39,36:[1,40],37:[1,41],38:[1,42],39:[2,27]},{44:[1,60],46:[1,59]},{44:[2,46],46:[2,46]},{15:[2,31],26:[2,31],27:[2,31],36:[2,31],37:[2,31],38:[2,31],39:[2,31],40:[2,31],41:[2,31],42:[2,31],43:[2,31],44:[2,31],47:[2,31]},{27:[2,25],29:61,36:[2,25],37:[2,25],38:[2,25],39:[2,25]},{26:[2,41],27:[2,41]},{44:[2,45],45:62,46:[2,45],48:[1,56]},{27:[2,26],32:37,34:39,36:[1,40],37:[1,41],38:[1,42],39:[2,26]},{44:[1,60],46:[1,63]},{44:[2,48],46:[2,48],48:[1,64]},{44:[2,47],46:[2,47]}],
defaultActions: {28:[2,1],33:[2,2]},
parseError: function parseError(str, hash) {
throw new Error(str);
@@ -210,10 +205,13 @@ parse: function parse(input) {
}
return true;
}
-};/* Jison generated lexer */
-var lexer = (function(){
+};
+
+var ebnf = false;
+/* Jison generated lexer */
+var lexer = (function(){
var lexer = ({EOF:1,
parseError:function parseError(str, hash) {
if (this.yy.parseError) {
@@ -274,6 +272,8 @@ next:function () {
var token,
match,
+ tempMatch,
+ index,
col,
lines;
if (!this._more) {
@@ -282,26 +282,30 @@ next:function () {
}
var rules = this._currentRules();
for (var i=0;i < rules.length; i++) {
- match = this._input.match(this.rules[rules[i]]);
- if (match) {
- lines = match[0].match(/\n.*/g);
- if (lines) this.yylineno += lines.length;
- this.yylloc = {first_line: this.yylloc.last_line,
- last_line: this.yylineno+1,
- first_column: this.yylloc.last_column,
- last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
- this.yytext += match[0];
- this.match += match[0];
- this.matches = match;
- this.yyleng = this.yytext.length;
- this._more = false;
- this._input = this._input.slice(match[0].length);
- this.matched += match[0];
- token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]);
- if (token) return token;
- else return;
+ tempMatch = this._input.match(this.rules[rules[i]]);
+ if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
+ match = tempMatch;
+ index = i;
+ if (!this.options.flex) break;
}
}
+ if (match) {
+ lines = match[0].match(/\n.*/g);
+ if (lines) this.yylineno += lines.length;
+ this.yylloc = {first_line: this.yylloc.last_line,
+ last_line: this.yylineno+1,
+ first_column: this.yylloc.last_column,
+ last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length}
+ this.yytext += match[0];
+ this.match += match[0];
+ this.yyleng = this.yytext.length;
+ this._more = false;
+ this._input = this._input.slice(match[0].length);
+ this.matched += match[0];
+ token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
+ if (token) return token;
+ else return;
+ }
if (this._input === "") {
return this.EOF;
} else {
@@ -332,6 +336,7 @@ topState:function () {
pushState:function begin(condition) {
this.begin(condition);
}});
+lexer.options = {};
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
var YYSTATE=YY_START
@@ -346,68 +351,73 @@ case 3:return 40
break;
case 4:return 41
break;
-case 5:/* skip whitespace */
+case 5:return 42
break;
-case 6:/* skip comment */
+case 6:/* skip whitespace */
break;
-case 7:return yy.lexComment(this);
+case 7:/* skip comment */
break;
-case 8:return 36;
+case 8:return yy.lexComment(this);
break;
-case 9:yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 37;
+case 9:return 36;
break;
case 10:yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 37;
break;
-case 11:return 24;
+case 11:yy_.yytext = yy_.yytext.substr(1, yy_.yyleng-2); return 37;
+break;
+case 12:return 24;
break;
-case 12:return 26;
+case 13:return 26;
break;
-case 13:return 27;
+case 14:return 27;
break;
-case 14:this.begin(ebnf ? 'ebnf' : 'bnf');return 5;
+case 15:this.begin(ebnf ? 'ebnf' : 'bnf');return 5;
break;
-case 15:if (!yy.options) yy.options = {}; ebnf = yy.options.ebnf = true;
+case 16:if (!yy.options) yy.options = {}; ebnf = yy.options.ebnf = true;
break;
-case 16:return 42;
+case 17:return 43;
break;
-case 17:return 11;
+case 18:return 11;
break;
-case 18:return 18;
+case 19:return 18;
break;
-case 19:return 19;
+case 20:return 19;
break;
-case 20:return 20;
+case 21:return 20;
break;
-case 21:return 13;
+case 22:return 13;
break;
-case 22:/* ignore unrecognized decl */
+case 23:/* ignore unrecognized decl */
break;
-case 23:/* ignore type */
+case 24:/* ignore type */
break;
-case 24:yy_.yytext = yy_.yytext.substr(2, yy_.yyleng-4); return 15;
+case 25:yy_.yytext = yy_.yytext.substr(2, yy_.yyleng-4); return 15;
break;
-case 25:yy_.yytext = yy_.yytext.substr(2, yy_.yytext.length-4);return 15;
+case 26:yy_.yytext = yy_.yytext.substr(2, yy_.yytext.length-4);return 15;
break;
-case 26:yy.depth=0; this.begin('action'); return 43;
+case 27:yy.depth=0; this.begin('action'); return 44;
break;
-case 27:yy_.yytext = yy_.yytext.substr(2, yy_.yyleng-2); return 46;
+case 28:yy_.yytext = yy_.yytext.substr(2, yy_.yyleng-2); return 47;
break;
-case 28:/* ignore bad characters */
+case 29:/* ignore bad characters */
break;
-case 29:return 8;
+case 30:return 8;
break;
-case 30:return 47;
+case 31:return 48;
break;
-case 31:yy.depth++; return 43;
+case 32:yy.depth++; return 44;
break;
-case 32:yy.depth==0? this.begin(ebnf ? 'ebnf' : 'bnf') : yy.depth--; return 45;
+case 33:yy.depth==0? this.begin(ebnf ? 'ebnf' : 'bnf') : yy.depth--; return 46;
break;
-case 33:return 9;
+case 34:return 9;
break;
}
};
-lexer.rules = [/^%%/,/^\(/,/^\)/,/^\*/,/^\?/,/^\s+/,/^\/\/.*/,/^\/\*[^*]*\*/,/^[a-zA-Z][a-zA-Z0-9_-]*/,/^"[^"]+"/,/^'[^']+'/,/^:/,/^;/,/^\|/,/^%%/,/^%ebnf\b/,/^%prec\b/,/^%start\b/,/^%left\b/,/^%right\b/,/^%nonassoc\b/,/^%lex[\w\W]*?\/lex\b/,/^%[a-zA-Z]+[^\n]*/,/^<[a-zA-Z]*>/,/^\{\{[\w\W]*?\}\}/,/^%\{(.|\n)*?%\}/,/^\{/,/^->.*/,/^./,/^$/,/^[^{}]+/,/^\{/,/^\}/,/^(.|\n)+/];
-lexer.conditions = {"bnf":{"rules":[0,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29],"inclusive":true},"ebnf":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29],"inclusive":true},"action":{"rules":[29,30,31,32],"inclusive":false},"code":{"rules":[29,33],"inclusive":false},"INITIAL":{"rules":[5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29],"inclusive":true}};return lexer;})()
+lexer.rules = [/^%%/,/^\(/,/^\)/,/^\*/,/^\?/,/^\+/,/^\s+/,/^\/\/.*/,/^\/\*[^*]*\*/,/^[a-zA-Z][a-zA-Z0-9_-]*/,/^"[^"]+"/,/^'[^']+'/,/^:/,/^;/,/^\|/,/^%%/,/^%ebnf\b/,/^%prec\b/,/^%start\b/,/^%left\b/,/^%right\b/,/^%nonassoc\b/,/^%lex[\w\W]*?\/lex\b/,/^%[a-zA-Z]+[^\n]*/,/^<[a-zA-Z]*>/,/^\{\{[\w\W]*?\}\}/,/^%\{(.|\n)*?%\}/,/^\{/,/^->.*/,/^./,/^$/,/^[^{}]+/,/^\{/,/^\}/,/^(.|\n)+/];
+lexer.conditions = {"bnf":{"rules":[0,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],"inclusive":true},"ebnf":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],"inclusive":true},"action":{"rules":[30,31,32,33],"inclusive":false},"code":{"rules":[30,34],"inclusive":false},"INITIAL":{"rules":[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30],"inclusive":true}};
+
+;
+return lexer;})()
parser.lexer = lexer;
return parser;
})();
View
1  src/bnf.jison
@@ -122,6 +122,7 @@ suffix
: {$$ = ''}
| '*'
| '?'
+ | '+'
;
prec
View
1  src/bnf.jisonlex
@@ -9,6 +9,7 @@
<ebnf>")" return ')'
<ebnf>"*" return '*'
<ebnf>"?" return '?'
+<ebnf>"+" return '+'
\s+ /* skip whitespace */
"//".* /* skip comment */
View
24 tests/grammar/ebnf.js
@@ -23,6 +23,27 @@ function testParse(top, strings) {
}
}
+function testBadParse(top, strings) {
+ return function() {
+ var grammar = {
+ "lex": {
+ "rules": [
+ ["\\s+", ''],
+ ["[A-Za-z]+", "return 'word';"],
+ [",", "return ',';"],
+ ["$", "return 'EOF';"]
+ ]
+ },
+ "start": "top",
+ "ebnf": {"top": [top]}
+ }
+ strings = (typeof(strings) === 'string' ? [strings] : strings)
+ strings.forEach(function(string) {
+ assert["throws"](function () {new Parser(grammar).parse(string);})
+ });
+ }
+}
+
var tests = {
"test idempotent transform": function() {
var first = {
@@ -34,6 +55,9 @@ var tests = {
"test repeat (*) on empty string": testParse("word* EOF", ""),
"test repeat (*) on single word": testParse("word* EOF", "oneword"),
"test repeat (*) on multiple words": testParse("word* EOF", "multiple words"),
+ "test repeat (+) on empty string": testBadParse("word+ EOF", ""),
+ "test repeat (+) on single word": testParse("word+ EOF", "oneword"),
+ "test repeat (+) on multiple words": testParse("word+ EOF", "multiple words"),
"test option (?) on empty string": testParse("word? EOF", ""),
"test option (?) on single word": testParse("word? EOF", "oneword"),
"test group () on simple phrase": testParse("(word word) EOF", "two words"),
View
2  tests/grammar/ebnf_parse.js
@@ -24,6 +24,8 @@ var tests = {
"test repeat (*) on empty string": testParse("word* EOF", ""),
"test repeat (*) on single word": testParse("word* EOF", "oneword"),
"test repeat (*) on multiple words": testParse("word* EOF", "multiple words"),
+ "test repeat (+) on single word": testParse("word+ EOF", "oneword"),
+ "test repeat (+) on multiple words": testParse("word+ EOF", "multiple words"),
"test option (?) on empty string": testParse("word? EOF", ""),
"test option (?) on single word": testParse("word? EOF", "oneword"),
"test group () on simple phrase": testParse("(word word) EOF", "two words"),
Please sign in to comment.
Something went wrong with that request. Please try again.