@malloydata/malloy 0.0.384 → 0.0.386

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/api/foundation/config_resolve.js +12 -20
  2. package/dist/internal.d.ts +2 -0
  3. package/dist/internal.js +3 -1
  4. package/dist/lang/prettify/binary-chain.d.ts +3 -0
  5. package/dist/lang/prettify/binary-chain.js +65 -0
  6. package/dist/lang/prettify/block-body.d.ts +4 -0
  7. package/dist/lang/prettify/block-body.js +74 -0
  8. package/dist/lang/prettify/error-listener.d.ts +6 -0
  9. package/dist/lang/prettify/error-listener.js +19 -0
  10. package/dist/lang/prettify/field-properties.d.ts +3 -0
  11. package/dist/lang/prettify/field-properties.js +57 -0
  12. package/dist/lang/prettify/formatter.d.ts +17 -0
  13. package/dist/lang/prettify/formatter.js +145 -0
  14. package/dist/lang/prettify/index.d.ts +19 -0
  15. package/dist/lang/prettify/index.js +139 -0
  16. package/dist/lang/prettify/inline-renderer.d.ts +3 -0
  17. package/dist/lang/prettify/inline-renderer.js +101 -0
  18. package/dist/lang/prettify/leaf.d.ts +9 -0
  19. package/dist/lang/prettify/leaf.js +313 -0
  20. package/dist/lang/prettify/out.d.ts +12 -0
  21. package/dist/lang/prettify/out.js +74 -0
  22. package/dist/lang/prettify/pick-case.d.ts +5 -0
  23. package/dist/lang/prettify/pick-case.js +222 -0
  24. package/dist/lang/prettify/rules.d.ts +13 -0
  25. package/dist/lang/prettify/rules.js +103 -0
  26. package/dist/lang/prettify/sections.d.ts +4 -0
  27. package/dist/lang/prettify/sections.js +261 -0
  28. package/dist/lang/prettify/tokens.d.ts +13 -0
  29. package/dist/lang/prettify/tokens.js +160 -0
  30. package/dist/lang/prettify/types.d.ts +9 -0
  31. package/dist/lang/prettify/types.js +7 -0
  32. package/dist/lang/run-malloy-parser.d.ts +23 -0
  33. package/dist/lang/run-malloy-parser.js +32 -8
  34. package/dist/version.d.ts +1 -1
  35. package/dist/version.js +1 -1
  36. package/package.json +4 -4
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright Contributors to the Malloy project
4
+ * SPDX-License-Identifier: MIT
5
+ *
6
+ * Token classification, layout config, and small token utilities used by the
7
+ * prettifier's leaf walker and rule formatters.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.BINARY_OPS = exports.CALL_HUG_AFTER = exports.TOP_LEVEL_STARTERS = exports.SECTION_TOKENS = exports.INDENT_STR = exports.LINE_BUDGET = exports.L = void 0;
11
+ exports.leadingAction = leadingAction;
12
+ exports.endLineOf = endLineOf;
13
+ exports.findMatching = findMatching;
14
+ const MalloyLexer_1 = require("../lib/Malloy/MalloyLexer");
15
+ exports.L = MalloyLexer_1.MalloyLexer;
16
+ // ---------- Global formatting config ----------
17
+ exports.LINE_BUDGET = 100;
18
+ exports.INDENT_STR = ' '; // two spaces per indent level
19
+ // ---------- Token classification ----------
20
+ // Section keywords that introduce a `keyword: items` block (or a single value
21
+ // for some). Used by the leaf walker as a fallback newline rule when no
22
+ // explicit section-statement handler caught us.
23
+ exports.SECTION_TOKENS = new Set([
24
+ exports.L.ACCEPT,
25
+ exports.L.AGGREGATE,
26
+ exports.L.CALCULATE,
27
+ exports.L.CALCULATION,
28
+ exports.L.CONNECTION,
29
+ exports.L.DECLARE,
30
+ exports.L.DIMENSION,
31
+ exports.L.DRILL,
32
+ exports.L.EXCEPT,
33
+ exports.L.EXTENDQ,
34
+ exports.L.GROUP_BY,
35
+ exports.L.GROUPED_BY,
36
+ exports.L.HAVING,
37
+ exports.L.INDEX,
38
+ exports.L.INTERNAL,
39
+ exports.L.JOIN_CROSS,
40
+ exports.L.JOIN_ONE,
41
+ exports.L.JOIN_MANY,
42
+ exports.L.LIMIT,
43
+ exports.L.MEASURE,
44
+ exports.L.NEST,
45
+ exports.L.ORDER_BY,
46
+ exports.L.PARTITION_BY,
47
+ exports.L.PRIMARY_KEY,
48
+ exports.L.PRIVATE,
49
+ exports.L.PROJECT,
50
+ exports.L.PUBLIC,
51
+ exports.L.QUERY,
52
+ exports.L.RENAME,
53
+ exports.L.RUN,
54
+ exports.L.SAMPLE,
55
+ exports.L.SELECT,
56
+ exports.L.SOURCE,
57
+ exports.L.TYPE,
58
+ exports.L.TOP,
59
+ exports.L.WHERE,
60
+ exports.L.VIEW,
61
+ exports.L.TIMEZONE,
62
+ ]);
63
+ // Top-level statement starters. At column 0 each gets a blank line before it
64
+ // when introducing a new statement (subject to the same-kind-no-blank rule).
65
+ exports.TOP_LEVEL_STARTERS = new Set([
66
+ exports.L.SOURCE,
67
+ exports.L.QUERY,
68
+ exports.L.RUN,
69
+ exports.L.IMPORT,
70
+ ]);
71
+ // Token types after which an immediately following `(` or `[` is a call /
72
+ // subscript and should hug (no leading space). Anything else (binary ops,
73
+ // IS/AS/EXTEND/ON/WHEN/PICK/etc.) gets a space — the `(` is grouping.
74
+ exports.CALL_HUG_AFTER = new Set([
75
+ exports.L.IDENTIFIER,
76
+ exports.L.CPAREN,
77
+ exports.L.CBRACK,
78
+ // Aggregate / built-in callable keywords commonly used as function names.
79
+ exports.L.COUNT,
80
+ exports.L.SUM,
81
+ exports.L.AVG,
82
+ exports.L.MIN,
83
+ exports.L.MAX,
84
+ exports.L.TABLE,
85
+ exports.L.SQL,
86
+ exports.L.COMPOSE,
87
+ exports.L.CAST,
88
+ exports.L.NOW,
89
+ exports.L.LAST,
90
+ ]);
91
+ // Binary operators that get spaces on both sides at the leaf level.
92
+ // (Chain wrapping for and/or/??/+/- happens at parse-tree level — see
93
+ // formatBinaryChain.)
94
+ exports.BINARY_OPS = new Set([
95
+ exports.L.PLUS,
96
+ exports.L.MINUS,
97
+ exports.L.STAR,
98
+ exports.L.SLASH,
99
+ exports.L.PERCENT,
100
+ exports.L.STARSTAR,
101
+ exports.L.EQ,
102
+ exports.L.NE,
103
+ exports.L.LT,
104
+ exports.L.GT,
105
+ exports.L.LTE,
106
+ exports.L.GTE,
107
+ exports.L.AND,
108
+ exports.L.OR,
109
+ exports.L.MATCH,
110
+ exports.L.NOT_MATCH,
111
+ exports.L.ARROW,
112
+ exports.L.FAT_ARROW,
113
+ exports.L.BAR,
114
+ exports.L.AMPER,
115
+ ]);
116
+ function leadingAction(prevType, nextType) {
117
+ if (nextType === exports.L.DOT ||
118
+ nextType === exports.L.COMMA ||
119
+ nextType === exports.L.SEMI ||
120
+ nextType === exports.L.COLON ||
121
+ nextType === exports.L.TRIPLECOLON ||
122
+ nextType === exports.L.CPAREN ||
123
+ nextType === exports.L.CBRACK) {
124
+ return 'glue';
125
+ }
126
+ if ((nextType === exports.L.OPAREN || nextType === exports.L.OBRACK) &&
127
+ prevType !== null &&
128
+ exports.CALL_HUG_AFTER.has(prevType)) {
129
+ return 'hug';
130
+ }
131
+ return 'space';
132
+ }
133
+ // ---------- Token utilities ----------
134
+ function endLineOf(t) {
135
+ var _a, _b;
136
+ const text = (_a = t.text) !== null && _a !== void 0 ? _a : '';
137
+ const newlines = ((_b = text.match(/\n/g)) !== null && _b !== void 0 ? _b : []).length;
138
+ return t.line + newlines;
139
+ }
140
+ // Find the index of the closing token that matches the opener at startIdx.
141
+ // Counts nested begin/end pairs of the same types.
142
+ //
143
+ // Precondition: must not be called inside an SQL string region — depth
144
+ // tracking only knows about the begin/end token types passed in, not about
145
+ // embedded SQL. In practice we never call this inside an SQL block (we skip
146
+ // past them).
147
+ function findMatching(tokens, startIdx, beginType, endType) {
148
+ let depth = 1;
149
+ for (let j = startIdx + 1; j < tokens.length; j++) {
150
+ if (tokens[j].type === beginType)
151
+ depth++;
152
+ else if (tokens[j].type === endType) {
153
+ depth--;
154
+ if (depth === 0)
155
+ return j;
156
+ }
157
+ }
158
+ return tokens.length - 1;
159
+ }
160
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1,9 @@
1
+ export interface PrettifyError {
2
+ message: string;
3
+ line: number;
4
+ column: number;
5
+ }
6
+ export interface PrettifyResult {
7
+ result: string;
8
+ errors: PrettifyError[];
9
+ }
@@ -0,0 +1,7 @@
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
+ //# sourceMappingURL=types.js.map
@@ -1,3 +1,26 @@
1
+ import { CommonTokenStream } from 'antlr4ts';
2
+ import type { ANTLRErrorListener, Token, CodePointCharStream } from 'antlr4ts';
3
+ import { MalloyParser } from './lib/Malloy/MalloyParser';
1
4
  import type { MessageLogger } from './parse-log';
