diff --git a/packages/kbn-es-query/src/kuery/ast/__tests__/ast.js b/packages/kbn-es-query/src/kuery/ast/__tests__/ast.js index 481d0405373a..1107d1eea04d 100644 --- a/packages/kbn-es-query/src/kuery/ast/__tests__/ast.js +++ b/packages/kbn-es-query/src/kuery/ast/__tests__/ast.js @@ -418,4 +418,81 @@ describe('kuery AST API', function () { }); + describe('doesKueryExpressionHaveLuceneSyntaxError', function () { + it('should return true for Lucene ranges', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar: [1 TO 10]'); + expect(result).to.eql(true); + }); + + it('should return false for KQL ranges', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar < 1'); + expect(result).to.eql(false); + }); + + it('should return true for Lucene exists', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('_exists_: bar'); + expect(result).to.eql(true); + }); + + it('should return false for KQL exists', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar:*'); + expect(result).to.eql(false); + }); + + it('should return true for Lucene wildcards', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar: ba?'); + expect(result).to.eql(true); + }); + + it('should return false for KQL wildcards', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar: ba*'); + expect(result).to.eql(false); + }); + + it('should return true for Lucene regex', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar: /ba.*/'); + expect(result).to.eql(true); + }); + + it('should return true for Lucene fuzziness', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar: ba~'); + expect(result).to.eql(true); + }); + + it('should return true for Lucene proximity', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar: "ba"~2'); + expect(result).to.eql(true); + }); + + it('should return true for Lucene boosting', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('bar: ba^2'); + expect(result).to.eql(true); + }); + + it('should return true for Lucene + operator', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('+foo: bar'); + expect(result).to.eql(true); + }); + + it('should return true for Lucene - operators', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('-foo: bar'); + expect(result).to.eql(true); + }); + + it('should return true for Lucene && operators', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('foo: bar && baz: qux'); + expect(result).to.eql(true); + }); + + it('should return true for Lucene || operators', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('foo: bar || baz: qux'); + expect(result).to.eql(true); + }); + + it('should return true for mixed KQL/Lucene queries', function () { + const result = ast.doesKueryExpressionHaveLuceneSyntaxError('foo: bar and (baz: qux || bag)'); + expect(result).to.eql(true); + }); + }); + }); diff --git a/packages/kbn-es-query/src/kuery/ast/ast.d.ts b/packages/kbn-es-query/src/kuery/ast/ast.d.ts index 711e2e9f3776..df81c8651c4c 100644 --- a/packages/kbn-es-query/src/kuery/ast/ast.d.ts +++ b/packages/kbn-es-query/src/kuery/ast/ast.d.ts @@ -46,3 +46,5 @@ export function fromKueryExpression( ): KueryNode; export function toElasticsearchQuery(node: KueryNode, indexPattern: StaticIndexPattern): JsonObject; + +export function doesKueryExpressionHaveLuceneSyntaxError(expression: string): boolean; diff --git a/packages/kbn-es-query/src/kuery/ast/ast.js b/packages/kbn-es-query/src/kuery/ast/ast.js index aba5d4906046..39a22eb8a77a 100644 --- a/packages/kbn-es-query/src/kuery/ast/ast.js +++ b/packages/kbn-es-query/src/kuery/ast/ast.js @@ -61,3 +61,12 @@ export function toElasticsearchQuery(node, indexPattern) { return nodeTypes[node.type].toElasticsearchQuery(node, indexPattern); } + +export function doesKueryExpressionHaveLuceneSyntaxError(expression) { + try { + fromExpression(expression, { errorOnLuceneSyntax: true }, parseKuery); + return false; + } catch (e) { + return (e.message.startsWith('Lucene')); + } +} diff --git a/packages/kbn-es-query/src/kuery/ast/index.js b/packages/kbn-es-query/src/kuery/ast/index.js index f0e94b59d30e..9d797406420d 100644 --- a/packages/kbn-es-query/src/kuery/ast/index.js +++ b/packages/kbn-es-query/src/kuery/ast/index.js @@ -17,4 +17,4 @@ * under the License. */ -export { fromLegacyKueryExpression, fromKueryExpression, fromLiteralExpression, toElasticsearchQuery } from './ast'; +export * from './ast'; diff --git a/packages/kbn-es-query/src/kuery/ast/kuery.js b/packages/kbn-es-query/src/kuery/ast/kuery.js index b0fb04b66450..c033a9e723be 100644 --- a/packages/kbn-es-query/src/kuery/ast/kuery.js +++ b/packages/kbn-es-query/src/kuery/ast/kuery.js @@ -46,25 +46,26 @@ module.exports = (function() { if (query !== null) return query; return nodeTypes.function.buildNode('is', '*', '*'); }, - peg$c1 = function(left, right) { + peg$c1 = function() { return errorOnLuceneSyntax; }, + peg$c2 = function(left, right) { const cursor = [left, right].find(node => node.type === 'cursor'); if (cursor) return cursor; return buildFunctionNode('or', [left, right]); }, - peg$c2 = function(left, right) { + peg$c3 = function(left, right) { const cursor = [left, right].find(node => node.type === 'cursor'); if (cursor) return cursor; return buildFunctionNode('and', [left, right]); }, - peg$c3 = function(query) { + peg$c4 = function(query) { if (query.type === 'cursor') return query; return buildFunctionNode('not', [query]); }, - peg$c4 = "(", - peg$c5 = { type: "literal", value: "(", description: "\"(\"" }, - peg$c6 = ")", - peg$c7 = { type: "literal", value: ")", description: "\")\"" }, - peg$c8 = function(query, trailing) { + peg$c5 = "(", + peg$c6 = { type: "literal", value: "(", description: "\"(\"" }, + peg$c7 = ")", + peg$c8 = { type: "literal", value: ")", description: "\")\"" }, + peg$c9 = function(query, trailing) { if (trailing.type === 'cursor') { return { ...trailing, @@ -73,7 +74,7 @@ module.exports = (function() { } return query; }, - peg$c9 = function(field, operator, value) { + peg$c10 = function(field, operator, value) { if (value.type === 'cursor') { return { ...value, @@ -83,9 +84,9 @@ module.exports = (function() { const range = buildNamedArgNode(operator, value); return buildFunctionNode('range', [field, range]); }, - peg$c10 = ":", - peg$c11 = { type: "literal", value: ":", description: "\":\"" }, - peg$c12 = function(field, partial) { + peg$c11 = ":", + peg$c12 = { type: "literal", value: ":", description: "\":\"" }, + peg$c13 = function(field, partial) { if (partial.type === 'cursor') { return { ...partial, @@ -95,7 +96,7 @@ module.exports = (function() { } return partial(field); }, - peg$c13 = function(partial) { + peg$c14 = function(partial) { if (partial.type === 'cursor') { const fieldName = `${partial.prefix}${partial.suffix}`.trim(); return { @@ -107,7 +108,7 @@ module.exports = (function() { const field = buildLiteralNode(null); return partial(field); }, - peg$c14 = function(partial, trailing) { + peg$c15 = function(partial, trailing) { if (trailing.type === 'cursor') { return { ...trailing, @@ -116,17 +117,17 @@ module.exports = (function() { } return partial; }, - peg$c15 = function(partialLeft, partialRight) { - const cursor = [partialLeft, partialRight].find(node => node.type === 'cursor'); - if (cursor) { - return { - ...cursor, - suggestionTypes: ['value'] - }; - } - return (field) => buildFunctionNode('or', [partialLeft(field), partialRight(field)]); - }, peg$c16 = function(partialLeft, partialRight) { + const cursor = [partialLeft, partialRight].find(node => node.type === 'cursor'); + if (cursor) { + return { + ...cursor, + suggestionTypes: ['value'] + }; + } + return (field) => buildFunctionNode('or', [partialLeft(field), partialRight(field)]); + }, + peg$c17 = function(partialLeft, partialRight) { const cursor = [partialLeft, partialRight].find(node => node.type === 'cursor'); if (cursor) { return { @@ -136,7 +137,7 @@ module.exports = (function() { } return (field) => buildFunctionNode('and', [partialLeft(field), partialRight(field)]); }, - peg$c17 = function(partial) { + peg$c18 = function(partial) { if (partial.type === 'cursor') { return { ...list, @@ -145,12 +146,12 @@ module.exports = (function() { } return (field) => buildFunctionNode('not', [partial(field)]); }, - peg$c18 = function(value) { + peg$c19 = function(value) { if (value.type === 'cursor') return value; const isPhrase = buildLiteralNode(true); return (field) => buildFunctionNode('is', [field, value, isPhrase]); }, - peg$c19 = function(value) { + peg$c20 = function(value) { if (value.type === 'cursor') return value; if (!allowLeadingWildcards && value.type === 'wildcard' && nodeTypes.wildcard.hasLeadingWildcard(value)) { @@ -160,15 +161,15 @@ module.exports = (function() { const isPhrase = buildLiteralNode(false); return (field) => buildFunctionNode('is', [field, value, isPhrase]); }, - peg$c20 = "or", - peg$c21 = { type: "literal", value: "or", description: "\"or\"" }, - peg$c22 = "and", - peg$c23 = { type: "literal", value: "and", description: "\"and\"" }, - peg$c24 = "not", - peg$c25 = { type: "literal", value: "not", description: "\"not\"" }, - peg$c26 = "\"", - peg$c27 = { type: "literal", value: "\"", description: "\"\\\"\"" }, - peg$c28 = function(prefix, cursor, suffix) { + peg$c21 = "or", + peg$c22 = { type: "literal", value: "or", description: "\"or\"" }, + peg$c23 = "and", + peg$c24 = { type: "literal", value: "and", description: "\"and\"" }, + peg$c25 = "not", + peg$c26 = { type: "literal", value: "not", description: "\"not\"" }, + peg$c27 = "\"", + peg$c28 = { type: "literal", value: "\"", description: "\"\\\"\"" }, + peg$c29 = function(prefix, cursor, suffix) { const { start, end } = location(); return { type: 'cursor', @@ -179,17 +180,17 @@ module.exports = (function() { text: text().replace(cursor, '') }; }, - peg$c29 = function(chars) { + peg$c30 = function(chars) { return buildLiteralNode(chars.join('')); }, - peg$c30 = "\\", - peg$c31 = { type: "literal", value: "\\", description: "\"\\\\\"" }, - peg$c32 = /^[\\"]/, - peg$c33 = { type: "class", value: "[\\\\\"]", description: "[\\\\\"]" }, - peg$c34 = function(char) { return char; }, - peg$c35 = /^[^"]/, - peg$c36 = { type: "class", value: "[^\"]", description: "[^\"]" }, - peg$c37 = function(chars) { + peg$c31 = "\\", + peg$c32 = { type: "literal", value: "\\", description: "\"\\\\\"" }, + peg$c33 = /^[\\"]/, + peg$c34 = { type: "class", value: "[\\\\\"]", description: "[\\\\\"]" }, + peg$c35 = function(char) { return char; }, + peg$c36 = /^[^"]/, + peg$c37 = { type: "class", value: "[^\"]", description: "[^\"]" }, + peg$c38 = function(chars) { const sequence = chars.join('').trim(); if (sequence === 'null') return buildLiteralNode(null); if (sequence === 'true') return buildLiteralNode(true); @@ -199,40 +200,107 @@ module.exports = (function() { const value = isNaN(number) ? sequence : number; return buildLiteralNode(value); }, - peg$c38 = { type: "any", description: "any character" }, - peg$c39 = "*", - peg$c40 = { type: "literal", value: "*", description: "\"*\"" }, - peg$c41 = function() { return wildcardSymbol; }, - peg$c42 = "\\t", - peg$c43 = { type: "literal", value: "\\t", description: "\"\\\\t\"" }, - peg$c44 = function() { return '\t'; }, - peg$c45 = "\\r", - peg$c46 = { type: "literal", value: "\\r", description: "\"\\\\r\"" }, - peg$c47 = function() { return '\r'; }, - peg$c48 = "\\n", - peg$c49 = { type: "literal", value: "\\n", description: "\"\\\\n\"" }, - peg$c50 = function() { return '\n'; }, - peg$c51 = function(keyword) { return keyword; }, - peg$c52 = /^[\\():<>"*]/, - peg$c53 = { type: "class", value: "[\\\\():<>\"*]", description: "[\\\\():<>\"*]" }, - peg$c54 = "<=", - peg$c55 = { type: "literal", value: "<=", description: "\"<=\"" }, - peg$c56 = function() { return 'lte'; }, - peg$c57 = ">=", - peg$c58 = { type: "literal", value: ">=", description: "\">=\"" }, - peg$c59 = function() { return 'gte'; }, - peg$c60 = "<", - peg$c61 = { type: "literal", value: "<", description: "\"<\"" }, - peg$c62 = function() { return 'lt'; }, - peg$c63 = ">", - peg$c64 = { type: "literal", value: ">", description: "\">\"" }, - peg$c65 = function() { return 'gt'; }, - peg$c66 = /^[ \t\r\n]/, - peg$c67 = { type: "class", value: "[\\ \\t\\r\\n]", description: "[\\ \\t\\r\\n]" }, - peg$c68 = function() { return parseCursor; }, - peg$c69 = "@kuery-cursor@", - peg$c70 = { type: "literal", value: "@kuery-cursor@", description: "\"@kuery-cursor@\"" }, - peg$c71 = function() { return cursorSymbol; }, + peg$c39 = { type: "any", description: "any character" }, + peg$c40 = "*", + peg$c41 = { type: "literal", value: "*", description: "\"*\"" }, + peg$c42 = function() { return wildcardSymbol; }, + peg$c43 = "\\t", + peg$c44 = { type: "literal", value: "\\t", description: "\"\\\\t\"" }, + peg$c45 = function() { return '\t'; }, + peg$c46 = "\\r", + peg$c47 = { type: "literal", value: "\\r", description: "\"\\\\r\"" }, + peg$c48 = function() { return '\r'; }, + peg$c49 = "\\n", + peg$c50 = { type: "literal", value: "\\n", description: "\"\\\\n\"" }, + peg$c51 = function() { return '\n'; }, + peg$c52 = function(keyword) { return keyword; }, + peg$c53 = /^[\\():<>"*]/, + peg$c54 = { type: "class", value: "[\\\\():<>\"*]", description: "[\\\\():<>\"*]" }, + peg$c55 = "<=", + peg$c56 = { type: "literal", value: "<=", description: "\"<=\"" }, + peg$c57 = function() { return 'lte'; }, + peg$c58 = ">=", + peg$c59 = { type: "literal", value: ">=", description: "\">=\"" }, + peg$c60 = function() { return 'gte'; }, + peg$c61 = "<", + peg$c62 = { type: "literal", value: "<", description: "\"<\"" }, + peg$c63 = function() { return 'lt'; }, + peg$c64 = ">", + peg$c65 = { type: "literal", value: ">", description: "\">\"" }, + peg$c66 = function() { return 'gt'; }, + peg$c67 = /^[ \t\r\n]/, + peg$c68 = { type: "class", value: "[\\ \\t\\r\\n]", description: "[\\ \\t\\r\\n]" }, + peg$c69 = function() { return parseCursor; }, + peg$c70 = "@kuery-cursor@", + peg$c71 = { type: "literal", value: "@kuery-cursor@", description: "\"@kuery-cursor@\"" }, + peg$c72 = function() { return cursorSymbol; }, + peg$c73 = "||", + peg$c74 = { type: "literal", value: "||", description: "\"||\"" }, + peg$c75 = function() { + error('LuceneOr'); + }, + peg$c76 = "&&", + peg$c77 = { type: "literal", value: "&&", description: "\"&&\"" }, + peg$c78 = function() { + error('LuceneAnd'); + }, + peg$c79 = "+", + peg$c80 = { type: "literal", value: "+", description: "\"+\"" }, + peg$c81 = "-", + peg$c82 = { type: "literal", value: "-", description: "\"-\"" }, + peg$c83 = function() { + error('LuceneNot'); + }, + peg$c84 = "!", + peg$c85 = { type: "literal", value: "!", description: "\"!\"" }, + peg$c86 = "_exists_", + peg$c87 = { type: "literal", value: "_exists_", description: "\"_exists_\"" }, + peg$c88 = function() { + error('LuceneExists'); + }, + peg$c89 = function() { + error('LuceneRange'); + }, + peg$c90 = "?", + peg$c91 = { type: "literal", value: "?", description: "\"?\"" }, + peg$c92 = function() { + error('LuceneWildcard'); + }, + peg$c93 = "/", + peg$c94 = { type: "literal", value: "/", description: "\"/\"" }, + peg$c95 = /^[^\/]/, + peg$c96 = { type: "class", value: "[^/]", description: "[^/]" }, + peg$c97 = function() { + error('LuceneRegex'); + }, + peg$c98 = "~", + peg$c99 = { type: "literal", value: "~", description: "\"~\"" }, + peg$c100 = /^[0-9]/, + peg$c101 = { type: "class", value: "[0-9]", description: "[0-9]" }, + peg$c102 = function() { + error('LuceneFuzzy'); + }, + peg$c103 = function() { + error('LuceneProximity'); + }, + peg$c104 = "^", + peg$c105 = { type: "literal", value: "^", description: "\"^\"" }, + peg$c106 = function() { + error('LuceneBoost'); + }, + peg$c107 = function() { return char; }, + peg$c108 = "=", + peg$c109 = { type: "literal", value: "=", description: "\"=\"" }, + peg$c110 = "{", + peg$c111 = { type: "literal", value: "{", description: "\"{\"" }, + peg$c112 = "}", + peg$c113 = { type: "literal", value: "}", description: "\"}\"" }, + peg$c114 = "[", + peg$c115 = { type: "literal", value: "[", description: "\"[\"" }, + peg$c116 = "]", + peg$c117 = { type: "literal", value: "]", description: "\"]\"" }, + peg$c118 = "TO", + peg$c119 = { type: "literal", value: "TO", description: "\"TO\"" }, peg$currPos = 0, peg$savedPos = 0, @@ -460,19 +528,18 @@ module.exports = (function() { var s0, s1, s2, s3; s0 = peg$currPos; - s1 = peg$parseAndQuery(); + peg$savedPos = peg$currPos; + s1 = peg$c1(); + if (s1) { + s1 = void 0; + } else { + s1 = peg$FAILED; + } if (s1 !== peg$FAILED) { - s2 = peg$parseOr(); + s2 = peg$parseLuceneQuery(); if (s2 !== peg$FAILED) { - s3 = peg$parseOrQuery(); - if (s3 !== peg$FAILED) { - peg$savedPos = s0; - s1 = peg$c1(s1, s3); - s0 = s1; - } else { - peg$currPos = s0; - s0 = peg$FAILED; - } + s1 = [s1, s2]; + s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; @@ -482,7 +549,31 @@ module.exports = (function() { s0 = peg$FAILED; } if (s0 === peg$FAILED) { - s0 = peg$parseAndQuery(); + s0 = peg$currPos; + s1 = peg$parseAndQuery(); + if (s1 !== peg$FAILED) { + s2 = peg$parseOr(); + if (s2 !== peg$FAILED) { + s3 = peg$parseOrQuery(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c2(s1, s3); + s0 = s1; + } 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$parseAndQuery(); + } } return s0; @@ -499,7 +590,7 @@ module.exports = (function() { s3 = peg$parseAndQuery(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c2(s1, s3); + s1 = peg$c3(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -529,7 +620,7 @@ module.exports = (function() { s2 = peg$parseSubQuery(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c3(s2); + s1 = peg$c4(s2); s0 = s1; } else { peg$currPos = s0; @@ -551,11 +642,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { - s1 = peg$c4; + s1 = peg$c5; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c5); } + if (peg$silentFails === 0) { peg$fail(peg$c6); } } if (s1 !== peg$FAILED) { s2 = []; @@ -570,15 +661,15 @@ module.exports = (function() { s4 = peg$parseOptionalSpace(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { - s5 = peg$c6; + s5 = peg$c7; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c7); } + if (peg$silentFails === 0) { peg$fail(peg$c8); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c8(s3, s4); + s1 = peg$c9(s3, s4); s0 = s1; } else { peg$currPos = s0; @@ -643,13 +734,10 @@ module.exports = (function() { s5 = peg$parseSpace(); } if (s4 !== peg$FAILED) { - s5 = peg$parseQuotedString(); - if (s5 === peg$FAILED) { - s5 = peg$parseUnquotedLiteral(); - } + s5 = peg$parseLiteral(); if (s5 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c9(s1, s3, s5); + s1 = peg$c10(s1, s3, s5); s0 = s1; } else { peg$currPos = s0; @@ -689,11 +777,11 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 58) { - s3 = peg$c10; + s3 = peg$c11; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c11); } + if (peg$silentFails === 0) { peg$fail(peg$c12); } } if (s3 !== peg$FAILED) { s4 = []; @@ -706,7 +794,7 @@ module.exports = (function() { s5 = peg$parseListOfValues(); if (s5 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c12(s1, s5); + s1 = peg$c13(s1, s5); s0 = s1; } else { peg$currPos = s0; @@ -739,7 +827,7 @@ module.exports = (function() { s1 = peg$parseValue(); if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c13(s1); + s1 = peg$c14(s1); } s0 = s1; @@ -751,11 +839,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 40) { - s1 = peg$c4; + s1 = peg$c5; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c5); } + if (peg$silentFails === 0) { peg$fail(peg$c6); } } if (s1 !== peg$FAILED) { s2 = []; @@ -770,15 +858,15 @@ module.exports = (function() { s4 = peg$parseOptionalSpace(); if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 41) { - s5 = peg$c6; + s5 = peg$c7; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c7); } + if (peg$silentFails === 0) { peg$fail(peg$c8); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c14(s3, s4); + s1 = peg$c15(s3, s4); s0 = s1; } else { peg$currPos = s0; @@ -818,7 +906,7 @@ module.exports = (function() { s3 = peg$parseOrListOfValues(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c15(s1, s3); + s1 = peg$c16(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -850,7 +938,7 @@ module.exports = (function() { s3 = peg$parseAndListOfValues(); if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c16(s1, s3); + s1 = peg$c17(s1, s3); s0 = s1; } else { peg$currPos = s0; @@ -880,7 +968,7 @@ module.exports = (function() { s2 = peg$parseListOfValues(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c17(s2); + s1 = peg$c18(s2); s0 = s1; } else { peg$currPos = s0; @@ -904,7 +992,7 @@ module.exports = (function() { s1 = peg$parseQuotedString(); if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c18(s1); + s1 = peg$c19(s1); } s0 = s1; if (s0 === peg$FAILED) { @@ -912,7 +1000,7 @@ module.exports = (function() { s1 = peg$parseUnquotedLiteral(); if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c19(s1); + s1 = peg$c20(s1); } s0 = s1; } @@ -935,12 +1023,12 @@ module.exports = (function() { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 2).toLowerCase() === peg$c20) { + if (input.substr(peg$currPos, 2).toLowerCase() === peg$c21) { s2 = input.substr(peg$currPos, 2); peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c21); } + if (peg$silentFails === 0) { peg$fail(peg$c22); } } if (s2 !== peg$FAILED) { s3 = []; @@ -968,6 +1056,29 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$FAILED; } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + peg$savedPos = peg$currPos; + s1 = peg$c1(); + if (s1) { + s1 = void 0; + } else { + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + s2 = peg$parseLuceneOr(); + if (s2 !== peg$FAILED) { + s1 = [s1, s2]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } return s0; } @@ -987,12 +1098,12 @@ module.exports = (function() { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 3).toLowerCase() === peg$c22) { + if (input.substr(peg$currPos, 3).toLowerCase() === peg$c23) { s2 = input.substr(peg$currPos, 3); peg$currPos += 3; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c23); } + if (peg$silentFails === 0) { peg$fail(peg$c24); } } if (s2 !== peg$FAILED) { s3 = []; @@ -1020,6 +1131,29 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$FAILED; } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + peg$savedPos = peg$currPos; + s1 = peg$c1(); + if (s1) { + s1 = void 0; + } else { + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + s2 = peg$parseLuceneAnd(); + if (s2 !== peg$FAILED) { + s1 = [s1, s2]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } return s0; } @@ -1028,12 +1162,12 @@ module.exports = (function() { var s0, s1, s2, s3; s0 = peg$currPos; - if (input.substr(peg$currPos, 3).toLowerCase() === peg$c24) { + if (input.substr(peg$currPos, 3).toLowerCase() === peg$c25) { s1 = input.substr(peg$currPos, 3); peg$currPos += 3; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c25); } + if (peg$silentFails === 0) { peg$fail(peg$c26); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1057,6 +1191,29 @@ module.exports = (function() { peg$currPos = s0; s0 = peg$FAILED; } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + peg$savedPos = peg$currPos; + s1 = peg$c1(); + if (s1) { + s1 = void 0; + } else { + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + s2 = peg$parseLuceneNot(); + if (s2 !== peg$FAILED) { + s1 = [s1, s2]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } return s0; } @@ -1077,11 +1234,11 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c26; + s1 = peg$c27; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c27); } + if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1101,15 +1258,15 @@ module.exports = (function() { } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s5 = peg$c26; + s5 = peg$c27; peg$currPos++; } else { s5 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c27); } + if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s5 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c28(s2, s3, s4); + s1 = peg$c29(s2, s3, s4); s0 = s1; } else { peg$currPos = s0; @@ -1134,11 +1291,11 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 34) { - s1 = peg$c26; + s1 = peg$c27; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c27); } + if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s1 !== peg$FAILED) { s2 = []; @@ -1149,15 +1306,15 @@ module.exports = (function() { } if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 34) { - s3 = peg$c26; + s3 = peg$c27; peg$currPos++; } else { s3 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c27); } + if (peg$silentFails === 0) { peg$fail(peg$c28); } } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c29(s2); + s1 = peg$c30(s2); s0 = s1; } else { peg$currPos = s0; @@ -1183,23 +1340,23 @@ module.exports = (function() { if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c30; + s1 = peg$c31; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c31); } + if (peg$silentFails === 0) { peg$fail(peg$c32); } } if (s1 !== peg$FAILED) { - if (peg$c32.test(input.charAt(peg$currPos))) { + if (peg$c33.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c33); } + if (peg$silentFails === 0) { peg$fail(peg$c34); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c34(s2); + s1 = peg$c35(s2); s0 = s1; } else { peg$currPos = s0; @@ -1222,16 +1379,16 @@ module.exports = (function() { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { - if (peg$c35.test(input.charAt(peg$currPos))) { + if (peg$c36.test(input.charAt(peg$currPos))) { s2 = input.charAt(peg$currPos); peg$currPos++; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c36); } + if (peg$silentFails === 0) { peg$fail(peg$c37); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c34(s2); + s1 = peg$c35(s2); s0 = s1; } else { peg$currPos = s0; @@ -1268,7 +1425,7 @@ module.exports = (function() { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c28(s1, s2, s3); + s1 = peg$c29(s1, s2, s3); s0 = s1; } else { peg$currPos = s0; @@ -1296,7 +1453,7 @@ module.exports = (function() { } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c37(s1); + s1 = peg$c38(s1); } s0 = s1; } @@ -1354,11 +1511,11 @@ module.exports = (function() { peg$currPos++; } else { s4 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c38); } + if (peg$silentFails === 0) { peg$fail(peg$c39); } } if (s4 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c34(s4); + s1 = peg$c35(s4); s0 = s1; } else { peg$currPos = s0; @@ -1389,15 +1546,15 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 42) { - s1 = peg$c39; + s1 = peg$c40; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c40); } + if (peg$silentFails === 0) { peg$fail(peg$c41); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c41(); + s1 = peg$c42(); } s0 = s1; @@ -1425,7 +1582,7 @@ module.exports = (function() { } if (s3 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c28(s1, s2, s3); + s1 = peg$c29(s1, s2, s3); s0 = s1; } else { peg$currPos = s0; @@ -1455,44 +1612,44 @@ module.exports = (function() { var s0, s1; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c42) { - s1 = peg$c42; + if (input.substr(peg$currPos, 2) === peg$c43) { + s1 = peg$c43; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c43); } + if (peg$silentFails === 0) { peg$fail(peg$c44); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c44(); + s1 = peg$c45(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c45) { - s1 = peg$c45; + if (input.substr(peg$currPos, 2) === peg$c46) { + s1 = peg$c46; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c46); } + if (peg$silentFails === 0) { peg$fail(peg$c47); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c47(); + s1 = peg$c48(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c48) { - s1 = peg$c48; + if (input.substr(peg$currPos, 2) === peg$c49) { + s1 = peg$c49; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c49); } + if (peg$silentFails === 0) { peg$fail(peg$c50); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c50(); + s1 = peg$c51(); } s0 = s1; } @@ -1506,17 +1663,17 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c30; + s1 = peg$c31; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c31); } + if (peg$silentFails === 0) { peg$fail(peg$c32); } } if (s1 !== peg$FAILED) { s2 = peg$parseSpecialCharacter(); if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c34(s2); + s1 = peg$c35(s2); s0 = s1; } else { peg$currPos = s0; @@ -1535,41 +1692,41 @@ module.exports = (function() { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 92) { - s1 = peg$c30; + s1 = peg$c31; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c31); } + if (peg$silentFails === 0) { peg$fail(peg$c32); } } if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 2).toLowerCase() === peg$c20) { + if (input.substr(peg$currPos, 2).toLowerCase() === peg$c21) { s2 = input.substr(peg$currPos, 2); peg$currPos += 2; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c21); } + if (peg$silentFails === 0) { peg$fail(peg$c22); } } if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 3).toLowerCase() === peg$c22) { + if (input.substr(peg$currPos, 3).toLowerCase() === peg$c23) { s2 = input.substr(peg$currPos, 3); peg$currPos += 3; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c23); } + if (peg$silentFails === 0) { peg$fail(peg$c24); } } if (s2 === peg$FAILED) { - if (input.substr(peg$currPos, 3).toLowerCase() === peg$c24) { + if (input.substr(peg$currPos, 3).toLowerCase() === peg$c25) { s2 = input.substr(peg$currPos, 3); peg$currPos += 3; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c25); } + if (peg$silentFails === 0) { peg$fail(peg$c26); } } } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c51(s2); + s1 = peg$c52(s2); s0 = s1; } else { peg$currPos = s0; @@ -1600,12 +1757,12 @@ module.exports = (function() { function peg$parseSpecialCharacter() { var s0; - if (peg$c52.test(input.charAt(peg$currPos))) { + if (peg$c53.test(input.charAt(peg$currPos))) { s0 = input.charAt(peg$currPos); peg$currPos++; } else { s0 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c53); } + if (peg$silentFails === 0) { peg$fail(peg$c54); } } return s0; @@ -1615,58 +1772,58 @@ module.exports = (function() { var s0, s1; s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c54) { - s1 = peg$c54; + if (input.substr(peg$currPos, 2) === peg$c55) { + s1 = peg$c55; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c55); } + if (peg$silentFails === 0) { peg$fail(peg$c56); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c56(); + s1 = peg$c57(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; - if (input.substr(peg$currPos, 2) === peg$c57) { - s1 = peg$c57; + if (input.substr(peg$currPos, 2) === peg$c58) { + s1 = peg$c58; peg$currPos += 2; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c58); } + if (peg$silentFails === 0) { peg$fail(peg$c59); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c59(); + s1 = peg$c60(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 60) { - s1 = peg$c60; + s1 = peg$c61; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c61); } + if (peg$silentFails === 0) { peg$fail(peg$c62); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c62(); + s1 = peg$c63(); } s0 = s1; if (s0 === peg$FAILED) { s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 62) { - s1 = peg$c63; + s1 = peg$c64; peg$currPos++; } else { s1 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c64); } + if (peg$silentFails === 0) { peg$fail(peg$c65); } } if (s1 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c65(); + s1 = peg$c66(); } s0 = s1; } @@ -1679,12 +1836,12 @@ module.exports = (function() { function peg$parseSpace() { var s0; - if (peg$c66.test(input.charAt(peg$currPos))) { + 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); } } return s0; @@ -1695,23 +1852,23 @@ module.exports = (function() { s0 = peg$currPos; peg$savedPos = peg$currPos; - s1 = peg$c68(); + s1 = peg$c69(); if (s1) { s1 = void 0; } else { s1 = peg$FAILED; } if (s1 !== peg$FAILED) { - if (input.substr(peg$currPos, 14) === peg$c69) { - s2 = peg$c69; + if (input.substr(peg$currPos, 14) === peg$c70) { + s2 = peg$c70; peg$currPos += 14; } else { s2 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c70); } + if (peg$silentFails === 0) { peg$fail(peg$c71); } } if (s2 !== peg$FAILED) { peg$savedPos = s0; - s1 = peg$c71(); + s1 = peg$c72(); s0 = s1; } else { peg$currPos = s0; @@ -1725,8 +1882,1083 @@ module.exports = (function() { return s0; } + function peg$parseLuceneOr() { + var s0, s1, s2, s3, s4; - const { parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes } } = options; + s0 = peg$currPos; + s1 = []; + s2 = peg$parseSpace(); + while (s2 !== peg$FAILED) { + s1.push(s2); + s2 = peg$parseSpace(); + } + if (s1 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c73) { + s2 = peg$c73; + peg$currPos += 2; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c74); } + } + if (s2 !== peg$FAILED) { + s3 = []; + s4 = peg$parseSpace(); + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parseSpace(); + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c75(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneAnd() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + s1 = []; + s2 = peg$parseSpace(); + while (s2 !== peg$FAILED) { + s1.push(s2); + s2 = peg$parseSpace(); + } + if (s1 !== peg$FAILED) { + if (input.substr(peg$currPos, 2) === peg$c76) { + s2 = peg$c76; + peg$currPos += 2; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c77); } + } + if (s2 !== peg$FAILED) { + s3 = []; + s4 = peg$parseSpace(); + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parseSpace(); + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c78(); + s0 = s1; + } 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) === 43) { + s1 = peg$c79; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c80); } + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c78(); + } + s0 = s1; + } + + return s0; + } + + function peg$parseLuceneNot() { + var s0, s1; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 45) { + s1 = peg$c81; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c82); } + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c83(); + } + s0 = s1; + if (s0 === peg$FAILED) { + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 33) { + s1 = peg$c84; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c85); } + } + if (s1 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c83(); + } + s0 = s1; + } + + return s0; + } + + function peg$parseLuceneQuery() { + var s0; + + s0 = peg$parseLuceneFieldQuery(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneValue(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneExists(); + } + } + + return s0; + } + + function peg$parseLuceneFieldQuery() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + s1 = peg$parseLuceneLiteral(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parseSpace(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseSpace(); + } + if (s2 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 58) { + s3 = peg$c11; + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c12); } + } + if (s3 !== peg$FAILED) { + s4 = []; + s5 = peg$parseSpace(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parseSpace(); + } + if (s4 !== peg$FAILED) { + s5 = peg$parseLuceneValue(); + if (s5 !== peg$FAILED) { + s1 = [s1, s2, s3, s4, s5]; + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneValue() { + var s0; + + s0 = peg$parseLuceneRange(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneWildcard(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneRegex(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneFuzzy(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneProximity(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneBoost(); + } + } + } + } + } + + return s0; + } + + function peg$parseLuceneExists() { + var s0, s1, s2, s3, s4, s5; + + s0 = peg$currPos; + if (input.substr(peg$currPos, 8) === peg$c86) { + s1 = peg$c86; + peg$currPos += 8; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c87); } + } + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parseSpace(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseSpace(); + } + if (s2 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 58) { + s3 = peg$c11; + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c12); } + } + if (s3 !== peg$FAILED) { + s4 = []; + s5 = peg$parseSpace(); + while (s5 !== peg$FAILED) { + s4.push(s5); + s5 = peg$parseSpace(); + } + if (s4 !== peg$FAILED) { + s5 = peg$parseLuceneLiteral(); + if (s5 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c88(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneRange() { + var s0, s1, s2, s3, s4, s5, s6; + + s0 = peg$currPos; + s1 = peg$parseRangeOperator(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parseSpace(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseSpace(); + } + if (s2 !== peg$FAILED) { + s3 = peg$parseLuceneLiteral(); + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c89(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$parseLuceneRangeStart(); + if (s1 !== peg$FAILED) { + s2 = []; + s3 = peg$parseSpace(); + while (s3 !== peg$FAILED) { + s2.push(s3); + s3 = peg$parseSpace(); + } + if (s2 !== peg$FAILED) { + s3 = peg$parseLuceneLiteral(); + if (s3 !== peg$FAILED) { + s4 = peg$parseLuceneTo(); + if (s4 !== peg$FAILED) { + s5 = peg$parseLuceneLiteral(); + if (s5 !== peg$FAILED) { + s6 = peg$parseLuceneRangeEnd(); + if (s6 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c89(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } + + return s0; + } + + function peg$parseLuceneWildcard() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + s1 = []; + s2 = peg$parseLuceneUnquotedCharacter(); + if (s2 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 42) { + s2 = peg$c40; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c41); } + } + } + while (s2 !== peg$FAILED) { + s1.push(s2); + s2 = peg$parseLuceneUnquotedCharacter(); + if (s2 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 42) { + s2 = peg$c40; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c41); } + } + } + } + if (s1 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 63) { + s2 = peg$c90; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c91); } + } + if (s2 !== peg$FAILED) { + s3 = []; + s4 = peg$parseLuceneWildcard(); + while (s4 !== peg$FAILED) { + s3.push(s4); + s4 = peg$parseLuceneWildcard(); + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c92(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneRegex() { + var s0, s1, s2, s3; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 47) { + s1 = peg$c93; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c94); } + } + if (s1 !== peg$FAILED) { + s2 = []; + if (peg$c95.test(input.charAt(peg$currPos))) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c96); } + } + while (s3 !== peg$FAILED) { + s2.push(s3); + if (peg$c95.test(input.charAt(peg$currPos))) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c96); } + } + } + if (s2 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 47) { + s3 = peg$c93; + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c94); } + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c97(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneFuzzy() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + s1 = peg$parseLuceneUnquotedLiteral(); + if (s1 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 126) { + s2 = peg$c98; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c99); } + } + if (s2 !== peg$FAILED) { + s3 = []; + if (peg$c100.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c101); } + } + while (s4 !== peg$FAILED) { + s3.push(s4); + if (peg$c100.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c101); } + } + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c102(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneProximity() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + s1 = peg$parseQuotedString(); + if (s1 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 126) { + s2 = peg$c98; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c99); } + } + if (s2 !== peg$FAILED) { + s3 = []; + if (peg$c100.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c101); } + } + while (s4 !== peg$FAILED) { + s3.push(s4); + if (peg$c100.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c101); } + } + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c103(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneBoost() { + var s0, s1, s2, s3, s4; + + s0 = peg$currPos; + s1 = peg$parseLuceneLiteral(); + if (s1 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 94) { + s2 = peg$c104; + peg$currPos++; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c105); } + } + if (s2 !== peg$FAILED) { + s3 = []; + if (peg$c100.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c101); } + } + while (s4 !== peg$FAILED) { + s3.push(s4); + if (peg$c100.test(input.charAt(peg$currPos))) { + s4 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s4 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c101); } + } + } + if (s3 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c106(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneLiteral() { + var s0; + + s0 = peg$parseQuotedString(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneUnquotedLiteral(); + } + + return s0; + } + + function peg$parseLuceneUnquotedLiteral() { + var s0, s1; + + s0 = []; + s1 = peg$parseLuceneUnquotedCharacter(); + if (s1 !== peg$FAILED) { + while (s1 !== peg$FAILED) { + s0.push(s1); + s1 = peg$parseLuceneUnquotedCharacter(); + } + } else { + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneUnquotedCharacter() { + var s0, s1, s2, s3; + + s0 = peg$parseEscapedWhitespace(); + if (s0 === peg$FAILED) { + s0 = peg$parseEscapedLuceneSpecialCharacter(); + if (s0 === peg$FAILED) { + s0 = peg$currPos; + s1 = peg$currPos; + peg$silentFails++; + s2 = peg$parseLuceneSpecialCharacter(); + peg$silentFails--; + if (s2 === peg$FAILED) { + s1 = void 0; + } else { + peg$currPos = s1; + s1 = peg$FAILED; + } + if (s1 !== peg$FAILED) { + s2 = peg$currPos; + peg$silentFails++; + s3 = peg$parseLuceneKeyword(); + peg$silentFails--; + if (s3 === peg$FAILED) { + s2 = void 0; + } else { + peg$currPos = s2; + s2 = peg$FAILED; + } + if (s2 !== peg$FAILED) { + if (input.length > peg$currPos) { + s3 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s3 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c39); } + } + 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; + } + } + } + + return s0; + } + + function peg$parseLuceneKeyword() { + var s0; + + s0 = peg$parseOr(); + if (s0 === peg$FAILED) { + s0 = peg$parseAnd(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneOr(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneAnd(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneNot(); + if (s0 === peg$FAILED) { + s0 = peg$parseLuceneTo(); + } + } + } + } + } + + return s0; + } + + function peg$parseEscapedLuceneSpecialCharacter() { + var s0, s1, s2; + + s0 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 92) { + s1 = peg$c31; + peg$currPos++; + } else { + s1 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c32); } + } + if (s1 !== peg$FAILED) { + s2 = peg$parseLuceneSpecialCharacter(); + if (s2 !== peg$FAILED) { + peg$savedPos = s0; + s1 = peg$c107(); + s0 = s1; + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + } else { + peg$currPos = s0; + s0 = peg$FAILED; + } + + return s0; + } + + function peg$parseLuceneSpecialCharacter() { + var s0; + + if (input.charCodeAt(peg$currPos) === 43) { + s0 = peg$c79; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c80); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 45) { + s0 = peg$c81; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c82); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 61) { + s0 = peg$c108; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c109); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 62) { + s0 = peg$c64; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c65); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 60) { + s0 = peg$c61; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c62); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 33) { + s0 = peg$c84; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c85); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 40) { + s0 = peg$c5; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c6); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 41) { + s0 = peg$c7; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c8); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 123) { + s0 = peg$c110; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c111); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 125) { + s0 = peg$c112; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c113); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 91) { + s0 = peg$c114; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c115); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 93) { + s0 = peg$c116; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c117); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 94) { + s0 = peg$c104; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c105); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 34) { + s0 = peg$c27; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c28); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 126) { + s0 = peg$c98; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c99); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 42) { + s0 = peg$c40; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c41); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 63) { + s0 = peg$c90; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c91); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 58) { + s0 = peg$c11; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c12); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 92) { + s0 = peg$c31; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c32); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 47) { + s0 = peg$c93; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c94); } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + + return s0; + } + + function peg$parseLuceneTo() { + var s0, s1, s2, s3, s4; + + 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) === peg$c118) { + s2 = peg$c118; + peg$currPos += 2; + } else { + s2 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c119); } + } + 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; + } + + return s0; + } + + function peg$parseLuceneRangeStart() { + var s0; + + if (input.charCodeAt(peg$currPos) === 91) { + s0 = peg$c114; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c115); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 123) { + s0 = peg$c110; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c111); } + } + } + + return s0; + } + + function peg$parseLuceneRangeEnd() { + var s0; + + if (input.charCodeAt(peg$currPos) === 93) { + s0 = peg$c116; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c117); } + } + if (s0 === peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 125) { + s0 = peg$c112; + peg$currPos++; + } else { + s0 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c113); } + } + } + + return s0; + } + + + const { errorOnLuceneSyntax, parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes } } = options; const buildFunctionNode = nodeTypes.function.buildNodeWithArgumentNodes; const buildLiteralNode = nodeTypes.literal.buildNode; const buildWildcardNode = nodeTypes.wildcard.buildNode; diff --git a/packages/kbn-es-query/src/kuery/ast/kuery.peg b/packages/kbn-es-query/src/kuery/ast/kuery.peg index e459e319bc58..311a3099310f 100644 --- a/packages/kbn-es-query/src/kuery/ast/kuery.peg +++ b/packages/kbn-es-query/src/kuery/ast/kuery.peg @@ -5,7 +5,7 @@ // Initialization block { - const { parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes } } = options; + const { errorOnLuceneSyntax, parseCursor, cursorSymbol, allowLeadingWildcards = true, helpers: { nodeTypes } } = options; const buildFunctionNode = nodeTypes.function.buildNodeWithArgumentNodes; const buildLiteralNode = nodeTypes.literal.buildNode; const buildWildcardNode = nodeTypes.wildcard.buildNode; @@ -26,7 +26,8 @@ start } OrQuery - = left:AndQuery Or right:OrQuery { + = &{ return errorOnLuceneSyntax; } LuceneQuery + / left:AndQuery Or right:OrQuery { const cursor = [left, right].find(node => node.type === 'cursor'); if (cursor) return cursor; return buildFunctionNode('or', [left, right]); @@ -66,7 +67,7 @@ Expression / ValueExpression FieldRangeExpression - = field:Literal Space* operator:RangeOperator Space* value:(QuotedString / UnquotedLiteral) { + = field:Literal Space* operator:RangeOperator Space* value:Literal { if (value.type === 'cursor') { return { ...value, @@ -172,12 +173,15 @@ Value Or = Space+ 'or'i Space+ + / &{ return errorOnLuceneSyntax; } LuceneOr And = Space+ 'and'i Space+ + / &{ return errorOnLuceneSyntax; } LuceneAnd Not = 'not'i Space+ + / &{ return errorOnLuceneSyntax; } LuceneNot Literal = QuotedString / UnquotedLiteral @@ -278,3 +282,109 @@ Space Cursor = &{ return parseCursor; } '@kuery-cursor@' { return cursorSymbol; } + +// Temporary error rules (to help users transition from Lucene... should be removed at some point) + +LuceneOr + = Space* '||' Space* { + error('LuceneOr'); + } + +LuceneAnd + = Space* '&&' Space* { + error('LuceneAnd'); + } + / '+' { + error('LuceneAnd'); + } + +LuceneNot + = '-' { + error('LuceneNot'); + } + / '!' { + error('LuceneNot'); + } + +LuceneQuery + = LuceneFieldQuery + / LuceneValue + / LuceneExists + +LuceneFieldQuery + = LuceneLiteral Space* ':' Space* LuceneValue + +LuceneValue + = LuceneRange + / LuceneWildcard + / LuceneRegex + / LuceneFuzzy + / LuceneProximity + / LuceneBoost + +LuceneExists + = '_exists_' Space* ':' Space* LuceneLiteral { + error('LuceneExists'); + } + +LuceneRange + = RangeOperator Space* LuceneLiteral { + error('LuceneRange'); + } + / LuceneRangeStart Space* LuceneLiteral LuceneTo LuceneLiteral LuceneRangeEnd { + error('LuceneRange'); + } + +LuceneWildcard + = (LuceneUnquotedCharacter / '*')* '?' LuceneWildcard* { + error('LuceneWildcard'); + } + +LuceneRegex + = '/' [^/]* '/' { + error('LuceneRegex'); + } + +LuceneFuzzy + = LuceneUnquotedLiteral '~' [0-9]* { + error('LuceneFuzzy'); + } + +LuceneProximity + = QuotedString '~' [0-9]* { + error('LuceneProximity'); + } + +LuceneBoost + = LuceneLiteral '^' [0-9]* { + error('LuceneBoost'); + } + +LuceneLiteral + = QuotedString / LuceneUnquotedLiteral + +LuceneUnquotedLiteral + = LuceneUnquotedCharacter+ + +LuceneUnquotedCharacter + = EscapedWhitespace + / EscapedLuceneSpecialCharacter + / !LuceneSpecialCharacter !LuceneKeyword . + +LuceneKeyword + = Or / And / LuceneOr / LuceneAnd / LuceneNot / LuceneTo + +EscapedLuceneSpecialCharacter + = '\\' LuceneSpecialCharacter { return char; } + +LuceneSpecialCharacter + = '+' / '-' / '=' / '>' / '<' / '!' / '(' / ')' / '{' / '}' / '[' / ']' / '^' / '"' / '~' / '*' / '?' / ':' / '\\' / '/' + +LuceneTo + = Space+ 'TO' Space+ + +LuceneRangeStart + = '[' / '{' + +LuceneRangeEnd + = ']' / '}' diff --git a/src/legacy/ui/public/query_bar/components/query_bar.tsx b/src/legacy/ui/public/query_bar/components/query_bar.tsx index b544d4d3080b..c7d541cca283 100644 --- a/src/legacy/ui/public/query_bar/components/query_bar.tsx +++ b/src/legacy/ui/public/query_bar/components/query_bar.tsx @@ -17,6 +17,7 @@ * under the License. */ +import { doesKueryExpressionHaveLuceneSyntaxError } from '@kbn/es-query'; import { IndexPattern } from 'ui/index_patterns'; import classNames from 'classnames'; @@ -38,12 +39,21 @@ import { matchPairs } from '../lib/match_pairs'; import { QueryLanguageSwitcher } from './language_switcher'; import { SuggestionsComponent } from './typeahead/suggestions_component'; -import { EuiFieldText, EuiFlexGroup, EuiFlexItem, EuiOutsideClickDetector } from '@elastic/eui'; +import { + EuiButton, + EuiFieldText, + EuiFlexGroup, + EuiFlexItem, + EuiLink, + EuiOutsideClickDetector, +} from '@elastic/eui'; // @ts-ignore import { EuiSuperDatePicker, EuiSuperUpdateButton } from '@elastic/eui'; -import { InjectedIntl, injectI18n } from '@kbn/i18n/react'; +import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react'; +import { documentationLinks } from 'ui/documentation_links'; +import { Toast, toastNotifications } from 'ui/notify'; const KEY_CODES = { LEFT: 37, @@ -462,6 +472,8 @@ export class QueryBarUI extends Component { preventDefault(); } + this.handleLuceneSyntaxWarning(); + if (this.persistedLog) { this.persistedLog.add(this.state.query.query); } @@ -683,6 +695,56 @@ export class QueryBarUI extends Component { ); } + + private handleLuceneSyntaxWarning() { + const { intl, store } = this.props; + const { query, language } = this.state.query; + if ( + language === 'kuery' && + !store.get('kibana.luceneSyntaxWarningOptOut') && + doesKueryExpressionHaveLuceneSyntaxError(query) + ) { + const toast = toastNotifications.addWarning({ + title: intl.formatMessage({ + id: 'common.ui.queryBar.luceneSyntaxWarningTitle', + defaultMessage: 'Lucene syntax warning', + }), + text: ( +
+

+ + + + ), + }} + /> +

+ + + this.onLuceneSyntaxWarningOptOut(toast)}> + Don't show again + + + +
+ ), + }); + } + } + + private onLuceneSyntaxWarningOptOut(toast: Toast) { + this.props.store.set('kibana.luceneSyntaxWarningOptOut', true); + toastNotifications.remove(toast); + } } // @ts-ignore