From c96b509db0ae672e8dfa143c7e94f0b37f76a8c5 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Thu, 6 Apr 2006 12:54:23 +0000 Subject: [PATCH] (music_function_musicless_prefix): fold together definitions of signature (SCM*) (Music|post_event|chord_body_element) --- ChangeLog | 3 ++ lily/bar-number-engraver.cc | 1 - lily/lexer.ll | 104 +++++++++++++++--------------------- lily/parser.yy | 71 ++++++++++++------------ 4 files changed, 83 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a7142b698..34554a4cc5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2006-04-06 Han-Wen Nienhuys + * 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 diff --git a/lily/bar-number-engraver.cc b/lily/bar-number-engraver.cc index f4cc5e66eb..1758a91c57 100644 --- a/lily/bar-number-engraver.cc +++ b/lily/bar-number-engraver.cc @@ -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: diff --git a/lily/lexer.ll b/lily/lexer.ll index 7ea74ff9d4..f9601985f4 100644 --- a/lily/lexer.ll +++ b/lily/lexer.ll @@ -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. */ diff --git a/lily/parser.yy b/lily/parser.yy index 02599215fd..cb8a8fdede 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -285,6 +285,8 @@ If we give names, Bison complains. %token MUSIC_FUNCTION_SCM_SCM %token MUSIC_FUNCTION_SCM_SCM_MUSIC %token MUSIC_FUNCTION_SCM_SCM_SCM +%token MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC +%token MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC %token MUSIC_IDENTIFIER %token NOTENAME_PITCH %token NUMBER_IDENTIFIER @@ -354,6 +356,7 @@ If we give names, Bison complains. %type bare_number %type music_function_event %type music_function_chord_body +%type music_function_musicless_prefix %type bass_figure %type figured_bass_modification %type 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 { -- 2.39.5