From: David Kastrup Date: Sat, 14 Dec 2013 19:59:30 +0000 (+0100) Subject: Issue 3727: Allow header blocks and output definitions in \score to precede music X-Git-Tag: release/2.19.0-1~73 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=e0cc9e91b9863eeea2f22f792f24d3b8a9dc6080;p=lilypond.git Issue 3727: Allow header blocks and output definitions in \score to precede music This addresses a frequent complaint of users. --- diff --git a/input/regression/header-score-reordered.ly b/input/regression/header-score-reordered.ly new file mode 100644 index 0000000000..acbe127e21 --- /dev/null +++ b/input/regression/header-score-reordered.ly @@ -0,0 +1,22 @@ +\version "2.19.0" +\header { + texidoc=" +Header blocks may appear before and after the actual music in a score. +" +} + +\markup \vspace #3 +\markup { \bold Note: expect piece and opus. } +\markup \vspace #3 + +\score { + \header { + piece = "Piece correct (set in score)" + opus = "Opus incorrect (to be superseded at score level)" + } + \new Staff { c'1 } + \header { + % This should NOT overwrite the piece from above! + opus = "Opus correct (superseded at score level)" + } +} diff --git a/lily/parser.yy b/lily/parser.yy index f90dfd0799..ee705a5761 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -878,12 +878,58 @@ score_block: } ; +score_headers: + /* empty */ + { + $$ = SCM_EOL; + } + | score_headers + { + if (!scm_is_pair ($1) + || !ly_is_module (scm_car ($1))) + $1 = scm_cons (ly_make_module (false), $1); + parser->lexer_->add_scope (scm_car ($1)); + } lilypond_header + { + $$ = $1; + } + | score_headers output_def + { + Output_def *od = unsmob_output_def ($2); + if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T) + { + parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead")); + + } + else + { + if (scm_is_pair ($1) && ly_is_module (scm_car ($1))) + scm_set_cdr_x ($1, scm_cons ($2, scm_cdr ($1))); + else + $$ = scm_cons ($2, $1); + } + } + ; + + + score_body: - music { + score_headers music { SCM scorify = ly_lily_module_constant ("scorify-music"); - $$ = scm_call_2 (scorify, $1, parser->self_scm ()); + $$ = scm_call_2 (scorify, $2, parser->self_scm ()); - unsmob_score ($$)->origin ()->set_spot (@$); + unsmob_score ($$)->origin ()->set_spot (@2); + if (scm_is_pair ($1) && ly_is_module (scm_car ($1))) + { + unsmob_score ($$)->set_header (scm_car ($1)); + $1 = scm_cdr ($1); + } + for (SCM p = scm_reverse_x ($1, SCM_EOL); + scm_is_pair (p); p = scm_cdr (p)) + { + unsmob_score ($$)-> + add_output_def (unsmob_output_def (scm_car (p))); + } } | embedded_scm_active { Score *score;