From 9850d29382068f0412059b0c0d68dd30a847b475 Mon Sep 17 00:00:00 2001 From: Aurelien FOUCRET Date: Wed, 18 Sep 2024 15:25:01 +0200 Subject: [PATCH] Generating the base parser from the grammar. --- .../plugin/kql/src/main/antlr/KqlBase.tokens | 18 + .../kql/src/main/antlr/KqlBaseLexer.tokens | 18 + .../xpack/kql/parser/KqlBase.interp | 46 + .../xpack/kql/parser/KqlBaseBaseListener.java | 184 ++++ .../xpack/kql/parser/KqlBaseBaseVisitor.java | 99 ++ .../xpack/kql/parser/KqlBaseLexer.interp | 65 ++ .../xpack/kql/parser/KqlBaseLexer.java | 199 ++++ .../xpack/kql/parser/KqlBaseListener.java | 138 +++ .../xpack/kql/parser/KqlBaseParser.java | 955 ++++++++++++++++++ .../xpack/kql/parser/KqlBaseVisitor.java | 89 ++ 10 files changed, 1811 insertions(+) create mode 100644 x-pack/plugin/kql/src/main/antlr/KqlBase.tokens create mode 100644 x-pack/plugin/kql/src/main/antlr/KqlBaseLexer.tokens create mode 100644 x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBase.interp create mode 100644 x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseBaseListener.java create mode 100644 x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseBaseVisitor.java create mode 100644 x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseLexer.interp create mode 100644 x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseLexer.java create mode 100644 x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseListener.java create mode 100644 x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseParser.java create mode 100644 x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseVisitor.java diff --git a/x-pack/plugin/kql/src/main/antlr/KqlBase.tokens b/x-pack/plugin/kql/src/main/antlr/KqlBase.tokens new file mode 100644 index 0000000000000..3f294034e42c4 --- /dev/null +++ b/x-pack/plugin/kql/src/main/antlr/KqlBase.tokens @@ -0,0 +1,18 @@ +AND=1 +OR=2 +NOT=3 +LEFT_PARENTHESIS=4 +RIGHT_PARENTHESIS=5 +LEFT_CURLY_BRACKET=6 +RIGHT_CURLY_BRACKET=7 +COLON=8 +OP_COMPARE=9 +QUOTED=10 +NUMBER=11 +LITERAL=12 +DEFAULT_SKIP=13 +'('=4 +')'=5 +'{'=6 +'}'=7 +':'=8 diff --git a/x-pack/plugin/kql/src/main/antlr/KqlBaseLexer.tokens b/x-pack/plugin/kql/src/main/antlr/KqlBaseLexer.tokens new file mode 100644 index 0000000000000..3f294034e42c4 --- /dev/null +++ b/x-pack/plugin/kql/src/main/antlr/KqlBaseLexer.tokens @@ -0,0 +1,18 @@ +AND=1 +OR=2 +NOT=3 +LEFT_PARENTHESIS=4 +RIGHT_PARENTHESIS=5 +LEFT_CURLY_BRACKET=6 +RIGHT_CURLY_BRACKET=7 +COLON=8 +OP_COMPARE=9 +QUOTED=10 +NUMBER=11 +LITERAL=12 +DEFAULT_SKIP=13 +'('=4 +')'=5 +'{'=6 +'}'=7 +':'=8 diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBase.interp b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBase.interp new file mode 100644 index 0000000000000..9440bfc48baed --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBase.interp @@ -0,0 +1,46 @@ +token literal names: +null +null +null +null +'(' +')' +'{' +'}' +':' +null +null +null +null +null + +token symbolic names: +null +AND +OR +NOT +LEFT_PARENTHESIS +RIGHT_PARENTHESIS +LEFT_CURLY_BRACKET +RIGHT_CURLY_BRACKET +COLON +OP_COMPARE +QUOTED +NUMBER +LITERAL +DEFAULT_SKIP + +rule names: +topLevelQuery +query +expression +nestedQuery +fieldRangeQuery +fieldMTermQuery +term +groupingExpr +fieldName + + +atn: +[4, 1, 13, 92, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 31, 8, 1, 1, 1, 1, 1, 1, 1, 4, 1, 36, 8, 1, 11, 1, 12, 1, 37, 1, 1, 1, 1, 1, 1, 4, 1, 43, 8, 1, 11, 1, 12, 1, 44, 5, 1, 47, 8, 1, 10, 1, 12, 1, 50, 9, 1, 1, 2, 1, 2, 3, 2, 54, 8, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 3, 5, 69, 8, 5, 1, 5, 4, 5, 72, 8, 5, 11, 5, 12, 5, 73, 1, 5, 3, 5, 77, 8, 5, 1, 6, 1, 6, 1, 7, 1, 7, 4, 7, 83, 8, 7, 11, 7, 12, 7, 84, 1, 7, 3, 7, 88, 8, 7, 1, 8, 1, 8, 1, 8, 0, 1, 2, 9, 0, 2, 4, 6, 8, 10, 12, 14, 16, 0, 1, 1, 0, 10, 12, 95, 0, 18, 1, 0, 0, 0, 2, 30, 1, 0, 0, 0, 4, 53, 1, 0, 0, 0, 6, 55, 1, 0, 0, 0, 8, 61, 1, 0, 0, 0, 10, 68, 1, 0, 0, 0, 12, 78, 1, 0, 0, 0, 14, 80, 1, 0, 0, 0, 16, 89, 1, 0, 0, 0, 18, 19, 3, 2, 1, 0, 19, 20, 5, 0, 0, 1, 20, 1, 1, 0, 0, 0, 21, 22, 6, 1, -1, 0, 22, 23, 5, 3, 0, 0, 23, 31, 3, 2, 1, 4, 24, 31, 3, 6, 3, 0, 25, 31, 3, 4, 2, 0, 26, 27, 5, 4, 0, 0, 27, 28, 3, 2, 1, 0, 28, 29, 5, 5, 0, 0, 29, 31, 1, 0, 0, 0, 30, 21, 1, 0, 0, 0, 30, 24, 1, 0, 0, 0, 30, 25, 1, 0, 0, 0, 30, 26, 1, 0, 0, 0, 31, 48, 1, 0, 0, 0, 32, 35, 10, 6, 0, 0, 33, 34, 5, 2, 0, 0, 34, 36, 3, 2, 1, 0, 35, 33, 1, 0, 0, 0, 36, 37, 1, 0, 0, 0, 37, 35, 1, 0, 0, 0, 37, 38, 1, 0, 0, 0, 38, 47, 1, 0, 0, 0, 39, 42, 10, 5, 0, 0, 40, 41, 5, 1, 0, 0, 41, 43, 3, 2, 1, 0, 42, 40, 1, 0, 0, 0, 43, 44, 1, 0, 0, 0, 44, 42, 1, 0, 0, 0, 44, 45, 1, 0, 0, 0, 45, 47, 1, 0, 0, 0, 46, 32, 1, 0, 0, 0, 46, 39, 1, 0, 0, 0, 47, 50, 1, 0, 0, 0, 48, 46, 1, 0, 0, 0, 48, 49, 1, 0, 0, 0, 49, 3, 1, 0, 0, 0, 50, 48, 1, 0, 0, 0, 51, 54, 3, 10, 5, 0, 52, 54, 3, 8, 4, 0, 53, 51, 1, 0, 0, 0, 53, 52, 1, 0, 0, 0, 54, 5, 1, 0, 0, 0, 55, 56, 3, 16, 8, 0, 56, 57, 5, 8, 0, 0, 57, 58, 5, 6, 0, 0, 58, 59, 3, 2, 1, 0, 59, 60, 5, 7, 0, 0, 60, 7, 1, 0, 0, 0, 61, 62, 3, 16, 8, 0, 62, 63, 5, 9, 0, 0, 63, 64, 3, 12, 6, 0, 64, 9, 1, 0, 0, 0, 65, 66, 3, 16, 8, 0, 66, 67, 5, 8, 0, 0, 67, 69, 1, 0, 0, 0, 68, 65, 1, 0, 0, 0, 68, 69, 1, 0, 0, 0, 69, 76, 1, 0, 0, 0, 70, 72, 3, 12, 6, 0, 71, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 77, 1, 0, 0, 0, 75, 77, 3, 14, 7, 0, 76, 71, 1, 0, 0, 0, 76, 75, 1, 0, 0, 0, 77, 11, 1, 0, 0, 0, 78, 79, 7, 0, 0, 0, 79, 13, 1, 0, 0, 0, 80, 82, 5, 4, 0, 0, 81, 83, 3, 12, 6, 0, 82, 81, 1, 0, 0, 0, 83, 84, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 84, 85, 1, 0, 0, 0, 85, 87, 1, 0, 0, 0, 86, 88, 5, 5, 0, 0, 87, 86, 1, 0, 0, 0, 87, 88, 1, 0, 0, 0, 88, 15, 1, 0, 0, 0, 89, 90, 5, 12, 0, 0, 90, 17, 1, 0, 0, 0, 11, 30, 37, 44, 46, 48, 53, 68, 73, 76, 84, 87] \ No newline at end of file diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseBaseListener.java b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseBaseListener.java new file mode 100644 index 0000000000000..774e971eb5ca6 --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseBaseListener.java @@ -0,0 +1,184 @@ +// ANTLR GENERATED CODE: DO NOT EDIT +package org.elasticsearch.xpack.kql.parser; + +import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.tree.ErrorNode; +import org.antlr.v4.runtime.tree.TerminalNode; + +/** + * This class provides an empty implementation of {@link KqlBaseListener}, + * which can be extended to create a listener which only needs to handle a subset + * of the available methods. + */ +@SuppressWarnings("CheckReturnValue") +class KqlBaseBaseListener implements KqlBaseListener { + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterTopLevelQuery(KqlBaseParser.TopLevelQueryContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitTopLevelQuery(KqlBaseParser.TopLevelQueryContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterLogicalNot(KqlBaseParser.LogicalNotContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitLogicalNot(KqlBaseParser.LogicalNotContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterQueryDefault(KqlBaseParser.QueryDefaultContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitQueryDefault(KqlBaseParser.QueryDefaultContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterLogicalAnd(KqlBaseParser.LogicalAndContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitLogicalAnd(KqlBaseParser.LogicalAndContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterLogicalOr(KqlBaseParser.LogicalOrContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitLogicalOr(KqlBaseParser.LogicalOrContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterExpression(KqlBaseParser.ExpressionContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitExpression(KqlBaseParser.ExpressionContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterNestedQuery(KqlBaseParser.NestedQueryContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitNestedQuery(KqlBaseParser.NestedQueryContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterFieldRangeQuery(KqlBaseParser.FieldRangeQueryContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitFieldRangeQuery(KqlBaseParser.FieldRangeQueryContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterFieldMTermQuery(KqlBaseParser.FieldMTermQueryContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitFieldMTermQuery(KqlBaseParser.FieldMTermQueryContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterTerm(KqlBaseParser.TermContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitTerm(KqlBaseParser.TermContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterGroupingExpr(KqlBaseParser.GroupingExprContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitGroupingExpr(KqlBaseParser.GroupingExprContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterFieldName(KqlBaseParser.FieldNameContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitFieldName(KqlBaseParser.FieldNameContext ctx) { } + + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void enterEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void exitEveryRule(ParserRuleContext ctx) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void visitTerminal(TerminalNode node) { } + /** + * {@inheritDoc} + * + *

