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
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user