X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fparser.yy;h=33d9e0e4a647b6eb24cd98ef6ec03623d3bef0aa;hb=07be9fcc058e41ab2cec96e852a60c1aff6333f8;hp=842244079cf22cffe26fb2821e70e98a24b1194e;hpb=e2a4be3b72b1c473658436e4f82234b401dd7b60;p=lilypond.git diff --git a/lily/parser.yy b/lily/parser.yy index 842244079c..33d9e0e4a6 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -247,7 +247,6 @@ or %token LYRICSTO %token ALIAS %token ALTERNATIVE -%token APPLY %token APPLYCONTEXT %token APPLYOUTPUT %token AUTOCHANGE @@ -359,12 +358,19 @@ or %token MARKUP_HEAD_SCM0_SCM1_SCM2 %token MARKUP_HEAD_SCM0_SCM1_MARKUP2 +%token MUSIC_FUNCTION_SCM +%token MUSIC_FUNCTION_MUSIC +%token MUSIC_FUNCTION_SCM_MUSIC +%token MUSIC_FUNCTION_MUSIC_MUSIC +%token MUSIC_FUNCTION_SCM_SCM_MUSIC +%token MUSIC_FUNCTION_SCM_MUSIC_MUSIC + %token MARKUP_IDENTIFIER MARKUP_HEAD_LIST0 %type markup markup_line markup_list markup_list_body full_markup %type book_block book_body %type exclamations questions dots optional_rest -%type bass_mod +%type bass_mod %type grace_head %type oct_check %type context_mod_list @@ -377,7 +383,8 @@ or %type sub_quotes sup_quotes %type toplevel_music %type simple_element event_chord command_element -%type Composite_music Simple_music Prefix_composite_music +%type Composite_music Simple_music Prefix_composite_music Generic_prefix_music +%type Generic_prefix_music_scm %type Grouped_music_list %type Repeated_music %type Alternative_music @@ -945,9 +952,85 @@ Grouped_music_list: Simultaneous_music { $$ = $1; } | Sequential_music { $$ = $1; } ; - + +Generic_prefix_music_scm: + MUSIC_FUNCTION_SCM { + THIS->push_spot (); + } embedded_scm { + $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3); + } + | MUSIC_FUNCTION_MUSIC { + THIS->push_spot (); + } Music { + $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3->self_scm ()); + scm_gc_unprotect_object ($3->self_scm ()); + } + | MUSIC_FUNCTION_SCM_MUSIC { + THIS->push_spot (); + } embedded_scm Music { + $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4->self_scm ()); + scm_gc_unprotect_object ($4->self_scm ()); + } + | MUSIC_FUNCTION_MUSIC_MUSIC { + THIS->push_spot (); + } Music Music { + $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3->self_scm (), $4->self_scm ()); + scm_gc_unprotect_object ($3->self_scm ()); + scm_gc_unprotect_object ($4->self_scm ()); + } + | MUSIC_FUNCTION_SCM_MUSIC_MUSIC { + THIS->push_spot (); + } embedded_scm Music Music { + $$ = scm_list_5 ($1, make_input (THIS->pop_spot ()), + $3, $4->self_scm (), $5->self_scm ()); + scm_gc_unprotect_object ($5->self_scm ()); + scm_gc_unprotect_object ($4->self_scm ()); + } + ; + +Generic_prefix_music: + Generic_prefix_music_scm { + SCM func = ly_car ($1); + Input *loc = unsmob_input (ly_cadr ($1)); + SCM args = ly_cddr ($1); + SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature")); + int k = 0; + bool ok = true; + for (SCM s = sig, t = args; + ok && ly_c_pair_p (s) && ly_c_pair_p (t); + s = ly_cdr (s), t = ly_cdr (t)) { + k++; + if (scm_call_1 (ly_car (s), ly_car (t)) != SCM_BOOL_T) + { + loc->error (_f ("Argument %d failed typecheck", k)); + THIS->error_level_ = 1; + ok = false; + } + } + SCM m = SCM_EOL; + if (ok) + m = scm_apply_0 (func, ly_cdr ($1)); + if (unsmob_music (m)) + { + $$ = unsmob_music (m); + scm_gc_protect_object (m); + } + else + { + if (ok) + loc->error (_ ("Music head function should return Music object.")); + $$ = MY_MAKE_MUSIC ("Music"); + } + $$->set_spot (*loc); + } + ; + + Prefix_composite_music: - AUTOCHANGE Music { + Generic_prefix_music { + $$ = $1; + } + |AUTOCHANGE Music { SCM proc = ly_scheme_function ("make-autochange-music"); SCM res = scm_call_1 (proc, $2->self_scm ()); @@ -1060,23 +1143,6 @@ basic music objects too, since the meaning is different. $$->set_property ("element", p->self_scm ()); scm_gc_unprotect_object (p->self_scm ()); } - | APPLY embedded_scm Music { - if (!ly_input_procedure_p ($2)) - { - THIS->parser_error (_ ("\\apply takes function argument")); - $$ = $3; - } - else - { - SCM ret = scm_call_1 ($2, $3->self_scm ()); - Music *m = unsmob_music (ret); - if (!m) { - THIS->parser_error ("\\apply must return a Music"); - m = MY_MAKE_MUSIC ("Music"); - } - $$ = m; - } - } | NOTES { SCM nn = THIS->lexer_->lookup_identifier ("pitchnames"); @@ -2035,9 +2101,13 @@ tremolo_type: bass_number: DIGIT { $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10)); + $$ = scm_list_2 (ly_scheme_function ("number-markup"), + $$); } | UNSIGNED { $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10)); + $$ = scm_list_2 (ly_scheme_function ("number-markup"), + $$); } | STRING { $$ = $1; } ; @@ -2451,16 +2521,19 @@ markup: $$ = $1; } | score_block { - // WIP -- arbitrary, shoul also allow \book or Composite_music. + /* WIP this is a bit arbitrary, + we should also allow \book or Composite_music. + However, you'd typically want to change paper + settings, and need a \score block anyway. */ Score *score = $1; Book *book = new Book; book->scores_.push (score); extern Music_output_def* get_paper (My_lily_parser *parser); Music_output_def *paper = get_paper (THIS); SCM s = book->to_stencil (paper, THIS->header_); - $$ = scm_list_2 (ly_scheme_function ("stencil-markup"), s); scm_gc_unprotect_object (score->self_scm ()); scm_gc_unprotect_object (book->self_scm ()); + $$ = scm_list_2 (ly_scheme_function ("stencil-markup"), s); } ;