]> git.donarmstrong.com Git - lilypond.git/commitdiff
Implement define-event-function
authorDavid Kastrup <dak@gnu.org>
Wed, 21 Sep 2011 19:05:10 +0000 (21:05 +0200)
committerDavid Kastrup <dak@gnu.org>
Thu, 22 Sep 2011 19:21:42 +0000 (21:21 +0200)
lily/lexer.ll
lily/parser.yy
scm/music-functions.scm

index 707f84bd83727369deed3f303108f07cd9342668..6b19c8f67dd8aed1d205736a1fe8a182afb5af78 100644 (file)
@@ -817,6 +817,8 @@ Lily_lexer::scan_escaped_word (string str)
 
                if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
                        funtype = MUSIC_FUNCTION;
+               else if (scm_is_eq (cs, ly_lily_module_constant ("ly:event?")))
+                       funtype = EVENT_FUNCTION;
                else if (ly_is_procedure (cs))
                        funtype = SCM_FUNCTION;
                else programming_error ("Bad syntax function predicate");
index 0eefc1f40ea6c3da814675ad0706f8739ce6095b..21f467746e281c8753263015637f6c6e76345f5c 100644 (file)
@@ -286,6 +286,7 @@ If we give names, Bison complains.
 %token <scm> PITCH_IDENTIFIER
 %token <scm> DURATION_IDENTIFIER
 %token <scm> EVENT_IDENTIFIER
+%token <scm> EVENT_FUNCTION
 %token <scm> FRACTION
 %token <scm> LYRICS_STRING
 %token <scm> LYRIC_MARKUP_IDENTIFIER
@@ -393,6 +394,7 @@ If we give names, Bison complains.
 %type <scm> embedded_scm_closed
 %type <scm> embedded_scm_chord_body
 %type <scm> embedded_scm_event
+%type <scm> event_function_event
 %type <scm> figure_list
 %type <scm> figure_spec
 %type <scm> fraction
@@ -1680,6 +1682,13 @@ music_function_event:
        }
        ;
 
+event_function_event:
+       EVENT_FUNCTION music_function_event_arglist {
+               $$ = run_music_function (PARSER, @$,
+                                        $1, $2);
+       }
+       ;
+
 command_element:
        command_event {
                $$ = $1;
@@ -1879,6 +1888,7 @@ direction_less_event:
                a->set_property ("tremolo-type", scm_from_int ($1));
                $$ = a->unprotect ();
         }
+       | event_function_event  
        ;
 
 direction_reqd_event:
index feb11143b1068bb4beaeb00cd61f5d21ff500476..de6ec015da5793419df82eaa8332ba9fd10490c0 100644 (file)
@@ -880,6 +880,28 @@ parameter."
 
   `(define-syntax-function scheme? ,@rest))
 
+(defmacro-public define-event-function rest
+  "Defining macro returning event functions.
+Syntax:
+  (define-event-function (parser location arg1 arg2 ...) (arg1-type? arg2-type? ...)
+    ...function body...)
+
+argX-type can take one of the forms @code{predicate?} for mandatory
+arguments satisfying the predicate, @code{(predicate?)} for optional
+parameters of that type defaulting to @code{#f}, @code{@w{(predicate?
+value)}} for optional parameters with a specified default
+value (evaluated at definition time).  An optional parameter can be
+omitted in a call only when it can't get confused with a following
+parameter of different type.
+
+Predicates with syntactical significance are @code{ly:pitch?},
+@code{ly:duration?}, @code{ly:music?}, @code{markup?}.  Other
+predicates require the parameter to be entered as Scheme expression.
+
+Must return an event expression.  The @code{origin} is automatically
+set to the @code{location} parameter."
+
+  `(define-syntax-function (ly:event? (make-music 'Event 'void #t)) ,@rest))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;