The default implementation does nothing.

+ */ + @Override public void visitErrorNode(ErrorNode node) { } +} diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseBaseVisitor.java b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseBaseVisitor.java new file mode 100644 index 0000000000000..b30abaff3ab51 --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseBaseVisitor.java @@ -0,0 +1,99 @@ +// ANTLR GENERATED CODE: DO NOT EDIT +package org.elasticsearch.xpack.kql.parser; +import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; + +/** + * This class provides an empty implementation of {@link KqlBaseVisitor}, + * which can be extended to create a visitor which only needs to handle a subset + * of the available methods. + * + * @param The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +@SuppressWarnings("CheckReturnValue") +class KqlBaseBaseVisitor extends AbstractParseTreeVisitor implements KqlBaseVisitor { + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitTopLevelQuery(KqlBaseParser.TopLevelQueryContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitLogicalNot(KqlBaseParser.LogicalNotContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitQueryDefault(KqlBaseParser.QueryDefaultContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitLogicalAnd(KqlBaseParser.LogicalAndContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitLogicalOr(KqlBaseParser.LogicalOrContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitExpression(KqlBaseParser.ExpressionContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitNestedQuery(KqlBaseParser.NestedQueryContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitFieldRangeQuery(KqlBaseParser.FieldRangeQueryContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitFieldMTermQuery(KqlBaseParser.FieldMTermQueryContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitTerm(KqlBaseParser.TermContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitGroupingExpr(KqlBaseParser.GroupingExprContext ctx) { return visitChildren(ctx); } + /** + * {@inheritDoc} + * + *

