diff --git a/src/builtin.lisp b/src/builtin.lisp new file mode 100644 index 0000000..cd56a85 --- /dev/null +++ b/src/builtin.lisp @@ -0,0 +1,33 @@ +(uiop:define-package #:hsx/builtin + (:use #:cl) + (:import-from #:alexandria + #:make-keyword) + (:import-from #:hsx/hsx + #:defhsx)) +(in-package #:hsx/builtin) + +(defparameter *builtin-elements* (make-hash-table)) + +(defmacro define-and-export-builtin-elements (&rest names) + `(progn + ,@(mapcan (lambda (name) + (list `(defhsx ,name ,(string-downcase name)) + `(setf (gethash (make-keyword ',name) *builtin-elements*) t) + `(export ',name))) + names))) + +(define-and-export-builtin-elements + ; tag-elements + a abbr address area article aside audio b base bdi bdo blockquote + body br button canvas caption cite code col colgroup data datalist + dd del details dfn dialog div dl dt em embed fieldset figcaption + figure footer form h1 h2 h3 h4 h5 h6 head header hr i iframe + img input ins kbd label legend li link main |map| mark meta meter nav + noscript object ol optgroup option output p param picture pre progress + q rp rt ruby s samp script section select small source span strong + style sub summary sup svg table tbody td template textarea tfoot th + thead |time| title tr track u ul var video wbr + ; html-tag-element + html + ; fragment-element + <>) diff --git a/src/hsx.lisp b/src/hsx.lisp index 66e8b72..7d9261c 100644 --- a/src/hsx.lisp +++ b/src/hsx.lisp @@ -1,8 +1,7 @@ (uiop:define-package #:hsx/hsx (:use #:cl) (:import-from #:alexandria - #:symbolicate - #:make-keyword) + #:symbolicate) (:import-from #:hsx/element #:create-element) (:export #:defhsx @@ -30,32 +29,6 @@ :finally (return (values props nil))) (values nil body))) -(defparameter *builtin-elements* (make-hash-table)) - -(defmacro define-and-export-builtin-elements (&rest names) - `(progn - ,@(mapcan (lambda (name) - (list `(defhsx ,name ,(string-downcase name)) - `(setf (gethash (make-keyword ',name) *builtin-elements*) t) - `(export ',name))) - names))) - -(define-and-export-builtin-elements - ; tag-elements - a abbr address area article aside audio b base bdi bdo blockquote - body br button canvas caption cite code col colgroup data datalist - dd del details dfn dialog div dl dt em embed fieldset figcaption - figure footer form h1 h2 h3 h4 h5 h6 head header hr i iframe - img input ins kbd label legend li link main |map| mark meta meter nav - noscript object ol optgroup option output p param picture pre progress - q rp rt ruby s samp script section select small source span strong - style sub summary sup svg table tbody td template textarea tfoot th - thead |time| title tr track u ul var video wbr - ; html-tag-element - html - ; fragment-element - <>) - (defmacro defcomp (name props &body body) (let ((%name (symbolicate '% name))) `(eval-when (:compile-toplevel :load-toplevel :execute) @@ -67,26 +40,17 @@ ;;;; hsx macro to find hsx symbols (defmacro hsx (form) - (modify-first-of-lists form - #'builtin-element-p - (lambda (node) - (find-symbol (string node) :hsx/hsx)))) + (find-builtin-symbols form)) -(defun modify-first-of-lists (tree test result) +(defun find-builtin-symbols (tree) (if tree (cons (let ((first-node (first tree))) - (cond - ((listp first-node) - (modify-first-of-lists first-node test result)) - ((funcall test first-node) - (funcall result first-node)) - (t first-node))) + (if (listp first-node) + (find-builtin-symbols first-node) + (or (find-symbol (string first-node) :hsx/builtin) + first-node))) (mapcar (lambda (node) (if (listp node) - (modify-first-of-lists node test result) + (find-builtin-symbols node) node)) (rest tree))))) - -(defun builtin-element-p (node) - (and (symbolp node) - (gethash (make-keyword node) *builtin-elements*))) diff --git a/src/main.lisp b/src/main.lisp index 76a9f69..cf188c4 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -1,4 +1,7 @@ (defpackage :hsx (:nicknames #:hsx/main) + (:import-from #:hsx/element) + (:import-from #:hsx/hsx) + (:import-from #:hsx/builtin) (:use #:cl)) (in-package :hsx) diff --git a/tests/hsx.lisp b/tests/hsx.lisp index 7cfe79e..b1eae1d 100644 --- a/tests/hsx.lisp +++ b/tests/hsx.lisp @@ -1,7 +1,8 @@ (defpackage #:hsx-test/hsx (:use #:cl #:fiveam - #:hsx/hsx) + #:hsx/hsx + #:hsx/builtin) (:import-from #:hsx/element #:create-element)) (in-package #:hsx-test/hsx)