From 3a6475df6aee90933030d282ac3672f2835a1a39 Mon Sep 17 00:00:00 2001 From: paku Date: Mon, 27 May 2024 12:24:38 +0900 Subject: [PATCH] Improve hsx macro --- src/hsx.lisp | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/hsx.lisp b/src/hsx.lisp index 1ba7a5c..53b7b5b 100644 --- a/src/hsx.lisp +++ b/src/hsx.lisp @@ -19,6 +19,17 @@ (parse-body body) `(create-element ,',element-type (list ,@props) ,@children)))) +(defun parse-body (body) + (if (keywordp (first body)) + (loop :for thing :on body :by #'cddr + :for (k v) := thing + :when (and (keywordp k) v) + :append (list k v) :into props + :when (not (keywordp k)) + :return (values props thing) + :finally (return (values props nil))) + (values nil body))) + (defparameter *builtin-elements* (make-hash-table)) (defmacro define-and-export-builtin-elements (&body names) @@ -52,26 +63,14 @@ ,@body) (defhsx ,name (fdefinition ',%name))))) -(defun parse-body (body) - (if (keywordp (first body)) - (loop :for thing :on body :by #'cddr - :for (k v) := thing - :when (and (keywordp k) v) - :append (list k v) :into props - :when (not (keywordp k)) - :return (values props thing) - :finally (return (values props nil))) - (values nil body))) - ;;;; hsx macro to find hsx symbols -(defmacro hsx (&body body) - `(progn - ,@(modify-first-leaves body - #'builtin-element-p - (lambda (node) - (find-symbol (string node) :hsx/hsx))))) +(defmacro hsx (form) + (modify-first-leaves form + #'builtin-element-p + (lambda (node) + (find-symbol (string node) :hsx/hsx)))) (defun modify-first-leaves (tree test result) (if tree