ocaml: phase 4 'let PATTERN = expr in body' tuple destructuring (+3 tests, 541 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 44s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 44s
When 'let' is followed by '(', parse-let now reads a full pattern
(via the existing parse-pattern used by match), expects '=', then
'in', and desugars to:
let PATTERN = EXPR in BODY => match EXPR with PATTERN -> BODY
This reuses the entire pattern-matching machinery, so any pattern
the match parser accepts works here too — paren-tuples, nested
tuples, cons patterns, list patterns. No 'rec' allowed for pattern
bindings (real OCaml's restriction).
let (a, b) = (1, 2) in a + b = 3
let (a, b, c) = (10, 20, 30) in a + b + c = 60
let pair = (5, 7) in
let (x, y) = pair in x * y = 35
Also retroactively cleaned up Printf's iter-97 width-pos packing
hack ('width * 1000000 + spec_pos') — it's now
'let (width, spec_pos) = parse_width_loop after_flags in ...' like
real OCaml.
This commit is contained in:
@@ -1342,6 +1342,14 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 5084)
|
||||
(eval "(ocaml-run \"Printf.sprintf \\\"hi=%-3d, hex=%04x\\\" 9 15\")")
|
||||
|
||||
;; ── let (a, b) = expr in body — tuple destructure ─────────────
|
||||
(epoch 5090)
|
||||
(eval "(ocaml-run \"let (a, b) = (1, 2) in a + b\")")
|
||||
(epoch 5091)
|
||||
(eval "(ocaml-run \"let (a, b, c) = (10, 20, 30) in a + b + c\")")
|
||||
(epoch 5092)
|
||||
(eval "(ocaml-run \"let pair = (5, 7) in let (x, y) = pair in x * y\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 360 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -2132,6 +2140,11 @@ check 5082 "%05d 42 zero-pad" '"00042"'
|
||||
check 5083 "%4s hi" '" hi"'
|
||||
check 5084 "%-3d %04x mixed" '"hi=9 , hex=000f"'
|
||||
|
||||
# ── let (a, b) = expr in body ───────────────────────────────────
|
||||
check 5090 "let (a, b) = (1,2)" '3'
|
||||
check 5091 "let (a, b, c) = (10,20,30)" '60'
|
||||
check 5092 "let pair; let (x, y) = pair" '35'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "ok $PASS/$TOTAL OCaml-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user