filter-query-parser
Version:
Library for parsing the query string to an Object form and stringify Object to query string.
1,770 lines (1,589 loc) • 64.7 kB
JavaScript
PEG = (function() {
"use strict";
/*
* Generated by PEG.js 0.9.0.
*
* http://pegjs.org/
*/
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);
function peg$parse(input) {
var options = arguments.length > 1 ? arguments[1] : {},
parser = this,
peg$FAILED = {},
peg$startRuleFunctions = { start: peg$parsestart },
peg$startRuleFunction = peg$parsestart,
peg$c0 = "\\",
peg$c1 = { type: "literal", value: "\\", description: "\"\\\\\"" },
peg$c2 = "AND",
peg$c3 = { type: "literal", value: "AND", description: "\"AND\"" },
peg$c4 = "and",
peg$c5 = { type: "literal", value: "and", description: "\"and\"" },
peg$c6 = function(v) { return v.toUpperCase(); },
peg$c7 = "OR",
peg$c8 = { type: "literal", value: "OR", description: "\"OR\"" },
peg$c9 = "or",
peg$c10 = { type: "literal", value: "or", description: "\"or\"" },
peg$c11 = "=",
peg$c12 = { type: "literal", value: "=", description: "\"=\"" },
peg$c13 = "!=",
peg$c14 = { type: "literal", value: "!=", description: "\"!=\"" },
peg$c15 = ">",
peg$c16 = { type: "literal", value: ">", description: "\">\"" },
peg$c17 = ">=",
peg$c18 = { type: "literal", value: ">=", description: "\">=\"" },
peg$c19 = "<",
peg$c20 = { type: "literal", value: "<", description: "\"<\"" },
peg$c21 = "<=",
peg$c22 = { type: "literal", value: "<=", description: "\"<=\"" },
peg$c23 = "CONTAINS",
peg$c24 = { type: "literal", value: "CONTAINS", description: "\"CONTAINS\"" },
peg$c25 = "contains",
peg$c26 = { type: "literal", value: "contains", description: "\"contains\"" },
peg$c27 = "STARTS WITH",
peg$c28 = { type: "literal", value: "STARTS WITH", description: "\"STARTS WITH\"" },
peg$c29 = "starts with",
peg$c30 = { type: "literal", value: "starts with", description: "\"starts with\"" },
peg$c31 = "ENDS WITH",
peg$c32 = { type: "literal", value: "ENDS WITH", description: "\"ENDS WITH\"" },
peg$c33 = "ends with",
peg$c34 = { type: "literal", value: "ends with", description: "\"ends with\"" },
peg$c35 = "(",
peg$c36 = { type: "literal", value: "(", description: "\"(\"" },
peg$c37 = ")",
peg$c38 = { type: "literal", value: ")", description: "\")\"" },
peg$c39 = "\"",
peg$c40 = { type: "literal", value: "\"", description: "\"\\\"\"" },
peg$c41 = ",",
peg$c42 = { type: "literal", value: ",", description: "\",\"" },
peg$c43 = "true",
peg$c44 = { type: "literal", value: "true", description: "\"true\"" },
peg$c45 = "false",
peg$c46 = { type: "literal", value: "false", description: "\"false\"" },
peg$c47 = "!",
peg$c48 = { type: "literal", value: "!", description: "\"!\"" },
peg$c49 = "EXACTLY MATCHES",
peg$c50 = { type: "literal", value: "EXACTLY MATCHES", description: "\"EXACTLY MATCHES\"" },
peg$c51 = "exactly matches",
peg$c52 = { type: "literal", value: "exactly matches", description: "\"exactly matches\"" },
peg$c53 = "DOES NOT CONTAIN",
peg$c54 = { type: "literal", value: "DOES NOT CONTAIN", description: "\"DOES NOT CONTAIN\"" },
peg$c55 = "does not contain",
peg$c56 = { type: "literal", value: "does not contain", description: "\"does not contain\"" },
peg$c57 = "LIKE",
peg$c58 = { type: "literal", value: "LIKE", description: "\"LIKE\"" },
peg$c59 = "like",
peg$c60 = { type: "literal", value: "like", description: "\"like\"" },
peg$c61 = "BETWEEN",
peg$c62 = { type: "literal", value: "BETWEEN", description: "\"BETWEEN\"" },
peg$c63 = "between",
peg$c64 = { type: "literal", value: "between", description: "\"between\"" },
peg$c65 = "NOT BETWEEN",
peg$c66 = { type: "literal", value: "NOT BETWEEN", description: "\"NOT BETWEEN\"" },
peg$c67 = "not between",
peg$c68 = { type: "literal", value: "not between", description: "\"not between\"" },
peg$c69 = "IN",
peg$c70 = { type: "literal", value: "IN", description: "\"IN\"" },
peg$c71 = "in",
peg$c72 = { type: "literal", value: "in", description: "\"in\"" },
peg$c73 = "NOT IN",
peg$c74 = { type: "literal", value: "NOT IN", description: "\"NOT IN\"" },
peg$c75 = "not in",
peg$c76 = { type: "literal", value: "not in", description: "\"not in\"" },
peg$c77 = "NULL",
peg$c78 = { type: "literal", value: "NULL", description: "\"NULL\"" },
peg$c79 = "null",
peg$c80 = { type: "literal", value: "null", description: "\"null\"" },
peg$c81 = "NOT NULL",
peg$c82 = { type: "literal", value: "NOT NULL", description: "\"NOT NULL\"" },
peg$c83 = "not null",
peg$c84 = { type: "literal", value: "not null", description: "\"not null\"" },
peg$c85 = /^[0-9]/,
peg$c86 = { type: "class", value: "[0-9]", description: "[0-9]" },
peg$c87 = /^[0-9a-f]/i,
peg$c88 = { type: "class", value: "[0-9a-f]i", description: "[0-9a-f]i" },
peg$c89 = /^[ \t\n\r]/,
peg$c90 = { type: "class", value: "[ \\t\\n\\r]", description: "[ \\t\\n\\r]" },
peg$c91 = /^[ -!#-[\]-\u10FFFF]/,
peg$c92 = { type: "class", value: "[\\x20-\\x21\\x23-\\x5B\\x5D-\\u10FFFF]", description: "[\\x20-\\x21\\x23-\\x5B\\x5D-\\u10FFFF]" },
peg$c93 = function(chars) { return chars.join(""); },
peg$c94 = /^[+\-]/,
peg$c95 = { type: "class", value: "[\\+\\-]", description: "[\\+\\-]" },
peg$c96 = ".",
peg$c97 = { type: "literal", value: ".", description: "\".\"" },
peg$c98 = function() { return Number(text()); },
peg$c99 = function(v) { return v.toLowerCase() === 'true'; },
peg$c100 = /^[^=() \t\n\r]/,
peg$c101 = { type: "class", value: "[^=\\(\\) \\t\\n\\r]", description: "[^=\\(\\) \\t\\n\\r]" },
peg$c102 = function() { return text(); },
peg$c103 = "/",
peg$c104 = { type: "literal", value: "/", description: "\"/\"" },
peg$c105 = "b",
peg$c106 = { type: "literal", value: "b", description: "\"b\"" },
peg$c107 = function() { return "\b"; },
peg$c108 = "f",
peg$c109 = { type: "literal", value: "f", description: "\"f\"" },
peg$c110 = function() { return "\f"; },
peg$c111 = "n",
peg$c112 = { type: "literal", value: "n", description: "\"n\"" },
peg$c113 = function() { return "\n"; },
peg$c114 = "r",
peg$c115 = { type: "literal", value: "r", description: "\"r\"" },
peg$c116 = function() { return "\r"; },
peg$c117 = "t",
peg$c118 = { type: "literal", value: "t", description: "\"t\"" },
peg$c119 = function() { return "\t"; },
peg$c120 = "u",
peg$c121 = { type: "literal", value: "u", description: "\"u\"" },
peg$c122 = function(digits) {
return String.fromCharCode(parseInt(digits, 16));
},
peg$c123 = function(sequence) { return sequence; },
peg$c124 = function(op) {
return ComparisonOperator.fromString(text());
},
peg$c125 = function() { return LogicalOperator.fromString(text()); },
peg$c126 = function(g) { return g; },
peg$c127 = function(cg) { return cg; },
peg$c128 = function(head, op, cg) { return { op:op, cg:cg }; },
peg$c129 = function(head, tail) {
if (!tail) {
const items = [head];
return head;
} else {
const items = [head, tail.cg];
const op = tail.op;
const cg = new RuleSet(op, items);
return cg;
}
},
peg$c130 = function(cg) { cg.not = true; return cg; },
peg$c131 = function(cond) { return { op:LogicalOperator.AND, cond:cond}; },
peg$c132 = function(head, op, cond) { return { op:op, cond:cond }; },
peg$c133 = function(head, tail) {
const items = [head].concat(tail);
const conds = items.map(x => { return x.cond; });
let cg;
if (items.length === 1) {
cg = items[0].cond;
} else {
const ops = items.map(x => { return x.op; });
ops.shift();
const opSet = new Set(ops);
if (opSet.size > 1) {
throw 'AND and OR cannot be used together';
}
const op = opSet.values().next().value;
cg = new RuleSet(op, conds);
}
return cg;
},
peg$c134 = function(v1, v2) { return [v1, v2]; },
peg$c135 = function(head, rest) { return rest; },
peg$c136 = function(head, tail) {
return [head].concat(tail);
},
peg$c137 = function(v) { return v; },
peg$c138 = function(k, op, v) { return new Rule(k, op, v); },
peg$c139 = function(k, op) { return new Rule(k, op, ''); },
peg$currPos = 0,
peg$savedPos = 0,
peg$posDetailsCache = [{ line: 1, column: 1, seenCR: false }],
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) {
throw peg$buildException(
null,
[{ type: "other", description: description }],
input.substring(peg$savedPos, peg$currPos),
peg$computeLocation(peg$savedPos, peg$currPos)
);
}
function error(message) {
throw peg$buildException(
message,
null,
input.substring(peg$savedPos, peg$currPos),
peg$computeLocation(peg$savedPos, peg$currPos)
);
}
function peg$computePosDetails(pos) {
var details = peg$posDetailsCache[pos],
p, ch;
if (details) {
return details;
} else {
p = pos - 1;
while (!peg$posDetailsCache[p]) {
p--;
}
details = peg$posDetailsCache[p];
details = {
line: details.line,
column: details.column,
seenCR: details.seenCR
};
while (p < pos) {
ch = input.charAt(p);
if (ch === "\n") {
if (!details.seenCR) { details.line++; }
details.column = 1;
details.seenCR = false;
} else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
details.line++;
details.column = 1;
details.seenCR = true;
} else {
details.column++;
details.seenCR = false;
}
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$buildException(message, expected, found, location) {
function cleanupExpected(expected) {
var i = 1;
expected.sort(function(a, b) {
if (a.description < b.description) {
return -1;
} else if (a.description > b.description) {
return 1;
} else {
return 0;
}
});
while (i < expected.length) {
if (expected[i - 1] === expected[i]) {
expected.splice(i, 1);
} else {
i++;
}
}
}
function buildMessage(expected, found) {
function stringEscape(s) {
function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
return s
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\x08/g, '\\b')
.replace(/\t/g, '\\t')
.replace(/\n/g, '\\n')
.replace(/\f/g, '\\f')
.replace(/\r/g, '\\r')
.replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
.replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
.replace(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
.replace(/[\u1000-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
}
var expectedDescs = new Array(expected.length),
expectedDesc, foundDesc, i;
for (i = 0; i < expected.length; i++) {
expectedDescs[i] = expected[i].description;
}
expectedDesc = expected.length > 1
? expectedDescs.slice(0, -1).join(", ")
+ " or "
+ expectedDescs[expected.length - 1]
: expectedDescs[0];
foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
return "Expected " + expectedDesc + " but " + foundDesc + " found.";
}
if (expected !== null) {
cleanupExpected(expected);
}
return new peg$SyntaxError(
message !== null ? message : buildMessage(expected, found),
expected,
found,
location
);
}
function peg$parsestart() {
var s0;
s0 = peg$parseExpression();
return s0;
}
function peg$parseEscape() {
var s0;
if (input.charCodeAt(peg$currPos) === 92) {
s0 = peg$c0;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c1); }
}
return s0;
}
function peg$parseAND() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 3) === peg$c2) {
s1 = peg$c2;
peg$currPos += 3;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c3); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 3) === peg$c4) {
s1 = peg$c4;
peg$currPos += 3;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c5); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseOR() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c7) {
s1 = peg$c7;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c8); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c9) {
s1 = peg$c9;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c10); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseEQ() {
var s0;
if (input.charCodeAt(peg$currPos) === 61) {
s0 = peg$c11;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c12); }
}
return s0;
}
function peg$parseNE() {
var s0;
if (input.substr(peg$currPos, 2) === peg$c13) {
s0 = peg$c13;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c14); }
}
return s0;
}
function peg$parseGT() {
var s0;
if (input.charCodeAt(peg$currPos) === 62) {
s0 = peg$c15;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c16); }
}
return s0;
}
function peg$parseGE() {
var s0;
if (input.substr(peg$currPos, 2) === peg$c17) {
s0 = peg$c17;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c18); }
}
return s0;
}
function peg$parseLT() {
var s0;
if (input.charCodeAt(peg$currPos) === 60) {
s0 = peg$c19;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c20); }
}
return s0;
}
function peg$parseLE() {
var s0;
if (input.substr(peg$currPos, 2) === peg$c21) {
s0 = peg$c21;
peg$currPos += 2;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c22); }
}
return s0;
}
function peg$parseCONTAINS() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 8) === peg$c23) {
s1 = peg$c23;
peg$currPos += 8;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c24); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 8) === peg$c25) {
s1 = peg$c25;
peg$currPos += 8;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c26); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseSW() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 11) === peg$c27) {
s1 = peg$c27;
peg$currPos += 11;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c28); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 11) === peg$c29) {
s1 = peg$c29;
peg$currPos += 11;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c30); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseEW() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 9) === peg$c31) {
s1 = peg$c31;
peg$currPos += 9;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c32); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 9) === peg$c33) {
s1 = peg$c33;
peg$currPos += 9;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c34); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseL_PAR() {
var s0;
if (input.charCodeAt(peg$currPos) === 40) {
s0 = peg$c35;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c36); }
}
return s0;
}
function peg$parseR_PAR() {
var s0;
if (input.charCodeAt(peg$currPos) === 41) {
s0 = peg$c37;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c38); }
}
return s0;
}
function peg$parseDQ() {
var s0;
if (input.charCodeAt(peg$currPos) === 34) {
s0 = peg$c39;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c40); }
}
return s0;
}
function peg$parseSC() {
var s0;
if (input.charCodeAt(peg$currPos) === 44) {
s0 = peg$c41;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c42); }
}
return s0;
}
function peg$parseTRUE() {
var s0;
if (input.substr(peg$currPos, 4) === peg$c43) {
s0 = peg$c43;
peg$currPos += 4;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c44); }
}
return s0;
}
function peg$parseFALSE() {
var s0;
if (input.substr(peg$currPos, 5) === peg$c45) {
s0 = peg$c45;
peg$currPos += 5;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c46); }
}
return s0;
}
function peg$parseNOT() {
var s0;
if (input.charCodeAt(peg$currPos) === 33) {
s0 = peg$c47;
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c48); }
}
return s0;
}
function peg$parseEM() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 15) === peg$c49) {
s1 = peg$c49;
peg$currPos += 15;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c50); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 15) === peg$c51) {
s1 = peg$c51;
peg$currPos += 15;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c52); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseDNCONTAIN() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 16) === peg$c53) {
s1 = peg$c53;
peg$currPos += 16;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c54); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 16) === peg$c55) {
s1 = peg$c55;
peg$currPos += 16;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c56); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseLIKE() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 4) === peg$c57) {
s1 = peg$c57;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c58); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c59) {
s1 = peg$c59;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c60); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseBTW() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 7) === peg$c61) {
s1 = peg$c61;
peg$currPos += 7;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c62); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 7) === peg$c63) {
s1 = peg$c63;
peg$currPos += 7;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c64); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseNBTW() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 11) === peg$c65) {
s1 = peg$c65;
peg$currPos += 11;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c66); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 11) === peg$c67) {
s1 = peg$c67;
peg$currPos += 11;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c68); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseIN() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c69) {
s1 = peg$c69;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c70); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 2) === peg$c71) {
s1 = peg$c71;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c72); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseNIN() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 6) === peg$c73) {
s1 = peg$c73;
peg$currPos += 6;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c74); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 6) === peg$c75) {
s1 = peg$c75;
peg$currPos += 6;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c76); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseNULL() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 4) === peg$c77) {
s1 = peg$c77;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c78); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 4) === peg$c79) {
s1 = peg$c79;
peg$currPos += 4;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c80); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseNNULL() {
var s0, s1;
s0 = peg$currPos;
if (input.substr(peg$currPos, 8) === peg$c81) {
s1 = peg$c81;
peg$currPos += 8;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c82); }
}
if (s1 === peg$FAILED) {
if (input.substr(peg$currPos, 8) === peg$c83) {
s1 = peg$c83;
peg$currPos += 8;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c84); }
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c6(s1);
}
s0 = s1;
return s0;
}
function peg$parseDIGIT() {
var s0;
if (peg$c85.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
return s0;
}
function peg$parseHEXDIG() {
var s0;
if (peg$c87.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c88); }
}
return s0;
}
function peg$parsews() {
var s0, s1;
s0 = [];
if (peg$c89.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c90); }
}
while (s1 !== peg$FAILED) {
s0.push(s1);
if (peg$c89.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c90); }
}
}
return s0;
}
function peg$parseUnescaped() {
var s0;
if (peg$c91.test(input.charAt(peg$currPos))) {
s0 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s0 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c92); }
}
return s0;
}
function peg$parseString() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parseDQ();
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$parseChar();
while (s3 !== peg$FAILED) {
s2.push(s3);
s3 = peg$parseChar();
}
if (s2 !== peg$FAILED) {
s3 = peg$parseDQ();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c93(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$parseNumber() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
if (peg$c94.test(input.charAt(peg$currPos))) {
s1 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c95); }
}
if (s1 === peg$FAILED) {
s1 = null;
}
if (s1 !== peg$FAILED) {
s2 = [];
if (peg$c85.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
if (s3 !== peg$FAILED) {
while (s3 !== peg$FAILED) {
s2.push(s3);
if (peg$c85.test(input.charAt(peg$currPos))) {
s3 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
}
} else {
s2 = peg$FAILED;
}
if (s2 !== peg$FAILED) {
s3 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 46) {
s4 = peg$c96;
peg$currPos++;
} else {
s4 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c97); }
}
if (s4 !== peg$FAILED) {
s5 = [];
if (peg$c85.test(input.charAt(peg$currPos))) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
if (s6 !== peg$FAILED) {
while (s6 !== peg$FAILED) {
s5.push(s6);
if (peg$c85.test(input.charAt(peg$currPos))) {
s6 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s6 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c86); }
}
}
} else {
s5 = peg$FAILED;
}
if (s5 !== peg$FAILED) {
s4 = [s4, s5];
s3 = s4;
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
} else {
peg$currPos = s3;
s3 = peg$FAILED;
}
if (s3 === peg$FAILED) {
s3 = null;
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c98();
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$parseBoolean() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parseTRUE();
if (s1 === peg$FAILED) {
s1 = peg$parseFALSE();
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c99(s1);
}
s0 = s1;
return s0;
}
function peg$parseKey() {
var s0, s1, s2;
s0 = peg$currPos;
s1 = [];
if (peg$c100.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c101); }
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
s1.push(s2);
if (peg$c100.test(input.charAt(peg$currPos))) {
s2 = input.charAt(peg$currPos);
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c101); }
}
}
} else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c102();
}
s0 = s1;
return s0;
}
function peg$parseValue() {
var s0;
s0 = peg$parseString();
if (s0 === peg$FAILED) {
s0 = peg$parseNumber();
if (s0 === peg$FAILED) {
s0 = peg$parseBoolean();
}
}
return s0;
}
function peg$parseChar() {
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
s0 = peg$parseUnescaped();
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseEscape();
if (s1 !== peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 34) {
s2 = peg$c39;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c40); }
}
if (s2 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 92) {
s2 = peg$c0;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c1); }
}
if (s2 === peg$FAILED) {
if (input.charCodeAt(peg$currPos) === 47) {
s2 = peg$c103;
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c104); }
}
if (s2 === peg$FAILED) {
s2 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 98) {
s3 = peg$c105;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c106); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s2;
s3 = peg$c107();
}
s2 = s3;
if (s2 === peg$FAILED) {
s2 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 102) {
s3 = peg$c108;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c109); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s2;
s3 = peg$c110();
}
s2 = s3;
if (s2 === peg$FAILED) {
s2 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 110) {
s3 = peg$c111;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c112); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s2;
s3 = peg$c113();
}
s2 = s3;
if (s2 === peg$FAILED) {
s2 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 114) {
s3 = peg$c114;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c115); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s2;
s3 = peg$c116();
}
s2 = s3;
if (s2 === peg$FAILED) {
s2 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 116) {
s3 = peg$c117;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c118); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s2;
s3 = peg$c119();
}
s2 = s3;
if (s2 === peg$FAILED) {
s2 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 117) {
s3 = peg$c120;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$c121); }
}
if (s3 !== peg$FAILED) {
s4 = peg$currPos;
s5 = peg$currPos;
s6 = peg$parseHEXDIG();
if (s6 !== peg$FAILED) {
s7 = peg$parseHEXDIG();
if (s7 !== peg$FAILED) {
s8 = peg$parseHEXDIG();
if (s8 !== peg$FAILED) {
s9 = peg$parseHEXDIG();
if (s9 !== peg$FAILED) {
s6 = [s6, s7, s8, s9];
s5 = s6;
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
} else {
peg$currPos = s5;
s5 = peg$FAILED;
}
if (s5 !== peg$FAILED) {
s4 = input.substring(s4, peg$currPos);
} else {
s4 = s5;
}
if (s4 !== peg$FAILED) {
peg$savedPos = s2;
s3 = peg$c122(s4);
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
}
}
}
}
}
}
}
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c123(s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
}
return s0;
}
function peg$parseComparisonOperator() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parseGE();
if (s1 === peg$FAILED) {
s1 = peg$parseLE();
if (s1 === peg$FAILED) {
s1 = peg$parseEQ();
if (s1 === peg$FAILED) {
s1 = peg$parseNE();
if (s1 === peg$FAILED) {
s1 = peg$parseGT();
if (s1 === peg$FAILED) {
s1 = peg$parseLT();
if (s1 === peg$FAILED) {
s1 = peg$parseCONTAINS();
if (s1 === peg$FAILED) {
s1 = peg$parseSW();
if (s1 === peg$FAILED) {
s1 = peg$parseEW();
if (s1 === peg$FAILED) {
s1 = peg$parseDNCONTAIN();
if (s1 === peg$FAILED) {
s1 = peg$parseLIKE();
if (s1 === peg$FAILED) {
s1 = peg$parseEM();
if (s1 === peg$FAILED) {
s1 = peg$parseBTW();
if (s1 === peg$FAILED) {
s1 = peg$parseNBTW();
if (s1 === peg$FAILED) {
s1 = peg$parseIN();
if (s1 === peg$FAILED) {
s1 = peg$parseNIN();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c124(s1);
}
s0 = s1;
return s0;
}
function peg$parseNULLOperator() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parseNULL();
if (s1 === peg$FAILED) {
s1 = peg$parseNNULL();
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c124(s1);
}
s0 = s1;
return s0;
}
function peg$parseLogicalOperator() {
var s0, s1;
s0 = peg$parseAND();
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseOR();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c125();
}
s0 = s1;
}
return s0;
}
function peg$parseExpression() {
var s0, s1, s2, s3;
s0 = peg$currPos;
s1 = peg$parsews();
if (s1 !== peg$FAILED) {
s2 = peg$parseGrammar();
if (s2 !== peg$FAILED) {
s3 = peg$parsews();
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c126(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$parseGrammar() {
var s0, s1;
s0 = peg$currPos;
s1 = peg$parseRuleSets();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c127(s1);
}
s0 = s1;
return s0;
}
function peg$parseRuleSets() {
var s0, s1, s2, s3, s4, s5, s6;
s0 = peg$currPos;
s1 = peg$parseRuleSet();
if (s1 !== peg$FAILED) {
s2 = peg$currPos;
s3 = peg$parsews();
if (s3 !== peg$FAILED) {
s4 = peg$parseLogicalOperator();
if (s4 !== peg$FAILED) {
s5 = peg$parsews();
if (s5 !== peg$FAILED) {
s6 = peg$parseRuleSet();
if (s6 !== peg$FAILED) {
peg$savedPos = s2;
s3 = peg$c128(s1, s4, s6);
s2 = s3;
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
} else {
peg$currPos = s2;
s2 = peg$FAILED;
}
if (s2 === peg$FAILED) {
s2 = null;
}
if (s2 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c129(s1, s2);
s0 = s1;
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
return s0;
}
function peg$parseRuleSet() {
var s0, s1, s2, s3, s4, s5, s6, s7;
s0 = peg$currPos;
s1 = peg$parseL_PAR();
if (s1 !== peg$FAILED) {
s2 = peg$parsews();
if (s2 !== peg$FAILED) {
s3 = peg$parse_RuleSet();
if (s3 !== peg$FAILED) {
s4 = peg$parsews();
if (s4 !== peg$FAILED) {
s5 = peg$parseR_PAR();
if (s5 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c127(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;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parseNOT();
if (s1 !== peg$FAILED) {
s2 = peg$parsews();
if (s2 !== peg$FAILED) {
s3 = peg$parseL_PAR();
if (s3 !== peg$FAILED) {
s4 = peg$parsews();
if (s4 !== peg$FAILED) {
s5 = peg$parse_RuleSet();
if (s5 !== peg$FAILED) {
s6 = peg$parsews();
if (s6 !== peg$FAILED) {
s7 = peg$parseR_PAR();
if (s7 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c130(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;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
} else {
peg$currPos = s0;
s0 = peg$FAILED;
}
if (s0 === peg$FAILED) {
s0 = peg$currPos;
s1 = peg$parse_RuleSet();
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$c127(s1);
}
s0 = s1;
}
}
return s0;
}
function peg$parse_RuleSet() {
var s0, s1, s2, s3, s4, s5, s6, s7;
s0 = peg$currPos;
s1 = peg$currPos;
s2 = peg$parseRule();
if (s2 !== peg$FAILED) {
peg$savedPos = s1;
s2 = peg$c131(s2);
}
s1 = s2;
if (s1 !== peg$FAILED) {
s2 = [];
s3 = peg$currPos;
s4 = peg$parsews();
if (s4 !== peg$FAILED) {
s5 = peg$parseLogicalOperator();
if (s5 !== peg$FAILED) {
s6 = peg$parsews();
if (s6 !== peg$FAILED) {
s7 = peg$parseRule();
if (s7 !== peg$FAILED) {
peg$savedPos = s3;
s4 = peg$c132(s1, s5, s7);