Function: SPLIT-BODY


(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))))
         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
              (string (if docstring
                          (if documentation
                              ;; already found the docstring, this is source
                              (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.
                          ;; no docstring allowed, this is source
              (t ;; more code, all done
         do (pop body)
         finally (done)))))
Source Context