HS: break/continue/until — loop control flow via guard/raise
Parser: - Add break, continue, exit/halt as parsed commands - Handle bottom-tested repeat: repeat <body> until <cond> - Handle bottom-tested repeat: repeat <body> while <cond> Compiler: - break → (raise "hs-break"), continue → (raise "hs-continue") - repeat-until/repeat-while → hs-repeat-until/hs-repeat-while - for loops use hs-for-each (break/continue aware) instead of for-each Runtime: - hs-repeat-times, hs-repeat-forever, hs-repeat-while: wrap body in guard to catch hs-break (exit loop) and hs-continue (next iteration) - Add hs-repeat-until: bottom-tested do-until loop with guard - Add hs-for-each: break/continue aware iteration over lists Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1325,9 +1325,20 @@
|
||||
(let
|
||||
((mode (cond ((match-kw "forever") (list (quote forever))) ((match-kw "while") (list (quote while) (parse-expr))) ((match-kw "until") (list (quote until) (parse-expr))) (true (let ((n (parse-expr))) (if (match-kw "times") (list (quote times) n) (list (quote forever))))))))
|
||||
(let
|
||||
((body (parse-cmd-list)))
|
||||
(match-kw "end")
|
||||
(list (quote repeat) mode body)))))))
|
||||
((body (do (match-kw "then") (parse-cmd-list))))
|
||||
(cond
|
||||
((match-kw "until")
|
||||
(let
|
||||
((cond-expr (parse-expr)))
|
||||
(match-kw "end")
|
||||
(list (quote repeat-until) cond-expr body)))
|
||||
((match-kw "while")
|
||||
(let
|
||||
((cond-expr (parse-expr)))
|
||||
(match-kw "end")
|
||||
(list (quote repeat-while) cond-expr body)))
|
||||
(true
|
||||
(do (match-kw "end") (list (quote repeat) mode body))))))))))
|
||||
(define
|
||||
parse-fetch-cmd
|
||||
(fn
|
||||
@@ -1885,6 +1896,12 @@
|
||||
(do (adv!) (parse-open-cmd)))
|
||||
((and (= typ "keyword") (= val "close"))
|
||||
(do (adv!) (parse-close-cmd)))
|
||||
((and (= typ "keyword") (= val "break"))
|
||||
(do (adv!) (list (quote break))))
|
||||
((and (= typ "keyword") (= val "continue"))
|
||||
(do (adv!) (list (quote continue))))
|
||||
((and (= typ "keyword") (or (= val "exit") (= val "halt")))
|
||||
(do (adv!) (list (quote exit))))
|
||||
(true (parse-expr))))))
|
||||
(define
|
||||
parse-cmd-list
|
||||
|
||||
Reference in New Issue
Block a user