changelog shortlog graph tags branches changeset files revisions annotate raw help

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
2 
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:
7 
8 ;; - Comments :: like this one.
9 #| or this one |#
10 
11 ;; - Docstrings :: typically store in symbol properties, documentation
12 ;; metaclass slot, etc. often found somewhere in the body of a form
13 ;; starting with DEF.
14 
15 ;; - Object Structure :: for functions - their declared type, for
16 ;; objects their slots, methods, sub/superclasses, etc (MOP).
17 
18 ;; - Source :: the source code which defines a symbol and its
19 ;; file/line location.
20 
21 ;;; Commentary:
22 
23 ;; Documentation is a tricky craft, good thing we have a
24 ;; self-documenting language :).
25 
26 ;; The API consists of extractors for the above categories of
27 ;; information and a compiler (in comp.lisp) which can be used to
28 ;; generate output.
29 
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.
34 
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.
38 
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.
46 
47 ;; The final static extractor is in system.lisp which of course is
48 ;; intended for entire Lisp systems, combining the extractors defined
49 ;; thus far.
50 
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.
54 
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.
59 
60 ;;; Code:
61 (eval-when (:compile-toplevel :load-toplevel) (require :sb-introspect))
62 
63 (defpackage :doc
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
68  :system-depends-on)
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)
76  (:export
77  :definition-specifier
78  :find-definitions
79  ;; err
80  :doc-error
81  ;; methods
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
84  ;; symbol
85  :do-symbol* :classify-symbol :symbol-classification-string
86  :symbol-documentation
87  ;; package
88  :package-documentation
89  ;; file
90  :define-source-file* :*source-file-types*
91  :file-heading :file-headline :file-header :read-file-header
92  :+max-heading-level+ :+min-heading-level+
93  :file-documentation
94  ;; system
95  :system-documentation
96  ;; dist
97  :dist-documentation
98  ;; image
99  :image-documentation))
100 
101 (in-package :doc)
102 
103 (defparameter *definition-types*
104  '(:variable defvar
105  :constant defconstant
106  :type deftype
107  :symbol-macro define-symbol-macro
108  :macro defmacro
109  :compiler-macro define-compiler-macro
110  :function defun
111  :generic-function defgeneric
112  :method defmethod
113  :setf-expander define-setf-expander
114  :structure defstruct
115  :condition define-condition
116  :class defclass
117  :method-combination define-method-combination
118  :package defpackage
119  :transform :deftransform
120  :optimizer :defoptimizer
121  :vop :define-vop
122  :source-transform :define-source-transform
123  :ir1-convert :def-ir1-translator
124  :declaration declaim
125  :alien-type :define-alien-type)
126  "Map SB-INTROSPECT definition type names to Slime-friendly forms")
127 
128 (defun definition-specifier (type)
129  "Return a pretty specifier for NAME representing a definition of type TYPE."
130  (getf *definition-types* type))
131 
132 (defun make-dspec (type name source-location)
133  (list* (definition-specifier type)
134  name
135  (sb-introspect::definition-source-description source-location)))
136 
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)))