yason
Version:
Yet Another Simple Object Notation - Object serialization in between JSON and YAML
1,682 lines (1,586 loc) • 50.3 kB
JavaScript
module.exports = (function() {
"use strict";
/*
* Generated by PEG.js 0.9.0.
*
* http://pegjs.org/
*/
function peg$subclass(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor();
}
function peg$SyntaxError(message, expected, found, location) {
this.message = message;
this.expected = expected;
this.found = found;
this.location = location;
this.name = "SyntaxError";
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(this, peg$SyntaxError);
}
}
peg$subclass(peg$SyntaxError, Error);
function peg$parse(input) {
var options = arguments.length > 1 ? arguments[1] : {},
parser = this,
peg$FAILED = {},
peg$startRuleFunctions = { start: peg$parsestart },
peg$startRuleFunction = peg$parsestart,
peg$c0 = function(val) {
references.forEach((ref) => {
if(ref.name in namedObjects && ref.parent != null && ref.parentKey != null) {
ref.parent[ref.parentKey] = namedObjects[ref.name];
}
});
return val;
},
peg$c1 = "true",
peg$c2 = { type: "literal", value: "true", description: "\"true\"" },
peg$c3 = "false",
peg$c4 = { type: "literal", value: "false", description: "\"false\"" },
peg$c5 = "null",
peg$c6 = { type: "literal", value: "null", description: "\"null\"" },
peg$c7 = function(tag, refid, val) {
if(val instanceof YasonReference) {
if(val.name in namedObjects) {
val = namedObjects[val.name];
}
}
if(typeof(refid) != "undefined" && refid != null) {
namedObjects[refid] = val;
}
if(typeof(tag) != "undefined" && tag != null) {
val = new YasonTaggedValue(tag, val);
}
return val;
},
peg$c8 = "\t",
peg$c9 = { type: "literal", value: "\t", description: "\"\\t\"" },
peg$c10 = "\x0B",
peg$c11 = { type: "literal", value: "\x0B", description: "\"\\x0B\"" },
peg$c12 = "\f",
peg$c13 = { type: "literal", value: "\f", description: "\"\\f\"" },
peg$c14 = " ",
peg$c15 = { type: "literal", value: " ", description: "\" \"" },
peg$c16 = "\xA0",
peg$c17 = { type: "literal", value: "\xA0", description: "\"\\xA0\"" },
peg$c18 = "\uFEFF",
peg$c19 = { type: "literal", value: "\uFEFF", description: "\"\\uFEFF\"" },
peg$c20 = /^[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/,
peg$c21 = { type: "class", value: "[\\u0020\\u00A0\\u1680\\u2000-\\u200A\\u202F\\u205F\\u3000]", description: "[\\u0020\\u00A0\\u1680\\u2000-\\u200A\\u202F\\u205F\\u3000]" },
peg$c22 = function() { return ""; },
peg$c23 = /^[\n\r\u2028\u2029]/,
peg$c24 = { type: "class", value: "[\\n\\r\\u2028\\u2029]", description: "[\\n\\r\\u2028\\u2029]" },
peg$c25 = "!",
peg$c26 = { type: "literal", value: "!", description: "\"!\"" },
peg$c27 = { type: "any", description: "any character" },
peg$c28 = function(ch) { return ch; },
peg$c29 = function(id) { return id.join(""); },
peg$c30 = /^[_a-zA-Z]/,
peg$c31 = { type: "class", value: "[_a-zA-Z]", description: "[_a-zA-Z]" },
peg$c32 = /^[_a-zA-Z0-9]/,
peg$c33 = { type: "class", value: "[_a-zA-Z0-9]", description: "[_a-zA-Z0-9]" },
peg$c34 = function(head, tail) { return head + tail.join(""); },
peg$c35 = "&",
peg$c36 = { type: "literal", value: "&", description: "\"&\"" },
peg$c37 = function(id) { return id; },
peg$c38 = "*",
peg$c39 = { type: "literal", value: "*", description: "\"*\"" },
peg$c40 = function(id) {
var ref = new YasonReference(id);
references.push(ref);
return ref;
},
peg$c41 = "{",
peg$c42 = { type: "literal", value: "{", description: "\"{\"" },
peg$c43 = ",",
peg$c44 = { type: "literal", value: ",", description: "\",\"" },
peg$c45 = function(head, pair) {return pair;},
peg$c46 = function(head, tail) {
var obj = {};
if(typeof(head) != "undefined" && head != null) { obj[head.key] = head.value; }
else { return {}; }
if(typeof(tail) != "undefined" && tail != null) {
Array.prototype.forEach.call(tail, (pair) => {
if(pair.value instanceof YasonReference) {
if(pair.value.name in namedObjects) {
pair.value = namedObjects[pair.value.name];
} else {
pair.value.parent = obj;
pair.value.parentKey = pair.key;
references.push(pair.value);
}
}
obj[pair.key] = pair.value;
});
}
return obj;
},
peg$c47 = "}",
peg$c48 = { type: "literal", value: "}", description: "\"}\"" },
peg$c49 = function(obj) { return typeof(obj) == "undefined" || obj == null ? {} : obj; },
peg$c50 = "[",
peg$c51 = { type: "literal", value: "[", description: "\"[\"" },
peg$c52 = function(head, val) {return val;},
peg$c53 = function(head, tail) {
var arr = [];
if(typeof(head) != "undefined" && head != null) {
arr.push(head);
if(typeof(tail) != "undefined" && tail != null) { arr = arr.concat(tail); }
for(var i = 0; i < arr.length; i++) {
var val = arr[i];
if(val instanceof YasonReference) {
if(val.name in namedObjects) {
arr[i] = namedObjects[val.name];
} else {
val.parent = arr;
val.parentKey = i;
references.push(val);
}
}
}
}
return arr;
},
peg$c54 = "]",
peg$c55 = { type: "literal", value: "]", description: "\"]\"" },
peg$c56 = function(arr) { return typeof(arr) == "undefined" || arr == null ? [] : arr; },
peg$c57 = ":",
peg$c58 = { type: "literal", value: ":", description: "\":\"" },
peg$c59 = function(key, val) {
return {
key: key,
value: val
};
},
peg$c60 = "-",
peg$c61 = { type: "literal", value: "-", description: "\"-\"" },
peg$c62 = "0",
peg$c63 = { type: "literal", value: "0", description: "\"0\"" },
peg$c64 = /^[1-9]/,
peg$c65 = { type: "class", value: "[1-9]", description: "[1-9]" },
peg$c66 = /^[0-9]/,
peg$c67 = { type: "class", value: "[0-9]", description: "[0-9]" },
peg$c68 = ".",
peg$c69 = { type: "literal", value: ".", description: "\".\"" },
peg$c70 = /^[eE]/,
peg$c71 = { type: "class", value: "[eE]", description: "[eE]" },
peg$c72 = /^[+\-]/,
peg$c73 = { type: "class", value: "[+-]", description: "[+-]" },
peg$c74 = function(num) {
return JSON.parse(num);
},
peg$c75 = function(str) {
str = JSON.parse('"' + str + '"');
return str;
},
peg$c76 = "\"",
peg$c77 = { type: "literal", value: "\"", description: "\"\\\"\"" },
peg$c78 = "\\\"",
peg$c79 = { type: "literal", value: "\\\"", description: "\"\\\\\\\"\"" },
peg$c80 = function() {return '\\"';},
peg$c81 = function(ch) {return ch;},
peg$c82 = function(chars) {
return chars.join("");
},
peg$c83 = "'",
peg$c84 = { type: "literal", value: "'", description: "\"'\"" },
peg$c85 = "\\'",
peg$c86 = { type: "literal", value: "\\'", description: "\"\\\\'\"" },
peg$c87 = function() {return "\\'";},
peg$c88 = function(chars) {
return chars.join("").replace(/[']/g, '\\"');
},
peg$currPos = 0,
peg$savedPos = 0,
peg$posDetailsCache = [{ line: 1, column: 1, seenCR: false }],
peg$maxFailPos = 0,
peg$maxFailExpected = [],
peg$silentFails = 0,
peg$result;
if ("startRule" in options) {
if (!(options.startRule in peg$startRuleFunctions)) {
throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
}
peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
}
function text() {
return input.substring(peg$savedPos, peg$currPos);
}
function location() {
return peg$computeLocation(peg$savedPos, peg$currPos);
}
function expected(description) {
throw peg$buildException(
null,
[{ type: "other", description: description }],
input.substring(peg$savedPos, peg$currPos),
peg$computeLocation(peg$savedPos, peg$currPos)
);
}
function error(message) {
throw peg$buildException(
message,
null,
input.substring(peg$savedPos, peg$currPos),
peg$computeLocation(peg$savedPos, peg$currPos)
);
}
function peg$computePosDetails(pos) {
var details = peg$posDetailsCache[pos],
p, ch;
if (details) {
return details;
} else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
p--;
}
details = peg$posDetailsCache[p];
details = {
line: details.line,
column: details.column,
seenCR: details.seenCR
};
while (p < pos) {
ch = input.charAt(p);
if (ch === "\n") {
if (!details.seenCR) { details.line++; }
details.column = 1;
details.seenCR = false;
} else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
details.line++;
details.column = 1;
details.seenCR = true;
} else {
details.column++;
details.seenCR = false;
}
p++;
}
peg$posDetailsCache[pos] = details;
return details;
}
}
function peg$computeLocation(startPos, endPos) {
var startPosDetails = peg$computePosDetails(startPos),
endPosDetails = peg$computePosDetails(endPos);
return {
start: {
offset: startPos,
line: startPosDetails.line,
column: startPosDetails.column
},
end: {
offset: endPos,
line: endPosDetails.line,
column: endPosDetails.column
}
};
}
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$buildException(message, expected, found, location) {
function cleanupExpected(expected) {
var i = 1;
expected.sort(function(a, b) {
if (a.description < b.description) {
return -1;
} else if (a.description > b.description) {
return 1;
} else {
return 0;
}
});
while (i < expected.length) {
if (expected[i - 1] === expected[i]) {
expected.splice(i, 1);
} else {
i++;
}
}
}
function buildMessage(expected, found) {
function stringEscape(s) {
function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
return s
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\x08/g, '\\b')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\f/g, '\\f')
.replace(/\r/g, '\\r')
.replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
.replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
.replace(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
.replace(/[\u1000-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
}
var expectedDescs = new Array(expected.length),
expectedDesc, foundDesc, i;
for (i = 0; i < expected.length; i++) {
expectedDescs[i] = expected[i].description;
}
expectedDesc = expected.length > 1
? expectedDescs.slice(0, -1).join(", ")
+ " or "
+ expectedDescs[expected.length - 1]
: expectedDescs[0];
foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
return "Expected " + expectedDesc + " but " + foundDesc + " found.";
}
if (expected !== null) {
cleanupExpected(expected);
}
return new peg$SyntaxError(
message !== null ? message : buildMessage(expected, found),
expected,
found,
location
);
}
function peg$parsestart() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parsevalue();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0(s1);
}
s0 = s1;
return s0;
}
function peg$parsevalue() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = peg$parse__();
if (s1 !== peg$FAILED) {
s2 = peg$parsetag();
if (s2 === peg$FAILED) {
s2 = null;
}
if (s2 !== peg$FAILED) {
s3 = peg$parse__();
if (s3 !== peg$FAILED) {
s4 = peg$parserefid_definition();
if (s4 === peg$FAILED) {
s4 = null;
}
if (s4 !== peg$FAILED) {
s5 = peg$parserefid_reference();
if (s5 === peg$FAILED) {
s5 = peg$parseobject();
if (s5 === peg$FAILED) {
s5 = peg$parsearray();
if (s5 === peg$FAILED) {
s5 = peg$parsestring_literal();
if (s5 === peg$FAILED) {
s5 = peg$parsenumber_literal();
if (s5 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c1) {
s5 = peg$c1;
peg$currPos += 4;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c2); }
}
if (s5 === peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c3) {
s5 = peg$c3;
peg$currPos += 5;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c4); }
}
if (s5 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c5) {
s5 = peg$c5;
peg$currPos += 4;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c6); }
}
}
}
}
}
}
}
}
if (s5 !== peg$FAILED) {
s6 = peg$parse__();
if (s6 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c7(s2, s4, s5);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parse_() {
var s0, s1;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 9) {
s1 = peg$c8;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c9); }
}
if (s1 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 11) {
s1 = peg$c10;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c11); }
}
if (s1 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 12) {
s1 = peg$c12;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c13); }
}
if (s1 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 32) {
s1 = peg$c14;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c15); }
}
if (s1 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 160) {
s1 = peg$c16;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
if (s1 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 65279) {
s1 = peg$c18;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c19); }
}
if (s1 === peg$FAILED) {
if (peg$c20.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c21); }
}
if (s1 === peg$FAILED) {
s1 = peg$parseline_terminator();
}
}
}
}
}
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c22();
}
s0 = s1;
return s0;
}
function peg$parseline_terminator() {
var s0;
if (peg$c23.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
return s0;
}
function peg$parse__() {
var s0, s1;
s0 = [];
s1 = peg$parse_();
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = peg$parse_();
}
return s0;
}
function peg$parsetag() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 33) {
s1 = peg$c25;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = peg$parse_();
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.length > peg$currPos) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c28(s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
s5 = peg$parse_();
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.length > peg$currPos) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c28(s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s3 = peg$parse_();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c29(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseidentifier() {
var s0, s1, s2, s3;
s0 = peg$currPos;
if (peg$c30.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c31); }
}
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c32.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c33); }
}
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c32.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c33); }
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c34(s1, s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parserefid_definition() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = peg$parse__();
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 38) {
s2 = peg$c35;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c36); }
}
if (s2 !== peg$FAILED) {
s3 = peg$parseidentifier();
if (s3 !== peg$FAILED) {
s4 = peg$parse__();
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c37(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parserefid_reference() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = peg$parse__();
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 42) {
s2 = peg$c38;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c39); }
}
if (s2 !== peg$FAILED) {
s3 = peg$parseidentifier();
if (s3 !== peg$FAILED) {
s4 = peg$parse__();
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c40(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseobject() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c41;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c42); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
s4 = peg$parsekey_value_pair();
if (s4 !== peg$FAILED) {
s5 = [];
s6 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s7 = peg$c43;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
if (s7 !== peg$FAILED) {
s8 = peg$parsekey_value_pair();
if (s8 !== peg$FAILED) {
peg$savedPos = s6;
s7 = peg$c45(s4, s8);
s6 = s7;
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s7 = peg$c43;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
if (s7 !== peg$FAILED) {
s8 = peg$parsekey_value_pair();
if (s8 !== peg$FAILED) {
peg$savedPos = s6;
s7 = peg$c45(s4, s8);
s6 = s7;
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c46(s4, s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
s4 = peg$parse__();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
s5 = peg$c47;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c48); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c49(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsearray() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 91) {
s1 = peg$c50;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c51); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
s4 = peg$parsevalue();
if (s4 !== peg$FAILED) {
s5 = [];
s6 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s7 = peg$c43;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
if (s7 !== peg$FAILED) {
s8 = peg$parsevalue();
if (s8 !== peg$FAILED) {
peg$savedPos = s6;
s7 = peg$c52(s4, s8);
s6 = s7;
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 44) {
s7 = peg$c43;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
if (s7 !== peg$FAILED) {
s8 = peg$parsevalue();
if (s8 !== peg$FAILED) {
peg$savedPos = s6;
s7 = peg$c52(s4, s8);
s6 = s7;
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c53(s4, s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
s4 = peg$parse__();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 93) {
s5 = peg$c54;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c55); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c56(s3);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsekey_value_pair() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$parse__();
if (s1 !== peg$FAILED) {
s2 = peg$parsestring_literal();
if (s2 === peg$FAILED) {
s2 = peg$parseidentifier();
}
if (s2 !== peg$FAILED) {
s3 = peg$parse__();
if (s3 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 58) {
s4 = peg$c57;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c58); }
}
if (s4 !== peg$FAILED) {
s5 = peg$parsevalue();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c59(s2, s5);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsenumber_literal() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
s0 = peg$currPos;
s1 = peg$parse__();
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
s3 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 45) {
s4 = peg$c60;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c61); }
}
if (s4 === peg$FAILED) {
s4 = null;
}
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 48) {
s5 = peg$c62;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c63); }
}
if (s5 === peg$FAILED) {
s5 = peg$currPos;
if (peg$c64.test(input.charAt(peg$currPos))) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c65); }
}
if (s6 !== peg$FAILED) {
s7 = [];
if (peg$c66.test(input.charAt(peg$currPos))) {
s8 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s8 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c67); }
}
while (s8 !== peg$FAILED) {
s7.push(s8);
if (peg$c66.test(input.charAt(peg$currPos))) {
s8 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s8 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c67); }
}
}
if (s7 !== peg$FAILED) {
s6 = [s6, s7];
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
}
if (s5 !== peg$FAILED) {
s6 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 46) {
s7 = peg$c68;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c69); }
}
if (s7 !== peg$FAILED) {
s8 = [];
if (peg$c66.test(input.charAt(peg$currPos))) {
s9 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s9 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c67); }
}
if (s9 !== peg$FAILED) {
while (s9 !== peg$FAILED) {
s8.push(s9);
if (peg$c66.test(input.charAt(peg$currPos))) {
s9 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s9 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c67); }
}
}
} else {
s8 = peg$FAILED;
}
if (s8 !== peg$FAILED) {
s7 = [s7, s8];
s6 = s7;
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
} else {
peg$currPos = s6;
s6 = peg$FAILED;
}
if (s6 === peg$FAILED) {
s6 = null;
}
if (s6 !== peg$FAILED) {
s7 = peg$currPos;
if (peg$c70.test(input.charAt(peg$currPos))) {
s8 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s8 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c71); }
}
if (s8 !== peg$FAILED) {
if (peg$c72.test(input.charAt(peg$currPos))) {
s9 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s9 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c73); }
}
if (s9 === peg$FAILED) {
s9 = null;
}
if (s9 !== peg$FAILED) {
s10 = [];
if (peg$c66.test(input.charAt(peg$currPos))) {
s11 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s11 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c67); }
}
while (s11 !== peg$FAILED) {
s10.push(s11);
if (peg$c66.test(input.charAt(peg$currPos))) {
s11 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s11 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c67); }
}
}
if (s10 !== peg$FAILED) {
s8 = [s8, s9, s10];
s7 = s8;
} else {
peg$currPos = s7;
s7 = peg$FAILED;
}
} else {
peg$currPos = s7;
s7 = peg$FAILED;
}
} else {
peg$currPos = s7;
s7 = peg$FAILED;
}
if (s7 === peg$FAILED) {
s7 = null;
}
if (s7 !== peg$FAILED) {
s4 = [s4, s5, s6, s7];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
s2 = input.substring(s2, peg$currPos);
} else {
s2 = s3;
}
if (s2 !== peg$FAILED) {
s3 = peg$parse__();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c74(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsestring_literal() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parse__();
if (s1 !== peg$FAILED) {
s2 = peg$parsedquot_string();
if (s2 === peg$FAILED) {
s2 = peg$parsesquot_string();
}
if (s2 !== peg$FAILED) {
s3 = peg$parse__();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c75(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsedquot_string() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 34) {
s1 = peg$c76;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c77); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c78) {
s4 = peg$c78;
peg$currPos += 2;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c79); }
}
if (s4 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c80();
}
s3 = s4;
if (s3 === peg$FAILED) {
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 34) {
s5 = peg$c76;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c77); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.length > peg$currPos) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c81(s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c78) {
s4 = peg$c78;
peg$currPos += 2;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c79); }
}
if (s4 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c80();
}
s3 = s4;
if (s3 === peg$FAILED) {
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 34) {
s5 = peg$c76;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c77); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.length > peg$currPos) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c81(s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 34) {
s3 = peg$c76;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c77); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c82(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parsesquot_string() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 39) {
s1 = peg$c83;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c84); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c85) {
s4 = peg$c85;
peg$currPos += 2;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
if (s4 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c87();
}
s3 = s4;
if (s3 === peg$FAILED) {
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 39) {
s5 = peg$c83;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c84); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.length > peg$currPos) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c81(s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c85) {
s4 = peg$c85;
peg$currPos += 2;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
if (s4 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c87();
}
s3 = s4;
if (s3 === peg$FAILED) {
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.charCodeAt(peg$currPos) === 39) {
s5 = peg$c83;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c84); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.length > peg$currPos) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c81(s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 39) {
s3 = peg$c83;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c84); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c88(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
const Y = require("./package.js");
const YasonReference = Y.YasonReference;
const YasonTaggedValue = Y.YasonTaggedValue;
var namedObjects = {};
var references = [];
peg$result = peg$startRuleFunction();
if (peg$result !== peg$FAILED && peg$currPos === input.length) {
return peg$result;
} else {
if (peg$result !== peg$FAILED && peg$currPos < input.length) {
peg$fail({ type: "end", description: "end of input" });
}
throw peg$buildException(
null,
peg$maxFailExpected,