@malloydata/malloy 0.0.360 → 0.0.361
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/annotation.js +6 -3
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +69 -54
- package/dist/lang/lib/Malloy/MalloyLexer.js +1407 -1287
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +280 -229
- package/dist/lang/lib/Malloy/MalloyParser.js +2668 -2354
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +44 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +28 -0
- package/dist/lang/malloy-to-ast.d.ts +3 -7
- package/dist/lang/malloy-to-ast.js +45 -25
- package/dist/lang/malloy-to-stable-query.d.ts +3 -3
- package/dist/lang/malloy-to-stable-query.js +3 -3
- package/dist/lang/parse-log.d.ts +2 -0
- package/dist/lang/parse-malloy.js +1 -1
- package/dist/lang/parse-tree-walkers/model-annotation-walker.js +5 -6
- package/dist/lang/parse-utils.d.ts +4 -1
- package/dist/lang/parse-utils.js +49 -0
- package/dist/lang/syntax-errors/malloy-parser-error-listener.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -88,7 +88,11 @@ import { MalloyStatementContext } from "./MalloyParser";
|
|
|
88
88
|
import { DefineSourceStatementContext } from "./MalloyParser";
|
|
89
89
|
import { DefineQueryContext } from "./MalloyParser";
|
|
90
90
|
import { TopLevelAnonQueryDefContext } from "./MalloyParser";
|
|
91
|
+
import { AnnotationContext } from "./MalloyParser";
|
|
91
92
|
import { TagsContext } from "./MalloyParser";
|
|
93
|
+
import { BlockAnnotationContext } from "./MalloyParser";
|
|
94
|
+
import { DocAnnotationContext } from "./MalloyParser";
|
|
95
|
+
import { DocBlockAnnotationContext } from "./MalloyParser";
|
|
92
96
|
import { IsDefineContext } from "./MalloyParser";
|
|
93
97
|
import { RunStatementContext } from "./MalloyParser";
|
|
94
98
|
import { SqlStringContext } from "./MalloyParser";
|
|
@@ -1308,6 +1312,16 @@ export interface MalloyParserListener extends ParseTreeListener {
|
|
|
1308
1312
|
* @param ctx the parse tree
|
|
1309
1313
|
*/
|
|
1310
1314
|
exitTopLevelAnonQueryDef?: (ctx: TopLevelAnonQueryDefContext) => void;
|
|
1315
|
+
/**
|
|
1316
|
+
* Enter a parse tree produced by `MalloyParser.annotation`.
|
|
1317
|
+
* @param ctx the parse tree
|
|
1318
|
+
*/
|
|
1319
|
+
enterAnnotation?: (ctx: AnnotationContext) => void;
|
|
1320
|
+
/**
|
|
1321
|
+
* Exit a parse tree produced by `MalloyParser.annotation`.
|
|
1322
|
+
* @param ctx the parse tree
|
|
1323
|
+
*/
|
|
1324
|
+
exitAnnotation?: (ctx: AnnotationContext) => void;
|
|
1311
1325
|
/**
|
|
1312
1326
|
* Enter a parse tree produced by `MalloyParser.tags`.
|
|
1313
1327
|
* @param ctx the parse tree
|
|
@@ -1318,6 +1332,36 @@ export interface MalloyParserListener extends ParseTreeListener {
|
|
|
1318
1332
|
* @param ctx the parse tree
|
|
1319
1333
|
*/
|
|
1320
1334
|
exitTags?: (ctx: TagsContext) => void;
|
|
1335
|
+
/**
|
|
1336
|
+
* Enter a parse tree produced by `MalloyParser.blockAnnotation`.
|
|
1337
|
+
* @param ctx the parse tree
|
|
1338
|
+
*/
|
|
1339
|
+
enterBlockAnnotation?: (ctx: BlockAnnotationContext) => void;
|
|
1340
|
+
/**
|
|
1341
|
+
* Exit a parse tree produced by `MalloyParser.blockAnnotation`.
|
|
1342
|
+
* @param ctx the parse tree
|
|
1343
|
+
*/
|
|
1344
|
+
exitBlockAnnotation?: (ctx: BlockAnnotationContext) => void;
|
|
1345
|
+
/**
|
|
1346
|
+
* Enter a parse tree produced by `MalloyParser.docAnnotation`.
|
|
1347
|
+
* @param ctx the parse tree
|
|
1348
|
+
*/
|
|
1349
|
+
enterDocAnnotation?: (ctx: DocAnnotationContext) => void;
|
|
1350
|
+
/**
|
|
1351
|
+
* Exit a parse tree produced by `MalloyParser.docAnnotation`.
|
|
1352
|
+
* @param ctx the parse tree
|
|
1353
|
+
*/
|
|
1354
|
+
exitDocAnnotation?: (ctx: DocAnnotationContext) => void;
|
|
1355
|
+
/**
|
|
1356
|
+
* Enter a parse tree produced by `MalloyParser.docBlockAnnotation`.
|
|
1357
|
+
* @param ctx the parse tree
|
|
1358
|
+
*/
|
|
1359
|
+
enterDocBlockAnnotation?: (ctx: DocBlockAnnotationContext) => void;
|
|
1360
|
+
/**
|
|
1361
|
+
* Exit a parse tree produced by `MalloyParser.docBlockAnnotation`.
|
|
1362
|
+
* @param ctx the parse tree
|
|
1363
|
+
*/
|
|
1364
|
+
exitDocBlockAnnotation?: (ctx: DocBlockAnnotationContext) => void;
|
|
1321
1365
|
/**
|
|
1322
1366
|
* Enter a parse tree produced by `MalloyParser.isDefine`.
|
|
1323
1367
|
* @param ctx the parse tree
|
|
@@ -88,7 +88,11 @@ import { MalloyStatementContext } from "./MalloyParser";
|
|
|
88
88
|
import { DefineSourceStatementContext } from "./MalloyParser";
|
|
89
89
|
import { DefineQueryContext } from "./MalloyParser";
|
|
90
90
|
import { TopLevelAnonQueryDefContext } from "./MalloyParser";
|
|
91
|
+
import { AnnotationContext } from "./MalloyParser";
|
|
91
92
|
import { TagsContext } from "./MalloyParser";
|
|
93
|
+
import { BlockAnnotationContext } from "./MalloyParser";
|
|
94
|
+
import { DocAnnotationContext } from "./MalloyParser";
|
|
95
|
+
import { DocBlockAnnotationContext } from "./MalloyParser";
|
|
92
96
|
import { IsDefineContext } from "./MalloyParser";
|
|
93
97
|
import { RunStatementContext } from "./MalloyParser";
|
|
94
98
|
import { SqlStringContext } from "./MalloyParser";
|
|
@@ -871,12 +875,36 @@ export interface MalloyParserVisitor<Result> extends ParseTreeVisitor<Result> {
|
|
|
871
875
|
* @return the visitor result
|
|
872
876
|
*/
|
|
873
877
|
visitTopLevelAnonQueryDef?: (ctx: TopLevelAnonQueryDefContext) => Result;
|
|
878
|
+
/**
|
|
879
|
+
* Visit a parse tree produced by `MalloyParser.annotation`.
|
|
880
|
+
* @param ctx the parse tree
|
|
881
|
+
* @return the visitor result
|
|
882
|
+
*/
|
|
883
|
+
visitAnnotation?: (ctx: AnnotationContext) => Result;
|
|
874
884
|
/**
|
|
875
885
|
* Visit a parse tree produced by `MalloyParser.tags`.
|
|
876
886
|
* @param ctx the parse tree
|
|
877
887
|
* @return the visitor result
|
|
878
888
|
*/
|
|
879
889
|
visitTags?: (ctx: TagsContext) => Result;
|
|
890
|
+
/**
|
|
891
|
+
* Visit a parse tree produced by `MalloyParser.blockAnnotation`.
|
|
892
|
+
* @param ctx the parse tree
|
|
893
|
+
* @return the visitor result
|
|
894
|
+
*/
|
|
895
|
+
visitBlockAnnotation?: (ctx: BlockAnnotationContext) => Result;
|
|
896
|
+
/**
|
|
897
|
+
* Visit a parse tree produced by `MalloyParser.docAnnotation`.
|
|
898
|
+
* @param ctx the parse tree
|
|
899
|
+
* @return the visitor result
|
|
900
|
+
*/
|
|
901
|
+
visitDocAnnotation?: (ctx: DocAnnotationContext) => Result;
|
|
902
|
+
/**
|
|
903
|
+
* Visit a parse tree produced by `MalloyParser.docBlockAnnotation`.
|
|
904
|
+
* @param ctx the parse tree
|
|
905
|
+
* @return the visitor result
|
|
906
|
+
*/
|
|
907
|
+
visitDocBlockAnnotation?: (ctx: DocBlockAnnotationContext) => Result;
|
|
880
908
|
/**
|
|
881
909
|
* Visit a parse tree produced by `MalloyParser.isDefine`.
|
|
882
910
|
* @param ctx the parse tree
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParserRuleContext } from 'antlr4ts';
|
|
2
|
-
import type { ParseTree
|
|
2
|
+
import type { ParseTree } from 'antlr4ts/tree';
|
|
3
3
|
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
|
|
4
4
|
import type { MalloyParserVisitor } from './lib/Malloy/MalloyParserVisitor';
|
|
5
5
|
import type * as parse from './lib/Malloy/MalloyParser';
|
|
@@ -21,7 +21,7 @@ declare class IgnoredElement extends ast.MalloyElement {
|
|
|
21
21
|
constructor(src: string);
|
|
22
22
|
}
|
|
23
23
|
type HasAnnotations = ParserRuleContext & {
|
|
24
|
-
|
|
24
|
+
annotation: () => parse.AnnotationContext[];
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* ANTLR visitor pattern parse tree traversal. Generates a Malloy
|
|
@@ -79,11 +79,7 @@ export declare class MalloyToAST extends AbstractParseTreeVisitor<ast.MalloyElem
|
|
|
79
79
|
* the parse, make sure it highlights properly
|
|
80
80
|
*/
|
|
81
81
|
protected parseTime(pcx: ParserRuleContext, parse: (s: string) => ast.ExpressionDef | undefined): ast.ExpressionDef;
|
|
82
|
-
|
|
83
|
-
* Get all the possibly missing annotations from this parse rule
|
|
84
|
-
* @param cx Any parse context which has an ANNOTATION* rules
|
|
85
|
-
* @returns Array of texts for the annotations
|
|
86
|
-
*/
|
|
82
|
+
protected getAnnotation(cx: parse.AnnotationContext): Note;
|
|
87
83
|
protected getNotes(cx: HasAnnotations): Note[];
|
|
88
84
|
protected getIsNotes(cx: parse.IsDefineContext): Note[];
|
|
89
85
|
visitMalloyDocument(pcx: parse.MalloyDocumentContext): ast.Document;
|
|
@@ -99,7 +99,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
99
99
|
}
|
|
100
100
|
getCompilerFlags() {
|
|
101
101
|
if (!this.compilerFlagTag) {
|
|
102
|
-
this.compilerFlagTag = (0, malloy_tag_1.
|
|
102
|
+
this.compilerFlagTag = (0, malloy_tag_1.parseAnnotation)(this.compilerFlagSrc).tag;
|
|
103
103
|
}
|
|
104
104
|
return this.compilerFlagTag;
|
|
105
105
|
}
|
|
@@ -256,18 +256,16 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
256
256
|
}
|
|
257
257
|
return this.astAt(def, pcx);
|
|
258
258
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
getNotes(cx) {
|
|
265
|
-
return cx.ANNOTATION().map(a => {
|
|
266
|
-
return {
|
|
267
|
-
text: a.text,
|
|
268
|
-
at: this.getLocation(cx),
|
|
269
|
-
};
|
|
259
|
+
getAnnotation(cx) {
|
|
260
|
+
const text = (0, parse_utils_1.getAnnotationText)(cx, (wcx, msg) => {
|
|
261
|
+
this.contextError(wcx, 'block-annotation-warning', msg, {
|
|
262
|
+
severity: 'warn',
|
|
263
|
+
});
|
|
270
264
|
});
|
|
265
|
+
return { text: text, at: this.getLocation(cx) };
|
|
266
|
+
}
|
|
267
|
+
getNotes(cx) {
|
|
268
|
+
return cx.annotation().map(a => this.getAnnotation(a));
|
|
271
269
|
}
|
|
272
270
|
getIsNotes(cx) {
|
|
273
271
|
const before = this.getNotes(cx._beforeIs);
|
|
@@ -456,14 +454,14 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
456
454
|
if (onCx) {
|
|
457
455
|
join.joinOn = this.getFieldExpr(onCx);
|
|
458
456
|
}
|
|
459
|
-
join.extendNote({ notes: this.getNotes(pcx).concat(notes) });
|
|
457
|
+
join.extendNote({ notes: this.getNotes(pcx.tags()).concat(notes) });
|
|
460
458
|
return this.astAt(join, pcx);
|
|
461
459
|
}
|
|
462
460
|
visitJoinWith(pcx) {
|
|
463
461
|
const { joinAs, joinFrom, notes } = this.getJoinFrom(pcx.joinFrom());
|
|
464
462
|
const joinOn = this.getFieldExpr(pcx.fieldExpr());
|
|
465
463
|
const join = new ast.KeyJoin(joinAs, joinFrom, joinOn);
|
|
466
|
-
join.extendNote({ notes: this.getNotes(pcx).concat(notes) });
|
|
464
|
+
join.extendNote({ notes: this.getNotes(pcx.tags()).concat(notes) });
|
|
467
465
|
return this.astAt(join, pcx);
|
|
468
466
|
}
|
|
469
467
|
getFieldDef(pcx, makeFieldDef) {
|
|
@@ -855,7 +853,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
855
853
|
visitExploreQueryDef(pcx) {
|
|
856
854
|
const name = (0, parse_utils_1.getId)(pcx.exploreQueryNameDef());
|
|
857
855
|
const queryDef = new ast.ViewFieldDeclaration(name, this.getVExpr(pcx.vExpr()));
|
|
858
|
-
const notes = this.getNotes(pcx).concat(this.getIsNotes(pcx.isDefine()));
|
|
856
|
+
const notes = this.getNotes(pcx.tags()).concat(this.getIsNotes(pcx.isDefine()));
|
|
859
857
|
queryDef.extendNote({ notes });
|
|
860
858
|
return this.astAt(queryDef, pcx);
|
|
861
859
|
}
|
|
@@ -1294,7 +1292,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1294
1292
|
if (newLines.length > 0) {
|
|
1295
1293
|
const oldLength = this.compilerFlagSrc.length;
|
|
1296
1294
|
this.compilerFlagSrc.push(...newLines);
|
|
1297
|
-
const { tag, log } = (0, malloy_tag_1.
|
|
1295
|
+
const { tag, log } = (0, malloy_tag_1.parseAnnotation)(this.compilerFlagSrc);
|
|
1298
1296
|
this.compilerFlagTag = tag;
|
|
1299
1297
|
for (const err of log) {
|
|
1300
1298
|
if (err.line >= oldLength) {
|
|
@@ -1309,22 +1307,44 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1309
1307
|
this.timer.contribute([parseCompilerFlagsTimer.stop()]);
|
|
1310
1308
|
}
|
|
1311
1309
|
visitDocAnnotations(pcx) {
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1310
|
+
for (const a of pcx.docAnnotation()) {
|
|
1311
|
+
const block = a.docBlockAnnotation();
|
|
1312
|
+
if (block && !block.BLOCK_ANNOTATION_END()) {
|
|
1313
|
+
this.contextError(pcx, 'unclosed-block-annotation', 'Block annotation is not closed, add correctly indented "|##"');
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
const allNotes = pcx.docAnnotation().map(a => ({
|
|
1317
|
+
text: (0, parse_utils_1.getAnnotationText)(a),
|
|
1318
|
+
at: this.getLocation(pcx),
|
|
1319
|
+
}));
|
|
1318
1320
|
const tags = new ast.ModelAnnotation(allNotes);
|
|
1319
1321
|
this.updateCompilerFlags(tags);
|
|
1320
1322
|
return tags;
|
|
1321
1323
|
}
|
|
1322
1324
|
visitIgnoredObjectAnnotations(pcx) {
|
|
1323
|
-
|
|
1325
|
+
const hasUnclosedBlock = pcx.annotation().some(a => {
|
|
1326
|
+
const block = a.blockAnnotation();
|
|
1327
|
+
return block && !block.BLOCK_ANNOTATION_END();
|
|
1328
|
+
});
|
|
1329
|
+
if (hasUnclosedBlock) {
|
|
1330
|
+
this.contextError(pcx, 'unclosed-block-annotation', 'Block annotation is not closed, add correctly indented "|#"');
|
|
1331
|
+
}
|
|
1332
|
+
else {
|
|
1333
|
+
this.contextError(pcx, 'orphaned-object-annotation', 'Object annotation not connected to any object');
|
|
1334
|
+
}
|
|
1324
1335
|
return new IgnoredElement(pcx.text);
|
|
1325
1336
|
}
|
|
1326
1337
|
visitIgnoredModelAnnotations(pcx) {
|
|
1327
|
-
|
|
1338
|
+
const hasUnclosedBlock = pcx.docAnnotation().some(a => {
|
|
1339
|
+
const block = a.docBlockAnnotation();
|
|
1340
|
+
return block && !block.BLOCK_ANNOTATION_END();
|
|
1341
|
+
});
|
|
1342
|
+
if (hasUnclosedBlock) {
|
|
1343
|
+
this.contextError(pcx, 'unclosed-block-annotation', 'Block annotation is not closed, add correctly indented "|##"');
|
|
1344
|
+
}
|
|
1345
|
+
else {
|
|
1346
|
+
this.contextError(pcx, 'misplaced-model-annotation', 'Model annotations not allowed at this scope');
|
|
1347
|
+
}
|
|
1328
1348
|
return new IgnoredElement(pcx.text);
|
|
1329
1349
|
}
|
|
1330
1350
|
visitDefExploreAnnotation(pcx) {
|
|
@@ -1412,7 +1432,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
|
|
|
1412
1432
|
}
|
|
1413
1433
|
getExcludeList(pcx) {
|
|
1414
1434
|
return pcx.includeExceptListItem().map(fcx => {
|
|
1415
|
-
if (fcx.tags().
|
|
1435
|
+
if (fcx.tags().annotation().length > 0) {
|
|
1416
1436
|
this.contextError(fcx.tags(), 'cannot-tag-include-except', 'Tags on `except:` are ignored', { severity: 'warn' });
|
|
1417
1437
|
}
|
|
1418
1438
|
const fieldNameCx = fcx.fieldPath();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParserRuleContext } from 'antlr4ts';
|
|
2
|
-
import type { ParseTree
|
|
2
|
+
import type { ParseTree } from 'antlr4ts/tree';
|
|
3
3
|
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
|
|
4
4
|
import type { MalloyParserVisitor } from './lib/Malloy/MalloyParserVisitor';
|
|
5
5
|
import type * as Malloy from '@malloydata/malloy-interfaces';
|
|
@@ -9,7 +9,7 @@ import type { DocumentLocation } from '../model/malloy_types';
|
|
|
9
9
|
import type { ParseInfo } from './utils';
|
|
10
10
|
import type { TimeLiteral } from './ast';
|
|
11
11
|
type HasAnnotations = ParserRuleContext & {
|
|
12
|
-
|
|
12
|
+
annotation: () => parse.AnnotationContext[];
|
|
13
13
|
};
|
|
14
14
|
type Node = Malloy.Query | Malloy.QueryDefinitionWithArrow | Malloy.QueryDefinitionWithQueryReference | Malloy.QueryDefinitionWithRefinement | null;
|
|
15
15
|
/**
|
|
@@ -38,7 +38,7 @@ export declare class MalloyToQuery extends AbstractParseTreeVisitor<Node> implem
|
|
|
38
38
|
protected defaultResult(): Node;
|
|
39
39
|
/**
|
|
40
40
|
* Get all the possibly missing annotations from this parse rule
|
|
41
|
-
* @param cx Any parse context which has an
|
|
41
|
+
* @param cx Any parse context which has an annotation* rule
|
|
42
42
|
* @returns Array of texts for the annotations
|
|
43
43
|
*/
|
|
44
44
|
protected getAnnotations(cx: HasAnnotations): Malloy.Annotation[] | undefined;
|
|
@@ -97,12 +97,12 @@ class MalloyToQuery extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor
|
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* Get all the possibly missing annotations from this parse rule
|
|
100
|
-
* @param cx Any parse context which has an
|
|
100
|
+
* @param cx Any parse context which has an annotation* rule
|
|
101
101
|
* @returns Array of texts for the annotations
|
|
102
102
|
*/
|
|
103
103
|
getAnnotations(cx) {
|
|
104
|
-
const annotations = cx.
|
|
105
|
-
return { value: a
|
|
104
|
+
const annotations = cx.annotation().map(a => {
|
|
105
|
+
return { value: (0, parse_utils_1.getAnnotationText)(a) };
|
|
106
106
|
});
|
|
107
107
|
return annotations.length > 0 ? annotations : undefined;
|
|
108
108
|
}
|
package/dist/lang/parse-log.d.ts
CHANGED
|
@@ -315,6 +315,8 @@ type MessageParameterTypes = {
|
|
|
315
315
|
'unexpected-malloy-type': string;
|
|
316
316
|
'failed-to-parse-function-name': string;
|
|
317
317
|
'orphaned-object-annotation': string;
|
|
318
|
+
'unclosed-block-annotation': string;
|
|
319
|
+
'block-annotation-warning': string;
|
|
318
320
|
'misplaced-model-annotation': string;
|
|
319
321
|
'unexpected-non-source-query-expression-node': string;
|
|
320
322
|
'sql-not-like': string;
|
|
@@ -486,7 +486,7 @@ class TranslateStep {
|
|
|
486
486
|
}
|
|
487
487
|
class MalloyTranslation {
|
|
488
488
|
getCompilerFlags() {
|
|
489
|
-
return (0, malloy_tag_1.
|
|
489
|
+
return (0, malloy_tag_1.parseAnnotation)(this.compilerFlagSrc).tag;
|
|
490
490
|
}
|
|
491
491
|
constructor(sourceURL, importBaseURL = null, grammarRule = 'malloyDocument') {
|
|
492
492
|
this.sourceURL = sourceURL;
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.walkForModelAnnotation = walkForModelAnnotation;
|
|
26
26
|
const ParseTreeWalker_1 = require("antlr4ts/tree/ParseTreeWalker");
|
|
27
|
+
const parse_utils_1 = require("../parse-utils");
|
|
27
28
|
class ModelAnnotationWalker {
|
|
28
29
|
constructor(translator, tokens, parseInfo) {
|
|
29
30
|
this.translator = translator;
|
|
@@ -38,12 +39,10 @@ class ModelAnnotationWalker {
|
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
41
|
enterDocAnnotations(pcx) {
|
|
41
|
-
const allNotes = pcx.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
});
|
|
42
|
+
const allNotes = pcx.docAnnotation().map(a => ({
|
|
43
|
+
text: (0, parse_utils_1.getAnnotationText)(a),
|
|
44
|
+
at: this.getLocation(pcx),
|
|
45
|
+
}));
|
|
47
46
|
this.notes.push(...allNotes);
|
|
48
47
|
}
|
|
49
48
|
get annotation() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ParserRuleContext } from 'antlr4ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type { DocAnnotationContext } from './lib/Malloy/MalloyParser';
|
|
3
|
+
import { type StringContext, type ShortStringContext, type SqlStringContext, type IdContext, AnnotationContext } from './lib/Malloy/MalloyParser';
|
|
3
4
|
/**
|
|
4
5
|
* Take the text of a matched string, including the matching quote
|
|
5
6
|
* characters, and return the actual contents of the string after
|
|
@@ -34,4 +35,6 @@ export declare function unIndent(parts: (string | unknown)[]): void;
|
|
|
34
35
|
* @returns string part and an error list.
|
|
35
36
|
*/
|
|
36
37
|
export declare function getPlainString(cx: HasString, strictCheck?: boolean): [string | undefined, ParserRuleContext[]];
|
|
38
|
+
type AnnotationWarn = (cx: ParserRuleContext, msg: string) => void;
|
|
39
|
+
export declare function getAnnotationText(cx: AnnotationContext | DocAnnotationContext, warn?: AnnotationWarn): string;
|
|
37
40
|
export {};
|
package/dist/lang/parse-utils.js
CHANGED
|
@@ -30,6 +30,8 @@ exports.idToStr = idToStr;
|
|
|
30
30
|
exports.getOptionalId = getOptionalId;
|
|
31
31
|
exports.unIndent = unIndent;
|
|
32
32
|
exports.getPlainString = getPlainString;
|
|
33
|
+
exports.getAnnotationText = getAnnotationText;
|
|
34
|
+
const MalloyParser_1 = require("./lib/Malloy/MalloyParser");
|
|
33
35
|
const malloy_tag_1 = require("@malloydata/malloy-tag");
|
|
34
36
|
/**
|
|
35
37
|
* Take the text of a matched string, including the matching quote
|
|
@@ -180,4 +182,51 @@ function getPlainString(cx, strictCheck = false) {
|
|
|
180
182
|
// string: shortString | sqlString; So this will never happen
|
|
181
183
|
return ['', errorList];
|
|
182
184
|
}
|
|
185
|
+
function stripBlockIndent(lines, column, cx, warn) {
|
|
186
|
+
if (column === 0) {
|
|
187
|
+
return lines.join('');
|
|
188
|
+
}
|
|
189
|
+
const prefix = ' '.repeat(column);
|
|
190
|
+
let warnedLeft = false;
|
|
191
|
+
let warnedTab = false;
|
|
192
|
+
return lines
|
|
193
|
+
.map(line => {
|
|
194
|
+
if (warn && !warnedTab && line.slice(0, column).includes('\t')) {
|
|
195
|
+
warn(cx, 'Block annotation indentation contains tabs, use spaces');
|
|
196
|
+
warnedTab = true;
|
|
197
|
+
}
|
|
198
|
+
if (line.startsWith(prefix)) {
|
|
199
|
+
return line.slice(column);
|
|
200
|
+
}
|
|
201
|
+
if (warn && !warnedLeft && !warnedTab && line.match(/\S/)) {
|
|
202
|
+
warn(cx, 'Block annotation content is left of the opening #|');
|
|
203
|
+
warnedLeft = true;
|
|
204
|
+
}
|
|
205
|
+
return line;
|
|
206
|
+
})
|
|
207
|
+
.join('');
|
|
208
|
+
}
|
|
209
|
+
function stripTrailingNewline(s) {
|
|
210
|
+
return s.endsWith('\n') ? s.slice(0, -1) : s;
|
|
211
|
+
}
|
|
212
|
+
function getAnnotationText(cx, warn) {
|
|
213
|
+
if (cx instanceof MalloyParser_1.AnnotationContext) {
|
|
214
|
+
const annot = cx.ANNOTATION();
|
|
215
|
+
if (annot)
|
|
216
|
+
return annot.text;
|
|
217
|
+
const block = cx.blockAnnotation();
|
|
218
|
+
const beginToken = block.BLOCK_ANNOTATION_BEGIN();
|
|
219
|
+
const textLines = block.BLOCK_ANNOTATION_TEXT().map(t => t.text);
|
|
220
|
+
return stripTrailingNewline(beginToken.text +
|
|
221
|
+
stripBlockIndent(textLines, beginToken.symbol.charPositionInLine, cx, warn));
|
|
222
|
+
}
|
|
223
|
+
const doc = cx.DOC_ANNOTATION();
|
|
224
|
+
if (doc)
|
|
225
|
+
return doc.text;
|
|
226
|
+
const block = cx.docBlockAnnotation();
|
|
227
|
+
const beginToken = block.DOC_BLOCK_ANNOTATION_BEGIN();
|
|
228
|
+
const textLines = block.BLOCK_ANNOTATION_TEXT().map(t => t.text);
|
|
229
|
+
return stripTrailingNewline(beginToken.text +
|
|
230
|
+
stripBlockIndent(textLines, beginToken.symbol.charPositionInLine, cx, warn));
|
|
231
|
+
}
|
|
183
232
|
//# sourceMappingURL=parse-utils.js.map
|
|
@@ -22,7 +22,7 @@ const utils_1 = require("../utils");
|
|
|
22
22
|
exports.malloyCustomErrorCases = [
|
|
23
23
|
{
|
|
24
24
|
errorMessage: "'view:' must be followed by '<identifier> is {'",
|
|
25
|
-
ruleContextOptions: ['exploreQueryDef'],
|
|
25
|
+
ruleContextOptions: ['exploreQueryDef', 'exploreQueryNameDef', 'id'],
|
|
26
26
|
offendingSymbol: MalloyParser_1.MalloyParser.OCURLY,
|
|
27
27
|
precedingTokenOptions: [[MalloyParser_1.MalloyParser.VIEW], [MalloyParser_1.MalloyParser.COLON]],
|
|
28
28
|
},
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const MALLOY_VERSION = "0.0.
|
|
1
|
+
export declare const MALLOY_VERSION = "0.0.361";
|
package/dist/version.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MALLOY_VERSION = void 0;
|
|
4
4
|
// generated with 'generate-version-file' script; do not edit manually
|
|
5
|
-
exports.MALLOY_VERSION = '0.0.
|
|
5
|
+
exports.MALLOY_VERSION = '0.0.361';
|
|
6
6
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/malloy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.361",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -47,9 +47,9 @@
|
|
|
47
47
|
"generate-version-file": "VERSION=$(npm pkg get version --workspaces=false | tr -d \\\")\necho \"// generated with 'generate-version-file' script; do not edit manually\\nexport const MALLOY_VERSION = '$VERSION';\" > src/version.ts"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@malloydata/malloy-filter": "0.0.
|
|
51
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
52
|
-
"@malloydata/malloy-tag": "0.0.
|
|
50
|
+
"@malloydata/malloy-filter": "0.0.361",
|
|
51
|
+
"@malloydata/malloy-interfaces": "0.0.361",
|
|
52
|
+
"@malloydata/malloy-tag": "0.0.361",
|
|
53
53
|
"@noble/hashes": "^1.8.0",
|
|
54
54
|
"antlr4ts": "^0.5.0-alpha.4",
|
|
55
55
|
"assert": "^2.0.0",
|