Skip to content

Commit d2f8af7

Browse files
committed
improved version of SHA-1: 1cb19b4 (:: Fix performance bug: Dynamic argumets - Bad value context for argument value): as we know the %parse-param names of each extra parse call parameter, we can use those to create a customized version of the parser for the given grammar + param set, without resorting slow slice(arguments) code or (also slow) bind+function wrap.
1 parent 002a5ae commit d2f8af7

File tree

7 files changed

+35
-33
lines changed

7 files changed

+35
-33
lines changed

lib/jison.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,6 +2916,14 @@ lrGeneratorMixin.generateModule_ = function generateModule_() {
29162916

29172917
parseFn = removeUnusedKernelFeatures(parseFn, this);
29182918

2919+
// fill in the optional, extra parse parameters (`%parse-param ...`)
2920+
// in the generated parser:
2921+
if (!this.parseParams) {
2922+
parseFn = parseFn.replace(/, parseParams/g, '');
2923+
} else {
2924+
parseFn = parseFn.replace(/, parseParams/g, ', ' + this.parseParams.join(', '));
2925+
}
2926+
29192927
var errorClassCode = this.generateErrorClass();
29202928

29212929
// set up the 'option' `exportAllTables` as a hash object for returning
@@ -4391,7 +4399,7 @@ for (var api in api_set) {
43914399
}
43924400

43934401

4394-
parser.parse = function parse(input) {
4402+
parser.parse = function parse(input, parseParams) {
43954403
var self = this,
43964404
stack = new Array(128), // token stack: stores token which leads to state at the same index (column storage)
43974405
sstack = new Array(128), // state stack: stores states
@@ -4407,8 +4415,6 @@ parser.parse = function parse(input) {
44074415
ERROR_RECOVERY_TOKEN_DISCARD_COUNT = (this.options.errorRecoveryTokenDiscardCount | 0) || 3;
44084416
var NO_ACTION = [0, table.length /* ensures that anyone using this new state will fail dramatically! */];
44094417

4410-
var args = stack.slice.call(arguments, 1);
4411-
44124418
//this.reductionCount = this.shiftCount = 0;
44134419

44144420
var lexer;
@@ -4583,11 +4589,11 @@ parser.parse = function parse(input) {
45834589

45844590
if (invoke_post_methods) {
45854591
if (sharedState.yy.post_parse) {
4586-
rv = sharedState.yy.post_parse.apply(this, [sharedState.yy, resultValue].concat(args));
4592+
rv = sharedState.yy.post_parse.apply(this, [sharedState.yy, resultValue, parseParams]);
45874593
if (typeof rv !== 'undefined') resultValue = rv;
45884594
}
45894595
if (this.post_parse) {
4590-
rv = this.post_parse.apply(this, [sharedState.yy, resultValue].concat(args));
4596+
rv = this.post_parse.apply(this, [sharedState.yy, resultValue, parseParams]);
45914597
if (typeof rv !== 'undefined') resultValue = rv;
45924598
}
45934599
}
@@ -4740,10 +4746,10 @@ _handle_error_end_of_section: // this concludes the error reco
47404746
this.__reentrant_call_depth++;
47414747

47424748
if (this.pre_parse) {
4743-
this.pre_parse.apply(this, [sharedState.yy].concat(args));
4749+
this.pre_parse.apply(this, [sharedState.yy, parseParams]);
47444750
}
47454751
if (sharedState.yy.pre_parse) {
4746-
sharedState.yy.pre_parse.apply(this, [sharedState.yy].concat(args));
4752+
sharedState.yy.pre_parse.apply(this, [sharedState.yy, parseParams]);
47474753
}
47484754

47494755
newState = sstack[sp - 1];
@@ -4967,7 +4973,7 @@ _handle_error_end_of_section: // this concludes the error recov
49674973
yyval._$.range = [lstack[lstack_begin].range[0], lstack[lstack_end].range[1]];
49684974
}
49694975

4970-
r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, yyloc, sharedState.yy, newState, sp - 1, vstack, lstack, stack, sstack].concat(args));
4976+
r = this.performAction.apply(yyval, [yytext, yyleng, yylineno, yyloc, sharedState.yy, newState, sp - 1, vstack, lstack, stack, sstack, parseParams]);
49714977

49724978
if (typeof r !== 'undefined') {
49734979
retval = r;

lib/util/ebnf-parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ bnf.yy.addDeclaration = function bnfAddDeclaration(grammar, decl) {
2525
decl.token_list.forEach(function (tok) {
2626
grammar.extra_tokens.push(tok);
2727
});
28-
} else if (decl.parseParam) {
28+
} else if (decl.parseParams) {
2929
if (!grammar.parseParams) grammar.parseParams = [];
30-
grammar.parseParams = grammar.parseParams.concat(decl.parseParam);
30+
grammar.parseParams = grammar.parseParams.concat(decl.parseParams);
3131
} else if (decl.parserType) {
3232
if (!grammar.options) grammar.options = {};
3333
grammar.options.type = decl.parserType;

lib/util/lex-parser.js

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util/parser.js

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util/transform-parser.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/lex-parser

0 commit comments

Comments
 (0)