ocaml: phase 4 open / include (+5 tests, 220 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 57s
Parser: open Path and include Path top-level decls; Path is Ctor (.Ctor)*. Eval resolves via ocaml-resolve-module-path (same :con-as-module-lookup escape hatch used by :field). open extends the env with the module's bindings; include also merges into the surrounding module's exports (when inside a struct...end). Path resolver lets M.Sub.x work for nested modules. Phase 4 LOC ~165.
This commit is contained in:
@@ -788,6 +788,8 @@
|
||||
((at-op? ";;") nil)
|
||||
((at-kw? "let") nil)
|
||||
((at-kw? "module") nil)
|
||||
((at-kw? "open") nil)
|
||||
((at-kw? "include") nil)
|
||||
(else (begin (advance-tok!) (skip-to-boundary!))))))
|
||||
(define
|
||||
parse-decl-let
|
||||
@@ -842,6 +844,29 @@
|
||||
;; module M = struct DECLS end
|
||||
;; Parsed by sub-tokenising the body source between `struct` and
|
||||
;; the matching `end`. Nested modules / sigs increment depth.
|
||||
;; open M / include M — collect a path Ctor(.SubCtor)* and emit
|
||||
;; (:open PATH) or (:include PATH).
|
||||
(define
|
||||
parse-decl-open
|
||||
(fn (include?)
|
||||
(advance-tok!)
|
||||
(let ((path-start (cur-pos)))
|
||||
(begin
|
||||
;; Walk until end of the path. A path is Ctor (. Ctor)*.
|
||||
(define skip-path
|
||||
(fn ()
|
||||
(cond
|
||||
((>= idx tok-len) nil)
|
||||
((= (ocaml-tok-type (peek-tok)) "ctor")
|
||||
(begin (advance-tok!) (skip-path)))
|
||||
((at-op? ".") (begin (advance-tok!) (skip-path)))
|
||||
(else nil))))
|
||||
(skip-path)
|
||||
(let ((path-src (slice src path-start (cur-pos))))
|
||||
(let ((path-expr (ocaml-parse path-src)))
|
||||
(if include?
|
||||
(list :include path-expr)
|
||||
(list :open path-expr))))))))
|
||||
(define
|
||||
parse-decl-module
|
||||
(fn ()
|
||||
@@ -890,6 +915,10 @@
|
||||
(begin (append! decls (parse-decl-let)) (loop)))
|
||||
((at-kw? "module")
|
||||
(begin (append! decls (parse-decl-module)) (loop)))
|
||||
((at-kw? "open")
|
||||
(begin (append! decls (parse-decl-open false)) (loop)))
|
||||
((at-kw? "include")
|
||||
(begin (append! decls (parse-decl-open true)) (loop)))
|
||||
(else (begin (append! decls (parse-decl-expr)) (loop))))))))
|
||||
(loop)
|
||||
(cons :program decls)))))
|
||||
|
||||
Reference in New Issue
Block a user