]> git.donarmstrong.com Git - lilypond.git/commitdiff
Document music functions too.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 6 Dec 2006 16:19:01 +0000 (17:19 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Wed, 6 Dec 2006 16:19:01 +0000 (17:19 +0100)
lily/include/music-function.hh
lily/music-function-scheme.cc [new file with mode: 0644]
lily/music-function.cc
scm/c++.scm
scm/document-identifiers.scm [new file with mode: 0644]
scm/document-markup.scm
scm/documentation-generate.scm
scm/lily.scm

index 1e9cbfe30752d08085a9b08de298a47168c24e58..723472bd78d400b07f18f55149decfb2f3ddf55c 100644 (file)
@@ -12,6 +12,8 @@
 #include "lily-guile.hh"
 
 SCM ly_make_music_function (SCM, SCM);
+SCM make_music_function (SCM, SCM);
+
 SCM get_music_function_transform (SCM);
 bool is_music_function (SCM);
 
diff --git a/lily/music-function-scheme.cc b/lily/music-function-scheme.cc
new file mode 100644 (file)
index 0000000..06e57f0
--- /dev/null
@@ -0,0 +1,30 @@
+#include "music-function.hh"
+
+LY_DEFINE (ly_music_function_p, "ly:music-function?", 1, 0, 0,
+          (SCM x),
+          "Is @var{x} an @code{music-function}?")
+{
+  return is_music_function (x) ? SCM_BOOL_T : SCM_BOOL_F;
+}
+                
+LY_DEFINE (ly_music_function_extract, "ly:music-function-extract", 1, 0, 0,
+          (SCM x),
+          "Return the Scheme function inside @var{x}")
+{
+  SCM_ASSERT_TYPE(is_music_function (x), x, SCM_ARG1, __FUNCTION__,
+                 "music function");
+  
+  return SCM_CELL_OBJECT_1(x);
+}
+
+LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0,
+          (SCM signature, SCM func),
+          "Make a function to process music, to be used for the "
+          "parser. @code{func} is the function, and @code{signature} describes "
+          "Its arguments. @code{signature} is a list containing either "
+          "@code{ly:music?} predicates or other type predicates.")
+{
+  SCM_ASSERT_TYPE(ly_is_procedure (func), func, SCM_ARG1, __FUNCTION__, "function");
+  return  make_music_function (signature, func);
+}
+
index 6795ca67d4566c7aa1fb41b01bfaf0a62ccda08d..6a97db4a5515cd3e8328454249b63f83d4ecd257 100644 (file)
@@ -26,19 +26,6 @@ print_music_function (SCM b, SCM port, scm_print_state *)
   return 1;
 }
 
-LY_DEFINE (ly_make_music_function, "ly:make-music-function", 2, 0, 0,
-          (SCM signature, SCM func),
-          "Make a function to process music, to be used for the "
-          "parser. @code{func} is the function, and @code{signature} describes "
-          "Its arguments. @code{signature} is a list containing either "
-          "@code{ly:music?} predicates or other type predicates.")
-{
-  scm_set_object_property_x (func, ly_symbol2scm ("music-function-signature"),
-                            signature);
-
-  SCM_RETURN_NEWSMOB (music_function_tag, func);
-}
-
 bool
 is_music_function (SCM music_function)
 {
@@ -62,4 +49,14 @@ init_music_function (void)
   scm_set_smob_print (music_function_tag, print_music_function);
 }
 
+SCM
+make_music_function (SCM signature, SCM func)
+{
+  scm_set_object_property_x (func, ly_symbol2scm ("music-function-signature"),
+                            signature);
+
+  SCM_RETURN_NEWSMOB (music_function_tag, func);
+}
+
 ADD_SCM_INIT_FUNC (music_function_tag, init_music_function);
+
index 7069ca1a41e32e2b2e42fa59f58b0ee55f4ec7f5..800d08bfe6b8f2578edeb7ff5c198660d628c12e 100644 (file)
 
 (define-public (object-type obj)
   (match-predicate obj type-p-name-alist))
+
 (define-public (object-type-name obj)
   (type-name (match-predicate obj type-p-name-alist)))
+
 (define-public (type-name predicate)
   (let ((entry (assoc predicate type-p-name-alist)))
     (if (pair? entry) (cdr entry)
diff --git a/scm/document-identifiers.scm b/scm/document-identifiers.scm
new file mode 100644 (file)
index 0000000..83c4fbd
--- /dev/null
@@ -0,0 +1,56 @@
+(use-modules (ice-9 format))
+
+(define (document-music-function music-func-pair)
+  (let*
+      ((name-sym (car music-func-pair))
+       (music-func (cdr music-func-pair))
+       (func (ly:music-function-extract music-func))
+       (arg-names
+       (map symbol->string 
+            (cddr (cadr (procedure-source func)))))
+       (doc (procedure-documentation func))
+       (sign (object-property func 'music-function-signature))
+       (type-names (map type-name sign))
+
+       ;; C&P
+       (signature (zip arg-names arg-names type-names))
+       (signature-str
+         (string-join
+          (map (lambda (x) (format "@var{~a} (~a)"
+                                   (car x)
+                                   (cadr x)))
+                                   
+               (zip arg-names type-names)))))
+
+    (format
+     
+     "\n
+@item @code{~a} - ~a\n
+@findex ~a
+
+~a\n\n"
+
+     name-sym signature-str
+     name-sym
+     (if doc doc "(undocumented; fixme)"))))
+
+
+
+(define (document-object obj-pair)
+  (cond
+   ((ly:music-function? (cdr obj-pair)) (document-music-function obj-pair))
+   (else
+    #f)))
+
+(define-public (identifiers-doc-string)
+  (format
+   "@table @asis
+~a
+@end table
+"
+  (string-join
+   (filter
+    identity
+   (map
+    document-object
+    (ly:module->alist (current-module)))))))
index c2257640a97ef323e9f50f01969cef425ceb8244..9a5e51eb19e7ec53349febb59f85747f70300b2e 100644 (file)
@@ -15,7 +15,6 @@
               (cddr (cadr (procedure-source func)))))
         
         (sig-type-names (map type-name sig))
-        (signature (zip arg-names  sig-type-names))
         (signature-str
          (string-join
           (map (lambda (x) (string-append
index 6143f60993cf5ccf5a2ef0b01db4a49a01bcaede..b44fc12e0e0ae5e464d88417a05fd1451beef32d 100644 (file)
@@ -20,6 +20,7 @@
               "document-functions.scm"
               "document-translation.scm"
               "document-music.scm"
+              "document-identifiers.scm"
               "document-backend.scm"
               "document-markup.scm"))
 
  (markup-doc-string)
  (open-output-file "markup-commands.tely"))
 
+(display 
+ (identifiers-doc-string)
+ (open-output-file "identifiers.tely"))
+
 
 (display
  (backend-properties-doc-string all-user-grob-properties)
index 01533949fd5d6dbc2a1326153b7d77feaed2e2de..495ef18cbc57ce7055501bef6a7c53de9fb72c2d 100644 (file)
@@ -139,7 +139,7 @@ on errors, and print a stack trace.")
     (if (ly:get-option 'verbose)
        (ly:progress "[~A" file-name))
     (if (not file-name)
-       (ly:error (_ "Can't find ~A" x)))
+       (ly:error (_ "Can't find ~A") x))
     (primitive-load file-name)
     (if (ly:get-option 'verbose)
        (ly:progress "]"))))