@malloydata/malloy 0.0.51-dev230629171920 → 0.0.51-dev230705184641

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/index.d.ts +1 -1
  2. package/dist/lang/ast/elements/define-query.d.ts +3 -5
  3. package/dist/lang/ast/elements/define-query.js +1 -4
  4. package/dist/lang/ast/elements/define-source.d.ts +3 -5
  5. package/dist/lang/ast/elements/define-source.js +1 -4
  6. package/dist/lang/ast/elements/import-statement.d.ts +2 -1
  7. package/dist/lang/ast/elements/import-statement.js +12 -5
  8. package/dist/lang/ast/index.d.ts +1 -0
  9. package/dist/lang/ast/index.js +1 -0
  10. package/dist/lang/ast/query-elements/anonymous-query.d.ts +1 -2
  11. package/dist/lang/ast/query-elements/anonymous-query.js +0 -1
  12. package/dist/lang/ast/query-elements/run-query.d.ts +3 -4
  13. package/dist/lang/ast/sources/from-sql-source.d.ts +7 -0
  14. package/dist/lang/ast/sources/from-sql-source.js +68 -0
  15. package/dist/lang/ast/sources/sql-source.d.ts +15 -4
  16. package/dist/lang/ast/sources/sql-source.js +79 -27
  17. package/dist/lang/ast/sql-elements/sql-statement.d.ts +3 -1
  18. package/dist/lang/ast/sql-elements/sql-statement.js +21 -10
  19. package/dist/lang/ast/sql-elements/sql-string.d.ts +1 -0
  20. package/dist/lang/ast/sql-elements/sql-string.js +8 -0
  21. package/dist/lang/ast/types/malloy-element.d.ts +9 -6
  22. package/dist/lang/ast/types/malloy-element.js +42 -14
  23. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +73 -72
  24. package/dist/lang/lib/Malloy/MalloyLexer.js +1078 -1072
  25. package/dist/lang/lib/Malloy/MalloyParser.d.ts +86 -73
  26. package/dist/lang/lib/Malloy/MalloyParser.js +1198 -1135
  27. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +13 -0
  28. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +8 -0
  29. package/dist/lang/malloy-to-ast.d.ts +3 -2
  30. package/dist/lang/malloy-to-ast.js +17 -3
  31. package/dist/lang/parse-malloy.js +3 -3
  32. package/dist/lang/test/parse.spec.js +88 -1
  33. package/dist/lang/zone.d.ts +1 -1
  34. package/dist/malloy.js +1 -1
  35. package/dist/tags.d.ts +1 -1
  36. package/package.json +1 -1
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ModelAnnotation = exports.ObjectAnnotation = exports.Document = exports.RunList = exports.ListOf = exports.isDocStatement = exports.ModelEntryReference = exports.Unimplemented = exports.MalloyElement = void 0;
6
+ exports.ModelAnnotation = exports.ObjectAnnotation = exports.Document = exports.DocStatementList = exports.ListOf = exports.isDocStatementOrDocStatementList = exports.isDocStatement = exports.ModelEntryReference = exports.Unimplemented = exports.MalloyElement = void 0;
7
7
  /*
8
8
  * Copyright 2023 Google LLC
9
9
  *
@@ -202,16 +202,15 @@ class MalloyElement {
202
202
  }
203
203
  return asString;
204
204
  }
205
- walk(callBack) {
206
- callBack(this);
205
+ *walk() {
207
206
  for (const kidLabel of Object.keys(this.children)) {
208
207
  const kiddle = this.children[kidLabel];
209
208
  if (kiddle instanceof MalloyElement) {
210
- kiddle.walk(callBack);
209
+ yield kiddle;
211
210
  }
212
211
  else {
213
212
  for (const k of kiddle) {
214
- k.walk(callBack);
213
+ yield k;
215
214
  }
216
215
  }
217
216
  }
@@ -234,6 +233,13 @@ class MalloyElement {
234
233
  this.log(`INTERNAL ERROR IN TRANSLATION: ${msg}`);
235
234
  return new Error(msg);
236
235
  }
236
+ needs(doc) {
237
+ for (const child of this.walk()) {
238
+ const childNeeds = child.needs(doc);
239
+ if (childNeeds)
240
+ return childNeeds;
241
+ }
242
+ }
237
243
  }
238
244
  exports.MalloyElement = MalloyElement;
239
245
  class Unimplemented extends MalloyElement {
@@ -262,6 +268,10 @@ function isDocStatement(e) {
262
268
  return e.execute !== undefined;
263
269
  }
264
270
  exports.isDocStatement = isDocStatement;
271
+ function isDocStatementOrDocStatementList(el) {
272
+ return el instanceof DocStatementList || isDocStatement(el);
273
+ }
274
+ exports.isDocStatementOrDocStatementList = isDocStatementOrDocStatementList;
265
275
  class ListOf extends MalloyElement {
266
276
  constructor(elements) {
267
277
  super();
@@ -285,9 +295,16 @@ class ListOf extends MalloyElement {
285
295
  this.newContents();
286
296
  return this.elements;
287
297
  }
298
+ needs(doc) {
299
+ for (const element of this.elements) {
300
+ const elementNeeds = element.needs(doc);
301
+ if (elementNeeds)
302
+ return elementNeeds;
303
+ }
304
+ }
288
305
  }
289
306
  exports.ListOf = ListOf;
290
- class RunList extends ListOf {
307
+ class DocStatementList extends ListOf {
291
308
  constructor() {
292
309
  super(...arguments);
293
310
  this.elementType = 'topLevelStatements';
@@ -307,18 +324,30 @@ class RunList extends ListOf {
307
324
  }
308
325
  this.noteCursor += 1;
309
326
  }
310
- const resp = el.execute(doc);
311
- if (resp) {
312
- // Statment needs information (likely SQL schema) so we return
313
- // the response, and will come back here later
314
- return resp;
327
+ // For DocStatementLists, we want to incrementally execute
328
+ // the list, returning needs only when individual statements
329
+ // report needs, not when the whole list has needs (because
330
+ // the needs of one statement in a list may depend on those
331
+ // of another statement earlier in the list). For regular
332
+ // DocStatements, we first check their needs and return them
333
+ // if there are any; otherwise we execute the statement.
334
+ if (el instanceof DocStatementList) {
335
+ const needs = el.executeList(doc);
336
+ if (needs)
337
+ return needs;
338
+ }
339
+ else {
340
+ const needs = el.needs(doc);
341
+ if (needs)
342
+ return needs;
343
+ el.execute(doc);
315
344
  }
316
345
  this.execCursor += 1;
317
346
  }
318
347
  return undefined;
319
348
  }
320
349
  }
321
- exports.RunList = RunList;
350
+ exports.DocStatementList = DocStatementList;
322
351
  /**
323
352
  * The Document class is a little weird because we might need to bounce back
324
353
  * to the requestor, which might be on the other side of a wire, to get
@@ -342,7 +371,7 @@ class Document extends MalloyElement {
342
371
  this.sqlBlocks = [];
343
372
  this.didInitModel = false;
344
373
  this.notes = [];
345
- this.statements = new RunList(statements);
374
+ this.statements = new DocStatementList(statements);
346
375
  this.has({ statements: statements });
347
376
  }
348
377
  initModelDef(extendingModelDef) {
@@ -435,7 +464,6 @@ class ModelAnnotation extends ObjectAnnotation {
435
464
  }
436
465
  execute(doc) {
437
466
  doc.notes = doc.notes.concat(this.notes);
438
- return;
439
467
  }
440
468
  }
441
469
  exports.ModelAnnotation = ModelAnnotation;
@@ -31,7 +31,7 @@ export declare class MalloyLexer extends Lexer {
31
31
  static readonly SAMPLE = 26;
32
32
  static readonly SELECT = 27;
33
33
  static readonly SOURCE = 28;
34
- static readonly SQL = 29;
34
+ static readonly SQLC = 29;
35
35
  static readonly TOP = 30;
36
36
  static readonly WHERE = 31;
37
37
  static readonly TIMEZONE = 32;
@@ -78,77 +78,78 @@ export declare class MalloyLexer extends Lexer {
78
78
  static readonly SECOND = 73;
79
79
  static readonly STRING = 74;
80
80
  static readonly SUM = 75;
81
- static readonly TABLE = 76;
82
- static readonly THEN = 77;
83
- static readonly THIS = 78;
84
- static readonly TIMESTAMP = 79;
85
- static readonly TO = 80;
86
- static readonly TRUE = 81;
87
- static readonly TURTLE = 82;
88
- static readonly WEEK = 83;
89
- static readonly WHEN = 84;
90
- static readonly WITH = 85;
91
- static readonly YEAR = 86;
92
- static readonly UNGROUPED = 87;
93
- static readonly STRING_ESCAPE = 88;
94
- static readonly HACKY_REGEX = 89;
95
- static readonly STRING_LITERAL = 90;
96
- static readonly DOC_ANNOTATION = 91;
97
- static readonly ANNOTATION = 92;
98
- static readonly AMPER = 93;
99
- static readonly ARROW = 94;
100
- static readonly FAT_ARROW = 95;
101
- static readonly OPAREN = 96;
102
- static readonly CPAREN = 97;
103
- static readonly OBRACK = 98;
104
- static readonly CBRACK = 99;
105
- static readonly OCURLY = 100;
106
- static readonly CCURLY = 101;
107
- static readonly DOUBLECOLON = 102;
108
- static readonly TRIPLECOLON = 103;
109
- static readonly EXCLAM = 104;
110
- static readonly COLON = 105;
111
- static readonly COMMA = 106;
112
- static readonly DOT = 107;
113
- static readonly LT = 108;
114
- static readonly GT = 109;
115
- static readonly EQ = 110;
116
- static readonly NE = 111;
117
- static readonly LTE = 112;
118
- static readonly GTE = 113;
119
- static readonly PLUS = 114;
120
- static readonly MINUS = 115;
121
- static readonly STAR = 116;
122
- static readonly STARSTAR = 117;
123
- static readonly SLASH = 118;
124
- static readonly BAR = 119;
125
- static readonly SEMI = 120;
126
- static readonly NOT_MATCH = 121;
127
- static readonly MATCH = 122;
128
- static readonly PERCENT = 123;
129
- static readonly DOUBLE_QMARK = 124;
130
- static readonly QMARK = 125;
131
- static readonly LITERAL_TIMESTAMP = 126;
132
- static readonly LITERAL_HOUR = 127;
133
- static readonly LITERAL_DAY = 128;
134
- static readonly LITERAL_QUARTER = 129;
135
- static readonly LITERAL_MONTH = 130;
136
- static readonly LITERAL_WEEK = 131;
137
- static readonly LITERAL_YEAR = 132;
138
- static readonly IDENTIFIER = 133;
139
- static readonly PERCENT_LITERAL = 134;
140
- static readonly INTEGER_LITERAL = 135;
141
- static readonly NUMERIC_LITERAL = 136;
142
- static readonly OBJECT_NAME_LITERAL = 137;
143
- static readonly BLOCK_COMMENT = 138;
144
- static readonly COMMENT_TO_EOL = 139;
145
- static readonly WHITE_SPACE = 140;
146
- static readonly SQL_BEGIN = 141;
147
- static readonly CLOSE_CODE = 142;
148
- static readonly UNWATED_CHARS_TRAILING_NUMBERS = 143;
149
- static readonly UNEXPECTED_CHAR = 144;
150
- static readonly OPEN_CODE = 145;
151
- static readonly SQL_END = 146;
81
+ static readonly SQL = 76;
82
+ static readonly TABLE = 77;
83
+ static readonly THEN = 78;
84
+ static readonly THIS = 79;
85
+ static readonly TIMESTAMP = 80;
86
+ static readonly TO = 81;
87
+ static readonly TRUE = 82;
88
+ static readonly TURTLE = 83;
89
+ static readonly WEEK = 84;
90
+ static readonly WHEN = 85;
91
+ static readonly WITH = 86;
92
+ static readonly YEAR = 87;
93
+ static readonly UNGROUPED = 88;
94
+ static readonly STRING_ESCAPE = 89;
95
+ static readonly HACKY_REGEX = 90;
96
+ static readonly STRING_LITERAL = 91;
97
+ static readonly DOC_ANNOTATION = 92;
98
+ static readonly ANNOTATION = 93;
99
+ static readonly AMPER = 94;
100
+ static readonly ARROW = 95;
101
+ static readonly FAT_ARROW = 96;
102
+ static readonly OPAREN = 97;
103
+ static readonly CPAREN = 98;
104
+ static readonly OBRACK = 99;
105
+ static readonly CBRACK = 100;
106
+ static readonly OCURLY = 101;
107
+ static readonly CCURLY = 102;
108
+ static readonly DOUBLECOLON = 103;
109
+ static readonly TRIPLECOLON = 104;
110
+ static readonly EXCLAM = 105;
111
+ static readonly COLON = 106;
112
+ static readonly COMMA = 107;
113
+ static readonly DOT = 108;
114
+ static readonly LT = 109;
115
+ static readonly GT = 110;
116
+ static readonly EQ = 111;
117
+ static readonly NE = 112;
118
+ static readonly LTE = 113;
119
+ static readonly GTE = 114;
120
+ static readonly PLUS = 115;
121
+ static readonly MINUS = 116;
122
+ static readonly STAR = 117;
123
+ static readonly STARSTAR = 118;
124
+ static readonly SLASH = 119;
125
+ static readonly BAR = 120;
126
+ static readonly SEMI = 121;
127
+ static readonly NOT_MATCH = 122;
128
+ static readonly MATCH = 123;
129
+ static readonly PERCENT = 124;
130
+ static readonly DOUBLE_QMARK = 125;
131
+ static readonly QMARK = 126;
132
+ static readonly LITERAL_TIMESTAMP = 127;
133
+ static readonly LITERAL_HOUR = 128;
134
+ static readonly LITERAL_DAY = 129;
135
+ static readonly LITERAL_QUARTER = 130;
136
+ static readonly LITERAL_MONTH = 131;
137
+ static readonly LITERAL_WEEK = 132;
138
+ static readonly LITERAL_YEAR = 133;
139
+ static readonly IDENTIFIER = 134;
140
+ static readonly PERCENT_LITERAL = 135;
141
+ static readonly INTEGER_LITERAL = 136;
142
+ static readonly NUMERIC_LITERAL = 137;
143
+ static readonly OBJECT_NAME_LITERAL = 138;
144
+ static readonly BLOCK_COMMENT = 139;
145
+ static readonly COMMENT_TO_EOL = 140;
146
+ static readonly WHITE_SPACE = 141;
147
+ static readonly SQL_BEGIN = 142;
148
+ static readonly CLOSE_CODE = 143;
149
+ static readonly UNWATED_CHARS_TRAILING_NUMBERS = 144;
150
+ static readonly UNEXPECTED_CHAR = 145;
151
+ static readonly OPEN_CODE = 146;
152
+ static readonly SQL_END = 147;
152
153
  static readonly SQL_MODE = 1;
153
154
  static readonly channelNames: string[];
154
155
  static readonly modeNames: string[];