ocaml: phase 4 'let open M in body' local opens (+3 tests, 478 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s
Parser detects 'let open' as a separate let-form, parses M as a path (Ctor(.Ctor)*) directly via inline AST construction (no source slicing since cur-pos is only available in ocaml-parse-program), and emits (:let-open PATH BODY). Eval resolves the path to a module dict and merges its bindings into the env for body evaluation. Now: let open List in map (fun x -> x * 2) [1;2;3] = [2;4;6] let open Option in map (fun x -> x + 1) (Some 5) = Some 6
This commit is contained in:
@@ -682,6 +682,37 @@
|
||||
(define
|
||||
parse-let
|
||||
(fn ()
|
||||
;; `let open M in body` — local open. Detect early so the
|
||||
;; rest of the let-handler doesn't try to parse `open` as
|
||||
;; an ident name.
|
||||
(cond
|
||||
((at-kw? "open")
|
||||
(begin
|
||||
(advance-tok!)
|
||||
;; Read path as Ctor(.Ctor)* and build :field-chain AST.
|
||||
(let ((path nil))
|
||||
(begin
|
||||
(when (= (ocaml-tok-type (peek-tok)) "ctor")
|
||||
(begin
|
||||
(set! path (list :con (ocaml-tok-value (peek-tok))))
|
||||
(advance-tok!)))
|
||||
(define more
|
||||
(fn ()
|
||||
(when (and (at-op? ".")
|
||||
(= (ocaml-tok-type
|
||||
(nth tokens (+ idx 1))) "ctor"))
|
||||
(begin
|
||||
(advance-tok!) ;; .
|
||||
(let ((nm (ocaml-tok-value (peek-tok))))
|
||||
(begin
|
||||
(advance-tok!)
|
||||
(set! path (list :field path nm))))
|
||||
(more)))))
|
||||
(more)
|
||||
(consume! "keyword" "in")
|
||||
(let ((body (parse-expr)))
|
||||
(list :let-open path body))))))
|
||||
(else
|
||||
(let ((reccy false) (bindings (list)))
|
||||
(begin
|
||||
(when (at-kw? "rec")
|
||||
@@ -729,7 +760,7 @@
|
||||
(else
|
||||
(if reccy
|
||||
(list :let-rec-mut bindings body)
|
||||
(list :let-mut bindings body)))))))))
|
||||
(list :let-mut bindings body)))))))))))
|
||||
(define
|
||||
parse-if
|
||||
(fn
|
||||
|
||||
Reference in New Issue
Block a user