]> git.donarmstrong.com Git - lilypond.git/commitdiff
Make the parser interpret music function signatures ly:pitch? and ly:duration?
authorDavid Kastrup <dak@gnu.org>
Fri, 22 Jul 2011 22:09:02 +0000 (00:09 +0200)
committerDavid Kastrup <dak@gnu.org>
Sun, 24 Jul 2011 10:53:53 +0000 (12:53 +0200)
Documentation/extending/programming-interface.itely
lily/include/duration.hh
lily/include/pitch.hh
lily/lexer.ll
lily/parser.yy

index acbff571193f2ae3dda76c6029fb06f61c346c51..72ca39e83d01a25f17d90614e10513c50fa8dae6 100644 (file)
@@ -66,7 +66,18 @@ where
 
 @item @code{@var{typeN?}}
 @tab a scheme @emph{type predicate} for which @code{@var{argN}}
-must return @code{#t}.
+must return @code{#t}.  Some of these predicates are specially
+recognized by the parser, making the respective values be read in
+Lilypond syntax rather than in Scheme syntax.  Currently these are
+@code{ly:music?}, @code{markup?}, @code{ly:pitch?}, and
+@code{ly:duration?}.  Not all combinations are allowed: i.e., you can't
+look for a duration after music since music may end @emph{optionally}
+with a duration.
+
+If you really want to input some of those items as a Scheme rather than
+a Lilypond expression, you may wrap them in a call of @code{ly:export}.
+@c TODO: document what kind of argument lists are permitted in what
+@c syntactical context of a music function call.
 
 @item @code{@var{music}}
 @tab A music expression, optionally written in scheme, with any
index 003b9e8efaa00aa1ca267b8ee403638355122cde..69ac4872b5f5902f6d1f2f3cbb80e7a54b2ac911 100644 (file)
@@ -56,5 +56,7 @@ private:
 INSTANTIATE_COMPARE (Duration, Duration::compare);
 DECLARE_UNSMOB (Duration, duration);
 
+extern SCM Duration_type_p_proc;
+
 #endif // DURATION_HH
 
index 1ef59f3e94d8eb671f9fcc924e26f91072f53482..df829b2a0d3f8860259e1ae41ea4ef35d3d2bbe7 100644 (file)
@@ -106,5 +106,6 @@ INSTANTIATE_COMPARE (Pitch, Pitch::compare);
 
 extern SCM pitch_less_proc;
 Pitch pitch_interval (Pitch const &from, Pitch const &to);
+extern SCM Pitch_type_p_proc;
 
 #endif /* PITCH_HH */
index 882418242d9d4ce8577ee81069a22d8ef75f5675..83a7940b6938dc634083fe9936ee389635713412 100644 (file)
@@ -46,6 +46,7 @@
 using namespace std;
 
 #include "context-def.hh"
+#include "duration.hh"
 #include "identifier-smob.hh"
 #include "international.hh"
 #include "interval.hh"
@@ -58,6 +59,7 @@ using namespace std;
 #include "music-function.hh"
 #include "parse-scm.hh"
 #include "parser.hh"
+#include "pitch.hh"
 #include "source-file.hh"
 #include "std-string.hh"
 #include "string-convert.hh"
@@ -794,11 +796,17 @@ Lily_lexer::scan_escaped_word (string str)
                push_extra_token (EXPECT_NO_MORE_ARGS);
                for (; scm_is_pair (s); s = scm_cdr (s))
                {
-                       if (scm_car (s) == ly_music_p_proc)
+                       SCM cs = scm_car (s);
+                       
+                       if (cs == ly_music_p_proc)
                                push_extra_token (EXPECT_MUSIC);
-                       else if (scm_car (s) == ly_lily_module_constant ("markup?"))
+                       else if (cs == Pitch_type_p_proc)
+                               push_extra_token (EXPECT_PITCH);
+                       else if (cs == Duration_type_p_proc)
+                               push_extra_token (EXPECT_DURATION);
+                       else if (cs == ly_lily_module_constant ("markup?"))
                                push_extra_token (EXPECT_MARKUP);
-                       else if (ly_is_procedure (scm_car (s)))
+                       else if (ly_is_procedure (cs))
                                push_extra_token (EXPECT_SCM);
                        else programming_error ("Function parameter without type-checking predicate");
                }
index 9b46bfe3cc3d16c1bd0e8ace4eae21c96c2ab9b1..38f4eb4f233ea44af258c239881a7ae8c19a2477 100644 (file)
@@ -270,6 +270,8 @@ If we give names, Bison complains.
 /* Artificial tokens, for more generic function syntax */
 %token <i> EXPECT_MARKUP;
 %token <i> EXPECT_MUSIC;
+%token <i> EXPECT_PITCH;
+%token <i> EXPECT_DURATION;
 %token <i> EXPECT_SCM;
 %token <i> EXPECT_MARKUP_LIST
 /* After the last argument. */
@@ -1075,12 +1077,23 @@ function_arglist_music_last:
        ;
 
 function_arglist_nonmusic_last:
-       EXPECT_MARKUP function_arglist full_markup {
+       EXPECT_NO_MORE_ARGS {
+               /* This is for 0-ary functions, so they don't need to
+                  read a lookahead token */
+               $$ = SCM_EOL;
+       }
+       | EXPECT_MARKUP function_arglist full_markup {
                $$ = scm_cons ($3, $2);
        }
        | EXPECT_MARKUP function_arglist simple_string {
                $$ = scm_cons ($3, $2);
        }
+       | EXPECT_PITCH function_arglist pitch {
+               $$ = scm_cons ($3, $2);
+       }
+       | EXPECT_DURATION function_arglist_nonmusic_last duration_length {
+               $$ = scm_cons ($3, $2);
+       }
        | EXPECT_SCM function_arglist function_scm_argument {
                $$ = scm_cons ($3, $2);
        }
@@ -1095,17 +1108,19 @@ function_arglist_nonmusic: EXPECT_NO_MORE_ARGS {
        | EXPECT_MARKUP function_arglist_nonmusic simple_string {
                $$ = scm_cons ($3, $2);
        }
+       | EXPECT_PITCH function_arglist_nonmusic pitch {
+               $$ = scm_cons ($3, $2);
+       }
+       | EXPECT_DURATION function_arglist_nonmusic duration_length {
+               $$ = scm_cons ($3, $2);
+       }
        | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
                $$ = scm_cons ($3, $2);
        }
        ;
 
-function_arglist: EXPECT_NO_MORE_ARGS {
-               /* This is for 0-ary functions, so they don't need to
-                  read a lookahead token */
-               $$ = SCM_EOL;
-       }
-       | function_arglist_music_last
+function_arglist:
+       function_arglist_music_last
        | function_arglist_nonmusic_last
        ;