@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,4 @@
1
+ "use strict";
2
+ // Generated from Malloy.g4 by ANTLR 4.9.0-SNAPSHOT
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=MalloyVisitor.js.map
@@ -0,0 +1,27 @@
1
+ import { DocumentLocation } from "../model/malloy_types";
2
+ export declare type LogSeverity = "error" | "warn" | "debug";
3
+ /**
4
+ * Default severity is "error"
5
+ */
6
+ export interface LogMessage {
7
+ message: string;
8
+ at?: DocumentLocation;
9
+ severity?: LogSeverity;
10
+ }
11
+ export interface MessageLogger {
12
+ log(logMsg: LogMessage): void;
13
+ reset(): void;
14
+ getLog(): LogMessage[];
15
+ hasErrors(): boolean;
16
+ noErrors(): boolean;
17
+ empty(): boolean;
18
+ }
19
+ export declare class MessageLog implements MessageLogger {
20
+ private rawLog;
21
+ getLog(): LogMessage[];
22
+ log(logMsg: LogMessage): void;
23
+ reset(): void;
24
+ noErrors(): boolean;
25
+ hasErrors(): boolean;
26
+ empty(): boolean;
27
+ }
@@ -0,0 +1,41 @@
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.MessageLog = void 0;
16
+ class MessageLog {
17
+ constructor() {
18
+ this.rawLog = [];
19
+ }
20
+ getLog() {
21
+ return this.rawLog;
22
+ }
23
+ log(logMsg) {
24
+ this.rawLog.push(logMsg);
25
+ }
26
+ reset() {
27
+ this.rawLog.length = 0;
28
+ }
29
+ noErrors() {
30
+ return !this.hasErrors();
31
+ }
32
+ hasErrors() {
33
+ const firstError = this.rawLog.find((l) => l.severity !== "warn");
34
+ return firstError !== undefined;
35
+ }
36
+ empty() {
37
+ return this.rawLog.length === 0;
38
+ }
39
+ }
40
+ exports.MessageLog = MessageLog;
41
+ //# sourceMappingURL=parse-log.js.map
@@ -0,0 +1,245 @@
1
+ import { Token, CommonTokenStream, ParserRuleContext, CodePointCharStream } from "antlr4ts";
2
+ import type { ParseTree } from "antlr4ts/tree";
3
+ import { Query, NamedStructDefs, StructDef, ModelDef, SQLBlock, DocumentReference, DocumentPosition, DocumentLocation, DocumentRange } from "../model/malloy_types";
4
+ import * as ast from "./ast";
5
+ import { LogMessage, MessageLog } from "./parse-log";
6
+ import { Zone, ZoneData } from "./zone";
7
+ import { DocumentSymbol } from "./parse-tree-walkers/document-symbol-walker";
8
+ import { DocumentHighlight } from "./parse-tree-walkers/document-highlight-walker";
9
+ import { DocumentCompletion } from "./parse-tree-walkers/document-completion-walker";
10
+ import { DocumentHelpContext } from "./parse-tree-walkers/document-help-context-walker";
11
+ import { ReferenceList } from "./reference-list";
12
+ /**
13
+ * The translation interface is essentially a request/respone protocol, and
14
+ * this is the list of all the "protocol" messages.
15
+ */
16
+ interface FinalResponse {
17
+ final: true;
18
+ }
19
+ interface ErrorResponse {
20
+ errors: LogMessage[];
21
+ }
22
+ declare type FatalResponse = FinalResponse & ErrorResponse;
23
+ export interface NeedSchemaData {
24
+ tables: string[];
25
+ }
26
+ export interface NeedURLData {
27
+ urls: string[];
28
+ }
29
+ /**
30
+ * An SQL Block contains a unique key inside it, and we use that to
31
+ * reference and define blocks, since Zone really wants keys to be strings.
32
+ *
33
+ * If I had SQLBlocks when Zones were defined, this would not be
34
+ * a one off class, it would be Zone<keyType,valueType>
35
+ */
36
+ export declare class SQLExploreZone extends Zone<StructDef> {
37
+ keyed: Record<string, SQLBlock>;
38
+ referenceBlock(from: ast.SQLStatement, at: DocumentLocation): void;
39
+ getUndefinedBlocks(): SQLBlock[] | undefined;
40
+ }
41
+ export interface NeedSQLStruct {
42
+ sqlStructs: SQLBlock[];
43
+ }
44
+ interface NeededData extends NeedURLData, NeedSchemaData, NeedSQLStruct {
45
+ }
46
+ export declare type DataRequestResponse = Partial<NeededData> | null;
47
+ interface ASTData extends ErrorResponse, NeededData, FinalResponse {
48
+ ast: ast.MalloyElement;
49
+ }
50
+ declare type ASTResponse = Partial<ASTData>;
51
+ interface Metadata extends NeededData, ErrorResponse, FinalResponse {
52
+ symbols: DocumentSymbol[];
53
+ highlights: DocumentHighlight[];
54
+ }
55
+ declare type MetadataResponse = Partial<Metadata>;
56
+ interface Completions extends NeededData, ErrorResponse, FinalResponse {
57
+ completions: DocumentCompletion[];
58
+ }
59
+ declare type CompletionsResponse = Partial<Completions>;
60
+ interface HelpContext extends NeededData, ErrorResponse, FinalResponse {
61
+ helpContext: DocumentHelpContext | undefined;
62
+ }
63
+ declare type HelpContextResponse = Partial<HelpContext>;
64
+ interface TranslatedResponseData extends NeededData, ErrorResponse, FinalResponse {
65
+ translated: {
66
+ modelDef: ModelDef;
67
+ queryList: Query[];
68
+ sqlBlocks: SQLBlock[];
69
+ };
70
+ }
71
+ export declare type TranslateResponse = Partial<TranslatedResponseData>;
72
+ declare type StepResponses = DataRequestResponse | ASTResponse | TranslateResponse | ParseResponse | MetadataResponse;
73
+ /**
74
+ * A Translation is a series of translation steps. Each step can depend
75
+ * on other steps, in which case the preceeding steps will be passed
76
+ * to the constructor. The translator methods will then ask the final
77
+ * step for the answer, and it will call up the chain asking all the
78
+ * steps that it depends on for their answers.
79
+ *
80
+ * Any step can return a result which will be ...
81
+ * "I had errors, go no further"
82
+ * "I hit a spot where I need more data before I can continue"
83
+ * "I am done, here is the result of this step"
84
+ */
85
+ interface TranslationStep {
86
+ step(that: MalloyTranslation): StepResponses;
87
+ }
88
+ export interface MalloyParseRoot {
89
+ root: ParseTree;
90
+ tokenStream: CommonTokenStream;
91
+ sourceStream: CodePointCharStream;
92
+ subTranslator: MalloyTranslation;
93
+ malloyVersion: string;
94
+ }
95
+ interface ParseData extends ErrorResponse, NeedURLData, FinalResponse {
96
+ parse: MalloyParseRoot;
97
+ }
98
+ declare type ParseResponse = Partial<ParseData>;
99
+ /**
100
+ * ParseStep -- Parse the source URL
101
+ */
102
+ interface SourceInfo {
103
+ lines: string[];
104
+ at: {
105
+ begin: number;
106
+ end: number;
107
+ }[];
108
+ length: number;
109
+ }
110
+ declare class ParseStep implements TranslationStep {
111
+ response?: ParseResponse;
112
+ sourceInfo?: SourceInfo;
113
+ step(that: MalloyTranslation): ParseResponse;
114
+ /**
115
+ * Split the source up into lines so we can correctly compute offset
116
+ * to the line/char positions favored by LSP and VSCode.
117
+ */
118
+ private getSourceInfo;
119
+ private runParser;
120
+ }
121
+ declare class ImportsAndTablesStep implements TranslationStep {
122
+ readonly parseStep: ParseStep;
123
+ private alreadyLooked;
124
+ constructor(parseStep: ParseStep);
125
+ step(that: MalloyTranslation): DataRequestResponse | ParseResponse;
126
+ }
127
+ declare class ASTStep implements TranslationStep {
128
+ readonly importStep: ImportsAndTablesStep;
129
+ response?: ASTResponse;
130
+ private walked;
131
+ constructor(importStep: ImportsAndTablesStep);
132
+ step(that: MalloyTranslation): ASTResponse;
133
+ }
134
+ declare class MetadataStep implements TranslationStep {
135
+ readonly parseStep: ParseStep;
136
+ response?: MetadataResponse;
137
+ constructor(parseStep: ParseStep);
138
+ step(that: MalloyTranslation): MetadataResponse;
139
+ }
140
+ declare class CompletionsStep implements TranslationStep {
141
+ readonly parseStep: ParseStep;
142
+ constructor(parseStep: ParseStep);
143
+ step(that: MalloyTranslation, position?: {
144
+ line: number;
145
+ character: number;
146
+ }): CompletionsResponse;
147
+ }
148
+ declare class HelpContextStep implements TranslationStep {
149
+ readonly parseStep: ParseStep;
150
+ constructor(parseStep: ParseStep);
151
+ step(that: MalloyTranslation, position?: {
152
+ line: number;
153
+ character: number;
154
+ }): HelpContextResponse;
155
+ }
156
+ declare class TranslateStep implements TranslationStep {
157
+ readonly astStep: ASTStep;
158
+ response?: TranslateResponse;
159
+ constructor(astStep: ASTStep);
160
+ step(that: MalloyTranslation, extendingModel?: ModelDef): TranslateResponse;
161
+ }
162
+ export declare abstract class MalloyTranslation {
163
+ readonly sourceURL: string;
164
+ grammarRule: string;
165
+ abstract root: MalloyTranslator;
166
+ childTranslators: Map<string, MalloyTranslation>;
167
+ urlIsFullPath?: boolean;
168
+ queryList: Query[];
169
+ sqlBlocks: SQLBlock[];
170
+ modelDef: ModelDef;
171
+ readonly parseStep: ParseStep;
172
+ readonly importsAndTablesStep: ImportsAndTablesStep;
173
+ readonly astStep: ASTStep;
174
+ readonly metadataStep: MetadataStep;
175
+ readonly completionsStep: CompletionsStep;
176
+ readonly helpContextStep: HelpContextStep;
177
+ readonly translateStep: TranslateStep;
178
+ readonly references: ReferenceList;
179
+ constructor(sourceURL: string, grammarRule?: string);
180
+ addChild(url: string): void;
181
+ addReference(reference: DocumentReference): void;
182
+ referenceAt(position: DocumentPosition): DocumentReference | undefined;
183
+ fatalErrors(): FatalResponse;
184
+ /**
185
+ * The error log can grow as progressively deeper questions are asked.
186
+ * When returning "errors so far", make a snapshot.
187
+ */
188
+ errors(): ErrorResponse;
189
+ getLineMap(url: string): string[] | undefined;
190
+ prettyErrors(): string;
191
+ getChildExports(importURL: string): NamedStructDefs;
192
+ private finalAnswer?;
193
+ translate(extendingModel?: ModelDef): TranslateResponse;
194
+ metadata(): MetadataResponse;
195
+ completions(position: {
196
+ line: number;
197
+ character: number;
198
+ }): CompletionsResponse;
199
+ helpContext(position: {
200
+ line: number;
201
+ character: number;
202
+ }): HelpContextResponse;
203
+ defaultLocation(): DocumentLocation;
204
+ rangeFromContext(pcx: ParserRuleContext): DocumentRange;
205
+ rangeFromTokens(startToken: Token, stopToken: Token): DocumentRange;
206
+ rangeFromToken(token: Token): DocumentRange;
207
+ }
208
+ /**
209
+ * The main interface to Malloy tranlsation. It has a call pattern
210
+ * similar to a server. Once a translator is instantiated
211
+ * you can request tralnsations repeatedly. Responses to that request
212
+ * will either be "NeedResponse" or "TranslateResponse" objects. The
213
+ * correct pattern is to call "translation" in a loop, calling
214
+ * "update" in response to each "NeedResponse" until a "TranslateResponse"
215
+ * is returned. If you get a response with "final:true", there is
216
+ * no need to call again, the translation is finished or error'd.
217
+ */
218
+ export declare class MalloyTranslator extends MalloyTranslation {
219
+ schemaZone: Zone<StructDef>;
220
+ importZone: Zone<string>;
221
+ sqlQueryZone: SQLExploreZone;
222
+ logger: MessageLog;
223
+ readonly root: MalloyTranslator;
224
+ constructor(rootURL: string, preload?: ParseUpdate | null);
225
+ update(dd: ParseUpdate): void;
226
+ }
227
+ interface ErrorData {
228
+ tables: Record<string, string>;
229
+ urls: Record<string, string>;
230
+ sqlStructs: Record<string, string>;
231
+ }
232
+ export interface URLData {
233
+ urls: ZoneData<string>;
234
+ }
235
+ export interface SchemaData {
236
+ tables: ZoneData<StructDef>;
237
+ }
238
+ export interface SQLStructData {
239
+ sqlStructs: ZoneData<StructDef>;
240
+ }
241
+ export interface UpdateData extends URLData, SchemaData, SQLStructData {
242
+ errors: Partial<ErrorData>;
243
+ }
244
+ export declare type ParseUpdate = Partial<UpdateData>;
245
+ export {};