feat: unify expressions and simplify record syntax - #54
Merged
Conversation
Signed-off-by: nerdalytics <97166791+nerdalytics@users.noreply.github.com>
Add LambdaBlock and LambdaBlockLine rules to support multi-line lambda bodies with expression sequences. This enables: - Nested bindings inside functions - Forward declarations inside function bodies - Multiple expressions where last one is the return value Part of expression unification work.
Add semantic actions for TypeAlias and expression sequence parsing: - TypeAlias emits NodeKind.TypeAlias with type annotation child - LambdaBlock emits NodeKind.ExpressionSequence for multi-line bodies - LambdaBlockLine routes to appropriate emitter based on content type Use Set lookup for block expression routing to reduce cognitive complexity. Part of expression unification work.
- Grammar: Remove 'type' keyword from record declarations. Records are now declared using just the capitalized name (e.g., 'Point' instead of 'type Point'). - Checker: Implement ExpressionSequence checking for multi-line lambda bodies, allowing bindings and statements before the final return expression. - Codegen: Correctly collect and allocate local variables for bindings defined within function bodies. - Parser: Add support for optional type annotations in function bindings. - Refactor: Update all record examples and tests to use the new concise syntax. Signed-off-by: nerdalytics <97166791+nerdalytics@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Unifies expression handling by enabling multi-line lambda bodies (Expression Sequences) and simplifies record type declarations by removing the unnecessary
typekeyword. This brings the language closer to a uniform expression-based structure.Changes
typekeyword from record declarations (e.g.,type Point→Point).LambdaBlockandLambdaBlockLinerules for multi-line lambda bodies.ExpressionSequenceto support interleaved statements and expressions in lambda bodies.ExpressionSequencechecking, allowing local bindings and side-effects before the final return expression in lambdas.examples/records/*.tw) and related tests to use the new concise record syntax.Test plan
mise run testpasses (all package tests).examples/records/*.twcompile successfully with the new syntax.