From 2c18ae02874d6e5bbb579603f4de64274ba9faaf Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 16 Mar 2013 17:35:53 +0100 Subject: [PATCH] Issue 3249: Make a PostEvents container class for packaging several postevents Previously it was not possible to assign multiple postevents to a single variable or pass them as the result of an event function. This patch wraps multiple events in such situations inside of a PostEvents post-event and unwraps them when used again in the parser. --- lily/parser.yy | 41 ++++++++++++++++++++++++++++++++++---- scm/define-music-types.scm | 6 ++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/lily/parser.yy b/lily/parser.yy index 79560ab1d7..ee413b301f 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -596,7 +596,28 @@ identifier_init: | output_def | context_def_spec_block | music_assign - | post_event_nofinger + | post_event_nofinger post_events + { + $$ = scm_reverse_x ($2, SCM_EOL); + if (Music *m = unsmob_music ($1)) + { + if (m->is_mus_type ("post-event-wrapper")) + $$ = scm_append + (scm_list_2 (m->get_property ("elements"), + $$)); + else + $$ = scm_cons ($1, $$); + } + if (scm_is_pair ($$) + && scm_is_null (scm_cdr ($$))) + $$ = scm_car ($$); + else + { + Music * m = MY_MAKE_MUSIC ("PostEvents", @$); + m->set_property ("elements", $$); + $$ = m->unprotect (); + } + } | number_expression | FRACTION | string @@ -2490,9 +2511,21 @@ post_events: $$ = SCM_EOL; } | post_events post_event { - if (unsmob_music ($2)) { - unsmob_music ($2)->set_spot (@2); - $$ = scm_cons ($2, $$); + $$ = $1; + if (Music *m = unsmob_music ($2)) + { + if (m->is_mus_type ("post-event-wrapper")) + { + for (SCM p = m->get_property ("elements"); + scm_is_pair (p); + p = scm_cdr (p)) + { + $$ = scm_cons (scm_car (p), $$); + } + } else { + m->set_spot (@2); + $$ = scm_cons ($2, $$); + } } } ; diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm index 6d40ce0f56..1090d332b4 100644 --- a/scm/define-music-types.scm +++ b/scm/define-music-types.scm @@ -437,6 +437,12 @@ Syntax: @var{note}@code{\\(} and @var{note}@code{\\)}") (types . (general-music post-event span-event event phrasing-slur-event)) )) + (PostEvents + . ((description . "Container for several postevents. + +This can be used to package several events into a single one. Should not be seen outside of the parser.") + (types . (post-event post-event-wrapper)))) + (PropertySet . ((description . "Set a context property. -- 2.39.5