]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
*** empty log message ***
[lilypond.git] / lily / parser.yy
index 195daf46fbd832f3d510a0c8ea8194fd59307c33..02599215fd509d0ad63ee98bf18e2e6be90524ab 100644 (file)
@@ -74,24 +74,25 @@ using namespace std;
 #include "book.hh"
 #include "context-def.hh"
 #include "dimensions.hh"
-#include "music.hh"
 #include "file-path.hh"
 #include "input-smob.hh"
 #include "input.hh"
+#include "international.hh"
 #include "lily-guile.hh"
+#include "lily-lexer.hh"
+#include "lily-parser.hh"
 #include "lilypond-input-version.hh"
 #include "main.hh"
 #include "misc.hh"
-#include "lily-lexer.hh"
-#include "lily-parser.hh"
-#include "paper-book.hh"
+#include "music.hh"
+#include "music.hh"
 #include "output-def.hh"
-#include "scm-hash.hh"
+#include "paper-book.hh"
 #include "program-option.hh"
+#include "scm-hash.hh"
 #include "score.hh"
 #include "text-interface.hh"
 #include "warn.hh"
-#include "music.hh"
 
 %}
 
@@ -100,7 +101,7 @@ using namespace std;
        Book *book;
        Output_def *outputdef;
        SCM scm;
-       String *string;
+       std::string *string;
        Music *music;
        Score *score;
        int i;
@@ -111,7 +112,7 @@ using namespace std;
 #define MY_MAKE_MUSIC(x)  make_music_by_name (ly_symbol2scm (x))
 
 Music *property_op_to_music (SCM op);
-Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops);
+Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops, bool create_new);
 SCM get_next_unique_context_id ();
 SCM get_next_unique_lyrics_context_id ();
 
@@ -341,6 +342,7 @@ If we give names, Bison complains.
 
 %type <outputdef> output_def_body
 %type <outputdef> output_def_head
+%type <outputdef> output_def_head_with_mode_switch
 %type <outputdef> output_def
 %type <outputdef> paper_block 
 
@@ -397,6 +399,7 @@ If we give names, Bison complains.
 %type <scm> object_id_setting
 %type <scm> octave_check
 %type <scm> optional_context_mod
+%type <scm> optional_id
 %type <scm> optional_notemode_duration
 %type <scm> pitch
 %type <scm> pitch_also_in_chords
@@ -448,9 +451,6 @@ object_id_setting:
 toplevel_expression:
        lilypond_header {
                THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
-       }
-       | add_quote {
-       
        }
        | book_block {
                Book *book = $1;
@@ -530,9 +530,13 @@ assignment:
        assignment_id '=' identifier_init  {
                if (! is_regular_identifier ($1))
                {
+#if 0
+                       /* no longer valid with dashes in \paper{} block. */ 
                        @1.warning (_ ("identifier should have alphabetic characters only"));
+#endif
                }
 
+
                THIS->lexer_->set_identifier ($1, $3);
 
 /*
@@ -703,7 +707,7 @@ score_body:
                }
                else
                {
-                       $$->defs_.push ($2);
+                       $$->add_output_def ($2);
                }
                $2->unprotect ();
        }
@@ -757,21 +761,25 @@ output_def_head:
        }
        ;
 
+output_def_head_with_mode_switch:
+       output_def_head {
+               THIS->lexer_->push_initial_state ();
+               $$ = $1;
+       }
+       ;
 
 output_def_body:
-       output_def_head '{' {
+       output_def_head_with_mode_switch '{' {
                $$ = $1;
                $$->input_origin_.set_spot (@$);
-               THIS->lexer_->push_initial_state ();
        }
-       | output_def_head '{' OUTPUT_DEF_IDENTIFIER     {
+       | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER    {
                $1->unprotect ();
                Output_def *o = unsmob_output_def ($3);
                o->input_origin_.set_spot (@$);
                $$ = o;
                THIS->lexer_->remove_scope ();
                THIS->lexer_->add_scope (o->scope_);
-               THIS->lexer_->push_initial_state ();
        }
        | output_def_body assignment  {
 
@@ -861,6 +869,7 @@ Alternative_music:
 Repeated_music:
        REPEAT simple_string bare_unsigned Music Alternative_music
        {
+               /*TODO: move to Scheme.*/
                Music *beg = $4;
                int times = $3;
                SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
@@ -953,7 +962,6 @@ Simple_music:
        | context_change
        ;
 
-
 optional_context_mod:
        /**/ { $$ = SCM_EOL; }
        | WITH { THIS->lexer_->push_initial_state (); }
@@ -971,7 +979,6 @@ context_mod_list:
        }
        ;
 
-
 Composite_music:
        Prefix_composite_music { $$ = $1; }
        | Grouped_music_list { $$ = $1; }
@@ -982,7 +989,6 @@ Grouped_music_list:
        | Sequential_music              { $$ = $1; }
        ;
 
-
 function_scm_argument:
        embedded_scm  
        | simple_string
@@ -1040,26 +1046,29 @@ Generic_prefix_music_scm:
        }
        ;
 
+optional_id:
+       /**/ { $$ = SCM_EOL; }
+       | '=' simple_string {
+               $$ = $2;
+       }
+       ;       
+
+
 Prefix_composite_music:
        Generic_prefix_music_scm {
                $$ = run_music_function (THIS, $1);
        }
