diff --git a/lib/jison.js b/lib/jison.js index eeafef10e..54b78a57a 100755 --- a/lib/jison.js +++ b/lib/jison.js @@ -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. @@ -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(); @@ -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 });