Debian Codegraph @

doc/extract-doc.scm

raw
1 ;;; -*- mode: scheme; coding: utf-8; -*-
2 ;;;
3 ;;; Copyright 2005, 2006, 2007, 2010 Ludovic Courtès <[email protected]>
4 ;;;
5 ;;;
6 ;;; This program is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 2 of the License, or
9 ;;; (at your option) any later version.
10 ;;;
11 ;;; This program is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program; if not, write to the Free Software
18 ;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20
21 (define-module (extract-doc)
22 #:use-module (system reader)
23 #:use-module (system reader library)
24 #:use-module (srfi srfi-1)
25 #:use-module (srfi srfi-13)
26 #:use-module (ice-9 documentation))
27
28 ;;; Author: Ludovic Courtès
29 ;;;
30 ;;; Commentary:
31 ;;;
32 ;;; Extract documentation of the standard token readers and print them in a
33 ;;; Texinfo-friendly form so that they can be included in the manual.
34 ;;;
35 ;;; Code:
36
37 (define (extract-token-reader-doc)
38 (define (show-char-escaped chr)
39 (string-append "#\\"
40 (case chr
41 ((#\{ #\} #\@) "@")
42 (else ""))
43 (string-drop (with-output-to-string
44 (lambda ()
45 (write chr)))
46 2)))
47
48 (define (char-spec-doc spec)
49 (cond ((char? spec)
50 (format #f "@code{~a}" (show-char-escaped spec)))
51 ((list? spec)
52 (let ((len (length spec)))
53 (format #f "~a characters, @code{~a}... @code{~a}"
54 len (show-char-escaped (car spec))
55 (show-char-escaped (car (drop spec (- len 1)))))))
56 ((pair? spec)
57 (format #f "from @code{~a} to @code{~a}"
58 (show-char-escaped (car spec))
59 (show-char-escaped (cdr spec))))
60 (else
61 (error "invalid character specification" spec))))
62
63 (format #t "~%@multitable @columnfractions .25 .25 .50~%")
64 (format #t "@headitem Token Reader~%@tab Character Spec.~%@tab Description~%~%")
65 (for-each (lambda (tr-name)
66 (let* ((tr (standard-token-reader tr-name))
67 (spec-doc (char-spec-doc (token-reader-specification tr)))
68 (doc (token-reader-documentation tr)))
69 (format #t "@item @code{~a}~%@tab ~a~%@tab ~a~%~%"
70 tr-name spec-doc doc)))
71 (sort (standard-token-reader-names)
72 (lambda (s1 s2)
73 (string<=? (symbol->string s1)
74 (symbol->string s2)))))
75 (format #t "~%@end multitable~%"))
76
77 (define (output-args args)
78 (let loop ((args args))
79 (cond ((null? args) (format #t "~%"))
80 ((list? args)
81 (format #t "~a " (car args))
82 (loop (cdr args)))
83 ((pair? args)
84 (format #t "~a ~a@dots{}~%" (car args) (cdr args))))))
85
86 (define (extract-module-doc module)
87 "Issue documentation for the documented procedures exported by
88 @var{module}."
89 (module-for-each (lambda (binding var)
90 (let* ((obj (module-ref module binding))
91 (doc (object-documentation obj)))
92 (if (and (procedure? obj) doc)
93 (let* ((src (procedure-source obj))
94 (args (if src (cadr src) '())))
95 (format #t "~%@deffn {Scheme Procedure} ~a "
96 binding)
97 (output-args args)
98 (format #t "~a~%" doc)
99 (format #t "@end deffn~%")))))
100 (module-public-interface module)))
101
102 (define (extract-reader-lib-doc)
103 (extract-module-doc (resolve-module '(system reader library))))
104
105
106 (define-public (extract-doc . args)
107 (with-output-to-file "token-reader-doc.texi"
108 extract-token-reader-doc)
109
110 (with-output-to-file "reader-lib-doc.texi"
111 extract-reader-lib-doc))
112
113 (define main extract-doc)
114
115 ;;; arch-tag: e6ff91db-72f3-4b1c-8cec-ccc6305b2fd1
116
117 ;;; extract-doc.scm ends here