Skip to content

Parser: match expression parsing (§5.2) #59

Description

@StreamDemon

Summary

Implement match expression parsing. The match keyword lexes but has no parse production today; match x { 1 => 2, _ => 3 } fails with "expected expression".

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

Spec

  • §5.2 Match (exhaustive pattern matching); §16 match_expr / match_arm / pattern productions.
  • The struct-literal block-head restriction applies to the scrutinee (§5.2, §16 side condition). The cond_expr helper added in PR Start lexer parser compiler bootstrap #57 already models this — reuse it for the scrutinee.

Scope

  • Parse match scrutinee { pat => expr, ... }, scrutinee under the block-head restriction.
  • Patterns: literals, paths/variants, tuple/struct destructuring, bindings, _ wildcard, .. rest, | or-patterns, and if guards (§5.2, §3.7).
  • AST nodes for Match and MatchArm.
  • Corpus fixture derived from the §5.2 examples (destructuring + guards).
  • Unit tests incl. the scrutinee restriction (parenthesized struct-literal scrutinee accepted).

Notes

Patterns are a sizable sub-grammar shared with while let / for (see the loop-constructs issue). Implement pattern parsing once and reuse. If it balloons, land literal/variant/wildcard patterns first and split the richer patterns into a follow-up.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions