@elastic/monaco-esql 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Elastic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # ES|QL syntax grammar for Monaco editor
2
+
3
+ This package contains the ES|QL grammar form Monarch (the Monaco editor grammar engine).
4
+
5
+
6
+ ## Usage
7
+
8
+ To highlight ES|QL code in Monaco editor, you need to register ES|QL language
9
+ and its Monarch grammar:
10
+
11
+ ```js
12
+ import { monarchLanguage } from '@elastic/monaco-esql';
13
+
14
+ monaco.languages.register({id: 'esql'});
15
+ monaco.languages.setMonarchTokensProvider('esql', monarchLanguage);
16
+ ```
17
+
18
+
19
+ ## Releasing
20
+
21
+ Publish with `release-it` tool:
22
+
23
+ ```
24
+ npx release-it
25
+ ```
26
+
27
+
28
+ ## License
29
+
30
+ MIT
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { monarchLanguage } from "./monarch";
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
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; } });
@@ -0,0 +1,2 @@
1
+ import type { languages } from "monaco-editor";
2
+ export declare const monarchLanguage: languages.IMonarchLanguage;
package/lib/monarch.js ADDED
@@ -0,0 +1,360 @@
1
+ "use strict";
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
+ "FROM",
11
+ "FULL JOIN",
12
+ "GROK",
13
+ "INFO",
14
+ "INLINESTATS",
15
+ "JOIN",
16
+ "KEEP",
17
+ "LEFT JOIN",
18
+ "LEFT",
19
+ "LIMIT",
20
+ "LOOKUP JOIN",
21
+ "LOOKUP",
22
+ "METRICS",
23
+ "MV_EXPAND",
24
+ "RENAME",
25
+ "RIGHT JOIN",
26
+ "RIGHT",
27
+ "ROW",
28
+ "SHOW INFO",
29
+ "SHOW",
30
+ "SORT",
31
+ "STATS",
32
+ "WHERE",
33
+ ];
34
+ const options = ["BY", "ON", "WITH", "METADATA", "WHERE"];
35
+ const literals = ["TRUE", "FALSE", "NULL"];
36
+ const functions = [
37
+ "ABS",
38
+ "ACOS",
39
+ "ASIN",
40
+ "ATAN",
41
+ "ATAN2",
42
+ "AVG",
43
+ "BIT_LENGTH",
44
+ "BUCKET",
45
+ "BYTE_LENGTH",
46
+ "CASE",
47
+ "CATEGORIZE",
48
+ "CBRT",
49
+ "CEIL",
50
+ "CIDR_MATCH",
51
+ "COALESCE",
52
+ "CONCAT",
53
+ "COS",
54
+ "COSH",
55
+ "COUNT_DISTINCT",
56
+ "COUNT",
57
+ "DATE_DIFF",
58
+ "DATE_EXTRACT",
59
+ "DATE_FORMAT",
60
+ "DATE_PARSE",
61
+ "DATE_TRUNC",
62
+ "E",
63
+ "ENDS_WITH",
64
+ "EXP",
65
+ "FLOOR",
66
+ "FROM_BASE64",
67
+ "GREATEST",
68
+ "HASH",
69
+ "HYPOT",
70
+ "IP_PREFIX",
71
+ "LEAST",
72
+ "LEFT",
73
+ "LENGTH",
74
+ "LOCATE",
75
+ "LOG",
76
+ "LOG10",
77
+ "LTRIM",
78
+ "MATCH",
79
+ "MAX",
80
+ "MEDIAN_ABSOLUTE_DEVIATION",
81
+ "MEDIAN",
82
+ "MIN",
83
+ "MV_APPEND",
84
+ "MV_AVG",
85
+ "MV_CONCAT",
86
+ "MV_COUNT",
87
+ "MV_DEDUPE",
88
+ "MV_FIRST",
89
+ "MV_LAST",
90
+ "MV_MAX",
91
+ "MV_MEDIAN_ABSOLUTE_DEVIATION",
92
+ "MV_MEDIAN",
93
+ "MV_MIN",
94
+ "MV_PERCENTILE",
95
+ "MV_PSERIES_WEIGHTED_SUM",
96
+ "MV_SLICE",
97
+ "MV_SORT",
98
+ "MV_SUM",
99
+ "MV_ZIP",
100
+ "NOW",
101
+ "PERCENTILE",
102
+ "PI",
103
+ "POW",
104
+ "QSTR",
105
+ "REPEAT",
106
+ "REPLACE",
107
+ "REVERSE",
108
+ "RIGHT",
109
+ "ROUND",
110
+ "RTRIM",
111
+ "SIGNUM",
112
+ "SIN",
113
+ "SINH",
114
+ "SPACE",
115
+ "SPLIT",
116
+ "SQRT",
117
+ "ST_CENTROID_AGG",
118
+ "ST_CONTAINS",
119
+ "ST_DISJOINT",
120
+ "ST_DISTANCE",
121
+ "ST_ENVELOPE",
122
+ "ST_EXTENT_AGG",
123
+ "ST_INTERSECTS",
124
+ "ST_WITHIN",
125
+ "ST_X",
126
+ "ST_XMAX",
127
+ "ST_XMIN",
128
+ "ST_Y",
129
+ "ST_YMAX",
130
+ "ST_YMIN",
131
+ "STARTS_WITH",
132
+ "STD_DEV",
133
+ "SUBSTRING",
134
+ "SUM",
135
+ "TAN",
136
+ "TANH",
137
+ "TAU",
138
+ "TO_BASE64",
139
+ "TO_BOOLEAN",
140
+ "TO_CARTESIANPOINT",
141
+ "TO_CARTESIANSHAPE",
142
+ "TO_DATE_NANOS",
143
+ "TO_DATEPERIOD",
144
+ "TO_DATETIME",
145
+ "TO_DEGREES",
146
+ "TO_DOUBLE",
147
+ "TO_GEOPOINT",
148
+ "TO_GEOSHAPE",
149
+ "TO_INTEGER",
150
+ "TO_IP",
151
+ "TO_LONG",
152
+ "TO_LOWER",
153
+ "TO_RADIANS",
154
+ "TO_STRING",
155
+ "TO_TIMEDURATION",
156
+ "TO_UNSIGNED_LONG",
157
+ "TO_UPPER",
158
+ "TO_VERSION",
159
+ "TOP",
160
+ "TRIM",
161
+ "VALUES",
162
+ "WEIGHTED_AVG",
163
+ ];
164
+ const delimiters = [
165
+ "/",
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
+ const binaryNamedOperators = ["AND", "OR", "IS", "IN", "AS", "LIKE", "RLIKE"];
213
+ const otherNamedOperators = ["ASC", "DESC", "FIRST", "LAST", "NULLS", "NOT"];
214
+ exports.monarchLanguage = {
215
+ // Uncomment when developing.
216
+ // defaultToken: "invalid",
217
+ // ES|QL is case-insensitive.
218
+ ignoreCase: true,
219
+ // Lists of known language keywords and built-ins.
220
+ commands,
221
+ options,
222
+ literals,
223
+ functions,
224
+ delimiters,
225
+ namedOperators: [...binaryNamedOperators, ...otherNamedOperators],
226
+ // Pre-defined regular expressions.
227
+ escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
228
+ digits: /\d+(_+\d+)*/,
229
+ brackets: [
230
+ { open: "[", close: "]", token: "delimiter.square" },
231
+ { open: "(", close: ")", token: "delimiter.parenthesis" },
232
+ { open: "{", close: "}", token: "delimiter.curly" },
233
+ { open: "<", close: ">", token: "delimiter.angle" },
234
+ ],
235
+ tokenizer: {
236
+ root: [
237
+ { include: "@whitespace" },
238
+ // Keywords
239
+ [
240
+ /[a-zA-Z_$][\w$]*/,
241
+ {
242
+ cases: {
243
+ "@commands": { token: "keyword.command.$0" },
244
+ "@options": { token: "keyword.option.$0" },
245
+ "@literals": { token: "keyword.literal.$0" },
246
+ "@functions": { token: "identifier.function.$0" },
247
+ "@delimiters": { token: "delimiter" },
248
+ "@namedOperators": { token: "keyword.operator.$0" },
249
+ "@default": "identifier",
250
+ },
251
+ },
252
+ ],
253
+ { include: "@expression" },
254
+ { include: "@processingCommand" },
255
+ [/\[|\(|\)|\]/, "@brackets"],
256
+ ],
257
+ // --------------------------------- Hidden channel: whitespace and comments
258
+ whitespace: [
259
+ [/[ \t\r\n]+/, ""],
260
+ [/\/\*\*(?!\/)/, "comment.doc", "@doc"],
261
+ [/\/\*/, "comment", "@comment"],
262
+ [/\/\/.*$/, "comment"],
263
+ ],
264
+ comment: [
265
+ [/[^\/*]+/, "comment"],
266
+ [/\*\//, "comment", "@pop"],
267
+ [/[\/*]/, "comment"],
268
+ ],
269
+ doc: [
270
+ [/[^\/*]+/, "comment.doc"],
271
+ [/\*\//, "comment.doc", "@pop"],
272
+ [/[\/*]/, "comment.doc"],
273
+ ],
274
+ // ---------------------------------------------------------------- Commands
275
+ // This code block allows to color commands when they are followed by a pipe
276
+ // character "|", this way all new processing commands are color even if
277
+ // they are not part of the command name list.
278
+ processingCommand: [
279
+ [
280
+ /\|/,
281
+ { token: "delimiter.pipe", switchTo: "@beforeMnemonicWhitespace" },
282
+ ],
283
+ ],
284
+ beforeMnemonicWhitespace: [
285
+ { include: "@whitespace" },
286
+ ["", { token: "", switchTo: "@commandName" }],
287
+ ],
288
+ // Matches *command name*, i.e. the mnemonic.
289
+ commandName: [
290
+ // First tries to match all known command names.
291
+ [
292
+ commands.join("|"),
293
+ { token: "keyword.command.name", switchTo: "@root" },
294
+ ],
295
+ // If command name is not well known, just matches the first word.
296
+ [/\w+\b/, { token: "keyword.command.name", switchTo: "@root" }],
297
+ ],
298
+ // ------------------------------------------------------------- Expressions
299
+ expression: [
300
+ { include: "@whitespace" },
301
+ { include: "@literal" },
302
+ // Inline casts: 1.3::INTEGER
303
+ [/::\w+\b/, "type"],
304
+ // strings
305
+ [/"""/, "string.triple", "@string_triple"],
306
+ [/"([^"\\]|\\.)*$/, "string.invalid"], // non-terminated string
307
+ [/'([^'\\]|\\.)*$/, "string.invalid"], // non-terminated string
308
+ [/"/, "string", "@string"],
309
+ // Escaped column parts: nested.`escaped`.column
310
+ [/`/, "string", "@column_escape_part"],
311
+ // Source index pattern date-math expression: <logs-{now/d}>
312
+ [/</, "string", "@datemath_source"],
313
+ ],
314
+ literal: [
315
+ { include: "@number" },
316
+ // Params
317
+ [
318
+ /\?{1,9}(([a-zA-Z_][a-zA-Z_0-9]+)|[0-9]+)?/,
319
+ {
320
+ cases: {
321
+ "\\?{1,9}": "variable.name.unnamed",
322
+ "\\?{1,9}([a-zA-Z_][a-zA-Z_0-9]+)?": "variable.name.named",
323
+ "\\?{1,9}([0-9]+)?": "variable.name.positional",
324
+ },
325
+ },
326
+ ],
327
+ ],
328
+ number: [
329
+ [/(@digits)[eE]([\-+]?(@digits))?/, "number.float"],
330
+ [/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, "number.float"],
331
+ [/(@digits)/, "number"],
332
+ ],
333
+ // Single double-quote strings: "str"
334
+ string: [
335
+ [/[^\\"]+/, "string"],
336
+ [/@escapes/, "string.escape"],
337
+ [/\\./, "string.escape.invalid"],
338
+ [/"/, "string", "@pop"],
339
+ ],
340
+ // Triple double-quoted strings: """str"""
341
+ string_triple: [
342
+ [/"""/, "string.triple", "@pop"],
343
+ [/[^"]+/, "string.triple"],
344
+ ],
345
+ // Backtick quoted "strings". ES|QL does not have back-tick "strings"
346
+ // *per se*, but column parts can have backtick-escaped parts.
347
+ column_escape_part: [
348
+ [/[^`]+/, "string"],
349
+ [/@escapes/, "string.escape"],
350
+ [/\\./, "string.escape.invalid"],
351
+ [/`/, "string", "@pop"],
352
+ ],
353
+ datemath_source: [
354
+ [/[^>]+/, "string"],
355
+ [/@escapes/, "string.escape"],
356
+ [/\\./, "string.escape.invalid"],
357
+ [/>/, "string", "@pop"],
358
+ ],
359
+ },
360
+ };
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@elastic/monaco-esql",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "description": "Monaco editor Monarch language syntax definitions for ES|QL",
9
+ "main": "lib/index.js",
10
+ "files": [
11
+ "LICENSE",
12
+ "lib/"
13
+ ],
14
+ "scripts": {
15
+ "format": "biome format ./src",
16
+ "format:fix": "biome format --write ./src",
17
+ "lint": "biome lint ./src",
18
+ "lint:fix": "biome lint --apply ./src",
19
+ "test": "echo \"no tests...\"",
20
+ "clean": "npx rimraf@5.0.5 lib",
21
+ "build:es2020": "tsc --project tsconfig.build.json --module commonjs --target es2020 --outDir lib",
22
+ "build": "yarn build:es2020",
23
+ "storybook": "storybook dev -p 6006",
24
+ "build-storybook": "storybook build"
25
+ },
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/elastic/highlightjs-esql.git"
30
+ },
31
+ "keywords": [
32
+ "esql",
33
+ "es|ql",
34
+ "elastic",
35
+ "search processing language",
36
+ "eql",
37
+ "monacor",
38
+ "monarch",
39
+ "vscode",
40
+ "code",
41
+ "syntax"
42
+ ],
43
+ "bugs": {
44
+ "url": "https://github.com/elastic/monaco-esql/issues"
45
+ },
46
+ "homepage": "https://github.com/elastic/monaco-esql",
47
+ "peerDependencies": {
48
+ "monaco-editor": "*"
49
+ },
50
+ "devDependencies": {
51
+ "@biomejs/biome": "^1.9.4",
52
+ "@chromatic-com/storybook": "^3.2.5",
53
+ "@monaco-editor/react": "^4.7.0",
54
+ "@storybook/addon-essentials": "^8.6.3",
55
+ "@storybook/addon-onboarding": "^8.6.3",
56
+ "@storybook/blocks": "^8.6.3",
57
+ "@storybook/experimental-addon-test": "^8.6.3",
58
+ "@storybook/react": "^8.6.3",
59
+ "@storybook/react-vite": "^8.6.3",
60
+ "@storybook/test": "^8.6.3",
61
+ "@vitest/browser": "^3.0.7",
62
+ "@vitest/coverage-v8": "^3.0.7",
63
+ "monaco-editor": "^0.52.2",
64
+ "playwright": "^1.50.1",
65
+ "storybook": "^8.6.3",
66
+ "typescript": "^5.7.3",
67
+ "vitest": "^3.0.7"
68
+ },
69
+ "dependencies": {
70
+ "@types/react": "^19.0.10",
71
+ "react": "^19.0.0",
72
+ "react-dom": "^19.0.0"
73
+ }
74
+ }