Skip to content

Commit

Permalink
Yank out some parsers too
Browse files Browse the repository at this point in the history
  • Loading branch information
nik9000 committed Feb 10, 2025
1 parent 1c16761 commit 49bbfc2
Show file tree
Hide file tree
Showing 10 changed files with 4,285 additions and 4,272 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugin/esql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ tasks.register("regenParser", JavaExec) {
'-package', 'org.elasticsearch.xpack.esql.parser',
'-listener',
'-visitor',
'-o', outputPath,
'-lib', outputPath,
'-lib', "${file(grammarPath)}/parser",
'-o', outputPath,
"${file(grammarPath)}/EsqlBaseParser.g4"
}

Expand Down
113 changes: 3 additions & 110 deletions x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ options {
tokenVocab=EsqlBaseLexer;
}

import Expression,
Join;

singleStatement
: query EOF
;
Expand Down Expand Up @@ -62,62 +65,6 @@ whereCommand
: WHERE booleanExpression
;

booleanExpression
: NOT booleanExpression #logicalNot
| valueExpression #booleanDefault
| regexBooleanExpression #regexExpression
| left=booleanExpression operator=AND right=booleanExpression #logicalBinary
| left=booleanExpression operator=OR right=booleanExpression #logicalBinary
| valueExpression (NOT)? IN LP valueExpression (COMMA valueExpression)* RP #logicalIn
| valueExpression IS NOT? NULL #isNull
| matchBooleanExpression #matchExpression
;

regexBooleanExpression
: valueExpression (NOT)? kind=LIKE pattern=string
| valueExpression (NOT)? kind=RLIKE pattern=string
;

matchBooleanExpression
: fieldExp=qualifiedName (CAST_OP fieldType=dataType)? COLON matchQuery=constant
;

valueExpression
: operatorExpression #valueExpressionDefault
| left=operatorExpression comparisonOperator right=operatorExpression #comparison
;

operatorExpression
: primaryExpression #operatorExpressionDefault
| operator=(MINUS | PLUS) operatorExpression #arithmeticUnary
| left=operatorExpression operator=(ASTERISK | SLASH | PERCENT) right=operatorExpression #arithmeticBinary
| left=operatorExpression operator=(PLUS | MINUS) right=operatorExpression #arithmeticBinary
;

primaryExpression
: constant #constantDefault
| qualifiedName #dereference
| functionExpression #function
| LP booleanExpression RP #parenthesizedExpression
| primaryExpression CAST_OP dataType #inlineCast
;

functionExpression
: functionName LP (ASTERISK | (booleanExpression (COMMA booleanExpression)* (COMMA mapExpression)?))? RP
;

functionName
: identifierOrParameter
;

mapExpression
: LEFT_BRACES entryExpression (COMMA entryExpression)* RIGHT_BRACES
;

entryExpression
: key=string COLON value=constant
;

dataType
: identifier #toDataType
;
Expand Down Expand Up @@ -198,19 +145,6 @@ identifierPattern
| parameter
;

constant
: NULL #nullLiteral
| integerValue UNQUOTED_IDENTIFIER #qualifiedIntegerLiteral
| decimalValue #decimalLiteral
| integerValue #integerLiteral
| booleanValue #booleanLiteral
| parameter #inputParameter
| string #stringLiteral
| OPENING_BRACKET numericValue (COMMA numericValue)* CLOSING_BRACKET #numericArrayLiteral
| OPENING_BRACKET booleanValue (COMMA booleanValue)* CLOSING_BRACKET #booleanArrayLiteral
| OPENING_BRACKET string (COMMA string)* CLOSING_BRACKET #stringArrayLiteral
;

parameter
: PARAM #inputParam
| NAMED_OR_POSITIONAL_PARAM #inputNamedOrPositionalParam
Expand Down Expand Up @@ -269,31 +203,6 @@ commandOption
: identifier ASSIGN constant
;

booleanValue
: TRUE | FALSE
;

numericValue
: decimalValue
| integerValue
;

decimalValue
: (PLUS | MINUS)? DECIMAL_LITERAL
;

integerValue
: (PLUS | MINUS)? INTEGER_LITERAL
;

string
: QUOTED_STRING
;

comparisonOperator
: EQ | NEQ | LT | LTE | GT | GTE
;

explainCommand
: EXPLAIN subqueryExpression
;
Expand Down Expand Up @@ -325,22 +234,6 @@ inlinestatsCommand
: DEV_INLINESTATS stats=aggFields (BY grouping=fields)?
;

joinCommand
: type=(JOIN_LOOKUP | DEV_JOIN_LEFT | DEV_JOIN_RIGHT) JOIN joinTarget joinCondition
;

joinTarget
: index=indexPattern
;

joinCondition
: ON joinPredicate (COMMA joinPredicate)*
;

joinPredicate
: valueExpression
;

changePointCommand
: DEV_CHANGE_POINT value=qualifiedName (ON key=qualifiedName)? (AS targetType=qualifiedName COMMA targetPvalue=qualifiedName)?
;
101 changes: 101 additions & 0 deletions x-pack/plugin/esql/src/main/antlr/parser/Expression.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
parser grammar Expression;

booleanExpression
: NOT booleanExpression #logicalNot
| valueExpression #booleanDefault
| regexBooleanExpression #regexExpression
| left=booleanExpression operator=AND right=booleanExpression #logicalBinary
| left=booleanExpression operator=OR right=booleanExpression #logicalBinary
| valueExpression (NOT)? IN LP valueExpression (COMMA valueExpression)* RP #logicalIn
| valueExpression IS NOT? NULL #isNull
| matchBooleanExpression #matchExpression
;

regexBooleanExpression
: valueExpression (NOT)? kind=LIKE pattern=string
| valueExpression (NOT)? kind=RLIKE pattern=string
;

matchBooleanExpression
: fieldExp=qualifiedName (CAST_OP fieldType=dataType)? COLON matchQuery=constant
;

valueExpression
: operatorExpression #valueExpressionDefault
| left=operatorExpression comparisonOperator right=operatorExpression #comparison
;

operatorExpression
: primaryExpression #operatorExpressionDefault
| operator=(MINUS | PLUS) operatorExpression #arithmeticUnary
| left=operatorExpression operator=(ASTERISK | SLASH | PERCENT) right=operatorExpression #arithmeticBinary
| left=operatorExpression operator=(PLUS | MINUS) right=operatorExpression #arithmeticBinary
;

primaryExpression
: constant #constantDefault
| qualifiedName #dereference
| functionExpression #function
| LP booleanExpression RP #parenthesizedExpression
| primaryExpression CAST_OP dataType #inlineCast
;

functionExpression
: functionName LP (ASTERISK | (booleanExpression (COMMA booleanExpression)* (COMMA mapExpression)?))? RP
;

functionName
: identifierOrParameter
;

mapExpression
: LEFT_BRACES entryExpression (COMMA entryExpression)* RIGHT_BRACES
;

entryExpression
: key=string COLON value=constant
;

constant
: NULL #nullLiteral
| integerValue UNQUOTED_IDENTIFIER #qualifiedIntegerLiteral
| decimalValue #decimalLiteral
| integerValue #integerLiteral
| booleanValue #booleanLiteral
| parameter #inputParameter
| string #stringLiteral
| OPENING_BRACKET numericValue (COMMA numericValue)* CLOSING_BRACKET #numericArrayLiteral
| OPENING_BRACKET booleanValue (COMMA booleanValue)* CLOSING_BRACKET #booleanArrayLiteral
| OPENING_BRACKET string (COMMA string)* CLOSING_BRACKET #stringArrayLiteral
;

booleanValue
: TRUE | FALSE
;

numericValue
: decimalValue
| integerValue
;

decimalValue
: (PLUS | MINUS)? DECIMAL_LITERAL
;

integerValue
: (PLUS | MINUS)? INTEGER_LITERAL
;

string
: QUOTED_STRING
;

comparisonOperator
: EQ | NEQ | LT | LTE | GT | GTE
;
25 changes: 25 additions & 0 deletions x-pack/plugin/esql/src/main/antlr/parser/Join.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
parser grammar Join;

joinCommand
: type=(JOIN_LOOKUP | DEV_JOIN_LEFT | DEV_JOIN_RIGHT) JOIN joinTarget joinCondition
;

joinTarget
: index=indexPattern
;

joinCondition
: ON joinPredicate (COMMA joinPredicate)*
;

joinPredicate
: valueExpression
;


Large diffs are not rendered by default.

Loading

0 comments on commit 49bbfc2

Please sign in to comment.