Skip to content
This repository has been archived by the owner on Jun 15, 2019. It is now read-only.

Commit

Permalink
working on zaach#20 / zaach/jison#341: collecting the first few stati…
Browse files Browse the repository at this point in the history
…stics of the generated lexer to be used in the code optimizer.
  • Loading branch information
GerHobbelt committed Mar 27, 2017
1 parent e1f3d87 commit 34c8223
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions regexp-lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts)
active_conditions,
rules = dict.rules,
newRules = [],
macros = {};
macros = {},
regular_rule_count = 0,
simple_rule_count = 0;

// Assure all options are camelCased:
assert(typeof opts.options['case-insensitive'] === 'undefined');
Expand Down Expand Up @@ -306,8 +308,10 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts)
// always append `break;` even when it would be obvious to a human that such would be 'unreachable code'.
var match_nr = /^return[\s\r\n]+((?:'(?:\\'|[^']+)+')|(?:"(?:\\"|[^"]+)+")|\d+)[\s\r\n]*;?$/.exec(action.trim());
if (match_nr) {
simple_rule_count++;
caseHelper.push([].concat(code, i, ':', match_nr[1]).join(' ').replace(/[\n]/g, '\n '));
} else {
regular_rule_count++;
actions.push([].concat('case', i, ':', code, action, '\nbreak;').join(' '));
}
}
Expand All @@ -317,7 +321,10 @@ function prepareRules(dict, actions, caseHelper, tokens, startConditions, opts)

return {
rules: newRules,
macros: macros
macros: macros,

regular_rule_count: regular_rule_count,
simple_rule_count: simple_rule_count,
};
}

Expand Down Expand Up @@ -903,7 +910,10 @@ function buildActions(dict, tokens, opts) {
actions: expandParseArguments('function lexer__performAction(yy, yy_, $avoiding_name_collisions, YY_START, parseParams) {\n', opts) + fun + '\n}',

rules: gen.rules,
macros: gen.macros // propagate these for debugging/diagnostic purposes
macros: gen.macros, // propagate these for debugging/diagnostic purposes

regular_rule_count: gen.regular_rule_count,
simple_rule_count: gen.simple_rule_count,
};
}

Expand Down

0 comments on commit 34c8223

Please sign in to comment.