From b23da3190eba8a1ae625a33e3785a328c431cd45 Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 21 Apr 2026 05:58:40 +0000 Subject: [PATCH] HS: add {prop: value; ...} CSS block syntax in add command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parser: - Handle brace-open token in parse-add-cmd - Parse colon-separated property:value pairs until brace-close - Produces (set-styles ((prop val) ...) target) Compiler: - set-styles → (do (dom-set-style target prop1 val1) ...) Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/hyperscript/compiler.sx | 10 ++++++++++ lib/hyperscript/parser.sx | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 4b29e85f..4baa345c 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -856,6 +856,16 @@ (hs-to-sx (nth ast 3)) (nth ast 1) (nth ast 2))) + ((= head (quote set-styles)) + (let + ((pairs (nth ast 1)) (tgt (hs-to-sx (nth ast 2)))) + (cons + (quote do) + (map + (fn + (p) + (list (quote dom-set-style) tgt (first p) (nth p 1))) + pairs)))) ((= head (quote multi-add-class)) (let ((target (hs-to-sx (nth ast 1))) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 8e5dada7..4f8fa5af 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -822,6 +822,32 @@ (let ((tgt (if (match-kw "to") (parse-expr) (list (quote me))))) (list (quote set-style) prop value tgt)))) + ((= (tp-type) "brace-open") + (do + (adv!) + (let + ((pairs (list))) + (define + collect-pairs! + (fn + () + (when + (and + (not (= (tp-type) "brace-close")) + (not (at-end?))) + (let + ((prop (get (adv!) "value"))) + (when (= (tp-type) "colon") (adv!)) + (let + ((val (tp-val))) + (adv!) + (set! pairs (cons (list prop val) pairs)) + (collect-pairs!)))))) + (collect-pairs!) + (when (= (tp-type) "brace-close") (adv!)) + (let + ((tgt (if (match-kw "to") (parse-expr) (list (quote me))))) + (list (quote set-styles) (reverse pairs) tgt))))) (true (let ((value (parse-expr)))