ocaml: phase 1+3 or-patterns (P1 | P2 | ...) parens-only (+5 tests, 394 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 41s

Parser: when | follows a pattern inside parens, build (:por ALT1 ALT2
...). Eval: try alternatives, succeed on first match. Top-level |
remains the clause separator — parens-only avoids ambiguity without
lookahead.

Examples now work:
  match n with | (1 | 2 | 3) -> 100 | _ -> 0
  match c with | (Red | Green) -> 1 | Blue -> 2
This commit is contained in:
2026-05-08 15:22:34 +00:00
parent ad252088c3
commit 86343345dc
4 changed files with 56 additions and 3 deletions

View File

@@ -137,9 +137,9 @@ SX CEK evaluator (both JS and OCaml hosts)
- [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.)_
`as` binding, or-pattern `(P1 | P2 | …)` (parens-only — top-level
`|` is the clause separator). Match clauses support `when` guard
via `(:case-when PAT GUARD BODY)`.
- [ ] OCaml is **not** indentation-sensitive — no layout algorithm needed.
- [ ] Tests in `lib/ocaml/tests/parse.sx` — 50+ round-trip parse tests.
@@ -377,6 +377,11 @@ the "mother tongue" closure: OCaml → SX → OCaml. This means:
_Newest first._
- 2026-05-08 Phase 1+3 — or-patterns `(P1 | P2 | ...)` parens-only
(+5 tests, 394 total). Parser: when `|` follows a pattern inside
parens, build `(:por ALT1 ALT2 ...)`. Eval: try alternatives, succeed
on the first match. Top-level `|` remains the clause separator (no
lookahead needed). Examples: `(1 | 2 | 3) -> ...`, `(Red | Green) -> 1`.
- 2026-05-08 Phase 4 — `module type S = sig … end` parser (+3 tests,
389 total). Signatures are parsed-and-discarded — sig..end balanced
skipping. AST: `(:module-type-def NAME)`. Runtime no-op (signatures