Skip to content

Commit 05dfb28

Browse files
authored
[ES|QL] use lexer from elasticsearch (#178257)
## Summary Up till now, we had to define our own lexer rules for our client-side ES|QL validation. This was because we were using an unofficial ANTLR package (before the official ANTLR had typescript support). Now that we are using the official ANTLR library (as of #177211), we no longer have to encode case insensitivity into the lexer rules themselves because the [`caseInsensitive` option](antlr/antlr4#3399) is now available to us. This means we can adopt the very [same definitions](https://github.com/elastic/elasticsearch/blob/343b1ae1ba74fbf2e75c29adddb2790312dd680b/x-pack/plugin/esql/src/main/antlr/EsqlBaseLexer.g4) that Elasticsearch uses as long as we set `caseInsensitive` (Elasticsearch handles case insensitivity at runtime). ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent b0170e5 commit 05dfb28

File tree

8 files changed

+904
-971
lines changed

8 files changed

+904
-971
lines changed

packages/kbn-monaco/src/esql/antlr/esql_lexer.g4

+286-365
Large diffs are not rendered by default.

packages/kbn-monaco/src/esql/antlr/esql_lexer.interp

+40-66
Large diffs are not rendered by default.

packages/kbn-monaco/src/esql/antlr/esql_lexer.tokens

+39
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,46 @@ SETTING=101
102102
SETTING_LINE_COMMENT=102
103103
SETTTING_MULTILINE_COMMENT=103
104104
SETTING_WS=104
105+
'dissect'=1
106+
'drop'=2
107+
'enrich'=3
108+
'eval'=4
109+
'explain'=5
110+
'from'=6
111+
'grok'=7
112+
'inlinestats'=8
113+
'keep'=9
114+
'limit'=10
115+
'mv_expand'=11
116+
'rename'=12
117+
'row'=13
118+
'show'=14
119+
'sort'=15
120+
'stats'=16
121+
'where'=17
105122
'|'=25
123+
'by'=29
124+
'and'=30
125+
'asc'=31
106126
'='=32
107127
','=33
128+
'desc'=34
108129
'.'=35
130+
'false'=36
131+
'first'=37
132+
'last'=38
109133
'('=39
134+
'in'=40
135+
'is'=41
136+
'like'=42
137+
'not'=43
138+
'null'=44
139+
'nulls'=45
140+
'or'=46
110141
'?'=47
142+
'rlike'=48
111143
')'=49
144+
'true'=50
112145
'=='=51
113146
'=~'=52
114147
'!='=53
@@ -122,4 +155,10 @@ SETTING_WS=104
122155
'/'=61
123156
'%'=62
124157
']'=64
158+
'metadata'=70
159+
'as'=79
160+
'on'=83
161+
'with'=84
162+
'info'=95
163+
'functions'=96
125164
':'=100

packages/kbn-monaco/src/esql/antlr/esql_lexer.ts

+400-441
Large diffs are not rendered by default.

packages/kbn-monaco/src/esql/antlr/esql_parser.interp

+39-39
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
token literal names:
22
null
3-
null
4-
null
5-
null
6-
null
7-
null
8-
null
9-
null
10-
null
11-
null
12-
null
13-
null
14-
null
15-
null
16-
null
17-
null
18-
null
19-
null
3+
'dissect'
4+
'drop'
5+
'enrich'
6+
'eval'
7+
'explain'
8+
'from'
9+
'grok'
10+
'inlinestats'
11+
'keep'
12+
'limit'
13+
'mv_expand'
14+
'rename'
15+
'row'
16+
'show'
17+
'sort'
18+
'stats'
19+
'where'
2020
null
2121
null
2222
null
@@ -28,28 +28,28 @@ null
2828
null
2929
null
3030
null
31-
null
32-
null
33-
null
31+
'by'
32+
'and'
33+
'asc'
3434
'='
3535
','
36-
null
36+
'desc'
3737
'.'
38-
null
39-
null
40-
null
38+
'false'
39+
'first'
40+
'last'
4141
'('
42-
null
43-
null
44-
null
45-
null
46-
null
47-
null
48-
null
42+
'in'
43+
'is'
44+
'like'
45+
'not'
46+
'null'
47+
'nulls'
48+
'or'
4949
'?'
50-
null
50+
'rlike'
5151
')'
52-
null
52+
'true'
5353
'=='
5454
'=~'
5555
'!='
@@ -69,6 +69,7 @@ null
6969
null
7070
null
7171
null
72+
'metadata'
7273
null
7374
null
7475
null
@@ -77,9 +78,12 @@ null
7778
null
7879
null
7980
null
81+
'as'
8082
null
8183
null
8284
null
85+
'on'
86+
'with'
8387
null
8488
null
8589
null
@@ -90,12 +94,8 @@ null
9094
null
9195
null
9296
null
93-
null
94-
null
95-
null
96-
null
97-
null
98-
null
97+
'info'
98+
'functions'
9999
null
100100
null
101101
null

packages/kbn-monaco/src/esql/antlr/esql_parser.tokens

+39
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,46 @@ SETTING_LINE_COMMENT=102
103103
SETTTING_MULTILINE_COMMENT=103
104104
SETTING_WS=104
105105
UNQUOTED_ID_PATTERN=105
106+
'dissect'=1
107+
'drop'=2
108+
'enrich'=3
109+
'eval'=4
110+
'explain'=5
111+
'from'=6
112+
'grok'=7
113+
'inlinestats'=8
114+
'keep'=9
115+
'limit'=10
116+
'mv_expand'=11
117+
'rename'=12
118+
'row'=13
119+
'show'=14
120+
'sort'=15
121+
'stats'=16
122+
'where'=17
106123
'|'=25
124+
'by'=29
125+
'and'=30
126+
'asc'=31
107127
'='=32
108128
','=33
129+
'desc'=34
109130
'.'=35
131+
'false'=36
132+
'first'=37
133+
'last'=38
110134
'('=39
135+
'in'=40
136+
'is'=41
137+
'like'=42
138+
'not'=43
139+
'null'=44
140+
'nulls'=45
141+
'or'=46
111142
'?'=47
143+
'rlike'=48
112144
')'=49
145+
'true'=50
113146
'=='=51
114147
'=~'=52
115148
'!='=53
@@ -123,4 +156,10 @@ UNQUOTED_ID_PATTERN=105
123156
'/'=61
124157
'%'=62
125158
']'=64
159+
'metadata'=70
160+
'as'=79
161+
'on'=83
162+
'with'=84
163+
'info'=95
164+
'functions'=96
126165
':'=100

packages/kbn-monaco/src/esql/antlr/esql_parser.ts

+35-34
Original file line numberDiff line numberDiff line change
@@ -175,57 +175,58 @@ export default class esql_parser extends Parser {
175175
public static readonly RULE_showCommand = 48;
176176
public static readonly RULE_enrichCommand = 49;
177177
public static readonly RULE_enrichWithClause = 50;
178-
public static readonly literalNames: (string | null)[] = [ null, null,
178+
public static readonly literalNames: (string | null)[] = [ null, "'dissect'",
179+
"'drop'", "'enrich'",
180+
"'eval'", "'explain'",
181+
"'from'", "'grok'",
182+
"'inlinestats'",
183+
"'keep'", "'limit'",
184+
"'mv_expand'",
185+
"'rename'",
186+
"'row'", "'show'",
187+
"'sort'", "'stats'",
188+
"'where'", null,
179189
null, null,
180190
null, null,
181191
null, null,
192+
"'|'", null,
182193
null, null,
194+
"'by'", "'and'",
195+
"'asc'", "'='",
196+
"','", "'desc'",
197+
"'.'", "'false'",
198+
"'first'", "'last'",
199+
"'('", "'in'",
200+
"'is'", "'like'",
201+
"'not'", "'null'",
202+
"'nulls'", "'or'",
203+
"'?'", "'rlike'",
204+
"')'", "'true'",
205+
"'=='", "'=~'",
206+
"'!='", "'<'",
207+
"'<='", "'>'",
208+
"'>='", "'+'",
209+
"'-'", "'*'",
210+
"'/'", "'%'",
211+
null, "']'",
183212
null, null,
184213
null, null,
214+
null, "'metadata'",
185215
null, null,
186216
null, null,
187217
null, null,
188218
null, null,
219+
"'as'", null,
189220
null, null,
190-
null, "'|'",
221+
"'on'", "'with'",
191222
null, null,
192223
null, null,
193224
null, null,
194-
"'='", "','",
195-
null, "'.'",
196225
null, null,
197-
null, "'('",
198226
null, null,
227+
"'info'", "'functions'",
199228
null, null,
200-
null, null,
201-
null, "'?'",
202-
null, "')'",
203-
null, "'=='",
204-
"'=~'", "'!='",
205-
"'<'", "'<='",
206-
"'>'", "'>='",
207-
"'+'", "'-'",
208-
"'*'", "'/'",
209-
"'%'", null,
210-
"']'", null,
211-
null, null,
212-
null, null,
213-
null, null,
214-
null, null,
215-
null, null,
216-
null, null,
217-
null, null,
218-
null, null,
219-
null, null,
220-
null, null,
221-
null, null,
222-
null, null,
223-
null, null,
224-
null, null,
225-
null, null,
226-
null, null,
227-
null, null,
228-
"':'" ];
229+
null, "':'" ];
229230
public static readonly symbolicNames: (string | null)[] = [ null, "DISSECT",
230231
"DROP", "ENRICH",
231232
"EVAL", "EXPLAIN",

0 commit comments

Comments
 (0)