@azx-pbc/axiom-compiler 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +415 -2
- package/dist/article.d.ts +12 -0
- package/dist/article.d.ts.map +1 -0
- package/dist/article.js +16 -0
- package/dist/article.js.map +1 -0
- package/dist/cli/args.d.ts +101 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +158 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/check.d.ts +2 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +33 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/compile.d.ts +2 -0
- package/dist/cli/compile.d.ts.map +1 -0
- package/dist/cli/compile.js +43 -0
- package/dist/cli/compile.js.map +1 -0
- package/dist/cli/count.d.ts +15 -0
- package/dist/cli/count.d.ts.map +1 -0
- package/dist/cli/count.js +21 -0
- package/dist/cli/count.js.map +1 -0
- package/dist/cli/dataset.d.ts +28 -0
- package/dist/cli/dataset.d.ts.map +1 -0
- package/dist/cli/dataset.js +115 -0
- package/dist/cli/dataset.js.map +1 -0
- package/dist/cli/diff.d.ts +2 -0
- package/dist/cli/diff.d.ts.map +1 -0
- package/dist/cli/diff.js +297 -0
- package/dist/cli/diff.js.map +1 -0
- package/dist/cli/explain.d.ts +2 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +95 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fields.d.ts +11 -0
- package/dist/cli/fields.d.ts.map +1 -0
- package/dist/cli/fields.js +13 -0
- package/dist/cli/fields.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +40 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/read.d.ts +56 -0
- package/dist/cli/read.d.ts.map +1 -0
- package/dist/cli/read.js +179 -0
- package/dist/cli/read.js.map +1 -0
- package/dist/cli/render.d.ts +58 -0
- package/dist/cli/render.d.ts.map +1 -0
- package/dist/cli/render.js +422 -0
- package/dist/cli/render.js.map +1 -0
- package/dist/cli/schema.d.ts +28 -0
- package/dist/cli/schema.d.ts.map +1 -0
- package/dist/cli/schema.js +46 -0
- package/dist/cli/schema.js.map +1 -0
- package/dist/cli/suite-report.d.ts +18 -0
- package/dist/cli/suite-report.d.ts.map +1 -0
- package/dist/cli/suite-report.js +58 -0
- package/dist/cli/suite-report.js.map +1 -0
- package/dist/cli/suites.d.ts +25 -0
- package/dist/cli/suites.d.ts.map +1 -0
- package/dist/cli/suites.js +67 -0
- package/dist/cli/suites.js.map +1 -0
- package/dist/cli/terminal.d.ts +45 -0
- package/dist/cli/terminal.d.ts.map +1 -0
- package/dist/cli/terminal.js +119 -0
- package/dist/cli/terminal.js.map +1 -0
- package/dist/cli/test.d.ts +12 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +199 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/cli/usage.d.ts +15 -0
- package/dist/cli/usage.d.ts.map +1 -0
- package/dist/cli/usage.js +95 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +1 -0
- package/dist/compile/artifact-members.d.ts +57 -0
- package/dist/compile/artifact-members.d.ts.map +1 -0
- package/dist/compile/artifact-members.js +130 -0
- package/dist/compile/artifact-members.js.map +1 -0
- package/dist/compile/artifact.d.ts +20 -0
- package/dist/compile/artifact.d.ts.map +1 -0
- package/dist/compile/artifact.js +87 -0
- package/dist/compile/artifact.js.map +1 -0
- package/dist/compile/compilation.d.ts +46 -0
- package/dist/compile/compilation.d.ts.map +1 -0
- package/dist/compile/compilation.js +4 -0
- package/dist/compile/compilation.js.map +1 -0
- package/dist/compile/computed.d.ts +22 -0
- package/dist/compile/computed.d.ts.map +1 -0
- package/dist/compile/computed.js +245 -0
- package/dist/compile/computed.js.map +1 -0
- package/dist/compile/condition-warnings.d.ts +12 -0
- package/dist/compile/condition-warnings.d.ts.map +1 -0
- package/dist/compile/condition-warnings.js +26 -0
- package/dist/compile/condition-warnings.js.map +1 -0
- package/dist/compile/conditions.d.ts +18 -0
- package/dist/compile/conditions.d.ts.map +1 -0
- package/dist/compile/conditions.js +22 -0
- package/dist/compile/conditions.js.map +1 -0
- package/dist/compile/cross-checks.d.ts +67 -0
- package/dist/compile/cross-checks.d.ts.map +1 -0
- package/dist/compile/cross-checks.js +238 -0
- package/dist/compile/cross-checks.js.map +1 -0
- package/dist/compile/datasets.d.ts +52 -0
- package/dist/compile/datasets.d.ts.map +1 -0
- package/dist/compile/datasets.js +183 -0
- package/dist/compile/datasets.js.map +1 -0
- package/dist/compile/dead-weight.d.ts +26 -0
- package/dist/compile/dead-weight.d.ts.map +1 -0
- package/dist/compile/dead-weight.js +244 -0
- package/dist/compile/dead-weight.js.map +1 -0
- package/dist/compile/declaration-rules.d.ts +54 -0
- package/dist/compile/declaration-rules.d.ts.map +1 -0
- package/dist/compile/declaration-rules.js +510 -0
- package/dist/compile/declaration-rules.js.map +1 -0
- package/dist/compile/declarations.d.ts +44 -0
- package/dist/compile/declarations.d.ts.map +1 -0
- package/dist/compile/declarations.js +160 -0
- package/dist/compile/declarations.js.map +1 -0
- package/dist/compile/document.d.ts +4 -0
- package/dist/compile/document.d.ts.map +1 -0
- package/dist/compile/document.js +13 -0
- package/dist/compile/document.js.map +1 -0
- package/dist/compile/expression.d.ts +38 -0
- package/dist/compile/expression.d.ts.map +1 -0
- package/dist/compile/expression.js +288 -0
- package/dist/compile/expression.js.map +1 -0
- package/dist/compile/hashes.d.ts +26 -0
- package/dist/compile/hashes.d.ts.map +1 -0
- package/dist/compile/hashes.js +96 -0
- package/dist/compile/hashes.js.map +1 -0
- package/dist/compile/item-targets.d.ts +12 -0
- package/dist/compile/item-targets.d.ts.map +1 -0
- package/dist/compile/item-targets.js +287 -0
- package/dist/compile/item-targets.js.map +1 -0
- package/dist/compile/messages.d.ts +8 -0
- package/dist/compile/messages.d.ts.map +1 -0
- package/dist/compile/messages.js +62 -0
- package/dist/compile/messages.js.map +1 -0
- package/dist/compile/option-availability.d.ts +51 -0
- package/dist/compile/option-availability.d.ts.map +1 -0
- package/dist/compile/option-availability.js +171 -0
- package/dist/compile/option-availability.js.map +1 -0
- package/dist/compile/option-codes.d.ts +27 -0
- package/dist/compile/option-codes.d.ts.map +1 -0
- package/dist/compile/option-codes.js +212 -0
- package/dist/compile/option-codes.js.map +1 -0
- package/dist/compile/references.d.ts +14 -0
- package/dist/compile/references.d.ts.map +1 -0
- package/dist/compile/references.js +126 -0
- package/dist/compile/references.js.map +1 -0
- package/dist/compile/rows-from.d.ts +27 -0
- package/dist/compile/rows-from.d.ts.map +1 -0
- package/dist/compile/rows-from.js +164 -0
- package/dist/compile/rows-from.js.map +1 -0
- package/dist/compile/rules.d.ts +58 -0
- package/dist/compile/rules.d.ts.map +1 -0
- package/dist/compile/rules.js +327 -0
- package/dist/compile/rules.js.map +1 -0
- package/dist/compile/suggestions.d.ts +52 -0
- package/dist/compile/suggestions.d.ts.map +1 -0
- package/dist/compile/suggestions.js +633 -0
- package/dist/compile/suggestions.js.map +1 -0
- package/dist/compile/targets.d.ts +22 -0
- package/dist/compile/targets.d.ts.map +1 -0
- package/dist/compile/targets.js +125 -0
- package/dist/compile/targets.js.map +1 -0
- package/dist/compile/types.d.ts +84 -0
- package/dist/compile/types.d.ts.map +1 -0
- package/dist/compile/types.js +2 -0
- package/dist/compile/types.js.map +1 -0
- package/dist/compile/warning.d.ts +45 -0
- package/dist/compile/warning.d.ts.map +1 -0
- package/dist/compile/warning.js +2 -0
- package/dist/compile/warning.js.map +1 -0
- package/dist/compile-yaml.d.ts +23 -0
- package/dist/compile-yaml.d.ts.map +1 -0
- package/dist/compile-yaml.js +30 -0
- package/dist/compile-yaml.js.map +1 -0
- package/dist/compile.d.ts +78 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +372 -0
- package/dist/compile.js.map +1 -0
- package/dist/csv/limits.d.ts +43 -0
- package/dist/csv/limits.d.ts.map +1 -0
- package/dist/csv/limits.js +51 -0
- package/dist/csv/limits.js.map +1 -0
- package/dist/csv/scalar.d.ts +33 -0
- package/dist/csv/scalar.d.ts.map +1 -0
- package/dist/csv/scalar.js +77 -0
- package/dist/csv/scalar.js.map +1 -0
- package/dist/datasets/csv.d.ts +46 -0
- package/dist/datasets/csv.d.ts.map +1 -0
- package/dist/datasets/csv.js +293 -0
- package/dist/datasets/csv.js.map +1 -0
- package/dist/datasets/declaration.d.ts +16 -0
- package/dist/datasets/declaration.d.ts.map +1 -0
- package/dist/datasets/declaration.js +104 -0
- package/dist/datasets/declaration.js.map +1 -0
- package/dist/datasets/diagnostics.d.ts +65 -0
- package/dist/datasets/diagnostics.d.ts.map +1 -0
- package/dist/datasets/diagnostics.js +2 -0
- package/dist/datasets/diagnostics.js.map +1 -0
- package/dist/datasets/diff.d.ts +46 -0
- package/dist/datasets/diff.d.ts.map +1 -0
- package/dist/datasets/diff.js +84 -0
- package/dist/datasets/diff.js.map +1 -0
- package/dist/datasets/document.d.ts +12 -0
- package/dist/datasets/document.d.ts.map +1 -0
- package/dist/datasets/document.js +382 -0
- package/dist/datasets/document.js.map +1 -0
- package/dist/datasets/index.d.ts +43 -0
- package/dist/datasets/index.d.ts.map +1 -0
- package/dist/datasets/index.js +68 -0
- package/dist/datasets/index.js.map +1 -0
- package/dist/datasets/repair.d.ts +26 -0
- package/dist/datasets/repair.d.ts.map +1 -0
- package/dist/datasets/repair.js +60 -0
- package/dist/datasets/repair.js.map +1 -0
- package/dist/document-path.d.ts +62 -0
- package/dist/document-path.d.ts.map +1 -0
- package/dist/document-path.js +200 -0
- package/dist/document-path.js.map +1 -0
- package/dist/expr/boundary.d.ts +8 -0
- package/dist/expr/boundary.d.ts.map +1 -0
- package/dist/expr/boundary.js +243 -0
- package/dist/expr/boundary.js.map +1 -0
- package/dist/expr/compile-expr.d.ts +35 -0
- package/dist/expr/compile-expr.d.ts.map +1 -0
- package/dist/expr/compile-expr.js +66 -0
- package/dist/expr/compile-expr.js.map +1 -0
- package/dist/expr/deprecation.d.ts +23 -0
- package/dist/expr/deprecation.d.ts.map +1 -0
- package/dist/expr/deprecation.js +28 -0
- package/dist/expr/deprecation.js.map +1 -0
- package/dist/expr/diagnostics.d.ts +31 -0
- package/dist/expr/diagnostics.d.ts.map +1 -0
- package/dist/expr/diagnostics.js +34 -0
- package/dist/expr/diagnostics.js.map +1 -0
- package/dist/expr/lexer.d.ts +49 -0
- package/dist/expr/lexer.d.ts.map +1 -0
- package/dist/expr/lexer.js +277 -0
- package/dist/expr/lexer.js.map +1 -0
- package/dist/expr/lint-warnings.d.ts +11 -0
- package/dist/expr/lint-warnings.d.ts.map +1 -0
- package/dist/expr/lint-warnings.js +20 -0
- package/dist/expr/lint-warnings.js.map +1 -0
- package/dist/expr/lint.d.ts +41 -0
- package/dist/expr/lint.d.ts.map +1 -0
- package/dist/expr/lint.js +1034 -0
- package/dist/expr/lint.js.map +1 -0
- package/dist/expr/parse/aggregates.d.ts +13 -0
- package/dist/expr/parse/aggregates.d.ts.map +1 -0
- package/dist/expr/parse/aggregates.js +48 -0
- package/dist/expr/parse/aggregates.js.map +1 -0
- package/dist/expr/parse/budget.d.ts +11 -0
- package/dist/expr/parse/budget.d.ts.map +1 -0
- package/dist/expr/parse/budget.js +57 -0
- package/dist/expr/parse/budget.js.map +1 -0
- package/dist/expr/parse/grammar.d.ts +9 -0
- package/dist/expr/parse/grammar.d.ts.map +1 -0
- package/dist/expr/parse/grammar.js +699 -0
- package/dist/expr/parse/grammar.js.map +1 -0
- package/dist/expr/parse/literals.d.ts +20 -0
- package/dist/expr/parse/literals.d.ts.map +1 -0
- package/dist/expr/parse/literals.js +132 -0
- package/dist/expr/parse/literals.js.map +1 -0
- package/dist/expr/parse/stream.d.ts +60 -0
- package/dist/expr/parse/stream.d.ts.map +1 -0
- package/dist/expr/parse/stream.js +151 -0
- package/dist/expr/parse/stream.js.map +1 -0
- package/dist/expr/parser.d.ts +45 -0
- package/dist/expr/parser.d.ts.map +1 -0
- package/dist/expr/parser.js +110 -0
- package/dist/expr/parser.js.map +1 -0
- package/dist/expr/print/spell.d.ts +78 -0
- package/dist/expr/print/spell.d.ts.map +1 -0
- package/dist/expr/print/spell.js +592 -0
- package/dist/expr/print/spell.js.map +1 -0
- package/dist/expr/print.d.ts +20 -0
- package/dist/expr/print.d.ts.map +1 -0
- package/dist/expr/print.js +102 -0
- package/dist/expr/print.js.map +1 -0
- package/dist/expr/suggest.d.ts +26 -0
- package/dist/expr/suggest.d.ts.map +1 -0
- package/dist/expr/suggest.js +77 -0
- package/dist/expr/suggest.js.map +1 -0
- package/dist/expr/typecheck/aggregates.d.ts +8 -0
- package/dist/expr/typecheck/aggregates.d.ts.map +1 -0
- package/dist/expr/typecheck/aggregates.js +334 -0
- package/dist/expr/typecheck/aggregates.js.map +1 -0
- package/dist/expr/typecheck/arithmetic.d.ts +6 -0
- package/dist/expr/typecheck/arithmetic.d.ts.map +1 -0
- package/dist/expr/typecheck/arithmetic.js +258 -0
- package/dist/expr/typecheck/arithmetic.js.map +1 -0
- package/dist/expr/typecheck/arity.d.ts +38 -0
- package/dist/expr/typecheck/arity.d.ts.map +1 -0
- package/dist/expr/typecheck/arity.js +173 -0
- package/dist/expr/typecheck/arity.js.map +1 -0
- package/dist/expr/typecheck/calls.d.ts +6 -0
- package/dist/expr/typecheck/calls.d.ts.map +1 -0
- package/dist/expr/typecheck/calls.js +137 -0
- package/dist/expr/typecheck/calls.js.map +1 -0
- package/dist/expr/typecheck/comparison.d.ts +13 -0
- package/dist/expr/typecheck/comparison.d.ts.map +1 -0
- package/dist/expr/typecheck/comparison.js +200 -0
- package/dist/expr/typecheck/comparison.js.map +1 -0
- package/dist/expr/typecheck/compound.d.ts +24 -0
- package/dist/expr/typecheck/compound.d.ts.map +1 -0
- package/dist/expr/typecheck/compound.js +175 -0
- package/dist/expr/typecheck/compound.js.map +1 -0
- package/dist/expr/typecheck/context.d.ts +44 -0
- package/dist/expr/typecheck/context.d.ts.map +1 -0
- package/dist/expr/typecheck/context.js +2 -0
- package/dist/expr/typecheck/context.js.map +1 -0
- package/dist/expr/typecheck/datasets.d.ts +17 -0
- package/dist/expr/typecheck/datasets.d.ts.map +1 -0
- package/dist/expr/typecheck/datasets.js +136 -0
- package/dist/expr/typecheck/datasets.js.map +1 -0
- package/dist/expr/typecheck/digest.d.ts +7 -0
- package/dist/expr/typecheck/digest.d.ts.map +1 -0
- package/dist/expr/typecheck/digest.js +44 -0
- package/dist/expr/typecheck/digest.js.map +1 -0
- package/dist/expr/typecheck/fold.d.ts +41 -0
- package/dist/expr/typecheck/fold.d.ts.map +1 -0
- package/dist/expr/typecheck/fold.js +71 -0
- package/dist/expr/typecheck/fold.js.map +1 -0
- package/dist/expr/typecheck/gate-folds.d.ts +22 -0
- package/dist/expr/typecheck/gate-folds.d.ts.map +1 -0
- package/dist/expr/typecheck/gate-folds.js +40 -0
- package/dist/expr/typecheck/gate-folds.js.map +1 -0
- package/dist/expr/typecheck/guards.d.ts +6 -0
- package/dist/expr/typecheck/guards.d.ts.map +1 -0
- package/dist/expr/typecheck/guards.js +38 -0
- package/dist/expr/typecheck/guards.js.map +1 -0
- package/dist/expr/typecheck/member.d.ts +17 -0
- package/dist/expr/typecheck/member.d.ts.map +1 -0
- package/dist/expr/typecheck/member.js +46 -0
- package/dist/expr/typecheck/member.js.map +1 -0
- package/dist/expr/typecheck/money.d.ts +8 -0
- package/dist/expr/typecheck/money.d.ts.map +1 -0
- package/dist/expr/typecheck/money.js +49 -0
- package/dist/expr/typecheck/money.js.map +1 -0
- package/dist/expr/typecheck/numeric.d.ts +8 -0
- package/dist/expr/typecheck/numeric.d.ts.map +1 -0
- package/dist/expr/typecheck/numeric.js +84 -0
- package/dist/expr/typecheck/numeric.js.map +1 -0
- package/dist/expr/typecheck/operands.d.ts +27 -0
- package/dist/expr/typecheck/operands.d.ts.map +1 -0
- package/dist/expr/typecheck/operands.js +106 -0
- package/dist/expr/typecheck/operands.js.map +1 -0
- package/dist/expr/typecheck/paths.d.ts +21 -0
- package/dist/expr/typecheck/paths.d.ts.map +1 -0
- package/dist/expr/typecheck/paths.js +321 -0
- package/dist/expr/typecheck/paths.js.map +1 -0
- package/dist/expr/typecheck/records.d.ts +24 -0
- package/dist/expr/typecheck/records.d.ts.map +1 -0
- package/dist/expr/typecheck/records.js +53 -0
- package/dist/expr/typecheck/records.js.map +1 -0
- package/dist/expr/typecheck/sequences.d.ts +15 -0
- package/dist/expr/typecheck/sequences.d.ts.map +1 -0
- package/dist/expr/typecheck/sequences.js +55 -0
- package/dist/expr/typecheck/sequences.js.map +1 -0
- package/dist/expr/typecheck/strings.d.ts +8 -0
- package/dist/expr/typecheck/strings.d.ts.map +1 -0
- package/dist/expr/typecheck/strings.js +188 -0
- package/dist/expr/typecheck/strings.js.map +1 -0
- package/dist/expr/typecheck/temporal.d.ts +7 -0
- package/dist/expr/typecheck/temporal.d.ts.map +1 -0
- package/dist/expr/typecheck/temporal.js +80 -0
- package/dist/expr/typecheck/temporal.js.map +1 -0
- package/dist/expr/typecheck/types.d.ts +163 -0
- package/dist/expr/typecheck/types.d.ts.map +1 -0
- package/dist/expr/typecheck/types.js +404 -0
- package/dist/expr/typecheck/types.js.map +1 -0
- package/dist/expr/typecheck.d.ts +75 -0
- package/dist/expr/typecheck.d.ts.map +1 -0
- package/dist/expr/typecheck.js +242 -0
- package/dist/expr/typecheck.js.map +1 -0
- package/dist/expr/undecided.d.ts +13 -0
- package/dist/expr/undecided.d.ts.map +1 -0
- package/dist/expr/undecided.js +58 -0
- package/dist/expr/undecided.js.map +1 -0
- package/dist/expr/values/code-points.d.ts +13 -0
- package/dist/expr/values/code-points.d.ts.map +1 -0
- package/dist/expr/values/code-points.js +25 -0
- package/dist/expr/values/code-points.js.map +1 -0
- package/dist/expr/values/inline.d.ts +77 -0
- package/dist/expr/values/inline.d.ts.map +1 -0
- package/dist/expr/values/inline.js +404 -0
- package/dist/expr/values/inline.js.map +1 -0
- package/dist/expr/values/interval.d.ts +19 -0
- package/dist/expr/values/interval.d.ts.map +1 -0
- package/dist/expr/values/interval.js +1180 -0
- package/dist/expr/values/interval.js.map +1 -0
- package/dist/index.d.ts +163 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest/document.d.ts +58 -0
- package/dist/ingest/document.d.ts.map +1 -0
- package/dist/ingest/document.js +83 -0
- package/dist/ingest/document.js.map +1 -0
- package/dist/ingest/yaml-document.d.ts +15 -0
- package/dist/ingest/yaml-document.d.ts.map +1 -0
- package/dist/ingest/yaml-document.js +42 -0
- package/dist/ingest/yaml-document.js.map +1 -0
- package/dist/ingest/yaml.d.ts +51 -0
- package/dist/ingest/yaml.d.ts.map +1 -0
- package/dist/ingest/yaml.js +340 -0
- package/dist/ingest/yaml.js.map +1 -0
- package/dist/layout/compile.d.ts +6 -0
- package/dist/layout/compile.d.ts.map +1 -0
- package/dist/layout/compile.js +224 -0
- package/dist/layout/compile.js.map +1 -0
- package/dist/layout/context.d.ts +12 -0
- package/dist/layout/context.d.ts.map +1 -0
- package/dist/layout/context.js +26 -0
- package/dist/layout/context.js.map +1 -0
- package/dist/layout/grammar.d.ts +34 -0
- package/dist/layout/grammar.d.ts.map +1 -0
- package/dist/layout/grammar.js +171 -0
- package/dist/layout/grammar.js.map +1 -0
- package/dist/layout/read.d.ts +54 -0
- package/dist/layout/read.d.ts.map +1 -0
- package/dist/layout/read.js +101 -0
- package/dist/layout/read.js.map +1 -0
- package/dist/layout/shape.d.ts +34 -0
- package/dist/layout/shape.d.ts.map +1 -0
- package/dist/layout/shape.js +149 -0
- package/dist/layout/shape.js.map +1 -0
- package/dist/messages/compile.d.ts +47 -0
- package/dist/messages/compile.d.ts.map +1 -0
- package/dist/messages/compile.js +202 -0
- package/dist/messages/compile.js.map +1 -0
- package/dist/messages/locale.d.ts +18 -0
- package/dist/messages/locale.d.ts.map +1 -0
- package/dist/messages/locale.js +33 -0
- package/dist/messages/locale.js.map +1 -0
- package/dist/messages/slots.d.ts +54 -0
- package/dist/messages/slots.d.ts.map +1 -0
- package/dist/messages/slots.js +137 -0
- package/dist/messages/slots.js.map +1 -0
- package/dist/overlay/compile-overlay.d.ts +29 -0
- package/dist/overlay/compile-overlay.d.ts.map +1 -0
- package/dist/overlay/compile-overlay.js +120 -0
- package/dist/overlay/compile-overlay.js.map +1 -0
- package/dist/overlay/compose.d.ts +26 -0
- package/dist/overlay/compose.d.ts.map +1 -0
- package/dist/overlay/compose.js +674 -0
- package/dist/overlay/compose.js.map +1 -0
- package/dist/overlay/types.d.ts +41 -0
- package/dist/overlay/types.d.ts.map +1 -0
- package/dist/overlay/types.js +2 -0
- package/dist/overlay/types.js.map +1 -0
- package/dist/publish/classify.d.ts +50 -0
- package/dist/publish/classify.d.ts.map +1 -0
- package/dist/publish/classify.js +85 -0
- package/dist/publish/classify.js.map +1 -0
- package/dist/publish/environment.d.ts +15 -0
- package/dist/publish/environment.d.ts.map +1 -0
- package/dist/publish/environment.js +2 -0
- package/dist/publish/environment.js.map +1 -0
- package/dist/publish/migrations.d.ts +108 -0
- package/dist/publish/migrations.d.ts.map +1 -0
- package/dist/publish/migrations.js +166 -0
- package/dist/publish/migrations.js.map +1 -0
- package/dist/publish/observation.d.ts +29 -0
- package/dist/publish/observation.d.ts.map +1 -0
- package/dist/publish/observation.js +43 -0
- package/dist/publish/observation.js.map +1 -0
- package/dist/publish/readiness.d.ts +197 -0
- package/dist/publish/readiness.d.ts.map +1 -0
- package/dist/publish/readiness.js +239 -0
- package/dist/publish/readiness.js.map +1 -0
- package/dist/publish/vectors.d.ts +50 -0
- package/dist/publish/vectors.d.ts.map +1 -0
- package/dist/publish/vectors.js +306 -0
- package/dist/publish/vectors.js.map +1 -0
- package/dist/publish/verify.d.ts +146 -0
- package/dist/publish/verify.d.ts.map +1 -0
- package/dist/publish/verify.js +548 -0
- package/dist/publish/verify.js.map +1 -0
- package/dist/scenarios/branch.d.ts +36 -0
- package/dist/scenarios/branch.d.ts.map +1 -0
- package/dist/scenarios/branch.js +30 -0
- package/dist/scenarios/branch.js.map +1 -0
- package/dist/scenarios/capture.d.ts +89 -0
- package/dist/scenarios/capture.d.ts.map +1 -0
- package/dist/scenarios/capture.js +443 -0
- package/dist/scenarios/capture.js.map +1 -0
- package/dist/scenarios/classifier.d.ts +20 -0
- package/dist/scenarios/classifier.d.ts.map +1 -0
- package/dist/scenarios/classifier.js +88 -0
- package/dist/scenarios/classifier.js.map +1 -0
- package/dist/scenarios/credit.d.ts +33 -0
- package/dist/scenarios/credit.d.ts.map +1 -0
- package/dist/scenarios/credit.js +330 -0
- package/dist/scenarios/credit.js.map +1 -0
- package/dist/scenarios/csv.d.ts +34 -0
- package/dist/scenarios/csv.d.ts.map +1 -0
- package/dist/scenarios/csv.js +1047 -0
- package/dist/scenarios/csv.js.map +1 -0
- package/dist/scenarios/data-identity.d.ts +39 -0
- package/dist/scenarios/data-identity.d.ts.map +1 -0
- package/dist/scenarios/data-identity.js +28 -0
- package/dist/scenarios/data-identity.js.map +1 -0
- package/dist/scenarios/document.d.ts +148 -0
- package/dist/scenarios/document.d.ts.map +1 -0
- package/dist/scenarios/document.js +513 -0
- package/dist/scenarios/document.js.map +1 -0
- package/dist/scenarios/environment.d.ts +64 -0
- package/dist/scenarios/environment.d.ts.map +1 -0
- package/dist/scenarios/environment.js +106 -0
- package/dist/scenarios/environment.js.map +1 -0
- package/dist/scenarios/evidence.d.ts +128 -0
- package/dist/scenarios/evidence.d.ts.map +1 -0
- package/dist/scenarios/evidence.js +179 -0
- package/dist/scenarios/evidence.js.map +1 -0
- package/dist/scenarios/expectations.d.ts +63 -0
- package/dist/scenarios/expectations.d.ts.map +1 -0
- package/dist/scenarios/expectations.js +490 -0
- package/dist/scenarios/expectations.js.map +1 -0
- package/dist/scenarios/references.d.ts +15 -0
- package/dist/scenarios/references.d.ts.map +1 -0
- package/dist/scenarios/references.js +239 -0
- package/dist/scenarios/references.js.map +1 -0
- package/dist/scenarios/report.d.ts +216 -0
- package/dist/scenarios/report.d.ts.map +1 -0
- package/dist/scenarios/report.js +54 -0
- package/dist/scenarios/report.js.map +1 -0
- package/dist/scenarios/runner.d.ts +55 -0
- package/dist/scenarios/runner.d.ts.map +1 -0
- package/dist/scenarios/runner.js +205 -0
- package/dist/scenarios/runner.js.map +1 -0
- package/dist/scenarios/vocabulary.d.ts +19 -0
- package/dist/scenarios/vocabulary.d.ts.map +1 -0
- package/dist/scenarios/vocabulary.js +56 -0
- package/dist/scenarios/vocabulary.js.map +1 -0
- package/dist/schema/catalogue.d.ts +54 -0
- package/dist/schema/catalogue.d.ts.map +1 -0
- package/dist/schema/catalogue.js +221 -0
- package/dist/schema/catalogue.js.map +1 -0
- package/dist/schema/check.d.ts +22 -0
- package/dist/schema/check.d.ts.map +1 -0
- package/dist/schema/check.js +30 -0
- package/dist/schema/check.js.map +1 -0
- package/dist/schema/closed.d.ts +19 -0
- package/dist/schema/closed.d.ts.map +1 -0
- package/dist/schema/closed.js +33 -0
- package/dist/schema/closed.js.map +1 -0
- package/dist/schema/collapse.d.ts +27 -0
- package/dist/schema/collapse.d.ts.map +1 -0
- package/dist/schema/collapse.js +143 -0
- package/dist/schema/collapse.js.map +1 -0
- package/dist/schema/controls.d.ts +46 -0
- package/dist/schema/controls.d.ts.map +1 -0
- package/dist/schema/controls.js +75 -0
- package/dist/schema/controls.js.map +1 -0
- package/dist/schema/dataset-declaration.d.ts +11 -0
- package/dist/schema/dataset-declaration.d.ts.map +1 -0
- package/dist/schema/dataset-declaration.js +11 -0
- package/dist/schema/dataset-declaration.js.map +1 -0
- package/dist/schema/declaration-warnings.d.ts +14 -0
- package/dist/schema/declaration-warnings.d.ts.map +1 -0
- package/dist/schema/declaration-warnings.js +77 -0
- package/dist/schema/declaration-warnings.js.map +1 -0
- package/dist/schema/declarations.d.ts +41 -0
- package/dist/schema/declarations.d.ts.map +1 -0
- package/dist/schema/declarations.js +1299 -0
- package/dist/schema/declarations.js.map +1 -0
- package/dist/schema/diagnostic.d.ts +118 -0
- package/dist/schema/diagnostic.d.ts.map +1 -0
- package/dist/schema/diagnostic.js +39 -0
- package/dist/schema/diagnostic.js.map +1 -0
- package/dist/schema/document.d.ts +93 -0
- package/dist/schema/document.d.ts.map +1 -0
- package/dist/schema/document.js +507 -0
- package/dist/schema/document.js.map +1 -0
- package/dist/schema/fields.d.ts +11 -0
- package/dist/schema/fields.d.ts.map +1 -0
- package/dist/schema/fields.js +265 -0
- package/dist/schema/fields.js.map +1 -0
- package/dist/schema/gates.d.ts +4 -0
- package/dist/schema/gates.d.ts.map +1 -0
- package/dist/schema/gates.js +68 -0
- package/dist/schema/gates.js.map +1 -0
- package/dist/schema/located.d.ts +27 -0
- package/dist/schema/located.d.ts.map +1 -0
- package/dist/schema/located.js +56 -0
- package/dist/schema/located.js.map +1 -0
- package/dist/schema/measurement.d.ts +9 -0
- package/dist/schema/measurement.d.ts.map +1 -0
- package/dist/schema/measurement.js +38 -0
- package/dist/schema/measurement.js.map +1 -0
- package/dist/schema/member-wording.d.ts +35 -0
- package/dist/schema/member-wording.d.ts.map +1 -0
- package/dist/schema/member-wording.js +286 -0
- package/dist/schema/member-wording.js.map +1 -0
- package/dist/schema/metaschema.d.ts +20 -0
- package/dist/schema/metaschema.d.ts.map +1 -0
- package/dist/schema/metaschema.js +476 -0
- package/dist/schema/metaschema.js.map +1 -0
- package/dist/schema/pointer.d.ts +31 -0
- package/dist/schema/pointer.d.ts.map +1 -0
- package/dist/schema/pointer.js +73 -0
- package/dist/schema/pointer.js.map +1 -0
- package/dist/schema/primary.d.ts +29 -0
- package/dist/schema/primary.d.ts.map +1 -0
- package/dist/schema/primary.js +48 -0
- package/dist/schema/primary.js.map +1 -0
- package/dist/schema/publish-vector.d.ts +17 -0
- package/dist/schema/publish-vector.d.ts.map +1 -0
- package/dist/schema/publish-vector.js +34 -0
- package/dist/schema/publish-vector.js.map +1 -0
- package/dist/schema/repair.d.ts +34 -0
- package/dist/schema/repair.d.ts.map +1 -0
- package/dist/schema/repair.js +163 -0
- package/dist/schema/repair.js.map +1 -0
- package/dist/schema/schema-v1.generated.d.ts +14 -0
- package/dist/schema/schema-v1.generated.d.ts.map +1 -0
- package/dist/schema/schema-v1.generated.js +7089 -0
- package/dist/schema/schema-v1.generated.js.map +1 -0
- package/dist/schema/screens.d.ts +4 -0
- package/dist/schema/screens.d.ts.map +1 -0
- package/dist/schema/screens.js +28 -0
- package/dist/schema/screens.js.map +1 -0
- package/dist/schema/test-values.d.ts +12 -0
- package/dist/schema/test-values.d.ts.map +1 -0
- package/dist/schema/test-values.js +97 -0
- package/dist/schema/test-values.js.map +1 -0
- package/dist/schema/unions.d.ts +46 -0
- package/dist/schema/unions.d.ts.map +1 -0
- package/dist/schema/unions.js +131 -0
- package/dist/schema/unions.js.map +1 -0
- package/dist/schema/validate-yaml.d.ts +14 -0
- package/dist/schema/validate-yaml.d.ts.map +1 -0
- package/dist/schema/validate-yaml.js +17 -0
- package/dist/schema/validate-yaml.js.map +1 -0
- package/dist/schema/validate.d.ts +46 -0
- package/dist/schema/validate.d.ts.map +1 -0
- package/dist/schema/validate.js +186 -0
- package/dist/schema/validate.js.map +1 -0
- package/dist/testing.d.ts +21 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +28 -0
- package/dist/testing.js.map +1 -0
- package/dist/vocabulary.d.ts +6 -0
- package/dist/vocabulary.d.ts.map +1 -0
- package/dist/vocabulary.js +26 -0
- package/dist/vocabulary.js.map +1 -0
- package/package.json +66 -3
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { ExpressionCompileError } from '../diagnostics.js';
|
|
2
|
+
import { isNumeric, isPrimitive, moneyDomainOf, moneySpellingName, primitiveType, quantityDomainOf, quantityName, durationDomainOf, durationUnitName, typeName, unify, unifyDuration, unifyMoney, unifyQuantity, } from './types.js';
|
|
3
|
+
/** `+`, `-`, `*` and `/`: string concatenation, unary negation, numeric widening, division or measurement arithmetic. */
|
|
4
|
+
export function arithmeticType(ctx, op, node) {
|
|
5
|
+
const types = node.args.map((arg) => ({ arg, type: ctx.check(arg) }));
|
|
6
|
+
if (op === '/' || op === '%' || op === '//')
|
|
7
|
+
return divisionType(ctx, op, node, types);
|
|
8
|
+
if (op === '*' && types.some(({ type }) => measuredKind(type) !== undefined)) {
|
|
9
|
+
return scalingType(ctx, node, types);
|
|
10
|
+
}
|
|
11
|
+
const quantity = types.find(({ type }) => isPrimitive(type, 'quantity'));
|
|
12
|
+
if (quantity !== undefined)
|
|
13
|
+
return quantityArithmetic(ctx, op, node, types);
|
|
14
|
+
const duration = types.find(({ type }) => isPrimitive(type, 'duration'));
|
|
15
|
+
if (duration !== undefined)
|
|
16
|
+
return durationArithmetic(ctx, op, node, types);
|
|
17
|
+
const money = types.find(({ type }) => isPrimitive(type, 'money'));
|
|
18
|
+
if (money !== undefined)
|
|
19
|
+
return moneyArithmetic(ctx, op, node, types);
|
|
20
|
+
if (op === '+' && types.length >= 2 && types.every(({ type }) => isPrimitive(type, 'string'))) {
|
|
21
|
+
return primitiveType('string');
|
|
22
|
+
}
|
|
23
|
+
if (op === '-' && types.length === 1) {
|
|
24
|
+
const [only] = types;
|
|
25
|
+
if (only === undefined || !isNumeric(only.type)) {
|
|
26
|
+
throw ctx.mismatch(node, `unary \`-\` requires a numeric operand, got ${typeName(only?.type ?? primitiveType('null'))}`);
|
|
27
|
+
}
|
|
28
|
+
return only.type;
|
|
29
|
+
}
|
|
30
|
+
let widened;
|
|
31
|
+
for (const { arg, type } of types) {
|
|
32
|
+
if (!isNumeric(type)) {
|
|
33
|
+
throw ctx.mismatch(arg, `\`${op}\` requires numeric operands, got ${typeName(type)}`);
|
|
34
|
+
}
|
|
35
|
+
widened = widened === undefined ? type : unify(widened, type);
|
|
36
|
+
}
|
|
37
|
+
return widened ?? primitiveType('integer');
|
|
38
|
+
}
|
|
39
|
+
/** The measured domain a type names, or `undefined` for a numeric or other value. */
|
|
40
|
+
function measuredKind(type) {
|
|
41
|
+
if (isPrimitive(type, 'money'))
|
|
42
|
+
return 'money';
|
|
43
|
+
if (isPrimitive(type, 'quantity'))
|
|
44
|
+
return 'quantity';
|
|
45
|
+
if (isPrimitive(type, 'duration'))
|
|
46
|
+
return 'duration';
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
/** The one sentence a squared or unnamed unit is refused with. */
|
|
50
|
+
function unitRefusal(ctx, node, op, left, right) {
|
|
51
|
+
throw ctx.mismatch(node, op === '*'
|
|
52
|
+
? `\`*\` cannot name the unit of ${left} × ${right}; multiply by a unit-less number (a quantity's \`q.value\` is one), or divide two values of one unit to get a plain ratio`
|
|
53
|
+
: `\`/\` cannot name the unit of ${left} ÷ ${right}; divide a measured value by a unit-less number to scale it (a quantity's \`q.value\` is one), or divide two values of one unit to get a plain ratio`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* `*` with one measured operand: a unit-less number scales the value and the unit travels with
|
|
57
|
+
* the result. Two measured operands would name a squared unit, which the language has no way to
|
|
58
|
+
* spell, so that pair is refused instead of silently producing a bare number.
|
|
59
|
+
*/
|
|
60
|
+
function scalingType(ctx, node, types) {
|
|
61
|
+
const measured = types.filter(({ type }) => measuredKind(type) !== undefined);
|
|
62
|
+
const only = measured[0];
|
|
63
|
+
if (measured.length !== 1 || only === undefined || types.length < 2) {
|
|
64
|
+
const [left, right] = types;
|
|
65
|
+
return unitRefusal(ctx, node, '*', measuredKind(left?.type ?? primitiveType('null')) ?? 'number', measuredKind(right?.type ?? primitiveType('null')) ?? 'number');
|
|
66
|
+
}
|
|
67
|
+
const kind = measuredKind(only.type);
|
|
68
|
+
for (const { arg, type } of types) {
|
|
69
|
+
if (type === only.type)
|
|
70
|
+
continue;
|
|
71
|
+
if (!isNumeric(type)) {
|
|
72
|
+
throw ctx.mismatch(arg, `\`*\` requires a unit-less number beside ${kind ?? 'a measured value'}, got ${typeName(type)}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return only.type;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* `/`: numeric division answers a `decimal`; two measured values of one unit answer the decimal
|
|
79
|
+
* ratio; and a measured value divided by a unit-less number keeps its unit and rounding target
|
|
80
|
+
* (`EXPR-11.1.14`). A bare number divided by a measured value names no unit and is refused.
|
|
81
|
+
*/
|
|
82
|
+
function divisionType(ctx, op, node, types) {
|
|
83
|
+
const [left, right] = types;
|
|
84
|
+
if (left === undefined || right === undefined) {
|
|
85
|
+
throw ctx.mismatch(node, 'this operator requires two operands');
|
|
86
|
+
}
|
|
87
|
+
if (op === '%' || op === '//') {
|
|
88
|
+
for (const { arg, type } of types) {
|
|
89
|
+
if (!isPrimitive(type, 'integer')) {
|
|
90
|
+
throw ctx.mismatch(arg, `\`${op}\` requires integer operands, got ${typeName(type)}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return primitiveType('integer');
|
|
94
|
+
}
|
|
95
|
+
const leftKind = measuredKind(left.type);
|
|
96
|
+
const rightKind = measuredKind(right.type);
|
|
97
|
+
if (leftKind !== undefined && rightKind !== undefined) {
|
|
98
|
+
if (leftKind !== rightKind) {
|
|
99
|
+
return unitRefusal(ctx, node, '/', leftKind, rightKind);
|
|
100
|
+
}
|
|
101
|
+
if (leftKind === 'money') {
|
|
102
|
+
let shared = moneyDomainOf(left.type);
|
|
103
|
+
const next = moneyDomainOf(right.type);
|
|
104
|
+
if (shared === undefined || next === undefined) {
|
|
105
|
+
throw ctx.mismatch(node, '`/` divides money by a unit-less number, so one operand must be money and the other unit-less');
|
|
106
|
+
}
|
|
107
|
+
const united = unifyMoney(shared, next);
|
|
108
|
+
if (united === undefined) {
|
|
109
|
+
throw ctx.mismatch(node, `\`/\` compares one money spelling, got ${moneySpellingName(shared)} and ${moneySpellingName(next)}`);
|
|
110
|
+
}
|
|
111
|
+
return primitiveType('decimal');
|
|
112
|
+
}
|
|
113
|
+
if (leftKind === 'quantity') {
|
|
114
|
+
const shared = quantityDomainOf(left.type);
|
|
115
|
+
const next = quantityDomainOf(right.type);
|
|
116
|
+
if (shared === undefined || next === undefined) {
|
|
117
|
+
throw ctx.mismatch(node, '`/` requires a quantity operand');
|
|
118
|
+
}
|
|
119
|
+
if (unifyQuantity(shared, next) === undefined) {
|
|
120
|
+
throw ctx.mismatch(node, `\`/\` divides one quantity unit, got ${quantityName(shared)} and ${quantityName(next)}`);
|
|
121
|
+
}
|
|
122
|
+
return primitiveType('decimal');
|
|
123
|
+
}
|
|
124
|
+
const shared = durationDomainOf(left.type);
|
|
125
|
+
const next = durationDomainOf(right.type);
|
|
126
|
+
if (shared === undefined || next === undefined) {
|
|
127
|
+
throw ctx.mismatch(node, '`/` requires a duration operand');
|
|
128
|
+
}
|
|
129
|
+
if (unifyDuration(shared, next) === undefined) {
|
|
130
|
+
throw ctx.mismatch(node, `\`/\` divides one duration unit, got ${durationUnitName(shared)} and ${durationUnitName(next)}`);
|
|
131
|
+
}
|
|
132
|
+
return primitiveType('decimal');
|
|
133
|
+
}
|
|
134
|
+
if (leftKind !== undefined) {
|
|
135
|
+
if (!isNumeric(right.type)) {
|
|
136
|
+
throw ctx.mismatch(right.arg, `\`/\` requires a unit-less number beside ${leftKind}, got ${typeName(right.type)}`);
|
|
137
|
+
}
|
|
138
|
+
return left.type;
|
|
139
|
+
}
|
|
140
|
+
if (rightKind !== undefined) {
|
|
141
|
+
return unitRefusal(ctx, node, '/', 'number', rightKind);
|
|
142
|
+
}
|
|
143
|
+
for (const { arg, type } of types) {
|
|
144
|
+
if (!isNumeric(type)) {
|
|
145
|
+
throw ctx.mismatch(arg, `\`/\` requires numeric operands, got ${typeName(type)}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return primitiveType('decimal');
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* `+` and `-` over quantities: every operand is a quantity and their declared unit sets share
|
|
152
|
+
* at least one unit (`MODEL-2.1.21`). A disjoint pair is a compile error naming both unit sets
|
|
153
|
+
* and the fields that declared them; an overlapping or unpinned set is decided by the values at
|
|
154
|
+
* runtime, where a different `unit` raises rather than converting. `*` and unary `-` are not
|
|
155
|
+
* quantity forms.
|
|
156
|
+
*/
|
|
157
|
+
function quantityArithmetic(ctx, op, node, types) {
|
|
158
|
+
if (op === '*' || (op === '-' && types.length === 1)) {
|
|
159
|
+
throw ctx.mismatch(node, `\`${op}\` is not defined on quantity; add or subtract quantities with \`+\` and \`-\`, and read \`q.value\` when a decimal is needed`);
|
|
160
|
+
}
|
|
161
|
+
const expected = types.find(({ type }) => isPrimitive(type, 'quantity'))?.type ?? primitiveType('quantity');
|
|
162
|
+
for (const { arg, type } of types) {
|
|
163
|
+
if (!isPrimitive(type, 'quantity')) {
|
|
164
|
+
throw ctx.mismatch(arg, `\`${op}\` requires operands of one domain, got ${typeName(type)} and ${typeName(expected)}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const nameOf = (domain) => `${quantityName(domain)}${domain.fieldId === undefined ? '' : ` on field \`${domain.fieldId}\``}`;
|
|
168
|
+
let shared = quantityDomainOf(types[0]?.type ?? primitiveType('null'));
|
|
169
|
+
if (shared === undefined)
|
|
170
|
+
throw ctx.mismatch(node, `\`${op}\` requires a quantity operand`);
|
|
171
|
+
for (const { type } of types.slice(1)) {
|
|
172
|
+
const next = quantityDomainOf(type);
|
|
173
|
+
if (next === undefined)
|
|
174
|
+
throw ctx.mismatch(node, `\`${op}\` requires a quantity operand`);
|
|
175
|
+
const united = unifyQuantity(shared, next);
|
|
176
|
+
if (united === undefined) {
|
|
177
|
+
throw ctx.mismatch(node, `\`${op}\` joins one unit, got ${nameOf(shared)} and ${nameOf(next)}; v1 defines no unit conversion`);
|
|
178
|
+
}
|
|
179
|
+
shared = {
|
|
180
|
+
...united,
|
|
181
|
+
...(shared.fieldId === next.fieldId && shared.fieldId !== undefined
|
|
182
|
+
? { fieldId: shared.fieldId }
|
|
183
|
+
: {}),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return primitiveType('quantity', undefined, false, shared);
|
|
187
|
+
}
|
|
188
|
+
/** `+` and `-` over durations: one declared unit, no conversion (`MODEL-2.1.24`). */
|
|
189
|
+
function durationArithmetic(ctx, op, node, types) {
|
|
190
|
+
if (op === '*' || (op === '-' && types.length === 1)) {
|
|
191
|
+
throw ctx.mismatch(node, `\`${op}\` is not defined on duration; add or subtract durations with \`+\` and \`-\`, or convert with duration_minutes`);
|
|
192
|
+
}
|
|
193
|
+
const expected = types.find(({ type }) => isPrimitive(type, 'duration'))?.type ?? primitiveType('duration');
|
|
194
|
+
for (const { arg, type } of types) {
|
|
195
|
+
if (!isPrimitive(type, 'duration')) {
|
|
196
|
+
throw ctx.mismatch(arg, `\`${op}\` requires operands of one domain, got ${typeName(type)} and ${typeName(expected)}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const nameOf = (domain) => `${durationUnitName(domain)}${domain.fieldId === undefined ? '' : ` on field \`${domain.fieldId}\``}`;
|
|
200
|
+
let shared = durationDomainOf(types[0]?.type ?? primitiveType('null'));
|
|
201
|
+
if (shared === undefined)
|
|
202
|
+
throw ctx.mismatch(node, `\`${op}\` requires a duration operand`);
|
|
203
|
+
for (const { type } of types.slice(1)) {
|
|
204
|
+
const next = durationDomainOf(type);
|
|
205
|
+
if (next === undefined)
|
|
206
|
+
throw ctx.mismatch(node, `\`${op}\` requires a duration operand`);
|
|
207
|
+
const united = unifyDuration(shared, next);
|
|
208
|
+
if (united === undefined) {
|
|
209
|
+
throw ctx.mismatch(node, `\`${op}\` joins one duration unit, got ${nameOf(shared)} and ${nameOf(next)}; v1 defines no unit conversion`);
|
|
210
|
+
}
|
|
211
|
+
shared = {
|
|
212
|
+
...united,
|
|
213
|
+
...(shared.fieldId === next.fieldId && shared.fieldId !== undefined
|
|
214
|
+
? { fieldId: shared.fieldId }
|
|
215
|
+
: {}),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return primitiveType('duration', undefined, false, undefined, shared);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* `+` and `-` over money: every operand is money and they share one spelling, the way `<=`
|
|
222
|
+
* compares one domain. A `*` with a money operand is the scaling form and is decided one
|
|
223
|
+
* function earlier, and unary `-` is not a money form an author can write (`EXPR-12.1.4`).
|
|
224
|
+
*
|
|
225
|
+
* A mismatch is the compiler's answer, and the refusal names both spellings. An `unknown`
|
|
226
|
+
* slot unifies with anything and makes the result `unknown`, so the runtime is then the one
|
|
227
|
+
* that refuses a value whose currency or scale differs from its neighbour's (`EXPR-12.1.3`).
|
|
228
|
+
*/
|
|
229
|
+
function moneyArithmetic(ctx, op, node, types) {
|
|
230
|
+
if (op === '-' && types.length === 1) {
|
|
231
|
+
throw new ExpressionCompileError('MONEY_ARITHMETIC', ctx.offsetOf(node), `\`${op}\` is not defined on money; add or subtract money with \`+\` and \`-\`, or convert with money_minor and money_from_minor`);
|
|
232
|
+
}
|
|
233
|
+
// A money operand pins the operator's domain, so a non-money neighbour is a mismatch that
|
|
234
|
+
// names both types (`EXPR-6.1.1`): the offending operand is decimal, and the expected one is
|
|
235
|
+
// the spelling it would have to share. Naming only the decimal operand left the author to
|
|
236
|
+
// guess what the operator wanted.
|
|
237
|
+
const expected = types.find(({ type }) => isPrimitive(type, 'money'))?.type ?? primitiveType('money');
|
|
238
|
+
for (const { arg, type } of types) {
|
|
239
|
+
if (!isPrimitive(type, 'money')) {
|
|
240
|
+
throw ctx.mismatch(arg, `\`${op}\` requires operands of one domain, got ${typeName(type)} and ${typeName(expected)}`);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
let shared = moneyDomainOf(types[0]?.type ?? primitiveType('null'));
|
|
244
|
+
if (shared === undefined)
|
|
245
|
+
throw ctx.mismatch(node, `\`${op}\` requires a money operand`);
|
|
246
|
+
for (const { type } of types.slice(1)) {
|
|
247
|
+
const next = moneyDomainOf(type);
|
|
248
|
+
if (next === undefined)
|
|
249
|
+
throw ctx.mismatch(node, `\`${op}\` requires a money operand`);
|
|
250
|
+
const united = unifyMoney(shared, next);
|
|
251
|
+
if (united === undefined) {
|
|
252
|
+
throw ctx.mismatch(node, `\`${op}\` compares one money spelling, got ${moneySpellingName(shared)} and ${moneySpellingName(next)}`);
|
|
253
|
+
}
|
|
254
|
+
shared = united;
|
|
255
|
+
}
|
|
256
|
+
return primitiveType('money', shared);
|
|
257
|
+
}
|
|
258
|
+
//# sourceMappingURL=arithmetic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arithmetic.js","sourceRoot":"","sources":["../../../src/expr/typecheck/arithmetic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAG3D,OAAO,EACL,SAAS,EACT,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,KAAK,EACL,aAAa,EACb,UAAU,EACV,aAAa,GACd,MAAM,YAAY,CAAC;AAEpB,yHAAyH;AACzH,MAAM,UAAU,cAAc,CAC5B,GAAiB,EACjB,EAAsC,EACtC,IAAc;IAEd,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACtE,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI;QAAE,OAAO,YAAY,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACvF,IAAI,EAAE,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,EAA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C,QAAQ,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAC7F,CAAC;QACJ,CAAC;IACH,CAAC;IACD,IAAI,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,IAAI,MAAM,KAAK,SAAS;QAAE,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,6BAA6B,CAAC,CAAC;IACzF,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,IAAI,KAAK,SAAS;YAAE,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,6BAA6B,CAAC,CAAC;QACvF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,GAAG,CAAC,QAAQ,CAChB,IAAI,EACJ,KAAK,EAAE,uCAAuC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,iBAAiB,CAAC,IAAI,CAAC,EAAE,CACzG,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,MAAM,CAAC;IAClB,CAAC;IACD,OAAO,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import type { CallNode, ExprNode } from '@azx-pbc/axiom-runtime';\nimport { ExpressionCompileError } from '../diagnostics.js';\nimport type { CheckContext } from './context.js';\nimport type { StaticType } from './types.js';\nimport {\n isNumeric,\n isPrimitive,\n moneyDomainOf,\n moneySpellingName,\n primitiveType,\n quantityDomainOf,\n quantityName,\n durationDomainOf,\n durationUnitName,\n typeName,\n unify,\n unifyDuration,\n unifyMoney,\n unifyQuantity,\n} from './types.js';\n\n/** `+`, `-`, `*` and `/`: string concatenation, unary negation, numeric widening, division or measurement arithmetic. */\nexport function arithmeticType(\n ctx: CheckContext,\n op: '+' | '-' | '*' | '/' | '%' | '//',\n node: CallNode,\n): StaticType {\n const types = node.args.map((arg) => ({ arg, type: ctx.check(arg) }));\n if (op === '/' || op === '%' || op === '//') return divisionType(ctx, op, node, types);\n if (op === '*' && types.some(({ type }) => measuredKind(type) !== undefined)) {\n return scalingType(ctx, node, types);\n }\n const quantity = types.find(({ type }) => isPrimitive(type, 'quantity'));\n if (quantity !== undefined) return quantityArithmetic(ctx, op, node, types);\n const duration = types.find(({ type }) => isPrimitive(type, 'duration'));\n if (duration !== undefined) return durationArithmetic(ctx, op, node, types);\n const money = types.find(({ type }) => isPrimitive(type, 'money'));\n if (money !== undefined) return moneyArithmetic(ctx, op, node, types);\n if (op === '+' && types.length >= 2 && types.every(({ type }) => isPrimitive(type, 'string'))) {\n return primitiveType('string');\n }\n if (op === '-' && types.length === 1) {\n const [only] = types;\n if (only === undefined || !isNumeric(only.type)) {\n throw ctx.mismatch(\n node,\n `unary \\`-\\` requires a numeric operand, got ${typeName(only?.type ?? primitiveType('null'))}`,\n );\n }\n return only.type;\n }\n let widened: StaticType | undefined;\n for (const { arg, type } of types) {\n if (!isNumeric(type)) {\n throw ctx.mismatch(arg, `\\`${op}\\` requires numeric operands, got ${typeName(type)}`);\n }\n widened = widened === undefined ? type : unify(widened, type);\n }\n return widened ?? primitiveType('integer');\n}\n\n/** The measured domain a type names, or `undefined` for a numeric or other value. */\nfunction measuredKind(type: StaticType): 'money' | 'quantity' | 'duration' | undefined {\n if (isPrimitive(type, 'money')) return 'money';\n if (isPrimitive(type, 'quantity')) return 'quantity';\n if (isPrimitive(type, 'duration')) return 'duration';\n return undefined;\n}\n\n/** The one sentence a squared or unnamed unit is refused with. */\nfunction unitRefusal(\n ctx: CheckContext,\n node: CallNode,\n op: '*' | '/',\n left: string,\n right: string,\n): never {\n throw ctx.mismatch(\n node,\n op === '*'\n ? `\\`*\\` cannot name the unit of ${left} × ${right}; multiply by a unit-less number (a quantity's \\`q.value\\` is one), or divide two values of one unit to get a plain ratio`\n : `\\`/\\` cannot name the unit of ${left} ÷ ${right}; divide a measured value by a unit-less number to scale it (a quantity's \\`q.value\\` is one), or divide two values of one unit to get a plain ratio`,\n );\n}\n\n/**\n * `*` with one measured operand: a unit-less number scales the value and the unit travels with\n * the result. Two measured operands would name a squared unit, which the language has no way to\n * spell, so that pair is refused instead of silently producing a bare number.\n */\nfunction scalingType(\n ctx: CheckContext,\n node: CallNode,\n types: readonly { readonly arg: ExprNode; readonly type: StaticType }[],\n): StaticType {\n const measured = types.filter(({ type }) => measuredKind(type) !== undefined);\n const only = measured[0];\n if (measured.length !== 1 || only === undefined || types.length < 2) {\n const [left, right] = types;\n return unitRefusal(\n ctx,\n node,\n '*',\n measuredKind(left?.type ?? primitiveType('null')) ?? 'number',\n measuredKind(right?.type ?? primitiveType('null')) ?? 'number',\n );\n }\n const kind = measuredKind(only.type);\n for (const { arg, type } of types) {\n if (type === only.type) continue;\n if (!isNumeric(type)) {\n throw ctx.mismatch(\n arg,\n `\\`*\\` requires a unit-less number beside ${kind ?? 'a measured value'}, got ${typeName(type)}`,\n );\n }\n }\n return only.type;\n}\n\n/**\n * `/`: numeric division answers a `decimal`; two measured values of one unit answer the decimal\n * ratio; and a measured value divided by a unit-less number keeps its unit and rounding target\n * (`EXPR-11.1.14`). A bare number divided by a measured value names no unit and is refused.\n */\nfunction divisionType(\n ctx: CheckContext,\n op: '/' | '%' | '//',\n node: CallNode,\n types: readonly { readonly arg: ExprNode; readonly type: StaticType }[],\n): StaticType {\n const [left, right] = types;\n if (left === undefined || right === undefined) {\n throw ctx.mismatch(node, 'this operator requires two operands');\n }\n if (op === '%' || op === '//') {\n for (const { arg, type } of types) {\n if (!isPrimitive(type, 'integer')) {\n throw ctx.mismatch(arg, `\\`${op}\\` requires integer operands, got ${typeName(type)}`);\n }\n }\n return primitiveType('integer');\n }\n const leftKind = measuredKind(left.type);\n const rightKind = measuredKind(right.type);\n if (leftKind !== undefined && rightKind !== undefined) {\n if (leftKind !== rightKind) {\n return unitRefusal(ctx, node, '/', leftKind, rightKind);\n }\n if (leftKind === 'money') {\n let shared = moneyDomainOf(left.type);\n const next = moneyDomainOf(right.type);\n if (shared === undefined || next === undefined) {\n throw ctx.mismatch(\n node,\n '`/` divides money by a unit-less number, so one operand must be money and the other unit-less',\n );\n }\n const united = unifyMoney(shared, next);\n if (united === undefined) {\n throw ctx.mismatch(\n node,\n `\\`/\\` compares one money spelling, got ${moneySpellingName(shared)} and ${moneySpellingName(next)}`,\n );\n }\n return primitiveType('decimal');\n }\n if (leftKind === 'quantity') {\n const shared = quantityDomainOf(left.type);\n const next = quantityDomainOf(right.type);\n if (shared === undefined || next === undefined) {\n throw ctx.mismatch(node, '`/` requires a quantity operand');\n }\n if (unifyQuantity(shared, next) === undefined) {\n throw ctx.mismatch(\n node,\n `\\`/\\` divides one quantity unit, got ${quantityName(shared)} and ${quantityName(next)}`,\n );\n }\n return primitiveType('decimal');\n }\n const shared = durationDomainOf(left.type);\n const next = durationDomainOf(right.type);\n if (shared === undefined || next === undefined) {\n throw ctx.mismatch(node, '`/` requires a duration operand');\n }\n if (unifyDuration(shared, next) === undefined) {\n throw ctx.mismatch(\n node,\n `\\`/\\` divides one duration unit, got ${durationUnitName(shared)} and ${durationUnitName(next)}`,\n );\n }\n return primitiveType('decimal');\n }\n if (leftKind !== undefined) {\n if (!isNumeric(right.type)) {\n throw ctx.mismatch(\n right.arg,\n `\\`/\\` requires a unit-less number beside ${leftKind}, got ${typeName(right.type)}`,\n );\n }\n return left.type;\n }\n if (rightKind !== undefined) {\n return unitRefusal(ctx, node, '/', 'number', rightKind);\n }\n for (const { arg, type } of types) {\n if (!isNumeric(type)) {\n throw ctx.mismatch(arg, `\\`/\\` requires numeric operands, got ${typeName(type)}`);\n }\n }\n return primitiveType('decimal');\n}\n\n/**\n * `+` and `-` over quantities: every operand is a quantity and their declared unit sets share\n * at least one unit (`MODEL-2.1.21`). A disjoint pair is a compile error naming both unit sets\n * and the fields that declared them; an overlapping or unpinned set is decided by the values at\n * runtime, where a different `unit` raises rather than converting. `*` and unary `-` are not\n * quantity forms.\n */\nfunction quantityArithmetic(\n ctx: CheckContext,\n op: '+' | '-' | '*',\n node: CallNode,\n types: readonly { readonly arg: ExprNode; readonly type: StaticType }[],\n): StaticType {\n if (op === '*' || (op === '-' && types.length === 1)) {\n throw ctx.mismatch(\n node,\n `\\`${op}\\` is not defined on quantity; add or subtract quantities with \\`+\\` and \\`-\\`, and read \\`q.value\\` when a decimal is needed`,\n );\n }\n const expected =\n types.find(({ type }) => isPrimitive(type, 'quantity'))?.type ?? primitiveType('quantity');\n for (const { arg, type } of types) {\n if (!isPrimitive(type, 'quantity')) {\n throw ctx.mismatch(\n arg,\n `\\`${op}\\` requires operands of one domain, got ${typeName(type)} and ${typeName(expected)}`,\n );\n }\n }\n const nameOf = (domain: {\n readonly fieldId?: string;\n readonly units: readonly string[] | undefined;\n readonly scale: number | undefined;\n }): string =>\n `${quantityName(domain)}${domain.fieldId === undefined ? '' : ` on field \\`${domain.fieldId}\\``}`;\n let shared = quantityDomainOf(types[0]?.type ?? primitiveType('null'));\n if (shared === undefined) throw ctx.mismatch(node, `\\`${op}\\` requires a quantity operand`);\n for (const { type } of types.slice(1)) {\n const next = quantityDomainOf(type);\n if (next === undefined) throw ctx.mismatch(node, `\\`${op}\\` requires a quantity operand`);\n const united = unifyQuantity(shared, next);\n if (united === undefined) {\n throw ctx.mismatch(\n node,\n `\\`${op}\\` joins one unit, got ${nameOf(shared)} and ${nameOf(next)}; v1 defines no unit conversion`,\n );\n }\n shared = {\n ...united,\n ...(shared.fieldId === next.fieldId && shared.fieldId !== undefined\n ? { fieldId: shared.fieldId }\n : {}),\n };\n }\n return primitiveType('quantity', undefined, false, shared);\n}\n\n/** `+` and `-` over durations: one declared unit, no conversion (`MODEL-2.1.24`). */\nfunction durationArithmetic(\n ctx: CheckContext,\n op: '+' | '-' | '*',\n node: CallNode,\n types: readonly { readonly arg: ExprNode; readonly type: StaticType }[],\n): StaticType {\n if (op === '*' || (op === '-' && types.length === 1)) {\n throw ctx.mismatch(\n node,\n `\\`${op}\\` is not defined on duration; add or subtract durations with \\`+\\` and \\`-\\`, or convert with duration_minutes`,\n );\n }\n const expected =\n types.find(({ type }) => isPrimitive(type, 'duration'))?.type ?? primitiveType('duration');\n for (const { arg, type } of types) {\n if (!isPrimitive(type, 'duration')) {\n throw ctx.mismatch(\n arg,\n `\\`${op}\\` requires operands of one domain, got ${typeName(type)} and ${typeName(expected)}`,\n );\n }\n }\n const nameOf = (domain: {\n readonly fieldId?: string;\n readonly unit: string | undefined;\n }): string =>\n `${durationUnitName(domain)}${domain.fieldId === undefined ? '' : ` on field \\`${domain.fieldId}\\``}`;\n let shared = durationDomainOf(types[0]?.type ?? primitiveType('null'));\n if (shared === undefined) throw ctx.mismatch(node, `\\`${op}\\` requires a duration operand`);\n for (const { type } of types.slice(1)) {\n const next = durationDomainOf(type);\n if (next === undefined) throw ctx.mismatch(node, `\\`${op}\\` requires a duration operand`);\n const united = unifyDuration(shared, next);\n if (united === undefined) {\n throw ctx.mismatch(\n node,\n `\\`${op}\\` joins one duration unit, got ${nameOf(shared)} and ${nameOf(next)}; v1 defines no unit conversion`,\n );\n }\n shared = {\n ...united,\n ...(shared.fieldId === next.fieldId && shared.fieldId !== undefined\n ? { fieldId: shared.fieldId }\n : {}),\n };\n }\n return primitiveType('duration', undefined, false, undefined, shared);\n}\n\n/**\n * `+` and `-` over money: every operand is money and they share one spelling, the way `<=`\n * compares one domain. A `*` with a money operand is the scaling form and is decided one\n * function earlier, and unary `-` is not a money form an author can write (`EXPR-12.1.4`).\n *\n * A mismatch is the compiler's answer, and the refusal names both spellings. An `unknown`\n * slot unifies with anything and makes the result `unknown`, so the runtime is then the one\n * that refuses a value whose currency or scale differs from its neighbour's (`EXPR-12.1.3`).\n */\nfunction moneyArithmetic(\n ctx: CheckContext,\n op: '+' | '-' | '*',\n node: CallNode,\n types: readonly { readonly arg: ExprNode; readonly type: StaticType }[],\n): StaticType {\n if (op === '-' && types.length === 1) {\n throw new ExpressionCompileError(\n 'MONEY_ARITHMETIC',\n ctx.offsetOf(node),\n `\\`${op}\\` is not defined on money; add or subtract money with \\`+\\` and \\`-\\`, or convert with money_minor and money_from_minor`,\n );\n }\n // A money operand pins the operator's domain, so a non-money neighbour is a mismatch that\n // names both types (`EXPR-6.1.1`): the offending operand is decimal, and the expected one is\n // the spelling it would have to share. Naming only the decimal operand left the author to\n // guess what the operator wanted.\n const expected =\n types.find(({ type }) => isPrimitive(type, 'money'))?.type ?? primitiveType('money');\n for (const { arg, type } of types) {\n if (!isPrimitive(type, 'money')) {\n throw ctx.mismatch(\n arg,\n `\\`${op}\\` requires operands of one domain, got ${typeName(type)} and ${typeName(expected)}`,\n );\n }\n }\n let shared = moneyDomainOf(types[0]?.type ?? primitiveType('null'));\n if (shared === undefined) throw ctx.mismatch(node, `\\`${op}\\` requires a money operand`);\n for (const { type } of types.slice(1)) {\n const next = moneyDomainOf(type);\n if (next === undefined) throw ctx.mismatch(node, `\\`${op}\\` requires a money operand`);\n const united = unifyMoney(shared, next);\n if (united === undefined) {\n throw ctx.mismatch(\n node,\n `\\`${op}\\` compares one money spelling, got ${moneySpellingName(shared)} and ${moneySpellingName(next)}`,\n );\n }\n shared = united;\n }\n return primitiveType('money', shared);\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { BuiltinOperator, CallNode, CallOperator } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import type { CheckContext } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* How many operands one built-in takes.
|
|
5
|
+
*
|
|
6
|
+
* A fixed arity states `min` and `max` together; a variadic operator states `min` and omits
|
|
7
|
+
* `max`. Variadic is a property of an operator's signature, not a general escape hatch: an
|
|
8
|
+
* operator that is n-ary MUST state its upper bound, so a pathological document cannot build
|
|
9
|
+
* a call of unbounded width. Only `concat` is variadic today, with a bound of 32.
|
|
10
|
+
*/
|
|
11
|
+
export interface Arity {
|
|
12
|
+
/** The fewest operands the signature admits. */
|
|
13
|
+
readonly min: number;
|
|
14
|
+
/** The most it admits, or absent when the operator is variadic. */
|
|
15
|
+
readonly max?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function arityText(arity: Arity): string;
|
|
18
|
+
/**
|
|
19
|
+
* The arity one call operator's compiled node admits.
|
|
20
|
+
*
|
|
21
|
+
* One table serves the typechecker and the compiled-node boundary, so a node the boundary
|
|
22
|
+
* admits is one the checker's signature accepts: a metaschema-valid `call` may otherwise state
|
|
23
|
+
* `len` with two operands, and the boundary would pass it to an evaluator whose only defence is
|
|
24
|
+
* a second table. Arithmetic is stated here too, because `call` nodes carry `+`, `-` and `*`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function arityOf(op: CallOperator): Arity;
|
|
27
|
+
/**
|
|
28
|
+
* The bounds one callable built-in's signature admits, for the frozen-grammar gate.
|
|
29
|
+
*
|
|
30
|
+
* The grammar states each built-in's width; this is the same fact from the table the typechecker
|
|
31
|
+
* enforces, so `test/dsl/grammar-lock.test.ts` can compare the published production with the
|
|
32
|
+
* compiled behaviour. It is on `@azx-pbc/axiom-compiler/testing`, not a host door: a host has no
|
|
33
|
+
* reason to ask, and the signature belongs to the compile it already runs.
|
|
34
|
+
*/
|
|
35
|
+
export declare function builtinArity(name: BuiltinOperator): Arity;
|
|
36
|
+
/** Refuses a built-in called with a count outside its signature. */
|
|
37
|
+
export declare function requireArity(ctx: CheckContext, op: BuiltinOperator, node: CallNode): void;
|
|
38
|
+
//# sourceMappingURL=arity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arity.d.ts","sourceRoot":"","sources":["../../../src/expr/typecheck/arity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,KAAK;IACpB,gDAAgD;IAChD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAyGD,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAM9C;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,YAAY,GAAG,KAAK,CAG/C;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,eAAe,GAAG,KAAK,CAEzD;AA8BD,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,GAAG,IAAI,CAgBzF"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
const AGGREGATE_ARITY = { min: 1, max: 1 };
|
|
2
|
+
/**
|
|
3
|
+
* The bounds an infix arithmetic call node admits. The source grammar writes `+`, `-` and `*`
|
|
4
|
+
* infix and n-ary, so the compiled node carries at least one operand and has no fixed width;
|
|
5
|
+
* unary `-` is the one-operand spelling. `/` is the exception: it is binary and
|
|
6
|
+
* left-associative, so its node never states a run.
|
|
7
|
+
*/
|
|
8
|
+
const ARITHMETIC_ARITY = { min: 1 };
|
|
9
|
+
const DIVISION_ARITY = { min: 2, max: 2 };
|
|
10
|
+
/** Per-name arity. */
|
|
11
|
+
const ARITY = {
|
|
12
|
+
len: { min: 1, max: 1 },
|
|
13
|
+
lower: { min: 1, max: 1 },
|
|
14
|
+
upper: { min: 1, max: 1 },
|
|
15
|
+
trim: { min: 1, max: 1 },
|
|
16
|
+
starts_with: { min: 2, max: 2 },
|
|
17
|
+
ends_with: { min: 2, max: 2 },
|
|
18
|
+
contains: { min: 2, max: 2 },
|
|
19
|
+
between: { min: 3, max: 3 },
|
|
20
|
+
ascii_match: { min: 2, max: 2 },
|
|
21
|
+
is_email: { min: 1, max: 1 },
|
|
22
|
+
is_phone: { min: 1, max: 1 },
|
|
23
|
+
is_url: { min: 1, max: 1 },
|
|
24
|
+
is_unique: { min: 1, max: 2 },
|
|
25
|
+
all: AGGREGATE_ARITY,
|
|
26
|
+
any: AGGREGATE_ARITY,
|
|
27
|
+
present: { min: 1, max: 1 },
|
|
28
|
+
absent: { min: 1, max: 1 },
|
|
29
|
+
empty: { min: 1, max: 1 },
|
|
30
|
+
is_relevant: { min: 1, max: 1 },
|
|
31
|
+
sum: AGGREGATE_ARITY,
|
|
32
|
+
count_where: AGGREGATE_ARITY,
|
|
33
|
+
count_distinct: { min: 1, max: 1 },
|
|
34
|
+
min: AGGREGATE_ARITY,
|
|
35
|
+
max: AGGREGATE_ARITY,
|
|
36
|
+
to_decimal: { min: 1, max: 1 },
|
|
37
|
+
to_string: { min: 1, max: 1 },
|
|
38
|
+
parse_integer: { min: 1, max: 1 },
|
|
39
|
+
parse_decimal: { min: 1, max: 1 },
|
|
40
|
+
round: { min: 2, max: 2 },
|
|
41
|
+
round_up: { min: 2, max: 2 },
|
|
42
|
+
round_down: { min: 2, max: 2 },
|
|
43
|
+
round_even: { min: 2, max: 2 },
|
|
44
|
+
pow: { min: 2, max: 2 },
|
|
45
|
+
money_minor: { min: 1, max: 1 },
|
|
46
|
+
money_from_minor: { min: 4, max: 4 },
|
|
47
|
+
money_currency: { min: 1, max: 1 },
|
|
48
|
+
money_scale: { min: 1, max: 1 },
|
|
49
|
+
add_days: { min: 2, max: 2 },
|
|
50
|
+
add_months: { min: 2, max: 2 },
|
|
51
|
+
add_minutes: { min: 2, max: 2 },
|
|
52
|
+
days_between: { min: 2, max: 2 },
|
|
53
|
+
months_between: { min: 2, max: 2 },
|
|
54
|
+
minutes_between: { min: 2, max: 2 },
|
|
55
|
+
duration_minutes: { min: 1, max: 1 },
|
|
56
|
+
duration_seconds: { min: 1, max: 1 },
|
|
57
|
+
in_set: { min: 2, max: 3 },
|
|
58
|
+
lookup: { min: 2, max: 3 },
|
|
59
|
+
decide_keys: { min: 2, max: 3 },
|
|
60
|
+
digest: { min: 2, max: 2 },
|
|
61
|
+
member: { min: 2, max: 2 },
|
|
62
|
+
keys: { min: 1, max: 1 },
|
|
63
|
+
values: { min: 1, max: 1 },
|
|
64
|
+
has_cap: { min: 1, max: 1 },
|
|
65
|
+
rule_ok: { min: 1, max: 1 },
|
|
66
|
+
no_blocking: { min: 1, max: 1 },
|
|
67
|
+
rule_ok_in: { min: 1, max: 1 },
|
|
68
|
+
no_blocking_in: { min: 1, max: 1 },
|
|
69
|
+
required_in: { min: 1, max: 1 },
|
|
70
|
+
abs: { min: 1, max: 1 },
|
|
71
|
+
ceil: { min: 1, max: 1 },
|
|
72
|
+
floor: { min: 1, max: 1 },
|
|
73
|
+
avg: AGGREGATE_ARITY,
|
|
74
|
+
median: AGGREGATE_ARITY,
|
|
75
|
+
first: AGGREGATE_ARITY,
|
|
76
|
+
last: AGGREGATE_ARITY,
|
|
77
|
+
replace: { min: 3, max: 3 },
|
|
78
|
+
split: { min: 2, max: 2 },
|
|
79
|
+
join: { min: 2, max: 2 },
|
|
80
|
+
substring: { min: 3, max: 3 },
|
|
81
|
+
index_of: { min: 2, max: 2 },
|
|
82
|
+
add_years: { min: 2, max: 2 },
|
|
83
|
+
start_of_day: { min: 1, max: 1 },
|
|
84
|
+
civil_date: { min: 1, max: 1 },
|
|
85
|
+
matches: { min: 2, max: 3 },
|
|
86
|
+
map: AGGREGATE_ARITY,
|
|
87
|
+
filter: AGGREGATE_ARITY,
|
|
88
|
+
mode: AGGREGATE_ARITY,
|
|
89
|
+
concat: { min: 2, max: 32 },
|
|
90
|
+
year: { min: 1, max: 1 },
|
|
91
|
+
month: { min: 1, max: 1 },
|
|
92
|
+
day: { min: 1, max: 1 },
|
|
93
|
+
weekday: { min: 1, max: 1 },
|
|
94
|
+
parse_date: { min: 1, max: 1 },
|
|
95
|
+
parse_instant: { min: 1, max: 1 },
|
|
96
|
+
sort: { min: 1, max: 1 },
|
|
97
|
+
slice: { min: 3, max: 3 },
|
|
98
|
+
distinct: { min: 1, max: 1 },
|
|
99
|
+
reverse: { min: 1, max: 1 },
|
|
100
|
+
};
|
|
101
|
+
export function arityText(arity) {
|
|
102
|
+
if (arity.max === undefined)
|
|
103
|
+
return `at least ${String(arity.min)} arguments`;
|
|
104
|
+
if (arity.min === arity.max) {
|
|
105
|
+
return `${String(arity.min)} argument${arity.min === 1 ? '' : 's'}`;
|
|
106
|
+
}
|
|
107
|
+
return `${String(arity.min)} to ${String(arity.max)} arguments`;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The arity one call operator's compiled node admits.
|
|
111
|
+
*
|
|
112
|
+
* One table serves the typechecker and the compiled-node boundary, so a node the boundary
|
|
113
|
+
* admits is one the checker's signature accepts: a metaschema-valid `call` may otherwise state
|
|
114
|
+
* `len` with two operands, and the boundary would pass it to an evaluator whose only defence is
|
|
115
|
+
* a second table. Arithmetic is stated here too, because `call` nodes carry `+`, `-` and `*`.
|
|
116
|
+
*/
|
|
117
|
+
export function arityOf(op) {
|
|
118
|
+
if (op === '/' || op === '%' || op === '//')
|
|
119
|
+
return DIVISION_ARITY;
|
|
120
|
+
return op === '+' || op === '-' || op === '*' ? ARITHMETIC_ARITY : ARITY[op];
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The bounds one callable built-in's signature admits, for the frozen-grammar gate.
|
|
124
|
+
*
|
|
125
|
+
* The grammar states each built-in's width; this is the same fact from the table the typechecker
|
|
126
|
+
* enforces, so `test/dsl/grammar-lock.test.ts` can compare the published production with the
|
|
127
|
+
* compiled behaviour. It is on `@azx-pbc/axiom-compiler/testing`, not a host door: a host has no
|
|
128
|
+
* reason to ask, and the signature belongs to the compile it already runs.
|
|
129
|
+
*/
|
|
130
|
+
export function builtinArity(name) {
|
|
131
|
+
return ARITY[name];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The source form a short call most likely meant.
|
|
135
|
+
*
|
|
136
|
+
* A missing operand is otherwise reported only as a count, which tells an author that
|
|
137
|
+
* `starts_with(s)` is wrong without naming the operand the signature requires
|
|
138
|
+
* (`EXPR-11.1.4`). Each repair is a complete expression, so the diagnostics-repair gate can
|
|
139
|
+
* parse it.
|
|
140
|
+
*/
|
|
141
|
+
const SHORT_CALL_REPAIR = {
|
|
142
|
+
round: 'round(x, 2)',
|
|
143
|
+
round_up: 'round_up(x, 2)',
|
|
144
|
+
round_down: 'round_down(x, 2)',
|
|
145
|
+
round_even: 'round_even(x, 2)',
|
|
146
|
+
pow: 'pow(x, y)',
|
|
147
|
+
money_from_minor: 'money_from_minor(x, "AUD", 2, "half_up")',
|
|
148
|
+
between: 'between(x, low, high)',
|
|
149
|
+
starts_with: 'starts_with(s, p)',
|
|
150
|
+
ends_with: 'ends_with(s, p)',
|
|
151
|
+
contains: 'contains(s, p)',
|
|
152
|
+
};
|
|
153
|
+
/** The repair for a call whose extra operand states a rounding the signature does not take. */
|
|
154
|
+
const TOO_MANY_REPAIR = {
|
|
155
|
+
round: 'the rounding is the function name: write `round_up(x, 2)`, `round_down(x, 2)` or `round_even(x, 2)`',
|
|
156
|
+
pow: 'a stated scale is a composition: write `round(pow(a, b), places)`',
|
|
157
|
+
};
|
|
158
|
+
/** Refuses a built-in called with a count outside its signature. */
|
|
159
|
+
export function requireArity(ctx, op, node) {
|
|
160
|
+
const arity = ARITY[op];
|
|
161
|
+
const maximum = arity.max;
|
|
162
|
+
if (node.args.length < arity.min || (maximum !== undefined && node.args.length > maximum)) {
|
|
163
|
+
const tooMany = maximum !== undefined && node.args.length > maximum;
|
|
164
|
+
const extra = tooMany ? TOO_MANY_REPAIR[op] : undefined;
|
|
165
|
+
const repair = tooMany
|
|
166
|
+
? extra
|
|
167
|
+
: SHORT_CALL_REPAIR[op] === undefined
|
|
168
|
+
? undefined
|
|
169
|
+
: `write \`${SHORT_CALL_REPAIR[op]}\``;
|
|
170
|
+
throw ctx.mismatch(node, `\`${op}\` takes ${arityText(arity)}, found ${String(node.args.length)}${repair === undefined ? '' : `; ${repair}`}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=arity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arity.js","sourceRoot":"","sources":["../../../src/expr/typecheck/arity.ts"],"names":[],"mappings":"AAkBA,MAAM,eAAe,GAAU,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AAElD;;;;;GAKG;AACH,MAAM,gBAAgB,GAAU,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AAC3C,MAAM,cAAc,GAAU,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AAEjD,sBAAsB;AACtB,MAAM,KAAK,GAAmC;IAC5C,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IACvB,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IACzB,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IACzB,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IACxB,WAAW,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IAC/B,SAAS,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IAC7B,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IAC5B,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IAC3B,WAAW,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CA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AC,MAAM,CAAC,GAAG,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE,CACrH,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type { BuiltinOperator, CallNode, CallOperator } from '@azx-pbc/axiom-runtime';\nimport type { CheckContext } from './context.js';\n\n/**\n * How many operands one built-in takes.\n *\n * A fixed arity states `min` and `max` together; a variadic operator states `min` and omits\n * `max`. Variadic is a property of an operator's signature, not a general escape hatch: an\n * operator that is n-ary MUST state its upper bound, so a pathological document cannot build\n * a call of unbounded width. Only `concat` is variadic today, with a bound of 32.\n */\nexport interface Arity {\n /** The fewest operands the signature admits. */\n readonly min: number;\n /** The most it admits, or absent when the operator is variadic. */\n readonly max?: number;\n}\n\nconst AGGREGATE_ARITY: Arity = { min: 1, max: 1 };\n\n/**\n * The bounds an infix arithmetic call node admits. The source grammar writes `+`, `-` and `*`\n * infix and n-ary, so the compiled node carries at least one operand and has no fixed width;\n * unary `-` is the one-operand spelling. `/` is the exception: it is binary and\n * left-associative, so its node never states a run.\n */\nconst ARITHMETIC_ARITY: Arity = { min: 1 };\nconst DIVISION_ARITY: Arity = { min: 2, max: 2 };\n\n/** Per-name arity. */\nconst ARITY: Record<BuiltinOperator, Arity> = {\n len: { min: 1, max: 1 },\n lower: { min: 1, max: 1 },\n upper: { min: 1, max: 1 },\n trim: { min: 1, max: 1 },\n starts_with: { min: 2, max: 2 },\n ends_with: { min: 2, max: 2 },\n contains: { min: 2, max: 2 },\n between: { min: 3, max: 3 },\n ascii_match: { min: 2, max: 2 },\n is_email: { min: 1, max: 1 },\n is_phone: { min: 1, max: 1 },\n is_url: { min: 1, max: 1 },\n is_unique: { min: 1, max: 2 },\n all: AGGREGATE_ARITY,\n any: AGGREGATE_ARITY,\n present: { min: 1, max: 1 },\n absent: { min: 1, max: 1 },\n empty: { min: 1, max: 1 },\n is_relevant: { min: 1, max: 1 },\n sum: AGGREGATE_ARITY,\n count_where: AGGREGATE_ARITY,\n count_distinct: { min: 1, max: 1 },\n min: AGGREGATE_ARITY,\n max: AGGREGATE_ARITY,\n to_decimal: { min: 1, max: 1 },\n to_string: { min: 1, max: 1 },\n parse_integer: { min: 1, max: 1 },\n parse_decimal: { min: 1, max: 1 },\n round: { min: 2, max: 2 },\n round_up: { min: 2, max: 2 },\n round_down: { min: 2, max: 2 },\n round_even: { min: 2, max: 2 },\n pow: { min: 2, max: 2 },\n money_minor: { min: 1, max: 1 },\n money_from_minor: { min: 4, max: 4 },\n money_currency: { min: 1, max: 1 },\n money_scale: { min: 1, max: 1 },\n add_days: { min: 2, max: 2 },\n add_months: { min: 2, max: 2 },\n add_minutes: { min: 2, max: 2 },\n days_between: { min: 2, max: 2 },\n months_between: { min: 2, max: 2 },\n minutes_between: { min: 2, max: 2 },\n duration_minutes: { min: 1, max: 1 },\n duration_seconds: { min: 1, max: 1 },\n in_set: { min: 2, max: 3 },\n lookup: { min: 2, max: 3 },\n decide_keys: { min: 2, max: 3 },\n digest: { min: 2, max: 2 },\n member: { min: 2, max: 2 },\n keys: { min: 1, max: 1 },\n values: { min: 1, max: 1 },\n has_cap: { min: 1, max: 1 },\n rule_ok: { min: 1, max: 1 },\n no_blocking: { min: 1, max: 1 },\n rule_ok_in: { min: 1, max: 1 },\n no_blocking_in: { min: 1, max: 1 },\n required_in: { min: 1, max: 1 },\n abs: { min: 1, max: 1 },\n ceil: { min: 1, max: 1 },\n floor: { min: 1, max: 1 },\n avg: AGGREGATE_ARITY,\n median: AGGREGATE_ARITY,\n first: AGGREGATE_ARITY,\n last: AGGREGATE_ARITY,\n replace: { min: 3, max: 3 },\n split: { min: 2, max: 2 },\n join: { min: 2, max: 2 },\n substring: { min: 3, max: 3 },\n index_of: { min: 2, max: 2 },\n add_years: { min: 2, max: 2 },\n start_of_day: { min: 1, max: 1 },\n civil_date: { min: 1, max: 1 },\n matches: { min: 2, max: 3 },\n map: AGGREGATE_ARITY,\n filter: AGGREGATE_ARITY,\n mode: AGGREGATE_ARITY,\n concat: { min: 2, max: 32 },\n year: { min: 1, max: 1 },\n month: { min: 1, max: 1 },\n day: { min: 1, max: 1 },\n weekday: { min: 1, max: 1 },\n parse_date: { min: 1, max: 1 },\n parse_instant: { min: 1, max: 1 },\n sort: { min: 1, max: 1 },\n slice: { min: 3, max: 3 },\n distinct: { min: 1, max: 1 },\n reverse: { min: 1, max: 1 },\n};\n\nexport function arityText(arity: Arity): string {\n if (arity.max === undefined) return `at least ${String(arity.min)} arguments`;\n if (arity.min === arity.max) {\n return `${String(arity.min)} argument${arity.min === 1 ? '' : 's'}`;\n }\n return `${String(arity.min)} to ${String(arity.max)} arguments`;\n}\n\n/**\n * The arity one call operator's compiled node admits.\n *\n * One table serves the typechecker and the compiled-node boundary, so a node the boundary\n * admits is one the checker's signature accepts: a metaschema-valid `call` may otherwise state\n * `len` with two operands, and the boundary would pass it to an evaluator whose only defence is\n * a second table. Arithmetic is stated here too, because `call` nodes carry `+`, `-` and `*`.\n */\nexport function arityOf(op: CallOperator): Arity {\n if (op === '/' || op === '%' || op === '//') return DIVISION_ARITY;\n return op === '+' || op === '-' || op === '*' ? ARITHMETIC_ARITY : ARITY[op];\n}\n\n/**\n * The bounds one callable built-in's signature admits, for the frozen-grammar gate.\n *\n * The grammar states each built-in's width; this is the same fact from the table the typechecker\n * enforces, so `test/dsl/grammar-lock.test.ts` can compare the published production with the\n * compiled behaviour. It is on `@azx-pbc/axiom-compiler/testing`, not a host door: a host has no\n * reason to ask, and the signature belongs to the compile it already runs.\n */\nexport function builtinArity(name: BuiltinOperator): Arity {\n return ARITY[name];\n}\n\n/**\n * The source form a short call most likely meant.\n *\n * A missing operand is otherwise reported only as a count, which tells an author that\n * `starts_with(s)` is wrong without naming the operand the signature requires\n * (`EXPR-11.1.4`). Each repair is a complete expression, so the diagnostics-repair gate can\n * parse it.\n */\nconst SHORT_CALL_REPAIR: Partial<Record<BuiltinOperator, string>> = {\n round: 'round(x, 2)',\n round_up: 'round_up(x, 2)',\n round_down: 'round_down(x, 2)',\n round_even: 'round_even(x, 2)',\n pow: 'pow(x, y)',\n money_from_minor: 'money_from_minor(x, \"AUD\", 2, \"half_up\")',\n between: 'between(x, low, high)',\n starts_with: 'starts_with(s, p)',\n ends_with: 'ends_with(s, p)',\n contains: 'contains(s, p)',\n};\n\n/** The repair for a call whose extra operand states a rounding the signature does not take. */\nconst TOO_MANY_REPAIR: Partial<Record<BuiltinOperator, string>> = {\n round:\n 'the rounding is the function name: write `round_up(x, 2)`, `round_down(x, 2)` or `round_even(x, 2)`',\n pow: 'a stated scale is a composition: write `round(pow(a, b), places)`',\n};\n\n/** Refuses a built-in called with a count outside its signature. */\nexport function requireArity(ctx: CheckContext, op: BuiltinOperator, node: CallNode): void {\n const arity = ARITY[op];\n const maximum = arity.max;\n if (node.args.length < arity.min || (maximum !== undefined && node.args.length > maximum)) {\n const tooMany = maximum !== undefined && node.args.length > maximum;\n const extra = tooMany ? TOO_MANY_REPAIR[op] : undefined;\n const repair = tooMany\n ? extra\n : SHORT_CALL_REPAIR[op] === undefined\n ? undefined\n : `write \\`${SHORT_CALL_REPAIR[op]}\\``;\n throw ctx.mismatch(\n node,\n `\\`${op}\\` takes ${arityText(arity)}, found ${String(node.args.length)}${repair === undefined ? '' : `; ${repair}`}`,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CallNode } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import type { CheckContext } from './context.js';
|
|
3
|
+
import type { StaticType } from './types.js';
|
|
4
|
+
/** The type of one call, routed to the family that owns its operator. */
|
|
5
|
+
export declare function callType(ctx: CheckContext, node: CallNode): StaticType;
|
|
6
|
+
//# sourceMappingURL=calls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../../../src/expr/typecheck/calls.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAMvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAWjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,yEAAyE;AACzE,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,GAAG,UAAU,CAsHtE"}
|