Source
(defun split-body (body env &key parent (docstring t) (declare t))
(let ((documentation nil)
(newdecls nil)
(decls nil))
(flet ((done ()
(return-from split-body (values body env documentation decls))))
(loop
for form = (car body)
while body
do (typecase form
(cons (if (and declare (eql 'cl:declare (first form)))
;; declare form
(let ((declarations (rest form)))
(dolist* (dec declarations)
(multiple-value-setf (env newdecls) (parse-declaration dec env parent))
(setf decls (append newdecls decls))))
;; source code, all done
(done)))
(string (if docstring
(if documentation
;; already found the docstring, this is source
(done)
(if (cdr body)
;; found the doc string
(setf documentation form)
;; this looks like a doc string, but
;; it's the only form in body, so
;; it's actually code.
(done)))
;; no docstring allowed, this is source
(done)))
(t ;; more code, all done
(done)))
do (pop body)
finally (done)))))
Source Context