]> git.donarmstrong.com Git - lilypond.git/blob - scm/document-backend.scm
Run grand-replace (issue 3765)
[lilypond.git] / scm / document-backend.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2000--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;; Jan Nieuwenhuizen <janneke@gnu.org>
5 ;;;;
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.
10 ;;;;
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.
15 ;;;;
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/>.
18
19 (define (sort-grob-properties x)
20   ;; force 'meta to the end of each prop-list
21   (let ((meta (assoc 'meta x)))
22     (append (sort (assoc-remove! x 'meta) ly:alist-ci<?)
23             (list meta))))
24
25 ;; properly sort all grobs, properties, and interfaces
26 ;; within the all-grob-descriptions alist
27 (for-each
28  (lambda (x)
29    (let* ((props      (assoc-ref all-grob-descriptions (car x)))
30           (meta       (assoc-ref props 'meta))
31           (interfaces (assoc-ref meta 'interfaces)))
32      (set! all-grob-descriptions
33            (sort (assoc-set! all-grob-descriptions (car x)
34                              (sort-grob-properties
35                               (assoc-set! props 'meta
36                                           (assoc-set! meta 'interfaces
37                                                       (sort interfaces ly:symbol-ci<?)))))
38                  ly:alist-ci<?))))
39  all-grob-descriptions)
40
41 (define (interface-doc-string interface grob-description)
42   (let* ((name (car interface))
43          (desc (cadr interface))
44          (props (caddr interface))
45          (docfunc (lambda (pr)
46                     (property->texi
47                      'backend pr grob-description)))
48          (iprops (filter (lambda (x) (object-property x 'backend-internal))
49                          props))
50          (uprops (filter
51                   (lambda (x) (not (object-property x 'backend-internal)))
52                   props))
53          (user-propdocs (map docfunc uprops))
54          (internal-propdocs (map docfunc iprops)))
55
56     (string-append
57      desc
58
59      (if (pair? uprops)
60          (string-append
61           "\n\n@subsubheading User settable properties:\n"
62           (description-list->texi user-propdocs #t))
63          "")
64
65      (if (pair? iprops)
66          (string-append
67           "\n\n@subsubheading Internal properties:\n"
68           (description-list->texi internal-propdocs #t))
69          ""))))
70
71 (define iface->grob-table (make-hash-table 61))
72 ;; extract ifaces, and put grob into the hash table.
73 (for-each
74  (lambda (x)
75    (let* ((meta (assoc-get 'meta (cdr x)))
76           (ifaces (assoc-get 'interfaces meta)))
77
78      (for-each (lambda (iface)
79                  (hashq-set!
80                   iface->grob-table iface
81                   (cons (car x)
82                         (hashq-ref iface->grob-table iface '()))))
83                ifaces)))
84  all-grob-descriptions)
85
86 ;; First level Interface description
87 (define (interface-doc interface)
88   (let* ((name (symbol->string (car interface)))
89          (interface-list (human-listify
90                           (map ref-ify
91                                (sort
92                                 (map symbol->string
93                                      (hashq-ref iface->grob-table
94                                                 (car interface)
95                                                 '()))
96                                 ly:string-ci<?)))))
97     (make <texi-node>
98       #:name name
99       #:text (string-append
100               (interface-doc-string (cdr interface) '())
101               "\n\n"
102               "This grob interface "
103               (if (equal? interface-list "none")
104                   "is not used in any graphical object"
105                   (string-append
106                    "is used in the following graphical object(s): "
107                    interface-list))
108               "."))))
109
110 (define (grob-alist->texi alist)
111   (let* ((uprops (filter (lambda (x) (not (object-property x 'backend-internal)))
112                          (map car alist))))
113
114     (description-list->texi
115      (map (lambda (y) (property->texi 'backend y alist))
116           uprops)
117      #t)))
118
119 (define (grob-doc description)
120   "Given a property alist DESCRIPTION, make a documentation
121 node."
122
123   (let* ((meta (assoc-get 'meta description))
124          (name (assoc-get 'name meta))
125          ;;       (bla (display name))
126          (ifaces (map lookup-interface (assoc-get 'interfaces meta)))
127          (ifacedoc (map ref-ify
128                         (sort
129                          (map (lambda (iface)
130                                 (if (pair? iface)
131                                     (symbol->string (car iface))
132                                     (ly:error (_ "pair expected in doc ~s") name)))
133                               ifaces)
134                          ly:string-ci<?)))
135          (engravers (filter
136                      (lambda (x) (engraver-makes-grob? name x))
137                      all-engravers-list))
138          (namestr (symbol->string name))
139          (engraver-names (map symbol->string
140                               (map ly:translator-name engravers)))
141          (engraver-list (human-listify
142                          (map ref-ify
143                               (map engraver-name engraver-names)))))
144
145     (make <texi-node>
146       #:name namestr
147       #:text
148       (string-append
149        namestr " objects "
150        (if (equal? engraver-list "none")
151            "are not created by any engraver"
152            (string-append
153             "are created by: "
154             engraver-list))
155        "."
156
157        "\n\nStandard settings:\n\n"
158        (grob-alist->texi description)
159        "\n\nThis object supports the following interface(s):\n"
160        (human-listify ifacedoc)
161        "."))))
162
163 (define (all-grobs-doc)
164   (make <texi-node>
165     #:name "All layout objects"
166     #:desc "Description and defaults for all graphical objects (grobs)."
167     #:children
168     (map (lambda (x) (grob-doc (cdr x)))  all-grob-descriptions)))
169
170 (define interface-description-alist
171   (hash-fold
172    (lambda (key val prior)
173      (cons (cons key val)  prior))
174    '() (ly:all-grob-interfaces)))
175
176 (set! interface-description-alist
177       (sort interface-description-alist ly:alist-ci<?))
178
179 ;;;;;;;;;; check for dangling backend properties.
180 (define (mark-interface-properties entry)
181   (for-each (lambda (x) (set-object-property! x 'iface-marked #t))
182             (caddr (cdr entry))))
183
184 (for-each mark-interface-properties interface-description-alist)
185
186 (define (check-dangling-properties prop)
187   (if (not (object-property prop 'iface-marked))
188       (ly:error (string-append "define-grob-properties.scm: "
189                                (_ "cannot find interface for property: ~S")) prop)))
190
191 (for-each check-dangling-properties all-backend-properties)
192
193 ;;;;;;;;;;;;;;;;
194
195 (define (lookup-interface name)
196   (let* ((entry (hashq-ref (ly:all-grob-interfaces) name #f)))
197     (if entry
198         entry
199         (ly:error (_ "unknown Grob interface: ~S") name))))
200
201 (define (all-interfaces-doc)
202   (make <texi-node>
203     #:name "Graphical Object Interfaces"
204     #:desc "Building blocks of graphical objects."
205     #:children
206     (map interface-doc interface-description-alist)))
207
208 (define (backend-properties-doc-string lst)
209   (let* ((ps (sort (map symbol->string lst) ly:string-ci<?))
210          (descs (map (lambda (prop)
211                        (property->texi 'backend (string->symbol prop) '())) ps))
212          (texi (description-list->texi descs #f)))
213     texi))
214
215 ;;(dump-node (grob-doc (cdadr all-grob-descriptions)) (current-output-port) 0 )
216 (define (backend-doc-node)
217   (make <texi-node>
218     #:name "Backend"
219     #:desc "Reference for the layout engine."
220     #:children
221     (list
222      (all-grobs-doc)
223      (all-interfaces-doc)
224      (make <texi-node>
225        #:name "User backend properties"
226        #:desc "All tunable properties in a big list."
227        #:text (backend-properties-doc-string all-user-grob-properties))
228      (make <texi-node>
229        #:name "Internal backend properties"
230        #:desc "All internal layout properties in a big list."
231        #:text (backend-properties-doc-string all-internal-grob-properties)))))