]> git.donarmstrong.com Git - lilypond.git/commitdiff
parser.yy et al: move functionality of run_music_function into syntax constructor
authorDavid Kastrup <dak@gnu.org>
Sat, 15 Oct 2011 12:13:06 +0000 (14:13 +0200)
committerDavid Kastrup <dak@gnu.org>
Sat, 22 Oct 2011 11:18:19 +0000 (13:18 +0200)
lily/parser.yy
scm/ly-syntax-constructors.scm

index 8a5cf3c322a36e0d83ba02a43fa64323c5a322fc..670e1a82fa12ba4c77f8b7e1bf12d22131fd189c 100644 (file)
@@ -156,7 +156,6 @@ SCM get_next_unique_lyrics_context_id ();
 
 
 static Music *make_music_with_input (SCM name, Input where);
-SCM run_music_function (Lily_parser *parser, Input loc, SCM func, SCM args);
 SCM check_scheme_arg (Lily_parser *parser, Input loc, SCM fallback,
                      SCM arg, SCM args, SCM pred);
 SCM loc_on_music (Input loc, SCM arg);
@@ -578,7 +577,7 @@ embedded_scm:
 
 scm_function_call:
        SCM_FUNCTION function_arglist {
-               $$ = run_music_function (PARSER, @$,
+               $$ = MAKE_SYNTAX ("music-function", @$,
                                         $1, $2);
        }
        ;
@@ -1266,7 +1265,7 @@ embedded_scm_closed:
 
 scm_function_call_closed:
        SCM_FUNCTION function_arglist_closed {
-               $$ = run_music_function (PARSER, @$,
+               $$ = MAKE_SYNTAX ("music-function", @$,
                                         $1, $2);
        }
        ;
@@ -1294,7 +1293,7 @@ function_arglist_bare:
 
 music_function_call:
        MUSIC_FUNCTION function_arglist {
-               $$ = run_music_function (PARSER, @$,
+               $$ = MAKE_SYNTAX ("music-function", @$,
                                         $1, $2);
        }
        ;
@@ -1755,14 +1754,14 @@ music_function_chord_body_arglist:
 embedded_scm_chord_body:
        embedded_scm_bare
        | SCM_FUNCTION music_function_chord_body_arglist {
-               $$ = run_music_function (PARSER, @$,
+               $$ = MAKE_SYNTAX ("music-function", @$,
                                         $1, $2);
        }
        ;
 
 music_function_chord_body:
        MUSIC_FUNCTION music_function_chord_body_arglist {
-               $$ = run_music_function (PARSER, @$,
+               $$ = MAKE_SYNTAX ("music-function", @$,
                                         $1, $2);
        }
        ;
@@ -1785,21 +1784,21 @@ music_function_event_arglist:
 embedded_scm_event:
        embedded_scm_bare
        | SCM_FUNCTION music_function_event_arglist {
-               $$ = run_music_function (PARSER, @$,
+               $$ = MAKE_SYNTAX ("music-function", @$,
                                         $1, $2);
        }
        ;
 
 music_function_event:
        MUSIC_FUNCTION music_function_event_arglist {
-               $$ = run_music_function (PARSER, @$,
+               $$ = MAKE_SYNTAX ("music-function", @$,
                                         $1, $2);
        }
        ;
 
 event_function_event:
        EVENT_FUNCTION music_function_event_arglist {
-               $$ = run_music_function (PARSER, @$,
+               $$ = MAKE_SYNTAX ("music-function", @$,
                                         $1, $2);
        }
        ;
@@ -2850,26 +2849,6 @@ get_next_unique_lyrics_context_id ()
 }
 
 
-SCM
-run_music_function (Lily_parser *parser, Input loc, SCM func, SCM args)
-{
-       SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
-
-       args = scm_reverse_x (args, SCM_EOL);
-
-       SCM fallback = SCM_BOOL_F;
-       SCM pred = scm_car (sig);
-
-       if (scm_is_pair (pred))
-       {
-               fallback = loc_on_music (loc, scm_cdr (pred));
-               pred = scm_car (pred);
-       }
-
-       SCM syntax_args = scm_list_n (parser->self_scm (), make_input (loc), pred, fallback, func, args, SCM_UNDEFINED);
-       return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
-}
-
 SCM check_scheme_arg (Lily_parser *parser, Input loc, SCM fallback,
                      SCM arg, SCM args, SCM pred)
 {
index c57917316b8f6950401062a58f4ac5099abed73b..f7f89cd0e1bb751ed2f676ba8b3ccf34de37e796 100644 (file)
        m)))
 
 ;; Music function: Apply function and check return value.
-(define-ly-syntax (music-function parser loc pred default fun args)
-  (let ((m (apply fun parser loc args)))
+;; args are in reverse order, rest may specify additional ones
+(define-ly-syntax (music-function parser loc fun args . rest)
+  (let* ((sig (object-property fun 'music-function-signature))
+        (pred (if (pair? (car sig)) (caar sig) (car sig)))
+        (m (apply fun parser loc (reverse! args rest))))
     (if (pred m)
        (begin
          (if (ly:music? m)
@@ -55,7 +58,7 @@
                           (format #f (_ "~a function cannot return ~a")
                                   (type-name pred) m)
                           loc)
-         default))))
+         (and (pair? (car sig)) (cdar sig))))))
 
 (define-ly-syntax-simple (void-music)
   (make-music 'Music))