2
5
  import type { ParseInfo, SourceInfo } from './utils';
6
+ export interface MalloyParserSetupOptions {
7
+ lexerErrorListener?: ANTLRErrorListener<any>;
8
+ parserErrorListener?: ANTLRErrorListener<Token>;
9
+ }
10
+ /**
11
+ * Build a Malloy lexer/token-stream/parser triplet ready to invoke a grammar
12
+ * rule on `code`. Centralises the lexer fix (HandlesOverpoppingLexer for
13
+ * unmatched `}%`) and the project's MalloyErrorStrategy so callers can't
14
+ * accidentally diverge on those.
15
+ *
16
+ * The token stream is NOT pre-filled. Callers that need all tokens up front
17
+ * (e.g. the prettifier's leaf walker) should call `tokenStream.fill()` before
18
+ * iterating; callers that only need parser-driven access can leave it alone
19
+ * — the parser pulls tokens as it consumes the rule.
20
+ */
21
+ export declare function makeMalloyParser(code: string, options?: MalloyParserSetupOptions): {
22
+ inputStream: CodePointCharStream;
23
+ tokenStream: CommonTokenStream;
24
+ parser: MalloyParser;
25
+ };
3
26
  export declare function runMalloyParser(code: string, sourceURL: string, sourceInfo: SourceInfo, logger: MessageLogger, grammarRule?: string): ParseInfo;
