]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
*** empty log message ***
[lilypond.git] / lily / parser.yy
index d238193ae2e5be2950b656cf5fa614dea68632e9..640eb3881977c50694e3b3f2444c71e9e276c68c 100644 (file)
@@ -54,6 +54,7 @@ TODO:
 
 #include <ctype.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 
 #include "scm-option.hh"
@@ -81,7 +82,6 @@ TODO:
 #include "text-item.hh"
 #include "music-list.hh"
 
-
 #define MY_MAKE_MUSIC(x)  make_music_by_name (ly_symbol2scm (x))
 
 
@@ -161,10 +161,11 @@ SCM
 make_chord_step (int step, int alter)
 {
        if (step == 7)
-               alter--;
+               alter += FLAT;
 
-       /* ugh: fucks up above 13 */
-       Pitch m(step > 7 ? 1 : 0,(step - 1) % 7, alter);
+       while(step < 0)
+               step += 7;
+       Pitch m((step -1) / 7 , (step - 1) % 7, alter);
        return m.smobbed_copy ();
 }
 
@@ -255,12 +256,11 @@ yylex (YYSTYPE *s,  void * v)
 %token DEFAULT
 %token DENIES
 %token DESCRIPTION
-%token DURATION
 %token EXTENDER
 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
 %token GRACE 
-%token ACCIACATURA
+%token ACCIACCATURA
 %token APPOGGIATURA 
 %token GROBDESCRIPTIONS
 %token HEADER
@@ -276,12 +276,10 @@ yylex (YYSTYPE *s,  void * v)
 %token NOTES
 %token OCTAVE
 %token ONCE
-%token OUTPUTPROPERTY
 %token OVERRIDE SET REVERT 
 %token PAPER
 %token PARTCOMBINE
 %token PARTIAL
-%token PITCH
 %token PITCHNAMES
 %token PROPERTY
 %token RELATIVE
@@ -367,12 +365,11 @@ yylex (YYSTYPE *s,  void * v)
 %type <music> note_chord_element chord_body chord_body_element
 %type <scm>  chord_body_elements 
 %type <scm> steno_duration optional_notemode_duration multiplied_duration
-%type <scm>  verbose_duration
        
 %type <scm>   post_events 
 %type <music> gen_text_def direction_less_event direction_reqd_event
 %type <scm>   steno_pitch pitch absolute_pitch pitch_also_in_chords
-%type <scm>   explicit_pitch steno_tonic_pitch
+%type <scm>    steno_tonic_pitch
 %type <scm>    duration_length fraction
 
 %type <scm> new_chord step_number chord_items chord_item chord_separator step_numbers
@@ -430,7 +427,36 @@ toplevel_expression:
                THIS->input_file_->header_ = $1;
        }
        | score_block {
-               THIS->input_file_->scores_.push ($1);
+               Score * sc = $1;
+
+               SCM head = ly_module_p (sc->header_) ? sc->header_ : THIS->input_file_->header_.to_SCM ();
+
+               Path p = split_path (THIS->output_basename_);
+               int *c =  &THIS->input_file_->score_count_;
+               if (*c)
+                       {
+                       p.base += "-" + to_string (*c);
+                       }
+
+               (*c)++;
+               SCM outname = scm_makfrom0str (p.to_string ().to_str0());
+
+               for (int i=0; i < sc->defs_.size (); i++)
+                       default_rendering (sc->music_, sc->defs_[i]->self_scm(),head, outname);
+
+               if (sc->defs_.empty ())
+               {
+                  Music_output_def *id =
+                       unsmob_music_output_def (THIS->lexer_->lookup_identifier
+                               ("$defaultpaper"));
+
+                  id = id ? id->clone () : new Paper_def;
+       
+                  default_rendering (sc->music_, id->self_scm(), head, outname);
+                                               
+                  scm_gc_unprotect_object (id->self_scm ());
+               }
+               scm_gc_unprotect_object (sc->self_scm());
        }
        | output_def {
                if (dynamic_cast<Paper_def*> ($1))
@@ -541,9 +567,6 @@ identifier_init:
                $$ = $1->self_scm ();
                scm_gc_unprotect_object ($$);
        }
