2024-05-28 11:15:29 +00:00
|
|
|
(defpackage #:hsx/defhsx
|
2024-05-28 03:33:01 +00:00
|
|
|
(:use #:cl)
|
|
|
|
(:import-from #:alexandria
|
2024-05-28 10:31:50 +00:00
|
|
|
#:make-keyword
|
2024-05-28 03:33:01 +00:00
|
|
|
#:symbolicate)
|
|
|
|
(:import-from #:hsx/element
|
|
|
|
#:create-element)
|
2024-05-28 10:31:50 +00:00
|
|
|
(:export #:deftag
|
2024-05-28 03:33:01 +00:00
|
|
|
#:defcomp))
|
|
|
|
(in-package #:hsx/defhsx)
|
|
|
|
|
|
|
|
(defmacro defhsx (name element-type)
|
2024-05-28 11:15:29 +00:00
|
|
|
`(defmacro ,name (&body body)
|
|
|
|
(multiple-value-bind (props children)
|
|
|
|
(parse-body body)
|
|
|
|
`(create-element ,',element-type (list ,@props) ,@children))))
|
2024-05-28 03:33:01 +00:00
|
|
|
|
|
|
|
(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)))
|
2024-05-28 10:31:50 +00:00
|
|
|
|
|
|
|
(defmacro deftag (name)
|
|
|
|
`(eval-when (:compile-toplevel :load-toplevel :execute)
|
|
|
|
(defhsx ,name ,(make-keyword name))))
|
2024-05-28 03:33:01 +00:00
|
|
|
|
|
|
|
(defmacro defcomp (name props &body body)
|
|
|
|
(let ((%name (symbolicate '% name)))
|
|
|
|
`(eval-when (:compile-toplevel :load-toplevel :execute)
|
|
|
|
(defun ,%name ,props
|
|
|
|
,@body)
|
|
|
|
(defhsx ,name (fdefinition ',%name)))))
|