mongo-url-utils
Version:
url parser utilities for connecting with mongodb
1,591 lines (1,489 loc) • 139 kB
JavaScript
/*
* Generated by PEG.js 0.10.0.
*
* http://pegjs.org/
*/
"use strict";
function peg$subclass(child, parent) {
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor();
}
function peg$SyntaxError(message, expected, found, location) {
this.message = message;
this.expected = expected;
this.found = found;
this.location = location;
this.name = "SyntaxError";
if (typeof Error.captureStackTrace === "function") {
Error.captureStackTrace(this, peg$SyntaxError);
}
}
peg$subclass(peg$SyntaxError, Error);
peg$SyntaxError.buildMessage = function(expected, found) {
var DESCRIBE_EXPECTATION_FNS = {
literal: function(expectation) {
return "\"" + literalEscape(expectation.text) + "\"";
},
"class": function(expectation) {
var escapedParts = "",
i;
for (i = 0; i < expectation.parts.length; i++) {
escapedParts += expectation.parts[i] instanceof Array
? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])
: classEscape(expectation.parts[i]);
}
return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
},
any: function(expectation) {
return "any character";
},
end: function(expectation) {
return "end of input";
},
other: function(expectation) {
return expectation.description;
}
};
function hex(ch) {
return ch.charCodeAt(0).toString(16).toUpperCase();
}
function literalEscape(s) {
return s
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\0/g, '\\0')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
}
function classEscape(s) {
return s
.replace(/\\/g, '\\\\')
.replace(/\]/g, '\\]')
.replace(/\^/g, '\\^')
.replace(/-/g, '\\-')
.replace(/\0/g, '\\0')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r')
.replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); });
}
function describeExpectation(expectation) {
return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
}
function describeExpected(expected) {
var descriptions = new Array(expected.length),
i, j;
for (i = 0; i < expected.length; i++) {
descriptions[i] = describeExpectation(expected[i]);
}
descriptions.sort();
if (descriptions.length > 0) {
for (i = 1, j = 1; i < descriptions.length; i++) {
if (descriptions[i - 1] !== descriptions[i]) {
descriptions[j] = descriptions[i];
j++;
}
}
descriptions.length = j;
}
switch (descriptions.length) {
case 1:
return descriptions[0];
case 2:
return descriptions[0] + " or " + descriptions[1];
default:
return descriptions.slice(0, -1).join(", ")
+ ", or "
+ descriptions[descriptions.length - 1];
}
}
function describeFound(found) {
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
}
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
};
function peg$parse(input, options) {
options = options !== void 0 ? options : {};
var peg$FAILED = {},
peg$startRuleFunctions = { start: peg$parsestart },
peg$startRuleFunction = peg$parsestart,
peg$c0 = "gte",
peg$c1 = peg$literalExpectation("gte", false),
peg$c2 = "gt",
peg$c3 = peg$literalExpectation("gt", false),
peg$c4 = "lte",
peg$c5 = peg$literalExpectation("lte", false),
peg$c6 = "lt",
peg$c7 = peg$literalExpectation("lt", false),
peg$c8 = "ne",
peg$c9 = peg$literalExpectation("ne", false),
peg$c10 = "size",
peg$c11 = peg$literalExpectation("size", false),
peg$c12 = "eq",
peg$c13 = peg$literalExpectation("eq", false),
peg$c14 = "in",
peg$c15 = peg$literalExpectation("in", false),
peg$c16 = "nin",
peg$c17 = peg$literalExpectation("nin", false),
peg$c18 = "all",
peg$c19 = peg$literalExpectation("all", false),
peg$c20 = "and",
peg$c21 = peg$literalExpectation("and", false),
peg$c22 = "or",
peg$c23 = peg$literalExpectation("or", false),
peg$c24 = "(",
peg$c25 = peg$literalExpectation("(", false),
peg$c26 = ",",
peg$c27 = peg$literalExpectation(",", false),
peg$c28 = ")",
peg$c29 = peg$literalExpectation(")", false),
peg$c30 = function(op, head, tail) {
assertCan(op);
return set({}, '$' + op, collect(head, tail));
},
peg$c31 = "not(",
peg$c32 = peg$literalExpectation("not(", false),
peg$c33 = function(expression) {
assertCan('not');
Object.keys(expression).forEach((key) => expression[key] = {$not: expression[key]});
return expression;
},
peg$c34 = function(op, prop, value) {
assertCan(op);
var child = set({}, '$' + op, value);
return set({}, prop, child);
},
peg$c35 = function(op, prop, values) {
assertCan(op);
var child = set({}, '$' + op, values);
return set({}, prop, child);
},
peg$c36 = "regex(",
peg$c37 = peg$literalExpectation("regex(", false),
peg$c38 = /^[imxs]/,
peg$c39 = peg$classExpectation(["i", "m", "x", "s"], false, false),
peg$c40 = function(prop, pattern, opts) {
assertCan('regex');
assertSafeRegex(pattern);
if (opts) return set({}, prop, {$regex: pattern, $options: opts[2].join('')});
return set({}, prop, {$regex: pattern});
},
peg$c41 = "eq(",
peg$c42 = peg$literalExpectation("eq(", false),
peg$c43 = function(prop, value, switches) {
var child = {};
assertCan('eq');
if (switches) {
assertCanWithSwitches('eq', switches);
child = new RegExp('^' + escapeRegex(value) + '$', switches);
} else {
child = {$eq: value};
}
return set({}, prop, child);
},
peg$c44 = "ne(",
peg$c45 = peg$literalExpectation("ne(", false),
peg$c46 = function(prop, value, switches) {
var child = {};
assertCan('ne');
if (switches) {
assertCanWithSwitches('ne', switches);
child = {$not: new RegExp('^' + escapeRegex(value) + '$', switches)};
} else {
child = set({}, '$ne', value);
}
return set({}, prop, child);
},
peg$c47 = "startsWith(",
peg$c48 = peg$literalExpectation("startsWith(", false),
peg$c49 = function(prop, value, switches) {
assertCan('startsWith');
assertCanWithSwitches('startsWith', switches);
value = {$regex: '^' + escapeRegex(value)};
if (contains(switches, 'i')) value.$options = 'i';
return set({}, prop, value);
},
peg$c50 = "not(startsWith(",
peg$c51 = peg$literalExpectation("not(startsWith(", false),
peg$c52 = "))",
peg$c53 = peg$literalExpectation("))", false),
peg$c54 = function(prop, value, switches) {
assertCan('startsWith');
assertCan('not');
assertCanWithSwitches('startsWith', switches);
var flags = (switches || []).join('');
return set({}, prop, {$not: new RegExp('^' + escapeRegex(value), flags)});
},
peg$c55 = "endsWith(",
peg$c56 = peg$literalExpectation("endsWith(", false),
peg$c57 = function(prop, value, switches) {
assertCan('endsWith');
assertCanWithSwitches('endsWith', switches);
value = {$regex: escapeRegex(value) + '$'};
if (contains(switches, 'i')) value.$options = 'i';
return set({}, prop, value);
},
peg$c58 = "not(endsWith(",
peg$c59 = peg$literalExpectation("not(endsWith(", false),
peg$c60 = function(prop, value, switches) {
assertCan('endsWith');
assertCan('not');
assertCanWithSwitches('endsWith', switches);
var flags = (switches || []).join('');
return set({}, prop, {$not: new RegExp(escapeRegex(value) + '$', flags)});
},
peg$c61 = "contains(",
peg$c62 = peg$literalExpectation("contains(", false),
peg$c63 = function(prop, value, switches) {
assertCan('contains');
assertCanWithSwitches('contains', switches);
value = {$regex: escapeRegex(value)};
if (contains(switches, 'i')) value.$options = 'i';
return set({}, prop, value);
},
peg$c64 = "not(contains(",
peg$c65 = peg$literalExpectation("not(contains(", false),
peg$c66 = function(prop, value, switches) {
assertCan('contains');
assertCan('not');
assertCanWithSwitches('contains', switches);
var flags = (switches || []).join('');
return set({}, prop, {$not: new RegExp(escapeRegex(value), flags)});
},
peg$c67 = "where(",
peg$c68 = peg$literalExpectation("where(", false),
peg$c69 = function(expression) {
assertCan('where');
return {$where: expression};
},
peg$c70 = "text(",
peg$c71 = peg$literalExpectation("text(", false),
peg$c72 = function(search, lang) {
assertCan('text');
if (lang) return {$text: {$search: search, $language: lang[2]}};
return {$text: {$search: search}};
},
peg$c73 = "mod(",
peg$c74 = peg$literalExpectation("mod(", false),
peg$c75 = function(prop, divisor, remainder) {
assertCan('mod');
return set({}, prop, { $mod: [divisor, remainder] });
},
peg$c76 = "elemMatch(",
peg$c77 = peg$literalExpectation("elemMatch(", false),
peg$c78 = function(prop, head, tail) {
assertCan('elemMatch');
return set({}, prop, {$elemMatch: {$and: collect(head, tail)}});
},
peg$c79 = "exists(",
peg$c80 = peg$literalExpectation("exists(", false),
peg$c81 = function(prop, value) {
assertCan('exists');
return set({}, prop, {$exists: value});
},
peg$c82 = "type(",
peg$c83 = peg$literalExpectation("type(", false),
peg$c84 = function(prop, id) {
var 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
};
assertCan('type');
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$c85 = /^[i]/,
peg$c86 = peg$classExpectation(["i"], false, false),
peg$c87 = function(switches) {
return uniq(switches);
},
peg$c88 = "Double",
peg$c89 = peg$literalExpectation("Double", false),
peg$c90 = "String",
peg$c91 = peg$literalExpectation("String", false),
peg$c92 = "ObjectId",
peg$c93 = peg$literalExpectation("ObjectId", false),
peg$c94 = "Object",
peg$c95 = peg$literalExpectation("Object", false),
peg$c96 = "Array",
peg$c97 = peg$literalExpectation("Array", false),
peg$c98 = "Binary",
peg$c99 = peg$literalExpectation("Binary", false),
peg$c100 = "Undefined",
peg$c101 = peg$literalExpectation("Undefined", false),
peg$c102 = "Boolean",
peg$c103 = peg$literalExpectation("Boolean", false),
peg$c104 = "Date",
peg$c105 = peg$literalExpectation("Date", false),
peg$c106 = "Null",
peg$c107 = peg$literalExpectation("Null", false),
peg$c108 = "RegExp",
peg$c109 = peg$literalExpectation("RegExp", false),
peg$c110 = "Javascript",
peg$c111 = peg$literalExpectation("Javascript", false),
peg$c112 = "Symbol",
peg$c113 = peg$literalExpectation("Symbol", false),
peg$c114 = "ScopedJavascript",
peg$c115 = peg$literalExpectation("ScopedJavascript", false),
peg$c116 = "Int32",
peg$c117 = peg$literalExpectation("Int32", false),
peg$c118 = "Timestamp",
peg$c119 = peg$literalExpectation("Timestamp", false),
peg$c120 = "Int64",
peg$c121 = peg$literalExpectation("Int64", false),
peg$c122 = peg$otherExpectation("document property"),
peg$c123 = /^[^.$,\0 ]/,
peg$c124 = peg$classExpectation([".", "$", ",", "\0", " "], true, false),
peg$c125 = /^[^,\0 ]/,
peg$c126 = peg$classExpectation([",", "\0", " "], true, false),
peg$c127 = function(property) { return property; },
peg$c128 = peg$otherExpectation("scalar value"),
peg$c129 = "null",
peg$c130 = peg$literalExpectation("null", false),
peg$c131 = function() { return null; },
peg$c132 = peg$otherExpectation("boolean"),
peg$c133 = "true",
peg$c134 = peg$literalExpectation("true", false),
peg$c135 = function() { return true; },
peg$c136 = "false",
peg$c137 = peg$literalExpectation("false", false),
peg$c138 = function() { return false; },
peg$c139 = peg$otherExpectation("array"),
peg$c140 = "[",
peg$c141 = peg$literalExpectation("[", false),
peg$c142 = "]",
peg$c143 = peg$literalExpectation("]", false),
peg$c144 = function() { return []; },
peg$c145 = function(elements) { return elements; },
peg$c146 = peg$otherExpectation("elements"),
peg$c147 = function(head, tail) {
return collect(head, tail);
},
peg$c148 = peg$otherExpectation("string"),
peg$c149 = "\"",
peg$c150 = peg$literalExpectation("\"", false),
peg$c151 = function() { return ""; },
peg$c152 = function(chars) { return chars; },
peg$c153 = peg$otherExpectation("chars"),
peg$c154 = function(chars) { return chars.join(""); },
peg$c155 = peg$otherExpectation("char"),
peg$c156 = /^[^"\\\0-\x1F\x7F]/,
peg$c157 = peg$classExpectation(["\"", "\\", ["\0", "\x1F"], "\x7F"], true, false),
peg$c158 = "\\\"",
peg$c159 = peg$literalExpectation("\\\"", false),
peg$c160 = function() { return '"'; },
peg$c161 = "\\\\",
peg$c162 = peg$literalExpectation("\\\\", false),
peg$c163 = function() { return "\\"; },
peg$c164 = "\\/",
peg$c165 = peg$literalExpectation("\\/", false),
peg$c166 = function() { return "/"; },
peg$c167 = "\\b",
peg$c168 = peg$literalExpectation("\\b", false),
peg$c169 = function() { return "\b"; },
peg$c170 = "\\f",
peg$c171 = peg$literalExpectation("\\f", false),
peg$c172 = function() { return "\f"; },
peg$c173 = "\\n",
peg$c174 = peg$literalExpectation("\\n", false),
peg$c175 = function() { return "\n"; },
peg$c176 = "\\r",
peg$c177 = peg$literalExpectation("\\r", false),
peg$c178 = function() { return "\r"; },
peg$c179 = "\\t",
peg$c180 = peg$literalExpectation("\\t", false),
peg$c181 = function() { return "\t"; },
peg$c182 = "\\u",
peg$c183 = peg$literalExpectation("\\u", false),
peg$c184 = function(digits) {
return String.fromCharCode(parseInt(digits, 16));
},
peg$c185 = peg$otherExpectation("number"),
peg$c186 = function(parts) { return parseFloat(parts); },
peg$c187 = peg$otherExpectation("integer"),
peg$c188 = "-",
peg$c189 = peg$literalExpectation("-", false),
peg$c190 = peg$otherExpectation("date"),
peg$c191 = "Date(",
peg$c192 = peg$literalExpectation("Date(", false),
peg$c193 = function(dateTimeStr) {
var date = new Date(dateTimeStr);
assertDateIsValid(date, dateTimeStr);
return date;
},
peg$c194 = function(n) {
return parseInt(n, 10);
},
peg$c195 = peg$otherExpectation("fraction"),
peg$c196 = ".",
peg$c197 = peg$literalExpectation(".", false),
peg$c198 = peg$otherExpectation("digits"),
peg$c199 = peg$otherExpectation("exponent"),
peg$c200 = /^[eE]/,
peg$c201 = peg$classExpectation(["e", "E"], false, false),
peg$c202 = /^[+\-]/,
peg$c203 = peg$classExpectation(["+", "-"], false, false),
peg$c204 = peg$otherExpectation("digit"),
peg$c205 = /^[0-9]/,
peg$c206 = peg$classExpectation([["0", "9"]], false, false),
peg$c207 = peg$otherExpectation("non-zero digit"),
peg$c208 = /^[1-9]/,
peg$c209 = peg$classExpectation([["1", "9"]], false, false),
peg$c210 = peg$otherExpectation("hex digit"),
peg$c211 = /^[0-9a-fA-F]/,
peg$c212 = peg$classExpectation([["0", "9"], ["a", "f"], ["A", "F"]], false, false),
peg$c213 = peg$otherExpectation("whitespace"),
peg$c214 = " ",
peg$c215 = peg$literalExpectation(" ", false),
peg$c216 = peg$otherExpectation("date time"),
peg$c217 = "T",
peg$c218 = peg$literalExpectation("T", false),
peg$c219 = peg$otherExpectation("time"),
peg$c220 = ":",
peg$c221 = peg$literalExpectation(":", false),
peg$c222 = peg$otherExpectation("hours"),
peg$c223 = peg$otherExpectation("minutes"),
peg$c224 = peg$otherExpectation("seconds"),
peg$c225 = peg$otherExpectation("milliseconds"),
peg$c226 = peg$otherExpectation("zulu timezone"),
peg$c227 = "Z",
peg$c228 = peg$literalExpectation("Z", false),
peg$c229 = peg$otherExpectation("timezone offset"),
peg$c230 = peg$otherExpectation("year"),
peg$c231 = peg$otherExpectation("month"),
peg$c232 = 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$parseQuery();
return s0;
}
function peg$parseQuery() {
var s0;
s0 = peg$parseEq();
if (s0 === peg$FAILED) {
s0 = peg$parseScalarComparison();
if (s0 === peg$FAILED) {
s0 = peg$parseLogicalComparison();
if (s0 === peg$FAILED) {
s0 = peg$parseNe();
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$parseStartsWith();
if (s0 === peg$FAILED) {
s0 = peg$parseEndsWith();
if (s0 === peg$FAILED) {
s0 = peg$parseContains();
if (s0 === peg$FAILED) {
s0 = peg$parseMod();
if (s0 === peg$FAILED) {
s0 = peg$parseText();
if (s0 === peg$FAILED) {
s0 = peg$parseWhere();
if (s0 === peg$FAILED) {
s0 = peg$parseType();
if (s0 === peg$FAILED) {
s0 = peg$parseNot();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return s0;
}
function peg$parseScalarComparisonOperator() {
var s0;
if (input.substr(peg$currPos, 3) === peg$c0) {
s0 = peg$c0;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c1); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c2) {
s0 = peg$c2;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c3); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c4) {
s0 = peg$c4;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c5); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c6) {
s0 = peg$c6;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c7); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c8) {
s0 = peg$c8;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c9); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c10) {
s0 = peg$c10;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c11); }
}
}
}
}
}
}
return s0;
}
function peg$parseEqualityComparisonOperator() {
var s0;
if (input.substr(peg$currPos, 2) === peg$c12) {
s0 = peg$c12;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c13); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c8) {
s0 = peg$c8;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c9); }
}
}
return s0;
}
function peg$parseArrayComparisonOperator() {
var s0;
if (input.substr(peg$currPos, 2) === peg$c14) {
s0 = peg$c14;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c15); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c16) {
s0 = peg$c16;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c17); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c18) {
s0 = peg$c18;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c19); }
}
}
}
return s0;
}
function peg$parseLogicalComparisonOperator() {
var s0;
if (input.substr(peg$currPos, 3) === peg$c20) {
s0 = peg$c20;
peg$currPos += 3;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c21); }
}
if (s0 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c22) {
s0 = peg$c22;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c23); }
}
}
return s0;
}
function peg$parseNegatableComparison() {
var s0;
s0 = peg$parseScalarComparison();
if (s0 === peg$FAILED) {
s0 = peg$parseArrayComparison();
if (s0 === peg$FAILED) {
s0 = peg$parseEq();
if (s0 === peg$FAILED) {
s0 = peg$parseNe();
}
}
}
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$c24;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c25); }
}
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$c26;
peg$currPos++;
} else {
s8 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
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$c26;
peg$currPos++;
} else {
s8 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
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$c28;
peg$currPos++;
} else {
s7 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c29); }
}
if (s7 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c30(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$parseNot() {
var s0, s1, s2, s3, s4, s5;
s0 = peg$currPos;
if (input.substr(peg$currPos, 4) === peg$c31) {
s1 = peg$c31;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c32); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$parseNegatableComparison();
if (s3 !== peg$FAILED) {
s4 = peg$parse__();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 41) {
s5 = peg$c28;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c29); }
}
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c33(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$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$c24;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c25); }
}
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$c26;
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
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$c28;
peg$currPos++;
} else {
s10 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c29); }
}
if (s10 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c34(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$c24;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c25); }
}
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$c26;
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
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$c28;
peg$currPos++;
} else {
s10 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c29); }
}
if (s10 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c35(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$c36) {
s1 = peg$c36;
peg$currPos += 6;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c37); }
}
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$c26;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
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$c26;
peg$currPos++;
} else {
s10 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s10 !== peg$FAILED) {
s11 = peg$parse__();
if (s11 !== peg$FAILED) {
s12 = [];
if (peg$c38.test(input.charAt(peg$currPos))) {
s13 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s13 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c39); }
}
if (s13 !== peg$FAILED) {
while (s13 !== peg$FAILED) {
s12.push(s13);
if (peg$c38.test(input.charAt(peg$currPos))) {
s13 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s13 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c39); }
}
}
} 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$c28;
peg$currPos++;
} else {
s10 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c29); }
}
if (s10 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c40(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$parseEq() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
s0 = peg$currPos;
if (input.substr(peg$currPos, 3) === peg$c41) {
s1 = peg$c41;
peg$currPos += 3;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c42); }
}
if (s1 !== peg$FAILED) {
s2 = peg$parse__();
if (s2 !== peg$FAILED) {
s3 = peg$parseProperty();
if (s3 !== peg$FAILED) {
s4 = peg$parse__();
if (s4 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 44) {
s5 = peg$c26;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s5 !== peg$FAILED) {
s6 = peg$parse__();
if (s6 !== peg$FAILED) {
s7 = peg$parseScalar();
if (s7 !== peg$FAILED) {
s8 = peg$parse__();
if (s8 !== peg$FAILED) {
s9 = peg$parseSwitches();
if (s9 === peg$FAILED) {
s9 = null;
}
if (s9 !== peg$FAILED) {
s10 = peg$parse__();
if (s10 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 41) {
s11 = peg$c28;
peg$currPos++;
} else {
s11 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c29); }
}
if (s11 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c43(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;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseNe() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
s0 = peg$currPos;
if (input.substr(peg$currPos, 3) === peg$c44) {
s1 = peg$c44;
peg$currPos += 3;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c45); }
}
if (s1 !== peg$FAILED) {
s2 = 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$c26;
peg$currPos++;
} else {
s5 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c27); }
}
if (s5 !== peg$FAILED) {
s6 = peg$parse__();
if (s6 !== peg$FAILED) {
s7 = peg$parseScalar();
if (s7 !== peg$FAILED) {
s8 = peg$parse__();
if (s8 !== peg$FAILED) {
s9 = peg$parseSwitches();
if (s9 === peg$FAILED) {
s9 = null;
}
if (s9 !== peg$FAILED) {
s10 = peg$parse__();
if (s10 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 41) {
s11 = peg$c28;
peg$currPos++;
} else {
s11 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c29); }
}
if (s11 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c46(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;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseStartsWith() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11;
s0 = peg$currPos;
if (input.substr(peg$currPos, 11) === peg$c47) {
s1 = peg$c47;
peg$currPos += 11;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c48); }
}
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$c26;
peg$currPos++;
} else {