@malloydata/malloy 0.0.70-dev230810160240 → 0.0.70
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/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/lang/ast/types/annotation-elements.d.ts +6 -4
- package/dist/lang/ast/types/annotation-elements.js +7 -11
- package/dist/lang/ast/types/malloy-element.d.ts +4 -4
- package/dist/lang/ast/types/malloy-element.js +7 -5
- package/dist/lang/lib/Malloy/MalloyTagLexer.d.ts +39 -0
- package/dist/lang/lib/Malloy/MalloyTagLexer.js +347 -0
- package/dist/lang/lib/Malloy/MalloyTagListener.d.ts +158 -0
- package/dist/lang/lib/Malloy/MalloyTagListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyTagParser.d.ts +187 -0
- package/dist/lang/lib/Malloy/MalloyTagParser.js +1104 -0
- package/dist/lang/lib/Malloy/MalloyTagVisitor.d.ts +105 -0
- package/dist/lang/lib/Malloy/MalloyTagVisitor.js +4 -0
- package/dist/lang/malloy-to-ast.d.ts +16 -4
- package/dist/lang/malloy-to-ast.js +65 -37
- package/dist/lang/parse-malloy.d.ts +2 -2
- package/dist/lang/parse-malloy.js +2 -1
- package/dist/lang/parse-utils.d.ts +1 -12
- package/dist/lang/parse-utils.js +1 -15
- package/dist/lang/test/annotation.spec.d.ts +13 -0
- package/dist/lang/test/annotation.spec.js +70 -30
- package/dist/malloy.d.ts +13 -1
- package/dist/malloy.js +41 -0
- package/dist/model/malloy_types.d.ts +6 -2
- package/dist/tags.d.ts +63 -3
- package/dist/tags.js +401 -13
- package/package.json +2 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor";
|
|
2
|
+
import { TagEqContext } from "./MalloyTagParser";
|
|
3
|
+
import { TagReplacePropertiesContext } from "./MalloyTagParser";
|
|
4
|
+
import { TagUpdatePropertiesContext } from "./MalloyTagParser";
|
|
5
|
+
import { TagDefContext } from "./MalloyTagParser";
|
|
6
|
+
import { TagLineContext } from "./MalloyTagParser";
|
|
7
|
+
import { TagSpecContext } from "./MalloyTagParser";
|
|
8
|
+
import { StringContext } from "./MalloyTagParser";
|
|
9
|
+
import { PropNameContext } from "./MalloyTagParser";
|
|
10
|
+
import { EqValueContext } from "./MalloyTagParser";
|
|
11
|
+
import { ArrayElementContext } from "./MalloyTagParser";
|
|
12
|
+
import { ReferenceContext } from "./MalloyTagParser";
|
|
13
|
+
import { ArrayValueContext } from "./MalloyTagParser";
|
|
14
|
+
import { PropertiesContext } from "./MalloyTagParser";
|
|
15
|
+
/**
|
|
16
|
+
* This interface defines a complete generic visitor for a parse tree produced
|
|
17
|
+
* by `MalloyTagParser`.
|
|
18
|
+
*
|
|
19
|
+
* @param <Result> The return type of the visit operation. Use `void` for
|
|
20
|
+
* operations with no return type.
|
|
21
|
+
*/
|
|
22
|
+
export interface MalloyTagVisitor<Result> extends ParseTreeVisitor<Result> {
|
|
23
|
+
/**
|
|
24
|
+
* Visit a parse tree produced by the `tagEq`
|
|
25
|
+
* labeled alternative in `MalloyTagParser.tagSpec`.
|
|
26
|
+
* @param ctx the parse tree
|
|
27
|
+
* @return the visitor result
|
|
28
|
+
*/
|
|
29
|
+
visitTagEq?: (ctx: TagEqContext) => Result;
|
|
30
|
+
/**
|
|
31
|
+
* Visit a parse tree produced by the `tagReplaceProperties`
|
|
32
|
+
* labeled alternative in `MalloyTagParser.tagSpec`.
|
|
33
|
+
* @param ctx the parse tree
|
|
34
|
+
* @return the visitor result
|
|
35
|
+
*/
|
|
36
|
+
visitTagReplaceProperties?: (ctx: TagReplacePropertiesContext) => Result;
|
|
37
|
+
/**
|
|
38
|
+
* Visit a parse tree produced by the `tagUpdateProperties`
|
|
39
|
+
* labeled alternative in `MalloyTagParser.tagSpec`.
|
|
40
|
+
* @param ctx the parse tree
|
|
41
|
+
* @return the visitor result
|
|
42
|
+
*/
|
|
43
|
+
visitTagUpdateProperties?: (ctx: TagUpdatePropertiesContext) => Result;
|
|
44
|
+
/**
|
|
45
|
+
* Visit a parse tree produced by the `tagDef`
|
|
46
|
+
* labeled alternative in `MalloyTagParser.tagSpec`.
|
|
47
|
+
* @param ctx the parse tree
|
|
48
|
+
* @return the visitor result
|
|
49
|
+
*/
|
|
50
|
+
visitTagDef?: (ctx: TagDefContext) => Result;
|
|
51
|
+
/**
|
|
52
|
+
* Visit a parse tree produced by `MalloyTagParser.tagLine`.
|
|
53
|
+
* @param ctx the parse tree
|
|
54
|
+
* @return the visitor result
|
|
55
|
+
*/
|
|
56
|
+
visitTagLine?: (ctx: TagLineContext) => Result;
|
|
57
|
+
/**
|
|
58
|
+
* Visit a parse tree produced by `MalloyTagParser.tagSpec`.
|
|
59
|
+
* @param ctx the parse tree
|
|
60
|
+
* @return the visitor result
|
|
61
|
+
*/
|
|
62
|
+
visitTagSpec?: (ctx: TagSpecContext) => Result;
|
|
63
|
+
/**
|
|
64
|
+
* Visit a parse tree produced by `MalloyTagParser.string`.
|
|
65
|
+
* @param ctx the parse tree
|
|
66
|
+
* @return the visitor result
|
|
67
|
+
*/
|
|
68
|
+
visitString?: (ctx: StringContext) => Result;
|
|
69
|
+
/**
|
|
70
|
+
* Visit a parse tree produced by `MalloyTagParser.propName`.
|
|
71
|
+
* @param ctx the parse tree
|
|
72
|
+
* @return the visitor result
|
|
73
|
+
*/
|
|
74
|
+
visitPropName?: (ctx: PropNameContext) => Result;
|
|
75
|
+
/**
|
|
76
|
+
* Visit a parse tree produced by `MalloyTagParser.eqValue`.
|
|
77
|
+
* @param ctx the parse tree
|
|
78
|
+
* @return the visitor result
|
|
79
|
+
*/
|
|
80
|
+
visitEqValue?: (ctx: EqValueContext) => Result;
|
|
81
|
+
/**
|
|
82
|
+
* Visit a parse tree produced by `MalloyTagParser.arrayElement`.
|
|
83
|
+
* @param ctx the parse tree
|
|
84
|
+
* @return the visitor result
|
|
85
|
+
*/
|
|
86
|
+
visitArrayElement?: (ctx: ArrayElementContext) => Result;
|
|
87
|
+
/**
|
|
88
|
+
* Visit a parse tree produced by `MalloyTagParser.reference`.
|
|
89
|
+
* @param ctx the parse tree
|
|
90
|
+
* @return the visitor result
|
|
91
|
+
*/
|
|
92
|
+
visitReference?: (ctx: ReferenceContext) => Result;
|
|
93
|
+
/**
|
|
94
|
+
* Visit a parse tree produced by `MalloyTagParser.arrayValue`.
|
|
95
|
+
* @param ctx the parse tree
|
|
96
|
+
* @return the visitor result
|
|
97
|
+
*/
|
|
98
|
+
visitArrayValue?: (ctx: ArrayValueContext) => Result;
|
|
99
|
+
/**
|
|
100
|
+
* Visit a parse tree produced by `MalloyTagParser.properties`.
|
|
101
|
+
* @param ctx the parse tree
|
|
102
|
+
* @return the visitor result
|
|
103
|
+
*/
|
|
104
|
+
visitProperties?: (ctx: PropertiesContext) => Result;
|
|
105
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParserRuleContext } from 'antlr4ts';
|
|
2
|
-
import { ParseTree } from 'antlr4ts/tree';
|
|
2
|
+
import { ParseTree, TerminalNode } from 'antlr4ts/tree';
|
|
3
3
|
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
|
|
4
4
|
import { MalloyParserVisitor } from './lib/Malloy/MalloyParserVisitor';
|
|
5
5
|
import * as parse from './lib/Malloy/MalloyParser';
|
|
@@ -8,12 +8,16 @@ import { LogSeverity, MessageLogger } from './parse-log';
|
|
|
8
8
|
import { MalloyParseInfo } from './malloy-parse-info';
|
|
9
9
|
import { FieldDeclarationConstructor } from './ast';
|
|
10
10
|
import { HasString, HasID } from './parse-utils';
|
|
11
|
-
import {
|
|
11
|
+
import { Tag } from '../tags';
|
|
12
|
+
import { DocumentLocation, Note } from '../model/malloy_types';
|
|
12
13
|
declare class IgnoredElement extends ast.MalloyElement {
|
|
13
14
|
elementType: string;
|
|
14
15
|
malloySrc: string;
|
|
15
16
|
constructor(src: string);
|
|
16
17
|
}
|
|
18
|
+
declare type HasAnnotations = ParserRuleContext & {
|
|
19
|
+
ANNOTATION: () => TerminalNode[];
|
|
20
|
+
};
|
|
17
21
|
/**
|
|
18
22
|
* ANTLR visitor pattern parse tree traversal. Generates a Malloy
|
|
19
23
|
* AST from an ANTLR parse tree.
|
|
@@ -21,7 +25,7 @@ declare class IgnoredElement extends ast.MalloyElement {
|
|
|
21
25
|
export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElement> implements MalloyParserVisitor<ast.MalloyElement> {
|
|
22
26
|
readonly parseInfo: MalloyParseInfo;
|
|
23
27
|
readonly msgLog: MessageLogger;
|
|
24
|
-
compilerFlags:
|
|
28
|
+
compilerFlags: Tag;
|
|
25
29
|
constructor(parseInfo: MalloyParseInfo, msgLog: MessageLogger);
|
|
26
30
|
/**
|
|
27
31
|
* Mostly used to flag a case where the grammar and the type system are
|
|
@@ -36,6 +40,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
36
40
|
* Log an error message relative to an AST node
|
|
37
41
|
*/
|
|
38
42
|
protected astError(el: ast.MalloyElement, str: string, sev?: LogSeverity): void;
|
|
43
|
+
protected getLocation(cx: ParserRuleContext): DocumentLocation;
|
|
39
44
|
/**
|
|
40
45
|
* Log an error message relative to a parse node
|
|
41
46
|
*/
|
|
@@ -61,6 +66,13 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
61
66
|
* the parse, make sure it highlights properly
|
|
62
67
|
*/
|
|
63
68
|
protected parseTime(pcx: ParserRuleContext, parse: (s: string) => ast.ExpressionDef | undefined): ast.ExpressionDef;
|
|
69
|
+
/**
|
|
70
|
+
* Get all the possibly missing annotations from this parse rule
|
|
71
|
+
* @param cx Any parse context which has an ANNOTATION* rules
|
|
72
|
+
* @returns Array of texts for the annotations
|
|
73
|
+
*/
|
|
74
|
+
protected getNotes(cx: HasAnnotations): Note[];
|
|
75
|
+
protected getIsNotes(cx: parse.IsDefineContext): Note[];
|
|
64
76
|
visitMalloyDocument(pcx: parse.MalloyDocumentContext): ast.Document;
|
|
65
77
|
visitDefineSourceStatement(pcx: parse.DefineSourceStatementContext): ast.DefineSourceList;
|
|
66
78
|
visitSourceDefinition(pcx: parse.SourceDefinitionContext): ast.DefineSource;
|
|
@@ -87,7 +99,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
87
99
|
protected getJoinList(pcx: parse.JoinListContext): ast.MalloyElement[];
|
|
88
100
|
protected getJoinSource(name: ast.ModelEntryReference, ecx: parse.IsExploreContext | undefined): {
|
|
89
101
|
joinFrom: ast.Source;
|
|
90
|
-
notes:
|
|
102
|
+
notes: Note[];
|
|
91
103
|
};
|
|
92
104
|
visitQueryJoinStatement(pcx: parse.QueryJoinStatementContext): ast.MalloyElement;
|
|
93
105
|
visitJoinOn(pcx: parse.JoinOnContext): ast.Join;
|
|
@@ -52,6 +52,7 @@ const ast = __importStar(require("./ast"));
|
|
|
52
52
|
const Interval_1 = require("antlr4ts/misc/Interval");
|
|
53
53
|
const ast_1 = require("./ast");
|
|
54
54
|
const parse_utils_1 = require("./parse-utils");
|
|
55
|
+
const tags_1 = require("../tags");
|
|
55
56
|
class IgnoredElement extends ast.MalloyElement {
|
|
56
57
|
constructor(src) {
|
|
57
58
|
super();
|
|
@@ -68,7 +69,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
68
69
|
super();
|
|
69
70
|
this.parseInfo = parseInfo;
|
|
70
71
|
this.msgLog = msgLog;
|
|
71
|
-
this.compilerFlags =
|
|
72
|
+
this.compilerFlags = new tags_1.Tag();
|
|
72
73
|
}
|
|
73
74
|
/**
|
|
74
75
|
* Mostly used to flag a case where the grammar and the type system are
|
|
@@ -89,16 +90,19 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
89
90
|
astError(el, str, sev = 'error') {
|
|
90
91
|
this.msgLog.log({ message: str, at: el.location, severity: sev });
|
|
91
92
|
}
|
|
93
|
+
getLocation(cx) {
|
|
94
|
+
return {
|
|
95
|
+
url: this.parseInfo.sourceURL,
|
|
96
|
+
range: this.parseInfo.rangeFromContext(cx),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
92
99
|
/**
|
|
93
100
|
* Log an error message relative to a parse node
|
|
94
101
|
*/
|
|
95
102
|
contextError(cx, msg, sev = 'error') {
|
|
96
103
|
this.msgLog.log({
|
|
97
104
|
message: msg,
|
|
98
|
-
at:
|
|
99
|
-
url: this.parseInfo.sourceURL,
|
|
100
|
-
range: this.parseInfo.rangeFromContext(cx),
|
|
101
|
-
},
|
|
105
|
+
at: this.getLocation(cx),
|
|
102
106
|
severity: sev,
|
|
103
107
|
});
|
|
104
108
|
}
|
|
@@ -116,7 +120,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
116
120
|
return acceptable;
|
|
117
121
|
}
|
|
118
122
|
m4WarningsEnabled() {
|
|
119
|
-
return
|
|
123
|
+
return this.compilerFlags.has('m4warnings');
|
|
120
124
|
}
|
|
121
125
|
getNumber(term) {
|
|
122
126
|
return Number.parseInt(term.text);
|
|
@@ -230,6 +234,23 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
230
234
|
}
|
|
231
235
|
return this.astAt(def, pcx);
|
|
232
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Get all the possibly missing annotations from this parse rule
|
|
239
|
+
* @param cx Any parse context which has an ANNOTATION* rules
|
|
240
|
+
* @returns Array of texts for the annotations
|
|
241
|
+
*/
|
|
242
|
+
getNotes(cx) {
|
|
243
|
+
return cx.ANNOTATION().map(a => {
|
|
244
|
+
return {
|
|
245
|
+
text: a.text,
|
|
246
|
+
at: this.getLocation(cx),
|
|
247
|
+
};
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
getIsNotes(cx) {
|
|
251
|
+
const before = this.getNotes(cx._beforeIs);
|
|
252
|
+
return before.concat(this.getNotes(cx._afterIs));
|
|
253
|
+
}
|
|
233
254
|
visitMalloyDocument(pcx) {
|
|
234
255
|
const stmts = this.only(pcx.malloyStatement().map(scx => this.visit(scx)), x => ast.isDocStatementOrDocStatementList(x) && x, 'statement');
|
|
235
256
|
return new ast.Document(stmts);
|
|
@@ -237,14 +258,14 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
237
258
|
visitDefineSourceStatement(pcx) {
|
|
238
259
|
const defsCx = pcx.sourcePropertyList().sourceDefinition();
|
|
239
260
|
const defs = defsCx.map(dcx => this.visitSourceDefinition(dcx));
|
|
240
|
-
const blockNotes =
|
|
261
|
+
const blockNotes = this.getNotes(pcx.tags());
|
|
241
262
|
const defList = new ast.DefineSourceList(defs);
|
|
242
263
|
defList.extendNote({ blockNotes });
|
|
243
264
|
return defList;
|
|
244
265
|
}
|
|
245
266
|
visitSourceDefinition(pcx) {
|
|
246
267
|
const exploreDef = new ast.DefineSource((0, parse_utils_1.getId)(pcx.sourceNameDef()), this.getSource(pcx.explore()), true, []);
|
|
247
|
-
const notes =
|
|
268
|
+
const notes = this.getNotes(pcx.tags()).concat(this.getIsNotes(pcx.isDefine()));
|
|
248
269
|
exploreDef.extendNote({ notes });
|
|
249
270
|
return this.astAt(exploreDef, pcx);
|
|
250
271
|
}
|
|
@@ -413,7 +434,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
413
434
|
}
|
|
414
435
|
}
|
|
415
436
|
const joinMany = new ast.Joins(joins);
|
|
416
|
-
joinMany.extendNote({ blockNotes:
|
|
437
|
+
joinMany.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
417
438
|
return joinMany;
|
|
418
439
|
}
|
|
419
440
|
visitDefJoinOne(pcx) {
|
|
@@ -428,7 +449,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
428
449
|
}
|
|
429
450
|
}
|
|
430
451
|
const joinOne = new ast.Joins(joins);
|
|
431
|
-
joinOne.extendNote({ blockNotes:
|
|
452
|
+
joinOne.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
432
453
|
return joinOne;
|
|
433
454
|
}
|
|
434
455
|
visitDefJoinCross(pcx) {
|
|
@@ -446,7 +467,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
446
467
|
}
|
|
447
468
|
}
|
|
448
469
|
const joinCross = new ast.Joins(joins);
|
|
449
|
-
joinCross.extendNote({ blockNotes:
|
|
470
|
+
joinCross.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
450
471
|
return joinCross;
|
|
451
472
|
}
|
|
452
473
|
getJoinList(pcx) {
|
|
@@ -455,7 +476,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
455
476
|
getJoinSource(name, ecx) {
|
|
456
477
|
if (ecx) {
|
|
457
478
|
const joinSrc = this.getSource(ecx.explore());
|
|
458
|
-
const notes =
|
|
479
|
+
const notes = this.getNotes(ecx._before_is).concat(this.getNotes(ecx._after_is));
|
|
459
480
|
return { joinFrom: joinSrc, notes };
|
|
460
481
|
}
|
|
461
482
|
return { joinFrom: new ast.NamedSource(name), notes: [] };
|
|
@@ -475,7 +496,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
475
496
|
if (onCx) {
|
|
476
497
|
join.joinOn = this.getFieldExpr(onCx);
|
|
477
498
|
}
|
|
478
|
-
join.extendNote({ notes:
|
|
499
|
+
join.extendNote({ notes: this.getNotes(pcx).concat(notes) });
|
|
479
500
|
return this.astAt(join, pcx);
|
|
480
501
|
}
|
|
481
502
|
visitJoinWith(pcx) {
|
|
@@ -483,7 +504,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
483
504
|
const { joinFrom, notes } = this.getJoinSource(joinAs, pcx.isExplore());
|
|
484
505
|
const joinOn = this.getFieldExpr(pcx.fieldExpr());
|
|
485
506
|
const join = new ast.KeyJoin(joinAs, joinFrom, joinOn);
|
|
486
|
-
join.extendNote({ notes:
|
|
507
|
+
join.extendNote({ notes: this.getNotes(pcx).concat(notes) });
|
|
487
508
|
return this.astAt(join, pcx);
|
|
488
509
|
}
|
|
489
510
|
getFieldDef(pcx, makeFieldDef) {
|
|
@@ -491,20 +512,20 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
491
512
|
const fieldName = (0, parse_utils_1.getId)(pcx.fieldNameDef());
|
|
492
513
|
const valExpr = this.getFieldExpr(defCx);
|
|
493
514
|
const def = new makeFieldDef(valExpr, fieldName, this.getSourceCode(defCx));
|
|
494
|
-
const notes =
|
|
515
|
+
const notes = this.getNotes(pcx.tags()).concat(this.getIsNotes(pcx.isDefine()));
|
|
495
516
|
def.extendNote({ notes });
|
|
496
517
|
return this.astAt(def, pcx);
|
|
497
518
|
}
|
|
498
519
|
visitDefDimensions(pcx) {
|
|
499
520
|
const defs = this.getFieldDefs(pcx.defList().fieldDef(), ast.DimensionFieldDeclaration);
|
|
500
521
|
const stmt = new ast.Dimensions(defs);
|
|
501
|
-
stmt.extendNote({ blockNotes:
|
|
522
|
+
stmt.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
502
523
|
return this.astAt(stmt, pcx);
|
|
503
524
|
}
|
|
504
525
|
visitDefMeasures(pcx) {
|
|
505
526
|
const defs = this.getFieldDefs(pcx.defList().fieldDef(), ast.MeasureFieldDeclaration);
|
|
506
527
|
const stmt = new ast.Measures(defs);
|
|
507
|
-
stmt.extendNote({ blockNotes:
|
|
528
|
+
stmt.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
508
529
|
return this.astAt(stmt, pcx);
|
|
509
530
|
}
|
|
510
531
|
visitQueryExtend(pcx) {
|
|
@@ -574,7 +595,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
574
595
|
}
|
|
575
596
|
visitDefExploreQuery(pcx) {
|
|
576
597
|
const queryDefs = this.visitSubQueryDefList(pcx.subQueryDefList());
|
|
577
|
-
const blockNotes =
|
|
598
|
+
const blockNotes = this.getNotes(pcx.tags());
|
|
578
599
|
queryDefs.extendNote({ blockNotes });
|
|
579
600
|
return queryDefs;
|
|
580
601
|
}
|
|
@@ -639,17 +660,17 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
639
660
|
}
|
|
640
661
|
visitAggregateStatement(pcx) {
|
|
641
662
|
const agStmt = new ast.Aggregate(this.getQueryItems(pcx.queryFieldList(), ast.AggregateFieldDeclaration, ast.AggregateFieldReference));
|
|
642
|
-
agStmt.extendNote({ blockNotes:
|
|
663
|
+
agStmt.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
643
664
|
return agStmt;
|
|
644
665
|
}
|
|
645
666
|
visitGroupByStatement(pcx) {
|
|
646
667
|
const groupBy = new ast.GroupBy(this.getQueryItems(pcx.queryFieldList(), ast.GroupByFieldDeclaration, ast.GroupByFieldReference));
|
|
647
|
-
groupBy.extendNote({ blockNotes:
|
|
668
|
+
groupBy.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
648
669
|
return groupBy;
|
|
649
670
|
}
|
|
650
671
|
visitCalculateStatement(pcx) {
|
|
651
672
|
const stmt = new ast.Calculate(this.getQueryItems(pcx.queryFieldList(), ast.CalculateFieldDeclaration, ast.CalculateFieldReference));
|
|
652
|
-
stmt.extendNote({ blockNotes:
|
|
673
|
+
stmt.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
653
674
|
return stmt;
|
|
654
675
|
}
|
|
655
676
|
getTaggedRef(pcx, makeFieldDef, makeFieldRef) {
|
|
@@ -673,11 +694,11 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
673
694
|
}
|
|
674
695
|
}
|
|
675
696
|
const def = new makeFieldDef(expr, ref.outputName);
|
|
676
|
-
def.extendNote({ notes:
|
|
697
|
+
def.extendNote({ notes: this.getNotes(pcx.tags()) });
|
|
677
698
|
return def;
|
|
678
699
|
}
|
|
679
700
|
const ref = this.getFieldPath(pcx.fieldPath(), makeFieldRef);
|
|
680
|
-
ref.extendNote({ notes:
|
|
701
|
+
ref.extendNote({ notes: this.getNotes(pcx.tags()) });
|
|
681
702
|
return ref;
|
|
682
703
|
}
|
|
683
704
|
getFieldCollectionMember(pcx, makeFieldDef, makeFieldRef) {
|
|
@@ -704,7 +725,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
704
725
|
}
|
|
705
726
|
visitProjectStatement(pcx) {
|
|
706
727
|
const stmt = this.visitFieldCollection(pcx.fieldCollection());
|
|
707
|
-
stmt.extendNote({ blockNotes:
|
|
728
|
+
stmt.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
708
729
|
return stmt;
|
|
709
730
|
}
|
|
710
731
|
visitCollectionWildCard(pcx) {
|
|
@@ -807,7 +828,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
807
828
|
const stmts = pcx
|
|
808
829
|
.topLevelQueryDef()
|
|
809
830
|
.map(cx => this.visitTopLevelQueryDef(cx));
|
|
810
|
-
const blockNotes =
|
|
831
|
+
const blockNotes = this.getNotes(pcx.tags());
|
|
811
832
|
const queryDefs = new ast.DefineQueryList(stmts);
|
|
812
833
|
queryDefs.extendNote({ blockNotes });
|
|
813
834
|
return queryDefs;
|
|
@@ -816,7 +837,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
816
837
|
const queryName = (0, parse_utils_1.getId)(pcx.queryName());
|
|
817
838
|
const queryExpr = this.visit(pcx.query());
|
|
818
839
|
if (ast.isQueryElement(queryExpr)) {
|
|
819
|
-
const notes =
|
|
840
|
+
const notes = this.getNotes(pcx.tags()).concat(this.getIsNotes(pcx.isDefine()));
|
|
820
841
|
const queryDef = new ast.DefineQuery(queryName, queryExpr);
|
|
821
842
|
queryDef.extendNote({ notes });
|
|
822
843
|
return this.astAt(queryDef, pcx);
|
|
@@ -828,8 +849,8 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
828
849
|
const query = this.visit(defCx.query());
|
|
829
850
|
if (ast.isQueryElement(query)) {
|
|
830
851
|
const theQuery = this.astAt(new ast.AnonymousQuery(query), defCx);
|
|
831
|
-
const notes =
|
|
832
|
-
const blockNotes =
|
|
852
|
+
const notes = this.getNotes(pcx.topLevelAnonQueryDef().tags());
|
|
853
|
+
const blockNotes = this.getNotes(pcx.tags());
|
|
833
854
|
theQuery.extendNote({ notes, blockNotes });
|
|
834
855
|
if (this.m4WarningsEnabled()) {
|
|
835
856
|
this.astError(theQuery, 'Anonymous `query:` statements are deprecated, use `run:` instead', 'warn');
|
|
@@ -842,15 +863,15 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
842
863
|
const query = this.visit(pcx.topLevelAnonQueryDef().query());
|
|
843
864
|
if (ast.isQueryElement(query)) {
|
|
844
865
|
const el = new ast.RunQuery(query);
|
|
845
|
-
el.extendNote({ blockNotes:
|
|
846
|
-
el.extendNote({ notes:
|
|
866
|
+
el.extendNote({ blockNotes: this.getNotes(pcx._blockTags) });
|
|
867
|
+
el.extendNote({ notes: this.getNotes(pcx._noteTags) });
|
|
847
868
|
return this.astAt(el, pcx);
|
|
848
869
|
}
|
|
849
870
|
throw this.internalError(pcx, `Run query matched, but ${query.elementType} found`);
|
|
850
871
|
}
|
|
851
872
|
visitNestStatement(pcx) {
|
|
852
873
|
const nests = this.visitNestedQueryList(pcx.nestedQueryList());
|
|
853
|
-
nests.extendNote({ blockNotes:
|
|
874
|
+
nests.extendNote({ blockNotes: this.getNotes(pcx.tags()) });
|
|
854
875
|
return nests;
|
|
855
876
|
}
|
|
856
877
|
visitNestedQueryList(pcx) {
|
|
@@ -859,7 +880,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
859
880
|
visitNestExisting(pcx) {
|
|
860
881
|
const name = this.getFieldName(pcx.queryName());
|
|
861
882
|
const rcx = pcx.queryRefinement();
|
|
862
|
-
const notes =
|
|
883
|
+
const notes = this.getNotes(pcx.tags());
|
|
863
884
|
if (rcx) {
|
|
864
885
|
const nestRefine = new ast.NestRefinement(name);
|
|
865
886
|
const queryDesc = this.getQueryRefinements(rcx);
|
|
@@ -876,14 +897,14 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
876
897
|
const nestDef = new ast.NestDefinition(name);
|
|
877
898
|
this.buildPipelineFromName(nestDef, pcx.pipelineFromName());
|
|
878
899
|
nestDef.extendNote({
|
|
879
|
-
notes:
|
|
900
|
+
notes: this.getNotes(pcx.tags()).concat(this.getIsNotes(pcx.isDefine())),
|
|
880
901
|
});
|
|
881
902
|
return this.astAt(nestDef, pcx);
|
|
882
903
|
}
|
|
883
904
|
visitExploreQueryDef(pcx) {
|
|
884
905
|
const name = (0, parse_utils_1.getId)(pcx.exploreQueryNameDef());
|
|
885
906
|
const queryDef = new ast.TurtleDecl(name);
|
|
886
|
-
const notes =
|
|
907
|
+
const notes = this.getNotes(pcx).concat(this.getIsNotes(pcx.isDefine()));
|
|
887
908
|
queryDef.extendNote({ notes });
|
|
888
909
|
this.buildPipelineFromName(queryDef, pcx.pipelineFromName());
|
|
889
910
|
return this.astAt(queryDef, pcx);
|
|
@@ -1219,19 +1240,26 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1219
1240
|
return new ast.SampleProperty({ enable: enabled });
|
|
1220
1241
|
}
|
|
1221
1242
|
visitDocAnnotations(pcx) {
|
|
1222
|
-
const allNotes = pcx.DOC_ANNOTATION().map(note =>
|
|
1243
|
+
const allNotes = pcx.DOC_ANNOTATION().map(note => {
|
|
1244
|
+
return {
|
|
1245
|
+
text: note.text,
|
|
1246
|
+
at: this.getLocation(pcx),
|
|
1247
|
+
};
|
|
1248
|
+
});
|
|
1223
1249
|
const tags = new ast.ModelAnnotation(allNotes);
|
|
1224
|
-
this.compilerFlags = tags.getCompilerFlags(this.compilerFlags);
|
|
1250
|
+
this.compilerFlags = tags.getCompilerFlags(this.compilerFlags, this.msgLog);
|
|
1225
1251
|
return tags;
|
|
1226
1252
|
}
|
|
1227
1253
|
visitIgnoredObjectAnnotations(pcx) {
|
|
1254
|
+
this.contextError(pcx, 'Object annotation not connected to any object');
|
|
1228
1255
|
return new IgnoredElement(pcx.text);
|
|
1229
1256
|
}
|
|
1230
1257
|
visitIgnoredModelAnnotations(pcx) {
|
|
1258
|
+
this.contextError(pcx, 'Model annotations not allowed at this scope');
|
|
1231
1259
|
return new IgnoredElement(pcx.text);
|
|
1232
1260
|
}
|
|
1233
1261
|
visitDefExploreAnnotation(pcx) {
|
|
1234
|
-
const allNotes =
|
|
1262
|
+
const allNotes = this.getNotes(pcx);
|
|
1235
1263
|
return new ast.ObjectAnnotation(allNotes);
|
|
1236
1264
|
}
|
|
1237
1265
|
}
|
|
@@ -4,7 +4,7 @@ import { LogMessage, MessageLog, MessageLogger } from './parse-log';
|
|
|
4
4
|
import { Zone, ZoneData } from './zone';
|
|
5
5
|
import { ReferenceList } from './reference-list';
|
|
6
6
|
import { ASTResponse, CompletionsResponse, DataRequestResponse, ProblemResponse, FatalResponse, FinalResponse, HelpContextResponse, MetadataResponse, ModelDataRequest, NeedURLData, TranslateResponse } from './translate-response';
|
|
7
|
-
import {
|
|
7
|
+
import { Tag } from '../tags';
|
|
8
8
|
import { MalloyParseInfo } from './malloy-parse-info';
|
|
9
9
|
export declare type StepResponses = DataRequestResponse | ASTResponse | TranslateResponse | ParseResponse | MetadataResponse;
|
|
10
10
|
/**
|
|
@@ -164,7 +164,7 @@ export declare class MalloyTranslator extends MalloyTranslation {
|
|
|
164
164
|
importZone: Zone<string>;
|
|
165
165
|
sqlQueryZone: Zone<SQLBlockStructDef>;
|
|
166
166
|
logger: MessageLog;
|
|
167
|
-
compilerFlags:
|
|
167
|
+
compilerFlags: Tag;
|
|
168
168
|
readonly root: MalloyTranslator;
|
|
169
169
|
constructor(rootURL: string, preload?: ParseUpdate | null);
|
|
170
170
|
update(dd: ParseUpdate): void;
|
|
@@ -61,6 +61,7 @@ const document_help_context_walker_1 = require("./parse-tree-walkers/document-he
|
|
|
61
61
|
const reference_list_1 = require("./reference-list");
|
|
62
62
|
const translate_response_1 = require("./translate-response");
|
|
63
63
|
const utils_1 = require("./utils");
|
|
64
|
+
const tags_1 = require("../tags");
|
|
64
65
|
/**
|
|
65
66
|
* This ignores a -> popMode when the mode stack is empty, which is a hack,
|
|
66
67
|
* but it let's us parse }%
|
|
@@ -751,7 +752,7 @@ class MalloyTranslator extends MalloyTranslation {
|
|
|
751
752
|
this.importZone = new zone_1.Zone();
|
|
752
753
|
this.sqlQueryZone = new zone_1.Zone();
|
|
753
754
|
this.logger = new parse_log_1.MessageLog();
|
|
754
|
-
this.compilerFlags =
|
|
755
|
+
this.compilerFlags = new tags_1.Tag();
|
|
755
756
|
this.root = this;
|
|
756
757
|
if (preload) {
|
|
757
758
|
this.update(preload);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ParserRuleContext } from 'antlr4ts';
|
|
2
|
-
import { StringContext, ShortStringContext, SqlStringContext,
|
|
3
|
-
import { TerminalNode } from 'antlr4ts/tree/TerminalNode';
|
|
2
|
+
import { StringContext, ShortStringContext, SqlStringContext, IdContext } from './lib/Malloy/MalloyParser';
|
|
4
3
|
/**
|
|
5
4
|
* Take the text of a matched string, including the matching quote
|
|
6
5
|
* characters, and return the actual contents of the string after
|
|
@@ -26,16 +25,6 @@ export declare function getStringParts(cx: SqlStringContext): Generator<StringPa
|
|
|
26
25
|
* @returns a string with the \ processing completed
|
|
27
26
|
*/
|
|
28
27
|
export declare function parseString(str: string, surround?: string): string;
|
|
29
|
-
declare type HasAnnotations = ParserRuleContext & {
|
|
30
|
-
ANNOTATION: () => TerminalNode[];
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Get all the possibly missing annotations from this parse rule
|
|
34
|
-
* @param cx Any parse context which has an ANNOTATION* rules
|
|
35
|
-
* @returns Array of texts for the annotations
|
|
36
|
-
*/
|
|
37
|
-
export declare function getNotes(cx: HasAnnotations): string[];
|
|
38
|
-
export declare function getIsNotes(cx: IsDefineContext): string[];
|
|
39
28
|
export declare type HasID = ParserRuleContext & {
|
|
40
29
|
id: () => IdContext;
|
|
41
30
|
};
|
package/dist/lang/parse-utils.js
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.unIndent = exports.getOptionalId = exports.getId = exports.
|
|
25
|
+
exports.unIndent = exports.getOptionalId = exports.getId = exports.parseString = exports.getStringParts = exports.getStringIfShort = exports.getShortString = void 0;
|
|
26
26
|
/**
|
|
27
27
|
* Take the text of a matched string, including the matching quote
|
|
28
28
|
* characters, and return the actual contents of the string after
|
|
@@ -145,20 +145,6 @@ function parseString(str, surround = '') {
|
|
|
145
145
|
return out;
|
|
146
146
|
}
|
|
147
147
|
exports.parseString = parseString;
|
|
148
|
-
/**
|
|
149
|
-
* Get all the possibly missing annotations from this parse rule
|
|
150
|
-
* @param cx Any parse context which has an ANNOTATION* rules
|
|
151
|
-
* @returns Array of texts for the annotations
|
|
152
|
-
*/
|
|
153
|
-
function getNotes(cx) {
|
|
154
|
-
return cx.ANNOTATION().map(a => a.text);
|
|
155
|
-
}
|
|
156
|
-
exports.getNotes = getNotes;
|
|
157
|
-
function getIsNotes(cx) {
|
|
158
|
-
const before = getNotes(cx._beforeIs);
|
|
159
|
-
return before.concat(getNotes(cx._afterIs));
|
|
160
|
-
}
|
|
161
|
-
exports.getIsNotes = getIsNotes;
|
|
162
148
|
/**
|
|
163
149
|
* An identifier is either a sequence of id characters or a `quoted`
|
|
164
150
|
* This parses either to simply the resulting text.
|
|
@@ -1 +1,14 @@
|
|
|
1
1
|
import './parse-expects';
|
|
2
|
+
interface TstAnnotation {
|
|
3
|
+
inherits?: TstAnnotation;
|
|
4
|
+
blockNotes?: string[];
|
|
5
|
+
notes?: string[];
|
|
6
|
+
}
|
|
7
|
+
declare global {
|
|
8
|
+
namespace jest {
|
|
9
|
+
interface Matchers<R> {
|
|
10
|
+
matchesAnnotation(tt: TstAnnotation): R;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {};
|