HS runtime: empty/swap/compound events, host-set! fix — 403→423 (51%)

- Fix host-set → host-set! in emit-inc/emit-dec (increment/decrement properties)
- Implement empty/clear command: parser dispatch, compiler, polymorphic runtime
- Implement swap command: parser dispatch, compiler (let+do temp swap pattern)
- Add parse-compound-event-name: joins dot/colon tokens (example.event, htmx:load)
- Add hs-compile to source parser (was only in WASM deploy copy)
- Add clear/swap to tokenizer keywords and cmd-kw? list
- Generator: fix run() with extra args, String.raw support

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 09:17:43 +00:00
parent e2fe070dd4
commit eaf3c88a36
9 changed files with 1159 additions and 35 deletions

View File

@@ -292,7 +292,7 @@
(let
((obj (hs-to-sx (nth expr 1))) (prop (nth expr 2)))
(list
(quote host-set)
(quote host-set!)
obj
prop
(list
@@ -344,7 +344,7 @@
(let
((obj (hs-to-sx (nth expr 1))) (prop (nth expr 2)))
(list
(quote host-set)
(quote host-set!)
obj
prop
(list
@@ -815,6 +815,18 @@
(nth ast 1)))))
((= head (quote remove-element))
(list (quote dom-remove) (hs-to-sx (nth ast 1))))
((= head (quote empty-target))
(list (quote hs-empty-target!) (hs-to-sx (nth ast 1))))
((= head (quote swap!))
(let
((lhs (nth ast 1)) (rhs (nth ast 2)))
(list
(quote let)
(list (list (quote _swap_tmp) (hs-to-sx lhs)))
(list
(quote do)
(emit-set lhs (hs-to-sx rhs))
(emit-set rhs (quote _swap_tmp))))))
((= head (quote remove-attr))
(let
((tgt (if (nil? (nth ast 2)) (quote me) (hs-to-sx (nth ast 2)))))

View File

@@ -942,12 +942,40 @@
(if (= (tp-type) "comma") (adv!) nil)
(dd-collect (append acc (list key val))))))))
(cons (quote dict) (dd-collect (list)))))
(define
parse-compound-event-name
(fn
()
(let
((result (get (adv!) "value")))
(define
collect!
(fn
()
(when
(not (at-end?))
(cond
((= (tp-type) "class")
(let
((part (tp-val)))
(adv!)
(set! result (str result "." part))
(collect!)))
((= (tp-type) "local")
(let
((part (tp-val)))
(adv!)
(set! result (str result ":" part))
(collect!)))
(true nil)))))
(collect!)
result)))
(define
parse-send-cmd
(fn
()
(let
((name (get (adv!) "value")))
((name (parse-compound-event-name)))
(let
((dtl (if (= (tp-type) "paren-open") (parse-detail-dict) nil)))
(let
@@ -1422,6 +1450,21 @@
(let
((end-pos (skip-to-close 0)))
(substring src start-pos end-pos)))))
(define
parse-empty-cmd
(fn
()
(let
((target (cond ((at-end?) (list (quote sym) "me")) ((and (= (tp-type) "keyword") (or (= (tp-val) "then") (= (tp-val) "end"))) (list (quote sym) "me")) (true (parse-expr)))))
(list (quote empty-target) target))))
(define
parse-swap-cmd
(fn
()
(let
((lhs (parse-expr)))
(match-kw "with")
(let ((rhs (parse-expr))) (list (quote swap!) lhs rhs)))))
(define
parse-cmd
(fn
@@ -1503,6 +1546,12 @@
(do (adv!) (parse-halt-cmd)))
((and (= typ "keyword") (= val "focus"))
(do (adv!) (parse-focus-cmd)))
((and (= typ "keyword") (= val "empty"))
(do (adv!) (parse-empty-cmd)))
((and (= typ "keyword") (= val "clear"))
(do (adv!) (parse-empty-cmd)))
((and (= typ "keyword") (= val "swap"))
(do (adv!) (parse-swap-cmd)))
(true (parse-expr))))))
(define
parse-cmd-list
@@ -1548,7 +1597,10 @@
(= v "scroll")
(= v "select")
(= v "reset")
(= v "focus"))))
(= v "focus")
(= v "empty")
(= v "clear")
(= v "swap"))))
(define
cl-collect
(fn
@@ -1578,7 +1630,7 @@
(let
((every? (match-kw "every")))
(let
((event-name (let ((v (tp-val))) (adv!) v)))
((event-name (parse-compound-event-name)))
(let
((flt (if (= (tp-type) "bracket-open") (do (adv!) (let ((f (parse-expr))) (if (= (tp-type) "bracket-close") (adv!) nil) f)) nil)))
(let

View File

@@ -444,10 +444,31 @@
((dict? v) (= (len (keys v)) 0))
(true false))))
;; Array slicing (inclusive both ends)
(define hs-first (fn (lst) (first lst)))
(define
hs-empty-target!
(fn
(target)
(cond
((list? target) (for-each (fn (el) (hs-empty-target! el)) target))
((nil? target) nil)
(true
(let
((tag (dom-get-prop target "tagName")))
(cond
((or (= tag "INPUT") (= tag "TEXTAREA"))
(let
((input-type (dom-get-prop target "type")))
(if
(or (= input-type "checkbox") (= input-type "radio"))
(dom-set-prop target "checked" false)
(dom-set-prop target "value" ""))))
((= tag "FORM") (dom-set-inner-html target ""))
(true (dom-set-inner-html target ""))))))))
;; Collection: sorted by
(define hs-last (fn (lst) (last lst)))
(define hs-first (fn (lst) (first lst)))
;; Collection: sorted by descending
(define hs-last (fn (lst) (last lst)))
;; Collection: split by
(define
hs-template
(fn
@@ -533,7 +554,7 @@
(set! i (+ i 1))
(tpl-loop)))))))
(do (tpl-loop) result))))
;; Collection: split by
;; Collection: joined by
(define
hs-make-object
(fn
@@ -545,7 +566,7 @@
(fn (pair) (dict-set! d (first pair) (nth pair 1)))
pairs)
d))))
;; Collection: joined by
(define
hs-method-call
(fn

View File

@@ -117,6 +117,8 @@
"last"
"random"
"empty"
"clear"
"swap"
"exists"
"matches"
"contains"