@malloy-publisher/sdk 0.0.1
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/.eslintrc +36 -0
- package/.prettierrc +4 -0
- package/README.md +1 -0
- package/openapitools.json +7 -0
- package/package.json +63 -0
- package/src/assets/img/spinner.svg +43 -0
- package/src/client/.openapi-generator/FILES +9 -0
- package/src/client/.openapi-generator/VERSION +1 -0
- package/src/client/.openapi-generator-ignore +23 -0
- package/src/client/api.ts +1170 -0
- package/src/client/base.ts +86 -0
- package/src/client/common.ts +150 -0
- package/src/client/configuration.ts +110 -0
- package/src/client/git_push.sh +57 -0
- package/src/client/index.ts +18 -0
- package/src/components/DOMElement/DOMElement.tsx +19 -0
- package/src/components/DOMElement/index.ts +1 -0
- package/src/components/Model/Model.tsx +110 -0
- package/src/components/Model/ModelCell.tsx +175 -0
- package/src/components/Model/index.ts +1 -0
- package/src/components/Notebook/Notebook.tsx +82 -0
- package/src/components/Notebook/NotebookCell.tsx +194 -0
- package/src/components/Notebook/index.ts +1 -0
- package/src/components/Package/Config.tsx +99 -0
- package/src/components/Package/Databases.tsx +75 -0
- package/src/components/Package/FileTreeView.tsx +224 -0
- package/src/components/Package/Models.tsx +77 -0
- package/src/components/Package/Package.tsx +78 -0
- package/src/components/Package/index.ts +1 -0
- package/src/components/Project/About.tsx +56 -0
- package/src/components/Project/Packages.tsx +105 -0
- package/src/components/Project/Project.tsx +26 -0
- package/src/components/Project/index.ts +1 -0
- package/src/components/QueryResult/QueryResult.tsx +84 -0
- package/src/components/QueryResult/index.ts +1 -0
- package/src/components/RenderedResult/RenderedResult.tsx +38 -0
- package/src/components/highlighter.ts +649 -0
- package/src/components/index.ts +5 -0
- package/src/components/styles.ts +21 -0
- package/src/index.ts +1 -0
- package/src/react-app-env.d.ts +73 -0
- package/tsconfig.json +34 -0
- package/vite.config.ts +31 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable react/prop-types */
|
|
2
|
+
import React, { useEffect, useRef } from "react";
|
|
3
|
+
import type { MalloyRenderProps } from "@malloydata/render";
|
|
4
|
+
import "@malloydata/render/webcomponent";
|
|
5
|
+
|
|
6
|
+
type MalloyRenderElement = HTMLElement & MalloyRenderProps;
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
10
|
+
namespace JSX {
|
|
11
|
+
interface IntrinsicElements {
|
|
12
|
+
"malloy-render": React.DetailedHTMLProps<
|
|
13
|
+
React.HTMLAttributes<HTMLElement>,
|
|
14
|
+
MalloyRenderElement
|
|
15
|
+
>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface RenderedResultProps {
|
|
21
|
+
queryResult: string;
|
|
22
|
+
modelDef: string;
|
|
23
|
+
dataStyles: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default function RenderedResult({
|
|
27
|
+
queryResult,
|
|
28
|
+
modelDef,
|
|
29
|
+
}: RenderedResultProps) {
|
|
30
|
+
const ref = useRef<MalloyRenderElement>(null);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (ref.current) {
|
|
33
|
+
ref.current.queryResult = JSON.parse(queryResult);
|
|
34
|
+
ref.current.modelDef = JSON.parse(modelDef);
|
|
35
|
+
}
|
|
36
|
+
}, [queryResult, modelDef]);
|
|
37
|
+
return <malloy-render ref={ref} />;
|
|
38
|
+
}
|
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { createHighlighter } from "shiki";
|
|
3
|
+
|
|
4
|
+
const malloyTMGrammar = {
|
|
5
|
+
scopeName: "source.malloy",
|
|
6
|
+
patterns: [{ include: "#malloy-language" }],
|
|
7
|
+
repository: {
|
|
8
|
+
"malloy-language": {
|
|
9
|
+
patterns: [
|
|
10
|
+
{ include: "#sql-string" },
|
|
11
|
+
{ include: "#comments" },
|
|
12
|
+
{ include: "#tags" },
|
|
13
|
+
{ include: "#strings" },
|
|
14
|
+
{ include: "#numbers" },
|
|
15
|
+
{ include: "#keywords" },
|
|
16
|
+
{ include: "#properties" },
|
|
17
|
+
{ include: "#functions" },
|
|
18
|
+
{ include: "#datetimes" },
|
|
19
|
+
{ include: "#identifiers-quoted" },
|
|
20
|
+
{ include: "#types" },
|
|
21
|
+
{ include: "#constants" },
|
|
22
|
+
{ include: "#timeframes" },
|
|
23
|
+
{ include: "#identifiers-unquoted" },
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
"malloy-matched": {
|
|
27
|
+
begin: "{",
|
|
28
|
+
end: "}",
|
|
29
|
+
patterns: [
|
|
30
|
+
{ include: "#malloy-matched" },
|
|
31
|
+
{ include: "#malloy-language" },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
"malloy-in-sql": {
|
|
35
|
+
begin: "%{",
|
|
36
|
+
name: "source.malloy-in-sql",
|
|
37
|
+
end: "}%?",
|
|
38
|
+
patterns: [
|
|
39
|
+
{ include: "#malloy-matched" },
|
|
40
|
+
{ include: "#malloy-language" },
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
"sql-string": {
|
|
44
|
+
patterns: [
|
|
45
|
+
{
|
|
46
|
+
begin: '(\\b[A-Za-z_][A-Za-z_0-9]*)(\\s*\\.\\s*)(sql)(\\s*\\(\\s*)(""")',
|
|
47
|
+
end: '"""',
|
|
48
|
+
beginCaptures: {
|
|
49
|
+
"1": { name: "variable.other" },
|
|
50
|
+
"3": { name: "keyword.control.sql" },
|
|
51
|
+
"5": { name: "punctuation.sql-block.open" },
|
|
52
|
+
},
|
|
53
|
+
endCaptures: {
|
|
54
|
+
"0": { name: "punctuation.sql-block.close" },
|
|
55
|
+
},
|
|
56
|
+
name: "source.sql",
|
|
57
|
+
patterns: [
|
|
58
|
+
{ include: "#malloy-in-sql" },
|
|
59
|
+
{ include: "source.sql" },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
functions: {
|
|
65
|
+
patterns: [
|
|
66
|
+
{
|
|
67
|
+
match: "(?i)\\b(count)(\\s*\\()(distinct)",
|
|
68
|
+
captures: {
|
|
69
|
+
"1": { name: "entity.name.function" },
|
|
70
|
+
"3": { name: "entity.name.function.modifier" },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
match: "(?i)\\b(AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE|UNGROUPED)(\\s*\\()",
|
|
75
|
+
captures: {
|
|
76
|
+
"1": { name: "entity.name.function" },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
match: "(?i)\\b([a-zA-Z_][a-zA-Z_0-9]*)(\\s*\\()",
|
|
81
|
+
captures: {
|
|
82
|
+
"1": { name: "entity.name.function" },
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
match: "(?i)\\b([a-zA-Z_][a-zA-Z_0-9]*)(!)(timestamp|number|string|boolean|date)?(\\s*\\()",
|
|
87
|
+
captures: {
|
|
88
|
+
"1": { name: "entity.name.function" },
|
|
89
|
+
"3": { name: "entity.name.type" },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
datetimes: {
|
|
95
|
+
patterns: [
|
|
96
|
+
{
|
|
97
|
+
match: "(?i)@[0-9]{4}-[0-9]{2}-[0-9]{2}[ T][0-9]{2}:[0-9]{2}((:[0-9]{2})(([\\.,][0-9]+)(\\[[A-Za-z_/]+\\])?)?)?",
|
|
98
|
+
name: "constant.numeric.timestamp",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
match: "(?i)@[0-9]{4}(-Q[1-4]|-[0-9]{2}(-[0-9]{2}(-WK)?)?)?",
|
|
102
|
+
name: "constant.numeric.date",
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
"identifiers-quoted": {
|
|
107
|
+
patterns: [
|
|
108
|
+
{
|
|
109
|
+
match: "`[^`]*`",
|
|
110
|
+
name: "variable.other.quoted",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
"identifiers-unquoted": {
|
|
115
|
+
patterns: [
|
|
116
|
+
{
|
|
117
|
+
match: "(?i)\\b[A-Za-z_][A-Za-z_0-9]*\\b",
|
|
118
|
+
name: "variable.other",
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
timeframes: {
|
|
123
|
+
patterns: [
|
|
124
|
+
{
|
|
125
|
+
match: "(?i)\\b((year|quarter|month|week|day|hour|minute|second)s?)\\b",
|
|
126
|
+
name: "keyword.other.timeframe",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
match: "(?i)\\b(day_of_year|day_of_month)\\b",
|
|
130
|
+
name: "keyword.other.timeframe",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
comments: {
|
|
135
|
+
patterns: [
|
|
136
|
+
{
|
|
137
|
+
begin: "/\\*",
|
|
138
|
+
end: "\\*/",
|
|
139
|
+
beginCaptures: {
|
|
140
|
+
"0": { name: "punctuation.definition.comment.begin" },
|
|
141
|
+
},
|
|
142
|
+
endCaptures: {
|
|
143
|
+
"0": { name: "punctuation.definition.comment.end" },
|
|
144
|
+
},
|
|
145
|
+
name: "comment.block",
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
begin: "//",
|
|
149
|
+
end: "\\n",
|
|
150
|
+
beginCaptures: {
|
|
151
|
+
"0": { name: "punctuation.definition.comment" },
|
|
152
|
+
},
|
|
153
|
+
name: "comment.line.double-slash",
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
begin: "--",
|
|
157
|
+
end: "\\n",
|
|
158
|
+
beginCaptures: {
|
|
159
|
+
"0": { name: "punctuation.definition.comment" },
|
|
160
|
+
},
|
|
161
|
+
name: "comment.line.double-hyphen",
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
tags: {
|
|
166
|
+
patterns: [
|
|
167
|
+
{
|
|
168
|
+
match: "##\\n",
|
|
169
|
+
name: "string.quoted",
|
|
170
|
+
captures: {
|
|
171
|
+
"0": { name: "string.quoted" },
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
begin: '#"',
|
|
176
|
+
end: "\\n",
|
|
177
|
+
beginCaptures: {
|
|
178
|
+
"0": { name: "punctuation.definition.comment" },
|
|
179
|
+
},
|
|
180
|
+
name: "comment.line.double-slash",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
match: "#\\n",
|
|
184
|
+
name: "string.quoted",
|
|
185
|
+
captures: {
|
|
186
|
+
"0": { name: "string.quoted" },
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
begin: "#\\s",
|
|
191
|
+
end: "\\n",
|
|
192
|
+
beginCaptures: {
|
|
193
|
+
"0": { name: "support.type.property-name.json" },
|
|
194
|
+
},
|
|
195
|
+
name: "comment.line.double-slash",
|
|
196
|
+
patterns: [{ include: "#tag-values" }],
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
begin: "##\\s",
|
|
200
|
+
end: "\\n",
|
|
201
|
+
beginCaptures: {
|
|
202
|
+
"0": { name: "support.type.property-name.json" },
|
|
203
|
+
},
|
|
204
|
+
name: "comment.line.double-slash",
|
|
205
|
+
patterns: [{ include: "#tag-values" }],
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
begin: "#",
|
|
209
|
+
end: "\\n",
|
|
210
|
+
beginCaptures: {
|
|
211
|
+
"0": { name: "string.quoted" },
|
|
212
|
+
},
|
|
213
|
+
name: "string.quoted",
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
repository: {
|
|
217
|
+
"tag-values": {
|
|
218
|
+
name: "support.type.property-name.json",
|
|
219
|
+
match: '(-)?((?:[^\\s=#]+)|(?:"[^#]+"))(?:\\s*(=)\\s*((?:[^\\s=#]+)|(?:"[^#]+")))?',
|
|
220
|
+
captures: {
|
|
221
|
+
"1": { name: "keyword.control.negate" },
|
|
222
|
+
"2": { name: "support.type.property-name.json" },
|
|
223
|
+
"3": { name: "keyword.operator.comparison.ts" },
|
|
224
|
+
"4": { name: "string.quoted" },
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
strings: {
|
|
230
|
+
patterns: [
|
|
231
|
+
{
|
|
232
|
+
begin: "'",
|
|
233
|
+
end: "'",
|
|
234
|
+
beginCaptures: {
|
|
235
|
+
"0": { name: "punctuation.definition.string.begin" },
|
|
236
|
+
},
|
|
237
|
+
endCaptures: {
|
|
238
|
+
"0": { name: "punctuation.definition.string.end" },
|
|
239
|
+
},
|
|
240
|
+
name: "string.quoted.single",
|
|
241
|
+
patterns: [{ include: "#escapes" }],
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
begin: '"',
|
|
245
|
+
end: '"',
|
|
246
|
+
beginCaptures: {
|
|
247
|
+
"0": { name: "punctuation.definition.string.begin" },
|
|
248
|
+
},
|
|
249
|
+
endCaptures: {
|
|
250
|
+
"0": { name: "punctuation.definition.string.end" },
|
|
251
|
+
},
|
|
252
|
+
name: "string.quoted.double",
|
|
253
|
+
patterns: [{ include: "#escapes" }],
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
begin: '"""',
|
|
257
|
+
end: '"""',
|
|
258
|
+
beginCaptures: {
|
|
259
|
+
"0": { name: "punctuation.definition.string.begin" },
|
|
260
|
+
},
|
|
261
|
+
endCaptures: {
|
|
262
|
+
"0": { name: "punctuation.definition.string.end" },
|
|
263
|
+
},
|
|
264
|
+
name: "string.quoted.triple",
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
begin: "(?i)[r|/]'",
|
|
268
|
+
end: "'",
|
|
269
|
+
name: "string.regexp",
|
|
270
|
+
patterns: [{ include: "#regex-escapes" }],
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
repository: {
|
|
274
|
+
escapes: {
|
|
275
|
+
name: "constant.character.escape",
|
|
276
|
+
match: "\\\\(u[A-Fa-f0-9]{4}|.)",
|
|
277
|
+
captures: {
|
|
278
|
+
"0": { name: "constant.character.escape" },
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
"regex-escapes": {
|
|
282
|
+
name: "constant.character.escape",
|
|
283
|
+
match: "\\\\.",
|
|
284
|
+
captures: {
|
|
285
|
+
"0": { name: "constant.character.escape" },
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
numbers: {
|
|
291
|
+
match: "(?i)(\\b((0|[1-9][0-9]*)(E[+-]?[0-9]+|\\.[0-9]*)?)|\\.[0-9]+)",
|
|
292
|
+
name: "constant.numeric",
|
|
293
|
+
},
|
|
294
|
+
constants: {
|
|
295
|
+
patterns: [
|
|
296
|
+
{
|
|
297
|
+
match: "(?i)\\bnull\\b",
|
|
298
|
+
name: "constant.language.null",
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
match: "(?i)\\btrue\\b",
|
|
302
|
+
name: "constant.language.true",
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
match: "(?i)\\bfalse\\b",
|
|
306
|
+
name: "constant.language.false",
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
},
|
|
310
|
+
types: {
|
|
311
|
+
patterns: [
|
|
312
|
+
{
|
|
313
|
+
match: "(?i)\\bstring\\b",
|
|
314
|
+
name: "entity.name.type.string",
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
match: "(?i)\\bnumber\\b",
|
|
318
|
+
name: "entity.name.type.number",
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
match: "(?i)\\bdate\\b",
|
|
322
|
+
name: "entity.name.type.date",
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
match: "(?i)\\btimestamp\\b",
|
|
326
|
+
name: "entity.name.type.timestamp",
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
match: "(?i)\\bboolean\\b",
|
|
330
|
+
name: "entity.name.type.boolean",
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
},
|
|
334
|
+
properties: {
|
|
335
|
+
patterns: [
|
|
336
|
+
{
|
|
337
|
+
match: "(?i)\\baccept\\b",
|
|
338
|
+
name: "keyword.control.accept",
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
match: "(?i)\\bselect\\b",
|
|
342
|
+
name: "keyword.control.select",
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
match: "(?i)\\bconnection\\b",
|
|
346
|
+
name: "keyword.control.connection",
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
match: "(?i)\\brun\\b",
|
|
350
|
+
name: "keyword.control.run",
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
match: "(?i)\\bextend\\b",
|
|
354
|
+
name: "keyword.control.extend",
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
match: "(?i)\\brefine\\b",
|
|
358
|
+
name: "keyword.control.refine",
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
match: "(?i)\\baggregate\\b",
|
|
362
|
+
name: "keyword.control.aggregate",
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
match: "(?i)\\bsample\\b",
|
|
366
|
+
name: "keyword.control.sample",
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
match: "(?i)\\bcalculate\\b",
|
|
370
|
+
name: "keyword.control.calculate",
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
match: "(?i)\\btimezone\\b",
|
|
374
|
+
name: "keyword.control.timezone",
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
match: "(?i)\\bdimension\\b",
|
|
378
|
+
name: "keyword.control.dimension",
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
match: "(?i)\\bexcept\\b",
|
|
382
|
+
name: "keyword.control.except",
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
match: "(?i)\\bsource\\b",
|
|
386
|
+
name: "keyword.control.source",
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
match: "(?i)\\bgroup_by\\b",
|
|
390
|
+
name: "keyword.control.group_by",
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
match: "(?i)\\bhaving\\b",
|
|
394
|
+
name: "keyword.control.having",
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
match: "(?i)\\bindex\\b",
|
|
398
|
+
name: "keyword.control.index",
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
match: "(?i)\\bjoin_one\\b",
|
|
402
|
+
name: "keyword.control.join_one",
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
match: "(?i)\\bwith\\b",
|
|
406
|
+
name: "keyword.control.with",
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
match: "(?i)\\bjoin_many\\b",
|
|
410
|
+
name: "keyword.control.join_many",
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
match: "(?i)\\bjoin_cross\\b",
|
|
414
|
+
name: "keyword.control.join_cross",
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
match: "(?i)\\blimit\\b",
|
|
418
|
+
name: "keyword.control.limit",
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
match: "(?i)\\bmeasure\\b",
|
|
422
|
+
name: "keyword.control.measure",
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
match: "(?i)\\bnest\\b",
|
|
426
|
+
name: "keyword.control.nest",
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
match: "(?i)\\border_by\\b",
|
|
430
|
+
name: "keyword.control.order_by",
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
match: "(?i)\\bpartition_by\\b",
|
|
434
|
+
name: "keyword.control.partition_by",
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
match: "(?i)\\bprimary_key\\b",
|
|
438
|
+
name: "keyword.control.primary_key",
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
match: "(?i)\\bproject\\b",
|
|
442
|
+
name: "keyword.control.project",
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
match: "(?i)\\bquery\\b",
|
|
446
|
+
name: "keyword.control.query",
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
match: "(?i)\\brename\\b",
|
|
450
|
+
name: "keyword.control.rename",
|
|
451
|
+
},
|
|
452
|
+
{
|
|
453
|
+
match: "(?i)\\btop\\b",
|
|
454
|
+
name: "keyword.control.top",
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
match: "(?i)\\bview\\b",
|
|
458
|
+
name: "keyword.control.view",
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
match: "(?i)\\bwhere\\b",
|
|
462
|
+
name: "keyword.control.where",
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
match: "(?i)\\bdeclare\\b",
|
|
466
|
+
name: "keyword.control.declare",
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
},
|
|
470
|
+
keywords: {
|
|
471
|
+
patterns: [
|
|
472
|
+
{
|
|
473
|
+
match: "(?i)\\bis\\b",
|
|
474
|
+
name: "keyword.control.is",
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
match: "(?i)\\bon\\b",
|
|
478
|
+
name: "keyword.control.on",
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
match: "(?i)\\bnot\\b",
|
|
482
|
+
name: "keyword.other.not",
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
match: "(?i)\\bor\\b",
|
|
486
|
+
name: "keyword.other.or",
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
match: "(?i)\\bdesc\\b",
|
|
490
|
+
name: "keyword.control.desc",
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
match: "(?i)\\bby\\b",
|
|
494
|
+
name: "keyword.control.by",
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
match: "(?i)\\band\\b",
|
|
498
|
+
name: "keyword.other.and",
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
match: "(?i)\\basc\\b",
|
|
502
|
+
name: "keyword.control.asc",
|
|
503
|
+
},
|
|
504
|
+
{
|
|
505
|
+
match: "(?i)\\bfor\\b",
|
|
506
|
+
name: "keyword.other.for",
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
match: "(?i)\\belse\\b",
|
|
510
|
+
name: "keyword.other.else",
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
match: "(?i)\\bto\\b",
|
|
514
|
+
name: "keyword.other.to",
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
match: "(?i)\\bwhen\\b",
|
|
518
|
+
name: "keyword.other.when",
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
match: "(?i)\\bpick\\b",
|
|
522
|
+
name: "keyword.other.pick",
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
match: "(?i)\\bimport\\b",
|
|
526
|
+
name: "keyword.control.import",
|
|
527
|
+
},
|
|
528
|
+
],
|
|
529
|
+
},
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
const malloyDocsTMGrammar = {
|
|
534
|
+
...malloyTMGrammar,
|
|
535
|
+
patterns: [...malloyTMGrammar.patterns, { include: "#docvar" }],
|
|
536
|
+
repository: {
|
|
537
|
+
...malloyTMGrammar.repository,
|
|
538
|
+
docvar: {
|
|
539
|
+
patterns: [
|
|
540
|
+
{
|
|
541
|
+
match: "\\<\\<[^(\\>\\>)]*\\>\\>",
|
|
542
|
+
beginCaptures: {
|
|
543
|
+
0: { name: "punctuation.definition.comment.begin" },
|
|
544
|
+
},
|
|
545
|
+
endCaptures: {
|
|
546
|
+
0: { name: "punctuation.definition.comment.end" },
|
|
547
|
+
},
|
|
548
|
+
name: "markup.italic.markdown",
|
|
549
|
+
},
|
|
550
|
+
],
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
const malloySQLTMGrammar = {
|
|
556
|
+
name: "Malloy SQL",
|
|
557
|
+
scopeName: "source.malloy-sql",
|
|
558
|
+
patterns: [{ include: "#malloysql-sql" }],
|
|
559
|
+
repository: {
|
|
560
|
+
"malloysql-sql": {
|
|
561
|
+
beginCaptures: {
|
|
562
|
+
"0": { name: "entity.other.attribute.malloy-sql" },
|
|
563
|
+
"1": { name: "entity.other.attribute.malloy-sql" },
|
|
564
|
+
"3": { name: "comment.line.double-slash" },
|
|
565
|
+
},
|
|
566
|
+
name: "meta.embedded.block.malloysql.sql",
|
|
567
|
+
patterns: [
|
|
568
|
+
{ include: "#comments" },
|
|
569
|
+
{
|
|
570
|
+
begin: "%{",
|
|
571
|
+
end: "}%",
|
|
572
|
+
beginCaptures: {
|
|
573
|
+
"0": { name: "punctuation.definition.malloy-sql" },
|
|
574
|
+
},
|
|
575
|
+
endCaptures: {
|
|
576
|
+
"0": { name: "punctuation.definition.malloy-sql" },
|
|
577
|
+
},
|
|
578
|
+
name: "meta.embedded.block.malloy",
|
|
579
|
+
patterns: [{ include: "source.malloy" }],
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
include: "source.sql",
|
|
583
|
+
},
|
|
584
|
+
],
|
|
585
|
+
},
|
|
586
|
+
comments: {
|
|
587
|
+
patterns: [
|
|
588
|
+
{
|
|
589
|
+
begin: "/\\*",
|
|
590
|
+
end: "\\*/",
|
|
591
|
+
beginCaptures: {
|
|
592
|
+
"0": { name: "punctuation.definition.comment.begin" },
|
|
593
|
+
},
|
|
594
|
+
endCaptures: {
|
|
595
|
+
"0": { name: "punctuation.definition.comment.end" },
|
|
596
|
+
},
|
|
597
|
+
name: "comment.block",
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
begin: "//",
|
|
601
|
+
end: "\\n",
|
|
602
|
+
beginCaptures: {
|
|
603
|
+
"0": { name: "punctuation.definition.comment" },
|
|
604
|
+
},
|
|
605
|
+
name: "comment.line.double-slash",
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
begin: "--",
|
|
609
|
+
end: "\\n",
|
|
610
|
+
beginCaptures: {
|
|
611
|
+
"0": { name: "punctuation.definition.comment" },
|
|
612
|
+
},
|
|
613
|
+
name: "comment.line.double-hyphen",
|
|
614
|
+
},
|
|
615
|
+
],
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
const THEME = "light-plus";
|
|
621
|
+
const HIGHLIGHTER = createHighlighter({
|
|
622
|
+
themes: [THEME],
|
|
623
|
+
langs: [
|
|
624
|
+
"sql",
|
|
625
|
+
"json",
|
|
626
|
+
"typescript",
|
|
627
|
+
{
|
|
628
|
+
name: "malloy",
|
|
629
|
+
scopeName: "source.malloy",
|
|
630
|
+
embeddedLangs: ["sql"],
|
|
631
|
+
...(malloyDocsTMGrammar as any),
|
|
632
|
+
},
|
|
633
|
+
{
|
|
634
|
+
name: "malloysql",
|
|
635
|
+
scopeName: "source.malloy-sql",
|
|
636
|
+
embeddedLangs: ["sql"],
|
|
637
|
+
...(malloySQLTMGrammar as any),
|
|
638
|
+
},
|
|
639
|
+
],
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
export async function highlight(code: string, lang: string): Promise<string> {
|
|
643
|
+
const highlighter = await HIGHLIGHTER;
|
|
644
|
+
const highlightedRaw = highlighter.codeToHtml(code, {
|
|
645
|
+
lang: lang,
|
|
646
|
+
theme: THEME,
|
|
647
|
+
});
|
|
648
|
+
return highlightedRaw;
|
|
649
|
+
}
|