]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
(get_indexed_char): scale metrics by
[lilypond.git] / lily / parser.yy
index 9439c6f3bc8dd664078175817f1f746e353f4747..f93b0b5df771252ce00e2a5afd76e39af020fc4f 100644 (file)
@@ -54,7 +54,8 @@ TODO:
 
 Music *property_op_to_music (SCM op);
 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops);
-SCM get_next_unique_context ();
+SCM get_next_unique_context_id ();
+SCM get_next_unique_lyrics_context_id ();
 
 #define YYERROR_VERBOSE 1
 
@@ -443,7 +444,8 @@ or
 %type <scm>    Generic_prefix_music_scm 
 %type <scm>    lyric_element
 %type <scm>     Alternative_music
-%type <scm>    markup markup_line markup_list markup_list_body full_markup
+%type <scm>    full_markup markup_list markup_composed_list markup_braced_list markup_braced_list_body 
+%type <scm>    markup_head_1_item markup_head_1_list markup simple_markup markup_top
 %type <scm>    mode_changing_head
 %type <scm>    mode_changing_head_with_context
 %type <scm>     object_id_setting 
@@ -1101,7 +1103,8 @@ Generic_prefix_music:
 
                SCM m = SCM_EOL;
                if (ok)
-                       m = scm_apply_0 (func, scm_cdr ($1));
+                       m = scm_apply_0 (func, scm_cons (THIS->self_scm(),
+                                                        scm_cdr ($1)));
 
                if (unsmob_music (m))
                        {
@@ -1131,7 +1134,7 @@ Prefix_composite_music:
                $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
        }
        | NEWCONTEXT simple_string optional_context_mod Music {
-               $$ = context_spec_music ($2, get_next_unique_context (), $4,
+               $$ = context_spec_music ($2, get_next_unique_context_id (), $4,
                        $3);
        }
 
@@ -1181,7 +1184,7 @@ Prefix_composite_music:
                THIS->lexer_->pop_state ();
        }
        | mode_changing_head_with_context optional_context_mod Grouped_music_list {
-               $$ = context_spec_music ($1, get_next_unique_context (),
+               $$ = context_spec_music ($1, get_next_unique_context_id (),
                                         $3, $2);
                if ($1 == ly_symbol2scm ("ChordNames"))
                {
@@ -1299,7 +1302,7 @@ re_rhythmed_music:
                SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice); 
                if (!scm_is_string (name))
                {
-                       name = get_next_unique_context ();
+                       name = get_next_unique_lyrics_context_id ();
                        voice = context_spec_music (scm_makfrom0str ("Voice"),
                                                    name,
                                                    voice, SCM_EOL);
@@ -1314,7 +1317,7 @@ re_rhythmed_music:
                        Music *music = unsmob_music (scm_car (s));
                        Music *com = make_lyric_combine_music (name, music);
                        Music *csm = context_spec_music (context,
-                               get_next_unique_context (), com, SCM_EOL);
+                               get_next_unique_context_id (), com, SCM_EOL);
                        lst = scm_cons (csm->self_scm (), lst);
                }
                all->set_property ("elements", scm_cons (voice->self_scm (),
@@ -1335,7 +1338,7 @@ re_rhythmed_music:
 
 context_change:
        CHANGE STRING '=' STRING  {
-               Music*t= MY_MAKE_MUSIC ("ContextChange");
+               Music*t = MY_MAKE_MUSIC ("ContextChange");
                t-> set_property ("change-to-type", scm_string_to_symbol ($2));
                t-> set_property ("change-to-id", $4);
 
@@ -1658,7 +1661,7 @@ command_element:
                $$->set_spot (THIS->here_input ());
        }
        | '|'      {
-               SCM pipe =THIS->lexer_->lookup_identifier ("pipeSymbol");
+               SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
 
                if (Music * m = unsmob_music (pipe))
                        $$ = m->clone ();
@@ -1703,7 +1706,7 @@ command_element:
                $$ = unsmob_music (result);
        }
        | TIME_T fraction  {
-               SCM proc= ly_scheme_function ("make-time-signature-set");
+               SCM proc = ly_scheme_function ("make-time-signature-set");
 
                SCM result = scm_apply_2   (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
                scm_gc_protect_object (result);
@@ -1730,17 +1733,17 @@ command_req:
                $$ = $1;
        }
        | KEY DEFAULT {
-               Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
+               Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
                $$ = key;
        }
        | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
 
-               Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
+               Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
                if (scm_ilength ($3) > 0)
                {               
                        key->set_property ("pitch-alist", $3);
                        key->set_property ("tonic", Pitch (0,0,0).smobbed_copy ());
-                       ((Music*)key)->transpose (* unsmob_pitch ($2));
+                       key->transpose (* unsmob_pitch ($2));
                } else {
                        THIS->parser_error (_ ("Second argument must be pitch list."));
                }
@@ -2461,57 +2464,90 @@ questions:
        | questions '?' { $$ ++; }
        ;
 
-
+/*
+This should be done more dynamically if possible.
+*/
 
 full_markup:
        MARKUP_IDENTIFIER {
                $$ = $1;
-       }
+       }
        | MARKUP
                { THIS->lexer_->push_markup_state (); }
-       markup
-               $$ = $3;
-                 THIS->lexer_->pop_state ();
-               }
+       markup_top {
+               $$ = $3;
+               THIS->lexer_->pop_state ();
+       }
        ;
 
+markup_top:
+       markup_list { 
+               $$ = scm_list_2 (ly_scheme_function ("line-markup"),  $1); 
+       }
+       | markup_head_1_list simple_markup      {
+               $$ = scm_car (scm_call_2 (ly_scheme_function ("map-markup-command-list"), $1, scm_list_1 ($2)));
+       }
+       | simple_markup {
+               $$ = $1;
+       }
+       ;
 
-/*
-This should be done more dynamically if possible.
-*/
-markup:
-       STRING {
-               $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
+markup_list:
+       markup_composed_list {
+               $$ = $1;
        }
-       | MARKUP_HEAD_EMPTY {
-               $$ = scm_list_1 ($1);
+       | markup_braced_list {
+               $$ = $1;
        }
-       | MARKUP_HEAD_MARKUP0 markup {
-               $$ = scm_list_2 ($1, $2);
+       ;
+
+markup_composed_list:
+       markup_head_1_list markup_braced_list {
+               $$ = scm_call_2 (ly_scheme_function ("map-markup-command-list"), $1, $2);
+               
        }
-       | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
-               $$ = scm_list_3 ($1, $2, $3);
+       ;
+
+markup_braced_list:
+       '{' markup_braced_list_body '}' {
+               $$ = scm_reverse_x ($2, SCM_EOL);
        }
-       | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
-               $$ = scm_list_3 ($1, $2, $3);
+       ;
+
+markup_braced_list_body:
+       /* empty */     {  $$ = scm_list (SCM_EOL); }
+       | markup_braced_list_body markup {
+               $$ = scm_cons ($2, $1);
        }
-       | markup_line {
-               $$ = $1;
+       | markup_braced_list_body markup_list {
+               $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
        }
-       | MARKUP_HEAD_LIST0 markup_list {
-               $$ = scm_list_2 ($1,$2);
+       ;
+
+markup_head_1_item:
+       MARKUP_HEAD_MARKUP0     {
+               $$ = scm_list_1 ($1);
        }
-       | MARKUP_HEAD_SCM0 embedded_scm {
+       | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
                $$ = scm_list_2 ($1, $2);
        }
-       | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
-               $$ = scm_list_4 ($1, $2, $3, $4);
+       | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm       {
+               $$ = scm_list_3 ($1, $2, $3);
        }
-       | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
-               $$ = scm_list_4 ($1, $2, $3, $4);
+       ;
+
+markup_head_1_list:
+       markup_head_1_item      {
+               $$ = scm_list_1 ($1);
        }
-       | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
-               $$ = scm_list_3 ($1, $2, $3);
+       | markup_head_1_list markup_head_1_item {
+               $$ = scm_cons ($2, $1);
+       }
+       ;
+
+simple_markup:
+       STRING {
+               $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
        }
        | MARKUP_IDENTIFIER {
                $$ = $1;
@@ -2528,28 +2564,35 @@ markup:
                scm_gc_unprotect_object (sc->self_scm ());
                THIS->lexer_->pop_state ();
        }
+       | MARKUP_HEAD_SCM0 embedded_scm {
+               $$ = scm_list_2 ($1, $2);
+       }
+       | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
+               $$ = scm_list_4 ($1, $2, $3, $4);
+       }
+       | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
+               $$ = scm_list_3 ($1, $2, $3);
+       }
+       | MARKUP_HEAD_EMPTY {
+               $$ = scm_list_1 ($1);
+       }
+       | MARKUP_HEAD_LIST0 markup_list {
+               $$ = scm_list_2 ($1,$2);
+       }
+       | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
+               $$ = scm_list_3 ($1, $2, $3);
+       }
        ;
-
-markup_list:
-       chord_open markup_list_body chord_close { $$ = scm_reverse_x ($2, SCM_EOL); }
-       ;
-
-markup_line:
-       '{' markup_list_body '}' {
-               SCM line = ly_scheme_function ("line-markup");
        
-               $$ = scm_list_2 (line, scm_reverse_x ($2, SCM_EOL));
+markup:
+       markup_head_1_list simple_markup        {
+               $$ = scm_car (scm_call_2 (ly_scheme_function ("map-markup-command-list"), $1, scm_list_1 ($2)));
        }
-       ;
-
-markup_list_body:
-       /**/ {  $$ = SCM_EOL; }
-       | markup_list_body markup {
-               $$ = scm_cons ($2, $1);
+       | simple_markup {
+               $$ = $1;
        }
        ;
 
-
 %%
 
 void
@@ -2713,15 +2756,18 @@ context_spec_music (SCM type, SCM id, Music *m, SCM ops)
        return csm;
 }
 
-/*
-FIXME: this should be postponed until the music hits \Score
-*/
 SCM
-get_next_unique_context ()
+get_next_unique_context_id ()
+{
+       return scm_makfrom0str ("$uniqueContextId");
+}
+
+
+SCM
+get_next_unique_lyrics_context_id ()
 {
        static int new_context_count;
-       char s[1024];
+       char s[128];
        snprintf (s, 1024, "uniqueContext%d", new_context_count++);
        return scm_makfrom0str (s);
 }
-