@elastic/monaco-esql 1.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,7 +12,7 @@ To highlight ES|QL code in Monaco editor, you need to register ES|QL language
12
12
  and its Monarch grammar:
13
13
 
14
14
  ```js
15
- import { monarchLanguage } from '@elastic/monaco-esql';
15
+ import { language as monarchLanguage } from '@elastic/monaco-esql/lib/monarch-shared';
16
16
 
17
17
  monaco.languages.register({id: 'esql'});
18
18
  monaco.languages.setMonarchTokensProvider('esql', monarchLanguage);
@@ -0,0 +1,17 @@
1
+ export declare const sourceCommands: string[];
2
+ export declare const processingCommands: string[];
3
+ export declare const options: string[];
4
+ export declare const literals: string[];
5
+ export declare const functions: string[];
6
+ export declare const delimiters: string[];
7
+ export declare const operators: {
8
+ named: {
9
+ binary: string[];
10
+ other: string[];
11
+ };
12
+ };
13
+ export type TemporalUnit = [unit: string, ...abbreviations: string[]];
14
+ /**
15
+ * @see https://www.elastic.co/docs/reference/query-languages/esql/esql-time-spans#esql-time-spans-table
16
+ */
17
+ export declare const temporalUnits: TemporalUnit[];
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.temporalUnits = exports.operators = exports.delimiters = exports.functions = exports.literals = exports.options = exports.processingCommands = exports.sourceCommands = void 0;
4
+ exports.sourceCommands = [
5
+ "FROM",
6
+ "ROW",
7
+ "EXPLAIN",
8
+ "SHOW INFO",
9
+ "SHOW",
10
+ "TS",
11
+ ];
12
+ exports.processingCommands = [
13
+ "CHANGE_POINT",
14
+ "COMPLETION",
15
+ "DISSECT",
16
+ "DROP",
17
+ "ENRICH",
18
+ "EVAL",
19
+ "FORK",
20
+ "FORK",
21
+ "FULL JOIN",
22
+ "GROK",
23
+ "INFO",
24
+ "INLINESTATS",
25
+ "INSIST",
26
+ "JOIN",
27
+ "KEEP",
28
+ "LEFT JOIN",
29
+ "LEFT",
30
+ "LIMIT",
31
+ "LOOKUP JOIN",
32
+ "LOOKUP",
33
+ "METRICS",
34
+ "MV_EXPAND",
35
+ "RENAME",
36
+ "RERANK",
37
+ "RIGHT JOIN",
38
+ "RIGHT",
39
+ "RRF",
40
+ "SORT",
41
+ "STATS",
42
+ "WHERE",
43
+ ];
44
+ exports.options = ["BY", "ON", "WITH", "METADATA", "WHERE"];
45
+ exports.literals = ["TRUE", "FALSE", "NULL"];
46
+ exports.functions = [
47
+ "ABS",
48
+ "ACOS",
49
+ "ASIN",
50
+ "ATAN",
51
+ "ATAN2",
52
+ "AVG",
53
+ "BIT_LENGTH",
54
+ "BUCKET",
55
+ "BYTE_LENGTH",
56
+ "CASE",
57
+ "CATEGORIZE",
58
+ "CBRT",
59
+ "CEIL",
60
+ "CIDR_MATCH",
61
+ "COALESCE",
62
+ "CONCAT",
63
+ "COS",
64
+ "COSH",
65
+ "COUNT_DISTINCT",
66
+ "COUNT",
67
+ "DATE_DIFF",
68
+ "DATE_EXTRACT",
69
+ "DATE_FORMAT",
70
+ "DATE_PARSE",
71
+ "DATE_TRUNC",
72
+ "E",
73
+ "ENDS_WITH",
74
+ "EXP",
75
+ "FLOOR",
76
+ "FROM_BASE64",
77
+ "GREATEST",
78
+ "HASH",
79
+ "HYPOT",
80
+ "IP_PREFIX",
81
+ "LEAST",
82
+ "LEFT",
83
+ "LENGTH",
84
+ "LOCATE",
85
+ "LOG",
86
+ "LOG10",
87
+ "LTRIM",
88
+ "MATCH",
89
+ "MAX",
90
+ "MEDIAN_ABSOLUTE_DEVIATION",
91
+ "MEDIAN",
92
+ "MIN",
93
+ "MV_APPEND",
94
+ "MV_AVG",
95
+ "MV_CONCAT",
96
+ "MV_COUNT",
97
+ "MV_DEDUPE",
98
+ "MV_FIRST",
99
+ "MV_LAST",
100
+ "MV_MAX",
101
+ "MV_MEDIAN_ABSOLUTE_DEVIATION",
102
+ "MV_MEDIAN",
103
+ "MV_MIN",
104
+ "MV_PERCENTILE",
105
+ "MV_PSERIES_WEIGHTED_SUM",
106
+ "MV_SLICE",
107
+ "MV_SORT",
108
+ "MV_SUM",
109
+ "MV_ZIP",
110
+ "NOW",
111
+ "PERCENTILE",
112
+ "PI",
113
+ "POW",
114
+ "QSTR",
115
+ "REPEAT",
116
+ "REPLACE",
117
+ "REVERSE",
118
+ "RIGHT",
119
+ "ROUND",
120
+ "RTRIM",
121
+ "SIGNUM",
122
+ "SIN",
123
+ "SINH",
124
+ "SPACE",
125
+ "SPLIT",
126
+ "SQRT",
127
+ "ST_CENTROID_AGG",
128
+ "ST_CONTAINS",
129
+ "ST_DISJOINT",
130
+ "ST_DISTANCE",
131
+ "ST_ENVELOPE",
132
+ "ST_EXTENT_AGG",
133
+ "ST_INTERSECTS",
134
+ "ST_WITHIN",
135
+ "ST_X",
136
+ "ST_XMAX",
137
+ "ST_XMIN",
138
+ "ST_Y",
139
+ "ST_YMAX",
140
+ "ST_YMIN",
141
+ "STARTS_WITH",
142
+ "STD_DEV",
143
+ "SUBSTRING",
144
+ "SUM",
145
+ "TAN",
146
+ "TANH",
147
+ "TAU",
148
+ "TO_BASE64",
149
+ "TO_BOOLEAN",
150
+ "TO_CARTESIANPOINT",
151
+ "TO_CARTESIANSHAPE",
152
+ "TO_DATE_NANOS",
153
+ "TO_DATEPERIOD",
154
+ "TO_DATETIME",
155
+ "TO_DEGREES",
156
+ "TO_DOUBLE",
157
+ "TO_GEOPOINT",
158
+ "TO_GEOSHAPE",
159
+ "TO_INTEGER",
160
+ "TO_IP",
161
+ "TO_LONG",
162
+ "TO_LOWER",
163
+ "TO_RADIANS",
164
+ "TO_STRING",
165
+ "TO_TIMEDURATION",
166
+ "TO_UNSIGNED_LONG",
167
+ "TO_UPPER",
168
+ "TO_VERSION",
169
+ "TOP",
170
+ "TRIM",
171
+ "VALUES",
172
+ "WEIGHTED_AVG",
173
+ ];
174
+ exports.delimiters = [
175
+ "/",
176
+ ".",
177
+ ",",
178
+ "=~",
179
+ "<=",
180
+ ">=",
181
+ "==",
182
+ "!=",
183
+ "===",
184
+ "!==",
185
+ "=>",
186
+ "+",
187
+ "-",
188
+ "**",
189
+ "*",
190
+ "/",
191
+ "%",
192
+ "++",
193
+ "--",
194
+ "<<",
195
+ "</",
196
+ ">>",
197
+ ">>>",
198
+ "&",
199
+ "|",
200
+ "^",
201
+ "!",
202
+ "~",
203
+ "&&",
204
+ "||",
205
+ "?",
206
+ ":",
207
+ "=",
208
+ "+=",
209
+ "-=",
210
+ "*=",
211
+ "**=",
212
+ "/=",
213
+ "%=",
214
+ "<<=",
215
+ ">>=",
216
+ ">>>=",
217
+ "&=",
218
+ "|=",
219
+ "^=",
220
+ "@",
221
+ ];
222
+ exports.operators = {
223
+ named: {
224
+ binary: ["AND", "OR", "IS", "IN", "AS", "LIKE", "RLIKE"],
225
+ other: ["ASC", "DESC", "FIRST", "LAST", "NULLS", "NOT"],
226
+ },
227
+ };
228
+ /**
229
+ * @see https://www.elastic.co/docs/reference/query-languages/esql/esql-time-spans#esql-time-spans-table
230
+ */
231
+ exports.temporalUnits = [
232
+ ["YEAR", "Y", "YR", "YEARS"],
233
+ ["QUARTER", "Q", "QUARTERS"],
234
+ ["MONTH", "MO", "MONTHS"],
235
+ ["WEEK", "W", "WEEKS"],
236
+ ["DAY", "D", "DAYS"],
237
+ ["HOUR", "H", "HOURS"],
238
+ ["MINUTE", "MIN", "MINUTES"],
239
+ ["SECOND", "S", "SEC", "SECONDS"],
240
+ ["MILLISECOND", "MS", "MILLISECONDS"],
241
+ ];
package/lib/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { monarchLanguage } from "./monarch";
1
+ export * as monarch from "./monarch";
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.monarchLanguage = void 0;
4
- var monarch_1 = require("./monarch");
5
- Object.defineProperty(exports, "monarchLanguage", { enumerable: true, get: function () { return monarch_1.monarchLanguage; } });
3
+ exports.monarch = void 0;
4
+ const tslib_1 = require("tslib");
5
+ exports.monarch = tslib_1.__importStar(require("./monarch"));
@@ -0,0 +1 @@
1
+ export declare const language: import("monaco-editor").languages.IMonarchLanguage;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.language = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const monarch_1 = require("./monarch");
6
+ const definitions = tslib_1.__importStar(require("./definitions"));
7
+ exports.language = (0, monarch_1.create)(definitions);
package/lib/monarch.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  import type { languages } from "monaco-editor";
2
- export declare const monarchLanguage: languages.IMonarchLanguage;
2
+ export type CreateDependencies = Partial<typeof import("./definitions")>;
3
+ export declare const create: (deps?: CreateDependencies) => languages.IMonarchLanguage;
package/lib/monarch.js CHANGED
@@ -1,360 +1,168 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.monarchLanguage = void 0;
4
- const commands = [
5
- "DISSECT",
6
- "DROP",
7
- "ENRICH",
8
- "EVAL",
9
- "EXPLAIN",
10
- "FORK",
11
- "FROM",
12
- "FULL JOIN",
13
- "GROK",
14
- "INFO",
15
- "INLINESTATS",
16
- "JOIN",
17
- "KEEP",
18
- "LEFT JOIN",
19
- "LEFT",
20
- "LIMIT",
21
- "LOOKUP JOIN",
22
- "LOOKUP",
23
- "METRICS",
24
- "MV_EXPAND",
25
- "RENAME",
26
- "RIGHT JOIN",
27
- "RIGHT",
28
- "ROW",
29
- "SHOW INFO",
30
- "SHOW",
31
- "SORT",
32
- "STATS",
33
- "WHERE",
34
- ];
35
- const options = ["BY", "ON", "WITH", "METADATA", "WHERE"];
36
- const literals = ["TRUE", "FALSE", "NULL"];
37
- const functions = [
38
- "ABS",
39
- "ACOS",
40
- "ASIN",
41
- "ATAN",
42
- "ATAN2",
43
- "AVG",
44
- "BIT_LENGTH",
45
- "BUCKET",
46
- "BYTE_LENGTH",
47
- "CASE",
48
- "CATEGORIZE",
49
- "CBRT",
50
- "CEIL",
51
- "CIDR_MATCH",
52
- "COALESCE",
53
- "CONCAT",
54
- "COS",
55
- "COSH",
56
- "COUNT_DISTINCT",
57
- "COUNT",
58
- "DATE_DIFF",
59
- "DATE_EXTRACT",
60
- "DATE_FORMAT",
61
- "DATE_PARSE",
62
- "DATE_TRUNC",
63
- "E",
64
- "ENDS_WITH",
65
- "EXP",
66
- "FLOOR",
67
- "FROM_BASE64",
68
- "GREATEST",
69
- "HASH",
70
- "HYPOT",
71
- "IP_PREFIX",
72
- "LEAST",
73
- "LEFT",
74
- "LENGTH",
75
- "LOCATE",
76
- "LOG",
77
- "LOG10",
78
- "LTRIM",
79
- "MATCH",
80
- "MAX",
81
- "MEDIAN_ABSOLUTE_DEVIATION",
82
- "MEDIAN",
83
- "MIN",
84
- "MV_APPEND",
85
- "MV_AVG",
86
- "MV_CONCAT",
87
- "MV_COUNT",
88
- "MV_DEDUPE",
89
- "MV_FIRST",
90
- "MV_LAST",
91
- "MV_MAX",
92
- "MV_MEDIAN_ABSOLUTE_DEVIATION",
93
- "MV_MEDIAN",
94
- "MV_MIN",
95
- "MV_PERCENTILE",
96
- "MV_PSERIES_WEIGHTED_SUM",
97
- "MV_SLICE",
98
- "MV_SORT",
99
- "MV_SUM",
100
- "MV_ZIP",
101
- "NOW",
102
- "PERCENTILE",
103
- "PI",
104
- "POW",
105
- "QSTR",
106
- "REPEAT",
107
- "REPLACE",
108
- "REVERSE",
109
- "RIGHT",
110
- "ROUND",
111
- "RTRIM",
112
- "SIGNUM",
113
- "SIN",
114
- "SINH",
115
- "SPACE",
116
- "SPLIT",
117
- "SQRT",
118
- "ST_CENTROID_AGG",
119
- "ST_CONTAINS",
120
- "ST_DISJOINT",
121
- "ST_DISTANCE",
122
- "ST_ENVELOPE",
123
- "ST_EXTENT_AGG",
124
- "ST_INTERSECTS",
125
- "ST_WITHIN",
126
- "ST_X",
127
- "ST_XMAX",
128
- "ST_XMIN",
129
- "ST_Y",
130
- "ST_YMAX",
131
- "ST_YMIN",
132
- "STARTS_WITH",
133
- "STD_DEV",
134
- "SUBSTRING",
135
- "SUM",
136
- "TAN",
137
- "TANH",
138
- "TAU",
139
- "TO_BASE64",
140
- "TO_BOOLEAN",
141
- "TO_CARTESIANPOINT",
142
- "TO_CARTESIANSHAPE",
143
- "TO_DATE_NANOS",
144
- "TO_DATEPERIOD",
145
- "TO_DATETIME",
146
- "TO_DEGREES",
147
- "TO_DOUBLE",
148
- "TO_GEOPOINT",
149
- "TO_GEOSHAPE",
150
- "TO_INTEGER",
151
- "TO_IP",
152
- "TO_LONG",
153
- "TO_LOWER",
154
- "TO_RADIANS",
155
- "TO_STRING",
156
- "TO_TIMEDURATION",
157
- "TO_UNSIGNED_LONG",
158
- "TO_UPPER",
159
- "TO_VERSION",
160
- "TOP",
161
- "TRIM",
162
- "VALUES",
163
- "WEIGHTED_AVG",
164
- ];
165
- const delimiters = [
166
- "/",
167
- ".",
168
- ",",
169
- "=~",
170
- "<=",
171
- ">=",
172
- "==",
173
- "!=",
174
- "===",
175
- "!==",
176
- "=>",
177
- "+",
178
- "-",
179
- "**",
180
- "*",
181
- "/",
182
- "%",
183
- "++",
184
- "--",
185
- "<<",
186
- "</",
187
- ">>",
188
- ">>>",
189
- "&",
190
- "|",
191
- "^",
192
- "!",
193
- "~",
194
- "&&",
195
- "||",
196
- "?",
197
- ":",
198
- "=",
199
- "+=",
200
- "-=",
201
- "*=",
202
- "**=",
203
- "/=",
204
- "%=",
205
- "<<=",
206
- ">>=",
207
- ">>>=",
208
- "&=",
209
- "|=",
210
- "^=",
211
- "@",
212
- ];
213
- const binaryNamedOperators = ["AND", "OR", "IS", "IN", "AS", "LIKE", "RLIKE"];
214
- const otherNamedOperators = ["ASC", "DESC", "FIRST", "LAST", "NULLS", "NOT"];
215
- exports.monarchLanguage = {
216
- // Uncomment when developing.
217
- // defaultToken: "invalid",
218
- // ES|QL is case-insensitive.
219
- ignoreCase: true,
220
- // Lists of known language keywords and built-ins.
221
- commands,
222
- options,
223
- literals,
224
- functions,
225
- delimiters,
226
- namedOperators: [...binaryNamedOperators, ...otherNamedOperators],
227
- // Pre-defined regular expressions.
228
- escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
229
- digits: /\d+(_+\d+)*/,
230
- brackets: [
231
- { open: "[", close: "]", token: "delimiter.square" },
232
- { open: "(", close: ")", token: "delimiter.parenthesis" },
233
- { open: "{", close: "}", token: "delimiter.curly" },
234
- { open: "<", close: ">", token: "delimiter.angle" },
235
- ],
236
- tokenizer: {
237
- root: [
238
- { include: "@whitespace" },
239
- // Keywords
240
- [
241
- /[a-zA-Z_$][\w$]*/,
242
- {
243
- cases: {
244
- "@commands": { token: "keyword.command.$0" },
245
- "@options": { token: "keyword.option.$0" },
246
- "@literals": { token: "keyword.literal.$0" },
247
- "@functions": { token: "identifier.function.$0" },
248
- "@namedOperators": { token: "keyword.operator.$0" },
249
- "@default": "identifier",
3
+ exports.create = void 0;
4
+ const create = (deps = {}) => {
5
+ const { sourceCommands = [], processingCommands = [], options = [], literals = [], functions = [], delimiters = [], temporalUnits = [], } = deps;
6
+ const timeUnits = temporalUnits.flat().sort((a, b) => (a > b ? -1 : 1));
7
+ return {
8
+ // Uncomment when developing.
9
+ // defaultToken: "invalid",
10
+ // ES|QL is case-insensitive.
11
+ ignoreCase: true,
12
+ // Lists of known language keywords and built-ins.
13
+ sourceCommands,
14
+ processingCommands,
15
+ options,
16
+ literals,
17
+ functions,
18
+ delimiters,
19
+ namedOperators: [
20
+ ...(deps.operators?.named?.binary ?? []),
21
+ ...(deps.operators?.named?.other ?? []),
22
+ ],
23
+ // Pre-defined regular expressions.
24
+ escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
25
+ digits: /\d+(_+\d+)*/,
26
+ brackets: [
27
+ { open: "[", close: "]", token: "delimiter.square" },
28
+ { open: "(", close: ")", token: "delimiter.parenthesis" },
29
+ { open: "{", close: "}", token: "delimiter.curly" },
30
+ { open: "<", close: ">", token: "delimiter.angle" },
31
+ ],
32
+ tokenizer: {
33
+ root: [
34
+ { include: "@whitespace" },
35
+ // Keywords
36
+ [
37
+ /[a-zA-Z_$][\w$]*/,
38
+ {
39
+ cases: {
40
+ "@sourceCommands": { token: "keyword.command.source.$0" },
41
+ "@processingCommands": { token: "keyword.command.processing.$0" },
42
+ "@options": { token: "keyword.option.$0" },
43
+ "@literals": { token: "keyword.literal.$0" },
44
+ "@functions": { token: "identifier.function.$0" },
45
+ "@namedOperators": { token: "keyword.operator.$0" },
46
+ "@default": "identifier",
47
+ },
250
48
  },
251
- },
252
- ],
253
- { include: "@expression" },
254
- { include: "@processingCommand" },
255
- [/\[|\(|\)|\]/, "@brackets"],
256
- [
257
- /[^\s]+/,
258
- {
259
- cases: {
260
- "@delimiters": "delimiter",
49
+ ],
50
+ { include: "@expression" },
51
+ { include: "@processingCommand" },
52
+ [/\[|\(|\)|\]/, "@brackets"],
53
+ [
54
+ /[^\s]+/,
55
+ {
56
+ cases: {
57
+ "@delimiters": "delimiter",
58
+ },
261
59
  },
262
- },
60
+ ],
263
61
  ],
264
- ],
265
- // --------------------------------- Hidden channel: whitespace and comments
266
- whitespace: [
267
- [/[ \t\r\n]+/, ""],
268
- [/\/\*\*(?!\/)/, "comment.doc", "@doc"],
269
- [/\/\*/, "comment", "@comment"],
270
- [/\/\/.*$/, "comment"],
271
- ],
272
- comment: [
273
- [/[^\/*]+/, "comment"],
274
- [/\*\//, "comment", "@pop"],
275
- [/[\/*]/, "comment"],
276
- ],
277
- doc: [
278
- [/[^\/*]+/, "comment.doc"],
279
- [/\*\//, "comment.doc", "@pop"],
280
- [/[\/*]/, "comment.doc"],
281
- ],
282
- // ---------------------------------------------------------------- Commands
283
- // This code block allows to color commands when they are followed by a pipe
284
- // character "|", this way all new processing commands are color even if
285
- // they are not part of the command name list.
286
- processingCommand: [
287
- [
288
- /\|/,
289
- { token: "delimiter.pipe", switchTo: "@beforeMnemonicWhitespace" },
62
+ // --------------------------------- Hidden channel: whitespace and comments
63
+ whitespace: [
64
+ [/[ \t\r\n]+/, ""],
65
+ [/\/\*\*(?!\/)/, "comment.doc", "@doc"],
66
+ [/\/\*/, "comment", "@comment"],
67
+ [/\/\/.*$/, "comment"],
290
68
  ],
291
- ],
292
- beforeMnemonicWhitespace: [
293
- { include: "@whitespace" },
294
- ["", { token: "", switchTo: "@commandName" }],
295
- ],
296
- // Matches *command name*, i.e. the mnemonic.
297
- commandName: [
298
- // First tries to match all known command names.
299
- [
300
- commands.join("|"),
301
- { token: "keyword.command.name", switchTo: "@root" },
69
+ comment: [
70
+ [/[^\/*]+/, "comment"],
71
+ [/\*\//, "comment", "@pop"],
72
+ [/[\/*]/, "comment"],
302
73
  ],
303
- // If command name is not well known, just matches the first word.
304
- [/\w+\b/, { token: "keyword.command.name", switchTo: "@root" }],
305
- ],
306
- // ------------------------------------------------------------- Expressions
307
- expression: [
308
- { include: "@whitespace" },
309
- { include: "@literal" },
310
- // Inline casts: 1.3::INTEGER
311
- [/::\w+\b/, "type"],
312
- // strings
313
- [/"""/, "string.triple", "@string_triple"],
314
- [/"([^"\\]|\\.)*$/, "string.invalid"], // non-terminated string
315
- [/'([^'\\]|\\.)*$/, "string.invalid"], // non-terminated string
316
- [/"/, "string", "@string"],
317
- // Escaped column parts: nested.`escaped`.column
318
- [/`/, "string", "@column_escape_part"],
319
- ],
320
- literal: [
321
- { include: "@number" },
322
- // Params
323
- [
324
- /\?{1,9}(([a-zA-Z_][a-zA-Z_0-9]+)|[0-9]+)?/,
325
- {
326
- cases: {
327
- "\\?{1,9}": "variable.name.unnamed",
328
- "\\?{1,9}([a-zA-Z_][a-zA-Z_0-9]+)?": "variable.name.named",
329
- "\\?{1,9}([0-9]+)?": "variable.name.positional",
74
+ doc: [
75
+ [/[^\/*]+/, "comment.doc"],
76
+ [/\*\//, "comment.doc", "@pop"],
77
+ [/[\/*]/, "comment.doc"],
78
+ ],
79
+ // ---------------------------------------------------------------- Commands
80
+ // This code block allows to color commands when they are followed by a pipe
81
+ // character "|", this way all new processing commands are color even if
82
+ // they are not part of the command name list.
83
+ processingCommand: [
84
+ [
85
+ /\|/,
86
+ { token: "delimiter.pipe", switchTo: "@beforeMnemonicWhitespace" },
87
+ ],
88
+ ],
89
+ beforeMnemonicWhitespace: [
90
+ { include: "@whitespace" },
91
+ ["", { token: "", switchTo: "@commandName" }],
92
+ ],
93
+ // Matches *command name*, i.e. the mnemonic.
94
+ commandName: [
95
+ // First tries to match all known command names.
96
+ [
97
+ sourceCommands.join("|"),
98
+ { token: "keyword.command.source.$0", switchTo: "@root" },
99
+ ],
100
+ [
101
+ processingCommands.join("|"),
102
+ { token: "keyword.command.processing.$0", switchTo: "@root" },
103
+ ],
104
+ // If command name is not well known, just matches the first word.
105
+ [
106
+ /\w+\b/,
107
+ { token: "keyword.command.processing.$0", switchTo: "@root" },
108
+ ],
109
+ ],
110
+ // ------------------------------------------------------------- Expressions
111
+ expression: [
112
+ { include: "@whitespace" },
113
+ { include: "@literal" },
114
+ // Inline casts: 1.3::INTEGER
115
+ [/::\w+\b/, "type"],
116
+ // strings
117
+ [/"""/, "string.triple", "@string_triple"],
118
+ [/"([^"\\]|\\.)*$/, "string.invalid"], // non-terminated string
119
+ [/'([^'\\]|\\.)*$/, "string.invalid"], // non-terminated string
120
+ [/"/, "string", "@string"],
121
+ // Escaped column parts: nested.`escaped`.column
122
+ [/`/, "string", "@column_escape_part"],
123
+ ],
124
+ literal: [
125
+ { include: "@timeInterval" },
126
+ { include: "@number" },
127
+ // Params
128
+ [
129
+ /\?{1,9}(([a-zA-Z_][a-zA-Z_0-9]+)|[0-9]+)?/,
130
+ {
131
+ cases: {
132
+ "\\?{1,9}": "variable.name.unnamed",
133
+ "\\?{1,9}([a-zA-Z_][a-zA-Z_0-9]+)?": "variable.name.named",
134
+ "\\?{1,9}([0-9]+)?": "variable.name.positional",
135
+ },
330
136
  },
331
- },
137
+ ],
332
138
  ],
333
- ],
334
- number: [
335
- [/(@digits)[eE]([\-+]?(@digits))?/, "number.float"],
336
- [/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, "number.float"],
337
- [/(@digits)/, "number"],
338
- ],
339
- // Single double-quote strings: "str"
340
- string: [
341
- [/[^\\"]+/, "string"],
342
- [/@escapes/, "string.escape"],
343
- [/\\./, "string.escape.invalid"],
344
- [/"/, "string", "@pop"],
345
- ],
346
- // Triple double-quoted strings: """str"""
347
- string_triple: [
348
- [/"""/, "string.triple", "@pop"],
349
- [/[^"]+/, "string.triple"],
350
- ],
351
- // Backtick quoted "strings". ES|QL does not have back-tick "strings"
352
- // *per se*, but column parts can have backtick-escaped parts.
353
- column_escape_part: [
354
- [/[^`]+/, "string"],
355
- [/@escapes/, "string.escape"],
356
- [/\\./, "string.escape.invalid"],
357
- [/`/, "string", "@pop"],
358
- ],
359
- },
139
+ timeInterval: [[`(@digits)\\s*(${timeUnits.join("|")})`, "number.time"]],
140
+ number: [
141
+ [/(@digits)[eE]([\-+]?(@digits))?/, "number.float"],
142
+ [/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, "number.float"],
143
+ [/(@digits)/, "number"],
144
+ ],
145
+ // Single double-quote strings: "str"
146
+ string: [
147
+ [/[^\\"]+/, "string"],
148
+ [/@escapes/, "string.escape"],
149
+ [/\\./, "string.escape.invalid"],
150
+ [/"/, "string", "@pop"],
151
+ ],
152
+ // Triple double-quoted strings: """str"""
153
+ string_triple: [
154
+ [/"""/, "string.triple", "@pop"],
155
+ [/[^"]+/, "string.triple"],
156
+ ],
157
+ // Backtick quoted "strings". ES|QL does not have back-tick "strings"
158
+ // *per se*, but column parts can have backtick-escaped parts.
159
+ column_escape_part: [
160
+ [/[^`]+/, "string"],
161
+ [/@escapes/, "string.escape"],
162
+ [/\\./, "string.escape.invalid"],
163
+ [/`/, "string", "@pop"],
164
+ ],
165
+ },
166
+ };
360
167
  };
168
+ exports.create = create;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elastic/monaco-esql",
3
- "version": "1.1.0",
3
+ "version": "3.0.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"