]> git.donarmstrong.com Git - lilypond.git/commitdiff
(music_function_musicless_prefix): fold together
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 6 Apr 2006 12:54:23 +0000 (12:54 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Thu, 6 Apr 2006 12:54:23 +0000 (12:54 +0000)
definitions of signature (SCM*) (Music|post_event|chord_body_element)

ChangeLog
lily/bar-number-engraver.cc
lily/lexer.ll
lily/parser.yy

index 8a7142b698862db47d8bb82c233a31abb37ea202..34554a4cc50b65144f423c4dcfade72e7e2d8030 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2006-04-06  Han-Wen Nienhuys  <hanwen@lilypond.org>
 
+       * lily/parser.yy (music_function_musicless_prefix): fold together
+       definitions of signature (SCM*) (Music|post_event|chord_body_element)
+
        * lily/slur.cc (print): only set font-size if not set yet.
 
        * lily/slur-configuration.cc (add_score): improved layout of debug
index f4cc5e66eb460896f28c7fb9601ae69ac1708392..1758a91c57c5486ac2687ebcdcc6da3febd730c7 100644 (file)
@@ -20,7 +20,6 @@
   system-start-delims. If we find these, and the top staff is in the
   staff-group, add padding to the bar number.
 */
-
 class Bar_number_engraver : public Engraver
 {
 protected:
index 7ea74ff9d4327744c65f63cbf1af14056b78411d..f9601985f40b6bed668c7853e61bb359f2ab1f13 100644 (file)
@@ -878,74 +878,56 @@ lookup_markup_command (string s)
        return scm_call_1 (proc, scm_makfrom0str (s.c_str ()));
 }
 
+struct Parser_signature
+{
+       char *symbol;
+       int token_type;
+};
+static SCM signature_hash_table;
+
+static void init_signature_hash_table ()
+{
+       signature_hash_table = scm_gc_protect_object (scm_c_make_hash_table (31));
+       Parser_signature sigs[]  = {
+               {"scm", MUSIC_FUNCTION_SCM},
+               {"music", MUSIC_FUNCTION_MUSIC},
+               {"scm-music", MUSIC_FUNCTION_SCM_MUSIC},
+               {"scm-scm", MUSIC_FUNCTION_SCM_SCM},
+               {"music-music", MUSIC_FUNCTION_MUSIC_MUSIC},
+               {"scm-music-music", MUSIC_FUNCTION_SCM_MUSIC_MUSIC},
+               {"scm-scm-music", MUSIC_FUNCTION_SCM_SCM_MUSIC},
+               {"scm-scm-scm-music", MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC},
+               {"scm-scm-scm-scm-music", MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC},
+               {"scm-scm-scm", MUSIC_FUNCTION_SCM_SCM_SCM},
+               {"markup", MUSIC_FUNCTION_MARKUP},
+               {"markup-music", MUSIC_FUNCTION_MARKUP_MUSIC},
+               {"markup-markup", MUSIC_FUNCTION_MARKUP_MARKUP},
+               {"markup-music-music", MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC},
+               {"markup-markup-music", MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC},
+               {"noarg", MUSIC_FUNCTION},
+               {0,0}
+       };
+
+       for (int i = 0; sigs[i].symbol; i++)
+               scm_hashq_set_x (signature_hash_table, scm_gc_protect_object (ly_symbol2scm (sigs[i].symbol)),
+                                scm_from_int (sigs[i].token_type));
+}
 
 int
 music_function_type (SCM func)
 {
+       if (!signature_hash_table)
+               init_signature_hash_table ();
+
        SCM type = scm_object_property (func, ly_symbol2scm ("music-function-signature-keyword"));
-       if (type == ly_symbol2scm ("scm"))
-       {
-               return MUSIC_FUNCTION_SCM;
-       }
-       else if (type == ly_symbol2scm ("music"))
-       {
-               return MUSIC_FUNCTION_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-music"))
-       {
-               return MUSIC_FUNCTION_SCM_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-scm"))
-       {
-               return MUSIC_FUNCTION_SCM_SCM;
-       }
-       else if (type == ly_symbol2scm ("music-music"))
-       {
-               return MUSIC_FUNCTION_MUSIC_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-music-music"))
-       {
-               return MUSIC_FUNCTION_SCM_MUSIC_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-scm-music"))
-       {
-               return MUSIC_FUNCTION_SCM_SCM_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("scm-scm-scm"))
-       {
-               return MUSIC_FUNCTION_SCM_SCM_SCM;
-       }
-       else if (type == ly_symbol2scm ("markup"))
-       {
-               return MUSIC_FUNCTION_MARKUP;
-       }
-       else if (type == ly_symbol2scm ("markup-music"))
-       {
-               return MUSIC_FUNCTION_MARKUP_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("markup-markup"))
-       {
-               return MUSIC_FUNCTION_MARKUP_MARKUP;
-       }
-       else if (type == ly_symbol2scm ("markup-music-music"))
-       {
-               return MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("markup-markup-music"))
-       {
-               return MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC;
-       }
-       else if (type == ly_symbol2scm ("noarg"))
-       {
-               return MUSIC_FUNCTION;
-       }
-       else
+       SCM token_type = scm_hashq_ref (signature_hash_table, type, SCM_BOOL_F);
+       if (!scm_is_number (token_type))
                {
-               /* TODO: print location */
-               error (_ ("can't find signature for music function"));
+               programming_error (_ ("can't find signature for music function"));
+               return MUSIC_FUNCTION_SCM;
                }
-
-       return MUSIC_FUNCTION_SCM;
+       
+       return scm_to_int (token_type);
 }
 
 /* Shut up lexer warnings.  */
index 02599215fd509d0ad63ee98bf18e2e6be90524ab..cb8a8fdede7c9c318e2cc273ea4e702bd13cbac8 100644 (file)
@@ -285,6 +285,8 @@ If we give names, Bison complains.
 %token <scm> MUSIC_FUNCTION_SCM_SCM 
 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC 
 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM 
+%token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC 
+%token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC 
 %token <scm> MUSIC_IDENTIFIER
 %token <scm> NOTENAME_PITCH
 %token <scm> NUMBER_IDENTIFIER
@@ -354,6 +356,7 @@ If we give names, Bison complains.
 %type <scm> bare_number
 %type <scm> music_function_event
 %type <scm> music_function_chord_body
+%type <scm> music_function_musicless_prefix
 %type <scm> bass_figure
 %type <scm> figured_bass_modification
 %type <scm> br_bass_figure
@@ -994,6 +997,9 @@ function_scm_argument:
        | simple_string
        ;
 
+/*
+TODO: use code generation for this
+*/
 Generic_prefix_music_scm:
        MUSIC_FUNCTION {
                $$ = scm_list_2 ($1, make_input (@$));
@@ -1004,10 +1010,9 @@ Generic_prefix_music_scm:
        | MUSIC_FUNCTION_MARKUP full_markup {
                $$ = scm_list_3 ($1, make_input (@$), $2);
        }
-
-       | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument Music {
-               $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
-               $3->unprotect ();
+       | music_function_musicless_prefix Music {
+               $$ = ly_append2 ($1, $2->self_scm ());
+               $2->unprotect ();
        }
        | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
                $$ = scm_list_4 ($1, make_input (@$), $2, $3);
@@ -1015,13 +1020,6 @@ Generic_prefix_music_scm:
        | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
                $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
        }
-       | MUSIC_FUNCTION_MUSIC Music {
-               $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
-               $2->unprotect ();
-       }
-       | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument Music {
-               $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
-       }
        | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
                $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
                $3->unprotect ();
@@ -1552,19 +1550,37 @@ music_function_chord_body:
        MUSIC_FUNCTION {
                $$ = scm_list_2 ($1, make_input (@$));
        }
-       | MUSIC_FUNCTION_MUSIC chord_body_element {
-               $$ = scm_list_3 ($1, make_input (@$),
-                                       $2->self_scm ());
+       | music_function_musicless_prefix chord_body_element {
+               $$ = ly_append2 ($1, scm_list_1 ($2->self_scm ()));
+               $2->unprotect ();
        }
-       | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument chord_body_element {
-               $$ = scm_list_4 ($1, make_input (@$),
-                                       $2, $3->self_scm ());
+       ;
+
+music_function_event:
+       music_function_musicless_prefix post_event {
+               $$ = ly_append2 ($1, scm_list_1 ($2->self_scm ()));
+               $2->unprotect ();
        }
-       | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument
-               chord_body_element {
+       ;
 
-               $$ = scm_list_5 ($1, make_input (@$),
-                                       $2, $3, $4->self_scm ());
+/*
+TODO: use code generation for this
+*/
+music_function_musicless_prefix:
+       MUSIC_FUNCTION_MUSIC {
+               $$ = scm_list_2 ($1, make_input (@$));
+       }
+       | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument { 
+               $$ = scm_list_3 ($1, make_input (@$), $2);
+       }
+       | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument {
+               $$ = scm_list_4 ($1, make_input (@$), $2, $3);
+       }
+       | MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument {
+               $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
+       }
+       | MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument function_scm_argument {
+               $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
        }
        ;
 
@@ -1696,19 +1712,6 @@ post_events:
                $2->unprotect ();
        }
        ;
-
-music_function_event:
-       MUSIC_FUNCTION_MUSIC post_event {
-               $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
-       }
-       | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument post_event {
-               $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
-       }
-       | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument post_event {
-               $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
-       }
-       ;
-
        
 post_event:
        direction_less_event {