UNPKG

mongo-url-utils

Version:

url parser utilities for connecting with mongodb

1,663 lines (1,559 loc) 111 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 = { start: peg$parsestart }, peg$startRuleFunction = peg$parsestart, peg$c0 = ",", peg$c1 = peg$literalExpectation(",", false), peg$c2 = function(head, tail) { const res = {}; res[head[0]] = head[1]; return tail.reduce(function (memo, sort) { // extra [1] to skip "," memo[sort[1][0]] = sort[1][1]; return memo; }, res); }, peg$c3 = "+", peg$c4 = peg$literalExpectation("+", false), peg$c5 = function(right) { return [right, 1]; }, peg$c6 = "-_id", peg$c7 = peg$literalExpectation("-_id", false), peg$c8 = function() { return ['_id', 0]; }, peg$c9 = " ", peg$c10 = peg$literalExpectation(" ", false), peg$c11 = function(right) { if (options.strictEncoding === true) throw new Error('Expected "+" or "-"; disable strictEncoding to allow space in place of +'); return [right, 1]; }, peg$c12 = "-", peg$c13 = peg$literalExpectation("-", false), peg$c14 = function(right) { return [right, 0]; }, peg$c15 = /^[^.$,\0]/, peg$c16 = peg$classExpectation([".", "$", ",", "\0"], true, false), peg$c17 = /^[^,\0]/, peg$c18 = peg$classExpectation([",", "\0"], true, false), peg$c19 = function(field) { return field; }, peg$c20 = "elemMatch(", peg$c21 = peg$literalExpectation("elemMatch(", false), peg$c22 = ")", peg$c23 = peg$literalExpectation(")", false), peg$c24 = function(field, query) { return [field, {$elemMatch: query}]; }, peg$c25 = "eq", peg$c26 = peg$literalExpectation("eq", false), peg$c27 = "ne", peg$c28 = peg$literalExpectation("ne", false), peg$c29 = "gte", peg$c30 = peg$literalExpectation("gte", false), peg$c31 = "gt", peg$c32 = peg$literalExpectation("gt", false), peg$c33 = "lte", peg$c34 = peg$literalExpectation("lte", false), peg$c35 = "lt", peg$c36 = peg$literalExpectation("lt", false), peg$c37 = "size", peg$c38 = peg$literalExpectation("size", false), peg$c39 = "in", peg$c40 = peg$literalExpectation("in", false), peg$c41 = "nin", peg$c42 = peg$literalExpectation("nin", false), peg$c43 = "all", peg$c44 = peg$literalExpectation("all", false), peg$c45 = "and", peg$c46 = peg$literalExpectation("and", false), peg$c47 = "or", peg$c48 = peg$literalExpectation("or", false), peg$c49 = "(", peg$c50 = peg$literalExpectation("(", false), peg$c51 = function(op, head, tail) { return set({}, '$' + op, collect(head, tail)); }, peg$c52 = function(op, prop, value) { const child = set({}, '$' + op, value); return set({}, prop, child); }, peg$c53 = function(op, prop, values) { const child = set({}, '$' + op, values); return set({}, prop, child); }, peg$c54 = "regex(", peg$c55 = peg$literalExpectation("regex(", false), peg$c56 = /^[imxs]/, peg$c57 = peg$classExpectation(["i", "m", "x", "s"], false, false), peg$c58 = function(prop, pattern, opts) { if (opts) return set({}, prop, {$regex: pattern, $options: opts[2].join('')}); return set({}, prop, {$regex: pattern}); }, peg$c59 = "where(", peg$c60 = peg$literalExpectation("where(", false), peg$c61 = function(expression) { return {$where: expression}; }, peg$c62 = "mod(", peg$c63 = peg$literalExpectation("mod(", false), peg$c64 = function(prop, divisor, remainder) { return set({}, prop, { $mod: [divisor, remainder] }); }, peg$c65 = function(prop, head, tail) { return set({}, prop, {$elemMatch: {$and: collect(head, tail)}}); }, peg$c66 = "exists(", peg$c67 = peg$literalExpectation("exists(", false), peg$c68 = function(prop, value) { return set({}, prop, {$exists: value}); }, peg$c69 = "type(", peg$c70 = peg$literalExpectation("type(", false), peg$c71 = function(prop, id) { const typeMap = { Double: 1, String: 2, Object: 3, Array: 4, Binary: 5, Undefined: 6, ObjectId: 7, Boolean: 8, Date: 9, Null: 10, RegExp: 11, Javascript: 13, Symbol: 14, ScopedJavascript: 15, Int32: 16, Timestamp: 17, Int64: 18 }; if (typeof id === 'string') id = typeMap[id]; if (id < -1 || id > 254) throw new Error('Expected number between -1 and 254'); return set({}, prop, {$type: id}); }, peg$c72 = "Double", peg$c73 = peg$literalExpectation("Double", false), peg$c74 = "String", peg$c75 = peg$literalExpectation("String", false), peg$c76 = "ObjectId", peg$c77 = peg$literalExpectation("ObjectId", false), peg$c78 = "Object", peg$c79 = peg$literalExpectation("Object", false), peg$c80 = "Array", peg$c81 = peg$literalExpectation("Array", false), peg$c82 = "Binary", peg$c83 = peg$literalExpectation("Binary", false), peg$c84 = "Undefined", peg$c85 = peg$literalExpectation("Undefined", false), peg$c86 = "Boolean", peg$c87 = peg$literalExpectation("Boolean", false), peg$c88 = "Date", peg$c89 = peg$literalExpectation("Date", false), peg$c90 = "Null", peg$c91 = peg$literalExpectation("Null", false), peg$c92 = "RegExp", peg$c93 = peg$literalExpectation("RegExp", false), peg$c94 = "Javascript", peg$c95 = peg$literalExpectation("Javascript", false), peg$c96 = "Symbol", peg$c97 = peg$literalExpectation("Symbol", false), peg$c98 = "ScopedJavascript", peg$c99 = peg$literalExpectation("ScopedJavascript", false), peg$c100 = "Int32", peg$c101 = peg$literalExpectation("Int32", false), peg$c102 = "Timestamp", peg$c103 = peg$literalExpectation("Timestamp", false), peg$c104 = "Int64", peg$c105 = peg$literalExpectation("Int64", false), peg$c106 = peg$otherExpectation("document property"), peg$c107 = /^[^.$,\0 ]/, peg$c108 = peg$classExpectation([".", "$", ",", "\0", " "], true, false), peg$c109 = /^[^,\0 ]/, peg$c110 = peg$classExpectation([",", "\0", " "], true, false), peg$c111 = function(property) { return property; }, peg$c112 = peg$otherExpectation("scalar value"), peg$c113 = "null", peg$c114 = peg$literalExpectation("null", false), peg$c115 = function() { return null; }, peg$c116 = peg$otherExpectation("boolean"), peg$c117 = "true", peg$c118 = peg$literalExpectation("true", false), peg$c119 = function() { return true; }, peg$c120 = "false", peg$c121 = peg$literalExpectation("false", false), peg$c122 = function() { return false; }, peg$c123 = peg$otherExpectation("array"), peg$c124 = "[", peg$c125 = peg$literalExpectation("[", false), peg$c126 = "]", peg$c127 = peg$literalExpectation("]", false), peg$c128 = function() { return []; }, peg$c129 = function(elements) { return elements; }, peg$c130 = peg$otherExpectation("elements"), peg$c131 = function(head, tail) { return collect(head, tail); }, peg$c132 = peg$otherExpectation("string"), peg$c133 = "\"", peg$c134 = peg$literalExpectation("\"", false), peg$c135 = function() { return ""; }, peg$c136 = function(chars) { return chars; }, peg$c137 = peg$otherExpectation("chars"), peg$c138 = function(chars) { return chars.join(""); }, peg$c139 = peg$otherExpectation("char"), peg$c140 = /^[^"\\\0-\x1F\x7F]/, peg$c141 = peg$classExpectation(["\"", "\\", ["\0", "\x1F"], "\x7F"], true, false), peg$c142 = "\\\"", peg$c143 = peg$literalExpectation("\\\"", false), peg$c144 = function() { return '"'; }, peg$c145 = "\\\\", peg$c146 = peg$literalExpectation("\\\\", false), peg$c147 = function() { return "\\"; }, peg$c148 = "\\/", peg$c149 = peg$literalExpectation("\\/", false), peg$c150 = function() { return "/"; }, peg$c151 = "\\b", peg$c152 = peg$literalExpectation("\\b", false), peg$c153 = function() { return "\b"; }, peg$c154 = "\\f", peg$c155 = peg$literalExpectation("\\f", false), peg$c156 = function() { return "\f"; }, peg$c157 = "\\n", peg$c158 = peg$literalExpectation("\\n", false), peg$c159 = function() { return "\n"; }, peg$c160 = "\\r", peg$c161 = peg$literalExpectation("\\r", false), peg$c162 = function() { return "\r"; }, peg$c163 = "\\t", peg$c164 = peg$literalExpectation("\\t", false), peg$c165 = function() { return "\t"; }, peg$c166 = "\\u", peg$c167 = peg$literalExpectation("\\u", false), peg$c168 = function(digits) { return String.fromCharCode(parseInt(digits, 16)); }, peg$c169 = peg$otherExpectation("number"), peg$c170 = function(parts) { return parseFloat(parts); }, peg$c171 = peg$otherExpectation("integer"), peg$c172 = peg$otherExpectation("date"), peg$c173 = "Date(", peg$c174 = peg$literalExpectation("Date(", false), peg$c175 = function(dateTimeStr) { const date = new Date(dateTimeStr); assertDateIsValid(date, dateTimeStr); return date; }, peg$c176 = function(n) { return parseInt(n, 10); }, peg$c177 = peg$otherExpectation("fraction"), peg$c178 = ".", peg$c179 = peg$literalExpectation(".", false), peg$c180 = peg$otherExpectation("digits"), peg$c181 = peg$otherExpectation("exponent"), peg$c182 = /^[eE]/, peg$c183 = peg$classExpectation(["e", "E"], false, false), peg$c184 = /^[+\-]/, peg$c185 = peg$classExpectation(["+", "-"], false, false), peg$c186 = peg$otherExpectation("digit"), peg$c187 = /^[0-9]/, peg$c188 = peg$classExpectation([["0", "9"]], false, false), peg$c189 = peg$otherExpectation("non-zero digit"), peg$c190 = /^[1-9]/, peg$c191 = peg$classExpectation([["1", "9"]], false, false), peg$c192 = peg$otherExpectation("hex digit"), peg$c193 = /^[0-9a-fA-F]/, peg$c194 = peg$classExpectation([["0", "9"], ["a", "f"], ["A", "F"]], false, false), peg$c195 = peg$otherExpectation("whitespace"), peg$c196 = peg$otherExpectation("date time"), peg$c197 = "T", peg$c198 = peg$literalExpectation("T", false), peg$c199 = peg$otherExpectation("time"), peg$c200 = ":", peg$c201 = peg$literalExpectation(":", false), peg$c202 = peg$otherExpectation("hours"), peg$c203 = peg$otherExpectation("minutes"), peg$c204 = peg$otherExpectation("seconds"), peg$c205 = peg$otherExpectation("milliseconds"), peg$c206 = peg$otherExpectation("zulu timezone"), peg$c207 = "Z", peg$c208 = peg$literalExpectation("Z", false), peg$c209 = peg$otherExpectation("timezone offset"), peg$c210 = peg$otherExpectation("year"), peg$c211 = peg$otherExpectation("month"), peg$c212 = peg$otherExpectation("day"), 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; s0 = peg$parsefields(); return s0; } function peg$parsefields() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$parseincluding(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s4 = peg$c0; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s4 !== peg$FAILED) { s5 = peg$parseincluding(); if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s4 = peg$c0; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s4 !== peg$FAILED) { s5 = peg$parseincluding(); if (s5 !== peg$FAILED) { s4 = [s4, 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 = peg$currPos; s1 = peg$parseexcluding(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s4 = peg$c0; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s4 !== peg$FAILED) { s5 = peg$parseexcluding(); if (s5 !== peg$FAILED) { s4 = [s4, s5]; s3 = s4; } else { peg$currPos = s3; s3 = peg$FAILED; } } else { peg$currPos = s3; s3 = peg$FAILED; } while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s4 = peg$c0; peg$currPos++; } else { s4 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s4 !== peg$FAILED) { s5 = peg$parseexcluding(); if (s5 !== peg$FAILED) { s4 = [s4, 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$parseincluding() { var s0, s1, s2; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 43) { s1 = peg$c3; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s1 !== peg$FAILED) { s2 = peg$parsefield(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c5(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.substr(peg$currPos, 4) === peg$c6) { s1 = peg$c6; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c7); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c8(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$parseElemMatchProjection(); if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 32) { s1 = peg$c9; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c10); } } if (s1 !== peg$FAILED) { s2 = peg$parsefield(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c11(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } } } return s0; } function peg$parseexcluding() { var s0, s1, s2; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { s1 = peg$c12; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s1 !== peg$FAILED) { s2 = peg$parsefield(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c14(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$parseElemMatchProjection(); } return s0; } function peg$parsefield() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$currPos; if (peg$c15.test(input.charAt(peg$currPos))) { s3 = input.charAt(peg$currPos); peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c16); } } if (s3 !== peg$FAILED) { s4 = []; if (peg$c17.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } while (s5 !== peg$FAILED) { s4.push(s5); if (peg$c17.test(input.charAt(peg$currPos))) { s5 = input.charAt(peg$currPos); peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } } if (s4 !== peg$FAILED) { s3 = [s3, s4]; s2 = s3; } else { peg$currPos = s2; s2 = peg$FAILED; } } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c19(s1); } s0 = s1; return s0; } function peg$parseElemMatchProjection() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; if (input.substr(peg$currPos, 10) === peg$c20) { s1 = peg$c20; peg$currPos += 10; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c21); } } if (s1 !== peg$FAILED) { s2 = peg$parsefield(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s3 = peg$c0; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s3 !== peg$FAILED) { s4 = peg$parseQuery(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s5 = peg$c22; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c24(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; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseQuery() { var s0; s0 = peg$parseScalarComparison(); if (s0 === peg$FAILED) { s0 = peg$parseLogicalComparison(); if (s0 === peg$FAILED) { s0 = peg$parseArrayComparison(); if (s0 === peg$FAILED) { s0 = peg$parseExists(); if (s0 === peg$FAILED) { s0 = peg$parseElemMatch(); if (s0 === peg$FAILED) { s0 = peg$parseRegex(); if (s0 === peg$FAILED) { s0 = peg$parseMod(); if (s0 === peg$FAILED) { s0 = peg$parseWhere(); if (s0 === peg$FAILED) { s0 = peg$parseType(); } } } } } } } } return s0; } function peg$parseScalarComparisonOperator() { var s0; if (input.substr(peg$currPos, 2) === peg$c25) { s0 = peg$c25; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c26); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c27) { s0 = peg$c27; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c29) { s0 = peg$c29; peg$currPos += 3; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c30); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c31) { s0 = peg$c31; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c32); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c33) { s0 = peg$c33; peg$currPos += 3; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c34); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c35) { s0 = peg$c35; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c36); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c27) { s0 = peg$c27; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 4) === peg$c37) { s0 = peg$c37; peg$currPos += 4; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c38); } } } } } } } } } return s0; } function peg$parseArrayComparisonOperator() { var s0; if (input.substr(peg$currPos, 2) === peg$c39) { s0 = peg$c39; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c40); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c41) { s0 = peg$c41; peg$currPos += 3; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s0 === peg$FAILED) { 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); } } } } return s0; } function peg$parseLogicalComparisonOperator() { var s0; if (input.substr(peg$currPos, 3) === peg$c45) { s0 = peg$c45; peg$currPos += 3; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s0 === peg$FAILED) { if (input.substr(peg$currPos, 2) === peg$c47) { s0 = peg$c47; peg$currPos += 2; } else { s0 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c48); } } } return s0; } function peg$parseLogicalComparison() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$parseLogicalComparisonOperator(); if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 40) { s2 = peg$c49; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c50); } } if (s2 !== peg$FAILED) { s3 = peg$parse__(); if (s3 !== peg$FAILED) { s4 = peg$parseQuery(); if (s4 !== peg$FAILED) { s5 = peg$parse__(); if (s5 !== peg$FAILED) { s6 = []; s7 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s8 = peg$c0; peg$currPos++; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s8 !== peg$FAILED) { s9 = peg$parse__(); if (s9 !== peg$FAILED) { s10 = peg$parseQuery(); if (s10 !== peg$FAILED) { s8 = [s8, s9, s10]; s7 = s8; } else { peg$currPos = s7; s7 = peg$FAILED; } } else { peg$currPos = s7; s7 = peg$FAILED; } } else { peg$currPos = s7; s7 = peg$FAILED; } while (s7 !== peg$FAILED) { s6.push(s7); s7 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s8 = peg$c0; peg$currPos++; } else { s8 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s8 !== peg$FAILED) { s9 = peg$parse__(); if (s9 !== peg$FAILED) { s10 = peg$parseQuery(); if (s10 !== peg$FAILED) { s8 = [s8, s9, s10]; s7 = s8; } else { peg$currPos = s7; s7 = peg$FAILED; } } else { peg$currPos = s7; s7 = peg$FAILED; } } else { peg$currPos = s7; s7 = peg$FAILED; } } if (s6 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s7 = peg$c22; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s7 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c51(s1, s4, 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$parseScalarComparison() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$parseScalarComparisonOperator(); if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 40) { s2 = peg$c49; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c50); } } if (s2 !== peg$FAILED) { s3 = peg$parse__(); if (s3 !== peg$FAILED) { s4 = peg$parseProperty(); if (s4 !== peg$FAILED) { s5 = peg$parse__(); if (s5 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s6 = peg$c0; peg$currPos++; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s6 !== peg$FAILED) { s7 = peg$parse__(); if (s7 !== peg$FAILED) { s8 = peg$parseScalar(); if (s8 !== peg$FAILED) { s9 = peg$parse__(); if (s9 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s10 = peg$c22; peg$currPos++; } else { s10 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s10 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c52(s1, s4, s8); 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; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseArrayComparison() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10; s0 = peg$currPos; s1 = peg$currPos; s2 = peg$parseArrayComparisonOperator(); if (s2 !== peg$FAILED) { s1 = input.substring(s1, peg$currPos); } else { s1 = s2; } if (s1 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 40) { s2 = peg$c49; peg$currPos++; } else { s2 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c50); } } if (s2 !== peg$FAILED) { s3 = peg$parse__(); if (s3 !== peg$FAILED) { s4 = peg$parseProperty(); if (s4 !== peg$FAILED) { s5 = peg$parse__(); if (s5 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s6 = peg$c0; peg$currPos++; } else { s6 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s6 !== peg$FAILED) { s7 = peg$parse__(); if (s7 !== peg$FAILED) { s8 = peg$parseArray(); if (s8 !== peg$FAILED) { s9 = peg$parse__(); if (s9 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s10 = peg$c22; peg$currPos++; } else { s10 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s10 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c53(s1, s4, s8); 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; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseRegex() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13; s0 = peg$currPos; if (input.substr(peg$currPos, 6) === peg$c54) { s1 = peg$c54; peg$currPos += 6; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c55); } } if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parseProperty(); if (s3 !== peg$FAILED) { s4 = peg$parse__(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c0; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s5 !== peg$FAILED) { s6 = peg$parse__(); if (s6 !== peg$FAILED) { s7 = peg$parseString(); if (s7 !== peg$FAILED) { s8 = peg$parse__(); if (s8 !== peg$FAILED) { s9 = peg$currPos; if (input.charCodeAt(peg$currPos) === 44) { s10 = peg$c0; peg$currPos++; } else { s10 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s10 !== peg$FAILED) { s11 = peg$parse__(); if (s11 !== peg$FAILED) { s12 = []; if (peg$c56.test(input.charAt(peg$currPos))) { s13 = input.charAt(peg$currPos); peg$currPos++; } else { s13 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c57); } } if (s13 !== peg$FAILED) { while (s13 !== peg$FAILED) { s12.push(s13); if (peg$c56.test(input.charAt(peg$currPos))) { s13 = input.charAt(peg$currPos); peg$currPos++; } else { s13 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c57); } } } } else { s12 = peg$FAILED; } if (s12 !== peg$FAILED) { s13 = peg$parse__(); if (s13 !== peg$FAILED) { s10 = [s10, s11, s12, s13]; s9 = s10; } else { peg$currPos = s9; s9 = peg$FAILED; } } else { peg$currPos = s9; s9 = peg$FAILED; } } else { peg$currPos = s9; s9 = peg$FAILED; } } else { peg$currPos = s9; s9 = peg$FAILED; } if (s9 === peg$FAILED) { s9 = null; } if (s9 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s10 = peg$c22; peg$currPos++; } else { s10 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s10 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c58(s3, s7, s9); 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; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseWhere() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; if (input.substr(peg$currPos, 6) === peg$c59) { s1 = peg$c59; peg$currPos += 6; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c60); } } if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parseString(); if (s3 !== peg$FAILED) { s4 = peg$parse__(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s5 = peg$c22; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c61(s3); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseMod() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13; s0 = peg$currPos; if (input.substr(peg$currPos, 4) === peg$c62) { s1 = peg$c62; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c63); } } if (s1 !== peg$FAILED) { s2 = peg$parse__(); if (s2 !== peg$FAILED) { s3 = peg$parseProperty(); if (s3 !== peg$FAILED) { s4 = peg$parse__(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s5 = peg$c0; peg$currPos++; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s5 !== peg$FAILED) { s6 = peg$parse__(); if (s6 !== peg$FAILED) { s7 = peg$parseNumber(); if (s7 !== peg$FAILED) { s8 = peg$parse__(); if (s8 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 44) { s9 = peg$c0; peg$currPos++; } else { s9 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c1); } } if (s9 !== peg$FAILED) { s10 = peg$parse__(); if (s10 !== peg$FAILED) { s11 = peg$parseNumber(); if (s11 !== peg$FAILED) { s12 = peg$parse__(); if (s12 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { s13 = peg$c22; peg$currPos++; } else { s13 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c23); } } if (s13 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c64(s3, s7, s11); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { p