From 6e38a2e1e168356b5b012687f61cac8a744038f9 Mon Sep 17 00:00:00 2001 From: giles Date: Fri, 10 Apr 2026 22:52:28 +0000 Subject: [PATCH] =?UTF-8?q?Parser:=20between,=20starts=20with,=20ends=20wi?= =?UTF-8?q?th=20=E2=80=94=20297/831=20(36%)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - is between X and Y / is not between X and Y: uses parse-atom for bounds to avoid consuming 'and' as logical operator - starts with / ends with: comparison operators mapping to starts-with? / ends-with? primitives - comparisonOperator: 12→17/40 Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/hyperscript/parser.sx | 21 +++++++++++++++++++++ shared/static/wasm/sx/hs-parser.sx | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 84ee38e1..3a5faded 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -363,6 +363,14 @@ (list (quote not) (list (quote empty?) left))) ((match-kw "in") (list (quote not-in?) left (parse-expr))) + ((match-kw "between") + (let ((lo (parse-atom))) + (match-kw "and") + (let ((hi (parse-atom))) + (list (quote not) + (list (quote and) + (list (quote >=) left lo) + (list (quote <=) left hi)))))) ((match-kw "really") (do (match-kw "equal") @@ -420,6 +428,13 @@ (match-kw "to") (list (quote >=) left (parse-expr))) (list (quote >) left (parse-expr))))) + ((match-kw "between") + (let ((lo (parse-atom))) + (match-kw "and") + (let ((hi (parse-atom))) + (list (quote and) + (list (quote >=) left lo) + (list (quote <=) left hi))))) ((match-kw "in") (list (quote in?) left (parse-expr))) ((match-kw "really") (do @@ -475,6 +490,12 @@ (list (quote =) left right)))))) ((and (= typ "keyword") (= val "exists")) (do (adv!) (list (quote exists?) left))) + ((and (or (= typ "keyword") (= typ "ident")) (= val "starts")) + (do (adv!) (match-kw "with") + (list (quote starts-with?) left (parse-expr)))) + ((and (or (= typ "keyword") (= typ "ident")) (= val "ends")) + (do (adv!) (match-kw "with") + (list (quote ends-with?) left (parse-expr)))) ((and (= typ "keyword") (= val "matches")) (do (adv!) (list (quote matches?) left (parse-expr)))) ((and (= typ "keyword") (= val "contains")) diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 84ee38e1..3a5faded 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -363,6 +363,14 @@ (list (quote not) (list (quote empty?) left))) ((match-kw "in") (list (quote not-in?) left (parse-expr))) + ((match-kw "between") + (let ((lo (parse-atom))) + (match-kw "and") + (let ((hi (parse-atom))) + (list (quote not) + (list (quote and) + (list (quote >=) left lo) + (list (quote <=) left hi)))))) ((match-kw "really") (do (match-kw "equal") @@ -420,6 +428,13 @@ (match-kw "to") (list (quote >=) left (parse-expr))) (list (quote >) left (parse-expr))))) + ((match-kw "between") + (let ((lo (parse-atom))) + (match-kw "and") + (let ((hi (parse-atom))) + (list (quote and) + (list (quote >=) left lo) + (list (quote <=) left hi))))) ((match-kw "in") (list (quote in?) left (parse-expr))) ((match-kw "really") (do @@ -475,6 +490,12 @@ (list (quote =) left right)))))) ((and (= typ "keyword") (= val "exists")) (do (adv!) (list (quote exists?) left))) + ((and (or (= typ "keyword") (= typ "ident")) (= val "starts")) + (do (adv!) (match-kw "with") + (list (quote starts-with?) left (parse-expr)))) + ((and (or (= typ "keyword") (= typ "ident")) (= val "ends")) + (do (adv!) (match-kw "with") + (list (quote ends-with?) left (parse-expr)))) ((and (= typ "keyword") (= val "matches")) (do (adv!) (list (quote matches?) left (parse-expr)))) ((and (= typ "keyword") (= val "contains"))