lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make \header blocks tangible in Scheme (issue 296600043 by address@h


From: dak
Subject: Re: Make \header blocks tangible in Scheme (issue 296600043 by address@hidden)
Date: Tue, 28 Jun 2016 10:29:19 -0700

Reviewers: thomasmorley651,

Message:
On 2016/06/28 17:09:04, thomasmorley651 wrote:
Can't review the code.
 From description: very nice.

Though, I'm not sure to which grade coding (with) header-expressions
will be
extended.

Complete?  Try finding something that doesn't work.

Meaning, how about an entry in changes and/or snippets?

Changes, regtests, snippets, documentation.  All that would be warranted
and required, turning this from a 60-line change to a 1000-line change,
and that's before translations.  But that's not the main problem for me.
 The main problem is that the feature itself is straightforward and
obvious, but examples and descriptions are arbitrary and there are
thousands of different ways to tell the story.

And whatever way I pick is sure to be substantially rewritten anyway.
So it's a bit of a fight for me to muster the energy for the first shot
at it.

Description:
Make \header blocks tangible in Scheme

This treats Guile modules and \header blocks as more or less
equivalent.  Since \header blocks also contain module imports that
might not concur with those at the place of use, any use of a module
in place of a \header merely copies the values of the module
variables.  Consists of the commits:


Admit \header-like expression into \score


Admit \header-like expressions in \header


Admit \header-like expressions at top levels

\header-like expressions are allowed at \book, \bookpart,
and top level.


Allow \header blocks in expressions

This allows creating modules for further programmatic manipulation.

Please review this at https://codereview.appspot.com/296600043/

Affected files (+52, -7 lines):
  M lily/parser.yy


Index: lily/parser.yy
diff --git a/lily/parser.yy b/lily/parser.yy
index 741aee7d73c32f5b23d2a1cfcbc2ae07eb196115..f184c5acb2685087d8add9fb12508d9c2b35b880 100644
--- a/lily/parser.yy
+++ b/lily/parser.yy
@@ -409,10 +409,8 @@ lilypond:  /* empty */ { $$ = SCM_UNSPECIFIED; }


 toplevel_expression:
-       {
-               parser->lexer_->add_scope (get_header (parser));
-       } lilypond_header {
-               parser->lexer_->set_identifier (ly_symbol2scm 
("$defaultheader"), $2);
+       header_block {
+               parser->lexer_->set_identifier (ly_symbol2scm 
("$defaultheader"), $1);
        }
        | book_block {
                SCM proc = parser->lexer_->lookup_identifier 
("toplevel-book-handler");
@@ -475,6 +473,12 @@ toplevel_expression:
                                id = ly_symbol2scm ("$defaultlayout");

                        parser->lexer_->set_identifier (id, $1);
+               } else if (ly_is_module ($1))
+               {
+                       SCM module = get_header (parser);
+                       ly_module_copy (module, $1);
+                       parser->lexer_->set_identifier
+                               (ly_symbol2scm ("$defaultheader"), module);
                } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
                        parser->parser_error (@1, _("bad expression type"));
        }
@@ -526,6 +530,7 @@ embedded_scm_bare_arg:
        | partial_markup
        | full_markup_list
        | context_modification
+       | header_block
        | score_block
        | context_def_spec_block
        | book_block
@@ -634,8 +639,15 @@ lilypond_header_body:
        | lilypond_header_body assignment  {

        }
-       | lilypond_header_body embedded_scm  {
-
+       | lilypond_header_body SCM_TOKEN {
+               // Evaluate and ignore #xxx, as opposed to \xxx
+               parser->lexer_->eval_scm_token ($2, @2);
+       }
+       | lilypond_header_body embedded_scm_active {
+               if (ly_is_module ($2))
+                       ly_module_copy (scm_current_module (), $2);
+               else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
+                       parser->parser_error (@2, _("bad expression type"));
        }
        ;

@@ -645,6 +657,14 @@ lilypond_header:
        }
        ;

+header_block:
+       {
+               parser->lexer_->add_scope (get_header (parser));
+       } lilypond_header {
+               $$ = $2;
+       }
+       ;
+
 /*
        DECLARATIONS
 */
@@ -706,7 +726,8 @@ identifier_init:
        ;

 identifier_init_nonumber:
-       score_block
+       header_block
+       | score_block
        | book_block
        | bookpart_block
        | output_def
@@ -965,6 +986,9 @@ book_body:
                                id = ly_symbol2scm ("$defaultlayout");

                        parser->lexer_->set_identifier (id, $2);
+               } else if (ly_is_module ($2))
+               {
+                       ly_module_copy (unsmob<Book> ($1)->header_, $2);
                } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
                        parser->parser_error (@2, _("bad expression type"));
        }
@@ -1046,6 +1070,11 @@ bookpart_body:
                                id = ly_symbol2scm ("$defaultlayout");

                        parser->lexer_->set_identifier (id, $2);
+               } else if (ly_is_module ($2)) {
+                       Book *book = unsmob<Book> ($1);
+                       if (!ly_is_module (book->header_))
+                               book->header_ = ly_make_module (false);
+                       ly_module_copy (book->header_, $2);
                } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
                        parser->parser_error (@2, _("bad expression type"));
        }
@@ -1144,6 +1173,22 @@ score_items:
                                scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
                        else
                                $$ = scm_cons ($2, $$);
+               } else if (ly_is_module ($2)) {
+                       SCM module = SCM_UNSPECIFIED;
+                       if (score) {
+                               module = score->get_header ();
+                               if (!ly_is_module (module))
+                               {
+                                       module = ly_make_module (false);
+                                       score->set_header (module);
+                               }
+                       } else if (scm_is_pair ($$) && ly_is_module (scm_car 
($$)))
+                               module = scm_car ($$);
+                       else {
+                               module = ly_make_module (false);
+                               $$ = scm_cons (module, $$);
+                       }
+                       ly_module_copy (module, $2);
                } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
                        parser->parser_error (@2, _("Spurious expression in 
\\score"));
        }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]