1 ; Copyright 2022 Frank Duncan (frank@consxy.com) under AGPL3. See distributed LICENSE.txt.
4 (define-condition validation-failure nil ((msg :initarg :msg :reader validation-failure-msg))
5 (:documentation "Used internally for sheep parts to signal a validation error."))
7 (defun get-symb-type (symb)
9 ((documentation symb 'variable) :variable)
10 ((documentation symb 'structure) :structure)
11 ((documentation symb 'function) :function)))
13 (defun validate-package (pkg)
14 "VALIDATE-PACKAGE PKG => FAILURES
17 FAILURE: (:failure SYMB MSG)
22 SYMB: Symbol the check failed on
23 MSG: Message containing information about the failure
27 VALIDATE-PACKAGE takes in PKG and validates that all the external symbols
28 adhere to documentation guidelines, exist, and can be parsed to be used
31 Only one error per symbol will be reported at a time, all concatenated to
32 a list in the aforementioned form."
34 ((with-success-check (symb &rest f)
37 (validation-failure (v) (list :failure ,symb (validation-failure-msg v))))))
40 (do-external-symbols (symb pkg) (push symb symbs))
41 (setf symbs (sort symbs #'string< :key #'symbol-name))
44 (list (with-success-check pkg (sheep-pkg:doc->ast (find-package pkg))))
47 (with-success-check symb
48 (case (get-symb-type symb)
49 (:function (sheep-func:doc->ast symb))
50 (:structure (sheep-struc:doc->ast symb))
51 (:variable (sheep-var:doc->ast symb))
52 (t (error (make-condition 'validation-failure :msg (format nil "Symbol ~A has no documentation" symb)))))))
55 (defun pretty-print-validate-packages (&rest pkgs)
56 "PRETTY-PRINT-VALIDATE-PACKAGES &rest PKGS => SUCCESS
62 SUCCESS: Whether or not all symbols passed validation
67 PRETTY-PRINT-VALIDATE-PACKAGES takes PKGS and runs validation on all of them.
68 It dumps to standard out failures as it comes upon them, finally returning
69 whether it was successful or not.
71 This can be used in validation tests to ensure that documentation can be generated
76 (pretty-print-validate-packages :pkg1 :pkg2) => t"
82 ((failures (validate-package pkg)))
85 (format t "In ~A : ~A, documentation error found:~% ~A~%" pkg (second failure) (third failure)))
90 (defun table-of-contents (pkg)
91 (format nil "## Contents~%~%~{~{* **~A [~A](#~A)** - ~A~}~%~}"
94 (do-external-symbols (symb pkg) (push symb symbs))
95 (setf symbs (sort symbs #'string< :key #'symbol-name))
98 (case (get-symb-type symb)
101 (sheep-func:ast->category-name (sheep-func:doc->ast symb))
102 (sheep-func:ast->short-name (sheep-func:doc->ast symb))
103 (sheep-func:ast->link (sheep-func:doc->ast symb))
104 (sheep-func:ast->short-desc (sheep-func:doc->ast symb))))
107 (sheep-struc:ast->category-name (sheep-struc:doc->ast symb))
108 (sheep-struc:ast->short-name (sheep-struc:doc->ast symb))
109 (sheep-struc:ast->link (sheep-struc:doc->ast symb))
110 (sheep-struc:ast->short-desc (sheep-struc:doc->ast symb))))
113 (sheep-var:ast->category-name (sheep-var:doc->ast symb))
114 (sheep-var:ast->short-name (sheep-var:doc->ast symb))
115 (sheep-var:ast->link (sheep-var:doc->ast symb))
116 (sheep-var:ast->short-desc (sheep-var:doc->ast symb))))))
119 (defun export-package (pkg)
120 "EXPORT-PACKAGE PKG => MARKDOWN
122 ARGUMENTS AND VALUES:
124 PKG: A package symbol
125 MARKDOWN: A string containing the markdown representation of this packages documentation
129 EXPORT-PACKAGE takes in PKG and converts all the documentation for the symbols
130 into markdown with the hope of emulating the hyperspec style.
132 It should only be run after the package has been validated, as it assumes that
133 all documentation it gets will be valid."
136 (do-external-symbols (symb pkg) (push symb symbs))
137 (setf symbs (sort symbs #'string< :key #'symbol-name))
138 (with-output-to-string (str)
139 (format str "~A~%~%" (sheep-pkg:ast->md (sheep-pkg:doc->ast (find-package pkg))))
140 (format str "~A~%" (table-of-contents pkg))
141 (format str "~{~A~^~%~}"
144 (case (get-symb-type symb)
145 (:variable (sheep-var:ast->md (sheep-var:doc->ast symb)))
146 (:function (sheep-func:ast->md (sheep-func:doc->ast symb)))
147 (:structure (sheep-struc:ast->md (sheep-struc:doc->ast symb)))))