Skip to content

Commit

Permalink
refactored the parseArgs code which was done for zaach#332
Browse files Browse the repository at this point in the history
  • Loading branch information
GerHobbelt committed Nov 10, 2016
1 parent ee65998 commit 4516862
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions lib/jison.js
Original file line number Diff line number Diff line change
Expand Up @@ -2912,6 +2912,24 @@ function removeFeatureMarkers(fn) {
return parseFn;
}

// Fill in the optional, extra parse parameters (`%parse-param ...`)
// in the generated parser.
//
// See for important context:
//
// https://github.com/zaach/jison/pull/332
function expandParseArguments(parseFn, self) {
var arglist = self.parseParams;

if (!arglist) {
parseFn = parseFn.replace(/, parseParams/g, '');
} else {
parseFn = parseFn.replace(/, parseParams/g, ', ' + arglist.join(', '));
}
return parseFn;
}


function pickOneOfTwoCodeAlternatives(parseFn, pick_A_not_B, A_start_marker, B_start_marker, end_marker) {
// Notes:
// 1) we use the special /[^\0]*/ regex set as that one will also munch newlines, etc.
Expand Down Expand Up @@ -3026,13 +3044,7 @@ lrGeneratorMixin.generateModule_ = function generateModule_() {

parseFn = removeUnusedKernelFeatures(parseFn, this);

// fill in the optional, extra parse parameters (`%parse-param ...`)
// in the generated parser:
if (!this.parseParams) {
parseFn = parseFn.replace(/, parseParams/g, '');
} else {
parseFn = parseFn.replace(/, parseParams/g, ', ' + this.parseParams.join(', '));
}
parseFn = expandParseArguments(parseFn, this);

var errorClassCode = this.generateErrorClass();

Expand Down Expand Up @@ -5042,7 +5054,7 @@ _handle_error_end_of_section: // this concludes the error recov
// read action for current state and first input
t = (table[newState] && table[newState][symbol]) || NO_ACTION;
if (!t[0]) {
// forget about that symbol and move forward: this wasn't an 'forgot to insert' error type where
// forget about that symbol and move forward: this wasn't a 'forgot to insert' error type where
// (simple) stuff might have been missing before the token which caused the error we're
// recovering from now...
if (yydebug) yydebug('... SHIFT:error recovery: re-application of old symbol doesn\'t work: instead, we\'re moving forward now. ', { recovering: recovering, symbol: symbol });
Expand Down

0 comments on commit 4516862

Please sign in to comment.