Skip to content

Parser: closures (|x| expr, move) #61

Description

@StreamDemon

Summary

Implement closure parsing. |x| x + 1 currently fails ("expected expression"); move closures are unsupported.

Part of the v0.6.x parser-completeness work (see crates/AGENTS.md "Implemented subset"). Surfaced during PR #57 verification.

Spec

  • §7 closures / §16 closure_expr. Capture modes (Fn/FnMut/FnOnce) are inferred, not syntax; move is already a reserved keyword.

Scope

  • |params| expr and |params| { block }, with typed params |x: T| and optional -> T return type.
  • move |…| ….
  • Disambiguate a closure-starting | from bitwise-or | / logical-or || (the lexer emits Pipe / PipePipe): a | in expression-prefix position starts a closure; elsewhere it is an operator. Handle the empty parameter list || expr.
  • AST node; corpus fixture; unit tests incl. zero-arg and typed-param closures.

Notes

The | / || disambiguation in prefix is the main subtlety. A bare || in prefix position is a zero-arg closure, not logical-or.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions