@malloydata/malloy 0.0.240-dev250311202829 → 0.0.240-dev250311214430
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/dist/api/core.d.ts +1 -0
- package/dist/api/core.js +2 -1
- package/dist/lang/malloy-parse-info.d.ts +2 -10
- package/dist/lang/malloy-to-ast.d.ts +1 -0
- package/dist/lang/malloy-to-ast.js +9 -6
- package/dist/lang/malloy-to-stable-query.d.ts +76 -0
- package/dist/lang/malloy-to-stable-query.js +660 -0
- package/dist/lang/parse-log.d.ts +1 -0
- package/dist/lang/parse-malloy.d.ts +2 -9
- package/dist/lang/parse-malloy.js +7 -112
- package/dist/lang/parse-tree-walkers/model-annotation-walker.js +1 -1
- package/dist/lang/run-malloy-parser.d.ts +3 -0
- package/dist/lang/run-malloy-parser.js +53 -0
- package/dist/lang/syntax-errors/malloy-parser-error-listener.d.ts +4 -3
- package/dist/lang/syntax-errors/malloy-parser-error-listener.js +8 -4
- package/dist/lang/utils.d.ts +27 -1
- package/dist/lang/utils.js +78 -1
- package/package.json +3 -3
- package/dist/api/asynchronous.spec.d.ts +0 -1
- package/dist/api/asynchronous.spec.js +0 -240
- package/dist/api/sessioned.spec.d.ts +0 -1
- package/dist/api/sessioned.spec.js +0 -476
- package/dist/api/stateless.spec.d.ts +0 -1
- package/dist/api/stateless.spec.js +0 -400
- package/dist/lang/test/annotation.spec.d.ts +0 -14
- package/dist/lang/test/annotation.spec.js +0 -809
- package/dist/lang/test/composite-field-usage.spec.d.ts +0 -1
- package/dist/lang/test/composite-field-usage.spec.js +0 -261
- package/dist/lang/test/document-help-context-walker.spec.d.ts +0 -1
- package/dist/lang/test/document-help-context-walker.spec.js +0 -55
- package/dist/lang/test/document-symbol-walker.spec.d.ts +0 -1
- package/dist/lang/test/document-symbol-walker.spec.js +0 -209
- package/dist/lang/test/expressions.spec.d.ts +0 -1
- package/dist/lang/test/expressions.spec.js +0 -1181
- package/dist/lang/test/field-symbols.spec.d.ts +0 -1
- package/dist/lang/test/field-symbols.spec.js +0 -194
- package/dist/lang/test/find-table-path-walker.spec.d.ts +0 -1
- package/dist/lang/test/find-table-path-walker.spec.js +0 -50
- package/dist/lang/test/imports.spec.d.ts +0 -1
- package/dist/lang/test/imports.spec.js +0 -283
- package/dist/lang/test/lenses.spec.d.ts +0 -1
- package/dist/lang/test/lenses.spec.js +0 -384
- package/dist/lang/test/literals.spec.d.ts +0 -1
- package/dist/lang/test/literals.spec.js +0 -267
- package/dist/lang/test/locations.spec.d.ts +0 -1
- package/dist/lang/test/locations.spec.js +0 -679
- package/dist/lang/test/model-annotation-walker.spec.d.ts +0 -1
- package/dist/lang/test/model-annotation-walker.spec.js +0 -46
- package/dist/lang/test/model_serialization.spec.d.ts +0 -5
- package/dist/lang/test/model_serialization.spec.js +0 -116
- package/dist/lang/test/parameters.spec.d.ts +0 -1
- package/dist/lang/test/parameters.spec.js +0 -619
- package/dist/lang/test/parse.spec.d.ts +0 -1
- package/dist/lang/test/parse.spec.js +0 -893
- package/dist/lang/test/pretranslate.spec.d.ts +0 -1
- package/dist/lang/test/pretranslate.spec.js +0 -80
- package/dist/lang/test/query.spec.d.ts +0 -1
- package/dist/lang/test/query.spec.js +0 -1149
- package/dist/lang/test/source.spec.d.ts +0 -1
- package/dist/lang/test/source.spec.js +0 -570
- package/dist/lang/test/sql-block.spec.d.ts +0 -1
- package/dist/lang/test/sql-block.spec.js +0 -145
- package/dist/lang/test/syntax-errors.spec.d.ts +0 -1
- package/dist/lang/test/syntax-errors.spec.js +0 -142
- package/dist/model/utils.spec.d.ts +0 -1
- package/dist/model/utils.spec.js +0 -38
package/dist/api/core.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare function statedCompileModel(state: CompileModelState): Malloy.Com
|
|
|
31
31
|
export declare function statedCompileSource(state: CompileModelState, name: string): Malloy.CompileSourceResponse;
|
|
32
32
|
export declare function _statedCompileModel(state: CompileModelState): CompileResponse;
|
|
33
33
|
export declare const DEFAULT_LOG_RANGE: Malloy.DocumentRange;
|
|
34
|
+
export declare function mapLogs(logs: LogMessage[], defaultURL: string): Malloy.LogMessage[];
|
|
34
35
|
export declare function compileModel(request: Malloy.CompileModelRequest, state?: CompileModelState): Malloy.CompileModelResponse;
|
|
35
36
|
export declare function compileSource(request: Malloy.CompileSourceRequest): Malloy.CompileSourceResponse;
|
|
36
37
|
export declare function hasErrors(log: Malloy.LogMessage[] | undefined): boolean;
|
package/dist/api/core.js
CHANGED
|
@@ -29,7 +29,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
29
29
|
return result;
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
-
exports.statedCompileQuery = exports.newCompileQueryState = exports.hasErrors = exports.compileSource = exports.compileModel = exports.DEFAULT_LOG_RANGE = exports._statedCompileModel = exports.statedCompileSource = exports.statedCompileModel = exports.newCompileSourceState = exports.newCompileModelState = exports.updateCompileModelState = exports.compileQuery = void 0;
|
|
32
|
+
exports.statedCompileQuery = exports.newCompileQueryState = exports.hasErrors = exports.compileSource = exports.compileModel = exports.mapLogs = exports.DEFAULT_LOG_RANGE = exports._statedCompileModel = exports.statedCompileSource = exports.statedCompileModel = exports.newCompileSourceState = exports.newCompileModelState = exports.updateCompileModelState = exports.compileQuery = void 0;
|
|
33
33
|
const Malloy = __importStar(require("@malloydata/malloy-interfaces"));
|
|
34
34
|
const lang_1 = require("../lang");
|
|
35
35
|
const model_1 = require("../model");
|
|
@@ -326,6 +326,7 @@ function mapLogs(logs, defaultURL) {
|
|
|
326
326
|
});
|
|
327
327
|
});
|
|
328
328
|
}
|
|
329
|
+
exports.mapLogs = mapLogs;
|
|
329
330
|
function wrapResponse(response, defaultURL) {
|
|
330
331
|
const logs = response.logs ? mapLogs(response.logs, defaultURL) : undefined;
|
|
331
332
|
if (response.compilerNeeds) {
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { DocumentRange } from '../model/malloy_types';
|
|
4
|
-
export interface MalloyParseInfo {
|
|
5
|
-
root: ParseTree;
|
|
6
|
-
tokenStream: CommonTokenStream;
|
|
7
|
-
sourceStream: CodePointCharStream;
|
|
8
|
-
sourceURL: string;
|
|
1
|
+
import { ParseInfo } from './utils';
|
|
2
|
+
export interface MalloyParseInfo extends ParseInfo {
|
|
9
3
|
importBaseURL: string;
|
|
10
|
-
rangeFromContext: (pcx: ParserRuleContext) => DocumentRange;
|
|
11
|
-
malloyVersion: string;
|
|
12
4
|
}
|
|
@@ -44,6 +44,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
44
44
|
* Log an error message relative to an AST node
|
|
45
45
|
*/
|
|
46
46
|
protected astError<T extends MessageCode>(el: ast.MalloyElement, code: T, data: MessageParameterType<T>, options?: LogMessageOptions): void;
|
|
47
|
+
protected rangeFromContext(cx: ParserRuleContext): DocumentRange;
|
|
47
48
|
protected getLocation(cx: ParserRuleContext): DocumentLocation;
|
|
48
49
|
protected getSourceString(cx: ParserRuleContext): string;
|
|
49
50
|
/**
|
|
@@ -105,10 +105,13 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
105
105
|
astError(el, code, data, options) {
|
|
106
106
|
this.msgLog.log((0, parse_log_1.makeLogMessage)(code, data, { at: el.location, ...options }));
|
|
107
107
|
}
|
|
108
|
+
rangeFromContext(cx) {
|
|
109
|
+
return (0, utils_1.rangeFromContext)(this.parseInfo.sourceInfo, cx);
|
|
110
|
+
}
|
|
108
111
|
getLocation(cx) {
|
|
109
112
|
return {
|
|
110
113
|
url: this.parseInfo.sourceURL,
|
|
111
|
-
range: this.
|
|
114
|
+
range: this.rangeFromContext(cx),
|
|
112
115
|
};
|
|
113
116
|
}
|
|
114
117
|
getSourceString(cx) {
|
|
@@ -180,7 +183,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
180
183
|
astAt(el, cx) {
|
|
181
184
|
el.location = {
|
|
182
185
|
url: this.parseInfo.sourceURL,
|
|
183
|
-
range: this.
|
|
186
|
+
range: this.rangeFromContext(cx),
|
|
184
187
|
};
|
|
185
188
|
return el;
|
|
186
189
|
}
|
|
@@ -957,7 +960,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
957
960
|
const left = this.getFieldExpr(pcx.fieldExpr(0));
|
|
958
961
|
const right = this.getFieldExpr(pcx.fieldExpr(1));
|
|
959
962
|
if (ast.isEquality(op)) {
|
|
960
|
-
const wholeRange = this.
|
|
963
|
+
const wholeRange = this.rangeFromContext(pcx);
|
|
961
964
|
if (right instanceof ast.ExprNULL) {
|
|
962
965
|
if (op === '=') {
|
|
963
966
|
this.warnWithReplacement('sql-is-null', "Use 'is null' to check for NULL instead of '= null'", wholeRange, `${this.getSourceCode(pcx.fieldExpr(0))} is null`);
|
|
@@ -1170,7 +1173,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1170
1173
|
});
|
|
1171
1174
|
const elseCx = pcx._caseElse;
|
|
1172
1175
|
const theElse = elseCx ? this.getFieldExpr(elseCx) : undefined;
|
|
1173
|
-
this.warnWithReplacement('sql-case', 'Use a `pick` statement instead of `case`', this.
|
|
1176
|
+
this.warnWithReplacement('sql-case', 'Use a `pick` statement instead of `case`', this.rangeFromContext(pcx), `${[
|
|
1174
1177
|
...(valueCx ? [`${this.getSourceCode(valueCx)} ?`] : []),
|
|
1175
1178
|
...whenCxs.map(whenCx => `pick ${this.getSourceCode(whenCx._result)} when ${this.getSourceCode(whenCx._condition)}`),
|
|
1176
1179
|
elseCx ? `else ${elseCx.text}` : 'else null',
|
|
@@ -1486,7 +1489,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1486
1489
|
let op = '~';
|
|
1487
1490
|
const left = pcx.fieldExpr(0);
|
|
1488
1491
|
const right = pcx.fieldExpr(1);
|
|
1489
|
-
const wholeRange = this.
|
|
1492
|
+
const wholeRange = this.rangeFromContext(pcx);
|
|
1490
1493
|
if (pcx.NOT()) {
|
|
1491
1494
|
op = '!~';
|
|
1492
1495
|
this.warnWithReplacement('sql-not-like', "Use Malloy operator '!~' instead of 'NOT LIKE'", wholeRange, `${this.getSourceCode(left)} !~ ${this.getSourceCode(right)}`);
|
|
@@ -1505,7 +1508,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1505
1508
|
const isNot = !!pcx.NOT();
|
|
1506
1509
|
const from = pcx.fieldExprList().fieldExpr();
|
|
1507
1510
|
const inStmt = this.astAt(new ast.ExprLegacyIn(expr, isNot, from.map(f => this.getFieldExpr(f))), pcx);
|
|
1508
|
-
this.warnWithReplacement('sql-in', `Use = (a|b|c) instead of${isNot ? ' NOT' : ''} IN (a,b,c)`, this.
|
|
1511
|
+
this.warnWithReplacement('sql-in', `Use = (a|b|c) instead of${isNot ? ' NOT' : ''} IN (a,b,c)`, this.rangeFromContext(pcx), `${this.getSourceCode(pcx.fieldExpr())} ${isNot ? '!=' : '='} (${from
|
|
1509
1512
|
.map(f => this.getSourceCode(f))
|
|
1510
1513
|
.join(' | ')})`);
|
|
1511
1514
|
return inStmt;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ParserRuleContext } from 'antlr4ts';
|
|
2
|
+
import { ParseTree, TerminalNode } from 'antlr4ts/tree';
|
|
3
|
+
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
|
|
4
|
+
import { MalloyParserVisitor } from './lib/Malloy/MalloyParserVisitor';
|
|
5
|
+
import * as Malloy from '@malloydata/malloy-interfaces';
|
|
6
|
+
import * as parse from './lib/Malloy/MalloyParser';
|
|
7
|
+
import { LogMessageOptions, MessageCode, MessageLogger, MessageParameterType } from './parse-log';
|
|
8
|
+
import { DocumentLocation } from '../model/malloy_types';
|
|
9
|
+
import { ParseInfo } from './utils';
|
|
10
|
+
type HasAnnotations = ParserRuleContext & {
|
|
11
|
+
ANNOTATION: () => TerminalNode[];
|
|
12
|
+
};
|
|
13
|
+
type Node = Malloy.Query | Malloy.QueryDefinitionWithArrow | Malloy.QueryDefinitionWithQueryReference | Malloy.QueryDefinitionWithRefinement | null;
|
|
14
|
+
/**
|
|
15
|
+
* ANTLR visitor pattern parse tree traversal. Generates a Malloy
|
|
16
|
+
* AST from an ANTLR parse tree.
|
|
17
|
+
*/
|
|
18
|
+
export declare class MalloyToQuery extends AbstractParseTreeVisitor<Node> implements MalloyParserVisitor<Node> {
|
|
19
|
+
readonly parseInfo: ParseInfo;
|
|
20
|
+
readonly msgLog: MessageLogger;
|
|
21
|
+
constructor(parseInfo: ParseInfo, msgLog: MessageLogger);
|
|
22
|
+
/**
|
|
23
|
+
* Mostly used to flag a case where the grammar and the type system are
|
|
24
|
+
* no longer in sync. A visitor was written based on a grammar which
|
|
25
|
+
* apparently has changed and now an unexpected element type has appeared.
|
|
26
|
+
* This is a non recoverable error, since the parser and the grammar
|
|
27
|
+
* are not compatible.
|
|
28
|
+
* @return an error object to throw.
|
|
29
|
+
*/
|
|
30
|
+
protected internalError(cx: ParserRuleContext, message: string): Error;
|
|
31
|
+
protected getLocation(cx: ParserRuleContext): DocumentLocation;
|
|
32
|
+
/**
|
|
33
|
+
* Log an error message relative to a parse node
|
|
34
|
+
*/
|
|
35
|
+
protected contextError<T extends MessageCode>(cx: ParserRuleContext, code: T, data: MessageParameterType<T>, options?: LogMessageOptions): void;
|
|
36
|
+
protected getNumber(term: ParseTree): number;
|
|
37
|
+
protected defaultResult(): Node;
|
|
38
|
+
/**
|
|
39
|
+
* Get all the possibly missing annotations from this parse rule
|
|
40
|
+
* @param cx Any parse context which has an ANNOTATION* rules
|
|
41
|
+
* @returns Array of texts for the annotations
|
|
42
|
+
*/
|
|
43
|
+
protected getAnnotations(cx: HasAnnotations): Malloy.Annotation[] | undefined;
|
|
44
|
+
protected getIsAnnotations(cx?: parse.IsDefineContext): Malloy.Annotation[] | undefined;
|
|
45
|
+
protected notAllowed(pcx: ParserRuleContext, what: string): void;
|
|
46
|
+
protected illegal(pcx: ParserRuleContext, what: string): void;
|
|
47
|
+
visitMalloyDocument(pcx: parse.MalloyDocumentContext): Malloy.Query | null;
|
|
48
|
+
visitRunStatement(pcx: parse.RunStatementContext): Malloy.Query | null;
|
|
49
|
+
protected getQueryReference(cx: parse.SQIDContext): Malloy.Reference | null;
|
|
50
|
+
protected getQueryDefinition(cx: parse.SqExprContext): Malloy.QueryDefinition | null;
|
|
51
|
+
protected getRefinementSegment(cx: parse.SegExprContext): Malloy.ViewDefinition | null;
|
|
52
|
+
protected getGroupByStatement(gbcx: parse.GroupByStatementContext): Malloy.ViewOperationWithGroupBy[] | null;
|
|
53
|
+
protected getAggregateStatement(agcx: parse.AggregateStatementContext): Malloy.ViewOperationWithAggregate[] | null;
|
|
54
|
+
protected getOrderByStatement(obcx: parse.OrderByStatementContext): Malloy.ViewOperationWithOrderBy[] | null;
|
|
55
|
+
protected getNestStatement(nstcx: parse.NestStatementContext): Malloy.ViewOperationWithNest[] | null;
|
|
56
|
+
protected getViewExpression(cx: parse.VExprContext): Malloy.ViewDefinition | null;
|
|
57
|
+
protected getLimitStatement(cx: parse.LimitStatementContext): Malloy.ViewOperationWithLimit | null;
|
|
58
|
+
protected getSegmentOperation(cx: parse.QueryStatementContext): Malloy.ViewOperation[] | null;
|
|
59
|
+
protected getFieldPath(pcx: parse.FieldPathContext): {
|
|
60
|
+
name: string;
|
|
61
|
+
path?: string[];
|
|
62
|
+
};
|
|
63
|
+
protected getTimeframe(cx: parse.TimeframeContext): Malloy.TimestampTimeframe | null;
|
|
64
|
+
protected getQueryField(cx: parse.QueryFieldEntryContext): {
|
|
65
|
+
name?: string;
|
|
66
|
+
field: Malloy.Field;
|
|
67
|
+
} | null;
|
|
68
|
+
getFieldExpression(cx: parse.FieldExprContext): Malloy.Expression | null;
|
|
69
|
+
getWhere(_whereCx: parse.WhereStatementContext): Malloy.Where[] | null;
|
|
70
|
+
protected combineAnnotations(...a: (Malloy.Annotation[] | undefined)[]): Malloy.Annotation[] | undefined;
|
|
71
|
+
}
|
|
72
|
+
export declare function malloyToQuery(code: string): {
|
|
73
|
+
query?: Malloy.Query;
|
|
74
|
+
logs: Malloy.LogMessage[];
|
|
75
|
+
};
|
|
76
|
+
export {};
|