Skip to content

[#336] Replace closure and function type syntax with fn() unified syntax#339

Merged
milkyskies merged 2 commits intomainfrom
feature/#336.fn-closure-syntax
Mar 17, 2026
Merged

[#336] Replace closure and function type syntax with fn() unified syntax#339
milkyskies merged 2 commits intomainfrom
feature/#336.fn-closure-syntax

Conversation

@milkyskies
Copy link
Owner

closes #336

Summary

  • Closures: |x| exprfn(x) expr, || exprfn() expr
  • Async closures: async || exprasync fn() expr
  • Function types: (T) -> Rfn(T) -> R, () -> ()fn() -> ()
  • One keyword (fn) for declarations, types, and closures — zero ambiguity
  • || is now only boolean OR, | is now only union types

Changes

Compiler (parser, lowering, formatter):

  • Parser disambiguates fn( (lambda) vs fn name( (declaration) in expression context
  • Removed is_function_type / scan_for_rparen_followed_by heuristics — fn keyword is unambiguous
  • Updated formatter to emit fn(...) syntax
  • Updated lowering to find lambda body after ) instead of |

All .fl files: fixtures, todo-app, store example — 25 files updated

Docs: design.md, llms.txt, 13 site pages

Syntax highlighting: tree-sitter grammar, TextMate, Neovim queries, VSCode snippet

Test plan

  • All 888 tests pass (846 lib + 26 snapshot codegen + 16 snapshot errors)
  • cargo fmt clean
  • cargo clippy -- -D warnings clean
  • RUSTFLAGS="-D warnings" cargo test clean
  • Verify store and todo-app render correctly in browser
  • Verify VSCode syntax highlighting works

🤖 Generated with Claude Code

milkyskies and others added 2 commits March 17, 2026 18:59
Unified closure and function type syntax under the fn keyword:
- Closures: |x| expr -> fn(x) expr, || expr -> fn() expr
- Async closures: async |x| expr -> async fn(x) expr
- Function types: (T) -> R -> fn(T) -> R, () -> () -> fn() -> ()

Parser: fn( in expression context is a lambda, fn name( is a declaration.
Removed is_function_type/scan_for_rparen_followed_by heuristics since
fn keyword now unambiguously starts function types.

Updated all .fl files, test fixtures, example apps, inline test strings,
formatter, and lowering to use new syntax.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- design.md: all syntax tables, examples, token table, banned tokens
- llms.txt: closure syntax, function types, compilation examples
- site docs: 13 pages updated (guide, reference, tooling)
- tree-sitter: grammar.js pipe_lambda and function_type rules
- TextMate: lambda patterns updated for fn() syntax
- VSCode: added closure snippet
- Neovim: highlights synced with tree-sitter
- Lexer: VerticalBar doc comment no longer mentions lambda delimiters

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@milkyskies milkyskies merged commit 102f87c into main Mar 17, 2026
2 checks passed
@milkyskies milkyskies deleted the feature/#336.fn-closure-syntax branch March 17, 2026 10:25
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.

Replace closure and function type syntax with fn() unified syntax

1 participant