From f4fae28bda613ce736aa8f655dd822adb7e97041 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Mon, 8 Mar 2021 12:32:01 -0700 Subject: [PATCH] [KQL] Use cache and other performance improvements (#93319) (#93973) * [KQL] Use cache and other performance improvements * Fix test * Fix jest tests Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../es_query/kuery/ast/_generated_/kuery.js | 1014 ++++++++++++++--- .../data/common/es_query/kuery/ast/kuery.peg | 14 +- .../es_query/kuery/kuery_syntax_error.test.ts | 8 +- tasks/config/peg.js | 1 + .../apis/saved_objects/find.ts | 5 +- 5 files changed, 846 insertions(+), 196 deletions(-) diff --git a/src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js b/src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js index e8c9c3b4e9cc3..4557c874c8264 100644 --- a/src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js +++ b/src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js @@ -50,13 +50,13 @@ module.exports = (function() { peg$c2 = function(head, query) { return query; }, peg$c3 = function(head, tail) { const nodes = [head, ...tail]; - const cursor = nodes.find(node => node.type === 'cursor'); + const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); if (cursor) return cursor; return buildFunctionNode('or', nodes); }, peg$c4 = function(head, tail) { const nodes = [head, ...tail]; - const cursor = nodes.find(node => node.type === 'cursor'); + const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); if (cursor) return cursor; return buildFunctionNode('and', nodes); }, @@ -144,7 +144,7 @@ module.exports = (function() { peg$c23 = function(head, partial) { return partial; }, peg$c24 = function(head, tail) { const nodes = [head, ...tail]; - const cursor = nodes.find(node => node.type === 'cursor'); + const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); if (cursor) { return { ...cursor, @@ -155,7 +155,7 @@ module.exports = (function() { }, peg$c25 = function(head, tail) { const nodes = [head, ...tail]; - const cursor = nodes.find(node => node.type === 'cursor'); + const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); if (cursor) { return { ...cursor, @@ -199,9 +199,10 @@ module.exports = (function() { peg$c37 = "not", peg$c38 = { type: "literal", value: "not", description: "\"not\"" }, peg$c39 = { type: "other", description: "literal" }, - peg$c40 = "\"", - peg$c41 = { type: "literal", value: "\"", description: "\"\\\"\"" }, - peg$c42 = function(prefix, cursor, suffix) { + peg$c40 = function() { return parseCursor; }, + peg$c41 = "\"", + peg$c42 = { type: "literal", value: "\"", description: "\"\\\"\"" }, + peg$c43 = function(prefix, cursor, suffix) { const { start, end } = location(); return { type: 'cursor', @@ -212,17 +213,17 @@ module.exports = (function() { text: text().replace(cursor, '') }; }, - peg$c43 = function(chars) { + peg$c44 = function(chars) { return buildLiteralNode(chars.join('')); }, - peg$c44 = "\\", - peg$c45 = { type: "literal", value: "\\", description: "\"\\\\\"" }, - peg$c46 = /^[\\"]/, - peg$c47 = { type: "class", value: "[\\\\\"]", description: "[\\\\\"]" }, - peg$c48 = function(char) { return char; }, - peg$c49 = /^[^"]/, - peg$c50 = { type: "class", value: "[^\"]", description: "[^\"]" }, - peg$c51 = function(chars) { + peg$c45 = "\\", + peg$c46 = { type: "literal", value: "\\", description: "\"\\\\\"" }, + peg$c47 = /^[\\"]/, + peg$c48 = { type: "class", value: "[\\\\\"]", description: "[\\\\\"]" }, + peg$c49 = function(char) { return char; }, + peg$c50 = /^[^"]/, + peg$c51 = { type: "class", value: "[^\"]", description: "[^\"]" }, + peg$c52 = function(chars) { const sequence = chars.join('').trim(); if (sequence === 'null') return buildLiteralNode(null); if (sequence === 'true') return buildLiteralNode(true); @@ -231,38 +232,37 @@ module.exports = (function() { const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/ return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence); }, - peg$c52 = { type: "any", description: "any character" }, - peg$c53 = "*", - peg$c54 = { type: "literal", value: "*", description: "\"*\"" }, - peg$c55 = function() { return wildcardSymbol; }, - peg$c56 = "\\t", - peg$c57 = { type: "literal", value: "\\t", description: "\"\\\\t\"" }, - peg$c58 = function() { return '\t'; }, - peg$c59 = "\\r", - peg$c60 = { type: "literal", value: "\\r", description: "\"\\\\r\"" }, - peg$c61 = function() { return '\r'; }, - peg$c62 = "\\n", - peg$c63 = { type: "literal", value: "\\n", description: "\"\\\\n\"" }, - peg$c64 = function() { return '\n'; }, - peg$c65 = function(keyword) { return keyword; }, - peg$c66 = /^[\\():<>"*{}]/, - peg$c67 = { type: "class", value: "[\\\\():<>\"*{}]", description: "[\\\\():<>\"*{}]" }, - peg$c68 = "<=", - peg$c69 = { type: "literal", value: "<=", description: "\"<=\"" }, - peg$c70 = function() { return 'lte'; }, - peg$c71 = ">=", - peg$c72 = { type: "literal", value: ">=", description: "\">=\"" }, - peg$c73 = function() { return 'gte'; }, - peg$c74 = "<", - peg$c75 = { type: "literal", value: "<", description: "\"<\"" }, - peg$c76 = function() { return 'lt'; }, - peg$c77 = ">", - peg$c78 = { type: "literal", value: ">", description: "\">\"" }, - peg$c79 = function() { return 'gt'; }, - peg$c80 = { type: "other", description: "whitespace" }, - peg$c81 = /^[ \t\r\n]/, - peg$c82 = { type: "class", value: "[\\ \\t\\r\\n]", description: "[\\ \\t\\r\\n]" }, - peg$c83 = function() { return parseCursor; }, + peg$c53 = { type: "any", description: "any character" }, + peg$c54 = "*", + peg$c55 = { type: "literal", value: "*", description: "\"*\"" }, + peg$c56 = function() { return wildcardSymbol; }, + peg$c57 = "\\t", + peg$c58 = { type: "literal", value: "\\t", description: "\"\\\\t\"" }, + peg$c59 = function() { return '\t'; }, + peg$c60 = "\\r", + peg$c61 = { type: "literal", value: "\\r", description: "\"\\\\r\"" }, + peg$c62 = function() { return '\r'; }, + peg$c63 = "\\n", + peg$c64 = { type: "literal", value: "\\n", description: "\"\\\\n\"" }, + peg$c65 = function() { return '\n'; }, + peg$c66 = function(keyword) { return keyword; }, + peg$c67 = /^[\\():<>"*{}]/, + peg$c68 = { type: "class", value: "[\\\\():<>\"*{}]", description: "[\\\\():<>\"*{}]" }, + peg$c69 = "<=", + peg$c70 = { type: "literal", value: "<=", description: "\"<=\"" }, + peg$c71 = function() { return 'lte'; }, + peg$c72 = ">=", + peg$c73 = { type: "literal", value: ">=", description: "\">=\"" }, + peg$c74 = function() { return 'gte'; }, + peg$c75 = "<", + peg$c76 = { type: "literal", value: "<", description: "\"<\"" }, + peg$c77 = function() { return 'lt'; }, + peg$c78 = ">", + peg$c79 = { type: "literal", value: ">", description: "\">\"" }, + peg$c80 = function() { return 'gt'; }, + peg$c81 = { type: "other", description: "whitespace" }, + peg$c82 = /^[ \t\r\n]/, + peg$c83 = { type: "class", value: "[\\ \\t\\r\\n]", description: "[\\ \\t\\r\\n]" }, peg$c84 = "@kuery-cursor@", peg$c85 = { type: "literal", value: "@kuery-cursor@", description: "\"@kuery-cursor@\"" }, peg$c86 = function() { return cursorSymbol; }, @@ -337,6 +337,8 @@ module.exports = (function() { peg$maxFailExpected = [], peg$silentFails = 0, + peg$resultsCache = {}, + peg$result; if ("startRule" in options) { @@ -518,6 +520,15 @@ module.exports = (function() { function peg$parsestart() { var s0, s1, s2, s3; + var key = peg$currPos * 56 + 0, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = []; s2 = peg$parseSpace(); @@ -549,12 +560,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseOrQuery() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 1, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; peg$savedPos = peg$currPos; s1 = peg$c1(); @@ -637,12 +659,23 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseAndQuery() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 2, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseNotQuery(); if (s1 !== peg$FAILED) { @@ -702,12 +735,23 @@ module.exports = (function() { s0 = peg$parseNotQuery(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseNotQuery() { var s0, s1, s2; + var key = peg$currPos * 56 + 3, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseNot(); if (s1 !== peg$FAILED) { @@ -728,12 +772,23 @@ module.exports = (function() { s0 = peg$parseSubQuery(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseSubQuery() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 4, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { s1 = peg$c6; @@ -789,12 +844,23 @@ module.exports = (function() { s0 = peg$parseNestedQuery(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseNestedQuery() { var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9; + var key = peg$currPos * 56 + 5, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseField(); if (s1 !== peg$FAILED) { @@ -890,12 +956,23 @@ module.exports = (function() { s0 = peg$parseExpression(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseExpression() { var s0; + var key = peg$currPos * 56 + 6, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseFieldRangeExpression(); if (s0 === peg$FAILED) { s0 = peg$parseFieldValueExpression(); @@ -904,12 +981,23 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseField() { var s0, s1; + var key = peg$currPos * 56 + 7, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + peg$silentFails++; s0 = peg$parseLiteral(); peg$silentFails--; @@ -918,12 +1006,23 @@ module.exports = (function() { if (peg$silentFails === 0) { peg$fail(peg$c18); } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseFieldRangeExpression() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 8, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseField(); if (s1 !== peg$FAILED) { @@ -969,12 +1068,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseFieldValueExpression() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 9, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseField(); if (s1 !== peg$FAILED) { @@ -1026,12 +1136,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseValueExpression() { var s0, s1; + var key = peg$currPos * 56 + 10, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseValue(); if (s1 !== peg$FAILED) { @@ -1040,12 +1161,23 @@ module.exports = (function() { } s0 = s1; + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseListOfValues() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 11, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { s1 = peg$c6; @@ -1101,12 +1233,23 @@ module.exports = (function() { s0 = peg$parseValue(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseOrListOfValues() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 12, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseAndListOfValues(); if (s1 !== peg$FAILED) { @@ -1166,12 +1309,23 @@ module.exports = (function() { s0 = peg$parseAndListOfValues(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseAndListOfValues() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 13, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseNotListOfValues(); if (s1 !== peg$FAILED) { @@ -1231,12 +1385,23 @@ module.exports = (function() { s0 = peg$parseNotListOfValues(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseNotListOfValues() { var s0, s1, s2; + var key = peg$currPos * 56 + 14, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseNot(); if (s1 !== peg$FAILED) { @@ -1257,12 +1422,23 @@ module.exports = (function() { s0 = peg$parseListOfValues(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseValue() { var s0, s1; + var key = peg$currPos * 56 + 15, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + peg$silentFails++; s0 = peg$currPos; s1 = peg$parseQuotedString(); @@ -1286,12 +1462,23 @@ module.exports = (function() { if (peg$silentFails === 0) { peg$fail(peg$c27); } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseOr() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 16, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + peg$silentFails++; s0 = peg$currPos; s1 = []; @@ -1367,12 +1554,23 @@ module.exports = (function() { if (peg$silentFails === 0) { peg$fail(peg$c30); } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseAnd() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 17, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + peg$silentFails++; s0 = peg$currPos; s1 = []; @@ -1448,12 +1646,23 @@ module.exports = (function() { if (peg$silentFails === 0) { peg$fail(peg$c33); } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseNot() { var s0, s1, s2, s3; + var key = peg$currPos * 56 + 18, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + peg$silentFails++; s0 = peg$currPos; if (input.substr(peg$currPos, 3).toLowerCase() === peg$c37) { @@ -1514,12 +1723,23 @@ module.exports = (function() { if (peg$silentFails === 0) { peg$fail(peg$c36); } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLiteral() { var s0, s1; + var key = peg$currPos * 56 + 19, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + peg$silentFails++; s0 = peg$parseQuotedString(); if (s0 === peg$FAILED) { @@ -1531,48 +1751,71 @@ module.exports = (function() { if (peg$silentFails === 0) { peg$fail(peg$c39); } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseQuotedString() { - var s0, s1, s2, s3, s4, s5; + var s0, s1, s2, s3, s4, s5, s6; + + var key = peg$currPos * 56 + 20, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } s0 = peg$currPos; - if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c40; - peg$currPos++; + peg$savedPos = peg$currPos; + s1 = peg$c40(); + if (s1) { + s1 = void 0; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s1 !== peg$FAILED) { - s2 = []; - s3 = peg$parseQuotedCharacter(); - while (s3 !== peg$FAILED) { - s2.push(s3); - s3 = peg$parseQuotedCharacter(); + if (input.charCodeAt(peg$currPos) === 34) { + s2 = peg$c41; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s2 !== peg$FAILED) { - s3 = peg$parseCursor(); + s3 = []; + s4 = peg$parseQuotedCharacter(); + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parseQuotedCharacter(); + } if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$parseQuotedCharacter(); - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$parseQuotedCharacter(); - } + s4 = peg$parseCursor(); if (s4 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 34) { - s5 = peg$c40; - peg$currPos++; - } else { - s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } + s5 = []; + s6 = peg$parseQuotedCharacter(); + while (s6 !== peg$FAILED) { + s5.push(s6); + s6 = peg$parseQuotedCharacter(); } if (s5 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c42(s2, s3, s4); - s0 = s1; + if (input.charCodeAt(peg$currPos) === 34) { + s6 = peg$c41; + peg$currPos++; + } else { + s6 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c42); } + } + if (s6 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c43(s3, s4, s5); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1596,11 +1839,11 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c40; + s1 = peg$c41; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } + if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1611,15 +1854,15 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c40; + s3 = peg$c41; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } + if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c43(s2); + s1 = peg$c44(s2); s0 = s1; } else { peg$currPos = s0; @@ -1635,33 +1878,44 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseQuotedCharacter() { var s0, s1, s2; + var key = peg$currPos * 56 + 21, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseEscapedWhitespace(); if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c44; + s1 = peg$c45; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c45); } + if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s1 !== peg$FAILED) { - if (peg$c46.test(input.charAt(peg$currPos))) { + if (peg$c47.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c47); } + if (peg$silentFails === 0) { peg$fail(peg$c48); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c48(s2); + s1 = peg$c49(s2); s0 = s1; } else { peg$currPos = s0; @@ -1684,16 +1938,16 @@ module.exports = (function() { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { - if (peg$c49.test(input.charAt(peg$currPos))) { + if (peg$c50.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c50); } + if (peg$silentFails === 0) { peg$fail(peg$c51); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c48(s2); + s1 = peg$c49(s2); s0 = s1; } else { peg$currPos = s0; @@ -1706,32 +1960,55 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseUnquotedLiteral() { - var s0, s1, s2, s3, s4; + var s0, s1, s2, s3, s4, s5; + + var key = peg$currPos * 56 + 22, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } s0 = peg$currPos; - s1 = []; - s2 = peg$parseUnquotedCharacter(); - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parseUnquotedCharacter(); + peg$savedPos = peg$currPos; + s1 = peg$c40(); + if (s1) { + s1 = void 0; + } else { + s1 = peg$FAILED; } if (s1 !== peg$FAILED) { - s2 = peg$parseCursor(); + s2 = []; + s3 = peg$parseUnquotedCharacter(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseUnquotedCharacter(); + } if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$parseUnquotedCharacter(); - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parseUnquotedCharacter(); - } + s3 = peg$parseCursor(); if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c42(s1, s2, s3); - s0 = s1; + s4 = []; + s5 = peg$parseUnquotedCharacter(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parseUnquotedCharacter(); + } + if (s4 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c43(s2, s3, s4); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1758,17 +2035,28 @@ module.exports = (function() { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c51(s1); + s1 = peg$c52(s1); } s0 = s1; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseUnquotedCharacter() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 23, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseEscapedWhitespace(); if (s0 === peg$FAILED) { s0 = peg$parseEscapedSpecialCharacter(); @@ -1816,11 +2104,11 @@ module.exports = (function() { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c52); } + if (peg$silentFails === 0) { peg$fail(peg$c53); } } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c48(s4); + s1 = peg$c49(s4); s0 = s1; } else { peg$currPos = s0; @@ -1843,52 +2131,86 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseWildcard() { var s0, s1; + var key = peg$currPos * 56 + 24, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 42) { - s1 = peg$c53; + s1 = peg$c54; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c55); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c55(); + s1 = peg$c56(); } s0 = s1; + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseOptionalSpace() { - var s0, s1, s2, s3, s4; + var s0, s1, s2, s3, s4, s5; + + var key = peg$currPos * 56 + 25, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } s0 = peg$currPos; - s1 = []; - s2 = peg$parseSpace(); - while (s2 !== peg$FAILED) { - s1.push(s2); - s2 = peg$parseSpace(); + peg$savedPos = peg$currPos; + s1 = peg$c40(); + if (s1) { + s1 = void 0; + } else { + s1 = peg$FAILED; } if (s1 !== peg$FAILED) { - s2 = peg$parseCursor(); + s2 = []; + s3 = peg$parseSpace(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseSpace(); + } if (s2 !== peg$FAILED) { - s3 = []; - s4 = peg$parseSpace(); - while (s4 !== peg$FAILED) { - s3.push(s4); - s4 = peg$parseSpace(); - } + s3 = peg$parseCursor(); if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c42(s1, s2, s3); - s0 = s1; + s4 = []; + s5 = peg$parseSpace(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parseSpace(); + } + if (s4 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c43(s2, s3, s4); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } } else { peg$currPos = s0; s0 = peg$FAILED; @@ -1910,75 +2232,97 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseEscapedWhitespace() { var s0, s1; + var key = peg$currPos * 56 + 26, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c56) { - s1 = peg$c56; + if (input.substr(peg$currPos, 2) === peg$c57) { + s1 = peg$c57; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c57); } + if (peg$silentFails === 0) { peg$fail(peg$c58); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c58(); + s1 = peg$c59(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c59) { - s1 = peg$c59; + if (input.substr(peg$currPos, 2) === peg$c60) { + s1 = peg$c60; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c60); } + if (peg$silentFails === 0) { peg$fail(peg$c61); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c61(); + s1 = peg$c62(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c62) { - s1 = peg$c62; + if (input.substr(peg$currPos, 2) === peg$c63) { + s1 = peg$c63; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c63); } + if (peg$silentFails === 0) { peg$fail(peg$c64); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c64(); + s1 = peg$c65(); } s0 = s1; } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseEscapedSpecialCharacter() { var s0, s1, s2; + var key = peg$currPos * 56 + 27, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c44; + s1 = peg$c45; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c45); } + if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s1 !== peg$FAILED) { s2 = peg$parseSpecialCharacter(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c48(s2); + s1 = peg$c49(s2); s0 = s1; } else { peg$currPos = s0; @@ -1989,19 +2333,30 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseEscapedKeyword() { var s0, s1, s2; + var key = peg$currPos * 56 + 28, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c44; + s1 = peg$c45; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c45); } + if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s1 !== peg$FAILED) { if (input.substr(peg$currPos, 2).toLowerCase() === peg$c31) { @@ -2031,7 +2386,7 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c65(s2); + s1 = peg$c66(s2); s0 = s1; } else { peg$currPos = s0; @@ -2042,12 +2397,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseKeyword() { var s0; + var key = peg$currPos * 56 + 29, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseOr(); if (s0 === peg$FAILED) { s0 = peg$parseAnd(); @@ -2056,114 +2422,158 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseSpecialCharacter() { var s0; - if (peg$c66.test(input.charAt(peg$currPos))) { + var key = peg$currPos * 56 + 30, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + + if (peg$c67.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c67); } + if (peg$silentFails === 0) { peg$fail(peg$c68); } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseRangeOperator() { var s0, s1; + var key = peg$currPos * 56 + 31, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c68) { - s1 = peg$c68; + if (input.substr(peg$currPos, 2) === peg$c69) { + s1 = peg$c69; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c69); } + if (peg$silentFails === 0) { peg$fail(peg$c70); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c70(); + s1 = peg$c71(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c71) { - s1 = peg$c71; + if (input.substr(peg$currPos, 2) === peg$c72) { + s1 = peg$c72; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c72); } + if (peg$silentFails === 0) { peg$fail(peg$c73); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c73(); + s1 = peg$c74(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c74; + s1 = peg$c75; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c75); } + if (peg$silentFails === 0) { peg$fail(peg$c76); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c76(); + s1 = peg$c77(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c77; + s1 = peg$c78; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c78); } + if (peg$silentFails === 0) { peg$fail(peg$c79); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c79(); + s1 = peg$c80(); } s0 = s1; } } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseSpace() { var s0, s1; + var key = peg$currPos * 56 + 32, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + peg$silentFails++; - if (peg$c81.test(input.charAt(peg$currPos))) { + if (peg$c82.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c82); } + if (peg$silentFails === 0) { peg$fail(peg$c83); } } peg$silentFails--; if (s0 === peg$FAILED) { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c80); } + if (peg$silentFails === 0) { peg$fail(peg$c81); } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseCursor() { var s0, s1, s2; + var key = peg$currPos * 56 + 33, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; peg$savedPos = peg$currPos; - s1 = peg$c83(); + s1 = peg$c40(); if (s1) { s1 = void 0; } else { @@ -2190,12 +2600,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneOr() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 34, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = []; s2 = peg$parseSpace(); @@ -2235,12 +2656,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneAnd() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 35, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = []; s2 = peg$parseSpace(); @@ -2295,12 +2727,23 @@ module.exports = (function() { s0 = s1; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneNot() { var s0, s1; + var key = peg$currPos * 56 + 36, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 45) { s1 = peg$c95; @@ -2330,12 +2773,23 @@ module.exports = (function() { s0 = s1; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneQuery() { var s0; + var key = peg$currPos * 56 + 37, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseLuceneFieldQuery(); if (s0 === peg$FAILED) { s0 = peg$parseLuceneValue(); @@ -2344,12 +2798,23 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneFieldQuery() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 38, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseLuceneLiteral(); if (s1 !== peg$FAILED) { @@ -2400,12 +2865,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneValue() { var s0; + var key = peg$currPos * 56 + 39, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseLuceneRange(); if (s0 === peg$FAILED) { s0 = peg$parseLuceneWildcard(); @@ -2423,12 +2899,23 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneExists() { var s0, s1, s2, s3, s4, s5; + var key = peg$currPos * 56 + 40, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.substr(peg$currPos, 8) === peg$c100) { s1 = peg$c100; @@ -2486,12 +2973,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneRange() { var s0, s1, s2, s3, s4, s5, s6; + var key = peg$currPos * 56 + 41, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseRangeOperator(); if (s1 !== peg$FAILED) { @@ -2567,22 +3065,33 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneWildcard() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 42, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = []; s2 = peg$parseLuceneUnquotedCharacter(); if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 42) { - s2 = peg$c53; + s2 = peg$c54; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c55); } } } while (s2 !== peg$FAILED) { @@ -2590,11 +3099,11 @@ module.exports = (function() { s2 = peg$parseLuceneUnquotedCharacter(); if (s2 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 42) { - s2 = peg$c53; + s2 = peg$c54; peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c55); } } } } @@ -2630,12 +3139,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneRegex() { var s0, s1, s2, s3; + var key = peg$currPos * 56 + 43, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 47) { s1 = peg$c107; @@ -2688,12 +3208,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneFuzzy() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 44, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseLuceneUnquotedLiteral(); if (s1 !== peg$FAILED) { @@ -2740,12 +3271,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneProximity() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 45, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseQuotedString(); if (s1 !== peg$FAILED) { @@ -2792,12 +3334,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneBoost() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 46, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = peg$parseLuceneLiteral(); if (s1 !== peg$FAILED) { @@ -2844,23 +3397,45 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneLiteral() { var s0; + var key = peg$currPos * 56 + 47, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseQuotedString(); if (s0 === peg$FAILED) { s0 = peg$parseLuceneUnquotedLiteral(); } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneUnquotedLiteral() { var s0, s1; + var key = peg$currPos * 56 + 48, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = []; s1 = peg$parseLuceneUnquotedCharacter(); if (s1 !== peg$FAILED) { @@ -2872,12 +3447,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneUnquotedCharacter() { var s0, s1, s2, s3; + var key = peg$currPos * 56 + 49, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseEscapedWhitespace(); if (s0 === peg$FAILED) { s0 = peg$parseEscapedLuceneSpecialCharacter(); @@ -2910,7 +3496,7 @@ module.exports = (function() { peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c52); } + if (peg$silentFails === 0) { peg$fail(peg$c53); } } if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; @@ -2930,12 +3516,23 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneKeyword() { var s0; + var key = peg$currPos * 56 + 50, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$parseOr(); if (s0 === peg$FAILED) { s0 = peg$parseAnd(); @@ -2953,19 +3550,30 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseEscapedLuceneSpecialCharacter() { var s0, s1, s2; + var key = peg$currPos * 56 + 51, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c44; + s1 = peg$c45; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c45); } + if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s1 !== peg$FAILED) { s2 = peg$parseLuceneSpecialCharacter(); @@ -2982,12 +3590,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneSpecialCharacter() { var s0; + var key = peg$currPos * 56 + 52, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + if (input.charCodeAt(peg$currPos) === 43) { s0 = peg$c93; peg$currPos++; @@ -3013,19 +3632,19 @@ module.exports = (function() { } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 62) { - s0 = peg$c77; + s0 = peg$c78; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c78); } + if (peg$silentFails === 0) { peg$fail(peg$c79); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 60) { - s0 = peg$c74; + s0 = peg$c75; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c75); } + if (peg$silentFails === 0) { peg$fail(peg$c76); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 33) { @@ -3093,11 +3712,11 @@ module.exports = (function() { } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s0 = peg$c40; + s0 = peg$c41; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c41); } + if (peg$silentFails === 0) { peg$fail(peg$c42); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 126) { @@ -3109,11 +3728,11 @@ module.exports = (function() { } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 42) { - s0 = peg$c53; + s0 = peg$c54; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c54); } + if (peg$silentFails === 0) { peg$fail(peg$c55); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 63) { @@ -3133,11 +3752,11 @@ module.exports = (function() { } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 92) { - s0 = peg$c44; + s0 = peg$c45; peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c45); } + if (peg$silentFails === 0) { peg$fail(peg$c46); } } if (s0 === peg$FAILED) { if (input.charCodeAt(peg$currPos) === 47) { @@ -3167,12 +3786,23 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneTo() { var s0, s1, s2, s3, s4; + var key = peg$currPos * 56 + 53, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + s0 = peg$currPos; s1 = []; s2 = peg$parseSpace(); @@ -3219,12 +3849,23 @@ module.exports = (function() { s0 = peg$FAILED; } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneRangeStart() { var s0; + var key = peg$currPos * 56 + 54, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + if (input.charCodeAt(peg$currPos) === 91) { s0 = peg$c124; peg$currPos++; @@ -3242,12 +3883,23 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } function peg$parseLuceneRangeEnd() { var s0; + var key = peg$currPos * 56 + 55, + cached = peg$resultsCache[key]; + + if (cached) { + peg$currPos = cached.nextPos; + + return cached.result; + } + if (input.charCodeAt(peg$currPos) === 93) { s0 = peg$c126; peg$currPos++; @@ -3265,6 +3917,8 @@ module.exports = (function() { } } + peg$resultsCache[key] = { nextPos: peg$currPos, result: s0 }; + return s0; } diff --git a/src/plugins/data/common/es_query/kuery/ast/kuery.peg b/src/plugins/data/common/es_query/kuery/ast/kuery.peg index 6407107e5ee65..865e4f04e0b10 100644 --- a/src/plugins/data/common/es_query/kuery/ast/kuery.peg +++ b/src/plugins/data/common/es_query/kuery/ast/kuery.peg @@ -29,7 +29,7 @@ OrQuery = &{ return errorOnLuceneSyntax; } LuceneQuery / head:AndQuery tail:(Or query:AndQuery { return query; })+ { const nodes = [head, ...tail]; - const cursor = nodes.find(node => node.type === 'cursor'); + const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); if (cursor) return cursor; return buildFunctionNode('or', nodes); } @@ -38,7 +38,7 @@ OrQuery AndQuery = head:NotQuery tail:(And query:NotQuery { return query; })+ { const nodes = [head, ...tail]; - const cursor = nodes.find(node => node.type === 'cursor'); + const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); if (cursor) return cursor; return buildFunctionNode('and', nodes); } @@ -143,7 +143,7 @@ ListOfValues OrListOfValues = head:AndListOfValues tail:(Or partial:AndListOfValues { return partial; })+ { const nodes = [head, ...tail]; - const cursor = nodes.find(node => node.type === 'cursor'); + const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); if (cursor) { return { ...cursor, @@ -157,7 +157,7 @@ OrListOfValues AndListOfValues = head:NotListOfValues tail:(And partial:NotListOfValues { return partial; })+ { const nodes = [head, ...tail]; - const cursor = nodes.find(node => node.type === 'cursor'); + const cursor = parseCursor && nodes.find(node => node.type === 'cursor'); if (cursor) { return { ...cursor, @@ -213,7 +213,7 @@ Literal "literal" = QuotedString / UnquotedLiteral QuotedString - = '"' prefix:QuotedCharacter* cursor:Cursor suffix:QuotedCharacter* '"' { + = &{ return parseCursor; } '"' prefix:QuotedCharacter* cursor:Cursor suffix:QuotedCharacter* '"' { const { start, end } = location(); return { type: 'cursor', @@ -234,7 +234,7 @@ QuotedCharacter / !Cursor char:[^"] { return char; } UnquotedLiteral - = prefix:UnquotedCharacter* cursor:Cursor suffix:UnquotedCharacter* { + = &{ return parseCursor; } prefix:UnquotedCharacter* cursor:Cursor suffix:UnquotedCharacter* { const { start, end } = location(); return { type: 'cursor', @@ -266,7 +266,7 @@ Wildcard = '*' { return wildcardSymbol; } OptionalSpace - = prefix:Space* cursor:Cursor suffix:Space* { + = &{ return parseCursor; } prefix:Space* cursor:Cursor suffix:Space* { const { start, end } = location(); return { type: 'cursor', diff --git a/src/plugins/data/common/es_query/kuery/kuery_syntax_error.test.ts b/src/plugins/data/common/es_query/kuery/kuery_syntax_error.test.ts index 970577cfa8954..6875bc3e5f74f 100644 --- a/src/plugins/data/common/es_query/kuery/kuery_syntax_error.test.ts +++ b/src/plugins/data/common/es_query/kuery/kuery_syntax_error.test.ts @@ -66,17 +66,13 @@ 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' + '---------^' - ); + }).toThrow('Expected AND, OR, end of input but "r" found.\n' + 'foo:"ba "r"\n' + '---------^'); }); 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' + '------^' - ); + }).toThrow('Expected AND, OR, end of input but ":" found.\n' + 'foo:ba:r\n' + '------^'); }); it('should throw an error for range queries missing a value', () => { diff --git a/tasks/config/peg.js b/tasks/config/peg.js index 09da1ed81c222..754f7a0290fe7 100644 --- a/tasks/config/peg.js +++ b/tasks/config/peg.js @@ -12,6 +12,7 @@ module.exports = { dest: 'src/plugins/data/common/es_query/kuery/ast/_generated_/kuery.js', options: { allowedStartRules: ['start', 'Literal'], + cache: true, }, }, timelion_chain: { diff --git a/test/api_integration/apis/saved_objects/find.ts b/test/api_integration/apis/saved_objects/find.ts index 66c2a083c79e5..28c38ca9e0ded 100644 --- a/test/api_integration/apis/saved_objects/find.ts +++ b/test/api_integration/apis/saved_objects/find.ts @@ -286,9 +286,8 @@ export default function ({ getService }: FtrProviderContext) { expect(resp.body).to.eql({ error: 'Bad Request', message: - 'KQLSyntaxError: Expected AND, OR, end of input, ' + - 'whitespace but "<" found.\ndashboard.attributes.title:foo' + - '