@malloydata/malloy 0.0.22-dev230207144036 → 0.0.22-dev230207171614
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/connection_utils.d.ts +1 -0
- package/dist/connection_utils.js +66 -0
- package/dist/dialect/dialect.d.ts +66 -0
- package/dist/dialect/dialect.js +85 -0
- package/dist/dialect/dialect_map.d.ts +3 -0
- package/dist/dialect/dialect_map.js +45 -0
- package/dist/dialect/duckdb.d.ts +52 -0
- package/dist/dialect/duckdb.js +364 -0
- package/dist/dialect/index.d.ts +6 -0
- package/dist/dialect/index.js +37 -0
- package/dist/dialect/postgres.d.ts +52 -0
- package/dist/dialect/postgres.js +330 -0
- package/dist/dialect/standardsql.d.ts +49 -0
- package/dist/dialect/standardsql.js +381 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +59 -0
- package/dist/lang/ast/ast-utils.d.ts +10 -0
- package/dist/lang/ast/ast-utils.js +42 -0
- package/dist/lang/ast/elements/define-query.d.ts +14 -0
- package/dist/lang/ast/elements/define-query.js +56 -0
- package/dist/lang/ast/elements/define-source.d.ts +17 -0
- package/dist/lang/ast/elements/define-source.js +79 -0
- package/dist/lang/ast/elements/import-statement.d.ts +9 -0
- package/dist/lang/ast/elements/import-statement.js +78 -0
- package/dist/lang/ast/elements/pipeline-desc.d.ts +30 -0
- package/dist/lang/ast/elements/pipeline-desc.js +102 -0
- package/dist/lang/ast/elements/refined-source.d.ts +15 -0
- package/dist/lang/ast/elements/refined-source.js +121 -0
- package/dist/lang/ast/elements/source.d.ts +12 -0
- package/dist/lang/ast/elements/source.js +53 -0
- package/dist/lang/ast/error-factory.d.ts +9 -0
- package/dist/lang/ast/error-factory.js +61 -0
- package/dist/lang/ast/executors/index-executor.d.ts +18 -0
- package/dist/lang/ast/executors/index-executor.js +96 -0
- package/dist/lang/ast/executors/project-executor.d.ts +10 -0
- package/dist/lang/ast/executors/project-executor.js +68 -0
- package/dist/lang/ast/executors/reduce-executor.d.ts +21 -0
- package/dist/lang/ast/executors/reduce-executor.js +149 -0
- package/dist/lang/ast/expressions/apply.d.ts +8 -0
- package/dist/lang/ast/expressions/apply.js +37 -0
- package/dist/lang/ast/expressions/binary-boolean.d.ts +12 -0
- package/dist/lang/ast/expressions/binary-boolean.js +54 -0
- package/dist/lang/ast/expressions/binary-numeric.d.ts +11 -0
- package/dist/lang/ast/expressions/binary-numeric.js +42 -0
- package/dist/lang/ast/expressions/boolean.d.ts +8 -0
- package/dist/lang/ast/expressions/boolean.js +39 -0
- package/dist/lang/ast/expressions/constant-sub-expression.d.ts +16 -0
- package/dist/lang/ast/expressions/constant-sub-expression.js +98 -0
- package/dist/lang/ast/expressions/expr-add-sub.d.ts +4 -0
- package/dist/lang/ast/expressions/expr-add-sub.js +34 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.d.ts +15 -0
- package/dist/lang/ast/expressions/expr-aggregate-function.js +99 -0
- package/dist/lang/ast/expressions/expr-alternation-tree.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-alternation-tree.js +54 -0
- package/dist/lang/ast/expressions/expr-asymmetric.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-asymmetric.js +27 -0
- package/dist/lang/ast/expressions/expr-avg.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-avg.js +34 -0
- package/dist/lang/ast/expressions/expr-cast.d.ts +13 -0
- package/dist/lang/ast/expressions/expr-cast.js +29 -0
- package/dist/lang/ast/expressions/expr-compare.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-compare.js +58 -0
- package/dist/lang/ast/expressions/expr-count-distinct.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-count-distinct.js +35 -0
- package/dist/lang/ast/expressions/expr-count.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-count.js +57 -0
- package/dist/lang/ast/expressions/expr-filter.d.ts +12 -0
- package/dist/lang/ast/expressions/expr-filter.js +69 -0
- package/dist/lang/ast/expressions/expr-func.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-func.js +63 -0
- package/dist/lang/ast/expressions/expr-granular-time.d.ts +24 -0
- package/dist/lang/ast/expressions/expr-granular-time.js +117 -0
- package/dist/lang/ast/expressions/expr-id-reference.d.ts +12 -0
- package/dist/lang/ast/expressions/expr-id-reference.js +75 -0
- package/dist/lang/ast/expressions/expr-logical-op.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-logical-op.js +36 -0
- package/dist/lang/ast/expressions/expr-max.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-max.js +16 -0
- package/dist/lang/ast/expressions/expr-min.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-min.js +16 -0
- package/dist/lang/ast/expressions/expr-minus.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-minus.js +48 -0
- package/dist/lang/ast/expressions/expr-mul-div.d.ts +4 -0
- package/dist/lang/ast/expressions/expr-mul-div.js +34 -0
- package/dist/lang/ast/expressions/expr-not.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-not.js +49 -0
- package/dist/lang/ast/expressions/expr-now.d.ts +7 -0
- package/dist/lang/ast/expressions/expr-now.js +46 -0
- package/dist/lang/ast/expressions/expr-null.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-null.js +41 -0
- package/dist/lang/ast/expressions/expr-number.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-number.js +42 -0
- package/dist/lang/ast/expressions/expr-parens.d.ts +10 -0
- package/dist/lang/ast/expressions/expr-parens.js +42 -0
- package/dist/lang/ast/expressions/expr-regex.d.ts +8 -0
- package/dist/lang/ast/expressions/expr-regex.js +42 -0
- package/dist/lang/ast/expressions/expr-string.d.ts +9 -0
- package/dist/lang/ast/expressions/expr-string.js +50 -0
- package/dist/lang/ast/expressions/expr-sum.d.ts +6 -0
- package/dist/lang/ast/expressions/expr-sum.js +12 -0
- package/dist/lang/ast/expressions/expr-time-extract.d.ts +13 -0
- package/dist/lang/ast/expressions/expr-time-extract.js +117 -0
- package/dist/lang/ast/expressions/expr-time.d.ts +11 -0
- package/dist/lang/ast/expressions/expr-time.js +62 -0
- package/dist/lang/ast/expressions/expr-ungroup.d.ts +14 -0
- package/dist/lang/ast/expressions/expr-ungroup.js +83 -0
- package/dist/lang/ast/expressions/for-range.d.ts +19 -0
- package/dist/lang/ast/expressions/for-range.js +101 -0
- package/dist/lang/ast/expressions/granular-literal.d.ts +20 -0
- package/dist/lang/ast/expressions/granular-literal.js +148 -0
- package/dist/lang/ast/expressions/partial-compare.d.ts +14 -0
- package/dist/lang/ast/expressions/partial-compare.js +50 -0
- package/dist/lang/ast/expressions/pick-when.d.ts +19 -0
- package/dist/lang/ast/expressions/pick-when.js +156 -0
- package/dist/lang/ast/expressions/range.d.ts +12 -0
- package/dist/lang/ast/expressions/range.js +80 -0
- package/dist/lang/ast/expressions/time-frame.d.ts +7 -0
- package/dist/lang/ast/expressions/time-frame.js +40 -0
- package/dist/lang/ast/expressions/top-by.d.ts +10 -0
- package/dist/lang/ast/expressions/top-by.js +51 -0
- package/dist/lang/ast/expressions/unary.d.ts +5 -0
- package/dist/lang/ast/expressions/unary.js +34 -0
- package/dist/lang/ast/expressions/utils.d.ts +12 -0
- package/dist/lang/ast/expressions/utils.js +87 -0
- package/dist/lang/ast/field-space/column-space-field.d.ts +9 -0
- package/dist/lang/ast/field-space/column-space-field.js +40 -0
- package/dist/lang/ast/field-space/dynamic-space.d.ts +22 -0
- package/dist/lang/ast/field-space/dynamic-space.js +140 -0
- package/dist/lang/ast/field-space/field-definition-value.d.ts +16 -0
- package/dist/lang/ast/field-space/field-definition-value.js +55 -0
- package/dist/lang/ast/field-space/index-field-space.d.ts +10 -0
- package/dist/lang/ast/field-space/index-field-space.js +57 -0
- package/dist/lang/ast/field-space/join-space-field.d.ts +8 -0
- package/dist/lang/ast/field-space/join-space-field.js +35 -0
- package/dist/lang/ast/field-space/project-field-space.d.ts +6 -0
- package/dist/lang/ast/field-space/project-field-space.js +51 -0
- package/dist/lang/ast/field-space/query-field-struct.d.ts +10 -0
- package/dist/lang/ast/field-space/query-field-struct.js +46 -0
- package/dist/lang/ast/field-space/query-space-field.d.ts +11 -0
- package/dist/lang/ast/field-space/query-space-field.js +37 -0
- package/dist/lang/ast/field-space/query-spaces.d.ts +50 -0
- package/dist/lang/ast/field-space/query-spaces.js +233 -0
- package/dist/lang/ast/field-space/reference-field.d.ts +11 -0
- package/dist/lang/ast/field-space/reference-field.js +45 -0
- package/dist/lang/ast/field-space/refined-space.d.ts +13 -0
- package/dist/lang/ast/field-space/refined-space.js +100 -0
- package/dist/lang/ast/field-space/rename-space-field.d.ts +11 -0
- package/dist/lang/ast/field-space/rename-space-field.js +50 -0
- package/dist/lang/ast/field-space/static-space.d.ts +29 -0
- package/dist/lang/ast/field-space/static-space.js +156 -0
- package/dist/lang/ast/field-space/struct-space-field-base.d.ts +11 -0
- package/dist/lang/ast/field-space/struct-space-field-base.js +40 -0
- package/dist/lang/ast/field-space/wild-space-field.d.ts +10 -0
- package/dist/lang/ast/field-space/wild-space-field.js +40 -0
- package/dist/lang/ast/fragtype-utils.d.ts +39 -0
- package/dist/lang/ast/fragtype-utils.js +100 -0
- package/dist/lang/ast/index.d.ts +90 -0
- package/dist/lang/ast/index.js +129 -0
- package/dist/lang/ast/parameters/constant-parameter.d.ts +8 -0
- package/dist/lang/ast/parameters/constant-parameter.js +54 -0
- package/dist/lang/ast/parameters/has-parameter.d.ts +19 -0
- package/dist/lang/ast/parameters/has-parameter.js +64 -0
- package/dist/lang/ast/query-elements/anonymous-query.d.ts +9 -0
- package/dist/lang/ast/query-elements/anonymous-query.js +41 -0
- package/dist/lang/ast/query-elements/existing-query.d.ts +11 -0
- package/dist/lang/ast/query-elements/existing-query.js +79 -0
- package/dist/lang/ast/query-elements/full-query.d.ts +10 -0
- package/dist/lang/ast/query-elements/full-query.js +85 -0
- package/dist/lang/ast/query-elements/query-head-struct.d.ts +9 -0
- package/dist/lang/ast/query-elements/query-head-struct.js +48 -0
- package/dist/lang/ast/query-items/field-declaration.d.ts +31 -0
- package/dist/lang/ast/query-items/field-declaration.js +137 -0
- package/dist/lang/ast/query-items/field-references.d.ts +25 -0
- package/dist/lang/ast/query-items/field-references.js +80 -0
- package/dist/lang/ast/query-properties/aggregate.d.ts +5 -0
- package/dist/lang/ast/query-properties/aggregate.js +39 -0
- package/dist/lang/ast/query-properties/declare-fields.d.ts +5 -0
- package/dist/lang/ast/query-properties/declare-fields.js +33 -0
- package/dist/lang/ast/query-properties/dimmensions.d.ts +5 -0
- package/dist/lang/ast/query-properties/dimmensions.js +36 -0
- package/dist/lang/ast/query-properties/filters.d.ts +18 -0
- package/dist/lang/ast/query-properties/filters.js +89 -0
- package/dist/lang/ast/query-properties/group-by.d.ts +5 -0
- package/dist/lang/ast/query-properties/group-by.js +39 -0
- package/dist/lang/ast/query-properties/indexing.d.ts +10 -0
- package/dist/lang/ast/query-properties/indexing.js +39 -0
- package/dist/lang/ast/query-properties/joins.d.ts +36 -0
- package/dist/lang/ast/query-properties/joins.js +143 -0
- package/dist/lang/ast/query-properties/limit.d.ts +6 -0
- package/dist/lang/ast/query-properties/limit.js +35 -0
- package/dist/lang/ast/query-properties/measures.d.ts +5 -0
- package/dist/lang/ast/query-properties/measures.js +36 -0
- package/dist/lang/ast/query-properties/nest-reference.d.ts +7 -0
- package/dist/lang/ast/query-properties/nest-reference.js +35 -0
- package/dist/lang/ast/query-properties/nest.d.ts +31 -0
- package/dist/lang/ast/query-properties/nest.js +133 -0
- package/dist/lang/ast/query-properties/nests.d.ts +5 -0
- package/dist/lang/ast/query-properties/nests.js +33 -0
- package/dist/lang/ast/query-properties/ordering.d.ts +15 -0
- package/dist/lang/ast/query-properties/ordering.js +66 -0
- package/dist/lang/ast/query-properties/project-statement.d.ts +5 -0
- package/dist/lang/ast/query-properties/project-statement.js +33 -0
- package/dist/lang/ast/query-properties/qop-desc.d.ts +17 -0
- package/dist/lang/ast/query-properties/qop-desc.js +124 -0
- package/dist/lang/ast/query-properties/sampling.d.ts +8 -0
- package/dist/lang/ast/query-properties/sampling.js +38 -0
- package/dist/lang/ast/query-properties/top.d.ts +13 -0
- package/dist/lang/ast/query-properties/top.js +60 -0
- package/dist/lang/ast/source-properties/field-list-edit.d.ts +8 -0
- package/dist/lang/ast/source-properties/field-list-edit.js +36 -0
- package/dist/lang/ast/source-properties/primary-key.d.ts +7 -0
- package/dist/lang/ast/source-properties/primary-key.js +35 -0
- package/dist/lang/ast/source-properties/renames.d.ts +11 -0
- package/dist/lang/ast/source-properties/renames.js +43 -0
- package/dist/lang/ast/source-properties/turtles.d.ts +5 -0
- package/dist/lang/ast/source-properties/turtles.js +33 -0
- package/dist/lang/ast/sources/named-source.d.ts +19 -0
- package/dist/lang/ast/sources/named-source.js +147 -0
- package/dist/lang/ast/sources/query-source.d.ts +9 -0
- package/dist/lang/ast/sources/query-source.js +41 -0
- package/dist/lang/ast/sources/sql-source.d.ts +7 -0
- package/dist/lang/ast/sources/sql-source.js +54 -0
- package/dist/lang/ast/sources/table-source.d.ts +8 -0
- package/dist/lang/ast/sources/table-source.js +60 -0
- package/dist/lang/ast/space-seed.d.ts +16 -0
- package/dist/lang/ast/space-seed.js +59 -0
- package/dist/lang/ast/sql-elements/sql-statement.d.ts +19 -0
- package/dist/lang/ast/sql-elements/sql-statement.js +80 -0
- package/dist/lang/ast/sql-elements/sql-string.d.ts +12 -0
- package/dist/lang/ast/sql-elements/sql-string.js +60 -0
- package/dist/lang/ast/struct-utils.d.ts +4 -0
- package/dist/lang/ast/struct-utils.js +48 -0
- package/dist/lang/ast/time-utils.d.ts +12 -0
- package/dist/lang/ast/time-utils.js +140 -0
- package/dist/lang/ast/types/comparison.d.ts +11 -0
- package/dist/lang/ast/types/comparison.js +41 -0
- package/dist/lang/ast/types/document-compile-result.d.ts +8 -0
- package/dist/lang/ast/types/document-compile-result.js +25 -0
- package/dist/lang/ast/types/equality.d.ts +7 -0
- package/dist/lang/ast/types/equality.js +37 -0
- package/dist/lang/ast/types/executor.d.ts +9 -0
- package/dist/lang/ast/types/executor.js +25 -0
- package/dist/lang/ast/types/explore-desc.d.ts +5 -0
- package/dist/lang/ast/types/explore-desc.js +33 -0
- package/dist/lang/ast/types/explore-field.d.ts +5 -0
- package/dist/lang/ast/types/explore-field.js +32 -0
- package/dist/lang/ast/types/expr-result.d.ts +5 -0
- package/dist/lang/ast/types/expr-result.js +25 -0
- package/dist/lang/ast/types/expr-value.d.ts +3 -0
- package/dist/lang/ast/types/expr-value.js +25 -0
- package/dist/lang/ast/types/expression-def.d.ts +69 -0
- package/dist/lang/ast/types/expression-def.js +346 -0
- package/dist/lang/ast/types/field-collection-member.d.ts +5 -0
- package/dist/lang/ast/types/field-collection-member.js +34 -0
- package/dist/lang/ast/types/field-decl.d.ts +7 -0
- package/dist/lang/ast/types/field-decl.js +37 -0
- package/dist/lang/ast/types/field-space.d.ts +24 -0
- package/dist/lang/ast/types/field-space.js +44 -0
- package/dist/lang/ast/types/granular-result.d.ts +7 -0
- package/dist/lang/ast/types/granular-result.js +11 -0
- package/dist/lang/ast/types/lookup-result.d.ts +10 -0
- package/dist/lang/ast/types/lookup-result.js +25 -0
- package/dist/lang/ast/types/malloy-element.d.ts +106 -0
- package/dist/lang/ast/types/malloy-element.js +398 -0
- package/dist/lang/ast/types/model-entry.d.ts +6 -0
- package/dist/lang/ast/types/model-entry.js +25 -0
- package/dist/lang/ast/types/name-space.d.ts +5 -0
- package/dist/lang/ast/types/name-space.js +25 -0
- package/dist/lang/ast/types/nested-query.d.ts +3 -0
- package/dist/lang/ast/types/nested-query.js +25 -0
- package/dist/lang/ast/types/op-desc.d.ts +6 -0
- package/dist/lang/ast/types/op-desc.js +25 -0
- package/dist/lang/ast/types/query-comp.d.ts +5 -0
- package/dist/lang/ast/types/query-comp.js +25 -0
- package/dist/lang/ast/types/query-element.d.ts +5 -0
- package/dist/lang/ast/types/query-element.js +32 -0
- package/dist/lang/ast/types/query-item.d.ts +5 -0
- package/dist/lang/ast/types/query-item.js +25 -0
- package/dist/lang/ast/types/query-property.d.ts +17 -0
- package/dist/lang/ast/types/query-property.js +55 -0
- package/dist/lang/ast/types/source-property.d.ts +10 -0
- package/dist/lang/ast/types/source-property.js +43 -0
- package/dist/lang/ast/types/space-entry.d.ts +5 -0
- package/dist/lang/ast/types/space-entry.js +29 -0
- package/dist/lang/ast/types/space-field.d.ts +10 -0
- package/dist/lang/ast/types/space-field.js +48 -0
- package/dist/lang/ast/types/space-param.d.ts +20 -0
- package/dist/lang/ast/types/space-param.js +61 -0
- package/dist/lang/ast/types/time-result.d.ts +6 -0
- package/dist/lang/ast/types/time-result.js +25 -0
- package/dist/lang/ast/types/turtle-headed-pipe.d.ts +7 -0
- package/dist/lang/ast/types/turtle-headed-pipe.js +37 -0
- package/dist/lang/ast/types/type-desc.d.ts +7 -0
- package/dist/lang/ast/types/type-desc.js +25 -0
- package/dist/lang/field-utils.d.ts +5 -0
- package/dist/lang/field-utils.js +43 -0
- package/dist/lang/index.d.ts +10 -0
- package/dist/lang/index.js +32 -0
- package/dist/lang/lib/Malloy/MalloyLexer.d.ts +165 -0
- package/dist/lang/lib/Malloy/MalloyLexer.js +1232 -0
- package/dist/lang/lib/Malloy/MalloyParser.d.ts +1947 -0
- package/dist/lang/lib/Malloy/MalloyParser.js +11909 -0
- package/dist/lang/lib/Malloy/MalloyParserListener.d.ts +2022 -0
- package/dist/lang/lib/Malloy/MalloyParserListener.js +4 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.d.ts +1274 -0
- package/dist/lang/lib/Malloy/MalloyParserVisitor.js +4 -0
- package/dist/lang/malloy-to-ast.d.ts +155 -0
- package/dist/lang/malloy-to-ast.js +990 -0
- package/dist/lang/parse-error-handler.d.ts +9 -0
- package/dist/lang/parse-error-handler.js +44 -0
- package/dist/lang/parse-log.d.ts +27 -0
- package/dist/lang/parse-log.js +51 -0
- package/dist/lang/parse-malloy.d.ts +182 -0
- package/dist/lang/parse-malloy.js +728 -0
- package/dist/lang/parse-tree-walkers/document-completion-walker.d.ts +10 -0
- package/dist/lang/parse-tree-walkers/document-completion-walker.js +148 -0
- package/dist/lang/parse-tree-walkers/document-help-context-walker.d.ts +9 -0
- package/dist/lang/parse-tree-walkers/document-help-context-walker.js +107 -0
- package/dist/lang/parse-tree-walkers/document-highlight-walker.d.ts +83 -0
- package/dist/lang/parse-tree-walkers/document-highlight-walker.js +385 -0
- package/dist/lang/parse-tree-walkers/document-symbol-walker.d.ts +11 -0
- package/dist/lang/parse-tree-walkers/document-symbol-walker.js +182 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.d.ts +34 -0
- package/dist/lang/parse-tree-walkers/explore-query-walker.js +74 -0
- package/dist/lang/parse-tree-walkers/find-external-references.d.ts +11 -0
- package/dist/lang/parse-tree-walkers/find-external-references.js +61 -0
- package/dist/lang/reference-list.d.ts +10 -0
- package/dist/lang/reference-list.js +90 -0
- package/dist/lang/test/document-help-context-walker.spec.d.ts +1 -0
- package/dist/lang/test/document-help-context-walker.spec.js +55 -0
- package/dist/lang/test/document-symbol-walker.spec.d.ts +1 -0
- package/dist/lang/test/document-symbol-walker.spec.js +110 -0
- package/dist/lang/test/field-symbols.spec.d.ts +1 -0
- package/dist/lang/test/field-symbols.spec.js +184 -0
- package/dist/lang/test/parse.spec.d.ts +14 -0
- package/dist/lang/test/parse.spec.js +2135 -0
- package/dist/lang/test/test-translator.d.ts +41 -0
- package/dist/lang/test/test-translator.js +344 -0
- package/dist/lang/translate-response.d.ts +59 -0
- package/dist/lang/translate-response.js +30 -0
- package/dist/lang/zone.d.ts +57 -0
- package/dist/lang/zone.js +107 -0
- package/dist/malloy.d.ts +1146 -0
- package/dist/malloy.js +2413 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/index.js +45 -0
- package/dist/model/malloy_query.d.ts +351 -0
- package/dist/model/malloy_query.js +3174 -0
- package/dist/model/malloy_types.d.ts +551 -0
- package/dist/model/malloy_types.js +378 -0
- package/dist/model/sql_block.d.ts +7 -0
- package/dist/model/sql_block.js +56 -0
- package/dist/model/utils.d.ts +22 -0
- package/dist/model/utils.js +102 -0
- package/dist/run_sql_options.d.ts +3 -0
- package/dist/run_sql_options.js +25 -0
- package/dist/runtime_types.d.ts +105 -0
- package/dist/runtime_types.js +25 -0
- package/package.json +2 -2
|
@@ -0,0 +1,728 @@
|
|
|
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.MalloyTranslator = exports.MalloyTranslation = void 0;
|
|
49
|
+
const antlr4ts_1 = require("antlr4ts");
|
|
50
|
+
const MalloyLexer_1 = require("./lib/Malloy/MalloyLexer");
|
|
51
|
+
const MalloyParser_1 = require("./lib/Malloy/MalloyParser");
|
|
52
|
+
const ast = __importStar(require("./ast"));
|
|
53
|
+
const malloy_to_ast_1 = require("./malloy-to-ast");
|
|
54
|
+
const parse_log_1 = require("./parse-log");
|
|
55
|
+
const find_external_references_1 = require("./parse-tree-walkers/find-external-references");
|
|
56
|
+
const zone_1 = require("./zone");
|
|
57
|
+
const document_symbol_walker_1 = require("./parse-tree-walkers/document-symbol-walker");
|
|
58
|
+
const document_highlight_walker_1 = require("./parse-tree-walkers/document-highlight-walker");
|
|
59
|
+
const document_completion_walker_1 = require("./parse-tree-walkers/document-completion-walker");
|
|
60
|
+
const document_help_context_walker_1 = require("./parse-tree-walkers/document-help-context-walker");
|
|
61
|
+
const reference_list_1 = require("./reference-list");
|
|
62
|
+
const translate_response_1 = require("./translate-response");
|
|
63
|
+
const parse_error_handler_1 = require("./parse-error-handler");
|
|
64
|
+
/**
|
|
65
|
+
* This ignores a -> popMode when the mode stack is empty, which is a hack,
|
|
66
|
+
* but it let's us parse }%
|
|
67
|
+
*/
|
|
68
|
+
class HandlesOverpoppingLexer extends MalloyLexer_1.MalloyLexer {
|
|
69
|
+
popMode() {
|
|
70
|
+
if (this._modeStack.isEmpty) {
|
|
71
|
+
return this._mode;
|
|
72
|
+
}
|
|
73
|
+
return super.popMode();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
class ParseStep {
|
|
77
|
+
step(that) {
|
|
78
|
+
if (this.response) {
|
|
79
|
+
return this.response;
|
|
80
|
+
}
|
|
81
|
+
if (that.urlIsFullPath === undefined) {
|
|
82
|
+
try {
|
|
83
|
+
const _checkFull = new URL(that.sourceURL);
|
|
84
|
+
that.urlIsFullPath = true;
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
const msg = e instanceof Error ? e.message : "";
|
|
88
|
+
that.urlIsFullPath = false;
|
|
89
|
+
that.root.logger.log({
|
|
90
|
+
message: `Could not compute full path URL: ${msg}`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!that.urlIsFullPath) {
|
|
95
|
+
return that.fatalErrors();
|
|
96
|
+
}
|
|
97
|
+
const srcEnt = that.root.importZone.getEntry(that.sourceURL);
|
|
98
|
+
if (srcEnt.status !== "present") {
|
|
99
|
+
if (srcEnt.status === "error") {
|
|
100
|
+
const message = srcEnt.message.includes(that.sourceURL)
|
|
101
|
+
? `import error: ${srcEnt.message}`
|
|
102
|
+
: `import '${that.sourceURL}' error: ${srcEnt.message}`;
|
|
103
|
+
const at = srcEnt.firstReference || that.defaultLocation();
|
|
104
|
+
that.root.logger.log({ message, at });
|
|
105
|
+
this.response = that.fatalErrors();
|
|
106
|
+
return this.response;
|
|
107
|
+
}
|
|
108
|
+
return { urls: [that.sourceURL] };
|
|
109
|
+
}
|
|
110
|
+
const source = srcEnt.value == "" ? "\n" : srcEnt.value;
|
|
111
|
+
this.sourceInfo = this.getSourceInfo(source);
|
|
112
|
+
let parse;
|
|
113
|
+
try {
|
|
114
|
+
parse = this.runParser(source, that);
|
|
115
|
+
}
|
|
116
|
+
catch (parseException) {
|
|
117
|
+
that.root.logger.log({
|
|
118
|
+
message: `Malloy internal parser exception [${parseException.message}]`,
|
|
119
|
+
});
|
|
120
|
+
parse = undefined;
|
|
121
|
+
}
|
|
122
|
+
if (that.root.logger.hasErrors()) {
|
|
123
|
+
this.response = {
|
|
124
|
+
parse,
|
|
125
|
+
...that.fatalErrors(),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this.response = { parse };
|
|
130
|
+
}
|
|
131
|
+
return this.response;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Split the source up into lines so we can correctly compute offset
|
|
135
|
+
* to the line/char positions favored by LSP and VSCode.
|
|
136
|
+
*/
|
|
137
|
+
getSourceInfo(code) {
|
|
138
|
+
const eolRegex = /\r?\n/;
|
|
139
|
+
const info = {
|
|
140
|
+
at: [],
|
|
141
|
+
lines: [],
|
|
142
|
+
length: code.length,
|
|
143
|
+
};
|
|
144
|
+
let src = code;
|
|
145
|
+
let lineStart = 0;
|
|
146
|
+
while (src !== "") {
|
|
147
|
+
const eol = src.match(eolRegex);
|
|
148
|
+
if (eol && eol.index != undefined) {
|
|
149
|
+
// line text DOES NOT include the EOL
|
|
150
|
+
info.lines.push(src.slice(0, eol.index));
|
|
151
|
+
const lineLength = eol.index + eol[0].length;
|
|
152
|
+
info.at.push({
|
|
153
|
+
begin: lineStart,
|
|
154
|
+
end: lineStart + lineLength,
|
|
155
|
+
});
|
|
156
|
+
lineStart += lineLength;
|
|
157
|
+
src = src.slice(lineLength);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// last line, does not have a line end
|
|
161
|
+
info.lines.push(src);
|
|
162
|
+
info.at.push({ begin: lineStart, end: lineStart + src.length });
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return info;
|
|
167
|
+
}
|
|
168
|
+
runParser(source, that) {
|
|
169
|
+
const inputStream = antlr4ts_1.CharStreams.fromString(source);
|
|
170
|
+
const lexer = new HandlesOverpoppingLexer(inputStream);
|
|
171
|
+
const tokenStream = new antlr4ts_1.CommonTokenStream(lexer);
|
|
172
|
+
const malloyParser = new MalloyParser_1.MalloyParser(tokenStream);
|
|
173
|
+
malloyParser.removeErrorListeners();
|
|
174
|
+
malloyParser.addErrorListener(new parse_error_handler_1.MalloyParserErrorHandler(that, that.root.logger));
|
|
175
|
+
// Admitted code smell here, testing likes to parse from an arbitrary
|
|
176
|
+
// node and this is the simplest way to allow that.
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
+
const parseFunc = malloyParser[that.grammarRule];
|
|
179
|
+
if (!parseFunc) {
|
|
180
|
+
throw new Error(`No such parse rule as ${that.grammarRule}`);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
root: parseFunc.call(malloyParser),
|
|
184
|
+
tokenStream: tokenStream,
|
|
185
|
+
sourceStream: inputStream,
|
|
186
|
+
// TODO put the real version here
|
|
187
|
+
malloyVersion: "?.?.?-????",
|
|
188
|
+
subTranslator: that,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
class ImportsAndTablesStep {
|
|
193
|
+
constructor(parseStep) {
|
|
194
|
+
this.parseStep = parseStep;
|
|
195
|
+
this.alreadyLooked = false;
|
|
196
|
+
}
|
|
197
|
+
step(that) {
|
|
198
|
+
const parseReq = this.parseStep.step(that);
|
|
199
|
+
if (parseReq.parse == undefined) {
|
|
200
|
+
return parseReq;
|
|
201
|
+
}
|
|
202
|
+
if (!this.alreadyLooked) {
|
|
203
|
+
this.alreadyLooked = true;
|
|
204
|
+
const parseRefs = (0, find_external_references_1.findReferences)(that, parseReq.parse.tokenStream, parseReq.parse.root);
|
|
205
|
+
if (parseRefs === null || parseRefs === void 0 ? void 0 : parseRefs.tables) {
|
|
206
|
+
for (const ref in parseRefs.tables) {
|
|
207
|
+
that.root.schemaZone.reference(ref, {
|
|
208
|
+
url: that.sourceURL,
|
|
209
|
+
range: parseRefs.tables[ref],
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (parseRefs === null || parseRefs === void 0 ? void 0 : parseRefs.urls) {
|
|
214
|
+
for (const relativeRef in parseRefs.urls) {
|
|
215
|
+
const firstRef = parseRefs.urls[relativeRef];
|
|
216
|
+
try {
|
|
217
|
+
const ref = decodeURI(new URL(relativeRef, that.sourceURL).toString());
|
|
218
|
+
that.addChild(ref);
|
|
219
|
+
that.root.importZone.reference(ref, {
|
|
220
|
+
url: that.sourceURL,
|
|
221
|
+
range: firstRef,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
// This import spec is so bad the URL library threw up, this
|
|
226
|
+
// may be impossible, because it will append any garbage
|
|
227
|
+
// to the known good rootURL assuming it is relative
|
|
228
|
+
that.root.logger.log({
|
|
229
|
+
message: `Malformed URL '${relativeRef}'"`,
|
|
230
|
+
at: { url: that.sourceURL, range: firstRef },
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (that.root.logger.hasErrors()) {
|
|
237
|
+
// Since we knew we parsed without errors, this would only be from
|
|
238
|
+
// having a malformed URL on an import reference.
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
let allMissing = {};
|
|
242
|
+
const missingTables = that.root.schemaZone.getUndefined();
|
|
243
|
+
if (missingTables) {
|
|
244
|
+
allMissing = { tables: missingTables };
|
|
245
|
+
}
|
|
246
|
+
const missingImports = that.root.importZone.getUndefined();
|
|
247
|
+
if (missingImports) {
|
|
248
|
+
allMissing = { ...allMissing, urls: missingImports };
|
|
249
|
+
}
|
|
250
|
+
if ((0, translate_response_1.isNeedResponse)(allMissing)) {
|
|
251
|
+
return allMissing;
|
|
252
|
+
}
|
|
253
|
+
for (const child of that.childTranslators.values()) {
|
|
254
|
+
const kidNeeds = child.importsAndTablesStep.step(child);
|
|
255
|
+
if ((0, translate_response_1.isNeedResponse)(kidNeeds)) {
|
|
256
|
+
return kidNeeds;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
class ASTStep {
|
|
263
|
+
constructor(importStep) {
|
|
264
|
+
this.importStep = importStep;
|
|
265
|
+
this.walked = false;
|
|
266
|
+
}
|
|
267
|
+
step(that) {
|
|
268
|
+
if (this.response) {
|
|
269
|
+
return this.response;
|
|
270
|
+
}
|
|
271
|
+
const mustResolve = this.importStep.step(that);
|
|
272
|
+
if (mustResolve) {
|
|
273
|
+
return mustResolve;
|
|
274
|
+
}
|
|
275
|
+
const parseResponse = that.parseStep.response;
|
|
276
|
+
// Errors in self or children will show up here ..
|
|
277
|
+
if (that.root.logger.hasErrors()) {
|
|
278
|
+
this.response = that.fatalErrors();
|
|
279
|
+
return this.response;
|
|
280
|
+
}
|
|
281
|
+
const parse = parseResponse === null || parseResponse === void 0 ? void 0 : parseResponse.parse;
|
|
282
|
+
if (!parse) {
|
|
283
|
+
throw new Error("TRANSLATOR INTERNAL ERROR: Translator parse response had no errors, but also no parser");
|
|
284
|
+
}
|
|
285
|
+
const secondPass = new malloy_to_ast_1.MalloyToAST(parse, that.root.logger);
|
|
286
|
+
const newAst = secondPass.visit(parse.root);
|
|
287
|
+
if (that.root.logger.hasErrors()) {
|
|
288
|
+
this.response = that.fatalErrors();
|
|
289
|
+
return this.response;
|
|
290
|
+
}
|
|
291
|
+
if (newAst.elementType === "unimplemented") {
|
|
292
|
+
throw new Error("TRANSLATOR INTERNAL ERROR: Unimplemented AST node");
|
|
293
|
+
}
|
|
294
|
+
// I kind of think table refs should probably also be collected here
|
|
295
|
+
// instead of in the parse step. Note to myself, do that someday.
|
|
296
|
+
const sqlExplores = {};
|
|
297
|
+
if (!this.walked) {
|
|
298
|
+
newAst.walk((walkedTo) => {
|
|
299
|
+
if (walkedTo instanceof ast.SQLSource) {
|
|
300
|
+
if (!sqlExplores[walkedTo.refName]) {
|
|
301
|
+
sqlExplores[walkedTo.refName] = {};
|
|
302
|
+
}
|
|
303
|
+
sqlExplores[walkedTo.refName].ref = walkedTo;
|
|
304
|
+
}
|
|
305
|
+
else if (walkedTo instanceof ast.SQLStatement && walkedTo.is) {
|
|
306
|
+
if (!sqlExplores[walkedTo.is]) {
|
|
307
|
+
sqlExplores[walkedTo.is] = {};
|
|
308
|
+
}
|
|
309
|
+
sqlExplores[walkedTo.is].def = walkedTo;
|
|
310
|
+
}
|
|
311
|
+
else if (walkedTo instanceof ast.Unimplemented) {
|
|
312
|
+
walkedTo.log("INTERNAL COMPILER ERROR: Untranslated parse node");
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
this.walked = true;
|
|
316
|
+
}
|
|
317
|
+
// If there is a partial ast ...
|
|
318
|
+
if (that.root.logger.hasErrors()) {
|
|
319
|
+
this.response = that.fatalErrors();
|
|
320
|
+
return this.response;
|
|
321
|
+
}
|
|
322
|
+
/*
|
|
323
|
+
TODO we used to scna the AST for SQL blocks here, don't need to do that
|
|
324
|
+
becausae that happens at the translate step, but the code I need to
|
|
325
|
+
understand is how a root translate can return the need of a chiold
|
|
326
|
+
which has an SQL block ...
|
|
327
|
+
|
|
328
|
+
*/
|
|
329
|
+
// Now make sure that every child has fully translated itself
|
|
330
|
+
// before this tree is ready to also translate ...
|
|
331
|
+
for (const child of that.childTranslators.values()) {
|
|
332
|
+
const kidNeeds = child.astStep.step(child);
|
|
333
|
+
if ((0, translate_response_1.isNeedResponse)(kidNeeds)) {
|
|
334
|
+
return kidNeeds;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
newAst.setTranslator(that);
|
|
338
|
+
this.response = {
|
|
339
|
+
...that.errors(),
|
|
340
|
+
ast: newAst,
|
|
341
|
+
final: true,
|
|
342
|
+
};
|
|
343
|
+
return this.response;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
class MetadataStep {
|
|
347
|
+
constructor(parseStep) {
|
|
348
|
+
this.parseStep = parseStep;
|
|
349
|
+
}
|
|
350
|
+
step(that) {
|
|
351
|
+
if (!this.response) {
|
|
352
|
+
const tryParse = this.parseStep.step(that);
|
|
353
|
+
if (!tryParse.parse) {
|
|
354
|
+
return tryParse;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
// Wrap the parse tree walker in a try block -- if the parse is bad, this walk
|
|
358
|
+
// could result in unexpected errors due to the parse tree not looking as expected.
|
|
359
|
+
// We still want to attempt to walk the tree, to preserve document symbols even
|
|
360
|
+
// when there's a bad parse, but we also want to be safe about it.
|
|
361
|
+
let symbols;
|
|
362
|
+
try {
|
|
363
|
+
symbols = (0, document_symbol_walker_1.walkForDocumentSymbols)(that, tryParse.parse.tokenStream, tryParse.parse.root);
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
// Do nothing, symbols already `undefined`
|
|
367
|
+
}
|
|
368
|
+
let walkHighlights;
|
|
369
|
+
try {
|
|
370
|
+
walkHighlights = (0, document_highlight_walker_1.walkForDocumentHighlights)(tryParse.parse.tokenStream, tryParse.parse.root);
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
walkHighlights = [];
|
|
374
|
+
}
|
|
375
|
+
this.response = {
|
|
376
|
+
symbols,
|
|
377
|
+
highlights: (0, document_highlight_walker_1.sortHighlights)([
|
|
378
|
+
...(0, document_highlight_walker_1.passForHighlights)(tryParse.parse.tokenStream),
|
|
379
|
+
...walkHighlights,
|
|
380
|
+
]),
|
|
381
|
+
final: true,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return this.response;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
class CompletionsStep {
|
|
389
|
+
constructor(parseStep) {
|
|
390
|
+
this.parseStep = parseStep;
|
|
391
|
+
}
|
|
392
|
+
step(that, position) {
|
|
393
|
+
const tryParse = this.parseStep.step(that);
|
|
394
|
+
if (!tryParse.parse) {
|
|
395
|
+
return tryParse;
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
let completions = [];
|
|
399
|
+
if (position !== undefined) {
|
|
400
|
+
try {
|
|
401
|
+
completions = (0, document_completion_walker_1.walkForDocumentCompletions)(tryParse.parse.tokenStream, tryParse.parse.root, position);
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
/* Do nothing */
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
...tryParse,
|
|
409
|
+
completions,
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
class HelpContextStep {
|
|
415
|
+
constructor(parseStep) {
|
|
416
|
+
this.parseStep = parseStep;
|
|
417
|
+
}
|
|
418
|
+
step(that, position) {
|
|
419
|
+
const tryParse = this.parseStep.step(that);
|
|
420
|
+
if (!tryParse.parse) {
|
|
421
|
+
return tryParse;
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
let helpContext;
|
|
425
|
+
if (position !== undefined) {
|
|
426
|
+
try {
|
|
427
|
+
helpContext = (0, document_help_context_walker_1.walkForDocumentHelpContext)(tryParse.parse.root, position);
|
|
428
|
+
}
|
|
429
|
+
catch {
|
|
430
|
+
/* Do nothing */
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
...tryParse,
|
|
435
|
+
helpContext,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
class TranslateStep {
|
|
441
|
+
constructor(astStep) {
|
|
442
|
+
this.astStep = astStep;
|
|
443
|
+
}
|
|
444
|
+
step(that, extendingModel) {
|
|
445
|
+
if (this.response) {
|
|
446
|
+
return this.response;
|
|
447
|
+
}
|
|
448
|
+
const astResponse = this.astStep.step(that);
|
|
449
|
+
if ((0, translate_response_1.isNeedResponse)(astResponse)) {
|
|
450
|
+
return astResponse;
|
|
451
|
+
}
|
|
452
|
+
if (!astResponse.ast) {
|
|
453
|
+
this.response = astResponse;
|
|
454
|
+
return this.response;
|
|
455
|
+
}
|
|
456
|
+
if (that.grammarRule === "malloyDocument") {
|
|
457
|
+
if (astResponse.ast instanceof ast.Document) {
|
|
458
|
+
const doc = astResponse.ast;
|
|
459
|
+
doc.initModelDef(extendingModel);
|
|
460
|
+
for (;;) {
|
|
461
|
+
const docCompile = doc.compile();
|
|
462
|
+
if (docCompile.needs) {
|
|
463
|
+
return docCompile.needs;
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
that.modelDef = docCompile.modelDef;
|
|
467
|
+
that.queryList = docCompile.queryList;
|
|
468
|
+
that.sqlBlocks = docCompile.sqlBlocks;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
that.root.logger.log({
|
|
475
|
+
message: `'${that.sourceURL}' did not parse to malloy document`,
|
|
476
|
+
at: that.defaultLocation(),
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (that.root.logger.hasErrors()) {
|
|
481
|
+
this.response = that.fatalErrors();
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
this.response = {
|
|
485
|
+
translated: {
|
|
486
|
+
modelDef: that.modelDef,
|
|
487
|
+
queryList: that.queryList,
|
|
488
|
+
sqlBlocks: that.sqlBlocks,
|
|
489
|
+
},
|
|
490
|
+
...that.errors(),
|
|
491
|
+
final: true,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
return this.response;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
class MalloyTranslation {
|
|
498
|
+
constructor(sourceURL, grammarRule = "malloyDocument") {
|
|
499
|
+
this.sourceURL = sourceURL;
|
|
500
|
+
this.grammarRule = grammarRule;
|
|
501
|
+
this.queryList = [];
|
|
502
|
+
this.sqlBlocks = [];
|
|
503
|
+
this.childTranslators = new Map();
|
|
504
|
+
this.modelDef = {
|
|
505
|
+
name: sourceURL,
|
|
506
|
+
exports: [],
|
|
507
|
+
contents: {},
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* This is sort of the makefile for the translation, all the steps
|
|
511
|
+
* and the dependencies of the steps are declared here. Then when
|
|
512
|
+
* a translator method is called which needs the result of a step,
|
|
513
|
+
* it asks the step what it needs to complete, and all the right
|
|
514
|
+
* things will happen automatically.
|
|
515
|
+
*/
|
|
516
|
+
this.parseStep = new ParseStep();
|
|
517
|
+
this.metadataStep = new MetadataStep(this.parseStep);
|
|
518
|
+
this.completionsStep = new CompletionsStep(this.parseStep);
|
|
519
|
+
this.helpContextStep = new HelpContextStep(this.parseStep);
|
|
520
|
+
this.importsAndTablesStep = new ImportsAndTablesStep(this.parseStep);
|
|
521
|
+
this.astStep = new ASTStep(this.importsAndTablesStep);
|
|
522
|
+
this.translateStep = new TranslateStep(this.astStep);
|
|
523
|
+
this.references = new reference_list_1.ReferenceList(sourceURL);
|
|
524
|
+
}
|
|
525
|
+
addChild(url) {
|
|
526
|
+
if (!this.childTranslators.get(url)) {
|
|
527
|
+
this.childTranslators.set(url, new MalloyChildTranslator(url, this.root));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
addReference(reference) {
|
|
531
|
+
this.references.add(reference);
|
|
532
|
+
}
|
|
533
|
+
referenceAt(position) {
|
|
534
|
+
return this.references.find(position);
|
|
535
|
+
}
|
|
536
|
+
fatalErrors() {
|
|
537
|
+
return {
|
|
538
|
+
final: true,
|
|
539
|
+
errors: [...this.root.logger.getLog()],
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* The error log can grow as progressively deeper questions are asked.
|
|
544
|
+
* When returning "errors so far", make a snapshot.
|
|
545
|
+
*/
|
|
546
|
+
errors() {
|
|
547
|
+
const errors = this.root.logger.getLog();
|
|
548
|
+
return { errors: [...errors] };
|
|
549
|
+
}
|
|
550
|
+
getLineMap(url) {
|
|
551
|
+
var _a, _b;
|
|
552
|
+
if (url == this.sourceURL) {
|
|
553
|
+
return (_a = this.parseStep.sourceInfo) === null || _a === void 0 ? void 0 : _a.lines;
|
|
554
|
+
}
|
|
555
|
+
const theChild = this.childTranslators.get(url);
|
|
556
|
+
if (theChild) {
|
|
557
|
+
return (_b = theChild.parseStep.sourceInfo) === null || _b === void 0 ? void 0 : _b.lines;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
prettyErrors() {
|
|
561
|
+
let lovely = "";
|
|
562
|
+
let inFile = "";
|
|
563
|
+
for (const entry of this.root.logger.getLog()) {
|
|
564
|
+
let cooked = entry.message;
|
|
565
|
+
let errorURL = this.sourceURL;
|
|
566
|
+
if (entry.at) {
|
|
567
|
+
errorURL = entry.at.url;
|
|
568
|
+
const lineNo = entry.at.range.start.line;
|
|
569
|
+
const charFrom = entry.at.range.start.character;
|
|
570
|
+
const lines = this.getLineMap(entry.at.url);
|
|
571
|
+
if (lines) {
|
|
572
|
+
const errorLine = lines[lineNo];
|
|
573
|
+
cooked = `line ${lineNo + 1}: ${entry.message}\n | ${errorLine}`;
|
|
574
|
+
if (charFrom > 0) {
|
|
575
|
+
cooked = cooked + `\n | ${" ".repeat(charFrom)}^`;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
cooked = `line ${lineNo + 1}: char ${charFrom}: ${entry.message}`;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (inFile !== errorURL) {
|
|
583
|
+
cooked = `FILE: ${errorURL}\n` + cooked;
|
|
584
|
+
inFile = errorURL;
|
|
585
|
+
}
|
|
586
|
+
if (lovely !== "") {
|
|
587
|
+
lovely = `${lovely}\n${cooked}`;
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
lovely = cooked;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return lovely;
|
|
594
|
+
}
|
|
595
|
+
childRequest(importURL) {
|
|
596
|
+
var _a;
|
|
597
|
+
const childURL = decodeURI(new URL(importURL, this.sourceURL).toString());
|
|
598
|
+
const ret = (_a = this.childTranslators.get(childURL)) === null || _a === void 0 ? void 0 : _a.translate();
|
|
599
|
+
if (ret === null || ret === void 0 ? void 0 : ret.compileSQL) {
|
|
600
|
+
return {
|
|
601
|
+
compileSQL: ret.compileSQL,
|
|
602
|
+
partialModel: ret.partialModel,
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
getChildExports(importURL) {
|
|
607
|
+
const exports = {};
|
|
608
|
+
const childURL = decodeURI(new URL(importURL, this.sourceURL).toString());
|
|
609
|
+
const child = this.childTranslators.get(childURL);
|
|
610
|
+
if (child) {
|
|
611
|
+
const did = child.translate();
|
|
612
|
+
if (did.translated) {
|
|
613
|
+
for (const fromChild of child.modelDef.exports) {
|
|
614
|
+
const modelEntry = child.modelDef.contents[fromChild];
|
|
615
|
+
if (modelEntry.type === "struct") {
|
|
616
|
+
exports[fromChild] = modelEntry;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
// else nothing, assuming there are already errors in the log
|
|
621
|
+
}
|
|
622
|
+
return exports;
|
|
623
|
+
}
|
|
624
|
+
translate(extendingModel) {
|
|
625
|
+
if (this.finalAnswer) {
|
|
626
|
+
return this.finalAnswer;
|
|
627
|
+
}
|
|
628
|
+
const attempt = this.translateStep.step(this, extendingModel);
|
|
629
|
+
if (attempt.final) {
|
|
630
|
+
this.finalAnswer = attempt;
|
|
631
|
+
}
|
|
632
|
+
return attempt;
|
|
633
|
+
}
|
|
634
|
+
metadata() {
|
|
635
|
+
return this.metadataStep.step(this);
|
|
636
|
+
}
|
|
637
|
+
completions(position) {
|
|
638
|
+
return this.completionsStep.step(this, position);
|
|
639
|
+
}
|
|
640
|
+
helpContext(position) {
|
|
641
|
+
return this.helpContextStep.step(this, position);
|
|
642
|
+
}
|
|
643
|
+
defaultLocation() {
|
|
644
|
+
return {
|
|
645
|
+
url: this.sourceURL,
|
|
646
|
+
range: {
|
|
647
|
+
start: { line: 0, character: 0 },
|
|
648
|
+
end: { line: 0, character: 0 },
|
|
649
|
+
},
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
rangeFromContext(pcx) {
|
|
653
|
+
return this.rangeFromTokens(pcx.start, pcx.stop || pcx.start);
|
|
654
|
+
}
|
|
655
|
+
rangeFromTokens(startToken, stopToken) {
|
|
656
|
+
const start = {
|
|
657
|
+
line: startToken.line - 1,
|
|
658
|
+
character: startToken.charPositionInLine,
|
|
659
|
+
};
|
|
660
|
+
if (this.parseStep.sourceInfo && stopToken.stopIndex != -1) {
|
|
661
|
+
// Find the line which contains the stopIndex
|
|
662
|
+
const lastLine = this.parseStep.sourceInfo.lines.length - 1;
|
|
663
|
+
for (let lineNo = startToken.line - 1; lineNo <= lastLine; lineNo++) {
|
|
664
|
+
const at = this.parseStep.sourceInfo.at[lineNo];
|
|
665
|
+
if (stopToken.stopIndex >= at.begin && stopToken.stopIndex <= at.end) {
|
|
666
|
+
return {
|
|
667
|
+
start,
|
|
668
|
+
end: {
|
|
669
|
+
line: lineNo,
|
|
670
|
+
character: stopToken.stopIndex - at.begin + 1,
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
// Should be impossible to get here, but if we do ... return the last
|
|
676
|
+
// character of the last line of the file
|
|
677
|
+
return {
|
|
678
|
+
start,
|
|
679
|
+
end: {
|
|
680
|
+
line: lastLine,
|
|
681
|
+
character: this.parseStep.sourceInfo.lines[lastLine].length,
|
|
682
|
+
},
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
return { start, end: start };
|
|
686
|
+
}
|
|
687
|
+
rangeFromToken(token) {
|
|
688
|
+
return this.rangeFromTokens(token, token);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
exports.MalloyTranslation = MalloyTranslation;
|
|
692
|
+
class MalloyChildTranslator extends MalloyTranslation {
|
|
693
|
+
constructor(rootURL, root) {
|
|
694
|
+
super(rootURL);
|
|
695
|
+
this.root = root;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* The main interface to Malloy tranlsation. It has a call pattern
|
|
700
|
+
* similar to a server. Once a translator is instantiated
|
|
701
|
+
* you can request tralnsations repeatedly. Responses to that request
|
|
702
|
+
* will either be "NeedResponse" or "TranslateResponse" objects. The
|
|
703
|
+
* correct pattern is to call "translation" in a loop, calling
|
|
704
|
+
* "update" in response to each "NeedResponse" until a "TranslateResponse"
|
|
705
|
+
* is returned. If you get a response with "final:true", there is
|
|
706
|
+
* no need to call again, the translation is finished or error'd.
|
|
707
|
+
*/
|
|
708
|
+
class MalloyTranslator extends MalloyTranslation {
|
|
709
|
+
constructor(rootURL, preload = null) {
|
|
710
|
+
super(rootURL);
|
|
711
|
+
this.schemaZone = new zone_1.Zone();
|
|
712
|
+
this.importZone = new zone_1.Zone();
|
|
713
|
+
this.sqlQueryZone = new zone_1.Zone();
|
|
714
|
+
this.logger = new parse_log_1.MessageLog();
|
|
715
|
+
this.root = this;
|
|
716
|
+
if (preload) {
|
|
717
|
+
this.update(preload);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
update(dd) {
|
|
721
|
+
var _a, _b, _c;
|
|
722
|
+
this.schemaZone.updateFrom(dd.tables, (_a = dd.errors) === null || _a === void 0 ? void 0 : _a.tables);
|
|
723
|
+
this.importZone.updateFrom(dd.urls, (_b = dd.errors) === null || _b === void 0 ? void 0 : _b.urls);
|
|
724
|
+
this.sqlQueryZone.updateFrom(dd.compileSQL, (_c = dd.errors) === null || _c === void 0 ? void 0 : _c.compileSQL);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
exports.MalloyTranslator = MalloyTranslator;
|
|
728
|
+
//# sourceMappingURL=parse-malloy.js.map
|