Mercurial > core / lisp/lib/doc/pkg.lisp
changeset 264: |
f603ff88b072 |
parent: |
b7183bfd7107
|
child: |
8116ba385ca6 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 05 Apr 2024 21:13:42 -0400 |
permissions: |
-rw-r--r-- |
description: |
DOC |
1 ;;; lib/doc/pkg.lisp --- CL Documentation 3 ;; This package is designed to help us navigate our Lisp systems, 4 ;; packages, symbols, and files to extract information relevant to 5 ;; documentation. This is a rather broad category. Here are some of 6 ;; the categories of information we're interested in: 8 ;; - Comments :: like this one. 11 ;; - Docstrings :: typically store in symbol properties, documentation 12 ;; metaclass slot, etc. often found somewhere in the body of a form 15 ;; - Object Structure :: for functions - their declared type, for 16 ;; objects their slots, methods, sub/superclasses, etc (MOP). 18 ;; - Source :: the source code which defines a symbol and its 19 ;; file/line location. 23 ;; Documentation is a tricky craft, good thing we have a 24 ;; self-documenting language :). 26 ;; The API consists of extractors for the above categories of 27 ;; information and a compiler (in comp.lisp) which can be used to 30 ;; This is an SBCL library, so we use the SB-INTROSPECT project for 31 ;; most of the heavy lifting related to inspecting Lisp objects. This 32 ;; covers most symbols and informs the next category of extractor 33 ;; which is the file extractor in file.lisp. 35 ;; The package extractor in package.lisp wraps SB-INTROSPECT functions 36 ;; and populates internal data structures with relevant information 37 ;; based on exported symbols. 39 ;; The file extractor is a parser which supports lisp source files as 40 ;; well as system definitions (ASD) and possibly other inputs. You can 41 ;; use it as a standalone document extractor for files, but it is 42 ;; intended to be called with source-location information from 43 ;; SB-INTROSPECT. The file extractor retrieves additional information 44 ;; from the source file where a symbol is defined such as comments and 45 ;; neighboring definitions. 47 ;; The final static extractor is in system.lisp which of course is 48 ;; intended for entire Lisp systems, combining the extractors defined 51 ;; The compiler in comp.lisp contains the high-level functions which 52 ;; take system, package, file, or symbol names and generate 53 ;; documentation output. 55 ;; This library DOES NOT implement export/publishing per se. We use 56 ;; the ORGAN system to generate ORG-DOCUMENT objects, which themselves 57 ;; implement the functionality needed to generate *.org files and 58 ;; translate to html,pdf,txt and other formats. 61 (eval-when (:compile-toplevel :load-toplevel) (require :sb-introspect)) 64 (:use :cl :std :organ :sb-mop :sb-introspect :obj/id :log) 65 (:import-from :uiop :string-prefix-p) 66 (:import-from :asdf :component-name :component-children 67 :system :component-pathname :find-system :system-description 69 (:import-from :sb-c :packed-info :symbol-hash :symbol-dbinfo :vop-p :package-external-symbol-count) 70 (:import-from :sb-kernel :symbol-package-id) 71 (:import-from :sb-ext :restrict-compiler-policy) 72 (:import-from :ql-dist :dist :find-dist :provided-systems :installed-systems) 73 (:import-from :sb-impl :describe-block :print-standard-describe-header :describe-object) 74 (:import-from :sb-int :condition) 75 (:import-from :sb-alien :alien-type-p) 82 :doc-file :doc-files :doc-symbol :doc-symbols :doc-package :doc-packages :doc-dist 83 :doc-pathnames :doc-directories :doc-parse :doc-system :doc-dependencies :doc-dependents 85 :do-symbol* :classify-symbol :symbol-classification-string 88 :package-documentation 90 :define-source-file* :*source-file-types* 91 :file-heading :file-headline :file-header :read-file-header 92 :+max-heading-level+ :+min-heading-level+ 99 :image-documentation)) 103 (defparameter *definition-types* 105 :constant defconstant 107 :symbol-macro define-symbol-macro 109 :compiler-macro define-compiler-macro 111 :generic-function defgeneric 113 :setf-expander define-setf-expander 115 :condition define-condition 117 :method-combination define-method-combination 119 :transform :deftransform 120 :optimizer :defoptimizer 122 :source-transform :define-source-transform 123 :ir1-convert :def-ir1-translator 125 :alien-type :define-alien-type) 126 "Map SB-INTROSPECT definition type names to Slime-friendly forms") 128 (defun definition-specifier (type) 129 "Return a pretty specifier for NAME representing a definition of type TYPE." 130 (getf *definition-types* type)) 132 (defun make-dspec (type name source-location) 133 (list* (definition-specifier type) 135 (sb-introspect::definition-source-description source-location))) 137 (defun find-definitions (name) 138 "Iterate over all type definitions returning two lists, DSPECs and DEFINITION-SOURCEs." 139 (let ((dspecs) (defs)) 140 (loop for type in *definition-types* by #'cddr 141 for defsrcs = (sb-introspect:find-definition-sources-by-name name type) 142 do (loop for defsrc in defsrcs 143 do (push (make-dspec type name defsrc) dspecs) 144 (dolist (d (sb-introspect:find-definition-sources-by-name name type)) (push d defs)))) 145 (values defs dspecs)))