@malloydata/malloy 0.0.385 → 0.0.387
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/internal.d.ts +2 -0
- package/dist/internal.js +3 -1
- package/dist/lang/prettify/binary-chain.d.ts +3 -0
- package/dist/lang/prettify/binary-chain.js +65 -0
- package/dist/lang/prettify/block-body.d.ts +4 -0
- package/dist/lang/prettify/block-body.js +87 -0
- package/dist/lang/prettify/error-listener.d.ts +6 -0
- package/dist/lang/prettify/error-listener.js +19 -0
- package/dist/lang/prettify/field-properties.d.ts +3 -0
- package/dist/lang/prettify/field-properties.js +57 -0
- package/dist/lang/prettify/formatter.d.ts +17 -0
- package/dist/lang/prettify/formatter.js +150 -0
- package/dist/lang/prettify/import-select.d.ts +3 -0
- package/dist/lang/prettify/import-select.js +88 -0
- package/dist/lang/prettify/index.d.ts +19 -0
- package/dist/lang/prettify/index.js +163 -0
- package/dist/lang/prettify/inline-renderer.d.ts +3 -0
- package/dist/lang/prettify/inline-renderer.js +101 -0
- package/dist/lang/prettify/leaf.d.ts +9 -0
- package/dist/lang/prettify/leaf.js +340 -0
- package/dist/lang/prettify/out.d.ts +12 -0
- package/dist/lang/prettify/out.js +74 -0
- package/dist/lang/prettify/pick-case.d.ts +5 -0
- package/dist/lang/prettify/pick-case.js +222 -0
- package/dist/lang/prettify/rules.d.ts +13 -0
- package/dist/lang/prettify/rules.js +111 -0
- package/dist/lang/prettify/sections.d.ts +4 -0
- package/dist/lang/prettify/sections.js +380 -0
- package/dist/lang/prettify/tokens.d.ts +13 -0
- package/dist/lang/prettify/tokens.js +185 -0
- package/dist/lang/prettify/types.d.ts +9 -0
- package/dist/lang/prettify/types.js +7 -0
- package/dist/lang/run-malloy-parser.d.ts +23 -0
- package/dist/lang/run-malloy-parser.js +32 -8
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Contributors to the Malloy project
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Out = void 0;
|
|
8
|
+
const tokens_1 = require("./tokens");
|
|
9
|
+
// Append-only buffer with helpers for indentation, single-space coalescing,
|
|
10
|
+
// and newlines. Knows nothing about Malloy; the formatting rules call into it.
|
|
11
|
+
class Out {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.buf = '';
|
|
14
|
+
this.indent = 0;
|
|
15
|
+
}
|
|
16
|
+
// Append text. If the buffer ended with a newline, prepend the current
|
|
17
|
+
// indent first so the new text starts at the right column.
|
|
18
|
+
text(s) {
|
|
19
|
+
if (this.buf.endsWith('\n'))
|
|
20
|
+
this.buf += tokens_1.INDENT_STR.repeat(this.indent);
|
|
21
|
+
this.buf += s;
|
|
22
|
+
}
|
|
23
|
+
// Append at most one space. No-op at start of buffer, after newline, or
|
|
24
|
+
// after `(`, `[`, `.` (so `f(x` stays glued).
|
|
25
|
+
space() {
|
|
26
|
+
if (this.buf.length === 0)
|
|
27
|
+
return;
|
|
28
|
+
const last = this.buf[this.buf.length - 1];
|
|
29
|
+
if (last === ' ' ||
|
|
30
|
+
last === '\n' ||
|
|
31
|
+
last === '(' ||
|
|
32
|
+
last === '[' ||
|
|
33
|
+
last === '.')
|
|
34
|
+
return;
|
|
35
|
+
this.buf += ' ';
|
|
36
|
+
}
|
|
37
|
+
// Force the next emit onto a new line. Trailing spaces are stripped.
|
|
38
|
+
nl() {
|
|
39
|
+
if (this.buf.length === 0)
|
|
40
|
+
return;
|
|
41
|
+
this.buf = this.buf.replace(/ +$/, '');
|
|
42
|
+
if (!this.buf.endsWith('\n'))
|
|
43
|
+
this.buf += '\n';
|
|
44
|
+
}
|
|
45
|
+
// Force a blank line before the next emit. No-op at start of buffer.
|
|
46
|
+
blank() {
|
|
47
|
+
if (this.buf.length === 0)
|
|
48
|
+
return;
|
|
49
|
+
this.nl();
|
|
50
|
+
if (!this.buf.endsWith('\n\n'))
|
|
51
|
+
this.buf += '\n';
|
|
52
|
+
}
|
|
53
|
+
trimTrailingSpace() {
|
|
54
|
+
this.buf = this.buf.replace(/ +$/, '');
|
|
55
|
+
}
|
|
56
|
+
trimTrailingNewlines() {
|
|
57
|
+
this.buf = this.buf.replace(/\n+$/, '');
|
|
58
|
+
}
|
|
59
|
+
// The column the next emit will land at. When the buffer ends with a
|
|
60
|
+
// newline the indent isn't yet in `buf`, so we have to add the pending
|
|
61
|
+
// indent width to predict where the next text will appear.
|
|
62
|
+
lineLengthSoFar() {
|
|
63
|
+
if (this.buf.length === 0 || this.buf.endsWith('\n')) {
|
|
64
|
+
return this.indent * tokens_1.INDENT_STR.length;
|
|
65
|
+
}
|
|
66
|
+
const lastNl = this.buf.lastIndexOf('\n');
|
|
67
|
+
return this.buf.length - (lastNl + 1);
|
|
68
|
+
}
|
|
69
|
+
toString() {
|
|
70
|
+
return this.buf.replace(/\n*$/, '\n');
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.Out = Out;
|
|
74
|
+
//# sourceMappingURL=out.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as parser from '../lib/Malloy/MalloyParser';
|
|
2
|
+
import type { Formatter } from './formatter';
|
|
3
|
+
export declare function formatPickStatement(f: Formatter, ctx: parser.PickStatementContext): void;
|
|
4
|
+
export declare function formatPick(f: Formatter, ctx: parser.PickContext): void;
|
|
5
|
+
export declare function formatCaseStatement(f: Formatter, ctx: parser.CaseStatementContext): void;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Contributors to the Malloy project
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*
|
|
6
|
+
* RULE: PICK — formatPickStatement / formatPickAligned / formatPick
|
|
7
|
+
*
|
|
8
|
+
* pickStatement: pick+ (ELSE pickElse=fieldExpr)?
|
|
9
|
+
*
|
|
10
|
+
* Inline if the whole thing fits. Otherwise:
|
|
11
|
+
* - each pick on its own line at +1 indent
|
|
12
|
+
* - column-align WHEN across picks (pad shorter values)
|
|
13
|
+
* - else aligns with `pick` (no value padding for else)
|
|
14
|
+
* - if a single pick still doesn't fit when aligned, break that pick at WHEN
|
|
15
|
+
* onto two lines.
|
|
16
|
+
*
|
|
17
|
+
* RULE: CASE — formatCaseStatement / formatCaseWhen
|
|
18
|
+
*
|
|
19
|
+
* caseStatement: CASE valueExpr? (caseWhen)+ (ELSE caseElse)? END
|
|
20
|
+
*
|
|
21
|
+
* Inline if it fits. Otherwise:
|
|
22
|
+
* case [valueExpr]
|
|
23
|
+
* when COND_A then RESULT_A
|
|
24
|
+
* when LONGCOND then RESULT_B
|
|
25
|
+
* else FALLBACK
|
|
26
|
+
* end
|
|
27
|
+
* THEN keyword column-aligns across whens (pad shorter conditions). ELSE/END
|
|
28
|
+
* live at the case's own indent. If an aligned when still overflows, break it
|
|
29
|
+
* at THEN onto two lines.
|
|
30
|
+
*/
|
|
31
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
32
|
+
if (k2 === undefined) k2 = k;
|
|
33
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
34
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
35
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(o, k2, desc);
|
|
38
|
+
}) : (function(o, m, k, k2) {
|
|
39
|
+
if (k2 === undefined) k2 = k;
|
|
40
|
+
o[k2] = m[k];
|
|
41
|
+
}));
|
|
42
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
43
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
44
|
+
}) : function(o, v) {
|
|
45
|
+
o["default"] = v;
|
|
46
|
+
});
|
|
47
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
48
|
+
var ownKeys = function(o) {
|
|
49
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
50
|
+
var ar = [];
|
|
51
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
return ownKeys(o);
|
|
55
|
+
};
|
|
56
|
+
return function (mod) {
|
|
57
|
+
if (mod && mod.__esModule) return mod;
|
|
58
|
+
var result = {};
|
|
59
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
60
|
+
__setModuleDefault(result, mod);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.formatPickStatement = formatPickStatement;
|
|
66
|
+
exports.formatPick = formatPick;
|
|
67
|
+
exports.formatCaseStatement = formatCaseStatement;
|
|
68
|
+
const tree_1 = require("antlr4ts/tree");
|
|
69
|
+
const parser = __importStar(require("../lib/Malloy/MalloyParser"));
|
|
70
|
+
const tokens_1 = require("./tokens");
|
|
71
|
+
const leaf_1 = require("./leaf");
|
|
72
|
+
const inline_renderer_1 = require("./inline-renderer");
|
|
73
|
+
function formatPickStatement(f, ctx) {
|
|
74
|
+
const startIdx = ctx._start.tokenIndex;
|
|
75
|
+
const stopIdx = ctx._stop.tokenIndex;
|
|
76
|
+
const inlineLen = (0, leaf_1.approxInlineSpan)(f, startIdx, stopIdx);
|
|
77
|
+
const hasComments = (0, leaf_1.hasCommentsInRange)(f, startIdx, stopIdx);
|
|
78
|
+
if (!hasComments && f.o.lineLengthSoFar() + 1 + inlineLen <= tokens_1.LINE_BUDGET) {
|
|
79
|
+
for (let i = 0; i < ctx.childCount; i++)
|
|
80
|
+
f.format(ctx.getChild(i));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const picks = ctx.pick();
|
|
84
|
+
const elseTok = ctx.ELSE();
|
|
85
|
+
const elseExpr = ctx.fieldExpr();
|
|
86
|
+
const valueStrs = picks.map(p => p._pickValue ? (0, inline_renderer_1.renderItemInline)(f, p._pickValue) : '');
|
|
87
|
+
const maxValueLen = valueStrs.reduce((m, s) => Math.max(m, s.length), 0);
|
|
88
|
+
// Use flushHiddenBefore (the leaf walker's emitter) to flush gap comments
|
|
89
|
+
// between picks. Critical: it advances f.lastEmittedIdx, so when the next
|
|
90
|
+
// pick takes the broken-at-WHEN form (which goes through f.format → emit-
|
|
91
|
+
// VisibleToken → flushHiddenBefore), the gap won't be re-emitted.
|
|
92
|
+
f.o.indent++;
|
|
93
|
+
for (let i = 0; i < picks.length; i++) {
|
|
94
|
+
(0, leaf_1.flushHiddenBefore)(f, picks[i]._start.tokenIndex);
|
|
95
|
+
f.o.nl();
|
|
96
|
+
formatPickAligned(f, picks[i], maxValueLen);
|
|
97
|
+
}
|
|
98
|
+
if (elseTok && elseExpr) {
|
|
99
|
+
(0, leaf_1.flushHiddenBefore)(f, elseTok.symbol.tokenIndex);
|
|
100
|
+
f.o.nl();
|
|
101
|
+
f.format(elseTok);
|
|
102
|
+
f.format(elseExpr);
|
|
103
|
+
}
|
|
104
|
+
f.o.indent--;
|
|
105
|
+
}
|
|
106
|
+
function formatPickAligned(f, pick, maxValueLen) {
|
|
107
|
+
const valueStr = pick._pickValue ? (0, inline_renderer_1.renderItemInline)(f, pick._pickValue) : '';
|
|
108
|
+
const condStr = (0, inline_renderer_1.renderItemInline)(f, pick._pickWhen);
|
|
109
|
+
const padding = ' '.repeat(maxValueLen - valueStr.length);
|
|
110
|
+
const aligned = valueStr
|
|
111
|
+
? `pick ${valueStr}${padding} when ${condStr}`
|
|
112
|
+
: `pick${padding ? ' ' + padding : ''} when ${condStr}`;
|
|
113
|
+
// Aligned form drops comments (renderItemInline skips them). If this pick
|
|
114
|
+
// has internal comments, fall through to the broken-at-WHEN form which uses
|
|
115
|
+
// f.format() and preserves them.
|
|
116
|
+
const hasComments = (0, leaf_1.hasCommentsInRange)(f, pick._start.tokenIndex, pick._stop.tokenIndex);
|
|
117
|
+
if (!hasComments && f.o.lineLengthSoFar() + aligned.length <= tokens_1.LINE_BUDGET) {
|
|
118
|
+
// Aligned form: emit as a single pre-rendered string so the spacing
|
|
119
|
+
// between value and `when` is exact regardless of padding width.
|
|
120
|
+
f.o.text(aligned);
|
|
121
|
+
(0, leaf_1.note)(f, pick._stop.type, pick._stop.tokenIndex, pick._stop);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// Doesn't fit even aligned — break at WHEN, no padding.
|
|
125
|
+
f.format(pick.PICK());
|
|
126
|
+
if (pick._pickValue)
|
|
127
|
+
f.format(pick._pickValue);
|
|
128
|
+
// Flush hidden tokens between value and WHEN BEFORE the line break, so
|
|
129
|
+
// same-line comments stay attached to the value's line and the formatted
|
|
130
|
+
// output is idempotent on a re-parse.
|
|
131
|
+
(0, leaf_1.flushHiddenBefore)(f, pick.WHEN().symbol.tokenIndex);
|
|
132
|
+
f.o.nl();
|
|
133
|
+
f.format(pick.WHEN());
|
|
134
|
+
f.format(pick._pickWhen);
|
|
135
|
+
}
|
|
136
|
+
// pick: PICK pickValue? WHEN pickWhen
|
|
137
|
+
// Inline if fits; otherwise break at WHEN. (Used when this pick is dispatched
|
|
138
|
+
// outside of a pickStatement context, which is rare but possible.)
|
|
139
|
+
function formatPick(f, ctx) {
|
|
140
|
+
const inlineLen = (0, leaf_1.approxInlineSpan)(f, ctx._start.tokenIndex, ctx._stop.tokenIndex);
|
|
141
|
+
if (f.o.lineLengthSoFar() + 1 + inlineLen <= tokens_1.LINE_BUDGET) {
|
|
142
|
+
for (let i = 0; i < ctx.childCount; i++)
|
|
143
|
+
f.format(ctx.getChild(i));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
for (let i = 0; i < ctx.childCount; i++) {
|
|
147
|
+
const c = ctx.getChild(i);
|
|
148
|
+
if (c instanceof tree_1.TerminalNode && c.symbol.type === tokens_1.L.WHEN) {
|
|
149
|
+
// Flush any hidden tokens between the previous child and WHEN before
|
|
150
|
+
// the line break, so same-line comments stay attached.
|
|
151
|
+
(0, leaf_1.flushHiddenBefore)(f, c.symbol.tokenIndex);
|
|
152
|
+
f.o.nl();
|
|
153
|
+
}
|
|
154
|
+
f.format(c);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function formatCaseStatement(f, ctx) {
|
|
158
|
+
const startIdx = ctx._start.tokenIndex;
|
|
159
|
+
const stopIdx = ctx._stop.tokenIndex;
|
|
160
|
+
const inlineLen = (0, leaf_1.approxInlineSpan)(f, startIdx, stopIdx);
|
|
161
|
+
const hasComments = (0, leaf_1.hasCommentsInRange)(f, startIdx, stopIdx);
|
|
162
|
+
if (!hasComments && f.o.lineLengthSoFar() + 1 + inlineLen <= tokens_1.LINE_BUDGET) {
|
|
163
|
+
for (let i = 0; i < ctx.childCount; i++)
|
|
164
|
+
f.format(ctx.getChild(i));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const whens = ctx.caseWhen();
|
|
168
|
+
const condStrs = whens.map(w => (0, inline_renderer_1.renderItemInline)(f, w._condition));
|
|
169
|
+
const maxCondLen = condStrs.reduce((m, s) => Math.max(m, s.length), 0);
|
|
170
|
+
f.o.indent++;
|
|
171
|
+
for (let i = 0; i < ctx.childCount; i++) {
|
|
172
|
+
const c = ctx.getChild(i);
|
|
173
|
+
if (c instanceof parser.CaseWhenContext) {
|
|
174
|
+
(0, leaf_1.flushHiddenBefore)(f, c._start.tokenIndex);
|
|
175
|
+
f.o.nl();
|
|
176
|
+
formatCaseWhen(f, c, maxCondLen);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (c instanceof tree_1.TerminalNode && c.symbol.type === tokens_1.L.ELSE) {
|
|
180
|
+
(0, leaf_1.flushHiddenBefore)(f, c.symbol.tokenIndex);
|
|
181
|
+
f.o.nl();
|
|
182
|
+
f.format(c);
|
|
183
|
+
// emit the else expression on the same line
|
|
184
|
+
i++;
|
|
185
|
+
if (i < ctx.childCount)
|
|
186
|
+
f.format(ctx.getChild(i));
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (c instanceof tree_1.TerminalNode && c.symbol.type === tokens_1.L.END) {
|
|
190
|
+
(0, leaf_1.flushHiddenBefore)(f, c.symbol.tokenIndex);
|
|
191
|
+
f.o.indent--;
|
|
192
|
+
f.o.nl();
|
|
193
|
+
f.format(c);
|
|
194
|
+
f.o.indent++;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
// CASE keyword and optional valueExpr stay on the head line.
|
|
198
|
+
f.format(c);
|
|
199
|
+
}
|
|
200
|
+
f.o.indent--;
|
|
201
|
+
}
|
|
202
|
+
function formatCaseWhen(f, ctx, maxCondLen) {
|
|
203
|
+
const condStr = (0, inline_renderer_1.renderItemInline)(f, ctx._condition);
|
|
204
|
+
const resultStr = (0, inline_renderer_1.renderItemInline)(f, ctx._result);
|
|
205
|
+
const padding = ' '.repeat(maxCondLen - condStr.length);
|
|
206
|
+
const aligned = `when ${condStr}${padding} then ${resultStr}`;
|
|
207
|
+
const hasComments = (0, leaf_1.hasCommentsInRange)(f, ctx._start.tokenIndex, ctx._stop.tokenIndex);
|
|
208
|
+
if (!hasComments && f.o.lineLengthSoFar() + aligned.length <= tokens_1.LINE_BUDGET) {
|
|
209
|
+
f.o.text(aligned);
|
|
210
|
+
(0, leaf_1.note)(f, ctx._stop.type, ctx._stop.tokenIndex, ctx._stop);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// Doesn't fit aligned — break at THEN. Flush comments between condition
|
|
214
|
+
// and THEN before the break for same-line attachment.
|
|
215
|
+
f.format(ctx.WHEN());
|
|
216
|
+
f.format(ctx._condition);
|
|
217
|
+
(0, leaf_1.flushHiddenBefore)(f, ctx.THEN().symbol.tokenIndex);
|
|
218
|
+
f.o.nl();
|
|
219
|
+
f.format(ctx.THEN());
|
|
220
|
+
f.format(ctx._result);
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=pick-case.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ParserRuleContext } from 'antlr4ts';
|
|
2
|
+
export type ItemKind = 'fieldEntry' | 'nestEntry' | 'fieldDef' | 'fieldName' | 'collectionMember' | 'orderBySpec' | 'fieldExpr' | 'joinDef' | 'includeField' | 'indexElement';
|
|
3
|
+
export interface SectionRule {
|
|
4
|
+
ctxClass: new (...args: never[]) => ParserRuleContext;
|
|
5
|
+
keywordTypes: number[];
|
|
6
|
+
list: (ctx: ParserRuleContext) => ParserRuleContext | undefined;
|
|
7
|
+
itemKind: ItemKind;
|
|
8
|
+
}
|
|
9
|
+
export declare const SECTION_STATEMENT_RULES: SectionRule[];
|
|
10
|
+
export declare const STATEMENT_KIND_BY_CTX: Array<{
|
|
11
|
+
ctxClass: new (...args: never[]) => ParserRuleContext;
|
|
12
|
+
kind: string;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Contributors to the Malloy project
|
|
4
|
+
* SPDX-License-Identifier: MIT
|
|
5
|
+
*
|
|
6
|
+
* Section-statement dispatch table and statement-kind labels.
|
|
7
|
+
*
|
|
8
|
+
* SECTION_STATEMENT_RULES is the table of `keyword: items` rules that need
|
|
9
|
+
* flow-fill, column alignment, or annotation-aware item handling. Section
|
|
10
|
+
* keywords NOT in this table fall through to the leaf walker, which produces
|
|
11
|
+
* correct-but-plain output. Add a row here only when the default isn't good
|
|
12
|
+
* enough.
|
|
13
|
+
*
|
|
14
|
+
* STATEMENT_KIND_BY_CTX is the coarse grouping used by the block-body rule
|
|
15
|
+
* to decide whether two adjacent statements should preserve a user-supplied
|
|
16
|
+
* blank line (different kinds: yes; same kind: no).
|
|
17
|
+
*
|
|
18
|
+
* A maintainer adding a new section-statement lands here first.
|
|
19
|
+
*/
|
|
20
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
24
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
25
|
+
}
|
|
26
|
+
Object.defineProperty(o, k2, desc);
|
|
27
|
+
}) : (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
}));
|
|
31
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
32
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
33
|
+
}) : function(o, v) {
|
|
34
|
+
o["default"] = v;
|
|
35
|
+
});
|
|
36
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
37
|
+
var ownKeys = function(o) {
|
|
38
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
39
|
+
var ar = [];
|
|
40
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
41
|
+
return ar;
|
|
42
|
+
};
|
|
43
|
+
return ownKeys(o);
|
|
44
|
+
};
|
|
45
|
+
return function (mod) {
|
|
46
|
+
if (mod && mod.__esModule) return mod;
|
|
47
|
+
var result = {};
|
|
48
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
})();
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.STATEMENT_KIND_BY_CTX = exports.SECTION_STATEMENT_RULES = void 0;
|
|
55
|
+
const parser = __importStar(require("../lib/Malloy/MalloyParser"));
|
|
56
|
+
const tokens_1 = require("./tokens");
|
|
57
|
+
// Constructs a SectionRule with the list-accessor closure typed against the
|
|
58
|
+
// concrete context class. The single internal narrowing is justified: the
|
|
59
|
+
// dispatcher only invokes `rule.list(node)` after `node instanceof
|
|
60
|
+
// rule.ctxClass`, so at runtime the parameter really is of type `C`.
|
|
61
|
+
function rule(ctxClass, keywordTypes, list, itemKind) {
|
|
62
|
+
return {
|
|
63
|
+
ctxClass,
|
|
64
|
+
keywordTypes,
|
|
65
|
+
list: ctx => list(ctx),
|
|
66
|
+
itemKind,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.SECTION_STATEMENT_RULES = [
|
|
70
|
+
rule(parser.AggregateStatementContext, [tokens_1.L.AGGREGATE], c => c.queryFieldList(), 'fieldEntry'),
|
|
71
|
+
rule(parser.GroupByStatementContext, [tokens_1.L.GROUP_BY], c => c.queryFieldList(), 'fieldEntry'),
|
|
72
|
+
rule(parser.CalculateStatementContext, [tokens_1.L.CALCULATE], c => c.queryFieldList(), 'fieldEntry'),
|
|
73
|
+
rule(parser.NestStatementContext, [tokens_1.L.NEST], c => c.nestedQueryList(), 'nestEntry'),
|
|
74
|
+
rule(parser.DeclareStatementContext, [tokens_1.L.DECLARE], c => c.defList(), 'fieldDef'),
|
|
75
|
+
rule(parser.DefMeasuresContext, [tokens_1.L.MEASURE], c => c.defList(), 'fieldDef'),
|
|
76
|
+
rule(parser.DefDimensionsContext, [tokens_1.L.DIMENSION], c => c.defList(), 'fieldDef'),
|
|
77
|
+
rule(parser.DefExploreEditFieldContext, [tokens_1.L.ACCEPT, tokens_1.L.EXCEPT], c => c.fieldNameList(), 'fieldName'),
|
|
78
|
+
rule(parser.ProjectStatementContext, [tokens_1.L.SELECT], c => c.fieldCollection(), 'collectionMember'),
|
|
79
|
+
rule(parser.OrderByStatementContext, [tokens_1.L.ORDER_BY], c => c.ordering(), 'orderBySpec'),
|
|
80
|
+
rule(parser.WhereStatementContext, [tokens_1.L.WHERE], c => c.filterClauseList(), 'fieldExpr'),
|
|
81
|
+
rule(parser.HavingStatementContext, [tokens_1.L.HAVING], c => c.filterClauseList(), 'fieldExpr'),
|
|
82
|
+
rule(parser.DefJoinOneContext, [tokens_1.L.JOIN_ONE], c => c.joinList(), 'joinDef'),
|
|
83
|
+
rule(parser.DefJoinManyContext, [tokens_1.L.JOIN_MANY], c => c.joinList(), 'joinDef'),
|
|
84
|
+
rule(parser.DefJoinCrossContext, [tokens_1.L.JOIN_CROSS], c => c.joinList(), 'joinDef'),
|
|
85
|
+
// include block items: `public: a, b`, `internal: x, y, z`. The keyword
|
|
86
|
+
// (PUBLIC/PRIVATE/INTERNAL) lives one level down inside accessLabelProp;
|
|
87
|
+
// findKeyword in ./sections handles that nested case.
|
|
88
|
+
rule(parser.IncludeItemContext, [tokens_1.L.PUBLIC, tokens_1.L.PRIVATE, tokens_1.L.INTERNAL], c => c.includeList(), 'includeField'),
|
|
89
|
+
rule(parser.IndexStatementContext, [tokens_1.L.INDEX], c => c.indexFields(), 'indexElement'),
|
|
90
|
+
];
|
|
91
|
+
// Coarse statement-kind labels for the same-kind-no-blank rule in block
|
|
92
|
+
// bodies. Different kinds preserve a single user-supplied blank line.
|
|
93
|
+
exports.STATEMENT_KIND_BY_CTX = [
|
|
94
|
+
{ ctxClass: parser.JoinStatementContext, kind: 'join' },
|
|
95
|
+
{ ctxClass: parser.QueryJoinStatementContext, kind: 'join' },
|
|
96
|
+
{ ctxClass: parser.DefMeasuresContext, kind: 'measure' },
|
|
97
|
+
{ ctxClass: parser.DefDimensionsContext, kind: 'dimension' },
|
|
98
|
+
{ ctxClass: parser.DeclareStatementContext, kind: 'declare' },
|
|
99
|
+
{ ctxClass: parser.AggregateStatementContext, kind: 'aggregate' },
|
|
100
|
+
{ ctxClass: parser.GroupByStatementContext, kind: 'group_by' },
|
|
101
|
+
{ ctxClass: parser.CalculateStatementContext, kind: 'calculate' },
|
|
102
|
+
{ ctxClass: parser.NestStatementContext, kind: 'nest' },
|
|
103
|
+
{ ctxClass: parser.WhereStatementContext, kind: 'where' },
|
|
104
|
+
{ ctxClass: parser.HavingStatementContext, kind: 'having' },
|
|
105
|
+
{ ctxClass: parser.OrderByStatementContext, kind: 'order_by' },
|
|
106
|
+
{ ctxClass: parser.ProjectStatementContext, kind: 'select' },
|
|
107
|
+
{ ctxClass: parser.DefExploreEditFieldContext, kind: 'edit_field' },
|
|
108
|
+
{ ctxClass: parser.DefExploreRenameContext, kind: 'rename' },
|
|
109
|
+
{ ctxClass: parser.DefExploreQueryContext, kind: 'view' },
|
|
110
|
+
];
|
|
111
|
+
//# sourceMappingURL=rules.js.map
|