ocaml: phase 4 module type S = sig … end parser (+3 tests, 389 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 33s

module type S = sig DECLS end is parsed-and-discarded — sig..end
balanced skipping in parse-decl-module-type. AST (:module-type-def
NAME). Runtime no-op (signatures are type-level only).

Allows real OCaml programs with module type decls to parse and run
without stripping the sig blocks.
This commit is contained in:
2026-05-08 15:11:45 +00:00
parent 76ccbfbab6
commit ad252088c3
4 changed files with 69 additions and 3 deletions

View File

@@ -1282,10 +1282,53 @@
(else (begin (advance-tok!) (skip))))))
(skip)))))))
;; module type S = sig ... end
;; Parsed-and-discarded (signatures are type-level only). Returns
;; a (:module-type-def NAME) marker for the eval loop to ignore.
(define
parse-decl-module-type
(fn ()
(advance-tok!) ;; "type"
(let ((name (ocaml-tok-value (consume! "ctor" nil))))
(begin
(consume! "op" "=")
(cond
((at-kw? "sig")
(begin
(advance-tok!)
(let ((depth 1))
(begin
(define skip
(fn ()
(cond
((>= idx tok-len) nil)
((= (ocaml-tok-type (peek-tok)) "eof") nil)
((or (at-kw? "sig") (at-kw? "struct") (at-kw? "begin"))
(begin (set! depth (+ depth 1)) (advance-tok!) (skip)))
((at-kw? "end")
(cond
((= depth 1) nil)
(else
(begin (set! depth (- depth 1)) (advance-tok!) (skip)))))
(else (begin (advance-tok!) (skip))))))
(skip)
(consume! "keyword" "end")))))
(else
;; module type S = AnotherSig — skip-to-boundary.
(skip-to-boundary!)))
(list :module-type-def name)))))
(define
parse-decl-module
(fn ()
(advance-tok!)
(cond
((at-kw? "type") (parse-decl-module-type))
(else (parse-decl-module-rest)))))
(define
parse-decl-module-rest
(fn ()
(let ((name (ocaml-tok-value (consume! "ctor" nil)))
(params (list)))
(begin