From 3346fe361ea3e597874f95063f6f27845d4fff5c 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 83226fb9bb..41b733bfbc 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -332,6 +332,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 @@ -1487,6 +1488,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 @@ -1625,10 +1631,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); @@ -1636,10 +1647,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); @@ -1647,10 +1663,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); @@ -1707,6 +1728,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, @@ -2807,6 +2833,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