Documented various markup classes
[parse-docstrings.git] / classes.lisp
blobde7a0715712fccb9041f380fee7fec89a324cdae
1 ;;; -*- lisp; show-trailing-whitespace: t; indent-tabs: nil -*-
3 ;;;; Part of this software was originally written as docstrings.lisp in
4 ;;;; SBCL, but is now part of the parse-docstrings project. The file
5 ;;;; docstrings.lisp was written by Rudi Schlatte <rudi@constantly.at>,
6 ;;;; mangled by Nikodemus Siivola, turned into a stand-alone project by
7 ;;;; Luis Oliveira. SBCL is in the public domain and is provided with
8 ;;;; absolutely no warranty.
10 ;;;; parse-docstrings is:
11 ;;;;
12 ;;;; Copyright (c) 2008 David Lichteblau:
13 ;;;;
14 ;;;; Permission is hereby granted, free of charge, to any person
15 ;;;; obtaining a copy of this software and associated documentation
16 ;;;; files (the "Software"), to deal in the Software without
17 ;;;; restriction, including without limitation the rights to use, copy,
18 ;;;; modify, merge, publish, distribute, sublicense, and/or sell copies
19 ;;;; of the Software, and to permit persons to whom the Software is
20 ;;;; furnished to do so, subject to the following conditions:
21 ;;;;
22 ;;;; The above copyright notice and this permission notice shall be
23 ;;;; included in all copies or substantial portions of the Software.
24 ;;;;
25 ;;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 ;;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 ;;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 ;;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
29 ;;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
30 ;;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31 ;;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 ;;;; DEALINGS IN THE SOFTWARE.
34 #+sbcl ;; FIXME: should handle this in the .asd file
35 (eval-when (:compile-toplevel :load-toplevel :execute)
36 (require 'sb-introspect))
38 (in-package #:parse-docstrings)
41 ;;; The DOCUMENTATION* class
43 (defvar *documentation-package*)
45 (defclass documentation* ()
46 ((name :initarg :name :reader get-name)
47 (kind :initarg :kind :reader get-kind)
48 (content :accessor get-content)
49 (children :initarg :children :initform nil :reader get-children)
50 (package :initform *documentation-package* :reader get-package)
51 (package-name :initform *documentation-package-name*
52 :reader get-package-name)))
55 ;;;; Markup classes
57 (defclass markup-element ()
59 (:documentation
60 "Wikipedia says: `A markup language is an artificial language using a set
61 of annotations to text that give instructions regarding the structure of
62 text or how it is to be displayed.'
64 MARKUP-ELEMENT is the superclass of all markup elements in
65 parse-docstrings.
67 Documentation, usually stored in .lisp files in the form of docstrings
68 and their annotations, is parsed into a structured CLOS representation by
69 parse-docstrings. At the highest level, instances of BLOCK-CONTENT as
70 used, for example PARAGRAPH object, CODE objects, or ITEMIZATION.
71 At lower levels, elements like BOLD or HYPERLINK provide structure
72 within paragraphs."))
74 (annotate-documentation (markup-element type)
75 (:see-also-type documentation*)
76 (:see-also-function documentation-content)
77 (:see-also-type documentation-annotations)
78 (:see-also-type parent-mixin)
79 (:see-also-function markup-to-sexp)
80 (:see-also-function sexp-to-markup))
82 (defclass block-content (markup-element)
84 (:documentation
85 "The common superclass of all markup elements that can appear directly
86 as children of a DOCUMENTATION* object, for example PARAGRAPH objects.
88 The distinction between BLOCK-CONTENT and INLINE-CONTENT is not being
89 enforced strictly by parse-docstring functions currently. However, output
90 generation will to many formats is expected to be easier if syntax
91 plugins adhere to the convention that inline elements don't appear at
92 the top themselves and don't have block elements as children."))
94 (annotate-documentation (block-content type)
95 (:see-also-type inline-content))
97 (defclass inline-content (markup-element)
99 (:documentation
100 "The common superclass of all markup elements that can appear at a lower
101 level in the markup tree, e.g. as a part of paragraphs.
103 The distinction between BLOCK-CONTENT and INLINE-CONTENT is not being
104 enforced strictly by parse-docstring functions currently. However, output
105 generation will to many formats is expected to be easier if syntax
106 plugins adhere to the convention that inline elements don't appear at
107 the top themselves and don't have block elements as children."))
109 (annotate-documentation (inline-content type)
110 (:see-also-type block-content))
112 (defclass parent-mixin ()
113 ((child-elements :initarg :child-elements
114 :accessor child-elements))
115 (:documentation
116 "The mixin superclass of all markup elements that have child elements.
117 This mixin is used by almost every markup class, except those that are
118 actual leafs (like TEXT) and those that have non-markup child objects
119 interposed before the next level of markup (like DEFINITION-LIST
120 with its DEFINITION-LIST-ITEM objects as non-element children)."))
122 (annotate-documentation (parent-mixin type)
123 (:slot-accessor child-elements)
124 (:see-also-type markup-element))
126 (annotate-documentation (child-elements function)
127 (:argument object "An instance of PARENT-MIXIN")
128 (:return-value "A list of MARKUP-ELEMENT instances.")
129 "Returns the children of this parent.
131 For elements of type BLOCK-CONTENT, the children are expected
132 to be of type BLOCK-CONTENT or INLINE-CONTENT, while element of type
133 INLINE-CONTENT are expected to have only INLINE-CONTENT children.
134 This distinction is not being enforced by parse-docstrings at this
135 point, however.")
137 (defmethod print-object ((object parent-mixin) stream)
138 (print-unreadable-object (object stream :type t)
139 (prin1 (child-elements object) stream)))
141 (defclass text (inline-content)
142 ((characters :initarg :characters
143 :accessor characters))
144 (:documentation
145 "Instances of this class wrap all strings that constitute the actual
146 text of a documentation string."))
148 (annotate-documentation (text type)
149 (:slot-accessor characters)
150 (:constructor make-text))
152 (annotate-documentation (characters function)
153 (:argument object "An instance of TEXT")
154 (:return-value "STRING")
155 "Returns the contents of this TEXT node as string.
157 Since TEXT nodes represent parsed markup, there are no special
158 characters in this text.
160 However, it is strongly recommended that ASCII control character not
161 be used in the string, except for whitespace characters, because such
162 characters cannot be represented at all in XML and HTML output formats.
164 Normally, newlines and other kinds of whitespace behave like an ordinary
165 space character, and sequences of whitespace are condensed into a single
166 space. However, some parent elements will specify different rules.
167 In particular, the PREFORMATTED and CODE element will render whitespace
168 exactly as contained in the original string.")
170 (defclass preformatted (parent-mixin block-content)
172 (:documentation
173 "Instances of this class define an exception from the usual formatting
174 of TEXT nodes for their children (and ancestor elements).
176 Here, newlines are preserved as line breaks, and sequences of space
177 are not condensed into a single space.
179 This element is similar to HTML's pre element, or the CSS assignment
180 `white-space: pre'.
182 When rendered to HTML, output formats may want to use different CSS
183 classes for PREFORMATTED and CODE, so that users can customize appearance
184 easily in a CSS file."))
186 (annotate-documentation (preformatted type)
187 (:constructor make-preformatted))
189 (defclass code (preformatted)
191 (:documentation
192 "A subclass of PREFORMATTED, this element can be used for code written
193 in a programming language.
195 Output formats might render CODE elements in a slightly different
196 style than ordinary PREFORMATTED elements, but are not required to do
199 When rendered to HTML, output formats may want to use different CSS
200 classes for PREFORMATTED and CODE, so that users can customize appearance
201 easily in a CSS file.
203 Currently, the programming language used is not presented in markup.
204 (Future versions of parse-docstrings might provide such an annotation,
205 to allow language-specific syntax highlighting.)"))
207 (annotate-documentation (code type)
208 (:constructor make-code))
210 ;; these aren't parents, because their children aren't markup
211 (defclass list-mixin ()
212 ((items :initarg :items
213 :accessor list-items))
214 (:documentation
215 "The mixin is a superclass of markup elements with a list of `children'
216 that are not proper markup elements, because they cannot appear as
217 child elements of other nodes."))
219 (annotate-documentation (list-mixin type)
220 (:slot-accessor list-items)
221 (:see-also-type list-element)
222 (:see-also-type markup-element))
224 (annotate-documentation (list-items function)
225 (:argument object "An instance of LIST-MIXIN")
226 (:return-value "A list of LIST-ITEM instances.")
227 "Returns the items of this list.")
229 (defclass definition-list (list-mixin block-content)
231 (:documentation
232 "Instances of this class represent lists of markup elements that is
233 rendered with special heading for each element.
235 Only objects of type DEFINITION-LIST-ITEM can occur as items
236 in this list.
238 This class is similar to DL element in HTML, with its LIST-ITEM children
239 corresponding to DT and DL elements."))
241 ;; theres aren't markup by themselves, because they can only appear in a
242 ;; list, but their children are markup again
243 (defclass list-item (parent-mixin)
245 (:documentation
246 "Instances of this class represent items in an object of type LIST-MIXIN.
248 Items have children of type MARKUP-ELEMENT, but are not markup themselves,
249 because they can only appear as children of LIST-MIXINs."))
251 (defclass definition-list-item (list-item)
252 ((title :initarg :title
253 :accessor definition-title))
254 (:documentation
255 "Instances of this class represent items in an object of type
256 DEFINITION-LIST.
258 Each item has a title and children, which are rendered next to each
259 other at the item's position in the list.
261 This class is similar to the DT and DL elements in HTML, which appear
262 as children of a DL list."))
264 (annotate-documentation (definition-list-item type)
265 (:slot-accessor definition-title)
266 (:constructor make-definition-list-item))
268 (annotate-documentation (definition-title function)
269 (:argument object "An instance of DEFINITION-LIST-ITEM")
270 (:return-value "STRING")
271 "Returns the title that is rendered as a header for this item.")
273 (defclass itemization (list-mixin block-content)
275 (:documentation
276 "Instances of this class represent lists of markup elements that will
277 be rendered similarly to paragraphs, but usually with indentation and
278 bullet points.
280 This class is similar to UL element in HTML, with its LIST-ITEM children
281 corresponding to LI elements."))
283 (annotate-documentation (itemization type)
284 (:constructor make-itemization))
286 (defclass enumeration (list-mixin block-content)
288 (:documentation
289 "Instances of this class represent lists of markup elements that will
290 be rendered similarly to paragraphs, but usually with indentation and
291 a sequential numbering starting with 1.
293 This class is similar to OL element in HTML, with its LIST-ITEM children
294 corresponding to LI elements."))
296 (annotate-documentation (enumeration type)
297 (:constructor make-enumeration))
299 (defclass paragraph (parent-mixin block-content)
301 (:documentation
302 "Instances of this class represent blocks of content beginning on a
303 fresh line and ending with a line break.
305 In contrast to DIV, the first line should have a margin of white space at
306 the top,and the last a margin of white space at the bottom.
308 This class is similar to the P element in HTML."))
310 (defclass div (parent-mixin block-content)
312 (:documentation
313 "Instances of this class represent blocks of content beginning on a
314 fresh line and ending with a line break.
316 In contrast to PARAGRAPH, there should be no margin of white space at
317 the top or bottom for the content of this element.
319 This class is similar to the DIV element in HTML."))
321 (defclass span (parent-mixin inline-content)
323 (:documentation
324 "Instances of this class represent a sequence of inline markup that is
325 rendered together, in the specified order.
327 This class is similar to the SPAN element in HTML."))
329 (defclass bold (parent-mixin inline-content)
331 (:documentation
332 "Instances of this class render their text in a bold font.
334 This class is similar to the B element in HTML, or the font-weight: bold
335 assignment in CSS."))
337 (defclass italic (parent-mixin inline-content)
339 (:documentation
340 "Instances of this class render their text in an italic font.
342 This class is similar to the I element in HTML, or the font-style: italic
343 assignment in CSS."))
345 (defclass underline (parent-mixin inline-content)
347 (:documentation
348 "Instances of this class render their text in an italic font.
350 This class is similar to the U element in HTML, or the text-decoration:
351 underline assignment in CSS."))
353 (defclass hyperlink (parent-mixin inline-content)
354 ((href :initarg :href
355 :accessor href))
356 (:documentation
357 "Instances of this class represent Hyperlinks. Their href attribute
358 specifies an URL as a string.
360 If possible,output formats should render the children of the element,
361 and use the href attribute only as the action when the element is
362 selected -- just like the A element behaves in HTML.
364 As an exception, output formats without native support for links, such
365 as plaintext formatting, are encourages to display the URL verbatim,
366 for example as a footnote or just following the child elements, using
367 using brackets to distinguish the URL from surrounding text.
369 If at all possible, do not use HYPERLINK elements to link to documentation
370 of individual Lisp functions. Instead, use cross references, either
371 in the form of an INLINE-CROSS-REFERENCE or as a
372 CROSS-REFERENCE-ANNOTATION, and use hyperdoc to define URLs for
373 functions in the target package.
375 Used this way, internal cross references to functions documented
376 in the same run of parse-docstrings can use links native to the output
377 format (for example, using relative URLs in #anchor format instead of
378 absolute URLs) and will use the absolute URLs for external
379 references only, with the URL format currently declared to be correct
380 by the library being referenced."))
382 (annotate-documentation (href function)
383 (:argument object "An instance of HYPERLINK")
384 (:return-value "STRING")
385 "Returns the title that is rendered as a header for this item.")
387 (defclass cross-reference-mixin ()
388 ((target :initarg :target
389 :accessor cross-reference-target)
390 (doc-type :initarg :doc-type
391 :accessor cross-reference-doc-type))
392 (:documentation
393 "Instances of this class specify cross references between documentation
394 strings. The target of a cross-reference is specified as a pair
395 of a documentation name (for example, a symbol) and a doc-type, which
396 would be suitable as an argument to DOCUMENTATION or DOCUMENTATION*."))
398 (annotate-documentation (cross-reference-mixin type)
399 (:slot-accessor cross-reference-target)
400 (:slot-accessor cross-reference-doc-type))
402 (defclass inline-cross-reference
403 (parent-mixin
404 cross-reference-mixin
405 inline-content)
406 ((annotation-category :initarg :annotation-category
407 :accessor annotation-category))
408 (:documentation
409 "Instances of this class represent cross references (or links) to
410 Lisp documentation.
412 (If at all possible, use this class or CROSS-REFERENCE-ANNOTATION over
413 HYPERLINK whenever possible.)
415 The ANNOTATION-CATEGORY slot in this class can specify what kind
416 of conceptual relationship the reference's target has to the documentation
417 it is being used in. Depending on the category, it will be listed
418 as a slot accessor, constructor function, condition type signalled,
419 or just listed under `see also'. Refer to ANNOTATION-CATEGORY for
420 permissible values.
422 This class will render internal cross references to functions documented
423 in the same run of parse-docstrings can use links native to the output
424 format (for example, using relative URLs in #anchor format instead of
425 absolute URLs) and will use the absolute URLs for external
426 references only, with the URL format currently declared to be correct
427 by the library being referenced."))
429 (annotate-documentation (inline-cross-reference type)
430 (:slot-accessor annotation-category)
431 (:constructor make-inline-cross-reference))
433 (annotate-documentation (annotation-category function)
434 (:argument object "An instance of INLINE-CROSS-REFERENCE")
435 (:return-value "One of :CONDITION, :CONSTRUCTOR, :SLOT-ACCESSOR, or NIL")
436 "Returns the ANNOTATION-CATEGORY of the cross reference.
438 The category specifies what kind of conceptual relationship the
439 reference's target has to the documentation it is being used in.
441 Possible values are:
443 * NIL -- will be listed as `See Also'
444 * :SLOT-ACCESSOR -- will be listed as `Slot Accessor Function'
445 * :CONSTRUCTOR -- will be listed as `Constructor Function'
446 * :CONDITION -- will be listed as `Condition Types Signalled'")
448 (defclass unknown-element (parent-mixin inline-content)
449 ((name :initarg :name
450 :accessor name)
451 (plist :initarg :plist
452 :accessor plist))
453 (:documentation
454 "This fallback class is used for unknown markup elements encountered
455 in a docstring.
457 A property list mapping strings (or symbols) to strings is provided
458 as PLIST.
460 Users are advised against use of unknown elements, because not all output
461 formats will render them identically.
463 Examples:
465 * An XML serialization might pass unknown elements through under the
466 specified name, perhaps in a special namespace.
467 * An HTML serialization might pass those elements through that happen
468 to have a name permitted in HTML, and ignore others. Alternatively, it
469 might allow all unknown elements, leaving it up to the docstring author
470 to ensure that no invalid HTML will result.
471 * Other output formats might ignore unknown elements completely, or
472 render only their children.
474 All output formats are encouraged (but not required to) continue
475 execution without errors when encountering unknown elements, but also
476 to print a warning alterting the user to their presence."))
478 (annotate-documentation (unknown-element type)
479 (:slot-accessor name)
480 (:slot-accessor plist)
481 (:constructor make-unknown-element))
483 (annotate-documentation (name function)
484 (:argument object "An instance of UNKNOWN-ELEMENT")
485 (:return-value "STRING")
486 "Returns the name of the unknown element.
488 For example, an atdoc tag @foo[bar]{baz} would result in an
489 UNKNOWN-ELEMENT with a NAME of \"foo\".")
491 (annotate-documentation (plist function)
492 (:argument object "An instance of UNKNOWN-ELEMENT")
493 (:return-value "A property list mapping strings or symbols to strings")
494 "Returns the plist of the unknown element.
496 For example, an atdoc tag @foo[bar]{baz} would result in an
497 UNKNOWN-ELEMENT with a PLIST mapping \"foo\" to \"bar\".")
499 (defun make-text (characters)
500 (check-type characters string)
501 (make-instance 'text :characters characters))
503 (macrolet ((%simple-parent (constructor class)
504 `(defun ,constructor (&rest children)
505 (dolist (child children)
506 (check-type child markup-element))
507 (make-instance ',class :child-elements children))))
508 (%simple-parent make-preformatted preformatted)
509 (%simple-parent make-code code)
510 (%simple-parent make-paragraph paragraph)
511 (%simple-parent make-div div)
512 (%simple-parent make-span span)
513 (%simple-parent make-bold bold)
514 (%simple-parent make-italic italic)
515 (%simple-parent make-underline underline))
517 (macrolet ((%list-parent (constructor class)
518 `(defun ,constructor (&rest items)
519 (dolist (item items)
520 (check-type item list-item))
521 (make-instance ',class :items items))))
522 (%list-parent make-itemization itemization)
523 (%list-parent make-enumeration enumeration))
525 (defun make-definition-list (&rest items)
526 (dolist (item items)
527 (check-type item definition-list-item))
528 (make-instance 'definition-list :items items))
530 (defun make-definition-list-item (title &rest children)
531 (check-type title string)
532 (dolist (child children)
533 (check-type child markup-element))
534 (make-instance 'definition-list-item :title title :child-elements children))
536 (defun make-hyperlink (href &rest children)
537 (check-type href string)
538 (dolist (child children)
539 (check-type child markup-element))
540 (make-instance 'hyperlink :href href :child-elements children))
542 (defun make-unknown-element (name plist &rest children)
543 (check-type name string)
544 (dolist (child children)
545 (check-type child markup-element))
546 (iter (for (name value) on plist by #'cddr)
547 (check-type name (or symbol string))
548 (check-type value string))
549 (make-instance 'unknown-element :name name
550 :plist plist
551 :child-elements children))
554 ;;;; Annotation Classes
556 (defclass documentation-annotations ()
557 ((arguments :initform nil
558 :accessor argument-annotations)
559 (return-values :initform nil
560 :accessor return-value-annotations)
561 (conditions :initform nil
562 :accessor condition-annotations)
563 (slot-accessors :initform nil
564 :accessor slot-accessor-annotations)
565 (constructors :initform nil
566 :accessor constructor-annotation)
567 (see-also-list :initform nil
568 :accessor see-also-annotations))
569 (:documentation
570 "This class stores annotations for docstrings, specifing for additional
571 information on arguments, return values, and cross references.
573 Depending on the docstring syntax in use, annotation can be specified
574 directly in the docstring using special markup.
576 Alternatively, the plist of symbol that names a definition can be used
577 to store annotations separately from the docstring. Refer to the
578 ANNOTATE-DOCUMENTATION macro for details."))
580 (annotate-documentation (documentation-annotations type)
581 (:slot-accessor argument-annotations)
582 (:slot-accessor return-value-annotations)
583 (:slot-accessor condition-annotations)
584 (:slot-accessor slot-accessor-annotations)
585 (:slot-accessor constructor-annotation)
586 (:slot-accessor see-also-annotations)
587 (:constructor annotations))
589 (annotate-documentation (argument-annotations function)
590 (:argument object "An instance of DOCUMENTATION-ANNOTATIONS")
591 (:return-value "A list of PARAMETER-LIKE-ANNOTATION objects")
592 "Returns annotations for this function's arguments.
594 Each annotation records the name of the argument, and a docstring
595 describing details of the argument, e.g. its type.
597 It is recommended (but currently not required) that arguments
598 in list correspond to the original names in the lambda list, and that
599 their order is preserved.")
601 (annotate-documentation (return-value-annotations function)
602 (:argument object "An instance of DOCUMENTATION-ANNOTATIONS")
603 (:return-value "A list of PARAMETER-LIKE-ANNOTATION objects")
604 "Returns annotations for this function's return values.
606 Each annotation records a docstring describing details of return value,
607 e.g. its type. Additionally, a name can be specified for annotation,
608 allowing HyperSpec-like descriptions of each return value.
610 Only functions using multiple values will have more than one annotation
611 in this slot.
613 Where multiple values are used, annotations in this list are stored in the
614 order of their return values.")
616 (annotate-documentation (condition-annotations function)
617 (:argument object "An instance of DOCUMENTATION-ANNOTATIONS")
618 (:return-value "A list of CROSS-REFERENCE-ANNOTATION objects")
619 "Returns annotations for condition classes signalled by this function.
621 Each entry is this list is a cross reference for a type, referring to
622 a condition class that might be signalled.
624 Entries in this list can occur in any order.")
626 (annotate-documentation (constructor-annotations function)
627 (:argument object "An instance of DOCUMENTATION-ANNOTATIONS")
628 (:return-value "A list of CROSS-REFERENCE-ANNOTATION objects")
629 "Returns annotations for functions serving as constructors for this type.
631 In this documentation, constructor for a type is any function that
632 returns fresh instances of that type.
634 This kind of annotation is useful when a type FOO is usually created
635 through a wrapper function MAKE-FOO rather than direct calls to
636 MAKE-INSTANCE.
638 Entries in this list can occur in any order.")
640 (annotate-documentation (slot-accessor-annotations function)
641 (:argument object "An instance of DOCUMENTATION-ANNOTATIONS")
642 (:return-value "A list of CROSS-REFERENCE-ANNOTATION objects")
643 "Returns annotations for functions serving as slot readers or accessors.
645 Annotations in this list document that this class has a slot accessible
646 through the function designated by the cross reference, and possibly
647 settable through a setf function for the same name.
649 This kind of annotation is most useful for programs that opt not to
650 document slots directly, and prefer to document the slot accessors as
651 ordinary functions instead.
653 Entries in this list can occur in any order.")
655 (annotate-documentation (see-also-annotations function)
656 (:argument object "An instance of DOCUMENTATION-ANNOTATIONS")
657 (:return-value "A list of CROSS-REFERENCE-ANNOTATION objects")
658 "Returns annotations for related definitions.
660 Cross-reference annotations in this list are meant to augment the
661 CONDITION-ANNOTATIONS, CONSTRUCTOR-ANNOTATIONS, and
662 SLOT-ACCESSOR-ANNOTATIONS. Any cross reference can be added to this list,
663 assuming that the target of the cross reference is related to the current
664 function, and that relation is not made explict in the docstring.
666 Entries in this list can occur in any order.")
668 (defclass cross-reference-annotation (cross-reference-mixin)
670 (:documentation
671 "Instances of this class specify cross references that are
672 included in documentation only as annotations, i.e. not as a part
673 of the main docstring's text.
675 Cross reference annotations are recorded as a part of
676 DOCUMENTATION-ANNOTATIONS objects, as CONDITION-ANNOTATIONS,
677 SLOT-ACCESSOR-ANNOTATIONS, CONSTRUCTOR-ANNOTATIONS, or
678 SEE-ALSO-ANNOTATIONS."))
680 (annotate-documentation (cross-reference-annotation type)
681 (:constructor make-cross-reference-annotation))
683 (defun make-cross-reference-annotation (target doc-type)
684 "Returns a fresh instance of CROSS-REFERENCE-ANNOTATION with the
685 slots for CROSS-REFERENCE-TARGET and CROSS-REFERENCE-DOC-TYPE bound
686 to TARGET and DOC-TYPE, respectively."
687 (make-instance 'cross-reference-annotation
688 :target target
689 :doc-type doc-type))
691 (annotate-documentation (make-cross-reference-annotation function)
692 (:argument target "A documentation name, for example a symbol.")
693 (:argument doc-type "A documentation type as accepted by DOCUMENTATION*"
694 "as a second argument.")
695 (:return-value "An instance of cross-reference-annotation"))
697 (defclass parameter-annotation ()
698 ((name :initarg :name
699 :accessor parameter-name)
700 (docstring :initarg :docstring :accessor parameter-docstring))
701 (:documentation
702 "Instances of this class specify documentation on function arguments and
703 return values.
705 The annotation specifies a name, which is required or at least highly
706 recommended for arguments, and optional for return values.
708 The docstring is meant to document the argument or return value and
709 should usually specify at least its type, but ideally also describe
710 its purpose."))
712 (annotate-documentation (parameter-annotation type)
713 (:slot-accessor parameter-name)
714 (:slot-accessor parameter-docstring)
715 (:constructor make-parameter-annotation))
717 (defun make-parameter-annotation (name docstring)
718 "Returns a fresh instance of PARAMETER-ANNOTATION with the
719 slots for PARAMETER-NAME and PARAMETER-DOCSTRING bound
720 to name and DOCSTRING, respectively."
721 (make-instance 'parameter-annotation
722 :name name
723 :docstring docstring))
725 (annotate-documentation (make-parameter-annotation function)
726 (:argument name "Symbol naming the argument or return value.")
727 (:argument docstring "String. This is a documentation string in the"
728 "docstring syntax used for the package that is being documented.")
729 (:return-value "A fresh PARAMETER-ANNOTATION."))