funkscript 0.0.0-stage → 0.2.4
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 +204 -2
- package/dist/Widget.tsx +9 -0
- package/dist/ast/types.d.ts +513 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/types.js +5 -0
- package/dist/ast/types.js.map +1 -0
- package/dist/ast/walk.d.ts +8 -0
- package/dist/ast/walk.d.ts.map +1 -0
- package/dist/ast/walk.js +23 -0
- package/dist/ast/walk.js.map +1 -0
- package/dist/cli/build-bun.d.ts +24 -0
- package/dist/cli/build-bun.d.ts.map +1 -0
- package/dist/cli/build-bun.js +190 -0
- package/dist/cli/build-bun.js.map +1 -0
- package/dist/cli/build-watch.d.ts +21 -0
- package/dist/cli/build-watch.d.ts.map +1 -0
- package/dist/cli/build-watch.js +244 -0
- package/dist/cli/build-watch.js.map +1 -0
- package/dist/cli/build.d.ts +4 -0
- package/dist/cli/build.d.ts.map +1 -0
- package/dist/cli/build.js +338 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/check.d.ts +4 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +278 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/commands.d.ts +13 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +262 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/doc.d.ts +3 -0
- package/dist/cli/doc.d.ts.map +1 -0
- package/dist/cli/doc.js +71 -0
- package/dist/cli/doc.js.map +1 -0
- package/dist/cli/doctor.d.ts +3 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +121 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/emit.d.ts +4 -0
- package/dist/cli/emit.d.ts.map +1 -0
- package/dist/cli/emit.js +87 -0
- package/dist/cli/emit.js.map +1 -0
- package/dist/cli/explain.d.ts +3 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +103 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fmt.d.ts +3 -0
- package/dist/cli/fmt.d.ts.map +1 -0
- package/dist/cli/fmt.js +146 -0
- package/dist/cli/fmt.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +186 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +10 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +412 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/io.d.ts +9 -0
- package/dist/cli/io.d.ts.map +1 -0
- package/dist/cli/io.js +113 -0
- package/dist/cli/io.js.map +1 -0
- package/dist/cli/output-collisions.d.ts +2 -0
- package/dist/cli/output-collisions.d.ts.map +1 -0
- package/dist/cli/output-collisions.js +39 -0
- package/dist/cli/output-collisions.js.map +1 -0
- package/dist/cli/pipeline-style.d.ts +3 -0
- package/dist/cli/pipeline-style.d.ts.map +1 -0
- package/dist/cli/pipeline-style.js +45 -0
- package/dist/cli/pipeline-style.js.map +1 -0
- package/dist/cli/repl.d.ts +37 -0
- package/dist/cli/repl.d.ts.map +1 -0
- package/dist/cli/repl.js +334 -0
- package/dist/cli/repl.js.map +1 -0
- package/dist/cli/run.d.ts +4 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +185 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/test.d.ts +3 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +124 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/cli/tsc.d.ts +3 -0
- package/dist/cli/tsc.d.ts.map +1 -0
- package/dist/cli/tsc.js +143 -0
- package/dist/cli/tsc.js.map +1 -0
- package/dist/cli/typecheck.d.ts +23 -0
- package/dist/cli/typecheck.d.ts.map +1 -0
- package/dist/cli/typecheck.js +65 -0
- package/dist/cli/typecheck.js.map +1 -0
- package/dist/compiler/ast-inspection.d.ts +18 -0
- package/dist/compiler/ast-inspection.d.ts.map +1 -0
- package/dist/compiler/ast-inspection.js +96 -0
- package/dist/compiler/ast-inspection.js.map +1 -0
- package/dist/compiler/boolean-operators.d.ts +8 -0
- package/dist/compiler/boolean-operators.d.ts.map +1 -0
- package/dist/compiler/boolean-operators.js +84 -0
- package/dist/compiler/boolean-operators.js.map +1 -0
- package/dist/compiler/check.d.ts +87 -0
- package/dist/compiler/check.d.ts.map +1 -0
- package/dist/compiler/check.js +1830 -0
- package/dist/compiler/check.js.map +1 -0
- package/dist/compiler/diagnostics.d.ts +6 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -0
- package/dist/compiler/diagnostics.js +136 -0
- package/dist/compiler/diagnostics.js.map +1 -0
- package/dist/compiler/effect-mutation-rule.d.ts +4 -0
- package/dist/compiler/effect-mutation-rule.d.ts.map +1 -0
- package/dist/compiler/effect-mutation-rule.js +348 -0
- package/dist/compiler/effect-mutation-rule.js.map +1 -0
- package/dist/compiler/entry-rules.d.ts +5 -0
- package/dist/compiler/entry-rules.d.ts.map +1 -0
- package/dist/compiler/entry-rules.js +89 -0
- package/dist/compiler/entry-rules.js.map +1 -0
- package/dist/compiler/imported-record-functions.d.ts +4 -0
- package/dist/compiler/imported-record-functions.d.ts.map +1 -0
- package/dist/compiler/imported-record-functions.js +706 -0
- package/dist/compiler/imported-record-functions.js.map +1 -0
- package/dist/compiler/imported-schemas.d.ts +21 -0
- package/dist/compiler/imported-schemas.d.ts.map +1 -0
- package/dist/compiler/imported-schemas.js +461 -0
- package/dist/compiler/imported-schemas.js.map +1 -0
- package/dist/compiler/incremental-build.d.ts +23 -0
- package/dist/compiler/incremental-build.d.ts.map +1 -0
- package/dist/compiler/incremental-build.js +90 -0
- package/dist/compiler/incremental-build.js.map +1 -0
- package/dist/compiler/incremental-dependencies.d.ts +7 -0
- package/dist/compiler/incremental-dependencies.d.ts.map +1 -0
- package/dist/compiler/incremental-dependencies.js +190 -0
- package/dist/compiler/incremental-dependencies.js.map +1 -0
- package/dist/compiler/js-interop-nullability.d.ts +9 -0
- package/dist/compiler/js-interop-nullability.d.ts.map +1 -0
- package/dist/compiler/js-interop-nullability.js +57 -0
- package/dist/compiler/js-interop-nullability.js.map +1 -0
- package/dist/compiler/module-resolution.d.ts +6 -0
- package/dist/compiler/module-resolution.d.ts.map +1 -0
- package/dist/compiler/module-resolution.js +44 -0
- package/dist/compiler/module-resolution.js.map +1 -0
- package/dist/compiler/modules/output-collisions.d.ts +2 -0
- package/dist/compiler/modules/output-collisions.d.ts.map +1 -0
- package/dist/compiler/modules/output-collisions.js +39 -0
- package/dist/compiler/modules/output-collisions.js.map +1 -0
- package/dist/compiler/modules/output-plan.d.ts +7 -0
- package/dist/compiler/modules/output-plan.d.ts.map +1 -0
- package/dist/compiler/modules/output-plan.js +37 -0
- package/dist/compiler/modules/output-plan.js.map +1 -0
- package/dist/compiler/modules/resolution.d.ts +8 -0
- package/dist/compiler/modules/resolution.d.ts.map +1 -0
- package/dist/compiler/modules/resolution.js +48 -0
- package/dist/compiler/modules/resolution.js.map +1 -0
- package/dist/compiler/numeric-comparisons.d.ts +9 -0
- package/dist/compiler/numeric-comparisons.d.ts.map +1 -0
- package/dist/compiler/numeric-comparisons.js +153 -0
- package/dist/compiler/numeric-comparisons.js.map +1 -0
- package/dist/compiler/optional-arguments.d.ts +11 -0
- package/dist/compiler/optional-arguments.d.ts.map +1 -0
- package/dist/compiler/optional-arguments.js +246 -0
- package/dist/compiler/optional-arguments.js.map +1 -0
- package/dist/compiler/package-fingerprint.d.ts +7 -0
- package/dist/compiler/package-fingerprint.d.ts.map +1 -0
- package/dist/compiler/package-fingerprint.js +178 -0
- package/dist/compiler/package-fingerprint.js.map +1 -0
- package/dist/compiler/package-record-contracts.d.ts +5 -0
- package/dist/compiler/package-record-contracts.d.ts.map +1 -0
- package/dist/compiler/package-record-contracts.js +126 -0
- package/dist/compiler/package-record-contracts.js.map +1 -0
- package/dist/compiler/pipeline-companions.d.ts +18 -0
- package/dist/compiler/pipeline-companions.d.ts.map +1 -0
- package/dist/compiler/pipeline-companions.js +1042 -0
- package/dist/compiler/pipeline-companions.js.map +1 -0
- package/dist/compiler/pipelines/catalog.d.ts +15 -0
- package/dist/compiler/pipelines/catalog.d.ts.map +1 -0
- package/dist/compiler/pipelines/catalog.js +55 -0
- package/dist/compiler/pipelines/catalog.js.map +1 -0
- package/dist/compiler/pipelines/companions.d.ts +18 -0
- package/dist/compiler/pipelines/companions.d.ts.map +1 -0
- package/dist/compiler/pipelines/companions.js +1042 -0
- package/dist/compiler/pipelines/companions.js.map +1 -0
- package/dist/compiler/pipelines/resolution.d.ts +38 -0
- package/dist/compiler/pipelines/resolution.d.ts.map +1 -0
- package/dist/compiler/pipelines/resolution.js +571 -0
- package/dist/compiler/pipelines/resolution.js.map +1 -0
- package/dist/compiler/project-config.d.ts +28 -0
- package/dist/compiler/project-config.d.ts.map +1 -0
- package/dist/compiler/project-config.js +155 -0
- package/dist/compiler/project-config.js.map +1 -0
- package/dist/compiler/providers.d.ts +4 -0
- package/dist/compiler/providers.d.ts.map +1 -0
- package/dist/compiler/providers.js +101 -0
- package/dist/compiler/providers.js.map +1 -0
- package/dist/compiler/record-contracts.d.ts +6 -0
- package/dist/compiler/record-contracts.d.ts.map +1 -0
- package/dist/compiler/record-contracts.js +41 -0
- package/dist/compiler/record-contracts.js.map +1 -0
- package/dist/compiler/rules/control-flow.d.ts +10 -0
- package/dist/compiler/rules/control-flow.d.ts.map +1 -0
- package/dist/compiler/rules/control-flow.js +19 -0
- package/dist/compiler/rules/control-flow.js.map +1 -0
- package/dist/compiler/rules/diagnostic.d.ts +4 -0
- package/dist/compiler/rules/diagnostic.d.ts.map +1 -0
- package/dist/compiler/rules/diagnostic.js +2 -0
- package/dist/compiler/rules/diagnostic.js.map +1 -0
- package/dist/compiler/rules/module-scope-refs.d.ts +5 -0
- package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -0
- package/dist/compiler/rules/module-scope-refs.js +47 -0
- package/dist/compiler/rules/module-scope-refs.js.map +1 -0
- package/dist/compiler/schemas/analysis.d.ts +13 -0
- package/dist/compiler/schemas/analysis.d.ts.map +1 -0
- package/dist/compiler/schemas/analysis.js +24 -0
- package/dist/compiler/schemas/analysis.js.map +1 -0
- package/dist/compiler/schemas/imported-record-functions.d.ts +4 -0
- package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -0
- package/dist/compiler/schemas/imported-record-functions.js +706 -0
- package/dist/compiler/schemas/imported-record-functions.js.map +1 -0
- package/dist/compiler/schemas/imported-schemas.d.ts +21 -0
- package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -0
- package/dist/compiler/schemas/imported-schemas.js +461 -0
- package/dist/compiler/schemas/imported-schemas.js.map +1 -0
- package/dist/compiler/source-map.d.ts +6 -0
- package/dist/compiler/source-map.d.ts.map +1 -0
- package/dist/compiler/source-map.js +127 -0
- package/dist/compiler/source-map.js.map +1 -0
- package/dist/compiler/typescript-context.d.ts +33 -0
- package/dist/compiler/typescript-context.d.ts.map +1 -0
- package/dist/compiler/typescript-context.js +200 -0
- package/dist/compiler/typescript-context.js.map +1 -0
- package/dist/compiler.d.ts +77 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +497 -0
- package/dist/compiler.js.map +1 -0
- package/dist/emitter/assemblyscript.d.ts +5 -0
- package/dist/emitter/assemblyscript.d.ts.map +1 -0
- package/dist/emitter/assemblyscript.js +979 -0
- package/dist/emitter/assemblyscript.js.map +1 -0
- package/dist/emitter/declarations.d.ts +46 -0
- package/dist/emitter/declarations.d.ts.map +1 -0
- package/dist/emitter/declarations.js +739 -0
- package/dist/emitter/declarations.js.map +1 -0
- package/dist/emitter/emitter.d.ts +165 -0
- package/dist/emitter/emitter.d.ts.map +1 -0
- package/dist/emitter/emitter.js +2448 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/emitter/imports.d.ts +6 -0
- package/dist/emitter/imports.d.ts.map +1 -0
- package/dist/emitter/imports.js +73 -0
- package/dist/emitter/imports.js.map +1 -0
- package/dist/emitter/indent.d.ts +3 -0
- package/dist/emitter/indent.d.ts.map +1 -0
- package/dist/emitter/indent.js +31 -0
- package/dist/emitter/indent.js.map +1 -0
- package/dist/emitter/jsx.d.ts +20 -0
- package/dist/emitter/jsx.d.ts.map +1 -0
- package/dist/emitter/jsx.js +82 -0
- package/dist/emitter/jsx.js.map +1 -0
- package/dist/emitter/local-bindings.d.ts +6 -0
- package/dist/emitter/local-bindings.d.ts.map +1 -0
- package/dist/emitter/local-bindings.js +32 -0
- package/dist/emitter/local-bindings.js.map +1 -0
- package/dist/emitter/match.d.ts +56 -0
- package/dist/emitter/match.d.ts.map +1 -0
- package/dist/emitter/match.js +1287 -0
- package/dist/emitter/match.js.map +1 -0
- package/dist/emitter/pipeline-catalog.d.ts +15 -0
- package/dist/emitter/pipeline-catalog.d.ts.map +1 -0
- package/dist/emitter/pipeline-catalog.js +55 -0
- package/dist/emitter/pipeline-catalog.js.map +1 -0
- package/dist/emitter/pipeline-resolution.d.ts +38 -0
- package/dist/emitter/pipeline-resolution.d.ts.map +1 -0
- package/dist/emitter/pipeline-resolution.js +571 -0
- package/dist/emitter/pipeline-resolution.js.map +1 -0
- package/dist/emitter/runtime-helpers.d.ts +10 -0
- package/dist/emitter/runtime-helpers.d.ts.map +1 -0
- package/dist/emitter/runtime-helpers.js +22 -0
- package/dist/emitter/runtime-helpers.js.map +1 -0
- package/dist/emitter/schemas.d.ts +36 -0
- package/dist/emitter/schemas.d.ts.map +1 -0
- package/dist/emitter/schemas.js +766 -0
- package/dist/emitter/schemas.js.map +1 -0
- package/dist/emitter/statements.d.ts +23 -0
- package/dist/emitter/statements.d.ts.map +1 -0
- package/dist/emitter/statements.js +216 -0
- package/dist/emitter/statements.js.map +1 -0
- package/dist/emitter/tagged-match.d.ts +23 -0
- package/dist/emitter/tagged-match.d.ts.map +1 -0
- package/dist/emitter/tagged-match.js +109 -0
- package/dist/emitter/tagged-match.js.map +1 -0
- package/dist/emitter/types.d.ts +22 -0
- package/dist/emitter/types.d.ts.map +1 -0
- package/dist/emitter/types.js +231 -0
- package/dist/emitter/types.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +98 -0
- package/dist/errors.js.map +1 -0
- package/dist/formatter/comments.d.ts +25 -0
- package/dist/formatter/comments.d.ts.map +1 -0
- package/dist/formatter/comments.js +283 -0
- package/dist/formatter/comments.js.map +1 -0
- package/dist/formatter/index.d.ts +71 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +1113 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/formatter/operator-precedence.d.ts +3 -0
- package/dist/formatter/operator-precedence.d.ts.map +1 -0
- package/dist/formatter/operator-precedence.js +27 -0
- package/dist/formatter/operator-precedence.js.map +1 -0
- package/dist/formatter/prettier.d.ts +7 -0
- package/dist/formatter/prettier.d.ts.map +1 -0
- package/dist/formatter/prettier.js +51 -0
- package/dist/formatter/prettier.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/interop/callback.d.ts +38 -0
- package/dist/interop/callback.d.ts.map +1 -0
- package/dist/interop/callback.js +130 -0
- package/dist/interop/callback.js.map +1 -0
- package/dist/interop/index.d.ts +6 -0
- package/dist/interop/index.d.ts.map +1 -0
- package/dist/interop/index.js +6 -0
- package/dist/interop/index.js.map +1 -0
- package/dist/interop/js.d.ts +16 -0
- package/dist/interop/js.d.ts.map +1 -0
- package/dist/interop/js.js +35 -0
- package/dist/interop/js.js.map +1 -0
- package/dist/interop/record.d.ts +9 -0
- package/dist/interop/record.d.ts.map +1 -0
- package/dist/interop/record.js +18 -0
- package/dist/interop/record.js.map +1 -0
- package/dist/interop/valibot.d.ts +9 -0
- package/dist/interop/valibot.d.ts.map +1 -0
- package/dist/interop/valibot.js +94 -0
- package/dist/interop/valibot.js.map +1 -0
- package/dist/interop/zod.d.ts +45 -0
- package/dist/interop/zod.d.ts.map +1 -0
- package/dist/interop/zod.js +143 -0
- package/dist/interop/zod.js.map +1 -0
- package/dist/lexer/lexer.d.ts +65 -0
- package/dist/lexer/lexer.d.ts.map +1 -0
- package/dist/lexer/lexer.js +1335 -0
- package/dist/lexer/lexer.js.map +1 -0
- package/dist/lexer/tokens.d.ts +96 -0
- package/dist/lexer/tokens.d.ts.map +1 -0
- package/dist/lexer/tokens.js +150 -0
- package/dist/lexer/tokens.js.map +1 -0
- package/dist/lsp/code-action-worker.d.ts +2 -0
- package/dist/lsp/code-action-worker.d.ts.map +1 -0
- package/dist/lsp/code-action-worker.js +17 -0
- package/dist/lsp/code-action-worker.js.map +1 -0
- package/dist/lsp/completion.d.ts +11 -0
- package/dist/lsp/completion.d.ts.map +1 -0
- package/dist/lsp/completion.js +260 -0
- package/dist/lsp/completion.js.map +1 -0
- package/dist/lsp/definition.d.ts +42 -0
- package/dist/lsp/definition.d.ts.map +1 -0
- package/dist/lsp/definition.js +1074 -0
- package/dist/lsp/definition.js.map +1 -0
- package/dist/lsp/diagnostics-worker.d.ts +2 -0
- package/dist/lsp/diagnostics-worker.d.ts.map +1 -0
- package/dist/lsp/diagnostics-worker.js +169 -0
- package/dist/lsp/diagnostics-worker.js.map +1 -0
- package/dist/lsp/docs.d.ts +37 -0
- package/dist/lsp/docs.d.ts.map +1 -0
- package/dist/lsp/docs.js +830 -0
- package/dist/lsp/docs.js.map +1 -0
- package/dist/lsp/error-channel.d.ts +3 -0
- package/dist/lsp/error-channel.d.ts.map +1 -0
- package/dist/lsp/error-channel.js +48 -0
- package/dist/lsp/error-channel.js.map +1 -0
- package/dist/lsp/hover.d.ts +5 -0
- package/dist/lsp/hover.d.ts.map +1 -0
- package/dist/lsp/hover.js +651 -0
- package/dist/lsp/hover.js.map +1 -0
- package/dist/lsp/imports.d.ts +5 -0
- package/dist/lsp/imports.d.ts.map +1 -0
- package/dist/lsp/imports.js +317 -0
- package/dist/lsp/imports.js.map +1 -0
- package/dist/lsp/index.d.ts +16 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +17 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/inlay-hints.d.ts +3 -0
- package/dist/lsp/inlay-hints.d.ts.map +1 -0
- package/dist/lsp/inlay-hints.js +236 -0
- package/dist/lsp/inlay-hints.js.map +1 -0
- package/dist/lsp/interop-rename.d.ts +26 -0
- package/dist/lsp/interop-rename.d.ts.map +1 -0
- package/dist/lsp/interop-rename.js +346 -0
- package/dist/lsp/interop-rename.js.map +1 -0
- package/dist/lsp/match-arms.d.ts +3 -0
- package/dist/lsp/match-arms.d.ts.map +1 -0
- package/dist/lsp/match-arms.js +341 -0
- package/dist/lsp/match-arms.js.map +1 -0
- package/dist/lsp/navigation.d.ts +23 -0
- package/dist/lsp/navigation.d.ts.map +1 -0
- package/dist/lsp/navigation.js +430 -0
- package/dist/lsp/navigation.js.map +1 -0
- package/dist/lsp/parsed-documents.d.ts +25 -0
- package/dist/lsp/parsed-documents.d.ts.map +1 -0
- package/dist/lsp/parsed-documents.js +47 -0
- package/dist/lsp/parsed-documents.js.map +1 -0
- package/dist/lsp/rename-worker.d.ts +2 -0
- package/dist/lsp/rename-worker.d.ts.map +1 -0
- package/dist/lsp/rename-worker.js +27 -0
- package/dist/lsp/rename-worker.js.map +1 -0
- package/dist/lsp/server.d.ts +78 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +1098 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/thunk-pipeline.d.ts +4 -0
- package/dist/lsp/thunk-pipeline.d.ts.map +1 -0
- package/dist/lsp/thunk-pipeline.js +95 -0
- package/dist/lsp/thunk-pipeline.js.map +1 -0
- package/dist/lsp/validation.d.ts +8 -0
- package/dist/lsp/validation.d.ts.map +1 -0
- package/dist/lsp/validation.js +124 -0
- package/dist/lsp/validation.js.map +1 -0
- package/dist/lsp/workspace.d.ts +8 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +70 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/math.ts +1 -0
- package/dist/parser/declarations.d.ts +21 -0
- package/dist/parser/declarations.d.ts.map +1 -0
- package/dist/parser/declarations.js +626 -0
- package/dist/parser/declarations.js.map +1 -0
- package/dist/parser/errors.d.ts +9 -0
- package/dist/parser/errors.d.ts.map +1 -0
- package/dist/parser/errors.js +11 -0
- package/dist/parser/errors.js.map +1 -0
- package/dist/parser/index.d.ts +9 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +9 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/jsx.d.ts +5 -0
- package/dist/parser/jsx.d.ts.map +1 -0
- package/dist/parser/jsx.js +188 -0
- package/dist/parser/jsx.js.map +1 -0
- package/dist/parser/operator-expressions.d.ts +16 -0
- package/dist/parser/operator-expressions.d.ts.map +1 -0
- package/dist/parser/operator-expressions.js +146 -0
- package/dist/parser/operator-expressions.js.map +1 -0
- package/dist/parser/parser.d.ts +104 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +1216 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/patterns.d.ts +9 -0
- package/dist/parser/patterns.d.ts.map +1 -0
- package/dist/parser/patterns.js +292 -0
- package/dist/parser/patterns.js.map +1 -0
- package/dist/parser/pipeline-expressions.d.ts +10 -0
- package/dist/parser/pipeline-expressions.d.ts.map +1 -0
- package/dist/parser/pipeline-expressions.js +57 -0
- package/dist/parser/pipeline-expressions.js.map +1 -0
- package/dist/parser/scope.d.ts +17 -0
- package/dist/parser/scope.d.ts.map +1 -0
- package/dist/parser/scope.js +56 -0
- package/dist/parser/scope.js.map +1 -0
- package/dist/parser/statements.d.ts +13 -0
- package/dist/parser/statements.d.ts.map +1 -0
- package/dist/parser/statements.js +737 -0
- package/dist/parser/statements.js.map +1 -0
- package/dist/parser/types.d.ts +13 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +371 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/plugins/bun-preload.d.ts +4 -0
- package/dist/plugins/bun-preload.d.ts.map +1 -0
- package/dist/plugins/bun-preload.js +18 -0
- package/dist/plugins/bun-preload.js.map +1 -0
- package/dist/plugins/bun.d.ts +115 -0
- package/dist/plugins/bun.d.ts.map +1 -0
- package/dist/plugins/bun.js +240 -0
- package/dist/plugins/bun.js.map +1 -0
- package/dist/plugins/esbuild.d.ts +45 -0
- package/dist/plugins/esbuild.d.ts.map +1 -0
- package/dist/plugins/esbuild.js +184 -0
- package/dist/plugins/esbuild.js.map +1 -0
- package/dist/plugins/type-view.d.ts +30 -0
- package/dist/plugins/type-view.d.ts.map +1 -0
- package/dist/plugins/type-view.js +245 -0
- package/dist/plugins/type-view.js.map +1 -0
- package/dist/plugins/vite.d.ts +56 -0
- package/dist/plugins/vite.d.ts.map +1 -0
- package/dist/plugins/vite.js +182 -0
- package/dist/plugins/vite.js.map +1 -0
- package/dist/service.ts +3 -0
- package/dist/service.ts.map +1 -0
- package/dist/testing/index.d.ts +24 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +56 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tooling/doc.d.ts +82 -0
- package/dist/tooling/doc.d.ts.map +1 -0
- package/dist/tooling/doc.js +624 -0
- package/dist/tooling/doc.js.map +1 -0
- package/dist/tooling/idiomatic.d.ts +20 -0
- package/dist/tooling/idiomatic.d.ts.map +1 -0
- package/dist/tooling/idiomatic.js +154 -0
- package/dist/tooling/idiomatic.js.map +1 -0
- package/dist/tooling/migrate.d.ts +62 -0
- package/dist/tooling/migrate.d.ts.map +1 -0
- package/dist/tooling/migrate.js +608 -0
- package/dist/tooling/migrate.js.map +1 -0
- package/dist/tooling/pipeline-style.d.ts +12 -0
- package/dist/tooling/pipeline-style.d.ts.map +1 -0
- package/dist/tooling/pipeline-style.js +208 -0
- package/dist/tooling/pipeline-style.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +25 -0
- package/dist/version.js.map +1 -0
- package/package.json +128 -4
- package/src/ast/types.ts +753 -0
- package/src/ast/walk.ts +35 -0
- package/src/cli/build-bun.ts +249 -0
- package/src/cli/build-watch.ts +299 -0
- package/src/cli/build.ts +450 -0
- package/src/cli/check.ts +342 -0
- package/src/cli/commands.ts +301 -0
- package/src/cli/doc.ts +81 -0
- package/src/cli/doctor.ts +173 -0
- package/src/cli/emit.ts +138 -0
- package/src/cli/explain.ts +127 -0
- package/src/cli/fmt.ts +170 -0
- package/src/cli/index.ts +227 -0
- package/src/cli/init.ts +491 -0
- package/src/cli/io.ts +150 -0
- package/src/cli/pipeline-style.ts +55 -0
- package/src/cli/repl.ts +443 -0
- package/src/cli/run.ts +238 -0
- package/src/cli/test.ts +148 -0
- package/src/cli/tsc.ts +207 -0
- package/src/cli/typecheck.ts +100 -0
- package/src/compiler/ast-inspection.ts +121 -0
- package/src/compiler/boolean-operators.ts +108 -0
- package/src/compiler/check.ts +2763 -0
- package/src/compiler/diagnostics.ts +179 -0
- package/src/compiler/effect-mutation-rule.ts +407 -0
- package/src/compiler/entry-rules.ts +116 -0
- package/src/compiler/incremental-build.ts +131 -0
- package/src/compiler/incremental-dependencies.ts +200 -0
- package/src/compiler/js-interop-nullability.ts +67 -0
- package/src/compiler/modules/output-collisions.ts +48 -0
- package/src/compiler/modules/output-plan.ts +46 -0
- package/src/compiler/modules/resolution.ts +56 -0
- package/src/compiler/numeric-comparisons.ts +213 -0
- package/src/compiler/optional-arguments.ts +335 -0
- package/src/compiler/package-fingerprint.ts +216 -0
- package/src/compiler/package-record-contracts.ts +156 -0
- package/src/compiler/pipelines/catalog.ts +1128 -0
- package/src/compiler/pipelines/companions.ts +1279 -0
- package/src/compiler/pipelines/resolution.ts +684 -0
- package/src/compiler/project-config.ts +221 -0
- package/src/compiler/record-contracts.ts +46 -0
- package/src/compiler/rules/control-flow.ts +57 -0
- package/src/compiler/rules/diagnostic.ts +11 -0
- package/src/compiler/rules/module-scope-refs.ts +63 -0
- package/src/compiler/schemas/analysis.ts +45 -0
- package/src/compiler/schemas/imported-record-functions.ts +984 -0
- package/src/compiler/schemas/imported-schemas.ts +761 -0
- package/src/compiler/source-map.ts +165 -0
- package/src/compiler/typescript-context.ts +250 -0
- package/src/compiler.ts +865 -0
- package/src/emitter/assemblyscript.ts +1220 -0
- package/src/emitter/declarations.ts +916 -0
- package/src/emitter/emitter.ts +3128 -0
- package/src/emitter/imports.ts +89 -0
- package/src/emitter/indent.ts +39 -0
- package/src/emitter/jsx.ts +122 -0
- package/src/emitter/local-bindings.ts +40 -0
- package/src/emitter/match.ts +1631 -0
- package/src/emitter/runtime-helpers.ts +31 -0
- package/src/emitter/schemas.ts +969 -0
- package/src/emitter/statements.ts +310 -0
- package/src/emitter/tagged-match.ts +171 -0
- package/src/emitter/types.ts +289 -0
- package/src/errors.ts +115 -0
- package/src/formatter/comments.ts +350 -0
- package/src/formatter/index.ts +1457 -0
- package/src/formatter/operator-precedence.ts +36 -0
- package/src/formatter/prettier.ts +61 -0
- package/src/index.ts +16 -0
- package/src/interop/callback.ts +188 -0
- package/src/interop/js.ts +66 -0
- package/src/interop/record.ts +36 -0
- package/src/interop/valibot.ts +141 -0
- package/src/interop/zod.ts +219 -0
- package/src/lexer/lexer.ts +1521 -0
- package/src/lexer/tokens.ts +174 -0
- package/src/lsp/code-action-worker.ts +31 -0
- package/src/lsp/completion.ts +343 -0
- package/src/lsp/definition.ts +1165 -0
- package/src/lsp/diagnostics-worker.ts +198 -0
- package/src/lsp/docs.ts +864 -0
- package/src/lsp/error-channel.ts +63 -0
- package/src/lsp/hover.ts +803 -0
- package/src/lsp/imports.ts +380 -0
- package/src/lsp/index.ts +55 -0
- package/src/lsp/inlay-hints.ts +308 -0
- package/src/lsp/interop-rename.ts +454 -0
- package/src/lsp/match-arms.ts +400 -0
- package/src/lsp/navigation.ts +553 -0
- package/src/lsp/parsed-documents.ts +64 -0
- package/src/lsp/rename-worker.ts +40 -0
- package/src/lsp/server.ts +1437 -0
- package/src/lsp/thunk-pipeline.ts +117 -0
- package/src/lsp/validation.ts +147 -0
- package/src/lsp/workspace.ts +74 -0
- package/src/parser/declarations.ts +808 -0
- package/src/parser/errors.ts +18 -0
- package/src/parser/jsx.ts +253 -0
- package/src/parser/operator-expressions.ts +170 -0
- package/src/parser/parser.ts +1565 -0
- package/src/parser/patterns.ts +342 -0
- package/src/parser/pipeline-expressions.ts +77 -0
- package/src/parser/scope.ts +69 -0
- package/src/parser/statements.ts +831 -0
- package/src/parser/types.ts +453 -0
- package/src/plugins/bun-preload.ts +25 -0
- package/src/plugins/bun.ts +448 -0
- package/src/plugins/esbuild.ts +308 -0
- package/src/plugins/type-view.ts +326 -0
- package/src/plugins/vite.ts +294 -0
- package/src/testing/index.ts +72 -0
- package/src/tooling/doc.ts +786 -0
- package/src/tooling/idiomatic.ts +202 -0
- package/src/tooling/pipeline-style.ts +248 -0
- package/src/version.ts +27 -0
|
@@ -0,0 +1,1565 @@
|
|
|
1
|
+
import { OperatorParser } from "./operator-expressions.js";
|
|
2
|
+
import { parsePipeline } from "./pipeline-expressions.js";
|
|
3
|
+
import {
|
|
4
|
+
type ArrayExpression,
|
|
5
|
+
type ArrayPattern,
|
|
6
|
+
type BindingDeclaration,
|
|
7
|
+
type BindingTarget,
|
|
8
|
+
type BlockStatement,
|
|
9
|
+
type ConstructorPattern,
|
|
10
|
+
type DotPathExpression,
|
|
11
|
+
type EffectBlockExpression,
|
|
12
|
+
type EffectTypeNode,
|
|
13
|
+
type ErrorDeclaration,
|
|
14
|
+
type ExportDefaultDeclaration,
|
|
15
|
+
type ExportFromDeclaration,
|
|
16
|
+
type Expression,
|
|
17
|
+
type FunctionBody,
|
|
18
|
+
type FunctionExpression,
|
|
19
|
+
type Identifier,
|
|
20
|
+
type ImportDeclaration,
|
|
21
|
+
type ImportedTsSchema,
|
|
22
|
+
type IndexExpression,
|
|
23
|
+
type JSXElement,
|
|
24
|
+
type JSXSelfClosingElement,
|
|
25
|
+
type MatchArm,
|
|
26
|
+
type MatchExpression,
|
|
27
|
+
type MutBlockExpression,
|
|
28
|
+
type Parameter,
|
|
29
|
+
type ParBlockExpression,
|
|
30
|
+
type Pattern,
|
|
31
|
+
type Position,
|
|
32
|
+
type Program,
|
|
33
|
+
type RecordEntry,
|
|
34
|
+
type RecordExpression,
|
|
35
|
+
type RecordPattern,
|
|
36
|
+
type RecordPatternField,
|
|
37
|
+
type RecordSchema,
|
|
38
|
+
type SchemaBody,
|
|
39
|
+
type SchemaDeclaration,
|
|
40
|
+
type ServiceDeclaration,
|
|
41
|
+
type Span,
|
|
42
|
+
type StringLiteral,
|
|
43
|
+
type StringPart,
|
|
44
|
+
type StructuralUnionSchema,
|
|
45
|
+
type TaggedUnionSchema,
|
|
46
|
+
type TemplateLiteral,
|
|
47
|
+
type TopLevelDeclaration,
|
|
48
|
+
type TsDerivedSchema,
|
|
49
|
+
type TypeNode,
|
|
50
|
+
type TypeParameter,
|
|
51
|
+
type UpperIdentifier,
|
|
52
|
+
type WhenStatement,
|
|
53
|
+
} from "../ast/types.js";
|
|
54
|
+
import { type Token, KEYWORDS, TokenType } from "../lexer/tokens.js";
|
|
55
|
+
import {
|
|
56
|
+
isExportFrom as isExportFromImpl,
|
|
57
|
+
parseBindingDeclaration as parseBindingDeclarationImpl,
|
|
58
|
+
parseDeclaration as parseDeclarationImpl,
|
|
59
|
+
parseErrorDeclaration as parseErrorDeclarationImpl,
|
|
60
|
+
parseExportDefaultDeclaration as parseExportDefaultDeclarationImpl,
|
|
61
|
+
parseExportFrom as parseExportFromImpl,
|
|
62
|
+
parseImportDeclaration as parseImportDeclarationImpl,
|
|
63
|
+
parseImportedTsSchema as parseImportedTsSchemaImpl,
|
|
64
|
+
parseImportSource as parseImportSourceImpl,
|
|
65
|
+
parseRecordSchema as parseRecordSchemaImpl,
|
|
66
|
+
parseSchemaBody as parseSchemaBodyImpl,
|
|
67
|
+
parseSchemaDeclaration as parseSchemaDeclarationImpl,
|
|
68
|
+
parseServiceDeclaration as parseServiceDeclarationImpl,
|
|
69
|
+
parseStructuralUnionSchema as parseStructuralUnionSchemaImpl,
|
|
70
|
+
parseTaggedUnionSchema as parseTaggedUnionSchemaImpl,
|
|
71
|
+
parseTopLevelDeclaration as parseTopLevelDeclarationImpl,
|
|
72
|
+
parseTsDerivedSchema as parseTsDerivedSchemaImpl,
|
|
73
|
+
} from "./declarations.js";
|
|
74
|
+
import { parseJsxElement } from "./jsx.js";
|
|
75
|
+
import {
|
|
76
|
+
collectPatternVariables as collectPatternVariablesImpl,
|
|
77
|
+
isDestructuringBindingStart as isDestructuringBindingStartImpl,
|
|
78
|
+
isDestructuringEffectBindStart as isDestructuringEffectBindStartImpl,
|
|
79
|
+
parseBindingPattern as parseBindingPatternImpl,
|
|
80
|
+
parsePattern as parsePatternImpl,
|
|
81
|
+
} from "./patterns.js";
|
|
82
|
+
import { ScopeStack } from "./scope.js";
|
|
83
|
+
import {
|
|
84
|
+
isAssignmentStart as isAssignmentStartImpl,
|
|
85
|
+
isBraceBlock as isBraceBlockImpl,
|
|
86
|
+
parseAssignmentTarget as parseAssignmentTargetImpl,
|
|
87
|
+
parseBraceBlock as parseBraceBlockImpl,
|
|
88
|
+
parseEffectBlock as parseEffectBlockImpl,
|
|
89
|
+
parseFunctionBody as parseFunctionBodyImpl,
|
|
90
|
+
parseIndentedBlock as parseIndentedBlockImpl,
|
|
91
|
+
parseParBlock as parseParBlockImpl,
|
|
92
|
+
parseWhenStatement as parseWhenStatementImpl,
|
|
93
|
+
} from "./statements.js";
|
|
94
|
+
import {
|
|
95
|
+
isGenericCallableStart,
|
|
96
|
+
parseEffectTypeNode,
|
|
97
|
+
parseFunctionTypeNode,
|
|
98
|
+
parseGenericFunctionExpression,
|
|
99
|
+
parseIntersectionType,
|
|
100
|
+
parsePrimaryType,
|
|
101
|
+
parseTypeNode,
|
|
102
|
+
parseTypeParameters,
|
|
103
|
+
parseUnionType,
|
|
104
|
+
} from "./types.js";
|
|
105
|
+
|
|
106
|
+
import {
|
|
107
|
+
EFFECT_BARE_EXPR_DIAGNOSTIC,
|
|
108
|
+
EFFECT_RETURN_DIAGNOSTIC,
|
|
109
|
+
FUNCTION_RETURN_DIAGNOSTIC,
|
|
110
|
+
ParseError,
|
|
111
|
+
} from "./errors.js";
|
|
112
|
+
export {
|
|
113
|
+
EFFECT_BARE_EXPR_DIAGNOSTIC,
|
|
114
|
+
EFFECT_RETURN_DIAGNOSTIC,
|
|
115
|
+
FUNCTION_RETURN_DIAGNOSTIC,
|
|
116
|
+
ParseError,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export interface ParserOptions {
|
|
120
|
+
throwOnError?: boolean;
|
|
121
|
+
isFunx?: boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export class Parser {
|
|
125
|
+
public current = 0;
|
|
126
|
+
public diagnostics: ParseError[] = [];
|
|
127
|
+
public functionDepth = 0;
|
|
128
|
+
private scopeStack = new ScopeStack();
|
|
129
|
+
|
|
130
|
+
public enterScope(): void {
|
|
131
|
+
this.scopeStack.enterScope();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public exitScope(): void {
|
|
135
|
+
this.scopeStack.exitScope();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public addMutableVariable(name: string): void {
|
|
139
|
+
this.scopeStack.addMutableVariable(name);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public addMutDraftVariable(name: string): void {
|
|
143
|
+
this.scopeStack.addMutDraftVariable(name);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public isMutableVariable(name: string): boolean {
|
|
147
|
+
return this.scopeStack.isMutableVariable(name);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public isMutDraftVariable(name: string): boolean {
|
|
151
|
+
return this.scopeStack.isMutDraftVariable(name);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
public parseBindingPattern(): RecordPattern | ArrayPattern {
|
|
155
|
+
return parseBindingPatternImpl(this);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public parsingBraceEffect = false;
|
|
159
|
+
public hasDefaultExport = false;
|
|
160
|
+
public allowDefaultedRecordFields = false;
|
|
161
|
+
public recordTypeDepth = 0;
|
|
162
|
+
private options: ParserOptions;
|
|
163
|
+
|
|
164
|
+
constructor(
|
|
165
|
+
public tokens: Token[],
|
|
166
|
+
_filename: string = "<anonymous>",
|
|
167
|
+
_source: string = "",
|
|
168
|
+
options?: ParserOptions,
|
|
169
|
+
) {
|
|
170
|
+
this.options = { ...options };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public getDiagnostics(): ParseError[] {
|
|
174
|
+
return this.diagnostics;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public synchronize(): void {
|
|
178
|
+
while (!this.isAtEnd()) {
|
|
179
|
+
if (this.peek().type === TokenType.DEDENT) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const tok = this.advance();
|
|
183
|
+
if (tok.type === TokenType.NEWLINE || tok.type === TokenType.RBRACE) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
public parse(optionsOrThrowOnError: boolean | ParserOptions = true): Program {
|
|
190
|
+
const opts: ParserOptions =
|
|
191
|
+
typeof optionsOrThrowOnError === "boolean"
|
|
192
|
+
? { throwOnError: optionsOrThrowOnError }
|
|
193
|
+
: (optionsOrThrowOnError ?? {});
|
|
194
|
+
const throwOnError = opts.throwOnError ?? this.options.throwOnError ?? true;
|
|
195
|
+
this.hasDefaultExport = false;
|
|
196
|
+
this.scopeStack.reset();
|
|
197
|
+
|
|
198
|
+
const start = this.peek().span.start;
|
|
199
|
+
const body: TopLevelDeclaration[] = [];
|
|
200
|
+
|
|
201
|
+
this.skipNewlines();
|
|
202
|
+
|
|
203
|
+
while (!this.isAtEnd()) {
|
|
204
|
+
if (this.match(TokenType.DEDENT)) {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
try {
|
|
208
|
+
body.push(this.parseTopLevelDeclaration());
|
|
209
|
+
} catch (err: unknown) {
|
|
210
|
+
if (err instanceof ParseError) {
|
|
211
|
+
this.diagnostics.push(err);
|
|
212
|
+
this.synchronize();
|
|
213
|
+
} else {
|
|
214
|
+
throw err;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
this.skipNewlines();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const end = this.previous().span.end;
|
|
221
|
+
|
|
222
|
+
if (throwOnError && this.diagnostics.length > 0) {
|
|
223
|
+
const err = this.diagnostics[0];
|
|
224
|
+
(err as ParseError & { diagnostics?: ParseError[] }).diagnostics =
|
|
225
|
+
this.diagnostics;
|
|
226
|
+
throw err;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
kind: "Program",
|
|
231
|
+
body,
|
|
232
|
+
span: { start, end },
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// --- Top-Level Declarations ---
|
|
237
|
+
|
|
238
|
+
public parseTopLevelDeclaration(): TopLevelDeclaration {
|
|
239
|
+
return parseTopLevelDeclarationImpl(this);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
public isExportFrom(): boolean {
|
|
243
|
+
return isExportFromImpl(this);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public parseExportFrom(start: Position): ExportFromDeclaration {
|
|
247
|
+
return parseExportFromImpl(this, start);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public parseExportDefaultDeclaration(
|
|
251
|
+
start: Position,
|
|
252
|
+
): ExportDefaultDeclaration {
|
|
253
|
+
return parseExportDefaultDeclarationImpl(this, start);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public parseDeclaration(isJs = false, isTs = false): TopLevelDeclaration {
|
|
257
|
+
return parseDeclarationImpl(this, isJs, isTs);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Consumes the raw TypeScript payload the lexer captured after 'ts'. */
|
|
261
|
+
public consumeTsCode(): Token {
|
|
262
|
+
return this.consume(TokenType.TS_CODE, "Expected '{ ... }' after 'ts'");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
public parseImportDeclaration(): ImportDeclaration {
|
|
266
|
+
return parseImportDeclarationImpl(this);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
public parseImportSource(): StringLiteral {
|
|
270
|
+
return parseImportSourceImpl(this);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
public parseSchemaDeclaration(
|
|
274
|
+
isTs = false,
|
|
275
|
+
tsStart?: Position,
|
|
276
|
+
): SchemaDeclaration {
|
|
277
|
+
return parseSchemaDeclarationImpl(this, isTs, tsStart);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public parseTsDerivedSchema(): TsDerivedSchema {
|
|
281
|
+
return parseTsDerivedSchemaImpl(this);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
public parseSchemaBody(): SchemaBody {
|
|
285
|
+
return parseSchemaBodyImpl(this);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
public parseImportedTsSchema(): ImportedTsSchema {
|
|
289
|
+
return parseImportedTsSchemaImpl(this);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public parseRecordSchema(): RecordSchema {
|
|
293
|
+
return parseRecordSchemaImpl(this);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
public parseStructuralUnionSchema(): StructuralUnionSchema {
|
|
297
|
+
return parseStructuralUnionSchemaImpl(this);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
public parseTaggedUnionSchema(): TaggedUnionSchema {
|
|
301
|
+
return parseTaggedUnionSchemaImpl(this);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public parseErrorDeclaration(): ErrorDeclaration {
|
|
305
|
+
return parseErrorDeclarationImpl(this);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
public parseServiceDeclaration(): ServiceDeclaration {
|
|
309
|
+
return parseServiceDeclarationImpl(this);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
public parseBindingDeclaration(isJs = false): BindingDeclaration {
|
|
313
|
+
return parseBindingDeclarationImpl(this, isJs);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private expressionToBindingTarget(expr: Expression): BindingTarget | null {
|
|
317
|
+
if (expr.kind === "Identifier" || expr.kind === "UpperIdentifier") {
|
|
318
|
+
return expr;
|
|
319
|
+
}
|
|
320
|
+
if (expr.kind === "Placeholder") {
|
|
321
|
+
return { kind: "Identifier", name: "_", span: expr.span };
|
|
322
|
+
}
|
|
323
|
+
if (expr.kind === "RecordExpression") {
|
|
324
|
+
const fields: RecordPatternField[] = [];
|
|
325
|
+
for (const entry of expr.entries) {
|
|
326
|
+
if (entry.kind === "SpreadEntry") {
|
|
327
|
+
if (entry.argument.kind !== "Identifier") return null;
|
|
328
|
+
fields.push({
|
|
329
|
+
kind: "RecordPatternField",
|
|
330
|
+
key: entry.argument,
|
|
331
|
+
isRest: true,
|
|
332
|
+
span: entry.span,
|
|
333
|
+
});
|
|
334
|
+
} else if (entry.kind === "ShorthandEntry") {
|
|
335
|
+
fields.push({
|
|
336
|
+
kind: "RecordPatternField",
|
|
337
|
+
key: entry.key,
|
|
338
|
+
span: entry.span,
|
|
339
|
+
});
|
|
340
|
+
} else if (entry.kind === "FieldEntry") {
|
|
341
|
+
const subTarget = this.expressionToBindingTarget(entry.value);
|
|
342
|
+
if (!subTarget) return null;
|
|
343
|
+
const subPattern: Pattern =
|
|
344
|
+
subTarget.kind === "Identifier" ||
|
|
345
|
+
subTarget.kind === "UpperIdentifier"
|
|
346
|
+
? {
|
|
347
|
+
kind: "VariablePattern",
|
|
348
|
+
name: subTarget,
|
|
349
|
+
span: subTarget.span,
|
|
350
|
+
}
|
|
351
|
+
: subTarget;
|
|
352
|
+
fields.push({
|
|
353
|
+
kind: "RecordPatternField",
|
|
354
|
+
key: entry.key,
|
|
355
|
+
pattern: subPattern,
|
|
356
|
+
span: entry.span,
|
|
357
|
+
});
|
|
358
|
+
} else {
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
kind: "RecordPattern",
|
|
364
|
+
fields,
|
|
365
|
+
span: expr.span,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
if (expr.kind === "ArrayExpression") {
|
|
369
|
+
const elements: Pattern[] = [];
|
|
370
|
+
for (const el of expr.elements) {
|
|
371
|
+
if (el.kind === "SpreadElement") {
|
|
372
|
+
const subTarget = this.expressionToBindingTarget(el.argument);
|
|
373
|
+
if (!subTarget) return null;
|
|
374
|
+
elements.push({
|
|
375
|
+
kind: "RestPattern",
|
|
376
|
+
argument:
|
|
377
|
+
subTarget.kind === "Identifier" ||
|
|
378
|
+
subTarget.kind === "UpperIdentifier"
|
|
379
|
+
? {
|
|
380
|
+
kind: "VariablePattern",
|
|
381
|
+
name: subTarget,
|
|
382
|
+
span: subTarget.span,
|
|
383
|
+
}
|
|
384
|
+
: subTarget,
|
|
385
|
+
span: el.span,
|
|
386
|
+
});
|
|
387
|
+
} else {
|
|
388
|
+
const subTarget = this.expressionToBindingTarget(el);
|
|
389
|
+
if (!subTarget) return null;
|
|
390
|
+
elements.push(
|
|
391
|
+
subTarget.kind === "Identifier" ||
|
|
392
|
+
subTarget.kind === "UpperIdentifier"
|
|
393
|
+
? {
|
|
394
|
+
kind: "VariablePattern",
|
|
395
|
+
name: subTarget,
|
|
396
|
+
span: subTarget.span,
|
|
397
|
+
}
|
|
398
|
+
: subTarget,
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return {
|
|
403
|
+
kind: "ArrayPattern",
|
|
404
|
+
elements,
|
|
405
|
+
span: expr.span,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
private parseValueParameter(
|
|
412
|
+
name: BindingTarget,
|
|
413
|
+
nameOnlySpan = false,
|
|
414
|
+
isRest = false,
|
|
415
|
+
): Parameter {
|
|
416
|
+
if (this.match(TokenType.QUESTION)) {
|
|
417
|
+
throw new ParseError(
|
|
418
|
+
"Optional '?' parameter syntax is disabled in FunkScript; use 'Option<T>' or a default value '= default'",
|
|
419
|
+
this.previous().span,
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
let typeAnnotation: TypeNode | undefined;
|
|
423
|
+
if (this.match(TokenType.COLON)) {
|
|
424
|
+
const previous = this.allowDefaultedRecordFields;
|
|
425
|
+
this.allowDefaultedRecordFields = this.check(TokenType.LBRACE);
|
|
426
|
+
try {
|
|
427
|
+
typeAnnotation = this.parseTypeNode();
|
|
428
|
+
} finally {
|
|
429
|
+
this.allowDefaultedRecordFields = previous;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const defaultValue = this.match(TokenType.EQ)
|
|
433
|
+
? this.parseExpression()
|
|
434
|
+
: undefined;
|
|
435
|
+
return {
|
|
436
|
+
kind: "Parameter",
|
|
437
|
+
name,
|
|
438
|
+
typeAnnotation,
|
|
439
|
+
defaultValue,
|
|
440
|
+
isRest: isRest ? true : undefined,
|
|
441
|
+
span: nameOnlySpan
|
|
442
|
+
? name.span
|
|
443
|
+
: {
|
|
444
|
+
start: name.span.start,
|
|
445
|
+
end: (defaultValue ?? typeAnnotation ?? name).span.end,
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
public validateValueParameters(params: Parameter[]): void {
|
|
451
|
+
for (let i = 0; i < params.length; i++) {
|
|
452
|
+
if (params[i].isRest) {
|
|
453
|
+
if (i !== params.length - 1) {
|
|
454
|
+
throw new ParseError(
|
|
455
|
+
"A rest parameter must be the last parameter in a parameter list",
|
|
456
|
+
params[i].span,
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
if (params[i].defaultValue) {
|
|
460
|
+
throw new ParseError(
|
|
461
|
+
"A rest parameter cannot have a default value",
|
|
462
|
+
params[i].span,
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
public parseWhenStatement(): WhenStatement {
|
|
470
|
+
return parseWhenStatementImpl(this);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// --- Expressions & Pratt Parser ---
|
|
474
|
+
|
|
475
|
+
public parseExpression(): Expression {
|
|
476
|
+
return parsePipeline(this, {
|
|
477
|
+
logical: () => new OperatorParser(this).parseLogicalOr(),
|
|
478
|
+
mut: () => this.parseMutBlock(),
|
|
479
|
+
match: (isCatch) => this.parseMatchExpression(true, isCatch),
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
private parseMutBlock(): MutBlockExpression {
|
|
484
|
+
const start = this.previous().span.start;
|
|
485
|
+
this.consume(TokenType.LPAREN, "Expected '(' after 'mut'");
|
|
486
|
+
const draftParam = this.parseIdentifier();
|
|
487
|
+
this.consume(TokenType.RPAREN, "Expected ')' after draft param");
|
|
488
|
+
if (!this.match(TokenType.ARROW)) {
|
|
489
|
+
throw new ParseError("Expected '=>' in mut block", this.peek().span);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
this.enterScope();
|
|
493
|
+
this.addMutDraftVariable(draftParam.name);
|
|
494
|
+
let body: FunctionBody;
|
|
495
|
+
try {
|
|
496
|
+
body = this.parseFunctionBody();
|
|
497
|
+
} finally {
|
|
498
|
+
this.exitScope();
|
|
499
|
+
}
|
|
500
|
+
return {
|
|
501
|
+
kind: "MutBlockExpression",
|
|
502
|
+
draftParam,
|
|
503
|
+
body,
|
|
504
|
+
span: { start, end: body.span.end },
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
public parsePostfix(): Expression {
|
|
509
|
+
let expr = this.parsePrimary();
|
|
510
|
+
|
|
511
|
+
while (true) {
|
|
512
|
+
if (
|
|
513
|
+
this.check(TokenType.TEMPLATE_STRING) ||
|
|
514
|
+
this.check(TokenType.TEMPLATE_PART)
|
|
515
|
+
) {
|
|
516
|
+
const template = this.parseTemplateLiteral();
|
|
517
|
+
expr = {
|
|
518
|
+
kind: "TaggedTemplateExpression",
|
|
519
|
+
tag: expr,
|
|
520
|
+
template,
|
|
521
|
+
span: { start: expr.span.start, end: template.span.end },
|
|
522
|
+
};
|
|
523
|
+
} else if (
|
|
524
|
+
this.check(TokenType.LT) &&
|
|
525
|
+
this.isTypeArgumentListBeforeTemplate()
|
|
526
|
+
) {
|
|
527
|
+
const typeArgs = this.parseTypeArguments();
|
|
528
|
+
const template = this.parseTemplateLiteral();
|
|
529
|
+
expr = {
|
|
530
|
+
kind: "TaggedTemplateExpression",
|
|
531
|
+
tag: expr,
|
|
532
|
+
typeArguments: typeArgs,
|
|
533
|
+
template,
|
|
534
|
+
span: { start: expr.span.start, end: template.span.end },
|
|
535
|
+
};
|
|
536
|
+
} else if (this.match(TokenType.LPAREN)) {
|
|
537
|
+
this.skipNewlines();
|
|
538
|
+
while (this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
539
|
+
this.skipNewlines();
|
|
540
|
+
const args: Expression[] = [];
|
|
541
|
+
if (!this.check(TokenType.RPAREN)) {
|
|
542
|
+
do {
|
|
543
|
+
this.skipNewlines();
|
|
544
|
+
while (
|
|
545
|
+
this.match(TokenType.INDENT) ||
|
|
546
|
+
this.match(TokenType.DEDENT)
|
|
547
|
+
) {}
|
|
548
|
+
this.skipNewlines();
|
|
549
|
+
if (this.check(TokenType.RPAREN)) break;
|
|
550
|
+
if (this.match(TokenType.DOTDOTDOT)) {
|
|
551
|
+
const dotSpan = this.previous().span;
|
|
552
|
+
const arg = this.parseExpression();
|
|
553
|
+
args.push({
|
|
554
|
+
kind: "SpreadElement",
|
|
555
|
+
argument: arg,
|
|
556
|
+
span: { start: dotSpan.start, end: arg.span.end },
|
|
557
|
+
});
|
|
558
|
+
} else {
|
|
559
|
+
args.push(this.parseExpression());
|
|
560
|
+
}
|
|
561
|
+
this.skipNewlines();
|
|
562
|
+
while (
|
|
563
|
+
this.match(TokenType.INDENT) ||
|
|
564
|
+
this.match(TokenType.DEDENT)
|
|
565
|
+
) {}
|
|
566
|
+
this.skipNewlines();
|
|
567
|
+
} while (
|
|
568
|
+
this.match(TokenType.COMMA) &&
|
|
569
|
+
!this.check(TokenType.RPAREN)
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
this.skipNewlines();
|
|
573
|
+
while (this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
574
|
+
this.skipNewlines();
|
|
575
|
+
const end = this.consume(
|
|
576
|
+
TokenType.RPAREN,
|
|
577
|
+
"Expected ')' after call arguments",
|
|
578
|
+
).span.end;
|
|
579
|
+
expr = {
|
|
580
|
+
kind: "CallExpression",
|
|
581
|
+
callee: expr,
|
|
582
|
+
args,
|
|
583
|
+
span: { start: expr.span.start, end },
|
|
584
|
+
};
|
|
585
|
+
} else if (this.match(TokenType.DOT)) {
|
|
586
|
+
const prop = this.parsePropertyIdentifier();
|
|
587
|
+
expr = {
|
|
588
|
+
kind: "MemberExpression",
|
|
589
|
+
object: expr,
|
|
590
|
+
property: prop,
|
|
591
|
+
span: { start: expr.span.start, end: prop.span.end },
|
|
592
|
+
};
|
|
593
|
+
} else if (
|
|
594
|
+
this.check(TokenType.LBRACKET) &&
|
|
595
|
+
this.peek().span.start.line === expr.span.end.line
|
|
596
|
+
) {
|
|
597
|
+
this.advance();
|
|
598
|
+
const index = this.parseExpression();
|
|
599
|
+
const end = this.consume(TokenType.RBRACKET, "Expected ']' after index")
|
|
600
|
+
.span.end;
|
|
601
|
+
expr = {
|
|
602
|
+
kind: "IndexExpression",
|
|
603
|
+
object: expr,
|
|
604
|
+
index,
|
|
605
|
+
span: { start: expr.span.start, end },
|
|
606
|
+
};
|
|
607
|
+
} else {
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
return expr;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
public parsePrimary(): Expression {
|
|
616
|
+
if (this.parsingBraceEffect && this.isAtEnd()) {
|
|
617
|
+
throw new ParseError(
|
|
618
|
+
"Expected '}' to close effect block",
|
|
619
|
+
this.peek().span,
|
|
620
|
+
);
|
|
621
|
+
}
|
|
622
|
+
// 0. Generic function expression: <A>(value: A) => ...
|
|
623
|
+
if (this.check(TokenType.LT) && this.isGenericCallableStart()) {
|
|
624
|
+
return this.parseGenericFunctionExpression();
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// 1. JSX Element: <tag ...> or <tag ... />
|
|
628
|
+
if (this.check(TokenType.JSX_TAG_OPEN)) {
|
|
629
|
+
return this.parseJsxElement();
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// 1. Placeholder _
|
|
633
|
+
if (this.match(TokenType.UNDERSCORE)) {
|
|
634
|
+
return {
|
|
635
|
+
kind: "Placeholder",
|
|
636
|
+
span: this.previous().span,
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// 2. Typed hole ???
|
|
641
|
+
if (this.match(TokenType.TYPED_HOLE)) {
|
|
642
|
+
const start = this.previous().span.start;
|
|
643
|
+
let label: string | undefined;
|
|
644
|
+
if (this.check(TokenType.STRING)) {
|
|
645
|
+
label = this.parseStringLiteral()
|
|
646
|
+
.parts.map((p) => (p.kind === "StringRawPart" ? p.value : ""))
|
|
647
|
+
.join("");
|
|
648
|
+
}
|
|
649
|
+
return {
|
|
650
|
+
kind: "TypedHole",
|
|
651
|
+
label,
|
|
652
|
+
span: { start, end: this.previous().span.end },
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// 3. Literals
|
|
657
|
+
if (this.match(TokenType.NUMBER)) {
|
|
658
|
+
const tok = this.previous();
|
|
659
|
+
return {
|
|
660
|
+
kind: "NumberLiteral",
|
|
661
|
+
value: parseFloat(tok.value.replaceAll("_", "")),
|
|
662
|
+
raw: tok.value,
|
|
663
|
+
span: tok.span,
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
if (
|
|
667
|
+
this.check(TokenType.STRING) ||
|
|
668
|
+
this.check(TokenType.STRING_PART) ||
|
|
669
|
+
this.check(TokenType.INTERPOLATION_START)
|
|
670
|
+
) {
|
|
671
|
+
return this.parseStringLiteral();
|
|
672
|
+
}
|
|
673
|
+
if (
|
|
674
|
+
this.check(TokenType.TEMPLATE_STRING) ||
|
|
675
|
+
this.check(TokenType.TEMPLATE_PART)
|
|
676
|
+
) {
|
|
677
|
+
return this.parseTemplateLiteral();
|
|
678
|
+
}
|
|
679
|
+
if (this.match(TokenType.TRUE)) {
|
|
680
|
+
return {
|
|
681
|
+
kind: "BooleanLiteral",
|
|
682
|
+
value: true,
|
|
683
|
+
span: this.previous().span,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
if (this.match(TokenType.FALSE)) {
|
|
687
|
+
return {
|
|
688
|
+
kind: "BooleanLiteral",
|
|
689
|
+
value: false,
|
|
690
|
+
span: this.previous().span,
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// 4. Identifiers & Constructors
|
|
695
|
+
if (this.match(TokenType.UPPER_IDENTIFIER)) {
|
|
696
|
+
return {
|
|
697
|
+
kind: "UpperIdentifier",
|
|
698
|
+
name: this.previous().value,
|
|
699
|
+
span: this.previous().span,
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
if (this.match(TokenType.IDENTIFIER)) {
|
|
703
|
+
return {
|
|
704
|
+
kind: "Identifier",
|
|
705
|
+
name: this.previous().value,
|
|
706
|
+
span: this.previous().span,
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// 5. Parenthesized expression or arrow function
|
|
711
|
+
if (this.match(TokenType.LPAREN)) {
|
|
712
|
+
const start = this.previous().span.start;
|
|
713
|
+
if (this.match(TokenType.RPAREN)) {
|
|
714
|
+
let returnType: TypeNode | undefined;
|
|
715
|
+
let arrowConsumed = false;
|
|
716
|
+
if (this.match(TokenType.COLON)) {
|
|
717
|
+
returnType = this.parseTypeNode();
|
|
718
|
+
} else if (
|
|
719
|
+
this.check(TokenType.ARROW) &&
|
|
720
|
+
this.peekAhead(1).type === TokenType.UPPER_IDENTIFIER &&
|
|
721
|
+
(this.peekAhead(2).type === TokenType.ARROW ||
|
|
722
|
+
this.peekAhead(2).type === TokenType.NEWLINE)
|
|
723
|
+
) {
|
|
724
|
+
this.advance();
|
|
725
|
+
arrowConsumed = true;
|
|
726
|
+
returnType = this.parseTypeNode();
|
|
727
|
+
this.match(TokenType.ARROW);
|
|
728
|
+
}
|
|
729
|
+
if (arrowConsumed || this.match(TokenType.ARROW)) {
|
|
730
|
+
const body = this.parseFunctionBody(true);
|
|
731
|
+
return {
|
|
732
|
+
kind: "FunctionExpression",
|
|
733
|
+
params: [],
|
|
734
|
+
returnType,
|
|
735
|
+
body,
|
|
736
|
+
span: { start, end: body.span.end },
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
throw new ParseError(
|
|
740
|
+
"Empty parentheses '()' must be followed by '=>'",
|
|
741
|
+
this.previous().span,
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
// Check if this looks like function params (param: Type, ...) => or (...rest) =>
|
|
746
|
+
let firstIsRest = false;
|
|
747
|
+
let firstDotSpan: Span | undefined;
|
|
748
|
+
if (this.match(TokenType.DOTDOTDOT)) {
|
|
749
|
+
firstIsRest = true;
|
|
750
|
+
firstDotSpan = this.previous().span;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
const firstExpr = firstIsRest
|
|
754
|
+
? this.parseIdentifier()
|
|
755
|
+
: this.parseExpression();
|
|
756
|
+
|
|
757
|
+
if (
|
|
758
|
+
firstIsRest ||
|
|
759
|
+
this.check(TokenType.COLON) ||
|
|
760
|
+
this.check(TokenType.COMMA) ||
|
|
761
|
+
this.check(TokenType.QUESTION) ||
|
|
762
|
+
this.check(TokenType.EQ)
|
|
763
|
+
) {
|
|
764
|
+
const firstTarget = this.expressionToBindingTarget(firstExpr);
|
|
765
|
+
if (!firstTarget)
|
|
766
|
+
throw new ParseError(
|
|
767
|
+
"Expected a parameter name or pattern",
|
|
768
|
+
firstExpr.span,
|
|
769
|
+
);
|
|
770
|
+
const firstParam = this.parseValueParameter(
|
|
771
|
+
firstTarget,
|
|
772
|
+
true,
|
|
773
|
+
firstIsRest,
|
|
774
|
+
);
|
|
775
|
+
if (firstDotSpan) {
|
|
776
|
+
firstParam.span = {
|
|
777
|
+
start: firstDotSpan.start,
|
|
778
|
+
end: firstParam.span.end,
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
const params: Parameter[] = [firstParam];
|
|
782
|
+
while (this.match(TokenType.COMMA)) {
|
|
783
|
+
if (this.check(TokenType.RPAREN)) break;
|
|
784
|
+
let isRest = false;
|
|
785
|
+
let dotSpan: Span | undefined;
|
|
786
|
+
if (this.match(TokenType.DOTDOTDOT)) {
|
|
787
|
+
isRest = true;
|
|
788
|
+
dotSpan = this.previous().span;
|
|
789
|
+
}
|
|
790
|
+
let pTarget: BindingTarget;
|
|
791
|
+
if (this.check(TokenType.LBRACE) || this.check(TokenType.LBRACKET)) {
|
|
792
|
+
pTarget = this.parseBindingPattern();
|
|
793
|
+
} else {
|
|
794
|
+
pTarget = this.parseIdentifier();
|
|
795
|
+
}
|
|
796
|
+
const p = this.parseValueParameter(pTarget, true, isRest);
|
|
797
|
+
if (dotSpan) {
|
|
798
|
+
p.span = { start: dotSpan.start, end: p.span.end };
|
|
799
|
+
}
|
|
800
|
+
params.push(p);
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
this.consume(TokenType.RPAREN, "Expected ')' after parameters");
|
|
804
|
+
this.validateValueParameters(params);
|
|
805
|
+
let returnType: TypeNode | undefined;
|
|
806
|
+
let arrowConsumed = false;
|
|
807
|
+
if (this.match(TokenType.COLON)) {
|
|
808
|
+
returnType = this.parseTypeNode();
|
|
809
|
+
} else if (
|
|
810
|
+
this.check(TokenType.ARROW) &&
|
|
811
|
+
this.peekAhead(1).type === TokenType.UPPER_IDENTIFIER &&
|
|
812
|
+
(this.peekAhead(2).type === TokenType.ARROW ||
|
|
813
|
+
this.peekAhead(2).type === TokenType.NEWLINE)
|
|
814
|
+
) {
|
|
815
|
+
this.advance(); // consume the arrow before the return type
|
|
816
|
+
arrowConsumed = true;
|
|
817
|
+
returnType = this.parseTypeNode();
|
|
818
|
+
this.match(TokenType.ARROW);
|
|
819
|
+
}
|
|
820
|
+
if (!arrowConsumed && !this.match(TokenType.ARROW)) {
|
|
821
|
+
throw new ParseError(
|
|
822
|
+
"Expected '=>' after parameters",
|
|
823
|
+
this.peek().span,
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
const body = this.parseFunctionBody(true);
|
|
827
|
+
return {
|
|
828
|
+
kind: "FunctionExpression",
|
|
829
|
+
params,
|
|
830
|
+
returnType,
|
|
831
|
+
body,
|
|
832
|
+
span: { start, end: body.span.end },
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
this.consume(TokenType.RPAREN, "Expected ')' after expression");
|
|
837
|
+
|
|
838
|
+
let singleReturnType: TypeNode | undefined;
|
|
839
|
+
let arrowConsumed = false;
|
|
840
|
+
if (this.match(TokenType.COLON)) {
|
|
841
|
+
singleReturnType = this.parseTypeNode();
|
|
842
|
+
} else if (
|
|
843
|
+
this.check(TokenType.ARROW) &&
|
|
844
|
+
this.peekAhead(1).type === TokenType.UPPER_IDENTIFIER &&
|
|
845
|
+
(this.peekAhead(2).type === TokenType.ARROW ||
|
|
846
|
+
this.peekAhead(2).type === TokenType.NEWLINE)
|
|
847
|
+
) {
|
|
848
|
+
this.advance(); // consume the arrow before the return type
|
|
849
|
+
arrowConsumed = true;
|
|
850
|
+
singleReturnType = this.parseTypeNode();
|
|
851
|
+
this.match(TokenType.ARROW);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
if (arrowConsumed || this.match(TokenType.ARROW)) {
|
|
855
|
+
const body = this.parseFunctionBody(true);
|
|
856
|
+
const paramTarget = this.expressionToBindingTarget(firstExpr);
|
|
857
|
+
if (!paramTarget)
|
|
858
|
+
throw new ParseError(
|
|
859
|
+
"Expected parameter name or pattern",
|
|
860
|
+
firstExpr.span,
|
|
861
|
+
);
|
|
862
|
+
return {
|
|
863
|
+
kind: "FunctionExpression",
|
|
864
|
+
params: [
|
|
865
|
+
{ kind: "Parameter", name: paramTarget, span: firstExpr.span },
|
|
866
|
+
],
|
|
867
|
+
returnType: singleReturnType,
|
|
868
|
+
body,
|
|
869
|
+
span: { start, end: body.span.end },
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
return firstExpr;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// 6. Zero-argument function: => body
|
|
877
|
+
if (this.match(TokenType.ARROW)) {
|
|
878
|
+
const start = this.previous().span.start;
|
|
879
|
+
const body = this.parseFunctionBody(true);
|
|
880
|
+
return {
|
|
881
|
+
kind: "FunctionExpression",
|
|
882
|
+
params: [],
|
|
883
|
+
body,
|
|
884
|
+
span: { start, end: body.span.end },
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// 7. Record Literal: { ... }
|
|
889
|
+
if (this.check(TokenType.LBRACE)) {
|
|
890
|
+
return this.parseRecordLiteral();
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
// 8. Array Literal: [ ... ]
|
|
894
|
+
if (this.check(TokenType.LBRACKET)) {
|
|
895
|
+
return this.parseArrayLiteral();
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// 9. Match / Catch Expression: match ... / catch ...
|
|
899
|
+
if (this.match(TokenType.MATCH)) {
|
|
900
|
+
return this.parseMatchExpression();
|
|
901
|
+
}
|
|
902
|
+
if (this.match(TokenType.CATCH)) {
|
|
903
|
+
return this.parseMatchExpression(false, true);
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
// 10. Effect Block: effect ...
|
|
907
|
+
if (this.match(TokenType.EFFECT)) {
|
|
908
|
+
return this.parseEffectBlock();
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// 10b. Par Block: par ...
|
|
912
|
+
if (this.match(TokenType.PAR)) {
|
|
913
|
+
return this.parseParBlock();
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// 11. JS Expression or bare 'js' pipeline stage
|
|
917
|
+
if (this.match(TokenType.JS)) {
|
|
918
|
+
const start = this.previous().span.start;
|
|
919
|
+
if (
|
|
920
|
+
this.isAtEnd() ||
|
|
921
|
+
this.check(TokenType.NEWLINE) ||
|
|
922
|
+
this.check(TokenType.EOF) ||
|
|
923
|
+
this.check(TokenType.DEDENT) ||
|
|
924
|
+
this.check(TokenType.RPAREN)
|
|
925
|
+
) {
|
|
926
|
+
return {
|
|
927
|
+
kind: "Identifier",
|
|
928
|
+
name: "js",
|
|
929
|
+
span: this.previous().span,
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
if (this.match(TokenType.DOT)) {
|
|
933
|
+
throw new ParseError(
|
|
934
|
+
"FunkScript has no 'js.try'; use 'js <expr>' (or '<- js <expr>') directly.",
|
|
935
|
+
this.previous().span,
|
|
936
|
+
);
|
|
937
|
+
}
|
|
938
|
+
const inner = this.parseExpression();
|
|
939
|
+
return {
|
|
940
|
+
kind: "JsExpression",
|
|
941
|
+
expression: inner,
|
|
942
|
+
span: { start, end: inner.span.end },
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// 12. TS escape hatch: ts { raw TypeScript expression }
|
|
947
|
+
if (this.match(TokenType.TS)) {
|
|
948
|
+
const start = this.previous().span.start;
|
|
949
|
+
const code = this.consumeTsCode();
|
|
950
|
+
return {
|
|
951
|
+
kind: "TsEscapeExpression",
|
|
952
|
+
code: code.value,
|
|
953
|
+
span: { start, end: code.span.end },
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
throw new ParseError(
|
|
958
|
+
`Unexpected token '${this.peek().value}' (${this.peek().type})`,
|
|
959
|
+
this.peek().span,
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
private parseRecordLiteral(): RecordExpression {
|
|
964
|
+
const start = this.consume(TokenType.LBRACE, "Expected '{'").span.start;
|
|
965
|
+
const entries: RecordEntry[] = [];
|
|
966
|
+
|
|
967
|
+
this.skipNewlines();
|
|
968
|
+
const hasIndent = this.match(TokenType.INDENT);
|
|
969
|
+
|
|
970
|
+
while (
|
|
971
|
+
!this.check(TokenType.RBRACE) &&
|
|
972
|
+
!this.check(TokenType.DEDENT) &&
|
|
973
|
+
!this.isAtEnd()
|
|
974
|
+
) {
|
|
975
|
+
this.skipNewlines();
|
|
976
|
+
if (this.check(TokenType.RBRACE) || this.check(TokenType.DEDENT)) break;
|
|
977
|
+
|
|
978
|
+
if (this.match(TokenType.DOTDOTDOT)) {
|
|
979
|
+
const start = this.previous().span.start;
|
|
980
|
+
const arg = this.parseExpression();
|
|
981
|
+
entries.push({
|
|
982
|
+
kind: "SpreadEntry",
|
|
983
|
+
argument: arg,
|
|
984
|
+
span: { start, end: arg.span.end },
|
|
985
|
+
});
|
|
986
|
+
} else {
|
|
987
|
+
const firstId: Identifier = this.parseRecordKeyIdentifier();
|
|
988
|
+
if (this.match(TokenType.DOT)) {
|
|
989
|
+
// Dot-path entry: address.city: "Paris"
|
|
990
|
+
const path: (Identifier | UpperIdentifier)[] = [firstId];
|
|
991
|
+
do {
|
|
992
|
+
path.push(this.parsePropertyIdentifier());
|
|
993
|
+
} while (this.match(TokenType.DOT));
|
|
994
|
+
|
|
995
|
+
this.consume(TokenType.COLON, "Expected ':' after dot-path");
|
|
996
|
+
const val = this.parseExpression();
|
|
997
|
+
entries.push({
|
|
998
|
+
kind: "DotPathEntry",
|
|
999
|
+
path,
|
|
1000
|
+
value: val,
|
|
1001
|
+
span: { start: firstId.span.start, end: val.span.end },
|
|
1002
|
+
});
|
|
1003
|
+
} else if (this.match(TokenType.COLON)) {
|
|
1004
|
+
const val = this.parseExpression();
|
|
1005
|
+
entries.push({
|
|
1006
|
+
kind: "FieldEntry",
|
|
1007
|
+
key: firstId,
|
|
1008
|
+
value: val,
|
|
1009
|
+
span: { start: firstId.span.start, end: val.span.end },
|
|
1010
|
+
});
|
|
1011
|
+
} else {
|
|
1012
|
+
// Shorthand { x }
|
|
1013
|
+
entries.push({
|
|
1014
|
+
kind: "ShorthandEntry",
|
|
1015
|
+
key: firstId,
|
|
1016
|
+
span: firstId.span,
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
this.match(TokenType.COMMA);
|
|
1022
|
+
this.skipNewlines();
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
if (hasIndent) {
|
|
1026
|
+
this.consume(TokenType.DEDENT, "Expected unindent in record literal");
|
|
1027
|
+
}
|
|
1028
|
+
this.skipNewlines();
|
|
1029
|
+
const end = this.consume(TokenType.RBRACE, "Expected '}'").span.end;
|
|
1030
|
+
|
|
1031
|
+
return {
|
|
1032
|
+
kind: "RecordExpression",
|
|
1033
|
+
entries,
|
|
1034
|
+
span: { start, end },
|
|
1035
|
+
};
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
private parseArrayLiteral(): ArrayExpression {
|
|
1039
|
+
const start = this.consume(TokenType.LBRACKET, "Expected '['").span.start;
|
|
1040
|
+
const elements: Expression[] = [];
|
|
1041
|
+
|
|
1042
|
+
this.skipNewlines();
|
|
1043
|
+
if (!this.check(TokenType.RBRACKET)) {
|
|
1044
|
+
do {
|
|
1045
|
+
this.skipNewlines();
|
|
1046
|
+
if (this.check(TokenType.RBRACKET)) break;
|
|
1047
|
+
if (this.match(TokenType.DOTDOTDOT)) {
|
|
1048
|
+
const dotSpan = this.previous().span;
|
|
1049
|
+
const element = this.parseExpression();
|
|
1050
|
+
elements.push({
|
|
1051
|
+
kind: "SpreadElement",
|
|
1052
|
+
argument: element,
|
|
1053
|
+
span: { start: dotSpan.start, end: element.span.end },
|
|
1054
|
+
});
|
|
1055
|
+
} else {
|
|
1056
|
+
elements.push(this.parseExpression());
|
|
1057
|
+
}
|
|
1058
|
+
} while (this.match(TokenType.COMMA) && !this.check(TokenType.RBRACKET));
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
this.skipNewlines();
|
|
1062
|
+
const end = this.consume(TokenType.RBRACKET, "Expected ']'").span.end;
|
|
1063
|
+
|
|
1064
|
+
return {
|
|
1065
|
+
kind: "ArrayExpression",
|
|
1066
|
+
elements,
|
|
1067
|
+
span: { start, end },
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// --- Match & Patterns ---
|
|
1072
|
+
|
|
1073
|
+
private tryParseTupleScrutinee(): Expression | undefined {
|
|
1074
|
+
if (!this.check(TokenType.LPAREN)) return undefined;
|
|
1075
|
+
const saved = this.current;
|
|
1076
|
+
const start = this.advance().span.start;
|
|
1077
|
+
if (this.check(TokenType.RPAREN)) {
|
|
1078
|
+
this.current = saved;
|
|
1079
|
+
return undefined;
|
|
1080
|
+
}
|
|
1081
|
+
this.skipNewlines();
|
|
1082
|
+
const first = this.parseExpression();
|
|
1083
|
+
this.skipNewlines();
|
|
1084
|
+
if (!this.match(TokenType.COMMA)) {
|
|
1085
|
+
this.current = saved;
|
|
1086
|
+
return undefined;
|
|
1087
|
+
}
|
|
1088
|
+
const elements: Expression[] = [first];
|
|
1089
|
+
this.skipNewlines();
|
|
1090
|
+
while (!this.check(TokenType.RPAREN) && !this.isAtEnd()) {
|
|
1091
|
+
elements.push(this.parseExpression());
|
|
1092
|
+
this.skipNewlines();
|
|
1093
|
+
if (!this.match(TokenType.COMMA)) break;
|
|
1094
|
+
this.skipNewlines();
|
|
1095
|
+
}
|
|
1096
|
+
const end = this.consume(
|
|
1097
|
+
TokenType.RPAREN,
|
|
1098
|
+
"Expected ')' after tuple match expression",
|
|
1099
|
+
).span.end;
|
|
1100
|
+
return {
|
|
1101
|
+
kind: "ArrayExpression",
|
|
1102
|
+
elements,
|
|
1103
|
+
span: { start, end },
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
private parseMatchExpression(
|
|
1108
|
+
isPipeline = false,
|
|
1109
|
+
isCatch = false,
|
|
1110
|
+
): MatchExpression {
|
|
1111
|
+
const start = this.previous().span.start;
|
|
1112
|
+
let scrutinee: Expression | undefined;
|
|
1113
|
+
|
|
1114
|
+
// Check if scrutinee is present or if it's a subjectless boolean match
|
|
1115
|
+
if (
|
|
1116
|
+
!isPipeline &&
|
|
1117
|
+
!this.check(TokenType.BAR) &&
|
|
1118
|
+
!this.check(TokenType.NEWLINE) &&
|
|
1119
|
+
!this.check(TokenType.INDENT)
|
|
1120
|
+
) {
|
|
1121
|
+
scrutinee = this.tryParseTupleScrutinee() ?? this.parseExpression();
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
if (isCatch && !isPipeline && scrutinee === undefined) {
|
|
1125
|
+
throw new ParseError(
|
|
1126
|
+
"Expected Effect expression after 'catch'",
|
|
1127
|
+
this.peek().span,
|
|
1128
|
+
);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
this.skipNewlines();
|
|
1132
|
+
const hasIndent = this.match(TokenType.INDENT);
|
|
1133
|
+
const arms: MatchArm[] = [];
|
|
1134
|
+
const seenCatchTags = new Set<string>();
|
|
1135
|
+
|
|
1136
|
+
const extractCatchPatterns = (pat: Pattern): ConstructorPattern[] => {
|
|
1137
|
+
if (pat.kind === "OrPattern") {
|
|
1138
|
+
return pat.patterns.flatMap(extractCatchPatterns);
|
|
1139
|
+
}
|
|
1140
|
+
if (
|
|
1141
|
+
pat.kind !== "ConstructorPattern" ||
|
|
1142
|
+
pat.args.length > 1 ||
|
|
1143
|
+
(pat.args.length === 1 &&
|
|
1144
|
+
pat.args[0].kind !== "VariablePattern" &&
|
|
1145
|
+
pat.args[0].kind !== "WildcardPattern")
|
|
1146
|
+
) {
|
|
1147
|
+
throw new ParseError(
|
|
1148
|
+
"Catch arms require a tag, optionally followed by a single error binding or '_'; guards are not supported",
|
|
1149
|
+
pat.span,
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
return [pat];
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
const isSubjectless = !isPipeline && scrutinee === undefined;
|
|
1156
|
+
while (this.match(TokenType.BAR)) {
|
|
1157
|
+
const armStart = this.previous().span.start;
|
|
1158
|
+
let pattern: Pattern;
|
|
1159
|
+
|
|
1160
|
+
if (isSubjectless) {
|
|
1161
|
+
if (this.match(TokenType.UNDERSCORE)) {
|
|
1162
|
+
pattern = { kind: "WildcardPattern", span: this.previous().span };
|
|
1163
|
+
} else {
|
|
1164
|
+
const condExpr = this.parseExpression();
|
|
1165
|
+
pattern = {
|
|
1166
|
+
kind: "LiteralPattern",
|
|
1167
|
+
literal: {
|
|
1168
|
+
kind: "BooleanLiteral",
|
|
1169
|
+
value: true,
|
|
1170
|
+
rawExpr: condExpr,
|
|
1171
|
+
span: condExpr.span,
|
|
1172
|
+
},
|
|
1173
|
+
span: condExpr.span,
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
} else {
|
|
1177
|
+
pattern = this.parsePattern();
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
let guard: Expression | undefined;
|
|
1181
|
+
|
|
1182
|
+
if (this.match(TokenType.WHEN)) {
|
|
1183
|
+
guard = this.parseExpression();
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
if (isCatch) {
|
|
1187
|
+
if (guard) {
|
|
1188
|
+
throw new ParseError(
|
|
1189
|
+
"Catch arms require a tag, optionally followed by a single error binding or '_'; guards are not supported",
|
|
1190
|
+
guard.span,
|
|
1191
|
+
);
|
|
1192
|
+
}
|
|
1193
|
+
const catchPatterns = extractCatchPatterns(pattern);
|
|
1194
|
+
for (const catchPat of catchPatterns) {
|
|
1195
|
+
const tagName = catchPat.constructorName.name;
|
|
1196
|
+
if (seenCatchTags.has(tagName)) {
|
|
1197
|
+
throw new ParseError("Duplicate tag in catch arms", catchPat.span);
|
|
1198
|
+
}
|
|
1199
|
+
seenCatchTags.add(tagName);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
if (!this.match(TokenType.ARROW)) {
|
|
1204
|
+
throw new ParseError("Expected '=>' in match arm", this.peek().span);
|
|
1205
|
+
}
|
|
1206
|
+
const body = this.parseFunctionBody();
|
|
1207
|
+
|
|
1208
|
+
arms.push({
|
|
1209
|
+
kind: "MatchArm",
|
|
1210
|
+
pattern,
|
|
1211
|
+
guard,
|
|
1212
|
+
body,
|
|
1213
|
+
span: { start: armStart, end: body.span.end },
|
|
1214
|
+
});
|
|
1215
|
+
|
|
1216
|
+
this.skipNewlines();
|
|
1217
|
+
if (!this.check(TokenType.BAR)) break;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
if (hasIndent) {
|
|
1221
|
+
this.consume(TokenType.DEDENT, "Expected unindent after match arms");
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
if (isCatch && arms.length === 0) {
|
|
1225
|
+
throw new ParseError("Expected at least one catch arm", this.peek().span);
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
return {
|
|
1229
|
+
kind: "MatchExpression",
|
|
1230
|
+
scrutinee,
|
|
1231
|
+
isPipeline: isPipeline ? true : undefined,
|
|
1232
|
+
isCatch: isCatch ? true : undefined,
|
|
1233
|
+
arms,
|
|
1234
|
+
span: { start, end: arms[arms.length - 1]?.span.end || start },
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
public parsePattern(): Pattern {
|
|
1239
|
+
return parsePatternImpl(this);
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
// --- Statements & Blocks ---
|
|
1243
|
+
|
|
1244
|
+
public parseEffectBlock(): EffectBlockExpression {
|
|
1245
|
+
return parseEffectBlockImpl(this);
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
public parseParBlock(): ParBlockExpression {
|
|
1249
|
+
return parseParBlockImpl(this);
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
public isBraceBlock(): boolean {
|
|
1253
|
+
return isBraceBlockImpl(this);
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
public isAssignmentStart(): boolean {
|
|
1257
|
+
return isAssignmentStartImpl(this);
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
public parseAssignmentTarget():
|
|
1261
|
+
Identifier | DotPathExpression | IndexExpression {
|
|
1262
|
+
return parseAssignmentTargetImpl(this);
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
public collectPatternVariables(pat: Pattern | BindingTarget): string[] {
|
|
1266
|
+
return collectPatternVariablesImpl(pat);
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
public isDestructuringBindingStart(): boolean {
|
|
1270
|
+
return isDestructuringBindingStartImpl(this);
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
public isDestructuringEffectBindStart(): boolean {
|
|
1274
|
+
return isDestructuringEffectBindStartImpl(this);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
public parseFunctionBody(requireExplicitReturn = false): FunctionBody {
|
|
1278
|
+
return parseFunctionBodyImpl(this, requireExplicitReturn);
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
public parseBraceBlock(requireExplicitReturn = false): BlockStatement {
|
|
1282
|
+
return parseBraceBlockImpl(this, requireExplicitReturn);
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
public parseIndentedBlock(requireExplicitReturn = false): BlockStatement {
|
|
1286
|
+
return parseIndentedBlockImpl(this, requireExplicitReturn);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
// --- Types ---
|
|
1290
|
+
|
|
1291
|
+
public parseTypeNode(): TypeNode {
|
|
1292
|
+
return parseTypeNode(this);
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
public parseUnionType(): TypeNode {
|
|
1296
|
+
return parseUnionType(this);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
public parseIntersectionType(): TypeNode {
|
|
1300
|
+
return parseIntersectionType(this);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
public parseFunctionTypeNode(): TypeNode {
|
|
1304
|
+
return parseFunctionTypeNode(this);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
public parsePrimaryType(): TypeNode {
|
|
1308
|
+
return parsePrimaryType(this);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
public parseEffectTypeNode(): EffectTypeNode {
|
|
1312
|
+
return parseEffectTypeNode(this);
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
public parseGenericFunctionExpression(): FunctionExpression {
|
|
1316
|
+
return parseGenericFunctionExpression(this);
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
public isGenericCallableStart(): boolean {
|
|
1320
|
+
return isGenericCallableStart(this);
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
public parseTypeParameters(): TypeParameter[] {
|
|
1324
|
+
return parseTypeParameters(this);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// --- JSX Parsing ---
|
|
1328
|
+
|
|
1329
|
+
public parseJsxElement(): JSXElement | JSXSelfClosingElement {
|
|
1330
|
+
return parseJsxElement(this);
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// --- Helpers ---
|
|
1334
|
+
|
|
1335
|
+
public parseIdentifier(): Identifier {
|
|
1336
|
+
const tok = this.consume(
|
|
1337
|
+
TokenType.IDENTIFIER,
|
|
1338
|
+
"Expected lowercase identifier",
|
|
1339
|
+
);
|
|
1340
|
+
return { kind: "Identifier", name: tok.value, span: tok.span };
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
public parseUpperIdentifier(): UpperIdentifier {
|
|
1344
|
+
const tok = this.consume(
|
|
1345
|
+
TokenType.UPPER_IDENTIFIER,
|
|
1346
|
+
"Expected UpperCamel identifier",
|
|
1347
|
+
);
|
|
1348
|
+
return { kind: "UpperIdentifier", name: tok.value, span: tok.span };
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
public parseAnyIdentifier(): Identifier | UpperIdentifier {
|
|
1352
|
+
if (this.check(TokenType.ERROR)) {
|
|
1353
|
+
const token = this.advance();
|
|
1354
|
+
return { kind: "Identifier", name: token.value, span: token.span };
|
|
1355
|
+
}
|
|
1356
|
+
if (this.check(TokenType.UPPER_IDENTIFIER))
|
|
1357
|
+
return this.parseUpperIdentifier();
|
|
1358
|
+
return this.parseIdentifier();
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
public parsePropertyIdentifier(): Identifier | UpperIdentifier {
|
|
1362
|
+
if (this.check(TokenType.ERROR)) {
|
|
1363
|
+
const token = this.advance();
|
|
1364
|
+
return { kind: "Identifier", name: token.value, span: token.span };
|
|
1365
|
+
}
|
|
1366
|
+
if (this.check(TokenType.UPPER_IDENTIFIER)) {
|
|
1367
|
+
return this.parseUpperIdentifier();
|
|
1368
|
+
}
|
|
1369
|
+
if (this.check(TokenType.IDENTIFIER)) {
|
|
1370
|
+
return this.parseIdentifier();
|
|
1371
|
+
}
|
|
1372
|
+
const peek = this.peek();
|
|
1373
|
+
if (Object.values(KEYWORDS).includes(peek.type)) {
|
|
1374
|
+
const tok = this.advance();
|
|
1375
|
+
return { kind: "Identifier", name: tok.value, span: tok.span };
|
|
1376
|
+
}
|
|
1377
|
+
return this.parseIdentifier();
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
public parseRecordKeyIdentifier(): Identifier {
|
|
1381
|
+
if (this.match(TokenType.STRING)) {
|
|
1382
|
+
const tok = this.previous();
|
|
1383
|
+
return { kind: "Identifier", name: tok.value, span: tok.span };
|
|
1384
|
+
}
|
|
1385
|
+
const prop = this.parsePropertyIdentifier();
|
|
1386
|
+
return { kind: "Identifier", name: prop.name, span: prop.span };
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
public parseStringLiteral(): StringLiteral {
|
|
1390
|
+
const start = this.peek().span.start;
|
|
1391
|
+
const parts: StringPart[] = [];
|
|
1392
|
+
|
|
1393
|
+
if (this.match(TokenType.STRING)) {
|
|
1394
|
+
return {
|
|
1395
|
+
kind: "StringLiteral",
|
|
1396
|
+
parts: [{ kind: "StringRawPart", value: this.previous().value }],
|
|
1397
|
+
raw: `"${this.previous().value}"`,
|
|
1398
|
+
span: this.previous().span,
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
while (
|
|
1403
|
+
this.check(TokenType.STRING_PART) ||
|
|
1404
|
+
this.check(TokenType.INTERPOLATION_START)
|
|
1405
|
+
) {
|
|
1406
|
+
if (this.match(TokenType.STRING_PART)) {
|
|
1407
|
+
parts.push({ kind: "StringRawPart", value: this.previous().value });
|
|
1408
|
+
} else if (this.match(TokenType.INTERPOLATION_START)) {
|
|
1409
|
+
const expr = this.parseExpression();
|
|
1410
|
+
this.consume(
|
|
1411
|
+
TokenType.INTERPOLATION_END,
|
|
1412
|
+
"Expected '}' to close interpolation",
|
|
1413
|
+
);
|
|
1414
|
+
parts.push({ kind: "StringInterpolationPart", expression: expr });
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
return {
|
|
1419
|
+
kind: "StringLiteral",
|
|
1420
|
+
parts,
|
|
1421
|
+
raw: "",
|
|
1422
|
+
span: { start, end: this.previous().span.end },
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
private parseTemplateLiteral(): TemplateLiteral {
|
|
1427
|
+
const start = this.peek().span.start;
|
|
1428
|
+
const parts: StringPart[] = [];
|
|
1429
|
+
|
|
1430
|
+
if (this.match(TokenType.TEMPLATE_STRING)) {
|
|
1431
|
+
return {
|
|
1432
|
+
kind: "TemplateLiteral",
|
|
1433
|
+
parts: [{ kind: "StringRawPart", value: this.previous().value }],
|
|
1434
|
+
raw: `\`${this.previous().value}\``,
|
|
1435
|
+
span: this.previous().span,
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
while (
|
|
1440
|
+
this.check(TokenType.TEMPLATE_PART) ||
|
|
1441
|
+
this.check(TokenType.INTERPOLATION_START)
|
|
1442
|
+
) {
|
|
1443
|
+
if (this.match(TokenType.TEMPLATE_PART)) {
|
|
1444
|
+
parts.push({ kind: "StringRawPart", value: this.previous().value });
|
|
1445
|
+
} else if (this.match(TokenType.INTERPOLATION_START)) {
|
|
1446
|
+
const expr = this.parseExpression();
|
|
1447
|
+
this.consume(
|
|
1448
|
+
TokenType.INTERPOLATION_END,
|
|
1449
|
+
"Expected '}' to close interpolation",
|
|
1450
|
+
);
|
|
1451
|
+
parts.push({ kind: "StringInterpolationPart", expression: expr });
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
return {
|
|
1456
|
+
kind: "TemplateLiteral",
|
|
1457
|
+
parts,
|
|
1458
|
+
raw: "",
|
|
1459
|
+
span: { start, end: this.previous().span.end },
|
|
1460
|
+
};
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
private isTypeArgumentListBeforeTemplate(): boolean {
|
|
1464
|
+
if (!this.check(TokenType.LT)) return false;
|
|
1465
|
+
let angleDepth = 1;
|
|
1466
|
+
for (let i = 1; i < 512; i++) {
|
|
1467
|
+
const token = this.peekAhead(i);
|
|
1468
|
+
if (token.type === TokenType.EOF || token.type === TokenType.NEWLINE)
|
|
1469
|
+
return false;
|
|
1470
|
+
if (token.type === TokenType.LT) {
|
|
1471
|
+
angleDepth++;
|
|
1472
|
+
} else if (token.type === TokenType.GT) {
|
|
1473
|
+
angleDepth--;
|
|
1474
|
+
if (angleDepth === 0) {
|
|
1475
|
+
const next = this.peekAhead(i + 1);
|
|
1476
|
+
return (
|
|
1477
|
+
next.type === TokenType.TEMPLATE_STRING ||
|
|
1478
|
+
next.type === TokenType.TEMPLATE_PART
|
|
1479
|
+
);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
return false;
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
private parseTypeArguments(): TypeNode[] {
|
|
1487
|
+
this.consume(TokenType.LT, "Expected '<'");
|
|
1488
|
+
const args: TypeNode[] = [];
|
|
1489
|
+
do {
|
|
1490
|
+
args.push(this.parseTypeNode());
|
|
1491
|
+
} while (this.match(TokenType.COMMA) && !this.check(TokenType.GT));
|
|
1492
|
+
this.consume(TokenType.GT, "Expected '>'");
|
|
1493
|
+
return args;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
public skipNewlines(): void {
|
|
1497
|
+
while (this.match(TokenType.NEWLINE)) {}
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
public consumeNewlineOrEof(message = "Expected newline"): void {
|
|
1501
|
+
if (
|
|
1502
|
+
this.isAtEnd() ||
|
|
1503
|
+
this.check(TokenType.DEDENT) ||
|
|
1504
|
+
this.check(TokenType.RBRACE) ||
|
|
1505
|
+
this.previous().type === TokenType.DEDENT ||
|
|
1506
|
+
this.previous().type === TokenType.RBRACE ||
|
|
1507
|
+
this.previous().type === TokenType.NEWLINE
|
|
1508
|
+
) {
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
if (this.previous().span.end.line < this.peek().span.start.line) return;
|
|
1512
|
+
if (this.match(TokenType.NEWLINE)) {
|
|
1513
|
+
this.skipNewlines();
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
throw new ParseError(
|
|
1517
|
+
`${message} (got '${this.peek().value}', expected NEWLINE)`,
|
|
1518
|
+
this.peek().span,
|
|
1519
|
+
);
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
public match(...types: TokenType[]): boolean {
|
|
1523
|
+
for (const type of types) {
|
|
1524
|
+
if (this.check(type)) {
|
|
1525
|
+
this.advance();
|
|
1526
|
+
return true;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
return false;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
public check(type: TokenType): boolean {
|
|
1533
|
+
if (this.isAtEnd()) return type === TokenType.EOF;
|
|
1534
|
+
return this.peek().type === type;
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
public advance(): Token {
|
|
1538
|
+
if (!this.isAtEnd()) this.current++;
|
|
1539
|
+
return this.previous();
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
public isAtEnd(): boolean {
|
|
1543
|
+
return this.peek().type === TokenType.EOF;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
public peek(): Token {
|
|
1547
|
+
return this.tokens[this.current] || this.tokens[this.tokens.length - 1];
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
public peekAhead(n: number): Token {
|
|
1551
|
+
return this.tokens[this.current + n] || this.tokens[this.tokens.length - 1];
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
public previous(): Token {
|
|
1555
|
+
return this.tokens[this.current - 1];
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
public consume(type: TokenType, message: string): Token {
|
|
1559
|
+
if (this.check(type)) return this.advance();
|
|
1560
|
+
throw new ParseError(
|
|
1561
|
+
`${message} (got '${this.peek().value}', expected ${type})`,
|
|
1562
|
+
this.peek().span,
|
|
1563
|
+
);
|
|
1564
|
+
}
|
|
1565
|
+
}
|