UNPKG

mongodb-language-model

Version:

Parses MongoDB query language and returns an abstract syntax tree

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