From bc5b48501b3bf01bfa219b96a2c56e4bc7ffeca4 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Mon, 22 Apr 2024 23:37:50 -0700 Subject: [PATCH 1/7] Add cache param --- .../kbn-es-query/src/kuery/grammar/grammar.peggy.config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/kbn-es-query/src/kuery/grammar/grammar.peggy.config.json b/packages/kbn-es-query/src/kuery/grammar/grammar.peggy.config.json index 2428599612899..2f71406084337 100644 --- a/packages/kbn-es-query/src/kuery/grammar/grammar.peggy.config.json +++ b/packages/kbn-es-query/src/kuery/grammar/grammar.peggy.config.json @@ -1,3 +1,4 @@ { - "allowedStartRules": ["start", "Literal"] + "allowedStartRules": ["start", "Literal"], + "cache": true } From 3b9967949e7dddda7a9c59f18b15e920002bda86 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 23 Apr 2024 16:19:12 -0700 Subject: [PATCH 2/7] Fix tests --- test/api_integration/apis/saved_objects/find.ts | 10 +++------- .../discover/embeddable/_saved_search_embeddable.ts | 5 ++--- .../discover/embeddable/_saved_search_embeddable.ts | 5 ++--- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/test/api_integration/apis/saved_objects/find.ts b/test/api_integration/apis/saved_objects/find.ts index e5ae6c674ba8d..33aba5a5a171b 100644 --- a/test/api_integration/apis/saved_objects/find.ts +++ b/test/api_integration/apis/saved_objects/find.ts @@ -214,13 +214,9 @@ export default function ({ getService }: FtrProviderContext) { ) .expect(400) .then((resp) => { - expect(resp.body).to.eql({ - error: 'Bad Request', - message: - 'KQLSyntaxError: Expected AND, OR, end of input, whitespace but "<" found.\ndashboard.' + - 'attributes.title:foo query\n----------^' - ); + const errorText = await errorMessage.getVisibleText(); + expect(errorText).to.match(/Expected[\S\s]+but "n" found/); }); it('should not show the full screen button', async () => { diff --git a/x-pack/test_serverless/functional/test_suites/common/discover/embeddable/_saved_search_embeddable.ts b/x-pack/test_serverless/functional/test_suites/common/discover/embeddable/_saved_search_embeddable.ts index 14c4417da4c31..2cd16b00feb6a 100644 --- a/x-pack/test_serverless/functional/test_suites/common/discover/embeddable/_saved_search_embeddable.ts +++ b/x-pack/test_serverless/functional/test_suites/common/discover/embeddable/_saved_search_embeddable.ts @@ -133,9 +133,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await PageObjects.header.waitUntilLoadingHasFinished(); const embeddableError = await testSubjects.find('embeddableError'); const errorMessage = await embeddableError.findByTestSubject('errorMessageMarkdown'); - expect(await errorMessage.getVisibleText()).to.equal( - 'Expected AND, OR, end of input, whitespace but "n" found.\nthis < is not : a valid > query\n----------^' - ); + const errorText = await errorMessage.getVisibleText(); + expect(errorText).to.match(/Expected[\S\s]+but "n" found/); }); it('should not show the full screen button', async () => { From 7cbb0072de66dd36d0b188b3c06fd70c6a1b671a Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 24 Apr 2024 09:20:41 -0700 Subject: [PATCH 3/7] Remove unused mocks --- .../src/kuery/grammar/__mocks__/grammar.js | 2215 ----------------- .../src/kuery/grammar/__mocks__/index.ts | 9 - 2 files changed, 2224 deletions(-) delete mode 100644 packages/kbn-es-query/src/kuery/grammar/__mocks__/grammar.js delete mode 100644 packages/kbn-es-query/src/kuery/grammar/__mocks__/index.ts diff --git a/packages/kbn-es-query/src/kuery/grammar/__mocks__/grammar.js b/packages/kbn-es-query/src/kuery/grammar/__mocks__/grammar.js deleted file mode 100644 index de6d508872bb2..0000000000000 --- a/packages/kbn-es-query/src/kuery/grammar/__mocks__/grammar.js +++ /dev/null @@ -1,2215 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -// Generated by Peggy 1.2.0. -// -// https://peggyjs.org/ -/* eslint-disable prettier/prettier,no-var,strict,no-use-before-define,one-var,no-undef,no-unused-vars,new-cap */ - -"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 loc = this.location.source + ":" + s.line + ":" + s.column; - if (src) { - var e = this.location.end; - var filler = peg$padEnd("", s.line.toString().length); - var line = src[s.line - 1]; - var last = s.line === e.line ? e.column : line.length + 1; - str += "\n --> " + loc + "\n" - + filler + " |\n" - + s.line + " | " + line + "\n" - + filler + " | " + peg$padEnd("", s.column - 1) - + peg$padEnd("", last - s.column, "^"); - } else { - str += "\n at " + loc; - } - } - return str; -}; - -peg$SyntaxError.buildMessage = function(expected, found) { - var DESCRIBE_EXPECTATION_FNS = { - literal: function(expectation) { - return "\"" + literalEscape(expectation.text) + "\""; - }, - - 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 + "]"; - }, - - any: function() { - return "any character"; - }, - - end: function() { - 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 = expected.map(describeExpectation); - var i, j; - - 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 !== undefined ? options : {}; - - var peg$FAILED = {}; - var peg$source = options.grammarSource; - - var peg$startRuleFunctions = { start: peg$parsestart, Literal: peg$parseLiteral }; - var peg$startRuleFunction = peg$parsestart; - - var peg$c0 = "("; - var peg$c1 = ")"; - var peg$c2 = ":"; - var peg$c3 = "{"; - var peg$c4 = "}"; - var peg$c5 = "or"; - var peg$c6 = "and"; - var peg$c7 = "not"; - var peg$c8 = "\""; - var peg$c9 = "\\"; - var peg$c10 = "*"; - var peg$c11 = "\\t"; - var peg$c12 = "\\r"; - var peg$c13 = "\\n"; - var peg$c14 = "u"; - var peg$c15 = "<="; - var peg$c16 = ">="; - var peg$c17 = "<"; - var peg$c18 = ">"; - var peg$c19 = "@kuery-cursor@"; - - var peg$r0 = /^[\\"]/; - var peg$r1 = /^[^"]/; - var peg$r2 = /^[\\():<>"*{}]/; - var peg$r3 = /^[0-9a-f]/i; - var peg$r4 = /^[ \t\r\n\xA0]/; - - var peg$e0 = peg$literalExpectation("(", 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$otherExpectation("fieldName"); - var peg$e6 = peg$otherExpectation("value"); - var peg$e7 = peg$otherExpectation("OR"); - var peg$e8 = peg$literalExpectation("or", true); - var peg$e9 = peg$otherExpectation("AND"); - var peg$e10 = peg$literalExpectation("and", true); - var peg$e11 = peg$otherExpectation("NOT"); - var peg$e12 = peg$literalExpectation("not", true); - var peg$e13 = peg$otherExpectation("literal"); - var peg$e14 = peg$literalExpectation("\"", false); - var peg$e15 = peg$literalExpectation("\\", false); - var peg$e16 = peg$classExpectation(["\\", "\""], false, false); - var peg$e17 = peg$classExpectation(["\""], true, false); - var peg$e18 = peg$anyExpectation(); - var peg$e19 = peg$literalExpectation("*", false); - var peg$e20 = peg$literalExpectation("\\t", false); - var peg$e21 = peg$literalExpectation("\\r", false); - var peg$e22 = peg$literalExpectation("\\n", false); - var peg$e23 = peg$classExpectation(["\\", "(", ")", ":", "<", ">", "\"", "*", "{", "}"], false, false); - var peg$e24 = peg$literalExpectation("u", false); - var peg$e25 = peg$classExpectation([["0", "9"], ["a", "f"]], false, true); - var peg$e26 = peg$literalExpectation("<=", false); - var peg$e27 = peg$literalExpectation(">=", false); - var peg$e28 = peg$literalExpectation("<", false); - var peg$e29 = peg$literalExpectation(">", false); - var peg$e30 = peg$otherExpectation("whitespace"); - var peg$e31 = peg$classExpectation([" ", "\t", "\r", "\n", "\xA0"], false, false); - var peg$e32 = peg$literalExpectation("@kuery-cursor@", false); - - var peg$f0 = function(query, trailing) { - if (trailing.type === 'cursor') { - return { - ...trailing, - suggestionTypes: ['conjunction'] - }; - } - if (query !== null) return query; - return nodeTypes.function.buildNode('is', '*', '*'); - }; - var peg$f1 = function(head, query) { return query; }; - var peg$f2 = function(head, tail) { - const nodes = [head, ...tail]; - const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); - if (cursor) return cursor; - return buildFunctionNode('or', nodes); - }; - var peg$f3 = function(head, tail) { - const nodes = [head, ...tail]; - const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); - if (cursor) return cursor; - return buildFunctionNode('and', nodes); - }; - var peg$f4 = function(query) { - if (query.type === 'cursor') return query; - return buildFunctionNode('not', [query]); - }; - var peg$f5 = function(query, trailing) { - if (trailing.type === 'cursor') { - return { - ...trailing, - suggestionTypes: ['conjunction'] - }; - } - return query; - }; - var peg$f6 = function(field, query, trailing) { - if (query.type === 'cursor') { - return { - ...query, - nestedPath: query.nestedPath ? `${field.value}.${query.nestedPath}` : field.value, - } - }; - - if (trailing.type === 'cursor') { - return { - ...trailing, - suggestionTypes: ['conjunction'] - }; - } - return buildFunctionNode('nested', [field, query]); - }; - var peg$f7 = function(field, operator, value) { - if (value.type === 'cursor') { - return { - ...value, - suggestionTypes: ['conjunction'] - }; - } - return buildFunctionNode('range', [field, operator, value]); - }; - var peg$f8 = function(field, partial) { - if (partial.type === 'cursor') { - return { - ...partial, - fieldName: field.value, - suggestionTypes: ['value', 'conjunction'] - }; - } - return partial(field); - }; - var peg$f9 = function(partial) { - if (partial.type === 'cursor') { - const fieldName = `${partial.prefix}${partial.suffix}`.trim(); - return { - ...partial, - fieldName, - suggestionTypes: ['field', 'operator', 'conjunction'] - }; - } - const field = buildLiteralNode(null); - return partial(field); - }; - var peg$f10 = function(partial, trailing) { - if (trailing.type === 'cursor') { - return { - ...trailing, - suggestionTypes: ['conjunction'] - }; - } - return partial; - }; - var peg$f11 = function(head, partial) { return partial; }; - var peg$f12 = function(head, tail) { - const nodes = [head, ...tail]; - const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); - if (cursor) { - return { - ...cursor, - suggestionTypes: ['value'] - }; - } - return (field) => buildFunctionNode('or', nodes.map(partial => partial(field))); - }; - var peg$f13 = function(head, tail) { - const nodes = [head, ...tail]; - const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); - if (cursor) { - return { - ...cursor, - suggestionTypes: ['value'] - }; - } - return (field) => buildFunctionNode('and', nodes.map(partial => partial(field))); - }; - var peg$f14 = function(partial) { - if (partial.type === 'cursor') { - return { - ...list, - suggestionTypes: ['value'] - }; - } - return (field) => buildFunctionNode('not', [partial(field)]); - }; - var peg$f15 = function(value) { - if (value.type === 'cursor') return value; - return (field) => buildFunctionNode('is', [field, value]); - }; - var peg$f16 = function(value) { - if (value.type === 'cursor') return value; - - if (!allowLeadingWildcards && nodeTypes.wildcard.isNode(value) && nodeTypes.wildcard.hasLeadingWildcard(value)) { - error('Leading wildcards are disabled. See query:allowLeadingWildcards in Advanced Settings.'); - } - - return (field) => buildFunctionNode('is', [field, value]); - }; - var peg$f17 = function() { return parseCursor; }; - var peg$f18 = function(prefix, cursor, suffix) { - const { start, end } = location(); - return { - type: 'cursor', - start: start.offset, - end: end.offset - cursor.length, - prefix: prefix.join(''), - suffix: suffix.join(''), - text: text().replace(cursor, '') - }; - }; - var peg$f19 = function(chars) { - return buildLiteralNode(chars.join(''), true); - }; - var peg$f20 = function(char) { return char; }; - var peg$f21 = function(chars) { - const sequence = chars.join('').trim(); - if (sequence === 'null') return buildLiteralNode(null); - if (sequence === 'true') return buildLiteralNode(true); - if (sequence === 'false') return buildLiteralNode(false); - if (chars.includes(KQL_WILDCARD_SYMBOL)) return buildWildcardNode(sequence); - return buildLiteralNode(sequence); - }; - var peg$f22 = function() { return KQL_WILDCARD_SYMBOL; }; - var peg$f23 = function() { return '\t'; }; - var peg$f24 = function() { return '\r'; }; - var peg$f25 = function() { return '\n'; }; - var peg$f26 = function(keyword) { return keyword; }; - var peg$f27 = function(sequence) { return sequence; }; - var peg$f28 = function(digits) { - return String.fromCharCode(parseInt(digits, 16)); - }; - var peg$f29 = function() { return 'lte'; }; - var peg$f30 = function() { return 'gte'; }; - var peg$f31 = function() { return 'lt'; }; - var peg$f32 = function() { return 'gt'; }; - var peg$f33 = function() { return cursorSymbol; }; - - 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 { - source: peg$source, - start: peg$savedPos, - end: peg$currPos - }; - } - - function location() { - return peg$computeLocation(peg$savedPos, peg$currPos); - } - - function expected(description, location) { - location = location !== undefined - ? 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 !== undefined - ? 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]; - var 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); - var endPosDetails = peg$computePosDetails(endPos); - - return { - source: peg$source, - 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, s1, s2, s3; - - s0 = peg$currPos; - s1 = []; - s2 = peg$parseSpace(); - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parseSpace(); - } - s2 = peg$parseOrQuery(); - if (s2 === peg$FAILED) { - s2 = null; - } - s3 = peg$parseOptionalSpace(); - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f0(s2, s3); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - return s0; - } - - function peg$parseOrQuery() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - s1 = peg$parseAndQuery(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parseOr(); - if (s4 !== peg$FAILED) { - s5 = peg$parseAndQuery(); - if (s5 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f1(s1, s5); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parseOr(); - if (s4 !== peg$FAILED) { - s5 = peg$parseAndQuery(); - if (s5 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f1(s1, s5); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f2(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parseAndQuery(); - } - - return s0; - } - - function peg$parseAndQuery() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - s1 = peg$parseNotQuery(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parseAnd(); - if (s4 !== peg$FAILED) { - s5 = peg$parseNotQuery(); - if (s5 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f1(s1, s5); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parseAnd(); - if (s4 !== peg$FAILED) { - s5 = peg$parseNotQuery(); - if (s5 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f1(s1, s5); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f3(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parseNotQuery(); - } - - return s0; - } - - function peg$parseNotQuery() { - var s0, s1, s2; - - s0 = peg$currPos; - s1 = peg$parseNot(); - if (s1 !== peg$FAILED) { - s2 = peg$parseSubQuery(); - if (s2 !== 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$parseSubQuery(); - } - - return s0; - } - - function peg$parseSubQuery() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 40) { - s1 = peg$c0; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } - } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseSpace(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseSpace(); - } - s3 = peg$parseOrQuery(); - if (s3 !== peg$FAILED) { - s4 = peg$parseOptionalSpace(); - if (s4 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 41) { - s5 = peg$c1; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f5(s3, s4); - } 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$parseNestedQuery(); - } - - return s0; - } - - function peg$parseNestedQuery() { - var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; - - s0 = peg$currPos; - s1 = peg$parseField(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseSpace(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseSpace(); - } - if (input.charCodeAt(peg$currPos) === 58) { - s3 = peg$c2; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parseSpace(); - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parseSpace(); - } - if (input.charCodeAt(peg$currPos) === 123) { - s5 = peg$c3; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e3); } - } - if (s5 !== peg$FAILED) { - s6 = []; - s7 = peg$parseSpace(); - while (s7 !== peg$FAILED) { - s6.push(s7); - s7 = peg$parseSpace(); - } - s7 = peg$parseOrQuery(); - if (s7 !== peg$FAILED) { - s8 = peg$parseOptionalSpace(); - if (s8 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 125) { - s9 = peg$c4; - peg$currPos++; - } else { - s9 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e4); } - } - if (s9 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f6(s1, s7, s8); - } 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$parseExpression(); - } - - return s0; - } - - function peg$parseExpression() { - var s0; - - s0 = peg$parseFieldRangeExpression(); - if (s0 === peg$FAILED) { - s0 = peg$parseFieldValueExpression(); - if (s0 === peg$FAILED) { - s0 = peg$parseValueExpression(); - } - } - - return s0; - } - - function peg$parseField() { - var s0, s1; - - peg$silentFails++; - s0 = peg$parseLiteral(); - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e5); } - } - - return s0; - } - - function peg$parseFieldRangeExpression() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - s1 = peg$parseField(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseSpace(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseSpace(); - } - s3 = peg$parseRangeOperator(); - if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parseSpace(); - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parseSpace(); - } - s5 = peg$parseLiteral(); - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f7(s1, s3, 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$parseFieldValueExpression() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - s1 = peg$parseField(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseSpace(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseSpace(); - } - if (input.charCodeAt(peg$currPos) === 58) { - s3 = peg$c2; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e2); } - } - if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parseSpace(); - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parseSpace(); - } - s5 = peg$parseListOfValues(); - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f8(s1, 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$parseValueExpression() { - var s0, s1; - - s0 = peg$currPos; - s1 = peg$parseValue(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f9(s1); - } - s0 = s1; - - return s0; - } - - function peg$parseListOfValues() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 40) { - s1 = peg$c0; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e0); } - } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseSpace(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseSpace(); - } - s3 = peg$parseOrListOfValues(); - if (s3 !== peg$FAILED) { - s4 = peg$parseOptionalSpace(); - if (s4 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 41) { - s5 = peg$c1; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e1); } - } - if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f10(s3, s4); - } 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$parseValue(); - } - - return s0; - } - - function peg$parseOrListOfValues() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - s1 = peg$parseAndListOfValues(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parseOr(); - if (s4 !== peg$FAILED) { - s5 = peg$parseAndListOfValues(); - if (s5 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parseOr(); - if (s4 !== peg$FAILED) { - s5 = peg$parseAndListOfValues(); - if (s5 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f12(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parseAndListOfValues(); - } - - return s0; - } - - function peg$parseAndListOfValues() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - s1 = peg$parseNotListOfValues(); - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$currPos; - s4 = peg$parseAnd(); - if (s4 !== peg$FAILED) { - s5 = peg$parseNotListOfValues(); - if (s5 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$currPos; - s4 = peg$parseAnd(); - if (s4 !== peg$FAILED) { - s5 = peg$parseNotListOfValues(); - if (s5 !== peg$FAILED) { - peg$savedPos = s3; - s3 = peg$f11(s1, s5); - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f13(s1, s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parseNotListOfValues(); - } - - return s0; - } - - function peg$parseNotListOfValues() { - var s0, s1, s2; - - s0 = peg$currPos; - s1 = peg$parseNot(); - if (s1 !== peg$FAILED) { - s2 = peg$parseListOfValues(); - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f14(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$parseListOfValues(); - } - - return s0; - } - - function peg$parseValue() { - var s0, s1; - - peg$silentFails++; - s0 = peg$currPos; - s1 = peg$parseQuotedString(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f15(s1); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$parseUnquotedLiteral(); - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f16(s1); - } - s0 = s1; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e6); } - } - - return s0; - } - - function peg$parseOr() { - var s0, s1, s2, s3, s4; - - peg$silentFails++; - s0 = peg$currPos; - s1 = []; - s2 = peg$parseSpace(); - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parseSpace(); - } - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 2).toLowerCase() === peg$c5) { - s2 = input.substr(peg$currPos, 2); - peg$currPos += 2; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } - } - if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$parseSpace(); - if (s4 !== peg$FAILED) { - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parseSpace(); - } - } else { - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - s1 = [s1, s2, s3]; - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e7); } - } - - return s0; - } - - function peg$parseAnd() { - var s0, s1, s2, s3, s4; - - peg$silentFails++; - s0 = peg$currPos; - s1 = []; - s2 = peg$parseSpace(); - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parseSpace(); - } - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 3).toLowerCase() === peg$c6) { - s2 = input.substr(peg$currPos, 3); - peg$currPos += 3; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e10); } - } - if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$parseSpace(); - if (s4 !== peg$FAILED) { - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parseSpace(); - } - } else { - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - s1 = [s1, s2, s3]; - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e9); } - } - - return s0; - } - - function peg$parseNot() { - var s0, s1, s2, s3; - - peg$silentFails++; - s0 = peg$currPos; - if (input.substr(peg$currPos, 3).toLowerCase() === peg$c7) { - s1 = input.substr(peg$currPos, 3); - peg$currPos += 3; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseSpace(); - if (s3 !== peg$FAILED) { - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseSpace(); - } - } else { - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s1 = [s1, s2]; - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e11); } - } - - return s0; - } - - function peg$parseLiteral() { - var s0, s1; - - peg$silentFails++; - s0 = peg$parseQuotedString(); - if (s0 === peg$FAILED) { - s0 = peg$parseUnquotedLiteral(); - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e13); } - } - - return s0; - } - - function peg$parseQuotedString() { - var s0, s1, s2, s3, s4, s5, s6; - - s0 = peg$currPos; - peg$savedPos = peg$currPos; - s1 = peg$f17(); - if (s1) { - s1 = undefined; - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 34) { - s2 = peg$c8; - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } - } - if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$parseQuotedCharacter(); - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parseQuotedCharacter(); - } - s4 = peg$parseCursor(); - if (s4 !== peg$FAILED) { - s5 = []; - s6 = peg$parseQuotedCharacter(); - while (s6 !== peg$FAILED) { - s5.push(s6); - s6 = peg$parseQuotedCharacter(); - } - if (input.charCodeAt(peg$currPos) === 34) { - s6 = peg$c8; - peg$currPos++; - } else { - s6 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } - } - if (s6 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f18(s3, s4, s5); - } 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; - if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c8; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } - } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseQuotedCharacter(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseQuotedCharacter(); - } - if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c8; - peg$currPos++; - } else { - s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e14); } - } - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f19(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } - - return s0; - } - - function peg$parseQuotedCharacter() { - var s0, s1, s2; - - s0 = peg$parseEscapedWhitespace(); - if (s0 === peg$FAILED) { - s0 = peg$parseEscapedUnicodeSequence(); - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c9; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } - } - if (s1 !== peg$FAILED) { - if (peg$r0.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e16); } - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f20(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$currPos; - peg$silentFails++; - s2 = peg$parseCursor(); - peg$silentFails--; - if (s2 === peg$FAILED) { - s1 = undefined; - } else { - peg$currPos = s1; - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - if (peg$r1.test(input.charAt(peg$currPos))) { - s2 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e17); } - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f20(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } - } - } - - return s0; - } - - function peg$parseUnquotedLiteral() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - peg$savedPos = peg$currPos; - s1 = peg$f17(); - if (s1) { - s1 = undefined; - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseUnquotedCharacter(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseUnquotedCharacter(); - } - s3 = peg$parseCursor(); - if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parseUnquotedCharacter(); - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parseUnquotedCharacter(); - } - peg$savedPos = s0; - s0 = peg$f18(s2, s3, s4); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = []; - s2 = peg$parseUnquotedCharacter(); - if (s2 !== peg$FAILED) { - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parseUnquotedCharacter(); - } - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f21(s1); - } - s0 = s1; - } - - return s0; - } - - function peg$parseUnquotedCharacter() { - var s0, s1, s2, s3, s4; - - s0 = peg$parseEscapedWhitespace(); - if (s0 === peg$FAILED) { - s0 = peg$parseEscapedSpecialCharacter(); - if (s0 === peg$FAILED) { - s0 = peg$parseEscapedUnicodeSequence(); - if (s0 === peg$FAILED) { - s0 = peg$parseEscapedKeyword(); - if (s0 === peg$FAILED) { - s0 = peg$parseWildcard(); - if (s0 === peg$FAILED) { - s0 = peg$currPos; - s1 = peg$currPos; - peg$silentFails++; - s2 = peg$parseSpecialCharacter(); - peg$silentFails--; - if (s2 === peg$FAILED) { - s1 = undefined; - } else { - peg$currPos = s1; - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - peg$silentFails++; - s3 = peg$parseKeyword(); - peg$silentFails--; - if (s3 === peg$FAILED) { - s2 = undefined; - } else { - peg$currPos = s2; - s2 = peg$FAILED; - } - if (s2 !== peg$FAILED) { - s3 = peg$currPos; - peg$silentFails++; - s4 = peg$parseCursor(); - peg$silentFails--; - if (s4 === peg$FAILED) { - s3 = undefined; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - if (input.length > peg$currPos) { - s4 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e18); } - } - if (s4 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f20(s4); - } 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$parseWildcard() { - var s0, s1; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 42) { - s1 = peg$c10; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e19); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f22(); - } - s0 = s1; - - return s0; - } - - function peg$parseOptionalSpace() { - var s0, s1, s2, s3, s4, s5; - - s0 = peg$currPos; - peg$savedPos = peg$currPos; - s1 = peg$f17(); - if (s1) { - s1 = undefined; - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseSpace(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseSpace(); - } - s3 = peg$parseCursor(); - if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parseSpace(); - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parseSpace(); - } - peg$savedPos = s0; - s0 = peg$f18(s2, s3, s4); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - if (s0 === peg$FAILED) { - s0 = []; - s1 = peg$parseSpace(); - while (s1 !== peg$FAILED) { - s0.push(s1); - s1 = peg$parseSpace(); - } - } - - return s0; - } - - function peg$parseEscapedWhitespace() { - var s0, s1; - - s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c11) { - s1 = peg$c11; - peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e20); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f23(); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c12) { - s1 = peg$c12; - peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e21); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f24(); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c13) { - s1 = peg$c13; - peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e22); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f25(); - } - s0 = s1; - } - } - - return s0; - } - - function peg$parseEscapedSpecialCharacter() { - var s0, s1, s2; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c9; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parseSpecialCharacter(); - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f20(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - return s0; - } - - function peg$parseEscapedKeyword() { - var s0, s1, s2; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c9; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } - } - if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 2).toLowerCase() === peg$c5) { - s2 = input.substr(peg$currPos, 2); - peg$currPos += 2; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e8); } - } - if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 3).toLowerCase() === peg$c6) { - s2 = input.substr(peg$currPos, 3); - peg$currPos += 3; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e10); } - } - if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 3).toLowerCase() === peg$c7) { - s2 = input.substr(peg$currPos, 3); - peg$currPos += 3; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e12); } - } - } - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f26(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - return s0; - } - - function peg$parseKeyword() { - var s0; - - s0 = peg$parseOr(); - if (s0 === peg$FAILED) { - s0 = peg$parseAnd(); - if (s0 === peg$FAILED) { - s0 = peg$parseNot(); - } - } - - return s0; - } - - function peg$parseSpecialCharacter() { - var s0; - - if (peg$r2.test(input.charAt(peg$currPos))) { - s0 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e23); } - } - - return s0; - } - - function peg$parseEscapedUnicodeSequence() { - var s0, s1, s2; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c9; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e15); } - } - if (s1 !== peg$FAILED) { - s2 = peg$parseUnicodeSequence(); - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f27(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - return s0; - } - - function peg$parseUnicodeSequence() { - var s0, s1, s2, s3, s4, s5, s6, s7; - - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 117) { - s1 = peg$c14; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e24); } - } - if (s1 !== peg$FAILED) { - s2 = peg$currPos; - s3 = peg$currPos; - s4 = peg$parseHexDigit(); - if (s4 !== peg$FAILED) { - s5 = peg$parseHexDigit(); - if (s5 !== peg$FAILED) { - s6 = peg$parseHexDigit(); - if (s6 !== peg$FAILED) { - s7 = peg$parseHexDigit(); - if (s7 !== peg$FAILED) { - s4 = [s4, s5, s6, s7]; - s3 = s4; - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - } else { - peg$currPos = s3; - s3 = peg$FAILED; - } - if (s3 !== peg$FAILED) { - s2 = input.substring(s2, peg$currPos); - } else { - s2 = s3; - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f28(s2); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - return s0; - } - - function peg$parseHexDigit() { - var s0; - - if (peg$r3.test(input.charAt(peg$currPos))) { - s0 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e25); } - } - - return s0; - } - - function peg$parseRangeOperator() { - var s0, s1; - - s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c15) { - s1 = peg$c15; - peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e26); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f29(); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c16) { - s1 = peg$c16; - peg$currPos += 2; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e27); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f30(); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c17; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e28); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f31(); - } - s0 = s1; - if (s0 === peg$FAILED) { - s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c18; - peg$currPos++; - } else { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e29); } - } - if (s1 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$f32(); - } - s0 = s1; - } - } - } - - return s0; - } - - function peg$parseSpace() { - var s0, s1; - - peg$silentFails++; - if (peg$r4.test(input.charAt(peg$currPos))) { - s0 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e31); } - } - peg$silentFails--; - if (s0 === peg$FAILED) { - s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e30); } - } - - return s0; - } - - function peg$parseCursor() { - var s0, s1, s2; - - s0 = peg$currPos; - peg$savedPos = peg$currPos; - s1 = peg$f17(); - if (s1) { - s1 = undefined; - } else { - s1 = peg$FAILED; - } - if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 14) === peg$c19) { - s2 = peg$c19; - peg$currPos += 14; - } else { - s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$e32); } - } - if (s2 !== peg$FAILED) { - peg$savedPos = s0; - s0 = peg$f33(); - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } - - return s0; - } - - - const { parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes } } = options; - const buildFunctionNode = nodeTypes.function.buildNodeWithArgumentNodes; - const buildLiteralNode = nodeTypes.literal.buildNode; - const buildWildcardNode = nodeTypes.wildcard.buildNode; - const { KQL_WILDCARD_SYMBOL } = nodeTypes.wildcard; - - - peg$result = peg$startRuleFunction(); - - if (peg$result !== peg$FAILED && peg$currPos === input.length) { - return peg$result; - } else { - if (peg$result !== peg$FAILED && peg$currPos < input.length) { - peg$fail(peg$endExpectation()); - } - - throw peg$buildStructuredError( - peg$maxFailExpected, - peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, - peg$maxFailPos < input.length - ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1) - : peg$computeLocation(peg$maxFailPos, peg$maxFailPos) - ); - } -} - -module.exports = { - SyntaxError: peg$SyntaxError, - parse: peg$parse -}; diff --git a/packages/kbn-es-query/src/kuery/grammar/__mocks__/index.ts b/packages/kbn-es-query/src/kuery/grammar/__mocks__/index.ts deleted file mode 100644 index c8466fead14a1..0000000000000 --- a/packages/kbn-es-query/src/kuery/grammar/__mocks__/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -export { parse } from './grammar'; From bd41fb594e9c57c6df1a7fa8b2fcff8137c590e2 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 24 Apr 2024 12:27:33 -0700 Subject: [PATCH 4/7] Add performance test --- .../kbn-es-query/src/kuery/ast/ast.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/kbn-es-query/src/kuery/ast/ast.test.ts b/packages/kbn-es-query/src/kuery/ast/ast.test.ts index aae4bc9de42bd..836f3fb8c3460 100644 --- a/packages/kbn-es-query/src/kuery/ast/ast.test.ts +++ b/packages/kbn-es-query/src/kuery/ast/ast.test.ts @@ -16,6 +16,7 @@ import { nodeTypes } from '../node_types'; import { DataViewBase } from '../../..'; import { KueryNode } from '../types'; import { fields } from '../../filters/stubs'; +import { performance } from 'perf_hooks'; jest.mock('../grammar'); @@ -276,6 +277,33 @@ describe('kuery AST API', () => { const actual = fromKueryExpression('nestedField:{ nestedChild:{ doublyNestedChild:foo } }'); expect(actual).toEqual(expected); }); + + describe('performance', () => { + const NUM_RUNS = 100; + it('with simple expression', () => { + const start = performance.now(); + for (let i = 0; i < NUM_RUNS; i++) { + fromKueryExpression( + 'not fleet-agent-actions.attributes.sent_at: * and fleet-agent-actions.attributes.agent_id:1234567' + ); + } + const elapsed = performance.now() - start; + const opsPerSec = NUM_RUNS / (elapsed / 1000); + expect(opsPerSec).toBeGreaterThan(10000); + }); + + it('with complex expression', () => { + const start = performance.now(); + for (let i = 0; i < NUM_RUNS; i++) { + fromKueryExpression( + `((alert.attributes.alertTypeId:.index-threshold and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:siem.signals and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:siem.notifications and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:metrics.alert.threshold and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:metrics.alert.inventory.threshold and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:logs.alert.document.count and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:monitoring_alert_cluster_health and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:monitoring_alert_license_expiration and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:monitoring_alert_cpu_usage and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:monitoring_alert_nodes_changed and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:monitoring_alert_logstash_version_mismatch and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:monitoring_alert_kibana_version_mismatch and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:monitoring_alert_elasticsearch_version_mismatch and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:apm.transaction_duration and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:apm.transaction_duration_anomaly and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:apm.error_rate and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:xpack.uptime.alerts.monitorStatus and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:xpack.uptime.alerts.tls and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)) or (alert.attributes.alertTypeId:xpack.uptime.alerts.durationAnomaly and alert.attributes.consumer:(alerts or builtInAlerts or siem or infrastructure or logs or monitoring or apm or uptime)))` + ); + } + const elapsed = performance.now() - start; + const opsPerSec = NUM_RUNS / (elapsed / 1000); + expect(opsPerSec).toBeGreaterThan(1000); + }); + }); }); describe('fromLiteralExpression', () => { From d4be56bf15341c5f80cd5902a3674735f266647a Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 24 Apr 2024 14:16:43 -0700 Subject: [PATCH 5/7] Remove mock & adjust tests --- packages/kbn-es-query/src/kuery/ast/ast.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/kbn-es-query/src/kuery/ast/ast.test.ts b/packages/kbn-es-query/src/kuery/ast/ast.test.ts index 836f3fb8c3460..cc9692a6ad4c4 100644 --- a/packages/kbn-es-query/src/kuery/ast/ast.test.ts +++ b/packages/kbn-es-query/src/kuery/ast/ast.test.ts @@ -18,8 +18,6 @@ import { KueryNode } from '../types'; import { fields } from '../../filters/stubs'; import { performance } from 'perf_hooks'; -jest.mock('../grammar'); - describe('kuery AST API', () => { let indexPattern: DataViewBase; @@ -289,7 +287,7 @@ describe('kuery AST API', () => { } const elapsed = performance.now() - start; const opsPerSec = NUM_RUNS / (elapsed / 1000); - expect(opsPerSec).toBeGreaterThan(10000); + expect(opsPerSec).toBeGreaterThan(1000); }); it('with complex expression', () => { @@ -301,7 +299,7 @@ describe('kuery AST API', () => { } const elapsed = performance.now() - start; const opsPerSec = NUM_RUNS / (elapsed / 1000); - expect(opsPerSec).toBeGreaterThan(1000); + expect(opsPerSec).toBeGreaterThan(100); }); }); }); From 159fb92e7966a0e5456101cde4aebdcb62412fa7 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 24 Apr 2024 14:25:00 -0700 Subject: [PATCH 6/7] Add nested query test --- packages/kbn-es-query/src/kuery/ast/ast.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/kbn-es-query/src/kuery/ast/ast.test.ts b/packages/kbn-es-query/src/kuery/ast/ast.test.ts index cc9692a6ad4c4..f9916ecb2edaa 100644 --- a/packages/kbn-es-query/src/kuery/ast/ast.test.ts +++ b/packages/kbn-es-query/src/kuery/ast/ast.test.ts @@ -301,6 +301,16 @@ describe('kuery AST API', () => { const opsPerSec = NUM_RUNS / (elapsed / 1000); expect(opsPerSec).toBeGreaterThan(100); }); + + it('with many subqueries', () => { + const start = performance.now(); + for (let i = 0; i < NUM_RUNS; i++) { + fromKueryExpression(`((((((((((foo))))))))))`); + } + const elapsed = performance.now() - start; + const opsPerSec = NUM_RUNS / (elapsed / 1000); + expect(opsPerSec).toBeGreaterThan(1000); + }); }); }); From 0c36c57e7134ea15c1ad35f73f747b053ba7a582 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 25 Apr 2024 10:50:49 -0700 Subject: [PATCH 7/7] Remove grammar mocks from tests --- .../src/es_query/build_es_query.test.ts | 2 -- .../src/kuery/functions/and.test.ts | 2 -- .../src/kuery/functions/exists.test.ts | 2 -- .../src/kuery/functions/is.test.ts | 2 -- .../src/kuery/functions/nested.test.ts | 2 -- .../src/kuery/functions/not.test.ts | 2 -- .../src/kuery/functions/or.test.ts | 1 - .../src/kuery/functions/range.test.ts | 2 -- .../kuery/functions/utils/get_fields.test.ts | 2 -- .../utils/get_full_field_name_node.test.ts | 2 -- .../src/kuery/kuery_syntax_error.test.ts | 18 ++++++++++-------- .../src/kuery/node_types/function.test.ts | 2 -- .../src/kuery/node_types/literal.test.ts | 2 -- .../src/kuery/node_types/node_builder.test.ts | 2 -- .../src/kuery/node_types/wildcard.test.ts | 2 -- 15 files changed, 10 insertions(+), 35 deletions(-) diff --git a/packages/kbn-es-query/src/es_query/build_es_query.test.ts b/packages/kbn-es-query/src/es_query/build_es_query.test.ts index a75c8d3d3a03f..b19ac9ce132d9 100644 --- a/packages/kbn-es-query/src/es_query/build_es_query.test.ts +++ b/packages/kbn-es-query/src/es_query/build_es_query.test.ts @@ -14,8 +14,6 @@ import { MatchAllFilter, Query } from '../filters'; import { fields } from '../filters/stubs'; import { DataViewBase } from './types'; -jest.mock('../kuery/grammar'); - describe('build query', () => { const indexPattern: DataViewBase = { fields, diff --git a/packages/kbn-es-query/src/kuery/functions/and.test.ts b/packages/kbn-es-query/src/kuery/functions/and.test.ts index 3b9dcbff51fea..87d16c9115bef 100644 --- a/packages/kbn-es-query/src/kuery/functions/and.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/and.test.ts @@ -13,8 +13,6 @@ import * as and from './and'; import { DataViewBase } from '../../es_query'; import { KqlAndFunctionNode } from './and'; -jest.mock('../grammar'); - const childNode1 = nodeTypes.function.buildNode('is', 'machine.os', 'osx'); const childNode2 = nodeTypes.function.buildNode('is', 'extension', 'jpg'); diff --git a/packages/kbn-es-query/src/kuery/functions/exists.test.ts b/packages/kbn-es-query/src/kuery/functions/exists.test.ts index 69340ab96c752..44f82afdd68fe 100644 --- a/packages/kbn-es-query/src/kuery/functions/exists.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/exists.test.ts @@ -13,8 +13,6 @@ import { KQL_NODE_TYPE_LITERAL } from '../node_types/literal'; import * as exists from './exists'; import type { KqlExistsFunctionNode } from './exists'; -jest.mock('../grammar'); - describe('kuery functions', () => { describe('exists', () => { let indexPattern: DataViewBase; diff --git a/packages/kbn-es-query/src/kuery/functions/is.test.ts b/packages/kbn-es-query/src/kuery/functions/is.test.ts index 5b52eff548ed3..1b94562c6e99f 100644 --- a/packages/kbn-es-query/src/kuery/functions/is.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/is.test.ts @@ -16,8 +16,6 @@ import { KQL_NODE_TYPE_WILDCARD } from '../node_types/wildcard'; import { KQL_NODE_TYPE_LITERAL } from '../node_types/literal'; import { KqlIsFunctionNode } from './is'; -jest.mock('../grammar'); - describe('kuery functions', () => { describe('is', () => { let indexPattern: DataViewBase; diff --git a/packages/kbn-es-query/src/kuery/functions/nested.test.ts b/packages/kbn-es-query/src/kuery/functions/nested.test.ts index 5078f3899cd8e..4eedbacce1ff9 100644 --- a/packages/kbn-es-query/src/kuery/functions/nested.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/nested.test.ts @@ -13,8 +13,6 @@ import * as ast from '../ast'; import * as nested from './nested'; import type { KqlNestedFunctionNode } from './nested'; -jest.mock('../grammar'); - const childNode = nodeTypes.function.buildNode('is', 'child', 'foo'); describe('kuery functions', () => { diff --git a/packages/kbn-es-query/src/kuery/functions/not.test.ts b/packages/kbn-es-query/src/kuery/functions/not.test.ts index 84163620e72ce..7ab596101892b 100644 --- a/packages/kbn-es-query/src/kuery/functions/not.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/not.test.ts @@ -14,8 +14,6 @@ import * as ast from '../ast'; import * as not from './not'; import { KqlNotFunctionNode } from './not'; -jest.mock('../grammar'); - const childNode = nodeTypes.function.buildNode('is', 'extension', 'jpg'); describe('kuery functions', () => { diff --git a/packages/kbn-es-query/src/kuery/functions/or.test.ts b/packages/kbn-es-query/src/kuery/functions/or.test.ts index 26eeb25f7b605..fb0ff337df1ef 100644 --- a/packages/kbn-es-query/src/kuery/functions/or.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/or.test.ts @@ -14,7 +14,6 @@ import * as ast from '../ast'; import * as or from './or'; import { KqlOrFunctionNode } from './or'; -jest.mock('../grammar'); const childNode1 = nodeTypes.function.buildNode('is', 'machine.os', 'osx'); const childNode2 = nodeTypes.function.buildNode('is', 'extension', 'jpg'); diff --git a/packages/kbn-es-query/src/kuery/functions/range.test.ts b/packages/kbn-es-query/src/kuery/functions/range.test.ts index 3d4d80b6e602f..229b781af476d 100644 --- a/packages/kbn-es-query/src/kuery/functions/range.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/range.test.ts @@ -15,8 +15,6 @@ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { KQL_NODE_TYPE_LITERAL } from '../node_types/literal'; import { KqlRangeFunctionNode } from './range'; -jest.mock('../grammar'); - describe('kuery functions', () => { describe('range', () => { let indexPattern: DataViewBase; diff --git a/packages/kbn-es-query/src/kuery/functions/utils/get_fields.test.ts b/packages/kbn-es-query/src/kuery/functions/utils/get_fields.test.ts index e0e69c222604e..12955706bdf51 100644 --- a/packages/kbn-es-query/src/kuery/functions/utils/get_fields.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/utils/get_fields.test.ts @@ -12,8 +12,6 @@ import { fields } from '../../../filters/stubs'; import { nodeTypes } from '../..'; import { getFields } from './get_fields'; -jest.mock('../../grammar'); - describe('getFields', () => { let indexPattern: DataViewBase; diff --git a/packages/kbn-es-query/src/kuery/functions/utils/get_full_field_name_node.test.ts b/packages/kbn-es-query/src/kuery/functions/utils/get_full_field_name_node.test.ts index 6ea315446d0ea..a052ae009bf6c 100644 --- a/packages/kbn-es-query/src/kuery/functions/utils/get_full_field_name_node.test.ts +++ b/packages/kbn-es-query/src/kuery/functions/utils/get_full_field_name_node.test.ts @@ -11,8 +11,6 @@ import { fields } from '../../../filters/stubs'; import { DataViewBase } from '../../../..'; import { getFullFieldNameNode } from './get_full_field_name_node'; -jest.mock('../../grammar'); - describe('getFullFieldNameNode', function () { let indexPattern: DataViewBase; diff --git a/packages/kbn-es-query/src/kuery/kuery_syntax_error.test.ts b/packages/kbn-es-query/src/kuery/kuery_syntax_error.test.ts index e04b1abdc8494..9966c5125efab 100644 --- a/packages/kbn-es-query/src/kuery/kuery_syntax_error.test.ts +++ b/packages/kbn-es-query/src/kuery/kuery_syntax_error.test.ts @@ -8,8 +8,6 @@ import { fromKueryExpression } from './ast'; -jest.mock('./grammar'); - describe('kql syntax errors', () => { it('should throw an error for a field query missing a value', () => { expect(() => { @@ -68,17 +66,21 @@ describe('kql syntax errors', () => { it('should throw an error for unescaped quotes in a quoted string', () => { expect(() => { fromKueryExpression('foo:"ba "r"'); - }).toThrow( - 'Expected AND, OR, end of input, whitespace but "r" found.\n' + 'foo:"ba "r"\n' + '---------^' - ); + }).toThrowErrorMatchingInlineSnapshot(` + "Expected AND, OR, end of input but \\"r\\" found. + foo:\\"ba \\"r\\" + ---------^" + `); }); it('should throw an error for unescaped special characters in literals', () => { expect(() => { fromKueryExpression('foo:ba:r'); - }).toThrow( - 'Expected AND, OR, end of input, whitespace but ":" found.\n' + 'foo:ba:r\n' + '------^' - ); + }).toThrowErrorMatchingInlineSnapshot(` + "Expected AND, OR, end of input but \\":\\" found. + foo:ba:r + ------^" + `); }); it('should throw an error for range queries missing a value', () => { diff --git a/packages/kbn-es-query/src/kuery/node_types/function.test.ts b/packages/kbn-es-query/src/kuery/node_types/function.test.ts index 11e682a25602d..060658a227794 100644 --- a/packages/kbn-es-query/src/kuery/node_types/function.test.ts +++ b/packages/kbn-es-query/src/kuery/node_types/function.test.ts @@ -21,8 +21,6 @@ import { import { DataViewBase } from '../../es_query'; import { fields } from '../../filters/stubs/fields.mocks'; -jest.mock('../grammar'); - describe('kuery node types', () => { describe('function', () => { let indexPattern: DataViewBase; diff --git a/packages/kbn-es-query/src/kuery/node_types/literal.test.ts b/packages/kbn-es-query/src/kuery/node_types/literal.test.ts index c0680016644f7..31d885e9b3e17 100644 --- a/packages/kbn-es-query/src/kuery/node_types/literal.test.ts +++ b/packages/kbn-es-query/src/kuery/node_types/literal.test.ts @@ -8,8 +8,6 @@ import { buildNode, KQL_NODE_TYPE_LITERAL, toElasticsearchQuery, toKqlExpression } from './literal'; -jest.mock('../grammar'); - describe('kuery node types', () => { describe('literal', () => { describe('buildNode', () => { diff --git a/packages/kbn-es-query/src/kuery/node_types/node_builder.test.ts b/packages/kbn-es-query/src/kuery/node_types/node_builder.test.ts index d414788afec1e..0703e789aed6c 100644 --- a/packages/kbn-es-query/src/kuery/node_types/node_builder.test.ts +++ b/packages/kbn-es-query/src/kuery/node_types/node_builder.test.ts @@ -10,8 +10,6 @@ import { nodeBuilder } from './node_builder'; import { toElasticsearchQuery } from '..'; import { buildNode } from './literal'; -jest.mock('../grammar'); - describe('nodeBuilder', () => { describe('is method', () => { test('string value', () => { diff --git a/packages/kbn-es-query/src/kuery/node_types/wildcard.test.ts b/packages/kbn-es-query/src/kuery/node_types/wildcard.test.ts index 40cbfc00e8284..89387930b78f5 100644 --- a/packages/kbn-es-query/src/kuery/node_types/wildcard.test.ts +++ b/packages/kbn-es-query/src/kuery/node_types/wildcard.test.ts @@ -18,8 +18,6 @@ import { toQueryStringQuery, } from './wildcard'; -jest.mock('../grammar'); - describe('kuery node types', () => { describe('wildcard', () => { describe('buildNode', () => {