@malloydata/malloy 0.0.132-dev240315233415 → 0.0.132-dev240318200424

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.
@@ -1,91 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2023 Google LLC
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining
6
- * a copy of this software and associated documentation files
7
- * (the "Software"), to deal in the Software without restriction,
8
- * including without limitation the rights to use, copy, modify, merge,
9
- * publish, distribute, sublicense, and/or sell copies of the Software,
10
- * and to permit persons to whom the Software is furnished to do so,
11
- * subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be
14
- * included in all copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
- */
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.SQLStatement = void 0;
26
- const sql_block_1 = require("../../../model/sql_block");
27
- const malloy_element_1 = require("../types/malloy-element");
28
- class SQLStatement extends malloy_element_1.MalloyElement {
29
- constructor(select) {
30
- super();
31
- this.select = select;
32
- this.elementType = 'sqlStatement';
33
- this.has({ select: select });
34
- }
35
- sqlBlock() {
36
- if (!this.requestBlock) {
37
- this.requestBlock = (0, sql_block_1.makeSQLBlock)(this.select.sqlPhrases(), this.connection);
38
- }
39
- return this.requestBlock;
40
- }
41
- lookupCompiledSQL(sql) {
42
- var _a;
43
- const sqlDefEntry = (_a = this.translator()) === null || _a === void 0 ? void 0 : _a.root.sqlQueryZone;
44
- if (!sqlDefEntry)
45
- return;
46
- sqlDefEntry.reference(sql.name, this.location);
47
- return sqlDefEntry.getEntry(sql.name);
48
- }
49
- needs(doc) {
50
- const sql = this.sqlBlock();
51
- const lookup = this.lookupCompiledSQL(sql);
52
- if ((lookup === null || lookup === void 0 ? void 0 : lookup.status) === 'reference') {
53
- return {
54
- compileSQL: sql,
55
- partialModel: this.select.containsQueries ? doc.modelDef() : undefined,
56
- };
57
- }
58
- }
59
- /**
60
- * This is the one statement which pauses execution. First time through
61
- * it will generate a schema request, next time through it will either
62
- * record the error or record the schema.
63
- */
64
- execute(doc) {
65
- const sql = this.sqlBlock();
66
- const lookup = this.lookupCompiledSQL(sql);
67
- if (!lookup) {
68
- this.log("Cant't look up schema for sql block");
69
- return;
70
- }
71
- if (lookup.status === 'error') {
72
- const msgLines = lookup.message.split(/\r?\n/);
73
- this.select.log('Invalid SQL, ' + msgLines.join('\n '));
74
- return undefined;
75
- }
76
- if (lookup.status === 'present') {
77
- const location = this.select.location;
78
- const locStruct = {
79
- ...lookup.value,
80
- fields: lookup.value.fields.map(f => ({ ...f, location })),
81
- location: this.location,
82
- };
83
- if (this.is && !doc.defineSQL(locStruct, this.is)) {
84
- this.log(`'${this.is}' already defined`);
85
- }
86
- return undefined;
87
- }
88
- }
89
- }
90
- exports.SQLStatement = SQLStatement;
91
- //# sourceMappingURL=sql-statement.js.map
@@ -1,83 +0,0 @@
1
- import { CommonTokenStream } from 'antlr4ts';
2
- import { ParseTree } from 'antlr4ts/tree';
3
- import { DocumentRange } from '../../model/malloy_types';
4
- export interface DocumentHighlight {
5
- range: DocumentRange;
6
- type: string;
7
- }
8
- export declare const HighlightType: {
9
- Identifier: string;
10
- Type: string;
11
- Literal: {
12
- Date: string;
13
- Number: string;
14
- String: string;
15
- RegularExpression: string;
16
- Boolean: string;
17
- Null: string;
18
- };
19
- Call: {
20
- Aggregate: string;
21
- TimeFrame: string;
22
- Cast: string;
23
- Table: string;
24
- From: string;
25
- Function: string;
26
- FromSQL: string;
27
- };
28
- Keyword: {
29
- AggregateModifier: {
30
- Distinct: string;
31
- };
32
- CastModifier: {
33
- As: string;
34
- };
35
- Is: string;
36
- On: string;
37
- Desc: string;
38
- Asc: string;
39
- Pick: string;
40
- When: string;
41
- Else: string;
42
- With: string;
43
- JSON: string;
44
- Turtle: string;
45
- Import: string;
46
- };
47
- Operator: {
48
- Comparison: string;
49
- Boolean: string;
50
- Date: string;
51
- };
52
- Comment: {
53
- Line: string;
54
- Block: string;
55
- };
56
- Property: {
57
- Accept: string;
58
- Aggregate: string;
59
- Dimension: string;
60
- Except: string;
61
- Source: string;
62
- GroupBy: string;
63
- Having: string;
64
- Index: string;
65
- JoinOne: string;
66
- JoinMany: string;
67
- JoinCross: string;
68
- Limit: string;
69
- Measure: string;
70
- Nest: string;
71
- OrderBy: string;
72
- PrimaryKey: string;
73
- Project: string;
74
- Query: string;
75
- Rename: string;
76
- Top: string;
77
- Where: string;
78
- SQL: string;
79
- };
80
- };
81
- export declare function passForHighlights(tokens: CommonTokenStream): DocumentHighlight[];
82
- export declare function walkForDocumentHighlights(tokens: CommonTokenStream, parseTree: ParseTree): DocumentHighlight[];
83
- export declare function sortHighlights(highlights: DocumentHighlight[]): DocumentHighlight[];
@@ -1,388 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2023 Google LLC
4
- *
5
- * Permission is hereby granted, free of charge, to any person obtaining
6
- * a copy of this software and associated documentation files
7
- * (the "Software"), to deal in the Software without restriction,
8
- * including without limitation the rights to use, copy, modify, merge,
9
- * publish, distribute, sublicense, and/or sell copies of the Software,
10
- * and to permit persons to whom the Software is furnished to do so,
11
- * subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be
14
- * included in all copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
- */
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.sortHighlights = exports.walkForDocumentHighlights = exports.passForHighlights = exports.HighlightType = void 0;
26
- const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
27
- const MalloyParser_1 = require("../lib/Malloy/MalloyParser");
28
- // TODO maybe this could be an enum like Definition__Field, etc.
29
- exports.HighlightType = {
30
- Identifier: 'identifier',
31
- Type: 'type',
32
- Literal: {
33
- Date: 'literal.date',
34
- Number: 'literal.number',
35
- String: 'literal.string',
36
- RegularExpression: 'literal.regular_expression',
37
- Boolean: 'literal.boolean',
38
- Null: 'literal.null',
39
- },
40
- Call: {
41
- Aggregate: 'call.aggregate',
42
- TimeFrame: 'call.time_frame',
43
- Cast: 'call.cast',
44
- Table: 'call.table',
45
- From: 'call.from',
46
- Function: 'call.function',
47
- FromSQL: 'call.from_sql',
48
- },
49
- // TODO many of these should probably be categorized further
50
- Keyword: {
51
- AggregateModifier: {
52
- Distinct: 'keyword.aggregate_modifier.distinct',
53
- },
54
- CastModifier: {
55
- As: 'keyword.cast_modifier.as',
56
- },
57
- Is: 'keyword.is',
58
- On: 'keyword.on',
59
- Desc: 'keyword.desc',
60
- Asc: 'keyword.asc',
61
- Pick: 'keyword.pick',
62
- When: 'keyword.when',
63
- Else: 'keyword.else',
64
- With: 'keyword.with',
65
- // TODO or is this a meta type?
66
- JSON: 'keyword.json',
67
- // TODO or is this a meta type?
68
- Turtle: 'keyword.turtle',
69
- Import: 'keyword.import',
70
- },
71
- Operator: {
72
- Comparison: 'operator.comparison',
73
- Boolean: 'operator.boolean',
74
- Date: 'operator.date',
75
- },
76
- Comment: {
77
- Line: 'comment.line',
78
- Block: 'comment.block',
79
- },
80
- Property: {
81
- Accept: 'property.accept',
82
- Aggregate: 'property.aggregate',
83
- Dimension: 'property.dimension',
84
- Except: 'property.except',
85
- Source: 'property.source',
86
- GroupBy: 'property.group_by',
87
- Having: 'property.having',
88
- Index: 'property.index',
89
- JoinOne: 'keyword.join_one',
90
- JoinMany: 'keyword.join_many',
91
- JoinCross: 'keyword.join_cross',
92
- Limit: 'property.limit',
93
- Measure: 'property.measure',
94
- Nest: 'property.nest',
95
- OrderBy: 'property.order_by',
96
- PrimaryKey: 'property.primary_key',
97
- Project: 'property.project',
98
- Query: 'property.query',
99
- Rename: 'property.rename',
100
- Top: 'property.top',
101
- Where: 'property.where',
102
- SQL: 'property.sql',
103
- },
104
- };
105
- function passForHighlights(tokens) {
106
- const highlights = [];
107
- const register = (token, type, removeColon = false) => {
108
- var _a;
109
- const offset = token.startIndex - token.charPositionInLine;
110
- const tokenLines = ((_a = token.text) === null || _a === void 0 ? void 0 : _a.split('\n')) || [];
111
- const numberOfLines = tokenLines.length;
112
- const lengthOfAllButLastLine = tokenLines
113
- .slice(0, -1)
114
- .reduce((a, l) => a + l.length, 0);
115
- const colonAdjustment = removeColon ? 1 : 0;
116
- highlights.push({
117
- type,
118
- range: {
119
- start: {
120
- line: token.line - 1,
121
- character: token.startIndex - offset,
122
- },
123
- end: {
124
- line: token.line - 1 + numberOfLines - 1,
125
- character: token.stopIndex +
126
- 2 -
127
- (numberOfLines > 1 ? token.startIndex : offset) -
128
- lengthOfAllButLastLine -
129
- numberOfLines -
130
- colonAdjustment,
131
- },
132
- },
133
- });
134
- };
135
- for (let i = 0; i < tokens.size; i++) {
136
- const token = tokens.get(i);
137
- switch (token.type) {
138
- case MalloyParser_1.MalloyParser.ACCEPT:
139
- register(token, exports.HighlightType.Property.Accept, true);
140
- break;
141
- case MalloyParser_1.MalloyParser.AGGREGATE:
142
- register(token, exports.HighlightType.Property.Aggregate, true);
143
- break;
144
- case MalloyParser_1.MalloyParser.DIMENSION:
145
- register(token, exports.HighlightType.Property.Dimension, true);
146
- break;
147
- case MalloyParser_1.MalloyParser.EXCEPT:
148
- register(token, exports.HighlightType.Property.Except, true);
149
- break;
150
- case MalloyParser_1.MalloyParser.GROUP_BY:
151
- register(token, exports.HighlightType.Property.GroupBy, true);
152
- break;
153
- case MalloyParser_1.MalloyParser.HAVING:
154
- register(token, exports.HighlightType.Property.Having, true);
155
- break;
156
- case MalloyParser_1.MalloyParser.INDEX:
157
- register(token, exports.HighlightType.Property.Index, true);
158
- break;
159
- case MalloyParser_1.MalloyParser.JOIN_CROSS:
160
- register(token, exports.HighlightType.Property.JoinOne, true);
161
- break;
162
- case MalloyParser_1.MalloyParser.JOIN_ONE:
163
- register(token, exports.HighlightType.Property.JoinMany, true);
164
- break;
165
- case MalloyParser_1.MalloyParser.JOIN_MANY:
166
- register(token, exports.HighlightType.Property.JoinCross, true);
167
- break;
168
- case MalloyParser_1.MalloyParser.LIMIT:
169
- register(token, exports.HighlightType.Property.Limit, true);
170
- break;
171
- case MalloyParser_1.MalloyParser.MEASURE:
172
- register(token, exports.HighlightType.Property.Measure, true);
173
- break;
174
- case MalloyParser_1.MalloyParser.NEST:
175
- register(token, exports.HighlightType.Property.Nest, true);
176
- break;
177
- case MalloyParser_1.MalloyParser.ORDER_BY:
178
- register(token, exports.HighlightType.Property.OrderBy, true);
179
- break;
180
- case MalloyParser_1.MalloyParser.PRIMARY_KEY:
181
- register(token, exports.HighlightType.Property.PrimaryKey, true);
182
- break;
183
- case MalloyParser_1.MalloyParser.PROJECT:
184
- register(token, exports.HighlightType.Property.Project, true);
185
- break;
186
- case MalloyParser_1.MalloyParser.QUERY:
187
- register(token, exports.HighlightType.Property.Query, true);
188
- break;
189
- case MalloyParser_1.MalloyParser.RENAME:
190
- register(token, exports.HighlightType.Property.Rename, true);
191
- break;
192
- case MalloyParser_1.MalloyParser.SOURCE:
193
- register(token, exports.HighlightType.Property.Source, true);
194
- break;
195
- case MalloyParser_1.MalloyParser.TOP:
196
- register(token, exports.HighlightType.Property.Top, true);
197
- break;
198
- case MalloyParser_1.MalloyParser.WHERE:
199
- register(token, exports.HighlightType.Property.Where, true);
200
- break;
201
- case MalloyParser_1.MalloyParser.SQL:
202
- register(token, exports.HighlightType.Property.SQL, true);
203
- break;
204
- case MalloyParser_1.MalloyParser.TABLE:
205
- register(token, exports.HighlightType.Call.Table);
206
- break;
207
- case MalloyParser_1.MalloyParser.FROM:
208
- register(token, exports.HighlightType.Call.From);
209
- break;
210
- case MalloyParser_1.MalloyParser.FROM_SQL:
211
- register(token, exports.HighlightType.Call.FromSQL);
212
- break;
213
- case MalloyParser_1.MalloyParser.SQ_STRING:
214
- case MalloyParser_1.MalloyParser.DQ_STRING:
215
- register(token, exports.HighlightType.Literal.String);
216
- break;
217
- case MalloyParser_1.MalloyParser.NUMERIC_LITERAL:
218
- case MalloyParser_1.MalloyParser.INTEGER_LITERAL:
219
- register(token, exports.HighlightType.Literal.Number);
220
- break;
221
- case MalloyParser_1.MalloyParser.HACKY_REGEX:
222
- register(token, exports.HighlightType.Literal.RegularExpression);
223
- break;
224
- case MalloyParser_1.MalloyParser.IS:
225
- register(token, exports.HighlightType.Keyword.Is);
226
- break;
227
- case MalloyParser_1.MalloyParser.DISTINCT:
228
- register(token, exports.HighlightType.Keyword.AggregateModifier.Distinct);
229
- break;
230
- case MalloyParser_1.MalloyParser.ON:
231
- register(token, exports.HighlightType.Keyword.On);
232
- break;
233
- case MalloyParser_1.MalloyParser.DESC:
234
- register(token, exports.HighlightType.Keyword.Desc);
235
- break;
236
- case MalloyParser_1.MalloyParser.ASC:
237
- register(token, exports.HighlightType.Keyword.Asc);
238
- break;
239
- case MalloyParser_1.MalloyParser.CAST:
240
- register(token, exports.HighlightType.Call.Cast);
241
- break;
242
- case MalloyParser_1.MalloyParser.AS:
243
- register(token, exports.HighlightType.Keyword.CastModifier.As);
244
- break;
245
- case MalloyParser_1.MalloyParser.PICK:
246
- register(token, exports.HighlightType.Keyword.Pick);
247
- break;
248
- case MalloyParser_1.MalloyParser.WHEN:
249
- register(token, exports.HighlightType.Keyword.When);
250
- break;
251
- case MalloyParser_1.MalloyParser.WITH:
252
- register(token, exports.HighlightType.Keyword.With);
253
- break;
254
- case MalloyParser_1.MalloyParser.ELSE:
255
- register(token, exports.HighlightType.Keyword.Else);
256
- break;
257
- case MalloyParser_1.MalloyParser.JSON:
258
- register(token, exports.HighlightType.Keyword.JSON);
259
- break;
260
- case MalloyParser_1.MalloyParser.TURTLE:
261
- register(token, exports.HighlightType.Keyword.Turtle);
262
- break;
263
- case MalloyParser_1.MalloyParser.TRUE:
264
- case MalloyParser_1.MalloyParser.FALSE:
265
- register(token, exports.HighlightType.Literal.Boolean);
266
- break;
267
- case MalloyParser_1.MalloyParser.NOW:
268
- case MalloyParser_1.MalloyParser.LITERAL_TIMESTAMP:
269
- case MalloyParser_1.MalloyParser.LITERAL_QUARTER:
270
- case MalloyParser_1.MalloyParser.LITERAL_MONTH:
271
- case MalloyParser_1.MalloyParser.LITERAL_DAY:
272
- case MalloyParser_1.MalloyParser.LITERAL_WEEK:
273
- case MalloyParser_1.MalloyParser.LITERAL_YEAR:
274
- register(token, exports.HighlightType.Literal.Date);
275
- break;
276
- case MalloyParser_1.MalloyParser.NULL:
277
- register(token, exports.HighlightType.Literal.Null);
278
- break;
279
- case MalloyParser_1.MalloyParser.AND:
280
- case MalloyParser_1.MalloyParser.OR:
281
- case MalloyParser_1.MalloyParser.NOT:
282
- register(token, exports.HighlightType.Operator.Boolean);
283
- break;
284
- case MalloyParser_1.MalloyParser.FOR:
285
- register(token, exports.HighlightType.Operator.Date);
286
- break;
287
- case MalloyParser_1.MalloyParser.COMMENT_TO_EOL:
288
- register(token, exports.HighlightType.Comment.Line);
289
- break;
290
- case MalloyParser_1.MalloyParser.BLOCK_COMMENT:
291
- register(token, exports.HighlightType.Comment.Block);
292
- break;
293
- case MalloyParser_1.MalloyParser.SUM:
294
- case MalloyParser_1.MalloyParser.COUNT:
295
- case MalloyParser_1.MalloyParser.AVG:
296
- case MalloyParser_1.MalloyParser.MIN:
297
- case MalloyParser_1.MalloyParser.MAX:
298
- register(token, exports.HighlightType.Call.Aggregate);
299
- break;
300
- case MalloyParser_1.MalloyParser.IDENTIFIER:
301
- case MalloyParser_1.MalloyParser.BQ_STRING:
302
- register(token, exports.HighlightType.Identifier);
303
- break;
304
- case MalloyParser_1.MalloyParser.STRING:
305
- case MalloyParser_1.MalloyParser.NUMBER:
306
- case MalloyParser_1.MalloyParser.BOOLEAN:
307
- case MalloyParser_1.MalloyParser.DATE:
308
- case MalloyParser_1.MalloyParser.TIMESTAMP:
309
- register(token, exports.HighlightType.Type);
310
- break;
311
- case MalloyParser_1.MalloyParser.SECOND:
312
- case MalloyParser_1.MalloyParser.MINUTE:
313
- case MalloyParser_1.MalloyParser.HOUR:
314
- case MalloyParser_1.MalloyParser.DAY:
315
- case MalloyParser_1.MalloyParser.WEEK:
316
- case MalloyParser_1.MalloyParser.MONTH:
317
- case MalloyParser_1.MalloyParser.QUARTER:
318
- case MalloyParser_1.MalloyParser.YEAR:
319
- register(token, exports.HighlightType.Call.TimeFrame);
320
- break;
321
- case MalloyParser_1.MalloyParser.IMPORT:
322
- register(token, exports.HighlightType.Keyword.Import);
323
- break;
324
- // TODO durations? How should we highlight `3 days` or
325
- // `(1 + 2) days` or `n days`?
326
- }
327
- }
328
- return highlights;
329
- }
330
- exports.passForHighlights = passForHighlights;
331
- class DocumentHighlightWalker {
332
- constructor(tokens, highlights) {
333
- this.tokens = tokens;
334
- this.highlights = highlights;
335
- }
336
- rangeOf(pcx) {
337
- const stopToken = pcx.stop || pcx.start;
338
- return {
339
- start: {
340
- line: pcx.start.line - 1,
341
- character: pcx.start.charPositionInLine,
342
- },
343
- end: {
344
- line: stopToken.line - 1,
345
- character: stopToken.stopIndex -
346
- (stopToken.startIndex - stopToken.charPositionInLine) +
347
- 1,
348
- },
349
- };
350
- }
351
- enterExprFunc(pcx) {
352
- const id = pcx.id() || pcx.timeframe();
353
- if (id) {
354
- this.highlights.push({
355
- range: this.rangeOf(id),
356
- type: exports.HighlightType.Call.Function,
357
- });
358
- }
359
- }
360
- }
361
- function walkForDocumentHighlights(tokens, parseTree) {
362
- const finder = new DocumentHighlightWalker(tokens, []);
363
- const listener = finder;
364
- ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseTree);
365
- return finder.highlights;
366
- }
367
- exports.walkForDocumentHighlights = walkForDocumentHighlights;
368
- function sortHighlights(highlights) {
369
- return highlights.sort((a, b) => {
370
- if (a.range.start.line < b.range.start.line) {
371
- return -1;
372
- }
373
- else if (a.range.start.line > b.range.start.line) {
374
- return 1;
375
- }
376
- else if (a.range.start.character < b.range.start.character) {
377
- return -1;
378
- }
379
- else if (a.range.start.character > b.range.start.character) {
380
- return 1;
381
- }
382
- else {
383
- return 0;
384
- }
385
- });
386
- }
387
- exports.sortHighlights = sortHighlights;
388
- //# sourceMappingURL=document-highlight-walker.js.map