-
Notifications
You must be signed in to change notification settings - Fork 5
/
clhs-docstrings.lisp
60 lines (53 loc) · 2.5 KB
/
clhs-docstrings.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(require :clhs)
(require :alexandria)
(require :hyperspec-lookup)
(require :str)
(defpackage :clhs-docstrings
(:use :cl)
(:export :create-file-with-docstrings))
(in-package :clhs-docstrings)
(setf hyperspec::*hyperspec-root* (princ-to-string (clhs:hyperspec-root)))
(defmacro condp (predicate &body clauses)
"COND using PREDICATE."
(let ((pred (gensym)))
`(let ((,pred ,predicate))
(cond
,@(loop for clause in clauses
collect `((funcall ,pred ,(car clause))
,@(cdr clause)))))))
(defun create-file-with-docstrings (file &optional (method :append))
(check-type method (member :append :replace))
(with-open-file (f file :direction :output
:if-does-not-exist :create
:if-exists :supersede)
(do-external-symbols (symbol :cl)
(let ((hyperspec-file (hyperspec:lookup (symbol-name symbol))))
(when (and hyperspec-file (probe-file hyperspec-file))
(let ((hyperspec-text
(string-trim '(#\space #\newline #\tab)
(with-output-to-string (s)
(uiop:run-program (format nil "html2text -style pretty ~a" hyperspec-file)
:output s))))
(doc-type (condp (lambda (x) (str:starts-with-p x (pathname-name hyperspec-file)))
("v_" 'variable)
("f_" 'function)
("m_" 'function)
("t_" 'type)
("a_" nil) ;; ignore for now
("d_" nil) ;; ignore for now
("e_" nil)
(""
;;(error "Unrecognized: ~a" (pathname-name hyperspec-file))
nil
))))
(format t ".")
(when doc-type
(let ((docstring (documentation symbol doc-type)))
(write `(setf (documentation ',symbol ',doc-type)
,(if (and docstring (eql method :append))
(format nil "~a~%~%~a" (string-trim '(#\space #\newline #\tab) docstring) hyperspec-text)
hyperspec-text))
:stream f))
(terpri f)(terpri f))))))))
;; (create-file-with-docstrings "/mnt/sdb2/home/marian/src/lisp/slime-star/slime-doc-contribs/clhs-docstrings.gen.lisp")
;; (load "/mnt/sdb2/home/marian/src/lisp/slime-star/slime-doc-contribs/clhs-docstrings.gen.lisp")