@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,38 +0,0 @@
1
- import { StructDef, NamedModelObject, ModelDef, Query, FieldDef, PipeSegment, TurtleDef, DocumentLocation } from "../../model/malloy_types";
2
- import { MalloyElement, ModelEntry, NameSpace } from "../ast";
3
- import { MalloyTranslator, TranslateResponse } from "../parse-malloy";
4
- export declare function pretty(thing: any): string;
5
- export declare const aTableDef: StructDef;
6
- /**
7
- * When translating partial trees, there will not be a document node
8
- * to handle namespace requests, this stands in for document in that case.
9
- */
10
- declare class TestRoot extends MalloyElement implements NameSpace {
11
- private modelDef;
12
- elementType: string;
13
- constructor(child: MalloyElement, forTranslator: MalloyTranslator, modelDef: ModelDef);
14
- namespace(): NameSpace;
15
- getEntry(name: string): ModelEntry | undefined;
16
- setEntry(_name: string, _val: ModelEntry): void;
17
- }
18
- export declare class TestTranslator extends MalloyTranslator {
19
- testRoot?: TestRoot;
20
- internalModel: ModelDef;
21
- constructor(source: string, rootRule?: string);
22
- translate(): TranslateResponse;
23
- ast(): MalloyElement | undefined;
24
- private explainFailure;
25
- get nameSpace(): Record<string, NamedModelObject>;
26
- exploreFor(exploreName: string): StructDef;
27
- }
28
- export declare function getExplore(modelDef: ModelDef, name: string): StructDef;
29
- export declare function getModelQuery(modelDef: ModelDef, name: string): Query;
30
- export declare function getField(thing: StructDef | PipeSegment, name: string): FieldDef;
31
- export declare function getQueryField(structDef: StructDef, name: string): TurtleDef;
32
- export declare function getJoinField(structDef: StructDef, name: string): StructDef;
33
- export interface MarkedSource {
34
- code: string;
35
- locations: DocumentLocation[];
36
- }
37
- export declare function markSource(unmarked: TemplateStringsArray, ...marked: string[]): MarkedSource;
38
- export {};
@@ -1,344 +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.markSource = exports.getJoinField = exports.getQueryField = exports.getField = exports.getModelQuery = exports.getExplore = exports.TestTranslator = exports.aTableDef = exports.pretty = void 0;
26
- const util_1 = require("util");
27
- const malloy_types_1 = require("../../model/malloy_types");
28
- const ast_1 = require("../ast");
29
- const parse_malloy_1 = require("../parse-malloy");
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types
31
- function pretty(thing) {
32
- return (0, util_1.inspect)(thing, { breakLength: 72, depth: Infinity });
33
- }
34
- exports.pretty = pretty;
35
- const mockSchema = {
36
- aTable: {
37
- type: "struct",
38
- name: "aTable",
39
- dialect: "standardsql",
40
- structSource: { type: "table", tablePath: "aTable" },
41
- structRelationship: { type: "basetable", connectionName: "test" },
42
- fields: [
43
- { type: "string", name: "astr" },
44
- { type: "number", name: "af", numberType: "float" },
45
- { type: "number", name: "ai", numberType: "integer" },
46
- { type: "date", name: "ad" },
47
- { type: "boolean", name: "abool" },
48
- { type: "timestamp", name: "ats" },
49
- ],
50
- },
51
- "malloytest.carriers": {
52
- type: "struct",
53
- name: "malloytest.carriers",
54
- dialect: "standardsql",
55
- structSource: {
56
- type: "table",
57
- tablePath: "malloytest.carriers",
58
- },
59
- structRelationship: { type: "basetable", connectionName: "bigquery" },
60
- fields: [
61
- { name: "code", type: "string" },
62
- { name: "name", type: "string" },
63
- { name: "nickname", type: "string" },
64
- ],
65
- as: "carriers",
66
- },
67
- "malloytest.flights": {
68
- type: "struct",
69
- name: "malloytest.flights",
70
- dialect: "standardsql",
71
- structSource: {
72
- type: "table",
73
- tablePath: "malloytest.flights",
74
- },
75
- structRelationship: { type: "basetable", connectionName: "bigquery" },
76
- fields: [
77
- { name: "carrier", type: "string" },
78
- { name: "origin", type: "string" },
79
- { name: "destination", type: "string" },
80
- { name: "flight_num", type: "string" },
81
- { name: "flight_time", type: "number", numberType: "integer" },
82
- { name: "tail_num", type: "string" },
83
- { name: "dep_time", type: "timestamp" },
84
- { name: "arr_time", type: "timestamp" },
85
- { name: "dep_delay", type: "number", numberType: "integer" },
86
- { name: "arr_delay", type: "number", numberType: "integer" },
87
- { name: "taxi_out", type: "number", numberType: "integer" },
88
- { name: "taxi_in", type: "number", numberType: "integer" },
89
- { name: "distance", type: "number", numberType: "integer" },
90
- { name: "cancelled", type: "string" },
91
- { name: "diverted", type: "string" },
92
- { name: "id2", type: "number", numberType: "integer" },
93
- ],
94
- as: "flights",
95
- },
96
- "malloytest.airports": {
97
- type: "struct",
98
- name: "malloytest.airports",
99
- dialect: "standardsql",
100
- structSource: {
101
- type: "table",
102
- tablePath: "malloytest.airports",
103
- },
104
- structRelationship: { type: "basetable", connectionName: "bigquery" },
105
- fields: [
106
- { name: "id", type: "number", numberType: "integer" },
107
- { name: "code", type: "string" },
108
- { name: "site_number", type: "string" },
109
- { name: "fac_type", type: "string" },
110
- { name: "fac_use", type: "string" },
111
- { name: "faa_region", type: "string" },
112
- { name: "faa_dist", type: "string" },
113
- { name: "city", type: "string" },
114
- { name: "county", type: "string" },
115
- { name: "state", type: "string" },
116
- { name: "full_name", type: "string" },
117
- { name: "own_type", type: "string" },
118
- { name: "longitude", type: "number", numberType: "float" },
119
- { name: "latitude", type: "number", numberType: "float" },
120
- { name: "elevation", type: "number", numberType: "integer" },
121
- { name: "aero_cht", type: "string" },
122
- { name: "cbd_dist", type: "number", numberType: "integer" },
123
- { name: "cbd_dir", type: "string" },
124
- { name: "act_date", type: "string" },
125
- { name: "cert", type: "string" },
126
- { name: "fed_agree", type: "string" },
127
- { name: "cust_intl", type: "string" },
128
- { name: "c_ldg_rts", type: "string" },
129
- { name: "joint_use", type: "string" },
130
- { name: "mil_rts", type: "string" },
131
- { name: "cntl_twr", type: "string" },
132
- { name: "major", type: "string" },
133
- ],
134
- as: "airports",
135
- },
136
- };
137
- exports.aTableDef = mockSchema.aTable;
138
- /**
139
- * When translating partial trees, there will not be a document node
140
- * to handle namespace requests, this stands in for document in that case.
141
- */
142
- class TestRoot extends ast_1.MalloyElement {
143
- constructor(child, forTranslator, modelDef) {
144
- super({ child });
145
- this.modelDef = modelDef;
146
- this.elementType = "test root";
147
- this.setTranslator(forTranslator);
148
- }
149
- namespace() {
150
- return this;
151
- }
152
- getEntry(name) {
153
- const struct = this.modelDef.contents[name];
154
- if (struct.type == "struct") {
155
- const exported = this.modelDef.exports.includes(name);
156
- return { entry: struct, exported };
157
- }
158
- }
159
- setEntry(_name, _val) {
160
- throw new Error("Can't add entries to test model def");
161
- }
162
- }
163
- const testURI = "internal://test/langtests/root.malloy";
164
- class TestTranslator extends parse_malloy_1.MalloyTranslator {
165
- constructor(source, rootRule = "malloyDocument") {
166
- super(testURI);
167
- /*
168
- * Tests can assume this model exists:
169
- * explore: a is table('aTable') { primary_key: astr }
170
- * explore: b is a
171
- * explore: ab is a {
172
- * join_one: b with astr
173
- * measure: acount is count()
174
- * query: aturtle is { group_by: astr; aggregate: acount }
175
- * }
176
- */
177
- this.internalModel = {
178
- name: testURI,
179
- exports: [],
180
- contents: {
181
- a: { ...exports.aTableDef, primaryKey: "astr", as: "a" },
182
- b: { ...exports.aTableDef, primaryKey: "astr", as: "b" },
183
- ab: {
184
- ...exports.aTableDef,
185
- as: "ab",
186
- primaryKey: "astr",
187
- fields: [
188
- ...exports.aTableDef.fields,
189
- {
190
- ...exports.aTableDef,
191
- as: "b",
192
- structRelationship: {
193
- type: "one",
194
- onExpression: [
195
- { type: "field", path: "astr" },
196
- "=",
197
- { type: "field", path: "b.astr" },
198
- ],
199
- },
200
- },
201
- {
202
- type: "number",
203
- name: "acount",
204
- numberType: "integer",
205
- expressionType: "aggregate",
206
- e: ["COUNT()"],
207
- code: "count()",
208
- },
209
- {
210
- type: "turtle",
211
- name: "aturtle",
212
- pipeline: [
213
- {
214
- type: "reduce",
215
- fields: ["astr", "acount"],
216
- },
217
- ],
218
- },
219
- ],
220
- },
221
- },
222
- };
223
- this.grammarRule = rootRule;
224
- this.importZone.define(testURI, source);
225
- for (const tableName in mockSchema) {
226
- this.schemaZone.define(tableName, mockSchema[tableName]);
227
- }
228
- }
229
- translate() {
230
- return super.translate(this.internalModel);
231
- }
232
- ast() {
233
- const astAsk = this.astStep.step(this);
234
- if (astAsk.ast) {
235
- if (this.grammarRule !== "malloyDocument") {
236
- this.testRoot = new TestRoot(astAsk.ast, this, this.internalModel);
237
- }
238
- return astAsk.ast;
239
- }
240
- this.explainFailure();
241
- }
242
- explainFailure() {
243
- let mysterious = true;
244
- if (this.logger.empty()) {
245
- const whatImports = this.importZone.getUndefined();
246
- if (whatImports) {
247
- mysterious = false;
248
- this.logger.log({
249
- at: this.defaultLocation(),
250
- message: `Missing imports: ${whatImports.join(",")}`,
251
- });
252
- }
253
- const needThese = this.schemaZone.getUndefined();
254
- if (needThese) {
255
- mysterious = false;
256
- this.logger.log({
257
- at: this.defaultLocation(),
258
- message: `Missing schema: ${needThese.join(",")}`,
259
- });
260
- }
261
- if (mysterious) {
262
- this.logger.log({
263
- at: this.defaultLocation(),
264
- message: "mysterious translation failure",
265
- });
266
- }
267
- }
268
- }
269
- get nameSpace() {
270
- var _a;
271
- const gotModel = this.translate();
272
- return ((_a = gotModel === null || gotModel === void 0 ? void 0 : gotModel.translated) === null || _a === void 0 ? void 0 : _a.modelDef.contents) || {};
273
- }
274
- exploreFor(exploreName) {
275
- const explore = this.nameSpace[exploreName];
276
- if (explore && explore.type === "struct") {
277
- return explore;
278
- }
279
- throw new Error(`Expected model to contain explore '${exploreName}'`);
280
- }
281
- }
282
- exports.TestTranslator = TestTranslator;
283
- function getExplore(modelDef, name) {
284
- return modelDef.contents[name];
285
- }
286
- exports.getExplore = getExplore;
287
- function getModelQuery(modelDef, name) {
288
- return modelDef.contents[name];
289
- }
290
- exports.getModelQuery = getModelQuery;
291
- function getField(thing, name) {
292
- const result = thing.fields.find((field) => typeof field !== "string" && (field.as || field.name) === name);
293
- if (typeof result === "string") {
294
- throw new Error("Expected a def, got a ref.");
295
- }
296
- if (result === undefined) {
297
- throw new Error("Expected a field, not undefined");
298
- }
299
- if ((0, malloy_types_1.isFilteredAliasedName)(result)) {
300
- throw new Error("Ignoring these for now");
301
- }
302
- return result;
303
- }
304
- exports.getField = getField;
305
- // TODO "as" is almost always a code smell ...
306
- function getQueryField(structDef, name) {
307
- return getField(structDef, name);
308
- }
309
- exports.getQueryField = getQueryField;
310
- // TODO "as" is almost always a code smell ...
311
- function getJoinField(structDef, name) {
312
- return getField(structDef, name);
313
- }
314
- exports.getJoinField = getJoinField;
315
- function markSource(unmarked, ...marked) {
316
- let code = "";
317
- const locations = [];
318
- for (let index = 0; index < marked.length; index++) {
319
- const mark = marked[index];
320
- code += unmarked[index];
321
- const lines = code.split("\n");
322
- const start = {
323
- line: lines.length - 1,
324
- character: lines[lines.length - 1].length,
325
- };
326
- const bitLines = mark.split("\n");
327
- const location = {
328
- url: testURI,
329
- range: {
330
- start,
331
- end: {
332
- line: start.line + bitLines.length - 1,
333
- character: bitLines.length === 1 ? start.character + mark.length : mark.length,
334
- },
335
- },
336
- };
337
- locations.push(location);
338
- code += mark;
339
- }
340
- code += unmarked[marked.length];
341
- return { code, locations };
342
- }
343
- exports.markSource = markSource;
344
- //# sourceMappingURL=test-translator.js.map
@@ -1,57 +0,0 @@
1
- import { DocumentLocation } from "../model/malloy_types";
2
- export declare type ZoneData<TValue> = Record<string, TValue>;
3
- declare type EntryStatus = "present" | "reference" | "error";
4
- interface AllEntries {
5
- status: EntryStatus;
6
- firstReference?: DocumentLocation;
7
- }
8
- interface EntryPresent<T> extends AllEntries {
9
- status: "present";
10
- value: T;
11
- }
12
- interface ReferenceEntry {
13
- status: "reference";
14
- firstReference: DocumentLocation;
15
- }
16
- interface EntryErrored extends AllEntries {
17
- status: "error";
18
- message: string;
19
- }
20
- declare type ZoneEntry<T> = EntryPresent<T> | ReferenceEntry | EntryErrored;
21
- /**
22
- * A Zone is a symbol table which may contain references to symbols
23
- * which are not yet defined. This is used by the parser to track
24
- * references to objects which it will have to request values from
25
- * before the translation can be complete. The API is struictured to
26
- * build the repsonse-style interfaces that the translator uses.
27
- */
28
- export declare class Zone<TValue> {
29
- zone: Map<string, ZoneEntry<TValue>>;
30
- location: Record<string, DocumentLocation>;
31
- constructor();
32
- get(str: string): TValue | undefined;
33
- getEntry(str: string): ZoneEntry<TValue>;
34
- /**
35
- * Add a symbol and it's definition to the symbol table.
36
- * @param str
37
- * @param val
38
- */
39
- define(str: string, val: TValue): void;
40
- /**
41
- * Add a symbol to the symbol table.
42
- * @param str The symbol
43
- * @param loc The location of the reference
44
- */
45
- reference(str: string, loc: DocumentLocation): void;
46
- /**
47
- * @returns A list of all symbols which have references but not definitions
48
- */
49
- getUndefined(): string[] | undefined;
50
- /**
51
- * Provide values for symbols
52
- * @param updateData Symbols and their values
53
- * @param errorData Pass on errors encountered during fetch
54
- */
55
- updateFrom(updateData: ZoneData<TValue> | undefined, errorData: Record<string, string> | undefined): void;
56
- }
57
- export {};
package/dist/lang/zone.js DELETED
@@ -1,107 +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.Zone = void 0;
26
- /**
27
- * A Zone is a symbol table which may contain references to symbols
28
- * which are not yet defined. This is used by the parser to track
29
- * references to objects which it will have to request values from
30
- * before the translation can be complete. The API is struictured to
31
- * build the repsonse-style interfaces that the translator uses.
32
- */
33
- class Zone {
34
- constructor() {
35
- this.location = {};
36
- this.zone = new Map();
37
- }
38
- get(str) {
39
- const zst = this.zone.get(str);
40
- if ((zst === null || zst === void 0 ? void 0 : zst.status) === "present") {
41
- return zst.value;
42
- }
43
- }
44
- getEntry(str) {
45
- const zst = this.zone.get(str);
46
- if (zst) {
47
- if (zst.firstReference || !this.location[str]) {
48
- return zst;
49
- }
50
- return { ...zst, firstReference: this.location[str] };
51
- }
52
- return { status: "error", message: "import reference failure" };
53
- }
54
- /**
55
- * Add a symbol and it's definition to the symbol table.
56
- * @param str
57
- * @param val
58
- */
59
- define(str, val) {
60
- this.zone.set(str, { status: "present", value: val });
61
- }
62
- /**
63
- * Add a symbol to the symbol table.
64
- * @param str The symbol
65
- * @param loc The location of the reference
66
- */
67
- reference(str, loc) {
68
- const zst = this.zone.get(str);
69
- if ((zst === null || zst === void 0 ? void 0 : zst.status) == undefined) {
70
- this.zone.set(str, { status: "reference", firstReference: loc });
71
- this.location[str] = loc;
72
- }
73
- }
74
- /**
75
- * @returns A list of all symbols which have references but not definitions
76
- */
77
- getUndefined() {
78
- const allUndefined = [];
79
- for (const [name, val] of this.zone) {
80
- if (val.status === "reference") {
81
- allUndefined.push(name);
82
- }
83
- }
84
- return allUndefined.length > 0 ? allUndefined : undefined;
85
- }
86
- /**
87
- * Provide values for symbols
88
- * @param updateData Symbols and their values
89
- * @param errorData Pass on errors encountered during fetch
90
- */
91
- updateFrom(updateData, errorData) {
92
- if (updateData) {
93
- for (const [updateKey, updateVal] of Object.entries(updateData)) {
94
- if (updateVal !== undefined) {
95
- this.define(updateKey, updateVal);
96
- }
97
- }
98
- }
99
- if (errorData) {
100
- for (const [errorKey, errorMessage] of Object.entries(errorData)) {
101
- this.zone.set(errorKey, { status: "error", message: errorMessage });
102
- }
103
- }
104
- }
105
- }
106
- exports.Zone = Zone;
107
- //# sourceMappingURL=zone.js.map