@greenpandastudios/aug-cli 0.19.0
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 +13 -0
- package/THIRD_PARTY_NOTICES.md +18 -0
- package/bin/aug.mjs +3 -0
- package/docs/api/crypto.md +351 -0
- package/docs/api/io.md +207 -0
- package/docs/api/json.md +21 -0
- package/docs/api/memory.md +109 -0
- package/docs/api/time.md +54 -0
- package/docs/api/web.md +184 -0
- package/docs/assets/benchmarks/execution.svg +2978 -0
- package/docs/assets/benchmarks/http.svg +1674 -0
- package/docs/assets/benchmarks/improvements.svg +2315 -0
- package/docs/assets/benchmarks/memory.svg +1891 -0
- package/docs/benchmark-baseline.json +1087 -0
- package/docs/benchmark-results.json +91123 -0
- package/docs/benchmarks.json +38 -0
- package/docs/compatibility.md +42 -0
- package/docs/concurrency-implementation.md +18 -0
- package/docs/diagnostics.md +97 -0
- package/docs/docker.md +35 -0
- package/docs/example-projects.json +26 -0
- package/docs/examples/approved-design/counters.md +253 -0
- package/docs/examples/approved-design/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/approved-design/domain/app.md +165 -0
- package/docs/examples/approved-design/domain/export.md +83 -0
- package/docs/examples/approved-design/domain/models.md +80 -0
- package/docs/examples/approved-design/domain/numbers.md +248 -0
- package/docs/examples/approved-design/index.md +39 -0
- package/docs/examples/approved-design/main-yaml.md +24 -0
- package/docs/examples/approved-design/main.md +215 -0
- package/docs/examples/benchmark/index.md +33 -0
- package/docs/examples/benchmark/main-yaml.md +17 -0
- package/docs/examples/benchmark/main.md +117 -0
- package/docs/examples/cli-args/index.md +32 -0
- package/docs/examples/cli-args/main.md +107 -0
- package/docs/examples/collections/index.md +32 -0
- package/docs/examples/collections/main.md +118 -0
- package/docs/examples/collections-benchmark/index.md +34 -0
- package/docs/examples/collections-benchmark/main.md +115 -0
- package/docs/examples/cpu-benchmark/index.md +34 -0
- package/docs/examples/cpu-benchmark/main.md +90 -0
- package/docs/examples/developer-workflow/calculator.md +357 -0
- package/docs/examples/developer-workflow/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/developer-workflow/index.md +37 -0
- package/docs/examples/developer-workflow/logging/console.md +124 -0
- package/docs/examples/developer-workflow/logging/export.md +70 -0
- package/docs/examples/developer-workflow/logging/logger.md +111 -0
- package/docs/examples/developer-workflow/main.md +172 -0
- package/docs/examples/drop/index.md +33 -0
- package/docs/examples/drop/main.md +85 -0
- package/docs/examples/drop/resource.md +95 -0
- package/docs/examples/errors/errors.md +85 -0
- package/docs/examples/errors/index.md +33 -0
- package/docs/examples/errors/main.md +92 -0
- package/docs/examples/ffi/index.md +33 -0
- package/docs/examples/ffi/main.md +75 -0
- package/docs/examples/ffi/native.md +93 -0
- package/docs/examples/generic-di/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/generic-di/index.md +33 -0
- package/docs/examples/generic-di/main.md +111 -0
- package/docs/examples/generic-di/types.md +180 -0
- package/docs/examples/generics/index.md +33 -0
- package/docs/examples/generics/main.md +120 -0
- package/docs/examples/generics/types.md +189 -0
- package/docs/examples/hello/app/export.md +67 -0
- package/docs/examples/hello/app/greeter.md +190 -0
- package/docs/examples/hello/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/hello/index.md +37 -0
- package/docs/examples/hello/logging/console.md +121 -0
- package/docs/examples/hello/logging/export.md +71 -0
- package/docs/examples/hello/logging/logger.md +120 -0
- package/docs/examples/hello/main.md +115 -0
- package/docs/examples/http-benchmark/index.md +35 -0
- package/docs/examples/http-benchmark/main.md +79 -0
- package/docs/examples/http-benchmark/routes.md +88 -0
- package/docs/examples/index.md +60 -0
- package/docs/examples/interceptors/app.md +250 -0
- package/docs/examples/interceptors/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/interceptors/index.md +35 -0
- package/docs/examples/interceptors/interceptors.md +284 -0
- package/docs/examples/interceptors/logging.md +155 -0
- package/docs/examples/interceptors/main.md +162 -0
- package/docs/examples/json-benchmark/data.md +71 -0
- package/docs/examples/json-benchmark/dependencies/august/0.19.0/json/contracts.md +103 -0
- package/docs/examples/json-benchmark/index.md +35 -0
- package/docs/examples/json-benchmark/main.md +131 -0
- package/docs/examples/new-syntax/console.md +118 -0
- package/docs/examples/new-syntax/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/new-syntax/greeter.md +145 -0
- package/docs/examples/new-syntax/index.md +36 -0
- package/docs/examples/new-syntax/logger.md +111 -0
- package/docs/examples/new-syntax/main.md +135 -0
- package/docs/examples/new-syntax/math.md +79 -0
- package/docs/examples/oidc-login/client/contracts.md +151 -0
- package/docs/examples/oidc-login/client/endpoints.md +263 -0
- package/docs/examples/oidc-login/client/export.md +107 -0
- package/docs/examples/oidc-login/client/login.md +515 -0
- package/docs/examples/oidc-login/client/logout.md +249 -0
- package/docs/examples/oidc-login/client/protocol.md +595 -0
- package/docs/examples/oidc-login/client/session.md +297 -0
- package/docs/examples/oidc-login/client/views.md +144 -0
- package/docs/examples/oidc-login/common/export.md +115 -0
- package/docs/examples/oidc-login/common/headers.md +162 -0
- package/docs/examples/oidc-login/common/keys.md +336 -0
- package/docs/examples/oidc-login/common/settings.md +116 -0
- package/docs/examples/oidc-login/common/views.md +103 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/crypto/contracts.md +925 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/crypto/jose.md +434 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/json/contracts.md +103 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/memory/store.md +374 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/time/contracts.md +150 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/web/contracts.md +532 -0
- package/docs/examples/oidc-login/index.md +57 -0
- package/docs/examples/oidc-login/main-yaml.md +28 -0
- package/docs/examples/oidc-login/main.md +283 -0
- package/docs/examples/oidc-login/provider/authorization.md +457 -0
- package/docs/examples/oidc-login/provider/contracts.md +267 -0
- package/docs/examples/oidc-login/provider/credentials.md +148 -0
- package/docs/examples/oidc-login/provider/discovery.md +215 -0
- package/docs/examples/oidc-login/provider/export.md +131 -0
- package/docs/examples/oidc-login/provider/token.md +364 -0
- package/docs/examples/oidc-login/provider/userinfo.md +228 -0
- package/docs/examples/oidc-login/provider/views.md +137 -0
- package/docs/examples/ownership/counter.md +140 -0
- package/docs/examples/ownership/index.md +33 -0
- package/docs/examples/ownership/main.md +90 -0
- package/docs/examples/ownership-transfer/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/ownership-transfer/index.md +33 -0
- package/docs/examples/ownership-transfer/main.md +125 -0
- package/docs/examples/ownership-transfer/resource.md +150 -0
- package/docs/examples/packages-app/dependencies/packages/@example/aug-math/0.1.0/arithmetic.md +117 -0
- package/docs/examples/packages-app/index.md +34 -0
- package/docs/examples/packages-app/main-yaml.md +18 -0
- package/docs/examples/packages-app/main.md +80 -0
- package/docs/examples/packages-math/aug-package-json.md +24 -0
- package/docs/examples/packages-math/index.md +36 -0
- package/docs/examples/packages-math/package-json.md +25 -0
- package/docs/examples/packages-math/src/arithmetic.md +121 -0
- package/docs/examples/packages-math/src/export.md +63 -0
- package/docs/examples/startup-benchmark/index.md +34 -0
- package/docs/examples/startup-benchmark/main.md +68 -0
- package/docs/examples/visibility/counter.md +142 -0
- package/docs/examples/visibility/index.md +33 -0
- package/docs/examples/visibility/main.md +96 -0
- package/docs/examples.json +47 -0
- package/docs/getting-started.md +5 -0
- package/docs/grammar.md +136 -0
- package/docs/implementation-map.md +106 -0
- package/docs/index.md +46 -0
- package/docs/language-conformance.md +30 -0
- package/docs/language-constructs.md +1461 -0
- package/docs/language-design-audit.md +147 -0
- package/docs/maintaining-docs.md +43 -0
- package/docs/packages.md +184 -0
- package/docs/performance.md +535 -0
- package/docs/production-readiness.md +39 -0
- package/docs/reference.md +361 -0
- package/docs/release-review.md +23 -0
- package/docs/releasing.md +79 -0
- package/docs/roadmap.md +13 -0
- package/docs/specifications.md +86 -0
- package/docs/testing.md +120 -0
- package/docs/tooling.md +197 -0
- package/docs/web-implementation-plan.md +39 -0
- package/docs/web-library-gaps.md +27 -0
- package/docs/web.md +197 -0
- package/examples/approved-design/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/approved-design/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/approved-design/.aug-spec/manifest.json +14 -0
- package/examples/approved-design/counters.aug +22 -0
- package/examples/approved-design/counters.aug.md +177 -0
- package/examples/approved-design/domain/app.aug +12 -0
- package/examples/approved-design/domain/app.aug.md +97 -0
- package/examples/approved-design/domain/export.aug +5 -0
- package/examples/approved-design/domain/export.aug.md +25 -0
- package/examples/approved-design/domain/models.aug +2 -0
- package/examples/approved-design/domain/models.aug.md +30 -0
- package/examples/approved-design/domain/numbers.aug +29 -0
- package/examples/approved-design/domain/numbers.aug.md +141 -0
- package/examples/approved-design/main.aug +26 -0
- package/examples/approved-design/main.aug.md +108 -0
- package/examples/approved-design/main.yaml +8 -0
- package/examples/benchmark/.aug-spec/manifest.json +7 -0
- package/examples/benchmark/main.aug +17 -0
- package/examples/benchmark/main.aug.md +43 -0
- package/examples/benchmark/main.yaml +1 -0
- package/examples/cli-args/.aug-spec/manifest.json +7 -0
- package/examples/cli-args/main.aug +15 -0
- package/examples/cli-args/main.aug.md +38 -0
- package/examples/collections/.aug-spec/manifest.json +7 -0
- package/examples/collections/main.aug +18 -0
- package/examples/collections/main.aug.md +43 -0
- package/examples/developer-workflow/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/developer-workflow/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/developer-workflow/.aug-spec/manifest.json +13 -0
- package/examples/developer-workflow/calculator.aug +55 -0
- package/examples/developer-workflow/calculator.aug.md +228 -0
- package/examples/developer-workflow/logging/console.aug +8 -0
- package/examples/developer-workflow/logging/console.aug.md +67 -0
- package/examples/developer-workflow/logging/export.aug +2 -0
- package/examples/developer-workflow/logging/export.aug.md +19 -0
- package/examples/developer-workflow/logging/logger.aug +6 -0
- package/examples/developer-workflow/logging/logger.aug.md +57 -0
- package/examples/developer-workflow/main.aug +25 -0
- package/examples/developer-workflow/main.aug.md +79 -0
- package/examples/drop/.aug-spec/manifest.json +8 -0
- package/examples/drop/main.aug +3 -0
- package/examples/drop/main.aug.md +35 -0
- package/examples/drop/resource.aug +8 -0
- package/examples/drop/resource.aug.md +44 -0
- package/examples/errors/.aug-spec/manifest.json +8 -0
- package/examples/errors/errors.aug +6 -0
- package/examples/errors/errors.aug.md +33 -0
- package/examples/errors/main.aug +7 -0
- package/examples/errors/main.aug.md +36 -0
- package/examples/ffi/.aug-spec/manifest.json +8 -0
- package/examples/ffi/main.aug +2 -0
- package/examples/ffi/main.aug.md +27 -0
- package/examples/ffi/native.aug +6 -0
- package/examples/ffi/native.aug.md +43 -0
- package/examples/generic-di/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/generic-di/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/generic-di/.aug-spec/manifest.json +10 -0
- package/examples/generic-di/main.aug +9 -0
- package/examples/generic-di/main.aug.md +49 -0
- package/examples/generic-di/types.aug +17 -0
- package/examples/generic-di/types.aug.md +124 -0
- package/examples/generics/.aug-spec/manifest.json +8 -0
- package/examples/generics/main.aug +9 -0
- package/examples/generics/main.aug.md +58 -0
- package/examples/generics/types.aug +19 -0
- package/examples/generics/types.aug.md +132 -0
- package/examples/hello/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/hello/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/hello/.aug-spec/manifest.json +14 -0
- package/examples/hello/app/export.aug +1 -0
- package/examples/hello/app/export.aug.md +17 -0
- package/examples/hello/app/greeter.aug +22 -0
- package/examples/hello/app/greeter.aug.md +109 -0
- package/examples/hello/logging/console.aug +7 -0
- package/examples/hello/logging/console.aug.md +65 -0
- package/examples/hello/logging/export.aug +2 -0
- package/examples/hello/logging/export.aug.md +19 -0
- package/examples/hello/logging/logger.aug +9 -0
- package/examples/hello/logging/logger.aug.md +59 -0
- package/examples/hello/main.aug +9 -0
- package/examples/hello/main.aug.md +49 -0
- package/examples/interceptors/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/interceptors/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/interceptors/.aug-spec/manifest.json +12 -0
- package/examples/interceptors/app.aug +28 -0
- package/examples/interceptors/app.aug.md +162 -0
- package/examples/interceptors/interceptors.aug +40 -0
- package/examples/interceptors/interceptors.aug.md +180 -0
- package/examples/interceptors/logging.aug +12 -0
- package/examples/interceptors/logging.aug.md +96 -0
- package/examples/interceptors/main.aug +22 -0
- package/examples/interceptors/main.aug.md +76 -0
- package/examples/new-syntax/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/new-syntax/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/new-syntax/.aug-spec/manifest.json +13 -0
- package/examples/new-syntax/console.aug +7 -0
- package/examples/new-syntax/console.aug.md +63 -0
- package/examples/new-syntax/greeter.aug +10 -0
- package/examples/new-syntax/greeter.aug.md +89 -0
- package/examples/new-syntax/logger.aug +6 -0
- package/examples/new-syntax/logger.aug.md +57 -0
- package/examples/new-syntax/main.aug +12 -0
- package/examples/new-syntax/main.aug.md +64 -0
- package/examples/new-syntax/math.aug +3 -0
- package/examples/new-syntax/math.aug.md +29 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/contracts.aug +73 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/contracts.aug.md +791 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/jose.aug +68 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/jose.aug.md +266 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/json/contracts.aug +6 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/json/contracts.aug.md +55 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/memory/store.aug +45 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/memory/store.aug.md +250 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/time/contracts.aug +11 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/time/contracts.aug.md +96 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/web/contracts.aug +58 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/web/contracts.aug.md +420 -0
- package/examples/oidc-login/.aug-spec/manifest.json +40 -0
- package/examples/oidc-login/README.md +29 -0
- package/examples/oidc-login/client/contracts.aug +7 -0
- package/examples/oidc-login/client/contracts.aug.md +80 -0
- package/examples/oidc-login/client/endpoints.aug +21 -0
- package/examples/oidc-login/client/endpoints.aug.md +161 -0
- package/examples/oidc-login/client/export.aug +7 -0
- package/examples/oidc-login/client/export.aug.md +29 -0
- package/examples/oidc-login/client/login.aug +58 -0
- package/examples/oidc-login/client/login.aug.md +331 -0
- package/examples/oidc-login/client/logout.aug +18 -0
- package/examples/oidc-login/client/logout.aug.md +150 -0
- package/examples/oidc-login/client/protocol.aug +106 -0
- package/examples/oidc-login/client/protocol.aug.md +326 -0
- package/examples/oidc-login/client/session.aug +34 -0
- package/examples/oidc-login/client/session.aug.md +155 -0
- package/examples/oidc-login/client/views.aug +21 -0
- package/examples/oidc-login/client/views.aug.md +68 -0
- package/examples/oidc-login/common/export.aug +9 -0
- package/examples/oidc-login/common/export.aug.md +33 -0
- package/examples/oidc-login/common/headers.aug +11 -0
- package/examples/oidc-login/common/headers.aug.md +79 -0
- package/examples/oidc-login/common/keys.aug +37 -0
- package/examples/oidc-login/common/keys.aug.md +207 -0
- package/examples/oidc-login/common/settings.aug +4 -0
- package/examples/oidc-login/common/settings.aug.md +47 -0
- package/examples/oidc-login/common/views.aug +16 -0
- package/examples/oidc-login/common/views.aug.md +34 -0
- package/examples/oidc-login/main.aug +39 -0
- package/examples/oidc-login/main.aug.md +166 -0
- package/examples/oidc-login/main.yaml +12 -0
- package/examples/oidc-login/provider/authorization.aug +59 -0
- package/examples/oidc-login/provider/authorization.aug.md +264 -0
- package/examples/oidc-login/provider/contracts.aug +15 -0
- package/examples/oidc-login/provider/contracts.aug.md +193 -0
- package/examples/oidc-login/provider/credentials.aug +10 -0
- package/examples/oidc-login/provider/credentials.aug.md +64 -0
- package/examples/oidc-login/provider/discovery.aug +13 -0
- package/examples/oidc-login/provider/discovery.aug.md +133 -0
- package/examples/oidc-login/provider/export.aug +13 -0
- package/examples/oidc-login/provider/export.aug.md +41 -0
- package/examples/oidc-login/provider/token.aug +37 -0
- package/examples/oidc-login/provider/token.aug.md +223 -0
- package/examples/oidc-login/provider/userinfo.aug +26 -0
- package/examples/oidc-login/provider/userinfo.aug.md +104 -0
- package/examples/oidc-login/provider/views.aug +18 -0
- package/examples/oidc-login/provider/views.aug.md +63 -0
- package/examples/ownership/.aug-spec/manifest.json +8 -0
- package/examples/ownership/counter.aug +14 -0
- package/examples/ownership/counter.aug.md +85 -0
- package/examples/ownership/main.aug +4 -0
- package/examples/ownership/main.aug.md +38 -0
- package/examples/ownership-transfer/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/ownership-transfer/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/ownership-transfer/.aug-spec/manifest.json +10 -0
- package/examples/ownership-transfer/main.aug +9 -0
- package/examples/ownership-transfer/main.aug.md +63 -0
- package/examples/ownership-transfer/resource.aug +16 -0
- package/examples/ownership-transfer/resource.aug.md +89 -0
- package/examples/packages/README.md +15 -0
- package/examples/packages/app/.aug-spec/manifest.json +9 -0
- package/examples/packages/app/.aug-spec/packages/@example/aug-math/0.1.0/arithmetic.aug +9 -0
- package/examples/packages/app/.aug-spec/packages/@example/aug-math/0.1.0/arithmetic.aug.md +63 -0
- package/examples/packages/app/main.aug +2 -0
- package/examples/packages/app/main.aug.md +33 -0
- package/examples/packages/app/main.yaml +2 -0
- package/examples/packages/math/.aug-spec/manifest.json +8 -0
- package/examples/packages/math/README.md +3 -0
- package/examples/packages/math/aug-package.json +8 -0
- package/examples/packages/math/package.json +9 -0
- package/examples/packages/math/src/arithmetic.aug +8 -0
- package/examples/packages/math/src/arithmetic.aug.md +63 -0
- package/examples/packages/math/src/export.aug +1 -0
- package/examples/packages/math/src/export.aug.md +17 -0
- package/examples/visibility/.aug-spec/manifest.json +8 -0
- package/examples/visibility/counter.aug +14 -0
- package/examples/visibility/counter.aug.md +87 -0
- package/examples/visibility/main.aug +7 -0
- package/examples/visibility/main.aug.md +39 -0
- package/package.json +50 -0
- package/runtime/aug_crypto.c +121 -0
- package/runtime/aug_html.c +93 -0
- package/runtime/aug_http.c +829 -0
- package/runtime/aug_json.c +165 -0
- package/runtime/aug_runtime.c +792 -0
- package/runtime/aug_runtime.h +245 -0
- package/runtime/aug_tasks.c +172 -0
- package/runtime/aug_time.c +5 -0
- package/runtime/aug_values.c +80 -0
- package/scripts/bootstrap-native.mjs +121 -0
- package/scripts/native-dependencies.lock.json +65 -0
- package/scripts/native-home.mjs +11 -0
- package/src/actions.js +109 -0
- package/src/ast.js +19 -0
- package/src/builtins.js +93 -0
- package/src/checker.js +2896 -0
- package/src/cli.js +344 -0
- package/src/codegen.js +1159 -0
- package/src/config.js +149 -0
- package/src/continuation.js +110 -0
- package/src/di.js +24 -0
- package/src/documentation.js +27 -0
- package/src/editor.js +782 -0
- package/src/effects.js +29 -0
- package/src/fixes.js +222 -0
- package/src/formatter.js +296 -0
- package/src/freshness.js +154 -0
- package/src/help.js +212 -0
- package/src/html.js +27 -0
- package/src/http-policies.js +90 -0
- package/src/inference.js +16 -0
- package/src/interceptors.js +70 -0
- package/src/javadoc.js +67 -0
- package/src/lexer.js +199 -0
- package/src/libraries.js +31 -0
- package/src/lsp.js +180 -0
- package/src/native.js +144 -0
- package/src/navigation.js +162 -0
- package/src/openapi.js +220 -0
- package/src/ownership.js +232 -0
- package/src/package-manager.js +299 -0
- package/src/parser.js +1155 -0
- package/src/policies.js +130 -0
- package/src/project-init.js +19 -0
- package/src/project.js +292 -0
- package/src/schemas.js +62 -0
- package/src/semantic.js +255 -0
- package/src/spec.js +738 -0
- package/src/testing.js +186 -0
- package/src/types.js +10 -0
package/src/parser.js
ADDED
|
@@ -0,0 +1,1155 @@
|
|
|
1
|
+
import { syntheticType } from "./ast.js";
|
|
2
|
+
import { lex } from "./lexer.js";
|
|
3
|
+
import { basename } from 'node:path';
|
|
4
|
+
class ParseFailure extends Error {
|
|
5
|
+
diagnostic;
|
|
6
|
+
constructor(diagnostic) { super(diagnostic.message); this.diagnostic = diagnostic; }
|
|
7
|
+
}
|
|
8
|
+
export function parse(file, source) {
|
|
9
|
+
const scanned = lex(file, source);
|
|
10
|
+
const parser = new Parser(scanned.tokens, basename(file) === 'main.aug', source);
|
|
11
|
+
const items = parser.parseItems();
|
|
12
|
+
return { file: { path: file, source, items }, diagnostics: [...scanned.diagnostics, ...parser.diagnostics] };
|
|
13
|
+
}
|
|
14
|
+
class Parser {
|
|
15
|
+
position = 0;
|
|
16
|
+
diagnostics = [];
|
|
17
|
+
tokens;
|
|
18
|
+
isMain;
|
|
19
|
+
expressionDepth = 0;
|
|
20
|
+
lines;
|
|
21
|
+
blocks = [];
|
|
22
|
+
constructor(tokens, isMain, source) {
|
|
23
|
+
this.tokens = tokens;
|
|
24
|
+
this.isMain = isMain;
|
|
25
|
+
this.lines = source.split('\n');
|
|
26
|
+
}
|
|
27
|
+
current(offset = 0) { return this.tokens[Math.min(this.position + offset, this.tokens.length - 1)]; }
|
|
28
|
+
at(kind) { return this.current().kind === kind; }
|
|
29
|
+
take() { return this.tokens[this.position++]; }
|
|
30
|
+
match(kind) { return this.at(kind) ? this.take() : undefined; }
|
|
31
|
+
expect(kind) {
|
|
32
|
+
if (this.at(kind))
|
|
33
|
+
return this.take();
|
|
34
|
+
const token = this.current();
|
|
35
|
+
throw new ParseFailure({ file: token.span.file, line: token.span.line, column: token.span.column,
|
|
36
|
+
message: `Expected ${kind}, found ${token.kind === 'eof' ? 'end of file' : JSON.stringify(token.value)}`,
|
|
37
|
+
code: 'PARSE' });
|
|
38
|
+
}
|
|
39
|
+
word(value) {
|
|
40
|
+
if (this.current().value === value)
|
|
41
|
+
return this.take();
|
|
42
|
+
return this.expect(value);
|
|
43
|
+
}
|
|
44
|
+
span(start, end = this.tokens[Math.max(0, this.position - 1)].span) {
|
|
45
|
+
return { ...start, end: end.end };
|
|
46
|
+
}
|
|
47
|
+
lineBreak() {
|
|
48
|
+
const previous = this.tokens[Math.max(0, this.position - 1)];
|
|
49
|
+
return this.current().span.line > previous.endLine;
|
|
50
|
+
}
|
|
51
|
+
endStatement() {
|
|
52
|
+
if (this.match(';') || this.at('}') || this.at('eof') || this.lineBreak())
|
|
53
|
+
return;
|
|
54
|
+
this.expect('; or a newline');
|
|
55
|
+
}
|
|
56
|
+
recover() {
|
|
57
|
+
this.expressionDepth = 0;
|
|
58
|
+
while (!this.at('eof') && !this.at(';') && !this.at('}') && !this.lineBreak())
|
|
59
|
+
this.take();
|
|
60
|
+
if (this.at(';'))
|
|
61
|
+
this.take();
|
|
62
|
+
}
|
|
63
|
+
closeBrace() {
|
|
64
|
+
if (!this.at('eof')) {
|
|
65
|
+
this.expect('}');
|
|
66
|
+
this.blocks.pop();
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const span = this.current().span;
|
|
70
|
+
this.diagnostics.push({ file: span.file, line: span.line, column: span.column,
|
|
71
|
+
code: 'PARSE', message: 'Expected }, found end of file' });
|
|
72
|
+
this.blocks.pop();
|
|
73
|
+
}
|
|
74
|
+
indentation(token) {
|
|
75
|
+
const span = 'span' in token ? token.span : token;
|
|
76
|
+
return /^[\t ]*/.exec(this.lines[span.line - 1] ?? '')[0];
|
|
77
|
+
}
|
|
78
|
+
layoutEnd(colonIndex, header) {
|
|
79
|
+
const colon = this.tokens[colonIndex];
|
|
80
|
+
const first = this.tokens[colonIndex + 1];
|
|
81
|
+
const base = this.indentation(header);
|
|
82
|
+
const indentation = this.indentation(first);
|
|
83
|
+
const fail = (token, message) => {
|
|
84
|
+
throw new ParseFailure({ ...token.span, code: 'INDENT', message });
|
|
85
|
+
};
|
|
86
|
+
if (first.kind === 'eof' || first.span.line <= colon.endLine)
|
|
87
|
+
fail(first, 'A colon block needs an indented body on the following line');
|
|
88
|
+
if (/[ ]/.test(indentation) && /\t/.test(indentation))
|
|
89
|
+
fail(first, 'Use tabs or spaces for indentation; do not mix them in a block prefix');
|
|
90
|
+
if (!indentation.startsWith(base) || indentation.length <= base.length)
|
|
91
|
+
fail(first, 'Indent the block body beyond its header; use pass for an empty body');
|
|
92
|
+
let depth = 0;
|
|
93
|
+
let previousLine = colon.endLine;
|
|
94
|
+
for (let index = colonIndex + 1; index < this.tokens.length; index++) {
|
|
95
|
+
const token = this.tokens[index];
|
|
96
|
+
if (token.kind === 'eof')
|
|
97
|
+
return { index, indentation };
|
|
98
|
+
if (token.span.line > previousLine && depth === 0) {
|
|
99
|
+
const prefix = this.indentation(token);
|
|
100
|
+
if (/[ ]/.test(prefix) && /\t/.test(prefix))
|
|
101
|
+
fail(token, 'Use tabs or spaces for indentation; do not mix them in a block prefix');
|
|
102
|
+
if (prefix.length <= base.length) {
|
|
103
|
+
if (prefix !== base && !base.startsWith(prefix))
|
|
104
|
+
fail(token, 'A dedent must match an enclosing block indentation');
|
|
105
|
+
return { index, indentation };
|
|
106
|
+
}
|
|
107
|
+
if (!prefix.startsWith(indentation))
|
|
108
|
+
fail(token, 'A dedent must match an enclosing block indentation');
|
|
109
|
+
}
|
|
110
|
+
if (['(', '[', '{', 'jsx_open'].includes(token.kind))
|
|
111
|
+
depth++;
|
|
112
|
+
if ([')', ']', '}', 'jsx_self', 'jsx_close_end'].includes(token.kind)) {
|
|
113
|
+
if (depth === 0)
|
|
114
|
+
return { index, indentation };
|
|
115
|
+
depth--;
|
|
116
|
+
}
|
|
117
|
+
previousLine = token.endLine;
|
|
118
|
+
}
|
|
119
|
+
return { index: this.tokens.length - 1, indentation };
|
|
120
|
+
}
|
|
121
|
+
openBlock(header) {
|
|
122
|
+
if (this.match('{')) {
|
|
123
|
+
this.blocks.push({});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const colonIndex = this.position;
|
|
127
|
+
this.expect(':');
|
|
128
|
+
const layout = this.layoutEnd(colonIndex, header);
|
|
129
|
+
const boundary = this.tokens[layout.index];
|
|
130
|
+
const previous = this.tokens[layout.index - 1];
|
|
131
|
+
this.tokens.splice(layout.index, 0, { kind: '}', value: '',
|
|
132
|
+
span: { ...boundary.span, end: boundary.span.start }, endLine: previous.endLine });
|
|
133
|
+
this.blocks.push({ indentation: layout.indentation });
|
|
134
|
+
}
|
|
135
|
+
checkBlockIndentation() {
|
|
136
|
+
const expected = this.blocks.at(-1)?.indentation;
|
|
137
|
+
if (expected !== undefined && this.indentation(this.current()) !== expected)
|
|
138
|
+
throw new ParseFailure({ ...this.current().span, code: 'INDENT',
|
|
139
|
+
message: 'Unexpected indentation; introduce a nested block with : or braces' });
|
|
140
|
+
}
|
|
141
|
+
emptyBody() {
|
|
142
|
+
if (!this.match('pass'))
|
|
143
|
+
return false;
|
|
144
|
+
this.endStatement();
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
parseItems() {
|
|
148
|
+
const items = [];
|
|
149
|
+
while (!this.at('eof')) {
|
|
150
|
+
const before = this.position;
|
|
151
|
+
try {
|
|
152
|
+
items.push(this.parseItem());
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (!(error instanceof ParseFailure))
|
|
156
|
+
throw error;
|
|
157
|
+
this.diagnostics.push(error.diagnostic);
|
|
158
|
+
this.recover();
|
|
159
|
+
if (this.position === before && !this.at('eof'))
|
|
160
|
+
this.take();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return items;
|
|
164
|
+
}
|
|
165
|
+
parseItem() {
|
|
166
|
+
if (this.at('[') && this.looksLikeAnnotation()) {
|
|
167
|
+
const annotations = this.parseAnnotations();
|
|
168
|
+
let item;
|
|
169
|
+
if (this.at('endpoint'))
|
|
170
|
+
item = this.parseEndpoint();
|
|
171
|
+
else if (this.looksLikeBareClass())
|
|
172
|
+
item = this.parseClass();
|
|
173
|
+
else if (this.at('extern')) {
|
|
174
|
+
this.take();
|
|
175
|
+
this.expect('C');
|
|
176
|
+
item = this.parseFunction(true);
|
|
177
|
+
}
|
|
178
|
+
else if (this.looksLikeBareFunction())
|
|
179
|
+
item = this.parseFunction(false);
|
|
180
|
+
else
|
|
181
|
+
throw new ParseFailure({ ...annotations[0].span, code: 'INTERCEPTOR',
|
|
182
|
+
message: 'Interceptor annotations belong on functions, methods, or class constructors' });
|
|
183
|
+
item.annotations = annotations;
|
|
184
|
+
return item;
|
|
185
|
+
}
|
|
186
|
+
if (this.at('import'))
|
|
187
|
+
return this.parseImport();
|
|
188
|
+
if (this.at('endpoint'))
|
|
189
|
+
return this.parseEndpoint();
|
|
190
|
+
if (this.at('export'))
|
|
191
|
+
return this.parseExport();
|
|
192
|
+
if (this.at('bind') || this.at('implement'))
|
|
193
|
+
return this.parseBind();
|
|
194
|
+
if (this.at('interface') || this.at('capability'))
|
|
195
|
+
return this.parseInterface();
|
|
196
|
+
if (this.at('interceptor'))
|
|
197
|
+
return this.parseInterceptor();
|
|
198
|
+
if (this.at('test'))
|
|
199
|
+
return this.parseTest();
|
|
200
|
+
if (this.match('fixture'))
|
|
201
|
+
return { ...this.parseFunction(false), fixture: true };
|
|
202
|
+
if (this.at('record'))
|
|
203
|
+
return this.parseRecord();
|
|
204
|
+
if (this.at('include'))
|
|
205
|
+
return this.parseInclude();
|
|
206
|
+
if (this.match('composition')) {
|
|
207
|
+
const start = this.tokens[this.position - 1].span;
|
|
208
|
+
const name = this.expect('identifier').value;
|
|
209
|
+
this.openBlock(start);
|
|
210
|
+
const bindings = [];
|
|
211
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
212
|
+
this.checkBlockIndentation();
|
|
213
|
+
if (!this.at('implement') && !this.at('bind'))
|
|
214
|
+
this.expect('implement');
|
|
215
|
+
bindings.push(this.parseBind());
|
|
216
|
+
}
|
|
217
|
+
this.closeBrace();
|
|
218
|
+
return { kind: 'composition', name, typeParams: [], bindings, span: this.span(start) };
|
|
219
|
+
}
|
|
220
|
+
if (this.at('extern')) {
|
|
221
|
+
this.take();
|
|
222
|
+
this.expect('C');
|
|
223
|
+
return this.parseFunction(true);
|
|
224
|
+
}
|
|
225
|
+
if (this.looksLikeBareClass())
|
|
226
|
+
return this.parseClass();
|
|
227
|
+
if (this.looksLikeBareFunction())
|
|
228
|
+
return this.parseFunction(false);
|
|
229
|
+
if (this.at('class') || this.at('function'))
|
|
230
|
+
this.rejectDeclarationKeyword();
|
|
231
|
+
if (this.looksLikeMistypedFunctionKeyword())
|
|
232
|
+
this.rejectDeclarationKeyword();
|
|
233
|
+
return this.parseStatement();
|
|
234
|
+
}
|
|
235
|
+
looksLikeAnnotation() {
|
|
236
|
+
const saved = this.position;
|
|
237
|
+
try {
|
|
238
|
+
this.parseAnnotations();
|
|
239
|
+
return this.looksLikeBareClass() || this.looksLikeBareFunction() || this.at('extern') || this.at('endpoint');
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
if (!(error instanceof ParseFailure))
|
|
243
|
+
throw error;
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
this.position = saved;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
testName() {
|
|
251
|
+
if (this.at('string') || /^[A-Za-z_]\w*$/.test(this.current().value))
|
|
252
|
+
return this.take().value;
|
|
253
|
+
return this.expect('identifier').value;
|
|
254
|
+
}
|
|
255
|
+
parseTest() {
|
|
256
|
+
const start = this.take().span;
|
|
257
|
+
const endpointSuite = !!this.match('endpoint');
|
|
258
|
+
const type = this.parseType();
|
|
259
|
+
const functionSuite = !endpointSuite && !this.at('identifier');
|
|
260
|
+
const name = functionSuite ? type.name : this.take().value;
|
|
261
|
+
this.openBlock(start);
|
|
262
|
+
const groups = [];
|
|
263
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
264
|
+
this.checkBlockIndentation();
|
|
265
|
+
const groupStart = this.expect('when').span;
|
|
266
|
+
const groupName = this.testName();
|
|
267
|
+
this.openBlock(groupStart);
|
|
268
|
+
const setup = [];
|
|
269
|
+
const cases = [];
|
|
270
|
+
let seenSetup = false;
|
|
271
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
272
|
+
this.checkBlockIndentation();
|
|
273
|
+
if (this.match('it')) {
|
|
274
|
+
const caseStart = this.tokens[this.position - 1].span;
|
|
275
|
+
const caseName = this.testName();
|
|
276
|
+
let parameters, rows;
|
|
277
|
+
if (this.match('for')) {
|
|
278
|
+
parameters = this.patternNames();
|
|
279
|
+
this.expect('in');
|
|
280
|
+
const values = this.parseExpression();
|
|
281
|
+
if (values.kind !== 'collection' || values.collection !== 'List')
|
|
282
|
+
throw new ParseFailure({ ...values.span,
|
|
283
|
+
code: 'TEST', message: 'Parameterized cases need a list of tuple rows' });
|
|
284
|
+
rows = values.items;
|
|
285
|
+
}
|
|
286
|
+
const body = this.parseBlock(caseStart);
|
|
287
|
+
cases.push({ name: caseName, body, parameters, rows, span: this.span(caseStart) });
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
if (cases.length)
|
|
291
|
+
throw new ParseFailure({ ...this.current().span,
|
|
292
|
+
code: 'TEST', message: 'Put group setup before its it cases' });
|
|
293
|
+
if (this.at('implement') || this.at('bind') || this.at('include')) {
|
|
294
|
+
if (seenSetup)
|
|
295
|
+
throw new ParseFailure({ ...this.current().span,
|
|
296
|
+
code: 'TEST', message: 'Put test bindings before group setup statements' });
|
|
297
|
+
setup.push(this.at('include') ? this.parseInclude() : this.parseBind());
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
seenSetup = true;
|
|
301
|
+
setup.push(this.parseStatement());
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
this.closeBrace();
|
|
306
|
+
groups.push({ name: groupName, setup, cases, span: this.span(groupStart) });
|
|
307
|
+
}
|
|
308
|
+
this.closeBrace();
|
|
309
|
+
return { kind: 'test', type, name, functionSuite, endpointSuite, groups, span: this.span(start) };
|
|
310
|
+
}
|
|
311
|
+
parseAnnotations() {
|
|
312
|
+
const annotations = [];
|
|
313
|
+
while (this.at('[')) {
|
|
314
|
+
const start = this.take().span;
|
|
315
|
+
const token = this.expect('identifier');
|
|
316
|
+
const typeArgs = this.at('<') ? this.parseCallTypeArgs() : [];
|
|
317
|
+
const mappings = [];
|
|
318
|
+
if (this.match('(')) {
|
|
319
|
+
while (!this.at(')') && !this.at('eof')) {
|
|
320
|
+
const name = this.expect('identifier');
|
|
321
|
+
if (!this.match('to'))
|
|
322
|
+
this.expect('=');
|
|
323
|
+
if (this.current().kind !== 'string' && /^[A-Za-z_]\w*$/.test(this.current().value) && !['true', 'false', 'null'].includes(this.current().value)) {
|
|
324
|
+
const source = this.take();
|
|
325
|
+
mappings.push({ name: name.value, source: source.value, span: this.span(name.span), sourceSpan: source.span });
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
const value = this.parseExpression();
|
|
329
|
+
mappings.push({ name: name.value, source: '', value, span: this.span(name.span), sourceSpan: value.span });
|
|
330
|
+
}
|
|
331
|
+
if (!this.match(','))
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
this.expect(')');
|
|
335
|
+
}
|
|
336
|
+
this.expect(']');
|
|
337
|
+
annotations.push({ name: token.value, nameSpan: token.span, typeArgs, mappings,
|
|
338
|
+
span: this.span(start) });
|
|
339
|
+
}
|
|
340
|
+
return annotations;
|
|
341
|
+
}
|
|
342
|
+
parseInterceptor() {
|
|
343
|
+
const start = this.take().span;
|
|
344
|
+
const name = this.expect('identifier');
|
|
345
|
+
const { typeParams, typeConstraints, typeVariance } = this.parseTypeParams();
|
|
346
|
+
const fields = this.at('(') ? this.parseParams(true) : [];
|
|
347
|
+
this.openBlock(start);
|
|
348
|
+
const methods = [];
|
|
349
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
350
|
+
this.checkBlockIndentation();
|
|
351
|
+
if (!this.emptyBody())
|
|
352
|
+
methods.push(this.parseFunction(false));
|
|
353
|
+
}
|
|
354
|
+
this.closeBrace();
|
|
355
|
+
return { kind: 'interceptor', name: name.value, nameSpan: name.span, typeParams, typeConstraints, typeVariance,
|
|
356
|
+
fields, methods, span: this.span(start) };
|
|
357
|
+
}
|
|
358
|
+
rejectDeclarationKeyword() {
|
|
359
|
+
const token = this.current();
|
|
360
|
+
throw new ParseFailure({ file: token.span.file, line: token.span.line,
|
|
361
|
+
column: token.span.column, code: 'PARSE',
|
|
362
|
+
message: `Remove ${token.value}; declarations start with their name` });
|
|
363
|
+
}
|
|
364
|
+
looksLikeMistypedFunctionKeyword() {
|
|
365
|
+
return this.at('identifier') && this.current(1).kind === 'identifier' &&
|
|
366
|
+
['(', '<'].includes(this.current(2).kind);
|
|
367
|
+
}
|
|
368
|
+
looksLikeBareFunction() {
|
|
369
|
+
if (!this.at('identifier') && !['start', 'wait', 'missing'].includes(this.current().kind))
|
|
370
|
+
return false;
|
|
371
|
+
const saved = this.position;
|
|
372
|
+
try {
|
|
373
|
+
this.take();
|
|
374
|
+
this.parseTypeParams();
|
|
375
|
+
this.parseParams();
|
|
376
|
+
return ['returns', 'unless', 'throws', 'changes', 'uses', '{', ':'].includes(this.current().kind) ||
|
|
377
|
+
(!this.isMain && (this.at(';') || this.at('}') || this.at('eof') || this.lineBreak()));
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
if (!(error instanceof ParseFailure))
|
|
381
|
+
throw error;
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
this.position = saved;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
looksLikeBareClass() {
|
|
389
|
+
if (!this.at('identifier'))
|
|
390
|
+
return false;
|
|
391
|
+
const saved = this.position;
|
|
392
|
+
const start = this.current().span;
|
|
393
|
+
try {
|
|
394
|
+
this.take();
|
|
395
|
+
this.parseTypeParams();
|
|
396
|
+
if (this.at('('))
|
|
397
|
+
this.parseParams(true);
|
|
398
|
+
if (this.match('=>')) {
|
|
399
|
+
return true;
|
|
400
|
+
}
|
|
401
|
+
return this.at('implements');
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
if (!(error instanceof ParseFailure))
|
|
405
|
+
throw error;
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
finally {
|
|
409
|
+
this.position = saved;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
parseImport() {
|
|
413
|
+
const start = this.take().span;
|
|
414
|
+
const everything = !!this.match('everything');
|
|
415
|
+
const names = everything ? [] : [this.expect('identifier').value];
|
|
416
|
+
while (!everything && this.match('and'))
|
|
417
|
+
names.push(this.expect('identifier').value);
|
|
418
|
+
this.expect('from');
|
|
419
|
+
const from = [this.expect('identifier').value];
|
|
420
|
+
while (this.match('.'))
|
|
421
|
+
from.push(this.expect('identifier').value);
|
|
422
|
+
this.endStatement();
|
|
423
|
+
return { kind: 'import', names, everything, from, span: this.span(start) };
|
|
424
|
+
}
|
|
425
|
+
parseExport() {
|
|
426
|
+
const start = this.take().span;
|
|
427
|
+
if (this.match('folder')) {
|
|
428
|
+
const name = this.expect('identifier').value;
|
|
429
|
+
this.endStatement();
|
|
430
|
+
return { kind: 'export', name, folder: true, span: this.span(start) };
|
|
431
|
+
}
|
|
432
|
+
const name = this.expect('identifier').value;
|
|
433
|
+
this.expect('from');
|
|
434
|
+
const from = this.expect('identifier').value;
|
|
435
|
+
this.endStatement();
|
|
436
|
+
return { kind: 'export', name, from, folder: false, span: this.span(start) };
|
|
437
|
+
}
|
|
438
|
+
parseInclude() {
|
|
439
|
+
const start = this.take().span;
|
|
440
|
+
const name = this.expect('identifier').value;
|
|
441
|
+
this.endStatement();
|
|
442
|
+
return { kind: 'include', name, span: this.span(start) };
|
|
443
|
+
}
|
|
444
|
+
parseBind() {
|
|
445
|
+
const keyword = this.take();
|
|
446
|
+
const start = keyword.span;
|
|
447
|
+
if (keyword.kind === 'bind')
|
|
448
|
+
this.diagnostics.push({ ...start, code: 'SYNTAX',
|
|
449
|
+
message: 'Use implement Key with Implementation instead of bind Key to Implementation' });
|
|
450
|
+
const key = this.expect('identifier').value;
|
|
451
|
+
const keyTypeArgs = this.at('<') ? this.parseCallTypeArgs() : [];
|
|
452
|
+
this.expect(keyword.kind === 'implement' ? 'with' : 'to');
|
|
453
|
+
const target = this.parseType();
|
|
454
|
+
const lifetime = ['shared', 'fresh', 'scoped'].includes(this.current().kind) ? this.take().kind : undefined;
|
|
455
|
+
const sharedMutation = !!this.match('mutable');
|
|
456
|
+
this.endStatement();
|
|
457
|
+
return { kind: 'bind', key, keyTypeArgs, target, lifetime, sharedMutation, span: this.span(start) };
|
|
458
|
+
}
|
|
459
|
+
parseRecord() {
|
|
460
|
+
const start = this.take().span;
|
|
461
|
+
const name = this.expect('identifier').value;
|
|
462
|
+
const header = this.parseTypeParams();
|
|
463
|
+
const fields = this.parseParams(true);
|
|
464
|
+
const validationErrors = [];
|
|
465
|
+
if (this.match('unless')) {
|
|
466
|
+
validationErrors.push(this.parseType());
|
|
467
|
+
while (this.match('and') || this.match(','))
|
|
468
|
+
validationErrors.push(this.parseType());
|
|
469
|
+
}
|
|
470
|
+
let constructorBody = this.match('=>') ? this.parseBlock(start) : undefined;
|
|
471
|
+
let hasBody = !!constructorBody;
|
|
472
|
+
if (!constructorBody && (this.at('{') || this.at(':'))) {
|
|
473
|
+
hasBody = true;
|
|
474
|
+
this.openBlock(start);
|
|
475
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
476
|
+
this.checkBlockIndentation();
|
|
477
|
+
if (this.emptyBody())
|
|
478
|
+
continue;
|
|
479
|
+
const initializer = this.expect('initialize');
|
|
480
|
+
if (constructorBody)
|
|
481
|
+
throw new ParseFailure({ ...initializer.span, code: 'PARSE', message: 'A record has at most one initialize block' });
|
|
482
|
+
constructorBody = this.parseBlock(initializer.span);
|
|
483
|
+
}
|
|
484
|
+
this.closeBrace();
|
|
485
|
+
}
|
|
486
|
+
if (!hasBody)
|
|
487
|
+
this.endStatement();
|
|
488
|
+
return { kind: 'class', record: true, name, ...header, fields, constructorBody,
|
|
489
|
+
validationErrors, implements: [], methods: [], span: this.span(start) };
|
|
490
|
+
}
|
|
491
|
+
parseClass() {
|
|
492
|
+
const start = this.current().span;
|
|
493
|
+
const name = this.expect('identifier').value;
|
|
494
|
+
const { typeParams, typeConstraints, typeVariance } = this.parseTypeParams();
|
|
495
|
+
const fields = this.at('(') ? this.parseParams(true) : [];
|
|
496
|
+
let constructorBody = this.match('=>') ? this.parseBlock(start) : undefined;
|
|
497
|
+
const implemented = [];
|
|
498
|
+
if (!this.at('implements'))
|
|
499
|
+
throw new ParseFailure({ ...start, code: 'PARSE',
|
|
500
|
+
message: `${name} has a constructor body; add implements Interface after that body to declare a class` });
|
|
501
|
+
this.expect('implements');
|
|
502
|
+
implemented.push(this.parseType());
|
|
503
|
+
while (this.match(','))
|
|
504
|
+
implemented.push(this.parseType());
|
|
505
|
+
this.openBlock(start);
|
|
506
|
+
const methods = [];
|
|
507
|
+
const stateFields = [];
|
|
508
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
509
|
+
this.checkBlockIndentation();
|
|
510
|
+
if (this.emptyBody())
|
|
511
|
+
continue;
|
|
512
|
+
if (this.match('initialize')) {
|
|
513
|
+
const initializer = this.tokens[this.position - 1];
|
|
514
|
+
if (constructorBody)
|
|
515
|
+
throw new ParseFailure({ ...initializer.span, code: 'PARSE', message: 'A class has at most one initialize block' });
|
|
516
|
+
if (methods.length)
|
|
517
|
+
throw new ParseFailure({ ...initializer.span, code: 'PARSE', message: 'Put initialize before the class methods' });
|
|
518
|
+
constructorBody = this.parseBlock(initializer.span);
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (this.at('function') || this.at('class'))
|
|
522
|
+
this.rejectDeclarationKeyword();
|
|
523
|
+
if (this.at('mutable') || !this.looksLikeBareFunction() && !this.at('[')) {
|
|
524
|
+
const fieldStart = this.current().span;
|
|
525
|
+
const mutable = !!this.match('mutable');
|
|
526
|
+
const type = this.parseType();
|
|
527
|
+
const name = this.expect('identifier').value;
|
|
528
|
+
if (!this.match('=') && !this.match('to'))
|
|
529
|
+
this.expect('= or to');
|
|
530
|
+
const initializer = this.parseExpression();
|
|
531
|
+
this.endStatement();
|
|
532
|
+
stateFields.push({ name, type, ownership: 'managed', injected: false, mutable,
|
|
533
|
+
initializer, span: this.span(fieldStart) });
|
|
534
|
+
}
|
|
535
|
+
else
|
|
536
|
+
methods.push(this.parseFunction(false));
|
|
537
|
+
}
|
|
538
|
+
this.closeBrace();
|
|
539
|
+
return { kind: 'class', name, typeParams, typeConstraints, typeVariance, fields, stateFields, constructorBody,
|
|
540
|
+
implements: implemented, methods, span: this.span(start) };
|
|
541
|
+
}
|
|
542
|
+
parseInterface() {
|
|
543
|
+
const keyword = this.take();
|
|
544
|
+
const start = keyword.span;
|
|
545
|
+
const name = this.expect('identifier').value;
|
|
546
|
+
const { typeParams, typeConstraints, typeVariance } = this.parseTypeParams();
|
|
547
|
+
const parents = [];
|
|
548
|
+
if (this.match('extends')) {
|
|
549
|
+
parents.push(this.parseType());
|
|
550
|
+
while (this.match(','))
|
|
551
|
+
parents.push(this.parseType());
|
|
552
|
+
}
|
|
553
|
+
this.openBlock(start);
|
|
554
|
+
const methods = [];
|
|
555
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
556
|
+
this.checkBlockIndentation();
|
|
557
|
+
if (!this.emptyBody())
|
|
558
|
+
methods.push(this.parseFunction(false));
|
|
559
|
+
}
|
|
560
|
+
this.closeBrace();
|
|
561
|
+
return { kind: 'interface', name, capability: keyword.kind === 'capability', typeParams, typeConstraints, typeVariance, extends: parents, methods, span: this.span(start) };
|
|
562
|
+
}
|
|
563
|
+
parseEndpoint() {
|
|
564
|
+
const start = this.expect('endpoint').span;
|
|
565
|
+
const method = this.expect('identifier').value;
|
|
566
|
+
const path = this.expect('string').value;
|
|
567
|
+
this.expect('as');
|
|
568
|
+
const node = this.parseFunction(false, { method, path, status: 200, errors: [] });
|
|
569
|
+
node.span = this.span(start);
|
|
570
|
+
return node;
|
|
571
|
+
}
|
|
572
|
+
parseFunction(externC, endpoint) {
|
|
573
|
+
const valueAbi = externC && this.at('identifier') && this.current().value === 'value' ? (this.take(), true) : undefined;
|
|
574
|
+
const nativePure = valueAbi && this.match('pure') ? true : undefined;
|
|
575
|
+
const annotations = this.at('[') ? this.parseAnnotations() : undefined;
|
|
576
|
+
if (this.at('function') || this.looksLikeMistypedFunctionKeyword())
|
|
577
|
+
this.rejectDeclarationKeyword();
|
|
578
|
+
const start = this.current().span;
|
|
579
|
+
const name = ['start', 'wait', 'missing'].includes(this.current().kind) ? this.take().value : this.expect('identifier').value;
|
|
580
|
+
const { typeParams, typeConstraints, typeVariance } = this.parseTypeParams();
|
|
581
|
+
const params = this.parseParams(false, !!endpoint);
|
|
582
|
+
if (this.at('=>'))
|
|
583
|
+
throw new ParseFailure({ ...start, code: 'PARSE',
|
|
584
|
+
message: `${name} has a constructor body; add implements Interface after that body to declare a class` });
|
|
585
|
+
let returns = syntheticType('void', start);
|
|
586
|
+
let returnOwnership = 'managed';
|
|
587
|
+
const throws = [];
|
|
588
|
+
const changes = [];
|
|
589
|
+
const uses = [];
|
|
590
|
+
const clauses = new Set();
|
|
591
|
+
while (['returns', 'streams', 'unless', 'throws', 'changes', 'uses', ...(endpoint ? ['with'] : [])].includes(this.current().kind)) {
|
|
592
|
+
const clause = this.take();
|
|
593
|
+
if (clause.kind === 'with') {
|
|
594
|
+
this.word('status');
|
|
595
|
+
endpoint.status = Number(this.expect('number').value);
|
|
596
|
+
continue;
|
|
597
|
+
}
|
|
598
|
+
if (clause.kind === 'throws')
|
|
599
|
+
throw new ParseFailure({ ...clause.span,
|
|
600
|
+
code: 'PARSE', message: 'Use unless instead of throws in error contracts' });
|
|
601
|
+
if (clauses.has(clause.kind))
|
|
602
|
+
throw new ParseFailure({ ...clause.span,
|
|
603
|
+
code: 'PARSE', message: `Duplicate ${clause.kind} clause` });
|
|
604
|
+
clauses.add(clause.kind);
|
|
605
|
+
if (clause.kind === 'returns' || clause.kind === 'streams') {
|
|
606
|
+
if (clause.kind === 'streams' && !endpoint || clauses.has('streams') && clauses.has('returns'))
|
|
607
|
+
throw new ParseFailure({ ...clause.span, code: 'HTTP', message: 'An endpoint declares either returns T or streams T' });
|
|
608
|
+
if (clause.kind === 'streams')
|
|
609
|
+
endpoint.streams = true;
|
|
610
|
+
if (this.match('own'))
|
|
611
|
+
returnOwnership = 'own';
|
|
612
|
+
returns = this.parseType();
|
|
613
|
+
}
|
|
614
|
+
else if (clause.kind === 'unless') {
|
|
615
|
+
do {
|
|
616
|
+
const type = this.parseType();
|
|
617
|
+
throws.push(type);
|
|
618
|
+
if (endpoint && this.match('with')) {
|
|
619
|
+
this.word('status');
|
|
620
|
+
endpoint.errors.push({ type, status: Number(this.expect('number').value) });
|
|
621
|
+
}
|
|
622
|
+
} while (this.match(',') || this.match('and'));
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
do {
|
|
626
|
+
const effectStart = this.current().span;
|
|
627
|
+
const path = [(this.match('C') ?? this.expect('identifier')).value];
|
|
628
|
+
while (this.match('.'))
|
|
629
|
+
path.push(this.expect('identifier').value);
|
|
630
|
+
if (clause.kind === 'changes')
|
|
631
|
+
changes.push(path.join('.'));
|
|
632
|
+
else {
|
|
633
|
+
if (path.length < 2)
|
|
634
|
+
throw new ParseFailure({ ...effectStart, code: 'EFFECT',
|
|
635
|
+
message: 'Name a capability operation, for example uses files.write' });
|
|
636
|
+
uses.push({ source: path.slice(0, -1).join('.'), operation: path.at(-1), span: this.span(effectStart) });
|
|
637
|
+
}
|
|
638
|
+
} while (this.match(',') || this.match('and'));
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
const body = this.at('{') || this.at(':') ? this.parseBlock(start) : (this.endStatement(), undefined);
|
|
642
|
+
if (externC && body) {
|
|
643
|
+
throw new ParseFailure({ file: start.file, line: start.line, column: start.column,
|
|
644
|
+
message: 'extern C functions cannot have a body', code: 'PARSE' });
|
|
645
|
+
}
|
|
646
|
+
return { kind: 'function', name, typeParams, typeConstraints, typeVariance, params, returns, returnOwnership,
|
|
647
|
+
throws, changes, uses, body, externC, valueAbi, nativePure, endpoint, annotations, span: this.span(start) };
|
|
648
|
+
}
|
|
649
|
+
parseTypeParams() {
|
|
650
|
+
if (!this.match('<'))
|
|
651
|
+
return { typeParams: [] };
|
|
652
|
+
const typeParams = [];
|
|
653
|
+
const typeConstraints = {};
|
|
654
|
+
const typeVariance = {};
|
|
655
|
+
do {
|
|
656
|
+
const variance = this.match('in')?.kind ?? this.match('out')?.kind;
|
|
657
|
+
const name = this.expect('identifier').value;
|
|
658
|
+
typeParams.push(name);
|
|
659
|
+
if (variance)
|
|
660
|
+
typeVariance[name] = variance;
|
|
661
|
+
if (this.match('implements')) {
|
|
662
|
+
typeConstraints[name] = [this.parseType()];
|
|
663
|
+
while (this.match('and'))
|
|
664
|
+
typeConstraints[name].push(this.parseType());
|
|
665
|
+
}
|
|
666
|
+
} while (this.match(','));
|
|
667
|
+
this.expect('>');
|
|
668
|
+
return { typeParams, typeConstraints, typeVariance };
|
|
669
|
+
}
|
|
670
|
+
parseParams(fields = false, endpoint = false) {
|
|
671
|
+
this.expect('(');
|
|
672
|
+
const params = [];
|
|
673
|
+
while (!this.at(')') && !this.at('eof')) {
|
|
674
|
+
const start = this.current().span;
|
|
675
|
+
const injected = !!this.match('resolve');
|
|
676
|
+
const mutable = !!this.match('mutable');
|
|
677
|
+
const ownership = this.match('own') ? 'own' : this.match('borrow') ? 'borrow' : 'managed';
|
|
678
|
+
const type = this.parseType();
|
|
679
|
+
const label = /^[A-Za-z_]\w*$/.test(this.current().value) ? this.take().value : this.expect('identifier').value;
|
|
680
|
+
const name = fields && this.match('to') ? this.expect('identifier').value : label;
|
|
681
|
+
let source;
|
|
682
|
+
if (endpoint && this.match('from')) {
|
|
683
|
+
const kind = this.expect('identifier').value;
|
|
684
|
+
if (!['path', 'query', 'header', 'body', 'cookie', 'form', 'request'].includes(kind))
|
|
685
|
+
this.expect('path, query, header, body, cookie, form, or request');
|
|
686
|
+
source = { kind, name: this.at('string') ? this.take().value : undefined };
|
|
687
|
+
}
|
|
688
|
+
if (mutable && !fields)
|
|
689
|
+
throw new ParseFailure({ ...start, code: 'MUTABILITY',
|
|
690
|
+
message: 'mutable declares class storage; use borrow for a mutable function input' });
|
|
691
|
+
params.push({ name, label: fields ? label.replace(/^_/, '') : label, mutable, type, ownership, injected, source, span: this.span(start) });
|
|
692
|
+
if (!this.match(','))
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
this.expect(')');
|
|
696
|
+
return params;
|
|
697
|
+
}
|
|
698
|
+
parseType() {
|
|
699
|
+
const start = this.current().span;
|
|
700
|
+
const optional = this.match('optional') ? true : undefined;
|
|
701
|
+
const name = this.expect('identifier').value;
|
|
702
|
+
const args = [];
|
|
703
|
+
if (this.match('<')) {
|
|
704
|
+
args.push(this.parseType());
|
|
705
|
+
while (this.match(','))
|
|
706
|
+
args.push(this.parseType());
|
|
707
|
+
this.expect('>');
|
|
708
|
+
}
|
|
709
|
+
const legacy = this.match('?');
|
|
710
|
+
if (legacy)
|
|
711
|
+
this.diagnostics.push({ ...legacy.span, code: 'SYNTAX', message: 'Use optional Type instead of Type?; omitted values are null' });
|
|
712
|
+
const nullable = !!optional || !!legacy;
|
|
713
|
+
return { name, args, nullable, optional: nullable || undefined, span: this.span(start) };
|
|
714
|
+
}
|
|
715
|
+
parseBlock(header) {
|
|
716
|
+
this.openBlock(header);
|
|
717
|
+
const body = [];
|
|
718
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
719
|
+
const before = this.position;
|
|
720
|
+
try {
|
|
721
|
+
this.checkBlockIndentation();
|
|
722
|
+
body.push(this.parseStatement());
|
|
723
|
+
}
|
|
724
|
+
catch (error) {
|
|
725
|
+
if (!(error instanceof ParseFailure))
|
|
726
|
+
throw error;
|
|
727
|
+
this.diagnostics.push(error.diagnostic);
|
|
728
|
+
this.recover();
|
|
729
|
+
if (this.position === before && !this.at('eof'))
|
|
730
|
+
this.take();
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
this.closeBrace();
|
|
734
|
+
return Object.assign(body, { span: this.span(header) });
|
|
735
|
+
}
|
|
736
|
+
parseStatement() {
|
|
737
|
+
const start = this.current().span;
|
|
738
|
+
if (this.match('yield')) {
|
|
739
|
+
const value = this.parseExpression();
|
|
740
|
+
this.endStatement();
|
|
741
|
+
return { kind: 'yield', value, span: this.span(start) };
|
|
742
|
+
}
|
|
743
|
+
if (this.match('serve')) {
|
|
744
|
+
const names = [this.expect('identifier').value];
|
|
745
|
+
while (this.match('and') || this.match(','))
|
|
746
|
+
names.push(this.expect('identifier').value);
|
|
747
|
+
this.word('on');
|
|
748
|
+
this.word('port');
|
|
749
|
+
const port = this.parseExpression();
|
|
750
|
+
this.endStatement();
|
|
751
|
+
return { kind: 'serve', names, port, span: this.span(start) };
|
|
752
|
+
}
|
|
753
|
+
if (this.match('freeze')) {
|
|
754
|
+
const value = this.parseExpression();
|
|
755
|
+
this.expect('as');
|
|
756
|
+
const name = this.expect('identifier').value;
|
|
757
|
+
this.endStatement();
|
|
758
|
+
return { kind: 'freeze', value, name, span: this.span(start) };
|
|
759
|
+
}
|
|
760
|
+
if (this.at('wait')) {
|
|
761
|
+
const saved = this.position;
|
|
762
|
+
const value = this.parseUnary();
|
|
763
|
+
if (this.match('to') || this.match('as')) {
|
|
764
|
+
const names = [this.expect('identifier').value];
|
|
765
|
+
while (this.match('and') || this.match(','))
|
|
766
|
+
names.push(this.expect('identifier').value);
|
|
767
|
+
this.endStatement();
|
|
768
|
+
return names.length === 1 ? { kind: 'assign', target: { kind: 'name', name: names[0], span: start }, value, ownership: 'managed', span: this.span(start) } :
|
|
769
|
+
{ kind: 'destructure', names, value, span: this.span(start) };
|
|
770
|
+
}
|
|
771
|
+
this.position = saved;
|
|
772
|
+
}
|
|
773
|
+
if (this.looksLikeBareFunction()) {
|
|
774
|
+
const saved = this.position;
|
|
775
|
+
this.take();
|
|
776
|
+
this.parseTypeParams();
|
|
777
|
+
const params = this.parseParams();
|
|
778
|
+
const declaration = params.length > 0 || ['returns', 'unless', 'changes', 'uses', '{', ':'].includes(this.current().kind);
|
|
779
|
+
this.position = saved;
|
|
780
|
+
if (declaration)
|
|
781
|
+
throw new ParseFailure({ ...start, code: 'PARSE',
|
|
782
|
+
message: 'A nested declaration needs a class header with implements Interface; functions cannot contain declarations' });
|
|
783
|
+
}
|
|
784
|
+
if (this.emptyBody())
|
|
785
|
+
return { kind: 'expr', expr: { kind: 'literal', value: null, span: start }, span: this.span(start) };
|
|
786
|
+
if (this.match('return')) {
|
|
787
|
+
const value = this.at(';') || this.at('}') || this.at('eof') || this.lineBreak() ? undefined : this.parseExpression();
|
|
788
|
+
this.endStatement();
|
|
789
|
+
return { kind: 'return', value, span: this.span(start) };
|
|
790
|
+
}
|
|
791
|
+
if (this.match('throw')) {
|
|
792
|
+
const value = this.parseExpression();
|
|
793
|
+
this.endStatement();
|
|
794
|
+
return { kind: 'throw', value, span: this.span(start) };
|
|
795
|
+
}
|
|
796
|
+
if (this.match('for')) {
|
|
797
|
+
const names = this.patternNames();
|
|
798
|
+
this.expect('in');
|
|
799
|
+
const iterable = this.parseExpression();
|
|
800
|
+
return { kind: 'for', names, iterable, body: this.parseBlock(start), span: this.span(start) };
|
|
801
|
+
}
|
|
802
|
+
if (this.match('match')) {
|
|
803
|
+
const value = this.parseExpression();
|
|
804
|
+
this.openBlock(start);
|
|
805
|
+
const cases = [];
|
|
806
|
+
while (!this.at('}') && !this.at('eof')) {
|
|
807
|
+
this.checkBlockIndentation();
|
|
808
|
+
const caseStart = this.current().span;
|
|
809
|
+
let pattern;
|
|
810
|
+
let literal, type, name;
|
|
811
|
+
if (this.match('else'))
|
|
812
|
+
pattern = 'else';
|
|
813
|
+
else {
|
|
814
|
+
this.expect('when');
|
|
815
|
+
if (this.match('missing'))
|
|
816
|
+
pattern = 'null';
|
|
817
|
+
else if (this.match('null'))
|
|
818
|
+
pattern = 'null';
|
|
819
|
+
else if (this.match('some')) {
|
|
820
|
+
pattern = 'some';
|
|
821
|
+
name = this.expect('identifier').value;
|
|
822
|
+
}
|
|
823
|
+
else if (this.at('identifier')) {
|
|
824
|
+
pattern = 'type';
|
|
825
|
+
type = this.parseType();
|
|
826
|
+
name = this.expect('identifier').value;
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
pattern = 'literal';
|
|
830
|
+
literal = this.parsePrimary();
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
cases.push({ pattern, literal, type, name, body: this.parseBlock(caseStart), span: this.span(caseStart) });
|
|
834
|
+
}
|
|
835
|
+
this.closeBrace();
|
|
836
|
+
return { kind: 'match', value, cases, span: this.span(start) };
|
|
837
|
+
}
|
|
838
|
+
if (this.match('if')) {
|
|
839
|
+
const test = this.parseExpression();
|
|
840
|
+
const then = this.parseBlock(start);
|
|
841
|
+
const elseToken = this.match('else');
|
|
842
|
+
const otherwise = elseToken ? (this.at('if') ? [this.parseStatement()] : this.parseBlock(elseToken.span)) : [];
|
|
843
|
+
return { kind: 'if', test, then, otherwise, span: this.span(start) };
|
|
844
|
+
}
|
|
845
|
+
if (this.match('while')) {
|
|
846
|
+
const test = this.parseExpression();
|
|
847
|
+
return { kind: 'while', test, body: this.parseBlock(start), span: this.span(start) };
|
|
848
|
+
}
|
|
849
|
+
if (this.match('try')) {
|
|
850
|
+
const body = this.parseBlock(start);
|
|
851
|
+
const catches = [];
|
|
852
|
+
while (this.match('catch')) {
|
|
853
|
+
const catchStart = this.tokens[this.position - 1].span;
|
|
854
|
+
const type = this.parseType();
|
|
855
|
+
const name = this.expect('identifier').value;
|
|
856
|
+
catches.push({ type, name, body: this.parseBlock(catchStart), span: this.span(catchStart) });
|
|
857
|
+
}
|
|
858
|
+
const always = this.match('always') ? this.parseBlock(start) : undefined;
|
|
859
|
+
if (catches.length === 0 && !always)
|
|
860
|
+
this.expect('catch');
|
|
861
|
+
return { kind: 'try', body, catches, always, span: this.span(start) };
|
|
862
|
+
}
|
|
863
|
+
if (this.match('unsafe'))
|
|
864
|
+
return { kind: 'unsafe', body: this.parseBlock(start), span: this.span(start) };
|
|
865
|
+
if (this.match('scope'))
|
|
866
|
+
return { kind: 'scope', body: this.parseBlock(start), span: this.span(start) };
|
|
867
|
+
if (this.match('lock')) {
|
|
868
|
+
const value = this.parseExpression();
|
|
869
|
+
this.expect('as');
|
|
870
|
+
const name = this.expect('identifier').value;
|
|
871
|
+
return { kind: 'lock', value, name, body: this.parseBlock(start), span: this.span(start) };
|
|
872
|
+
}
|
|
873
|
+
if (this.match('borrow')) {
|
|
874
|
+
const name = this.expect('identifier').value;
|
|
875
|
+
return { kind: 'borrow', name, body: this.parseBlock(start), span: this.span(start) };
|
|
876
|
+
}
|
|
877
|
+
if (this.at('resolve')) {
|
|
878
|
+
const saved = this.position;
|
|
879
|
+
const value = this.parseUnary(true);
|
|
880
|
+
if (value.kind === 'resolve' && this.match('to')) {
|
|
881
|
+
const name = this.expect('identifier');
|
|
882
|
+
this.endStatement();
|
|
883
|
+
return { kind: 'assign', target: { kind: 'name', name: name.value, span: name.span },
|
|
884
|
+
value, ownership: 'managed', span: this.span(start) };
|
|
885
|
+
}
|
|
886
|
+
this.position = saved;
|
|
887
|
+
}
|
|
888
|
+
const ownership = this.match('own') ? 'own' : 'managed';
|
|
889
|
+
const saved = this.position;
|
|
890
|
+
if (this.at('identifier') || this.at('optional')) {
|
|
891
|
+
try {
|
|
892
|
+
const declaredType = this.parseType();
|
|
893
|
+
if (this.at('identifier') && ['=', 'to'].includes(this.current(1).kind)) {
|
|
894
|
+
const nameToken = this.take();
|
|
895
|
+
this.take();
|
|
896
|
+
const value = this.parseExpression();
|
|
897
|
+
this.endStatement();
|
|
898
|
+
return { kind: 'assign', target: { kind: 'name', name: nameToken.value, span: nameToken.span },
|
|
899
|
+
value, declaredType, ownership, span: this.span(start) };
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
catch (error) {
|
|
903
|
+
if (!(error instanceof ParseFailure))
|
|
904
|
+
throw error;
|
|
905
|
+
}
|
|
906
|
+
this.position = saved;
|
|
907
|
+
}
|
|
908
|
+
if (ownership === 'own') {
|
|
909
|
+
const token = this.current();
|
|
910
|
+
throw new ParseFailure({ file: token.span.file, line: token.span.line, column: token.span.column,
|
|
911
|
+
message: 'own requires a typed variable declaration', code: 'PARSE' });
|
|
912
|
+
}
|
|
913
|
+
const target = this.parseExpression();
|
|
914
|
+
if (this.match('=') || this.match('to')) {
|
|
915
|
+
const value = this.parseExpression();
|
|
916
|
+
this.endStatement();
|
|
917
|
+
if (target.kind === 'collection' && target.collection === 'Tuple' && target.items.every(item => item.kind === 'name'))
|
|
918
|
+
return { kind: 'destructure', names: target.items.map(item => item.name), value, span: this.span(start) };
|
|
919
|
+
return { kind: 'assign', target, value, ownership, span: this.span(start) };
|
|
920
|
+
}
|
|
921
|
+
this.endStatement();
|
|
922
|
+
return { kind: 'expr', expr: target, span: this.span(start) };
|
|
923
|
+
}
|
|
924
|
+
patternNames() {
|
|
925
|
+
if (!this.match('('))
|
|
926
|
+
return [this.expect('identifier').value];
|
|
927
|
+
const names = [this.expect('identifier').value];
|
|
928
|
+
while (this.match(','))
|
|
929
|
+
names.push(this.expect('identifier').value);
|
|
930
|
+
this.expect(')');
|
|
931
|
+
return names;
|
|
932
|
+
}
|
|
933
|
+
parseExpression(min = 0) {
|
|
934
|
+
let left = this.parseUnary();
|
|
935
|
+
const precedence = { 'or': 1, 'and': 2, '||': 1, '&&': 2, '==': 3, '!=': 3,
|
|
936
|
+
'<': 4, '>': 4, '<=': 4, '>=': 4, '+': 5, '-': 5, '*': 6, '/': 6 };
|
|
937
|
+
while ((this.expressionDepth > 0 || !this.lineBreak()) && (precedence[this.current().kind] ?? 0) > min) {
|
|
938
|
+
const op = this.take().kind;
|
|
939
|
+
const right = this.parseExpression(precedence[op]);
|
|
940
|
+
left = { kind: 'binary', op: op === 'and' ? '&&' : op === 'or' ? '||' : op, left, right, span: this.span(left.span, right.span) };
|
|
941
|
+
}
|
|
942
|
+
return left;
|
|
943
|
+
}
|
|
944
|
+
parseUnary(allowResolve = false) {
|
|
945
|
+
if (this.match('not')) {
|
|
946
|
+
const start = this.tokens[this.position - 1].span;
|
|
947
|
+
const value = this.parseExpression(2);
|
|
948
|
+
return { kind: 'unary', op: '!', value, span: this.span(start, value.span) };
|
|
949
|
+
}
|
|
950
|
+
if (this.match('handle')) {
|
|
951
|
+
const start = this.tokens[this.position - 1].span;
|
|
952
|
+
return { kind: 'handle', call: this.parseUnary(), span: this.span(start) };
|
|
953
|
+
}
|
|
954
|
+
if (this.at('start') && this.current(1).kind !== '(' && this.match('start')) {
|
|
955
|
+
const start = this.tokens[this.position - 1].span;
|
|
956
|
+
const call = this.parseUnary();
|
|
957
|
+
return { kind: 'start', call, span: this.span(start) };
|
|
958
|
+
}
|
|
959
|
+
if (this.at('wait') && this.current(1).kind === 'for' && this.match('wait')) {
|
|
960
|
+
const start = this.tokens[this.position - 1].span;
|
|
961
|
+
this.expect('for');
|
|
962
|
+
const tasks = [this.parseUnary()];
|
|
963
|
+
while (this.match('and'))
|
|
964
|
+
tasks.push(this.parseUnary());
|
|
965
|
+
return { kind: 'wait', tasks, span: this.span(start) };
|
|
966
|
+
}
|
|
967
|
+
if (this.at('!') || this.at('-')) {
|
|
968
|
+
const token = this.take();
|
|
969
|
+
const value = this.parseUnary();
|
|
970
|
+
if (token.kind === '-' && value.kind === 'literal' && typeof value.value === 'number')
|
|
971
|
+
return { ...value, value: -value.value, numericText: value.numericText ? `-${value.numericText}` : undefined,
|
|
972
|
+
span: this.span(token.span, value.span) };
|
|
973
|
+
return { kind: 'unary', op: token.kind, value, span: this.span(token.span, value.span) };
|
|
974
|
+
}
|
|
975
|
+
if (this.match('resolve')) {
|
|
976
|
+
const start = this.tokens[this.position - 1].span;
|
|
977
|
+
if (!allowResolve)
|
|
978
|
+
this.diagnostics.push({ ...start, code: 'SYNTAX', message: 'Use resolve Key to name as a statement instead of an assignment or expression' });
|
|
979
|
+
const name = this.expect('identifier');
|
|
980
|
+
const typeArgs = this.at('<') ? this.parseCallTypeArgs() : [];
|
|
981
|
+
return { kind: 'resolve', name: name.value, typeArgs, span: this.span(start) };
|
|
982
|
+
}
|
|
983
|
+
let expr = this.parsePrimary();
|
|
984
|
+
while (true) {
|
|
985
|
+
if (this.expressionDepth === 0 && this.lineBreak())
|
|
986
|
+
break;
|
|
987
|
+
if (this.match('.')) {
|
|
988
|
+
const name = /^[A-Za-z_]\w*$/.test(this.current().value) ? this.take() : this.expect('identifier');
|
|
989
|
+
expr = { kind: 'member', object: expr, name: name.value, span: this.span(expr.span, name.span) };
|
|
990
|
+
continue;
|
|
991
|
+
}
|
|
992
|
+
const typeArgs = this.looksLikeGenericCall() ? this.parseCallTypeArgs() : [];
|
|
993
|
+
if (this.match('(')) {
|
|
994
|
+
this.expressionDepth++;
|
|
995
|
+
const args = [];
|
|
996
|
+
const argLabels = [];
|
|
997
|
+
const argument = () => {
|
|
998
|
+
let label;
|
|
999
|
+
if (/^[A-Za-z_]\w*$/.test(this.current().value) && ['=', 'to'].includes(this.current(1).kind)) {
|
|
1000
|
+
label = this.take().value;
|
|
1001
|
+
this.take();
|
|
1002
|
+
}
|
|
1003
|
+
argLabels.push(label);
|
|
1004
|
+
args.push(this.parseExpression());
|
|
1005
|
+
};
|
|
1006
|
+
if (!this.at(')')) {
|
|
1007
|
+
argument();
|
|
1008
|
+
while (this.match(',') && !this.at(')'))
|
|
1009
|
+
argument();
|
|
1010
|
+
}
|
|
1011
|
+
const end = this.expect(')').span;
|
|
1012
|
+
this.expressionDepth--;
|
|
1013
|
+
expr = { kind: 'call', callee: expr, args, argLabels, typeArgs,
|
|
1014
|
+
span: this.span(expr.span, end) };
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
return expr;
|
|
1020
|
+
}
|
|
1021
|
+
looksLikeGenericCall() {
|
|
1022
|
+
if (!this.at('<'))
|
|
1023
|
+
return false;
|
|
1024
|
+
let depth = 0;
|
|
1025
|
+
for (let i = this.position; i < this.tokens.length; i++) {
|
|
1026
|
+
const kind = this.tokens[i].kind;
|
|
1027
|
+
if (kind === '<')
|
|
1028
|
+
depth++;
|
|
1029
|
+
if (kind === '>') {
|
|
1030
|
+
depth--;
|
|
1031
|
+
if (depth === 0)
|
|
1032
|
+
return this.tokens[i + 1]?.kind === '(';
|
|
1033
|
+
}
|
|
1034
|
+
if (kind === ';' || kind === 'eof')
|
|
1035
|
+
break;
|
|
1036
|
+
}
|
|
1037
|
+
return false;
|
|
1038
|
+
}
|
|
1039
|
+
parseCallTypeArgs() {
|
|
1040
|
+
this.expect('<');
|
|
1041
|
+
const args = [this.parseType()];
|
|
1042
|
+
while (this.match(','))
|
|
1043
|
+
args.push(this.parseType());
|
|
1044
|
+
this.expect('>');
|
|
1045
|
+
return args;
|
|
1046
|
+
}
|
|
1047
|
+
parsePrimary() {
|
|
1048
|
+
const token = this.current();
|
|
1049
|
+
if (token.value === 'input' && this.current(1).kind === 'from' && this.current(2).value === 'form') {
|
|
1050
|
+
this.take();
|
|
1051
|
+
this.take();
|
|
1052
|
+
this.take();
|
|
1053
|
+
return { kind: 'formInput', span: this.span(token.span) };
|
|
1054
|
+
}
|
|
1055
|
+
if (this.at('jsx_open'))
|
|
1056
|
+
return this.parseMarkup();
|
|
1057
|
+
if (['start', 'wait', 'missing'].includes(token.kind) && this.current(1).kind === '(') {
|
|
1058
|
+
this.take();
|
|
1059
|
+
return { kind: 'name', name: token.value, span: token.span };
|
|
1060
|
+
}
|
|
1061
|
+
if (this.match('number'))
|
|
1062
|
+
return { kind: 'literal', value: Number(token.value),
|
|
1063
|
+
numericType: token.value.includes('.') ? 'float' : 'int', numericText: token.value, span: token.span };
|
|
1064
|
+
if (this.match('string'))
|
|
1065
|
+
return { kind: 'literal', value: token.value, span: token.span };
|
|
1066
|
+
if (this.match('true'))
|
|
1067
|
+
return { kind: 'literal', value: true, span: token.span };
|
|
1068
|
+
if (this.match('false'))
|
|
1069
|
+
return { kind: 'literal', value: false, span: token.span };
|
|
1070
|
+
if (this.match('null'))
|
|
1071
|
+
return { kind: 'literal', value: null, span: token.span };
|
|
1072
|
+
if (this.match('missing'))
|
|
1073
|
+
return { kind: 'literal', value: null, span: token.span };
|
|
1074
|
+
if (this.match('identifier'))
|
|
1075
|
+
return { kind: 'name', name: token.value, span: token.span };
|
|
1076
|
+
if (this.at('[') || this.at('{') || this.at('(')) {
|
|
1077
|
+
const opening = this.take();
|
|
1078
|
+
const closing = opening.kind === '[' ? ']' : opening.kind === '{' ? '}' : ')';
|
|
1079
|
+
this.expressionDepth++;
|
|
1080
|
+
const items = [];
|
|
1081
|
+
let collection = opening.kind === '[' ? 'List' : opening.kind === '{' ? 'empty' : 'Tuple';
|
|
1082
|
+
let comma = false;
|
|
1083
|
+
if (!this.at(closing)) {
|
|
1084
|
+
do {
|
|
1085
|
+
items.push(this.parseExpression());
|
|
1086
|
+
if (opening.kind === '{') {
|
|
1087
|
+
const pair = !!this.match(':');
|
|
1088
|
+
const nextKind = pair ? 'Map' : 'Set';
|
|
1089
|
+
if (collection !== 'empty' && collection !== nextKind)
|
|
1090
|
+
throw new ParseFailure({ ...this.current().span,
|
|
1091
|
+
code: 'COLLECTION', message: 'A literal cannot mix set items and map entries' });
|
|
1092
|
+
collection = nextKind;
|
|
1093
|
+
if (pair)
|
|
1094
|
+
items.push(this.parseExpression());
|
|
1095
|
+
}
|
|
1096
|
+
comma = !!this.match(',');
|
|
1097
|
+
} while (comma && !this.at(closing) && !this.at('eof'));
|
|
1098
|
+
}
|
|
1099
|
+
this.expect(closing);
|
|
1100
|
+
this.expressionDepth--;
|
|
1101
|
+
if (opening.kind === '(' && items.length === 1 && !comma)
|
|
1102
|
+
return items[0];
|
|
1103
|
+
return { kind: 'collection', collection, items, span: this.span(opening.span) };
|
|
1104
|
+
}
|
|
1105
|
+
throw new ParseFailure({ file: token.span.file, line: token.span.line, column: token.span.column,
|
|
1106
|
+
message: `Expected expression, found ${JSON.stringify(token.value)}`, code: 'PARSE' });
|
|
1107
|
+
}
|
|
1108
|
+
parseMarkup() {
|
|
1109
|
+
const start = this.expect('jsx_open').span;
|
|
1110
|
+
const tag = this.match('jsx_name')?.value ?? '';
|
|
1111
|
+
const attributes = [], children = [];
|
|
1112
|
+
while (!this.at('jsx_end') && !this.at('jsx_self') && !this.at('eof')) {
|
|
1113
|
+
const name = this.expect('jsx_name');
|
|
1114
|
+
let value = { kind: 'literal', value: true, span: name.span };
|
|
1115
|
+
if (this.match('=')) {
|
|
1116
|
+
if (this.match('{')) {
|
|
1117
|
+
this.expressionDepth++;
|
|
1118
|
+
value = this.parseExpression();
|
|
1119
|
+
this.expect('}');
|
|
1120
|
+
this.expressionDepth--;
|
|
1121
|
+
}
|
|
1122
|
+
else {
|
|
1123
|
+
const text = this.expect('string');
|
|
1124
|
+
value = { kind: 'literal', value: text.value, span: text.span };
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
attributes.push({ name: name.value, value, span: name.span });
|
|
1128
|
+
}
|
|
1129
|
+
if (this.match('jsx_self'))
|
|
1130
|
+
return { kind: 'markup', tag, attributes, children, span: this.span(start) };
|
|
1131
|
+
this.expect('jsx_end');
|
|
1132
|
+
while (!this.at('jsx_close') && !this.at('eof')) {
|
|
1133
|
+
if (this.at('jsx_open'))
|
|
1134
|
+
children.push(this.parseMarkup());
|
|
1135
|
+
else if (this.match('{')) {
|
|
1136
|
+
this.expressionDepth++;
|
|
1137
|
+
children.push(this.parseExpression());
|
|
1138
|
+
this.expect('}');
|
|
1139
|
+
this.expressionDepth--;
|
|
1140
|
+
}
|
|
1141
|
+
else {
|
|
1142
|
+
const text = this.expect('jsx_text');
|
|
1143
|
+
const value = text.value.includes('\n') ? text.value.split(/\r?\n/).map(line => line.trim()).filter(Boolean).join(' ') : text.value;
|
|
1144
|
+
if (value)
|
|
1145
|
+
children.push({ kind: 'markupText', text: value, span: text.span });
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
this.expect('jsx_close');
|
|
1149
|
+
const closing = this.match('jsx_name')?.value ?? '';
|
|
1150
|
+
if (closing !== tag)
|
|
1151
|
+
throw new ParseFailure({ ...start, code: 'HTML', message: `Close <${tag}> with </${tag}>` });
|
|
1152
|
+
this.expect('jsx_close_end');
|
|
1153
|
+
return { kind: 'markup', tag, attributes, children, span: this.span(start) };
|
|
1154
|
+
}
|
|
1155
|
+
}
|