]> git.donarmstrong.com Git - lilypond.git/blob - scm/document-backend.scm
Turn assoc calls into secure assoc-get calls.
[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* ((meta (assoc-get 'meta (cdr x)))
65           (ifaces (assoc-get 'interfaces meta)))
66
67      (map (lambda (iface)
68             (hashq-set!
69              iface->grob-table iface
70              (cons (car x)
71                    (hashq-ref iface->grob-table iface '()))))
72           ifaces)))
73  all-grob-descriptions)
74
75 ;; First level Interface description
76 (define (interface-doc interface)
77   (let* ((name (symbol->string (car interface)))
78          (interface-list (human-listify
79                           (map ref-ify
80                                (sort
81                                 (map symbol->string
82                                      (hashq-ref iface->grob-table
83                                                 (car interface)
84                                                 '()))
85                                 ly:string-ci<?)))))
86     (make <texi-node>
87       #:name name
88       #:text (string-append
89               (interface-doc-string (cdr interface) '())
90               "\n\n"
91               "This grob interface "
92               (if (equal? interface-list "none")
93                   "is not used in any graphical object"
94                   (string-append
95                    "is used in the following graphical object(s): "
96                    interface-list))
97               "."))))
98
99 (define (grob-alist->texi alist)
100   (let* ((uprops (filter (lambda (x) (not (object-property x 'backend-internal)))
101                          (map car alist))))
102
103     (description-list->texi
104      (map (lambda (y) (property->texi 'backend y alist))
105           uprops)
106      #t)))
107
108 (define (grob-doc description)
109   "Given a property alist DESCRIPTION, make a documentation
110 node."
111
112   (let* ((meta (assoc-get 'meta description))
113          (name (assoc-get 'name meta))
114          ;;       (bla (display name))
115          (ifaces (map lookup-interface (assoc-get 'interfaces meta)))
116          (ifacedoc (map ref-ify
117                         (sort
118                          (map (lambda (iface)
119                                 (if (pair? iface)
120                                     (symbol->string (car iface))
121                                     (ly:error (_ "pair expected in doc ~s") name)))
122                               ifaces)
123                          ly:string-ci<?)))
124          (engravers (filter
125                      (lambda (x) (engraver-makes-grob? name x))
126                      all-engravers-list))
127          (namestr (symbol->string name))
128          (engraver-names (map symbol->string
129                               (map ly:translator-name engravers)))
130          (engraver-list (human-listify
131                          (map ref-ify
132                               (map engraver-name engraver-names)))))
133
134     (make <texi-node>
135       #:name namestr
136       #:text
137       (string-append
138        namestr " objects "
139        (if (equal? engraver-list "none")
140            "are not created by any engraver"
141            (string-append
142             "are created by: "
143             engraver-list))
144        "."
145
146        "\n\nStandard settings:\n\n"
147        (grob-alist->texi description)
148        "\n\nThis object supports the following interface(s):\n"
149        (human-listify ifacedoc)
150        "."))))
151
152 (define (all-grobs-doc)
153   (make <texi-node>
154     #:name "All layout objects"
155     #:desc "Description and defaults for all graphical objects (grobs)."
156     #:children
157     (map (lambda (x) (grob-doc (cdr x)))  all-grob-descriptions)))
158
159 (define interface-description-alist
160   (hash-fold
161    (lambda (key val prior)
162      (cons (cons key val)  prior))
163    '() (ly:all-grob-interfaces)))
164
165 (set! interface-description-alist
166   (sort interface-description-alist ly:alist-ci<?))
167
168 ;;;;;;;;;; check for dangling backend properties.
169 (define (mark-interface-properties entry)
170   (map (lambda (x) (set-object-property! x 'iface-marked #t))
171        (caddr (cdr entry))))
172
173 (map mark-interface-properties interface-description-alist)
174
175 (define (check-dangling-properties prop)
176   (if (not (object-property prop 'iface-marked))
177       (ly:error (string-append "define-grob-properties.scm: "
178                 (_ "cannot find interface for property: ~S")) prop)))
179
180 (map check-dangling-properties all-backend-properties)
181
182 ;;;;;;;;;;;;;;;;
183
184 (define (lookup-interface name)
185   (let* ((entry (hashq-ref (ly:all-grob-interfaces) name #f)))
186     (if entry
187         entry
188         (ly:error (_ "unknown Grob interface: ~S") name))))
189
190 (define (all-interfaces-doc)
191   (make <texi-node>
192     #:name "Graphical Object Interfaces"
193     #:desc "Building blocks of graphical objects."
194     #:children
195     (map interface-doc interface-description-alist)))
196
197 (define (backend-properties-doc-string lst)
198   (let* ((ps (sort (map symbol->string lst) ly:string-ci<?))
199          (descs (map (lambda (prop)
200                        (property->texi 'backend (string->symbol prop) '())) ps))
201          (texi (description-list->texi descs #f)))
202     texi))
203
204 ;;(dump-node (grob-doc (cdadr all-grob-descriptions)) (current-output-port) 0 )
205 (define (backend-doc-node)
206   (make <texi-node>
207     #:name "Backend"
208     #:desc "Reference for the layout engine."
209     #:children
210     (list
211      (all-grobs-doc)
212      (all-interfaces-doc)
213      (make <texi-node>
214        #:name "User backend properties"
215        #:desc "All tunable properties in a big list."
216        #:text (backend-properties-doc-string all-user-grob-properties))
217      (make <texi-node>
218        #:name "Internal backend properties"
219        #:desc "All internal layout properties in a big list."
220        #:text (backend-properties-doc-string all-internal-grob-properties)))))