diff --git a/lib/jison.js b/lib/jison.js index ea8571c02..913a8edd5 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -862,7 +862,7 @@ generator.buildProductions = function buildProductions(bnf, productions, nonterm // before all others: this way these tokens have the maximum chance to get assigned their ASCII value as symbol ID, // which helps debugging/diagnosis of generated grammars. // (This is why previously we had set `usedSymbolIdsLowIndex` to 127 instead of 3!) - + var prodsLUT = {}; for (symbol in bnf) { if (!bnf.hasOwnProperty(symbol)) continue; @@ -975,7 +975,7 @@ generator.buildProductions = function buildProductions(bnf, productions, nonterm } rhs = rhs.substr(pos + 1); // now find the matching end marker. - // + // // Edge case: token MAY include the ESCAPED MARKER... or other escapes! // Hence we need to skip over ALL escapes inside the token! var pos3 = rhs.indexOf('\\'); @@ -1315,7 +1315,7 @@ generator.buildProductionActions = function buildProductionActions() { .replace(/\x01\x1B/g, 'yysp'); // And a final, minimal, fixup for the semicolon-lovers -- like me! ;-) - // + // // Make sure the last statement is properly semicolon-terminated 99.9% of the time: s = s .replace(/[\s\r\n]+$/, '') // trim trailing whitespace and empty lines @@ -1334,7 +1334,7 @@ generator.buildProductionActions = function buildProductionActions() { // and now go and process the entire grammar: productions.forEach(buildProductionAction); - + for (var hash in actionGroups) { actions.push([].concat.apply([], actionGroups[hash]).join('') + actionGroupValue[hash] + '\n break;\n'); } @@ -3228,9 +3228,17 @@ function removeUnusedKernelFeatures(parseFn, info) { * * // perform semantic action * yyval.$ = vstack[sp - len]; // default to $$ = $1 + * + * and this bit of comment: + * + * // Make sure subsequent `$$ = $1` default action doesn't fail + * // for rules where len==0 as then there's no $1 (you're reducing an epsilon rule then!) + * // + * // Also do this ... */ parseFn = parseFn - .replace(/\s+\/\/ perform semantic action\n\s+yyval\.\$ = vstack\[sp - [^\n]+\n/g, '\n\n'); + .replace(/\s+\/\/ perform semantic action\n\s+yyval\.\$ = vstack\[sp - [^\n]+\n/g, '\n\n') + .replace(/\s+\/\/ Make sure subsequent `\$\$ = \$1` default action doesn't fail\n[^\n]+\n[^\n]+\n(\s+\/\/ )Also do this/g, '\n\n\n\n\n$1Do this'); } if (info.options.noTryCatch) {