Compare commits

...

1 Commits

Author SHA1 Message Date
Ozzie Gooen
44d2def034 Fixed Parser issue 2022-09-06 12:22:31 -07:00

View File

@ -5,9 +5,7 @@
"use strict";
function peg$subclass(child, parent) {
function C() {
this.constructor = child;
}
function C() { this.constructor = child; }
C.prototype = parent.prototype;
child.prototype = new C();
}
@ -29,15 +27,13 @@ peg$subclass(peg$SyntaxError, Error);
function peg$padEnd(str, targetLength, padString) {
padString = padString || " ";
if (str.length > targetLength) {
return str;
}
if (str.length > targetLength) { return str; }
targetLength -= str.length;
padString += padString.repeat(targetLength);
return str + padString.slice(0, targetLength);
}
peg$SyntaxError.prototype.format = function (sources) {
peg$SyntaxError.prototype.format = function(sources) {
var str = "Error: " + this.message;
if (this.location) {
var src = null;
@ -52,24 +48,15 @@ peg$SyntaxError.prototype.format = function (sources) {
var loc = this.location.source + ":" + s.line + ":" + s.column;
if (src) {
var e = this.location.end;
var filler = peg$padEnd("", s.line.toString().length, " ");
var filler = peg$padEnd("", s.line.toString().length, ' ');
var line = src[s.line - 1];
var last = s.line === e.line ? e.column : line.length + 1;
var hatLen = last - s.column || 1;
str +=
"\n --> " +
loc +
"\n" +
filler +
" |\n" +
s.line +
" | " +
line +
"\n" +
filler +
" | " +
peg$padEnd("", s.column - 1, " ") +
peg$padEnd("", hatLen, "^");
var hatLen = (last - s.column) || 1;
str += "\n --> " + loc + "\n"
+ filler + " |\n"
+ s.line + " | " + line + "\n"
+ filler + " | " + peg$padEnd("", s.column - 1, ' ')
+ peg$padEnd("", hatLen, "^");
} else {
str += "\n at " + loc;
}
@ -77,35 +64,33 @@ peg$SyntaxError.prototype.format = function (sources) {
return str;
};
peg$SyntaxError.buildMessage = function (expected, found) {
peg$SyntaxError.buildMessage = function(expected, found) {
var DESCRIBE_EXPECTATION_FNS = {
literal: function (expectation) {
return '"' + literalEscape(expectation.text) + '"';
literal: function(expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
class: function (expectation) {
var escapedParts = expectation.parts.map(function (part) {
class: function(expectation) {
var escapedParts = expectation.parts.map(function(part) {
return Array.isArray(part)
? classEscape(part[0]) + "-" + classEscape(part[1])
: classEscape(part);
});
return (
"[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]"
);
return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
},
any: function () {
any: function() {
return "any character";
},
end: function () {
end: function() {
return "end of input";
},
other: function (expectation) {
other: function(expectation) {
return expectation.description;
},
}
};
function hex(ch) {
@ -115,17 +100,13 @@ peg$SyntaxError.buildMessage = function (expected, found) {
function literalEscape(s) {
return s
.replace(/\\/g, "\\\\")
.replace(/"/g, '\\"')
.replace(/"/g, "\\\"")
.replace(/\0/g, "\\0")
.replace(/\t/g, "\\t")
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/[\x00-\x0F]/g, function (ch) {
return "\\x0" + hex(ch);
})
.replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
return "\\x" + hex(ch);
});
.replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
}
function classEscape(s) {
@ -133,17 +114,13 @@ peg$SyntaxError.buildMessage = function (expected, found) {
.replace(/\\/g, "\\\\")
.replace(/\]/g, "\\]")
.replace(/\^/g, "\\^")
.replace(/-/g, "\\-")
.replace(/-/g, "\\-")
.replace(/\0/g, "\\0")
.replace(/\t/g, "\\t")
.replace(/\n/g, "\\n")
.replace(/\r/g, "\\r")
.replace(/[\x00-\x0F]/g, function (ch) {
return "\\x0" + hex(ch);
})
.replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) {
return "\\x" + hex(ch);
});
.replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
}
function describeExpectation(expectation) {
@ -174,25 +151,17 @@ peg$SyntaxError.buildMessage = function (expected, found) {
return descriptions[0] + " or " + descriptions[1];
default:
return (
descriptions.slice(0, -1).join(", ") +
", or " +
descriptions[descriptions.length - 1]
);
return descriptions.slice(0, -1).join(", ")
+ ", or "
+ descriptions[descriptions.length - 1];
}
}
function describeFound(found) {
return found ? '"' + literalEscape(found) + '"' : "end of input";
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
}
return (
"Expected " +
describeExpected(expected) +
" but " +
describeFound(found) +
" found."
);
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
};
function peg$parse(input, options) {
@ -208,7 +177,7 @@ function peg$parse(input, options) {
var peg$c1 = "#include";
var peg$c2 = "as";
var peg$c3 = "'";
var peg$c4 = '"';
var peg$c4 = "\"";
var peg$c5 = "//";
var peg$c6 = "/*";
var peg$c7 = "*/";
@ -228,8 +197,8 @@ function peg$parse(input, options) {
var peg$e3 = peg$otherExpectation("string");
var peg$e4 = peg$literalExpectation("'", false);
var peg$e5 = peg$classExpectation(["'"], true, false);
var peg$e6 = peg$literalExpectation('"', false);
var peg$e7 = peg$classExpectation(['"'], true, false);
var peg$e6 = peg$literalExpectation("\"", false);
var peg$e7 = peg$classExpectation(["\""], true, false);
var peg$e8 = peg$otherExpectation("comment");
var peg$e9 = peg$literalExpectation("//", false);
var peg$e10 = peg$literalExpectation("/*", false);
@ -243,36 +212,16 @@ function peg$parse(input, options) {
var peg$e18 = peg$classExpectation(["\r", "\n"], true, false);
var peg$e19 = peg$otherExpectation("identifier");
var peg$e20 = peg$classExpectation(["_", ["a", "z"]], false, false);
var peg$e21 = peg$classExpectation(
["_", ["a", "z"], ["0", "9"]],
false,
true
);
var peg$e21 = peg$classExpectation(["_", ["a", "z"], ["0", "9"]], false, true);
var peg$f0 = function (head, tail) {
return [head, ...tail].filter((e) => e != "");
};
var peg$f1 = function () {
return [];
};
var peg$f2 = function (file, variable) {
return [!variable ? "" : variable, file];
};
var peg$f3 = function (characters) {
return characters.join("");
};
var peg$f4 = function (characters) {
return characters.join("");
};
var peg$f5 = function () {
return "";
};
var peg$f6 = function () {
return "";
};
var peg$f7 = function () {
return text();
};
var peg$f0 = function(head, tail) {return [head, ...tail].filter( e => e != '');};
var peg$f1 = function() {return [];};
var peg$f2 = function(file, variable) {return [!variable ? '' : variable, file]};
var peg$f3 = function(characters) {return characters.join('');};
var peg$f4 = function(characters) {return characters.join('');};
var peg$f5 = function() { return '';};
var peg$f6 = function() { return '';};
var peg$f7 = function() {return text();};
var peg$currPos = 0;
var peg$savedPos = 0;
var peg$posDetailsCache = [{ line: 1, column: 1 }];
@ -286,9 +235,7 @@ function peg$parse(input, options) {
if ("startRule" in options) {
if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error(
"Can't start parsing from rule \"" + options.startRule + '".'
);
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
}
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
@ -306,7 +253,7 @@ function peg$parse(input, options) {
return {
source: peg$source,
start: peg$savedPos,
end: peg$currPos,
end: peg$currPos
};
}
@ -315,10 +262,9 @@ function peg$parse(input, options) {
}
function expected(description, location) {
location =
location !== undefined
? location
: peg$computeLocation(peg$savedPos, peg$currPos);
location = location !== undefined
? location
: peg$computeLocation(peg$savedPos, peg$currPos);
throw peg$buildStructuredError(
[peg$otherExpectation(description)],
@ -328,10 +274,9 @@ function peg$parse(input, options) {
}
function error(message, location) {
location =
location !== undefined
? location
: peg$computeLocation(peg$savedPos, peg$currPos);
location = location !== undefined
? location
: peg$computeLocation(peg$savedPos, peg$currPos);
throw peg$buildSimpleError(message, location);
}
@ -341,12 +286,7 @@ function peg$parse(input, options) {
}
function peg$classExpectation(parts, inverted, ignoreCase) {
return {
type: "class",
parts: parts,
inverted: inverted,
ignoreCase: ignoreCase,
};
return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
}
function peg$anyExpectation() {
@ -376,7 +316,7 @@ function peg$parse(input, options) {
details = peg$posDetailsCache[p];
details = {
line: details.line,
column: details.column,
column: details.column
};
while (p < pos) {
@ -405,20 +345,18 @@ function peg$parse(input, options) {
start: {
offset: startPos,
line: startPosDetails.line,
column: startPosDetails.column,
column: startPosDetails.column
},
end: {
offset: endPos,
line: endPosDetails.line,
column: endPosDetails.column,
},
column: endPosDetails.column
}
};
}
function peg$fail(expected) {
if (peg$currPos < peg$maxFailPos) {
return;
}
if (peg$currPos < peg$maxFailPos) { return; }
if (peg$currPos > peg$maxFailPos) {
peg$maxFailPos = peg$currPos;
@ -578,9 +516,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e0);
}
if (peg$silentFails === 0) { peg$fail(peg$e0); }
}
peg$silentFails--;
if (s2 === peg$FAILED) {
@ -650,9 +586,7 @@ function peg$parse(input, options) {
peg$currPos += 8;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e1);
}
if (peg$silentFails === 0) { peg$fail(peg$e1); }
}
if (s2 !== peg$FAILED) {
s3 = [];
@ -685,9 +619,7 @@ function peg$parse(input, options) {
peg$currPos += 2;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e2);
}
if (peg$silentFails === 0) { peg$fail(peg$e2); }
}
if (s7 !== peg$FAILED) {
s8 = [];
@ -784,9 +716,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e4);
}
if (peg$silentFails === 0) { peg$fail(peg$e4); }
}
if (s2 !== peg$FAILED) {
s3 = [];
@ -795,9 +725,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e5);
}
if (peg$silentFails === 0) { peg$fail(peg$e5); }
}
while (s4 !== peg$FAILED) {
s3.push(s4);
@ -806,9 +734,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e5);
}
if (peg$silentFails === 0) { peg$fail(peg$e5); }
}
}
if (input.charCodeAt(peg$currPos) === 39) {
@ -816,9 +742,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e4);
}
if (peg$silentFails === 0) { peg$fail(peg$e4); }
}
if (s4 !== peg$FAILED) {
s1 = s3;
@ -843,9 +767,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e6);
}
if (peg$silentFails === 0) { peg$fail(peg$e6); }
}
if (s2 !== peg$FAILED) {
s3 = [];
@ -854,9 +776,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e7);
}
if (peg$silentFails === 0) { peg$fail(peg$e7); }
}
while (s4 !== peg$FAILED) {
s3.push(s4);
@ -865,9 +785,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e7);
}
if (peg$silentFails === 0) { peg$fail(peg$e7); }
}
}
if (input.charCodeAt(peg$currPos) === 34) {
@ -875,9 +793,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e6);
}
if (peg$silentFails === 0) { peg$fail(peg$e6); }
}
if (s4 !== peg$FAILED) {
s1 = s3;
@ -898,9 +814,7 @@ function peg$parse(input, options) {
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e3);
}
if (peg$silentFails === 0) { peg$fail(peg$e3); }
}
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -963,9 +877,7 @@ function peg$parse(input, options) {
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e9);
}
if (peg$silentFails === 0) { peg$fail(peg$e9); }
}
if (s1 !== peg$FAILED) {
s2 = [];
@ -998,9 +910,7 @@ function peg$parse(input, options) {
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e8);
}
if (peg$silentFails === 0) { peg$fail(peg$e8); }
}
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1027,9 +937,7 @@ function peg$parse(input, options) {
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e10);
}
if (peg$silentFails === 0) { peg$fail(peg$e10); }
}
if (s1 !== peg$FAILED) {
s2 = [];
@ -1038,9 +946,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e11);
}
if (peg$silentFails === 0) { peg$fail(peg$e11); }
}
while (s3 !== peg$FAILED) {
s2.push(s3);
@ -1049,9 +955,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e11);
}
if (peg$silentFails === 0) { peg$fail(peg$e11); }
}
}
if (input.substr(peg$currPos, 2) === peg$c7) {
@ -1059,9 +963,7 @@ function peg$parse(input, options) {
peg$currPos += 2;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e12);
}
if (peg$silentFails === 0) { peg$fail(peg$e12); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
@ -1077,9 +979,7 @@ function peg$parse(input, options) {
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e8);
}
if (peg$silentFails === 0) { peg$fail(peg$e8); }
}
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1105,16 +1005,12 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e14);
}
if (peg$silentFails === 0) { peg$fail(peg$e14); }
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e13);
}
if (peg$silentFails === 0) { peg$fail(peg$e13); }
}
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1140,16 +1036,12 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e16);
}
if (peg$silentFails === 0) { peg$fail(peg$e16); }
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e15);
}
if (peg$silentFails === 0) { peg$fail(peg$e15); }
}
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1175,16 +1067,12 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e18);
}
if (peg$silentFails === 0) { peg$fail(peg$e18); }
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e17);
}
if (peg$silentFails === 0) { peg$fail(peg$e17); }
}
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1213,9 +1101,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e20);
}
if (peg$silentFails === 0) { peg$fail(peg$e20); }
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
@ -1225,9 +1111,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e20);
}
if (peg$silentFails === 0) { peg$fail(peg$e20); }
}
}
} else {
@ -1240,9 +1124,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e21);
}
if (peg$silentFails === 0) { peg$fail(peg$e21); }
}
while (s4 !== peg$FAILED) {
s3.push(s4);
@ -1251,9 +1133,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e21);
}
if (peg$silentFails === 0) { peg$fail(peg$e21); }
}
}
s2 = [s2, s3];
@ -1270,9 +1150,7 @@ function peg$parse(input, options) {
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e19);
}
if (peg$silentFails === 0) { peg$fail(peg$e19); }
}
peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 };
@ -1301,5 +1179,5 @@ function peg$parse(input, options) {
module.exports = {
SyntaxError: peg$SyntaxError,
parse: peg$parse,
parse: peg$parse
};