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

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:
2026-05-09 03:40:38 +00:00
parent 7e64695a74
commit dab8718289
4 changed files with 36 additions and 4 deletions

View File

@@ -562,7 +562,7 @@
else cont := false
else cont := false
done;
(!w) * 1000000 + (!i)
(!w, !i)
in
let rec walk pos prefix =
if pos >= n then prefix
@@ -573,9 +573,7 @@
let left_flag = ref false in
let zero_flag = ref false in
let after_flags = parse_flags_loop (pos + 1) left_flag zero_flag in
let packed = parse_width_loop after_flags in
let width = packed / 1000000 in
let spec_pos = packed - width * 1000000 in
let (width, spec_pos) = parse_width_loop after_flags in
if spec_pos < n && is_spec (_string_get fmt spec_pos) then
let spec = _string_get fmt spec_pos in
let left = !left_flag in