Skip to content

Commit

Permalink
Strip out a then-invalid comment when --no-default-action is set fo…
Browse files Browse the repository at this point in the history
…r the given grammar: the kernel code should not carry blatantly incorrect comments either after kernel stripping! Sideways related to zaach#341.
  • Loading branch information
GerHobbelt committed Jan 31, 2017
1 parent fce937c commit 384ee8a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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('\\');
Expand Down Expand Up @@ -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
Expand All @@ -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');
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 384ee8a

Please sign in to comment.