From e1f3d87513b324d2ba5dd461b18d2a7b29071333 Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Mon, 27 Mar 2017 23:28:03 +0200 Subject: [PATCH] working on https://github.com/zaach/jison-lex/issues/20 / https://github.com/zaach/jison/issues/341: pass parser analysis info bits to the lexer compiler using better names, so they are confused once in there. --- regexp-lexer.js | 96 ++++++++++++++++++++++++------------------------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/regexp-lexer.js b/regexp-lexer.js index 665047d..73f3c98 100644 --- a/regexp-lexer.js +++ b/regexp-lexer.js @@ -992,6 +992,7 @@ function RegExpLexer(dict, input, tokens, build_options) { function test_me(tweak_cb, description, src_exception, ex_callback) { opts = processGrammar(dict, tokens, build_options); opts.__in_rules_failure_analysis_mode__ = false; + assert(opts.options); if (tweak_cb) { tweak_cb(); } @@ -1901,23 +1902,23 @@ function processGrammar(dict, tokens, build_options) { // // (this stuff comes straight from the jison Optimization Analysis.) // - opts.actionsAreAllDefault = build_options.actionsAreAllDefault; - opts.actionsUseYYLENG = build_options.actionsUseYYLENG; - opts.actionsUseYYLINENO = build_options.actionsUseYYLINENO; - opts.actionsUseYYTEXT = build_options.actionsUseYYTEXT; - opts.actionsUseYYLOC = build_options.actionsUseYYLOC; - opts.actionsUseParseError = build_options.actionsUseParseError; - opts.actionsUseYYERROR = build_options.actionsUseYYERROR; - opts.actionsUseYYERROK = build_options.actionsUseYYERROK; - opts.actionsUseYYCLEARIN = build_options.actionsUseYYCLEARIN; - opts.actionsUseValueTracking = build_options.actionsUseValueTracking; - opts.actionsUseValueAssignment = build_options.actionsUseValueAssignment; - opts.actionsUseLocationTracking = build_options.actionsUseLocationTracking; - opts.actionsUseLocationAssignment = build_options.actionsUseLocationAssignment; - opts.actionsUseYYSTACK = build_options.actionsUseYYSTACK; - opts.actionsUseYYSSTACK = build_options.actionsUseYYSSTACK; - opts.actionsUseYYSTACKPOINTER = build_options.actionsUseYYSTACKPOINTER; - opts.hasErrorRecovery = build_options.hasErrorRecovery; + opts.parseActionsAreAllDefault = build_options.parseActionsAreAllDefault; + opts.parseActionsUseYYLENG = build_options.parseActionsUseYYLENG; + opts.parseActionsUseYYLINENO = build_options.parseActionsUseYYLINENO; + opts.parseActionsUseYYTEXT = build_options.parseActionsUseYYTEXT; + opts.parseActionsUseYYLOC = build_options.parseActionsUseYYLOC; + opts.parseActionsUseParseError = build_options.parseActionsUseParseError; + opts.parseActionsUseYYERROR = build_options.parseActionsUseYYERROR; + opts.parseActionsUseYYERROK = build_options.parseActionsUseYYERROK; + opts.parseActionsUseYYCLEARIN = build_options.parseActionsUseYYCLEARIN; + opts.parseActionsUseValueTracking = build_options.parseActionsUseValueTracking; + opts.parseActionsUseValueAssignment = build_options.parseActionsUseValueAssignment; + opts.parseActionsUseLocationTracking = build_options.parseActionsUseLocationTracking; + opts.parseActionsUseLocationAssignment = build_options.parseActionsUseLocationAssignment; + opts.parseActionsUseYYSTACK = build_options.parseActionsUseYYSTACK; + opts.parseActionsUseYYSSTACK = build_options.parseActionsUseYYSSTACK; + opts.parseActionsUseYYSTACKPOINTER = build_options.parseActionsUseYYSTACKPOINTER; + opts.parserHasErrorRecovery = build_options.parserHasErrorRecovery; dict = autodetectAndConvertToJSONformat(dict, build_options) || {}; @@ -1925,6 +1926,7 @@ function processGrammar(dict, tokens, build_options) { // (for use by our error diagnostic assistance code) opts.lex_rule_dictionary = dict; + // Always provide the lexer with an options object, even if it's empty! // Make sure to camelCase all options: opts.options = mkStdOptions(build_options, dict.options); @@ -2023,23 +2025,23 @@ function generateModuleBody(opt) { backtrack_lexer: 0, caseInsensitive: 0, showSource: 1, - actionsAreAllDefault: 1, - actionsUseYYLENG: 1, - actionsUseYYLINENO: 1, - actionsUseYYTEXT: 1, - actionsUseYYLOC: 1, - actionsUseParseError: 1, - actionsUseYYERROR: 1, - actionsUseYYERROK: 1, - actionsUseYYCLEARIN: 1, - actionsUseValueTracking: 1, - actionsUseValueAssignment: 1, - actionsUseLocationTracking: 1, - actionsUseLocationAssignment: 1, - actionsUseYYSTACK: 1, - actionsUseYYSSTACK: 1, - actionsUseYYSTACKPOINTER: 1, - hasErrorRecovery: 1, + parseActionsAreAllDefault: 1, + parseActionsUseYYLENG: 1, + parseActionsUseYYLINENO: 1, + parseActionsUseYYTEXT: 1, + parseActionsUseYYLOC: 1, + parseActionsUseParseError: 1, + parseActionsUseYYERROR: 1, + parseActionsUseYYERROK: 1, + parseActionsUseYYCLEARIN: 1, + parseActionsUseValueTracking: 1, + parseActionsUseValueAssignment: 1, + parseActionsUseLocationTracking: 1, + parseActionsUseLocationAssignment: 1, + parseActionsUseYYSTACK: 1, + parseActionsUseYYSSTACK: 1, + parseActionsUseYYSTACKPOINTER: 1, + parserHasErrorRecovery: 1, }; for (var k in opts) { if (!do_not_pass[k] && opts[k] != null && opts[k] !== false) { @@ -2087,13 +2089,13 @@ var lexer = { // location.ranges: ${opt.options.ranges} // // Forwarded Parser Analysis flags: - // uses yyleng: ${opt.actionsUseYYLENG} - // uses yylineno: ${opt.actionsUseYYLINENO} - // uses yytext: ${opt.actionsUseYYTEXT} - // uses yylloc: ${opt.actionsUseYYLOC} - // uses lexer values: ${opt.actionsUseValueTracking} / ${opt.actionsUseValueAssignment} - // location tracking: ${opt.actionsUseLocationTracking} - // location assignment: ${opt.actionsUseLocationAssignment} + // uses yyleng: ${opt.parseActionsUseYYLENG} + // uses yylineno: ${opt.parseActionsUseYYLINENO} + // uses yytext: ${opt.parseActionsUseYYTEXT} + // uses yylloc: ${opt.parseActionsUseYYLOC} + // uses lexer values: ${opt.parseActionsUseValueTracking} / ${opt.parseActionsUseValueAssignment} + // location tracking: ${opt.parseActionsUseLocationTracking} + // location assignment: ${opt.parseActionsUseLocationAssignment} // // --------- END OF REPORT ----------- @@ -2109,15 +2111,11 @@ var lexer = { protosrc = stripUnusedLexerCode(protosrc, opt); out += protosrc + ',\n'; - if (opt.options) { - // Assure all options are camelCased: - assert(typeof opt.options['case-insensitive'] === 'undefined'); + assert(opt.options); + // Assure all options are camelCased: + assert(typeof opt.options['case-insensitive'] === 'undefined'); - out += ' options: ' + produceOptions(opt.options); - } else { - // always provide the lexer with an options object, even if it's empty! - out += ' options: {}'; - } + out += ' options: ' + produceOptions(opt.options); out += ',\n JisonLexerError: JisonLexerError'; out += ',\n performAction: ' + String(opt.performAction);