From 91f4a2bd9f9a4c395b9ac81aea268b496e8a1710 Mon Sep 17 00:00:00 2001 From: Bo Yao Date: Wed, 27 Jun 2018 10:01:18 -0400 Subject: [PATCH] make attrs modifiable --- src/flute.lisp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/flute.lisp b/src/flute.lisp index a2b0410..8f0f6a3 100644 --- a/src/flute.lisp +++ b/src/flute.lisp @@ -58,6 +58,18 @@ (defstruct attrs alist) +;;; TODO make it setf +(defmethod set-attr ((attrs attrs) key value) + ) + +(defmethod delete-attr ((attrs attrs) key value) + ) + +(defmethod get-attr ((attrs attrs)) + ) + +; (defmethod set-attr ((element element) key value)) + (defun split-attrs-and-children (attrs-and-children) (cond ((attrs-p (first attrs-and-children)) @@ -150,19 +162,27 @@ (defmacro! define-element (name (&rest args) &body body) `(defun ,name (&rest ,g!attrs-and-children) - (multiple-value-bind (,g!attrs children) + (multiple-value-bind (,g!attrs ,g!children) (split-attrs-and-children ,g!attrs-and-children) (let ,(mapcar (lambda (arg) (list arg `(cdr (assoc (make-keyword ',arg) (attrs-alist ,g!attrs))))) args) (make-user-element :tag (string-downcase ',name) :attrs ,g!attrs - :children children :expand-to (progn ,@body)))))) + :children ,g!children + :expand-to + (lambda (tag attrs children) + (declare (ignorable tag attrs children)) + (progn ,@body))))))) (defvar *expand-user-element* t) (defmethod print-object ((element user-element) stream) (if *expand-user-element* - (print-object (user-element-expand-to element) stream) + (print-object (funcall (user-element-expand-to element) + (element-tag element) + (element-attrs element) + (element-children element)) + stream) (call-next-method))) (defun tree-leaves%% (tree test result)