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