-       | verbose_duration {
-               $$ = $1;
-       }
        | number_expression {
                $$ = $1;
        }
@@ -563,15 +586,16 @@ translator_spec_block:
        ;
 
 translator_spec_body:
-       TRANSLATOR_IDENTIFIER   {
+       /**/ {
+               $$ = Translator_def::make_scm ();
+               unsmob_translator_def ($$)->set_spot (THIS->here_input ());
+       }
+       | TRANSLATOR_IDENTIFIER {
                $$ = $1;
                unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
        }
-       | TYPE STRING   {
-               $$ = Translator_def::make_scm ();
-               Translator_def*td =  unsmob_translator_def ($$);
-               td->translator_group_type_ = $2;
-               td->set_spot (THIS->here_input ());
+       | translator_spec_body TYPE STRING      {
+               unsmob_translator_def ($$)->translator_group_type_ = $3;
        }
        | translator_spec_body DESCRIPTION string  {
                unsmob_translator_def ($$)->description_ = $3;
@@ -631,12 +655,7 @@ score_block:
        /*cont*/ '{' score_body '}'     {
                THIS->pop_spot ();
                $$ = $4;
-               if (!$$->defs_.size ())
-               {
-                 Music_output_def *id =
-                       unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
-                 $$->add_output (id ? id->clone () :  new Paper_def );
-               }
+
        }
        ;
 
@@ -665,7 +684,7 @@ score_body:
                $$->header_ = $2;
        }
        | score_body output_def {
-               $$->add_output ($2);
+               $$->defs_.push ($2);
        }
        | score_body error {
 
@@ -893,25 +912,6 @@ Simple_music:
                $$->set_mus_property ("procedure", $2);
                $$->set_spot (THIS->here_input());
        }
-       | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
-               SCM pred = $2;
-               if (!gh_symbol_p ($3))
-               {
-                       THIS->parser_error (_ ("Second argument must be a symbol")); 
-               }
-               /* Should check # args */
-               if (!gh_procedure_p (pred))
-               {
-                       THIS->parser_error (_ ("First argument must be a procedure taking one argument"));
-               }
-
-               Music*m = MY_MAKE_MUSIC("OutputPropertySetMusic");
-               m->set_mus_property ("predicate", pred);
-               m->set_mus_property ("grob-property", $3);
-               m->set_mus_property ("grob-value",  $5);
-
-               $$ = m;
-       }
        | MUSIC_IDENTIFIER {
                $$ = unsmob_music ($1);
        }
@@ -922,7 +922,7 @@ Simple_music:
 
 grace_head:
        GRACE  { $$ = scm_makfrom0str ("Grace"); } 
-       | ACCIACATURA { $$ = scm_makfrom0str ("Acciaccatura"); }
+       | ACCIACCATURA { $$ = scm_makfrom0str ("Acciaccatura"); }
        | APPOGGIATURA { $$ = scm_makfrom0str ("Appoggiatura"); }
        ;
        
@@ -1022,8 +1022,10 @@ basic music objects too, since the meaning is different.
 
                csm->set_mus_property ("context-type", scm_string_to_symbol ($2));
 
-               SCM new_id = scm_number_to_string (gh_int2scm (new_context_count ++),
-                                       gh_int2scm (10));
+               char s[1024];
+               snprintf (s, 1024, "uniqueContext%d", new_context_count ++);
+               
+               SCM new_id = scm_makfrom0str (s);
                csm->set_mus_property ("context-id", new_id);
                $$ = csm;
        }
