From bc451aebbe160afdea7c66fc4849bed18cf371a7 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 16 Nov 2013 16:23:59 +0100 Subject: [PATCH] Make sure optional arguments accepted as pitches stay pitches when reparsing --- lily/parser.yy | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/lily/parser.yy b/lily/parser.yy index fec7bd8820..ecea711ac6 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -333,6 +333,7 @@ If we give names, Bison complains. %token CONTEXT_MOD_IDENTIFIER %token DRUM_PITCH %token PITCH_IDENTIFIER +%token PITCH_ARG %token DURATION_IDENTIFIER %token EVENT_IDENTIFIER %token EVENT_FUNCTION @@ -1540,6 +1541,11 @@ function_arglist_nonbackup_reparse: ; +// function_arglist_backup can't occur at the end of an argument +// list. It needs to be careful about avoiding lookahead only until +// it has made a decision whether or not to accept the parsed entity. +// At that point of time, music requiring lookahead to parse becomes +// fine. function_arglist_backup: function_arglist_common | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg_closed @@ -1678,10 +1684,15 @@ function_arglist_backup: } | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup PITCH_IDENTIFIER { - if (scm_is_true (scm_call_1 ($2, $4))) + SCM m = make_music_from_simple (parser, @4, $4); + if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m))) { MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4); $$ = $3; + } else if (scm_is_true (scm_call_1 ($2, $4))) + { + MYREPARSE (@4, $2, PITCH_ARG, $4); + $$ = $3; } else { $$ = scm_cons (loc_on_music (@3, $1), $3); MYBACKUP (PITCH_IDENTIFIER, $4, @4); @@ -1689,10 +1700,15 @@ function_arglist_backup: } | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NOTENAME_PITCH { - if (scm_is_true (scm_call_1 ($2, $4))) + SCM m = make_music_from_simple (parser, @4, $4); + if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m))) { MYREPARSE (@4, $2, NOTENAME_PITCH, $4); $$ = $3; + } else if (scm_is_true (scm_call_1 ($2, $4))) + { + MYREPARSE (@4, $2, PITCH_ARG, $4); + $$ = $3; } else { $$ = scm_cons (loc_on_music (@3, $1), $3); MYBACKUP (NOTENAME_PITCH, $4, @4); @@ -1700,10 +1716,15 @@ function_arglist_backup: } | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup TONICNAME_PITCH { - if (scm_is_true (scm_call_1 ($2, $4))) + SCM m = make_music_from_simple (parser, @4, $4); + if (unsmob_music (m) && scm_is_true (scm_call_1 ($2, m))) { MYREPARSE (@4, $2, TONICNAME_PITCH, $4); $$ = $3; + } else if (scm_is_true (scm_call_1 ($2, $4))) + { + MYREPARSE (@4, $2, PITCH_ARG, $4); + $$ = $3; } else { $$ = scm_cons (loc_on_music (@3, $1), $3); MYBACKUP (TONICNAME_PITCH, $4, @4); @@ -1760,6 +1781,11 @@ function_arglist_backup: (parser, @3, $3), $1, $2); } + | function_arglist_backup REPARSE pitch_arg + { + $$ = check_scheme_arg (parser, @3, + $3, $1, $2); + } | function_arglist_backup REPARSE bare_number_common { $$ = check_scheme_arg (parser, @3, @@ -2860,6 +2886,17 @@ pitch: } ; +pitch_arg: + PITCH_ARG quotes { + if (!scm_is_eq (SCM_INUM0, $2)) + { + Pitch p = *unsmob_pitch ($1); + p = p.transposed (Pitch (scm_to_int ($2),0,0)); + $$ = p.smobbed_copy (); + } + } + ; + gen_text_def: full_markup { Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$); -- 2.39.5