From d123cf0eda1a459d9e6c662c45b40de639196207 Mon Sep 17 00:00:00 2001 From: David Majda Date: Mon, 22 Aug 2011 19:48:43 +0200 Subject: [PATCH] Rewrite variable handling in generated parsers Before this commit, variables for saving match results and parse positions in generated parsers were not used efficiently. Each rule basically used its own variable(s) for storing the data, with names generated sequentially during code emitting. There was no reuse of variables and a lot of unnecessary assignments between them. It is easy to see that both match results and parse positions can actually be stored on a stack that grows as the parser walks deeper in the grammar tree and shrinks as it returns. Moreover, if one creates a new stack for each rule the parser enters, its maximum depth can be computed statically from the grammar. This allows us to implement the stack not as an array, but as a set of numbered variables in each function that handles parsing of a grammar rule, avoiding potentially slow array accesses. This commit implements the idea from the previous paragraph, using separate stack for match results and for parse positions. As a result, defined variables are reused and unnecessary copying avoided. Speed implications ------------------ This change speeds up the benchmark suite execution by 2.14%. Detailed results (benchmark suite totals as reported by "jake benchmark" on Node.js 0.4.8): ----------------------------------- Test # Before After ----------------------------------- 1 129.01 kB/s 131.98 kB/s 2 129.39 kB/s 130.13 kB/s 3 128.63 kB/s 132.57 kB/s 4 127.53 kB/s 129.82 kB/s 5 127.98 kB/s 131.80 kB/s ----------------------------------- Average 128.51 kB/s 131.26 kB/s ----------------------------------- Size implications ----------------- This change makes a sample of generated parsers 8.60% smaller: Before: $ wc -c src/parser.js examples/*.js 110867 src/parser.js 13886 examples/arithmetics.js 450125 examples/css.js 632390 examples/javascript.js 61365 examples/json.js 1268633 total After: $ wc -c src/parser.js examples/*.js 99597 src/parser.js 13077 examples/arithmetics.js 399893 examples/css.js 592044 examples/javascript.js 54797 examples/json.js 1159408 total --- src/compiler.js | 3 +- src/emitter.js | 327 ++--- src/parser.js | 3119 ++++++++++++++++++++----------------------- src/passes.js | 76 ++ src/utils.js | 18 +- test/passes-test.js | 86 ++ 6 files changed, 1804 insertions(+), 1825 deletions(-) diff --git a/src/compiler.js b/src/compiler.js index f8a93e9..dd10973 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -12,7 +12,8 @@ PEG.compiler = { ]; var PASS_NAMES = [ - "proxyRules" + "proxyRules", + "stackDepths" ]; for (var i = 0; i < CHECK_NAMES.length; i++) { diff --git a/src/emitter.js b/src/emitter.js index 58a2bca..d0e30ab 100644 --- a/src/emitter.js +++ b/src/emitter.js @@ -76,19 +76,8 @@ PEG.compiler.emitter = function(ast) { return indentMultilineParts(interpolateVariablesInParts(args)).join("\n"); }; - /* Unique ID generator. */ - var UID = { - _counters: {}, - - next: function(prefix) { - this._counters[prefix] = this._counters[prefix] || 0; - return prefix + this._counters[prefix]++; - }, - - reset: function() { - this._counters = {}; - } - }; + function resultVar(index) { return "result" + index; } + function posVar(index) { return "pos" + index; } var emit = buildNodeVisitor({ grammar: function(node) { @@ -332,16 +321,16 @@ PEG.compiler.emitter = function(ast) { }, rule: function(node) { - /* - * We want to reset variable names at the beginning of every function so - * that a little change in the source grammar does not change variables in - * all the generated code. This is desired especially when one has the - * generated grammar stored in a VCS (this is true e.g. for our - * metagrammar). - */ - UID.reset(); + var context = { + resultIndex: 0, + posIndex: 0 + }; + + var resultVars = map(range(node.resultStackDepth), resultVar); + var posVars = map(range(node.posStackDepth), posVar); - var resultVar = UID.next("result"); + var resultVarsCode = resultVars.length > 0 ? "var " + resultVars.join(", ") + ";" : ""; + var posVarsCode = posVars.length > 0 ? "var " + posVars.join(", ") + ";" : ""; if (node.displayName !== null) { var setReportFailuresCode = formatCode( @@ -356,7 +345,7 @@ PEG.compiler.emitter = function(ast) { "}", { displayName: node.displayName, - resultVar: resultVar + resultVar: resultVar(context.resultIndex) } ); } else { @@ -374,6 +363,9 @@ PEG.compiler.emitter = function(ast) { " return cachedResult.result;", " }", " ", + " ${resultVarsCode}", + " ${posVarsCode}", + " ", " ${setReportFailuresCode}", " ${code}", " ${restoreReportFailuresCode}", @@ -387,51 +379,68 @@ PEG.compiler.emitter = function(ast) { "}", { name: node.name, + resultVarsCode: resultVarsCode, + posVarsCode: posVarsCode, setReportFailuresCode: setReportFailuresCode, restoreReportFailuresCode: restoreReportFailuresCode, reportFailureCode: reportFailureCode, - code: emit(node.expression, resultVar), - resultVar: resultVar + code: emit(node.expression, context), + resultVar: resultVar(context.resultIndex) } ); }, /* * The contract for all code fragments generated by the following functions - * is as follows: + * is as follows. + * + * The code fragment tries to match a part of the input starting with the + * position indicated in |pos|. That position may point past the end of the + * input. + * + * * If the code fragment matches the input, it advances |pos| to point to + * the first chracter following the matched part of the input and sets + * variable with a name computed by calling + * |resultVar(context.resultIndex)| to an appropriate value. This value is + * always non-|null|. + * + * * If the code fragment does not match the input, it returns with |pos| + * set to the original value and it sets a variable with a name computed + * by calling |resultVar(context.resultIndex)| to |null|. * - * * The code fragment should try to match a part of the input starting with - * the position indicated in |pos|. That position may point past the end of - * the input. + * The code can use variables with names computed by calling * - * * If the code fragment matches the input, it advances |pos| after the - * matched part of the input and sets variable with a name stored in - * |resultVar| to appropriate value, which is always non-null. + * |resultVar(context.resultIndex + i)| * - * * If the code fragment does not match the input, it does not change |pos| - * and it sets a variable with a name stored in |resultVar| to |null|. + * and + * + * |posVar(context.posIndex + i)| + * + * where |i| >= 1 to store necessary data (return values and positions). It + * won't use any other variables. */ - choice: function(node, resultVar) { - var code = formatCode( - "var ${resultVar} = null;", - { resultVar: resultVar } - ); + choice: function(node, context) { + var code, nextAlternativesCode; for (var i = node.alternatives.length - 1; i >= 0; i--) { - var alternativeResultVar = UID.next("result"); + nextAlternativesCode = i !== node.alternatives.length - 1 + ? formatCode( + "if (${resultVar} === null) {", + " ${code}", + "}", + { + code: code, + resultVar: resultVar(context.resultIndex) + } + ) + : ""; code = formatCode( - "${alternativeCode}", - "if (${alternativeResultVar} !== null) {", - " var ${resultVar} = ${alternativeResultVar};", - "} else {", - " ${code};", - "}", + "${currentAlternativeCode}", + "${nextAlternativesCode}", { - alternativeCode: emit(node.alternatives[i], alternativeResultVar), - alternativeResultVar: alternativeResultVar, - code: code, - resultVar: resultVar + currentAlternativeCode: emit(node.alternatives[i], context), + nextAlternativesCode: nextAlternativesCode } ); } @@ -439,177 +448,185 @@ PEG.compiler.emitter = function(ast) { return code; }, - sequence: function(node, resultVar) { - var savedPosVar = UID.next("savedPos"); - - var elementResultVars = map(node.elements, function() { - return UID.next("result") + sequence: function(node, context) { + var elementResultVars = map(node.elements, function(element, i) { + return resultVar(context.resultIndex + i); }); var code = formatCode( - "var ${resultVar} = ${elementResultVarArray};", + "${resultVar} = ${elementResultVarArray};", { - resultVar: resultVar, + resultVar: resultVar(context.resultIndex), elementResultVarArray: "[" + elementResultVars.join(", ") + "]" } ); + var elementContext; for (var i = node.elements.length - 1; i >= 0; i--) { + elementContext = { + resultIndex: context.resultIndex + i, + posIndex: context.posIndex + 1 + }; code = formatCode( "${elementCode}", "if (${elementResultVar} !== null) {", " ${code}", "} else {", - " var ${resultVar} = null;", - " pos = ${savedPosVar};", + " ${resultVar} = null;", + " pos = ${posVar};", "}", { - elementCode: emit(node.elements[i], elementResultVars[i]), + elementCode: emit(node.elements[i], elementContext), elementResultVar: elementResultVars[i], code: code, - savedPosVar: savedPosVar, - resultVar: resultVar + posVar: posVar(context.posIndex), + resultVar: resultVar(context.resultIndex) } ); } return formatCode( - "var ${savedPosVar} = pos;", + "${posVar} = pos;", "${code}", { - code: code, - savedPosVar: savedPosVar + code: code, + posVar: posVar(context.posIndex) } ); }, - labeled: function(node, resultVar) { - return emit(node.expression, resultVar); + labeled: function(node, context) { + return emit(node.expression, context); }, - simple_and: function(node, resultVar) { - var savedPosVar = UID.next("savedPos"); - var expressionResultVar = UID.next("result"); + simple_and: function(node, context) { + var expressionContext = { + resultIndex: context.resultIndex, + posIndex: context.posIndex + 1 + }; return formatCode( - "var ${savedPosVar} = pos;", + "${posVar} = pos;", "reportFailures++;", "${expressionCode}", "reportFailures--;", - "if (${expressionResultVar} !== null) {", - " var ${resultVar} = '';", - " pos = ${savedPosVar};", + "if (${resultVar} !== null) {", + " ${resultVar} = '';", + " pos = ${posVar};", "} else {", - " var ${resultVar} = null;", + " ${resultVar} = null;", "}", { - expressionCode: emit(node.expression, expressionResultVar), - expressionResultVar: expressionResultVar, - savedPosVar: savedPosVar, - resultVar: resultVar + expressionCode: emit(node.expression, expressionContext), + posVar: posVar(context.posIndex), + resultVar: resultVar(context.resultIndex) } ); }, - simple_not: function(node, resultVar) { - var savedPosVar = UID.next("savedPos"); - var expressionResultVar = UID.next("result"); + simple_not: function(node, context) { + var expressionContext = { + resultIndex: context.resultIndex, + posIndex: context.posIndex + 1 + }; return formatCode( - "var ${savedPosVar} = pos;", + "${posVar} = pos;", "reportFailures++;", "${expressionCode}", "reportFailures--;", - "if (${expressionResultVar} === null) {", - " var ${resultVar} = '';", + "if (${resultVar} === null) {", + " ${resultVar} = '';", "} else {", - " var ${resultVar} = null;", - " pos = ${savedPosVar};", + " ${resultVar} = null;", + " pos = ${posVar};", "}", { - expressionCode: emit(node.expression, expressionResultVar), - expressionResultVar: expressionResultVar, - savedPosVar: savedPosVar, - resultVar: resultVar + expressionCode: emit(node.expression, expressionContext), + posVar: posVar(context.posIndex), + resultVar: resultVar(context.resultIndex) } ); }, - semantic_and: function(node, resultVar) { + semantic_and: function(node, context) { return formatCode( - "var ${resultVar} = (function() {${actionCode}})() ? '' : null;", + "${resultVar} = (function() {${actionCode}})() ? '' : null;", { - actionCode: node.code, - resultVar: resultVar + actionCode: node.code, + resultVar: resultVar(context.resultIndex) } ); }, - semantic_not: function(node, resultVar) { + semantic_not: function(node, context) { return formatCode( - "var ${resultVar} = (function() {${actionCode}})() ? null : '';", + "${resultVar} = (function() {${actionCode}})() ? null : '';", { - actionCode: node.code, - resultVar: resultVar + actionCode: node.code, + resultVar: resultVar(context.resultIndex) } ); }, - optional: function(node, resultVar) { - var expressionResultVar = UID.next("result"); - + optional: function(node, context) { return formatCode( "${expressionCode}", - "var ${resultVar} = ${expressionResultVar} !== null ? ${expressionResultVar} : '';", + "${resultVar} = ${resultVar} !== null ? ${resultVar} : '';", { - expressionCode: emit(node.expression, expressionResultVar), - expressionResultVar: expressionResultVar, - resultVar: resultVar + expressionCode: emit(node.expression, context), + resultVar: resultVar(context.resultIndex) } ); }, - zero_or_more: function(node, resultVar) { - var expressionResultVar = UID.next("result"); + zero_or_more: function(node, context) { + var expressionContext = { + resultIndex: context.resultIndex + 1, + posIndex: context.posIndex + }; return formatCode( - "var ${resultVar} = [];", + "${resultVar} = [];", "${expressionCode}", "while (${expressionResultVar} !== null) {", " ${resultVar}.push(${expressionResultVar});", " ${expressionCode}", "}", { - expressionCode: emit(node.expression, expressionResultVar), - expressionResultVar: expressionResultVar, - resultVar: resultVar + expressionCode: emit(node.expression, expressionContext), + expressionResultVar: resultVar(context.resultIndex + 1), + resultVar: resultVar(context.resultIndex) } ); }, - one_or_more: function(node, resultVar) { - var expressionResultVar = UID.next("result"); + one_or_more: function(node, context) { + var expressionContext = { + resultIndex: context.resultIndex + 1, + posIndex: context.posIndex + }; return formatCode( "${expressionCode}", "if (${expressionResultVar} !== null) {", - " var ${resultVar} = [];", + " ${resultVar} = [];", " while (${expressionResultVar} !== null) {", " ${resultVar}.push(${expressionResultVar});", " ${expressionCode}", " }", "} else {", - " var ${resultVar} = null;", + " ${resultVar} = null;", "}", { - expressionCode: emit(node.expression, expressionResultVar), - expressionResultVar: expressionResultVar, - resultVar: resultVar + expressionCode: emit(node.expression, expressionContext), + expressionResultVar: resultVar(context.resultIndex + 1), + resultVar: resultVar(context.resultIndex) } ); }, - action: function(node, resultVar) { + action: function(node, context) { /* * In case of sequences, we splat their elements into function arguments * one by one. Example: @@ -619,9 +636,10 @@ PEG.compiler.emitter = function(ast) { * This behavior is reflected in this function. */ - var expressionResultVar = UID.next("result"); - var actionResultVar = UID.next("result"); - var savedPosVar = UID.next("savedPos"); + var expressionContext = { + resultIndex: context.resultIndex, + posIndex: context.posIndex + 1 + }; if (node.expression.type === "sequence") { var formalParams = []; @@ -632,59 +650,54 @@ PEG.compiler.emitter = function(ast) { for (var i = 0; i < elementsLength; i++) { if (elements[i].type === "labeled") { formalParams.push(elements[i].label); - actualParams.push(expressionResultVar + "[" + i + "]"); + actualParams.push(resultVar(context.resultIndex) + "[" + i + "]"); } } } else if (node.expression.type === "labeled") { var formalParams = [node.expression.label]; - var actualParams = [expressionResultVar]; + var actualParams = [resultVar(context.resultIndex)]; } else { var formalParams = []; var actualParams = []; } return formatCode( - "var ${savedPosVar} = pos;", + "${posVar} = pos;", "${expressionCode}", - "var ${actionResultVar} = ${expressionResultVar} !== null", - " ? (function(${formalParams}) {${actionCode}})(${actualParams})", - " : null;", - "if (${actionResultVar} !== null) {", - " var ${resultVar} = ${actionResultVar};", - "} else {", - " var ${resultVar} = null;", - " pos = ${savedPosVar};", + "if (${resultVar} !== null) {", + " ${resultVar} = (function(${formalParams}) {${actionCode}})(${actualParams});", + "}", + "if (${resultVar} === null) {", + " pos = ${posVar};", "}", { - expressionCode: emit(node.expression, expressionResultVar), - expressionResultVar: expressionResultVar, - actionCode: node.code, - actionResultVar: actionResultVar, - formalParams: formalParams.join(", "), - actualParams: actualParams.join(", "), - savedPosVar: savedPosVar, - resultVar: resultVar + expressionCode: emit(node.expression, expressionContext), + actionCode: node.code, + formalParams: formalParams.join(", "), + actualParams: actualParams.join(", "), + posVar: posVar(context.posIndex), + resultVar: resultVar(context.resultIndex) } ); }, - rule_ref: function(node, resultVar) { + rule_ref: function(node, context) { return formatCode( - "var ${resultVar} = ${ruleMethod}();", + "${resultVar} = ${ruleMethod}();", { ruleMethod: "parse_" + node.name, - resultVar: resultVar + resultVar: resultVar(context.resultIndex) } ); }, - literal: function(node, resultVar) { + literal: function(node, context) { return formatCode( "if (input.substr(pos, ${length}) === ${value|string}) {", - " var ${resultVar} = ${value|string};", + " ${resultVar} = ${value|string};", " pos += ${length};", "} else {", - " var ${resultVar} = null;", + " ${resultVar} = null;", " if (reportFailures === 0) {", " matchFailed(${valueQuoted|string});", " }", @@ -693,27 +706,27 @@ PEG.compiler.emitter = function(ast) { value: node.value, valueQuoted: quote(node.value), length: node.value.length, - resultVar: resultVar + resultVar: resultVar(context.resultIndex) } ); }, - any: function(node, resultVar) { + any: function(node, context) { return formatCode( "if (input.length > pos) {", - " var ${resultVar} = input.charAt(pos);", + " ${resultVar} = input.charAt(pos);", " pos++;", "} else {", - " var ${resultVar} = null;", + " ${resultVar} = null;", " if (reportFailures === 0) {", " matchFailed('any character');", " }", "}", - { resultVar: resultVar } + { resultVar: resultVar(context.resultIndex) } ); }, - "class": function(node, resultVar) { + "class": function(node, context) { if (node.parts.length > 0) { var regexp = "/^[" + (node.inverted ? "^" : "") @@ -735,10 +748,10 @@ PEG.compiler.emitter = function(ast) { return formatCode( "if (input.substr(pos).match(${regexp}) !== null) {", - " var ${resultVar} = input.charAt(pos);", + " ${resultVar} = input.charAt(pos);", " pos++;", "} else {", - " var ${resultVar} = null;", + " ${resultVar} = null;", " if (reportFailures === 0) {", " matchFailed(${rawText|string});", " }", @@ -746,7 +759,7 @@ PEG.compiler.emitter = function(ast) { { regexp: regexp, rawText: node.rawText, - resultVar: resultVar + resultVar: resultVar(context.resultIndex) } ); } diff --git a/src/parser.js b/src/parser.js index 89f7fa1..2895ce0 100644 --- a/src/parser.js +++ b/src/parser.js @@ -143,40 +143,43 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3, result4; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; - var result3 = parse___(); - if (result3 !== null) { - var result7 = parse_initializer(); - var result4 = result7 !== null ? result7 : ''; - if (result4 !== null) { - var result6 = parse_rule(); - if (result6 !== null) { - var result5 = []; - while (result6 !== null) { - result5.push(result6); - var result6 = parse_rule(); + + pos0 = pos; + pos1 = pos; + result0 = parse___(); + if (result0 !== null) { + result1 = parse_initializer(); + result1 = result1 !== null ? result1 : ''; + if (result1 !== null) { + result3 = parse_rule(); + if (result3 !== null) { + result2 = []; + while (result3 !== null) { + result2.push(result3); + result3 = parse_rule(); } } else { - var result5 = null; + result2 = null; } - if (result5 !== null) { - var result1 = [result3, result4, result5]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(initializer, rules) { + if (result0 !== null) { + result0 = (function(initializer, rules) { var rulesConverted = {}; each(rules, function(rule) { rulesConverted[rule.name] = rule; }); @@ -186,13 +189,10 @@ PEG.parser = (function(){ rules: rulesConverted, startRule: rules[0].name } - })(result1[1], result1[2]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[1], result0[2]); + } + if (result0 === null) { + pos = pos0; } @@ -212,36 +212,36 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; - var result3 = parse_action(); - if (result3 !== null) { - var result5 = parse_semicolon(); - var result4 = result5 !== null ? result5 : ''; - if (result4 !== null) { - var result1 = [result3, result4]; + pos0 = pos; + pos1 = pos; + result0 = parse_action(); + if (result0 !== null) { + result1 = parse_semicolon(); + result1 = result1 !== null ? result1 : ''; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(code) { + if (result0 !== null) { + result0 = (function(code) { return { type: "initializer", code: code }; - })(result1[0]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[0]); + } + if (result0 === null) { + pos = pos0; } @@ -261,74 +261,68 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3, result4, result5; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; - var result3 = parse_identifier(); - if (result3 !== null) { - var result10 = parse_literal(); - if (result10 !== null) { - var result4 = result10; - } else { + + pos0 = pos; + pos1 = pos; + result0 = parse_identifier(); + if (result0 !== null) { + result1 = parse_literal(); + if (result1 === null) { if (input.substr(pos, 0) === "") { - var result9 = ""; + result1 = ""; pos += 0; } else { - var result9 = null; + result1 = null; if (reportFailures === 0) { matchFailed("\"\""); } } - if (result9 !== null) { - var result4 = result9; - } else { - var result4 = null;; - }; - } - if (result4 !== null) { - var result5 = parse_equals(); - if (result5 !== null) { - var result6 = parse_choice(); - if (result6 !== null) { - var result8 = parse_semicolon(); - var result7 = result8 !== null ? result8 : ''; - if (result7 !== null) { - var result1 = [result3, result4, result5, result6, result7]; + + } + if (result1 !== null) { + result2 = parse_equals(); + if (result2 !== null) { + result3 = parse_choice(); + if (result3 !== null) { + result4 = parse_semicolon(); + result4 = result4 !== null ? result4 : ''; + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(name, displayName, expression) { + if (result0 !== null) { + result0 = (function(name, displayName, expression) { return { type: "rule", name: name, displayName: displayName !== "" ? displayName : null, expression: expression }; - })(result1[0], result1[1], result1[3]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[0], result0[1], result0[3]); + } + if (result0 === null) { + pos = pos0; } @@ -348,55 +342,58 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3, result4, result5; + var pos0, pos1, pos2, pos3; + - var savedPos0 = pos; - var savedPos1 = pos; - var result3 = parse_sequence(); - if (result3 !== null) { - var result4 = []; - var savedPos2 = pos; - var result6 = parse_slash(); - if (result6 !== null) { - var result7 = parse_sequence(); - if (result7 !== null) { - var result5 = [result6, result7]; + pos0 = pos; + pos1 = pos; + result0 = parse_sequence(); + if (result0 !== null) { + result1 = []; + pos2 = pos; + result2 = parse_slash(); + if (result2 !== null) { + result3 = parse_sequence(); + if (result3 !== null) { + result2 = [result2, result3]; } else { - var result5 = null; - pos = savedPos2; + result2 = null; + pos = pos2; } } else { - var result5 = null; - pos = savedPos2; - } - while (result5 !== null) { - result4.push(result5); - var savedPos2 = pos; - var result6 = parse_slash(); - if (result6 !== null) { - var result7 = parse_sequence(); - if (result7 !== null) { - var result5 = [result6, result7]; + result2 = null; + pos = pos2; + } + while (result2 !== null) { + result1.push(result2); + pos2 = pos; + result2 = parse_slash(); + if (result2 !== null) { + result3 = parse_sequence(); + if (result3 !== null) { + result2 = [result2, result3]; } else { - var result5 = null; - pos = savedPos2; + result2 = null; + pos = pos2; } } else { - var result5 = null; - pos = savedPos2; + result2 = null; + pos = pos2; } } - if (result4 !== null) { - var result1 = [result3, result4]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(head, tail) { + if (result0 !== null) { + result0 = (function(head, tail) { if (tail.length > 0) { var alternatives = [head].concat(map( tail, @@ -409,13 +406,10 @@ PEG.parser = (function(){ } else { return head; } - })(result1[0], result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[0], result0[1]); + } + if (result0 === null) { + pos = pos0; } @@ -435,29 +429,32 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; - var savedPos1 = pos; - var savedPos2 = pos; - var result8 = []; - var result10 = parse_labeled(); - while (result10 !== null) { - result8.push(result10); - var result10 = parse_labeled(); + + pos0 = pos; + pos1 = pos; + result0 = []; + result1 = parse_labeled(); + while (result1 !== null) { + result0.push(result1); + result1 = parse_labeled(); } - if (result8 !== null) { - var result9 = parse_action(); - if (result9 !== null) { - var result6 = [result8, result9]; + if (result0 !== null) { + result1 = parse_action(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result6 = null; - pos = savedPos2; + result0 = null; + pos = pos1; } } else { - var result6 = null; - pos = savedPos2; + result0 = null; + pos = pos1; } - var result7 = result6 !== null - ? (function(elements, code) { + if (result0 !== null) { + result0 = (function(elements, code) { var expression = elements.length != 1 ? { type: "sequence", @@ -469,45 +466,33 @@ PEG.parser = (function(){ expression: expression, code: code }; - })(result6[0], result6[1]) - : null; - if (result7 !== null) { - var result5 = result7; - } else { - var result5 = null; - pos = savedPos1; - } - if (result5 !== null) { - var result0 = result5; - } else { - var savedPos0 = pos; - var result2 = []; - var result4 = parse_labeled(); - while (result4 !== null) { - result2.push(result4); - var result4 = parse_labeled(); - } - var result3 = result2 !== null - ? (function(elements) { + })(result0[0], result0[1]); + } + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + result0 = []; + result1 = parse_labeled(); + while (result1 !== null) { + result0.push(result1); + result1 = parse_labeled(); + } + if (result0 !== null) { + result0 = (function(elements) { return elements.length != 1 ? { type: "sequence", elements: elements } : elements[0]; - })(result2) - : null; - if (result3 !== null) { - var result1 = result3; - } else { - var result1 = null; - pos = savedPos0; + })(result0); } - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; + if (result0 === null) { + pos = pos0; + } + } @@ -527,52 +512,46 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; - var result5 = parse_identifier(); - if (result5 !== null) { - var result6 = parse_colon(); - if (result6 !== null) { - var result7 = parse_prefixed(); - if (result7 !== null) { - var result3 = [result5, result6, result7]; + + pos0 = pos; + pos1 = pos; + result0 = parse_identifier(); + if (result0 !== null) { + result1 = parse_colon(); + if (result1 !== null) { + result2 = parse_prefixed(); + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result3 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result3 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result3 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result4 = result3 !== null - ? (function(label, expression) { + if (result0 !== null) { + result0 = (function(label, expression) { return { type: "labeled", label: label, expression: expression }; - })(result3[0], result3[2]) - : null; - if (result4 !== null) { - var result2 = result4; - } else { - var result2 = null; - pos = savedPos0; + })(result0[0], result0[2]); } - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_prefixed(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + result0 = parse_prefixed(); + } @@ -592,144 +571,123 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; - var savedPos6 = pos; - var savedPos7 = pos; - var result20 = parse_and(); - if (result20 !== null) { - var result21 = parse_action(); - if (result21 !== null) { - var result18 = [result20, result21]; + + pos0 = pos; + pos1 = pos; + result0 = parse_and(); + if (result0 !== null) { + result1 = parse_action(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result18 = null; - pos = savedPos7; + result0 = null; + pos = pos1; } } else { - var result18 = null; - pos = savedPos7; + result0 = null; + pos = pos1; } - var result19 = result18 !== null - ? (function(code) { + if (result0 !== null) { + result0 = (function(code) { return { type: "semantic_and", code: code }; - })(result18[1]) - : null; - if (result19 !== null) { - var result17 = result19; - } else { - var result17 = null; - pos = savedPos6; - } - if (result17 !== null) { - var result0 = result17; - } else { - var savedPos4 = pos; - var savedPos5 = pos; - var result15 = parse_and(); - if (result15 !== null) { - var result16 = parse_suffixed(); - if (result16 !== null) { - var result13 = [result15, result16]; - } else { - var result13 = null; - pos = savedPos5; + })(result0[1]); + } + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + pos1 = pos; + result0 = parse_and(); + if (result0 !== null) { + result1 = parse_suffixed(); + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; } } else { - var result13 = null; - pos = savedPos5; + result0 = null; + pos = pos1; } - var result14 = result13 !== null - ? (function(expression) { + if (result0 !== null) { + result0 = (function(expression) { return { type: "simple_and", expression: expression }; - })(result13[1]) - : null; - if (result14 !== null) { - var result12 = result14; - } else { - var result12 = null; - pos = savedPos4; + })(result0[1]); } - if (result12 !== null) { - var result0 = result12; - } else { - var savedPos2 = pos; - var savedPos3 = pos; - var result10 = parse_not(); - if (result10 !== null) { - var result11 = parse_action(); - if (result11 !== null) { - var result8 = [result10, result11]; + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + pos1 = pos; + result0 = parse_not(); + if (result0 !== null) { + result1 = parse_action(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result8 = null; - pos = savedPos3; + result0 = null; + pos = pos1; } } else { - var result8 = null; - pos = savedPos3; + result0 = null; + pos = pos1; } - var result9 = result8 !== null - ? (function(code) { + if (result0 !== null) { + result0 = (function(code) { return { type: "semantic_not", code: code }; - })(result8[1]) - : null; - if (result9 !== null) { - var result7 = result9; - } else { - var result7 = null; - pos = savedPos2; + })(result0[1]); } - if (result7 !== null) { - var result0 = result7; - } else { - var savedPos0 = pos; - var savedPos1 = pos; - var result5 = parse_not(); - if (result5 !== null) { - var result6 = parse_suffixed(); - if (result6 !== null) { - var result3 = [result5, result6]; + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + pos1 = pos; + result0 = parse_not(); + if (result0 !== null) { + result1 = parse_suffixed(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result3 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result3 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result4 = result3 !== null - ? (function(expression) { + if (result0 !== null) { + result0 = (function(expression) { return { type: "simple_not", expression: expression }; - })(result3[1]) - : null; - if (result4 !== null) { - var result2 = result4; - } else { - var result2 = null; - pos = savedPos0; + })(result0[1]); } - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_suffixed(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + result0 = parse_suffixed(); + + } + } + } } @@ -749,111 +707,95 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos4 = pos; - var savedPos5 = pos; - var result15 = parse_primary(); - if (result15 !== null) { - var result16 = parse_question(); - if (result16 !== null) { - var result13 = [result15, result16]; + pos0 = pos; + pos1 = pos; + result0 = parse_primary(); + if (result0 !== null) { + result1 = parse_question(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result13 = null; - pos = savedPos5; + result0 = null; + pos = pos1; } } else { - var result13 = null; - pos = savedPos5; + result0 = null; + pos = pos1; } - var result14 = result13 !== null - ? (function(expression) { + if (result0 !== null) { + result0 = (function(expression) { return { type: "optional", expression: expression }; - })(result13[0]) - : null; - if (result14 !== null) { - var result12 = result14; - } else { - var result12 = null; - pos = savedPos4; - } - if (result12 !== null) { - var result0 = result12; - } else { - var savedPos2 = pos; - var savedPos3 = pos; - var result10 = parse_primary(); - if (result10 !== null) { - var result11 = parse_star(); - if (result11 !== null) { - var result8 = [result10, result11]; - } else { - var result8 = null; - pos = savedPos3; + })(result0[0]); + } + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + pos1 = pos; + result0 = parse_primary(); + if (result0 !== null) { + result1 = parse_star(); + if (result1 !== null) { + result0 = [result0, result1]; + } else { + result0 = null; + pos = pos1; } } else { - var result8 = null; - pos = savedPos3; + result0 = null; + pos = pos1; } - var result9 = result8 !== null - ? (function(expression) { + if (result0 !== null) { + result0 = (function(expression) { return { type: "zero_or_more", expression: expression }; - })(result8[0]) - : null; - if (result9 !== null) { - var result7 = result9; - } else { - var result7 = null; - pos = savedPos2; + })(result0[0]); } - if (result7 !== null) { - var result0 = result7; - } else { - var savedPos0 = pos; - var savedPos1 = pos; - var result5 = parse_primary(); - if (result5 !== null) { - var result6 = parse_plus(); - if (result6 !== null) { - var result3 = [result5, result6]; + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + pos1 = pos; + result0 = parse_primary(); + if (result0 !== null) { + result1 = parse_plus(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result3 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result3 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result4 = result3 !== null - ? (function(expression) { + if (result0 !== null) { + result0 = (function(expression) { return { type: "one_or_more", expression: expression }; - })(result3[0]) - : null; - if (result4 !== null) { - var result2 = result4; - } else { - var result2 = null; - pos = savedPos0; + })(result0[0]); } - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_primary(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + result0 = parse_primary(); + + } + } } @@ -873,154 +815,127 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3, result4; + var pos0, pos1, pos2, pos3, pos4; - var savedPos4 = pos; - var savedPos5 = pos; - var result17 = parse_identifier(); - if (result17 !== null) { - var savedPos6 = pos; + + pos0 = pos; + pos1 = pos; + result0 = parse_identifier(); + if (result0 !== null) { + pos2 = pos; reportFailures++; - var savedPos7 = pos; - var result23 = parse_literal(); - if (result23 !== null) { - var result20 = result23; - } else { + pos3 = pos; + result1 = parse_literal(); + if (result1 === null) { if (input.substr(pos, 0) === "") { - var result22 = ""; + result1 = ""; pos += 0; } else { - var result22 = null; + result1 = null; if (reportFailures === 0) { matchFailed("\"\""); } } - if (result22 !== null) { - var result20 = result22; - } else { - var result20 = null;; - }; + } - if (result20 !== null) { - var result21 = parse_equals(); - if (result21 !== null) { - var result19 = [result20, result21]; + if (result1 !== null) { + result2 = parse_equals(); + if (result2 !== null) { + result1 = [result1, result2]; } else { - var result19 = null; - pos = savedPos7; + result1 = null; + pos = pos3; } } else { - var result19 = null; - pos = savedPos7; + result1 = null; + pos = pos3; } reportFailures--; - if (result19 === null) { - var result18 = ''; + if (result1 === null) { + result1 = ''; } else { - var result18 = null; - pos = savedPos6; + result1 = null; + pos = pos2; } - if (result18 !== null) { - var result15 = [result17, result18]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result15 = null; - pos = savedPos5; + result0 = null; + pos = pos1; } } else { - var result15 = null; - pos = savedPos5; + result0 = null; + pos = pos1; } - var result16 = result15 !== null - ? (function(name) { + if (result0 !== null) { + result0 = (function(name) { return { type: "rule_ref", name: name }; - })(result15[0]) - : null; - if (result16 !== null) { - var result14 = result16; - } else { - var result14 = null; - pos = savedPos4; + })(result0[0]); } - if (result14 !== null) { - var result0 = result14; - } else { - var savedPos3 = pos; - var result12 = parse_literal(); - var result13 = result12 !== null - ? (function(value) { + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + result0 = parse_literal(); + if (result0 !== null) { + result0 = (function(value) { return { type: "literal", value: value }; - })(result12) - : null; - if (result13 !== null) { - var result11 = result13; - } else { - var result11 = null; - pos = savedPos3; + })(result0); } - if (result11 !== null) { - var result0 = result11; - } else { - var savedPos2 = pos; - var result9 = parse_dot(); - var result10 = result9 !== null - ? (function() { return { type: "any" }; })() - : null; - if (result10 !== null) { - var result8 = result10; - } else { - var result8 = null; - pos = savedPos2; + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + pos0 = pos; + result0 = parse_dot(); + if (result0 !== null) { + result0 = (function() { return { type: "any" }; })(); } - if (result8 !== null) { - var result0 = result8; - } else { - var result7 = parse_class(); - if (result7 !== null) { - var result0 = result7; - } else { - var savedPos0 = pos; - var savedPos1 = pos; - var result4 = parse_lparen(); - if (result4 !== null) { - var result5 = parse_choice(); - if (result5 !== null) { - var result6 = parse_rparen(); - if (result6 !== null) { - var result2 = [result4, result5, result6]; + if (result0 === null) { + pos = pos0; + } + if (result0 === null) { + result0 = parse_class(); + if (result0 === null) { + pos0 = pos; + pos1 = pos; + result0 = parse_lparen(); + if (result0 !== null) { + result1 = parse_choice(); + if (result1 !== null) { + result2 = parse_rparen(); + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result2 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result2 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result2 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result3 = result2 !== null - ? (function(expression) { return expression; })(result2[1]) - : null; - if (result3 !== null) { - var result1 = result3; - } else { - var result1 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(expression) { return expression; })(result0[1]); } - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; + if (result0 === null) { + pos = pos0; + } + + } + } + } } @@ -1040,30 +955,30 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + reportFailures++; - var savedPos0 = pos; - var savedPos1 = pos; - var result3 = parse_braced(); - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + pos0 = pos; + pos1 = pos; + result0 = parse_braced(); + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(braced) { return braced.substr(1, braced.length - 2); })(result1[0]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(braced) { return braced.substr(1, braced.length - 2); })(result0[0]); + } + if (result0 === null) { + pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { @@ -1085,79 +1000,67 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "{") { - var result3 = "{"; + result0 = "{"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"{\""); } } - if (result3 !== null) { - var result4 = []; - var result8 = parse_braced(); - if (result8 !== null) { - var result6 = result8; - } else { - var result7 = parse_nonBraceCharacter(); - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; - } - while (result6 !== null) { - result4.push(result6); - var result8 = parse_braced(); - if (result8 !== null) { - var result6 = result8; - } else { - var result7 = parse_nonBraceCharacter(); - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; + if (result0 !== null) { + result1 = []; + result2 = parse_braced(); + if (result2 === null) { + result2 = parse_nonBraceCharacter(); + + } + while (result2 !== null) { + result1.push(result2); + result2 = parse_braced(); + if (result2 === null) { + result2 = parse_nonBraceCharacter(); + } } - if (result4 !== null) { + if (result1 !== null) { if (input.substr(pos, 1) === "}") { - var result5 = "}"; + result2 = "}"; pos += 1; } else { - var result5 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"}\""); } } - if (result5 !== null) { - var result1 = [result3, result4, result5]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(parts) { + if (result0 !== null) { + result0 = (function(parts) { return "{" + parts.join("") + "}"; - })(result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[1]); + } + if (result0 === null) { + pos = pos0; } @@ -1177,26 +1080,26 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1; + var pos0, pos1; - var savedPos0 = pos; - var result3 = parse_nonBraceCharacter(); - if (result3 !== null) { - var result1 = []; - while (result3 !== null) { - result1.push(result3); - var result3 = parse_nonBraceCharacter(); + + pos0 = pos; + result1 = parse_nonBraceCharacter(); + if (result1 !== null) { + result0 = []; + while (result1 !== null) { + result0.push(result1); + result1 = parse_nonBraceCharacter(); } } else { - var result1 = null; + result0 = null; } - var result2 = result1 !== null - ? (function(chars) { return chars.join(""); })(result1) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(chars) { return chars.join(""); })(result0); + } + if (result0 === null) { + pos = pos0; } @@ -1216,12 +1119,15 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + if (input.substr(pos).match(/^[^{}]/) !== null) { - var result0 = input.charAt(pos); + result0 = input.charAt(pos); pos++; } else { - var result0 = null; + result0 = null; if (reportFailures === 0) { matchFailed("[^{}]"); } @@ -1244,38 +1150,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "=") { - var result3 = "="; + result0 = "="; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"=\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "="; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "="; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1295,38 +1201,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === ":") { - var result3 = ":"; + result0 = ":"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\":\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return ":"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return ":"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1346,38 +1252,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === ";") { - var result3 = ";"; + result0 = ";"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\";\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return ";"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return ";"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1397,38 +1303,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "/") { - var result3 = "/"; + result0 = "/"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"/\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "/"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "/"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1448,38 +1354,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "&") { - var result3 = "&"; + result0 = "&"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"&\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "&"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "&"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1499,38 +1405,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "!") { - var result3 = "!"; + result0 = "!"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"!\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "!"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "!"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1550,38 +1456,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "?") { - var result3 = "?"; + result0 = "?"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"?\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "?"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "?"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1601,38 +1507,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "*") { - var result3 = "*"; + result0 = "*"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"*\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "*"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "*"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1652,38 +1558,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "+") { - var result3 = "+"; + result0 = "+"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"+\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "+"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "+"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1703,38 +1609,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "(") { - var result3 = "("; + result0 = "("; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"(\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "("; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "("; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1754,38 +1660,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === ")") { - var result3 = ")"; + result0 = ")"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\")\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return ")"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return ")"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1805,38 +1711,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === ".") { - var result3 = "."; + result0 = "."; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\".\""); } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "."; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "."; })(); + } + if (result0 === null) { + pos = pos0; } @@ -1856,146 +1762,118 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3; + var pos0, pos1, pos2; + reportFailures++; - var savedPos0 = pos; - var savedPos1 = pos; - var result13 = parse_letter(); - if (result13 !== null) { - var result3 = result13; - } else { + pos0 = pos; + pos1 = pos; + result0 = parse_letter(); + if (result0 === null) { if (input.substr(pos, 1) === "_") { - var result12 = "_"; + result0 = "_"; pos += 1; } else { - var result12 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"_\""); } } - if (result12 !== null) { - var result3 = result12; - } else { + if (result0 === null) { if (input.substr(pos, 1) === "$") { - var result11 = "$"; + result0 = "$"; pos += 1; } else { - var result11 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"$\""); } } - if (result11 !== null) { - var result3 = result11; - } else { - var result3 = null;; - }; - }; - } - if (result3 !== null) { - var result4 = []; - var result10 = parse_letter(); - if (result10 !== null) { - var result6 = result10; - } else { - var result9 = parse_digit(); - if (result9 !== null) { - var result6 = result9; - } else { + + } + } + if (result0 !== null) { + result1 = []; + result2 = parse_letter(); + if (result2 === null) { + result2 = parse_digit(); + if (result2 === null) { if (input.substr(pos, 1) === "_") { - var result8 = "_"; + result2 = "_"; pos += 1; } else { - var result8 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"_\""); } } - if (result8 !== null) { - var result6 = result8; - } else { + if (result2 === null) { if (input.substr(pos, 1) === "$") { - var result7 = "$"; + result2 = "$"; pos += 1; } else { - var result7 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"$\""); } } - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; - }; - }; - } - while (result6 !== null) { - result4.push(result6); - var result10 = parse_letter(); - if (result10 !== null) { - var result6 = result10; - } else { - var result9 = parse_digit(); - if (result9 !== null) { - var result6 = result9; - } else { + + } + } + } + while (result2 !== null) { + result1.push(result2); + result2 = parse_letter(); + if (result2 === null) { + result2 = parse_digit(); + if (result2 === null) { if (input.substr(pos, 1) === "_") { - var result8 = "_"; + result2 = "_"; pos += 1; } else { - var result8 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"_\""); } } - if (result8 !== null) { - var result6 = result8; - } else { + if (result2 === null) { if (input.substr(pos, 1) === "$") { - var result7 = "$"; + result2 = "$"; pos += 1; } else { - var result7 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"$\""); } } - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; - }; - }; + + } + } } } - if (result4 !== null) { - var result5 = parse___(); - if (result5 !== null) { - var result1 = [result3, result4, result5]; + if (result1 !== null) { + result2 = parse___(); + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(head, tail) { + if (result0 !== null) { + result0 = (function(head, tail) { return head + tail.join(""); - })(result1[0], result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[0], result0[1]); + } + if (result0 === null) { + pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { @@ -2017,40 +1895,34 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; + reportFailures++; - var savedPos0 = pos; - var savedPos1 = pos; - var result6 = parse_doubleQuotedLiteral(); - if (result6 !== null) { - var result3 = result6; - } else { - var result5 = parse_singleQuotedLiteral(); - if (result5 !== null) { - var result3 = result5; - } else { - var result3 = null;; - }; + pos0 = pos; + pos1 = pos; + result0 = parse_doubleQuotedLiteral(); + if (result0 === null) { + result0 = parse_singleQuotedLiteral(); + } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse___(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(literal) { return literal; })(result1[0]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(literal) { return literal; })(result0[0]); + } + if (result0 === null) { + pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { @@ -2072,57 +1944,57 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "\"") { - var result3 = "\""; + result0 = "\""; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } - if (result3 !== null) { - var result4 = []; - var result6 = parse_doubleQuotedCharacter(); - while (result6 !== null) { - result4.push(result6); - var result6 = parse_doubleQuotedCharacter(); + if (result0 !== null) { + result1 = []; + result2 = parse_doubleQuotedCharacter(); + while (result2 !== null) { + result1.push(result2); + result2 = parse_doubleQuotedCharacter(); } - if (result4 !== null) { + if (result1 !== null) { if (input.substr(pos, 1) === "\"") { - var result5 = "\""; + result2 = "\""; pos += 1; } else { - var result5 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } - if (result5 !== null) { - var result1 = [result3, result4, result5]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(chars) { return chars.join(""); })(result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(chars) { return chars.join(""); })(result0[1]); + } + if (result0 === null) { + pos = pos0; } @@ -2142,37 +2014,26 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; - var result6 = parse_simpleDoubleQuotedCharacter(); - if (result6 !== null) { - var result0 = result6; - } else { - var result5 = parse_simpleEscapeSequence(); - if (result5 !== null) { - var result0 = result5; - } else { - var result4 = parse_zeroEscapeSequence(); - if (result4 !== null) { - var result0 = result4; - } else { - var result3 = parse_hexEscapeSequence(); - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_unicodeEscapeSequence(); - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_eolEscapeSequence(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; - }; + + result0 = parse_simpleDoubleQuotedCharacter(); + if (result0 === null) { + result0 = parse_simpleEscapeSequence(); + if (result0 === null) { + result0 = parse_zeroEscapeSequence(); + if (result0 === null) { + result0 = parse_hexEscapeSequence(); + if (result0 === null) { + result0 = parse_unicodeEscapeSequence(); + if (result0 === null) { + result0 = parse_eolEscapeSequence(); + + } + } + } + } } @@ -2192,78 +2053,70 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2, pos3; + - var savedPos0 = pos; - var savedPos1 = pos; - var savedPos2 = pos; + pos0 = pos; + pos1 = pos; + pos2 = pos; reportFailures++; if (input.substr(pos, 1) === "\"") { - var result8 = "\""; + result0 = "\""; pos += 1; } else { - var result8 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\"\""); } } - if (result8 !== null) { - var result5 = result8; - } else { + if (result0 === null) { if (input.substr(pos, 1) === "\\") { - var result7 = "\\"; + result0 = "\\"; pos += 1; } else { - var result7 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\\""); } } - if (result7 !== null) { - var result5 = result7; - } else { - var result6 = parse_eolChar(); - if (result6 !== null) { - var result5 = result6; - } else { - var result5 = null;; - }; - }; + if (result0 === null) { + result0 = parse_eolChar(); + + } } reportFailures--; - if (result5 === null) { - var result3 = ''; + if (result0 === null) { + result0 = ''; } else { - var result3 = null; - pos = savedPos2; + result0 = null; + pos = pos2; } - if (result3 !== null) { + if (result0 !== null) { if (input.length > pos) { - var result4 = input.charAt(pos); + result1 = input.charAt(pos); pos++; } else { - var result4 = null; + result1 = null; if (reportFailures === 0) { matchFailed('any character'); } } - if (result4 !== null) { - var result1 = [result3, result4]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(char_) { return char_; })(result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(char_) { return char_; })(result0[1]); + } + if (result0 === null) { + pos = pos0; } @@ -2283,57 +2136,57 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "'") { - var result3 = "'"; + result0 = "'"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"'\""); } } - if (result3 !== null) { - var result4 = []; - var result6 = parse_singleQuotedCharacter(); - while (result6 !== null) { - result4.push(result6); - var result6 = parse_singleQuotedCharacter(); + if (result0 !== null) { + result1 = []; + result2 = parse_singleQuotedCharacter(); + while (result2 !== null) { + result1.push(result2); + result2 = parse_singleQuotedCharacter(); } - if (result4 !== null) { + if (result1 !== null) { if (input.substr(pos, 1) === "'") { - var result5 = "'"; + result2 = "'"; pos += 1; } else { - var result5 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"'\""); } } - if (result5 !== null) { - var result1 = [result3, result4, result5]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(chars) { return chars.join(""); })(result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(chars) { return chars.join(""); })(result0[1]); + } + if (result0 === null) { + pos = pos0; } @@ -2353,37 +2206,26 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; - var result6 = parse_simpleSingleQuotedCharacter(); - if (result6 !== null) { - var result0 = result6; - } else { - var result5 = parse_simpleEscapeSequence(); - if (result5 !== null) { - var result0 = result5; - } else { - var result4 = parse_zeroEscapeSequence(); - if (result4 !== null) { - var result0 = result4; - } else { - var result3 = parse_hexEscapeSequence(); - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_unicodeEscapeSequence(); - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_eolEscapeSequence(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; - }; + + result0 = parse_simpleSingleQuotedCharacter(); + if (result0 === null) { + result0 = parse_simpleEscapeSequence(); + if (result0 === null) { + result0 = parse_zeroEscapeSequence(); + if (result0 === null) { + result0 = parse_hexEscapeSequence(); + if (result0 === null) { + result0 = parse_unicodeEscapeSequence(); + if (result0 === null) { + result0 = parse_eolEscapeSequence(); + + } + } + } + } } @@ -2403,78 +2245,70 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2, pos3; + - var savedPos0 = pos; - var savedPos1 = pos; - var savedPos2 = pos; + pos0 = pos; + pos1 = pos; + pos2 = pos; reportFailures++; if (input.substr(pos, 1) === "'") { - var result8 = "'"; + result0 = "'"; pos += 1; } else { - var result8 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"'\""); } } - if (result8 !== null) { - var result5 = result8; - } else { + if (result0 === null) { if (input.substr(pos, 1) === "\\") { - var result7 = "\\"; + result0 = "\\"; pos += 1; } else { - var result7 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\\""); } } - if (result7 !== null) { - var result5 = result7; - } else { - var result6 = parse_eolChar(); - if (result6 !== null) { - var result5 = result6; - } else { - var result5 = null;; - }; - }; + if (result0 === null) { + result0 = parse_eolChar(); + + } } reportFailures--; - if (result5 === null) { - var result3 = ''; + if (result0 === null) { + result0 = ''; } else { - var result3 = null; - pos = savedPos2; + result0 = null; + pos = pos2; } - if (result3 !== null) { + if (result0 !== null) { if (input.length > pos) { - var result4 = input.charAt(pos); + result1 = input.charAt(pos); pos++; } else { - var result4 = null; + result1 = null; if (reportFailures === 0) { matchFailed('any character'); } } - if (result4 !== null) { - var result1 = [result3, result4]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(char_) { return char_; })(result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(char_) { return char_; })(result0[1]); + } + if (result0 === null) { + pos = pos0; } @@ -2494,92 +2328,83 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3, result4, result5; + var pos0, pos1, pos2; + reportFailures++; - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "[") { - var result3 = "["; + result0 = "["; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"[\""); } } - if (result3 !== null) { + if (result0 !== null) { if (input.substr(pos, 1) === "^") { - var result11 = "^"; + result1 = "^"; pos += 1; } else { - var result11 = null; + result1 = null; if (reportFailures === 0) { matchFailed("\"^\""); } } - var result4 = result11 !== null ? result11 : ''; - if (result4 !== null) { - var result5 = []; - var result10 = parse_classCharacterRange(); - if (result10 !== null) { - var result8 = result10; - } else { - var result9 = parse_classCharacter(); - if (result9 !== null) { - var result8 = result9; - } else { - var result8 = null;; - }; - } - while (result8 !== null) { - result5.push(result8); - var result10 = parse_classCharacterRange(); - if (result10 !== null) { - var result8 = result10; - } else { - var result9 = parse_classCharacter(); - if (result9 !== null) { - var result8 = result9; - } else { - var result8 = null;; - }; + result1 = result1 !== null ? result1 : ''; + if (result1 !== null) { + result2 = []; + result3 = parse_classCharacterRange(); + if (result3 === null) { + result3 = parse_classCharacter(); + + } + while (result3 !== null) { + result2.push(result3); + result3 = parse_classCharacterRange(); + if (result3 === null) { + result3 = parse_classCharacter(); + } } - if (result5 !== null) { + if (result2 !== null) { if (input.substr(pos, 1) === "]") { - var result6 = "]"; + result3 = "]"; pos += 1; } else { - var result6 = null; + result3 = null; if (reportFailures === 0) { matchFailed("\"]\""); } } - if (result6 !== null) { - var result7 = parse___(); - if (result7 !== null) { - var result1 = [result3, result4, result5, result6, result7]; + if (result3 !== null) { + result4 = parse___(); + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(inverted, parts) { + if (result0 !== null) { + result0 = (function(inverted, parts) { var partsConverted = map(parts, function(part) { return part.data; }); var rawText = "[" + inverted @@ -2593,13 +2418,10 @@ PEG.parser = (function(){ // FIXME: Get the raw text from the input directly. rawText: rawText }; - })(result1[1], result1[2]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[1], result0[2]); + } + if (result0 === null) { + pos = pos0; } reportFailures--; if (reportFailures === 0 && result0 === null) { @@ -2621,38 +2443,41 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; - var result3 = parse_classCharacter(); - if (result3 !== null) { + + pos0 = pos; + pos1 = pos; + result0 = parse_classCharacter(); + if (result0 !== null) { if (input.substr(pos, 1) === "-") { - var result4 = "-"; + result1 = "-"; pos += 1; } else { - var result4 = null; + result1 = null; if (reportFailures === 0) { matchFailed("\"-\""); } } - if (result4 !== null) { - var result5 = parse_classCharacter(); - if (result5 !== null) { - var result1 = [result3, result4, result5]; + if (result1 !== null) { + result2 = parse_classCharacter(); + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(begin, end) { + if (result0 !== null) { + result0 = (function(begin, end) { if (begin.data.charCodeAt(0) > end.data.charCodeAt(0)) { throw new this.SyntaxError( "Invalid character range: " + begin.rawText + "-" + end.rawText + "." @@ -2664,13 +2489,10 @@ PEG.parser = (function(){ // FIXME: Get the raw text from the input directly. rawText: begin.rawText + "-" + end.rawText } - })(result1[0], result1[2]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[0], result0[2]); + } + if (result0 === null) { + pos = pos0; } @@ -2690,23 +2512,23 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0, pos1; + - var savedPos0 = pos; - var result1 = parse_bracketDelimitedCharacter(); - var result2 = result1 !== null - ? (function(char_) { + pos0 = pos; + result0 = parse_bracketDelimitedCharacter(); + if (result0 !== null) { + result0 = (function(char_) { return { data: char_, // FIXME: Get the raw text from the input directly. rawText: quoteForRegexpClass(char_) }; - })(result1) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0); + } + if (result0 === null) { + pos = pos0; } @@ -2726,37 +2548,26 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; - var result6 = parse_simpleBracketDelimitedCharacter(); - if (result6 !== null) { - var result0 = result6; - } else { - var result5 = parse_simpleEscapeSequence(); - if (result5 !== null) { - var result0 = result5; - } else { - var result4 = parse_zeroEscapeSequence(); - if (result4 !== null) { - var result0 = result4; - } else { - var result3 = parse_hexEscapeSequence(); - if (result3 !== null) { - var result0 = result3; - } else { - var result2 = parse_unicodeEscapeSequence(); - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_eolEscapeSequence(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; - }; + + result0 = parse_simpleBracketDelimitedCharacter(); + if (result0 === null) { + result0 = parse_simpleEscapeSequence(); + if (result0 === null) { + result0 = parse_zeroEscapeSequence(); + if (result0 === null) { + result0 = parse_hexEscapeSequence(); + if (result0 === null) { + result0 = parse_unicodeEscapeSequence(); + if (result0 === null) { + result0 = parse_eolEscapeSequence(); + + } + } + } + } } @@ -2776,78 +2587,70 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2, pos3; - var savedPos0 = pos; - var savedPos1 = pos; - var savedPos2 = pos; + + pos0 = pos; + pos1 = pos; + pos2 = pos; reportFailures++; if (input.substr(pos, 1) === "]") { - var result8 = "]"; + result0 = "]"; pos += 1; } else { - var result8 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"]\""); } } - if (result8 !== null) { - var result5 = result8; - } else { + if (result0 === null) { if (input.substr(pos, 1) === "\\") { - var result7 = "\\"; + result0 = "\\"; pos += 1; } else { - var result7 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\\""); } } - if (result7 !== null) { - var result5 = result7; - } else { - var result6 = parse_eolChar(); - if (result6 !== null) { - var result5 = result6; - } else { - var result5 = null;; - }; - }; + if (result0 === null) { + result0 = parse_eolChar(); + + } } reportFailures--; - if (result5 === null) { - var result3 = ''; + if (result0 === null) { + result0 = ''; } else { - var result3 = null; - pos = savedPos2; + result0 = null; + pos = pos2; } - if (result3 !== null) { + if (result0 !== null) { if (input.length > pos) { - var result4 = input.charAt(pos); + result1 = input.charAt(pos); pos++; } else { - var result4 = null; + result1 = null; if (reportFailures === 0) { matchFailed('any character'); } } - if (result4 !== null) { - var result1 = [result3, result4]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(char_) { return char_; })(result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(char_) { return char_; })(result0[1]); + } + if (result0 === null) { + pos = pos0; } @@ -2867,91 +2670,84 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3; + var pos0, pos1, pos2, pos3; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "\\") { - var result3 = "\\"; + result0 = "\\"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\\""); } } - if (result3 !== null) { - var savedPos2 = pos; + if (result0 !== null) { + pos2 = pos; reportFailures++; - var result10 = parse_digit(); - if (result10 !== null) { - var result6 = result10; - } else { + result1 = parse_digit(); + if (result1 === null) { if (input.substr(pos, 1) === "x") { - var result9 = "x"; + result1 = "x"; pos += 1; } else { - var result9 = null; + result1 = null; if (reportFailures === 0) { matchFailed("\"x\""); } } - if (result9 !== null) { - var result6 = result9; - } else { + if (result1 === null) { if (input.substr(pos, 1) === "u") { - var result8 = "u"; + result1 = "u"; pos += 1; } else { - var result8 = null; + result1 = null; if (reportFailures === 0) { matchFailed("\"u\""); } } - if (result8 !== null) { - var result6 = result8; - } else { - var result7 = parse_eolChar(); - if (result7 !== null) { - var result6 = result7; - } else { - var result6 = null;; - }; - }; - }; + if (result1 === null) { + result1 = parse_eolChar(); + + } + } } reportFailures--; - if (result6 === null) { - var result4 = ''; + if (result1 === null) { + result1 = ''; } else { - var result4 = null; - pos = savedPos2; + result1 = null; + pos = pos2; } - if (result4 !== null) { + if (result1 !== null) { if (input.length > pos) { - var result5 = input.charAt(pos); + result2 = input.charAt(pos); pos++; } else { - var result5 = null; + result2 = null; if (reportFailures === 0) { matchFailed('any character'); } } - if (result5 !== null) { - var result1 = [result3, result4, result5]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(char_) { + if (result0 !== null) { + result0 = (function(char_) { return char_ .replace("b", "\b") .replace("f", "\f") @@ -2959,13 +2755,10 @@ PEG.parser = (function(){ .replace("r", "\r") .replace("t", "\t") .replace("v", "\x0B") // IE does not recognize "\v". - })(result1[2]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[2]); + } + if (result0 === null) { + pos = pos0; } @@ -2985,47 +2778,47 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2, pos3; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 2) === "\\0") { - var result3 = "\\0"; + result0 = "\\0"; pos += 2; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\0\""); } } - if (result3 !== null) { - var savedPos2 = pos; + if (result0 !== null) { + pos2 = pos; reportFailures++; - var result5 = parse_digit(); + result1 = parse_digit(); reportFailures--; - if (result5 === null) { - var result4 = ''; + if (result1 === null) { + result1 = ''; } else { - var result4 = null; - pos = savedPos2; + result1 = null; + pos = pos2; } - if (result4 !== null) { - var result1 = [result3, result4]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function() { return "\0"; })() - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function() { return "\0"; })(); + } + if (result0 === null) { + pos = pos0; } @@ -3045,46 +2838,46 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 2) === "\\x") { - var result3 = "\\x"; + result0 = "\\x"; pos += 2; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\x\""); } } - if (result3 !== null) { - var result4 = parse_hexDigit(); - if (result4 !== null) { - var result5 = parse_hexDigit(); - if (result5 !== null) { - var result1 = [result3, result4, result5]; + if (result0 !== null) { + result1 = parse_hexDigit(); + if (result1 !== null) { + result2 = parse_hexDigit(); + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(h1, h2) { + if (result0 !== null) { + result0 = (function(h1, h2) { return String.fromCharCode(parseInt("0x" + h1 + h2)); - })(result1[1], result1[2]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[1], result0[2]); + } + if (result0 === null) { + pos = pos0; } @@ -3104,58 +2897,58 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3, result4, result5; + var pos0, pos1, pos2; + - var savedPos0 = pos; - var savedPos1 = pos; + pos0 = pos; + pos1 = pos; if (input.substr(pos, 2) === "\\u") { - var result3 = "\\u"; + result0 = "\\u"; pos += 2; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\u\""); } } - if (result3 !== null) { - var result4 = parse_hexDigit(); - if (result4 !== null) { - var result5 = parse_hexDigit(); - if (result5 !== null) { - var result6 = parse_hexDigit(); - if (result6 !== null) { - var result7 = parse_hexDigit(); - if (result7 !== null) { - var result1 = [result3, result4, result5, result6, result7]; + if (result0 !== null) { + result1 = parse_hexDigit(); + if (result1 !== null) { + result2 = parse_hexDigit(); + if (result2 !== null) { + result3 = parse_hexDigit(); + if (result3 !== null) { + result4 = parse_hexDigit(); + if (result4 !== null) { + result0 = [result0, result1, result2, result3, result4]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(h1, h2, h3, h4) { + if (result0 !== null) { + result0 = (function(h1, h2, h3, h4) { return String.fromCharCode(parseInt("0x" + h1 + h2 + h3 + h4)); - })(result1[1], result1[2], result1[3], result1[4]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + })(result0[1], result0[2], result0[3], result0[4]); + } + if (result0 === null) { + pos = pos0; } @@ -3175,38 +2968,38 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2; + var pos0, pos1, pos2; - var savedPos0 = pos; - var savedPos1 = pos; + + pos0 = pos; + pos1 = pos; if (input.substr(pos, 1) === "\\") { - var result3 = "\\"; + result0 = "\\"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\\\\""); } } - if (result3 !== null) { - var result4 = parse_eol(); - if (result4 !== null) { - var result1 = [result3, result4]; + if (result0 !== null) { + result1 = parse_eol(); + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } } else { - var result1 = null; - pos = savedPos1; + result0 = null; + pos = pos1; } - var result2 = result1 !== null - ? (function(eol) { return eol; })(result1[1]) - : null; - if (result2 !== null) { - var result0 = result2; - } else { - var result0 = null; - pos = savedPos0; + if (result0 !== null) { + result0 = (function(eol) { return eol; })(result0[1]); + } + if (result0 === null) { + pos = pos0; } @@ -3226,12 +3019,15 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + if (input.substr(pos).match(/^[0-9]/) !== null) { - var result0 = input.charAt(pos); + result0 = input.charAt(pos); pos++; } else { - var result0 = null; + result0 = null; if (reportFailures === 0) { matchFailed("[0-9]"); } @@ -3254,12 +3050,15 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + if (input.substr(pos).match(/^[0-9a-fA-F]/) !== null) { - var result0 = input.charAt(pos); + result0 = input.charAt(pos); pos++; } else { - var result0 = null; + result0 = null; if (reportFailures === 0) { matchFailed("[0-9a-fA-F]"); } @@ -3282,17 +3081,14 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; - var result2 = parse_lowerCaseLetter(); - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_upperCaseLetter(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; + + result0 = parse_lowerCaseLetter(); + if (result0 === null) { + result0 = parse_upperCaseLetter(); + } @@ -3312,12 +3108,15 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + if (input.substr(pos).match(/^[a-z]/) !== null) { - var result0 = input.charAt(pos); + result0 = input.charAt(pos); pos++; } else { - var result0 = null; + result0 = null; if (reportFailures === 0) { matchFailed("[a-z]"); } @@ -3340,12 +3139,15 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + if (input.substr(pos).match(/^[A-Z]/) !== null) { - var result0 = input.charAt(pos); + result0 = input.charAt(pos); pos++; } else { - var result0 = null; + result0 = null; if (reportFailures === 0) { matchFailed("[A-Z]"); } @@ -3368,41 +3170,28 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1; + var pos0; - var result0 = []; - var result4 = parse_whitespace(); - if (result4 !== null) { - var result1 = result4; - } else { - var result3 = parse_eol(); - if (result3 !== null) { - var result1 = result3; - } else { - var result2 = parse_comment(); - if (result2 !== null) { - var result1 = result2; - } else { - var result1 = null;; - }; - }; + + result0 = []; + result1 = parse_whitespace(); + if (result1 === null) { + result1 = parse_eol(); + if (result1 === null) { + result1 = parse_comment(); + + } } while (result1 !== null) { result0.push(result1); - var result4 = parse_whitespace(); - if (result4 !== null) { - var result1 = result4; - } else { - var result3 = parse_eol(); - if (result3 !== null) { - var result1 = result3; - } else { - var result2 = parse_comment(); - if (result2 !== null) { - var result1 = result2; - } else { - var result1 = null;; - }; - }; + result1 = parse_whitespace(); + if (result1 === null) { + result1 = parse_eol(); + if (result1 === null) { + result1 = parse_comment(); + + } } } @@ -3423,17 +3212,14 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + reportFailures++; - var result2 = parse_singleLineComment(); - if (result2 !== null) { - var result0 = result2; - } else { - var result1 = parse_multiLineComment(); - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; + result0 = parse_singleLineComment(); + if (result0 === null) { + result0 = parse_multiLineComment(); + } reportFailures--; if (reportFailures === 0 && result0 === null) { @@ -3455,93 +3241,96 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3, result4, result5; + var pos0, pos1, pos2, pos3; + - var savedPos0 = pos; + pos0 = pos; if (input.substr(pos, 2) === "//") { - var result1 = "//"; + result0 = "//"; pos += 2; } else { - var result1 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"//\""); } } - if (result1 !== null) { - var result2 = []; - var savedPos1 = pos; - var savedPos2 = pos; + if (result0 !== null) { + result1 = []; + pos1 = pos; + pos2 = pos; reportFailures++; - var result6 = parse_eolChar(); + result2 = parse_eolChar(); reportFailures--; - if (result6 === null) { - var result4 = ''; + if (result2 === null) { + result2 = ''; } else { - var result4 = null; - pos = savedPos2; + result2 = null; + pos = pos2; } - if (result4 !== null) { + if (result2 !== null) { if (input.length > pos) { - var result5 = input.charAt(pos); + result3 = input.charAt(pos); pos++; } else { - var result5 = null; + result3 = null; if (reportFailures === 0) { matchFailed('any character'); } } - if (result5 !== null) { - var result3 = [result4, result5]; + if (result3 !== null) { + result2 = [result2, result3]; } else { - var result3 = null; - pos = savedPos1; + result2 = null; + pos = pos1; } } else { - var result3 = null; - pos = savedPos1; + result2 = null; + pos = pos1; } - while (result3 !== null) { - result2.push(result3); - var savedPos1 = pos; - var savedPos2 = pos; + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + pos2 = pos; reportFailures++; - var result6 = parse_eolChar(); + result2 = parse_eolChar(); reportFailures--; - if (result6 === null) { - var result4 = ''; + if (result2 === null) { + result2 = ''; } else { - var result4 = null; - pos = savedPos2; + result2 = null; + pos = pos2; } - if (result4 !== null) { + if (result2 !== null) { if (input.length > pos) { - var result5 = input.charAt(pos); + result3 = input.charAt(pos); pos++; } else { - var result5 = null; + result3 = null; if (reportFailures === 0) { matchFailed('any character'); } } - if (result5 !== null) { - var result3 = [result4, result5]; + if (result3 !== null) { + result2 = [result2, result3]; } else { - var result3 = null; - pos = savedPos1; + result2 = null; + pos = pos1; } } else { - var result3 = null; - pos = savedPos1; + result2 = null; + pos = pos1; } } - if (result2 !== null) { - var result0 = [result1, result2]; + if (result1 !== null) { + result0 = [result0, result1]; } else { - var result0 = null; - pos = savedPos0; + result0 = null; + pos = pos0; } } else { - var result0 = null; - pos = savedPos0; + result0 = null; + pos = pos0; } @@ -3561,123 +3350,126 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0, result1, result2, result3, result4, result5; + var pos0, pos1, pos2, pos3; - var savedPos0 = pos; + + pos0 = pos; if (input.substr(pos, 2) === "/*") { - var result1 = "/*"; + result0 = "/*"; pos += 2; } else { - var result1 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"/*\""); } } - if (result1 !== null) { - var result2 = []; - var savedPos1 = pos; - var savedPos2 = pos; + if (result0 !== null) { + result1 = []; + pos1 = pos; + pos2 = pos; reportFailures++; if (input.substr(pos, 2) === "*/") { - var result7 = "*/"; + result2 = "*/"; pos += 2; } else { - var result7 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"*/\""); } } reportFailures--; - if (result7 === null) { - var result5 = ''; + if (result2 === null) { + result2 = ''; } else { - var result5 = null; - pos = savedPos2; + result2 = null; + pos = pos2; } - if (result5 !== null) { + if (result2 !== null) { if (input.length > pos) { - var result6 = input.charAt(pos); + result3 = input.charAt(pos); pos++; } else { - var result6 = null; + result3 = null; if (reportFailures === 0) { matchFailed('any character'); } } - if (result6 !== null) { - var result4 = [result5, result6]; + if (result3 !== null) { + result2 = [result2, result3]; } else { - var result4 = null; - pos = savedPos1; + result2 = null; + pos = pos1; } } else { - var result4 = null; - pos = savedPos1; + result2 = null; + pos = pos1; } - while (result4 !== null) { - result2.push(result4); - var savedPos1 = pos; - var savedPos2 = pos; + while (result2 !== null) { + result1.push(result2); + pos1 = pos; + pos2 = pos; reportFailures++; if (input.substr(pos, 2) === "*/") { - var result7 = "*/"; + result2 = "*/"; pos += 2; } else { - var result7 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"*/\""); } } reportFailures--; - if (result7 === null) { - var result5 = ''; + if (result2 === null) { + result2 = ''; } else { - var result5 = null; - pos = savedPos2; + result2 = null; + pos = pos2; } - if (result5 !== null) { + if (result2 !== null) { if (input.length > pos) { - var result6 = input.charAt(pos); + result3 = input.charAt(pos); pos++; } else { - var result6 = null; + result3 = null; if (reportFailures === 0) { matchFailed('any character'); } } - if (result6 !== null) { - var result4 = [result5, result6]; + if (result3 !== null) { + result2 = [result2, result3]; } else { - var result4 = null; - pos = savedPos1; + result2 = null; + pos = pos1; } } else { - var result4 = null; - pos = savedPos1; + result2 = null; + pos = pos1; } } - if (result2 !== null) { + if (result1 !== null) { if (input.substr(pos, 2) === "*/") { - var result3 = "*/"; + result2 = "*/"; pos += 2; } else { - var result3 = null; + result2 = null; if (reportFailures === 0) { matchFailed("\"*/\""); } } - if (result3 !== null) { - var result0 = [result1, result2, result3]; + if (result2 !== null) { + result0 = [result0, result1, result2]; } else { - var result0 = null; - pos = savedPos0; + result0 = null; + pos = pos0; } } else { - var result0 = null; - pos = savedPos0; + result0 = null; + pos = pos0; } } else { - var result0 = null; - pos = savedPos0; + result0 = null; + pos = pos0; } @@ -3697,72 +3489,63 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + reportFailures++; if (input.substr(pos, 1) === "\n") { - var result5 = "\n"; + result0 = "\n"; pos += 1; } else { - var result5 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\n\""); } } - if (result5 !== null) { - var result0 = result5; - } else { + if (result0 === null) { if (input.substr(pos, 2) === "\r\n") { - var result4 = "\r\n"; + result0 = "\r\n"; pos += 2; } else { - var result4 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\r\\n\""); } } - if (result4 !== null) { - var result0 = result4; - } else { + if (result0 === null) { if (input.substr(pos, 1) === "\r") { - var result3 = "\r"; + result0 = "\r"; pos += 1; } else { - var result3 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\r\""); } } - if (result3 !== null) { - var result0 = result3; - } else { + if (result0 === null) { if (input.substr(pos, 1) === "\u2028") { - var result2 = "\u2028"; + result0 = "\u2028"; pos += 1; } else { - var result2 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\u2028\""); } } - if (result2 !== null) { - var result0 = result2; - } else { + if (result0 === null) { if (input.substr(pos, 1) === "\u2029") { - var result1 = "\u2029"; + result0 = "\u2029"; pos += 1; } else { - var result1 = null; + result0 = null; if (reportFailures === 0) { matchFailed("\"\\u2029\""); } } - if (result1 !== null) { - var result0 = result1; - } else { - var result0 = null;; - }; - }; - }; - }; + + } + } + } } reportFailures--; if (reportFailures === 0 && result0 === null) { @@ -3784,12 +3567,15 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + if (input.substr(pos).match(/^[\n\r\u2028\u2029]/) !== null) { - var result0 = input.charAt(pos); + result0 = input.charAt(pos); pos++; } else { - var result0 = null; + result0 = null; if (reportFailures === 0) { matchFailed("[\\n\\r\\u2028\\u2029]"); } @@ -3812,12 +3598,15 @@ PEG.parser = (function(){ return cachedResult.result; } + var result0; + var pos0; + reportFailures++; if (input.substr(pos).match(/^[ \xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/) !== null) { - var result0 = input.charAt(pos); + result0 = input.charAt(pos); pos++; } else { - var result0 = null; + result0 = null; if (reportFailures === 0) { matchFailed("[ \\xA0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]"); } diff --git a/src/passes.js b/src/passes.js index 4b8ef91..a91e505 100644 --- a/src/passes.js +++ b/src/passes.js @@ -75,6 +75,82 @@ PEG.compiler.passes = { } } + return ast; + }, + + /* + * Adds |resultStackDepth| and |posStackDepth| properties to each AST node. + * These properties specify how many positions on the result or position stack + * code generated by the emitter for the node will use. This information is + * used to declare varibles holding the stack data in the generated code. + */ + stackDepths: function(ast) { + function computeZeroes(node) { + node.resultStackDepth = 0; + node.posStackDepth = 0; + } + + function computeFromExpression(resultStackDelta, posStackDelta) { + return function(node) { + compute(node.expression); + node.resultStackDepth = node.expression.resultStackDepth + resultStackDelta; + node.posStackDepth = node.expression.posStackDepth + posStackDelta; + } + } + + var compute = buildNodeVisitor({ + grammar: + function(node) { + for (var name in node.rules) { + compute(node.rules[name]); + } + }, + + rule: computeFromExpression(1, 1), + + choice: + function(node) { + each(node.alternatives, compute); + node.resultStackDepth = Math.max.apply( + null, + map(node.alternatives, function(e) { return e.resultStackDepth; }) + ); + node.posStackDepth = Math.max.apply( + null, + map(node.alternatives, function(e) { return e.posStackDepth; }) + ); + }, + + sequence: + function(node) { + each(node.elements, compute); + node.resultStackDepth = 1 + Math.max.apply( + null, + map(node.elements, function(e, i) { return i + e.resultStackDepth; }) + ); + node.posStackDepth = 1 + Math.max.apply( + null, + map(node.elements, function(e) { return e.posStackDepth; }) + ); + }, + + labeled: computeFromExpression(0, 0), + simple_and: computeFromExpression(0, 1), + simple_not: computeFromExpression(0, 1), + semantic_and: computeZeroes, + semantic_not: computeZeroes, + optional: computeFromExpression(0, 0), + zero_or_more: computeFromExpression(1, 0), + one_or_more: computeFromExpression(1, 0), + action: computeFromExpression(0, 1), + rule_ref: computeZeroes, + literal: computeZeroes, + any: computeZeroes, + "class": computeZeroes + }); + + compute(ast); + return ast; } }; diff --git a/src/utils.js b/src/utils.js index 1057326..f659e74 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,3 +1,17 @@ +/* Like Python's |range|, but without |step|. */ +function range(start, stop) { + if (stop === undefined) { + stop = start; + start = 0; + } + + var result = new Array(Math.max(0, stop - start)); + for (var i = 0, j = start; j < stop; i++, j++) { + result[i] = j; + } + return result; +} + function contains(array, value) { /* * Stupid IE does not have Array.prototype.indexOf, otherwise this function @@ -15,7 +29,7 @@ function contains(array, value) { function each(array, callback) { var length = array.length; for (var i = 0; i < length; i++) { - callback(array[i]); + callback(array[i], i); } } @@ -23,7 +37,7 @@ function map(array, callback) { var result = []; var length = array.length; for (var i = 0; i < length; i++) { - result[i] = callback(array[i]); + result[i] = callback(array[i], i); } return result; } diff --git a/test/passes-test.js b/test/passes-test.js index 4ae423f..054cad3 100644 --- a/test/passes-test.js +++ b/test/passes-test.js @@ -147,4 +147,90 @@ test("removes proxy rules", function() { } }); +test("computes stack depths", function() { + var cases = [ + /* Choice */ + { + grammar: 'start = "a" / "b" / "c"', + resultStackDepth: 1, + posStackDepth: 1 + }, + { + grammar: 'start = "a" / "b"* / "c"', + resultStackDepth: 2, + posStackDepth: 1 + }, + { + grammar: 'start = "a" / &"b" / "c"', + resultStackDepth: 1, + posStackDepth: 2 + }, + + /* Sequence */ + { + grammar: 'start = "a" "b" "c"', + resultStackDepth: 4, + posStackDepth: 2 + }, + { + grammar: 'start = "a" "b" "c"*', + resultStackDepth: 5, + posStackDepth: 2 + }, + { + grammar: 'start = "a" "b"* "c"', + resultStackDepth: 4, + posStackDepth: 2 + }, + { + grammar: 'start = "a" ("b"*)* "c"', + resultStackDepth: 5, + posStackDepth: 2 + }, + { + grammar: 'start = "a"* "b" "c"', + resultStackDepth: 4, + posStackDepth: 2 + }, + { + grammar: 'start = ("a"*)* "b" "c"', + resultStackDepth: 4, + posStackDepth: 2 + }, + { + grammar: 'start = (("a"*)*)* "b" "c"', + resultStackDepth: 5, + posStackDepth: 2 + }, + { + grammar: 'start = "a" &"b" "c"', + resultStackDepth: 4, + posStackDepth: 3 + }, + + /* Others */ + { grammar: 'start = label:"a"', resultStackDepth: 1, posStackDepth: 1 }, + { grammar: 'start = &"a"', resultStackDepth: 1, posStackDepth: 2 }, + { grammar: 'start = !"a"', resultStackDepth: 1, posStackDepth: 2 }, + { grammar: 'start = &{ code }', resultStackDepth: 1, posStackDepth: 1 }, + { grammar: 'start = !{ code }', resultStackDepth: 1, posStackDepth: 1 }, + { grammar: 'start = "a"?', resultStackDepth: 1, posStackDepth: 1 }, + { grammar: 'start = "a"*', resultStackDepth: 2, posStackDepth: 1 }, + { grammar: 'start = "a"+', resultStackDepth: 2, posStackDepth: 1 }, + { grammar: 'start = "a" { code }', resultStackDepth: 1, posStackDepth: 2 }, + { grammar: 'start = a', resultStackDepth: 1, posStackDepth: 1 }, + { grammar: 'start = "a"', resultStackDepth: 1, posStackDepth: 1 }, + { grammar: 'start = .', resultStackDepth: 1, posStackDepth: 1 }, + { grammar: 'start = [a-z]', resultStackDepth: 1, posStackDepth: 1 } + ]; + + for (var i = 0; i < cases.length; i++) { + var ast = PEG.parser.parse(cases[i].grammar); + PEG.compiler.passes.stackDepths(ast) + + deepEqual(ast.rules["start"].resultStackDepth, cases[i].resultStackDepth); + deepEqual(ast.rules["start"].posStackDepth, cases[i].posStackDepth); + } +}); + })();