@@ -1062,15 +1064,20 @@ basic music objects too, since the meaning is different.
        }
        | APPLY embedded_scm Music  {
                if (!ly_input_procedure_p ($2))
+                       {
                        THIS->parser_error (_ ("\\apply takes function argument"));
-               
-               SCM ret = gh_call1 ($2, $3->self_scm ());
-               Music *m = unsmob_music (ret);
-               if (!m) {
-                       THIS->parser_error ("\\apply must return a Music");
-                       m = MY_MAKE_MUSIC("Music");
+                       $$ = $3;
+                       }
+               else
+                       {
+                       SCM ret = gh_call1 ($2, $3->self_scm ());
+                       Music *m = unsmob_music (ret);
+                       if (!m) {
+                               THIS->parser_error ("\\apply must return a Music");
+                               m = MY_MAKE_MUSIC("Music");
+                               }
+                       $$ = m;
                        }
-               $$ = m;
        }
        | NOTES
                { THIS->lexer_->push_note_state (); }
@@ -1620,7 +1627,7 @@ configurable, i.e.
        }
        | open_event {
                $$ = $1;
-               dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (STOP))
+               dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (STOP));
        }
        | EVENT_IDENTIFIER      {
                $$ = unsmob_music ($1);
@@ -1706,9 +1713,6 @@ pitch:
        steno_pitch {
                $$ = $1;
        }
-       | explicit_pitch {
-               $$ = $1;
-       }
        ;
 
 pitch_also_in_chords:
@@ -1716,26 +1720,9 @@ pitch_also_in_chords:
        | steno_tonic_pitch
        ;
 
-explicit_pitch:
-       PITCH embedded_scm {
-               $$ = $2;
-               if (!unsmob_pitch ($2)) {
-                       THIS->parser_error (_f ("Expecting musical-pitch value", 3));
-                        $$ = Pitch ().smobbed_copy ();
-               }
-       }
-       ;
 
-verbose_duration:
-       DURATION embedded_scm   {
-               $$ = $2;
-               if (!unsmob_duration ($2))
-               {
-                       THIS->parser_error (_ ("Must have duration object"));
-                       $$ = Duration ().smobbed_copy ();
-               }
-       }
-       ;
+
+
 
 extender_req:
        EXTENDER {
@@ -1861,9 +1848,6 @@ duration_length:
        multiplied_duration {
                $$ = $1;
        }
-       | verbose_duration {
-               $$ = $1;
-       }       
        ;
 
 optional_notemode_duration:
@@ -1879,10 +1863,6 @@ optional_notemode_duration:
 
                THIS->beam_check ($$);
        }
-       | verbose_duration {
-               $$ = $1;
-               THIS->default_duration_ = *unsmob_duration ($$);
-       }       
        ;
 
 steno_duration:
@@ -1961,12 +1941,12 @@ bass_number:
        | UNSIGNED {
                $$ = scm_number_to_string (gh_int2scm ($1), gh_int2scm (10));
        }
-       | STRING { $$ =  $1 }
+       | STRING { $$ =  $1; }
        ;
 
 bass_mod:
-       '-'     { $$ = -1; }
-       | '+'   { $$ = 1; } 
+       '-'     { $$ = -2; }
+       | '+'   { $$ = 2; } 
        | '!'   { $$ = 0; }
        ;
 
@@ -2132,7 +2112,7 @@ simple_element:
        ;
 
 lyric_element:
-       full_markup { $$ = $1 }
+       full_markup { $$ = $1; }
        | STRING {  $$ = $1 ; }
        ;
 
@@ -2194,10 +2174,10 @@ step_number:
                $$ = make_chord_step ($1, 0);
         } 
        | bare_unsigned '+' {
-               $$ = make_chord_step ($1, 1);
+               $$ = make_chord_step ($1, SHARP);
        }
        | bare_unsigned CHORD_MINUS {
-               $$ = make_chord_step ($1,-1);
+               $$ = make_chord_step ($1, FLAT);
        }
         ;