mongodb-language-model
Version:
Parses MongoDB query language and returns an abstract syntax tree
1,748 lines (1,633 loc) • 222 kB
JavaScript
/*
* Generated by PEG.js 0.10.0.
*
* http://pegjs.org/
*/
"use strict";
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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 literal(expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
"class": function _class(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 any(expectation) {
return "any character";
},
end: function end(expectation) {
return "end of input";
},
other: function other(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 = { query: peg$parsequery },
peg$startRuleFunction = peg$parsequery,
peg$c0 = function peg$c0(clauses) {
return { pos: "expression", clauses: clauses !== null ? clauses : [] };
},
peg$c1 = function peg$c1(head, c) {
return c;
},
peg$c2 = function peg$c2(head, tail) {
return [head].concat(tail);
},
peg$c3 = function peg$c3(text_options) {
return { pos: "text-clause", search: text_options.search };
},
peg$c4 = function peg$c4(search) {
return { search: search };
},
peg$c5 = function peg$c5(value) {
return { value: value };
},
peg$c6 = function peg$c6(operator, expressions) {
return { pos: "expression-tree-clause", operator: operator, expressions: expressions };
},
peg$c7 = "$or",
peg$c8 = peg$literalExpectation("$or", false),
peg$c9 = "$nor",
peg$c10 = peg$literalExpectation("$nor", false),
peg$c11 = "$and",
peg$c12 = peg$literalExpectation("$and", false),
peg$c13 = function peg$c13(head, e) {
return e;
},
peg$c14 = function peg$c14(expressions) {
return expressions !== null ? expressions : [];
},
peg$c15 = function peg$c15(value) {
return { pos: "where-clause", type: "string", value: value };
},
peg$c16 = function peg$c16(key, value) {
return { pos: "leaf-clause", key: key, value: value };
},
peg$c17 = "$gte",
peg$c18 = peg$literalExpectation("$gte", false),
peg$c19 = "$gt",
peg$c20 = peg$literalExpectation("$gt", false),
peg$c21 = "$lte",
peg$c22 = peg$literalExpectation("$lte", false),
peg$c23 = "$lt",
peg$c24 = peg$literalExpectation("$lt", false),
peg$c25 = "$eq",
peg$c26 = peg$literalExpectation("$eq", false),
peg$c27 = "$ne",
peg$c28 = peg$literalExpectation("$ne", false),
peg$c29 = "$type",
peg$c30 = peg$literalExpectation("$type", false),
peg$c31 = "$size",
peg$c32 = peg$literalExpectation("$size", false),
peg$c33 = "$exists",
peg$c34 = peg$literalExpectation("$exists", false),
peg$c35 = "$bitsAllClear",
peg$c36 = peg$literalExpectation("$bitsAllClear", false),
peg$c37 = "$bitsAllSet",
peg$c38 = peg$literalExpectation("$bitsAllSet", false),
peg$c39 = "$bitsAnyClear",
peg$c40 = peg$literalExpectation("$bitsAnyClear", false),
peg$c41 = "$bitsAnySet",
peg$c42 = peg$literalExpectation("$bitsAnySet", false),
peg$c43 = "$in",
peg$c44 = peg$literalExpectation("$in", false),
peg$c45 = "$nin",
peg$c46 = peg$literalExpectation("$nin", false),
peg$c47 = "$all",
peg$c48 = peg$literalExpectation("$all", false),
peg$c49 = "$mod",
peg$c50 = peg$literalExpectation("$mod", false),
peg$c51 = "$not",
peg$c52 = peg$literalExpectation("$not", false),
peg$c53 = "$elemMatch",
peg$c54 = peg$literalExpectation("$elemMatch", false),
peg$c55 = function peg$c55(operators) {
return { pos: "operator-expression", operators: operators !== null ? operators : [] };
},
peg$c56 = function peg$c56(head, o) {
return o;
},
peg$c57 = function peg$c57(operator, value) {
return { pos: "value-operator", operator: operator, value: value };
},
peg$c58 = function peg$c58(operator, values) {
return { pos: "list-operator", operator: operator, values: values };
},
peg$c59 = function peg$c59(expression) {
return { pos: "elemmatch-expression-operator", expression: expression };
},
peg$c60 = function peg$c60(operator, opobject) {
return { pos: "operator-expression-operator", operator: operator, operators: opobject.operators };
},
peg$c61 = "$geoWithin",
peg$c62 = peg$literalExpectation("$geoWithin", false),
peg$c63 = function peg$c63(shape) {
return { pos: "geo-within-operator", operator: "$geoWithin", shape: shape };
},
peg$c64 = "$geoIntersects",
peg$c65 = peg$literalExpectation("$geoIntersects", false),
peg$c66 = function peg$c66(geometry) {
return { pos: "geo-intersects-operator", operator: "$geoIntersects", geometry: geometry };
},
peg$c67 = "$nearSphere",
peg$c68 = peg$literalExpectation("$nearSphere", false),
peg$c69 = "$near",
peg$c70 = peg$literalExpectation("$near", false),
peg$c71 = function peg$c71(near_operator, value) {
return { pos: "near-operator", operator: near_operator, value: value };
},
peg$c72 = function peg$c72(operator, value) {
return { pos: "distance-operator", operator: operator, value: value };
},
peg$c73 = "$minDistance",
peg$c74 = peg$literalExpectation("$minDistance", false),
peg$c75 = "$maxDistance",
peg$c76 = peg$literalExpectation("$maxDistance", false),
peg$c77 = "$geometry",
peg$c78 = peg$literalExpectation("$geometry", false),
peg$c79 = "type",
peg$c80 = peg$literalExpectation("type", false),
peg$c81 = function peg$c81(type) {
return type;
},
peg$c82 = "coordinates",
peg$c83 = peg$literalExpectation("coordinates", false),
peg$c84 = function peg$c84(type, coordinates) {
return coordinates;
},
peg$c85 = function peg$c85(type, coordinates) {
return { "type": type, "coordinates": coordinates };
},
peg$c86 = function peg$c86(members) {
return { "$geometry": members };
},
peg$c87 = "Point",
peg$c88 = peg$literalExpectation("Point", false),
peg$c89 = function peg$c89(geometry, operator, value) {
return _defineProperty({}, operator, value);
},
peg$c90 = function peg$c90(geometry, distance) {
return _extends({
"$geometry": geometry
}, distance ? distance : {});
},
peg$c91 = "Polygon",
peg$c92 = peg$literalExpectation("Polygon", false),
peg$c93 = "MultiPolygon",
peg$c94 = peg$literalExpectation("MultiPolygon", false),
peg$c95 = function peg$c95(head, v) {
return v;
},
peg$c96 = "$centerSphere",
peg$c97 = peg$literalExpectation("$centerSphere", false),
peg$c98 = "$center",
peg$c99 = peg$literalExpectation("$center", false),
peg$c100 = function peg$c100(center_operator, parameters) {
var res = {};
res[center_operator] = JSON.parse(parameters);
return res;
},
peg$c101 = "$box",
peg$c102 = peg$literalExpectation("$box", false),
peg$c103 = function peg$c103(parameters) {
return { "$box": JSON.parse(parameters) };
},
peg$c104 = "$polygon",
peg$c105 = peg$literalExpectation("$polygon", false),
peg$c106 = function peg$c106(parameters) {
return { "$polygon": JSON.parse(parameters) };
},
peg$c107 = "$where",
peg$c108 = peg$literalExpectation("$where", false),
peg$c109 = "$text",
peg$c110 = peg$literalExpectation("$text", false),
peg$c111 = "$search",
peg$c112 = peg$literalExpectation("$search", false),
peg$c113 = "$language",
peg$c114 = peg$literalExpectation("$language", false),
peg$c115 = "$caseSensitive",
peg$c116 = peg$literalExpectation("$caseSensitive", false),
peg$c117 = "$diacriticSensitive",
peg$c118 = peg$literalExpectation("$diacriticSensitive", false),
peg$c119 = function peg$c119(values) {
return values !== null ? values : [];
},
peg$c120 = /^[^$]/,
peg$c121 = peg$classExpectation(["$"], true, false),
peg$c122 = /^[^\0"]/,
peg$c123 = peg$classExpectation(["\0", "\""], true, false),
peg$c124 = function peg$c124(key) {
return key[0] + key[1].join('');
},
peg$c125 = function peg$c125(value) {
return { pos: 'leaf-value', value: value };
},
peg$c126 = "[",
peg$c127 = peg$literalExpectation("[", false),
peg$c128 = "{",
peg$c129 = peg$literalExpectation("{", false),
peg$c130 = "]",
peg$c131 = peg$literalExpectation("]", false),
peg$c132 = "}",
peg$c133 = peg$literalExpectation("}", false),
peg$c134 = ":",
peg$c135 = peg$literalExpectation(":", false),
peg$c136 = ",",
peg$c137 = peg$literalExpectation(",", false),
peg$c138 = peg$otherExpectation("whitespace"),
peg$c139 = /^[ \t\n\r]/,
peg$c140 = peg$classExpectation([" ", "\t", "\n", "\r"], false, false),
peg$c141 = "false",
peg$c142 = peg$literalExpectation("false", false),
peg$c143 = function peg$c143() {
return false;
},
peg$c144 = "null",
peg$c145 = peg$literalExpectation("null", false),
peg$c146 = function peg$c146() {
return null;
},
peg$c147 = "true",
peg$c148 = peg$literalExpectation("true", false),
peg$c149 = function peg$c149() {
return true;
},
peg$c150 = "$oid",
peg$c151 = peg$literalExpectation("$oid", false),
peg$c152 = function peg$c152(string) {
return { "$oid": string };
},
peg$c153 = function peg$c153(digits) {
return digits.join('');
},
peg$c154 = "$minKey",
peg$c155 = peg$literalExpectation("$minKey", false),
peg$c156 = "1",
peg$c157 = peg$literalExpectation("1", false),
peg$c158 = function peg$c158() {
return { "$minKey": 1 };
},
peg$c159 = "$maxKey",
peg$c160 = peg$literalExpectation("$maxKey", false),
peg$c161 = function peg$c161() {
return { "$maxKey": 1 };
},
peg$c162 = "$numberLong",
peg$c163 = peg$literalExpectation("$numberLong", false),
peg$c164 = function peg$c164(digits) {
return { "$numberLong": digits.join('') };
},
peg$c165 = "$numberDecimal",
peg$c166 = peg$literalExpectation("$numberDecimal", false),
peg$c167 = function peg$c167(number) {
return { "$numberDecimal": number };
},
peg$c168 = "$date",
peg$c169 = peg$literalExpectation("$date", false),
peg$c170 = function peg$c170(date) {
return { "$date": date };
},
peg$c171 = function peg$c171(date) {
return date;
},
peg$c172 = "$undefined",
peg$c173 = peg$literalExpectation("$undefined", false),
peg$c174 = function peg$c174() {
return { "$undefined": true };
},
peg$c175 = "$ref",
peg$c176 = peg$literalExpectation("$ref", false),
peg$c177 = function peg$c177(string) {
return string;
},
peg$c178 = "$id",
peg$c179 = peg$literalExpectation("$id", false),
peg$c180 = function peg$c180(ref, value) {
return value;
},
peg$c181 = "$db",
peg$c182 = peg$literalExpectation("$db", false),
peg$c183 = function peg$c183(ref, id, string) {
return string;
},
peg$c184 = function peg$c184(ref, id, db) {
var result = { "$ref": ref, "$id": id };
if (db !== null) result["$db"] = db;
return result;
},
peg$c185 = function peg$c185(members) {
return members;
},
peg$c186 = "$regex",
peg$c187 = peg$literalExpectation("$regex", false),
peg$c188 = "$options",
peg$c189 = peg$literalExpectation("$options", false),
peg$c190 = /^[gims]/,
peg$c191 = peg$classExpectation(["g", "i", "m", "s"], false, false),
peg$c192 = function peg$c192(regex, options) {
return options.join('');
},
peg$c193 = function peg$c193(regex, options) {
return { "$regex": regex, "$options": options ? options : "" };
},
peg$c194 = "$binary",
peg$c195 = peg$literalExpectation("$binary", false),
peg$c196 = function peg$c196(binary, type) {
return type;
},
peg$c197 = function peg$c197(binary, type) {
return { "$binary": binary, "$type": type };
},
peg$c198 = "$timestamp",
peg$c199 = peg$literalExpectation("$timestamp", false),
peg$c200 = "t",
peg$c201 = peg$literalExpectation("t", false),
peg$c202 = "i",
peg$c203 = peg$literalExpectation("i", false),
peg$c204 = function peg$c204(t, i) {
return { "t": t, "i": i };
},
peg$c205 = function peg$c205(object) {
return { "$timestamp": object };
},
peg$c206 = function peg$c206(head, m) {
return m;
},
peg$c207 = function peg$c207(head, tail) {
var result = {};
[head].concat(tail).forEach(function (element) {
result[element.name] = element.value;
});
return result;
},
peg$c208 = function peg$c208(members) {
return members !== null ? members : {};
},
peg$c209 = function peg$c209(name, value) {
return { name: name, value: value };
},
peg$c210 = peg$otherExpectation("number"),
peg$c211 = function peg$c211() {
return parseFloat(text());
},
peg$c212 = "180",
peg$c213 = peg$literalExpectation("180", false),
peg$c214 = /^[0-7]/,
peg$c215 = peg$classExpectation([["0", "7"]], false, false),
peg$c216 = "90",
peg$c217 = peg$literalExpectation("90", false),
peg$c218 = ".",
peg$c219 = peg$literalExpectation(".", false),
peg$c220 = /^[1-9]/,
peg$c221 = peg$classExpectation([["1", "9"]], false, false),
peg$c222 = /^[eE]/,
peg$c223 = peg$classExpectation(["e", "E"], false, false),
peg$c224 = "-",
peg$c225 = peg$literalExpectation("-", false),
peg$c226 = "+",
peg$c227 = peg$literalExpectation("+", false),
peg$c228 = "0",
peg$c229 = peg$literalExpectation("0", false),
peg$c230 = peg$otherExpectation("string"),
peg$c231 = function peg$c231(chars) {
return chars.join("");
},
peg$c232 = "\"",
peg$c233 = peg$literalExpectation("\"", false),
peg$c234 = "\\",
peg$c235 = peg$literalExpectation("\\", false),
peg$c236 = "/",
peg$c237 = peg$literalExpectation("/", false),
peg$c238 = "b",
peg$c239 = peg$literalExpectation("b", false),
peg$c240 = function peg$c240() {
return "\b";
},
peg$c241 = "f",
peg$c242 = peg$literalExpectation("f", false),
peg$c243 = function peg$c243() {
return "\f";
},
peg$c244 = "n",
peg$c245 = peg$literalExpectation("n", false),
peg$c246 = function peg$c246() {
return "\n";
},
peg$c247 = "r",
peg$c248 = peg$literalExpectation("r", false),
peg$c249 = function peg$c249() {
return "\r";
},
peg$c250 = function peg$c250() {
return "\t";
},
peg$c251 = "u",
peg$c252 = peg$literalExpectation("u", false),
peg$c253 = function peg$c253(digits) {
return String.fromCharCode(parseInt(digits, 16));
},
peg$c254 = function peg$c254(sequence) {
return sequence;
},
peg$c255 = /^[^\0-\x1F"\\]/,
peg$c256 = peg$classExpectation([["\0", "\x1F"], "\"", "\\"], true, false),
peg$c257 = /^[0-9]/,
peg$c258 = peg$classExpectation([["0", "9"]], false, false),
peg$c259 = /^[0-9a-f]/i,
peg$c260 = peg$classExpectation([["0", "9"], ["a", "f"]], false, true),
peg$c261 = "--",
peg$c262 = peg$literalExpectation("--", false),
peg$c263 = "W",
peg$c264 = peg$literalExpectation("W", false),
peg$c265 = "---",
peg$c266 = peg$literalExpectation("---", false),
peg$c267 = "Z",
peg$c268 = peg$literalExpectation("Z", false),
peg$c269 = "T",
peg$c270 = peg$literalExpectation("T", false),
peg$c271 = "S",
peg$c272 = peg$literalExpectation("S", false),
peg$c273 = "M",
peg$c274 = peg$literalExpectation("M", false),
peg$c275 = "H",
peg$c276 = peg$literalExpectation("H", false),
peg$c277 = "D",
peg$c278 = peg$literalExpectation("D", false),
peg$c279 = "Y",
peg$c280 = peg$literalExpectation("Y", false),
peg$c281 = "P",
peg$c282 = peg$literalExpectation("P", false),
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$parsequery() {
var s0;
s0 = peg$parseexpression();
return s0;
}
function peg$parseexpression() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parsebegin_object();
if (s1 !== peg$FAILED) {
s2 = peg$parseclause_list();
if (s2 !== peg$FAILED) {
s3 = peg$parseend_object();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c0(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$parseclause_list() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$parseclause();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
s4 = peg$parsevalue_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parseclause();
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c1(s1, 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;
s4 = peg$parsevalue_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parseclause();
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c1(s1, s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c2(s1, s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = null;
}
return s0;
}
function peg$parseclause() {
var s0;
s0 = peg$parseleaf_clause();
if (s0 === peg$FAILED) {
s0 = peg$parseexpression_tree_clause();
if (s0 === peg$FAILED) {
s0 = peg$parsewhere_clause();
if (s0 === peg$FAILED) {
s0 = peg$parsetext_clause();
}
}
}
return s0;
}
function peg$parsetext_clause() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$parsequotation_mark();
if (s1 !== peg$FAILED) {
s2 = peg$parsetext_operator();
if (s2 !== peg$FAILED) {
s3 = peg$parsequotation_mark();
if (s3 !== peg$FAILED) {
s4 = peg$parsename_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parsetext_options();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c3(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$parsetext_options() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
s0 = peg$currPos;
s1 = peg$parsebegin_object();
if (s1 !== peg$FAILED) {
s2 = peg$parsequotation_mark();
if (s2 !== peg$FAILED) {
s3 = peg$parsesearch_operator();
if (s3 !== peg$FAILED) {
s4 = peg$parsequotation_mark();
if (s4 !== peg$FAILED) {
s5 = peg$parsename_separator();
if (s5 !== peg$FAILED) {
s6 = peg$parsestring();
if (s6 !== peg$FAILED) {
s7 = peg$currPos;
s8 = peg$parsevalue_separator();
if (s8 !== peg$FAILED) {
s9 = peg$parsetext_options_optional();
if (s9 !== peg$FAILED) {
s8 = [s8, s9];
s7 = s8;
} else {
peg$currPos = s7;
s7 = peg$FAILED;
}
} else {
peg$currPos = s7;
s7 = peg$FAILED;
}
if (s7 === peg$FAILED) {
s7 = null;
}
if (s7 !== peg$FAILED) {
s8 = peg$parseend_object();
if (s8 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c4(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$parsetext_options_value() {
var s0;
s0 = peg$parsestring();
if (s0 === peg$FAILED) {
s0 = peg$parsetrue();
if (s0 === peg$FAILED) {
s0 = peg$parsefalse();
}
}
return s0;
}
function peg$parsetext_options_optional() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = [];
s1 = peg$currPos;
s2 = peg$parsequotation_mark();
if (s2 !== peg$FAILED) {
s3 = peg$parsetext_optional_operator();
if (s3 !== peg$FAILED) {
s4 = peg$parsequotation_mark();
if (s4 !== peg$FAILED) {
s5 = peg$parsename_separator();
if (s5 !== peg$FAILED) {
s6 = peg$parsetext_options_value();
if (s6 !== peg$FAILED) {
peg$savedPos = s1;
s2 = peg$c5(s6);
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
while (s1 !== peg$FAILED) {
s0.push(s1);
s1 = peg$currPos;
s2 = peg$parsequotation_mark();
if (s2 !== peg$FAILED) {
s3 = peg$parsetext_optional_operator();
if (s3 !== peg$FAILED) {
s4 = peg$parsequotation_mark();
if (s4 !== peg$FAILED) {
s5 = peg$parsename_separator();
if (s5 !== peg$FAILED) {
s6 = peg$parsetext_options_value();
if (s6 !== peg$FAILED) {
peg$savedPos = s1;
s2 = peg$c5(s6);
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
}
return s0;
}
function peg$parseexpression_tree_clause() {
var s0, s1, s2, s3, s4, s5, s6, s7;
s0 = peg$currPos;
s1 = peg$parsequotation_mark();
if (s1 !== peg$FAILED) {
s2 = peg$parseexpression_tree_operator();
if (s2 !== peg$FAILED) {
s3 = peg$parsequotation_mark();
if (s3 !== peg$FAILED) {
s4 = peg$parsename_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parsebegin_array();
if (s5 !== peg$FAILED) {
s6 = peg$parseexpression_list();
if (s6 !== peg$FAILED) {
s7 = peg$parseend_array();
if (s7 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(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;
}
return s0;
}
function peg$parseexpression_tree_operator() {
var s0;
if (input.substr(peg$currPos, 3) === peg$c7) {
s0 = peg$c7;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c8);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c9) {
s0 = peg$c9;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c10);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c11) {
s0 = peg$c11;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c12);
}
}
}
}
return s0;
}
function peg$parseexpression_list() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parseexpression();
if (s2 !== peg$FAILED) {
s3 = [];
s4 = peg$currPos;
s5 = peg$parsevalue_separator();
if (s5 !== peg$FAILED) {
s6 = peg$parseexpression();
if (s6 !== peg$FAILED) {
peg$savedPos = s4;
s5 = peg$c13(s2, 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$parsevalue_separator();
if (s5 !== peg$FAILED) {
s6 = peg$parseexpression();
if (s6 !== peg$FAILED) {
peg$savedPos = s4;
s5 = peg$c13(s2, s6);
s4 = s5;
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
} else {
peg$currPos = s4;
s4 = peg$FAILED;
}
}
if (s3 !== peg$FAILED) {
peg$savedPos = s1;
s2 = peg$c2(s2, s3);
s1 = s2;
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
} else {
peg$currPos = s1;
s1 = peg$FAILED;
}
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c14(s1);
}
s0 = s1;
return s0;
}
function peg$parsewhere_clause() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$parsequotation_mark();
if (s1 !== peg$FAILED) {
s2 = peg$parsewhere_operator();
if (s2 !== peg$FAILED) {
s3 = peg$parsequotation_mark();
if (s3 !== peg$FAILED) {
s4 = peg$parsename_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parsestring();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c15(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$parseleaf_clause() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parsekey();
if (s1 !== peg$FAILED) {
s2 = peg$parsename_separator();
if (s2 !== peg$FAILED) {
s3 = peg$parsevalue();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c16(s1, s3);
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$parsevalue() {
var s0;
s0 = peg$parseoperator_expression();
if (s0 === peg$FAILED) {
s0 = peg$parseJSON();
}
return s0;
}
function peg$parsevalue_operator() {
var s0;
if (input.substr(peg$currPos, 4) === peg$c17) {
s0 = peg$c17;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c18);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c19) {
s0 = peg$c19;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c20);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c21) {
s0 = peg$c21;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c22);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c23) {
s0 = peg$c23;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c24);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c25) {
s0 = peg$c25;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c26);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c27) {
s0 = peg$c27;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c28);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c29) {
s0 = peg$c29;
peg$currPos += 5;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c30);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 5) === peg$c31) {
s0 = peg$c31;
peg$currPos += 5;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c32);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 7) === peg$c33) {
s0 = peg$c33;
peg$currPos += 7;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c34);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 13) === peg$c35) {
s0 = peg$c35;
peg$currPos += 13;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c36);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 11) === peg$c37) {
s0 = peg$c37;
peg$currPos += 11;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c38);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 13) === peg$c39) {
s0 = peg$c39;
peg$currPos += 13;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c40);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 11) === peg$c41) {
s0 = peg$c41;
peg$currPos += 11;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c42);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return s0;
}
function peg$parselist_operator() {
var s0;
if (input.substr(peg$currPos, 3) === peg$c43) {
s0 = peg$c43;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c44);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c45) {
s0 = peg$c45;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c46);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c47) {
s0 = peg$c47;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c48);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c49) {
s0 = peg$c49;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c50);
}
}
}
}
}
return s0;
}
function peg$parseoperator_expression_operator() {
var s0;
if (input.substr(peg$currPos, 4) === peg$c51) {
s0 = peg$c51;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c52);
}
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 10) === peg$c53) {
s0 = peg$c53;
peg$currPos += 10;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c54);
}
}
}
return s0;
}
function peg$parseoperator_expression() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parsebegin_object();
if (s1 !== peg$FAILED) {
s2 = peg$parseoperator_list();
if (s2 !== peg$FAILED) {
s3 = peg$parseend_object();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c55(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$parseoperator_list() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
s1 = peg$parseoperator();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
s4 = peg$parsevalue_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parseoperator();
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c56(s1, 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;
s4 = peg$parsevalue_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parseoperator();
if (s5 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c56(s1, s5);
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c2(s1, s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseoperator() {
var s0, s1, s2, s3, s4, s5, s6, s7;
s0 = peg$currPos;
s1 = peg$parsequotation_mark();
if (s1 !== peg$FAILED) {
s2 = peg$parsevalue_operator();
if (s2 !== peg$FAILED) {
s3 = peg$parsequotation_mark();
if (s3 !== peg$FAILED) {
s4 = peg$parsename_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parseJSON();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c57(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;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsequotation_mark();
if (s1 !== peg$FAILED) {
s2 = peg$parselist_operator();
if (s2 !== peg$FAILED) {
s3 = peg$parsequotation_mark();
if (s3 !== peg$FAILED) {
s4 = peg$parsename_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parsebegin_array();
if (s5 !== peg$FAILED) {
s6 = peg$parseleaf_value_list();
if (s6 !== peg$FAILED) {
s7 = peg$parseend_array();
if (s7 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c58(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;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsequotation_mark();
if (s1 !== peg$FAILED) {
if (input.substr(peg$currPos, 10) === peg$c53) {
s2 = peg$c53;
peg$currPos += 10;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c54);
}
}
if (s2 !== peg$FAILED) {
s3 = peg$parsequotation_mark();
if (s3 !== peg$FAILED) {
s4 = peg$parsename_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parseexpression();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c59(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;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsequotation_mark();
if (s1 !== peg$FAILED) {
s2 = peg$parseoperator_expression_operator();
if (s2 !== peg$FAILED) {
s3 = peg$parsequotation_mark();
if (s3 !== peg$FAILED) {
s4 = peg$parsename_separator();
if (s4 !== peg$FAILED) {
s5 = peg$parseoperator_expression();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c60(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;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parsequotation_mark();
if (s1 !== peg$FAILED) {
if (input.substr(peg$currPos, 10) === peg$c61) {
s2 = peg$c61;
peg$currPos += 10;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) {
peg$fail(peg$c62);
}
}
if (s2 !== peg$FAILED) {