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