]> git.donarmstrong.com Git - lilypond.git/blob - scm/document-backend.scm
d291b2299cdad34e1d307931fd1fb8d1712dec4a
[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@unnumberedsubsubsec User settable properties:\n"
29           (description-list->texi user-propdocs #t))
30          "")
31
32      (if (pair? iprops)
33          (string-append
34           "\n\n@unnumberedsubsubsec 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     (make <texi-node>
58       #:name name
59       #:text (string-append
60               (interface-doc-string (cdr interface) '())
61               "\n\n"
62               "This grob interface is used in the following graphical objects: "
63               (human-listify
64                (map ref-ify
65                     (sort 
66                      (map symbol->string
67                           (hashq-ref iface->grob-table (car interface) '()))
68                      string<?)))
69               "."))))
70
71 (define (grob-alist->texi alist)
72   (let* ((uprops (filter (lambda (x) (not (object-property x 'backend-internal)))
73                          (map car alist))))
74
75     (description-list->texi
76      (map (lambda (y) (property->texi 'backend y alist))
77           uprops)
78      #t)))
79
80 (define (grob-doc description)
81   "Given a property alist DESCRIPTION, make a documentation
82 node."
83
84   (let* ((metah (assoc 'meta description))
85          (meta (cdr metah))
86          (name (cdr (assoc 'name meta)))
87          ;;       (bla (display name))
88          (ifaces (map lookup-interface (cdr (assoc 'interfaces meta))))
89          (ifacedoc (map (lambda (iface)
90                           (if (pair? iface)
91                               (ref-ify (symbol->string (car iface)))
92                               (ly:error (_ "pair expected in doc ~s") name)))
93                         (reverse ifaces)))
94          (engravers (filter
95                      (lambda (x) (engraver-makes-grob? name x)) all-engravers-list))
96          (namestr (symbol->string name))
97          (engraver-names (map symbol->string (map ly:translator-name engravers))))
98
99     (make <texi-node>
100       #:name namestr
101       #:text
102       (string-append
103        namestr " objects are created by: "
104        (human-listify (map ref-ify
105                            (map engraver-name engraver-names)))
106        "\n\nStandard settings: \n\n"
107        (grob-alist->texi description)
108        "\n\nThis object supports the following interfaces: \n"
109        (human-listify ifacedoc)))))
110
111 (define (all-grobs-doc)
112   (make <texi-node>
113     #:name "All layout objects"
114     #:desc "Description and defaults for all graphical objects (grobs)."
115     #:children
116     (map (lambda (x) (grob-doc (cdr x)))  all-grob-descriptions)))
117
118 (define interface-description-alist
119   (hash-fold
120    (lambda (key val prior)
121      (cons (cons key val)  prior))
122    '() (ly:all-grob-interfaces)))
123
124 (set! interface-description-alist (sort interface-description-alist alist<?))
125
126 ;;;;;;;;;; check for dangling backend properties.
127 (define (mark-interface-properties entry)
128   (map (lambda (x) (set-object-property! x 'iface-marked #t))
129        (caddr (cdr entry))))
130
131 (map mark-interface-properties interface-description-alist)
132
133 (define (check-dangling-properties prop)
134   (if (not (object-property prop 'iface-marked))
135       (ly:error (string-append "define-grob-properties.scm: "
136                 (_ "cannot find interface for property: ~S")) prop)))
137
138 (map check-dangling-properties all-backend-properties)
139
140 ;;;;;;;;;;;;;;;;
141
142 (define (lookup-interface name)
143   (let* ((entry (hashq-ref (ly:all-grob-interfaces) name #f)))
144     (if entry
145         entry
146         (ly:error (_ "unknown Grob interface: ~S") name))))
147
148 (define (all-interfaces-doc)
149   (make <texi-node>
150     #:name "Graphical Object Interfaces"
151     #:desc "Building blocks of graphical objects."
152     #:children
153     (map interface-doc interface-description-alist)))
154
155 (define (backend-properties-doc-string lst)
156   (let* ((ps (sort (map symbol->string lst) string<?))
157          (descs (map (lambda (prop)
158                        (property->texi 'backend (string->symbol prop) '())) ps))
159          (texi (description-list->texi descs #f)))
160     texi))
161
162 ;;(dump-node (grob-doc (cdadr all-grob-descriptions)) (current-output-port) 0 )
163 (define (backend-doc-node)
164   (make <texi-node>
165     #:name "Backend"
166     #:desc "Reference for the layout engine."
167     #:children
168     (list
169      (all-grobs-doc)
170      (all-interfaces-doc)
171      (make <texi-node>
172        #:name "User backend properties"
173        #:desc "All tunable properties in a big list."
174        #:text (backend-properties-doc-string all-user-grob-properties))
175      (make <texi-node>
176        #:name "Internal backend properties"
177        #:desc "All internal layout properties in a big list."
178        #:text (backend-properties-doc-string all-internal-grob-properties)))))