@malloydata/malloy 0.0.22-dev230126015148 → 0.0.22-dev230206094309

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.
Files changed (93) hide show
  1. package/package.json +2 -2
  2. package/dist/connection_utils.d.ts +0 -1
  3. package/dist/connection_utils.js +0 -66
  4. package/dist/dialect/dialect.d.ts +0 -66
  5. package/dist/dialect/dialect.js +0 -85
  6. package/dist/dialect/dialect_map.d.ts +0 -3
  7. package/dist/dialect/dialect_map.js +0 -45
  8. package/dist/dialect/duckdb.d.ts +0 -52
  9. package/dist/dialect/duckdb.js +0 -364
  10. package/dist/dialect/index.d.ts +0 -6
  11. package/dist/dialect/index.js +0 -37
  12. package/dist/dialect/postgres.d.ts +0 -52
  13. package/dist/dialect/postgres.js +0 -330
  14. package/dist/dialect/standardsql.d.ts +0 -49
  15. package/dist/dialect/standardsql.js +0 -381
  16. package/dist/index.d.ts +0 -10
  17. package/dist/index.js +0 -59
  18. package/dist/lang/ast/apply-expr.d.ts +0 -3
  19. package/dist/lang/ast/apply-expr.js +0 -34
  20. package/dist/lang/ast/ast-expr.d.ts +0 -206
  21. package/dist/lang/ast/ast-expr.js +0 -781
  22. package/dist/lang/ast/ast-main.d.ts +0 -915
  23. package/dist/lang/ast/ast-main.js +0 -3672
  24. package/dist/lang/ast/ast-time-expr.d.ts +0 -69
  25. package/dist/lang/ast/ast-time-expr.js +0 -389
  26. package/dist/lang/ast/ast-types.d.ts +0 -83
  27. package/dist/lang/ast/ast-types.js +0 -225
  28. package/dist/lang/ast/index.d.ts +0 -5
  29. package/dist/lang/ast/index.js +0 -44
  30. package/dist/lang/ast/time-utils.d.ts +0 -9
  31. package/dist/lang/ast/time-utils.js +0 -104
  32. package/dist/lang/field-utils.d.ts +0 -5
  33. package/dist/lang/field-utils.js +0 -43
  34. package/dist/lang/index.d.ts +0 -9
  35. package/dist/lang/index.js +0 -32
  36. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +0 -165
  37. package/dist/lang/lib/Malloy/MalloyLexer.js +0 -1232
  38. package/dist/lang/lib/Malloy/MalloyParser.d.ts +0 -1947
  39. package/dist/lang/lib/Malloy/MalloyParser.js +0 -11909
  40. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +0 -2022
  41. package/dist/lang/lib/Malloy/MalloyParserListener.js +0 -4
  42. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +0 -1274
  43. package/dist/lang/lib/Malloy/MalloyParserVisitor.js +0 -4
  44. package/dist/lang/parse-log.d.ts +0 -27
  45. package/dist/lang/parse-log.js +0 -51
  46. package/dist/lang/parse-malloy.d.ts +0 -236
  47. package/dist/lang/parse-malloy.js +0 -746
  48. package/dist/lang/parse-to-ast.d.ts +0 -155
  49. package/dist/lang/parse-to-ast.js +0 -990
  50. package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +0 -10
  51. package/dist/lang/parse-tree-walkers/document-completion-walker.js +0 -148
  52. package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +0 -9
  53. package/dist/lang/parse-tree-walkers/document-help-context-walker.js +0 -107
  54. package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +0 -83
  55. package/dist/lang/parse-tree-walkers/document-highlight-walker.js +0 -385
  56. package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +0 -11
  57. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +0 -182
  58. package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +0 -34
  59. package/dist/lang/parse-tree-walkers/explore-query-walker.js +0 -74
  60. package/dist/lang/parse-tree-walkers/find-external-references.d.ts +0 -11
  61. package/dist/lang/parse-tree-walkers/find-external-references.js +0 -61
  62. package/dist/lang/reference-list.d.ts +0 -10
  63. package/dist/lang/reference-list.js +0 -90
  64. package/dist/lang/space-field.d.ts +0 -17
  65. package/dist/lang/space-field.js +0 -127
  66. package/dist/lang/test/document-help-context-walker.spec.d.ts +0 -1
  67. package/dist/lang/test/document-help-context-walker.spec.js +0 -55
  68. package/dist/lang/test/document-symbol-walker.spec.d.ts +0 -1
  69. package/dist/lang/test/document-symbol-walker.spec.js +0 -110
  70. package/dist/lang/test/field-symbols.spec.d.ts +0 -1
  71. package/dist/lang/test/field-symbols.spec.js +0 -180
  72. package/dist/lang/test/parse.spec.d.ts +0 -14
  73. package/dist/lang/test/parse.spec.js +0 -2134
  74. package/dist/lang/test/test-translator.d.ts +0 -38
  75. package/dist/lang/test/test-translator.js +0 -344
  76. package/dist/lang/zone.d.ts +0 -57
  77. package/dist/lang/zone.js +0 -107
  78. package/dist/malloy.d.ts +0 -1146
  79. package/dist/malloy.js +0 -2413
  80. package/dist/model/index.d.ts +0 -2
  81. package/dist/model/index.js +0 -45
  82. package/dist/model/malloy_query.d.ts +0 -351
  83. package/dist/model/malloy_query.js +0 -3174
  84. package/dist/model/malloy_types.d.ts +0 -551
  85. package/dist/model/malloy_types.js +0 -378
  86. package/dist/model/sql_block.d.ts +0 -7
  87. package/dist/model/sql_block.js +0 -56
  88. package/dist/model/utils.d.ts +0 -22
  89. package/dist/model/utils.js +0 -102
  90. package/dist/run_sql_options.d.ts +0 -3
  91. package/dist/run_sql_options.js +0 -25
  92. package/dist/runtime_types.d.ts +0 -105
  93. package/dist/runtime_types.js +0 -25
