@malloydata/malloy 0.0.39-dev230613161129 → 0.0.39

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 (288) hide show
  1. package/dist/dialect/dialect.d.ts +9 -13
  2. package/dist/dialect/dialect.js +16 -3
  3. package/dist/dialect/dialect_map.d.ts +2 -0
  4. package/dist/dialect/dialect_map.js +61 -1
  5. package/dist/dialect/{duckdb.d.ts → duckdb/duckdb.d.ts} +8 -5
  6. package/dist/dialect/{duckdb.js → duckdb/duckdb.js} +21 -9
  7. package/dist/dialect/duckdb/functions/byte_length.d.ts +2 -0
  8. package/dist/dialect/duckdb/functions/byte_length.js +33 -0
  9. package/dist/dialect/duckdb/functions/div.d.ts +2 -0
  10. package/dist/dialect/duckdb/functions/div.js +38 -0
  11. package/dist/dialect/duckdb/functions/duckdb_functions.d.ts +1 -0
  12. package/dist/dialect/duckdb/functions/duckdb_functions.js +52 -0
  13. package/dist/dialect/duckdb/functions/ends_with.d.ts +2 -0
  14. package/dist/dialect/duckdb/functions/ends_with.js +35 -0
  15. package/dist/dialect/duckdb/functions/greatest_and_least.d.ts +3 -0
  16. package/dist/dialect/duckdb/functions/greatest_and_least.js +58 -0
  17. package/dist/dialect/duckdb/functions/index.d.ts +1 -0
  18. package/dist/dialect/duckdb/functions/index.js +28 -0
  19. package/dist/dialect/duckdb/functions/is_inf.d.ts +2 -0
  20. package/dist/dialect/duckdb/functions/is_inf.js +33 -0
  21. package/dist/dialect/duckdb/functions/is_nan.d.ts +2 -0
  22. package/dist/dialect/duckdb/functions/is_nan.js +33 -0
  23. package/dist/dialect/duckdb/functions/log.d.ts +2 -0
  24. package/dist/dialect/duckdb/functions/log.js +38 -0
  25. package/dist/dialect/duckdb/functions/rand.d.ts +2 -0
  26. package/dist/dialect/duckdb/functions/rand.js +31 -0
  27. package/dist/dialect/duckdb/functions/replace.d.ts +2 -0
  28. package/dist/dialect/duckdb/functions/replace.js +40 -0
  29. package/dist/dialect/duckdb/functions/trunc.d.ts +2 -0
  30. package/dist/dialect/duckdb/functions/trunc.js +39 -0
  31. package/dist/dialect/duckdb/functions/unicode.d.ts +2 -0
  32. package/dist/dialect/duckdb/functions/unicode.js +35 -0
  33. package/dist/dialect/duckdb/index.d.ts +1 -0
  34. package/dist/dialect/duckdb/index.js +40 -0
  35. package/dist/dialect/functions/all_functions.d.ts +8 -0
  36. package/dist/dialect/functions/all_functions.js +135 -0
  37. package/dist/dialect/functions/atan2.d.ts +2 -0
  38. package/dist/dialect/functions/atan2.js +33 -0
  39. package/dist/dialect/functions/avg_moving.d.ts +2 -0
  40. package/dist/dialect/functions/avg_moving.js +46 -0
  41. package/dist/dialect/functions/chr.d.ts +4 -0
  42. package/dist/dialect/functions/chr.js +45 -0
  43. package/dist/dialect/functions/coalesce.d.ts +2 -0
  44. package/dist/dialect/functions/coalesce.js +38 -0
  45. package/dist/dialect/functions/concat.d.ts +2 -0
  46. package/dist/dialect/functions/concat.js +38 -0
  47. package/dist/dialect/functions/div.d.ts +2 -0
  48. package/dist/dialect/functions/div.js +36 -0
  49. package/dist/dialect/functions/first_value_window.d.ts +3 -0
  50. package/dist/dialect/functions/first_value_window.js +49 -0
  51. package/dist/dialect/functions/function_map.d.ts +16 -0
  52. package/dist/dialect/functions/function_map.js +50 -0
  53. package/dist/dialect/functions/greatest_and_least.d.ts +3 -0
  54. package/dist/dialect/functions/greatest_and_least.js +44 -0
  55. package/dist/dialect/functions/ifnull.d.ts +2 -0
  56. package/dist/dialect/functions/ifnull.js +38 -0
  57. package/dist/dialect/functions/index.d.ts +2 -0
  58. package/dist/dialect/functions/index.js +28 -0
  59. package/dist/dialect/functions/is_inf.d.ts +2 -0
  60. package/dist/dialect/functions/is_inf.js +33 -0
  61. package/dist/dialect/functions/is_nan.d.ts +2 -0
  62. package/dist/dialect/functions/is_nan.js +33 -0
  63. package/dist/dialect/functions/lag.d.ts +2 -0
  64. package/dist/dialect/functions/lag.js +53 -0
  65. package/dist/dialect/functions/lead.d.ts +2 -0
  66. package/dist/dialect/functions/lead.js +50 -0
  67. package/dist/dialect/functions/length.d.ts +3 -0
  68. package/dist/dialect/functions/length.js +39 -0
  69. package/dist/dialect/functions/log.d.ts +2 -0
  70. package/dist/dialect/functions/log.js +35 -0
  71. package/dist/dialect/functions/lower.d.ts +2 -0
  72. package/dist/dialect/functions/lower.js +34 -0
  73. package/dist/dialect/functions/nullif.d.ts +2 -0
  74. package/dist/dialect/functions/nullif.js +42 -0
  75. package/dist/dialect/functions/pi.d.ts +2 -0
  76. package/dist/{lang/ast/types/type-desc.js → dialect/functions/pi.js} +7 -1
  77. package/dist/dialect/functions/pow.d.ts +2 -0
  78. package/dist/dialect/functions/pow.js +35 -0
  79. package/dist/dialect/functions/rand.d.ts +2 -0
  80. package/dist/dialect/functions/rand.js +31 -0
  81. package/dist/dialect/functions/rank.d.ts +2 -0
  82. package/dist/dialect/functions/rank.js +36 -0
  83. package/dist/dialect/functions/regexp_extract.d.ts +2 -0
  84. package/dist/dialect/functions/regexp_extract.js +41 -0
  85. package/dist/dialect/functions/repeat.d.ts +2 -0
  86. package/dist/dialect/functions/repeat.js +35 -0
  87. package/dist/dialect/functions/replace.d.ts +2 -0
  88. package/dist/dialect/functions/replace.js +42 -0
  89. package/dist/dialect/functions/reverse.d.ts +2 -0
  90. package/dist/dialect/functions/reverse.js +34 -0
  91. package/dist/dialect/functions/round.d.ts +2 -0
  92. package/dist/dialect/functions/round.js +40 -0
  93. package/dist/dialect/functions/row_number.d.ts +2 -0
  94. package/dist/dialect/functions/row_number.js +40 -0
  95. package/dist/dialect/functions/simple_numeric_functions.d.ts +15 -0
  96. package/dist/dialect/functions/simple_numeric_functions.js +60 -0
  97. package/dist/dialect/functions/starts_ends_with.d.ts +3 -0
  98. package/dist/dialect/functions/starts_ends_with.js +43 -0
  99. package/dist/dialect/functions/stddev.d.ts +2 -0
  100. package/dist/dialect/functions/stddev.js +34 -0
  101. package/dist/dialect/functions/strpos.d.ts +2 -0
  102. package/dist/dialect/functions/strpos.js +35 -0
  103. package/dist/dialect/functions/substr.d.ts +2 -0
  104. package/dist/dialect/functions/substr.js +37 -0
  105. package/dist/dialect/functions/sum_min_max_window.d.ts +7 -0
  106. package/dist/dialect/functions/sum_min_max_window.js +94 -0
  107. package/dist/dialect/functions/trim_functions.d.ts +4 -0
  108. package/dist/dialect/functions/trim_functions.js +42 -0
  109. package/dist/dialect/functions/trunc.d.ts +2 -0
  110. package/dist/dialect/functions/trunc.js +38 -0
  111. package/dist/dialect/functions/upper.d.ts +2 -0
  112. package/dist/dialect/functions/upper.js +34 -0
  113. package/dist/dialect/functions/util.d.ts +45 -0
  114. package/dist/dialect/functions/util.js +187 -0
  115. package/dist/dialect/index.d.ts +1 -1
  116. package/dist/dialect/index.js +2 -1
  117. package/dist/dialect/postgres/functions/byte_length.d.ts +2 -0
  118. package/dist/dialect/postgres/functions/byte_length.js +33 -0
  119. package/dist/dialect/postgres/functions/ends_with.d.ts +2 -0
  120. package/dist/dialect/postgres/functions/ends_with.js +38 -0
  121. package/dist/dialect/postgres/functions/greatest_and_least.d.ts +3 -0
  122. package/dist/dialect/postgres/functions/greatest_and_least.js +45 -0
  123. package/dist/dialect/postgres/functions/ifnull.d.ts +2 -0
  124. package/dist/dialect/postgres/functions/ifnull.js +40 -0
  125. package/dist/dialect/postgres/functions/index.d.ts +1 -0
  126. package/dist/dialect/postgres/functions/index.js +28 -0
  127. package/dist/dialect/postgres/functions/is_inf.d.ts +2 -0
  128. package/dist/dialect/postgres/functions/is_inf.js +34 -0
  129. package/dist/dialect/postgres/functions/is_nan.d.ts +2 -0
  130. package/dist/dialect/postgres/functions/is_nan.js +33 -0
  131. package/dist/dialect/postgres/functions/log.d.ts +2 -0
  132. package/dist/dialect/postgres/functions/log.js +37 -0
  133. package/dist/dialect/postgres/functions/postgres_functions.d.ts +1 -0
  134. package/dist/dialect/postgres/functions/postgres_functions.js +60 -0
  135. package/dist/dialect/postgres/functions/rand.d.ts +2 -0
  136. package/dist/dialect/postgres/functions/rand.js +31 -0
  137. package/dist/dialect/postgres/functions/regexp_extract.d.ts +2 -0
  138. package/dist/dialect/postgres/functions/regexp_extract.js +35 -0
  139. package/dist/dialect/postgres/functions/replace.d.ts +2 -0
  140. package/dist/dialect/postgres/functions/replace.js +40 -0
  141. package/dist/dialect/postgres/functions/round.d.ts +2 -0
  142. package/dist/dialect/postgres/functions/round.js +39 -0
  143. package/dist/dialect/postgres/functions/stddev.d.ts +2 -0
  144. package/dist/dialect/postgres/functions/stddev.js +37 -0
  145. package/dist/dialect/postgres/functions/substr.d.ts +2 -0
  146. package/dist/dialect/postgres/functions/substr.js +38 -0
  147. package/dist/dialect/postgres/functions/trunc.d.ts +2 -0
  148. package/dist/dialect/postgres/functions/trunc.js +40 -0
  149. package/dist/dialect/postgres/functions/unicode.d.ts +2 -0
  150. package/dist/dialect/postgres/functions/unicode.js +34 -0
  151. package/dist/dialect/postgres/index.d.ts +1 -0
  152. package/dist/dialect/postgres/index.js +40 -0
  153. package/dist/dialect/{postgres.d.ts → postgres/postgres.d.ts} +9 -5
  154. package/dist/dialect/{postgres.js → postgres/postgres.js} +24 -10
  155. package/dist/dialect/standardsql/functions/chr.d.ts +2 -0
  156. package/dist/dialect/standardsql/functions/chr.js +37 -0
  157. package/dist/dialect/standardsql/functions/index.d.ts +1 -0
  158. package/dist/dialect/standardsql/functions/index.js +28 -0
  159. package/dist/dialect/standardsql/functions/pi.d.ts +2 -0
  160. package/dist/dialect/standardsql/functions/pi.js +32 -0
  161. package/dist/dialect/standardsql/functions/standardsql_functions.d.ts +1 -0
  162. package/dist/dialect/standardsql/functions/standardsql_functions.js +33 -0
  163. package/dist/dialect/standardsql/index.d.ts +1 -0
  164. package/dist/dialect/standardsql/index.js +40 -0
  165. package/dist/dialect/{standardsql.d.ts → standardsql/standardsql.d.ts} +7 -4
  166. package/dist/dialect/{standardsql.js → standardsql/standardsql.js} +13 -11
  167. package/dist/index.d.ts +1 -1
  168. package/dist/lang/ast/ast-utils.js +1 -0
  169. package/dist/lang/ast/elements/define-query.js +1 -1
  170. package/dist/lang/ast/elements/import-statement.js +6 -1
  171. package/dist/lang/ast/executors/index-executor.d.ts +1 -1
  172. package/dist/lang/ast/executors/index-executor.js +2 -2
  173. package/dist/lang/ast/executors/project-executor.d.ts +1 -1
  174. package/dist/lang/ast/executors/project-executor.js +2 -2
  175. package/dist/lang/ast/executors/reduce-executor.d.ts +2 -4
  176. package/dist/lang/ast/executors/reduce-executor.js +8 -4
  177. package/dist/lang/ast/expressions/binary-boolean.d.ts +1 -1
  178. package/dist/lang/ast/expressions/binary-boolean.js +2 -0
  179. package/dist/lang/ast/expressions/constant-sub-expression.js +10 -0
  180. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +2 -2
  181. package/dist/lang/ast/expressions/expr-aggregate-function.js +28 -2
  182. package/dist/lang/ast/expressions/expr-alternation-tree.js +1 -0
  183. package/dist/lang/ast/expressions/expr-cast.js +1 -0
  184. package/dist/lang/ast/expressions/expr-coalesce.d.ts +1 -1
  185. package/dist/lang/ast/expressions/expr-coalesce.js +1 -0
  186. package/dist/lang/ast/expressions/expr-count-distinct.d.ts +1 -1
  187. package/dist/lang/ast/expressions/expr-count.js +1 -0
  188. package/dist/lang/ast/expressions/expr-filter.d.ts +1 -1
  189. package/dist/lang/ast/expressions/expr-filter.js +1 -1
  190. package/dist/lang/ast/expressions/expr-func.d.ts +6 -1
  191. package/dist/lang/ast/expressions/expr-func.js +266 -16
  192. package/dist/lang/ast/expressions/expr-granular-time.d.ts +1 -1
  193. package/dist/lang/ast/expressions/expr-id-reference.js +12 -0
  194. package/dist/lang/ast/expressions/expr-logical-op.d.ts +1 -1
  195. package/dist/lang/ast/expressions/expr-max.d.ts +2 -2
  196. package/dist/lang/ast/expressions/expr-min.d.ts +2 -2
  197. package/dist/lang/ast/expressions/expr-not.d.ts +1 -1
  198. package/dist/lang/ast/expressions/expr-now.js +2 -0
  199. package/dist/lang/ast/expressions/expr-null.js +1 -0
  200. package/dist/lang/ast/expressions/expr-number.js +5 -1
  201. package/dist/lang/ast/expressions/expr-regex.js +4 -1
  202. package/dist/lang/ast/expressions/expr-string.js +1 -0
  203. package/dist/lang/ast/expressions/expr-time-extract.js +2 -0
  204. package/dist/lang/ast/expressions/expr-time.js +1 -0
  205. package/dist/lang/ast/expressions/expr-ungroup.d.ts +2 -2
  206. package/dist/lang/ast/expressions/expr-ungroup.js +15 -7
  207. package/dist/lang/ast/expressions/for-range.d.ts +1 -1
  208. package/dist/lang/ast/expressions/pick-when.js +7 -0
  209. package/dist/lang/ast/expressions/range.js +1 -0
  210. package/dist/lang/ast/expressions/time-literal.js +9 -3
  211. package/dist/lang/ast/field-space/column-space-field.d.ts +1 -2
  212. package/dist/lang/ast/field-space/dynamic-space.js +6 -4
  213. package/dist/lang/ast/field-space/field-definition-value.d.ts +1 -1
  214. package/dist/lang/ast/field-space/project-field-space.d.ts +2 -2
  215. package/dist/lang/ast/field-space/project-field-space.js +12 -13
  216. package/dist/lang/ast/field-space/query-space-field.d.ts +1 -2
  217. package/dist/lang/ast/field-space/query-space-field.js +1 -1
  218. package/dist/lang/ast/field-space/query-spaces.d.ts +16 -2
  219. package/dist/lang/ast/field-space/query-spaces.js +175 -10
  220. package/dist/lang/ast/field-space/reference-field.d.ts +3 -2
  221. package/dist/lang/ast/field-space/reference-field.js +8 -1
  222. package/dist/lang/ast/field-space/rename-space-field.d.ts +1 -2
  223. package/dist/lang/ast/field-space/static-space.d.ts +4 -3
  224. package/dist/lang/ast/field-space/static-space.js +4 -0
  225. package/dist/lang/ast/field-space/struct-space-field-base.d.ts +1 -2
  226. package/dist/lang/ast/field-space/struct-space-field-base.js +1 -1
  227. package/dist/lang/ast/field-space/wild-space-field.d.ts +1 -2
  228. package/dist/lang/ast/fragtype-utils.d.ts +1 -1
  229. package/dist/lang/ast/fragtype-utils.js +4 -3
  230. package/dist/lang/ast/index.d.ts +1 -0
  231. package/dist/lang/ast/index.js +1 -0
  232. package/dist/lang/ast/query-items/field-declaration.d.ts +40 -4
  233. package/dist/lang/ast/query-items/field-declaration.js +102 -3
  234. package/dist/lang/ast/query-items/field-references.d.ts +44 -2
  235. package/dist/lang/ast/query-items/field-references.js +110 -2
  236. package/dist/lang/ast/query-items/typecheck_utils.d.ts +10 -0
  237. package/dist/lang/ast/query-items/typecheck_utils.js +177 -0
  238. package/dist/lang/ast/query-properties/aggregate.js +0 -6
  239. package/dist/lang/ast/query-properties/calculate.d.ts +5 -0
  240. package/dist/lang/ast/query-properties/calculate.js +33 -0
  241. package/dist/lang/ast/query-properties/dimmensions.js +0 -3
  242. package/dist/lang/ast/query-properties/filters.js +6 -3
  243. package/dist/lang/ast/query-properties/group-by.js +0 -6
  244. package/dist/lang/ast/query-properties/measures.js +0 -3
  245. package/dist/lang/ast/query-properties/nest-reference.d.ts +2 -0
  246. package/dist/lang/ast/query-properties/nest-reference.js +23 -0
  247. package/dist/lang/ast/query-properties/ordering.d.ts +1 -1
  248. package/dist/lang/ast/query-properties/ordering.js +18 -8
  249. package/dist/lang/ast/query-properties/qop-desc.js +8 -4
  250. package/dist/lang/ast/query-properties/top.js +20 -6
  251. package/dist/lang/ast/sources/named-source.js +4 -0
  252. package/dist/lang/ast/sources/sql-source.js +5 -1
  253. package/dist/lang/ast/time-utils.d.ts +1 -2
  254. package/dist/lang/ast/types/expr-result.d.ts +1 -2
  255. package/dist/lang/ast/types/expression-def.d.ts +3 -4
  256. package/dist/lang/ast/types/expression-def.js +10 -2
  257. package/dist/lang/ast/types/field-space.d.ts +7 -0
  258. package/dist/lang/ast/types/global-name-space.d.ts +12 -0
  259. package/dist/lang/ast/types/global-name-space.js +51 -0
  260. package/dist/lang/ast/types/malloy-element.d.ts +1 -0
  261. package/dist/lang/ast/types/malloy-element.js +15 -2
  262. package/dist/lang/ast/types/query-property.d.ts +1 -2
  263. package/dist/lang/ast/types/query-property.js +2 -0
  264. package/dist/lang/ast/types/space-entry.d.ts +1 -1
  265. package/dist/lang/ast/types/space-field.d.ts +1 -2
  266. package/dist/lang/ast/types/space-field.js +5 -1
  267. package/dist/lang/ast/types/space-param.d.ts +1 -2
  268. package/dist/lang/ast/types/space-param.js +10 -2
  269. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +138 -135
  270. package/dist/lang/lib/Malloy/MalloyLexer.js +1135 -1103
  271. package/dist/lang/lib/Malloy/MalloyParser.d.ts +252 -275
  272. package/dist/lang/lib/Malloy/MalloyParser.js +1753 -1905
  273. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +40 -103
  274. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +25 -64
  275. package/dist/lang/malloy-to-ast.d.ts +11 -7
  276. package/dist/lang/malloy-to-ast.js +90 -51
  277. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +5 -2
  278. package/dist/lang/test/parse.spec.js +399 -18
  279. package/dist/lang/test/test-translator.d.ts +1 -0
  280. package/dist/lang/test/test-translator.js +5 -0
  281. package/dist/model/malloy_query.d.ts +13 -4
  282. package/dist/model/malloy_query.js +240 -76
  283. package/dist/model/malloy_types.d.ts +89 -18
  284. package/dist/model/malloy_types.js +88 -61
  285. package/dist/model/utils.d.ts +4 -0
  286. package/dist/model/utils.js +118 -1
  287. package/package.json +1 -1
  288. package/dist/lang/ast/types/type-desc.d.ts +0 -8
