Killed *MatchFailure classes => simpler code.

redux
David Majda 15 years ago
parent f87bcd6332
commit 20e230ca0e

@ -342,7 +342,7 @@ PEG.Grammar.Rule.prototype.compile = function() {
);
var reportMatchFailureCode = PEG.Compiler.formatCode(
"if (context.reportMatchFailures && ${resultVar} === null) {",
" this._matchFailed(new PEG.Parser.NamedRuleMatchFailure(${displayName|string}));",
" this._matchFailed(${displayName|string});",
"}",
{
displayName: this._displayName,
@ -413,7 +413,7 @@ PEG.Grammar.Literal.prototype.compile = function(resultVar) {
"} else {",
" var ${resultVar} = null;",
" if (context.reportMatchFailures) {",
" this._matchFailed(new PEG.Parser.LiteralMatchFailure(${value|string}));",
" this._matchFailed(PEG.StringUtils.quote(${value|string}));",
" }",
"}",
{
@ -432,7 +432,7 @@ PEG.Grammar.Class.prototype.compile = function(resultVar) {
"} else {",
" var ${resultVar} = null;",
" if (context.reportMatchFailures) {",
" this._matchFailed(new PEG.Parser.ClassMatchFailure(${characters|string}));",
" this._matchFailed('[' + ${characters|string} + ']');",
" }",
"}",
{
@ -451,7 +451,7 @@ PEG.Grammar.Any.prototype.compile = function(resultVar) {
"} else {",
" var ${resultVar} = null;",
" if (context.reportMatchFailures) {",
" this._matchFailed(new PEG.Parser.AnyMatchFailure());",
" this._matchFailed('any character');",
" }",
"}",
{ resultVar: resultVar }

@ -92,7 +92,7 @@ PEG.grammarParser = (function(){
} else {
var result14 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure(""));
this._matchFailed(PEG.StringUtils.quote(""));
}
}
if (result14 !== null) {
@ -498,7 +498,7 @@ PEG.grammarParser = (function(){
} else {
var result76 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure(""));
this._matchFailed(PEG.StringUtils.quote(""));
}
}
if (result76 !== null) {
@ -636,7 +636,7 @@ PEG.grammarParser = (function(){
: null;
context.reportMatchFailures = savedReportMatchFailures;
if (context.reportMatchFailures && result78 === null) {
this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("action"));
this._matchFailed("action");
}
this._cache["action"][pos] = {
@ -664,7 +664,7 @@ PEG.grammarParser = (function(){
} else {
var result84 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("{"));
this._matchFailed(PEG.StringUtils.quote("{"));
}
}
if (result84 !== null) {
@ -701,7 +701,7 @@ PEG.grammarParser = (function(){
} else {
var result86 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("}"));
this._matchFailed(PEG.StringUtils.quote("}"));
}
}
if (result86 !== null) {
@ -798,7 +798,7 @@ PEG.grammarParser = (function(){
} else {
var result97 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.ClassMatchFailure("^{}"));
this._matchFailed('[' + "^{}" + ']');
}
}
var result96 = result97 !== null
@ -832,7 +832,7 @@ PEG.grammarParser = (function(){
} else {
var result100 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure(":"));
this._matchFailed(PEG.StringUtils.quote(":"));
}
}
if (result100 !== null) {
@ -878,7 +878,7 @@ PEG.grammarParser = (function(){
} else {
var result104 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("/"));
this._matchFailed(PEG.StringUtils.quote("/"));
}
}
if (result104 !== null) {
@ -924,7 +924,7 @@ PEG.grammarParser = (function(){
} else {
var result108 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("&"));
this._matchFailed(PEG.StringUtils.quote("&"));
}
}
if (result108 !== null) {
@ -970,7 +970,7 @@ PEG.grammarParser = (function(){
} else {
var result112 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("!"));
this._matchFailed(PEG.StringUtils.quote("!"));
}
}
if (result112 !== null) {
@ -1016,7 +1016,7 @@ PEG.grammarParser = (function(){
} else {
var result116 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("?"));
this._matchFailed(PEG.StringUtils.quote("?"));
}
}
if (result116 !== null) {
@ -1062,7 +1062,7 @@ PEG.grammarParser = (function(){
} else {
var result120 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("*"));
this._matchFailed(PEG.StringUtils.quote("*"));
}
}
if (result120 !== null) {
@ -1108,7 +1108,7 @@ PEG.grammarParser = (function(){
} else {
var result124 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("+"));
this._matchFailed(PEG.StringUtils.quote("+"));
}
}
if (result124 !== null) {
@ -1154,7 +1154,7 @@ PEG.grammarParser = (function(){
} else {
var result128 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("("));
this._matchFailed(PEG.StringUtils.quote("("));
}
}
if (result128 !== null) {
@ -1200,7 +1200,7 @@ PEG.grammarParser = (function(){
} else {
var result132 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure(")"));
this._matchFailed(PEG.StringUtils.quote(")"));
}
}
if (result132 !== null) {
@ -1246,7 +1246,7 @@ PEG.grammarParser = (function(){
} else {
var result136 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("."));
this._matchFailed(PEG.StringUtils.quote("."));
}
}
if (result136 !== null) {
@ -1297,7 +1297,7 @@ PEG.grammarParser = (function(){
} else {
var result149 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("_"));
this._matchFailed(PEG.StringUtils.quote("_"));
}
}
if (result149 !== null) {
@ -1309,7 +1309,7 @@ PEG.grammarParser = (function(){
} else {
var result148 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("$"));
this._matchFailed(PEG.StringUtils.quote("$"));
}
}
if (result148 !== null) {
@ -1335,7 +1335,7 @@ PEG.grammarParser = (function(){
} else {
var result145 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("_"));
this._matchFailed(PEG.StringUtils.quote("_"));
}
}
if (result145 !== null) {
@ -1347,7 +1347,7 @@ PEG.grammarParser = (function(){
} else {
var result144 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("$"));
this._matchFailed(PEG.StringUtils.quote("$"));
}
}
if (result144 !== null) {
@ -1374,7 +1374,7 @@ PEG.grammarParser = (function(){
} else {
var result145 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("_"));
this._matchFailed(PEG.StringUtils.quote("_"));
}
}
if (result145 !== null) {
@ -1386,7 +1386,7 @@ PEG.grammarParser = (function(){
} else {
var result144 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("$"));
this._matchFailed(PEG.StringUtils.quote("$"));
}
}
if (result144 !== null) {
@ -1421,7 +1421,7 @@ PEG.grammarParser = (function(){
: null;
context.reportMatchFailures = savedReportMatchFailures;
if (context.reportMatchFailures && result138 === null) {
this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("identifier"));
this._matchFailed("identifier");
}
this._cache["identifier"][pos] = {
@ -1472,7 +1472,7 @@ PEG.grammarParser = (function(){
: null;
context.reportMatchFailures = savedReportMatchFailures;
if (context.reportMatchFailures && result151 === null) {
this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("literal"));
this._matchFailed("literal");
}
this._cache["literal"][pos] = {
@ -1500,7 +1500,7 @@ PEG.grammarParser = (function(){
} else {
var result159 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\""));
this._matchFailed(PEG.StringUtils.quote("\""));
}
}
if (result159 !== null) {
@ -1517,7 +1517,7 @@ PEG.grammarParser = (function(){
} else {
var result161 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\""));
this._matchFailed(PEG.StringUtils.quote("\""));
}
}
if (result161 !== null) {
@ -1620,7 +1620,7 @@ PEG.grammarParser = (function(){
} else {
var result177 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\""));
this._matchFailed(PEG.StringUtils.quote("\""));
}
}
if (result177 !== null) {
@ -1632,7 +1632,7 @@ PEG.grammarParser = (function(){
} else {
var result176 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\"));
this._matchFailed(PEG.StringUtils.quote("\\"));
}
}
if (result176 !== null) {
@ -1660,7 +1660,7 @@ PEG.grammarParser = (function(){
} else {
var result173 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.AnyMatchFailure());
this._matchFailed('any character');
}
}
if (result173 !== null) {
@ -1704,7 +1704,7 @@ PEG.grammarParser = (function(){
} else {
var result180 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("'"));
this._matchFailed(PEG.StringUtils.quote("'"));
}
}
if (result180 !== null) {
@ -1721,7 +1721,7 @@ PEG.grammarParser = (function(){
} else {
var result182 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("'"));
this._matchFailed(PEG.StringUtils.quote("'"));
}
}
if (result182 !== null) {
@ -1824,7 +1824,7 @@ PEG.grammarParser = (function(){
} else {
var result198 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("'"));
this._matchFailed(PEG.StringUtils.quote("'"));
}
}
if (result198 !== null) {
@ -1836,7 +1836,7 @@ PEG.grammarParser = (function(){
} else {
var result197 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\"));
this._matchFailed(PEG.StringUtils.quote("\\"));
}
}
if (result197 !== null) {
@ -1864,7 +1864,7 @@ PEG.grammarParser = (function(){
} else {
var result194 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.AnyMatchFailure());
this._matchFailed('any character');
}
}
if (result194 !== null) {
@ -1909,7 +1909,7 @@ PEG.grammarParser = (function(){
} else {
var result201 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("["));
this._matchFailed(PEG.StringUtils.quote("["));
}
}
if (result201 !== null) {
@ -1919,7 +1919,7 @@ PEG.grammarParser = (function(){
} else {
var result210 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("^"));
this._matchFailed(PEG.StringUtils.quote("^"));
}
}
if (result210 !== null) {
@ -1931,7 +1931,7 @@ PEG.grammarParser = (function(){
} else {
var result209 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure(""));
this._matchFailed(PEG.StringUtils.quote(""));
}
}
if (result209 !== null) {
@ -1974,7 +1974,7 @@ PEG.grammarParser = (function(){
} else {
var result204 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("]"));
this._matchFailed(PEG.StringUtils.quote("]"));
}
}
if (result204 !== null) {
@ -2008,7 +2008,7 @@ PEG.grammarParser = (function(){
: null;
context.reportMatchFailures = savedReportMatchFailures;
if (context.reportMatchFailures && result199 === null) {
this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("character class"));
this._matchFailed("character class");
}
this._cache["class"][pos] = {
@ -2038,7 +2038,7 @@ PEG.grammarParser = (function(){
} else {
var result214 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("-"));
this._matchFailed(PEG.StringUtils.quote("-"));
}
}
if (result214 !== null) {
@ -2184,7 +2184,7 @@ PEG.grammarParser = (function(){
} else {
var result232 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("]"));
this._matchFailed(PEG.StringUtils.quote("]"));
}
}
if (result232 !== null) {
@ -2196,7 +2196,7 @@ PEG.grammarParser = (function(){
} else {
var result231 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\"));
this._matchFailed(PEG.StringUtils.quote("\\"));
}
}
if (result231 !== null) {
@ -2224,7 +2224,7 @@ PEG.grammarParser = (function(){
} else {
var result228 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.AnyMatchFailure());
this._matchFailed('any character');
}
}
if (result228 !== null) {
@ -2268,7 +2268,7 @@ PEG.grammarParser = (function(){
} else {
var result235 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\"));
this._matchFailed(PEG.StringUtils.quote("\\"));
}
}
if (result235 !== null) {
@ -2285,7 +2285,7 @@ PEG.grammarParser = (function(){
} else {
var result241 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("x"));
this._matchFailed(PEG.StringUtils.quote("x"));
}
}
if (result241 !== null) {
@ -2297,7 +2297,7 @@ PEG.grammarParser = (function(){
} else {
var result240 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("u"));
this._matchFailed(PEG.StringUtils.quote("u"));
}
}
if (result240 !== null) {
@ -2326,7 +2326,7 @@ PEG.grammarParser = (function(){
} else {
var result237 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.AnyMatchFailure());
this._matchFailed('any character');
}
}
if (result237 !== null) {
@ -2382,7 +2382,7 @@ PEG.grammarParser = (function(){
} else {
var result245 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\0"));
this._matchFailed(PEG.StringUtils.quote("\\0"));
}
}
if (result245 !== null) {
@ -2438,7 +2438,7 @@ PEG.grammarParser = (function(){
} else {
var result250 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\x"));
this._matchFailed(PEG.StringUtils.quote("\\x"));
}
}
if (result250 !== null) {
@ -2492,7 +2492,7 @@ PEG.grammarParser = (function(){
} else {
var result255 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\u"));
this._matchFailed(PEG.StringUtils.quote("\\u"));
}
}
if (result255 !== null) {
@ -2558,7 +2558,7 @@ PEG.grammarParser = (function(){
} else {
var result262 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\\"));
this._matchFailed(PEG.StringUtils.quote("\\"));
}
}
if (result262 !== null) {
@ -2603,7 +2603,7 @@ PEG.grammarParser = (function(){
} else {
var result264 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.ClassMatchFailure("0-9"));
this._matchFailed('[' + "0-9" + ']');
}
}
@ -2633,7 +2633,7 @@ PEG.grammarParser = (function(){
} else {
var result265 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.ClassMatchFailure("0-9a-fA-F"));
this._matchFailed('[' + "0-9a-fA-F" + ']');
}
}
@ -2695,7 +2695,7 @@ PEG.grammarParser = (function(){
} else {
var result269 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.ClassMatchFailure("a-z"));
this._matchFailed('[' + "a-z" + ']');
}
}
@ -2725,7 +2725,7 @@ PEG.grammarParser = (function(){
} else {
var result270 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.ClassMatchFailure("A-Z"));
this._matchFailed('[' + "A-Z" + ']');
}
}
@ -2820,7 +2820,7 @@ PEG.grammarParser = (function(){
}
context.reportMatchFailures = savedReportMatchFailures;
if (context.reportMatchFailures && result276 === null) {
this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("comment"));
this._matchFailed("comment");
}
this._cache["comment"][pos] = {
@ -2848,7 +2848,7 @@ PEG.grammarParser = (function(){
} else {
var result280 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("//"));
this._matchFailed(PEG.StringUtils.quote("//"));
}
}
if (result280 !== null) {
@ -2872,7 +2872,7 @@ PEG.grammarParser = (function(){
} else {
var result284 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.AnyMatchFailure());
this._matchFailed('any character');
}
}
if (result284 !== null) {
@ -2906,7 +2906,7 @@ PEG.grammarParser = (function(){
} else {
var result284 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.AnyMatchFailure());
this._matchFailed('any character');
}
}
if (result284 !== null) {
@ -2958,7 +2958,7 @@ PEG.grammarParser = (function(){
} else {
var result287 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("/*"));
this._matchFailed(PEG.StringUtils.quote("/*"));
}
}
if (result287 !== null) {
@ -2973,7 +2973,7 @@ PEG.grammarParser = (function(){
} else {
var result293 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("*/"));
this._matchFailed(PEG.StringUtils.quote("*/"));
}
}
context.reportMatchFailures = savedReportMatchFailuresVar7;
@ -2990,7 +2990,7 @@ PEG.grammarParser = (function(){
} else {
var result292 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.AnyMatchFailure());
this._matchFailed('any character');
}
}
if (result292 !== null) {
@ -3015,7 +3015,7 @@ PEG.grammarParser = (function(){
} else {
var result293 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("*/"));
this._matchFailed(PEG.StringUtils.quote("*/"));
}
}
context.reportMatchFailures = savedReportMatchFailuresVar7;
@ -3032,7 +3032,7 @@ PEG.grammarParser = (function(){
} else {
var result292 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.AnyMatchFailure());
this._matchFailed('any character');
}
}
if (result292 !== null) {
@ -3053,7 +3053,7 @@ PEG.grammarParser = (function(){
} else {
var result289 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("*/"));
this._matchFailed(PEG.StringUtils.quote("*/"));
}
}
if (result289 !== null) {
@ -3098,7 +3098,7 @@ PEG.grammarParser = (function(){
} else {
var result299 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\n"));
this._matchFailed(PEG.StringUtils.quote("\n"));
}
}
if (result299 !== null) {
@ -3110,7 +3110,7 @@ PEG.grammarParser = (function(){
} else {
var result298 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\r\n"));
this._matchFailed(PEG.StringUtils.quote("\r\n"));
}
}
if (result298 !== null) {
@ -3122,7 +3122,7 @@ PEG.grammarParser = (function(){
} else {
var result297 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\r"));
this._matchFailed(PEG.StringUtils.quote("\r"));
}
}
if (result297 !== null) {
@ -3134,7 +3134,7 @@ PEG.grammarParser = (function(){
} else {
var result296 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\u2028"));
this._matchFailed(PEG.StringUtils.quote("\u2028"));
}
}
if (result296 !== null) {
@ -3146,7 +3146,7 @@ PEG.grammarParser = (function(){
} else {
var result295 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.LiteralMatchFailure("\u2029"));
this._matchFailed(PEG.StringUtils.quote("\u2029"));
}
}
if (result295 !== null) {
@ -3160,7 +3160,7 @@ PEG.grammarParser = (function(){
}
context.reportMatchFailures = savedReportMatchFailures;
if (context.reportMatchFailures && result294 === null) {
this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("end of line"));
this._matchFailed("end of line");
}
this._cache["eol"][pos] = {
@ -3187,7 +3187,7 @@ PEG.grammarParser = (function(){
} else {
var result300 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.ClassMatchFailure("\\n\\r\\u2028\\u2029"));
this._matchFailed('[' + "\\n\\r\\u2028\\u2029" + ']');
}
}
@ -3218,12 +3218,12 @@ PEG.grammarParser = (function(){
} else {
var result301 = null;
if (context.reportMatchFailures) {
this._matchFailed(new PEG.Parser.ClassMatchFailure("   - "));
this._matchFailed('[' + "   - " + ']');
}
}
context.reportMatchFailures = savedReportMatchFailures;
if (context.reportMatchFailures && result301 === null) {
this._matchFailed(new PEG.Parser.NamedRuleMatchFailure("whitespace"));
this._matchFailed("whitespace");
}
this._cache["whitespace"][pos] = {

@ -91,9 +91,9 @@ PEG.Parser.prototype = {
_matchFailed: function(failure) {
if (this._pos > this._rightmostMatchFailuresPos) {
this._rightmostMatchFailuresPos = this._pos;
this._rightmostMatchFailures = [];
this._rightmostMatchFailuresExpected = [];
}
this._rightmostMatchFailures.push(failure);
this._rightmostMatchFailuresExpected.push(failure);
},
/*
@ -109,30 +109,25 @@ PEG.Parser.prototype = {
that._input = input;
that._pos = 0;
that._rightmostMatchFailuresPos = 0;
that._rightmostMatchFailures = [];
that._rightmostMatchFailuresExpected = [];
that._cache = {};
}
function buildErrorMessage() {
function buildExpectedFromMatchFailures(failures) {
switch (failures.length) {
function buildExpected(failuresExpected) {
switch (failuresExpected.length) {
case 0:
return "end of input";
case 1:
return failures[0].toString();
return failuresExpected[0];
default:
return PEG.ArrayUtils.map(
failures.slice(0, failures.length - 1),
function(failure) { return failure.toString(); }
).join(", ")
return failuresExpected.slice(0, failuresExpected.length - 1).join(", ")
+ " or "
+ failures[failures.length - 1].toString();
+ failuresExpected[failuresExpected.length - 1];
}
}
var expected = buildExpectedFromMatchFailures(
that._rightmostMatchFailures
);
var expected = buildExpected(that._rightmostMatchFailuresExpected);
var pos = Math.max(that._pos, that._rightmostMatchFailuresPos);
var actual = pos < that._input.length
? PEG.StringUtils.quote(that._input.charAt(pos))
@ -189,21 +184,21 @@ PEG.Parser.prototype = {
*
* - |result !== null|
* - |that._pos === input.length|
* - |that._rightmostMatchFailures.length| may or may not contain
* - |that._rightmostMatchFailuresExpected.length| may or may not contain
* something
*
* 2. The parser successfully parsed only a part of the input.
*
* - |result !== null|
* - |that._pos < input.length|
* - |that._rightmostMatchFailures.length| may or may not contain
* - |that._rightmostMatchFailuresExpected.length| may or may not contain
* something
*
* 3. The parser did not successfully parse any part of the input.
*
* - |result === null|
* - |that._pos === 0|
* - |that._rightmostMatchFailures.length| contains at least one failure
* - |that._rightmostMatchFailuresExpected.length| contains at least one failure
*
* All code following this comment (including called functions) must
* handle these states.
@ -224,50 +219,6 @@ PEG.Parser.prototype = {
toSource: function() { return this._source; }
};
/* ===== PEG.Parser.LiteralMatchFailure ===== */
/* Stores information about a literal match failure. */
PEG.Parser.LiteralMatchFailure = function(value) { this._value = value; };
PEG.Parser.LiteralMatchFailure.prototype = {
toString: function() { return PEG.StringUtils.quote(this._value); }
};
/* ===== PEG.Parser.ClassMatchFailure ===== */
/* Stores information about a class match failure. */
PEG.Parser.ClassMatchFailure = function(characters) {
this._characters = characters;
};
PEG.Parser.ClassMatchFailure.prototype = {
toString: function() { return "[" + this._characters + "]"; }
};
/* ===== PEG.Parser.AnyMatchFailure ===== */
/* Stores information about a failure to match a "." expression. */
PEG.Parser.AnyMatchFailure = function() {}
PEG.Parser.AnyMatchFailure.prototype = {
toString: function() { return "any character"; }
};
/* ===== PEG.Parser.NamedRuleMatchFailure ===== */
/* Stores information about a failure to match a named rule. */
PEG.Parser.NamedRuleMatchFailure = function(displayName) {
this._displayName = displayName;
}
PEG.Parser.NamedRuleMatchFailure.prototype = {
toString: function() { return this._displayName; }
};
/* ===== PEG.Parser.SyntaxError ===== */
/* Thrown when a parser encounters a syntax error. */

Loading…
Cancel
Save