java.lang.Object
org.elasticsearch.xpack.kql.parser.ParserUtils
Utility class for parsing and processing KQL expressions.
Provides methods for type-safe parsing, text extraction, and string escaping/unescaping.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringescapeLuceneQueryString(String queryText, boolean preserveWildcards) Escapes special characters in a query string for use in Lucene queries.static StringextractText(org.antlr.v4.runtime.ParserRuleContext ctx) Extracts text from a parser tree context by joining all terminal nodes with a space delimiter.static booleanhasWildcard(org.antlr.v4.runtime.ParserRuleContext ctx) Checks if the given context contains any unescaped wildcard characters.static <T> TtypedParsing(org.antlr.v4.runtime.tree.ParseTreeVisitor<?> visitor, org.antlr.v4.runtime.ParserRuleContext ctx, Class<T> type) Performs type-safe parsing using the provided visitor.
-
Method Details
-
typedParsing
public static <T> T typedParsing(org.antlr.v4.runtime.tree.ParseTreeVisitor<?> visitor, org.antlr.v4.runtime.ParserRuleContext ctx, Class<T> type) Performs type-safe parsing using the provided visitor.- Parameters:
visitor- The visitor to use to do the parsingctx- The parser tree context to visittype- The expected return type class- Returns:
- The parsed result, casted to the expected type
-
extractText
Extracts text from a parser tree context by joining all terminal nodes with a space delimiter.- Parameters:
ctx- The parser tree context- Returns:
- The extracted text
-
hasWildcard
public static boolean hasWildcard(org.antlr.v4.runtime.ParserRuleContext ctx) Checks if the given context contains any unescaped wildcard characters.- Parameters:
ctx- The tree context to check- Returns:
- true if wildcards are present, false otherwise
-
escapeLuceneQueryString
Escapes special characters in a query string for use in Lucene queries.- Parameters:
queryText- The query text to escapepreserveWildcards- If true, does not escape wildcard characters (*)- Returns:
- The escaped query string
-