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