sdkloom 0.0.0-stage → 0.1.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 +202 -0
- package/README.md +239 -2
- package/kits/allowed-sources.json +24 -0
- package/kits/csharp/kit.json +6 -0
- package/kits/csharp/src/Runtime/Client.cs +295 -0
- package/kits/csharp/src/Runtime/Context.cs +216 -0
- package/kits/csharp/src/Runtime/Errors.cs +121 -0
- package/kits/csharp/src/Runtime/Http.cs +218 -0
- package/kits/csharp/src/Runtime/Json.cs +650 -0
- package/kits/csharp/src/Runtime/Lang.cs +212 -0
- package/kits/csharp/src/Runtime/Models.cs +206 -0
- package/kits/csharp/src/Runtime/Multipart.cs +108 -0
- package/kits/csharp/src/Runtime/Pagination.cs +122 -0
- package/kits/csharp/src/Runtime/Sse.cs +197 -0
- package/kits/csharp/src/Runtime/Testing.cs +375 -0
- package/kits/csharp/src/Runtime/Transport.cs +212 -0
- package/kits/csharp/src/Runtime/Wait.cs +57 -0
- package/kits/csharp/src/Runtime/Webhooks.cs +148 -0
- package/kits/csharp/tests/ClientTests.cs +128 -0
- package/kits/csharp/tests/HttpTests.cs +44 -0
- package/kits/csharp/tests/JsonTests.cs +132 -0
- package/kits/csharp/tests/LangTests.cs +57 -0
- package/kits/csharp/tests/MultipartTests.cs +31 -0
- package/kits/csharp/tests/PaginationTests.cs +93 -0
- package/kits/csharp/tests/SseTests.cs +122 -0
- package/kits/csharp/tests/TestRunner.cs +93 -0
- package/kits/csharp/tests/TestingTests.cs +80 -0
- package/kits/csharp/tests/TransportTests.cs +145 -0
- package/kits/csharp/tests/WaitTests.cs +39 -0
- package/kits/csharp/tests/WebhooksTests.cs +46 -0
- package/kits/csharp/versions.json +12 -0
- package/kits/go/kit.json +6 -0
- package/kits/go/src/sdkruntime/client.go +322 -0
- package/kits/go/src/sdkruntime/context.go +207 -0
- package/kits/go/src/sdkruntime/errors.go +74 -0
- package/kits/go/src/sdkruntime/http.go +261 -0
- package/kits/go/src/sdkruntime/json.go +527 -0
- package/kits/go/src/sdkruntime/lang.go +462 -0
- package/kits/go/src/sdkruntime/multipart.go +75 -0
- package/kits/go/src/sdkruntime/pagination.go +150 -0
- package/kits/go/src/sdkruntime/sse.go +267 -0
- package/kits/go/src/sdkruntime/testing.go +343 -0
- package/kits/go/src/sdkruntime/transport.go +168 -0
- package/kits/go/src/sdkruntime/wait.go +49 -0
- package/kits/go/src/sdkruntime/webhooks.go +129 -0
- package/kits/go/tests/client_test.go +185 -0
- package/kits/go/tests/http_test.go +78 -0
- package/kits/go/tests/json_test.go +127 -0
- package/kits/go/tests/lang_test.go +98 -0
- package/kits/go/tests/multipart_test.go +29 -0
- package/kits/go/tests/pagination_test.go +69 -0
- package/kits/go/tests/sse_test.go +129 -0
- package/kits/go/tests/testing_test.go +121 -0
- package/kits/go/tests/transport_test.go +133 -0
- package/kits/go/tests/wait_test.go +46 -0
- package/kits/go/tests/webhooks_test.go +62 -0
- package/kits/go/versions.json +12 -0
- package/kits/java/kit.json +6 -0
- package/kits/java/src/dev/sdkloom/runtime/ApiException.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/ArgumentException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Assert.java +72 -0
- package/kits/java/src/dev/sdkloom/runtime/ClientRuntime.java +220 -0
- package/kits/java/src/dev/sdkloom/runtime/Clock.java +39 -0
- package/kits/java/src/dev/sdkloom/runtime/Context.java +79 -0
- package/kits/java/src/dev/sdkloom/runtime/Decode.java +200 -0
- package/kits/java/src/dev/sdkloom/runtime/DecodeException.java +26 -0
- package/kits/java/src/dev/sdkloom/runtime/Decoder.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/Emitter.java +56 -0
- package/kits/java/src/dev/sdkloom/runtime/ErrorFactory.java +18 -0
- package/kits/java/src/dev/sdkloom/runtime/EventListener.java +20 -0
- package/kits/java/src/dev/sdkloom/runtime/EventStream.java +232 -0
- package/kits/java/src/dev/sdkloom/runtime/FakeClock.java +37 -0
- package/kits/java/src/dev/sdkloom/runtime/Headers.java +42 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpRequest.java +88 -0
- package/kits/java/src/dev/sdkloom/runtime/HttpResponse.java +69 -0
- package/kits/java/src/dev/sdkloom/runtime/JdkTransport.java +97 -0
- package/kits/java/src/dev/sdkloom/runtime/Js.java +230 -0
- package/kits/java/src/dev/sdkloom/runtime/Json.java +281 -0
- package/kits/java/src/dev/sdkloom/runtime/JsonValue.java +15 -0
- package/kits/java/src/dev/sdkloom/runtime/Links.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/Middleware.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/MiddlewareEntry.java +43 -0
- package/kits/java/src/dev/sdkloom/runtime/MockRoute.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/MockTransport.java +62 -0
- package/kits/java/src/dev/sdkloom/runtime/MultipartForm.java +111 -0
- package/kits/java/src/dev/sdkloom/runtime/Next.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationInfo.java +35 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationMock.java +105 -0
- package/kits/java/src/dev/sdkloom/runtime/OperationSpec.java +125 -0
- package/kits/java/src/dev/sdkloom/runtime/Pages.java +55 -0
- package/kits/java/src/dev/sdkloom/runtime/Pipeline.java +29 -0
- package/kits/java/src/dev/sdkloom/runtime/RawResult.java +31 -0
- package/kits/java/src/dev/sdkloom/runtime/RecordedEvent.java +36 -0
- package/kits/java/src/dev/sdkloom/runtime/SdkInfo.java +38 -0
- package/kits/java/src/dev/sdkloom/runtime/SendOptions.java +34 -0
- package/kits/java/src/dev/sdkloom/runtime/ServerSentEvent.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/State.java +58 -0
- package/kits/java/src/dev/sdkloom/runtime/Test.java +21 -0
- package/kits/java/src/dev/sdkloom/runtime/TestRunner.java +63 -0
- package/kits/java/src/dev/sdkloom/runtime/Transport.java +16 -0
- package/kits/java/src/dev/sdkloom/runtime/TransportException.java +30 -0
- package/kits/java/src/dev/sdkloom/runtime/UrlConnectionTransport.java +195 -0
- package/kits/java/src/dev/sdkloom/runtime/Urls.java +116 -0
- package/kits/java/src/dev/sdkloom/runtime/Waits.java +53 -0
- package/kits/java/src/dev/sdkloom/runtime/WebhookSignatureException.java +24 -0
- package/kits/java/src/dev/sdkloom/runtime/Webhooks.java +146 -0
- package/kits/java/tests/dev/sdkloom/runtime/ClientTest.java +266 -0
- package/kits/java/tests/dev/sdkloom/runtime/EventStreamTest.java +131 -0
- package/kits/java/tests/dev/sdkloom/runtime/HttpTest.java +95 -0
- package/kits/java/tests/dev/sdkloom/runtime/JdkTransportTest.java +12 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsTest.java +102 -0
- package/kits/java/tests/dev/sdkloom/runtime/JsonTest.java +87 -0
- package/kits/java/tests/dev/sdkloom/runtime/LinksTest.java +22 -0
- package/kits/java/tests/dev/sdkloom/runtime/MultipartFormTest.java +30 -0
- package/kits/java/tests/dev/sdkloom/runtime/PagesTest.java +75 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestData.java +53 -0
- package/kits/java/tests/dev/sdkloom/runtime/TestingTest.java +156 -0
- package/kits/java/tests/dev/sdkloom/runtime/TransportContract.java +201 -0
- package/kits/java/tests/dev/sdkloom/runtime/UrlConnectionTransportTest.java +49 -0
- package/kits/java/tests/dev/sdkloom/runtime/WaitsTest.java +43 -0
- package/kits/java/tests/dev/sdkloom/runtime/WebhooksTest.java +45 -0
- package/kits/java/versions.json +41 -0
- package/kits/python/kit.json +6 -0
- package/kits/python/src/sdkloom_runtime/__init__.py +1 -0
- package/kits/python/src/sdkloom_runtime/client.py +232 -0
- package/kits/python/src/sdkloom_runtime/compat.py +195 -0
- package/kits/python/src/sdkloom_runtime/context.py +134 -0
- package/kits/python/src/sdkloom_runtime/errors.py +65 -0
- package/kits/python/src/sdkloom_runtime/http.py +192 -0
- package/kits/python/src/sdkloom_runtime/lang.py +207 -0
- package/kits/python/src/sdkloom_runtime/models.py +221 -0
- package/kits/python/src/sdkloom_runtime/multipart.py +69 -0
- package/kits/python/src/sdkloom_runtime/pagination.py +61 -0
- package/kits/python/src/sdkloom_runtime/pipeline.py +39 -0
- package/kits/python/src/sdkloom_runtime/sse.py +121 -0
- package/kits/python/src/sdkloom_runtime/testing.py +224 -0
- package/kits/python/src/sdkloom_runtime/transport.py +120 -0
- package/kits/python/src/sdkloom_runtime/wait.py +44 -0
- package/kits/python/src/sdkloom_runtime/webhooks.py +84 -0
- package/kits/python/tests/support.py +28 -0
- package/kits/python/tests/test_client.py +275 -0
- package/kits/python/tests/test_compat.py +87 -0
- package/kits/python/tests/test_http.py +94 -0
- package/kits/python/tests/test_lang.py +104 -0
- package/kits/python/tests/test_models.py +110 -0
- package/kits/python/tests/test_multipart.py +37 -0
- package/kits/python/tests/test_pagination.py +70 -0
- package/kits/python/tests/test_sse.py +61 -0
- package/kits/python/tests/test_testing.py +130 -0
- package/kits/python/tests/test_transport.py +124 -0
- package/kits/python/tests/test_wait.py +46 -0
- package/kits/python/tests/test_webhooks.py +57 -0
- package/kits/python/versions.json +33 -0
- package/kits/rust/kit.json +6 -0
- package/kits/rust/src/runtime/client.rs +212 -0
- package/kits/rust/src/runtime/context.rs +182 -0
- package/kits/rust/src/runtime/crypto.rs +84 -0
- package/kits/rust/src/runtime/errors.rs +147 -0
- package/kits/rust/src/runtime/http.rs +248 -0
- package/kits/rust/src/runtime/json.rs +424 -0
- package/kits/rust/src/runtime/lang.rs +296 -0
- package/kits/rust/src/runtime/mod.rs +30 -0
- package/kits/rust/src/runtime/models.rs +266 -0
- package/kits/rust/src/runtime/multipart.rs +81 -0
- package/kits/rust/src/runtime/pagination.rs +117 -0
- package/kits/rust/src/runtime/sse.rs +195 -0
- package/kits/rust/src/runtime/testing.rs +308 -0
- package/kits/rust/src/runtime/transport.rs +324 -0
- package/kits/rust/src/runtime/wait.rs +29 -0
- package/kits/rust/src/runtime/webhooks.rs +142 -0
- package/kits/rust/tests/client.rs +152 -0
- package/kits/rust/tests/http.rs +44 -0
- package/kits/rust/tests/json.rs +82 -0
- package/kits/rust/tests/lang.rs +74 -0
- package/kits/rust/tests/multipart.rs +21 -0
- package/kits/rust/tests/pagination.rs +61 -0
- package/kits/rust/tests/sse.rs +77 -0
- package/kits/rust/tests/testing.rs +90 -0
- package/kits/rust/tests/transport.rs +218 -0
- package/kits/rust/tests/wait.rs +32 -0
- package/kits/rust/tests/webhooks.rs +73 -0
- package/kits/rust/versions.json +6 -0
- package/kits/typescript/kit.json +6 -0
- package/kits/typescript/src/client.ts +223 -0
- package/kits/typescript/src/context.ts +108 -0
- package/kits/typescript/src/errors.ts +63 -0
- package/kits/typescript/src/helpers.ts +49 -0
- package/kits/typescript/src/http.ts +192 -0
- package/kits/typescript/src/models.ts +139 -0
- package/kits/typescript/src/multipart.ts +66 -0
- package/kits/typescript/src/pagination.ts +54 -0
- package/kits/typescript/src/pipeline.ts +25 -0
- package/kits/typescript/src/sse.ts +102 -0
- package/kits/typescript/src/testing.ts +217 -0
- package/kits/typescript/src/transport.ts +101 -0
- package/kits/typescript/src/wait.ts +36 -0
- package/kits/typescript/src/webhooks.ts +168 -0
- package/kits/typescript/tests/client.test.ts +269 -0
- package/kits/typescript/tests/helpers.test.ts +27 -0
- package/kits/typescript/tests/http.test.ts +80 -0
- package/kits/typescript/tests/models.test.ts +71 -0
- package/kits/typescript/tests/multipart.test.ts +28 -0
- package/kits/typescript/tests/pagination.test.ts +76 -0
- package/kits/typescript/tests/sse.test.ts +82 -0
- package/kits/typescript/tests/testing.test.ts +103 -0
- package/kits/typescript/tests/transport.test.ts +127 -0
- package/kits/typescript/tests/wait.test.ts +31 -0
- package/kits/typescript/tests/webhooks.test.ts +53 -0
- package/kits/typescript/versions.json +15 -0
- package/package.json +37 -4
- package/packages/cli/recipes/apiKeyHeader.ts +16 -0
- package/packages/cli/recipes/apiVersionHeader.ts +16 -0
- package/packages/cli/recipes/basic.ts +13 -0
- package/packages/cli/recipes/bearer.ts +10 -0
- package/packages/cli/recipes/hmacSign.ts +23 -0
- package/packages/cli/recipes/idempotencyKey.ts +19 -0
- package/packages/cli/recipes/oauthClientCredentials.ts +50 -0
- package/packages/cli/recipes/retry.ts +42 -0
- package/packages/cli/recipes/timing.ts +12 -0
- package/packages/cli/recipes/userAgent.ts +8 -0
- package/packages/cli/src/build.js +93 -0
- package/packages/cli/src/commands/build.js +31 -0
- package/packages/cli/src/commands/conformance-check.js +50 -0
- package/packages/cli/src/commands/contract.js +181 -0
- package/packages/cli/src/commands/diff.js +113 -0
- package/packages/cli/src/commands/doctor.js +43 -0
- package/packages/cli/src/commands/import-openapi.js +42 -0
- package/packages/cli/src/commands/init.js +27 -0
- package/packages/cli/src/commands/kit-check.js +145 -0
- package/packages/cli/src/commands/publish.js +81 -0
- package/packages/cli/src/commands/recipe.js +49 -0
- package/packages/cli/src/commands/record.js +181 -0
- package/packages/cli/src/commands/serve.js +156 -0
- package/packages/cli/src/commands/spec-check.js +57 -0
- package/packages/cli/src/commands/test.js +177 -0
- package/packages/cli/src/commands/variants.js +32 -0
- package/packages/cli/src/commands/verify.js +57 -0
- package/packages/cli/src/commands/version.js +63 -0
- package/packages/cli/src/containers.js +82 -0
- package/packages/cli/src/coverage.js +72 -0
- package/packages/cli/src/git.js +25 -0
- package/packages/cli/src/io.js +50 -0
- package/packages/cli/src/java/ScenarioHarness.java +297 -0
- package/packages/cli/src/java/SchemaRoundTrip.java +63 -0
- package/packages/cli/src/java.js +70 -0
- package/packages/cli/src/js/harness.mjs +120 -0
- package/packages/cli/src/kits.js +103 -0
- package/packages/cli/src/languages/csharp.js +274 -0
- package/packages/cli/src/languages/go.js +185 -0
- package/packages/cli/src/languages/index.js +18 -0
- package/packages/cli/src/languages/java.js +187 -0
- package/packages/cli/src/languages/python.js +120 -0
- package/packages/cli/src/languages/rust.js +189 -0
- package/packages/cli/src/languages/types.js +93 -0
- package/packages/cli/src/languages/typescript.js +112 -0
- package/packages/cli/src/main.js +13 -0
- package/packages/cli/src/packaging.js +39 -0
- package/packages/cli/src/portability.js +45 -0
- package/packages/cli/src/profiles.js +55 -0
- package/packages/cli/src/project.js +56 -0
- package/packages/cli/src/python/scenario_harness.py +162 -0
- package/packages/cli/src/python/schema_roundtrip.py +42 -0
- package/packages/cli/src/registries.js +214 -0
- package/packages/cli/src/resolve-core.js +39 -0
- package/packages/cli/src/run.js +133 -0
- package/packages/cli/src/runtimes.js +61 -0
- package/packages/cli/src/scenarios-java.js +82 -0
- package/packages/cli/src/scenarios-javascript.js +54 -0
- package/packages/cli/src/scenarios-python.js +90 -0
- package/packages/cli/src/scenarios.js +183 -0
- package/packages/cli/src/schema.js +84 -0
- package/packages/cli/src/templates.js +85 -0
- package/packages/cli/src/toolchains.js +68 -0
- package/packages/cli/src/transpiled-tests.js +92 -0
- package/packages/codegen/src/canonical-json.js +31 -0
- package/packages/codegen/src/capabilities.js +50 -0
- package/packages/codegen/src/code-writer.js +54 -0
- package/packages/codegen/src/file-tree.js +25 -0
- package/packages/codegen/src/hash.js +6 -0
- package/packages/codegen/src/index.js +16 -0
- package/packages/codegen/src/lock.js +106 -0
- package/packages/conformance/src/case.js +143 -0
- package/packages/conformance/src/checks.js +40 -0
- package/packages/conformance/src/index.js +3 -0
- package/packages/conformance/src/matrix.js +48 -0
- package/packages/conformance/src/suite.js +48 -0
- package/packages/differ/src/diff.js +500 -0
- package/packages/differ/src/index.js +3 -0
- package/packages/differ/src/notes.js +112 -0
- package/packages/differ/src/support.js +34 -0
- package/packages/gen-csharp/src/emit-client.js +397 -0
- package/packages/gen-csharp/src/emit-harness.js +333 -0
- package/packages/gen-csharp/src/emit-mock.js +111 -0
- package/packages/gen-csharp/src/emit-models.js +119 -0
- package/packages/gen-csharp/src/emit-webhooks.js +57 -0
- package/packages/gen-csharp/src/generate.js +245 -0
- package/packages/gen-csharp/src/index.js +5 -0
- package/packages/gen-csharp/src/names.js +284 -0
- package/packages/gen-go/src/emit-client.js +405 -0
- package/packages/gen-go/src/emit-harness.js +294 -0
- package/packages/gen-go/src/emit-mock.js +112 -0
- package/packages/gen-go/src/emit-models.js +146 -0
- package/packages/gen-go/src/emit-webhooks.js +58 -0
- package/packages/gen-go/src/generate.js +205 -0
- package/packages/gen-go/src/index.js +5 -0
- package/packages/gen-go/src/names.js +197 -0
- package/packages/gen-java/src/emit-client.js +441 -0
- package/packages/gen-java/src/emit-models.js +342 -0
- package/packages/gen-java/src/emit-testing.js +123 -0
- package/packages/gen-java/src/emit-webhooks.js +70 -0
- package/packages/gen-java/src/generate.js +244 -0
- package/packages/gen-java/src/index.js +4 -0
- package/packages/gen-java/src/names.js +197 -0
- package/packages/gen-python/src/emit-client.js +272 -0
- package/packages/gen-python/src/emit-models.js +139 -0
- package/packages/gen-python/src/emit-testing.js +93 -0
- package/packages/gen-python/src/emit-webhooks.js +48 -0
- package/packages/gen-python/src/generate.js +237 -0
- package/packages/gen-python/src/index.js +2 -0
- package/packages/gen-python/src/names.js +161 -0
- package/packages/gen-python/src/style.js +67 -0
- package/packages/gen-rust/src/emit-client.js +379 -0
- package/packages/gen-rust/src/emit-harness.js +278 -0
- package/packages/gen-rust/src/emit-mock.js +121 -0
- package/packages/gen-rust/src/emit-models.js +117 -0
- package/packages/gen-rust/src/emit-webhooks.js +58 -0
- package/packages/gen-rust/src/generate.js +243 -0
- package/packages/gen-rust/src/index.js +5 -0
- package/packages/gen-rust/src/names.js +223 -0
- package/packages/gen-typescript/src/emit-client.js +434 -0
- package/packages/gen-typescript/src/emit-models.js +93 -0
- package/packages/gen-typescript/src/emit-package.js +90 -0
- package/packages/gen-typescript/src/emit-testing.js +138 -0
- package/packages/gen-typescript/src/emit-webhooks.js +52 -0
- package/packages/gen-typescript/src/generate.js +70 -0
- package/packages/gen-typescript/src/index.js +3 -0
- package/packages/gen-typescript/src/naming.js +64 -0
- package/packages/gen-typescript/src/runtime.js +81 -0
- package/packages/gen-typescript/src/types.js +136 -0
- package/packages/ir/src/api-surface.js +22 -0
- package/packages/ir/src/checks.js +52 -0
- package/packages/ir/src/index.js +32 -0
- package/packages/ir/src/ir.js +214 -0
- package/packages/ir/src/pages.js +18 -0
- package/packages/ir/src/validate-ir.js +462 -0
- package/packages/ir/src/validate-types.js +140 -0
- package/packages/kit/src/block-parser.js +196 -0
- package/packages/kit/src/index.js +15 -0
- package/packages/kit/src/kit-check.js +203 -0
- package/packages/kit/src/sources.js +53 -0
- package/packages/kit/src/version-policy.js +133 -0
- package/packages/kit/src/version-range.js +132 -0
- package/packages/openapi/src/import.js +292 -0
- package/packages/openapi/src/index.js +1 -0
- package/packages/openapi/src/names.js +50 -0
- package/packages/openapi/src/schemas.js +264 -0
- package/packages/packager/src/archive.js +106 -0
- package/packages/packager/src/crate.js +39 -0
- package/packages/packager/src/gomodule.js +11 -0
- package/packages/packager/src/index.js +9 -0
- package/packages/packager/src/maven.js +85 -0
- package/packages/packager/src/metadata.js +34 -0
- package/packages/packager/src/npm.js +71 -0
- package/packages/packager/src/nuget.js +78 -0
- package/packages/packager/src/sbom.js +56 -0
- package/packages/packager/src/wheel.js +62 -0
- package/packages/spec/src/index.js +11 -0
- package/packages/spec/src/requirements.js +139 -0
- package/packages/transpile/src/ast.js +51 -0
- package/packages/transpile/src/check.js +669 -0
- package/packages/transpile/src/emit-csharp.js +469 -0
- package/packages/transpile/src/emit-go.js +529 -0
- package/packages/transpile/src/emit-java.js +360 -0
- package/packages/transpile/src/emit-python.js +320 -0
- package/packages/transpile/src/emit-rust.js +499 -0
- package/packages/transpile/src/errors.js +15 -0
- package/packages/transpile/src/index.js +13 -0
- package/packages/transpile/src/lexer.js +161 -0
- package/packages/transpile/src/parser.js +543 -0
- package/packages/transpile/src/tests/ast.js +46 -0
- package/packages/transpile/src/tests/parse.js +376 -0
- package/packages/transpile/src/tests/translate.js +849 -0
- package/packages/transpile/src/transpile.js +57 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
// A recursive-descent parser for the restricted TypeScript subset. Anything outside the subset fails with its rule.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { TranspileError } from "./errors.ts";
|
|
5
|
+
import { decodeTemplateText, tokenize, } from "./lexer.ts";
|
|
6
|
+
|
|
7
|
+
const UNSUPPORTED_STATEMENTS = {
|
|
8
|
+
var: "`var` is not supported; use `const` or `let`",
|
|
9
|
+
switch: "`switch` is not supported; use if/else",
|
|
10
|
+
do: "`do … while` is not supported; use `while`",
|
|
11
|
+
continue: "`continue` is not supported",
|
|
12
|
+
class: "classes are not supported",
|
|
13
|
+
function: "nested functions are not supported",
|
|
14
|
+
async: "nested functions are not supported",
|
|
15
|
+
with: "`with` is not supported",
|
|
16
|
+
delete: "`delete` is not supported",
|
|
17
|
+
import: "imports are not supported inside a middleware",
|
|
18
|
+
export: "exports are not supported inside a middleware",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const UNSUPPORTED_OPERATORS = {
|
|
22
|
+
typeof: "`typeof` is not supported",
|
|
23
|
+
instanceof: "`instanceof` is not supported",
|
|
24
|
+
in: "`in` is not supported",
|
|
25
|
+
void: "`void` is not supported",
|
|
26
|
+
delete: "`delete` is not supported",
|
|
27
|
+
"?.": "optional chaining is not supported; compare with `undefined` first",
|
|
28
|
+
"...": "spread is not supported",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class Parser {
|
|
32
|
+
index = 0;
|
|
33
|
+
middleware ;
|
|
34
|
+
tokens ;
|
|
35
|
+
|
|
36
|
+
constructor(middleware , tokens ) {
|
|
37
|
+
this.middleware = middleware;
|
|
38
|
+
this.tokens = tokens;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get current() {
|
|
42
|
+
return this.tokens[this.index] ?? this.tokens[this.tokens.length - 1] ?? { kind: "end", text: "end of source", value: "", line: 1 };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
peek(offset ) {
|
|
46
|
+
return this.tokens[Math.min(this.index + offset, this.tokens.length - 1)] ?? this.current;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fail(message , rule , line = this.current.line) {
|
|
50
|
+
throw new TranspileError(this.middleware, line, message, rule);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
is(text ) {
|
|
54
|
+
const token = this.current;
|
|
55
|
+
return (token.kind === "punct" || token.kind === "name") && token.text === text;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
eat(text ) {
|
|
59
|
+
if (!this.is(text)) return false;
|
|
60
|
+
this.index += 1;
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
expect(text ) {
|
|
65
|
+
const token = this.current;
|
|
66
|
+
if (!this.eat(text)) this.fail(`expected ${text} but found ${token.text}`);
|
|
67
|
+
return token;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
name() {
|
|
71
|
+
const token = this.current;
|
|
72
|
+
if (token.kind !== "name") this.fail(`expected a name but found ${token.text}`);
|
|
73
|
+
this.index += 1;
|
|
74
|
+
return token.text;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
semicolon() {
|
|
78
|
+
this.eat(";");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
atEnd() {
|
|
82
|
+
return this.current.kind === "end";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ---- function
|
|
86
|
+
|
|
87
|
+
parseFunction() {
|
|
88
|
+
const line = this.current.line;
|
|
89
|
+
this.eat("async");
|
|
90
|
+
let params ;
|
|
91
|
+
if (this.eat("function")) {
|
|
92
|
+
if (this.current.kind === "name") this.index += 1;
|
|
93
|
+
params = this.params();
|
|
94
|
+
} else if (this.is("(")) {
|
|
95
|
+
params = this.params();
|
|
96
|
+
this.expect("=>");
|
|
97
|
+
} else {
|
|
98
|
+
this.fail("a middleware takes exactly three parameters (req, next, ctx)", "SL-T001", line);
|
|
99
|
+
}
|
|
100
|
+
if (params.length !== 3) this.fail("a middleware takes exactly three parameters (req, next, ctx)", "SL-T001", line);
|
|
101
|
+
const body = this.is("{") ? this.block() : [{ kind: "return" , line: this.current.line, value: this.expression() }];
|
|
102
|
+
this.semicolon();
|
|
103
|
+
if (!this.atEnd()) this.fail(`unexpected ${this.current.text} after the middleware`);
|
|
104
|
+
return { name: this.middleware, params: [params[0] ?? "", params[1] ?? "", params[2] ?? ""], body };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** A logic function: `(input) => …`, `input => …` or `function name(input) { … }`, not async. */
|
|
108
|
+
parseLogic() {
|
|
109
|
+
const line = this.current.line;
|
|
110
|
+
const wrong = "a logic function takes exactly one parameter (input) and is not async";
|
|
111
|
+
if (this.is("async")) this.fail(wrong, "SL-L001", line);
|
|
112
|
+
let params ;
|
|
113
|
+
if (this.eat("function")) {
|
|
114
|
+
if (this.current.kind === "name") this.index += 1;
|
|
115
|
+
params = this.params();
|
|
116
|
+
} else if (this.is("(")) {
|
|
117
|
+
params = this.params();
|
|
118
|
+
this.expect("=>");
|
|
119
|
+
} else if (this.current.kind === "name") {
|
|
120
|
+
params = [this.name()];
|
|
121
|
+
this.expect("=>");
|
|
122
|
+
} else {
|
|
123
|
+
this.fail(wrong, "SL-L001", line);
|
|
124
|
+
}
|
|
125
|
+
if (params.length !== 1) this.fail(wrong, "SL-L001", line);
|
|
126
|
+
const body = this.is("{") ? this.block() : [{ kind: "return" , line: this.current.line, value: this.expression() }];
|
|
127
|
+
this.semicolon();
|
|
128
|
+
if (!this.atEnd()) this.fail(`unexpected ${this.current.text} after the logic function`);
|
|
129
|
+
return { name: this.middleware, params: [params[0] ?? "", "", ""], body, logic: true };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
params() {
|
|
133
|
+
this.expect("(");
|
|
134
|
+
const params = [];
|
|
135
|
+
while (!this.eat(")")) {
|
|
136
|
+
if (this.is("{") || this.is("[")) this.fail("destructuring is not supported", "SL-T002");
|
|
137
|
+
if (this.is("...")) this.fail("rest parameters are not supported", "SL-T001");
|
|
138
|
+
params.push(this.name());
|
|
139
|
+
if (this.is("=")) this.fail("default parameter values are not supported", "SL-T001");
|
|
140
|
+
if (!this.is(")")) this.expect(",");
|
|
141
|
+
}
|
|
142
|
+
return params;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ---- statements
|
|
146
|
+
|
|
147
|
+
block() {
|
|
148
|
+
this.expect("{");
|
|
149
|
+
const statements = [];
|
|
150
|
+
while (!this.eat("}")) {
|
|
151
|
+
if (this.atEnd()) this.fail("missing }");
|
|
152
|
+
statements.push(this.statement());
|
|
153
|
+
}
|
|
154
|
+
return statements;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
body() {
|
|
158
|
+
return this.is("{") ? this.block() : [this.statement()];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
statement() {
|
|
162
|
+
const token = this.current;
|
|
163
|
+
const line = token.line;
|
|
164
|
+
if (token.kind === "name") {
|
|
165
|
+
const unsupported = UNSUPPORTED_STATEMENTS[token.text];
|
|
166
|
+
if (unsupported !== undefined) this.fail(unsupported, "SL-T002");
|
|
167
|
+
if (this.peek(1).text === ":" && this.peek(1).kind === "punct") this.fail("labels are not supported", "SL-T002");
|
|
168
|
+
switch (token.text) {
|
|
169
|
+
case "const":
|
|
170
|
+
case "let":
|
|
171
|
+
return this.declaration();
|
|
172
|
+
case "if":
|
|
173
|
+
return this.ifStatement();
|
|
174
|
+
case "for":
|
|
175
|
+
return this.forStatement();
|
|
176
|
+
case "while": {
|
|
177
|
+
this.index += 1;
|
|
178
|
+
const test = this.parenthesized();
|
|
179
|
+
return { kind: "while", line, test, body: this.body() };
|
|
180
|
+
}
|
|
181
|
+
case "break":
|
|
182
|
+
this.index += 1;
|
|
183
|
+
this.semicolon();
|
|
184
|
+
return { kind: "break", line };
|
|
185
|
+
case "return": {
|
|
186
|
+
this.index += 1;
|
|
187
|
+
if (this.is(";") || this.is("}")) this.fail("a middleware returns a response", "SL-T003");
|
|
188
|
+
const value = this.expression();
|
|
189
|
+
this.semicolon();
|
|
190
|
+
return { kind: "return", line, value };
|
|
191
|
+
}
|
|
192
|
+
case "throw":
|
|
193
|
+
return this.throwStatement();
|
|
194
|
+
case "try":
|
|
195
|
+
return this.tryStatement();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const simple = this.simpleStatement();
|
|
199
|
+
this.semicolon();
|
|
200
|
+
return simple;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
declaration() {
|
|
204
|
+
const line = this.current.line;
|
|
205
|
+
const constant = this.current.text === "const";
|
|
206
|
+
this.index += 1;
|
|
207
|
+
if (this.is("{") || this.is("[")) this.fail("destructuring is not supported", "SL-T002");
|
|
208
|
+
const name = this.name();
|
|
209
|
+
if (!this.eat("=")) this.fail("a variable needs an initializer", "SL-T004", line);
|
|
210
|
+
const init = this.expression();
|
|
211
|
+
if (this.is(",")) this.fail("declare one variable per statement", "SL-T002");
|
|
212
|
+
this.semicolon();
|
|
213
|
+
return { kind: "let", line, name, constant, init };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** An assignment, ++/-- or a call; used as a statement and in for headers. */
|
|
217
|
+
simpleStatement() {
|
|
218
|
+
const line = this.current.line;
|
|
219
|
+
if (this.current.kind === "name" && (this.peek(1).text === "++" || this.peek(1).text === "--")) {
|
|
220
|
+
const name = this.name();
|
|
221
|
+
const op = this.current.text === "++" ? "+=" : "-=";
|
|
222
|
+
this.index += 1;
|
|
223
|
+
return { kind: "assign", line, name, op, value: { kind: "number", line, value: 1, integer: true } };
|
|
224
|
+
}
|
|
225
|
+
if (this.is("++") || this.is("--")) this.fail("write `x += 1` instead of prefix ++/--", "SL-T002");
|
|
226
|
+
const target = this.expression();
|
|
227
|
+
const op = ["=", "+=", "-=", "*="].find((candidate) => this.is(candidate)) ;
|
|
228
|
+
if (op === undefined) {
|
|
229
|
+
if (["/=", "%=", "**="].some((candidate) => this.is(candidate))) this.fail(`${this.current.text} is not supported; write x = x … y`, "SL-T002");
|
|
230
|
+
return { kind: "expression", line, value: target };
|
|
231
|
+
}
|
|
232
|
+
if (target.kind !== "name") this.fail("only variables can be assigned; requests and responses are immutable", "SL-T002");
|
|
233
|
+
this.index += 1;
|
|
234
|
+
return { kind: "assign", line, name: target.name, op, value: this.expression() };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
ifStatement() {
|
|
238
|
+
const line = this.current.line;
|
|
239
|
+
this.index += 1;
|
|
240
|
+
const test = this.parenthesized();
|
|
241
|
+
const then = this.body();
|
|
242
|
+
const otherwise = this.eat("else") ? this.body() : undefined;
|
|
243
|
+
return { kind: "if", line, test, then, otherwise };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
forStatement() {
|
|
247
|
+
const line = this.current.line;
|
|
248
|
+
this.index += 1;
|
|
249
|
+
if (this.is("await")) this.fail("`for await` is not supported", "SL-T002");
|
|
250
|
+
this.expect("(");
|
|
251
|
+
if ((this.is("const") || this.is("let")) && this.peek(2).text === "of") {
|
|
252
|
+
this.index += 1;
|
|
253
|
+
const name = this.name();
|
|
254
|
+
this.expect("of");
|
|
255
|
+
const iterable = this.expression();
|
|
256
|
+
this.expect(")");
|
|
257
|
+
return { kind: "forOf", line, name, iterable, body: this.body() };
|
|
258
|
+
}
|
|
259
|
+
if ((this.is("const") || this.is("let")) && this.peek(2).text === "in") this.fail("`for … in` is not supported; use `for … of`", "SL-T002");
|
|
260
|
+
const init = this.is(";") ? undefined : this.is("let") || this.is("const") ? this.declaration() : this.simpleStatement();
|
|
261
|
+
if (init === undefined || init.kind !== "let") this.eat(";");
|
|
262
|
+
if (this.is(";")) this.fail("a for loop needs a condition", "SL-T002");
|
|
263
|
+
const test = this.expression();
|
|
264
|
+
this.expect(";");
|
|
265
|
+
const update = this.is(")") ? undefined : this.simpleStatement();
|
|
266
|
+
this.expect(")");
|
|
267
|
+
return { kind: "for", line, init, test, update, body: this.body() };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
throwStatement() {
|
|
271
|
+
const line = this.current.line;
|
|
272
|
+
this.index += 1;
|
|
273
|
+
if (!this.eat("new") || !this.eat("Error")) this.fail("only `throw new Error(message)` is supported", "SL-T002", line);
|
|
274
|
+
this.expect("(");
|
|
275
|
+
const message = this.is(")") ? ({ kind: "string", line, value: "" } ) : this.expression();
|
|
276
|
+
this.expect(")");
|
|
277
|
+
this.semicolon();
|
|
278
|
+
return { kind: "throw", line, message };
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
tryStatement() {
|
|
282
|
+
const line = this.current.line;
|
|
283
|
+
this.index += 1;
|
|
284
|
+
const body = this.block();
|
|
285
|
+
if (this.is("finally")) this.fail("`finally` is not supported", "SL-T002");
|
|
286
|
+
this.expect("catch");
|
|
287
|
+
if (!this.eat("(")) this.fail("name the caught error: catch (error) { … }", "SL-T002");
|
|
288
|
+
const param = this.name();
|
|
289
|
+
this.expect(")");
|
|
290
|
+
const handler = this.block();
|
|
291
|
+
if (this.is("finally")) this.fail("`finally` is not supported", "SL-T002");
|
|
292
|
+
return { kind: "try", line, body, param, handler };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
parenthesized() {
|
|
296
|
+
this.expect("(");
|
|
297
|
+
const value = this.expression();
|
|
298
|
+
this.expect(")");
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ---- expressions
|
|
303
|
+
|
|
304
|
+
expression() {
|
|
305
|
+
const test = this.nullish();
|
|
306
|
+
if (!this.is("?")) return test;
|
|
307
|
+
this.index += 1;
|
|
308
|
+
const then = this.expression();
|
|
309
|
+
this.expect(":");
|
|
310
|
+
return { kind: "conditional", line: test.line, test, then, otherwise: this.expression() };
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
nullish() {
|
|
314
|
+
let left = this.or();
|
|
315
|
+
while (this.is("??")) {
|
|
316
|
+
this.index += 1;
|
|
317
|
+
left = { kind: "logical", line: left.line, op: "??", left, right: this.or() };
|
|
318
|
+
}
|
|
319
|
+
return left;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
or() {
|
|
323
|
+
let left = this.and();
|
|
324
|
+
while (this.is("||")) {
|
|
325
|
+
this.index += 1;
|
|
326
|
+
left = { kind: "logical", line: left.line, op: "||", left, right: this.and() };
|
|
327
|
+
}
|
|
328
|
+
return left;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
and() {
|
|
332
|
+
let left = this.equality();
|
|
333
|
+
while (this.is("&&")) {
|
|
334
|
+
this.index += 1;
|
|
335
|
+
left = { kind: "logical", line: left.line, op: "&&", left, right: this.equality() };
|
|
336
|
+
}
|
|
337
|
+
return left;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
binaryLevel(ops , next ) {
|
|
341
|
+
let left = next();
|
|
342
|
+
for (;;) {
|
|
343
|
+
const op = ops.find((candidate) => this.is(candidate));
|
|
344
|
+
if (op === undefined) return left;
|
|
345
|
+
this.index += 1;
|
|
346
|
+
left = { kind: "binary", line: left.line, op, left, right: next() };
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
equality() {
|
|
351
|
+
return this.binaryLevel(["===", "!=="], () => {
|
|
352
|
+
const value = this.relational();
|
|
353
|
+
if (this.is("==") || this.is("!=")) this.fail(`use ${this.current.text}= instead of ${this.current.text}`, "SL-T006");
|
|
354
|
+
return value;
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
relational() {
|
|
359
|
+
return this.binaryLevel(["<=", ">=", "<", ">"], () => this.additive());
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
additive() {
|
|
363
|
+
return this.binaryLevel(["+", "-"], () => this.multiplicative());
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
multiplicative() {
|
|
367
|
+
return this.binaryLevel(["*", "/", "%"], () => this.exponent());
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
exponent() {
|
|
371
|
+
const base = this.unary();
|
|
372
|
+
if (!this.is("**")) return base;
|
|
373
|
+
this.index += 1;
|
|
374
|
+
return { kind: "binary", line: base.line, op: "**", left: base, right: this.exponent() };
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
unary() {
|
|
378
|
+
const line = this.current.line;
|
|
379
|
+
const unsupported = UNSUPPORTED_OPERATORS[this.current.text];
|
|
380
|
+
if (unsupported !== undefined && this.current.kind !== "string") this.fail(unsupported, "SL-T002");
|
|
381
|
+
if (this.eat("!")) return { kind: "unary", line, op: "!", value: this.unary() };
|
|
382
|
+
if (this.eat("-")) return { kind: "unary", line, op: "-", value: this.unary() };
|
|
383
|
+
if (this.eat("await")) return { kind: "await", line, value: this.unary() };
|
|
384
|
+
if (this.is("+") || this.is("~")) this.fail(`unary ${this.current.text} is not supported`, "SL-T002");
|
|
385
|
+
return this.postfix();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
postfix() {
|
|
389
|
+
let value = this.primary();
|
|
390
|
+
for (;;) {
|
|
391
|
+
const line = this.current.line;
|
|
392
|
+
if (this.eat(".")) {
|
|
393
|
+
value = { kind: "member", line, object: value, name: this.name() };
|
|
394
|
+
} else if (this.is("(")) {
|
|
395
|
+
this.index += 1;
|
|
396
|
+
const args = [];
|
|
397
|
+
while (!this.eat(")")) {
|
|
398
|
+
if (this.is("...")) this.fail("spread is not supported", "SL-T002");
|
|
399
|
+
args.push(this.expression());
|
|
400
|
+
if (!this.is(")")) this.expect(",");
|
|
401
|
+
}
|
|
402
|
+
value = { kind: "call", line, callee: value, args };
|
|
403
|
+
} else if (this.is("?.")) {
|
|
404
|
+
this.fail("optional chaining is not supported; compare with `undefined` first", "SL-T002");
|
|
405
|
+
} else if (this.is("[")) {
|
|
406
|
+
this.fail("computed member access is not supported; use value.field", "SL-T002");
|
|
407
|
+
} else if (this.is("=>")) {
|
|
408
|
+
this.fail("nested functions are not supported", "SL-T002");
|
|
409
|
+
} else {
|
|
410
|
+
return value;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
primary() {
|
|
416
|
+
const token = this.current;
|
|
417
|
+
const line = token.line;
|
|
418
|
+
if (token.kind === "number") {
|
|
419
|
+
this.index += 1;
|
|
420
|
+
const value = Number(token.value);
|
|
421
|
+
return { kind: "number", line, value, integer: Number.isInteger(value) && !/[.eE]/.test(token.value.replace(/^0[xX].*/, "")) };
|
|
422
|
+
}
|
|
423
|
+
if (token.kind === "string") {
|
|
424
|
+
this.index += 1;
|
|
425
|
+
return { kind: "string", line, value: token.value };
|
|
426
|
+
}
|
|
427
|
+
if (token.kind === "template") {
|
|
428
|
+
this.index += 1;
|
|
429
|
+
return this.template(token);
|
|
430
|
+
}
|
|
431
|
+
if (token.kind === "regex") this.fail("regular expressions are not supported", "SL-T002");
|
|
432
|
+
if (token.kind === "name") {
|
|
433
|
+
if (UNSUPPORTED_OPERATORS[token.text] !== undefined) this.fail(UNSUPPORTED_OPERATORS[token.text] ?? "", "SL-T002");
|
|
434
|
+
if (token.text === "function" || token.text === "async") this.fail("nested functions are not supported", "SL-T002");
|
|
435
|
+
if (token.text === "new") this.fail("`new` is only allowed in `throw new Error(message)`", "SL-T002");
|
|
436
|
+
if (token.text === "class") this.fail("classes are not supported", "SL-T002");
|
|
437
|
+
this.index += 1;
|
|
438
|
+
if (token.text === "true" || token.text === "false") return { kind: "boolean", line, value: token.text === "true" };
|
|
439
|
+
if (token.text === "null" || token.text === "undefined") return { kind: "null", line };
|
|
440
|
+
if (this.is("=>")) this.fail("nested functions are not supported", "SL-T002");
|
|
441
|
+
return { kind: "name", line, name: token.text };
|
|
442
|
+
}
|
|
443
|
+
if (this.is("(")) {
|
|
444
|
+
if (this.arrowAhead()) this.fail("nested functions are not supported", "SL-T002");
|
|
445
|
+
return this.parenthesized();
|
|
446
|
+
}
|
|
447
|
+
if (this.is("{")) return this.objectLiteral();
|
|
448
|
+
if (this.is("[")) return this.arrayLiteral();
|
|
449
|
+
if (this.is("/")) this.fail("regular expressions are not supported", "SL-T002");
|
|
450
|
+
return this.fail(`unexpected ${token.text}`);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/** True when the "(" at the cursor opens the parameter list of an arrow function. */
|
|
454
|
+
arrowAhead() {
|
|
455
|
+
let depth = 0;
|
|
456
|
+
for (let offset = 0; ; offset += 1) {
|
|
457
|
+
const token = this.peek(offset);
|
|
458
|
+
if (token.kind === "end") return false;
|
|
459
|
+
if (token.text === "(") depth += 1;
|
|
460
|
+
if (token.text === ")") {
|
|
461
|
+
depth -= 1;
|
|
462
|
+
if (depth === 0) return this.peek(offset + 1).text === "=>";
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
objectLiteral() {
|
|
468
|
+
const line = this.current.line;
|
|
469
|
+
this.expect("{");
|
|
470
|
+
const entries = [];
|
|
471
|
+
while (!this.eat("}")) {
|
|
472
|
+
if (this.is("...")) this.fail("spread is not supported", "SL-T002");
|
|
473
|
+
if (this.is("[")) this.fail("computed keys are not supported", "SL-T013");
|
|
474
|
+
const keyToken = this.current;
|
|
475
|
+
if (keyToken.kind !== "name" && keyToken.kind !== "string") this.fail(`unexpected ${keyToken.text} in an object literal`, "SL-T013");
|
|
476
|
+
this.index += 1;
|
|
477
|
+
const key = keyToken.value;
|
|
478
|
+
if (this.is("(")) this.fail("methods in object literals are not supported", "SL-T002");
|
|
479
|
+
const hasValue = this.eat(":");
|
|
480
|
+
if (!hasValue && keyToken.kind === "string") this.fail("a quoted key needs a value", "SL-T013");
|
|
481
|
+
entries.push({ key, value: hasValue ? this.expression() : { kind: "name", line: keyToken.line, name: key } });
|
|
482
|
+
if (!this.is("}")) this.expect(",");
|
|
483
|
+
}
|
|
484
|
+
return { kind: "object", line, entries };
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
arrayLiteral() {
|
|
488
|
+
const line = this.current.line;
|
|
489
|
+
this.expect("[");
|
|
490
|
+
const items = [];
|
|
491
|
+
while (!this.eat("]")) {
|
|
492
|
+
if (this.is("...")) this.fail("spread is not supported", "SL-T002");
|
|
493
|
+
items.push(this.expression());
|
|
494
|
+
if (!this.is("]")) this.expect(",");
|
|
495
|
+
}
|
|
496
|
+
return { kind: "array", line, items };
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
template(token ) {
|
|
500
|
+
const raw = token.value;
|
|
501
|
+
const parts = [];
|
|
502
|
+
let text = "";
|
|
503
|
+
let line = token.line;
|
|
504
|
+
let index = 0;
|
|
505
|
+
while (index < raw.length) {
|
|
506
|
+
if (raw[index] === "\\") {
|
|
507
|
+
text += raw.slice(index, index + 2);
|
|
508
|
+
index += 2;
|
|
509
|
+
} else if (raw.startsWith("${", index)) {
|
|
510
|
+
if (text !== "") parts.push(decodeTemplateText(this.middleware, line, text));
|
|
511
|
+
text = "";
|
|
512
|
+
let depth = 1;
|
|
513
|
+
let end = index + 2;
|
|
514
|
+
for (; end < raw.length && depth > 0; end += 1) {
|
|
515
|
+
if (raw[end] === "{") depth += 1;
|
|
516
|
+
if (raw[end] === "}") depth -= 1;
|
|
517
|
+
}
|
|
518
|
+
const inner = raw.slice(index + 2, end - 1);
|
|
519
|
+
const tokens = tokenize(this.middleware, inner).map((item) => ({ ...item, line: item.line + line - 1 }));
|
|
520
|
+
const parser = new Parser(this.middleware, tokens);
|
|
521
|
+
parts.push(parser.expression());
|
|
522
|
+
if (!parser.atEnd()) parser.fail("unexpected text in a template expression");
|
|
523
|
+
line += (inner.match(/\n/g) ?? []).length;
|
|
524
|
+
index = end;
|
|
525
|
+
} else {
|
|
526
|
+
if (raw[index] === "\n") line += 1;
|
|
527
|
+
text += raw[index] ?? "";
|
|
528
|
+
index += 1;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
if (text !== "") parts.push(decodeTemplateText(this.middleware, line, text));
|
|
532
|
+
return { kind: "template", line: token.line, parts };
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** Parses one middleware function from its source text (as produced by Function.prototype.toString after type stripping). */
|
|
537
|
+
export function parseMiddleware(name , source ) {
|
|
538
|
+
return new Parser(name, tokenize(name, source)).parseFunction();
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export function parseLogic(name , source ) {
|
|
542
|
+
return new Parser(name, tokenize(name, source)).parseLogic();
|
|
543
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// The syntax tree of a test file in the test subset (spec/subset.md, "Tests").
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|