From 747cb8afaabd36569e8c12f2cef896e887095ebf Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 20 Aug 2011 17:34:26 +0200 Subject: [PATCH] Reset parser position when action returns |null| The change does not change the benchmark suite execution speed statistically significantly. Detailed results (benchmark suite totals as reported by "jake benchmark" on Node.js 0.4.8): ----------------------------------- Test # Before After ----------------------------------- 1 128.20 kB/s 128.03 kB/s 2 130.36 kB/s 128.73 kB/s 3 126.53 kB/s 129.72 kB/s 4 127.46 kB/s 127.48 kB/s 5 127.63 kB/s 128.53 kB/s ----------------------------------- Average 128.04 kB/s 125.50 kB/s ----------------------------------- Closes GH-25. --- src/emitter.js | 13 +- src/parser.js | 1782 ++++++++++++++++++++++++----------------- test/compiler-test.js | 7 + 3 files changed, 1078 insertions(+), 724 deletions(-) diff --git a/src/emitter.js b/src/emitter.js index f0f9aed..4f3ce4b 100644 --- a/src/emitter.js +++ b/src/emitter.js @@ -627,6 +627,8 @@ PEG.compiler.emitter = function(ast) { */ var expressionResultVar = UID.next("result"); + var actionResultVar = UID.next("result"); + var savedPosVar = UID.next("savedPos"); if (node.expression.type === "sequence") { var formalParams = []; @@ -649,16 +651,25 @@ PEG.compiler.emitter = function(ast) { } return formatCode( + "var ${savedPosVar} = pos;", "${expressionCode}", - "var ${resultVar} = ${expressionResultVar} !== null", + "var ${actionResultVar} = ${expressionResultVar} !== null", " ? (function(${formalParams}) {${actionCode}})(${actualParams})", " : null;", + "if (${actionResultVar} !== null) {", + " var ${resultVar} = ${actionResultVar};", + "} else {", + " var ${resultVar} = null;", + " pos = ${savedPosVar};", + "}", { expressionCode: emit(node.expression, expressionResultVar), expressionResultVar: expressionResultVar, actionCode: node.code, + actionResultVar: actionResultVar, formalParams: formalParams.join(", "), actualParams: actualParams.join(", "), + savedPosVar: savedPosVar, resultVar: resultVar } ); diff --git a/src/parser.js b/src/parser.js index b9d461f..abffbcd 100644 --- a/src/parser.js +++ b/src/parser.js @@ -145,36 +145,37 @@ PEG.parser = (function(){ var savedPos0 = pos; - var result2 = parse___(); - if (result2 !== null) { - var result6 = parse_initializer(); - var result3 = result6 !== null ? result6 : ''; - if (result3 !== null) { - var result5 = parse_rule(); - if (result5 !== null) { - var result4 = []; - while (result5 !== null) { - result4.push(result5); - var result5 = parse_rule(); + 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(); } } else { - var result4 = null; + var result5 = null; } - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result5 !== null) { + var result1 = [result3, result4, result5]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(initializer, rules) { var rulesConverted = {}; each(rules, function(rule) { rulesConverted[rule.name] = rule; }); @@ -187,6 +188,12 @@ PEG.parser = (function(){ } })(result1[1], result1[2]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -207,21 +214,22 @@ PEG.parser = (function(){ var savedPos0 = pos; - var result2 = parse_action(); - if (result2 !== null) { - var result4 = parse_semicolon(); - var result3 = result4 !== null ? result4 : ''; - if (result3 !== null) { - var result1 = [result2, result3]; + 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]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(code) { return { type: "initializer", @@ -229,6 +237,12 @@ PEG.parser = (function(){ }; })(result1[0]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -249,57 +263,58 @@ PEG.parser = (function(){ var savedPos0 = pos; - var result2 = parse_identifier(); - if (result2 !== null) { - var result9 = parse_literal(); - if (result9 !== null) { - var result3 = result9; + var savedPos1 = pos; + var result3 = parse_identifier(); + if (result3 !== null) { + var result10 = parse_literal(); + if (result10 !== null) { + var result4 = result10; } else { if (input.substr(pos, 0) === "") { - var result8 = ""; + var result9 = ""; pos += 0; } else { - var result8 = null; + var result9 = null; if (reportMatchFailures) { matchFailed("\"\""); } } - if (result8 !== null) { - var result3 = result8; + if (result9 !== null) { + var result4 = result9; } else { - var result3 = null;; + var result4 = null;; }; } - if (result3 !== null) { - var result4 = parse_equals(); - if (result4 !== null) { - var result5 = parse_choice(); - if (result5 !== null) { - var result7 = parse_semicolon(); - var result6 = result7 !== null ? result7 : ''; - if (result6 !== null) { - var result1 = [result2, result3, result4, result5, result6]; + 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]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(name, displayName, expression) { return { type: "rule", @@ -309,6 +324,12 @@ PEG.parser = (function(){ }; })(result1[0], result1[1], result1[3]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -329,51 +350,52 @@ PEG.parser = (function(){ var savedPos0 = pos; - var result2 = parse_sequence(); - if (result2 !== null) { - var result3 = []; - var savedPos1 = pos; - var result5 = parse_slash(); - if (result5 !== null) { - var result6 = parse_sequence(); - if (result6 !== null) { - var result4 = [result5, result6]; + 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]; } else { - var result4 = null; - pos = savedPos1; + var result5 = null; + pos = savedPos2; } } else { - var result4 = null; - pos = savedPos1; + var result5 = null; + pos = savedPos2; } - while (result4 !== null) { - result3.push(result4); - var savedPos1 = pos; - var result5 = parse_slash(); - if (result5 !== null) { - var result6 = parse_sequence(); - if (result6 !== null) { - var result4 = [result5, result6]; + 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]; } else { - var result4 = null; - pos = savedPos1; + var result5 = null; + pos = savedPos2; } } else { - var result4 = null; - pos = savedPos1; + var result5 = null; + pos = savedPos2; } } - if (result3 !== null) { - var result1 = [result2, result3]; + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(head, tail) { if (tail.length > 0) { var alternatives = [head].concat(map( @@ -389,6 +411,12 @@ PEG.parser = (function(){ } })(result1[0], result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -408,26 +436,27 @@ PEG.parser = (function(){ } - var savedPos0 = pos; - var result6 = []; - var result8 = parse_labeled(); - while (result8 !== null) { - result6.push(result8); - var result8 = parse_labeled(); - } - if (result6 !== null) { - var result7 = parse_action(); - if (result7 !== null) { - var result5 = [result6, result7]; + var savedPos1 = pos; + var savedPos2 = pos; + var result8 = []; + var result10 = parse_labeled(); + while (result10 !== null) { + result8.push(result10); + var result10 = parse_labeled(); + } + if (result8 !== null) { + var result9 = parse_action(); + if (result9 !== null) { + var result6 = [result8, result9]; } else { - var result5 = null; - pos = savedPos0; + var result6 = null; + pos = savedPos2; } } else { - var result5 = null; - pos = savedPos0; + var result6 = null; + pos = savedPos2; } - var result4 = result5 !== null + var result7 = result6 !== null ? (function(elements, code) { var expression = elements.length != 1 ? { @@ -440,18 +469,25 @@ PEG.parser = (function(){ expression: expression, code: code }; - })(result5[0], result5[1]) + })(result6[0], result6[1]) : null; - if (result4 !== null) { - var result0 = result4; + 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 result3 = parse_labeled(); - while (result3 !== null) { - result2.push(result3); - var result3 = parse_labeled(); + var result4 = parse_labeled(); + while (result4 !== null) { + result2.push(result4); + var result4 = parse_labeled(); } - var result1 = result2 !== null + var result3 = result2 !== null ? (function(elements) { return elements.length != 1 ? { @@ -461,6 +497,12 @@ PEG.parser = (function(){ : elements[0]; })(result2) : null; + if (result3 !== null) { + var result1 = result3; + } else { + var result1 = null; + pos = savedPos0; + } if (result1 !== null) { var result0 = result1; } else { @@ -487,26 +529,27 @@ PEG.parser = (function(){ var savedPos0 = pos; - var result4 = parse_identifier(); - if (result4 !== null) { - var result5 = parse_colon(); - if (result5 !== null) { - var result6 = parse_prefixed(); - if (result6 !== null) { - var result3 = [result4, result5, result6]; + 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]; } else { var result3 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result3 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result3 = null; - pos = savedPos0; + pos = savedPos1; } - var result2 = result3 !== null + var result4 = result3 !== null ? (function(label, expression) { return { type: "labeled", @@ -515,6 +558,12 @@ PEG.parser = (function(){ }; })(result3[0], result3[2]) : null; + if (result4 !== null) { + var result2 = result4; + } else { + var result2 = null; + pos = savedPos0; + } if (result2 !== null) { var result0 = result2; } else { @@ -544,96 +593,118 @@ PEG.parser = (function(){ } - var savedPos3 = pos; - var result16 = parse_and(); - if (result16 !== null) { - var result17 = parse_action(); - if (result17 !== null) { - var result15 = [result16, result17]; + var savedPos6 = pos; + var savedPos7 = pos; + var result20 = parse_and(); + if (result20 !== null) { + var result21 = parse_action(); + if (result21 !== null) { + var result18 = [result20, result21]; } else { - var result15 = null; - pos = savedPos3; + var result18 = null; + pos = savedPos7; } } else { - var result15 = null; - pos = savedPos3; + var result18 = null; + pos = savedPos7; } - var result14 = result15 !== null + var result19 = result18 !== null ? (function(code) { return { type: "semantic_and", code: code }; - })(result15[1]) + })(result18[1]) : null; - if (result14 !== null) { - var result0 = result14; - } else { - var savedPos2 = pos; - var result12 = parse_and(); - if (result12 !== null) { - var result13 = parse_suffixed(); - if (result13 !== null) { - var result11 = [result12, result13]; + 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 result11 = null; - pos = savedPos2; + var result13 = null; + pos = savedPos5; } } else { - var result11 = null; - pos = savedPos2; + var result13 = null; + pos = savedPos5; } - var result10 = result11 !== null + var result14 = result13 !== null ? (function(expression) { return { type: "simple_and", expression: expression }; - })(result11[1]) + })(result13[1]) : null; - if (result10 !== null) { - var result0 = result10; + if (result14 !== null) { + var result12 = result14; } else { - var savedPos1 = pos; - var result8 = parse_not(); - if (result8 !== null) { - var result9 = parse_action(); - if (result9 !== null) { - var result7 = [result8, result9]; + var result12 = null; + pos = savedPos4; + } + 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]; } else { - var result7 = null; - pos = savedPos1; + var result8 = null; + pos = savedPos3; } } else { - var result7 = null; - pos = savedPos1; + var result8 = null; + pos = savedPos3; } - var result6 = result7 !== null + var result9 = result8 !== null ? (function(code) { return { type: "semantic_not", code: code }; - })(result7[1]) + })(result8[1]) : null; - if (result6 !== null) { - var result0 = result6; + if (result9 !== null) { + var result7 = result9; + } else { + var result7 = null; + pos = savedPos2; + } + if (result7 !== null) { + var result0 = result7; } else { var savedPos0 = pos; - var result4 = parse_not(); - if (result4 !== null) { - var result5 = parse_suffixed(); - if (result5 !== null) { - var result3 = [result4, result5]; + var savedPos1 = pos; + var result5 = parse_not(); + if (result5 !== null) { + var result6 = parse_suffixed(); + if (result6 !== null) { + var result3 = [result5, result6]; } else { var result3 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result3 = null; - pos = savedPos0; + pos = savedPos1; } - var result2 = result3 !== null + var result4 = result3 !== null ? (function(expression) { return { type: "simple_not", @@ -641,6 +712,12 @@ PEG.parser = (function(){ }; })(result3[1]) : null; + if (result4 !== null) { + var result2 = result4; + } else { + var result2 = null; + pos = savedPos0; + } if (result2 !== null) { var result0 = result2; } else { @@ -673,71 +750,86 @@ PEG.parser = (function(){ } - var savedPos2 = pos; - var result12 = parse_primary(); - if (result12 !== null) { - var result13 = parse_question(); - if (result13 !== null) { - var result11 = [result12, result13]; + var savedPos4 = pos; + var savedPos5 = pos; + var result15 = parse_primary(); + if (result15 !== null) { + var result16 = parse_question(); + if (result16 !== null) { + var result13 = [result15, result16]; } else { - var result11 = null; - pos = savedPos2; + var result13 = null; + pos = savedPos5; } } else { - var result11 = null; - pos = savedPos2; + var result13 = null; + pos = savedPos5; } - var result10 = result11 !== null + var result14 = result13 !== null ? (function(expression) { return { type: "optional", expression: expression }; - })(result11[0]) + })(result13[0]) : null; - if (result10 !== null) { - var result0 = result10; + if (result14 !== null) { + var result12 = result14; } else { - var savedPos1 = pos; - var result8 = parse_primary(); - if (result8 !== null) { - var result9 = parse_star(); - if (result9 !== null) { - var result7 = [result8, result9]; + 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 result7 = null; - pos = savedPos1; + var result8 = null; + pos = savedPos3; } } else { - var result7 = null; - pos = savedPos1; + var result8 = null; + pos = savedPos3; } - var result6 = result7 !== null + var result9 = result8 !== null ? (function(expression) { return { type: "zero_or_more", expression: expression }; - })(result7[0]) + })(result8[0]) : null; - if (result6 !== null) { - var result0 = result6; + if (result9 !== null) { + var result7 = result9; + } else { + var result7 = null; + pos = savedPos2; + } + if (result7 !== null) { + var result0 = result7; } else { var savedPos0 = pos; - var result4 = parse_primary(); - if (result4 !== null) { - var result5 = parse_plus(); - if (result5 !== null) { - var result3 = [result4, result5]; + var savedPos1 = pos; + var result5 = parse_primary(); + if (result5 !== null) { + var result6 = parse_plus(); + if (result6 !== null) { + var result3 = [result5, result6]; } else { var result3 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result3 = null; - pos = savedPos0; + pos = savedPos1; } - var result2 = result3 !== null + var result4 = result3 !== null ? (function(expression) { return { type: "one_or_more", @@ -745,6 +837,12 @@ PEG.parser = (function(){ }; })(result3[0]) : null; + if (result4 !== null) { + var result2 = result4; + } else { + var result2 = null; + pos = savedPos0; + } if (result2 !== null) { var result0 = result2; } else { @@ -776,118 +874,146 @@ PEG.parser = (function(){ } - var savedPos1 = pos; - var result13 = parse_identifier(); - if (result13 !== null) { - var savedPos2 = pos; + var savedPos4 = pos; + var savedPos5 = pos; + var result17 = parse_identifier(); + if (result17 !== null) { + var savedPos6 = pos; var savedReportMatchFailuresVar0 = reportMatchFailures; reportMatchFailures = false; - var savedPos3 = pos; - var result19 = parse_literal(); - if (result19 !== null) { - var result16 = result19; + var savedPos7 = pos; + var result23 = parse_literal(); + if (result23 !== null) { + var result20 = result23; } else { if (input.substr(pos, 0) === "") { - var result18 = ""; + var result22 = ""; pos += 0; } else { - var result18 = null; + var result22 = null; if (reportMatchFailures) { matchFailed("\"\""); } } - if (result18 !== null) { - var result16 = result18; + if (result22 !== null) { + var result20 = result22; } else { - var result16 = null;; + var result20 = null;; }; } - if (result16 !== null) { - var result17 = parse_equals(); - if (result17 !== null) { - var result15 = [result16, result17]; + if (result20 !== null) { + var result21 = parse_equals(); + if (result21 !== null) { + var result19 = [result20, result21]; } else { - var result15 = null; - pos = savedPos3; + var result19 = null; + pos = savedPos7; } } else { - var result15 = null; - pos = savedPos3; + var result19 = null; + pos = savedPos7; } reportMatchFailures = savedReportMatchFailuresVar0; - if (result15 === null) { - var result14 = ''; + if (result19 === null) { + var result18 = ''; } else { - var result14 = null; - pos = savedPos2; + var result18 = null; + pos = savedPos6; } - if (result14 !== null) { - var result12 = [result13, result14]; + if (result18 !== null) { + var result15 = [result17, result18]; } else { - var result12 = null; - pos = savedPos1; + var result15 = null; + pos = savedPos5; } } else { - var result12 = null; - pos = savedPos1; + var result15 = null; + pos = savedPos5; } - var result11 = result12 !== null + var result16 = result15 !== null ? (function(name) { return { type: "rule_ref", name: name }; - })(result12[0]) + })(result15[0]) : null; - if (result11 !== null) { - var result0 = result11; + if (result16 !== null) { + var result14 = result16; } else { - var result10 = parse_literal(); - var result9 = result10 !== null + var result14 = null; + pos = savedPos4; + } + if (result14 !== null) { + var result0 = result14; + } else { + var savedPos3 = pos; + var result12 = parse_literal(); + var result13 = result12 !== null ? (function(value) { return { type: "literal", value: value }; - })(result10) + })(result12) : null; - if (result9 !== null) { - var result0 = result9; + if (result13 !== null) { + var result11 = result13; + } else { + var result11 = null; + pos = savedPos3; + } + if (result11 !== null) { + var result0 = result11; } else { - var result8 = parse_dot(); - var result7 = result8 !== null + var savedPos2 = pos; + var result9 = parse_dot(); + var result10 = result9 !== null ? (function() { return { type: "any" }; })() : null; - if (result7 !== null) { - var result0 = result7; + if (result10 !== null) { + var result8 = result10; } else { - var result6 = parse_class(); - if (result6 !== null) { - var result0 = result6; + var result8 = null; + pos = savedPos2; + } + if (result8 !== null) { + var result0 = result8; + } else { + var result7 = parse_class(); + if (result7 !== null) { + var result0 = result7; } else { var savedPos0 = pos; - var result3 = parse_lparen(); - if (result3 !== null) { - var result4 = parse_choice(); - if (result4 !== null) { - var result5 = parse_rparen(); - if (result5 !== null) { - var result2 = [result3, result4, result5]; + 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]; } else { var result2 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result2 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result2 = null; - pos = savedPos0; + pos = savedPos1; } - var result1 = result2 !== null + var result3 = result2 !== null ? (function(expression) { return expression; })(result2[1]) : null; + if (result3 !== null) { + var result1 = result3; + } else { + var result1 = null; + pos = savedPos0; + } if (result1 !== null) { var result0 = result1; } else { @@ -918,22 +1044,29 @@ PEG.parser = (function(){ var savedReportMatchFailures = reportMatchFailures; reportMatchFailures = false; var savedPos0 = pos; - var result2 = parse_braced(); - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + var savedPos1 = pos; + var result3 = parse_braced(); + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + 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; + } reportMatchFailures = savedReportMatchFailures; if (reportMatchFailures && result0 === null) { matchFailed("action"); @@ -956,71 +1089,78 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "{") { - var result2 = "{"; + var result3 = "{"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"{\""); } } - if (result2 !== null) { - var result3 = []; - var result7 = parse_braced(); - if (result7 !== null) { - var result5 = result7; + if (result3 !== null) { + var result4 = []; + var result8 = parse_braced(); + if (result8 !== null) { + var result6 = result8; } else { - var result6 = parse_nonBraceCharacter(); - if (result6 !== null) { - var result5 = result6; + var result7 = parse_nonBraceCharacter(); + if (result7 !== null) { + var result6 = result7; } else { - var result5 = null;; + var result6 = null;; }; } - while (result5 !== null) { - result3.push(result5); - var result7 = parse_braced(); - if (result7 !== null) { - var result5 = result7; + while (result6 !== null) { + result4.push(result6); + var result8 = parse_braced(); + if (result8 !== null) { + var result6 = result8; } else { - var result6 = parse_nonBraceCharacter(); - if (result6 !== null) { - var result5 = result6; + var result7 = parse_nonBraceCharacter(); + if (result7 !== null) { + var result6 = result7; } else { - var result5 = null;; + var result6 = null;; }; } } - if (result3 !== null) { + if (result4 !== null) { if (input.substr(pos, 1) === "}") { - var result4 = "}"; + var result5 = "}"; pos += 1; } else { - var result4 = null; + var result5 = null; if (reportMatchFailures) { matchFailed("\"}\""); } } - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result5 !== null) { + var result1 = [result3, result4, result5]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(parts) { return "{" + parts.join("") + "}"; })(result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1040,19 +1180,26 @@ PEG.parser = (function(){ } - var result2 = parse_nonBraceCharacter(); - if (result2 !== null) { + var savedPos0 = pos; + var result3 = parse_nonBraceCharacter(); + if (result3 !== null) { var result1 = []; - while (result2 !== null) { - result1.push(result2); - var result2 = parse_nonBraceCharacter(); + while (result3 !== null) { + result1.push(result3); + var result3 = parse_nonBraceCharacter(); } } else { var result1 = null; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(chars) { return chars.join(""); })(result1) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1101,30 +1248,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "=") { - var result2 = "="; + var result3 = "="; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"=\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "="; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1145,30 +1299,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === ":") { - var result2 = ":"; + var result3 = ":"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\":\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return ":"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1189,30 +1350,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === ";") { - var result2 = ";"; + var result3 = ";"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\";\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return ";"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1233,30 +1401,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "/") { - var result2 = "/"; + var result3 = "/"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"/\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "/"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1277,30 +1452,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "&") { - var result2 = "&"; + var result3 = "&"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"&\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; + pos = savedPos1; + } + var result2 = result1 !== null + ? (function() { return "&"; })() + : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; pos = savedPos0; } - var result0 = result1 !== null - ? (function() { return "&"; })() - : null; @@ -1321,30 +1503,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "!") { - var result2 = "!"; + var result3 = "!"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"!\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "!"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1365,30 +1554,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "?") { - var result2 = "?"; + var result3 = "?"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"?\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "?"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1409,30 +1605,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "*") { - var result2 = "*"; + var result3 = "*"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"*\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "*"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1453,30 +1656,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "+") { - var result2 = "+"; + var result3 = "+"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"+\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "+"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1497,30 +1707,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "(") { - var result2 = "("; + var result3 = "("; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"(\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "("; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1541,30 +1758,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === ")") { - var result2 = ")"; + var result3 = ")"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\")\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return ")"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1585,30 +1809,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === ".") { - var result2 = "."; + var result3 = "."; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\".\""); } } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "."; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1630,138 +1861,145 @@ PEG.parser = (function(){ var savedReportMatchFailures = reportMatchFailures; reportMatchFailures = false; var savedPos0 = pos; - var result12 = parse_letter(); - if (result12 !== null) { - var result2 = result12; + var savedPos1 = pos; + var result13 = parse_letter(); + if (result13 !== null) { + var result3 = result13; } else { if (input.substr(pos, 1) === "_") { - var result11 = "_"; + var result12 = "_"; pos += 1; } else { - var result11 = null; + var result12 = null; if (reportMatchFailures) { matchFailed("\"_\""); } } - if (result11 !== null) { - var result2 = result11; + if (result12 !== null) { + var result3 = result12; } else { if (input.substr(pos, 1) === "$") { - var result10 = "$"; + var result11 = "$"; pos += 1; } else { - var result10 = null; + var result11 = null; if (reportMatchFailures) { matchFailed("\"$\""); } } - if (result10 !== null) { - var result2 = result10; + if (result11 !== null) { + var result3 = result11; } else { - var result2 = null;; + var result3 = null;; }; }; } - if (result2 !== null) { - var result3 = []; - var result9 = parse_letter(); - if (result9 !== null) { - var result5 = result9; + if (result3 !== null) { + var result4 = []; + var result10 = parse_letter(); + if (result10 !== null) { + var result6 = result10; } else { - var result8 = parse_digit(); - if (result8 !== null) { - var result5 = result8; + var result9 = parse_digit(); + if (result9 !== null) { + var result6 = result9; } else { if (input.substr(pos, 1) === "_") { - var result7 = "_"; + var result8 = "_"; pos += 1; } else { - var result7 = null; + var result8 = null; if (reportMatchFailures) { matchFailed("\"_\""); } } - if (result7 !== null) { - var result5 = result7; + if (result8 !== null) { + var result6 = result8; } else { if (input.substr(pos, 1) === "$") { - var result6 = "$"; + var result7 = "$"; pos += 1; } else { - var result6 = null; + var result7 = null; if (reportMatchFailures) { matchFailed("\"$\""); } } - if (result6 !== null) { - var result5 = result6; + if (result7 !== null) { + var result6 = result7; } else { - var result5 = null;; + var result6 = null;; }; }; }; } - while (result5 !== null) { - result3.push(result5); - var result9 = parse_letter(); - if (result9 !== null) { - var result5 = result9; + while (result6 !== null) { + result4.push(result6); + var result10 = parse_letter(); + if (result10 !== null) { + var result6 = result10; } else { - var result8 = parse_digit(); - if (result8 !== null) { - var result5 = result8; + var result9 = parse_digit(); + if (result9 !== null) { + var result6 = result9; } else { if (input.substr(pos, 1) === "_") { - var result7 = "_"; + var result8 = "_"; pos += 1; } else { - var result7 = null; + var result8 = null; if (reportMatchFailures) { matchFailed("\"_\""); } } - if (result7 !== null) { - var result5 = result7; + if (result8 !== null) { + var result6 = result8; } else { if (input.substr(pos, 1) === "$") { - var result6 = "$"; + var result7 = "$"; pos += 1; } else { - var result6 = null; + var result7 = null; if (reportMatchFailures) { matchFailed("\"$\""); } } - if (result6 !== null) { - var result5 = result6; + if (result7 !== null) { + var result6 = result7; } else { - var result5 = null;; + var result6 = null;; }; }; }; } } - if (result3 !== null) { - var result4 = parse___(); - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result4 !== null) { + var result5 = parse___(); + if (result5 !== null) { + var result1 = [result3, result4, result5]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(head, tail) { return head + tail.join(""); })(result1[0], result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } reportMatchFailures = savedReportMatchFailures; if (reportMatchFailures && result0 === null) { matchFailed("identifier"); @@ -1785,32 +2023,39 @@ PEG.parser = (function(){ var savedReportMatchFailures = reportMatchFailures; reportMatchFailures = false; var savedPos0 = pos; - var result5 = parse_doubleQuotedLiteral(); - if (result5 !== null) { - var result2 = result5; + var savedPos1 = pos; + var result6 = parse_doubleQuotedLiteral(); + if (result6 !== null) { + var result3 = result6; } else { - var result4 = parse_singleQuotedLiteral(); - if (result4 !== null) { - var result2 = result4; + var result5 = parse_singleQuotedLiteral(); + if (result5 !== null) { + var result3 = result5; } else { - var result2 = null;; + var result3 = null;; }; } - if (result2 !== null) { - var result3 = parse___(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse___(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(literal) { return literal; })(result1[0]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } reportMatchFailures = savedReportMatchFailures; if (reportMatchFailures && result0 === null) { matchFailed("literal"); @@ -1833,49 +2078,56 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "\"") { - var result2 = "\""; + var result3 = "\""; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"\\\"\""); } } - if (result2 !== null) { - var result3 = []; - var result5 = parse_doubleQuotedCharacter(); - while (result5 !== null) { - result3.push(result5); - var result5 = parse_doubleQuotedCharacter(); + if (result3 !== null) { + var result4 = []; + var result6 = parse_doubleQuotedCharacter(); + while (result6 !== null) { + result4.push(result6); + var result6 = parse_doubleQuotedCharacter(); } - if (result3 !== null) { + if (result4 !== null) { if (input.substr(pos, 1) === "\"") { - var result4 = "\""; + var result5 = "\""; pos += 1; } else { - var result4 = null; + var result5 = null; if (reportMatchFailures) { matchFailed("\"\\\"\""); } } - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result5 !== null) { + var result1 = [result3, result4, result5]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(chars) { return chars.join(""); })(result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -1947,70 +2199,77 @@ PEG.parser = (function(){ var savedPos0 = pos; var savedPos1 = pos; + var savedPos2 = pos; var savedReportMatchFailuresVar0 = reportMatchFailures; reportMatchFailures = false; if (input.substr(pos, 1) === "\"") { - var result7 = "\""; + var result8 = "\""; pos += 1; } else { - var result7 = null; + var result8 = null; if (reportMatchFailures) { matchFailed("\"\\\"\""); } } - if (result7 !== null) { - var result4 = result7; + if (result8 !== null) { + var result5 = result8; } else { if (input.substr(pos, 1) === "\\") { - var result6 = "\\"; + var result7 = "\\"; pos += 1; } else { - var result6 = null; + var result7 = null; if (reportMatchFailures) { matchFailed("\"\\\\\""); } } - if (result6 !== null) { - var result4 = result6; + if (result7 !== null) { + var result5 = result7; } else { - var result5 = parse_eolChar(); - if (result5 !== null) { - var result4 = result5; + var result6 = parse_eolChar(); + if (result6 !== null) { + var result5 = result6; } else { - var result4 = null;; + var result5 = null;; }; }; } reportMatchFailures = savedReportMatchFailuresVar0; - if (result4 === null) { - var result2 = ''; + if (result5 === null) { + var result3 = ''; } else { - var result2 = null; - pos = savedPos1; + var result3 = null; + pos = savedPos2; } - if (result2 !== null) { + if (result3 !== null) { if (input.length > pos) { - var result3 = input.charAt(pos); + var result4 = input.charAt(pos); pos++; } else { - var result3 = null; + var result4 = null; if (reportMatchFailures) { matchFailed('any character'); } } - if (result3 !== null) { - var result1 = [result2, result3]; + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(char_) { return char_; })(result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -2031,49 +2290,56 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "'") { - var result2 = "'"; + var result3 = "'"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"'\""); } } - if (result2 !== null) { - var result3 = []; - var result5 = parse_singleQuotedCharacter(); - while (result5 !== null) { - result3.push(result5); - var result5 = parse_singleQuotedCharacter(); + if (result3 !== null) { + var result4 = []; + var result6 = parse_singleQuotedCharacter(); + while (result6 !== null) { + result4.push(result6); + var result6 = parse_singleQuotedCharacter(); } - if (result3 !== null) { + if (result4 !== null) { if (input.substr(pos, 1) === "'") { - var result4 = "'"; + var result5 = "'"; pos += 1; } else { - var result4 = null; + var result5 = null; if (reportMatchFailures) { matchFailed("\"'\""); } } - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result5 !== null) { + var result1 = [result3, result4, result5]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(chars) { return chars.join(""); })(result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -2145,70 +2411,77 @@ PEG.parser = (function(){ var savedPos0 = pos; var savedPos1 = pos; + var savedPos2 = pos; var savedReportMatchFailuresVar0 = reportMatchFailures; reportMatchFailures = false; if (input.substr(pos, 1) === "'") { - var result7 = "'"; + var result8 = "'"; pos += 1; } else { - var result7 = null; + var result8 = null; if (reportMatchFailures) { matchFailed("\"'\""); } } - if (result7 !== null) { - var result4 = result7; + if (result8 !== null) { + var result5 = result8; } else { if (input.substr(pos, 1) === "\\") { - var result6 = "\\"; + var result7 = "\\"; pos += 1; } else { - var result6 = null; + var result7 = null; if (reportMatchFailures) { matchFailed("\"\\\\\""); } } - if (result6 !== null) { - var result4 = result6; + if (result7 !== null) { + var result5 = result7; } else { - var result5 = parse_eolChar(); - if (result5 !== null) { - var result4 = result5; + var result6 = parse_eolChar(); + if (result6 !== null) { + var result5 = result6; } else { - var result4 = null;; + var result5 = null;; }; }; } reportMatchFailures = savedReportMatchFailuresVar0; - if (result4 === null) { - var result2 = ''; + if (result5 === null) { + var result3 = ''; } else { - var result2 = null; - pos = savedPos1; + var result3 = null; + pos = savedPos2; } - if (result2 !== null) { + if (result3 !== null) { if (input.length > pos) { - var result3 = input.charAt(pos); + var result4 = input.charAt(pos); pos++; } else { - var result3 = null; + var result4 = null; if (reportMatchFailures) { matchFailed('any character'); } } - if (result3 !== null) { - var result1 = [result2, result3]; + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(char_) { return char_; })(result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -2230,88 +2503,89 @@ PEG.parser = (function(){ var savedReportMatchFailures = reportMatchFailures; reportMatchFailures = false; var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "[") { - var result2 = "["; + var result3 = "["; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"[\""); } } - if (result2 !== null) { + if (result3 !== null) { if (input.substr(pos, 1) === "^") { - var result10 = "^"; + var result11 = "^"; pos += 1; } else { - var result10 = null; + var result11 = null; if (reportMatchFailures) { matchFailed("\"^\""); } } - var result3 = result10 !== null ? result10 : ''; - if (result3 !== null) { - var result4 = []; - var result9 = parse_classCharacterRange(); - if (result9 !== null) { - var result7 = result9; + var result4 = result11 !== null ? result11 : ''; + if (result4 !== null) { + var result5 = []; + var result10 = parse_classCharacterRange(); + if (result10 !== null) { + var result8 = result10; } else { - var result8 = parse_classCharacter(); - if (result8 !== null) { - var result7 = result8; + var result9 = parse_classCharacter(); + if (result9 !== null) { + var result8 = result9; } else { - var result7 = null;; + var result8 = null;; }; } - while (result7 !== null) { - result4.push(result7); - var result9 = parse_classCharacterRange(); - if (result9 !== null) { - var result7 = result9; + while (result8 !== null) { + result5.push(result8); + var result10 = parse_classCharacterRange(); + if (result10 !== null) { + var result8 = result10; } else { - var result8 = parse_classCharacter(); - if (result8 !== null) { - var result7 = result8; + var result9 = parse_classCharacter(); + if (result9 !== null) { + var result8 = result9; } else { - var result7 = null;; + var result8 = null;; }; } } - if (result4 !== null) { + if (result5 !== null) { if (input.substr(pos, 1) === "]") { - var result5 = "]"; + var result6 = "]"; pos += 1; } else { - var result5 = null; + var result6 = null; if (reportMatchFailures) { matchFailed("\"]\""); } } - if (result5 !== null) { - var result6 = parse___(); - if (result6 !== null) { - var result1 = [result2, result3, result4, result5, result6]; + if (result6 !== null) { + var result7 = parse___(); + if (result7 !== null) { + var result1 = [result3, result4, result5, result6, result7]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(inverted, parts) { var partsConverted = map(parts, function(part) { return part.data; }); var rawText = "[" @@ -2328,6 +2602,12 @@ PEG.parser = (function(){ }; })(result1[1], result1[2]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } reportMatchFailures = savedReportMatchFailures; if (reportMatchFailures && result0 === null) { matchFailed("character class"); @@ -2350,34 +2630,35 @@ PEG.parser = (function(){ var savedPos0 = pos; - var result2 = parse_classCharacter(); - if (result2 !== null) { + var savedPos1 = pos; + var result3 = parse_classCharacter(); + if (result3 !== null) { if (input.substr(pos, 1) === "-") { - var result3 = "-"; + var result4 = "-"; pos += 1; } else { - var result3 = null; + var result4 = null; if (reportMatchFailures) { matchFailed("\"-\""); } } - if (result3 !== null) { - var result4 = parse_classCharacter(); - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result4 !== null) { + var result5 = parse_classCharacter(); + if (result5 !== null) { + var result1 = [result3, result4, result5]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(begin, end) { if (begin.data.charCodeAt(0) > end.data.charCodeAt(0)) { throw new this.SyntaxError( @@ -2392,6 +2673,12 @@ PEG.parser = (function(){ } })(result1[0], result1[2]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -2411,8 +2698,9 @@ PEG.parser = (function(){ } + var savedPos0 = pos; var result1 = parse_bracketDelimitedCharacter(); - var result0 = result1 !== null + var result2 = result1 !== null ? (function(char_) { return { data: char_, @@ -2421,6 +2709,12 @@ PEG.parser = (function(){ }; })(result1) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -2492,70 +2786,77 @@ PEG.parser = (function(){ var savedPos0 = pos; var savedPos1 = pos; + var savedPos2 = pos; var savedReportMatchFailuresVar0 = reportMatchFailures; reportMatchFailures = false; if (input.substr(pos, 1) === "]") { - var result7 = "]"; + var result8 = "]"; pos += 1; } else { - var result7 = null; + var result8 = null; if (reportMatchFailures) { matchFailed("\"]\""); } } - if (result7 !== null) { - var result4 = result7; + if (result8 !== null) { + var result5 = result8; } else { if (input.substr(pos, 1) === "\\") { - var result6 = "\\"; + var result7 = "\\"; pos += 1; } else { - var result6 = null; + var result7 = null; if (reportMatchFailures) { matchFailed("\"\\\\\""); } } - if (result6 !== null) { - var result4 = result6; + if (result7 !== null) { + var result5 = result7; } else { - var result5 = parse_eolChar(); - if (result5 !== null) { - var result4 = result5; + var result6 = parse_eolChar(); + if (result6 !== null) { + var result5 = result6; } else { - var result4 = null;; + var result5 = null;; }; }; } reportMatchFailures = savedReportMatchFailuresVar0; - if (result4 === null) { - var result2 = ''; + if (result5 === null) { + var result3 = ''; } else { - var result2 = null; - pos = savedPos1; + var result3 = null; + pos = savedPos2; } - if (result2 !== null) { + if (result3 !== null) { if (input.length > pos) { - var result3 = input.charAt(pos); + var result4 = input.charAt(pos); pos++; } else { - var result3 = null; + var result4 = null; if (reportMatchFailures) { matchFailed('any character'); } } - if (result3 !== null) { - var result1 = [result2, result3]; + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(char_) { return char_; })(result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -2576,88 +2877,89 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "\\") { - var result2 = "\\"; + var result3 = "\\"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"\\\\\""); } } - if (result2 !== null) { - var savedPos1 = pos; + if (result3 !== null) { + var savedPos2 = pos; var savedReportMatchFailuresVar0 = reportMatchFailures; reportMatchFailures = false; - var result9 = parse_digit(); - if (result9 !== null) { - var result5 = result9; + var result10 = parse_digit(); + if (result10 !== null) { + var result6 = result10; } else { if (input.substr(pos, 1) === "x") { - var result8 = "x"; + var result9 = "x"; pos += 1; } else { - var result8 = null; + var result9 = null; if (reportMatchFailures) { matchFailed("\"x\""); } } - if (result8 !== null) { - var result5 = result8; + if (result9 !== null) { + var result6 = result9; } else { if (input.substr(pos, 1) === "u") { - var result7 = "u"; + var result8 = "u"; pos += 1; } else { - var result7 = null; + var result8 = null; if (reportMatchFailures) { matchFailed("\"u\""); } } - if (result7 !== null) { - var result5 = result7; + if (result8 !== null) { + var result6 = result8; } else { - var result6 = parse_eolChar(); - if (result6 !== null) { - var result5 = result6; + var result7 = parse_eolChar(); + if (result7 !== null) { + var result6 = result7; } else { - var result5 = null;; + var result6 = null;; }; }; }; } reportMatchFailures = savedReportMatchFailuresVar0; - if (result5 === null) { - var result3 = ''; + if (result6 === null) { + var result4 = ''; } else { - var result3 = null; - pos = savedPos1; + var result4 = null; + pos = savedPos2; } - if (result3 !== null) { + if (result4 !== null) { if (input.length > pos) { - var result4 = input.charAt(pos); + var result5 = input.charAt(pos); pos++; } else { - var result4 = null; + var result5 = null; if (reportMatchFailures) { matchFailed('any character'); } } - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result5 !== null) { + var result1 = [result3, result4, result5]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(char_) { return char_ .replace("b", "\b") @@ -2668,6 +2970,12 @@ PEG.parser = (function(){ .replace("v", "\x0B") // IE does not recognize "\v". })(result1[2]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -2688,40 +2996,47 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 2) === "\\0") { - var result2 = "\\0"; + var result3 = "\\0"; pos += 2; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"\\\\0\""); } } - if (result2 !== null) { - var savedPos1 = pos; + if (result3 !== null) { + var savedPos2 = pos; var savedReportMatchFailuresVar0 = reportMatchFailures; reportMatchFailures = false; - var result4 = parse_digit(); + var result5 = parse_digit(); reportMatchFailures = savedReportMatchFailuresVar0; - if (result4 === null) { - var result3 = ''; + if (result5 === null) { + var result4 = ''; } else { - var result3 = null; - pos = savedPos1; + var result4 = null; + pos = savedPos2; } - if (result3 !== null) { - var result1 = [result2, result3]; + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function() { return "\0"; })() : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } @@ -2742,38 +3057,45 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 2) === "\\x") { - var result2 = "\\x"; + var result3 = "\\x"; pos += 2; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"\\\\x\""); } } - if (result2 !== null) { - var result3 = parse_hexDigit(); - if (result3 !== null) { - var result4 = parse_hexDigit(); - if (result4 !== null) { - var result1 = [result2, result3, result4]; + if (result3 !== null) { + var result4 = parse_hexDigit(); + if (result4 !== null) { + var result5 = parse_hexDigit(); + if (result5 !== null) { + var result1 = [result3, result4, result5]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (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; + } @@ -2794,50 +3116,57 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 2) === "\\u") { - var result2 = "\\u"; + var result3 = "\\u"; pos += 2; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"\\\\u\""); } } - if (result2 !== null) { - var result3 = parse_hexDigit(); - 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 result1 = [result2, result3, result4, result5, result6]; + 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]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (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; + } @@ -2858,30 +3187,37 @@ PEG.parser = (function(){ var savedPos0 = pos; + var savedPos1 = pos; if (input.substr(pos, 1) === "\\") { - var result2 = "\\"; + var result3 = "\\"; pos += 1; } else { - var result2 = null; + var result3 = null; if (reportMatchFailures) { matchFailed("\"\\\\\""); } } - if (result2 !== null) { - var result3 = parse_eol(); - if (result3 !== null) { - var result1 = [result2, result3]; + if (result3 !== null) { + var result4 = parse_eol(); + if (result4 !== null) { + var result1 = [result3, result4]; } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } } else { var result1 = null; - pos = savedPos0; + pos = savedPos1; } - var result0 = result1 !== null + var result2 = result1 !== null ? (function(eol) { return eol; })(result1[1]) : null; + if (result2 !== null) { + var result0 = result2; + } else { + var result0 = null; + pos = savedPos0; + } diff --git a/test/compiler-test.js b/test/compiler-test.js index d152c65..839e164 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -129,6 +129,13 @@ test("actions", function() { ); parses(innerElementsLabeledParser, "abcde", ["a", [2, "b", "d"], "e"]); + /* + * Test that the parsing position returns after successfull parsing of the + * action expression and action returning |null|. + */ + var posTestParser = PEG.buildParser('start = "a" { return null; } / "a"'); + parses(posTestParser, "a", "a"); + /* Test that the action is not called when its expression does not match. */ var notAMatchParser = PEG.buildParser( 'start = "a" { ok(false, "action got called when it should not be"); }'