]> git.donarmstrong.com Git - lilypond.git/commitdiff
Create a nicer signature format for syntax functions. Fix their autogenerated docs.
authorDavid Kastrup <dak@gnu.org>
Mon, 12 Sep 2011 16:35:29 +0000 (18:35 +0200)
committerDavid Kastrup <dak@gnu.org>
Mon, 12 Sep 2011 17:15:11 +0000 (19:15 +0200)
lily/lexer.ll
lily/parser.yy
scm/document-identifiers.scm
scm/ly-syntax-constructors.scm
scm/music-functions.scm

index b445e707d78ff9e67579c45cfa249630cb620b44..db78e049f2597b09a0e772aa1f41e9e620aa12c3 100644 (file)
@@ -803,18 +803,23 @@ Lily_lexer::scan_escaped_word (string str)
        SCM sid = lookup_identifier (str);
        if (is_music_function (sid))
        {
-               int funtype = MUSIC_FUNCTION;
+               int funtype = SCM_FUNCTION;
 
                yylval.scm = get_music_function_transform (sid);
 
                SCM s = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
-               if (scm_is_eq (scm_car (s), ly_lily_module_constant ("scheme-function")))
+               SCM cs = scm_car (s);
+
+               if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
+                       funtype = MUSIC_FUNCTION;
+               else if (ly_is_procedure (cs))
                        funtype = SCM_FUNCTION;
-                              
+               else programming_error ("Bad syntax function predicate");
+
                push_extra_token (EXPECT_NO_MORE_ARGS);
                for (s = scm_cdr (s); scm_is_pair (s); s = scm_cdr (s))
                {
-                       SCM cs = scm_car (s);
+                       cs = scm_car (s);
                        
                        if (cs == ly_music_p_proc)
                                push_extra_token (EXPECT_MUSIC);
index 37ded754c716156fa5906572a46e1f7cd7001938..c38a4a2d5b8517b1a690d28951828c2d84ea9ba5 100644 (file)
@@ -2735,8 +2735,8 @@ run_music_function (Lily_parser *parser, Input loc, SCM func, SCM args)
                return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (loc)));
        }
 
-       SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (loc), func, args);
-       return LOWLEVEL_MAKE_SYNTAX (scm_car (sig), syntax_args);
+       SCM syntax_args = scm_list_5 (parser->self_scm (), make_input (loc), scm_car (sig), func, args);
+       return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
 }
 
 bool
index f83ba4505638bdb903808b90cccdaaccb693a730..2d598d156f3181b14581985f142c084a2035e5f3 100644 (file)
        (doc (procedure-documentation func))
        (sign (object-property func 'music-function-signature))
        (type-names (map type-name sign))
-
        (signature-str
        (string-join
         (map (lambda (x) (format #f "@var{~a} (~a)"
                                  (car x)
                                  (cadr x)))
-             (zip arg-names type-names)))))
+             (zip arg-names (cdr type-names))))))
     (format #f
-     "@item @code{~a}~a~a
+     "@item @code{~a} (~a) ~a~a
 @funindex ~a
 ~a
 "
-     name-sym (if (equal? "" signature-str) "" " - ") signature-str
+     name-sym (car type-names)
+     (if (equal? "" signature-str) "" " - ") signature-str
      name-sym
-     (if doc doc "(undocumented; fixme)"))))
+     (or doc "(undocumented; fixme)"))))
 
 
 (define (document-object obj-pair)
index e25539c469f794aaf6aa8fb7a04ef9c0f029bd52..59a47031b699afcd7483e9d62317e7e31198acd1 100644 (file)
        (set! (ly:music-property m 'origin) location)
        m)))
 
-;; Scheme function: Apply function, return value can be anything
-(define-ly-syntax (scheme-function parser loc fun args)
-      (apply fun parser loc args))
-
 ;; Music function: Apply function and check return value.
-(define-ly-syntax-loc (music-function parser loc fun args)
+(define-ly-syntax-loc (music-function parser loc pred fun args)
   (let ((m (apply fun parser loc args)))
-    (if (ly:music? m)
+    (if (pred m)
        m
-       (begin
-         (ly:parser-error parser (_ "Music head function must return Music object") loc)
-         (make-music 'Music)))))
+       (cond ((eq? pred ly:music?)
+              (ly:parser-error parser (_ "Music syntax function must return Music object") loc)
+              (make-music 'Music))
+             (else
+              (ly:parser-error parser
+                               (format #f (_ "Scheme function must return ~a object") (type-name pred))
+                               loc)
+              #f)))))
 
 (define-ly-syntax-simple (void-music)
   (make-music 'Music))
index f2b41292abe52d36b52f540d5bc639a7ac15408c..661d73e4097b64e1b82b104e0b4726c340949fdf 100644 (file)
@@ -758,43 +758,41 @@ NUMBER is 0-base, i.e., Voice=1 (upstems) has number 0.
                                                      music
                                                      (ly:music-deep-copy ,stop))))))
 
-(defmacro-public define-music-function (args signature . body)
+(defmacro-public define-syntax-function (type args signature . body)
   "Helper macro for `ly:make-music-function'.
 Syntax:
-  (define-music-function (parser location arg1 arg2 ...) (arg1-type? arg2-type? ...)
+  (define-syntax-function (result-type? parser location arg1 arg2 ...) (result-type? arg1-type? arg2-type? ...)
     ...function body...)
 "
-(if (and (pair? body) (pair? (car body)) (eqv? '_i (caar body)))
+  (if (and (pair? body) (pair? (car body)) (eqv? '_i (caar body)))
       ;; When the music function definition contains a i10n doc string,
       ;; (_i "doc string"), keep the literal string only
       (let ((docstring (cadar body))
            (body (cdr body)))
-       `(ly:make-music-function (list music-function ,@signature)
+       `(ly:make-music-function (list ,type ,@signature)
                                 (lambda (,@args)
                                   ,docstring
                                   ,@body)))
-      `(ly:make-music-function (list music-function ,@signature)
+      `(ly:make-music-function (list ,type ,@signature)
                               (lambda (,@args)
                                 ,@body))))
 
-(defmacro-public define-scheme-function (args signature . body)
+(defmacro-public define-music-function rest
+  "Helper macro for `ly:make-music-function'.
+Syntax:
+  (define-music-function (parser location arg1 arg2 ...) (arg1-type? arg2-type? ...)
+    ...function body...)
+"
+  `(define-syntax-function ly:music? ,@rest))
+
+
+(defmacro-public define-scheme-function rest
   "Helper macro for `ly:make-music-function'.
 Syntax:
   (define-scheme-function (parser location arg1 arg2 ...) (arg1-type? arg2-type? ...)
     ...function body...)
 "
-(if (and (pair? body) (pair? (car body)) (eqv? '_i (caar body)))
-      ;; When the music function definition contains a i10n doc string,
-      ;; (_i "doc string"), keep the literal string only
-      (let ((docstring (cadar body))
-           (body (cdr body)))
-       `(ly:make-music-function (list scheme-function ,@signature)
-                                (lambda (,@args)
-                                  ,docstring
-                                  ,@body)))
-      `(ly:make-music-function (list scheme-function ,@signature)
-                              (lambda (,@args)
-                                ,@body))))
+  `(define-syntax-function ly:scheme? ,@rest))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;