]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
patch::: 1.5.4.jcn3
[lilypond.git] / lily / parser.yy
index 043a658fcff27c91f8719b7514afa3a2c80a6e8d..18bca5059b98840adbe87c6cc43fd41b5ecd726f 100644 (file)
@@ -8,6 +8,13 @@
   (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
            Jan Nieuwenhuizen <janneke@gnu.org>
 */
+
+/*
+  Two shift/reduce problems:
+    -
+    -
+ */
+
 #include <ctype.h>
 #include <iostream.h>
 
@@ -181,7 +188,7 @@ yylex (YYSTYPE *s,  void * v_l)
 %token EXTENDER
 %token FONT
 %token GLISSANDO
-%token GRACE
+%token GRACE NGRACE
 %token HEADER
 %token HYPHEN
 %token IN_T
@@ -329,7 +336,7 @@ toplevel_expression:
        }
        | lilypond_header {
                if (global_header_p)
-                       scm_unprotect_object (global_header_p->self_scm ());
+                       scm_gc_unprotect_object (global_header_p->self_scm ());
                global_header_p = $1;
        }
        | score_block {
@@ -402,7 +409,7 @@ lilypond_header:
 */
 assignment:
        STRING {
-               THIS->remember_spot ();
+               THIS->push_spot ();
        }
        /* cont */ '=' identifier_init  {
 
@@ -433,22 +440,22 @@ all objects can be unprotected as soon as they're here.
 identifier_init:
        score_block {
                $$ = $1->self_scm ();
-               scm_unprotect_object ($$);
+               scm_gc_unprotect_object ($$);
        }
        | output_def {
                $$ = $1->self_scm ();
-               scm_unprotect_object ($$);
+               scm_gc_unprotect_object ($$);
        }
        | translator_spec_block {
                $$ = $1;
        }
        | Music  {
                $$ = $1->self_scm ();
-               scm_unprotect_object ($$);
+               scm_gc_unprotect_object ($$);
        }
        | post_request {
                $$ = $1->self_scm ();
-               scm_unprotect_object ($$);
+               scm_gc_unprotect_object ($$);
        }
        | explicit_duration {
                $$ = $1;
@@ -528,7 +535,7 @@ translator_spec_body:
 */
 score_block:
        SCORE { 
-               THIS->remember_spot ();
+               THIS->push_spot ();
        }
        /*cont*/ '{' score_body '}'     {
                THIS->pop_spot ();
@@ -548,7 +555,7 @@ score_body:
        
                $$->set_spot (THIS->here_input ());
                SCM m = $1->self_scm ();
-               scm_unprotect_object (m);
+               scm_gc_unprotect_object (m);
                $$->music_ = m;
        }
        | SCORE_IDENTIFIER {
@@ -556,7 +563,7 @@ score_body:
                $$->set_spot (THIS->here_input ());
        }
        | score_body lilypond_header    {
-               scm_unprotect_object ($2->self_scm ()); 
+               scm_gc_unprotect_object ($2->self_scm ()); 
                $$->header_p_ = $2;
        }
        | score_body output_def {
@@ -652,7 +659,7 @@ Music_list: /* empty */ {
        | Music_list Music {
                SCM s = $$;
                SCM c = gh_cons ($2->self_scm (), SCM_EOL);
-               scm_unprotect_object ($2->self_scm ()); /* UGH */
+               scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
                if (gh_pair_p (gh_cdr (s)))
                        gh_set_cdr_x (gh_cdr (s), c); /* append */
                else
@@ -696,7 +703,7 @@ Repeated_music:
                if (beg)
                        {
                        r-> set_mus_property ("body", beg->self_scm ());
-                       scm_unprotect_object (beg->self_scm ());
+                       scm_gc_unprotect_object (beg->self_scm ());
                        }
                r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
 
@@ -704,9 +711,9 @@ Repeated_music:
                        {
                        alts->truncate (times);
                        r-> set_mus_property ("alternatives", alts->self_scm ());
-                       scm_unprotect_object (alts->self_scm ());  
+                       scm_gc_unprotect_object (alts->self_scm ());  
                        }
-               SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
+               SCM func = scm_primitive_eval (ly_symbol2scm ("repeat-name-to-ctor"));
                SCM result = gh_call1 (func, $2);
 
                set_music_properties (r, result);
@@ -780,7 +787,7 @@ Composite_music:
        CONTEXT STRING Music    {
                Context_specced_music *csm =  new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", $3->self_scm ());
-               scm_unprotect_object ($3->self_scm ());
+               scm_gc_unprotect_object ($3->self_scm ());
 
                csm->set_mus_property ("context-type",$2);
                csm->set_mus_property ("context-id", ly_str02scm (""));
@@ -792,22 +799,56 @@ Composite_music:
                chm->set_mus_property ("element", $3->self_scm ());
                chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
 
-               scm_unprotect_object ($3->self_scm ());
+               scm_gc_unprotect_object ($3->self_scm ());
                chm->set_mus_property ("what", $2); 
 
                $$ = chm;
                chm->set_spot (*$3->origin ());
        }
        | GRACE Music {
+#if 0
+       /*
+               The other version is for easier debugging  of
+               Sequential_music_iterator in combination with grace notes.
+       */
+
+               SCM start = THIS->lexer_p_->lookup_identifier ("startGraceMusic");
+               SCM stop = THIS->lexer_p_->lookup_identifier ("stopGraceMusic");
+               Music *startm = unsmob_music (start);
+               Music *stopm = unsmob_music (stop);
+
+               SCM ms = SCM_EOL;
+               if (stopm) {
+                       stopm = stopm->clone ();
+                       ms = gh_cons (stopm->self_scm (), ms);
+                       scm_gc_unprotect_object (stopm->self_scm ());
+               }
+               ms = gh_cons ($2->self_scm (), ms);
+               scm_gc_unprotect_object ($2->self_scm());
+               if (startm) {
+                       startm = startm->clone ();
+                       ms = gh_cons (startm->self_scm () , ms);
+                       scm_gc_unprotect_object (startm->self_scm ());
+               }
+
+               Music* seq = new Sequential_music (SCM_EOL);
+               seq->set_mus_property ("elements", ms);
+
+               $$ = new Grace_music (SCM_EOL);
+               $$->set_mus_property ("element", seq->self_scm ());
+               scm_gc_unprotect_object (seq->self_scm ());
+#else
                $$ = new Grace_music (SCM_EOL);
                $$->set_mus_property ("element", $2->self_scm ());
-               scm_unprotect_object ($2->self_scm ());
+               scm_gc_unprotect_object ($2->self_scm ());
+#endif
+
 
        }
        | CONTEXT string '=' string Music {
                Context_specced_music *csm =  new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", $5->self_scm ());
-               scm_unprotect_object ($5->self_scm ());
+               scm_gc_unprotect_object ($5->self_scm ());
 
                csm->set_mus_property ("context-type", $2);
                csm->set_mus_property ("context-id", $4);
@@ -815,7 +856,7 @@ Composite_music:
                $$ = csm;
        }
        | TIMES {
-               THIS->remember_spot ();
+               THIS->push_spot ();
        }
        /* CONTINUED */ 
                fraction Music  
@@ -828,7 +869,7 @@ Composite_music:
 
 
                $$->set_mus_property ("element", mp->self_scm ());
-               scm_unprotect_object (mp->self_scm ());
+               scm_gc_unprotect_object (mp->self_scm ());
                $$->set_mus_property ("numerator", gh_int2scm (n));
                $$->set_mus_property ("denominator", gh_int2scm (d));
                $$->compress (Moment (n,d));
@@ -844,7 +885,7 @@ Composite_music:
 
                p->transpose (pit);
                $$->set_mus_property ("element", p->self_scm ());
-               scm_unprotect_object (p->self_scm ());
+               scm_gc_unprotect_object (p->self_scm ());
        }
        | TRANSPOSE steno_tonic_pitch Music {
                $$ = new Transposed_music (SCM_EOL);
@@ -853,7 +894,7 @@ Composite_music:
 
                p->transpose (pit);
                $$->set_mus_property ("element", p->self_scm ());
-               scm_unprotect_object (p->self_scm ());
+               scm_gc_unprotect_object (p->self_scm ());
        
        }
        | APPLY embedded_scm Music  {
@@ -900,7 +941,7 @@ relative_music:
                $$ = new Relative_octave_music (SCM_EOL);
 
                $$->set_mus_property ("element", p->self_scm ());
-               scm_unprotect_object (p->self_scm ());
+               scm_gc_unprotect_object (p->self_scm ());
 
                $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
 
@@ -912,8 +953,8 @@ re_rhythmed_music:
          Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
          l->set_mus_property ("music", $2->self_scm ());
          l->set_mus_property ("lyrics", $3->self_scm ());
-         scm_unprotect_object ($3->self_scm ());
-         scm_unprotect_object ($2->self_scm ());
+         scm_gc_unprotect_object ($3->self_scm ());
+         scm_gc_unprotect_object ($2->self_scm ());
          $$ = l;
        }
        ;
@@ -926,8 +967,8 @@ part_combined_music:
                p->set_mus_property ("one", $3->self_scm ());
                p->set_mus_property ("two", $4->self_scm ());  
 
-               scm_unprotect_object ($3->self_scm ());
-               scm_unprotect_object ($4->self_scm ());  
+               scm_gc_unprotect_object ($3->self_scm ());
+               scm_gc_unprotect_object ($4->self_scm ());  
 
 
                $$ = p;
@@ -954,7 +995,7 @@ property_def:
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
 
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -970,7 +1011,7 @@ property_def:
 
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -987,7 +1028,7 @@ property_def:
                t->set_mus_property ("grob-value", $8);
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
                $$ = csm;
                $$->set_spot (THIS->here_input ());
 
@@ -1002,7 +1043,7 @@ property_def:
                t->set_mus_property ("grob-value", $8);
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -1018,7 +1059,7 @@ property_def:
 
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -1035,18 +1076,19 @@ scalar:
 
 
 request_chord:
-       pre_requests simple_element post_requests       {
-               Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
+       pre_requests {
+               THIS->push_spot ();
+       } /*cont */ simple_element post_requests        {
+               Music_sequence *l = dynamic_cast<Music_sequence*> ($3);
                if (l) {
                        for (int i=0; i < $1->size (); i++)
                                l->append_music ($1->elem (i));
-                       for (int i=0; i < $3->size (); i++)
-                               l->append_music ($3->elem (i));
+                       for (int i=0; i < $4->size (); i++)
+                               l->append_music ($4->elem (i));
                        }
                else
                        programming_error ("Need Sequence to add music to");
-               $$ = $2;
-               
+               $$ = $3;
        }
        | command_element
        ;
@@ -1063,7 +1105,7 @@ command_element:
 
                Context_specced_music *csm = new Context_specced_music (SCM_EOL);
                csm->set_mus_property ("element", t->self_scm ());
-               scm_unprotect_object (t->self_scm ());
+               scm_gc_unprotect_object (t->self_scm ());
 
                $$ = csm;
                $$->set_spot (THIS->here_input ());
@@ -1076,13 +1118,13 @@ command_element:
 
                Context_specced_music * sp = new Context_specced_music (SCM_EOL);
                sp->set_mus_property ("element", p->self_scm ());
-               scm_unprotect_object (p->self_scm ());
+               scm_gc_unprotect_object (p->self_scm ());
 
                $$ =sp ;
                sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
        }
        | CLEF STRING  {
-               SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
+               SCM func = scm_primitive_eval (ly_symbol2scm ("clef-name-to-properties"));
                SCM result = gh_call1 (func, $2);
 
                SCM l = SCM_EOL;
@@ -1090,14 +1132,14 @@ command_element:
                        Music * p = new Music (SCM_EOL);
                        set_music_properties (p, gh_car (s));
                        l = gh_cons (p->self_scm (), l);
-                       scm_unprotect_object (p->self_scm ());
+                       scm_gc_unprotect_object (p->self_scm ());
                }
                Sequential_music * seq = new Sequential_music (SCM_EOL);
                seq->set_mus_property ("elements", l);
 
                Context_specced_music * sp = new Context_specced_music (SCM_EOL);
                sp->set_mus_property ("element", seq->self_scm ());
-               scm_unprotect_object (seq->self_scm ());
+               scm_gc_unprotect_object (seq->self_scm ());
 
                $$ =sp ;
                sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
@@ -1125,10 +1167,10 @@ command_element:
 
                
 
-               scm_unprotect_object (p3->self_scm ());
-               scm_unprotect_object (p2->self_scm ());
-               scm_unprotect_object (p1->self_scm ());
-               scm_unprotect_object (seq->self_scm ());
+               scm_gc_unprotect_object (p3->self_scm ());
+               scm_gc_unprotect_object (p2->self_scm ());
+               scm_gc_unprotect_object (p1->self_scm ());
+               scm_gc_unprotect_object (seq->self_scm ());
 
                $$ = sp;
 
@@ -1593,11 +1635,11 @@ multiplied_duration:
        steno_duration {
                $$ = $1;
        }
-       | steno_duration '*' bare_unsigned {
+       | multiplied_duration '*' bare_unsigned {
                $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
        }
-       | steno_duration '*' FRACTION {
-               Moment m (gh_scm2int (gh_car ($3)), gh_scm2int (gh_cdr ($3)));
+       | multiplied_duration '*' FRACTION {
+               Rational  m (gh_scm2int (gh_car ($3)), gh_scm2int (gh_cdr ($3)));
 
                $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
        }
@@ -1634,6 +1676,8 @@ tremolo_type:
 
 simple_element:
        pitch exclamations questions optional_notemode_duration {
+
+               Input i = THIS->pop_spot ();
                if (!THIS->lexer_p_->note_state_b ())
                        THIS->parser_error (_ ("Have to be in Note mode for notes"));
 
@@ -1650,40 +1694,36 @@ simple_element:
                Simultaneous_music*v = new Request_chord (SCM_EOL);
                v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
                
-/*
-FIXME: location is one off, since ptich & duration don't contain origin refs. 
-*/
-               v->set_spot (THIS->here_input ());
-               n->set_spot (THIS->here_input ());
-
+               v->set_spot (i);
+               n->set_spot (i);
                $$ = v;
        }
        | RESTNAME optional_notemode_duration           {
 
-               SCM e = SCM_UNDEFINED;
-                 if (ly_scm2string ($1) =="s")
-                   { /* Space */
-                     Skip_req * skip_p = new Skip_req;
-                     skip_p->set_mus_property ("duration" ,$2);
-
-                     skip_p->set_spot (THIS->here_input ());
+               Input i = THIS->pop_spot ();
+               SCM e = SCM_UNDEFINED;
+               if (ly_scm2string ($1) =="s") {
+                       /* Space */
+                       Skip_req * skip_p = new Skip_req;
+                       skip_p->set_mus_property ("duration" ,$2);
+                       skip_p->set_spot (i);
                        e = skip_p->self_scm ();
-                   }
-                 else
-                   {
-                     Rest_req * rest_req_p = new Rest_req;
-                     rest_req_p->set_mus_property ("duration", $2);
-                     rest_req_p->set_spot (THIS->here_input ());
+                 }
+                 else {
+                       Rest_req * rest_req_p = new Rest_req;
+                       rest_req_p->set_mus_property ("duration", $2);
+                       rest_req_p->set_spot (i);
                        e = rest_req_p->self_scm ();
                    }
-                 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
+               Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
                velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
-                 velt_p->set_spot (THIS->here_input ());
-
+               velt_p->set_spot (i);
 
-                 $$ = velt_p;
+               $$ = velt_p;
        }
        | MULTI_MEASURE_REST optional_notemode_duration         {
+               Input i = THIS->pop_spot ();
+
                Skip_req * sk = new Skip_req;
                sk->set_mus_property ("duration", $2);
                Span_req *sp1 = new Span_req;
@@ -1707,19 +1747,20 @@ FIXME: location is one off, since ptich & duration don't contain origin refs.
                $$->set_mus_property ("elements", ms);
        }
        | STRING optional_notemode_duration     {
+               Input i = THIS->pop_spot ();
 
                Lyric_req* lreq_p = new Lyric_req;
                 lreq_p->set_mus_property ("text", $1);
                lreq_p->set_mus_property ("duration",$2);
-               lreq_p->set_spot (THIS->here_input ());
+               lreq_p->set_spot (i);
                Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
                velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
 
-
                $$= velt_p;
-
        }
        | chord {
+               Input i = THIS->pop_spot ();
+
                if (!THIS->lexer_p_->chord_state_b ())
                        THIS->parser_error (_ ("Have to be in Chord mode for chords"));
                $$ = $1;
@@ -1784,10 +1825,11 @@ chord_step:
                $$ = gh_cons ($1, SCM_EOL);
        }
        | CHORDMODIFIER_PITCH {
-               $$ = gh_cons ($1, SCM_EOL);
+               $$ = gh_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
        }
        | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
-               $$ = gh_list ($1, $2, SCM_UNDEFINED);
+               $$ = gh_list (unsmob_pitch ($1)->smobbed_copy (),
+                       $2, SCM_UNDEFINED);
        }
        ;
 
@@ -1918,7 +1960,7 @@ string:
                $$ = $1;
        }
        | string '+' string {
-               $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
+               $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
        }
        ;