@mc-wiki/snbt
Version:
A library for parsing SNBT (Stringified NBT) format
1,555 lines (1,553 loc) • 196 kB
JavaScript
'use strict';
// @generated by Peggy 4.2.0.
//
// https://peggyjs.org/
function push(tokens, loc, type) {
tokens.push({ start: loc.start.offset, end: loc.end.offset, type });
}
function peg$subclass$1(child, parent) {
function C() { this.constructor = child; }
C.prototype = parent.prototype;
child.prototype = new C();
}
function peg$SyntaxError$1(message, expected, found, location) {
var self = Error.call(this, message);
// istanbul ignore next Check is a necessary evil to support older environments
if (Object.setPrototypeOf) {
Object.setPrototypeOf(self, peg$SyntaxError$1.prototype);
}
self.expected = expected;
self.found = found;
self.location = location;
self.name = "SyntaxError";
return self;
}
peg$subclass$1(peg$SyntaxError$1, Error);
function peg$padEnd$1(str, targetLength, padString) {
padString = padString || " ";
if (str.length > targetLength) {
return str;
}
targetLength -= str.length;
padString += padString.repeat(targetLength);
return str + padString.slice(0, targetLength);
}
peg$SyntaxError$1.prototype.format = function (sources) {
var str = "Error: " + this.message;
if (this.location) {
var src = null;
var k;
for (k = 0; k < sources.length; k++) {
if (sources[k].source === this.location.source) {
src = sources[k].text.split(/\r\n|\n|\r/g);
break;
}
}
var s = this.location.start;
var offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
? this.location.source.offset(s)
: s;
var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
if (src) {
var e = this.location.end;
var filler = peg$padEnd$1("", offset_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"
+ offset_s.line + " | " + line + "\n"
+ filler + " | " + peg$padEnd$1("", s.column - 1, ' ')
+ peg$padEnd$1("", hatLen, "^");
}
else {
str += "\n at " + loc;
}
}
return str;
};
peg$SyntaxError$1.buildMessage = function (expected, found) {
var DESCRIBE_EXPECTATION_FNS = {
literal: function (expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
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("") + "]";
},
any: function () {
return "any character";
},
end: function () {
return "end of input";
},
other: function (expectation) {
return expectation.description;
}
};
function hex(ch) {
return ch.charCodeAt(0).toString(16).toUpperCase();
}
function literalEscape(s) {
return s
.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); });
}
function classEscape(s) {
return s
.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); });
}
function describeExpectation(expectation) {
return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
}
function describeExpected(expected) {
var descriptions = expected.map(describeExpectation);
var i, j;
descriptions.sort();
if (descriptions.length > 0) {
for (i = 1, j = 1; i < descriptions.length; i++) {
if (descriptions[i - 1] !== descriptions[i]) {
descriptions[j] = descriptions[i];
j++;
}
}
descriptions.length = j;
}
switch (descriptions.length) {
case 1:
return descriptions[0];
case 2:
return descriptions[0] + " or " + descriptions[1];
default:
return descriptions.slice(0, -1).join(", ")
+ ", or "
+ descriptions[descriptions.length - 1];
}
}
function describeFound(found) {
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
}
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
};
function peg$parse$1(input, options) {
options = options !== undefined ? options : {};
const tokens = [];
var peg$FAILED = {};
var peg$source = options.grammarSource;
var peg$startRuleFunctions = { literal: peg$parseliteral };
var peg$startRuleFunction = peg$parseliteral;
var peg$c0 = "0";
var peg$c1 = ".";
var peg$c2 = "x";
var peg$c3 = "u";
var peg$c4 = "U";
var peg$c5 = "N";
var peg$c6 = "{";
var peg$c7 = "}";
var peg$c8 = "\\";
var peg$c9 = "\"";
var peg$c10 = "'";
var peg$c11 = ",";
var peg$c12 = "(";
var peg$c13 = ")";
var peg$c14 = ":";
var peg$c15 = "[";
var peg$c16 = ";";
var peg$c17 = "]";
var peg$r0 = /^[ \t\n\f\r\xA0\u2007\u202F\v\x1C-\x1F]/;
var peg$r1 = /^[+\-]/;
var peg$r2 = /^[BILSbils]/;
var peg$r3 = /^[.0-9\-+]/;
var peg$r4 = /^[uU]/;
var peg$r5 = /^[sS]/;
var peg$r6 = /^[01_]/;
var peg$r7 = /^[0-9_]/;
var peg$r8 = /^[0-9a-fA-F_]/;
var peg$r9 = /^[xX]/;
var peg$r10 = /^[bB]/;
var peg$r11 = /^[fF]/;
var peg$r12 = /^[dD]/;
var peg$r13 = /^[eE]/;
var peg$r14 = /^['"]/;
var peg$r15 = /^[0-9A-Fa-f]/;
var peg$r16 = /^[\-a-zA-Z0-9 ]/;
var peg$r17 = /^[bstnfr\\'"]/;
var peg$r18 = /^[^"'\\]/;
var peg$r19 = /^[0-9A-Za-z_.+\-]/;
var peg$r20 = /^[{]/;
var peg$r21 = /^[[]/;
var peg$r22 = /^[BLI]/;
var peg$e0 = peg$otherExpectation("literal");
var peg$e1 = peg$otherExpectation("whitespace");
var peg$e2 = peg$classExpectation([" ", "\t", "\n", "\f", "\r", "\xA0", "\u2007", "\u202F", "\v", ["\x1C", "\x1F"]], false, false);
var peg$e3 = peg$otherExpectation("sign");
var peg$e4 = peg$classExpectation(["+", "-"], false, false);
var peg$e5 = peg$classExpectation(["B", "I", "L", "S", "b", "i", "l", "s"], false, false);
var peg$e6 = peg$classExpectation([".", ["0", "9"], "-", "+"], false, false);
var peg$e7 = peg$otherExpectation("integer_suffix");
var peg$e8 = peg$classExpectation(["u", "U"], false, false);
var peg$e9 = peg$classExpectation(["s", "S"], false, false);
var peg$e10 = peg$otherExpectation("binary_numeral_char");
var peg$e11 = peg$classExpectation(["0", "1", "_"], false, false);
var peg$e12 = peg$otherExpectation("decimal_numeral_char");
var peg$e13 = peg$classExpectation([["0", "9"], "_"], false, false);
var peg$e14 = peg$otherExpectation("hex_numeral_char");
var peg$e15 = peg$classExpectation([["0", "9"], ["a", "f"], ["A", "F"], "_"], false, false);
var peg$e16 = peg$otherExpectation("binary_numeral");
var peg$e17 = peg$otherExpectation("decimal_numeral");
var peg$e18 = peg$otherExpectation("hex_numeral");
var peg$e19 = peg$otherExpectation("number_sequence");
var peg$e20 = peg$literalExpectation("0", false);
var peg$e21 = peg$classExpectation(["x", "X"], false, false);
var peg$e22 = peg$classExpectation(["b", "B"], false, false);
var peg$e23 = peg$otherExpectation("integer_literal");
var peg$e24 = peg$classExpectation(["f", "F"], false, false);
var peg$e25 = peg$classExpectation(["d", "D"], false, false);
var peg$e26 = peg$otherExpectation("float_exponent_part");
var peg$e27 = peg$classExpectation(["e", "E"], false, false);
var peg$e28 = peg$otherExpectation("float_whole_part");
var peg$e29 = peg$otherExpectation("float_fraction_part");
var peg$e30 = peg$otherExpectation("float_literal");
var peg$e31 = peg$literalExpectation(".", false);
var peg$e32 = peg$classExpectation(["'", "\""], false, false);
var peg$e33 = peg$otherExpectation("hexadecimal_literal");
var peg$e34 = peg$classExpectation([["0", "9"], ["A", "F"], ["a", "f"]], false, false);
var peg$e35 = peg$otherExpectation("string_hex_2");
var peg$e36 = peg$otherExpectation("string_hex_4");
var peg$e37 = peg$otherExpectation("string_hex_8");
var peg$e38 = peg$otherExpectation("unicode_name");
var peg$e39 = peg$classExpectation(["-", ["a", "z"], ["A", "Z"], ["0", "9"], " "], false, false);
var peg$e40 = peg$otherExpectation("string_escape_sequence");
var peg$e41 = peg$classExpectation(["b", "s", "t", "n", "f", "r", "\\", "'", "\""], false, false);
var peg$e42 = peg$literalExpectation("x", false);
var peg$e43 = peg$literalExpectation("u", false);
var peg$e44 = peg$literalExpectation("U", false);
var peg$e45 = peg$literalExpectation("N", false);
var peg$e46 = peg$literalExpectation("{", false);
var peg$e47 = peg$literalExpectation("}", false);
var peg$e48 = peg$otherExpectation("string_plain_contents");
var peg$e49 = peg$classExpectation(["\"", "'", "\\"], true, false);
var peg$e50 = peg$otherExpectation("string_contents");
var peg$e51 = peg$literalExpectation("\\", false);
var peg$e52 = peg$otherExpectation("single_quoted_string_chunk");
var peg$e53 = peg$literalExpectation("\"", false);
var peg$e54 = peg$otherExpectation("single_quoted_string_contents");
var peg$e55 = peg$otherExpectation("double_quoted_string_chunk");
var peg$e56 = peg$literalExpectation("'", false);
var peg$e57 = peg$otherExpectation("double_quoted_string_contents");
var peg$e58 = peg$otherExpectation("quoted_string_literal");
var peg$e59 = peg$otherExpectation("unquoted_string");
var peg$e60 = peg$classExpectation([["0", "9"], ["A", "Z"], ["a", "z"], "_", ".", "+", "-"], false, false);
var peg$e61 = peg$otherExpectation("arguments");
var peg$e62 = peg$literalExpectation(",", false);
var peg$e63 = peg$otherExpectation("unquoted_string_or_builtin");
var peg$e64 = peg$literalExpectation("(", false);
var peg$e65 = peg$literalExpectation(")", false);
var peg$e66 = peg$classExpectation(["{"], false, false);
var peg$e67 = peg$otherExpectation("map_key");
var peg$e68 = peg$otherExpectation("map_entry");
var peg$e69 = peg$literalExpectation(":", false);
var peg$e70 = peg$otherExpectation("map_entries");
var peg$e71 = peg$otherExpectation("map_literal");
var peg$e72 = peg$classExpectation(["["], false, false);
var peg$e73 = peg$otherExpectation("list_entries");
var peg$e74 = peg$otherExpectation("array_prefix");
var peg$e75 = peg$classExpectation(["B", "L", "I"], false, false);
var peg$e76 = peg$otherExpectation("int_array_entries");
var peg$e77 = peg$otherExpectation("list_literal");
var peg$e78 = peg$literalExpectation("[", false);
var peg$e79 = peg$literalExpectation(";", false);
var peg$e80 = peg$literalExpectation("]", false);
var peg$f0 = function () { return tokens; };
var peg$f1 = function () { return tokens; };
var peg$f2 = function () { return tokens; };
var peg$f3 = function () { return tokens; };
var peg$f4 = function () { return tokens; };
var peg$f5 = function () { push(tokens, location(), 'numberSuffix'); };
var peg$f6 = function () { push(tokens, location(), 'numberSuffix'); };
var peg$f7 = function () { push(tokens, location(), 'numberSuffix'); };
var peg$f8 = function () { push(tokens, location(), 'number'); };
var peg$f9 = function () { push(tokens, location(), 'numberSuffix'); };
var peg$f10 = function () { push(tokens, location(), 'numberSuffix'); };
var peg$f11 = function () { push(tokens, location(), 'number'); };
var peg$f12 = function () { push(tokens, location(), 'number'); };
var peg$f13 = function () { push(tokens, location(), 'number'); };
var peg$f14 = function () { push(tokens, location(), 'number'); };
var peg$f15 = function () { push(tokens, location(), 'string'); };
var peg$f16 = function () { push(tokens, location(), 'string'); };
var peg$f17 = function () { push(tokens, location(), 'operation'); };
var peg$f18 = function () { push(tokens, location(), 'string'); };
var peg$f19 = function () { push(tokens, location(), 'key'); };
var peg$f20 = function () { push(tokens, location(), 'key'); };
var peg$f21 = function () { push(tokens, location(), 'key'); };
var peg$f22 = function () { push(tokens, location(), 'arrayType'); };
var peg$currPos = options.peg$currPos | 0;
var peg$savedPos = peg$currPos;
var peg$posDetailsCache = [{ line: 1, column: 1 }];
var peg$maxFailPos = peg$currPos;
var peg$maxFailExpected = options.peg$maxFailExpected || [];
var peg$silentFails = options.peg$silentFails | 0;
var peg$result;
if (options.startRule) {
if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
}
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
}
function location() {
return peg$computeLocation(peg$savedPos, peg$currPos);
}
function peg$literalExpectation(text, ignoreCase) {
return { type: "literal", text: text, ignoreCase: ignoreCase };
}
function peg$classExpectation(parts, inverted, ignoreCase) {
return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
}
function peg$endExpectation() {
return { type: "end" };
}
function peg$otherExpectation(description) {
return { type: "other", description: description };
}
function peg$computePosDetails(pos) {
var details = peg$posDetailsCache[pos];
var p;
if (details) {
return details;
}
else {
if (pos >= peg$posDetailsCache.length) {
p = peg$posDetailsCache.length - 1;
}
else {
p = pos;
while (!peg$posDetailsCache[--p]) { }
}
details = peg$posDetailsCache[p];
details = {
line: details.line,
column: details.column
};
while (p < pos) {
if (input.charCodeAt(p) === 10) {
details.line++;
details.column = 1;
}
else {
details.column++;
}
p++;
}
peg$posDetailsCache[pos] = details;
return details;
}
}
function peg$computeLocation(startPos, endPos, offset) {
var startPosDetails = peg$computePosDetails(startPos);
var endPosDetails = peg$computePosDetails(endPos);
var res = {
source: peg$source,
start: {
offset: startPos,
line: startPosDetails.line,
column: startPosDetails.column
},
end: {
offset: endPos,
line: endPosDetails.line,
column: endPosDetails.column
}
};
return res;
}
function peg$fail(expected) {
if (peg$currPos < peg$maxFailPos) {
return;
}
if (peg$currPos > peg$maxFailPos) {
peg$maxFailPos = peg$currPos;
peg$maxFailExpected = [];
}
peg$maxFailExpected.push(expected);
}
function peg$buildStructuredError(expected, found, location) {
return new peg$SyntaxError$1(peg$SyntaxError$1.buildMessage(expected, found), expected, found, location);
}
function peg$parseliteral() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parsestartNumber();
peg$silentFails--;
if (s2 !== peg$FAILED) {
peg$currPos = s1;
s1 = undefined;
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parsefloat();
if (s2 === peg$FAILED) {
s2 = peg$parseinteger();
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f0();
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parsequote();
peg$silentFails--;
if (s2 !== peg$FAILED) {
peg$currPos = s1;
s1 = undefined;
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parsequotedStringLiteral();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f1();
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parsemap();
peg$silentFails--;
if (s2 !== peg$FAILED) {
peg$currPos = s1;
s1 = undefined;
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parsemapLiteral();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f2();
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$parselist();
peg$silentFails--;
if (s2 !== peg$FAILED) {
peg$currPos = s1;
s1 = undefined;
}
else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parselistLiteral();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f3();
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseunquotedStringOrBuiltin();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f4();
}
s0 = s1;
}
}
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e0);
}
}
return s0;
}
function peg$parse_() {
var s0, s1;
peg$silentFails++;
s0 = [];
s1 = input.charAt(peg$currPos);
if (peg$r0.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e2);
}
}
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = input.charAt(peg$currPos);
if (peg$r0.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e2);
}
}
}
peg$silentFails--;
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e1);
}
return s0;
}
function peg$parsesign() {
var s0;
peg$silentFails++;
s0 = input.charAt(peg$currPos);
if (peg$r1.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e4);
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$e3);
}
}
return s0;
}
function peg$parsenoSignSuffix() {
var s0;
s0 = input.charAt(peg$currPos);
if (peg$r2.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e5);
}
}
return s0;
}
function peg$parsestartNumber() {
var s0;
s0 = input.charAt(peg$currPos);
if (peg$r3.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e6);
}
}
return s0;
}
function peg$parseintSuffix() {
var s0, s1;
peg$silentFails++;
s0 = peg$currPos;
s1 = input.charAt(peg$currPos);
if (peg$r4.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e8);
}
}
if (s1 !== peg$FAILED) {
peg$parse_();
peg$parsenoSignSuffix();
peg$savedPos = s0;
s0 = peg$f5();
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = input.charAt(peg$currPos);
if (peg$r5.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e9);
}
}
if (s1 !== peg$FAILED) {
peg$parse_();
peg$parsenoSignSuffix();
peg$savedPos = s0;
s0 = peg$f6();
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsenoSignSuffix();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f7();
}
s0 = s1;
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e7);
}
}
return s0;
}
function peg$parsebinNumChar() {
var s0;
peg$silentFails++;
s0 = input.charAt(peg$currPos);
if (peg$r6.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e11);
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$e10);
}
}
return s0;
}
function peg$parsedecNumChar() {
var s0;
peg$silentFails++;
s0 = input.charAt(peg$currPos);
if (peg$r7.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e13);
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$e12);
}
}
return s0;
}
function peg$parsehexNumChar() {
var s0;
peg$silentFails++;
s0 = input.charAt(peg$currPos);
if (peg$r8.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e15);
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$e14);
}
}
return s0;
}
function peg$parsebinNum() {
var s0, s1;
peg$silentFails++;
s0 = [];
s1 = peg$parsebinNumChar();
if (s1 !== peg$FAILED) {
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = peg$parsebinNumChar();
}
}
else {
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e16);
}
}
return s0;
}
function peg$parsedecNum() {
var s0, s1;
peg$silentFails++;
s0 = [];
s1 = peg$parsedecNumChar();
if (s1 !== peg$FAILED) {
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = peg$parsedecNumChar();
}
}
else {
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e17);
}
}
return s0;
}
function peg$parsehexNum() {
var s0, s1;
peg$silentFails++;
s0 = [];
s1 = peg$parsehexNumChar();
if (s1 !== peg$FAILED) {
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = peg$parsehexNumChar();
}
}
else {
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e18);
}
}
return s0;
}
function peg$parsenumSeq() {
var s0, s1, s2, s3, s4, s5, s6;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 48) {
s1 = peg$c0;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e20);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
s3 = peg$currPos;
s4 = input.charAt(peg$currPos);
if (peg$r9.test(s4)) {
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e21);
}
}
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
s6 = peg$parsehexNum();
if (s6 !== peg$FAILED) {
s4 = [s4, s5, s6];
s3 = s4;
}
else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 === peg$FAILED) {
s3 = peg$currPos;
s4 = input.charAt(peg$currPos);
if (peg$r10.test(s4)) {
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e22);
}
}
if (s4 !== peg$FAILED) {
s5 = peg$parse_();
s6 = peg$parsebinNum();
if (s6 !== peg$FAILED) {
s4 = [s4, s5, s6];
s3 = s4;
}
else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
if (s3 !== peg$FAILED) {
s1 = [s1, s2, s3];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$parsedecNum();
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e19);
}
}
return s0;
}
function peg$parseinteger() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parsesign();
if (s2 === peg$FAILED) {
s2 = null;
}
s3 = peg$parse_();
s4 = peg$parsenumSeq();
if (s4 !== peg$FAILED) {
peg$savedPos = s1;
s1 = peg$f8();
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
s3 = peg$parseintSuffix();
if (s3 === peg$FAILED) {
s3 = null;
}
s1 = [s1, s2, s3];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e23);
}
}
return s0;
}
function peg$parsefloatSuffix() {
var s0, s1;
s0 = peg$currPos;
s1 = input.charAt(peg$currPos);
if (peg$r11.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e24);
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f9();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = input.charAt(peg$currPos);
if (peg$r12.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e25);
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f10();
}
s0 = s1;
}
return s0;
}
function peg$parsefloatExpPart() {
var s0, s1, s2, s3, s4, s5;
peg$silentFails++;
s0 = peg$currPos;
s1 = input.charAt(peg$currPos);
if (peg$r13.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e27);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
s3 = peg$parsesign();
if (s3 === peg$FAILED) {
s3 = null;
}
s4 = peg$parse_();
s5 = peg$parsedecNum();
if (s5 !== peg$FAILED) {
s1 = [s1, s2, s3, s4, s5];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e26);
}
}
return s0;
}
function peg$parsefloatWholePart() {
var s0;
peg$silentFails++;
s0 = peg$parsedecNum();
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$e28);
}
}
return s0;
}
function peg$parsefloatFracPart() {
var s0;
peg$silentFails++;
s0 = peg$parsedecNum();
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$e29);
}
}
return s0;
}
function peg$parsefloat() {
var s0, s1, s2, s3, s4, s6;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parsesign();
if (s2 === peg$FAILED) {
s2 = null;
}
s3 = peg$parse_();
s4 = peg$parsefloatWholePart();
if (s4 !== peg$FAILED) {
peg$parse_();
if (input.charCodeAt(peg$currPos) === 46) {
s6 = peg$c1;
peg$currPos++;
}
else {
s6 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e31);
}
}
if (s6 !== peg$FAILED) {
peg$parse_();
peg$parsefloatFracPart();
peg$parse_();
peg$parsefloatExpPart();
peg$savedPos = s1;
s1 = peg$f11();
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
s3 = peg$parsefloatSuffix();
if (s3 === peg$FAILED) {
s3 = null;
}
s1 = [s1, s2, s3];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parsesign();
if (s2 === peg$FAILED) {
s2 = null;
}
s3 = peg$parse_();
if (input.charCodeAt(peg$currPos) === 46) {
s4 = peg$c1;
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e31);
}
}
if (s4 !== peg$FAILED) {
peg$parse_();
s6 = peg$parsefloatFracPart();
if (s6 !== peg$FAILED) {
peg$parse_();
peg$parsefloatExpPart();
peg$savedPos = s1;
s1 = peg$f12();
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
s3 = peg$parsefloatSuffix();
if (s3 === peg$FAILED) {
s3 = null;
}
s1 = [s1, s2, s3];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parsesign();
if (s2 === peg$FAILED) {
s2 = null;
}
s3 = peg$parse_();
s4 = peg$parsefloatWholePart();
if (s4 !== peg$FAILED) {
peg$parse_();
s6 = peg$parsefloatExpPart();
if (s6 !== peg$FAILED) {
peg$savedPos = s1;
s1 = peg$f13();
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
s3 = peg$parsefloatSuffix();
if (s3 === peg$FAILED) {
s3 = null;
}
s1 = [s1, s2, s3];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parsesign();
if (s2 === peg$FAILED) {
s2 = null;
}
s3 = peg$parse_();
s4 = peg$parsefloatWholePart();
if (s4 !== peg$FAILED) {
peg$parse_();
s6 = peg$parsefloatExpPart();
if (s6 === peg$FAILED) {
s6 = null;
}
peg$savedPos = s1;
s1 = peg$f14();
}
else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parse_();
s3 = peg$parsefloatSuffix();
if (s3 !== peg$FAILED) {
s1 = [s1, s2, s3];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e30);
}
}
return s0;
}
function peg$parsequote() {
var s0;
s0 = input.charAt(peg$currPos);
if (peg$r14.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e32);
}
}
return s0;
}
function peg$parsehexLiteral() {
var s0;
peg$silentFails++;
s0 = input.charAt(peg$currPos);
if (peg$r15.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e34);
}
}
peg$silentFails--;
if (s0 === peg$FAILED) {
if (peg$silentFails === 0) {
peg$fail(peg$e33);
}
}
return s0;
}
function peg$parsestringHex2() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsehexLiteral();
while (s2 !== peg$FAILED) {
s1.push(s2);
if (s1.length >= 2) {
s2 = peg$FAILED;
}
else {
s2 = peg$parsehexLiteral();
}
}
if (s1.length < 2) {
peg$currPos = s0;
s0 = peg$FAILED;
}
else {
s0 = s1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e35);
}
}
return s0;
}
function peg$parsestringHex4() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsehexLiteral();
while (s2 !== peg$FAILED) {
s1.push(s2);
if (s1.length >= 4) {
s2 = peg$FAILED;
}
else {
s2 = peg$parsehexLiteral();
}
}
if (s1.length < 4) {
peg$currPos = s0;
s0 = peg$FAILED;
}
else {
s0 = s1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e36);
}
}
return s0;
}
function peg$parsestringHex8() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$parsehexLiteral();
while (s2 !== peg$FAILED) {
s1.push(s2);
if (s1.length >= 8) {
s2 = peg$FAILED;
}
else {
s2 = peg$parsehexLiteral();
}
}
if (s1.length < 8) {
peg$currPos = s0;
s0 = peg$FAILED;
}
else {
s0 = s1;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e37);
}
}
return s0;
}
function peg$parseunicodeName() {
var s0, s1;
peg$silentFails++;
s0 = [];
s1 = input.charAt(peg$currPos);
if (peg$r16.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e39);
}
}
if (s1 !== peg$FAILED) {
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = input.charAt(peg$currPos);
if (peg$r16.test(s1)) {
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e39);
}
}
}
}
else {
s0 = peg$FAILED;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e38);
}
}
return s0;
}
function peg$parsestringEscapeSeq() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = input.charAt(peg$currPos);
if (peg$r17.test(s0)) {
peg$currPos++;
}
else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e41);
}
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 120) {
s1 = peg$c2;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e42);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsestringHex2();
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 117) {
s1 = peg$c3;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e43);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsestringHex4();
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 85) {
s1 = peg$c4;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e44);
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parsestringHex8();
if (s2 !== peg$FAILED) {
s1 = [s1, s2];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 78) {
s1 = peg$c5;
peg$currPos++;
}
else {
s1 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e45);
}
}
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 123) {
s2 = peg$c6;
peg$currPos++;
}
else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e46);
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parseunicodeName();
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s4 = peg$c7;
peg$currPos++;
}
else {
s4 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$e47);
}
}
if (s4 !== peg$FAILED) {
s1 = [s1, s2, s3, s4];
s0 = s1;
}
else {
peg$currPos = s0;
s0 = peg$FAILED;
}