@elastic/monaco-esql 2.0.0 → 3.1.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 +1 -1
- package/lib/definitions.d.ts +7 -1
- package/lib/definitions.js +30 -7
- package/lib/monarch.js +23 -8
- package/package.json +1 -1
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);
|
package/lib/definitions.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const sourceCommands: string[];
|
|
2
|
+
export declare const processingCommands: string[];
|
|
2
3
|
export declare const options: string[];
|
|
3
4
|
export declare const literals: string[];
|
|
4
5
|
export declare const functions: string[];
|
|
@@ -9,3 +10,8 @@ export declare const operators: {
|
|
|
9
10
|
other: string[];
|
|
10
11
|
};
|
|
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[];
|
package/lib/definitions.js
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.operators = exports.delimiters = exports.functions = exports.literals = exports.options = exports.
|
|
4
|
-
exports.
|
|
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",
|
|
5
15
|
"DISSECT",
|
|
6
16
|
"DROP",
|
|
7
17
|
"ENRICH",
|
|
8
18
|
"EVAL",
|
|
9
|
-
"EXPLAIN",
|
|
10
19
|
"FORK",
|
|
11
|
-
"
|
|
20
|
+
"FORK",
|
|
12
21
|
"FULL JOIN",
|
|
13
22
|
"GROK",
|
|
14
23
|
"INFO",
|
|
15
24
|
"INLINESTATS",
|
|
25
|
+
"INSIST",
|
|
16
26
|
"JOIN",
|
|
17
27
|
"KEEP",
|
|
18
28
|
"LEFT JOIN",
|
|
@@ -23,11 +33,10 @@ exports.commands = [
|
|
|
23
33
|
"METRICS",
|
|
24
34
|
"MV_EXPAND",
|
|
25
35
|
"RENAME",
|
|
36
|
+
"RERANK",
|
|
26
37
|
"RIGHT JOIN",
|
|
27
38
|
"RIGHT",
|
|
28
|
-
"
|
|
29
|
-
"SHOW INFO",
|
|
30
|
-
"SHOW",
|
|
39
|
+
"RRF",
|
|
31
40
|
"SORT",
|
|
32
41
|
"STATS",
|
|
33
42
|
"WHERE",
|
|
@@ -216,3 +225,17 @@ exports.operators = {
|
|
|
216
225
|
other: ["ASC", "DESC", "FIRST", "LAST", "NULLS", "NOT"],
|
|
217
226
|
},
|
|
218
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/monarch.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.create = void 0;
|
|
4
4
|
const create = (deps = {}) => {
|
|
5
|
-
const {
|
|
5
|
+
const { sourceCommands = [], processingCommands = [], options = [], literals = [], functions = [], delimiters = [], temporalUnits = [], } = deps;
|
|
6
|
+
const timeUnits = temporalUnits.flat().sort((a, b) => (a > b ? -1 : 1));
|
|
6
7
|
return {
|
|
7
8
|
// Uncomment when developing.
|
|
8
9
|
// defaultToken: "invalid",
|
|
9
10
|
// ES|QL is case-insensitive.
|
|
10
11
|
ignoreCase: true,
|
|
11
12
|
// Lists of known language keywords and built-ins.
|
|
12
|
-
|
|
13
|
+
sourceCommands,
|
|
14
|
+
processingCommands,
|
|
13
15
|
options,
|
|
14
16
|
literals,
|
|
15
17
|
functions,
|
|
@@ -21,6 +23,7 @@ const create = (deps = {}) => {
|
|
|
21
23
|
// Pre-defined regular expressions.
|
|
22
24
|
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
|
|
23
25
|
digits: /\d+(_+\d+)*/,
|
|
26
|
+
symbols: /[=><!~:&|+\-*\/\^%\.,]+/,
|
|
24
27
|
brackets: [
|
|
25
28
|
{ open: "[", close: "]", token: "delimiter.square" },
|
|
26
29
|
{ open: "(", close: ")", token: "delimiter.parenthesis" },
|
|
@@ -32,14 +35,16 @@ const create = (deps = {}) => {
|
|
|
32
35
|
{ include: "@whitespace" },
|
|
33
36
|
// Keywords
|
|
34
37
|
[
|
|
35
|
-
|
|
38
|
+
/@?[a-zA-Z_$][\w$]*/,
|
|
36
39
|
{
|
|
37
40
|
cases: {
|
|
38
|
-
"@
|
|
41
|
+
"@sourceCommands": { token: "keyword.command.source.$0" },
|
|
42
|
+
"@processingCommands": { token: "keyword.command.processing.$0" },
|
|
39
43
|
"@options": { token: "keyword.option.$0" },
|
|
40
44
|
"@literals": { token: "keyword.literal.$0" },
|
|
41
45
|
"@functions": { token: "identifier.function.$0" },
|
|
42
46
|
"@namedOperators": { token: "keyword.operator.$0" },
|
|
47
|
+
"\\@{1}timestamp": "identifier.timestamp",
|
|
43
48
|
"@default": "identifier",
|
|
44
49
|
},
|
|
45
50
|
},
|
|
@@ -48,10 +53,11 @@ const create = (deps = {}) => {
|
|
|
48
53
|
{ include: "@processingCommand" },
|
|
49
54
|
[/\[|\(|\)|\]/, "@brackets"],
|
|
50
55
|
[
|
|
51
|
-
|
|
56
|
+
/@symbols/,
|
|
52
57
|
{
|
|
53
58
|
cases: {
|
|
54
59
|
"@delimiters": "delimiter",
|
|
60
|
+
"@default": "",
|
|
55
61
|
},
|
|
56
62
|
},
|
|
57
63
|
],
|
|
@@ -91,11 +97,18 @@ const create = (deps = {}) => {
|
|
|
91
97
|
commandName: [
|
|
92
98
|
// First tries to match all known command names.
|
|
93
99
|
[
|
|
94
|
-
|
|
95
|
-
{ token: "keyword.command.
|
|
100
|
+
sourceCommands.join("|"),
|
|
101
|
+
{ token: "keyword.command.source.$0", switchTo: "@root" },
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
processingCommands.join("|"),
|
|
105
|
+
{ token: "keyword.command.processing.$0", switchTo: "@root" },
|
|
96
106
|
],
|
|
97
107
|
// If command name is not well known, just matches the first word.
|
|
98
|
-
[
|
|
108
|
+
[
|
|
109
|
+
/\w+\b/,
|
|
110
|
+
{ token: "keyword.command.processing.$0", switchTo: "@root" },
|
|
111
|
+
],
|
|
99
112
|
],
|
|
100
113
|
// ------------------------------------------------------------- Expressions
|
|
101
114
|
expression: [
|
|
@@ -112,6 +125,7 @@ const create = (deps = {}) => {
|
|
|
112
125
|
[/`/, "string", "@column_escape_part"],
|
|
113
126
|
],
|
|
114
127
|
literal: [
|
|
128
|
+
{ include: "@timeInterval" },
|
|
115
129
|
{ include: "@number" },
|
|
116
130
|
// Params
|
|
117
131
|
[
|
|
@@ -125,6 +139,7 @@ const create = (deps = {}) => {
|
|
|
125
139
|
},
|
|
126
140
|
],
|
|
127
141
|
],
|
|
142
|
+
timeInterval: [[`(@digits)\\s*(${timeUnits.join("|")})`, "number.time"]],
|
|
128
143
|
number: [
|
|
129
144
|
[/(@digits)[eE]([\-+]?(@digits))?/, "number.float"],
|
|
130
145
|
[/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, "number.float"],
|