Add holistic checking
[sheep] / src / main / docgen.lisp
1 (in-package #:docgen)
2
3 (define-condition validation-failure nil ((msg :initarg :msg :reader validation-failure-msg)))
4
5 (defun get-symb-type (symb)
6  (cond
7   ;((documentation symb 'variable) :variable)
8   ;((documentation symb 'structure) :structure)
9   ((documentation symb 'function) :function)))
10
11 (defun validate-package (pkg)
12  (macrolet
13   ((with-success-check (&rest f)
14     `(handler-case
15       (progn ,@f :success)
16       (validation-failure (v) (list :failure (validation-failure-msg v))))))
17   (let
18    ((symbs nil))
19    (do-external-symbols (symb pkg) (push symb symbs))
20    (setf symbs (sort symbs #'string< :key #'symbol-name))
21    (remove :success
22     (append
23      (list (with-success-check (docgen-pkg:doc->ast (find-package pkg))))
24      (mapcar
25       (lambda (symb)
26        (with-success-check
27         (case (get-symb-type symb)
28          (:function (docgen-func:doc->ast symb))
29          (t (error (make-condition 'validation-failure :msg (format nil "Symbol ~A has no documentation" symb)))))))
30       symbs))))))
31
32 (defun pretty-print-validate-packages (&rest pkgs)
33  (mapcar
34   (lambda (pkg)
35    (let
36     ((failures (validate-package pkg)))
37     (mapcar
38      (lambda (failure)
39       (format t "In package ~A, documentation error found:~%  ~A" pkg (cadr failure)))
40      failures)
41     (not failures)))
42   pkgs))
43
44 (defun export-package (pkg)
45  (let
46   ((symbs nil))
47   (do-external-symbols (symb pkg) (push symb symbs))
48   (setf symbs (sort symbs #'string< :key #'symbol-name))
49   (with-output-to-string (str)
50    (format str "~A~%~%" (docgen-pkg:ast->md (docgen-pkg:doc->ast (find-package pkg))))
51    (format str "~{~A~^~%~}"
52     (mapcar
53      (lambda (symb)
54       (case (get-symb-type symb)
55        (:function (docgen-func:ast->md (docgen-func:doc->ast symb)))))
56      symbs)))))