From 33a1a7c1e996dcf0d1c423b6db9740ff1ecea746 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 22 May 2010 10:13:48 +0200 Subject: [PATCH] Clean up class handling in the metagrammar and compiler The class AST node now contains structured data and a raw text which is used for error messages. --- lib/compiler.js | 29 +- lib/metagrammar.js | 1653 +++++++++++++++++++------------------- lib/metagrammar.pegjs | 40 +- test/metagrammar-test.js | 51 +- 4 files changed, 905 insertions(+), 868 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 5244299..87ba39b 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -723,16 +723,23 @@ PEG.Compiler = { }, "class": function(node, resultVar) { - /* - * Stupid IE considers regexps /[]/ and /[^]/ syntactically invalid, so we - * translate them into euqivalents it can handle. - */ - if (node.chars === "") { - var regexp = "/^(?!)/"; - } else if (node.chars === "^") { - var regexp = "/^[\\S\\s]/"; + if (node.parts.length > 0) { + var regexp = "/^[" + + (node.inverted ? "^" : "") + + PEG.ArrayUtils.map(node.parts, function(part) { + return part instanceof Array + ? PEG.RegExpUtils.quoteForClass(part[0]) + + "-" + + PEG.RegExpUtils.quoteForClass(part[1]) + : PEG.RegExpUtils.quoteForClass(part); + }).join("") + + "]/"; } else { - var regexp = "/^[" + node.chars + "]/"; + /* + * Stupid IE considers regexps /[]/ and /[^]/ syntactically invalid, so + * we translate them into euqivalents it can handle. + */ + var regexp = node.inverted ? "/^[\\S\\s]/" : "/^(?!)/"; } return PEG.Compiler.formatCode( @@ -742,12 +749,12 @@ PEG.Compiler = { "} else {", " var ${resultVar} = null;", " if (context.reportMatchFailures) {", - " this._matchFailed('[' + ${chars|string} + ']');", + " this._matchFailed(${rawText|string});", " }", "}", { - chars: node.chars, regexp: regexp, + rawText: node.rawText, resultVar: resultVar } ); diff --git a/lib/metagrammar.js b/lib/metagrammar.js index e177585..3e2725e 100644 --- a/lib/metagrammar.js +++ b/lib/metagrammar.js @@ -527,84 +527,81 @@ PEG.grammarParser = (function(){ var savedPos11 = this._pos; - var result68 = this._parse_identifier(context); - if (result68 !== null) { + var result67 = this._parse_identifier(context); + if (result67 !== null) { var savedPos12 = this._pos; var savedReportMatchFailuresVar0 = context.reportMatchFailures; context.reportMatchFailures = false; var savedPos13 = this._pos; - var result74 = this._parse_literal(context); - if (result74 !== null) { - var result71 = result74; + var result73 = this._parse_literal(context); + if (result73 !== null) { + var result70 = result73; } else { if (this._input.substr(this._pos, 0) === "") { - var result73 = ""; + var result72 = ""; this._pos += 0; } else { - var result73 = null; + var result72 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("")); } } - if (result73 !== null) { - var result71 = result73; + if (result72 !== null) { + var result70 = result72; } else { - var result71 = null;; + var result70 = null;; }; } - if (result71 !== null) { - var result72 = this._parse_colon(context); - if (result72 !== null) { - var result70 = [result71, result72]; + if (result70 !== null) { + var result71 = this._parse_colon(context); + if (result71 !== null) { + var result69 = [result70, result71]; } else { - var result70 = null; + var result69 = null; this._pos = savedPos13; } } else { - var result70 = null; + var result69 = null; this._pos = savedPos13; } context.reportMatchFailures = savedReportMatchFailuresVar0; - if (result70 === null) { - var result69 = ''; + if (result69 === null) { + var result68 = ''; } else { - var result69 = null; + var result68 = null; this._pos = savedPos12; } - if (result69 !== null) { - var result67 = [result68, result69]; + if (result68 !== null) { + var result66 = [result67, result68]; } else { - var result67 = null; + var result66 = null; this._pos = savedPos11; } } else { - var result67 = null; + var result66 = null; this._pos = savedPos11; } - var result66 = result67 !== null - ? (function($1, $2) { return { type: "rule_ref", name: $1 }; }).apply(null, result67) + var result65 = result66 !== null + ? (function($1, $2) { return { type: "rule_ref", name: $1 }; }).apply(null, result66) : null; - if (result66 !== null) { - var result54 = result66; + if (result65 !== null) { + var result54 = result65; } else { - var result65 = this._parse_literal(context); - var result64 = result65 !== null - ? (function($1) { return { type: "literal", value: $1 }; })(result65) + var result64 = this._parse_literal(context); + var result63 = result64 !== null + ? (function($1) { return { type: "literal", value: $1 }; })(result64) : null; - if (result64 !== null) { - var result54 = result64; + if (result63 !== null) { + var result54 = result63; } else { - var result63 = this._parse_dot(context); - var result62 = result63 !== null - ? (function($1) { return { type: "any" }; })(result63) + var result62 = this._parse_dot(context); + var result61 = result62 !== null + ? (function($1) { return { type: "any" }; })(result62) : null; - if (result62 !== null) { - var result54 = result62; + if (result61 !== null) { + var result54 = result61; } else { - var result61 = this._parse_class(context); - var result60 = result61 !== null - ? (function($1) { return { type: "class", chars: $1 }; })(result61) - : null; + var result60 = this._parse_class(context); if (result60 !== null) { var result54 = result60; } else { @@ -663,32 +660,32 @@ PEG.grammarParser = (function(){ var savedReportMatchFailures = context.reportMatchFailures; context.reportMatchFailures = false; var savedPos14 = this._pos; - var result77 = this._parse_braced(context); - if (result77 !== null) { - var result78 = this._parse___(context); - if (result78 !== null) { - var result76 = [result77, result78]; + var result76 = this._parse_braced(context); + if (result76 !== null) { + var result77 = this._parse___(context); + if (result77 !== null) { + var result75 = [result76, result77]; } else { - var result76 = null; + var result75 = null; this._pos = savedPos14; } } else { - var result76 = null; + var result75 = null; this._pos = savedPos14; } - var result75 = result76 !== null - ? (function($1, $2) { return $1.substr(1, $1.length - 2); }).apply(null, result76) + var result74 = result75 !== null + ? (function($1, $2) { return $1.substr(1, $1.length - 2); }).apply(null, result75) : null; context.reportMatchFailures = savedReportMatchFailures; - if (context.reportMatchFailures && result75 === null) { + if (context.reportMatchFailures && result74 === null) { this._matchFailed("action"); } this._cache[cacheKey] = { nextPos: this._pos, - result: result75 + result: result74 }; - return result75; + return result74; }, _parse_braced: function(context) { @@ -704,76 +701,76 @@ PEG.grammarParser = (function(){ var savedPos15 = this._pos; if (this._input.substr(this._pos, 1) === "{") { - var result81 = "{"; + var result80 = "{"; this._pos += 1; } else { - var result81 = null; + var result80 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("{")); } } - if (result81 !== null) { - var result82 = []; - var result86 = this._parse_braced(context); - if (result86 !== null) { - var result84 = result86; + if (result80 !== null) { + var result81 = []; + var result85 = this._parse_braced(context); + if (result85 !== null) { + var result83 = result85; } else { - var result85 = this._parse_nonBraceCharacter(context); - if (result85 !== null) { - var result84 = result85; + var result84 = this._parse_nonBraceCharacter(context); + if (result84 !== null) { + var result83 = result84; } else { - var result84 = null;; + var result83 = null;; }; } - while (result84 !== null) { - result82.push(result84); - var result86 = this._parse_braced(context); - if (result86 !== null) { - var result84 = result86; + while (result83 !== null) { + result81.push(result83); + var result85 = this._parse_braced(context); + if (result85 !== null) { + var result83 = result85; } else { - var result85 = this._parse_nonBraceCharacter(context); - if (result85 !== null) { - var result84 = result85; + var result84 = this._parse_nonBraceCharacter(context); + if (result84 !== null) { + var result83 = result84; } else { - var result84 = null;; + var result83 = null;; }; } } - if (result82 !== null) { + if (result81 !== null) { if (this._input.substr(this._pos, 1) === "}") { - var result83 = "}"; + var result82 = "}"; this._pos += 1; } else { - var result83 = null; + var result82 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("}")); } } - if (result83 !== null) { - var result80 = [result81, result82, result83]; + if (result82 !== null) { + var result79 = [result80, result81, result82]; } else { - var result80 = null; + var result79 = null; this._pos = savedPos15; } } else { - var result80 = null; + var result79 = null; this._pos = savedPos15; } } else { - var result80 = null; + var result79 = null; this._pos = savedPos15; } - var result79 = result80 !== null - ? (function($1, $2, $3) { return $1 + $2.join("") + $3; }).apply(null, result80) + var result78 = result79 !== null + ? (function($1, $2, $3) { return $1 + $2.join("") + $3; }).apply(null, result79) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result79 + result: result78 }; - return result79; + return result78; }, _parse_nonBraceCharacters: function(context) { @@ -787,27 +784,27 @@ PEG.grammarParser = (function(){ var pos = this._pos; - var result89 = this._parse_nonBraceCharacter(context); - if (result89 !== null) { - var result88 = []; - while (result89 !== null) { - result88.push(result89); - var result89 = this._parse_nonBraceCharacter(context); + var result88 = this._parse_nonBraceCharacter(context); + if (result88 !== null) { + var result87 = []; + while (result88 !== null) { + result87.push(result88); + var result88 = this._parse_nonBraceCharacter(context); } } else { - var result88 = null; + var result87 = null; } - var result87 = result88 !== null - ? (function($1) { return $1.join(""); })(result88) + var result86 = result87 !== null + ? (function($1) { return $1.join(""); })(result87) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result87 + result: result86 }; - return result87; + return result86; }, _parse_nonBraceCharacter: function(context) { @@ -822,25 +819,25 @@ PEG.grammarParser = (function(){ if (this._input.substr(this._pos).match(/^[^{}]/) !== null) { - var result91 = this._input.charAt(this._pos); + var result90 = this._input.charAt(this._pos); this._pos++; } else { - var result91 = null; + var result90 = null; if (context.reportMatchFailures) { - this._matchFailed('[' + "^{}" + ']'); + this._matchFailed("[^{}]"); } } - var result90 = result91 !== null - ? (function($1) { return $1; })(result91) + var result89 = result90 !== null + ? (function($1) { return $1; })(result90) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result90 + result: result89 }; - return result90; + return result89; }, _parse_colon: function(context) { @@ -856,37 +853,37 @@ PEG.grammarParser = (function(){ var savedPos16 = this._pos; if (this._input.substr(this._pos, 1) === ":") { - var result94 = ":"; + var result93 = ":"; this._pos += 1; } else { - var result94 = null; + var result93 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString(":")); } } - if (result94 !== null) { - var result95 = this._parse___(context); - if (result95 !== null) { - var result93 = [result94, result95]; + if (result93 !== null) { + var result94 = this._parse___(context); + if (result94 !== null) { + var result92 = [result93, result94]; } else { - var result93 = null; + var result92 = null; this._pos = savedPos16; } } else { - var result93 = null; + var result92 = null; this._pos = savedPos16; } - var result92 = result93 !== null - ? (function($1, $2) { return $1; }).apply(null, result93) + var result91 = result92 !== null + ? (function($1, $2) { return $1; }).apply(null, result92) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result92 + result: result91 }; - return result92; + return result91; }, _parse_slash: function(context) { @@ -902,37 +899,37 @@ PEG.grammarParser = (function(){ var savedPos17 = this._pos; if (this._input.substr(this._pos, 1) === "/") { - var result98 = "/"; + var result97 = "/"; this._pos += 1; } else { - var result98 = null; + var result97 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("/")); } } - if (result98 !== null) { - var result99 = this._parse___(context); - if (result99 !== null) { - var result97 = [result98, result99]; + if (result97 !== null) { + var result98 = this._parse___(context); + if (result98 !== null) { + var result96 = [result97, result98]; } else { - var result97 = null; + var result96 = null; this._pos = savedPos17; } } else { - var result97 = null; + var result96 = null; this._pos = savedPos17; } - var result96 = result97 !== null - ? (function($1, $2) { return $1; }).apply(null, result97) + var result95 = result96 !== null + ? (function($1, $2) { return $1; }).apply(null, result96) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result96 + result: result95 }; - return result96; + return result95; }, _parse_and: function(context) { @@ -948,37 +945,37 @@ PEG.grammarParser = (function(){ var savedPos18 = this._pos; if (this._input.substr(this._pos, 1) === "&") { - var result102 = "&"; + var result101 = "&"; this._pos += 1; } else { - var result102 = null; + var result101 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("&")); } } - if (result102 !== null) { - var result103 = this._parse___(context); - if (result103 !== null) { - var result101 = [result102, result103]; + if (result101 !== null) { + var result102 = this._parse___(context); + if (result102 !== null) { + var result100 = [result101, result102]; } else { - var result101 = null; + var result100 = null; this._pos = savedPos18; } } else { - var result101 = null; + var result100 = null; this._pos = savedPos18; } - var result100 = result101 !== null - ? (function($1, $2) { return $1; }).apply(null, result101) + var result99 = result100 !== null + ? (function($1, $2) { return $1; }).apply(null, result100) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result100 + result: result99 }; - return result100; + return result99; }, _parse_not: function(context) { @@ -994,37 +991,37 @@ PEG.grammarParser = (function(){ var savedPos19 = this._pos; if (this._input.substr(this._pos, 1) === "!") { - var result106 = "!"; + var result105 = "!"; this._pos += 1; } else { - var result106 = null; + var result105 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("!")); } } - if (result106 !== null) { - var result107 = this._parse___(context); - if (result107 !== null) { - var result105 = [result106, result107]; + if (result105 !== null) { + var result106 = this._parse___(context); + if (result106 !== null) { + var result104 = [result105, result106]; } else { - var result105 = null; + var result104 = null; this._pos = savedPos19; } } else { - var result105 = null; + var result104 = null; this._pos = savedPos19; } - var result104 = result105 !== null - ? (function($1, $2) { return $1; }).apply(null, result105) + var result103 = result104 !== null + ? (function($1, $2) { return $1; }).apply(null, result104) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result104 + result: result103 }; - return result104; + return result103; }, _parse_question: function(context) { @@ -1040,37 +1037,37 @@ PEG.grammarParser = (function(){ var savedPos20 = this._pos; if (this._input.substr(this._pos, 1) === "?") { - var result110 = "?"; + var result109 = "?"; this._pos += 1; } else { - var result110 = null; + var result109 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("?")); } } - if (result110 !== null) { - var result111 = this._parse___(context); - if (result111 !== null) { - var result109 = [result110, result111]; + if (result109 !== null) { + var result110 = this._parse___(context); + if (result110 !== null) { + var result108 = [result109, result110]; } else { - var result109 = null; + var result108 = null; this._pos = savedPos20; } } else { - var result109 = null; + var result108 = null; this._pos = savedPos20; } - var result108 = result109 !== null - ? (function($1, $2) { return $1; }).apply(null, result109) + var result107 = result108 !== null + ? (function($1, $2) { return $1; }).apply(null, result108) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result108 + result: result107 }; - return result108; + return result107; }, _parse_star: function(context) { @@ -1086,37 +1083,37 @@ PEG.grammarParser = (function(){ var savedPos21 = this._pos; if (this._input.substr(this._pos, 1) === "*") { - var result114 = "*"; + var result113 = "*"; this._pos += 1; } else { - var result114 = null; + var result113 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("*")); } } - if (result114 !== null) { - var result115 = this._parse___(context); - if (result115 !== null) { - var result113 = [result114, result115]; + if (result113 !== null) { + var result114 = this._parse___(context); + if (result114 !== null) { + var result112 = [result113, result114]; } else { - var result113 = null; + var result112 = null; this._pos = savedPos21; } } else { - var result113 = null; + var result112 = null; this._pos = savedPos21; } - var result112 = result113 !== null - ? (function($1, $2) { return $1; }).apply(null, result113) + var result111 = result112 !== null + ? (function($1, $2) { return $1; }).apply(null, result112) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result112 + result: result111 }; - return result112; + return result111; }, _parse_plus: function(context) { @@ -1132,37 +1129,37 @@ PEG.grammarParser = (function(){ var savedPos22 = this._pos; if (this._input.substr(this._pos, 1) === "+") { - var result118 = "+"; + var result117 = "+"; this._pos += 1; } else { - var result118 = null; + var result117 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("+")); } } - if (result118 !== null) { - var result119 = this._parse___(context); - if (result119 !== null) { - var result117 = [result118, result119]; + if (result117 !== null) { + var result118 = this._parse___(context); + if (result118 !== null) { + var result116 = [result117, result118]; } else { - var result117 = null; + var result116 = null; this._pos = savedPos22; } } else { - var result117 = null; + var result116 = null; this._pos = savedPos22; } - var result116 = result117 !== null - ? (function($1, $2) { return $1; }).apply(null, result117) + var result115 = result116 !== null + ? (function($1, $2) { return $1; }).apply(null, result116) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result116 + result: result115 }; - return result116; + return result115; }, _parse_lparen: function(context) { @@ -1178,37 +1175,37 @@ PEG.grammarParser = (function(){ var savedPos23 = this._pos; if (this._input.substr(this._pos, 1) === "(") { - var result122 = "("; + var result121 = "("; this._pos += 1; } else { - var result122 = null; + var result121 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("(")); } } - if (result122 !== null) { - var result123 = this._parse___(context); - if (result123 !== null) { - var result121 = [result122, result123]; + if (result121 !== null) { + var result122 = this._parse___(context); + if (result122 !== null) { + var result120 = [result121, result122]; } else { - var result121 = null; + var result120 = null; this._pos = savedPos23; } } else { - var result121 = null; + var result120 = null; this._pos = savedPos23; } - var result120 = result121 !== null - ? (function($1, $2) { return $1; }).apply(null, result121) + var result119 = result120 !== null + ? (function($1, $2) { return $1; }).apply(null, result120) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result120 + result: result119 }; - return result120; + return result119; }, _parse_rparen: function(context) { @@ -1224,37 +1221,37 @@ PEG.grammarParser = (function(){ var savedPos24 = this._pos; if (this._input.substr(this._pos, 1) === ")") { - var result126 = ")"; + var result125 = ")"; this._pos += 1; } else { - var result126 = null; + var result125 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString(")")); } } - if (result126 !== null) { - var result127 = this._parse___(context); - if (result127 !== null) { - var result125 = [result126, result127]; + if (result125 !== null) { + var result126 = this._parse___(context); + if (result126 !== null) { + var result124 = [result125, result126]; } else { - var result125 = null; + var result124 = null; this._pos = savedPos24; } } else { - var result125 = null; + var result124 = null; this._pos = savedPos24; } - var result124 = result125 !== null - ? (function($1, $2) { return $1; }).apply(null, result125) + var result123 = result124 !== null + ? (function($1, $2) { return $1; }).apply(null, result124) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result124 + result: result123 }; - return result124; + return result123; }, _parse_dot: function(context) { @@ -1270,37 +1267,37 @@ PEG.grammarParser = (function(){ var savedPos25 = this._pos; if (this._input.substr(this._pos, 1) === ".") { - var result130 = "."; + var result129 = "."; this._pos += 1; } else { - var result130 = null; + var result129 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString(".")); } } - if (result130 !== null) { - var result131 = this._parse___(context); - if (result131 !== null) { - var result129 = [result130, result131]; + if (result129 !== null) { + var result130 = this._parse___(context); + if (result130 !== null) { + var result128 = [result129, result130]; } else { - var result129 = null; + var result128 = null; this._pos = savedPos25; } } else { - var result129 = null; + var result128 = null; this._pos = savedPos25; } - var result128 = result129 !== null - ? (function($1, $2) { return $1; }).apply(null, result129) + var result127 = result128 !== null + ? (function($1, $2) { return $1; }).apply(null, result128) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result128 + result: result127 }; - return result128; + return result127; }, _parse_identifier: function(context) { @@ -1316,148 +1313,148 @@ PEG.grammarParser = (function(){ var savedReportMatchFailures = context.reportMatchFailures; context.reportMatchFailures = false; var savedPos26 = this._pos; - var result144 = this._parse_letter(context); - if (result144 !== null) { - var result134 = result144; + var result143 = this._parse_letter(context); + if (result143 !== null) { + var result133 = result143; } else { if (this._input.substr(this._pos, 1) === "_") { - var result143 = "_"; + var result142 = "_"; this._pos += 1; } else { - var result143 = null; + var result142 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("_")); } } - if (result143 !== null) { - var result134 = result143; + if (result142 !== null) { + var result133 = result142; } else { if (this._input.substr(this._pos, 1) === "$") { - var result142 = "$"; + var result141 = "$"; this._pos += 1; } else { - var result142 = null; + var result141 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("$")); } } - if (result142 !== null) { - var result134 = result142; + if (result141 !== null) { + var result133 = result141; } else { - var result134 = null;; + var result133 = null;; }; }; } - if (result134 !== null) { - var result135 = []; - var result141 = this._parse_letter(context); - if (result141 !== null) { - var result137 = result141; + if (result133 !== null) { + var result134 = []; + var result140 = this._parse_letter(context); + if (result140 !== null) { + var result136 = result140; } else { - var result140 = this._parse_digit(context); - if (result140 !== null) { - var result137 = result140; + var result139 = this._parse_digit(context); + if (result139 !== null) { + var result136 = result139; } else { if (this._input.substr(this._pos, 1) === "_") { - var result139 = "_"; + var result138 = "_"; this._pos += 1; } else { - var result139 = null; + var result138 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("_")); } } - if (result139 !== null) { - var result137 = result139; + if (result138 !== null) { + var result136 = result138; } else { if (this._input.substr(this._pos, 1) === "$") { - var result138 = "$"; + var result137 = "$"; this._pos += 1; } else { - var result138 = null; + var result137 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("$")); } } - if (result138 !== null) { - var result137 = result138; + if (result137 !== null) { + var result136 = result137; } else { - var result137 = null;; + var result136 = null;; }; }; }; } - while (result137 !== null) { - result135.push(result137); - var result141 = this._parse_letter(context); - if (result141 !== null) { - var result137 = result141; + while (result136 !== null) { + result134.push(result136); + var result140 = this._parse_letter(context); + if (result140 !== null) { + var result136 = result140; } else { - var result140 = this._parse_digit(context); - if (result140 !== null) { - var result137 = result140; + var result139 = this._parse_digit(context); + if (result139 !== null) { + var result136 = result139; } else { if (this._input.substr(this._pos, 1) === "_") { - var result139 = "_"; + var result138 = "_"; this._pos += 1; } else { - var result139 = null; + var result138 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("_")); } } - if (result139 !== null) { - var result137 = result139; + if (result138 !== null) { + var result136 = result138; } else { if (this._input.substr(this._pos, 1) === "$") { - var result138 = "$"; + var result137 = "$"; this._pos += 1; } else { - var result138 = null; + var result137 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("$")); } } - if (result138 !== null) { - var result137 = result138; + if (result137 !== null) { + var result136 = result137; } else { - var result137 = null;; + var result136 = null;; }; }; }; } } - if (result135 !== null) { - var result136 = this._parse___(context); - if (result136 !== null) { - var result133 = [result134, result135, result136]; + if (result134 !== null) { + var result135 = this._parse___(context); + if (result135 !== null) { + var result132 = [result133, result134, result135]; } else { - var result133 = null; + var result132 = null; this._pos = savedPos26; } } else { - var result133 = null; + var result132 = null; this._pos = savedPos26; } } else { - var result133 = null; + var result132 = null; this._pos = savedPos26; } - var result132 = result133 !== null + var result131 = result132 !== null ? (function($1, $2, $3) { return $1 + $2.join(""); - }).apply(null, result133) + }).apply(null, result132) : null; context.reportMatchFailures = savedReportMatchFailures; - if (context.reportMatchFailures && result132 === null) { + if (context.reportMatchFailures && result131 === null) { this._matchFailed("identifier"); } this._cache[cacheKey] = { nextPos: this._pos, - result: result132 + result: result131 }; - return result132; + return result131; }, _parse_literal: function(context) { @@ -1473,42 +1470,42 @@ PEG.grammarParser = (function(){ var savedReportMatchFailures = context.reportMatchFailures; context.reportMatchFailures = false; var savedPos27 = this._pos; - var result150 = this._parse_doubleQuotedLiteral(context); - if (result150 !== null) { - var result147 = result150; + var result149 = this._parse_doubleQuotedLiteral(context); + if (result149 !== null) { + var result146 = result149; } else { - var result149 = this._parse_singleQuotedLiteral(context); - if (result149 !== null) { - var result147 = result149; + var result148 = this._parse_singleQuotedLiteral(context); + if (result148 !== null) { + var result146 = result148; } else { - var result147 = null;; + var result146 = null;; }; } - if (result147 !== null) { - var result148 = this._parse___(context); - if (result148 !== null) { - var result146 = [result147, result148]; + if (result146 !== null) { + var result147 = this._parse___(context); + if (result147 !== null) { + var result145 = [result146, result147]; } else { - var result146 = null; + var result145 = null; this._pos = savedPos27; } } else { - var result146 = null; + var result145 = null; this._pos = savedPos27; } - var result145 = result146 !== null - ? (function($1, $2) { return $1; }).apply(null, result146) + var result144 = result145 !== null + ? (function($1, $2) { return $1; }).apply(null, result145) : null; context.reportMatchFailures = savedReportMatchFailures; - if (context.reportMatchFailures && result145 === null) { + if (context.reportMatchFailures && result144 === null) { this._matchFailed("literal"); } this._cache[cacheKey] = { nextPos: this._pos, - result: result145 + result: result144 }; - return result145; + return result144; }, _parse_doubleQuotedLiteral: function(context) { @@ -1524,56 +1521,56 @@ PEG.grammarParser = (function(){ var savedPos28 = this._pos; if (this._input.substr(this._pos, 1) === "\"") { - var result153 = "\""; + var result152 = "\""; this._pos += 1; } else { - var result153 = null; + var result152 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\"")); } } - if (result153 !== null) { - var result154 = []; - var result156 = this._parse_doubleQuotedCharacter(context); - while (result156 !== null) { - result154.push(result156); - var result156 = this._parse_doubleQuotedCharacter(context); + if (result152 !== null) { + var result153 = []; + var result155 = this._parse_doubleQuotedCharacter(context); + while (result155 !== null) { + result153.push(result155); + var result155 = this._parse_doubleQuotedCharacter(context); } - if (result154 !== null) { + if (result153 !== null) { if (this._input.substr(this._pos, 1) === "\"") { - var result155 = "\""; + var result154 = "\""; this._pos += 1; } else { - var result155 = null; + var result154 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\"")); } } - if (result155 !== null) { - var result152 = [result153, result154, result155]; + if (result154 !== null) { + var result151 = [result152, result153, result154]; } else { - var result152 = null; + var result151 = null; this._pos = savedPos28; } } else { - var result152 = null; + var result151 = null; this._pos = savedPos28; } } else { - var result152 = null; + var result151 = null; this._pos = savedPos28; } - var result151 = result152 !== null - ? (function($1, $2, $3) { return $2.join(""); }).apply(null, result152) + var result150 = result151 !== null + ? (function($1, $2, $3) { return $2.join(""); }).apply(null, result151) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result151 + result: result150 }; - return result151; + return result150; }, _parse_doubleQuotedCharacter: function(context) { @@ -1587,31 +1584,31 @@ PEG.grammarParser = (function(){ var pos = this._pos; - var result163 = this._parse_simpleDoubleQuotedCharacter(context); - if (result163 !== null) { - var result157 = result163; + var result162 = this._parse_simpleDoubleQuotedCharacter(context); + if (result162 !== null) { + var result156 = result162; } else { - var result162 = this._parse_simpleEscapeSequence(context); - if (result162 !== null) { - var result157 = result162; + var result161 = this._parse_simpleEscapeSequence(context); + if (result161 !== null) { + var result156 = result161; } else { - var result161 = this._parse_zeroEscapeSequence(context); - if (result161 !== null) { - var result157 = result161; + var result160 = this._parse_zeroEscapeSequence(context); + if (result160 !== null) { + var result156 = result160; } else { - var result160 = this._parse_hexEscapeSequence(context); - if (result160 !== null) { - var result157 = result160; + var result159 = this._parse_hexEscapeSequence(context); + if (result159 !== null) { + var result156 = result159; } else { - var result159 = this._parse_unicodeEscapeSequence(context); - if (result159 !== null) { - var result157 = result159; + var result158 = this._parse_unicodeEscapeSequence(context); + if (result158 !== null) { + var result156 = result158; } else { - var result158 = this._parse_eolEscapeSequence(context); - if (result158 !== null) { - var result157 = result158; + var result157 = this._parse_eolEscapeSequence(context); + if (result157 !== null) { + var result156 = result157; } else { - var result157 = null;; + var result156 = null;; }; }; }; @@ -1623,9 +1620,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result157 + result: result156 }; - return result157; + return result156; }, _parse_simpleDoubleQuotedCharacter: function(context) { @@ -1644,75 +1641,75 @@ PEG.grammarParser = (function(){ var savedReportMatchFailuresVar1 = context.reportMatchFailures; context.reportMatchFailures = false; if (this._input.substr(this._pos, 1) === "\"") { - var result171 = "\""; + var result170 = "\""; this._pos += 1; } else { - var result171 = null; + var result170 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\"")); } } - if (result171 !== null) { - var result168 = result171; + if (result170 !== null) { + var result167 = result170; } else { if (this._input.substr(this._pos, 1) === "\\") { - var result170 = "\\"; + var result169 = "\\"; this._pos += 1; } else { - var result170 = null; + var result169 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\\")); } } - if (result170 !== null) { - var result168 = result170; + if (result169 !== null) { + var result167 = result169; } else { - var result169 = this._parse_eolChar(context); - if (result169 !== null) { - var result168 = result169; + var result168 = this._parse_eolChar(context); + if (result168 !== null) { + var result167 = result168; } else { - var result168 = null;; + var result167 = null;; }; }; } context.reportMatchFailures = savedReportMatchFailuresVar1; - if (result168 === null) { - var result166 = ''; + if (result167 === null) { + var result165 = ''; } else { - var result166 = null; + var result165 = null; this._pos = savedPos30; } - if (result166 !== null) { + if (result165 !== null) { if (this._input.length > this._pos) { - var result167 = this._input.charAt(this._pos); + var result166 = this._input.charAt(this._pos); this._pos++; } else { - var result167 = null; + var result166 = null; if (context.reportMatchFailures) { this._matchFailed('any character'); } } - if (result167 !== null) { - var result165 = [result166, result167]; + if (result166 !== null) { + var result164 = [result165, result166]; } else { - var result165 = null; + var result164 = null; this._pos = savedPos29; } } else { - var result165 = null; + var result164 = null; this._pos = savedPos29; } - var result164 = result165 !== null - ? (function($1, $2) { return $2; }).apply(null, result165) + var result163 = result164 !== null + ? (function($1, $2) { return $2; }).apply(null, result164) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result164 + result: result163 }; - return result164; + return result163; }, _parse_singleQuotedLiteral: function(context) { @@ -1728,56 +1725,56 @@ PEG.grammarParser = (function(){ var savedPos31 = this._pos; if (this._input.substr(this._pos, 1) === "'") { - var result174 = "'"; + var result173 = "'"; this._pos += 1; } else { - var result174 = null; + var result173 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("'")); } } - if (result174 !== null) { - var result175 = []; - var result177 = this._parse_singleQuotedCharacter(context); - while (result177 !== null) { - result175.push(result177); - var result177 = this._parse_singleQuotedCharacter(context); + if (result173 !== null) { + var result174 = []; + var result176 = this._parse_singleQuotedCharacter(context); + while (result176 !== null) { + result174.push(result176); + var result176 = this._parse_singleQuotedCharacter(context); } - if (result175 !== null) { + if (result174 !== null) { if (this._input.substr(this._pos, 1) === "'") { - var result176 = "'"; + var result175 = "'"; this._pos += 1; } else { - var result176 = null; + var result175 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("'")); } } - if (result176 !== null) { - var result173 = [result174, result175, result176]; + if (result175 !== null) { + var result172 = [result173, result174, result175]; } else { - var result173 = null; + var result172 = null; this._pos = savedPos31; } } else { - var result173 = null; + var result172 = null; this._pos = savedPos31; } } else { - var result173 = null; + var result172 = null; this._pos = savedPos31; } - var result172 = result173 !== null - ? (function($1, $2, $3) { return $2.join(""); }).apply(null, result173) + var result171 = result172 !== null + ? (function($1, $2, $3) { return $2.join(""); }).apply(null, result172) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result172 + result: result171 }; - return result172; + return result171; }, _parse_singleQuotedCharacter: function(context) { @@ -1791,31 +1788,31 @@ PEG.grammarParser = (function(){ var pos = this._pos; - var result184 = this._parse_simpleSingleQuotedCharacter(context); - if (result184 !== null) { - var result178 = result184; + var result183 = this._parse_simpleSingleQuotedCharacter(context); + if (result183 !== null) { + var result177 = result183; } else { - var result183 = this._parse_simpleEscapeSequence(context); - if (result183 !== null) { - var result178 = result183; + var result182 = this._parse_simpleEscapeSequence(context); + if (result182 !== null) { + var result177 = result182; } else { - var result182 = this._parse_zeroEscapeSequence(context); - if (result182 !== null) { - var result178 = result182; + var result181 = this._parse_zeroEscapeSequence(context); + if (result181 !== null) { + var result177 = result181; } else { - var result181 = this._parse_hexEscapeSequence(context); - if (result181 !== null) { - var result178 = result181; + var result180 = this._parse_hexEscapeSequence(context); + if (result180 !== null) { + var result177 = result180; } else { - var result180 = this._parse_unicodeEscapeSequence(context); - if (result180 !== null) { - var result178 = result180; + var result179 = this._parse_unicodeEscapeSequence(context); + if (result179 !== null) { + var result177 = result179; } else { - var result179 = this._parse_eolEscapeSequence(context); - if (result179 !== null) { - var result178 = result179; + var result178 = this._parse_eolEscapeSequence(context); + if (result178 !== null) { + var result177 = result178; } else { - var result178 = null;; + var result177 = null;; }; }; }; @@ -1827,9 +1824,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result178 + result: result177 }; - return result178; + return result177; }, _parse_simpleSingleQuotedCharacter: function(context) { @@ -1848,75 +1845,75 @@ PEG.grammarParser = (function(){ var savedReportMatchFailuresVar2 = context.reportMatchFailures; context.reportMatchFailures = false; if (this._input.substr(this._pos, 1) === "'") { - var result192 = "'"; + var result191 = "'"; this._pos += 1; } else { - var result192 = null; + var result191 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("'")); } } - if (result192 !== null) { - var result189 = result192; + if (result191 !== null) { + var result188 = result191; } else { if (this._input.substr(this._pos, 1) === "\\") { - var result191 = "\\"; + var result190 = "\\"; this._pos += 1; } else { - var result191 = null; + var result190 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\\")); } } - if (result191 !== null) { - var result189 = result191; + if (result190 !== null) { + var result188 = result190; } else { - var result190 = this._parse_eolChar(context); - if (result190 !== null) { - var result189 = result190; + var result189 = this._parse_eolChar(context); + if (result189 !== null) { + var result188 = result189; } else { - var result189 = null;; + var result188 = null;; }; }; } context.reportMatchFailures = savedReportMatchFailuresVar2; - if (result189 === null) { - var result187 = ''; + if (result188 === null) { + var result186 = ''; } else { - var result187 = null; + var result186 = null; this._pos = savedPos33; } - if (result187 !== null) { + if (result186 !== null) { if (this._input.length > this._pos) { - var result188 = this._input.charAt(this._pos); + var result187 = this._input.charAt(this._pos); this._pos++; } else { - var result188 = null; + var result187 = null; if (context.reportMatchFailures) { this._matchFailed('any character'); } } - if (result188 !== null) { - var result186 = [result187, result188]; + if (result187 !== null) { + var result185 = [result186, result187]; } else { - var result186 = null; + var result185 = null; this._pos = savedPos32; } } else { - var result186 = null; + var result185 = null; this._pos = savedPos32; } - var result185 = result186 !== null - ? (function($1, $2) { return $2; }).apply(null, result186) + var result184 = result185 !== null + ? (function($1, $2) { return $2; }).apply(null, result185) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result185 + result: result184 }; - return result185; + return result184; }, _parse_class: function(context) { @@ -1933,101 +1930,113 @@ PEG.grammarParser = (function(){ context.reportMatchFailures = false; var savedPos34 = this._pos; if (this._input.substr(this._pos, 1) === "[") { - var result195 = "["; + var result194 = "["; this._pos += 1; } else { - var result195 = null; + var result194 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("[")); } } - if (result195 !== null) { + if (result194 !== null) { if (this._input.substr(this._pos, 1) === "^") { - var result203 = "^"; + var result202 = "^"; this._pos += 1; } else { - var result203 = null; + var result202 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("^")); } } - var result196 = result203 !== null ? result203 : ''; - if (result196 !== null) { - var result197 = []; - var result202 = this._parse_classCharacterRange(context); - if (result202 !== null) { - var result200 = result202; + var result195 = result202 !== null ? result202 : ''; + if (result195 !== null) { + var result196 = []; + var result201 = this._parse_classCharacterRange(context); + if (result201 !== null) { + var result199 = result201; } else { - var result201 = this._parse_classCharacter(context); - if (result201 !== null) { - var result200 = result201; + var result200 = this._parse_classCharacter(context); + if (result200 !== null) { + var result199 = result200; } else { - var result200 = null;; + var result199 = null;; }; } - while (result200 !== null) { - result197.push(result200); - var result202 = this._parse_classCharacterRange(context); - if (result202 !== null) { - var result200 = result202; + while (result199 !== null) { + result196.push(result199); + var result201 = this._parse_classCharacterRange(context); + if (result201 !== null) { + var result199 = result201; } else { - var result201 = this._parse_classCharacter(context); - if (result201 !== null) { - var result200 = result201; + var result200 = this._parse_classCharacter(context); + if (result200 !== null) { + var result199 = result200; } else { - var result200 = null;; + var result199 = null;; }; } } - if (result197 !== null) { + if (result196 !== null) { if (this._input.substr(this._pos, 1) === "]") { - var result198 = "]"; + var result197 = "]"; this._pos += 1; } else { - var result198 = null; + var result197 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("]")); } } - if (result198 !== null) { - var result199 = this._parse___(context); - if (result199 !== null) { - var result194 = [result195, result196, result197, result198, result199]; + if (result197 !== null) { + var result198 = this._parse___(context); + if (result198 !== null) { + var result193 = [result194, result195, result196, result197, result198]; } else { - var result194 = null; + var result193 = null; this._pos = savedPos34; } } else { - var result194 = null; + var result193 = null; this._pos = savedPos34; } } else { - var result194 = null; + var result193 = null; this._pos = savedPos34; } } else { - var result194 = null; + var result193 = null; this._pos = savedPos34; } } else { - var result194 = null; + var result193 = null; this._pos = savedPos34; } - var result193 = result194 !== null + var result192 = result193 !== null ? (function($1, $2, $3, $4, $5) { - return $2 + $3.join(""); - }).apply(null, result194) + parts = PEG.ArrayUtils.map($3, function(part) { return part.data; }); + rawText = "[" + + $2 + + PEG.ArrayUtils.map($3, function(part) { return part.rawText; }).join("") + + "]"; + + return { + type: "class", + inverted: $2 === "^", + parts: parts, + // FIXME: Get the raw text from the input directly. + rawText: rawText + }; + }).apply(null, result193) : null; context.reportMatchFailures = savedReportMatchFailures; - if (context.reportMatchFailures && result193 === null) { + if (context.reportMatchFailures && result192 === null) { this._matchFailed("character class"); } this._cache[cacheKey] = { nextPos: this._pos, - result: result193 + result: result192 }; - return result193; + return result192; }, _parse_classCharacterRange: function(context) { @@ -2042,58 +2051,56 @@ PEG.grammarParser = (function(){ var savedPos35 = this._pos; - var result206 = this._parse_bracketDelimitedCharacter(context); - if (result206 !== null) { + var result205 = this._parse_classCharacter(context); + if (result205 !== null) { if (this._input.substr(this._pos, 1) === "-") { - var result207 = "-"; + var result206 = "-"; this._pos += 1; } else { - var result207 = null; + var result206 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("-")); } } - if (result207 !== null) { - var result208 = this._parse_bracketDelimitedCharacter(context); - if (result208 !== null) { - var result205 = [result206, result207, result208]; + if (result206 !== null) { + var result207 = this._parse_classCharacter(context); + if (result207 !== null) { + var result204 = [result205, result206, result207]; } else { - var result205 = null; + var result204 = null; this._pos = savedPos35; } } else { - var result205 = null; + var result204 = null; this._pos = savedPos35; } } else { - var result205 = null; + var result204 = null; this._pos = savedPos35; } - var result204 = result205 !== null + var result203 = result204 !== null ? (function($1, $2, $3) { - if ($1.charCodeAt(0) > $3.charCodeAt(0)) { + if ($1.data.charCodeAt(0) > $3.data.charCodeAt(0)) { throw new this.SyntaxError( - "Invalid character range: " - + PEG.RegExpUtils.quoteForClass($1) - + "-" - + PEG.RegExpUtils.quoteForClass($3) - + "." + "Invalid character range: " + $1.rawText + "-" + $2.rawText + "." ); } - return PEG.RegExpUtils.quoteForClass($1) - + "-" - + PEG.RegExpUtils.quoteForClass($3); - }).apply(null, result205) + return { + data: [$1.data, $3.data], + // FIXME: Get the raw text from the input directly. + rawText: $1.rawText + "-" + $3.rawText + } + }).apply(null, result204) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result204 + result: result203 }; - return result204; + return result203; }, _parse_classCharacter: function(context) { @@ -2107,20 +2114,24 @@ PEG.grammarParser = (function(){ var pos = this._pos; - var result210 = this._parse_bracketDelimitedCharacter(context); - var result209 = result210 !== null + var result209 = this._parse_bracketDelimitedCharacter(context); + var result208 = result209 !== null ? (function($1) { - return PEG.RegExpUtils.quoteForClass($1); - })(result210) + return { + data: $1, + // FIXME: Get the raw text from the input directly. + rawText: PEG.RegExpUtils.quoteForClass($1) + }; + })(result209) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result209 + result: result208 }; - return result209; + return result208; }, _parse_bracketDelimitedCharacter: function(context) { @@ -2134,31 +2145,31 @@ PEG.grammarParser = (function(){ var pos = this._pos; - var result217 = this._parse_simpleBracketDelimitedCharacter(context); - if (result217 !== null) { - var result211 = result217; + var result216 = this._parse_simpleBracketDelimitedCharacter(context); + if (result216 !== null) { + var result210 = result216; } else { - var result216 = this._parse_simpleEscapeSequence(context); - if (result216 !== null) { - var result211 = result216; + var result215 = this._parse_simpleEscapeSequence(context); + if (result215 !== null) { + var result210 = result215; } else { - var result215 = this._parse_zeroEscapeSequence(context); - if (result215 !== null) { - var result211 = result215; + var result214 = this._parse_zeroEscapeSequence(context); + if (result214 !== null) { + var result210 = result214; } else { - var result214 = this._parse_hexEscapeSequence(context); - if (result214 !== null) { - var result211 = result214; + var result213 = this._parse_hexEscapeSequence(context); + if (result213 !== null) { + var result210 = result213; } else { - var result213 = this._parse_unicodeEscapeSequence(context); - if (result213 !== null) { - var result211 = result213; + var result212 = this._parse_unicodeEscapeSequence(context); + if (result212 !== null) { + var result210 = result212; } else { - var result212 = this._parse_eolEscapeSequence(context); - if (result212 !== null) { - var result211 = result212; + var result211 = this._parse_eolEscapeSequence(context); + if (result211 !== null) { + var result210 = result211; } else { - var result211 = null;; + var result210 = null;; }; }; }; @@ -2170,9 +2181,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result211 + result: result210 }; - return result211; + return result210; }, _parse_simpleBracketDelimitedCharacter: function(context) { @@ -2191,75 +2202,75 @@ PEG.grammarParser = (function(){ var savedReportMatchFailuresVar3 = context.reportMatchFailures; context.reportMatchFailures = false; if (this._input.substr(this._pos, 1) === "]") { - var result225 = "]"; + var result224 = "]"; this._pos += 1; } else { - var result225 = null; + var result224 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("]")); } } - if (result225 !== null) { - var result222 = result225; + if (result224 !== null) { + var result221 = result224; } else { if (this._input.substr(this._pos, 1) === "\\") { - var result224 = "\\"; + var result223 = "\\"; this._pos += 1; } else { - var result224 = null; + var result223 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\\")); } } - if (result224 !== null) { - var result222 = result224; + if (result223 !== null) { + var result221 = result223; } else { - var result223 = this._parse_eolChar(context); - if (result223 !== null) { - var result222 = result223; + var result222 = this._parse_eolChar(context); + if (result222 !== null) { + var result221 = result222; } else { - var result222 = null;; + var result221 = null;; }; }; } context.reportMatchFailures = savedReportMatchFailuresVar3; - if (result222 === null) { - var result220 = ''; + if (result221 === null) { + var result219 = ''; } else { - var result220 = null; + var result219 = null; this._pos = savedPos37; } - if (result220 !== null) { + if (result219 !== null) { if (this._input.length > this._pos) { - var result221 = this._input.charAt(this._pos); + var result220 = this._input.charAt(this._pos); this._pos++; } else { - var result221 = null; + var result220 = null; if (context.reportMatchFailures) { this._matchFailed('any character'); } } - if (result221 !== null) { - var result219 = [result220, result221]; + if (result220 !== null) { + var result218 = [result219, result220]; } else { - var result219 = null; + var result218 = null; this._pos = savedPos36; } } else { - var result219 = null; + var result218 = null; this._pos = savedPos36; } - var result218 = result219 !== null - ? (function($1, $2) { return $2; }).apply(null, result219) + var result217 = result218 !== null + ? (function($1, $2) { return $2; }).apply(null, result218) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result218 + result: result217 }; - return result218; + return result217; }, _parse_simpleEscapeSequence: function(context) { @@ -2275,87 +2286,87 @@ PEG.grammarParser = (function(){ var savedPos38 = this._pos; if (this._input.substr(this._pos, 1) === "\\") { - var result228 = "\\"; + var result227 = "\\"; this._pos += 1; } else { - var result228 = null; + var result227 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\\")); } } - if (result228 !== null) { + if (result227 !== null) { var savedPos39 = this._pos; var savedReportMatchFailuresVar4 = context.reportMatchFailures; context.reportMatchFailures = false; - var result235 = this._parse_digit(context); - if (result235 !== null) { - var result231 = result235; + var result234 = this._parse_digit(context); + if (result234 !== null) { + var result230 = result234; } else { if (this._input.substr(this._pos, 1) === "x") { - var result234 = "x"; + var result233 = "x"; this._pos += 1; } else { - var result234 = null; + var result233 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("x")); } } - if (result234 !== null) { - var result231 = result234; + if (result233 !== null) { + var result230 = result233; } else { if (this._input.substr(this._pos, 1) === "u") { - var result233 = "u"; + var result232 = "u"; this._pos += 1; } else { - var result233 = null; + var result232 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("u")); } } - if (result233 !== null) { - var result231 = result233; + if (result232 !== null) { + var result230 = result232; } else { - var result232 = this._parse_eolChar(context); - if (result232 !== null) { - var result231 = result232; + var result231 = this._parse_eolChar(context); + if (result231 !== null) { + var result230 = result231; } else { - var result231 = null;; + var result230 = null;; }; }; }; } context.reportMatchFailures = savedReportMatchFailuresVar4; - if (result231 === null) { - var result229 = ''; + if (result230 === null) { + var result228 = ''; } else { - var result229 = null; + var result228 = null; this._pos = savedPos39; } - if (result229 !== null) { + if (result228 !== null) { if (this._input.length > this._pos) { - var result230 = this._input.charAt(this._pos); + var result229 = this._input.charAt(this._pos); this._pos++; } else { - var result230 = null; + var result229 = null; if (context.reportMatchFailures) { this._matchFailed('any character'); } } - if (result230 !== null) { - var result227 = [result228, result229, result230]; + if (result229 !== null) { + var result226 = [result227, result228, result229]; } else { - var result227 = null; + var result226 = null; this._pos = savedPos38; } } else { - var result227 = null; + var result226 = null; this._pos = savedPos38; } } else { - var result227 = null; + var result226 = null; this._pos = savedPos38; } - var result226 = result227 !== null + var result225 = result226 !== null ? (function($1, $2, $3) { return $3 .replace("b", "\b") @@ -2364,16 +2375,16 @@ PEG.grammarParser = (function(){ .replace("r", "\r") .replace("t", "\t") .replace("v", "\x0B") // IE does not recognize "\v". - }).apply(null, result227) + }).apply(null, result226) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result226 + result: result225 }; - return result226; + return result225; }, _parse_zeroEscapeSequence: function(context) { @@ -2389,47 +2400,47 @@ PEG.grammarParser = (function(){ var savedPos40 = this._pos; if (this._input.substr(this._pos, 2) === "\\0") { - var result238 = "\\0"; + var result237 = "\\0"; this._pos += 2; } else { - var result238 = null; + var result237 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\\0")); } } - if (result238 !== null) { + if (result237 !== null) { var savedPos41 = this._pos; var savedReportMatchFailuresVar5 = context.reportMatchFailures; context.reportMatchFailures = false; - var result240 = this._parse_digit(context); + var result239 = this._parse_digit(context); context.reportMatchFailures = savedReportMatchFailuresVar5; - if (result240 === null) { - var result239 = ''; + if (result239 === null) { + var result238 = ''; } else { - var result239 = null; + var result238 = null; this._pos = savedPos41; } - if (result239 !== null) { - var result237 = [result238, result239]; + if (result238 !== null) { + var result236 = [result237, result238]; } else { - var result237 = null; + var result236 = null; this._pos = savedPos40; } } else { - var result237 = null; + var result236 = null; this._pos = savedPos40; } - var result236 = result237 !== null - ? (function($1, $2) { return "\0"; }).apply(null, result237) + var result235 = result236 !== null + ? (function($1, $2) { return "\0"; }).apply(null, result236) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result236 + result: result235 }; - return result236; + return result235; }, _parse_hexEscapeSequence: function(context) { @@ -2445,45 +2456,45 @@ PEG.grammarParser = (function(){ var savedPos42 = this._pos; if (this._input.substr(this._pos, 2) === "\\x") { - var result243 = "\\x"; + var result242 = "\\x"; this._pos += 2; } else { - var result243 = null; + var result242 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\\x")); } } - if (result243 !== null) { - var result244 = this._parse_hexDigit(context); - if (result244 !== null) { - var result245 = this._parse_hexDigit(context); - if (result245 !== null) { - var result242 = [result243, result244, result245]; + if (result242 !== null) { + var result243 = this._parse_hexDigit(context); + if (result243 !== null) { + var result244 = this._parse_hexDigit(context); + if (result244 !== null) { + var result241 = [result242, result243, result244]; } else { - var result242 = null; + var result241 = null; this._pos = savedPos42; } } else { - var result242 = null; + var result241 = null; this._pos = savedPos42; } } else { - var result242 = null; + var result241 = null; this._pos = savedPos42; } - var result241 = result242 !== null + var result240 = result241 !== null ? (function($1, $2, $3) { return String.fromCharCode(parseInt("0x" + $2 + $3)); - }).apply(null, result242) + }).apply(null, result241) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result241 + result: result240 }; - return result241; + return result240; }, _parse_unicodeEscapeSequence: function(context) { @@ -2499,57 +2510,57 @@ PEG.grammarParser = (function(){ var savedPos43 = this._pos; if (this._input.substr(this._pos, 2) === "\\u") { - var result248 = "\\u"; + var result247 = "\\u"; this._pos += 2; } else { - var result248 = null; + var result247 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\\u")); } } - if (result248 !== null) { - var result249 = this._parse_hexDigit(context); - if (result249 !== null) { - var result250 = this._parse_hexDigit(context); - if (result250 !== null) { - var result251 = this._parse_hexDigit(context); - if (result251 !== null) { - var result252 = this._parse_hexDigit(context); - if (result252 !== null) { - var result247 = [result248, result249, result250, result251, result252]; + if (result247 !== null) { + var result248 = this._parse_hexDigit(context); + if (result248 !== null) { + var result249 = this._parse_hexDigit(context); + if (result249 !== null) { + var result250 = this._parse_hexDigit(context); + if (result250 !== null) { + var result251 = this._parse_hexDigit(context); + if (result251 !== null) { + var result246 = [result247, result248, result249, result250, result251]; } else { - var result247 = null; + var result246 = null; this._pos = savedPos43; } } else { - var result247 = null; + var result246 = null; this._pos = savedPos43; } } else { - var result247 = null; + var result246 = null; this._pos = savedPos43; } } else { - var result247 = null; + var result246 = null; this._pos = savedPos43; } } else { - var result247 = null; + var result246 = null; this._pos = savedPos43; } - var result246 = result247 !== null + var result245 = result246 !== null ? (function($1, $2, $3, $4, $5) { return String.fromCharCode(parseInt("0x" + $2 + $3 + $4 + $5)); - }).apply(null, result247) + }).apply(null, result246) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result246 + result: result245 }; - return result246; + return result245; }, _parse_eolEscapeSequence: function(context) { @@ -2565,37 +2576,37 @@ PEG.grammarParser = (function(){ var savedPos44 = this._pos; if (this._input.substr(this._pos, 1) === "\\") { - var result255 = "\\"; + var result254 = "\\"; this._pos += 1; } else { - var result255 = null; + var result254 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\\")); } } - if (result255 !== null) { - var result256 = this._parse_eol(context); - if (result256 !== null) { - var result254 = [result255, result256]; + if (result254 !== null) { + var result255 = this._parse_eol(context); + if (result255 !== null) { + var result253 = [result254, result255]; } else { - var result254 = null; + var result253 = null; this._pos = savedPos44; } } else { - var result254 = null; + var result253 = null; this._pos = savedPos44; } - var result253 = result254 !== null - ? (function($1, $2) { return $2; }).apply(null, result254) + var result252 = result253 !== null + ? (function($1, $2) { return $2; }).apply(null, result253) : null; this._cache[cacheKey] = { nextPos: this._pos, - result: result253 + result: result252 }; - return result253; + return result252; }, _parse_digit: function(context) { @@ -2610,12 +2621,12 @@ PEG.grammarParser = (function(){ if (this._input.substr(this._pos).match(/^[0-9]/) !== null) { - var result257 = this._input.charAt(this._pos); + var result256 = this._input.charAt(this._pos); this._pos++; } else { - var result257 = null; + var result256 = null; if (context.reportMatchFailures) { - this._matchFailed('[' + "0-9" + ']'); + this._matchFailed("[0-9]"); } } @@ -2623,9 +2634,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result257 + result: result256 }; - return result257; + return result256; }, _parse_hexDigit: function(context) { @@ -2640,12 +2651,12 @@ PEG.grammarParser = (function(){ if (this._input.substr(this._pos).match(/^[0-9a-fA-F]/) !== null) { - var result258 = this._input.charAt(this._pos); + var result257 = this._input.charAt(this._pos); this._pos++; } else { - var result258 = null; + var result257 = null; if (context.reportMatchFailures) { - this._matchFailed('[' + "0-9a-fA-F" + ']'); + this._matchFailed("[0-9a-fA-F]"); } } @@ -2653,9 +2664,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result258 + result: result257 }; - return result258; + return result257; }, _parse_letter: function(context) { @@ -2669,15 +2680,15 @@ PEG.grammarParser = (function(){ var pos = this._pos; - var result261 = this._parse_lowerCaseLetter(context); - if (result261 !== null) { - var result259 = result261; + var result260 = this._parse_lowerCaseLetter(context); + if (result260 !== null) { + var result258 = result260; } else { - var result260 = this._parse_upperCaseLetter(context); - if (result260 !== null) { - var result259 = result260; + var result259 = this._parse_upperCaseLetter(context); + if (result259 !== null) { + var result258 = result259; } else { - var result259 = null;; + var result258 = null;; }; } @@ -2685,9 +2696,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result259 + result: result258 }; - return result259; + return result258; }, _parse_lowerCaseLetter: function(context) { @@ -2702,12 +2713,12 @@ PEG.grammarParser = (function(){ if (this._input.substr(this._pos).match(/^[a-z]/) !== null) { - var result262 = this._input.charAt(this._pos); + var result261 = this._input.charAt(this._pos); this._pos++; } else { - var result262 = null; + var result261 = null; if (context.reportMatchFailures) { - this._matchFailed('[' + "a-z" + ']'); + this._matchFailed("[a-z]"); } } @@ -2715,9 +2726,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result262 + result: result261 }; - return result262; + return result261; }, _parse_upperCaseLetter: function(context) { @@ -2732,12 +2743,12 @@ PEG.grammarParser = (function(){ if (this._input.substr(this._pos).match(/^[A-Z]/) !== null) { - var result263 = this._input.charAt(this._pos); + var result262 = this._input.charAt(this._pos); this._pos++; } else { - var result263 = null; + var result262 = null; if (context.reportMatchFailures) { - this._matchFailed('[' + "A-Z" + ']'); + this._matchFailed("[A-Z]"); } } @@ -2745,9 +2756,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result263 + result: result262 }; - return result263; + return result262; }, _parse___: function(context) { @@ -2761,38 +2772,38 @@ PEG.grammarParser = (function(){ var pos = this._pos; - var result264 = []; - var result268 = this._parse_whitespace(context); - if (result268 !== null) { - var result265 = result268; + var result263 = []; + var result267 = this._parse_whitespace(context); + if (result267 !== null) { + var result264 = result267; } else { - var result267 = this._parse_eol(context); - if (result267 !== null) { - var result265 = result267; + var result266 = this._parse_eol(context); + if (result266 !== null) { + var result264 = result266; } else { - var result266 = this._parse_comment(context); - if (result266 !== null) { - var result265 = result266; + var result265 = this._parse_comment(context); + if (result265 !== null) { + var result264 = result265; } else { - var result265 = null;; + var result264 = null;; }; }; } - while (result265 !== null) { - result264.push(result265); - var result268 = this._parse_whitespace(context); - if (result268 !== null) { - var result265 = result268; + while (result264 !== null) { + result263.push(result264); + var result267 = this._parse_whitespace(context); + if (result267 !== null) { + var result264 = result267; } else { - var result267 = this._parse_eol(context); - if (result267 !== null) { - var result265 = result267; + var result266 = this._parse_eol(context); + if (result266 !== null) { + var result264 = result266; } else { - var result266 = this._parse_comment(context); - if (result266 !== null) { - var result265 = result266; + var result265 = this._parse_comment(context); + if (result265 !== null) { + var result264 = result265; } else { - var result265 = null;; + var result264 = null;; }; }; } @@ -2802,9 +2813,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result264 + result: result263 }; - return result264; + return result263; }, _parse_comment: function(context) { @@ -2819,27 +2830,27 @@ PEG.grammarParser = (function(){ var savedReportMatchFailures = context.reportMatchFailures; context.reportMatchFailures = false; - var result271 = this._parse_singleLineComment(context); - if (result271 !== null) { - var result269 = result271; + var result270 = this._parse_singleLineComment(context); + if (result270 !== null) { + var result268 = result270; } else { - var result270 = this._parse_multiLineComment(context); - if (result270 !== null) { - var result269 = result270; + var result269 = this._parse_multiLineComment(context); + if (result269 !== null) { + var result268 = result269; } else { - var result269 = null;; + var result268 = null;; }; } context.reportMatchFailures = savedReportMatchFailures; - if (context.reportMatchFailures && result269 === null) { + if (context.reportMatchFailures && result268 === null) { this._matchFailed("comment"); } this._cache[cacheKey] = { nextPos: this._pos, - result: result269 + result: result268 }; - return result269; + return result268; }, _parse_singleLineComment: function(context) { @@ -2855,91 +2866,91 @@ PEG.grammarParser = (function(){ var savedPos45 = this._pos; if (this._input.substr(this._pos, 2) === "//") { - var result273 = "//"; + var result272 = "//"; this._pos += 2; } else { - var result273 = null; + var result272 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("//")); } } - if (result273 !== null) { - var result274 = []; + if (result272 !== null) { + var result273 = []; var savedPos46 = this._pos; var savedPos47 = this._pos; var savedReportMatchFailuresVar6 = context.reportMatchFailures; context.reportMatchFailures = false; - var result278 = this._parse_eolChar(context); + var result277 = this._parse_eolChar(context); context.reportMatchFailures = savedReportMatchFailuresVar6; - if (result278 === null) { - var result276 = ''; + if (result277 === null) { + var result275 = ''; } else { - var result276 = null; + var result275 = null; this._pos = savedPos47; } - if (result276 !== null) { + if (result275 !== null) { if (this._input.length > this._pos) { - var result277 = this._input.charAt(this._pos); + var result276 = this._input.charAt(this._pos); this._pos++; } else { - var result277 = null; + var result276 = null; if (context.reportMatchFailures) { this._matchFailed('any character'); } } - if (result277 !== null) { - var result275 = [result276, result277]; + if (result276 !== null) { + var result274 = [result275, result276]; } else { - var result275 = null; + var result274 = null; this._pos = savedPos46; } } else { - var result275 = null; + var result274 = null; this._pos = savedPos46; } - while (result275 !== null) { - result274.push(result275); + while (result274 !== null) { + result273.push(result274); var savedPos46 = this._pos; var savedPos47 = this._pos; var savedReportMatchFailuresVar6 = context.reportMatchFailures; context.reportMatchFailures = false; - var result278 = this._parse_eolChar(context); + var result277 = this._parse_eolChar(context); context.reportMatchFailures = savedReportMatchFailuresVar6; - if (result278 === null) { - var result276 = ''; + if (result277 === null) { + var result275 = ''; } else { - var result276 = null; + var result275 = null; this._pos = savedPos47; } - if (result276 !== null) { + if (result275 !== null) { if (this._input.length > this._pos) { - var result277 = this._input.charAt(this._pos); + var result276 = this._input.charAt(this._pos); this._pos++; } else { - var result277 = null; + var result276 = null; if (context.reportMatchFailures) { this._matchFailed('any character'); } } - if (result277 !== null) { - var result275 = [result276, result277]; + if (result276 !== null) { + var result274 = [result275, result276]; } else { - var result275 = null; + var result274 = null; this._pos = savedPos46; } } else { - var result275 = null; + var result274 = null; this._pos = savedPos46; } } - if (result274 !== null) { - var result272 = [result273, result274]; + if (result273 !== null) { + var result271 = [result272, result273]; } else { - var result272 = null; + var result271 = null; this._pos = savedPos45; } } else { - var result272 = null; + var result271 = null; this._pos = savedPos45; } @@ -2947,9 +2958,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result272 + result: result271 }; - return result272; + return result271; }, _parse_multiLineComment: function(context) { @@ -2965,121 +2976,121 @@ PEG.grammarParser = (function(){ var savedPos48 = this._pos; if (this._input.substr(this._pos, 2) === "/*") { - var result280 = "/*"; + var result279 = "/*"; this._pos += 2; } else { - var result280 = null; + var result279 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("/*")); } } - if (result280 !== null) { - var result281 = []; + if (result279 !== null) { + var result280 = []; var savedPos49 = this._pos; var savedPos50 = this._pos; var savedReportMatchFailuresVar7 = context.reportMatchFailures; context.reportMatchFailures = false; if (this._input.substr(this._pos, 2) === "*/") { - var result286 = "*/"; + var result285 = "*/"; this._pos += 2; } else { - var result286 = null; + var result285 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("*/")); } } context.reportMatchFailures = savedReportMatchFailuresVar7; - if (result286 === null) { - var result284 = ''; + if (result285 === null) { + var result283 = ''; } else { - var result284 = null; + var result283 = null; this._pos = savedPos50; } - if (result284 !== null) { + if (result283 !== null) { if (this._input.length > this._pos) { - var result285 = this._input.charAt(this._pos); + var result284 = this._input.charAt(this._pos); this._pos++; } else { - var result285 = null; + var result284 = null; if (context.reportMatchFailures) { this._matchFailed('any character'); } } - if (result285 !== null) { - var result283 = [result284, result285]; + if (result284 !== null) { + var result282 = [result283, result284]; } else { - var result283 = null; + var result282 = null; this._pos = savedPos49; } } else { - var result283 = null; + var result282 = null; this._pos = savedPos49; } - while (result283 !== null) { - result281.push(result283); + while (result282 !== null) { + result280.push(result282); var savedPos49 = this._pos; var savedPos50 = this._pos; var savedReportMatchFailuresVar7 = context.reportMatchFailures; context.reportMatchFailures = false; if (this._input.substr(this._pos, 2) === "*/") { - var result286 = "*/"; + var result285 = "*/"; this._pos += 2; } else { - var result286 = null; + var result285 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("*/")); } } context.reportMatchFailures = savedReportMatchFailuresVar7; - if (result286 === null) { - var result284 = ''; + if (result285 === null) { + var result283 = ''; } else { - var result284 = null; + var result283 = null; this._pos = savedPos50; } - if (result284 !== null) { + if (result283 !== null) { if (this._input.length > this._pos) { - var result285 = this._input.charAt(this._pos); + var result284 = this._input.charAt(this._pos); this._pos++; } else { - var result285 = null; + var result284 = null; if (context.reportMatchFailures) { this._matchFailed('any character'); } } - if (result285 !== null) { - var result283 = [result284, result285]; + if (result284 !== null) { + var result282 = [result283, result284]; } else { - var result283 = null; + var result282 = null; this._pos = savedPos49; } } else { - var result283 = null; + var result282 = null; this._pos = savedPos49; } } - if (result281 !== null) { + if (result280 !== null) { if (this._input.substr(this._pos, 2) === "*/") { - var result282 = "*/"; + var result281 = "*/"; this._pos += 2; } else { - var result282 = null; + var result281 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("*/")); } } - if (result282 !== null) { - var result279 = [result280, result281, result282]; + if (result281 !== null) { + var result278 = [result279, result280, result281]; } else { - var result279 = null; + var result278 = null; this._pos = savedPos48; } } else { - var result279 = null; + var result278 = null; this._pos = savedPos48; } } else { - var result279 = null; + var result278 = null; this._pos = savedPos48; } @@ -3087,9 +3098,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result279 + result: result278 }; - return result279; + return result278; }, _parse_eol: function(context) { @@ -3105,81 +3116,81 @@ PEG.grammarParser = (function(){ var savedReportMatchFailures = context.reportMatchFailures; context.reportMatchFailures = false; if (this._input.substr(this._pos, 1) === "\n") { - var result292 = "\n"; + var result291 = "\n"; this._pos += 1; } else { - var result292 = null; + var result291 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\n")); } } - if (result292 !== null) { - var result287 = result292; + if (result291 !== null) { + var result286 = result291; } else { if (this._input.substr(this._pos, 2) === "\r\n") { - var result291 = "\r\n"; + var result290 = "\r\n"; this._pos += 2; } else { - var result291 = null; + var result290 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\r\n")); } } - if (result291 !== null) { - var result287 = result291; + if (result290 !== null) { + var result286 = result290; } else { if (this._input.substr(this._pos, 1) === "\r") { - var result290 = "\r"; + var result289 = "\r"; this._pos += 1; } else { - var result290 = null; + var result289 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\r")); } } - if (result290 !== null) { - var result287 = result290; + if (result289 !== null) { + var result286 = result289; } else { if (this._input.substr(this._pos, 1) === "\u2028") { - var result289 = "\u2028"; + var result288 = "\u2028"; this._pos += 1; } else { - var result289 = null; + var result288 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\u2028")); } } - if (result289 !== null) { - var result287 = result289; + if (result288 !== null) { + var result286 = result288; } else { if (this._input.substr(this._pos, 1) === "\u2029") { - var result288 = "\u2029"; + var result287 = "\u2029"; this._pos += 1; } else { - var result288 = null; + var result287 = null; if (context.reportMatchFailures) { this._matchFailed(this._quoteString("\u2029")); } } - if (result288 !== null) { - var result287 = result288; + if (result287 !== null) { + var result286 = result287; } else { - var result287 = null;; + var result286 = null;; }; }; }; }; } context.reportMatchFailures = savedReportMatchFailures; - if (context.reportMatchFailures && result287 === null) { + if (context.reportMatchFailures && result286 === null) { this._matchFailed("end of line"); } this._cache[cacheKey] = { nextPos: this._pos, - result: result287 + result: result286 }; - return result287; + return result286; }, _parse_eolChar: function(context) { @@ -3194,12 +3205,12 @@ PEG.grammarParser = (function(){ if (this._input.substr(this._pos).match(/^[\n\r\u2028\u2029]/) !== null) { - var result293 = this._input.charAt(this._pos); + var result292 = this._input.charAt(this._pos); this._pos++; } else { - var result293 = null; + var result292 = null; if (context.reportMatchFailures) { - this._matchFailed('[' + "\\n\\r\\u2028\\u2029" + ']'); + this._matchFailed("[\\n\\r\\u2028\\u2029]"); } } @@ -3207,9 +3218,9 @@ PEG.grammarParser = (function(){ this._cache[cacheKey] = { nextPos: this._pos, - result: result293 + result: result292 }; - return result293; + return result292; }, _parse_whitespace: function(context) { @@ -3225,24 +3236,24 @@ PEG.grammarParser = (function(){ var savedReportMatchFailures = context.reportMatchFailures; context.reportMatchFailures = false; if (this._input.substr(this._pos).match(/^[   ᠎ -    ]/) !== null) { - var result294 = this._input.charAt(this._pos); + var result293 = this._input.charAt(this._pos); this._pos++; } else { - var result294 = null; + var result293 = null; if (context.reportMatchFailures) { - this._matchFailed('[' + "   ᠎ -    " + ']'); + this._matchFailed("[   ᠎ -    ]"); } } context.reportMatchFailures = savedReportMatchFailures; - if (context.reportMatchFailures && result294 === null) { + if (context.reportMatchFailures && result293 === null) { this._matchFailed("whitespace"); } this._cache[cacheKey] = { nextPos: this._pos, - result: result294 + result: result293 }; - return result294; + return result293; }, /* diff --git a/lib/metagrammar.pegjs b/lib/metagrammar.pegjs index 6fb251e..35d438b 100644 --- a/lib/metagrammar.pegjs +++ b/lib/metagrammar.pegjs @@ -68,7 +68,7 @@ primary : identifier !(( literal / "") colon) { return { type: "rule_ref", name: $1 }; } / literal { return { type: "literal", value: $1 }; } / dot { return { type: "any" }; } - / class { return { type: "class", chars: $1 }; } + / class / lparen expression rparen { return $2; } /* "Lexical" elements */ @@ -142,27 +142,41 @@ singleQuotedCharacter simpleSingleQuotedCharacter: !("'" / "\\" / eolChar) . { return $2; } class "character class": "[" "^"? (classCharacterRange / classCharacter)* "]" __ { - return $2 + $3.join(""); + parts = PEG.ArrayUtils.map($3, function(part) { return part.data; }); + rawText = "[" + + $2 + + PEG.ArrayUtils.map($3, function(part) { return part.rawText; }).join("") + + "]"; + + return { + type: "class", + inverted: $2 === "^", + parts: parts, + // FIXME: Get the raw text from the input directly. + rawText: rawText + }; } -classCharacterRange: bracketDelimitedCharacter "-" bracketDelimitedCharacter { - if ($1.charCodeAt(0) > $3.charCodeAt(0)) { +classCharacterRange: classCharacter "-" classCharacter { + if ($1.data.charCodeAt(0) > $3.data.charCodeAt(0)) { throw new this.SyntaxError( - "Invalid character range: " - + PEG.RegExpUtils.quoteForClass($1) - + "-" - + PEG.RegExpUtils.quoteForClass($3) - + "." + "Invalid character range: " + $1.rawText + "-" + $2.rawText + "." ); } - return PEG.RegExpUtils.quoteForClass($1) - + "-" - + PEG.RegExpUtils.quoteForClass($3); + return { + data: [$1.data, $3.data], + // FIXME: Get the raw text from the input directly. + rawText: $1.rawText + "-" + $3.rawText + } } classCharacter: bracketDelimitedCharacter { - return PEG.RegExpUtils.quoteForClass($1); + return { + data: $1, + // FIXME: Get the raw text from the input directly. + rawText: PEG.RegExpUtils.quoteForClass($1) + }; } bracketDelimitedCharacter diff --git a/test/metagrammar-test.js b/test/metagrammar-test.js index 5d5b804..241cd8b 100644 --- a/test/metagrammar-test.js +++ b/test/metagrammar-test.js @@ -81,10 +81,12 @@ function any() { return { type: "any" }; } -function klass(chars) { +function klass(inverted, parts, rawText) { return { - type: "class", - chars: chars + type: "class", + inverted: inverted, + parts: parts, + rawText: rawText }; } @@ -119,8 +121,8 @@ function literalGrammar(literal) { return oneRuleGrammar(literal_(literal)); } -function classGrammar(chars) { - return oneRuleGrammar(klass(chars)); +function classGrammar(inverted, parts, rawText) { + return oneRuleGrammar(klass(inverted, parts, rawText)); } var anyGrammar = oneRuleGrammar(any()); @@ -224,7 +226,7 @@ test("parses primary", function() { grammarParserParses('start: a', identifierGrammar("a")); grammarParserParses('start: "abcd"', literalGrammar("abcd")); grammarParserParses('start: .', anyGrammar); - grammarParserParses('start: [a-d]', classGrammar("a-d")); + grammarParserParses('start: [a-d]', classGrammar(false, [["a", "d"]], "[a-d]")); grammarParserParses('start: ("abcd")', literalGrammar("abcd")); }); @@ -334,41 +336,44 @@ test("parses simpleSingleQuotedCharacter", function() { /* Canonical class is "[a-d]". */ test("parses class", function() { - grammarParserParses("start: []", classGrammar("")); - grammarParserParses("start: [a-d]", classGrammar("a-d")); - grammarParserParses("start: [^a-d]", classGrammar("^a-d")); - grammarParserParses("start: [a]", classGrammar("a")); - grammarParserParses("start: [a-de-hi-l]", classGrammar("a-de-hi-l")); + grammarParserParses("start: []", classGrammar(false, [], "[]")); + grammarParserParses("start: [a-d]", classGrammar(false, [["a", "d"]], "[a-d]")); + grammarParserParses("start: [^a-d]", classGrammar(true, [["a", "d"]], "[^a-d]")); + grammarParserParses("start: [a]", classGrammar(false, ["a"], "[a]")); + grammarParserParses( + "start: [a-de-hi-l]", + classGrammar(false, [["a", "d"], ["e", "h"], ["i", "l"]], "[a-de-hi-l]") + ); - grammarParserParses("start: [a-d]\n", classGrammar("a-d")); + grammarParserParses("start: [a-d]\n", classGrammar(false, [["a", "d"]], "[a-d"])); }); /* Canonical classCharacterRange is "a-d". */ test("parses classCharacterRange", function() { - grammarParserParses("start: [a-d]", classGrammar("a-d")); - grammarParserParses("start: [a-a]", classGrammar("a-a")); + grammarParserParses("start: [a-d]", classGrammar(false, [["a", "d"]], "[a-d]")); + grammarParserParses("start: [a-a]", classGrammar(false, [["a", "a"]], "[a-d]")); grammarParserDoesNotParse("start: [b-a]"); }); /* Canonical classCharacter is "a". */ test("parses classCharacter", function() { - grammarParserParses("start: [a]", classGrammar("a")); + grammarParserParses("start: [a]", classGrammar(false, ["a"], "[a]")); }); /* Canonical bracketDelimitedCharacter is "a". */ test("parses bracketDelimitedCharacter", function() { - grammarParserParses("start: [a]", classGrammar("a")); - grammarParserParses("start: [\\n]", classGrammar("\\n")); - grammarParserParses("start: [\\0]", classGrammar("\\0")); - grammarParserParses("start: [\\x00]", classGrammar("\\0")); - grammarParserParses("start: [\\u0120]", classGrammar("\u0120")); - grammarParserParses("start: [\\\n]", classGrammar("\\n")); + grammarParserParses("start: [a]", classGrammar(false, ["a"])); + grammarParserParses("start: [\\n]", classGrammar(false, ["\n"])); + grammarParserParses("start: [\\0]", classGrammar(false, ["\0"])); + grammarParserParses("start: [\\x00]", classGrammar(false, ["\0"])); + grammarParserParses("start: [\\u0120]", classGrammar(false, ["\u0120"])); + grammarParserParses("start: [\\\n]", classGrammar(false, ["\n"])); }); /* Canonical simpleBracketDelimiedCharacter is "a". */ test("parses simpleBracketDelimitedCharacter", function() { - grammarParserParses("start: [a]", classGrammar("a")); - grammarParserParses("start: [[]", classGrammar("[")); + grammarParserParses("start: [a]", classGrammar(false, ["a"])); + grammarParserParses("start: [[]", classGrammar(false, ["["])); grammarParserDoesNotParse("start: []]"); grammarParserDoesNotParse("start: [\\]"); grammarParserDoesNotParse("start: [\n]");