Mercurial > core / lisp/lib/organ/macs.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
609931bd65ba
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
3 (defmacro define-org-element (name slots &key documentation greater lesser) 4 (let ((docstring (or documentation (format nil "Org ~a element class." name))) 5 (sname (sym-to-org-class-name name))) 8 (defclass ,sname (,(or (when greater 'org-greater-element) 9 (when lesser 'org-lesser-element) 12 (:documentation ,docstring)) 13 (defmethod org-create ((type (eql ,(sb-int:keywordicate name))) &rest initargs) 14 (apply #'make-instance (sym-to-org-class-name type) initargs)) 15 (export '(,sname) :organ))))) 17 (defmacro define-org-object (name slots &key include documentation) 18 (let ((docstring (or documentation (format nil "Org ~a object structure." name))) 19 (obj (sym-to-org-class-name name))) 21 (defstruct (,obj ,@(when include (list `(:include ,(sym-to-org-class-name include))))) ,docstring ,@slots) 22 (defmethod org-create ((type (eql ,(sb-int:keywordicate name))) &rest initargs) 23 (apply #'make-instance (sym-to-org-class-name type) initargs)) 24 (export '(,obj) :organ)))) 26 ;; (macroexpand '(define-org-parser (headline) (print headline))) 27 (defmacro define-org-parser ((name &key (from 'string)) &body body) 28 "Define an ORG-PARSE method specializer for org type specifier NAME with body BODY." 29 (let ((elt (sb-int:keywordicate name))) 31 (defmethod org-parse ((type (eql ,elt)) (input ,from)) 32 ;; NOTE 2023-12-27: (,name (org-create ,nvar)) == bad idea. 33 ;; need parser to be fallible so shouldn't create an object 34 ;; upfront. We should delay initialization until the last moment 38 ;; It's super helpful to have our objects printed with their contents 40 (defmacro define-org-printer ())