@malloydata/malloy 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.
Files changed (104) hide show
  1. package/README.md +39 -0
  2. package/dist/connection_utils.d.ts +1 -0
  3. package/dist/connection_utils.js +56 -0
  4. package/dist/dialect/dialect-map.d.ts +3 -0
  5. package/dist/dialect/dialect-map.js +33 -0
  6. package/dist/dialect/dialect.d.ts +64 -0
  7. package/dist/dialect/dialect.js +64 -0
  8. package/dist/dialect/dialect_map.d.ts +3 -0
  9. package/dist/dialect/dialect_map.js +35 -0
  10. package/dist/dialect/duckdb.d.ts +49 -0
  11. package/dist/dialect/duckdb.js +349 -0
  12. package/dist/dialect/index.d.ts +6 -0
  13. package/dist/dialect/index.js +27 -0
  14. package/dist/dialect/postgres.d.ts +49 -0
  15. package/dist/dialect/postgres.js +308 -0
  16. package/dist/dialect/standardsql.d.ts +46 -0
  17. package/dist/dialect/standardsql.js +361 -0
  18. package/dist/index.d.ts +9 -0
  19. package/dist/index.js +47 -0
  20. package/dist/lang/ast/apply-expr.d.ts +16 -0
  21. package/dist/lang/ast/apply-expr.js +215 -0
  22. package/dist/lang/ast/ast-expr.d.ts +291 -0
  23. package/dist/lang/ast/ast-expr.js +1056 -0
  24. package/dist/lang/ast/ast-main.d.ts +480 -0
  25. package/dist/lang/ast/ast-main.js +2096 -0
  26. package/dist/lang/ast/ast-time-expr.d.ts +109 -0
  27. package/dist/lang/ast/ast-time-expr.js +550 -0
  28. package/dist/lang/ast/ast-types.d.ts +83 -0
  29. package/dist/lang/ast/ast-types.js +215 -0
  30. package/dist/lang/ast/index.d.ts +5 -0
  31. package/dist/lang/ast/index.js +34 -0
  32. package/dist/lang/ast/time-utils.d.ts +8 -0
  33. package/dist/lang/ast/time-utils.js +83 -0
  34. package/dist/lang/field-space.d.ts +157 -0
  35. package/dist/lang/field-space.js +651 -0
  36. package/dist/lang/field-utils.d.ts +5 -0
  37. package/dist/lang/field-utils.js +33 -0
  38. package/dist/lang/index.d.ts +9 -0
  39. package/dist/lang/index.js +22 -0
  40. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +156 -0
  41. package/dist/lang/lib/Malloy/MalloyLexer.js +1163 -0
  42. package/dist/lang/lib/Malloy/MalloyListener.d.ts +2026 -0
  43. package/dist/lang/lib/Malloy/MalloyListener.js +4 -0
  44. package/dist/lang/lib/Malloy/MalloyParser.d.ts +1920 -0
  45. package/dist/lang/lib/Malloy/MalloyParser.js +11790 -0
  46. package/dist/lang/lib/Malloy/MalloyVisitor.d.ts +1276 -0
  47. package/dist/lang/lib/Malloy/MalloyVisitor.js +4 -0
  48. package/dist/lang/parse-log.d.ts +27 -0
  49. package/dist/lang/parse-log.js +41 -0
  50. package/dist/lang/parse-malloy.d.ts +245 -0
  51. package/dist/lang/parse-malloy.js +729 -0
  52. package/dist/lang/parse-to-ast.d.ts +156 -0
  53. package/dist/lang/parse-to-ast.js +945 -0
  54. package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +10 -0
  55. package/dist/lang/parse-tree-walkers/document-completion-walker.js +136 -0
  56. package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +9 -0
  57. package/dist/lang/parse-tree-walkers/document-help-context-walker.js +97 -0
  58. package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +83 -0
  59. package/dist/lang/parse-tree-walkers/document-highlight-walker.js +375 -0
  60. package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +11 -0
  61. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +172 -0
  62. package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +34 -0
  63. package/dist/lang/parse-tree-walkers/explore-query-walker.js +64 -0
  64. package/dist/lang/parse-tree-walkers/find-external-references.d.ts +11 -0
  65. package/dist/lang/parse-tree-walkers/find-external-references.js +51 -0
  66. package/dist/lang/reference-list.d.ts +10 -0
  67. package/dist/lang/reference-list.js +80 -0
  68. package/dist/lang/space-field.d.ts +119 -0
  69. package/dist/lang/space-field.js +339 -0
  70. package/dist/lang/test/document-help-context-walker.spec.d.ts +1 -0
  71. package/dist/lang/test/document-help-context-walker.spec.js +45 -0
  72. package/dist/lang/test/document-symbol-walker.spec.d.ts +1 -0
  73. package/dist/lang/test/document-symbol-walker.spec.js +100 -0
  74. package/dist/lang/test/field-symbols.spec.d.ts +1 -0
  75. package/dist/lang/test/field-symbols.spec.js +172 -0
  76. package/dist/lang/test/parse.spec.d.ts +12 -0
  77. package/dist/lang/test/parse.spec.js +1936 -0
  78. package/dist/lang/test/test-translator.d.ts +38 -0
  79. package/dist/lang/test/test-translator.js +334 -0
  80. package/dist/lang/zone.d.ts +57 -0
  81. package/dist/lang/zone.js +97 -0
  82. package/dist/malloy.d.ts +1134 -0
  83. package/dist/malloy.js +2354 -0
  84. package/dist/model/index.d.ts +2 -0
  85. package/dist/model/index.js +34 -0
  86. package/dist/model/malloy-query.d.ts +313 -0
  87. package/dist/model/malloy-query.js +2603 -0
  88. package/dist/model/malloy-types.d.ts +404 -0
  89. package/dist/model/malloy-types.js +242 -0
  90. package/dist/model/malloy_query.d.ts +353 -0
  91. package/dist/model/malloy_query.js +2990 -0
  92. package/dist/model/malloy_types.d.ts +502 -0
  93. package/dist/model/malloy_types.js +283 -0
  94. package/dist/model/sql-block.d.ts +11 -0
  95. package/dist/model/sql-block.js +38 -0
  96. package/dist/model/sql_block.d.ts +11 -0
  97. package/dist/model/sql_block.js +41 -0
  98. package/dist/model/utils.d.ts +21 -0
  99. package/dist/model/utils.js +84 -0
  100. package/dist/runtime-types.d.ts +116 -0
  101. package/dist/runtime-types.js +40 -0
  102. package/dist/runtime_types.d.ts +119 -0
  103. package/dist/runtime_types.js +15 -0
  104. package/package.json +36 -0
