Skip to content

feat: unify expressions and simplify record syntax - #54

Merged
nerdalytics merged 4 commits into
mainfrom
feat/expression-unification
Jan 21, 2026
Merged

feat: unify expressions and simplify record syntax#54
nerdalytics merged 4 commits into
mainfrom
feat/expression-unification

Conversation

@nerdalytics

Copy link
Copy Markdown
Owner

Summary

Unifies expression handling by enabling multi-line lambda bodies (Expression Sequences) and simplifies record type declarations by removing the unnecessary type keyword. This brings the language closer to a uniform expression-based structure.

Changes

  • Grammar:
    • Removed type keyword from record declarations (e.g., type PointPoint).
    • Added LambdaBlock and LambdaBlockLine rules for multi-line lambda bodies.
  • Parser:
    • Added semantic actions for ExpressionSequence to support interleaved statements and expressions in lambda bodies.
    • Added support for optional type annotations in function bindings.
  • Checker:
    • Implemented ExpressionSequence checking, allowing local bindings and side-effects before the final return expression in lambdas.
  • Codegen:
    • Improved local variable collection to correctly allocate bindings defined within function bodies.
  • Refactor:
    • Updated all record examples (examples/records/*.tw) and related tests to use the new concise record syntax.

Test plan

  • mise run test passes (all package tests).
  • All examples/records/*.tw compile successfully with the new syntax.
  • Multi-line lambda bodies with local bindings are correctly compiled and executed.

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>
@nerdalytics
nerdalytics merged commit 587ecab into main Jan 21, 2026
6 checks passed
@nerdalytics
nerdalytics deleted the feat/expression-unification branch January 21, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant