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

@@ -964,6 +964,18 @@ cat > "$TMPFILE" << 'EPOCHS'
(epoch 2702)
(eval "(ocaml-parse-program \"module type EMPTY = sig end\")")
;; ── or-patterns (parens-only) ─────────────────────────────────
(epoch 2800)
(eval "(ocaml-run \"match 1 with | (1 | 2 | 3) -> 100 | _ -> 0\")")
(epoch 2801)
(eval "(ocaml-run \"match 2 with | (1 | 2 | 3) -> 100 | _ -> 0\")")
(epoch 2802)
(eval "(ocaml-run \"match 5 with | (1 | 2 | 3) -> 100 | _ -> 0\")")
(epoch 2803)
(eval "(ocaml-run \"match Red with | (Red | Green) -> 1 | Blue -> 2\")")
(epoch 2804)
(eval "(ocaml-run \"match Blue with | (Red | Green) -> 1 | Blue -> 2\")")
EPOCHS
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
@@ -1525,6 +1537,13 @@ check 2700 "module type S parses" '("module-type-def" "S")'
check 2701 "module type then module" '42'
check 2702 "module type EMPTY" '("module-type-def" "EMPTY")'
# ── or-patterns (parens-only) ──────────────────────────────────
check 2800 "(1|2|3) match 1" '100'
check 2801 "(1|2|3) match 2" '100'
check 2802 "(1|2|3) match 5" '0'
check 2803 "(Red|Green) Red" '1'
check 2804 "(Red|Green) Blue" '2'
TOTAL=$((PASS + FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"