UNPKG

lucene-kit

Version:

Lightweight and extensive, Lucene-like solution provides powerful full-text search, serialization, and parser for your application.

1,667 lines (1,663 loc) 157 kB
// src/types/guards.ts function _getType(node) { if (!node || typeof node !== "object") return; return node.type || void 0; } function isNode(node) { if (!node || typeof node !== "object") return false; return node["type"] !== void 0; } function isConjunction(node) { return _getType(node) === "conjunction" /* Conjunction */; } function isNegation(node) { return _getType(node) === "negation" /* Negation */; } function isRange(node) { return _getType(node) === "range" /* Range */; } function isFunctionNode(node) { return _getType(node) === "function" /* Function */; } function isRegexp(node) { return _getType(node) === "regexp" /* Regexp */; } function isWildcard(node) { return _getType(node) === "wildcard" /* Wildcard */; } function isVariableNode(node) { return isTerm(node) && node?.value?.type == "variable"; } function isWildCardString(term) { if (typeof term !== "string") return false; if (term.includes("*") || term.includes("?")) return true; return false; } function isTerm(node) { return _getType(node) === "term" /* Term */; } function isTermList(node) { return _getType(node) === "term-list" /* TermList */; } function isEmptyNode(node) { return _getType(node) === "empty" /* Empty */; } function isStringDataType(node) { return !!(node && typeof node?.value?.value === "string"); } var termTypes = [ "term" /* Term */, "regexp" /* Regexp */, "range" /* Range */, "wildcard" /* Wildcard */, "function" /* Function */, "term-list" /* TermList */ ]; function isTermType(node) { return !!(node && termTypes.includes(node?.type)); } var groupTypes = ["logical-group" /* LogicalGroup */, "field-group" /* FieldGroup */]; function isGroupLike(node) { return !!(node && groupTypes.includes(node?.type)); } // src/filter/test-value.ts var MAX_TIMESTAMP = 864e13; function testString(value, filter2, quoted) { if (quoted) { return String(value) == String(filter2); } else if (value instanceof Date) { return value.toLocaleString().includes(new Date(String(filter2)).toLocaleString()); } else { return String(value).toLocaleLowerCase().includes(String(filter2).toLowerCase()); } } function testRegexp(value, filter2) { if (value == void 0 || value == null) { return false; } return filter2.test(String(value)); } function testWildcard(value, filter2) { const regexPattern = escapeRegExp(filter2).replaceAll(String.raw`\*`, ".*").replaceAll(String.raw`\?`, "."); const regex = new RegExp(`^${regexPattern}$`); return testRegexp(value, regex); } function testRangeNode(operator, value, filter2) { switch (operator) { case "gte": { return compareValues(value, filter2, -1) >= 0; } case "gt": { return compareValues(value, filter2, -1) > 0; } case "lt": { return compareValues(value, filter2, 1) < 0; } case "lte": { return compareValues(value, filter2, 1) <= 0; } default: { return true; } } } function compareValues(a, b, falseValue) { if (typeof a === "number") { return a - Number(b); } else if (typeof b === "string" && isWildCardString(b)) { return testWildcard(a, b) ? 0 : -1; } else if (a instanceof Date) { return a.getTime() - new Date(b == Infinity ? MAX_TIMESTAMP : String(b)).getTime(); } else if (typeof b === "boolean" || typeof a === "boolean") { return a == b ? 1 : 0; } else if (typeof a === "string") { return a.localeCompare(String(b)); } else { return falseValue; } } function escapeRegExp(str) { return str.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`); } // src/utils/iterate.ts var NOT_ITERABLE = [Date]; function* iterate(obj, field = "", config = defaultIteratorConfig) { const splittedFields = field.split("."); function* _iterate(obj2, currentPath, depth) { const checkPrivate = config.featureEnablePrivateField; if (depth > config.maxDepth) return; const currentField = splittedFields[currentPath.length]; const lastField = splittedFields.length > 0 ? splittedFields.at(-1) : ""; const isTrailingWildcard = lastField?.endsWith("*") && !currentField; const isWildcard2 = isWildCardString(currentField); if (typeof obj2 === "object" && obj2 !== null && !NOT_ITERABLE.some((cls) => obj2 instanceof cls)) { if (Array.isArray(obj2) && currentPath.length === splittedFields.length && !isTrailingWildcard && field) { for (const [i2, element] of obj2.entries()) { yield [[...currentPath, i2].join("."), element]; } return; } const arrayWithInnerKey = Array.isArray(obj2) && obj2.some((o) => objectHasField(o, currentField, checkPrivate)); const objWithCurrentField = objectHasField(obj2, currentField, checkPrivate); if (!isWildcard2 && objWithCurrentField && !arrayWithInnerKey) { const newPath = [...currentPath, objWithCurrentField]; yield* _iterate(obj2[objWithCurrentField], newPath, depth + 1); } else { if (arrayWithInnerKey) { splittedFields.splice(currentPath.length, 0, "*"); } for (const key in obj2) { if (checkPrivate && isPrivateField(key) && privateFieldName(key) != currentField) continue; if (Object.prototype.hasOwnProperty.call(obj2, key)) { let objKeyWithCurrentField = ""; if (!field || currentField && testWildcard(checkPrivate ? privateFieldName(key) : key, currentField) || isTrailingWildcard) { const newPath = [...currentPath, key]; yield* _iterate(obj2[key], newPath, depth + 1); } else if (arrayWithInnerKey && typeof obj2[key] === "object" && obj2[key] !== null && (objKeyWithCurrentField = objectHasField(obj2[key], currentField, checkPrivate))) { const newPath = [...currentPath, key, objKeyWithCurrentField]; yield* _iterate(obj2[key][objKeyWithCurrentField], newPath, depth + 1); } } } } } else if (currentPath.length === splittedFields.length || isTrailingWildcard || !field) { yield [currentPath.join("."), obj2]; } } yield* _iterate(obj, [], 1); } var defaultIteratorConfig = { maxDepth: Infinity, featureEnablePrivateField: false }; function isPrivateField(key) { return key.startsWith("_"); } function privateFieldName(key) { return key.startsWith("_") ? key.slice(1) : key; } function objectHasField(obj, key, featureEnablePrivateField) { const privateKey = `_${key}`; if (Object.prototype.hasOwnProperty.call(obj, key)) return key; if (featureEnablePrivateField && Object.prototype.hasOwnProperty.call(obj, privateKey)) return privateKey; return ""; } // src/xlucene/helpers/index.ts function validateScopedChars(chars) { for (const [idx, char] of chars.entries()) { if (char === "." && chars[idx + 1] === ".") { throw new Error(`Invalid scoped variable "@${chars.join("")}", char "." cannot be next to another "." char`); } } } function propagateDefaultField(node, field) { if (!node) return; if (isRange(node)) { node.field ??= field; return; } if (isTermType(node)) { node.field ??= field; return; } if (isNegation(node)) { propagateDefaultField(node.node, field); return; } if (isGroupLike(node)) { for (const conj of node.flow) { propagateDefaultField(conj, field); } return; } if (isConjunction(node)) { for (const conj of node.nodes) { propagateDefaultField(conj, field); } } } // src/xlucene/lucene.ts var peggyParser = ( // Generated by Peggy 3.0.2. // // https://peggyjs.org/ // @ts-ignore function() { "use strict"; function peg$subclass(child, parent) { function C() { this.constructor = child; } C.prototype = parent.prototype; child.prototype = new C(); } function peg$SyntaxError(message, expected, found, location) { var self = Error.call(this, message); if (Object.setPrototypeOf) { Object.setPrototypeOf(self, peg$SyntaxError.prototype); } self.expected = expected; self.found = found; self.location = location; self.name = "SyntaxError"; return self; } peg$subclass(peg$SyntaxError, Error); function peg$padEnd(str, targetLength, padString) { padString = padString || " "; if (str.length > targetLength) { return str; } targetLength -= str.length; padString += padString.repeat(targetLength); return str + padString.slice(0, targetLength); } peg$SyntaxError.prototype.format = function(sources) { var str = "Error: " + this.message; if (this.location) { var src = null; var k; for (k = 0; k < sources.length; k++) { if (sources[k].source === this.location.source) { src = sources[k].text.split(/\r\n|\n|\r/g); break; } } var s = this.location.start; var offset_s = this.location.source && typeof this.location.source.offset === "function" ? this.location.source.offset(s) : s; var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column; if (src) { var e = this.location.end; var filler = peg$padEnd("", offset_s.line.toString().length, " "); var line = src[s.line - 1]; var last = s.line === e.line ? e.column : line.length + 1; var hatLen = last - s.column || 1; str += "\n --> " + loc + "\n" + filler + " |\n" + offset_s.line + " | " + line + "\n" + filler + " | " + peg$padEnd("", s.column - 1, " ") + peg$padEnd("", hatLen, "^"); } else { str += "\n at " + loc; } } return str; }; peg$SyntaxError.buildMessage = function(expected, found) { var DESCRIBE_EXPECTATION_FNS = { // @ts-ignore literal: function(expectation) { return '"' + literalEscape(expectation.text) + '"'; }, // @ts-ignore class: function(expectation) { var escapedParts = expectation.parts.map(function(part) { return Array.isArray(part) ? classEscape(part[0]) + "-" + classEscape(part[1]) : classEscape(part); }); return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]"; }, // @ts-ignore any: function() { return "any character"; }, // @ts-ignore end: function() { return "end of input"; }, // @ts-ignore 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(expected2) { var descriptions = expected2.map(describeExpectation); var i2, j; descriptions.sort(); if (descriptions.length > 0) { for (i2 = 1, j = 1; i2 < descriptions.length; i2++) { if (descriptions[i2 - 1] !== descriptions[i2]) { descriptions[j] = descriptions[i2]; j++; } } descriptions.length = j; } switch (descriptions.length) { // @ts-ignore case 1: return descriptions[0]; // @ts-ignore case 2: return descriptions[0] + " or " + descriptions[1]; // @ts-ignore default: return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1]; } } function describeFound(found2) { return found2 ? '"' + literalEscape(found2) + '"' : "end of input"; } return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; }; function peg$parse(input, options) { options = options !== void 0 ? options : {}; var peg$FAILED = {}; var peg$source = options.grammarSource; var peg$startRuleFunctions = { start: peg$parsestart }; var peg$startRuleFunction = peg$parsestart; var peg$c0 = "NOT"; var peg$c1 = "!"; var peg$c2 = "*"; var peg$c3 = "]"; var peg$c4 = "/"; var peg$c5 = "_exists_"; var peg$c6 = "true"; var peg$c7 = "false"; var peg$c8 = ">="; var peg$c9 = ">"; var peg$c10 = "<="; var peg$c11 = "<"; var peg$c12 = "["; var peg$c13 = "{"; var peg$c14 = "}"; var peg$c15 = "TO"; var peg$c16 = "("; var peg$c17 = ")"; var peg$c18 = ","; var peg$c19 = "?"; var peg$c20 = ":"; var peg$c21 = "."; var peg$c22 = '"'; var peg$c23 = "'"; var peg$c24 = "\\"; var peg$c25 = "b"; var peg$c26 = "f"; var peg$c27 = "n"; var peg$c28 = "r"; var peg$c29 = "t"; var peg$c30 = "v"; var peg$c31 = "AND"; var peg$c32 = "&&"; var peg$c33 = "OR"; var peg$c34 = "||"; var peg$c35 = "0"; var peg$c36 = "$"; var peg$c37 = "@"; var peg$c38 = " "; var peg$c39 = "+"; var peg$c40 = "-"; var peg$c41 = "^"; var peg$c42 = "&"; var peg$c43 = "|"; var peg$c44 = "~"; var peg$c45 = " "; var peg$c46 = "\v"; var peg$c47 = "\f"; var peg$r0 = /^[gimsuy]/; var peg$r1 = /^[^?*( ]/; var peg$r2 = /^[^?*) ]/; var peg$r3 = /^[_a-zA-Z0-9\-.?*]/; var peg$r4 = /^[_a-zA-Z0-9]/; var peg$r5 = /^[_a-zA-Z0-9.]/; var peg$r6 = /^[^:*?{}()"\/\^~[\]]/; var peg$r7 = /^[^ \t\r\n\f{}()|\/\\\/\^~[\]&!?=<>]/; var peg$r8 = /^[1-9]/; var peg$r9 = /^[0-9]/; var peg$e0 = peg$literalExpectation("NOT", false); var peg$e1 = peg$literalExpectation("!", false); var peg$e2 = peg$literalExpectation("*", false); var peg$e3 = peg$literalExpectation("]", false); var peg$e4 = peg$literalExpectation("/", false); var peg$e5 = peg$classExpectation(["g", "i", "m", "s", "u", "y"], false, false); var peg$e6 = peg$literalExpectation("_exists_", false); var peg$e7 = peg$literalExpectation("true", false); var peg$e8 = peg$literalExpectation("false", false); var peg$e9 = peg$literalExpectation(">=", false); var peg$e10 = peg$literalExpectation(">", false); var peg$e11 = peg$literalExpectation("<=", false); var peg$e12 = peg$literalExpectation("<", false); var peg$e13 = peg$literalExpectation("[", false); var peg$e14 = peg$literalExpectation("{", false); var peg$e15 = peg$literalExpectation("}", false); var peg$e16 = peg$literalExpectation("TO", false); var peg$e17 = peg$literalExpectation("(", false); var peg$e18 = peg$literalExpectation(")", false); var peg$e19 = peg$literalExpectation(",", false); var peg$e20 = peg$otherExpectation("wildcard"); var peg$e21 = peg$classExpectation(["?", "*", "(", " "], true, false); var peg$e22 = peg$literalExpectation("?", false); var peg$e23 = peg$classExpectation(["?", "*", ")", " "], true, false); var peg$e24 = peg$otherExpectation("field"); var peg$e25 = peg$classExpectation(["_", ["a", "z"], ["A", "Z"], ["0", "9"], "-", ".", "?", "*"], false, false); var peg$e26 = peg$classExpectation(["_", ["a", "z"], ["A", "Z"], ["0", "9"]], false, false); var peg$e27 = peg$classExpectation(["_", ["a", "z"], ["A", "Z"], ["0", "9"], "."], false, false); var peg$e28 = peg$otherExpectation(""); var peg$e29 = peg$literalExpectation(":", false); var peg$e30 = peg$literalExpectation(".", false); var peg$e31 = peg$otherExpectation("term"); var peg$e32 = peg$classExpectation([":", "*", "?", "{", "}", "(", ")", '"', "/", "^", "~", "[", "]"], true, false); var peg$e33 = peg$classExpectation([" ", " ", "\r", "\n", "\f", "{", "}", "(", ")", "|", "/", "\\", "/", "^", "~", "[", "]", "&", "!", "?", "=", "<", ">"], true, false); var peg$e34 = peg$literalExpectation('"', false); var peg$e35 = peg$literalExpectation("'", false); var peg$e36 = peg$literalExpectation("\\", false); var peg$e37 = peg$anyExpectation(); var peg$e38 = peg$literalExpectation("b", false); var peg$e39 = peg$literalExpectation("f", false); var peg$e40 = peg$literalExpectation("n", false); var peg$e41 = peg$literalExpectation("r", false); var peg$e42 = peg$literalExpectation("t", false); var peg$e43 = peg$literalExpectation("v", false); var peg$e44 = peg$literalExpectation("AND", false); var peg$e45 = peg$literalExpectation("&&", false); var peg$e46 = peg$literalExpectation("OR", false); var peg$e47 = peg$literalExpectation("||", false); var peg$e48 = peg$literalExpectation("0", false); var peg$e49 = peg$otherExpectation("a character between 1-9"); var peg$e50 = peg$classExpectation([["1", "9"]], false, false); var peg$e51 = peg$otherExpectation("a character between 0-9"); var peg$e52 = peg$classExpectation([["0", "9"]], false, false); var peg$e53 = peg$literalExpectation("$", false); var peg$e54 = peg$literalExpectation("@", false); var peg$e55 = peg$literalExpectation(" ", false); var peg$e56 = peg$literalExpectation("+", false); var peg$e57 = peg$literalExpectation("-", false); var peg$e58 = peg$literalExpectation("^", false); var peg$e59 = peg$literalExpectation("&", false); var peg$e60 = peg$literalExpectation("|", false); var peg$e61 = peg$literalExpectation("~", false); var peg$e62 = peg$otherExpectation("whitespace"); var peg$e63 = peg$literalExpectation(" ", false); var peg$e64 = peg$literalExpectation("\v", false); var peg$e65 = peg$literalExpectation("\f", false); var peg$f0 = function(negate) { return negate; }; var peg$f1 = function(logic) { return logic; }; var peg$f2 = function(term) { return term; }; var peg$f3 = function(term) { return term; }; var peg$f4 = function(group) { return group; }; var peg$f5 = function() { return { // @ts-ignore type: "empty" /* Empty */ }; }; var peg$f6 = function(conjunctions) { return { // @ts-ignore type: "logical-group" /* LogicalGroup */, // @ts-ignore flow: [].concat(...conjunctions) }; }; var peg$f7 = function(group) { return group; }; var peg$f8 = function(group) { return group; }; var peg$f9 = function(nodes) { return [{ // @ts-ignore type: "conjunction" /* Conjunction */, // @ts-ignore nodes: [].concat(...nodes) }]; }; var peg$f10 = function(nodes) { return nodes.reduce((prev, current) => { current.forEach((node) => { prev.push({ // @ts-ignore type: "conjunction" /* Conjunction */, // @ts-ignore nodes: Array.isArray(node) ? node : [node] }); }); return prev; }, []); }; var peg$f11 = function(left, nodes) { return [left, ...nodes]; }; var peg$f12 = function(right, nodes) { if (!nodes) return [right]; return [right, ...nodes]; }; var peg$f13 = function(right, nodes) { if (!nodes) return [right]; return [right, ...nodes]; }; var peg$f14 = function(left, right, nodes) { if (nodes) { return [left, [right, ...nodes]]; } return [left, right]; }; var peg$f15 = function(right, nodes) { if (nodes) { return [[right, ...nodes]]; } return [right]; }; var peg$f16 = function(left, right) { return [left, right]; }; var peg$f17 = function(node) { return { // @ts-ignore type: "negation" /* Negation */, // @ts-ignore node }; }; var peg$f18 = function(node) { return { // @ts-ignore type: "negation" /* Negation */, // @ts-ignore node }; }; var peg$f19 = function(node) { return node; }; var peg$f20 = function(field, group) { const node = { // @ts-ignore ...group, // @ts-ignore type: "field-group" /* FieldGroup */, // @ts-ignore field }; propagateDefaultField(group, field); return node; }; var peg$f21 = function(field) { return { // @ts-ignore type: "exists" /* Exists */, // @ts-ignore field }; }; var peg$f22 = function(field, range2) { return { // @ts-ignore ...range2, // @ts-ignore field }; }; var peg$f23 = function(field, term) { const node = { ...term, field }; return node; }; var peg$f24 = function(field, term) { const node = { ...term, field }; return node; }; var peg$f25 = function(field, value) { return false; }; var peg$f26 = function(field, value) { const term = { // @ts-ignore type: i.NodeType.Term, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value } }; return { // @ts-ignore ...term, // @ts-ignore field }; }; var peg$f27 = function(field, term) { const node = { ...term, field }; return node; }; var peg$f28 = function(field, variableTerm) { const node = { // @ts-ignore type: "term" /* Term */, // @ts-ignore field, // @ts-ignore value: variableTerm.value }; return node; }; var peg$f29 = function(range2) { return { // @ts-ignore ...range2, // @ts-ignore field: null }; }; var peg$f30 = function(term) { return { // @ts-ignore ...term, // @ts-ignore field: null }; }; var peg$f31 = function(term) { return term; }; var peg$f32 = function(term) { return { // @ts-ignore ...term, // @ts-ignore field: null }; }; var peg$f33 = function(field, term) { const { name, params } = term; return { // @ts-ignore type: "function" /* Function */, // @ts-ignore name, // @ts-ignore params, // @ts-ignore field }; }; var peg$f34 = function(name, fnArgs) { const params = fnArgs || []; return { params, name }; }; var peg$f35 = function(param, params) { if (params) return [param, ...params]; return [param]; }; var peg$f36 = function(param, params) { if (params) return [param, ...params]; return [param]; }; var peg$f37 = function(field, list) { const values = list && list.length > 0 ? list : []; return { // @ts-ignore type: "term-list" /* TermList */, // @ts-ignore field, // @ts-ignore value: values }; }; var peg$f38 = function(term) { return term.value; }; var peg$f39 = function(list) { return list; }; var peg$f40 = function(term) { return term; }; var peg$f41 = function(term) { return { // @ts-ignore ...term, // @ts-ignore field: null }; }; var peg$f42 = function(left, right) { return { // @ts-ignore type: "range" /* Range */, // @ts-ignore left, // @ts-ignore right }; }; var peg$f43 = function(operator, value) { return { // @ts-ignore type: "range" /* Range */, // @ts-ignore left: { // @ts-ignore operator, // @ts-ignore ...value } }; }; var peg$f44 = function(operator, value) { return { // @ts-ignore ...value, // @ts-ignore operator }; }; var peg$f45 = function(value, operator) { return { // @ts-ignore ...value, // @ts-ignore operator }; }; var peg$f46 = function() { return { // @ts-ignore type: "term" /* Term */, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value: Number.NEGATIVE_INFINITY } }; }; var peg$f47 = function() { return { // @ts-ignore type: "term" /* Term */, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value: Number.POSITIVE_INFINITY } }; }; var peg$f48 = function(chars) { const value = chars.join(""); const node = { // @ts-ignore type: "term" /* Term */, // @ts-ignore value: { // @ts-ignore type: "variable", // @ts-ignore scoped: false, // @ts-ignore value } }; return node; }; var peg$f49 = function(chars) { throw new Error('Cannot have a variable char next to a "@"'); }; var peg$f50 = function(chars) { validateScopedChars(chars); const value = `@${chars.join("")}`; const node = { // @ts-ignore type: "term" /* Term */, // @ts-ignore value: { // @ts-ignore type: "variable", // @ts-ignore scoped: true, // @ts-ignore value } }; return node; }; var peg$f51 = function(value) { return { // @ts-ignore type: "term" /* Term */, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value } }; }; var peg$f52 = function(value) { return { // @ts-ignore type: "term" /* Term */, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value } }; }; var peg$f53 = function(value) { return { // @ts-ignore type: "term" /* Term */, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value } }; }; var peg$f54 = function(value, flags) { return { // @ts-ignore type: "regexp" /* Regexp */, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value: new RegExp(value, flags.join("")) } }; }; var peg$f55 = function(value) { return { // @ts-ignore type: "wildcard" /* Wildcard */, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value } }; }; var peg$f56 = function(value) { return { // @ts-ignore type: "term" /* Term */, // @ts-ignore quoted: true, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value } }; }; var peg$f57 = function(value) { return { // @ts-ignore type: "term" /* Term */, // @ts-ignore quoted: false, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value } }; }; var peg$f58 = function(value) { return { // @ts-ignore type: "term" /* Term */, // @ts-ignore restricted: true, // @ts-ignore quoted: false, // @ts-ignore value: { // @ts-ignore type: "value", // @ts-ignore value } }; }; var peg$f59 = function(chars) { return chars.join(""); }; var peg$f60 = function(chars) { return chars.join(""); }; var peg$f61 = function(chars) { return chars.join(""); }; var peg$f62 = function(chars) { return chars.join(""); }; var peg$f63 = function(chars) { return chars.join(""); }; var peg$f64 = function() { return text().split(""); }; var peg$f65 = function(int) { return parseInt(int, 10); }; var peg$f66 = function(float) { return parseFloat(float); }; var peg$f67 = function() { return true; }; var peg$f68 = function() { return false; }; var peg$f69 = function() { return "gte"; }; var peg$f70 = function() { return "gt"; }; var peg$f71 = function() { return "lte"; }; var peg$f72 = function() { return "lt"; }; var peg$f73 = function() { return "gte"; }; var peg$f74 = function() { return "gt"; }; var peg$f75 = function() { return "lte"; }; var peg$f76 = function() { return "lt"; }; var peg$f77 = function(sequence) { return "\\" + sequence; }; var peg$f78 = function(sequence) { return "\\" + sequence; }; var peg$f79 = function(chars) { return chars.join(""); }; var peg$f80 = function(chars) { return chars.join(""); }; var peg$f81 = function(char) { return char; }; var peg$f82 = function(sequence) { return sequence; }; var peg$f83 = function(char) { return char; }; var peg$f84 = function(sequence) { return sequence; }; var peg$f85 = function() { return "\b"; }; var peg$f86 = function() { return "\f"; }; var peg$f87 = function() { return "\n"; }; var peg$f88 = function() { return "\r"; }; var peg$f89 = function() { return " "; }; var peg$f90 = function() { return "\v"; }; var peg$f91 = function(char) { return char; }; var peg$f92 = function(sequence) { return "\\" + sequence; }; var peg$currPos = 0; var peg$savedPos = 0; var peg$posDetailsCache = [{ line: 1, column: 1 }]; var peg$maxFailPos = 0; var peg$maxFailExpected = []; var peg$silentFails = 0; var 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 offset() { return peg$savedPos; } function range() { return { // @ts-ignore source: peg$source, // @ts-ignore start: peg$savedPos, // @ts-ignore end: peg$currPos }; } function location() { return peg$computeLocation(peg$savedPos, peg$currPos); } function expected(description, location2) { location2 = location2 !== void 0 ? location2 : peg$computeLocation(peg$savedPos, peg$currPos); throw peg$buildStructuredError( // @ts-ignore [peg$otherExpectation(description)], // @ts-ignore input.substring(peg$savedPos, peg$currPos), // @ts-ignore location2 ); } function error(message, location2) { location2 = location2 !== void 0 ? location2 : peg$computeLocation(peg$savedPos, peg$currPos); throw peg$buildSimpleError(message, location2); } function peg$literalExpectation(text2, ignoreCase) { return { type: "literal", text: text2, ignoreCase }; } function peg$classExpectation(parts, inverted, ignoreCase) { return { type: "class", parts, inverted, ignoreCase }; } function peg$anyExpectation() { return { type: "any" }; } function peg$endExpectation() { return { type: "end" }; } function peg$otherExpectation(description) { return { type: "other", description }; } function peg$computePosDetails(pos) { var details = peg$posDetailsCache[pos]; var p; if (details) { return details; } else { p = pos - 1; while (!peg$posDetailsCache[p]) { p--; } details = peg$posDetailsCache[p]; details = { // @ts-ignore line: details.line, // @ts-ignore 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, offset2) { var startPosDetails = peg$computePosDetails(startPos); var endPosDetails = peg$computePosDetails(endPos); var res = { // @ts-ignore source: peg$source, // @ts-ignore start: { // @ts-ignore offset: startPos, // @ts-ignore line: startPosDetails.line, // @ts-ignore column: startPosDetails.column }, // @ts-ignore end: { // @ts-ignore offset: endPos, // @ts-ignore line: endPosDetails.line, // @ts-ignore column: endPosDetails.column } }; if (offset2 && peg$source && typeof peg$source.offset === "function") { res.start = peg$source.offset(res.start); res.end = peg$source.offset(res.end); } return res; } function peg$fail(expected2) { if (peg$currPos < peg$maxFailPos) { return; } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; peg$maxFailExpected = []; } peg$maxFailExpected.push(expected2); } function peg$buildSimpleError(message, location2) { return new peg$SyntaxError(message, null, null, location2); } function peg$buildStructuredError(expected2, found, location2) { return new peg$SyntaxError( // @ts-ignore peg$SyntaxError.buildMessage(expected2, found), // @ts-ignore expected2, // @ts-ignore found, // @ts-ignore location2 ); } function peg$parsestart() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = []; s2 = peg$parsews(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsews(); } s2 = peg$parseNegationExpression(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsews(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsews(); } s4 = peg$parseEOF(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f0(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parsews(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsews(); } s2 = peg$parseLogicalGroup(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsews(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsews(); } s4 = peg$parseEOF(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f1(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parsews(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsews(); } s2 = peg$parseTermExpression(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsews(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsews(); } s4 = peg$parseEOF(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f2(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parsews(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsews(); } s2 = peg$parseUnquotedTermType(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsews(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsews(); } s4 = peg$parseEOF(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f3(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parsews(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsews(); } s2 = peg$parseParensGroup(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsews(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsews(); } s4 = peg$parseEOF(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f4(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parsews(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsews(); } s2 = peg$parseEOF(); if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f5(); } else { peg$currPos = s0; s0 = peg$FAILED; } } } } } } return s0; } function peg$parseLogicalGroup() { var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$currPos; peg$silentFails++; s2 = peg$parseConjunctionOperator(); peg$silentFails--; if (s2 === peg$FAILED) { s1 = void 0; } else { peg$currPos = s1; s1 = peg$FAILED; } if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parseConjunction(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parseConjunction(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f6(s2); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseParensGroup() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = peg$parseParensStart(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsews(); while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsews(); } s3 = peg$parseParensGroup(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsews(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parsews(); } s5 = peg$parseParensEnd(); if (s5 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f7(s3); } 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$parseParensStart(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsews(); while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsews(); } s3 = peg$parseLogicalGroup(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsews(); while (s5 !== peg$FAILED) { s4.push(s5); s5 = peg$parsews(); } s5 = peg$parseParensEnd(); if (s5 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f8(s3); } 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$parseConjunction() { var s0, s1, s2; s0 = peg$currPos; s1 = []; s2 = peg$parseAndConjunctionStart(); if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseAndConjunctionStart(); } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f9(s1); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parseOrConjunction(); if (s2 !== peg$FAILED) { while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parseOrConjunction(); } } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$f10(s1); } s0 = s1; } return s0; } function peg$parseAndConjunctionStart() { var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parseTermGroup(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsews(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsews(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parseAndConjunction(); if (s3 !== peg$FAILED) { peg$savedPos = s0; s0 = peg$f11(s1, s3); } 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$parseAndConjunction() { var s0, s1, s2, s3, s4, s5; s0 = peg$currPos; s1 = []; s2 = peg$parsews(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsews(); } s2 = peg$currPos; peg$silentFails++; if (input.substr(peg$currPos, 3) === peg$c0) { s3 = peg$c0; peg$currPos += 3; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e0); } } peg$silentFails--; if (s3 !== peg$FAILED) { peg$currPos = s2; s2 = void 0; } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsews(); while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsews(); } s4 = peg$parseTermGroup(); if (s4 !== peg$FAILED) { s5 = peg$parseAndConjunction(); if (s5 === peg$FAILED) { s5 = null; } peg$savedPos = s0; s0 = peg$f12(s4, s5); } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } if (s0 === peg$FAILED) { s0 = peg$currPos; s1 = []; s2 = peg$parsews(); while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$parsews(); } s2 = peg$parseAndConjunctionOperator(); if (s2 !== peg$FAILED) { s3 = []; s4 = peg$parsews(); if (s4 !== peg$FAILED) { while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parsews(); } } else { s3 = peg$FAILED; } if (s3 !== peg$FAILED) { s4 = peg$parseTermGroup(); if (s4 !== peg$FAILED) { s5 = peg$parseAndConjunction(); if (s5 === peg$FAILED) { s5 = null; } peg$savedPos = s0; s0 = peg$f13(s4, s5); } 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$parseOrConjunction() { var s0, s1, s2, s3, s4, s5, s6; s0 = peg$currPos; s1 = peg$parseTermGroup(); if (s1 !== peg$FAILED) { s2 = []; s3 = peg$parsews(); if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); s3 = peg$parsews(); } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parseOrConjunctionOperator(); if (s3 !== peg$FAILED) { s4 = []; s5 = peg$parsews(); if (s5 !== peg$FAILED) {