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
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:
@@ -223,6 +223,19 @@
|
||||
(loop)
|
||||
(consume! "op" ")")
|
||||
(cons :ptuple items))))
|
||||
;; Parens-only or-pattern: (P1 | P2 | ...).
|
||||
((at-op? "|")
|
||||
(let ((alts (list first)))
|
||||
(begin
|
||||
(define loop-or
|
||||
(fn ()
|
||||
(when (at-op? "|")
|
||||
(begin (advance-tok!)
|
||||
(append! alts (parse-pattern))
|
||||
(loop-or)))))
|
||||
(loop-or)
|
||||
(consume! "op" ")")
|
||||
(cons :por alts))))
|
||||
(else (begin (consume! "op" ")") first))))))))
|
||||
((and (= tt "op") (= tv "["))
|
||||
(begin
|
||||
|
||||
Reference in New Issue
Block a user