@malloydata/malloy 0.0.22-dev230207144036 → 0.0.22-dev230207180844

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 (359) hide show
  1. package/dist/connection_utils.d.ts +1 -0
  2. package/dist/connection_utils.js +66 -0
  3. package/dist/dialect/dialect.d.ts +66 -0
  4. package/dist/dialect/dialect.js +85 -0
  5. package/dist/dialect/dialect_map.d.ts +3 -0
  6. package/dist/dialect/dialect_map.js +45 -0
  7. package/dist/dialect/duckdb.d.ts +52 -0
  8. package/dist/dialect/duckdb.js +364 -0
  9. package/dist/dialect/index.d.ts +6 -0
  10. package/dist/dialect/index.js +37 -0
  11. package/dist/dialect/postgres.d.ts +52 -0
  12. package/dist/dialect/postgres.js +330 -0
  13. package/dist/dialect/standardsql.d.ts +49 -0
  14. package/dist/dialect/standardsql.js +381 -0
  15. package/dist/index.d.ts +10 -0
  16. package/dist/index.js +59 -0
  17. package/dist/lang/ast/ast-utils.d.ts +10 -0
  18. package/dist/lang/ast/ast-utils.js +42 -0
  19. package/dist/lang/ast/elements/define-query.d.ts +14 -0
  20. package/dist/lang/ast/elements/define-query.js +56 -0
  21. package/dist/lang/ast/elements/define-source.d.ts +17 -0
  22. package/dist/lang/ast/elements/define-source.js +79 -0
  23. package/dist/lang/ast/elements/import-statement.d.ts +9 -0
  24. package/dist/lang/ast/elements/import-statement.js +78 -0
  25. package/dist/lang/ast/elements/pipeline-desc.d.ts +30 -0
  26. package/dist/lang/ast/elements/pipeline-desc.js +102 -0
  27. package/dist/lang/ast/elements/refined-source.d.ts +15 -0
  28. package/dist/lang/ast/elements/refined-source.js +121 -0
  29. package/dist/lang/ast/elements/source.d.ts +12 -0
  30. package/dist/lang/ast/elements/source.js +53 -0
  31. package/dist/lang/ast/error-factory.d.ts +9 -0
  32. package/dist/lang/ast/error-factory.js +61 -0
  33. package/dist/lang/ast/executors/index-executor.d.ts +18 -0
  34. package/dist/lang/ast/executors/index-executor.js +96 -0
  35. package/dist/lang/ast/executors/project-executor.d.ts +10 -0
  36. package/dist/lang/ast/executors/project-executor.js +68 -0
  37. package/dist/lang/ast/executors/reduce-executor.d.ts +21 -0
  38. package/dist/lang/ast/executors/reduce-executor.js +149 -0
  39. package/dist/lang/ast/expressions/apply.d.ts +8 -0
  40. package/dist/lang/ast/expressions/apply.js +37 -0
  41. package/dist/lang/ast/expressions/binary-boolean.d.ts +12 -0
  42. package/dist/lang/ast/expressions/binary-boolean.js +54 -0
  43. package/dist/lang/ast/expressions/binary-numeric.d.ts +11 -0
  44. package/dist/lang/ast/expressions/binary-numeric.js +42 -0
  45. package/dist/lang/ast/expressions/boolean.d.ts +8 -0
  46. package/dist/lang/ast/expressions/boolean.js +39 -0
  47. package/dist/lang/ast/expressions/constant-sub-expression.d.ts +16 -0
  48. package/dist/lang/ast/expressions/constant-sub-expression.js +98 -0
  49. package/dist/lang/ast/expressions/expr-add-sub.d.ts +4 -0
  50. package/dist/lang/ast/expressions/expr-add-sub.js +34 -0
  51. package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +15 -0
  52. package/dist/lang/ast/expressions/expr-aggregate-function.js +99 -0
  53. package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +11 -0
  54. package/dist/lang/ast/expressions/expr-alternation-tree.js +54 -0
  55. package/dist/lang/ast/expressions/expr-asymmetric.d.ts +10 -0
  56. package/dist/lang/ast/expressions/expr-asymmetric.js +27 -0
  57. package/dist/lang/ast/expressions/expr-avg.d.ts +6 -0
  58. package/dist/lang/ast/expressions/expr-avg.js +34 -0
  59. package/dist/lang/ast/expressions/expr-cast.d.ts +13 -0
  60. package/dist/lang/ast/expressions/expr-cast.js +29 -0
  61. package/dist/lang/ast/expressions/expr-compare.d.ts +10 -0
  62. package/dist/lang/ast/expressions/expr-compare.js +58 -0
  63. package/dist/lang/ast/expressions/expr-count-distinct.d.ts +6 -0
  64. package/dist/lang/ast/expressions/expr-count-distinct.js +35 -0
  65. package/dist/lang/ast/expressions/expr-count.d.ts +11 -0
  66. package/dist/lang/ast/expressions/expr-count.js +57 -0
  67. package/dist/lang/ast/expressions/expr-filter.d.ts +12 -0
  68. package/dist/lang/ast/expressions/expr-filter.js +69 -0
  69. package/dist/lang/ast/expressions/expr-func.d.ts +10 -0
  70. package/dist/lang/ast/expressions/expr-func.js +63 -0
  71. package/dist/lang/ast/expressions/expr-granular-time.d.ts +24 -0
  72. package/dist/lang/ast/expressions/expr-granular-time.js +117 -0
  73. package/dist/lang/ast/expressions/expr-id-reference.d.ts +12 -0
  74. package/dist/lang/ast/expressions/expr-id-reference.js +75 -0
  75. package/dist/lang/ast/expressions/expr-logical-op.d.ts +9 -0
  76. package/dist/lang/ast/expressions/expr-logical-op.js +36 -0
  77. package/dist/lang/ast/expressions/expr-max.d.ts +9 -0
  78. package/dist/lang/ast/expressions/expr-max.js +16 -0
  79. package/dist/lang/ast/expressions/expr-min.d.ts +9 -0
  80. package/dist/lang/ast/expressions/expr-min.js +16 -0
  81. package/dist/lang/ast/expressions/expr-minus.d.ts +9 -0
  82. package/dist/lang/ast/expressions/expr-minus.js +48 -0
  83. package/dist/lang/ast/expressions/expr-mul-div.d.ts +4 -0
  84. package/dist/lang/ast/expressions/expr-mul-div.js +34 -0
  85. package/dist/lang/ast/expressions/expr-not.d.ts +10 -0
  86. package/dist/lang/ast/expressions/expr-not.js +49 -0
  87. package/dist/lang/ast/expressions/expr-now.d.ts +7 -0
  88. package/dist/lang/ast/expressions/expr-now.js +46 -0
  89. package/dist/lang/ast/expressions/expr-null.d.ts +6 -0
  90. package/dist/lang/ast/expressions/expr-null.js +41 -0
  91. package/dist/lang/ast/expressions/expr-number.d.ts +10 -0
  92. package/dist/lang/ast/expressions/expr-number.js +42 -0
  93. package/dist/lang/ast/expressions/expr-parens.d.ts +10 -0
  94. package/dist/lang/ast/expressions/expr-parens.js +42 -0
  95. package/dist/lang/ast/expressions/expr-regex.d.ts +8 -0
  96. package/dist/lang/ast/expressions/expr-regex.js +42 -0
  97. package/dist/lang/ast/expressions/expr-string.d.ts +9 -0
  98. package/dist/lang/ast/expressions/expr-string.js +50 -0
  99. package/dist/lang/ast/expressions/expr-sum.d.ts +6 -0
  100. package/dist/lang/ast/expressions/expr-sum.js +12 -0
  101. package/dist/lang/ast/expressions/expr-time-extract.d.ts +13 -0
  102. package/dist/lang/ast/expressions/expr-time-extract.js +117 -0
  103. package/dist/lang/ast/expressions/expr-time.d.ts +11 -0
  104. package/dist/lang/ast/expressions/expr-time.js +62 -0
  105. package/dist/lang/ast/expressions/expr-ungroup.d.ts +14 -0
  106. package/dist/lang/ast/expressions/expr-ungroup.js +83 -0
  107. package/dist/lang/ast/expressions/for-range.d.ts +19 -0
  108. package/dist/lang/ast/expressions/for-range.js +101 -0
  109. package/dist/lang/ast/expressions/granular-literal.d.ts +20 -0
  110. package/dist/lang/ast/expressions/granular-literal.js +148 -0
  111. package/dist/lang/ast/expressions/partial-compare.d.ts +14 -0
  112. package/dist/lang/ast/expressions/partial-compare.js +50 -0
  113. package/dist/lang/ast/expressions/pick-when.d.ts +19 -0
  114. package/dist/lang/ast/expressions/pick-when.js +156 -0
  115. package/dist/lang/ast/expressions/range.d.ts +12 -0
  116. package/dist/lang/ast/expressions/range.js +80 -0
  117. package/dist/lang/ast/expressions/time-frame.d.ts +7 -0
  118. package/dist/lang/ast/expressions/time-frame.js +40 -0
  119. package/dist/lang/ast/expressions/top-by.d.ts +10 -0
  120. package/dist/lang/ast/expressions/top-by.js +51 -0
  121. package/dist/lang/ast/expressions/unary.d.ts +5 -0
  122. package/dist/lang/ast/expressions/unary.js +34 -0
  123. package/dist/lang/ast/expressions/utils.d.ts +12 -0
  124. package/dist/lang/ast/expressions/utils.js +87 -0
  125. package/dist/lang/ast/field-space/column-space-field.d.ts +9 -0
  126. package/dist/lang/ast/field-space/column-space-field.js +40 -0
  127. package/dist/lang/ast/field-space/dynamic-space.d.ts +22 -0
  128. package/dist/lang/ast/field-space/dynamic-space.js +140 -0
  129. package/dist/lang/ast/field-space/field-definition-value.d.ts +16 -0
  130. package/dist/lang/ast/field-space/field-definition-value.js +55 -0
  131. package/dist/lang/ast/field-space/index-field-space.d.ts +10 -0
  132. package/dist/lang/ast/field-space/index-field-space.js +57 -0
  133. package/dist/lang/ast/field-space/join-space-field.d.ts +8 -0
  134. package/dist/lang/ast/field-space/join-space-field.js +35 -0
  135. package/dist/lang/ast/field-space/project-field-space.d.ts +6 -0
  136. package/dist/lang/ast/field-space/project-field-space.js +51 -0
  137. package/dist/lang/ast/field-space/query-field-struct.d.ts +10 -0
  138. package/dist/lang/ast/field-space/query-field-struct.js +46 -0
  139. package/dist/lang/ast/field-space/query-space-field.d.ts +11 -0
  140. package/dist/lang/ast/field-space/query-space-field.js +37 -0
  141. package/dist/lang/ast/field-space/query-spaces.d.ts +50 -0
  142. package/dist/lang/ast/field-space/query-spaces.js +233 -0
  143. package/dist/lang/ast/field-space/reference-field.d.ts +11 -0
  144. package/dist/lang/ast/field-space/reference-field.js +45 -0
  145. package/dist/lang/ast/field-space/refined-space.d.ts +13 -0
  146. package/dist/lang/ast/field-space/refined-space.js +100 -0
  147. package/dist/lang/ast/field-space/rename-space-field.d.ts +11 -0
  148. package/dist/lang/ast/field-space/rename-space-field.js +50 -0
  149. package/dist/lang/ast/field-space/static-space.d.ts +29 -0
  150. package/dist/lang/ast/field-space/static-space.js +156 -0
  151. package/dist/lang/ast/field-space/struct-space-field-base.d.ts +11 -0
  152. package/dist/lang/ast/field-space/struct-space-field-base.js +40 -0
  153. package/dist/lang/ast/field-space/wild-space-field.d.ts +10 -0
  154. package/dist/lang/ast/field-space/wild-space-field.js +40 -0
  155. package/dist/lang/ast/fragtype-utils.d.ts +39 -0
  156. package/dist/lang/ast/fragtype-utils.js +100 -0
  157. package/dist/lang/ast/index.d.ts +90 -0
  158. package/dist/lang/ast/index.js +129 -0
  159. package/dist/lang/ast/parameters/constant-parameter.d.ts +8 -0
  160. package/dist/lang/ast/parameters/constant-parameter.js +54 -0
  161. package/dist/lang/ast/parameters/has-parameter.d.ts +19 -0
  162. package/dist/lang/ast/parameters/has-parameter.js +64 -0
  163. package/dist/lang/ast/query-elements/anonymous-query.d.ts +9 -0
  164. package/dist/lang/ast/query-elements/anonymous-query.js +41 -0
  165. package/dist/lang/ast/query-elements/existing-query.d.ts +11 -0
  166. package/dist/lang/ast/query-elements/existing-query.js +79 -0
  167. package/dist/lang/ast/query-elements/full-query.d.ts +10 -0
  168. package/dist/lang/ast/query-elements/full-query.js +85 -0
  169. package/dist/lang/ast/query-elements/query-head-struct.d.ts +9 -0
  170. package/dist/lang/ast/query-elements/query-head-struct.js +48 -0
  171. package/dist/lang/ast/query-items/field-declaration.d.ts +31 -0
  172. package/dist/lang/ast/query-items/field-declaration.js +137 -0
  173. package/dist/lang/ast/query-items/field-references.d.ts +25 -0
  174. package/dist/lang/ast/query-items/field-references.js +80 -0
  175. package/dist/lang/ast/query-properties/aggregate.d.ts +5 -0
  176. package/dist/lang/ast/query-properties/aggregate.js +39 -0
  177. package/dist/lang/ast/query-properties/declare-fields.d.ts +5 -0
  178. package/dist/lang/ast/query-properties/declare-fields.js +33 -0
  179. package/dist/lang/ast/query-properties/dimmensions.d.ts +5 -0
  180. package/dist/lang/ast/query-properties/dimmensions.js +36 -0
  181. package/dist/lang/ast/query-properties/filters.d.ts +18 -0
  182. package/dist/lang/ast/query-properties/filters.js +89 -0
  183. package/dist/lang/ast/query-properties/group-by.d.ts +5 -0
  184. package/dist/lang/ast/query-properties/group-by.js +39 -0
  185. package/dist/lang/ast/query-properties/indexing.d.ts +10 -0
  186. package/dist/lang/ast/query-properties/indexing.js +39 -0
  187. package/dist/lang/ast/query-properties/joins.d.ts +36 -0
  188. package/dist/lang/ast/query-properties/joins.js +143 -0
  189. package/dist/lang/ast/query-properties/limit.d.ts +6 -0
  190. package/dist/lang/ast/query-properties/limit.js +35 -0
  191. package/dist/lang/ast/query-properties/measures.d.ts +5 -0
  192. package/dist/lang/ast/query-properties/measures.js +36 -0
  193. package/dist/lang/ast/query-properties/nest-reference.d.ts +7 -0
  194. package/dist/lang/ast/query-properties/nest-reference.js +35 -0
  195. package/dist/lang/ast/query-properties/nest.d.ts +31 -0
  196. package/dist/lang/ast/query-properties/nest.js +133 -0
  197. package/dist/lang/ast/query-properties/nests.d.ts +5 -0
  198. package/dist/lang/ast/query-properties/nests.js +33 -0
  199. package/dist/lang/ast/query-properties/ordering.d.ts +15 -0
  200. package/dist/lang/ast/query-properties/ordering.js +66 -0
  201. package/dist/lang/ast/query-properties/project-statement.d.ts +5 -0
  202. package/dist/lang/ast/query-properties/project-statement.js +33 -0
  203. package/dist/lang/ast/query-properties/qop-desc.d.ts +17 -0
  204. package/dist/lang/ast/query-properties/qop-desc.js +124 -0
  205. package/dist/lang/ast/query-properties/sampling.d.ts +8 -0
  206. package/dist/lang/ast/query-properties/sampling.js +38 -0
  207. package/dist/lang/ast/query-properties/top.d.ts +13 -0
  208. package/dist/lang/ast/query-properties/top.js +60 -0
  209. package/dist/lang/ast/source-properties/field-list-edit.d.ts +8 -0
  210. package/dist/lang/ast/source-properties/field-list-edit.js +36 -0
  211. package/dist/lang/ast/source-properties/primary-key.d.ts +7 -0
  212. package/dist/lang/ast/source-properties/primary-key.js +35 -0
  213. package/dist/lang/ast/source-properties/renames.d.ts +11 -0
  214. package/dist/lang/ast/source-properties/renames.js +43 -0
  215. package/dist/lang/ast/source-properties/turtles.d.ts +5 -0
  216. package/dist/lang/ast/source-properties/turtles.js +33 -0
  217. package/dist/lang/ast/sources/named-source.d.ts +19 -0
  218. package/dist/lang/ast/sources/named-source.js +147 -0
  219. package/dist/lang/ast/sources/query-source.d.ts +9 -0
  220. package/dist/lang/ast/sources/query-source.js +41 -0
  221. package/dist/lang/ast/sources/sql-source.d.ts +7 -0
  222. package/dist/lang/ast/sources/sql-source.js +54 -0
  223. package/dist/lang/ast/sources/table-source.d.ts +8 -0
  224. package/dist/lang/ast/sources/table-source.js +60 -0
  225. package/dist/lang/ast/space-seed.d.ts +16 -0
  226. package/dist/lang/ast/space-seed.js +59 -0
  227. package/dist/lang/ast/sql-elements/sql-statement.d.ts +19 -0
  228. package/dist/lang/ast/sql-elements/sql-statement.js +80 -0
  229. package/dist/lang/ast/sql-elements/sql-string.d.ts +12 -0
  230. package/dist/lang/ast/sql-elements/sql-string.js +60 -0
  231. package/dist/lang/ast/struct-utils.d.ts +4 -0
  232. package/dist/lang/ast/struct-utils.js +48 -0
  233. package/dist/lang/ast/time-utils.d.ts +12 -0
  234. package/dist/lang/ast/time-utils.js +140 -0
  235. package/dist/lang/ast/types/comparison.d.ts +11 -0
  236. package/dist/lang/ast/types/comparison.js +41 -0
  237. package/dist/lang/ast/types/document-compile-result.d.ts +8 -0
  238. package/dist/lang/ast/types/document-compile-result.js +25 -0
  239. package/dist/lang/ast/types/equality.d.ts +7 -0
  240. package/dist/lang/ast/types/equality.js +37 -0
  241. package/dist/lang/ast/types/executor.d.ts +9 -0
  242. package/dist/lang/ast/types/executor.js +25 -0
  243. package/dist/lang/ast/types/explore-desc.d.ts +5 -0
  244. package/dist/lang/ast/types/explore-desc.js +33 -0
  245. package/dist/lang/ast/types/explore-field.d.ts +5 -0
  246. package/dist/lang/ast/types/explore-field.js +32 -0
  247. package/dist/lang/ast/types/expr-result.d.ts +5 -0
  248. package/dist/lang/ast/types/expr-result.js +25 -0
  249. package/dist/lang/ast/types/expr-value.d.ts +3 -0
  250. package/dist/lang/ast/types/expr-value.js +25 -0
  251. package/dist/lang/ast/types/expression-def.d.ts +69 -0
  252. package/dist/lang/ast/types/expression-def.js +346 -0
  253. package/dist/lang/ast/types/field-collection-member.d.ts +5 -0
  254. package/dist/lang/ast/types/field-collection-member.js +34 -0
  255. package/dist/lang/ast/types/field-decl.d.ts +7 -0
  256. package/dist/lang/ast/types/field-decl.js +37 -0
  257. package/dist/lang/ast/types/field-space.d.ts +24 -0
  258. package/dist/lang/ast/types/field-space.js +44 -0
  259. package/dist/lang/ast/types/granular-result.d.ts +7 -0
  260. package/dist/lang/ast/types/granular-result.js +11 -0
  261. package/dist/lang/ast/types/lookup-result.d.ts +10 -0
  262. package/dist/lang/ast/types/lookup-result.js +25 -0
  263. package/dist/lang/ast/types/malloy-element.d.ts +106 -0
  264. package/dist/lang/ast/types/malloy-element.js +398 -0
  265. package/dist/lang/ast/types/model-entry.d.ts +6 -0
  266. package/dist/lang/ast/types/model-entry.js +25 -0
  267. package/dist/lang/ast/types/name-space.d.ts +5 -0
  268. package/dist/lang/ast/types/name-space.js +25 -0
  269. package/dist/lang/ast/types/nested-query.d.ts +3 -0
  270. package/dist/lang/ast/types/nested-query.js +25 -0
  271. package/dist/lang/ast/types/op-desc.d.ts +6 -0
  272. package/dist/lang/ast/types/op-desc.js +25 -0
  273. package/dist/lang/ast/types/query-comp.d.ts +5 -0
  274. package/dist/lang/ast/types/query-comp.js +25 -0
  275. package/dist/lang/ast/types/query-element.d.ts +5 -0
  276. package/dist/lang/ast/types/query-element.js +32 -0
  277. package/dist/lang/ast/types/query-item.d.ts +5 -0
  278. package/dist/lang/ast/types/query-item.js +25 -0
  279. package/dist/lang/ast/types/query-property.d.ts +17 -0
  280. package/dist/lang/ast/types/query-property.js +55 -0
  281. package/dist/lang/ast/types/source-property.d.ts +10 -0
  282. package/dist/lang/ast/types/source-property.js +43 -0
  283. package/dist/lang/ast/types/space-entry.d.ts +5 -0
  284. package/dist/lang/ast/types/space-entry.js +29 -0
  285. package/dist/lang/ast/types/space-field.d.ts +10 -0
  286. package/dist/lang/ast/types/space-field.js +48 -0
  287. package/dist/lang/ast/types/space-param.d.ts +20 -0
  288. package/dist/lang/ast/types/space-param.js +61 -0
  289. package/dist/lang/ast/types/time-result.d.ts +6 -0
  290. package/dist/lang/ast/types/time-result.js +25 -0
  291. package/dist/lang/ast/types/turtle-headed-pipe.d.ts +7 -0
  292. package/dist/lang/ast/types/turtle-headed-pipe.js +37 -0
  293. package/dist/lang/ast/types/type-desc.d.ts +7 -0
  294. package/dist/lang/ast/types/type-desc.js +25 -0
  295. package/dist/lang/field-utils.d.ts +5 -0
  296. package/dist/lang/field-utils.js +43 -0
  297. package/dist/lang/index.d.ts +10 -0
  298. package/dist/lang/index.js +32 -0
  299. package/dist/lang/lib/Malloy/MalloyLexer.d.ts +165 -0
  300. package/dist/lang/lib/Malloy/MalloyLexer.js +1232 -0
  301. package/dist/lang/lib/Malloy/MalloyParser.d.ts +1947 -0
  302. package/dist/lang/lib/Malloy/MalloyParser.js +11909 -0
  303. package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +2022 -0
  304. package/dist/lang/lib/Malloy/MalloyParserListener.js +4 -0
  305. package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +1274 -0
  306. package/dist/lang/lib/Malloy/MalloyParserVisitor.js +4 -0
  307. package/dist/lang/malloy-to-ast.d.ts +155 -0
  308. package/dist/lang/malloy-to-ast.js +990 -0
  309. package/dist/lang/parse-error-handler.d.ts +9 -0
  310. package/dist/lang/parse-error-handler.js +44 -0
  311. package/dist/lang/parse-log.d.ts +27 -0
  312. package/dist/lang/parse-log.js +51 -0
  313. package/dist/lang/parse-malloy.d.ts +182 -0
  314. package/dist/lang/parse-malloy.js +728 -0
  315. package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +10 -0
  316. package/dist/lang/parse-tree-walkers/document-completion-walker.js +148 -0
  317. package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +9 -0
  318. package/dist/lang/parse-tree-walkers/document-help-context-walker.js +107 -0
  319. package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +83 -0
  320. package/dist/lang/parse-tree-walkers/document-highlight-walker.js +385 -0
  321. package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +11 -0
  322. package/dist/lang/parse-tree-walkers/document-symbol-walker.js +182 -0
  323. package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +34 -0
  324. package/dist/lang/parse-tree-walkers/explore-query-walker.js +74 -0
  325. package/dist/lang/parse-tree-walkers/find-external-references.d.ts +11 -0
  326. package/dist/lang/parse-tree-walkers/find-external-references.js +61 -0
  327. package/dist/lang/reference-list.d.ts +10 -0
  328. package/dist/lang/reference-list.js +90 -0
  329. package/dist/lang/test/document-help-context-walker.spec.d.ts +1 -0
  330. package/dist/lang/test/document-help-context-walker.spec.js +55 -0
  331. package/dist/lang/test/document-symbol-walker.spec.d.ts +1 -0
  332. package/dist/lang/test/document-symbol-walker.spec.js +110 -0
  333. package/dist/lang/test/field-symbols.spec.d.ts +1 -0
  334. package/dist/lang/test/field-symbols.spec.js +184 -0
  335. package/dist/lang/test/parse.spec.d.ts +14 -0
  336. package/dist/lang/test/parse.spec.js +2135 -0
  337. package/dist/lang/test/test-translator.d.ts +41 -0
  338. package/dist/lang/test/test-translator.js +344 -0
  339. package/dist/lang/translate-response.d.ts +59 -0
  340. package/dist/lang/translate-response.js +30 -0
  341. package/dist/lang/zone.d.ts +57 -0
  342. package/dist/lang/zone.js +107 -0
  343. package/dist/malloy.d.ts +1146 -0
  344. package/dist/malloy.js +2413 -0
  345. package/dist/model/index.d.ts +2 -0
  346. package/dist/model/index.js +45 -0
  347. package/dist/model/malloy_query.d.ts +351 -0
  348. package/dist/model/malloy_query.js +3174 -0
  349. package/dist/model/malloy_types.d.ts +551 -0
  350. package/dist/model/malloy_types.js +378 -0
  351. package/dist/model/sql_block.d.ts +7 -0
  352. package/dist/model/sql_block.js +56 -0
  353. package/dist/model/utils.d.ts +22 -0
  354. package/dist/model/utils.js +102 -0
  355. package/dist/run_sql_options.d.ts +3 -0
  356. package/dist/run_sql_options.js +25 -0
  357. package/dist/runtime_types.d.ts +105 -0
  358. package/dist/runtime_types.js +25 -0
  359. package/package.json +2 -2