@@ -1,385 +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: { line: token.line - 1, character: token.startIndex - offset },
120
- end: {
121
- line: token.line - 1 + numberOfLines - 1,
122
- character: token.stopIndex +
123
- 2 -
124
- (numberOfLines > 1 ? token.startIndex : offset) -
125
- lengthOfAllButLastLine -
126
- numberOfLines -
127
- colonAdjustment,
128
- },
129
- },
130
- });
131
- };
132
- for (let i = 0; i < tokens.size; i++) {
133
- const token = tokens.get(i);
134
- switch (token.type) {
135
- case MalloyParser_1.MalloyParser.ACCEPT:
136
- register(token, exports.HighlightType.Property.Accept, true);
137
- break;
138
- case MalloyParser_1.MalloyParser.AGGREGATE:
139
- register(token, exports.HighlightType.Property.Aggregate, true);
140
- break;
141
- case MalloyParser_1.MalloyParser.DIMENSION:
142
- register(token, exports.HighlightType.Property.Dimension, true);
143
- break;
144
- case MalloyParser_1.MalloyParser.EXCEPT:
145
- register(token, exports.HighlightType.Property.Except, true);
146
- break;
147
- case MalloyParser_1.MalloyParser.GROUP_BY:
148
- register(token, exports.HighlightType.Property.GroupBy, true);
149
- break;
150
- case MalloyParser_1.MalloyParser.HAVING:
151
- register(token, exports.HighlightType.Property.Having, true);
152
- break;
153
- case MalloyParser_1.MalloyParser.INDEX:
154
- register(token, exports.HighlightType.Property.Index, true);
155
- break;
156
- case MalloyParser_1.MalloyParser.JOIN_CROSS:
157
- register(token, exports.HighlightType.Property.JoinOne, true);
158
- break;
159
- case MalloyParser_1.MalloyParser.JOIN_ONE:
160
- register(token, exports.HighlightType.Property.JoinMany, true);
161
- break;
162
- case MalloyParser_1.MalloyParser.JOIN_MANY:
163
- register(token, exports.HighlightType.Property.JoinCross, true);
164
- break;
165
- case MalloyParser_1.MalloyParser.LIMIT:
166
- register(token, exports.HighlightType.Property.Limit, true);
167
- break;
168
- case MalloyParser_1.MalloyParser.MEASURE:
169
- register(token, exports.HighlightType.Property.Measure, true);
170
- break;
171
- case MalloyParser_1.MalloyParser.NEST:
172
- register(token, exports.HighlightType.Property.Nest, true);
173
- break;
174
- case MalloyParser_1.MalloyParser.ORDER_BY:
175
- register(token, exports.HighlightType.Property.OrderBy, true);
176
- break;
177
- case MalloyParser_1.MalloyParser.PRIMARY_KEY:
178
- register(token, exports.HighlightType.Property.PrimaryKey, true);
179
- break;
180
- case MalloyParser_1.MalloyParser.PROJECT:
181
- register(token, exports.HighlightType.Property.Project, true);
182
- break;
183
- case MalloyParser_1.MalloyParser.QUERY:
184
- register(token, exports.HighlightType.Property.Query, true);
185
- break;
186
- case MalloyParser_1.MalloyParser.RENAME:
187
- register(token, exports.HighlightType.Property.Rename, true);
188
- break;
189
- case MalloyParser_1.MalloyParser.SOURCE:
190
- register(token, exports.HighlightType.Property.Source, true);
191
- break;
192
- case MalloyParser_1.MalloyParser.TOP:
193
- register(token, exports.HighlightType.Property.Top, true);
194
- break;
195
- case MalloyParser_1.MalloyParser.WHERE:
196
- register(token, exports.HighlightType.Property.Where, true);
197
- break;
198
- case MalloyParser_1.MalloyParser.SQL:
199
- register(token, exports.HighlightType.Property.SQL, true);
200
- break;
201
- case MalloyParser_1.MalloyParser.TABLE:
202
- register(token, exports.HighlightType.Call.Table);
203
- break;
204
- case MalloyParser_1.MalloyParser.FROM:
205
- register(token, exports.HighlightType.Call.From);
206
- break;
207
- case MalloyParser_1.MalloyParser.FROM_SQL:
208
- register(token, exports.HighlightType.Call.FromSQL);
209
- break;
210
- case MalloyParser_1.MalloyParser.STRING_LITERAL:
211
- case MalloyParser_1.MalloyParser.JSON_STRING:
212
- register(token, exports.HighlightType.Literal.String);
213
- break;
214
- case MalloyParser_1.MalloyParser.NUMERIC_LITERAL:
215
- case MalloyParser_1.MalloyParser.INTEGER_LITERAL:
216
- register(token, exports.HighlightType.Literal.Number);
217
- break;
218
- case MalloyParser_1.MalloyParser.HACKY_REGEX:
219
- register(token, exports.HighlightType.Literal.RegularExpression);
220
- break;
221
- case MalloyParser_1.MalloyParser.IS:
222
- register(token, exports.HighlightType.Keyword.Is);
223
- break;
224
- case MalloyParser_1.MalloyParser.DISTINCT:
225
- register(token, exports.HighlightType.Keyword.AggregateModifier.Distinct);
226
- break;
227
- case MalloyParser_1.MalloyParser.ON:
228
- register(token, exports.HighlightType.Keyword.On);
229
- break;
230
- case MalloyParser_1.MalloyParser.DESC:
231
- register(token, exports.HighlightType.Keyword.Desc);
232
- break;
233
- case MalloyParser_1.MalloyParser.ASC:
234
- register(token, exports.HighlightType.Keyword.Asc);
235
- break;
236
- case MalloyParser_1.MalloyParser.CAST:
237
- register(token, exports.HighlightType.Call.Cast);
238
- break;
239
- case MalloyParser_1.MalloyParser.AS:
240
- register(token, exports.HighlightType.Keyword.CastModifier.As);
241
- break;
242
- case MalloyParser_1.MalloyParser.PICK:
243
- register(token, exports.HighlightType.Keyword.Pick);
244
- break;
245
- case MalloyParser_1.MalloyParser.WHEN:
246
- register(token, exports.HighlightType.Keyword.When);
247
- break;
248
- case MalloyParser_1.MalloyParser.WITH:
249
- register(token, exports.HighlightType.Keyword.With);
250
- break;
251
- case MalloyParser_1.MalloyParser.ELSE:
252
- register(token, exports.HighlightType.Keyword.Else);
253
- break;
254
- case MalloyParser_1.MalloyParser.JSON:
255
- register(token, exports.HighlightType.Keyword.JSON);
256
- break;
257
- case MalloyParser_1.MalloyParser.TURTLE:
258
- register(token, exports.HighlightType.Keyword.Turtle);
259
- break;
260
- case MalloyParser_1.MalloyParser.TRUE:
261
- case MalloyParser_1.MalloyParser.FALSE:
262
- register(token, exports.HighlightType.Literal.Boolean);
263
- break;
264
- case MalloyParser_1.MalloyParser.NOW:
265
- case MalloyParser_1.MalloyParser.LITERAL_TIMESTAMP:
266
- case MalloyParser_1.MalloyParser.LITERAL_QUARTER:
267
- case MalloyParser_1.MalloyParser.LITERAL_MONTH:
268
- case MalloyParser_1.MalloyParser.LITERAL_DAY:
269
- case MalloyParser_1.MalloyParser.LITERAL_WEEK:
270
- case MalloyParser_1.MalloyParser.LITERAL_YEAR:
271
- register(token, exports.HighlightType.Literal.Date);
272
- break;
273
- case MalloyParser_1.MalloyParser.NULL:
274
- register(token, exports.HighlightType.Literal.Null);
275
- break;
276
- case MalloyParser_1.MalloyParser.AND:
277
- case MalloyParser_1.MalloyParser.OR:
278
- case MalloyParser_1.MalloyParser.NOT:
279
- register(token, exports.HighlightType.Operator.Boolean);
280
- break;
281
- case MalloyParser_1.MalloyParser.FOR:
282
- register(token, exports.HighlightType.Operator.Date);
283
- break;
284
- case MalloyParser_1.MalloyParser.COMMENT_TO_EOL:
285
- register(token, exports.HighlightType.Comment.Line);
286
- break;
287
- case MalloyParser_1.MalloyParser.BLOCK_COMMENT:
288
- register(token, exports.HighlightType.Comment.Block);
289
- break;
290
- case MalloyParser_1.MalloyParser.SUM:
291
- case MalloyParser_1.MalloyParser.COUNT:
292
- case MalloyParser_1.MalloyParser.AVG:
293
- case MalloyParser_1.MalloyParser.MIN:
294
- case MalloyParser_1.MalloyParser.MAX:
295
- register(token, exports.HighlightType.Call.Aggregate);
296
- break;
297
- case MalloyParser_1.MalloyParser.IDENTIFIER:
298
- case MalloyParser_1.MalloyParser.OBJECT_NAME_LITERAL:
299
- register(token, exports.HighlightType.Identifier);
300
- break;
301
- case MalloyParser_1.MalloyParser.STRING:
302
- case MalloyParser_1.MalloyParser.NUMBER:
303
- case MalloyParser_1.MalloyParser.BOOLEAN:
304
- case MalloyParser_1.MalloyParser.DATE:
305
- case MalloyParser_1.MalloyParser.TIMESTAMP:
306
- register(token, exports.HighlightType.Type);
307
- break;
308
- case MalloyParser_1.MalloyParser.SECOND:
309
- case MalloyParser_1.MalloyParser.MINUTE:
310
- case MalloyParser_1.MalloyParser.HOUR:
311
- case MalloyParser_1.MalloyParser.DAY:
312
- case MalloyParser_1.MalloyParser.WEEK:
313
- case MalloyParser_1.MalloyParser.MONTH:
314
- case MalloyParser_1.MalloyParser.QUARTER:
315
- case MalloyParser_1.MalloyParser.YEAR:
316
- register(token, exports.HighlightType.Call.TimeFrame);
317
- break;
318
- case MalloyParser_1.MalloyParser.IMPORT:
319
- register(token, exports.HighlightType.Keyword.Import);
320
- break;
321
- // TODO durations? How should we highlight `3 days` or
322
- // `(1 + 2) days` or `n days`?
323
- }
324
- }
325
- return highlights;
326
- }
327
- exports.passForHighlights = passForHighlights;
328
- class DocumentHighlightWalker {
329
- constructor(tokens, highlights) {
330
- this.tokens = tokens;
331
- this.highlights = highlights;
332
- }
333
- rangeOf(pcx) {
334
- const stopToken = pcx.stop || pcx.start;
335
- return {
336
- start: {
337
- line: pcx.start.line - 1,
338
- character: pcx.start.charPositionInLine,
339
- },
340
- end: {
341
- line: stopToken.line - 1,
342
- character: stopToken.stopIndex -
343
- (stopToken.startIndex - stopToken.charPositionInLine) +
344
- 1,
345
- },
346
- };
347
- }
348
- enterExprFunc(pcx) {
349
- const id = pcx.id() || pcx.timeframe();
350
- if (id) {
351
- this.highlights.push({
352
- range: this.rangeOf(id),
353
- type: exports.HighlightType.Call.Function,
354
- });
355
- }
356
- }
357
- }
358
- function walkForDocumentHighlights(tokens, parseTree) {
359
- const finder = new DocumentHighlightWalker(tokens, []);
360
- const listener = finder;
361
- ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseTree);
362
- return finder.highlights;
363
- }
364
- exports.walkForDocumentHighlights = walkForDocumentHighlights;
365
- function sortHighlights(highlights) {
366
- return highlights.sort((a, b) => {
367
- if (a.range.start.line < b.range.start.line) {
368
- return -1;
369
- }
370
- else if (a.range.start.line > b.range.start.line) {
371
- return 1;
372
- }
373
- else if (a.range.start.character < b.range.start.character) {
374
- return -1;
375
- }
376
- else if (a.range.start.character > b.range.start.character) {
377
- return 1;
378
- }
379
- else {
380
- return 0;
381
- }
382
- });
383
- }
384
- exports.sortHighlights = sortHighlights;
385
- //# sourceMappingURL=document-highlight-walker.js.map
@@ -1,11 +0,0 @@
1
- import { CommonTokenStream } from "antlr4ts";
2
- import { ParseTree } from "antlr4ts/tree";
3
- import { DocumentRange } from "../../model/malloy_types";
4
- import { MalloyTranslation } from "../parse-malloy";
5
- export interface DocumentSymbol {
6
- range: DocumentRange;
7
- type: string;
8
- name: string;
9
- children: DocumentSymbol[];
10
- }
11
- export declare function walkForDocumentSymbols(forParse: MalloyTranslation, tokens: CommonTokenStream, parseTree: ParseTree): DocumentSymbol[];
@@ -1,182 +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.walkForDocumentSymbols = void 0;
26
- const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
27
- class DocumentSymbolWalker {
28
- constructor(translator, tokens, scopes, symbols) {
29
- this.translator = translator;
30
- this.tokens = tokens;
31
- this.scopes = scopes;
32
- this.symbols = symbols;
33
- }
34
- popScope() {
35
- return this.scopes.pop();
36
- }
37
- peekScope() {
38
- return this.scopes[this.scopes.length - 1];
39
- }
40
- enterTopLevelQueryDef(pcx) {
41
- this.symbols.push({
42
- range: this.translator.rangeFromContext(pcx),
43
- name: pcx.queryName().text,
44
- type: "query",
45
- children: [],
46
- });
47
- }
48
- enterTopLevelAnonQueryDef(pcx) {
49
- this.symbols.push({
50
- range: this.translator.rangeFromContext(pcx),
51
- name: "unnamed_query",
52
- type: "unnamed_query",
53
- children: [],
54
- });
55
- }
56
- enterExploreDefinition(pcx) {
57
- this.scopes.push({
58
- range: this.translator.rangeFromContext(pcx),
59
- name: pcx.exploreNameDef().id().text,
60
- type: "explore",
61
- children: [],
62
- });
63
- }
64
- exitExploreDefinition(_pcx) {
65
- const scope = this.popScope();
66
- if (scope) {
67
- this.symbols.push(scope);
68
- }
69
- }
70
- enterExploreQueryDef(pcx) {
71
- const symbol = {
72
- range: this.translator.rangeFromContext(pcx),
73
- name: pcx.exploreQueryNameDef().id().text,
74
- type: "query",
75
- children: [],
76
- };
77
- const parent = this.peekScope();
78
- if (parent) {
79
- parent.children.push(symbol);
80
- }
81
- this.scopes.push(symbol);
82
- }
83
- exitExploreQueryDef(_pcx) {
84
- this.popScope();
85
- }
86
- handleNestEntry(pcx) {
87
- const symbol = {
88
- range: this.translator.rangeFromContext(pcx),
89
- name: pcx.queryName().id().text,
90
- type: "query",
91
- children: [],
92
- };
93
- const parent = this.peekScope();
94
- if (parent) {
95
- parent.children.push(symbol);
96
- }
97
- return symbol;
98
- }
99
- enterNestExisting(pcx) {
100
- this.handleNestEntry(pcx);
101
- }
102
- enterNestDef(pcx) {
103
- const symbol = this.handleNestEntry(pcx);
104
- this.scopes.push(symbol);
105
- }
106
- exitNestDef(_pcx) {
107
- this.popScope();
108
- }
109
- enterFieldDef(pcx) {
110
- const symbol = {
111
- range: this.translator.rangeFromContext(pcx),
112
- name: pcx.fieldNameDef().id().text,
113
- type: "field",
114
- children: [],
115
- };
116
- const parent = this.peekScope();
117
- if (parent) {
118
- parent.children.push(symbol);
119
- }
120
- }
121
- enterQueryFieldRef(pcx) {
122
- const symbol = {
123
- range: this.translator.rangeFromContext(pcx),
124
- name: pcx.fieldPath().text,
125
- type: "field",
126
- children: [],
127
- };
128
- const parent = this.peekScope();
129
- if (parent) {
130
- parent.children.push(symbol);
131
- }
132
- }
133
- enterExploreRenameDef(pcx) {
134
- const symbol = {
135
- range: this.translator.rangeFromContext(pcx),
136
- name: pcx.fieldName()[0].text,
137
- type: "field",
138
- children: [],
139
- };
140
- const parent = this.peekScope();
141
- if (parent) {
142
- parent.children.push(symbol);
143
- }
144
- }
145
- enterJoinWith(pcx) {
146
- this.handleJoinDef(pcx);
147
- }
148
- enterJoinOn(pcx) {
149
- this.handleJoinDef(pcx);
150
- }
151
- handleJoinDef(pcx) {
152
- const symbol = {
153
- range: this.translator.rangeFromContext(pcx),
154
- name: pcx.joinNameDef().id().text,
155
- type: "join",
156
- children: [],
157
- };
158
- const parent = this.peekScope();
159
- if (parent) {
160
- parent.children.push(symbol);
161
- }
162
- }
163
- enterDefineSQLStatement(pcx) {
164
- var _a;
165
- const name = (_a = pcx.nameSQLBlock()) === null || _a === void 0 ? void 0 : _a.text;
166
- const symbol = {
167
- range: this.translator.rangeFromContext(pcx),
168
- name: name || "unnamed_sql",
169
- type: name === undefined ? "unnamed_sql" : "sql",
170
- children: [],
171
- };
172
- this.symbols.push(symbol);
173
- }
174
- }
175
- function walkForDocumentSymbols(forParse, tokens, parseTree) {
176
- const finder = new DocumentSymbolWalker(forParse, tokens, [], []);
177
- const listener = finder;
178
- ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseTree);
179
- return finder.symbols;
180
- }
181
- exports.walkForDocumentSymbols = walkForDocumentSymbols;
182
- //# sourceMappingURL=document-symbol-walker.js.map
@@ -1,34 +0,0 @@
1
- import { CommonTokenStream } from "antlr4ts";
2
- import { ParseTree } from "antlr4ts/tree";
3
- import { MalloyParserListener } from "../lib/Malloy/MalloyParserListener";
4
- declare type SimpleRange = [number | undefined, number | undefined];
5
- export interface FilterRef {
6
- text: string;
7
- range: SimpleRange;
8
- }
9
- export interface FilterList {
10
- range: SimpleRange;
11
- }
12
- export interface ExploreRef {
13
- text: string;
14
- range: SimpleRange;
15
- }
16
- export interface ExploreClauseRef {
17
- exploreRef: ExploreRef;
18
- filterRefs: FilterRef[];
19
- filterLists: FilterList[];
20
- range: SimpleRange;
21
- }
22
- export declare class ExploreQueryWalker implements MalloyParserListener {
23
- tokens: CommonTokenStream;
24
- exploreClauseRefs: ExploreClauseRef[];
25
- currentExploreClauseRef: ExploreClauseRef | undefined;
26
- constructor(tokens: CommonTokenStream);
27
- exploreQueryAtOffset(offset: number): ExploreClauseRef | undefined;
28
- filterAtOffset(offset: number): FilterRef | undefined;
29
- hasFilterListAtOffset(offset: number): boolean;
30
- inDocument: boolean;
31
- enterMalloyDocument(): void;
32
- }
33
- export declare function exploreQueryWalkerBuilder(tokens: CommonTokenStream, parseTree: ParseTree): ExploreQueryWalker;
34
- export {};
@@ -1,74 +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.exploreQueryWalkerBuilder = exports.ExploreQueryWalker = void 0;
26
- const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
27
- class ExploreQueryWalker {
28
- constructor(tokens) {
29
- // just to make this compile, no need for this
30
- this.inDocument = false;
31
- this.exploreClauseRefs = [];
32
- this.tokens = tokens;
33
- }
34
- exploreQueryAtOffset(offset) {
35
- return this.exploreClauseRefs.find((ex) => {
36
- if (ex.range[0] === undefined || ex.range[1] === undefined)
37
- return false;
38
- return ex.range[0] <= offset && ex.range[1] >= offset;
39
- });
40
- }
41
- filterAtOffset(offset) {
42
- const exploreRef = this.exploreQueryAtOffset(offset);
43
- if (!exploreRef)
44
- return;
45
- return exploreRef.filterRefs.find((filterRef) => {
46
- if (filterRef.range[0] === undefined || filterRef.range[1] === undefined)
47
- return false;
48
- return filterRef.range[0] <= offset && filterRef.range[1] >= offset;
49
- });
50
- }
51
- hasFilterListAtOffset(offset) {
52
- const exploreRef = this.exploreQueryAtOffset(offset);
53
- if (!exploreRef)
54
- return false;
55
- return !!exploreRef.filterLists.find((filterList) => {
56
- if (filterList.range[0] === undefined ||
57
- filterList.range[1] === undefined)
58
- return false;
59
- return filterList.range[0] <= offset && filterList.range[1] >= offset;
60
- });
61
- }
62
- enterMalloyDocument() {
63
- this.inDocument = true;
64
- }
65
- }
66
- exports.ExploreQueryWalker = ExploreQueryWalker;
67
- function exploreQueryWalkerBuilder(tokens, parseTree) {
68
- const finder = new ExploreQueryWalker(tokens);
69
- const listener = finder;
70
- ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseTree);
71
- return finder;
72
- }
73
- exports.exploreQueryWalkerBuilder = exploreQueryWalkerBuilder;
74
- //# sourceMappingURL=explore-query-walker.js.map