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