-       | CONTEXT simple_string '=' simple_string optional_context_mod Music {
-               $$ = context_spec_music ($2, $4, $6, $5);
-
-       }
-       | CONTEXT simple_string optional_context_mod Music {
-               $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
+       | CONTEXT    simple_string optional_id optional_context_mod Music {
+               $$ = context_spec_music ($2, $3, $5, $4, false);
        }
-       | NEWCONTEXT simple_string optional_context_mod Music {
-               $$ = context_spec_music ($2, get_next_unique_context_id (), $4,
-                       $3);
+       | NEWCONTEXT simple_string optional_id optional_context_mod Music {
+               $$ = context_spec_music ($2, $3, $5, $4, true);
        }
 
        | TIMES fraction Music  
-
        {
-               int n = scm_to_int (scm_car ($2)); int d = scm_to_int (scm_cdr ($2));
+               int n = scm_to_int (scm_car ($2));
+               int d = scm_to_int (scm_cdr ($2));
                Music *mp = $3;
 
                $$= MY_MAKE_MUSIC ("TimeScaledMusic");
@@ -1098,8 +1107,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_id (),
-                                        $3, $2);
+               $$ = context_spec_music ($1, SCM_UNDEFINED, $3, $2, true);
                if ($1 == ly_symbol2scm ("ChordNames"))
                {
                  Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
@@ -1215,7 +1223,7 @@ re_rhythmed_music:
                        name = get_next_unique_lyrics_context_id ();
                        voice = context_spec_music (scm_makfrom0str ("Voice"),
                                                    name,
-                                                   voice, SCM_EOL);
+                                                   voice, SCM_EOL, false);
                }
 
                SCM context = scm_makfrom0str ("Lyrics");
@@ -1227,7 +1235,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_id (), com, SCM_EOL);
+                               SCM_UNDEFINED, com, SCM_EOL, true);
                        lst = scm_cons (csm->self_scm (), lst);
                }
                all->set_property ("elements", scm_cons (voice->self_scm (),
@@ -1323,14 +1331,14 @@ music_property_def:
                        ly_symbol2scm ("push"),
                        scm_cadr ($2),
                        $5, $3));
-               $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
+               $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
        }
        | OVERRIDE context_prop_spec embedded_scm  embedded_scm '=' scalar {
                $$ = property_op_to_music (scm_list_5 (
                        ly_symbol2scm ("push"),
                        scm_cadr ($2),
                        $6, $4, $3));
-               $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
+               $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
        }
        | REVERT context_prop_spec embedded_scm {
                $$ = property_op_to_music (scm_list_3 (
@@ -1338,20 +1346,20 @@ music_property_def:
                        scm_cadr ($2),
                        $3));
 
-               $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
+               $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
        }
        | SET context_prop_spec '=' scalar {
                $$ = property_op_to_music (scm_list_3 (
                        ly_symbol2scm ("assign"),
                        scm_cadr ($2),
                        $4));
-               $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
+               $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
        }
        | UNSET context_prop_spec {
                $$ = property_op_to_music (scm_list_2 (
                        ly_symbol2scm ("unset"),
                        scm_cadr ($2)));
-               $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
+               $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
        }
        | ONCE music_property_def {
                SCM e = $2->get_property ("element");
@@ -1561,15 +1569,6 @@ music_function_chord_body:
        ;
 
 
-add_quote:
-       ADDQUOTE string Music {
-               SCM adder = ly_lily_module_constant ("add-quotable");
-               
-               scm_call_2 (adder, $2, $3->self_scm ());
-               $3->unprotect();
-       }
-       ;
-
 command_element:
        command_event {
                $$ = MY_MAKE_MUSIC ("EventChord");
@@ -1585,12 +1584,6 @@ command_element:
                skip->set_spot (@$);
                $$ = skip;
        }
-       | OCTAVE pitch {
-               Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
-               $$ = m;
-               $$->set_spot (@$);
-               $$->set_property ("pitch", $2);
-       }
        | E_BRACKET_OPEN {
                Music *m = MY_MAKE_MUSIC ("LigatureEvent");
                m->set_property ("span-direction", scm_from_int (START));
@@ -1632,16 +1625,16 @@ command_element:
                                         sounds_as_c.smobbed_copy());
                $$->set_spot (@$);
                $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
-                       $$, SCM_EOL);
+                       $$, SCM_EOL, false);
        }
        | PARTIAL duration_length       {
                Moment m = - unsmob_duration ($2)->get_length ();
                Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
                p->set_spot (@$);
                p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
-                                       p, SCM_EOL);
+                                       p, SCM_EOL, false);
                p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
-                                       p, SCM_EOL);
+                                       p, SCM_EOL, false);
                $$ = p;
        }
 
@@ -2667,7 +2660,7 @@ property_op_to_music (SCM op)
 }
 
 Music*
-context_spec_music (SCM type, SCM id, Music *m, SCM ops)
+context_spec_music (SCM type, SCM id, Music *m, SCM ops, bool create_new)
 {
        Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
 
@@ -2677,6 +2670,8 @@ context_spec_music (SCM type, SCM id, Music *m, SCM ops)
        csm->set_property ("context-type",
                scm_is_symbol (type) ? type : scm_string_to_symbol (type));
        csm->set_property ("property-operations", ops);
+       if (create_new)
+               csm->set_property ("create-new", SCM_BOOL_T);
 
        if (scm_is_string (id))
                csm->set_property ("context-id", id);
@@ -2742,8 +2737,8 @@ run_music_function (Lily_parser *parser, SCM expr)
 bool
 is_regular_identifier (SCM id)
 {
-  String str = ly_scm2string (id);
-  char const *s = str.to_str0 ();
+  string str = ly_scm2string (id);
+  char const *s = str.c_str ();
 
   bool v = true;
 #if 0