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

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:
2026-05-08 15:06:44 +00:00
parent 0cf5c8f219
commit 98049d5458
4 changed files with 78 additions and 7 deletions

View File

@@ -250,6 +250,29 @@
(loop)
(consume! "op" "]")
(cons :plist items)))))))
((and (= tt "op") (= tv "{"))
;; Record pattern: { f1 = pat1; f2 = pat2; ... }
(begin
(advance-tok!)
(let ((fields (list)))
(begin
(define one
(fn ()
(let ((fname (ocaml-tok-value (consume! "ident" nil))))
(begin
(consume! "op" "=")
(let ((fp (parse-pattern)))
(append! fields (list fname fp)))))))
(one)
(define more
(fn ()
(when (at-op? ";")
(begin (advance-tok!)
(when (not (at-op? "}"))
(begin (one) (more)))))))
(more)
(consume! "op" "}")
(cons :precord fields)))))
(else
(error
(str