feat: parser slice 14 — match expression (MatchExpr, MatchArm, when guard) #3
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/003-feat-parser-slice-14-match-expression-matchexp"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
feat: parser slice 14 — match expression (MatchExpr, MatchArm, when guard)
Along the way:
Touches 60 files:
docs/README.md,docs/assert.md,docs/errors.md,docs/impl/02-lexer.md,docs/impl/03-parser.md,docs/impl/04-name-resolution.mdand 54 more.Happy with this. I ran the suite against the branch and it is green,
src/rust/crates/ck_parser/src/tests/lambda.rsincluded.@ -0,0 +148,4 @@}}SyntaxKind::Eof => return false,_ => {}The catch-all arm means a variant added later compiles and lands here without a word. Can the match on
_name every variant so the compiler tells us?@ -100,0 +264,4 @@self.expect(SyntaxKind::LParen, "E0064", "expected `(` after `assert`");self.parse_expr(0);self.expect(SyntaxKind::RParen, "E0065", "expected `)` to close assert");self.expect(The expect message on
expectis the only thing a user sees if this fires. Does it say what they should do, or only what we assumed?, at src/rust/crates/ck_parser/src/stmt.rs:267.@ -0,0 +103,4 @@}#[test]fn lambda_body_is_full_expression() {lambda_body_is_full_expressionreads, decides and writes in one function. The deciding part is the piece I would want to test on its own. Worth splitting?Split. The decision in
lambda_body_is_full_expressionis a pure function now, with its own tests insrc/rust/crates/ck_parser/src/tests/lambda.rs.It said what I assumed. Reworded in
src/rust/crates/ck_parser/src/stmt.rsso it names the input that broke it, which is what the bug report will need, at src/rust/crates/ck_parser/src/stmt.rs:267.Named them all. A new variant is a compile error in
src/rust/crates/ck_parser/src/lambda.rsnow, which is where we want to find out.`match` is wired in as a Pratt primary so it composes with the slice-10 binary / postfix operators for free. Scrutinee and arm body use parse_expr(0); arm patterns reuse slice 13; the `when` guard finally gets a caller. Three diagnostics (E0061..E0063) for missing `{`, `}`, and `->`. Slice-13 type-assert greedy `:` folds into the pattern before the arm's `->`, so `s: String -> ...` works without extra logic.Closes the parser dependency cascade locked 2026-05-21. Adds the four keyword-introduced statement forms to `parse_block_body` ahead of the speculative expression parse via a `try_parse_stmt_keyword` dispatch: - `CatchStmt ::= catch ( Pattern ) Block` (binder reuses slice-13 patterns; `e: Err<T>` parses as `TypeAssertPattern` for free) - `DeferStmt ::= defer Expr ;` (multi-stmt body via the slice-11 block-as-primary form: `defer { ... };`) - `ReturnStmt ::= return Expr? ;` (bare `return;` is the optional-expression form) - `AssertStmt ::= assert ( Expr ) ;` (mandatory parens; hint slot / narrowing / soft-vs-hard deferred to later stages) Five new diagnostics (E0064..E0068) for the slot-specific cases; `;`-terminator codes (E0055) and pattern/expr codes (E0048, E0056) are reused unchanged. `program_basic.cktest` and `program_record.cktest` fixtures flip from `Error+E0048` on `return ...` to a real `ReturnStmt` node. Doc lock-ins that gated this slice (design questions resolved 2026-05-22): - `assert.md` — recognized predicate set, release-mode strip, two-form syntax, placement rules. - `errors.md` — catch binder shape; defer-on-every-exit semantics. - `syntax.md` — statement grammar with all five forms. - `principles.md` — Go-speed reframed as the north star (aspiration, not gate) + single-pass parser as the front-end's compile-speed commitment. - `impl/README.md` — single-pass-parser architectural lock. - `meta-substrate.md` — `AssertEvaluated` correctly `—` in release (asserts are stripped, emission site does not exist). - `principles.md` + `04-name-resolution.md` + `open-questions.md` — `comptime` formally dropped; `const` evaluation rules carry the surviving piece.