Skip to content

Commit

Permalink
[ES|QL] Update grammars (elastic#201514)
Browse files Browse the repository at this point in the history
Part of elastic#200858

This PR updates the ES|QL grammars (lexer and parser) to match the
latest version in Elasticsearch.

---------

Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
2 people authored and CAWilson94 committed Dec 12, 2024
1 parent 2e78ee5 commit cb43a07
Show file tree
Hide file tree
Showing 13 changed files with 2,281 additions and 1,653 deletions.
38 changes: 34 additions & 4 deletions packages/kbn-esql-ast/src/antlr/esql_lexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ WHERE : 'where' -> pushMode(EXPRESSION_MODE);
// main section while preserving alphabetical order:
// MYCOMMAND : 'mycommand' -> ...
DEV_INLINESTATS : {this.isDevVersion()}? 'inlinestats' -> pushMode(EXPRESSION_MODE);
DEV_LOOKUP : {this.isDevVersion()}? 'lookup' -> pushMode(LOOKUP_MODE);
DEV_LOOKUP : {this.isDevVersion()}? 'lookup_🐔' -> pushMode(LOOKUP_MODE);
DEV_METRICS : {this.isDevVersion()}? 'metrics' -> pushMode(METRICS_MODE);
// list of all JOIN commands
DEV_JOIN : {this.isDevVersion()}? 'join' -> pushMode(JOIN_MODE);
DEV_JOIN_FULL : {this.isDevVersion()}? 'full' -> pushMode(JOIN_MODE);
DEV_JOIN_LEFT : {this.isDevVersion()}? 'left' -> pushMode(JOIN_MODE);
DEV_JOIN_RIGHT : {this.isDevVersion()}? 'right' -> pushMode(JOIN_MODE);
DEV_JOIN_LOOKUP : {this.isDevVersion()}? 'lookup' -> pushMode(JOIN_MODE);


//
// Catch-all for unrecognized commands - don't define any beyond this line
Expand All @@ -107,8 +114,6 @@ WS
: [ \r\n\t]+ -> channel(HIDDEN)
;

COLON : ':';

//
// Expression - used by most command
//
Expand Down Expand Up @@ -179,6 +184,7 @@ AND : 'and';
ASC : 'asc';
ASSIGN : '=';
CAST_OP : '::';
COLON : ':';
COMMA : ',';
DESC : 'desc';
DOT : '.';
Expand Down Expand Up @@ -211,7 +217,6 @@ MINUS : '-';
ASTERISK : '*';
SLASH : '/';
PERCENT : '%';
EXPRESSION_COLON : {this.isDevVersion()}? COLON -> type(COLON);

NESTED_WHERE : WHERE -> type(WHERE);

Expand Down Expand Up @@ -545,6 +550,31 @@ LOOKUP_FIELD_WS
: WS -> channel(HIDDEN)
;

//
// JOIN-related commands
//
mode JOIN_MODE;
JOIN_PIPE : PIPE -> type(PIPE), popMode;
JOIN_JOIN : DEV_JOIN -> type(DEV_JOIN);
JOIN_AS : AS -> type(AS);
JOIN_ON : ON -> type(ON), popMode, pushMode(EXPRESSION_MODE);
USING : 'USING' -> popMode, pushMode(EXPRESSION_MODE);

JOIN_UNQUOTED_IDENTIFER: UNQUOTED_IDENTIFIER -> type(UNQUOTED_IDENTIFIER);
JOIN_QUOTED_IDENTIFIER : QUOTED_IDENTIFIER -> type(QUOTED_IDENTIFIER);

JOIN_LINE_COMMENT
: LINE_COMMENT -> channel(HIDDEN)
;

JOIN_MULTILINE_COMMENT
: MULTILINE_COMMENT -> channel(HIDDEN)
;

JOIN_WS
: WS -> channel(HIDDEN)
;

//
// METRICS command
//
Expand Down
43 changes: 38 additions & 5 deletions packages/kbn-esql-ast/src/antlr/esql_lexer.interp

Large diffs are not rendered by default.

296 changes: 153 additions & 143 deletions packages/kbn-esql-ast/src/antlr/esql_lexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -17,106 +17,115 @@ WHERE=16
DEV_INLINESTATS=17
DEV_LOOKUP=18
DEV_METRICS=19
UNKNOWN_CMD=20
LINE_COMMENT=21
MULTILINE_COMMENT=22
WS=23
COLON=24
PIPE=25
QUOTED_STRING=26
INTEGER_LITERAL=27
DECIMAL_LITERAL=28
BY=29
AND=30
ASC=31
ASSIGN=32
CAST_OP=33
COMMA=34
DESC=35
DOT=36
FALSE=37
FIRST=38
IN=39
IS=40
LAST=41
LIKE=42
LP=43
NOT=44
NULL=45
NULLS=46
OR=47
PARAM=48
RLIKE=49
RP=50
TRUE=51
EQ=52
CIEQ=53
NEQ=54
LT=55
LTE=56
GT=57
GTE=58
PLUS=59
MINUS=60
ASTERISK=61
SLASH=62
PERCENT=63
NAMED_OR_POSITIONAL_PARAM=64
OPENING_BRACKET=65
CLOSING_BRACKET=66
UNQUOTED_IDENTIFIER=67
QUOTED_IDENTIFIER=68
EXPR_LINE_COMMENT=69
EXPR_MULTILINE_COMMENT=70
EXPR_WS=71
EXPLAIN_WS=72
EXPLAIN_LINE_COMMENT=73
EXPLAIN_MULTILINE_COMMENT=74
METADATA=75
UNQUOTED_SOURCE=76
FROM_LINE_COMMENT=77
FROM_MULTILINE_COMMENT=78
FROM_WS=79
ID_PATTERN=80
PROJECT_LINE_COMMENT=81
PROJECT_MULTILINE_COMMENT=82
PROJECT_WS=83
AS=84
RENAME_LINE_COMMENT=85
RENAME_MULTILINE_COMMENT=86
RENAME_WS=87
ON=88
WITH=89
ENRICH_POLICY_NAME=90
ENRICH_LINE_COMMENT=91
ENRICH_MULTILINE_COMMENT=92
ENRICH_WS=93
ENRICH_FIELD_LINE_COMMENT=94
ENRICH_FIELD_MULTILINE_COMMENT=95
ENRICH_FIELD_WS=96
MVEXPAND_LINE_COMMENT=97
MVEXPAND_MULTILINE_COMMENT=98
MVEXPAND_WS=99
INFO=100
SHOW_LINE_COMMENT=101
SHOW_MULTILINE_COMMENT=102
SHOW_WS=103
SETTING=104
SETTING_LINE_COMMENT=105
SETTTING_MULTILINE_COMMENT=106
SETTING_WS=107
LOOKUP_LINE_COMMENT=108
LOOKUP_MULTILINE_COMMENT=109
LOOKUP_WS=110
LOOKUP_FIELD_LINE_COMMENT=111
LOOKUP_FIELD_MULTILINE_COMMENT=112
LOOKUP_FIELD_WS=113
METRICS_LINE_COMMENT=114
METRICS_MULTILINE_COMMENT=115
METRICS_WS=116
CLOSING_METRICS_LINE_COMMENT=117
CLOSING_METRICS_MULTILINE_COMMENT=118
CLOSING_METRICS_WS=119
DEV_JOIN=20
DEV_JOIN_FULL=21
DEV_JOIN_LEFT=22
DEV_JOIN_RIGHT=23
DEV_JOIN_LOOKUP=24
UNKNOWN_CMD=25
LINE_COMMENT=26
MULTILINE_COMMENT=27
WS=28
PIPE=29
QUOTED_STRING=30
INTEGER_LITERAL=31
DECIMAL_LITERAL=32
BY=33
AND=34
ASC=35
ASSIGN=36
CAST_OP=37
COLON=38
COMMA=39
DESC=40
DOT=41
FALSE=42
FIRST=43
IN=44
IS=45
LAST=46
LIKE=47
LP=48
NOT=49
NULL=50
NULLS=51
OR=52
PARAM=53
RLIKE=54
RP=55
TRUE=56
EQ=57
CIEQ=58
NEQ=59
LT=60
LTE=61
GT=62
GTE=63
PLUS=64
MINUS=65
ASTERISK=66
SLASH=67
PERCENT=68
NAMED_OR_POSITIONAL_PARAM=69
OPENING_BRACKET=70
CLOSING_BRACKET=71
UNQUOTED_IDENTIFIER=72
QUOTED_IDENTIFIER=73
EXPR_LINE_COMMENT=74
EXPR_MULTILINE_COMMENT=75
EXPR_WS=76
EXPLAIN_WS=77
EXPLAIN_LINE_COMMENT=78
EXPLAIN_MULTILINE_COMMENT=79
METADATA=80
UNQUOTED_SOURCE=81
FROM_LINE_COMMENT=82
FROM_MULTILINE_COMMENT=83
FROM_WS=84
ID_PATTERN=85
PROJECT_LINE_COMMENT=86
PROJECT_MULTILINE_COMMENT=87
PROJECT_WS=88
AS=89
RENAME_LINE_COMMENT=90
RENAME_MULTILINE_COMMENT=91
RENAME_WS=92
ON=93
WITH=94
ENRICH_POLICY_NAME=95
ENRICH_LINE_COMMENT=96
ENRICH_MULTILINE_COMMENT=97
ENRICH_WS=98
ENRICH_FIELD_LINE_COMMENT=99
ENRICH_FIELD_MULTILINE_COMMENT=100
ENRICH_FIELD_WS=101
MVEXPAND_LINE_COMMENT=102
MVEXPAND_MULTILINE_COMMENT=103
MVEXPAND_WS=104
INFO=105
SHOW_LINE_COMMENT=106
SHOW_MULTILINE_COMMENT=107
SHOW_WS=108
SETTING=109
SETTING_LINE_COMMENT=110
SETTTING_MULTILINE_COMMENT=111
SETTING_WS=112
LOOKUP_LINE_COMMENT=113
LOOKUP_MULTILINE_COMMENT=114
LOOKUP_WS=115
LOOKUP_FIELD_LINE_COMMENT=116
LOOKUP_FIELD_MULTILINE_COMMENT=117
LOOKUP_FIELD_WS=118
USING=119
JOIN_LINE_COMMENT=120
JOIN_MULTILINE_COMMENT=121
JOIN_WS=122
METRICS_LINE_COMMENT=123
METRICS_MULTILINE_COMMENT=124
METRICS_WS=125
CLOSING_METRICS_LINE_COMMENT=126
CLOSING_METRICS_MULTILINE_COMMENT=127
CLOSING_METRICS_WS=128
'dissect'=1
'drop'=2
'enrich'=3
Expand All @@ -133,46 +142,47 @@ CLOSING_METRICS_WS=119
'sort'=14
'stats'=15
'where'=16
':'=24
'|'=25
'by'=29
'and'=30
'asc'=31
'='=32
'::'=33
','=34
'desc'=35
'.'=36
'false'=37
'first'=38
'in'=39
'is'=40
'last'=41
'like'=42
'('=43
'not'=44
'null'=45
'nulls'=46
'or'=47
'?'=48
'rlike'=49
')'=50
'true'=51
'=='=52
'=~'=53
'!='=54
'<'=55
'<='=56
'>'=57
'>='=58
'+'=59
'-'=60
'*'=61
'/'=62
'%'=63
']'=66
'metadata'=75
'as'=84
'on'=88
'with'=89
'info'=100
'|'=29
'by'=33
'and'=34
'asc'=35
'='=36
'::'=37
':'=38
','=39
'desc'=40
'.'=41
'false'=42
'first'=43
'in'=44
'is'=45
'last'=46
'like'=47
'('=48
'not'=49
'null'=50
'nulls'=51
'or'=52
'?'=53
'rlike'=54
')'=55
'true'=56
'=='=57
'=~'=58
'!='=59
'<'=60
'<='=61
'>'=62
'>='=63
'+'=64
'-'=65
'*'=66
'/'=67
'%'=68
']'=71
'metadata'=80
'as'=89
'on'=93
'with'=94
'info'=105
'USING'=119
Loading

0 comments on commit cb43a07

Please sign in to comment.