diff --git a/lib/hyperscript/parser.sx b/lib/hyperscript/parser.sx index 176174be..be58d2b6 100644 --- a/lib/hyperscript/parser.sx +++ b/lib/hyperscript/parser.sx @@ -1164,7 +1164,9 @@ (let ((tgt (parse-expr))) (list (quote add-value) value tgt)) - nil)))))) + (error + (str + "Invalid 'add' syntax: expected a class (.foo), attribute, or expression with 'to'")))))))) (define parse-remove-cmd (fn @@ -2973,7 +2975,7 @@ (let ((of-filter (when (and (= event-name "mutation") (match-kw "of")) (cond ((and (= (tp-type) "ident") (or (= (tp-val) "attributes") (= (tp-val) "childList") (= (tp-val) "characterData"))) (let ((nm (tp-val))) (do (adv!) (dict "type" nm)))) ((= (tp-type) "attr") (let ((attrs (list (tp-val)))) (do (adv!) (define collect-or! (fn () (when (match-kw "or") (cond ((= (tp-type) "attr") (do (set! attrs (append attrs (list (tp-val)))) (adv!) (collect-or!))) (true (set! p (- p 1))))))) (collect-or!) (dict "type" "attrs" "attrs" attrs)))) (true nil))))) (let - ((event-vars (if (= (tp-type) "paren-open") (do (adv!) (define ev-coll (fn () (cond ((or (= (tp-type) "paren-close") (= (tp-type) "eof")) (do (when (= (tp-type) "paren-close") (adv!)) (list))) ((or (= (tp-type) "ident") (= (tp-type) "keyword")) (let ((nm (tp-val))) (adv!) (cons nm (ev-coll)))) (true (do (adv!) (ev-coll)))))) (ev-coll)) (list)))) + ((event-vars (if (= (tp-type) "paren-open") (let ((saved-p p)) (do (adv!) (if (= (tp-type) "keyword") (do (set! p saved-p) (list)) (do (define ev-coll (fn () (cond ((or (= (tp-type) "paren-close") (= (tp-type) "eof")) (do (when (= (tp-type) "paren-close") (adv!)) (list))) ((or (= (tp-type) "ident") (= (tp-type) "keyword")) (let ((nm (tp-val))) (adv!) (cons nm (ev-coll)))) (true (do (adv!) (ev-coll)))))) (ev-coll))))) (list)))) (let ((flt (if (= (tp-type) "bracket-open") (do (adv!) (let ((f (parse-expr))) (if (= (tp-type) "bracket-close") (adv!) nil) f)) nil))) (let diff --git a/lib/hyperscript/tokenizer.sx b/lib/hyperscript/tokenizer.sx index a62849eb..367a178d 100644 --- a/lib/hyperscript/tokenizer.sx +++ b/lib/hyperscript/tokenizer.sx @@ -459,7 +459,7 @@ (define build-name (fn - (acc) + (acc depth) (cond ((and (< pos src-len) (= (hs-cur) "\\") (< (+ pos 1) src-len)) (do @@ -467,15 +467,35 @@ (let ((c (hs-cur))) (hs-advance! 1) - (build-name (str acc c))))) - ((and (< pos src-len) (or (hs-ident-char? (hs-cur)) (= (hs-cur) ":") (= (hs-cur) "[") (= (hs-cur) "]") (= (hs-cur) "(") (= (hs-cur) ")") (= (hs-cur) "&"))) + (build-name (str acc c) depth)))) + ((and (< pos src-len) (= (hs-cur) "[")) (do (let ((c (hs-cur))) (hs-advance! 1) - (build-name (str acc c))))) + (build-name (str acc c) (+ depth 1))))) + ((and (< pos src-len) (= (hs-cur) "]")) + (do + (let + ((c (hs-cur))) + (hs-advance! 1) + (build-name + (str acc c) + (if (> depth 0) (- depth 1) 0))))) + ((and (< pos src-len) (> depth 0) (or (= (hs-cur) "(") (= (hs-cur) ")"))) + (do + (let + ((c (hs-cur))) + (hs-advance! 1) + (build-name (str acc c) depth)))) + ((and (< pos src-len) (or (hs-ident-char? (hs-cur)) (= (hs-cur) ":") (= (hs-cur) "&"))) + (do + (let + ((c (hs-cur))) + (hs-advance! 1) + (build-name (str acc c) depth)))) (true acc)))) - (build-name ""))) + (build-name "" 0))) (define hs-emit! (fn diff --git a/shared/static/wasm/sx/hs-parser.sx b/shared/static/wasm/sx/hs-parser.sx index 176174be..be58d2b6 100644 --- a/shared/static/wasm/sx/hs-parser.sx +++ b/shared/static/wasm/sx/hs-parser.sx @@ -1164,7 +1164,9 @@ (let ((tgt (parse-expr))) (list (quote add-value) value tgt)) - nil)))))) + (error + (str + "Invalid 'add' syntax: expected a class (.foo), attribute, or expression with 'to'")))))))) (define parse-remove-cmd (fn @@ -2973,7 +2975,7 @@ (let ((of-filter (when (and (= event-name "mutation") (match-kw "of")) (cond ((and (= (tp-type) "ident") (or (= (tp-val) "attributes") (= (tp-val) "childList") (= (tp-val) "characterData"))) (let ((nm (tp-val))) (do (adv!) (dict "type" nm)))) ((= (tp-type) "attr") (let ((attrs (list (tp-val)))) (do (adv!) (define collect-or! (fn () (when (match-kw "or") (cond ((= (tp-type) "attr") (do (set! attrs (append attrs (list (tp-val)))) (adv!) (collect-or!))) (true (set! p (- p 1))))))) (collect-or!) (dict "type" "attrs" "attrs" attrs)))) (true nil))))) (let - ((event-vars (if (= (tp-type) "paren-open") (do (adv!) (define ev-coll (fn () (cond ((or (= (tp-type) "paren-close") (= (tp-type) "eof")) (do (when (= (tp-type) "paren-close") (adv!)) (list))) ((or (= (tp-type) "ident") (= (tp-type) "keyword")) (let ((nm (tp-val))) (adv!) (cons nm (ev-coll)))) (true (do (adv!) (ev-coll)))))) (ev-coll)) (list)))) + ((event-vars (if (= (tp-type) "paren-open") (let ((saved-p p)) (do (adv!) (if (= (tp-type) "keyword") (do (set! p saved-p) (list)) (do (define ev-coll (fn () (cond ((or (= (tp-type) "paren-close") (= (tp-type) "eof")) (do (when (= (tp-type) "paren-close") (adv!)) (list))) ((or (= (tp-type) "ident") (= (tp-type) "keyword")) (let ((nm (tp-val))) (adv!) (cons nm (ev-coll)))) (true (do (adv!) (ev-coll)))))) (ev-coll))))) (list)))) (let ((flt (if (= (tp-type) "bracket-open") (do (adv!) (let ((f (parse-expr))) (if (= (tp-type) "bracket-close") (adv!) nil) f)) nil))) (let diff --git a/shared/static/wasm/sx/hs-tokenizer.sx b/shared/static/wasm/sx/hs-tokenizer.sx index a62849eb..367a178d 100644 --- a/shared/static/wasm/sx/hs-tokenizer.sx +++ b/shared/static/wasm/sx/hs-tokenizer.sx @@ -459,7 +459,7 @@ (define build-name (fn - (acc) + (acc depth) (cond ((and (< pos src-len) (= (hs-cur) "\\") (< (+ pos 1) src-len)) (do @@ -467,15 +467,35 @@ (let ((c (hs-cur))) (hs-advance! 1) - (build-name (str acc c))))) - ((and (< pos src-len) (or (hs-ident-char? (hs-cur)) (= (hs-cur) ":") (= (hs-cur) "[") (= (hs-cur) "]") (= (hs-cur) "(") (= (hs-cur) ")") (= (hs-cur) "&"))) + (build-name (str acc c) depth)))) + ((and (< pos src-len) (= (hs-cur) "[")) (do (let ((c (hs-cur))) (hs-advance! 1) - (build-name (str acc c))))) + (build-name (str acc c) (+ depth 1))))) + ((and (< pos src-len) (= (hs-cur) "]")) + (do + (let + ((c (hs-cur))) + (hs-advance! 1) + (build-name + (str acc c) + (if (> depth 0) (- depth 1) 0))))) + ((and (< pos src-len) (> depth 0) (or (= (hs-cur) "(") (= (hs-cur) ")"))) + (do + (let + ((c (hs-cur))) + (hs-advance! 1) + (build-name (str acc c) depth)))) + ((and (< pos src-len) (or (hs-ident-char? (hs-cur)) (= (hs-cur) ":") (= (hs-cur) "&"))) + (do + (let + ((c (hs-cur))) + (hs-advance! 1) + (build-name (str acc c) depth)))) (true acc)))) - (build-name ""))) + (build-name "" 0))) (define hs-emit! (fn