1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2000--2015 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 menu-entry (node-children node)))
57 (for-each (lambda (x) (dump-node x port (+ 1 level)))
58 (node-children node)))
60 (define (processing name)
61 (ly:basic-progress (_ "Processing ~S...") name))
63 (define (scm->texi val)
64 (let* (; always start on a new line
65 (open-texi (if (pretty-printable? val)
68 (close-texi (if (pretty-printable? val)
71 (string-append open-texi (scm->string val) close-texi)))
73 (define (texi-section-command level)
75 ;; Hmm, texinfo doesn't have ``part''
80 (4 . "@unnumberedsubsubsec")
81 (5 . "@unnumberedsubsubsec"))))
83 (define (texi-appendix-section-command level)
84 (assoc-get level '((0 . "@top")
87 (3 . "@appendixsubsec")
88 (4 . "@appendixsubsubsec")
89 (5 . "@appendixsubsubsec"))))
91 (define (one-item->texi label-desc-pair)
92 "Document one (LABEL . DESC); return empty string if LABEL is empty string."
93 (if (eq? (car label-desc-pair) "")
95 (string-append "\n\n@item " (car label-desc-pair) "\n" (cdr label-desc-pair))))
98 (define (description-list->texi items-alist quote?)
99 "Document ITEMS-ALIST in a table; entries contain (item-label .
100 string-to-use). If QUOTE? is #t, embed table in a @quotation environment."
103 (if quote? "@quotation\n" "")
105 (string-concatenate (map one-item->texi items-alist))
108 (if quote? "@end quotation\n" "")))
110 (define (texi-menu items-alist)
111 "Generate what is between @menu and @end menu."
113 (apply max (map (lambda (x) (string-length (car x))) items-alist))))
121 (string-append "\n* " (car x) ":: ")
126 ;; Menus don't appear in html, so we make a list ourselves
129 (description-list->texi (map (lambda (x) (cons (ref-ify (car x)) (cdr x)))
135 (define (texi-file-head name file-name top)
137 "\\input texinfo @c -*-texinfo-*-"
138 "\n@setfilename " file-name ".info"
140 "\n@dircategory LilyPond"
142 ;; prepend GNU for dir, must be unique
143 "\n* GNU " name ": (" file-name "). " name "."
145 "@documentlanguage en\n"
146 "@documentencoding UTF-8\n"))
148 (define (context-name name)
151 (define (engraver-name name)
154 (define (grob-name name)
156 (symbol->string name)
159 (define (interface-name name)
163 "Return @ref{X}. If mapping ref-ify to a list that needs to be sorted,
164 sort the list first."
165 (string-append "@ref{" x "}"))
167 (define (human-listify lst)
168 "Produce a textual enumeration from LST, a list of strings"
172 ((null? (cdr lst)) (car lst))
173 ((null? (cddr lst)) (string-append (car lst) " and " (cadr lst)))
174 (else (string-append (car lst) ", " (human-listify (cdr lst))))))
176 (define (writing-wip x)
177 (ly:message (_ "Writing ~S...") x))
179 (define (identifier<? a b)
181 (symbol->string (car a))
182 (symbol->string (car b))))
184 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187 (define (verify-type-name where sym type)
189 (ly:error (_ "cannot find description for property `~S' (~S)")
194 (define (property->texi where sym . rest)
195 "Document SYM for WHERE (which can be translation, backend, music),
196 with init values from ALIST (1st optional argument)
198 (let* ((name (symbol->string sym))
199 (alist (if (pair? rest) (car rest) '()))
200 (type?-name (string->symbol
201 (string-append (symbol->string where) "-type?")))
202 (doc-name (string->symbol
203 (string-append (symbol->string where) "-doc")))
204 (type (object-property sym type?-name))
205 (typename (verify-type-name where sym type))
206 (desc (object-property sym doc-name))
207 (init-value (assoc-get sym alist)))
210 (ly:error (_ "cannot find description for property ~S (~S)") sym where))
213 (string-append "@code{" name "} (" typename ")"
215 (string-append ":" (scm->texi init-value) "\n")