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
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:
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. */
%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
%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
| simple_string
;
+/*
+TODO: use code generation for this
+*/
Generic_prefix_music_scm:
MUSIC_FUNCTION {
$$ = scm_list_2 ($1, make_input (@$));
| 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);
| 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 ();
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);
}
;
$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 {