@@ -0,0 +1,375 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * version 2 as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.sortHighlights = exports.walkForDocumentHighlights = exports.passForHighlights = exports.HighlightType = void 0;
16
+ const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
17
+ const MalloyParser_1 = require("../lib/Malloy/MalloyParser");
18
+ // TODO maybe this could be an enum like Definition__Field, etc.
19
+ exports.HighlightType = {
20
+ Identifier: "identifier",
21
+ Type: "type",
22
+ Literal: {
23
+ Date: "literal.date",
24
+ Number: "literal.number",
25
+ String: "literal.string",
26
+ RegularExpression: "literal.regular_expression",
27
+ Boolean: "literal.boolean",
28
+ Null: "literal.null",
29
+ },
30
+ Call: {
31
+ Aggregate: "call.aggregate",
32
+ TimeFrame: "call.time_frame",
33
+ Cast: "call.cast",
34
+ Table: "call.table",
35
+ From: "call.from",
36
+ Function: "call.function",
37
+ FromSQL: "call.from_sql",
38
+ },
39
+ // TODO many of these should probably be categorized further
40
+ Keyword: {
41
+ AggregateModifier: {
42
+ Distinct: "keyword.aggregate_modifier.distinct",
43
+ },
44
+ CastModifier: {
45
+ As: "keyword.cast_modifier.as",
46
+ },
47
+ Is: "keyword.is",
48
+ On: "keyword.on",
49
+ Desc: "keyword.desc",
50
+ Asc: "keyword.asc",
51
+ Pick: "keyword.pick",
52
+ When: "keyword.when",
53
+ Else: "keyword.else",
54
+ With: "keyword.with",
55
+ // TODO or is this a meta type?
56
+ JSON: "keyword.json",
57
+ // TODO or is this a meta type?
58
+ Turtle: "keyword.turtle",
59
+ Import: "keyword.import",
60
+ },
61
+ Operator: {
62
+ Comparison: "operator.comparison",
63
+ Boolean: "operator.boolean",
64
+ Date: "operator.date",
65
+ },
66
+ Comment: {
67
+ Line: "comment.line",
68
+ Block: "comment.block",
69
+ },
70
+ Property: {
71
+ Accept: "property.accept",
72
+ Aggregate: "property.aggregate",
73
+ Dimension: "property.dimension",
74
+ Except: "property.except",
75
+ Source: "property.source",
76
+ GroupBy: "property.group_by",
77
+ Having: "property.having",
78
+ Index: "property.index",
79
+ JoinOne: "keyword.join_one",
80
+ JoinMany: "keyword.join_many",
81
+ JoinCross: "keyword.join_cross",
82
+ Limit: "property.limit",
83
+ Measure: "property.measure",
84
+ Nest: "property.nest",
85
+ OrderBy: "property.order_by",
86
+ PrimaryKey: "property.primary_key",
87
+ Project: "property.project",
88
+ Query: "property.query",
89
+ Rename: "property.rename",
90
+ Top: "property.top",
91
+ Where: "property.where",
92
+ SQL: "property.sql",
93
+ },
94
+ };
95
+ function passForHighlights(tokens) {
96
+ const highlights = [];
97
+ const register = (token, type, removeColon = false) => {
98
+ var _a;
99
+ const offset = token.startIndex - token.charPositionInLine;
100
+ const tokenLines = ((_a = token.text) === null || _a === void 0 ? void 0 : _a.split("\n")) || [];
101
+ const numberOfLines = tokenLines.length;
102
+ const lengthOfAllButLastLine = tokenLines
103
+ .slice(0, -1)
104
+ .reduce((a, l) => a + l.length, 0);
105
+ const colonAdjustment = removeColon ? 1 : 0;
106
+ highlights.push({
107
+ type,
108
+ range: {
109
+ start: { line: token.line - 1, character: token.startIndex - offset },
110
+ end: {
111
+ line: token.line - 1 + numberOfLines - 1,
112
+ character: token.stopIndex +
113
+ 2 -
114
+ (numberOfLines > 1 ? token.startIndex : offset) -
115
+ lengthOfAllButLastLine -
116
+ numberOfLines -
117
+ colonAdjustment,
118
+ },
119
+ },
120
+ });
121
+ };
122
+ for (let i = 0; i < tokens.size; i++) {
123
+ const token = tokens.get(i);
124
+ switch (token.type) {
125
+ case MalloyParser_1.MalloyParser.ACCEPT:
126
+ register(token, exports.HighlightType.Property.Accept, true);
127
+ break;
128
+ case MalloyParser_1.MalloyParser.AGGREGATE:
129
+ register(token, exports.HighlightType.Property.Aggregate, true);
130
+ break;
131
+ case MalloyParser_1.MalloyParser.DIMENSION:
132
+ register(token, exports.HighlightType.Property.Dimension, true);
133
+ break;
134
+ case MalloyParser_1.MalloyParser.EXCEPT:
135
+ register(token, exports.HighlightType.Property.Except, true);
136
+ break;
137
+ case MalloyParser_1.MalloyParser.GROUP_BY:
138
+ register(token, exports.HighlightType.Property.GroupBy, true);
139
+ break;
140
+ case MalloyParser_1.MalloyParser.HAVING:
141
+ register(token, exports.HighlightType.Property.Having, true);
142
+ break;
143
+ case MalloyParser_1.MalloyParser.INDEX:
144
+ register(token, exports.HighlightType.Property.Index, true);
145
+ break;
146
+ case MalloyParser_1.MalloyParser.JOIN_CROSS:
147
+ register(token, exports.HighlightType.Property.JoinOne, true);
148
+ break;
149
+ case MalloyParser_1.MalloyParser.JOIN_ONE:
150
+ register(token, exports.HighlightType.Property.JoinMany, true);
151
+ break;
152
+ case MalloyParser_1.MalloyParser.JOIN_MANY:
153
+ register(token, exports.HighlightType.Property.JoinCross, true);
154
+ break;
155
+ case MalloyParser_1.MalloyParser.LIMIT:
156
+ register(token, exports.HighlightType.Property.Limit, true);
157
+ break;
158
+ case MalloyParser_1.MalloyParser.MEASURE:
159
+ register(token, exports.HighlightType.Property.Measure, true);
160
+ break;
161
+ case MalloyParser_1.MalloyParser.NEST:
162
+ register(token, exports.HighlightType.Property.Nest, true);
163
+ break;
164
+ case MalloyParser_1.MalloyParser.ORDER_BY:
165
+ register(token, exports.HighlightType.Property.OrderBy, true);
166
+ break;
167
+ case MalloyParser_1.MalloyParser.PRIMARY_KEY:
168
+ register(token, exports.HighlightType.Property.PrimaryKey, true);
169
+ break;
170
+ case MalloyParser_1.MalloyParser.PROJECT:
171
+ register(token, exports.HighlightType.Property.Project, true);
172
+ break;
173
+ case MalloyParser_1.MalloyParser.QUERY:
174
+ register(token, exports.HighlightType.Property.Query, true);
175
+ break;
176
+ case MalloyParser_1.MalloyParser.RENAME:
177
+ register(token, exports.HighlightType.Property.Rename, true);
178
+ break;
179
+ case MalloyParser_1.MalloyParser.SOURCE:
180
+ register(token, exports.HighlightType.Property.Source, true);
181
+ break;
182
+ case MalloyParser_1.MalloyParser.TOP:
183
+ register(token, exports.HighlightType.Property.Top, true);
184
+ break;
185
+ case MalloyParser_1.MalloyParser.WHERE:
186
+ register(token, exports.HighlightType.Property.Where, true);
187
+ break;
188
+ case MalloyParser_1.MalloyParser.SQL:
189
+ register(token, exports.HighlightType.Property.SQL, true);
190
+ break;
191
+ case MalloyParser_1.MalloyParser.TABLE:
192
+ register(token, exports.HighlightType.Call.Table);
193
+ break;
194
+ case MalloyParser_1.MalloyParser.FROM:
195
+ register(token, exports.HighlightType.Call.From);
196
+ break;
197
+ case MalloyParser_1.MalloyParser.FROM_SQL:
198
+ register(token, exports.HighlightType.Call.FromSQL);
199
+ break;
200
+ case MalloyParser_1.MalloyParser.STRING_LITERAL:
201
+ case MalloyParser_1.MalloyParser.JSON_STRING:
202
+ register(token, exports.HighlightType.Literal.String);
203
+ break;
204
+ case MalloyParser_1.MalloyParser.NUMERIC_LITERAL:
205
+ case MalloyParser_1.MalloyParser.INTEGER_LITERAL:
206
+ register(token, exports.HighlightType.Literal.Number);
207
+ break;
208
+ case MalloyParser_1.MalloyParser.HACKY_REGEX:
209
+ register(token, exports.HighlightType.Literal.RegularExpression);
210
+ break;
211
+ case MalloyParser_1.MalloyParser.IS:
212
+ register(token, exports.HighlightType.Keyword.Is);
213
+ break;
214
+ case MalloyParser_1.MalloyParser.DISTINCT:
215
+ register(token, exports.HighlightType.Keyword.AggregateModifier.Distinct);
216
+ break;
217
+ case MalloyParser_1.MalloyParser.ON:
218
+ register(token, exports.HighlightType.Keyword.On);
219
+ break;
220
+ case MalloyParser_1.MalloyParser.DESC:
221
+ register(token, exports.HighlightType.Keyword.Desc);
222
+ break;
223
+ case MalloyParser_1.MalloyParser.ASC:
224
+ register(token, exports.HighlightType.Keyword.Asc);
225
+ break;
226
+ case MalloyParser_1.MalloyParser.CAST:
227
+ register(token, exports.HighlightType.Call.Cast);
228
+ break;
229
+ case MalloyParser_1.MalloyParser.AS:
230
+ register(token, exports.HighlightType.Keyword.CastModifier.As);
231
+ break;
232
+ case MalloyParser_1.MalloyParser.PICK:
233
+ register(token, exports.HighlightType.Keyword.Pick);
234
+ break;
235
+ case MalloyParser_1.MalloyParser.WHEN:
236
+ register(token, exports.HighlightType.Keyword.When);
237
+ break;
238
+ case MalloyParser_1.MalloyParser.WITH:
239
+ register(token, exports.HighlightType.Keyword.With);
240
+ break;
241
+ case MalloyParser_1.MalloyParser.ELSE:
242
+ register(token, exports.HighlightType.Keyword.Else);
243
+ break;
244
+ case MalloyParser_1.MalloyParser.JSON:
245
+ register(token, exports.HighlightType.Keyword.JSON);
246
+ break;
247
+ case MalloyParser_1.MalloyParser.TURTLE:
248
+ register(token, exports.HighlightType.Keyword.Turtle);
249
+ break;
250
+ case MalloyParser_1.MalloyParser.TRUE:
251
+ case MalloyParser_1.MalloyParser.FALSE:
252
+ register(token, exports.HighlightType.Literal.Boolean);
253
+ break;
254
+ case MalloyParser_1.MalloyParser.NOW:
255
+ case MalloyParser_1.MalloyParser.LITERAL_TIMESTAMP:
256
+ case MalloyParser_1.MalloyParser.LITERAL_QUARTER:
257
+ case MalloyParser_1.MalloyParser.LITERAL_MONTH:
258
+ case MalloyParser_1.MalloyParser.LITERAL_DAY:
259
+ case MalloyParser_1.MalloyParser.LITERAL_WEEK:
260
+ case MalloyParser_1.MalloyParser.LITERAL_YEAR:
261
+ register(token, exports.HighlightType.Literal.Date);
262
+ break;
263
+ case MalloyParser_1.MalloyParser.NULL:
264
+ register(token, exports.HighlightType.Literal.Null);
265
+ break;
266
+ case MalloyParser_1.MalloyParser.AND:
267
+ case MalloyParser_1.MalloyParser.OR:
268
+ case MalloyParser_1.MalloyParser.NOT:
269
+ register(token, exports.HighlightType.Operator.Boolean);
270
+ break;
271
+ case MalloyParser_1.MalloyParser.FOR:
272
+ register(token, exports.HighlightType.Operator.Date);
273
+ break;
274
+ case MalloyParser_1.MalloyParser.COMMENT_TO_EOL:
275
+ register(token, exports.HighlightType.Comment.Line);
276
+ break;
277
+ case MalloyParser_1.MalloyParser.BLOCK_COMMENT:
278
+ register(token, exports.HighlightType.Comment.Block);
279
+ break;
280
+ case MalloyParser_1.MalloyParser.SUM:
281
+ case MalloyParser_1.MalloyParser.COUNT:
282
+ case MalloyParser_1.MalloyParser.AVG:
283
+ case MalloyParser_1.MalloyParser.MIN:
284
+ case MalloyParser_1.MalloyParser.MAX:
285
+ register(token, exports.HighlightType.Call.Aggregate);
286
+ break;
287
+ case MalloyParser_1.MalloyParser.IDENTIFIER:
288
+ case MalloyParser_1.MalloyParser.OBJECT_NAME_LITERAL:
289
+ register(token, exports.HighlightType.Identifier);
290
+ break;
291
+ case MalloyParser_1.MalloyParser.STRING:
292
+ case MalloyParser_1.MalloyParser.NUMBER:
293
+ case MalloyParser_1.MalloyParser.BOOLEAN:
294
+ case MalloyParser_1.MalloyParser.DATE:
295
+ case MalloyParser_1.MalloyParser.TIMESTAMP:
296
+ register(token, exports.HighlightType.Type);
297
+ break;
298
+ case MalloyParser_1.MalloyParser.SECOND:
299
+ case MalloyParser_1.MalloyParser.MINUTE:
300
+ case MalloyParser_1.MalloyParser.HOUR:
301
+ case MalloyParser_1.MalloyParser.DAY:
302
+ case MalloyParser_1.MalloyParser.WEEK:
303
+ case MalloyParser_1.MalloyParser.MONTH:
304
+ case MalloyParser_1.MalloyParser.QUARTER:
305
+ case MalloyParser_1.MalloyParser.YEAR:
306
+ register(token, exports.HighlightType.Call.TimeFrame);
307
+ break;
308
+ case MalloyParser_1.MalloyParser.IMPORT:
309
+ register(token, exports.HighlightType.Keyword.Import);
310
+ break;
311
+ // TODO durations? How should we highlight `3 days` or
312
+ // `(1 + 2) days` or `n days`?
313
+ }
314
+ }
315
+ return highlights;
316
+ }
317
+ exports.passForHighlights = passForHighlights;
318
+ class DocumentHighlightWalker {
319
+ constructor(tokens, highlights) {
320
+ this.tokens = tokens;
321
+ this.highlights = highlights;
322
+ }
323
+ rangeOf(pcx) {
324
+ const stopToken = pcx.stop || pcx.start;
325
+ return {
326
+ start: {
327
+ line: pcx.start.line - 1,
328
+ character: pcx.start.charPositionInLine,
329
+ },
330
+ end: {
331
+ line: stopToken.line - 1,
332
+ character: stopToken.stopIndex -
333
+ (stopToken.startIndex - stopToken.charPositionInLine) +
334
+ 1,
335
+ },
336
+ };
337
+ }
338
+ enterExprFunc(pcx) {
339
+ const id = pcx.id() || pcx.timeframe();
340
+ if (id) {
341
+ this.highlights.push({
342
+ range: this.rangeOf(id),
343
+ type: exports.HighlightType.Call.Function,
344
+ });
345
+ }
346
+ }
347
+ }
348
+ function walkForDocumentHighlights(tokens, parseTree) {
349
+ const finder = new DocumentHighlightWalker(tokens, []);
350
+ const listener = finder;
351
+ ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseTree);
352
+ return finder.highlights;
353
+ }
354
+ exports.walkForDocumentHighlights = walkForDocumentHighlights;
355
+ function sortHighlights(highlights) {
356
+ return highlights.sort((a, b) => {
357
+ if (a.range.start.line < b.range.start.line) {
358
+ return -1;
359
+ }
360
+ else if (a.range.start.line > b.range.start.line) {
361
+ return 1;
362
+ }
363
+ else if (a.range.start.character < b.range.start.character) {
364
+ return -1;
365
+ }
366
+ else if (a.range.start.character > b.range.start.character) {
367
+ return 1;
368
+ }
369
+ else {
370
+ return 0;
371
+ }
372
+ });
373
+ }
374
+ exports.sortHighlights = sortHighlights;
375
+ //# sourceMappingURL=document-highlight-walker.js.map
@@ -0,0 +1,11 @@
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[];
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * version 2 as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.walkForDocumentSymbols = void 0;
16
+ const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
17
+ class DocumentSymbolWalker {
18
+ constructor(translator, tokens, scopes, symbols) {
19
+ this.translator = translator;
20
+ this.tokens = tokens;
21
+ this.scopes = scopes;
22
+ this.symbols = symbols;
23
+ }
24
+ popScope() {
25
+ return this.scopes.pop();
26
+ }
27
+ peekScope() {
28
+ return this.scopes[this.scopes.length - 1];
29
+ }
30
+ enterTopLevelQueryDef(pcx) {
31
+ this.symbols.push({
32
+ range: this.translator.rangeFromContext(pcx),
33
+ name: pcx.queryName().text,
34
+ type: "query",
35
+ children: [],
36
+ });
37
+ }
38
+ enterTopLevelAnonQueryDef(pcx) {
39
+ this.symbols.push({
40
+ range: this.translator.rangeFromContext(pcx),
41
+ name: "unnamed_query",
42
+ type: "unnamed_query",
43
+ children: [],
44
+ });
45
+ }
46
+ enterExploreDefinition(pcx) {
47
+ this.scopes.push({
48
+ range: this.translator.rangeFromContext(pcx),
49
+ name: pcx.exploreNameDef().id().text,
50
+ type: "explore",
51
+ children: [],
52
+ });
53
+ }
54
+ exitExploreDefinition(_pcx) {
55
+ const scope = this.popScope();
56
+ if (scope) {
57
+ this.symbols.push(scope);
58
+ }
59
+ }
60
+ enterExploreQueryDef(pcx) {
61
+ const symbol = {
62
+ range: this.translator.rangeFromContext(pcx),
63
+ name: pcx.exploreQueryNameDef().id().text,
64
+ type: "query",
65
+ children: [],
66
+ };
67
+ const parent = this.peekScope();
68
+ if (parent) {
69
+ parent.children.push(symbol);
70
+ }
71
+ this.scopes.push(symbol);
72
+ }
73
+ exitExploreQueryDef(_pcx) {
74
+ this.popScope();
75
+ }
76
+ handleNestEntry(pcx) {
77
+ const symbol = {
78
+ range: this.translator.rangeFromContext(pcx),
79
+ name: pcx.queryName().id().text,
80
+ type: "query",
81
+ children: [],
82
+ };
83
+ const parent = this.peekScope();
84
+ if (parent) {
85
+ parent.children.push(symbol);
86
+ }
87
+ return symbol;
88
+ }
89
+ enterNestExisting(pcx) {
90
+ this.handleNestEntry(pcx);
91
+ }
92
+ enterNestDef(pcx) {
93
+ const symbol = this.handleNestEntry(pcx);
94
+ this.scopes.push(symbol);
95
+ }
96
+ exitNestDef(_pcx) {
97
+ this.popScope();
98
+ }
99
+ enterFieldDef(pcx) {
100
+ const symbol = {
101
+ range: this.translator.rangeFromContext(pcx),
102
+ name: pcx.fieldNameDef().id().text,
103
+ type: "field",
104
+ children: [],
105
+ };
106
+ const parent = this.peekScope();
107
+ if (parent) {
108
+ parent.children.push(symbol);
109
+ }
110
+ }
111
+ enterQueryFieldRef(pcx) {
112
+ const symbol = {
113
+ range: this.translator.rangeFromContext(pcx),
114
+ name: pcx.fieldPath().text,
115
+ type: "field",
116
+ children: [],
117
+ };
118
+ const parent = this.peekScope();
119
+ if (parent) {
120
+ parent.children.push(symbol);
121
+ }
122
+ }
123
+ enterExploreRenameDef(pcx) {
124
+ const symbol = {
125
+ range: this.translator.rangeFromContext(pcx),
126
+ name: pcx.fieldName()[0].text,
127
+ type: "field",
128
+ children: [],
129
+ };
130
+ const parent = this.peekScope();
131
+ if (parent) {
132
+ parent.children.push(symbol);
133
+ }
134
+ }
135
+ enterJoinWith(pcx) {
136
+ this.handleJoinDef(pcx);
137
+ }
138
+ enterJoinOn(pcx) {
139
+ this.handleJoinDef(pcx);
140
+ }
141
+ handleJoinDef(pcx) {
142
+ const symbol = {
143
+ range: this.translator.rangeFromContext(pcx),
144
+ name: pcx.joinNameDef().id().text,
145
+ type: "join",
146
+ children: [],
147
+ };
148
+ const parent = this.peekScope();
149
+ if (parent) {
150
+ parent.children.push(symbol);
151
+ }
152
+ }
153
+ enterSqlStatementDef(pcx) {
154
+ var _a;
155
+ const name = (_a = pcx.sqlCommandNameDef()) === null || _a === void 0 ? void 0 : _a.id().text;
156
+ const symbol = {
157
+ range: this.translator.rangeFromContext(pcx),
158
+ name: name || "unnamed_sql",
159
+ type: name === undefined ? "unnamed_sql" : "sql",
160
+ children: [],
161
+ };
162
+ this.symbols.push(symbol);
163
+ }
164
+ }
165
+ function walkForDocumentSymbols(forParse, tokens, parseTree) {
166
+ const finder = new DocumentSymbolWalker(forParse, tokens, [], []);
167
+ const listener = finder;
168
+ ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseTree);
169
+ return finder.symbols;
170
+ }
171
+ exports.walkForDocumentSymbols = walkForDocumentSymbols;
172
+ //# sourceMappingURL=document-symbol-walker.js.map
@@ -0,0 +1,34 @@
1
+ import { CommonTokenStream } from "antlr4ts";
2
+ import { ParseTree } from "antlr4ts/tree";
3
+ import { MalloyListener } from "../lib/Malloy/MalloyListener";
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 MalloyListener {
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 {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License
7
+ * version 2 as published by the Free Software Foundation.
8
+ *
9
+ * This program is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ * GNU General Public License for more details.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.exploreQueryWalkerBuilder = exports.ExploreQueryWalker = void 0;
16
+ const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
17
+ class ExploreQueryWalker {
18
+ constructor(tokens) {
19
+ // just to make this compile, no need for this
20
+ this.inDocument = false;
21
+ this.exploreClauseRefs = [];
22
+ this.tokens = tokens;
23
+ }
24
+ exploreQueryAtOffset(offset) {
25
+ return this.exploreClauseRefs.find((ex) => {
26
+ if (ex.range[0] === undefined || ex.range[1] === undefined)
27
+ return false;
28
+ return ex.range[0] <= offset && ex.range[1] >= offset;
29
+ });
30
+ }
31
+ filterAtOffset(offset) {
32
+ const exploreRef = this.exploreQueryAtOffset(offset);
33
+ if (!exploreRef)
34
+ return;
35
+ return exploreRef.filterRefs.find((filterRef) => {
36
+ if (filterRef.range[0] === undefined || filterRef.range[1] === undefined)
37
+ return false;
38
+ return filterRef.range[0] <= offset && filterRef.range[1] >= offset;
39
+ });
40
+ }
41
+ hasFilterListAtOffset(offset) {
42
+ const exploreRef = this.exploreQueryAtOffset(offset);
43
+ if (!exploreRef)
44
+ return false;
45
+ return !!exploreRef.filterLists.find((filterList) => {
46
+ if (filterList.range[0] === undefined ||
47
+ filterList.range[1] === undefined)
48
+ return false;
49
+ return filterList.range[0] <= offset && filterList.range[1] >= offset;
50
+ });
51
+ }
52
+ enterMalloyDocument() {
53
+ this.inDocument = true;
54
+ }
55
+ }
56
+ exports.ExploreQueryWalker = ExploreQueryWalker;
57
+ function exploreQueryWalkerBuilder(tokens, parseTree) {
58
+ const finder = new ExploreQueryWalker(tokens);
59
+ const listener = finder;
60
+ ParseTreeWalker_1.ParseTreeWalker.DEFAULT.walk(listener, parseTree);
61
+ return finder;
62
+ }
63
+ exports.exploreQueryWalkerBuilder = exploreQueryWalkerBuilder;
64
+ //# sourceMappingURL=explore-query-walker.js.map
@@ -0,0 +1,11 @@
1
+ import { CommonTokenStream } from "antlr4ts";
2
+ import type { ParseTree } from "antlr4ts/tree";
3
+ import { DocumentRange } from "../../model/malloy_types";
4
+ import { MalloyTranslation } from "../parse-malloy";
5
+ declare type References = Record<string, DocumentRange>;
6
+ interface FinderFound {
7
+ tables?: References;
8
+ urls?: References;
9
+ }
10
+ export declare function findReferences(trans: MalloyTranslation, tokens: CommonTokenStream, parseTree: ParseTree): FinderFound | null;
11
+ export {};