heta-parser
Version:
Parsing of Heta-language files.
1,837 lines (1,730 loc) • 85.5 kB
JavaScript
/*
* Generated by PEG.js 0.10.0.
*
* http://pegjs.org/
*/
"use strict";
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);
peg$SyntaxError.buildMessage = function(expected, found) {
var DESCRIBE_EXPECTATION_FNS = {
literal: function(expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
"class": function(expectation) {
var escapedParts = "",
i;
for (i = 0; i < expectation.parts.length; i++) {
escapedParts += expectation.parts[i] instanceof Array
? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])
: classEscape(expectation.parts[i]);
}
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
},
any: function(expectation) {
return "any character";
},
end: function(expectation) {
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 = new Array(expected.length),
i, j;
for (i = 0; i < expected.length; i++) {
descriptions[i] = describeExpectation(expected[i]);
}
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(input, options) {
options = options !== void 0 ? options : {};
var peg$FAILED = {},
peg$startRuleFunctions = { start: peg$parsestart },
peg$startRuleFunction = peg$parsestart,
peg$c0 = function(result) {
return result
.flat(1)
.filter(x => !!x)
.filter((x) => Object.keys(x).length > 0)
.map((x) => Object.assign({action: 'upsert'}, x));
},
peg$c1 = peg$otherExpectation("Comment"),
peg$c2 = "//",
peg$c3 = peg$literalExpectation("//", false),
peg$c4 = /^[^\r\n]/,
peg$c5 = peg$classExpectation(["\r", "\n"], true, false),
peg$c6 = function() {
return null;
},
peg$c7 = "/*",
peg$c8 = peg$literalExpectation("/*", false),
peg$c9 = "*/",
peg$c10 = peg$literalExpectation("*/", false),
peg$c11 = peg$anyExpectation(),
peg$c12 = function(fullLine) {
let res = Object.assign({}, ...fullLine);
return res;
},
peg$c13 = peg$otherExpectation("Index"),
peg$c14 = "block",
peg$c15 = peg$literalExpectation("block", false),
peg$c16 = "namespace",
peg$c17 = peg$literalExpectation("namespace", false),
peg$c18 = "begin",
peg$c19 = peg$literalExpectation("begin", false),
peg$c20 = "end",
peg$c21 = peg$literalExpectation("end", false),
peg$c22 = "::",
peg$c23 = peg$literalExpectation("::", false),
peg$c24 = "*",
peg$c25 = peg$literalExpectation("*", false),
peg$c26 = function(space, id) {
if(id==='*'){
return { space };
}else{
return { id, space };
}
},
peg$c27 = peg$otherExpectation("Id"),
peg$c28 = function(id) {
if (id === '*') {
return {};
} else {
return { id };
}
},
peg$c29 = peg$otherExpectation("Action"),
peg$c30 = "#",
peg$c31 = peg$literalExpectation("#", false),
peg$c32 = function(action) {
return { action };
},
peg$c33 = peg$otherExpectation("Type"),
peg$c34 = "@",
peg$c35 = peg$literalExpectation("@", false),
peg$c36 = function(type) {
return { class: type[0].toUpperCase() + type.slice(1) }; // replace first letter to capital
},
peg$c37 = peg$otherExpectation("Title"),
peg$c38 = "'",
peg$c39 = peg$literalExpectation("'", false),
peg$c40 = /^[^']/,
peg$c41 = peg$classExpectation(["'"], true, false),
peg$c42 = function(title) {
return { title };
},
peg$c43 = peg$otherExpectation("Note"),
peg$c44 = "'''",
peg$c45 = peg$literalExpectation("'''", false),
peg$c46 = "!(''')",
peg$c47 = peg$literalExpectation("!(''')", false),
peg$c48 = "\\'",
peg$c49 = peg$literalExpectation("\\'", false),
peg$c50 = function(s) {
let notes = s
.map(x => x[1])
.join('')
.replace(/\\'/g, "'")
.replace(/\r/g, '');
return { notes };
},
peg$c51 = peg$otherExpectation("Dict"),
peg$c52 = "{",
peg$c53 = peg$literalExpectation("{", false),
peg$c54 = "}",
peg$c55 = peg$literalExpectation("}", false),
peg$c56 = function(item) {
let res = {};
item.forEach(([key, value]) => res[key] = value);
return res;
},
peg$c57 = ":",
peg$c58 = peg$literalExpectation(":", false),
peg$c59 = ",",
peg$c60 = peg$literalExpectation(",", false),
peg$c61 = function(key, value) {
return [key, value];
},
peg$c62 = peg$otherExpectation("Assignment"),
peg$c63 = function(sign, exprString) {
//console.log('= Assignment =')
let result = {};
let clearValue = typeof exprString === 'string' // remove multiple spaces, tabs and \t\r
? exprString.replace(/\s{2,}/g, ' ')
: exprString;
if (Array.isArray(sign)) {
// statement of type: []= transforms to ['[', null, ']']
// statement of type: [sw]= transforms to ['[', 'sw', ']']
if (sign[1]!==null) {
result.assignments = { [sign[1]]: clearValue }
} else {
result.assignments = { "start_": clearValue }
}
} else {
switch (sign) {
case "=":
result.num = clearValue;
break;
case ".=":
result.assignments = {"start_": clearValue};
break;
case ":=":
result.assignments = {"ode_": clearValue};
break;
case "`=": // currently this syntax is not used in Heta
result.assignments = {"ode_": clearValue};
break;
}
}
return result;
},
peg$c64 = peg$otherExpectation("Quoted String"),
peg$c65 = "\"",
peg$c66 = peg$literalExpectation("\"", false),
peg$c67 = /^[^"]/,
peg$c68 = peg$classExpectation(["\""], true, false),
peg$c69 = function(s) {
return s.join('');
},
peg$c70 = "\\\"",
peg$c71 = peg$literalExpectation("\\\"", false),
peg$c72 = function() {
return '"';
},
peg$c73 = peg$otherExpectation("Assignment String"),
peg$c74 = /^[^;{#@']/,
peg$c75 = peg$classExpectation([";", "{", "#", "@", "'"], true, false),
peg$c76 = function(s) {
let str = s.join('')
.replace(/[\s]+/g, ' ') // remove multiple spaces
.replace(/^ +/g, '') // remove leading spaces
.replace(/ +$/g, ''); // remove trailing spaces
let doubleRegExpr = /^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/;
if (str === 'null') {
return null;
} else if (str === 'true') {
return true;
} else if (str === 'false') {
return false;
} else if (doubleRegExpr.test(str)) {
return parseFloat(str);
} else {
return str;
}
},
peg$c77 = peg$otherExpectation("Include"),
peg$c78 = "include",
peg$c79 = peg$literalExpectation("include", false),
peg$c80 = "type",
peg$c81 = peg$literalExpectation("type", false),
peg$c82 = /^[a-zA-Z0-9]/,
peg$c83 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"]], false, false),
peg$c84 = "with",
peg$c85 = peg$literalExpectation("with", false),
peg$c86 = function(source, oftype, ofwith) {
let res = {
action: "include",
source: source
};
let type = oftype
? oftype[4].join('')
: undefined;
if(type) res.type = type;
let with_ = ofwith
? ofwith[3]
: undefined;
if(with_) Object.assign(res, with_);
return res;
},
peg$c87 = /^[a-zA-Z0-9.\-\/_\\]/,
peg$c88 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"], ".", "-", "/", "_", "\\"], false, false),
peg$c89 = function(fullLine, block) {
let blockObj = Object.assign({}, ...fullLine);
//let qArr = !block ? [] : block.map((x) => Object.assign({}, blockObj, x));
let qArr = block && block.filter((x) => Object.keys(x).length > 0)
.map((x) => Object.assign({}, blockObj, x));
return qArr;
},
peg$c90 = "abstract",
peg$c91 = peg$literalExpectation("abstract", false),
peg$c92 = "concrete",
peg$c93 = peg$literalExpectation("concrete", false),
peg$c94 = function(type, space, block) {
let q0 = { action: "setNS" };
if(space) q0.space = space;
if(type) q0.type = type;
let qArr = [q0];
block && block.filter((x) => Object.keys(x).length > 0).forEach((x) => {
let q = Object.assign({space: space}, x);
qArr.push(q);
});
return qArr;
},
peg$c95 = function(internal) {
return internal
.flat(1)
.filter(x => !!x);
},
peg$c96 = /^[A-Za-z_]/,
peg$c97 = peg$classExpectation([["A", "Z"], ["a", "z"], "_"], false, false),
peg$c98 = /^[A-Za-z0-9_]/,
peg$c99 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_"], false, false),
peg$c100 = function(symbol) {
return symbol;
},
peg$c101 = peg$otherExpectation("String"),
peg$c102 = /^[^,[\]{};]/,
peg$c103 = peg$classExpectation([",", "[", "]", "{", "}", ";"], true, false),
peg$c104 = function(s) {
let str = s.join('').trim()
if (str === 'null') {
res = null;
} else if (str === 'true') {
var res = true
} else if (str === 'false') {
res = false
} else if (/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/.test(str)){
res = parseFloat(str);
} else {
res = str;
}
return res;
},
peg$c105 = peg$otherExpectation("Array"),
peg$c106 = "[",
peg$c107 = peg$literalExpectation("[", false),
peg$c108 = "]",
peg$c109 = peg$literalExpectation("]", false),
peg$c110 = function(items) {
return items.reduce((result, x) => {
result.push(x);
return result;
},[]);
},
peg$c111 = peg$otherExpectation("ArrayValue"),
peg$c112 = function(value) {
return value;
},
peg$c113 = "=",
peg$c114 = peg$literalExpectation("=", false),
peg$c115 = ":=",
peg$c116 = peg$literalExpectation(":=", false),
peg$c117 = ".=",
peg$c118 = peg$literalExpectation(".=", false),
peg$c119 = "`=",
peg$c120 = peg$literalExpectation("`=", false),
peg$c121 = "]=",
peg$c122 = peg$literalExpectation("]=", false),
peg$c123 = /^[@]/,
peg$c124 = peg$classExpectation(["@"], false, false),
peg$c125 = /^[']/,
peg$c126 = peg$classExpectation(["'"], false, false),
peg$c127 = peg$otherExpectation("Space"),
peg$c128 = /^[ \t\u202F\xA0\u2000\u2001\u2003]/,
peg$c129 = peg$classExpectation([" ", "\t", "\u202F", "\xA0", "\u2000", "\u2001", "\u2003"], false, false),
peg$c130 = function() {
return null;
},
peg$c131 = ";",
peg$c132 = peg$literalExpectation(";", false),
peg$c133 = /^["]/,
peg$c134 = peg$classExpectation(["\""], false, false),
peg$c135 = peg$otherExpectation("Break"),
peg$c136 = /^[\r]/,
peg$c137 = peg$classExpectation(["\r"], false, false),
peg$c138 = /^[\n]/,
peg$c139 = peg$classExpectation(["\n"], false, false),
peg$c140 = function() {
return null
},
peg$currPos = 0,
peg$savedPos = 0,
peg$posDetailsCache = [{ line: 1, column: 1 }],
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, location) {
location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
throw peg$buildStructuredError(
[peg$otherExpectation(description)],
input.substring(peg$savedPos, peg$currPos),
location
);
}
function error(message, location) {
location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos)
throw peg$buildSimpleError(message, location);
}
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$anyExpectation() {
return { type: "any" };
}
function peg$endExpectation() {
return { type: "end" };
}
function peg$otherExpectation(description) {
return { type: "other", description: description };
}
function peg$computePosDetails(pos) {
var details = peg$posDetailsCache[pos], p;
if (details) {
return details;
} else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
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) {
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$buildSimpleError(message, location) {
return new peg$SyntaxError(message, null, null, location);
}
function peg$buildStructuredError(expected, found, location) {
return new peg$SyntaxError(
peg$SyntaxError.buildMessage(expected, found),
expected,
found,
location
);
}
function peg$parsestart() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = [];
s2 = peg$parseComment();
if (s2 === peg$FAILED) {
s2 = peg$parseBlock();
if (s2 === peg$FAILED) {
s2 = peg$parseInclude();
if (s2 === peg$FAILED) {
s2 = peg$parseBaseStruct();
if (s2 === peg$FAILED) {
s2 = peg$parseNamespaceBlock();
}
}
}
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parseComment();
if (s2 === peg$FAILED) {
s2 = peg$parseBlock();
if (s2 === peg$FAILED) {
s2 = peg$parseInclude();
if (s2 === peg$FAILED) {
s2 = peg$parseBaseStruct();
if (s2 === peg$FAILED) {
s2 = peg$parseNamespaceBlock();
}
}
}
}
}
} else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parseBreak();
if (s3 === peg$FAILED) {
s3 = peg$parseSpace();
}
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parseBreak();
if (s3 === peg$FAILED) {
s3 = peg$parseSpace();
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0(s1);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseComment() {
var s0, s1;
peg$silentFails++;
s0 = peg$parseMultylineComment();
if (s0 === peg$FAILED) {
s0 = peg$parseLineComment();
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c1); }
}
return s0;
}
function peg$parseLineComment() {
var s0, s1, s2, s3, s4;
s0 = peg$currPos;
s1 = [];
s2 = peg$parseBreak();
if (s2 === peg$FAILED) {
s2 = peg$parseSpace();
}
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parseBreak();
if (s2 === peg$FAILED) {
s2 = peg$parseSpace();
}
}
if (s1 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c2) {
s2 = peg$c2;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c3); }
}
if (s2 !== peg$FAILED) {
s3 = [];
if (peg$c4.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c5); }
}
while (s4 !== peg$FAILED) {
s3.push(s4);
if (peg$c4.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c5); }
}
}
if (s3 !== peg$FAILED) {
s4 = peg$parseBreak();
if (s4 === peg$FAILED) {
s4 = null;
}
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6();
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$parseMultylineComment() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = [];
s2 = peg$parseSpace();
if (s2 === peg$FAILED) {
s2 = peg$parseBreak();
}
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parseSpace();
if (s2 === peg$FAILED) {
s2 = peg$parseBreak();
}
}
if (s1 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c7) {
s2 = peg$c7;
peg$currPos += 2;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c8); }
}
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$currPos;
s5 = peg$currPos;
peg$silentFails++;
if (input.substr(peg$currPos, 2) === peg$c9) {
s6 = peg$c9;
peg$currPos += 2;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c10); }
}
peg$silentFails--;
if (s6 === peg$FAILED) {
s5 = void 0;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
if (s5 !== peg$FAILED) {
if (input.length > peg$currPos) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c11); }
}
if (s6 !== peg$FAILED) {
s5 = [s5, s6];
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$currPos;
s5 = peg$currPos;
peg$silentFails++;
if (input.substr(peg$currPos, 2) === peg$c9) {
s6 = peg$c9;
peg$currPos += 2;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c10); }
}
peg$silentFails--;
if (s6 === peg$FAILED) {
s5 = void 0;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
if (s5 !== peg$FAILED) {
if (input.length > peg$currPos) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c11); }
}
if (s6 !== peg$FAILED) {
s5 = [s5, s6];
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
}
if (s3 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c9) {
s4 = peg$c9;
peg$currPos += 2;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c10); }
}
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6();
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$parseBaseStruct() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
s2 = peg$parseSpace();
if (s2 === peg$FAILED) {
s2 = peg$parseBreak();
if (s2 === peg$FAILED) {
s2 = peg$parseNote();
if (s2 === peg$FAILED) {
s2 = peg$parseId();
if (s2 === peg$FAILED) {
s2 = peg$parseIndex();
if (s2 === peg$FAILED) {
s2 = peg$parseAction();
if (s2 === peg$FAILED) {
s2 = peg$parseType();
if (s2 === peg$FAILED) {
s2 = peg$parseTitle();
if (s2 === peg$FAILED) {
s2 = peg$parseDict();
if (s2 === peg$FAILED) {
s2 = peg$parseAssignment();
if (s2 === peg$FAILED) {
s2 = peg$parseMultylineComment();
if (s2 === peg$FAILED) {
s2 = peg$parseLineComment();
}
}
}
}
}
}
}
}
}
}
}
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parseSpace();
if (s2 === peg$FAILED) {
s2 = peg$parseBreak();
if (s2 === peg$FAILED) {
s2 = peg$parseNote();
if (s2 === peg$FAILED) {
s2 = peg$parseId();
if (s2 === peg$FAILED) {
s2 = peg$parseIndex();
if (s2 === peg$FAILED) {
s2 = peg$parseAction();
if (s2 === peg$FAILED) {
s2 = peg$parseType();
if (s2 === peg$FAILED) {
s2 = peg$parseTitle();
if (s2 === peg$FAILED) {
s2 = peg$parseDict();
if (s2 === peg$FAILED) {
s2 = peg$parseAssignment();
if (s2 === peg$FAILED) {
s2 = peg$parseMultylineComment();
if (s2 === peg$FAILED) {
s2 = peg$parseLineComment();
}
}
}
}
}
}
}
}
}
}
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parseEndSign();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c12(s1);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseIndex() {
var s0, s1, s2, s3, s4, s5;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$currPos;
if (input.substr(peg$currPos, 5) === peg$c14) {
s3 = peg$c14;
peg$currPos += 5;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c15); }
}
if (s3 === peg$FAILED) {
if (input.substr(peg$currPos, 9) === peg$c16) {
s3 = peg$c16;
peg$currPos += 9;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
if (s3 === peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c18) {
s3 = peg$c18;
peg$currPos += 5;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c19); }
}
if (s3 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c20) {
s3 = peg$c20;
peg$currPos += 3;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c21); }
}
}
}
}
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parseSpace();
if (s5 === peg$FAILED) {
s5 = peg$parseBreak();
}
if (s5 !== peg$FAILED) {
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parseSpace();
if (s5 === peg$FAILED) {
s5 = peg$parseBreak();
}
}
} else {
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = void 0;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parseKeyName();
if (s2 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c22) {
s3 = peg$c22;
peg$currPos += 2;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c23); }
}
if (s3 !== peg$FAILED) {
s4 = peg$parseKeyName();
if (s4 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 42) {
s4 = peg$c24;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c25); }
}
}
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c26(s2, s4);
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;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c13); }
}
return s0;
}
function peg$parseId() {
var s0, s1, s2, s3, s4, s5, s6;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$currPos;
peg$silentFails++;
s2 = peg$currPos;
if (input.substr(peg$currPos, 5) === peg$c14) {
s3 = peg$c14;
peg$currPos += 5;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c15); }
}
if (s3 === peg$FAILED) {
if (input.substr(peg$currPos, 9) === peg$c16) {
s3 = peg$c16;
peg$currPos += 9;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
if (s3 === peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c18) {
s3 = peg$c18;
peg$currPos += 5;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c19); }
}
if (s3 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c20) {
s3 = peg$c20;
peg$currPos += 3;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c21); }
}
}
}
}
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parseSpace();
if (s5 === peg$FAILED) {
s5 = peg$parseBreak();
}
if (s5 !== peg$FAILED) {
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parseSpace();
if (s5 === peg$FAILED) {
s5 = peg$parseBreak();
}
}
} else {
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
s3 = [s3, s4];
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
peg$silentFails--;
if (s2 === peg$FAILED) {
s1 = void 0;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
s2 = peg$parseKeyName();
if (s2 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 42) {
s2 = peg$c24;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c25); }
}
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
peg$silentFails++;
s4 = peg$currPos;
s5 = [];
s6 = peg$parseSpace();
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parseSpace();
}
if (s5 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c22) {
s6 = peg$c22;
peg$currPos += 2;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c23); }
}
if (s6 !== peg$FAILED) {
s5 = [s5, s6];
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
peg$silentFails--;
if (s4 === peg$FAILED) {
s3 = void 0;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c28(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} 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$c27); }
}
return s0;
}
function peg$parseAction() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 35) {
s1 = peg$c30;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c31); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parseKeyName();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c32(s2);
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$c29); }
}
return s0;
}
function peg$parseType() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 64) {
s1 = peg$c34;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c35); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parseKeyName();
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c36(s2);
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$c33); }
}
return s0;
}
function peg$parseTitle() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 39) {
s1 = peg$c38;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c39); }
}
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
s3 = [];
if (peg$c40.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c41); }
}
if (s4 !== peg$FAILED) {
while (s4 !== peg$FAILED) {
s3.push(s4);
if (peg$c40.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c41); }
}
}
} else {
s3 = peg$FAILED;
}
if (s3 !== peg$FAILED) {
s2 = input.substring(s2, peg$currPos);
} else {
s2 = s3;
}
if (s2 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 39) {
s3 = peg$c38;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c39); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c42(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} 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$c37); }
}
return s0;
}
function peg$parseNote() {
var s0, s1, s2, s3, s4, s5;
peg$silentFails++;
s0 = peg$currPos;
if (input.substr(peg$currPos, 3) === peg$c44) {
s1 = peg$c44;
peg$currPos += 3;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c45); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
s4 = peg$currPos;
peg$silentFails++;
if (input.substr(peg$currPos, 6) === peg$c46) {
s5 = peg$c46;
peg$currPos += 6;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c47); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c48) {
s5 = peg$c48;
peg$currPos += 2;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c49); }
}
if (s5 === peg$FAILED) {
if (peg$c40.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c41); }
}
}
if (s5 !== peg$FAILED) {
s4 = [s4, 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++;
if (input.substr(peg$currPos, 6) === peg$c46) {
s5 = peg$c46;
peg$currPos += 6;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c47); }
}
peg$silentFails--;
if (s5 === peg$FAILED) {
s4 = void 0;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
if (s4 !== peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c48) {
s5 = peg$c48;
peg$currPos += 2;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c49); }
}
if (s5 === peg$FAILED) {
if (peg$c40.test(input.charAt(peg$currPos))) {
s5 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c41); }
}
}
if (s5 !== peg$FAILED) {
s4 = [s4, 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) {
if (input.substr(peg$currPos, 3) === peg$c44) {
s3 = peg$c44;
peg$currPos += 3;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c45); }
}
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parseBreak();
if (s5 === peg$FAILED) {
s5 = peg$parseSpace();
}
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parseBreak();
if (s5 === peg$FAILED) {
s5 = peg$parseSpace();
}
}
if (s4 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c50(s2);
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;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c43); }
}
return s0;
}
function peg$parseDict() {
var s0, s1, s2, s3, s4, s5;
peg$silentFails++;
s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 123) {
s1 = peg$c52;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c53); }
}
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parseBreak();
if (s3 === peg$FAILED) {
s3 = peg$parseSpace();
if (s3 === peg$FAILED) {
s3 = peg$parseComment();
}
}
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parseBreak();
if (s3 === peg$FAILED) {
s3 = peg$parseSpace();
if (s3 === peg$FAILED) {
s3 = peg$parseComment();
}
}
}
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parseDictPair();
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parseDictPair();
}
if (s3 !== peg$FAILED) {
s4 = [];
s5 = peg$parseBreak();
if (s5 === peg$FAILED) {
s5 = peg$parseSpace();
if (s5 === peg$FAILED) {
s5 = peg$parseComment();
}
}
while (s5 !== peg$FAILED) {
s4.push(s5);
s5 = peg$parseBreak();
if (s5 === peg$FAILED) {
s5 = peg$parseSpace();
if (s5 === peg$FAILED) {
s5 = peg$parseComment();
}
}
}
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 125) {
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;
}
peg$silentFails--;
if (s0 === peg$FAILED) {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c51); }
}
return s0;
}
function peg$parseDictPair() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
s0 = peg$currPos;
s1 = [];
s2 = peg$parseBreak();
if (s2 === peg$FAILED) {
s2 = peg$parseSpace();
}
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parseBreak();
if (s2 === peg$FAILED) {
s2 = peg$parseSpace();
}
}
if (s1 !== peg$FAILED) {
s2 = peg$parseKeyName();
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parseBreak();
if (s4 === peg$FAILED) {
s4 = peg$parseSpace();
}
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parseBreak();
if (s4 === peg$FAILED) {
s4 = peg$parseSpace();
}
}
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 = [];
s6 = peg$parseBreak();
if (s6 === peg$FAILED) {
s6 = peg$parseSpace();
}
while (s6 !== peg$FAILED) {
s5.push(s6);
s6 = peg$parseBreak();
if (s6 === peg$FAILED) {
s6 = peg$parseSpace();
}
}
if (s5 !== peg$FAILED) {
s6 = peg$parseValueTypes();
if (s6 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s7 = peg$c59;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c60); }
}
if (s7 === peg$FAILED) {
s7 = null;
}
if (s7 !== peg$FAILED) {
s8 = [];
s9 = peg$parseComment();
while (s9 !== peg$FAILED) {
s8.push(s9);
s9 = peg$parseComment();
}
if (s8 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c61(s2, s6);
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;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseAssignment() {
var s0, s1, s2;
peg$silentFails++;
s0 = peg$currPos;
s1 = peg$parseSignAssignment();
if (s1 !== peg$FAILED) {
s2 = peg$parseQuotedString();
if (s2 === peg$FAILED) {
s2 = peg$parseAssignString();
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c63(s1, s2);
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$c62); }
}
return s0;
}
function peg$parseQuotedString() {
var s0, s1, s2, s3, s4;
peg$silentFails++;
s0 = peg$currPos;
s1 = [];
s2 = peg$parseBreak();
if (s2 === peg$FAILED) {
s2 = peg$parseSpace();
}
while (s2 !== peg$FAILED) {
s1.push(s2);
s2 = peg$parseBreak();
if (s2 === peg$FAILED) {
s2 = peg$parseSpace();
}
}
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 34) {
s2 = peg$c65;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c66); }
}
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$parseescapedQuote();
if (s4 === peg$FAILED) {
if (peg$c67.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c68); }
}
}
while (s4 !== peg$FAILED) {
s3.push(s4);
s4 = peg$parseescapedQuote();
if (s4 === peg$FAILED) {
if (peg$c67.test(input.charAt(peg$currPos))) {
s4 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c68); }
}
}