@@ -6,6 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.makeMalloyParser = makeMalloyParser;
9
10
  exports.runMalloyParser = runMalloyParser;
10
11
  const antlr4ts_1 = require("antlr4ts");
11
12
  const MalloyLexer_1 = require("./lib/Malloy/MalloyLexer");
@@ -24,24 +25,47 @@ class HandlesOverpoppingLexer extends MalloyLexer_1.MalloyLexer {
24
25
  return super.popMode();
25
26
  }
26
27
  }
27
- function runMalloyParser(code, sourceURL, sourceInfo, logger, grammarRule = 'malloyDocument') {
28
+ /**
29
+ * Build a Malloy lexer/token-stream/parser triplet ready to invoke a grammar
30
+ * rule on `code`. Centralises the lexer fix (HandlesOverpoppingLexer for
31
+ * unmatched `}%`) and the project's MalloyErrorStrategy so callers can't
32
+ * accidentally diverge on those.
33
+ *
34
+ * The token stream is NOT pre-filled. Callers that need all tokens up front
35
+ * (e.g. the prettifier's leaf walker) should call `tokenStream.fill()` before
36
+ * iterating; callers that only need parser-driven access can leave it alone
37
+ * — the parser pulls tokens as it consumes the rule.
38
+ */
39
+ function makeMalloyParser(code, options = {}) {
28
40
  const inputStream = antlr4ts_1.CharStreams.fromString(code);
29
41
  const lexer = new HandlesOverpoppingLexer(inputStream);
42
+ if (options.lexerErrorListener) {
43
+ lexer.removeErrorListeners();
44
+ lexer.addErrorListener(options.lexerErrorListener);
45
+ }
30
46
  const tokenStream = new antlr4ts_1.CommonTokenStream(lexer);
31
- const malloyParser = new MalloyParser_1.MalloyParser(tokenStream);
32
- malloyParser.removeErrorListeners();
33
- malloyParser.addErrorListener(new malloy_parser_error_listener_1.MalloyParserErrorListener(logger, sourceURL, sourceInfo));
34
- malloyParser.errorHandler = new malloy_error_strategy_1.MalloyErrorStrategy();
47
+ const parser = new MalloyParser_1.MalloyParser(tokenStream);
48
+ if (options.parserErrorListener) {
49
+ parser.removeErrorListeners();
50
+ parser.addErrorListener(options.parserErrorListener);
51
+ }
52
+ parser.errorHandler = new malloy_error_strategy_1.MalloyErrorStrategy();
53
+ return { inputStream, tokenStream, parser };
54
+ }
55
+ function runMalloyParser(code, sourceURL, sourceInfo, logger, grammarRule = 'malloyDocument') {
56
+ const { inputStream, tokenStream, parser } = makeMalloyParser(code, {
57
+ parserErrorListener: new malloy_parser_error_listener_1.MalloyParserErrorListener(logger, sourceURL, sourceInfo),
58
+ });
35
59
  // Admitted code smell here, testing likes to parse from an arbitrary
36
60
  // node and this is the simplest way to allow that.
37
61
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
- const parseFunc = malloyParser[grammarRule];
62
+ const parseFunc = parser[grammarRule];
39
63
  if (!parseFunc) {
40
64
  throw new Error(`No such parse rule as ${grammarRule}`);
41
65
  }
42
66
  return {
43
- root: parseFunc.call(malloyParser),
44
- tokenStream: tokenStream,
67
+ root: parseFunc.call(parser),
68
+ tokenStream,
45
69
  sourceStream: inputStream,
46
70
  sourceInfo,
47
71
  sourceURL,
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const MALLOY_VERSION = "0.0.384";
1
+ export declare const MALLOY_VERSION = "0.0.386";
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.384';
5
+ exports.MALLOY_VERSION = '0.0.386';
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.384",
3
+ "version": "0.0.386",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -51,9 +51,9 @@
51
51
  "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"
52
52
  },
53
53
  "dependencies": {
54
- "@malloydata/malloy-filter": "0.0.384",
55
- "@malloydata/malloy-interfaces": "0.0.384",
56
- "@malloydata/malloy-tag": "0.0.384",
54
+ "@malloydata/malloy-filter": "0.0.386",
55
+ "@malloydata/malloy-interfaces": "0.0.386",
56
+ "@malloydata/malloy-tag": "0.0.386",
57
57
  "@noble/hashes": "^1.8.0",
58
58
  "antlr4ts": "^0.5.0-alpha.4",
59
59
  "assert": "^2.0.0",