@@ -208,22 +208,8 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
208
208
  const fel = new ast.FilterElement(expr, this.getSourceCode(cx));
209
209
  return this.astAt(fel, cx);
210
210
  }
211
- getFieldDefs(cxList, isAgg) {
212
- const visited = [];
213
- for (const cx of cxList) {
214
- const v = this.visit(cx);
215
- if (v instanceof ast.FieldDeclaration) {
216
- this.astAt(v, cx);
217
- visited.push(v);
218
- if (isAgg !== undefined) {
219
- v.isMeasure = isAgg;
220
- }
221
- }
222
- else {
223
- this.contextError(cx, 'Expected field definition');
224
- }
225
- }
226
- return visited;
211
+ getFieldDefs(cxList, makeFieldDef) {
212
+ return cxList.map(cx => this.getFieldDef(cx, makeFieldDef));
227
213
  }
228
214
  getFieldExpr(cx) {
229
215
  const element = this.visit(cx);
@@ -397,25 +383,25 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
397
383
  const join = new ast.KeyJoin(joinAs, joinFrom, joinOn);
398
384
  return this.astAt(join, pcx);
399
385
  }
400
- visitFieldDef(pcx) {
386
+ getFieldDef(pcx, makeFieldDef) {
401
387
  const defCx = pcx.fieldExpr();
402
388
  const fieldName = this.getIdText(pcx.fieldNameDef());
403
389
  const valExpr = this.getFieldExpr(defCx);
404
- const def = new ast.FieldDeclaration(valExpr, fieldName, this.getSourceCode(defCx));
390
+ const def = new makeFieldDef(valExpr, fieldName, this.getSourceCode(defCx));
405
391
  return this.astAt(def, pcx);
406
392
  }
407
393
  visitDefExploreDimension(pcx) {
408
- const defs = this.getFieldDefs(pcx.dimensionDefList().dimensionDef(), false);
394
+ const defs = this.getFieldDefs(pcx.defList().fieldDef(), ast.DimensionFieldDeclaration);
409
395
  const stmt = new ast.Dimensions(defs);
410
396
  return this.astAt(stmt, pcx);
411
397
  }
412
398
  visitDefExploreMeasure(pcx) {
413
- const defs = this.getFieldDefs(pcx.measureDefList().measureDef(), true);
399
+ const defs = this.getFieldDefs(pcx.defList().fieldDef(), ast.MeasureFieldDeclaration);
414
400
  const stmt = new ast.Measures(defs);
415
401
  return this.astAt(stmt, pcx);
416
402
  }
417
403
  visitDeclareStatement(pcx) {
418
- const defs = this.getFieldDefs(pcx.fieldDef(), true);
404
+ const defs = this.getFieldDefs(pcx.defList().fieldDef(), ast.DeclareFieldDeclaration);
419
405
  const stmt = new ast.DeclareFields(defs);
420
406
  return this.astAt(stmt, pcx);
421
407
  }
@@ -461,7 +447,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
461
447
  visitFieldNameList(pcx) {
462
448
  const members = pcx
463
449
  .fieldName()
464
- .map(cx => new ast.FieldReference([this.getFieldName(cx)]));
450
+ .map(cx => new ast.AcceptExceptFieldReference([this.getFieldName(cx)]));
465
451
  return new ast.FieldReferences(members);
466
452
  }
467
453
  visitDefExploreEditField(pcx) {
@@ -495,17 +481,13 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
495
481
  }
496
482
  return new ast.QOPDesc(qProps);
497
483
  }
498
- visitFieldPath(pcx) {
484
+ getFieldPath(pcx, makeFieldRef) {
499
485
  const names = pcx.fieldName().map(nameCx => this.getFieldName(nameCx));
500
- return this.astAt(new ast.FieldReference(names), pcx);
501
- }
502
- visitQueryFieldDef(pcx) {
503
- const defCx = pcx.dimensionDef().fieldDef();
504
- const dim = this.visitFieldDef(defCx);
505
- return this.astAt(dim, defCx);
486
+ return this.astAt(new makeFieldRef(names), pcx);
506
487
  }
507
- visitQueryFieldRef(pcx) {
508
- return this.visitFieldPath(pcx.fieldPath());
488
+ getQueryFieldDef(pcx, makeFieldDef) {
489
+ const dim = this.getFieldDef(pcx, makeFieldDef);
490
+ return this.astAt(dim, pcx);
509
491
  }
510
492
  // visitQueryFieldNameless(
511
493
  // pcx: parse.QueryFieldNamelessContext
@@ -515,33 +497,60 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
515
497
  // noItem.reported = true;
516
498
  // return noItem;
517
499
  // }
518
- getQueryItems(pcx) {
519
- const itemList = pcx.queryFieldEntry().map(e => this.visit(e));
500
+ getQueryFieldEntry(ctx, makeFieldDef, makeFieldRef) {
501
+ const fieldPath = ctx.fieldPath();
502
+ if (fieldPath) {
503
+ return this.getFieldPath(fieldPath, makeFieldRef);
504
+ }
505
+ const def = ctx.fieldDef();
506
+ if (def) {
507
+ return this.getQueryFieldDef(def, makeFieldDef);
508
+ }
509
+ throw new Error('Expected query field entry to be a field reference or definition');
510
+ }
511
+ getQueryItems(pcx, makeFieldDef, makeFieldRef) {
512
+ const itemList = pcx
513
+ .queryFieldEntry()
514
+ .map(e => this.getQueryFieldEntry(e, makeFieldDef, makeFieldRef));
520
515
  return this.onlyQueryRefs(itemList);
521
516
  }
522
517
  visitAggregateStatement(pcx) {
523
- return new ast.Aggregate(this.getQueryItems(pcx.queryFieldList()));
518
+ return new ast.Aggregate(this.getQueryItems(pcx.queryFieldList(), ast.AggregateFieldDeclaration, ast.AggregateFieldReference));
524
519
  }
525
520
  visitGroupByStatement(pcx) {
526
- return new ast.GroupBy(this.getQueryItems(pcx.queryFieldList()));
521
+ return new ast.GroupBy(this.getQueryItems(pcx.queryFieldList(), ast.GroupByFieldDeclaration, ast.GroupByFieldReference));
527
522
  }
528
- visitFieldCollection(pcx) {
529
- const fields = [];
530
- for (const elCx of pcx.collectionMember()) {
531
- const el = this.visit(elCx);
532
- if (ast.isFieldCollectionMember(el)) {
533
- fields.push(el);
534
- }
535
- else {
536
- throw this.internalError(elCx, `${el.elementType} is not a query field`);
537
- }
523
+ visitCalculateStatement(pcx) {
524
+ return new ast.Calculate(this.getQueryItems(pcx.queryFieldList(), ast.CalculateFieldDeclaration, ast.CalculateFieldReference));
525
+ }
526
+ getFieldCollectionMember(pcx, makeFieldDef, makeFieldRef) {
527
+ const fieldDef = pcx.fieldDef();
528
+ if (fieldDef) {
529
+ return this.getFieldDef(fieldDef, makeFieldDef);
530
+ }
531
+ const fieldPath = pcx.fieldPath();
532
+ if (fieldPath) {
533
+ return this.getFieldPath(fieldPath, makeFieldRef);
534
+ }
535
+ const collectionWildcard = pcx.collectionWildCard();
536
+ if (collectionWildcard) {
537
+ return this.visitCollectionWildCard(collectionWildcard);
538
538
  }
539
+ throw this.internalError(pcx, 'Unexpected element in fieldCollectionMember');
540
+ }
541
+ // "FieldCollection" can only mean a project statement today
542
+ visitFieldCollection(pcx) {
543
+ const fields = pcx
544
+ .collectionMember()
545
+ .map(c => this.getFieldCollectionMember(c, ast.ProjectFieldDeclaration, ast.ProjectFieldReference));
539
546
  return this.astAt(new ast.ProjectStatement(fields), pcx);
540
547
  }
541
- visitWildMember(pcx) {
548
+ visitCollectionWildCard(pcx) {
542
549
  const nameCx = pcx.fieldPath();
543
550
  const stars = pcx.STAR() ? '*' : '**';
544
- const join = nameCx ? this.visitFieldPath(nameCx) : undefined;
551
+ const join = nameCx
552
+ ? this.getFieldPath(nameCx, ast.ProjectFieldReference)
553
+ : undefined;
545
554
  return new ast.WildcardFieldReference(join, stars);
546
555
  }
547
556
  visitIndexFields(pcx) {
@@ -551,7 +560,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
551
560
  if (!pathCx) {
552
561
  return new ast.WildcardFieldReference(undefined, '*');
553
562
  }
554
- const path = this.visitFieldPath(pathCx);
563
+ const path = this.getFieldPath(pathCx, ast.IndexFieldReference);
555
564
  if (!hasStar) {
556
565
  return this.astAt(path, pcx);
557
566
  }
@@ -772,7 +781,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
772
781
  }
773
782
  }
774
783
  visitExprFieldPath(pcx) {
775
- const idRef = new ast.ExprIdReference(this.visitFieldPath(pcx.fieldPath()));
784
+ const idRef = new ast.ExprIdReference(this.getFieldPath(pcx.fieldPath(), ast.ExpressionFieldReference));
776
785
  return this.astAt(idRef, pcx);
777
786
  }
778
787
  visitExprNULL(_pcx) {
@@ -811,7 +820,9 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
811
820
  }
812
821
  visitExprAggregate(pcx) {
813
822
  const pathCx = pcx.fieldPath();
814
- const path = pathCx ? this.visitFieldPath(pathCx) : undefined;
823
+ const path = pathCx
824
+ ? this.getFieldPath(pathCx, ast.ExpressionFieldReference)
825
+ : undefined;
815
826
  const source = pathCx && path ? this.astAt(path, pathCx) : undefined;
816
827
  const exprDef = pcx.fieldExpr();
817
828
  if (pcx.aggregate().COUNT()) {
@@ -891,9 +902,37 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
891
902
  const units = this.visitTimeframe(pcx.timeframe());
892
903
  return new ast.ForRange(begin, duration, units);
893
904
  }
905
+ visitExprAggFunc(pcx) {
906
+ const argsCx = pcx.argumentList();
907
+ const args = argsCx ? this.allFieldExpressions(argsCx.fieldExpr()) : [];
908
+ const idCx = pcx.id();
909
+ const fn = this.getIdText(idCx);
910
+ const pathCx = pcx.fieldPath();
911
+ const path = pathCx
912
+ ? this.getFieldPath(pathCx, ast.ExpressionFieldReference)
913
+ : undefined;
914
+ const source = pathCx && path ? this.astAt(path, pathCx) : undefined;
915
+ if (ast.ExprTimeExtract.extractor(fn)) {
916
+ return this.astAt(new ast.ExprTimeExtract(fn, args), pcx);
917
+ }
918
+ return this.astAt(new ast.ExprFunc(fn, args, false, undefined, source), pcx);
919
+ }
894
920
  visitExprFunc(pcx) {
921
+ var _a;
895
922
  const argsCx = pcx.argumentList();
896
923
  const args = argsCx ? this.allFieldExpressions(argsCx.fieldExpr()) : [];
924
+ const isRaw = pcx.EXCLAM() !== undefined;
925
+ const rawRawType = (_a = pcx.malloyType()) === null || _a === void 0 ? void 0 : _a.text;
926
+ let rawType = undefined;
927
+ if (rawRawType) {
928
+ if (ast.isCastType(rawRawType)) {
929
+ rawType = rawRawType;
930
+ }
931
+ else {
932
+ this.contextError(pcx, `'#' assertion for unknown type '${rawRawType}'`);
933
+ rawType = undefined;
934
+ }
935
+ }
897
936
  const idCx = pcx.id();
898
937
  const dCx = pcx.timeframe();
899
938
  let fn;
@@ -910,7 +949,7 @@ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
910
949
  if (ast.ExprTimeExtract.extractor(fn)) {
911
950
  return this.astAt(new ast.ExprTimeExtract(fn, args), pcx);
912
951
  }
913
- return this.astAt(new ast.ExprFunc(fn, args), pcx);
952
+ return this.astAt(new ast.ExprFunc(fn, args, isRaw, rawType), pcx);
914
953
  }
915
954
  visitExprDuration(pcx) {
916
955
  return new ast.ExprDuration(this.getFieldExpr(pcx.fieldExpr()), this.visitTimeframe(pcx.timeframe()).text);
@@ -118,10 +118,13 @@ class DocumentSymbolWalker {
118
118
  parent.children.push(symbol);
119
119
  }
120
120
  }
121
- enterQueryFieldRef(pcx) {
121
+ enterQueryFieldEntry(pcx) {
122
+ const fieldRef = pcx.fieldPath();
123
+ if (fieldRef === undefined)
124
+ return;
122
125
  const symbol = {
123
126
  range: this.translator.rangeFromContext(pcx),
124
- name: pcx.fieldPath().text,
127
+ name: fieldRef.text,
125
128
  type: 'field',
126
129
  children: [],
127
130
  };