@@ -0,0 +1,990 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ var desc = Object.getOwnPropertyDescriptor(m, k);
27
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
28
+ desc = { enumerable: true, get: function() { return m[k]; } };
29
+ }
30
+ Object.defineProperty(o, k2, desc);
31
+ }) : (function(o, m, k, k2) {
32
+ if (k2 === undefined) k2 = k;
33
+ o[k2] = m[k];
34
+ }));
35
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
36
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
37
+ }) : function(o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar = (this && this.__importStar) || function (mod) {
41
+ if (mod && mod.__esModule) return mod;
42
+ var result = {};
43
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
44
+ __setModuleDefault(result, mod);
45
+ return result;
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.MalloyToAST = void 0;
49
+ const AbstractParseTreeVisitor_1 = require("antlr4ts/tree/AbstractParseTreeVisitor");
50
+ const ast = __importStar(require("./ast"));
51
+ const Interval_1 = require("antlr4ts/misc/Interval");
52
+ /**
53
+ * ANTLR visitor pattern parse tree traversal. Generates a Malloy
54
+ * AST from an ANTLR parse tree.
55
+ */
56
+ class MalloyToAST extends AbstractParseTreeVisitor_1.AbstractParseTreeVisitor {
57
+ constructor(parse, msgLog) {
58
+ super();
59
+ this.parse = parse;
60
+ this.msgLog = msgLog;
61
+ }
62
+ /**
63
+ * Mostly used to flag a case where the grammar and the type system are
64
+ * no longer in sync. A visitor was written based on a grammar which
65
+ * apparently has changed and now an unexpected element type has appeared.
66
+ * This is a non recoverable error, since the parser and the grammar
67
+ * are not compatible.
68
+ * @returns an error object to throw.
69
+ */
70
+ internalError(cx, msg) {
71
+ const tmsg = `Internal Translator Error: ${msg}`;
72
+ this.contextError(cx, tmsg);
73
+ return new Error(tmsg);
74
+ }
75
+ /**
76
+ * Log an error message relative to an AST node
77
+ */
78
+ astError(el, str, sev = "error") {
79
+ this.msgLog.log({ message: str, at: el.location, severity: sev });
80
+ }
81
+ /**
82
+ * Log an error message relative to a parse node
83
+ */
84
+ contextError(cx, msg, sev = "error") {
85
+ this.msgLog.log({
86
+ message: msg,
87
+ at: {
88
+ url: this.parse.subTranslator.sourceURL,
89
+ range: this.parse.subTranslator.rangeFromContext(cx),
90
+ },
91
+ severity: sev,
92
+ });
93
+ }
94
+ onlyExploreProperties(els) {
95
+ const eps = [];
96
+ for (const el of els) {
97
+ if (ast.isSourceProperty(el)) {
98
+ eps.push(el);
99
+ }
100
+ else {
101
+ this.astError(el, `Expected explore property, not '${el.elementType}'`);
102
+ }
103
+ }
104
+ return eps;
105
+ }
106
+ onlyJoins(els) {
107
+ const eps = [];
108
+ for (const el of els) {
109
+ if (el instanceof ast.Join) {
110
+ eps.push(el);
111
+ }
112
+ else {
113
+ this.astError(el, `Expected explore property, not '${el.elementType}'`);
114
+ }
115
+ }
116
+ return eps;
117
+ }
118
+ onlyDocStatements(els) {
119
+ const eps = [];
120
+ for (const el of els) {
121
+ if (ast.isDocStatement(el)) {
122
+ eps.push(el);
123
+ }
124
+ else {
125
+ this.astError(el, `Expected statement, not '${el.elementType}'`);
126
+ }
127
+ }
128
+ return eps;
129
+ }
130
+ onlyNestedQueries(els) {
131
+ const eps = [];
132
+ for (const el of els) {
133
+ if (ast.isNestedQuery(el)) {
134
+ eps.push(el);
135
+ }
136
+ else {
137
+ this.astError(el, `Expected query, not '${el.elementType}'`);
138
+ }
139
+ }
140
+ return eps;
141
+ }
142
+ onlyQueryRefs(els) {
143
+ const eps = [];
144
+ for (const el of els) {
145
+ if (el instanceof ast.FieldReference ||
146
+ el instanceof ast.FieldDeclaration) {
147
+ eps.push(el);
148
+ }
149
+ else {
150
+ const reported = el instanceof ast.Unimplemented && el.reported;
151
+ if (!reported) {
152
+ this.astError(el, `Expected query field, not '${el.elementType}'`);
153
+ }
154
+ }
155
+ }
156
+ return eps;
157
+ }
158
+ getNumber(term) {
159
+ return Number.parseInt(term.text);
160
+ }
161
+ optionalString(fromTerm) {
162
+ if (fromTerm) {
163
+ return this.stripQuotes(fromTerm.text);
164
+ }
165
+ return undefined;
166
+ }
167
+ getIdText(fromTerm) {
168
+ return this.stripQuotes(fromTerm.text);
169
+ }
170
+ getFieldName(cx) {
171
+ return this.astAt(new ast.FieldName(this.getIdText(cx)), cx);
172
+ }
173
+ getModelEntryName(cx) {
174
+ return this.astAt(new ast.ModelEntryReference(this.getIdText(cx)), cx);
175
+ }
176
+ stripQuotes(s) {
177
+ if (s[0] === "`" || s[0] === "'" || s[0] === '"') {
178
+ if (s[0] === s[s.length - 1]) {
179
+ return s.slice(1, -1);
180
+ }
181
+ }
182
+ return s;
183
+ }
184
+ optionalText(idCx) {
185
+ if (idCx) {
186
+ return this.getIdText(idCx);
187
+ }
188
+ return undefined;
189
+ }
190
+ defaultResult() {
191
+ return new ast.Unimplemented();
192
+ }
193
+ astAt(el, cx) {
194
+ el.location = {
195
+ url: this.parse.subTranslator.sourceURL,
196
+ range: this.parse.subTranslator.rangeFromContext(cx),
197
+ };
198
+ return el;
199
+ }
200
+ getSourceCode(cx) {
201
+ const from = cx.start.startIndex;
202
+ const lastToken = cx.stop || cx.start;
203
+ const sourceRange = new Interval_1.Interval(from, lastToken.stopIndex);
204
+ return this.parse.sourceStream.getText(sourceRange);
205
+ }
206
+ getFilterElement(cx) {
207
+ const expr = this.getFieldExpr(cx);
208
+ const fel = new ast.FilterElement(expr, this.getSourceCode(cx));
209
+ return this.astAt(fel, cx);
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;
227
+ }
228
+ getFieldExpr(cx) {
229
+ const element = this.visit(cx);
230
+ if (element instanceof ast.ExpressionDef) {
231
+ return this.astAt(element, cx);
232
+ }
233
+ throw this.internalError(cx, `expression node unknown type '${element.elementType}'`);
234
+ }
235
+ getSegments(segments) {
236
+ return segments.map((cx) => this.visitQueryProperties(cx.queryProperties()));
237
+ }
238
+ getFilterShortcut(cx) {
239
+ const el = this.getFilterElement(cx.fieldExpr());
240
+ return new ast.Filter([el]);
241
+ }
242
+ getExploreSource(pcx) {
243
+ const element = this.visit(pcx);
244
+ if (element instanceof ast.Source) {
245
+ return element;
246
+ }
247
+ throw this.internalError(pcx, `'${element.elementType}': illegal explore source`);
248
+ }
249
+ makeSqlString(pcx, sqlStr) {
250
+ var _a;
251
+ for (const part of pcx.sqlInterpolation()) {
252
+ const upToOpen = part.OPEN_CODE().text;
253
+ if (upToOpen.length > 2) {
254
+ sqlStr.push(upToOpen.slice(0, upToOpen.length - 2));
255
+ }
256
+ sqlStr.push(this.visit(part.query()));
257
+ }
258
+ const lastChars = (_a = pcx.SQL_END()) === null || _a === void 0 ? void 0 : _a.text.slice(0, -3);
259
+ sqlStr.push(lastChars || "");
260
+ this.astAt(sqlStr, pcx);
261
+ }
262
+ visitMalloyDocument(pcx) {
263
+ const stmts = this.onlyDocStatements(pcx.malloyStatement().map((scx) => this.visit(scx)));
264
+ return new ast.Document(stmts);
265
+ }
266
+ visitDefineSourceStatement(pcx) {
267
+ const defsCx = pcx.sourcePropertyList().sourceDefinition();
268
+ const defs = defsCx.map((dcx) => this.visitsourceDefinition(dcx));
269
+ if (defs.length == 1) {
270
+ return defs[0];
271
+ }
272
+ return new ast.DefineSourceList(defs);
273
+ }
274
+ visitsourceDefinition(pcx) {
275
+ const exploreDef = new ast.DefineSource(this.getIdText(pcx.sourceNameDef()), this.visitExplore(pcx.explore()), true, []);
276
+ return this.astAt(exploreDef, pcx);
277
+ }
278
+ visitExplore(pcx) {
279
+ const source = this.getExploreSource(pcx.exploreSource());
280
+ const refineCx = pcx.exploreProperties();
281
+ if (refineCx) {
282
+ return this.astAt(new ast.RefinedSource(source, this.visitExploreProperties(refineCx)), pcx);
283
+ }
284
+ return source;
285
+ }
286
+ visitExploreProperties(pcx) {
287
+ const filterCx = pcx.filterShortcut();
288
+ const visited = pcx.exploreStatement().map((ecx) => this.visit(ecx));
289
+ const propList = new ast.ExploreDesc(this.onlyExploreProperties(visited));
290
+ if (filterCx) {
291
+ propList.push(this.getFilterShortcut(filterCx));
292
+ }
293
+ return propList;
294
+ }
295
+ visitExploreTable(pcx) {
296
+ const tableName = this.stripQuotes(pcx.tableName().text);
297
+ return this.astAt(new ast.TableSource(tableName), pcx);
298
+ }
299
+ visitTableSource(pcx) {
300
+ return this.visitExploreTable(pcx.exploreTable());
301
+ }
302
+ visitSQLSourceName(pcx) {
303
+ const name = this.getModelEntryName(pcx.sqlExploreNameRef());
304
+ return this.astAt(new ast.SQLSource(name), pcx);
305
+ }
306
+ visitQuerySource(pcx) {
307
+ const query = this.visit(pcx.query());
308
+ if (ast.isQueryElement(query)) {
309
+ return this.astAt(new ast.QuerySource(query), pcx);
310
+ }
311
+ throw this.internalError(pcx, `Expect query definition, got a '${query.elementType}'`);
312
+ }
313
+ visitDefJoinMany(pcx) {
314
+ const joinList = this.getJoinList(pcx.joinList());
315
+ const joins = [];
316
+ for (const join of joinList) {
317
+ if (join instanceof ast.Join) {
318
+ joins.push(join);
319
+ if (join instanceof ast.ExpressionJoin) {
320
+ join.joinType = "many";
321
+ if (join.joinOn == undefined) {
322
+ join.log("join_many: requires ON expression");
323
+ }
324
+ }
325
+ else if (join instanceof ast.KeyJoin) {
326
+ join.log("Foreign key join not legal in join_many:");
327
+ }
328
+ }
329
+ }
330
+ return new ast.Joins(joins);
331
+ }
332
+ visitDefJoinOne(pcx) {
333
+ const joinList = this.getJoinList(pcx.joinList());
334
+ const joins = [];
335
+ for (const join of joinList) {
336
+ if (join instanceof ast.Join) {
337
+ joins.push(join);
338
+ if (join instanceof ast.ExpressionJoin) {
339
+ join.joinType = "one";
340
+ }
341
+ }
342
+ }
343
+ return new ast.Joins(joins);
344
+ }
345
+ visitDefJoinCross(pcx) {
346
+ const joinList = this.getJoinList(pcx.joinList());
347
+ const joins = [];
348
+ for (const join of joinList) {
349
+ if (join instanceof ast.Join) {
350
+ joins.push(join);
351
+ if (join instanceof ast.ExpressionJoin) {
352
+ join.joinType = "cross";
353
+ }
354
+ else {
355
+ join.log("Foreign key join not legal in join_cross:");
356
+ }
357
+ }
358
+ }
359
+ return new ast.Joins(joins);
360
+ }
361
+ getJoinList(pcx) {
362
+ return pcx.joinDef().map((jcx) => this.visit(jcx));
363
+ }
364
+ getJoinSource(name, ecx) {
365
+ if (ecx) {
366
+ return this.visitExplore(ecx);
367
+ }
368
+ return new ast.NamedSource(name);
369
+ }
370
+ visitJoinOn(pcx) {
371
+ const joinAs = this.getModelEntryName(pcx.joinNameDef());
372
+ const joinFrom = this.getJoinSource(joinAs, pcx.explore());
373
+ const join = new ast.ExpressionJoin(joinAs, joinFrom);
374
+ const onCx = pcx.joinExpression();
375
+ if (onCx) {
376
+ join.joinOn = this.getFieldExpr(onCx);
377
+ }
378
+ return this.astAt(join, pcx);
379
+ }
380
+ visitJoinWith(pcx) {
381
+ const joinAs = this.getModelEntryName(pcx.joinNameDef());
382
+ const joinFrom = this.getJoinSource(joinAs, pcx.explore());
383
+ const joinOn = this.getFieldExpr(pcx.fieldExpr());
384
+ const join = new ast.KeyJoin(joinAs, joinFrom, joinOn);
385
+ return this.astAt(join, pcx);
386
+ }
387
+ visitFieldDef(pcx) {
388
+ const defCx = pcx.fieldExpr();
389
+ const fieldName = this.getIdText(pcx.fieldNameDef());
390
+ const valExpr = this.getFieldExpr(defCx);
391
+ const def = new ast.FieldDeclaration(valExpr, fieldName, this.getSourceCode(defCx));
392
+ return this.astAt(def, pcx);
393
+ }
394
+ visitDefExploreDimension(pcx) {
395
+ const defs = this.getFieldDefs(pcx.dimensionDefList().dimensionDef(), false);
396
+ const stmt = new ast.Dimensions(defs);
397
+ return this.astAt(stmt, pcx);
398
+ }
399
+ visitDefExploreMeasure(pcx) {
400
+ const defs = this.getFieldDefs(pcx.measureDefList().measureDef(), true);
401
+ const stmt = new ast.Measures(defs);
402
+ return this.astAt(stmt, pcx);
403
+ }
404
+ visitDeclareStatement(pcx) {
405
+ const defs = this.getFieldDefs(pcx.fieldDef(), true);
406
+ const stmt = new ast.DeclareFields(defs);
407
+ return this.astAt(stmt, pcx);
408
+ }
409
+ visitExploreRenameDef(pcx) {
410
+ const newName = pcx.fieldName(0).id();
411
+ const oldName = pcx.fieldName(1).id();
412
+ const rename = new ast.RenameField(this.getIdText(newName), this.getFieldName(oldName));
413
+ return this.astAt(rename, pcx);
414
+ }
415
+ visitDefExploreRename(pcx) {
416
+ const rcxs = pcx.renameList().exploreRenameDef();
417
+ const renames = rcxs.map((rcx) => this.visitExploreRenameDef(rcx));
418
+ const stmt = new ast.Renames(renames);
419
+ return this.astAt(stmt, pcx);
420
+ }
421
+ visitFilterClauseList(pcx) {
422
+ return new ast.Filter(pcx.fieldExpr().map((f) => this.getFilterElement(f)));
423
+ }
424
+ visitFilterByShortcut(pcx) {
425
+ const el = this.getFilterElement(pcx.fieldExpr());
426
+ return this.astAt(new ast.Filter([el]), pcx);
427
+ }
428
+ visitWhereStatement(pcx) {
429
+ const where = this.visitFilterClauseList(pcx.filterClauseList());
430
+ where.having = false;
431
+ return this.astAt(where, pcx);
432
+ }
433
+ visitHavingStatement(pcx) {
434
+ const having = this.visitFilterClauseList(pcx.filterClauseList());
435
+ having.having = true;
436
+ return this.astAt(having, pcx);
437
+ }
438
+ visitSubQueryDefList(pcx) {
439
+ const babyTurtles = pcx
440
+ .exploreQueryDef()
441
+ .map((cx) => this.visitExploreQueryDef(cx));
442
+ return new ast.Turtles(babyTurtles);
443
+ }
444
+ visitDefExplorePrimaryKey(pcx) {
445
+ const node = new ast.PrimaryKey(this.getFieldName(pcx.fieldName()));
446
+ return this.astAt(node, pcx);
447
+ }
448
+ visitFieldNameList(pcx) {
449
+ const members = pcx
450
+ .fieldName()
451
+ .map((cx) => new ast.FieldReference([this.getFieldName(cx)]));
452
+ return new ast.FieldReferences(members);
453
+ }
454
+ visitDefExploreEditField(pcx) {
455
+ const action = pcx.ACCEPT() ? "accept" : "except";
456
+ return new ast.FieldListEdit(action, this.visitFieldNameList(pcx.fieldNameList()));
457
+ }
458
+ visitQueryProperties(pcx) {
459
+ const qProps = pcx
460
+ .queryStatement()
461
+ .map((qcx) => this.astAt(this.visit(qcx), qcx))
462
+ .filter(function (p) {
463
+ if (ast.isQueryProperty(p)) {
464
+ return true;
465
+ }
466
+ p.log(`Unexpected statement type '${p.elementType}' in query`);
467
+ return false;
468
+ });
469
+ const fcx = pcx.filterShortcut();
470
+ if (fcx) {
471
+ qProps.push(this.getFilterShortcut(fcx));
472
+ }
473
+ return new ast.QOPDesc(qProps);
474
+ }
475
+ visitFieldPath(pcx) {
476
+ const names = pcx.fieldName().map((nameCx) => this.getFieldName(nameCx));
477
+ return this.astAt(new ast.FieldReference(names), pcx);
478
+ }
479
+ visitQueryFieldDef(pcx) {
480
+ const defCx = pcx.dimensionDef().fieldDef();
481
+ const dim = this.visitFieldDef(defCx);
482
+ return this.astAt(dim, defCx);
483
+ }
484
+ visitQueryFieldRef(pcx) {
485
+ return this.visitFieldPath(pcx.fieldPath());
486
+ }
487
+ // visitQueryFieldNameless(
488
+ // pcx: parse.QueryFieldNamelessContext
489
+ // ): ast.MalloyElement {
490
+ // this.contextError(pcx, `Expressions in queries must have names`);
491
+ // const noItem = new ast.Unimplemented();
492
+ // noItem.reported = true;
493
+ // return noItem;
494
+ // }
495
+ getQueryItems(pcx) {
496
+ const itemList = pcx.queryFieldEntry().map((e) => this.visit(e));
497
+ return this.onlyQueryRefs(itemList);
498
+ }
499
+ visitAggregateStatement(pcx) {
500
+ return new ast.Aggregate(this.getQueryItems(pcx.queryFieldList()));
501
+ }
502
+ visitGroupByStatement(pcx) {
503
+ return new ast.GroupBy(this.getQueryItems(pcx.queryFieldList()));
504
+ }
505
+ visitFieldCollection(pcx) {
506
+ const fields = [];
507
+ for (const elCx of pcx.collectionMember()) {
508
+ const el = this.visit(elCx);
509
+ if (ast.isFieldCollectionMember(el)) {
510
+ fields.push(el);
511
+ }
512
+ else {
513
+ throw this.internalError(elCx, `${el.elementType} is not a query field`);
514
+ }
515
+ }
516
+ return this.astAt(new ast.ProjectStatement(fields), pcx);
517
+ }
518
+ visitWildMember(pcx) {
519
+ const nameCx = pcx.fieldPath();
520
+ const stars = pcx.STAR() ? "*" : "**";
521
+ const join = nameCx ? this.visitFieldPath(nameCx) : undefined;
522
+ return new ast.WildcardFieldReference(join, stars);
523
+ }
524
+ visitIndexFields(pcx) {
525
+ const refList = pcx.indexElement().map((el) => {
526
+ const hasStar = el.STAR() != undefined;
527
+ const pathCx = el.fieldPath();
528
+ if (!pathCx) {
529
+ return new ast.WildcardFieldReference(undefined, "*");
530
+ }
531
+ const path = this.visitFieldPath(pathCx);
532
+ if (!hasStar) {
533
+ return this.astAt(path, pcx);
534
+ }
535
+ return this.astAt(new ast.WildcardFieldReference(path, "*"), pcx);
536
+ });
537
+ return new ast.FieldReferences(refList);
538
+ }
539
+ visitIndexStatement(pcx) {
540
+ const fields = this.visitIndexFields(pcx.indexFields());
541
+ const indexStmt = new ast.Index(fields);
542
+ const weightCx = pcx.fieldName();
543
+ if (weightCx) {
544
+ indexStmt.useWeight(this.getFieldName(weightCx));
545
+ }
546
+ return this.astAt(indexStmt, pcx);
547
+ }
548
+ visitLimitStatement(pcx) {
549
+ return new ast.Limit(this.getNumber(pcx.INTEGER_LITERAL()));
550
+ }
551
+ visitOrderBySpec(pcx) {
552
+ const dir = pcx.ASC() ? "asc" : pcx.DESC() ? "desc" : undefined;
553
+ const ncx = pcx.INTEGER_LITERAL();
554
+ if (ncx) {
555
+ return new ast.OrderBy(this.getNumber(ncx), dir);
556
+ }
557
+ const fieldCx = pcx.fieldName();
558
+ if (fieldCx) {
559
+ return new ast.OrderBy(this.getFieldName(fieldCx), dir);
560
+ }
561
+ throw this.internalError(pcx, "can't parse order_by specification");
562
+ }
563
+ visitOrdering(pcx) {
564
+ const orderList = pcx.orderBySpec().map((o) => this.visitOrderBySpec(o));
565
+ return this.astAt(new ast.Ordering(orderList), pcx);
566
+ }
567
+ visitTopStatement(pcx) {
568
+ const byCx = pcx.bySpec();
569
+ const topN = this.getNumber(pcx.INTEGER_LITERAL());
570
+ let top;
571
+ if (byCx) {
572
+ const nameCx = byCx.fieldName();
573
+ if (nameCx) {
574
+ const name = this.getFieldName(nameCx);
575
+ top = new ast.Top(topN, name);
576
+ }
577
+ const exprCx = byCx.fieldExpr();
578
+ if (exprCx) {
579
+ top = new ast.Top(topN, this.getFieldExpr(exprCx));
580
+ }
581
+ }
582
+ if (!top) {
583
+ top = new ast.Top(topN, undefined);
584
+ }
585
+ return this.astAt(top, pcx);
586
+ }
587
+ visitSourceID(pcx) {
588
+ const name = this.getModelEntryName(pcx.id());
589
+ return this.astAt(new ast.NamedSource(name), pcx);
590
+ }
591
+ buildPipelineFromName(pipe, pipeCx) {
592
+ const firstCx = pipeCx.firstSegment();
593
+ const nameCx = firstCx.exploreQueryName();
594
+ if (nameCx) {
595
+ pipe.turtleName = this.getFieldName(nameCx);
596
+ }
597
+ const propsCx = firstCx.queryProperties();
598
+ if (propsCx) {
599
+ const queryDesc = this.visitQueryProperties(propsCx);
600
+ if (nameCx) {
601
+ pipe.refineHead(queryDesc);
602
+ }
603
+ else {
604
+ pipe.addSegments(queryDesc);
605
+ }
606
+ }
607
+ const tail = this.getSegments(pipeCx.pipeElement());
608
+ pipe.addSegments(...tail);
609
+ }
610
+ visitExploreArrowQuery(pcx) {
611
+ const root = this.visitExplore(pcx.explore());
612
+ const query = new ast.FullQuery(root);
613
+ this.buildPipelineFromName(query, pcx.pipelineFromName());
614
+ return this.astAt(query, pcx);
615
+ }
616
+ visitArrowQuery(pcx) {
617
+ const query = new ast.ExistingQuery();
618
+ query.head = this.getModelEntryName(pcx.queryName());
619
+ const refCx = pcx.queryProperties();
620
+ if (refCx) {
621
+ query.refineHead(this.visitQueryProperties(refCx));
622
+ }
623
+ query.addSegments(...this.getSegments(pcx.pipeElement()));
624
+ return this.astAt(query, pcx);
625
+ }
626
+ visitTopLevelQueryDefs(pcx) {
627
+ const stmts = pcx
628
+ .topLevelQueryDef()
629
+ .map((cx) => this.visitTopLevelQueryDef(cx));
630
+ if (stmts.length === 1) {
631
+ return stmts[0];
632
+ }
633
+ return new ast.DefineQueryList(stmts);
634
+ }
635
+ visitTopLevelQueryDef(pcx) {
636
+ const queryName = this.getIdText(pcx.queryName());
637
+ const queryDef = this.visit(pcx.query());
638
+ if (ast.isQueryElement(queryDef)) {
639
+ return this.astAt(new ast.DefineQuery(queryName, queryDef), pcx);
640
+ }
641
+ throw this.internalError(pcx, `Expect query definition, got a '${queryDef.elementType}'`);
642
+ }
643
+ visitAnonymousQuery(pcx) {
644
+ const query = this.visit(pcx.topLevelAnonQueryDef().query());
645
+ if (ast.isQueryElement(query)) {
646
+ return new ast.AnonymousQuery(query);
647
+ }
648
+ throw this.internalError(pcx, `Anonymous query matched, but ${query.elementType} found`);
649
+ }
650
+ visitNestedQueryList(pcx) {
651
+ const nestedList = pcx.nestEntry().map((cx) => this.visit(cx));
652
+ if (nestedList.length == 1) {
653
+ return nestedList[0];
654
+ }
655
+ return new ast.Nests(this.onlyNestedQueries(nestedList));
656
+ }
657
+ visitNestExisting(pcx) {
658
+ const name = this.getFieldName(pcx.queryName());
659
+ const propsCx = pcx.queryProperties();
660
+ if (propsCx) {
661
+ const nestRefine = new ast.NestRefinement(name);
662
+ const queryDesc = this.visitQueryProperties(propsCx);
663
+ nestRefine.refineHead(queryDesc);
664
+ return this.astAt(nestRefine, pcx);
665
+ }
666
+ return this.astAt(new ast.NestReference(name), pcx);
667
+ }
668
+ visitNestDef(pcx) {
669
+ const name = this.getIdText(pcx.queryName());
670
+ const nestDef = new ast.NestDefinition(name);
671
+ this.buildPipelineFromName(nestDef, pcx.pipelineFromName());
672
+ return this.astAt(nestDef, pcx);
673
+ }
674
+ visitExploreQueryDef(pcx) {
675
+ const name = this.getIdText(pcx.exploreQueryNameDef());
676
+ const queryDef = new ast.TurtleDecl(name);
677
+ this.buildPipelineFromName(queryDef, pcx.pipelineFromName());
678
+ return this.astAt(queryDef, pcx);
679
+ }
680
+ visitExprNot(pcx) {
681
+ return new ast.ExprNot(this.getFieldExpr(pcx.fieldExpr()));
682
+ }
683
+ visitExprBool(pcx) {
684
+ return new ast.Boolean(pcx.TRUE() ? "true" : "false");
685
+ }
686
+ allFieldExpressions(exprList) {
687
+ return exprList.map((ecx) => this.getFieldExpr(ecx));
688
+ }
689
+ visitExprLogical(pcx) {
690
+ const left = this.getFieldExpr(pcx.fieldExpr(0));
691
+ const right = this.getFieldExpr(pcx.fieldExpr(1));
692
+ return new ast.ExprLogicalOp(left, pcx.AND() ? "and" : "or", right);
693
+ }
694
+ visitExprLogicalTree(pcx) {
695
+ const left = this.getFieldExpr(pcx.fieldExpr());
696
+ const right = this.getFieldExpr(pcx.partialAllowedFieldExpr());
697
+ return new ast.ExprAlternationTree(left, pcx.AMPER() ? "&" : "|", right);
698
+ }
699
+ visitPartialAllowedFieldExpr(pcx) {
700
+ var _a;
701
+ const fieldExpr = this.getFieldExpr(pcx.fieldExpr());
702
+ const partialOp = (_a = pcx.compareOp()) === null || _a === void 0 ? void 0 : _a.text;
703
+ if (partialOp) {
704
+ if (ast.isComparison(partialOp)) {
705
+ return this.astAt(new ast.PartialCompare(partialOp, fieldExpr), pcx);
706
+ }
707
+ throw this.internalError(pcx, `partial comparison '${partialOp}' not recognized`);
708
+ }
709
+ return fieldExpr;
710
+ }
711
+ visitExprString(pcx) {
712
+ return new ast.ExprString(pcx.STRING_LITERAL().text);
713
+ }
714
+ visitExprRegex(pcx) {
715
+ const malloyRegex = pcx.HACKY_REGEX().text;
716
+ return new ast.ExprRegEx(this.stripQuotes(malloyRegex.slice(1)));
717
+ }
718
+ visitExprNow(_pcx) {
719
+ return new ast.ExprNow();
720
+ }
721
+ visitExprNumber(pcx) {
722
+ var _a, _b;
723
+ const number = ((_a = pcx.INTEGER_LITERAL()) === null || _a === void 0 ? void 0 : _a.text) || ((_b = pcx.NUMERIC_LITERAL()) === null || _b === void 0 ? void 0 : _b.text);
724
+ /*
725
+ * I "know" one of these is true because grammar, but Typescript
726
+ * rightly points out that grammvisitExprFieldPathar can change in unexpected ways
727
+ */
728
+ if (number) {
729
+ return new ast.ExprNumber(number);
730
+ }
731
+ else {
732
+ this.contextError(pcx, `'${pcx.text}' is not a number`);
733
+ return new ast.ExprNumber("42");
734
+ }
735
+ }
736
+ visitExprFieldPath(pcx) {
737
+ const idRef = new ast.ExprIdReference(this.visitFieldPath(pcx.fieldPath()));
738
+ return this.astAt(idRef, pcx);
739
+ }
740
+ visitExprNULL(_pcx) {
741
+ return new ast.ExprNULL();
742
+ }
743
+ visitExprExpr(pcx) {
744
+ return new ast.ExprParens(this.getFieldExpr(pcx.partialAllowedFieldExpr()));
745
+ }
746
+ visitExprMinus(pcx) {
747
+ return new ast.ExprMinus(this.getFieldExpr(pcx.fieldExpr()));
748
+ }
749
+ visitExprAddSub(pcx) {
750
+ const lhs = this.getFieldExpr(pcx.fieldExpr(0));
751
+ const rhs = this.getFieldExpr(pcx.fieldExpr(1));
752
+ const op = pcx.PLUS() ? "+" : "-";
753
+ return new ast.ExprAddSub(lhs, op, rhs);
754
+ }
755
+ visitExprMulDiv(pcx) {
756
+ const op = pcx.STAR() ? "*" : pcx.SLASH() ? "/" : "%";
757
+ return new ast.ExprMulDiv(this.getFieldExpr(pcx.fieldExpr(0)), op, this.getFieldExpr(pcx.fieldExpr(1)));
758
+ }
759
+ visitExprCompare(pcx) {
760
+ const op = pcx.compareOp().text;
761
+ if (ast.isComparison(op)) {
762
+ return new ast.ExprCompare(this.getFieldExpr(pcx.fieldExpr(0)), op, this.getFieldExpr(pcx.fieldExpr(1)));
763
+ }
764
+ throw this.internalError(pcx, `untranslatable comparison operator '${op}'`);
765
+ }
766
+ visitExprCountDisinct(pcx) {
767
+ return this.astAt(new ast.ExprCountDistinct(this.getFieldExpr(pcx.fieldExpr())), pcx);
768
+ }
769
+ visitExprUngroup(pcx) {
770
+ const flist = pcx.fieldName().map((fcx) => this.getFieldName(fcx));
771
+ const kw = this.getIdText(pcx.ungroup()).toLocaleLowerCase();
772
+ return this.astAt(new ast.ExprUngroup(kw == "all" ? kw : "exclude", this.getFieldExpr(pcx.fieldExpr()), flist), pcx);
773
+ }
774
+ visitExprAggregate(pcx) {
775
+ const pathCx = pcx.fieldPath();
776
+ const path = pathCx ? this.visitFieldPath(pathCx) : undefined;
777
+ const source = pathCx && path ? this.astAt(path, pathCx) : undefined;
778
+ const exprDef = pcx.fieldExpr();
779
+ if (pcx.aggregate().COUNT()) {
780
+ if (exprDef) {
781
+ this.contextError(exprDef, "Ignored expression inside COUNT()");
782
+ }
783
+ return new ast.ExprCount(source);
784
+ }
785
+ // * was ok in count, not ok now ... this should be in grammer but at
786
+ // the moment while things are still changing its right to be caught here
787
+ const star = pcx.STAR();
788
+ if (star) {
789
+ this.contextError(pcx, "'*' is not a valid expression");
790
+ }
791
+ const expr = exprDef ? this.getFieldExpr(exprDef) : undefined;
792
+ if (pcx.aggregate().MIN()) {
793
+ if (path) {
794
+ this.contextError(pcx, `Path not legal for min()`);
795
+ }
796
+ else if (expr) {
797
+ return new ast.ExprMin(expr);
798
+ }
799
+ else {
800
+ this.contextError(pcx, "Missing expression for min");
801
+ }
802
+ }
803
+ else if (pcx.aggregate().MAX()) {
804
+ if (path) {
805
+ this.contextError(pcx, `Path not legal for max()`);
806
+ }
807
+ else if (expr) {
808
+ return new ast.ExprMax(expr);
809
+ }
810
+ else {
811
+ this.contextError(pcx, "Missing expression for max");
812
+ }
813
+ }
814
+ else if (pcx.aggregate().AVG()) {
815
+ return new ast.ExprAvg(expr, source);
816
+ }
817
+ else if (pcx.aggregate().SUM()) {
818
+ return new ast.ExprSum(expr, source);
819
+ }
820
+ return new ast.ExprNULL();
821
+ }
822
+ visitExprApply(pcx) {
823
+ if (pcx.COLON()) {
824
+ this.contextError(pcx, "':' for apply is deprecated, use '?'", "warn");
825
+ }
826
+ return new ast.Apply(this.getFieldExpr(pcx.fieldExpr()), this.getFieldExpr(pcx.partialAllowedFieldExpr()));
827
+ }
828
+ visitExprRange(pcx) {
829
+ return new ast.Range(this.getFieldExpr(pcx.fieldExpr(0)), this.getFieldExpr(pcx.fieldExpr(1)));
830
+ }
831
+ visitExprCast(pcx) {
832
+ const type = pcx.malloyType().text;
833
+ if (ast.isCastType(type)) {
834
+ return new ast.ExprCast(this.getFieldExpr(pcx.fieldExpr()), type);
835
+ }
836
+ this.contextError(pcx, `CAST to unknown type '${type}'`);
837
+ return new ast.ExprNULL();
838
+ }
839
+ visitExprSafeCast(pcx) {
840
+ const type = pcx.malloyType().text;
841
+ if (ast.isCastType(type)) {
842
+ return new ast.ExprCast(this.getFieldExpr(pcx.fieldExpr()), type, true);
843
+ }
844
+ this.contextError(pcx, `'::' cast to unknown type '${type}'`);
845
+ return new ast.ExprNULL();
846
+ }
847
+ visitExprTimeTrunc(pcx) {
848
+ return new ast.ExprGranularTime(this.getFieldExpr(pcx.fieldExpr()), this.visitTimeframe(pcx.timeframe()).text, true);
849
+ }
850
+ visitTimeframe(pcx) {
851
+ return new ast.Timeframe(pcx.text);
852
+ }
853
+ visitExprForRange(pcx) {
854
+ const begin = this.getFieldExpr(pcx._startAt);
855
+ const duration = this.getFieldExpr(pcx._duration);
856
+ const units = this.visitTimeframe(pcx.timeframe());
857
+ return new ast.ForRange(begin, duration, units);
858
+ }
859
+ visitExprFunc(pcx) {
860
+ const argsCx = pcx.argumentList();
861
+ const args = argsCx ? this.allFieldExpressions(argsCx.fieldExpr()) : [];
862
+ const idCx = pcx.id();
863
+ const dCx = pcx.timeframe();
864
+ let fn;
865
+ if (idCx) {
866
+ fn = this.getIdText(idCx);
867
+ }
868
+ else if (dCx) {
869
+ fn = dCx.text;
870
+ }
871
+ else {
872
+ this.contextError(pcx, "Funciton name error");
873
+ fn = "FUNCTION_NAME_ERROR";
874
+ }
875
+ if (ast.ExprTimeExtract.extractor(fn)) {
876
+ return this.astAt(new ast.ExprTimeExtract(fn, args), pcx);
877
+ }
878
+ return this.astAt(new ast.ExprFunc(fn, args), pcx);
879
+ }
880
+ visitExprDuration(pcx) {
881
+ return new ast.ExprDuration(this.getFieldExpr(pcx.fieldExpr()), this.visitTimeframe(pcx.timeframe()).text);
882
+ }
883
+ visitPickStatement(pcx) {
884
+ const picks = pcx.pick().map((pwCx) => {
885
+ let pickExpr;
886
+ if (pwCx._pickValue) {
887
+ pickExpr = this.getFieldExpr(pwCx._pickValue);
888
+ }
889
+ return new ast.PickWhen(pickExpr, this.getFieldExpr(pwCx._pickWhen));
890
+ });
891
+ if (pcx.ELSE()) {
892
+ return new ast.Pick(picks, this.getFieldExpr(pcx._pickElse));
893
+ }
894
+ return new ast.Pick(picks);
895
+ }
896
+ visitNamedSource(pcx) {
897
+ const name = this.getModelEntryName(pcx.sourceID());
898
+ // Parameters ... coming ...
899
+ // const paramListCx = pcx.isParam();
900
+ // if (paramListCx) {
901
+ // const paramInit: Record<string, ast.ConstantSubExpression> = {};
902
+ // for (const cx of paramListCx) {
903
+ // const pName = this.identifer(cx.id());
904
+ // const pVal = this.getFieldExpr(cx.isExpr().partialAllowedFieldExpr());
905
+ // paramInit[pName] = new ast.ConstantSubExpression(pVal);
906
+ // }
907
+ // return this.astAt(new ast.NamedSource(name, paramInit), pcx);
908
+ // }
909
+ return this.astAt(new ast.NamedSource(name), pcx);
910
+ }
911
+ visitExprFilter(pcx) {
912
+ const filters = this.visit(pcx.filteredBy());
913
+ return new ast.ExprFilter(this.getFieldExpr(pcx.fieldExpr()), filters);
914
+ }
915
+ getLiteralTime(cx) {
916
+ const parsed = ast.GranularLiteral.parse(cx.text);
917
+ if (parsed === undefined) {
918
+ this.contextError(cx, `${cx.text} is not a legal day specification`);
919
+ return new ast.ExprNow();
920
+ }
921
+ return parsed;
922
+ }
923
+ visitLiteralTimestamp(pcx) {
924
+ return this.getLiteralTime(pcx);
925
+ }
926
+ visitLiteralDay(pcx) {
927
+ return this.getLiteralTime(pcx);
928
+ }
929
+ visitLiteralWeek(pcx) {
930
+ return this.getLiteralTime(pcx);
931
+ }
932
+ visitLiteralMonth(pcx) {
933
+ return this.getLiteralTime(pcx);
934
+ }
935
+ visitLiteralQuarter(pcx) {
936
+ return this.getLiteralTime(pcx);
937
+ }
938
+ visitLiteralYear(pcx) {
939
+ return this.getLiteralTime(pcx);
940
+ }
941
+ visitImportStatement(pcx) {
942
+ const url = this.stripQuotes(pcx.importURL().text);
943
+ return this.astAt(new ast.ImportStatement(url, this.parse.subTranslator.sourceURL), pcx);
944
+ }
945
+ visitJustExpr(pcx) {
946
+ return this.getFieldExpr(pcx.fieldExpr());
947
+ }
948
+ visitDefineSQLStatement(pcx) {
949
+ var _a;
950
+ const blockName = (_a = pcx.nameSQLBlock()) === null || _a === void 0 ? void 0 : _a.text;
951
+ const blockParts = pcx.sqlBlock().blockSQLDef();
952
+ const sqlStr = new ast.SQLString();
953
+ let connectionName;
954
+ for (const blockEnt of blockParts) {
955
+ const nmCx = blockEnt.connectionName();
956
+ if (nmCx) {
957
+ if (connectionName) {
958
+ this.contextError(nmCx, "Cannot redefine connection");
959
+ }
960
+ else {
961
+ connectionName = this.getIdText(nmCx);
962
+ }
963
+ }
964
+ const selCx = blockEnt.sqlString();
965
+ if (selCx) {
966
+ this.makeSqlString(selCx, sqlStr);
967
+ }
968
+ }
969
+ const stmt = new ast.SQLStatement(sqlStr);
970
+ if (connectionName !== undefined) {
971
+ stmt.connection = connectionName;
972
+ }
973
+ stmt.is = blockName;
974
+ return this.astAt(stmt, pcx);
975
+ }
976
+ visitSampleStatement(pcx) {
977
+ const rowCx = pcx.sampleSpec().INTEGER_LITERAL();
978
+ if (rowCx) {
979
+ return new ast.SampleProperty({ rows: this.getNumber(rowCx) });
980
+ }
981
+ const limitCx = pcx.sampleSpec().PERCENT_LITERAL();
982
+ if (limitCx) {
983
+ return new ast.SampleProperty({ percent: this.getNumber(limitCx) });
984
+ }
985
+ const enabled = pcx.sampleSpec().TRUE() != undefined;
986
+ return new ast.SampleProperty({ enable: enabled });
987
+ }
988
+ }
989
+ exports.MalloyToAST = MalloyToAST;
990
+ //# sourceMappingURL=malloy-to-ast.js.map