ocaml: phase 1+3 record patterns { f = pat } (+4 tests, 386 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 48s
Parser: { f1 = pat; f2 = pat; ... } in pattern position emits
(:precord (FIELDNAME PAT)...). Mixed with the existing { in
expression position via the at-pattern-atom? whitelist.
Eval: :precord matches against a dict; required fields must be present
and each pat must match the field's value. Can mix literal+var:
'match { x = 1; y = y } with | { x = 1; y = y } -> y' matches only
when x is 1.
This commit is contained in:
@@ -134,13 +134,12 @@ SX CEK evaluator (both JS and OCaml hosts)
|
||||
`type`/`module`/`exception`/`open`/`include` decls, `try`/`with`,
|
||||
`function`, record literals/updates, field access, `and` mutually-recursive
|
||||
bindings.)_
|
||||
- [~] **Patterns:** constructor (nullary + with args, incl. flattened tuple
|
||||
args `Pair (a, b)` → `(:pcon "Pair" PA PB)`), literal (int/string/char/
|
||||
bool/unit), variable, wildcard `_`, tuple, list cons `::`, list
|
||||
literal, `as` binding (`pat as name`). Match clauses support `when`
|
||||
guard via `(:case-when PAT GUARD BODY)`. _(Pending: record patterns,
|
||||
or-pattern `P1 | P2` — ambiguous with clause separator without
|
||||
lookahead.)_
|
||||
- [x] **Patterns:** constructor (nullary + with args, incl. flattened tuple
|
||||
args), literal (int/string/char/bool/unit), variable, wildcard `_`,
|
||||
tuple, list cons `::`, list literal, record `{ f = pat; … }`,
|
||||
`as` binding. Match clauses support `when` guard via
|
||||
`(:case-when PAT GUARD BODY)`. _(Pending: or-pattern `P1 | P2` —
|
||||
ambiguous with clause separator without lookahead.)_
|
||||
- [ ] OCaml is **not** indentation-sensitive — no layout algorithm needed.
|
||||
- [ ] Tests in `lib/ocaml/tests/parse.sx` — 50+ round-trip parse tests.
|
||||
|
||||
@@ -377,6 +376,12 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
|
||||
|
||||
_Newest first._
|
||||
|
||||
- 2026-05-08 Phase 1+3 — record patterns `{ f = pat; … }` (+4 tests,
|
||||
386 total). Parser adds `(:precord (FIELD PAT) …)` alongside
|
||||
the existing record-literal `{` handling. Eval matches against
|
||||
dicts: required fields must be present and each pat must match the
|
||||
value. Can mix with literals: `{ x = 1; y = y }` matches only when
|
||||
x is 1.
|
||||
- 2026-05-08 Phase 5.1 — expr_eval.ml baseline (9/9 pass). A tiny
|
||||
arithmetic-expression evaluator using ADT (`type expr = Lit | Add |
|
||||
Mul | Neg`) + recursive eval + pattern match — exercises the full
|
||||
|
||||
Reference in New Issue
Block a user