The default implementation returns the result of calling + * {@link #visitChildren} on {@code ctx}.

+ */ + @Override public T visitFieldName(KqlBaseParser.FieldNameContext ctx) { return visitChildren(ctx); } +} diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseLexer.interp b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseLexer.interp new file mode 100644 index 0000000000000..506834def5846 --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseLexer.interp @@ -0,0 +1,65 @@ +token literal names: +null +null +null +null +'(' +')' +'{' +'}' +':' +null +null +null +null +null + +token symbolic names: +null +AND +OR +NOT +LEFT_PARENTHESIS +RIGHT_PARENTHESIS +LEFT_CURLY_BRACKET +RIGHT_CURLY_BRACKET +COLON +OP_COMPARE +QUOTED +NUMBER +LITERAL +DEFAULT_SKIP + +rule names: +AND +OR +NOT +LEFT_PARENTHESIS +RIGHT_PARENTHESIS +LEFT_CURLY_BRACKET +RIGHT_CURLY_BRACKET +COLON +OP_LESS +OP_LESS_EQ +OP_MORE +OP_MORE_EQ +OP_COMPARE +QUOTED +NUMBER +LITERAL +QUOTED_CHAR +ESCAPED_CHAR +NUM_CHAR +TERM_CHAR +DEFAULT_SKIP +WHITESPACE + +channel names: +DEFAULT_TOKEN_CHANNEL +HIDDEN + +mode names: +DEFAULT_MODE + +atn: +[4, 0, 13, 133, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 54, 8, 1, 1, 2, 1, 2, 1, 2, 1, 2, 3, 2, 60, 8, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 1, 12, 3, 12, 86, 8, 12, 1, 13, 1, 13, 5, 13, 90, 8, 13, 10, 13, 12, 13, 93, 9, 13, 1, 13, 1, 13, 1, 14, 4, 14, 98, 8, 14, 11, 14, 12, 14, 99, 1, 14, 1, 14, 4, 14, 104, 8, 14, 11, 14, 12, 14, 105, 3, 14, 108, 8, 14, 1, 15, 4, 15, 111, 8, 15, 11, 15, 12, 15, 112, 1, 16, 1, 16, 3, 16, 117, 8, 16, 1, 17, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 3, 19, 126, 8, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 0, 0, 22, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 0, 19, 0, 21, 0, 23, 0, 25, 9, 27, 10, 29, 11, 31, 12, 33, 0, 35, 0, 37, 0, 39, 0, 41, 13, 43, 0, 1, 0, 7, 2, 0, 65, 65, 97, 97, 2, 0, 78, 78, 110, 110, 2, 0, 68, 68, 100, 100, 2, 0, 34, 34, 92, 92, 1, 0, 48, 57, 13, 0, 9, 10, 13, 13, 32, 32, 34, 34, 40, 41, 47, 47, 58, 58, 60, 60, 62, 62, 92, 92, 123, 123, 125, 125, 12288, 12288, 4, 0, 9, 10, 13, 13, 32, 32, 12288, 12288, 135, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 1, 45, 1, 0, 0, 0, 3, 53, 1, 0, 0, 0, 5, 59, 1, 0, 0, 0, 7, 61, 1, 0, 0, 0, 9, 63, 1, 0, 0, 0, 11, 65, 1, 0, 0, 0, 13, 67, 1, 0, 0, 0, 15, 69, 1, 0, 0, 0, 17, 71, 1, 0, 0, 0, 19, 73, 1, 0, 0, 0, 21, 76, 1, 0, 0, 0, 23, 78, 1, 0, 0, 0, 25, 85, 1, 0, 0, 0, 27, 87, 1, 0, 0, 0, 29, 97, 1, 0, 0, 0, 31, 110, 1, 0, 0, 0, 33, 116, 1, 0, 0, 0, 35, 118, 1, 0, 0, 0, 37, 121, 1, 0, 0, 0, 39, 125, 1, 0, 0, 0, 41, 127, 1, 0, 0, 0, 43, 131, 1, 0, 0, 0, 45, 46, 7, 0, 0, 0, 46, 47, 7, 1, 0, 0, 47, 48, 7, 2, 0, 0, 48, 2, 1, 0, 0, 0, 49, 50, 5, 79, 0, 0, 50, 54, 5, 82, 0, 0, 51, 52, 5, 124, 0, 0, 52, 54, 5, 124, 0, 0, 53, 49, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 54, 4, 1, 0, 0, 0, 55, 56, 5, 78, 0, 0, 56, 57, 5, 79, 0, 0, 57, 60, 5, 84, 0, 0, 58, 60, 5, 33, 0, 0, 59, 55, 1, 0, 0, 0, 59, 58, 1, 0, 0, 0, 60, 6, 1, 0, 0, 0, 61, 62, 5, 40, 0, 0, 62, 8, 1, 0, 0, 0, 63, 64, 5, 41, 0, 0, 64, 10, 1, 0, 0, 0, 65, 66, 5, 123, 0, 0, 66, 12, 1, 0, 0, 0, 67, 68, 5, 125, 0, 0, 68, 14, 1, 0, 0, 0, 69, 70, 5, 58, 0, 0, 70, 16, 1, 0, 0, 0, 71, 72, 5, 60, 0, 0, 72, 18, 1, 0, 0, 0, 73, 74, 5, 60, 0, 0, 74, 75, 5, 61, 0, 0, 75, 20, 1, 0, 0, 0, 76, 77, 5, 62, 0, 0, 77, 22, 1, 0, 0, 0, 78, 79, 5, 62, 0, 0, 79, 80, 5, 61, 0, 0, 80, 24, 1, 0, 0, 0, 81, 86, 3, 17, 8, 0, 82, 86, 3, 21, 10, 0, 83, 86, 3, 19, 9, 0, 84, 86, 3, 23, 11, 0, 85, 81, 1, 0, 0, 0, 85, 82, 1, 0, 0, 0, 85, 83, 1, 0, 0, 0, 85, 84, 1, 0, 0, 0, 86, 26, 1, 0, 0, 0, 87, 91, 5, 34, 0, 0, 88, 90, 3, 33, 16, 0, 89, 88, 1, 0, 0, 0, 90, 93, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 91, 92, 1, 0, 0, 0, 92, 94, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 94, 95, 5, 34, 0, 0, 95, 28, 1, 0, 0, 0, 96, 98, 3, 37, 18, 0, 97, 96, 1, 0, 0, 0, 98, 99, 1, 0, 0, 0, 99, 97, 1, 0, 0, 0, 99, 100, 1, 0, 0, 0, 100, 107, 1, 0, 0, 0, 101, 103, 5, 46, 0, 0, 102, 104, 3, 37, 18, 0, 103, 102, 1, 0, 0, 0, 104, 105, 1, 0, 0, 0, 105, 103, 1, 0, 0, 0, 105, 106, 1, 0, 0, 0, 106, 108, 1, 0, 0, 0, 107, 101, 1, 0, 0, 0, 107, 108, 1, 0, 0, 0, 108, 30, 1, 0, 0, 0, 109, 111, 3, 39, 19, 0, 110, 109, 1, 0, 0, 0, 111, 112, 1, 0, 0, 0, 112, 110, 1, 0, 0, 0, 112, 113, 1, 0, 0, 0, 113, 32, 1, 0, 0, 0, 114, 117, 8, 3, 0, 0, 115, 117, 3, 35, 17, 0, 116, 114, 1, 0, 0, 0, 116, 115, 1, 0, 0, 0, 117, 34, 1, 0, 0, 0, 118, 119, 5, 92, 0, 0, 119, 120, 9, 0, 0, 0, 120, 36, 1, 0, 0, 0, 121, 122, 7, 4, 0, 0, 122, 38, 1, 0, 0, 0, 123, 126, 8, 5, 0, 0, 124, 126, 3, 35, 17, 0, 125, 123, 1, 0, 0, 0, 125, 124, 1, 0, 0, 0, 126, 40, 1, 0, 0, 0, 127, 128, 3, 43, 21, 0, 128, 129, 1, 0, 0, 0, 129, 130, 6, 20, 0, 0, 130, 42, 1, 0, 0, 0, 131, 132, 7, 6, 0, 0, 132, 44, 1, 0, 0, 0, 11, 0, 53, 59, 85, 91, 99, 105, 107, 112, 116, 125, 1, 6, 0, 0] \ No newline at end of file diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseLexer.java b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseLexer.java new file mode 100644 index 0000000000000..69d85a75599ed --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseLexer.java @@ -0,0 +1,199 @@ +// ANTLR GENERATED CODE: DO NOT EDIT +package org.elasticsearch.xpack.kql.parser; +import org.antlr.v4.runtime.Lexer; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.TokenStream; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.misc.*; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"}) +class KqlBaseLexer extends Lexer { + static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + AND=1, OR=2, NOT=3, LEFT_PARENTHESIS=4, RIGHT_PARENTHESIS=5, LEFT_CURLY_BRACKET=6, + RIGHT_CURLY_BRACKET=7, COLON=8, OP_COMPARE=9, QUOTED=10, NUMBER=11, LITERAL=12, + DEFAULT_SKIP=13; + public static String[] channelNames = { + "DEFAULT_TOKEN_CHANNEL", "HIDDEN" + }; + + public static String[] modeNames = { + "DEFAULT_MODE" + }; + + private static String[] makeRuleNames() { + return new String[] { + "AND", "OR", "NOT", "LEFT_PARENTHESIS", "RIGHT_PARENTHESIS", "LEFT_CURLY_BRACKET", + "RIGHT_CURLY_BRACKET", "COLON", "OP_LESS", "OP_LESS_EQ", "OP_MORE", "OP_MORE_EQ", + "OP_COMPARE", "QUOTED", "NUMBER", "LITERAL", "QUOTED_CHAR", "ESCAPED_CHAR", + "NUM_CHAR", "TERM_CHAR", "DEFAULT_SKIP", "WHITESPACE" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, null, null, null, "'('", "')'", "'{'", "'}'", "':'" + }; + } + private static final String[] _LITERAL_NAMES = makeLiteralNames(); + private static String[] makeSymbolicNames() { + return new String[] { + null, "AND", "OR", "NOT", "LEFT_PARENTHESIS", "RIGHT_PARENTHESIS", "LEFT_CURLY_BRACKET", + "RIGHT_CURLY_BRACKET", "COLON", "OP_COMPARE", "QUOTED", "NUMBER", "LITERAL", + "DEFAULT_SKIP" + }; + } + private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = ""; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + + public KqlBaseLexer(CharStream input) { + super(input); + _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @Override + public String getGrammarFileName() { return "KqlBase.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public String[] getChannelNames() { return channelNames; } + + @Override + public String[] getModeNames() { return modeNames; } + + @Override + public ATN getATN() { return _ATN; } + + public static final String _serializedATN = + "\u0004\u0000\r\u0085\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+ + "\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+ + "\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+ + "\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+ + "\u0007\u000b\u0002\f\u0007\f\u0002\r\u0007\r\u0002\u000e\u0007\u000e\u0002"+ + "\u000f\u0007\u000f\u0002\u0010\u0007\u0010\u0002\u0011\u0007\u0011\u0002"+ + "\u0012\u0007\u0012\u0002\u0013\u0007\u0013\u0002\u0014\u0007\u0014\u0002"+ + "\u0015\u0007\u0015\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001"+ + "\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0003\u00016\b\u0001\u0001"+ + "\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0003\u0002<\b\u0002\u0001"+ + "\u0003\u0001\u0003\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0001"+ + "\u0006\u0001\u0006\u0001\u0007\u0001\u0007\u0001\b\u0001\b\u0001\t\u0001"+ + "\t\u0001\t\u0001\n\u0001\n\u0001\u000b\u0001\u000b\u0001\u000b\u0001\f"+ + "\u0001\f\u0001\f\u0001\f\u0003\fV\b\f\u0001\r\u0001\r\u0005\rZ\b\r\n\r"+ + "\f\r]\t\r\u0001\r\u0001\r\u0001\u000e\u0004\u000eb\b\u000e\u000b\u000e"+ + "\f\u000ec\u0001\u000e\u0001\u000e\u0004\u000eh\b\u000e\u000b\u000e\f\u000e"+ + "i\u0003\u000el\b\u000e\u0001\u000f\u0004\u000fo\b\u000f\u000b\u000f\f"+ + "\u000fp\u0001\u0010\u0001\u0010\u0003\u0010u\b\u0010\u0001\u0011\u0001"+ + "\u0011\u0001\u0011\u0001\u0012\u0001\u0012\u0001\u0013\u0001\u0013\u0003"+ + "\u0013~\b\u0013\u0001\u0014\u0001\u0014\u0001\u0014\u0001\u0014\u0001"+ + "\u0015\u0001\u0015\u0000\u0000\u0016\u0001\u0001\u0003\u0002\u0005\u0003"+ + "\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f\b\u0011\u0000\u0013\u0000"+ + "\u0015\u0000\u0017\u0000\u0019\t\u001b\n\u001d\u000b\u001f\f!\u0000#\u0000"+ + "%\u0000\'\u0000)\r+\u0000\u0001\u0000\u0007\u0002\u0000AAaa\u0002\u0000"+ + "NNnn\u0002\u0000DDdd\u0002\u0000\"\"\\\\\u0001\u000009\r\u0000\t\n\r\r"+ + " \"\"()//::<<>>\\\\{{}}\u3000\u3000\u0004\u0000\t\n\r\r \u3000\u3000"+ + "\u0087\u0000\u0001\u0001\u0000\u0000\u0000\u0000\u0003\u0001\u0000\u0000"+ + "\u0000\u0000\u0005\u0001\u0000\u0000\u0000\u0000\u0007\u0001\u0000\u0000"+ + "\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000\u000b\u0001\u0000\u0000\u0000"+ + "\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f\u0001\u0000\u0000\u0000\u0000"+ + "\u0019\u0001\u0000\u0000\u0000\u0000\u001b\u0001\u0000\u0000\u0000\u0000"+ + "\u001d\u0001\u0000\u0000\u0000\u0000\u001f\u0001\u0000\u0000\u0000\u0000"+ + ")\u0001\u0000\u0000\u0000\u0001-\u0001\u0000\u0000\u0000\u00035\u0001"+ + "\u0000\u0000\u0000\u0005;\u0001\u0000\u0000\u0000\u0007=\u0001\u0000\u0000"+ + "\u0000\t?\u0001\u0000\u0000\u0000\u000bA\u0001\u0000\u0000\u0000\rC\u0001"+ + "\u0000\u0000\u0000\u000fE\u0001\u0000\u0000\u0000\u0011G\u0001\u0000\u0000"+ + "\u0000\u0013I\u0001\u0000\u0000\u0000\u0015L\u0001\u0000\u0000\u0000\u0017"+ + "N\u0001\u0000\u0000\u0000\u0019U\u0001\u0000\u0000\u0000\u001bW\u0001"+ + "\u0000\u0000\u0000\u001da\u0001\u0000\u0000\u0000\u001fn\u0001\u0000\u0000"+ + "\u0000!t\u0001\u0000\u0000\u0000#v\u0001\u0000\u0000\u0000%y\u0001\u0000"+ + "\u0000\u0000\'}\u0001\u0000\u0000\u0000)\u007f\u0001\u0000\u0000\u0000"+ + "+\u0083\u0001\u0000\u0000\u0000-.\u0007\u0000\u0000\u0000./\u0007\u0001"+ + "\u0000\u0000/0\u0007\u0002\u0000\u00000\u0002\u0001\u0000\u0000\u0000"+ + "12\u0005O\u0000\u000026\u0005R\u0000\u000034\u0005|\u0000\u000046\u0005"+ + "|\u0000\u000051\u0001\u0000\u0000\u000053\u0001\u0000\u0000\u00006\u0004"+ + "\u0001\u0000\u0000\u000078\u0005N\u0000\u000089\u0005O\u0000\u00009<\u0005"+ + "T\u0000\u0000:<\u0005!\u0000\u0000;7\u0001\u0000\u0000\u0000;:\u0001\u0000"+ + "\u0000\u0000<\u0006\u0001\u0000\u0000\u0000=>\u0005(\u0000\u0000>\b\u0001"+ + "\u0000\u0000\u0000?@\u0005)\u0000\u0000@\n\u0001\u0000\u0000\u0000AB\u0005"+ + "{\u0000\u0000B\f\u0001\u0000\u0000\u0000CD\u0005}\u0000\u0000D\u000e\u0001"+ + "\u0000\u0000\u0000EF\u0005:\u0000\u0000F\u0010\u0001\u0000\u0000\u0000"+ + "GH\u0005<\u0000\u0000H\u0012\u0001\u0000\u0000\u0000IJ\u0005<\u0000\u0000"+ + "JK\u0005=\u0000\u0000K\u0014\u0001\u0000\u0000\u0000LM\u0005>\u0000\u0000"+ + "M\u0016\u0001\u0000\u0000\u0000NO\u0005>\u0000\u0000OP\u0005=\u0000\u0000"+ + "P\u0018\u0001\u0000\u0000\u0000QV\u0003\u0011\b\u0000RV\u0003\u0015\n"+ + "\u0000SV\u0003\u0013\t\u0000TV\u0003\u0017\u000b\u0000UQ\u0001\u0000\u0000"+ + "\u0000UR\u0001\u0000\u0000\u0000US\u0001\u0000\u0000\u0000UT\u0001\u0000"+ + "\u0000\u0000V\u001a\u0001\u0000\u0000\u0000W[\u0005\"\u0000\u0000XZ\u0003"+ + "!\u0010\u0000YX\u0001\u0000\u0000\u0000Z]\u0001\u0000\u0000\u0000[Y\u0001"+ + "\u0000\u0000\u0000[\\\u0001\u0000\u0000\u0000\\^\u0001\u0000\u0000\u0000"+ + "][\u0001\u0000\u0000\u0000^_\u0005\"\u0000\u0000_\u001c\u0001\u0000\u0000"+ + "\u0000`b\u0003%\u0012\u0000a`\u0001\u0000\u0000\u0000bc\u0001\u0000\u0000"+ + "\u0000ca\u0001\u0000\u0000\u0000cd\u0001\u0000\u0000\u0000dk\u0001\u0000"+ + "\u0000\u0000eg\u0005.\u0000\u0000fh\u0003%\u0012\u0000gf\u0001\u0000\u0000"+ + "\u0000hi\u0001\u0000\u0000\u0000ig\u0001\u0000\u0000\u0000ij\u0001\u0000"+ + "\u0000\u0000jl\u0001\u0000\u0000\u0000ke\u0001\u0000\u0000\u0000kl\u0001"+ + "\u0000\u0000\u0000l\u001e\u0001\u0000\u0000\u0000mo\u0003\'\u0013\u0000"+ + "nm\u0001\u0000\u0000\u0000op\u0001\u0000\u0000\u0000pn\u0001\u0000\u0000"+ + "\u0000pq\u0001\u0000\u0000\u0000q \u0001\u0000\u0000\u0000ru\b\u0003\u0000"+ + "\u0000su\u0003#\u0011\u0000tr\u0001\u0000\u0000\u0000ts\u0001\u0000\u0000"+ + "\u0000u\"\u0001\u0000\u0000\u0000vw\u0005\\\u0000\u0000wx\t\u0000\u0000"+ + "\u0000x$\u0001\u0000\u0000\u0000yz\u0007\u0004\u0000\u0000z&\u0001\u0000"+ + "\u0000\u0000{~\b\u0005\u0000\u0000|~\u0003#\u0011\u0000}{\u0001\u0000"+ + "\u0000\u0000}|\u0001\u0000\u0000\u0000~(\u0001\u0000\u0000\u0000\u007f"+ + "\u0080\u0003+\u0015\u0000\u0080\u0081\u0001\u0000\u0000\u0000\u0081\u0082"+ + "\u0006\u0014\u0000\u0000\u0082*\u0001\u0000\u0000\u0000\u0083\u0084\u0007"+ + "\u0006\u0000\u0000\u0084,\u0001\u0000\u0000\u0000\u000b\u00005;U[cikp"+ + "t}\u0001\u0006\u0000\u0000"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +} diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseListener.java b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseListener.java new file mode 100644 index 0000000000000..059fada6e9793 --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseListener.java @@ -0,0 +1,138 @@ +// ANTLR GENERATED CODE: DO NOT EDIT +package org.elasticsearch.xpack.kql.parser; +import org.antlr.v4.runtime.tree.ParseTreeListener; + +/** + * This interface defines a complete listener for a parse tree produced by + * {@link KqlBaseParser}. + */ +interface KqlBaseListener extends ParseTreeListener { + /** + * Enter a parse tree produced by {@link KqlBaseParser#topLevelQuery}. + * @param ctx the parse tree + */ + void enterTopLevelQuery(KqlBaseParser.TopLevelQueryContext ctx); + /** + * Exit a parse tree produced by {@link KqlBaseParser#topLevelQuery}. + * @param ctx the parse tree + */ + void exitTopLevelQuery(KqlBaseParser.TopLevelQueryContext ctx); + /** + * Enter a parse tree produced by the {@code logicalNot} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + */ + void enterLogicalNot(KqlBaseParser.LogicalNotContext ctx); + /** + * Exit a parse tree produced by the {@code logicalNot} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + */ + void exitLogicalNot(KqlBaseParser.LogicalNotContext ctx); + /** + * Enter a parse tree produced by the {@code queryDefault} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + */ + void enterQueryDefault(KqlBaseParser.QueryDefaultContext ctx); + /** + * Exit a parse tree produced by the {@code queryDefault} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + */ + void exitQueryDefault(KqlBaseParser.QueryDefaultContext ctx); + /** + * Enter a parse tree produced by the {@code logicalAnd} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + */ + void enterLogicalAnd(KqlBaseParser.LogicalAndContext ctx); + /** + * Exit a parse tree produced by the {@code logicalAnd} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + */ + void exitLogicalAnd(KqlBaseParser.LogicalAndContext ctx); + /** + * Enter a parse tree produced by the {@code logicalOr} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + */ + void enterLogicalOr(KqlBaseParser.LogicalOrContext ctx); + /** + * Exit a parse tree produced by the {@code logicalOr} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + */ + void exitLogicalOr(KqlBaseParser.LogicalOrContext ctx); + /** + * Enter a parse tree produced by {@link KqlBaseParser#expression}. + * @param ctx the parse tree + */ + void enterExpression(KqlBaseParser.ExpressionContext ctx); + /** + * Exit a parse tree produced by {@link KqlBaseParser#expression}. + * @param ctx the parse tree + */ + void exitExpression(KqlBaseParser.ExpressionContext ctx); + /** + * Enter a parse tree produced by {@link KqlBaseParser#nestedQuery}. + * @param ctx the parse tree + */ + void enterNestedQuery(KqlBaseParser.NestedQueryContext ctx); + /** + * Exit a parse tree produced by {@link KqlBaseParser#nestedQuery}. + * @param ctx the parse tree + */ + void exitNestedQuery(KqlBaseParser.NestedQueryContext ctx); + /** + * Enter a parse tree produced by {@link KqlBaseParser#fieldRangeQuery}. + * @param ctx the parse tree + */ + void enterFieldRangeQuery(KqlBaseParser.FieldRangeQueryContext ctx); + /** + * Exit a parse tree produced by {@link KqlBaseParser#fieldRangeQuery}. + * @param ctx the parse tree + */ + void exitFieldRangeQuery(KqlBaseParser.FieldRangeQueryContext ctx); + /** + * Enter a parse tree produced by {@link KqlBaseParser#fieldMTermQuery}. + * @param ctx the parse tree + */ + void enterFieldMTermQuery(KqlBaseParser.FieldMTermQueryContext ctx); + /** + * Exit a parse tree produced by {@link KqlBaseParser#fieldMTermQuery}. + * @param ctx the parse tree + */ + void exitFieldMTermQuery(KqlBaseParser.FieldMTermQueryContext ctx); + /** + * Enter a parse tree produced by {@link KqlBaseParser#term}. + * @param ctx the parse tree + */ + void enterTerm(KqlBaseParser.TermContext ctx); + /** + * Exit a parse tree produced by {@link KqlBaseParser#term}. + * @param ctx the parse tree + */ + void exitTerm(KqlBaseParser.TermContext ctx); + /** + * Enter a parse tree produced by {@link KqlBaseParser#groupingExpr}. + * @param ctx the parse tree + */ + void enterGroupingExpr(KqlBaseParser.GroupingExprContext ctx); + /** + * Exit a parse tree produced by {@link KqlBaseParser#groupingExpr}. + * @param ctx the parse tree + */ + void exitGroupingExpr(KqlBaseParser.GroupingExprContext ctx); + /** + * Enter a parse tree produced by {@link KqlBaseParser#fieldName}. + * @param ctx the parse tree + */ + void enterFieldName(KqlBaseParser.FieldNameContext ctx); + /** + * Exit a parse tree produced by {@link KqlBaseParser#fieldName}. + * @param ctx the parse tree + */ + void exitFieldName(KqlBaseParser.FieldNameContext ctx); +} diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseParser.java b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseParser.java new file mode 100644 index 0000000000000..69973549325c0 --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseParser.java @@ -0,0 +1,955 @@ +// ANTLR GENERATED CODE: DO NOT EDIT +package org.elasticsearch.xpack.kql.parser; +import org.antlr.v4.runtime.atn.*; +import org.antlr.v4.runtime.dfa.DFA; +import org.antlr.v4.runtime.*; +import org.antlr.v4.runtime.misc.*; +import org.antlr.v4.runtime.tree.*; +import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; + +@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) +class KqlBaseParser extends Parser { + static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); } + + protected static final DFA[] _decisionToDFA; + protected static final PredictionContextCache _sharedContextCache = + new PredictionContextCache(); + public static final int + AND=1, OR=2, NOT=3, LEFT_PARENTHESIS=4, RIGHT_PARENTHESIS=5, LEFT_CURLY_BRACKET=6, + RIGHT_CURLY_BRACKET=7, COLON=8, OP_COMPARE=9, QUOTED=10, NUMBER=11, LITERAL=12, + DEFAULT_SKIP=13; + public static final int + RULE_topLevelQuery = 0, RULE_query = 1, RULE_expression = 2, RULE_nestedQuery = 3, + RULE_fieldRangeQuery = 4, RULE_fieldMTermQuery = 5, RULE_term = 6, RULE_groupingExpr = 7, + RULE_fieldName = 8; + private static String[] makeRuleNames() { + return new String[] { + "topLevelQuery", "query", "expression", "nestedQuery", "fieldRangeQuery", + "fieldMTermQuery", "term", "groupingExpr", "fieldName" + }; + } + public static final String[] ruleNames = makeRuleNames(); + + private static String[] makeLiteralNames() { + return new String[] { + null, null, null, null, "'('", "')'", "'{'", "'}'", "':'" + }; + } + private static final String[] _LITERAL_NAMES = makeLiteralNames(); + private static String[] makeSymbolicNames() { + return new String[] { + null, "AND", "OR", "NOT", "LEFT_PARENTHESIS", "RIGHT_PARENTHESIS", "LEFT_CURLY_BRACKET", + "RIGHT_CURLY_BRACKET", "COLON", "OP_COMPARE", "QUOTED", "NUMBER", "LITERAL", + "DEFAULT_SKIP" + }; + } + private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); + public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); + + /** + * @deprecated Use {@link #VOCABULARY} instead. + */ + @Deprecated + public static final String[] tokenNames; + static { + tokenNames = new String[_SYMBOLIC_NAMES.length]; + for (int i = 0; i < tokenNames.length; i++) { + tokenNames[i] = VOCABULARY.getLiteralName(i); + if (tokenNames[i] == null) { + tokenNames[i] = VOCABULARY.getSymbolicName(i); + } + + if (tokenNames[i] == null) { + tokenNames[i] = ""; + } + } + } + + @Override + @Deprecated + public String[] getTokenNames() { + return tokenNames; + } + + @Override + + public Vocabulary getVocabulary() { + return VOCABULARY; + } + + @Override + public String getGrammarFileName() { return "KqlBase.g4"; } + + @Override + public String[] getRuleNames() { return ruleNames; } + + @Override + public String getSerializedATN() { return _serializedATN; } + + @Override + public ATN getATN() { return _ATN; } + + public KqlBaseParser(TokenStream input) { + super(input); + _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); + } + + @SuppressWarnings("CheckReturnValue") + public static class TopLevelQueryContext extends ParserRuleContext { + public QueryContext query() { + return getRuleContext(QueryContext.class,0); + } + public TerminalNode EOF() { return getToken(KqlBaseParser.EOF, 0); } + public TopLevelQueryContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_topLevelQuery; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterTopLevelQuery(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitTopLevelQuery(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitTopLevelQuery(this); + else return visitor.visitChildren(this); + } + } + + public final TopLevelQueryContext topLevelQuery() throws RecognitionException { + TopLevelQueryContext _localctx = new TopLevelQueryContext(_ctx, getState()); + enterRule(_localctx, 0, RULE_topLevelQuery); + try { + enterOuterAlt(_localctx, 1); + { + setState(18); + query(0); + setState(19); + match(EOF); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class QueryContext extends ParserRuleContext { + public QueryContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_query; } + + public QueryContext() { } + public void copyFrom(QueryContext ctx) { + super.copyFrom(ctx); + } + } + @SuppressWarnings("CheckReturnValue") + public static class LogicalNotContext extends QueryContext { + public TerminalNode NOT() { return getToken(KqlBaseParser.NOT, 0); } + public QueryContext query() { + return getRuleContext(QueryContext.class,0); + } + public LogicalNotContext(QueryContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterLogicalNot(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitLogicalNot(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitLogicalNot(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class QueryDefaultContext extends QueryContext { + public NestedQueryContext nestedQuery() { + return getRuleContext(NestedQueryContext.class,0); + } + public ExpressionContext expression() { + return getRuleContext(ExpressionContext.class,0); + } + public TerminalNode LEFT_PARENTHESIS() { return getToken(KqlBaseParser.LEFT_PARENTHESIS, 0); } + public QueryContext query() { + return getRuleContext(QueryContext.class,0); + } + public TerminalNode RIGHT_PARENTHESIS() { return getToken(KqlBaseParser.RIGHT_PARENTHESIS, 0); } + public QueryDefaultContext(QueryContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterQueryDefault(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitQueryDefault(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitQueryDefault(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class LogicalAndContext extends QueryContext { + public List query() { + return getRuleContexts(QueryContext.class); + } + public QueryContext query(int i) { + return getRuleContext(QueryContext.class,i); + } + public List AND() { return getTokens(KqlBaseParser.AND); } + public TerminalNode AND(int i) { + return getToken(KqlBaseParser.AND, i); + } + public LogicalAndContext(QueryContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterLogicalAnd(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitLogicalAnd(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitLogicalAnd(this); + else return visitor.visitChildren(this); + } + } + @SuppressWarnings("CheckReturnValue") + public static class LogicalOrContext extends QueryContext { + public List query() { + return getRuleContexts(QueryContext.class); + } + public QueryContext query(int i) { + return getRuleContext(QueryContext.class,i); + } + public List OR() { return getTokens(KqlBaseParser.OR); } + public TerminalNode OR(int i) { + return getToken(KqlBaseParser.OR, i); + } + public LogicalOrContext(QueryContext ctx) { copyFrom(ctx); } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterLogicalOr(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitLogicalOr(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitLogicalOr(this); + else return visitor.visitChildren(this); + } + } + + public final QueryContext query() throws RecognitionException { + return query(0); + } + + private QueryContext query(int _p) throws RecognitionException { + ParserRuleContext _parentctx = _ctx; + int _parentState = getState(); + QueryContext _localctx = new QueryContext(_ctx, _parentState); + QueryContext _prevctx = _localctx; + int _startState = 2; + enterRecursionRule(_localctx, 2, RULE_query, _p); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(30); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) { + case 1: + { + _localctx = new LogicalNotContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + + setState(22); + match(NOT); + setState(23); + query(4); + } + break; + case 2: + { + _localctx = new QueryDefaultContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(24); + nestedQuery(); + } + break; + case 3: + { + _localctx = new QueryDefaultContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(25); + expression(); + } + break; + case 4: + { + _localctx = new QueryDefaultContext(_localctx); + _ctx = _localctx; + _prevctx = _localctx; + setState(26); + match(LEFT_PARENTHESIS); + setState(27); + query(0); + setState(28); + match(RIGHT_PARENTHESIS); + } + break; + } + _ctx.stop = _input.LT(-1); + setState(48); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,4,_ctx); + while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ) { + if ( _alt==1 ) { + if ( _parseListeners!=null ) triggerExitRuleEvent(); + _prevctx = _localctx; + { + setState(46); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,3,_ctx) ) { + case 1: + { + _localctx = new LogicalOrContext(new QueryContext(_parentctx, _parentState)); + pushNewRecursionContext(_localctx, _startState, RULE_query); + setState(32); + if (!(precpred(_ctx, 6))) throw new FailedPredicateException(this, "precpred(_ctx, 6)"); + setState(35); + _errHandler.sync(this); + _alt = 1; + do { + switch (_alt) { + case 1: + { + { + setState(33); + match(OR); + setState(34); + query(0); + } + } + break; + default: + throw new NoViableAltException(this); + } + setState(37); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,1,_ctx); + } while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ); + } + break; + case 2: + { + _localctx = new LogicalAndContext(new QueryContext(_parentctx, _parentState)); + pushNewRecursionContext(_localctx, _startState, RULE_query); + setState(39); + if (!(precpred(_ctx, 5))) throw new FailedPredicateException(this, "precpred(_ctx, 5)"); + setState(42); + _errHandler.sync(this); + _alt = 1; + do { + switch (_alt) { + case 1: + { + { + setState(40); + match(AND); + setState(41); + query(0); + } + } + break; + default: + throw new NoViableAltException(this); + } + setState(44); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,2,_ctx); + } while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ); + } + break; + } + } + } + setState(50); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,4,_ctx); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + unrollRecursionContexts(_parentctx); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class ExpressionContext extends ParserRuleContext { + public FieldMTermQueryContext fieldMTermQuery() { + return getRuleContext(FieldMTermQueryContext.class,0); + } + public FieldRangeQueryContext fieldRangeQuery() { + return getRuleContext(FieldRangeQueryContext.class,0); + } + public ExpressionContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_expression; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterExpression(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitExpression(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitExpression(this); + else return visitor.visitChildren(this); + } + } + + public final ExpressionContext expression() throws RecognitionException { + ExpressionContext _localctx = new ExpressionContext(_ctx, getState()); + enterRule(_localctx, 4, RULE_expression); + try { + setState(53); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,5,_ctx) ) { + case 1: + enterOuterAlt(_localctx, 1); + { + setState(51); + fieldMTermQuery(); + } + break; + case 2: + enterOuterAlt(_localctx, 2); + { + setState(52); + fieldRangeQuery(); + } + break; + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class NestedQueryContext extends ParserRuleContext { + public FieldNameContext fieldName() { + return getRuleContext(FieldNameContext.class,0); + } + public TerminalNode COLON() { return getToken(KqlBaseParser.COLON, 0); } + public TerminalNode LEFT_CURLY_BRACKET() { return getToken(KqlBaseParser.LEFT_CURLY_BRACKET, 0); } + public QueryContext query() { + return getRuleContext(QueryContext.class,0); + } + public TerminalNode RIGHT_CURLY_BRACKET() { return getToken(KqlBaseParser.RIGHT_CURLY_BRACKET, 0); } + public NestedQueryContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_nestedQuery; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterNestedQuery(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitNestedQuery(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitNestedQuery(this); + else return visitor.visitChildren(this); + } + } + + public final NestedQueryContext nestedQuery() throws RecognitionException { + NestedQueryContext _localctx = new NestedQueryContext(_ctx, getState()); + enterRule(_localctx, 6, RULE_nestedQuery); + try { + enterOuterAlt(_localctx, 1); + { + setState(55); + fieldName(); + setState(56); + match(COLON); + setState(57); + match(LEFT_CURLY_BRACKET); + setState(58); + query(0); + setState(59); + match(RIGHT_CURLY_BRACKET); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class FieldRangeQueryContext extends ParserRuleContext { + public Token operator; + public FieldNameContext fieldName() { + return getRuleContext(FieldNameContext.class,0); + } + public TermContext term() { + return getRuleContext(TermContext.class,0); + } + public TerminalNode OP_COMPARE() { return getToken(KqlBaseParser.OP_COMPARE, 0); } + public FieldRangeQueryContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_fieldRangeQuery; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterFieldRangeQuery(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitFieldRangeQuery(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitFieldRangeQuery(this); + else return visitor.visitChildren(this); + } + } + + public final FieldRangeQueryContext fieldRangeQuery() throws RecognitionException { + FieldRangeQueryContext _localctx = new FieldRangeQueryContext(_ctx, getState()); + enterRule(_localctx, 8, RULE_fieldRangeQuery); + try { + enterOuterAlt(_localctx, 1); + { + setState(61); + fieldName(); + setState(62); + ((FieldRangeQueryContext)_localctx).operator = match(OP_COMPARE); + setState(63); + term(); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class FieldMTermQueryContext extends ParserRuleContext { + public GroupingExprContext groupingExpr() { + return getRuleContext(GroupingExprContext.class,0); + } + public FieldNameContext fieldName() { + return getRuleContext(FieldNameContext.class,0); + } + public TerminalNode COLON() { return getToken(KqlBaseParser.COLON, 0); } + public List term() { + return getRuleContexts(TermContext.class); + } + public TermContext term(int i) { + return getRuleContext(TermContext.class,i); + } + public FieldMTermQueryContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_fieldMTermQuery; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterFieldMTermQuery(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitFieldMTermQuery(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitFieldMTermQuery(this); + else return visitor.visitChildren(this); + } + } + + public final FieldMTermQueryContext fieldMTermQuery() throws RecognitionException { + FieldMTermQueryContext _localctx = new FieldMTermQueryContext(_ctx, getState()); + enterRule(_localctx, 10, RULE_fieldMTermQuery); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(68); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,6,_ctx) ) { + case 1: + { + setState(65); + fieldName(); + { + setState(66); + match(COLON); + } + } + break; + } + setState(76); + _errHandler.sync(this); + switch (_input.LA(1)) { + case QUOTED: + case NUMBER: + case LITERAL: + { + setState(71); + _errHandler.sync(this); + _alt = 1; + do { + switch (_alt) { + case 1: + { + { + setState(70); + term(); + } + } + break; + default: + throw new NoViableAltException(this); + } + setState(73); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,7,_ctx); + } while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ); + } + break; + case LEFT_PARENTHESIS: + { + setState(75); + groupingExpr(); + } + break; + default: + throw new NoViableAltException(this); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class TermContext extends ParserRuleContext { + public TerminalNode QUOTED() { return getToken(KqlBaseParser.QUOTED, 0); } + public TerminalNode NUMBER() { return getToken(KqlBaseParser.NUMBER, 0); } + public TerminalNode LITERAL() { return getToken(KqlBaseParser.LITERAL, 0); } + public TermContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_term; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterTerm(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitTerm(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitTerm(this); + else return visitor.visitChildren(this); + } + } + + public final TermContext term() throws RecognitionException { + TermContext _localctx = new TermContext(_ctx, getState()); + enterRule(_localctx, 12, RULE_term); + int _la; + try { + enterOuterAlt(_localctx, 1); + { + setState(78); + _la = _input.LA(1); + if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 7168L) != 0)) ) { + _errHandler.recoverInline(this); + } + else { + if ( _input.LA(1)==Token.EOF ) matchedEOF = true; + _errHandler.reportMatch(this); + consume(); + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class GroupingExprContext extends ParserRuleContext { + public TerminalNode LEFT_PARENTHESIS() { return getToken(KqlBaseParser.LEFT_PARENTHESIS, 0); } + public List term() { + return getRuleContexts(TermContext.class); + } + public TermContext term(int i) { + return getRuleContext(TermContext.class,i); + } + public TerminalNode RIGHT_PARENTHESIS() { return getToken(KqlBaseParser.RIGHT_PARENTHESIS, 0); } + public GroupingExprContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_groupingExpr; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterGroupingExpr(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitGroupingExpr(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitGroupingExpr(this); + else return visitor.visitChildren(this); + } + } + + public final GroupingExprContext groupingExpr() throws RecognitionException { + GroupingExprContext _localctx = new GroupingExprContext(_ctx, getState()); + enterRule(_localctx, 14, RULE_groupingExpr); + try { + int _alt; + enterOuterAlt(_localctx, 1); + { + setState(80); + match(LEFT_PARENTHESIS); + setState(82); + _errHandler.sync(this); + _alt = 1; + do { + switch (_alt) { + case 1: + { + { + setState(81); + term(); + } + } + break; + default: + throw new NoViableAltException(this); + } + setState(84); + _errHandler.sync(this); + _alt = getInterpreter().adaptivePredict(_input,9,_ctx); + } while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ); + setState(87); + _errHandler.sync(this); + switch ( getInterpreter().adaptivePredict(_input,10,_ctx) ) { + case 1: + { + setState(86); + match(RIGHT_PARENTHESIS); + } + break; + } + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + @SuppressWarnings("CheckReturnValue") + public static class FieldNameContext extends ParserRuleContext { + public TerminalNode LITERAL() { return getToken(KqlBaseParser.LITERAL, 0); } + public FieldNameContext(ParserRuleContext parent, int invokingState) { + super(parent, invokingState); + } + @Override public int getRuleIndex() { return RULE_fieldName; } + @Override + public void enterRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).enterFieldName(this); + } + @Override + public void exitRule(ParseTreeListener listener) { + if ( listener instanceof KqlBaseListener ) ((KqlBaseListener)listener).exitFieldName(this); + } + @Override + public T accept(ParseTreeVisitor visitor) { + if ( visitor instanceof KqlBaseVisitor ) return ((KqlBaseVisitor)visitor).visitFieldName(this); + else return visitor.visitChildren(this); + } + } + + public final FieldNameContext fieldName() throws RecognitionException { + FieldNameContext _localctx = new FieldNameContext(_ctx, getState()); + enterRule(_localctx, 16, RULE_fieldName); + try { + enterOuterAlt(_localctx, 1); + { + setState(89); + match(LITERAL); + } + } + catch (RecognitionException re) { + _localctx.exception = re; + _errHandler.reportError(this, re); + _errHandler.recover(this, re); + } + finally { + exitRule(); + } + return _localctx; + } + + public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) { + switch (ruleIndex) { + case 1: + return query_sempred((QueryContext)_localctx, predIndex); + } + return true; + } + private boolean query_sempred(QueryContext _localctx, int predIndex) { + switch (predIndex) { + case 0: + return precpred(_ctx, 6); + case 1: + return precpred(_ctx, 5); + } + return true; + } + + public static final String _serializedATN = + "\u0004\u0001\r\\\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+ + "\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+ + "\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007\u0007\u0007\u0002"+ + "\b\u0007\b\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001"+ + "\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+ + "\u0001\u0001\u0003\u0001\u001f\b\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+ + "\u0004\u0001$\b\u0001\u000b\u0001\f\u0001%\u0001\u0001\u0001\u0001\u0001"+ + "\u0001\u0004\u0001+\b\u0001\u000b\u0001\f\u0001,\u0005\u0001/\b\u0001"+ + "\n\u0001\f\u00012\t\u0001\u0001\u0002\u0001\u0002\u0003\u00026\b\u0002"+ + "\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003"+ + "\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005"+ + "\u0001\u0005\u0003\u0005E\b\u0005\u0001\u0005\u0004\u0005H\b\u0005\u000b"+ + "\u0005\f\u0005I\u0001\u0005\u0003\u0005M\b\u0005\u0001\u0006\u0001\u0006"+ + "\u0001\u0007\u0001\u0007\u0004\u0007S\b\u0007\u000b\u0007\f\u0007T\u0001"+ + "\u0007\u0003\u0007X\b\u0007\u0001\b\u0001\b\u0001\b\u0000\u0001\u0002"+ + "\t\u0000\u0002\u0004\u0006\b\n\f\u000e\u0010\u0000\u0001\u0001\u0000\n"+ + "\f_\u0000\u0012\u0001\u0000\u0000\u0000\u0002\u001e\u0001\u0000\u0000"+ + "\u0000\u00045\u0001\u0000\u0000\u0000\u00067\u0001\u0000\u0000\u0000\b"+ + "=\u0001\u0000\u0000\u0000\nD\u0001\u0000\u0000\u0000\fN\u0001\u0000\u0000"+ + "\u0000\u000eP\u0001\u0000\u0000\u0000\u0010Y\u0001\u0000\u0000\u0000\u0012"+ + "\u0013\u0003\u0002\u0001\u0000\u0013\u0014\u0005\u0000\u0000\u0001\u0014"+ + "\u0001\u0001\u0000\u0000\u0000\u0015\u0016\u0006\u0001\uffff\uffff\u0000"+ + "\u0016\u0017\u0005\u0003\u0000\u0000\u0017\u001f\u0003\u0002\u0001\u0004"+ + "\u0018\u001f\u0003\u0006\u0003\u0000\u0019\u001f\u0003\u0004\u0002\u0000"+ + "\u001a\u001b\u0005\u0004\u0000\u0000\u001b\u001c\u0003\u0002\u0001\u0000"+ + "\u001c\u001d\u0005\u0005\u0000\u0000\u001d\u001f\u0001\u0000\u0000\u0000"+ + "\u001e\u0015\u0001\u0000\u0000\u0000\u001e\u0018\u0001\u0000\u0000\u0000"+ + "\u001e\u0019\u0001\u0000\u0000\u0000\u001e\u001a\u0001\u0000\u0000\u0000"+ + "\u001f0\u0001\u0000\u0000\u0000 #\n\u0006\u0000\u0000!\"\u0005\u0002\u0000"+ + "\u0000\"$\u0003\u0002\u0001\u0000#!\u0001\u0000\u0000\u0000$%\u0001\u0000"+ + "\u0000\u0000%#\u0001\u0000\u0000\u0000%&\u0001\u0000\u0000\u0000&/\u0001"+ + "\u0000\u0000\u0000\'*\n\u0005\u0000\u0000()\u0005\u0001\u0000\u0000)+"+ + "\u0003\u0002\u0001\u0000*(\u0001\u0000\u0000\u0000+,\u0001\u0000\u0000"+ + "\u0000,*\u0001\u0000\u0000\u0000,-\u0001\u0000\u0000\u0000-/\u0001\u0000"+ + "\u0000\u0000. \u0001\u0000\u0000\u0000.\'\u0001\u0000\u0000\u0000/2\u0001"+ + "\u0000\u0000\u00000.\u0001\u0000\u0000\u000001\u0001\u0000\u0000\u0000"+ + "1\u0003\u0001\u0000\u0000\u000020\u0001\u0000\u0000\u000036\u0003\n\u0005"+ + "\u000046\u0003\b\u0004\u000053\u0001\u0000\u0000\u000054\u0001\u0000\u0000"+ + "\u00006\u0005\u0001\u0000\u0000\u000078\u0003\u0010\b\u000089\u0005\b"+ + "\u0000\u00009:\u0005\u0006\u0000\u0000:;\u0003\u0002\u0001\u0000;<\u0005"+ + "\u0007\u0000\u0000<\u0007\u0001\u0000\u0000\u0000=>\u0003\u0010\b\u0000"+ + ">?\u0005\t\u0000\u0000?@\u0003\f\u0006\u0000@\t\u0001\u0000\u0000\u0000"+ + "AB\u0003\u0010\b\u0000BC\u0005\b\u0000\u0000CE\u0001\u0000\u0000\u0000"+ + "DA\u0001\u0000\u0000\u0000DE\u0001\u0000\u0000\u0000EL\u0001\u0000\u0000"+ + "\u0000FH\u0003\f\u0006\u0000GF\u0001\u0000\u0000\u0000HI\u0001\u0000\u0000"+ + "\u0000IG\u0001\u0000\u0000\u0000IJ\u0001\u0000\u0000\u0000JM\u0001\u0000"+ + "\u0000\u0000KM\u0003\u000e\u0007\u0000LG\u0001\u0000\u0000\u0000LK\u0001"+ + "\u0000\u0000\u0000M\u000b\u0001\u0000\u0000\u0000NO\u0007\u0000\u0000"+ + "\u0000O\r\u0001\u0000\u0000\u0000PR\u0005\u0004\u0000\u0000QS\u0003\f"+ + "\u0006\u0000RQ\u0001\u0000\u0000\u0000ST\u0001\u0000\u0000\u0000TR\u0001"+ + "\u0000\u0000\u0000TU\u0001\u0000\u0000\u0000UW\u0001\u0000\u0000\u0000"+ + "VX\u0005\u0005\u0000\u0000WV\u0001\u0000\u0000\u0000WX\u0001\u0000\u0000"+ + "\u0000X\u000f\u0001\u0000\u0000\u0000YZ\u0005\f\u0000\u0000Z\u0011\u0001"+ + "\u0000\u0000\u0000\u000b\u001e%,.05DILTW"; + public static final ATN _ATN = + new ATNDeserializer().deserialize(_serializedATN.toCharArray()); + static { + _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; + for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { + _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); + } + } +} diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseVisitor.java b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseVisitor.java new file mode 100644 index 0000000000000..23e0b44173c0e --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/KqlBaseVisitor.java @@ -0,0 +1,89 @@ +// ANTLR GENERATED CODE: DO NOT EDIT +package org.elasticsearch.xpack.kql.parser; +import org.antlr.v4.runtime.tree.ParseTreeVisitor; + +/** + * This interface defines a complete generic visitor for a parse tree produced + * by {@link KqlBaseParser}. + * + * @param The return type of the visit operation. Use {@link Void} for + * operations with no return type. + */ +interface KqlBaseVisitor extends ParseTreeVisitor { + /** + * Visit a parse tree produced by {@link KqlBaseParser#topLevelQuery}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitTopLevelQuery(KqlBaseParser.TopLevelQueryContext ctx); + /** + * Visit a parse tree produced by the {@code logicalNot} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitLogicalNot(KqlBaseParser.LogicalNotContext ctx); + /** + * Visit a parse tree produced by the {@code queryDefault} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitQueryDefault(KqlBaseParser.QueryDefaultContext ctx); + /** + * Visit a parse tree produced by the {@code logicalAnd} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitLogicalAnd(KqlBaseParser.LogicalAndContext ctx); + /** + * Visit a parse tree produced by the {@code logicalOr} + * labeled alternative in {@link KqlBaseParser#query}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitLogicalOr(KqlBaseParser.LogicalOrContext ctx); + /** + * Visit a parse tree produced by {@link KqlBaseParser#expression}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitExpression(KqlBaseParser.ExpressionContext ctx); + /** + * Visit a parse tree produced by {@link KqlBaseParser#nestedQuery}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitNestedQuery(KqlBaseParser.NestedQueryContext ctx); + /** + * Visit a parse tree produced by {@link KqlBaseParser#fieldRangeQuery}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitFieldRangeQuery(KqlBaseParser.FieldRangeQueryContext ctx); + /** + * Visit a parse tree produced by {@link KqlBaseParser#fieldMTermQuery}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitFieldMTermQuery(KqlBaseParser.FieldMTermQueryContext ctx); + /** + * Visit a parse tree produced by {@link KqlBaseParser#term}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitTerm(KqlBaseParser.TermContext ctx); + /** + * Visit a parse tree produced by {@link KqlBaseParser#groupingExpr}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitGroupingExpr(KqlBaseParser.GroupingExprContext ctx); + /** + * Visit a parse tree produced by {@link KqlBaseParser#fieldName}. + * @param ctx the parse tree + * @return the visitor result + */ + T visitFieldName(KqlBaseParser.FieldNameContext ctx); +}