1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;; LilyPond 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 3 of the License, or
9 ;;;; (at your option) any later version.
11 ;;;; LilyPond 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.
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
19 (use-modules (oop goops)
24 (use-modules (ice-9 curried-definitions)))
26 (define-class <texi-node> ()
27 (appendix #:init-value #f #:accessor appendix? #:init-keyword #:appendix)
28 (children #:init-value '() #:accessor node-children #:init-keyword #:children)
29 (text #:init-value "" #:accessor node-text #:init-keyword #:text)
30 (name #:init-value "" #:accessor node-name #:init-keyword #:name)
31 (description #:init-value "" #:accessor node-desc #:init-keyword #:desc))
33 (define (menu-entry x)
38 (define* (dump-node node port level)
42 (if (= level 0) "Top" (node-name node))
45 (texi-appendix-section-command level)
46 (texi-section-command level))
52 (if (pair? (node-children node))
54 (map (lambda (x) (menu-entry x))
55 (node-children node)))
58 (for-each (lambda (x) (dump-node x port (+ 1 level)))
59 (node-children node)))
61 (define (processing name)
62 (ly:basic-progress (_ "Processing ~S...") name))
64 (define (scm->texi val)
65 (let* (; always start on a new line
66 (open-texi (if (pretty-printable? val)
69 (close-texi (if (pretty-printable? val)
72 (string-append open-texi (scm->string val) close-texi)))
74 (define (texi-section-command level)
76 ;; Hmm, texinfo doesn't have ``part''
81 (4 . "@unnumberedsubsubsec")
82 (5 . "@unnumberedsubsubsec"))))
84 (define (texi-appendix-section-command level)
85 (assoc-get level '((0 . "@top")
88 (3 . "@appendixsubsec")
89 (4 . "@appendixsubsubsec")
90 (5 . "@appendixsubsubsec"))))
92 (define (one-item->texi label-desc-pair)
93 "Document one (LABEL . DESC); return empty string if LABEL is empty string."
94 (if (eq? (car label-desc-pair) "")
96 (string-append "\n\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))))
99 (define (description-list->texi items-alist quote?)
100 "Document ITEMS-ALIST in a table; entries contain (item-label .
101 string-to-use). If QUOTE? is #t, embed table in a @quotation environment."
104 (if quote? "@quotation\n" "")
106 (string-concatenate (map one-item->texi items-alist))
109 (if quote? "@end quotation\n" "")))
111 (define (texi-menu items-alist)
112 "Generate what is between @menu and @end menu."
114 (apply max (map (lambda (x) (string-length (car x))) items-alist))))
122 (string-append "\n* " (car x) ":: ")
127 ;; Menus don't appear in html, so we make a list ourselves
130 (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
136 (define (texi-file-head name file-name top)
138 "\\input texinfo @c -*-texinfo-*-"
139 "\n@setfilename " file-name ".info"
141 "\n@dircategory LilyPond"
143 ;; prepend GNU for dir, must be unique
144 "\n* GNU " name ": (" file-name "). " name "."
146 "@documentlanguage en\n"
147 "@documentencoding utf-8\n"))
149 (define (context-name name)
152 (define (engraver-name name)
155 (define (grob-name name)
157 (symbol->string name)
160 (define (interface-name name)
164 "Return @ref{X}. If mapping ref-ify to a list that needs to be sorted,
165 sort the list first."
166 (string-append "@ref{" x "}"))
168 (define (human-listify lst)
169 "Produce a textual enumeration from LST, a list of strings"
173 ((null? (cdr lst)) (car lst))
174 ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
175 (else (string-append (car lst) ", " (human-listify (cdr lst))))))
177 (define (writing-wip x)
178 (ly:message (_ "Writing ~S...") x))
180 (define (identifier<? a b)
182 (symbol->string (car a))
183 (symbol->string (car b))))
185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
188 (define (verify-type-name where sym type)
190 (ly:error (_ "cannot find description for property `~S' (~S)")
195 (define (property->texi where sym . rest)
196 "Document SYM for WHERE (which can be translation, backend, music),
197 with init values from ALIST (1st optional argument)
199 (let* ((name (symbol->string sym))
200 (alist (if (pair? rest) (car rest) '()))
201 (type?-name (string->symbol
202 (string-append (symbol->string where) "-type?")))
203 (doc-name (string->symbol
204 (string-append (symbol->string where) "-doc")))
205 (type (object-property sym type?-name))
206 (typename (verify-type-name where sym type))
207 (desc (object-property sym doc-name))
208 (init-value (assoc-get sym alist)))
211 (ly:error (_ "cannot find description for property ~S (~S)") sym where))
214 (string-append "@code{" name "} (" typename ")"
216 (string-append ":" (scm->texi init-value) "\n")