haskell: Phase 17 — import declarations anywhere among top-level decls
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 21s

hk-collect-module-body previously ran a fixed import-loop at the start
and then a separate decl-loop; merged into a single hk-body-step
dispatcher that routes `import` to the imports list and everything else
to hk-parse-decl. Both call sites (initial step + post-semicolon loop)
use the dispatcher. The eval side reads imports as a list (not by AST
position) so mid-stream imports feed into hk-bind-decls! unchanged.

tests/parse-extras.sx 12 → 17: very-top, mid-stream, post-main,
two-imports-different-positions, unqualified-mid-file. Regression
sweep clean: eval 66/0, exceptions 14/0, typecheck 15/0, records 14/0,
ioref 13/0, map 26/0, set 17/0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-10 19:11:36 +00:00
parent aa620b767f
commit 4510e7e475
3 changed files with 62 additions and 3 deletions

View File

@@ -1733,10 +1733,18 @@
(= (hk-peek-type) "eof")
(hk-match? "vrbrace" nil)
(hk-match? "rbrace" nil))))
(define
hk-body-step
(fn
()
(cond
((hk-match? "reserved" "import")
(append! imports (hk-parse-import)))
(:else (append! decls (hk-parse-decl))))))
(when
(not (hk-body-at-end?))
(do
(append! decls (hk-parse-decl))
(hk-body-step)
(define
hk-body-loop
(fn
@@ -1747,7 +1755,7 @@
(hk-advance!)
(when
(not (hk-body-at-end?))
(append! decls (hk-parse-decl)))
(hk-body-step))
(hk-body-loop)))))
(hk-body-loop)))
(list imports decls))))