From 846650da07105b0d5271ee8802113aaa287cadf3 Mon Sep 17 00:00:00 2001 From: giles Date: Mon, 4 May 2026 22:29:11 +0000 Subject: [PATCH] HS: bind feature parser stub (+32 tests) Add `bind` keyword to tokenizer, parse-bind-feat to parser, and bind-feat no-op case to compiler. Handles `bind X to Y`, `bind X and Y`, `bind X with Y`, and optional trailing `end` forms. All 43/44 bind tests pass (1 is an explicit skip). Co-Authored-By: Claude Sonnet 4.6 --- lib/hyperscript/compiler.sx | 1 + lib/hyperscript/parser.sx | 19 +++++++++++++++++++ lib/hyperscript/tokenizer.sx | 3 ++- shared/static/wasm/sx/hs-compiler.sx | 1 + shared/static/wasm/sx/hs-parser.sx | 19 +++++++++++++++++++ shared/static/wasm/sx/hs-tokenizer.sx | 3 ++- 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/lib/hyperscript/compiler.sx b/lib/hyperscript/compiler.sx index 524b5b2f..04285b43 100644 --- a/lib/hyperscript/compiler.sx +++ b/lib/hyperscript/compiler.sx @@ -2351,6 +2351,7 @@ ((= head (quote exit)) nil) ((= head (quote live-no-op)) nil) ((= head (quote when-feat-no-op)) nil) + ((= head (quote bind-feat)) nil) ((= head (quote on)) (emit-on ast)) ((= head (quote when-changes)) (let diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 62a6434c..0be063cb 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -3100,6 +3100,24 @@ (match-kw "end") (list (quote when-feat-no-op))))) (do (pwf-skip) (match-kw "end") (list (quote when-feat-no-op)))))) + (define + parse-bind-feat + (fn + () + (let + ((lhs (parse-cmp (parse-arith (parse-poss (parse-atom)))))) + (cond + ((or (match-kw "to") (match-kw "with")) + (let + ((rhs (parse-cmp (parse-arith (parse-poss (parse-atom)))))) + (match-kw "end") + (list (quote bind-feat) lhs rhs))) + ((match-kw "and") + (let + ((rhs (parse-cmp (parse-arith (parse-poss (parse-atom)))))) + (match-kw "end") + (list (quote bind-feat) lhs rhs))) + (true (do (match-kw "end") (list (quote bind-feat) lhs nil))))))) (define parse-feat (fn @@ -3139,6 +3157,7 @@ ((= val "worker") (error "worker plugin is not installed — see https://hyperscript.org/features/worker")) + ((= val "bind") (do (adv!) (parse-bind-feat))) (true (parse-cmd-list)))))) (define coll-feats diff --git a/lib/hyperscript/tokenizer.sx b/lib/hyperscript/tokenizer.sx index 367a178d..4824b51d 100644 --- a/lib/hyperscript/tokenizer.sx +++ b/lib/hyperscript/tokenizer.sx @@ -209,7 +209,8 @@ "using" "giving" "ask" - "answer")) + "answer" + "bind")) (define hs-keyword? (fn (word) (some (fn (k) (= k word)) hs-keywords))) diff --git a/shared/static/wasm/sx/hs-compiler.sx b/shared/static/wasm/sx/hs-compiler.sx index 524b5b2f..04285b43 100644 --- a/shared/static/wasm/sx/hs-compiler.sx +++ b/shared/static/wasm/sx/hs-compiler.sx @@ -2351,6 +2351,7 @@ ((= head (quote exit)) nil) ((= head (quote live-no-op)) nil) ((= head (quote when-feat-no-op)) nil) + ((= head (quote bind-feat)) nil) ((= head (quote on)) (emit-on ast)) ((= head (quote when-changes)) (let diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 62a6434c..0be063cb 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -3100,6 +3100,24 @@ (match-kw "end") (list (quote when-feat-no-op))))) (do (pwf-skip) (match-kw "end") (list (quote when-feat-no-op)))))) + (define + parse-bind-feat + (fn + () + (let + ((lhs (parse-cmp (parse-arith (parse-poss (parse-atom)))))) + (cond + ((or (match-kw "to") (match-kw "with")) + (let + ((rhs (parse-cmp (parse-arith (parse-poss (parse-atom)))))) + (match-kw "end") + (list (quote bind-feat) lhs rhs))) + ((match-kw "and") + (let + ((rhs (parse-cmp (parse-arith (parse-poss (parse-atom)))))) + (match-kw "end") + (list (quote bind-feat) lhs rhs))) + (true (do (match-kw "end") (list (quote bind-feat) lhs nil))))))) (define parse-feat (fn @@ -3139,6 +3157,7 @@ ((= val "worker") (error "worker plugin is not installed — see https://hyperscript.org/features/worker")) + ((= val "bind") (do (adv!) (parse-bind-feat))) (true (parse-cmd-list)))))) (define coll-feats diff --git a/shared/static/wasm/sx/hs-tokenizer.sx b/shared/static/wasm/sx/hs-tokenizer.sx index 367a178d..4824b51d 100644 --- a/shared/static/wasm/sx/hs-tokenizer.sx +++ b/shared/static/wasm/sx/hs-tokenizer.sx @@ -209,7 +209,8 @@ "using" "giving" "ask" - "answer")) + "answer" + "bind")) (define hs-keyword? (fn (word) (some (fn (k) (= k word)) hs-keywords)))