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