]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
release: 1.2.15
[lilypond.git] / lily / parser.yy
index 88da679854cc51cff3533d770299975735045d82..4d84041f3866a08ff32d687678451aacae4409fe 100644 (file)
 #include "lyric-combine-music.hh"
 #include "transposed-music.hh"
 #include "time-scaled-music.hh"
-#include "new-repeated-music.hh"
+#include "repeated-music.hh"
 #include "mudela-version.hh"
 #include "grace-music.hh"
+#include "auto-change-music.hh"
 
 // mmm
 Mudela_version oldest_version ("1.1.52");
@@ -52,7 +53,8 @@ Mudela_version oldest_version ("1.1.52");
 void
 print_mudela_versions (ostream &os)
 {
-  os << "Oldest supported input version:   " << oldest_version.str () << endl;
+  os << _f ("Oldest supported input version: %s", oldest_version.str ()) 
+    << endl;
 }
 // needed for bison.simple's malloc() and free()
 #include <malloc.h>
@@ -68,7 +70,7 @@ print_mudela_versions (ostream &os)
 #define THIS ((My_lily_parser *) my_lily_parser_l)
 
 #define yyerror THIS->parser_error
-#define ARRAY_SIZE(a,s)   if (a.size () != s) THIS->parser_error (_f("expecting %d arguments", s))
+#define ARRAY_SIZE(a,s)   if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
 
 %}
 
@@ -123,7 +125,7 @@ yylex (YYSTYPE *s,  void * v_l)
 %pure_parser
 
 /* tokens which are not keywords */
-
+%token AUTOCHANGE
 %token TEXTSCRIPT
 %token ACCEPTS
 %token ALTERNATIVE
@@ -136,6 +138,8 @@ yylex (YYSTYPE *s,  void * v_l)
 %token CLEF
 %token CM_T
 %token CONSISTS
+%token SEQUENTIAL
+%token SIMULTANEOUS
 %token CONSISTSEND
 %token DURATION
 %token EXTENDER
@@ -182,7 +186,7 @@ yylex (YYSTYPE *s,  void * v_l)
 %token VERSION
 
 /* escaped */
-%token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR
+%token E_EXCLAMATION E_SMALLER E_BIGGER E_CHAR CHORD_MINUS CHORD_CARET 
 
 %type <i>      exclamations questions
 %token <i>     DIGIT
@@ -265,7 +269,7 @@ yylex (YYSTYPE *s,  void * v_l)
 
 mudela:        /* empty */
        | mudela toplevel_expression {}
-       | mudela assignment { }
+       | mudela assignment  { }
        | mudela error
        | mudela INVALID        {
                THIS->error_level_i_  =1;
@@ -307,7 +311,7 @@ embedded_scm:
        }
        | SCM_T STRING semicolon {
                if (THIS->lexer_p_->main_input_b_ && safe_global_b)
-                       error (_("Cannot evaluate Scheme in safe mode"));
+                       error (_("Can't evaluate Scheme in safe mode"));
                gh_eval_str ($2->ch_l ());
                delete $2;
        };
@@ -425,6 +429,9 @@ translator_spec_block:
 translator_spec_body:
        TRANS_IDENTIFIER        {
                $$ = $1->access_content_Translator (true);
+               Translator_group * tg = dynamic_cast<Translator_group*> ($$);
+               if (!tg)
+                       THIS->parser_error (_("Need a translator group for a context"));
                $$-> set_spot (THIS->here_input ());
        }
        | TYPE STRING semicolon {
@@ -454,8 +461,10 @@ translator_spec_body:
 
                delete $4;
                /* ugh*/
-               Translator_group * tr = dynamic_cast<Translator_group*>($$);
-               tr->set_property (*$2, str);
+               Translator_group* tg = dynamic_cast<Translator_group*> ($$);
+               if (!tg)
+                       THIS->parser_error (_("Need a translator group for a context"));
+               tg->set_property (*$2, str);
        }
        | translator_spec_body NAME STRING semicolon {
                $$->type_str_ = *$3;
@@ -564,7 +573,7 @@ paper_def_body:
                        URG URG.
                */
                if ($3->size () % 2)
-                       warning ("Need even number of args for shape array");
+                       warning (_ ("Need even number of args for shape array"));
 
                for (int i=0; i < $3->size ();  i+=2)
                {
@@ -643,15 +652,21 @@ real_array:
 */
 midi_block:
        MIDI
-
-       '{' midi_body '}'       { $$ = $3; }
+       '{' midi_body '}'       {
+               $$ = $3;
+               THIS-> lexer_p_-> scope_l_arr_.pop();
+       }
        ;
 
 midi_body: /* empty */                 {
-               $$ = THIS->default_midi_p ();
+               Midi_def * p =THIS->default_midi_p ();
+               $$ = p;
+               THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
        }
        | MIDI_IDENTIFIER       {
-               $$ = $1-> access_content_Midi_def (true);
+               Midi_def * p =$1-> access_content_Midi_def (true);
+               $$ = p;
+               THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
        }
        | midi_body assignment semicolon {
 
@@ -712,12 +727,12 @@ Repeated_music:
        {
                Music_sequence* m = dynamic_cast <Music_sequence*> ($5);
                if (m && $3 < m->length_i ())
-                       $5->warning ("More alternatives than repeats. Junking excess alternatives.");
+                       $5->warning (_ ("More alternatives than repeats.  Junking excess alternatives."));
 
                Repeated_music * r = new Repeated_music ($4, $3 >? 1, m);
                $$ = r;
                r->fold_b_ = (*$2 == "fold");
-               r->semi_fold_b_ =  (*$2 == "semi");
+               r->volta_fold_b_ =  (*$2 == "volta");
                delete $2;
                r->set_spot ($4->spot  ());
        }
@@ -729,13 +744,23 @@ Music_sequence: '{' Music_list '}'        {
        }
        ;
 
-Sequential_music: '{' Music_list '}'           {
+Sequential_music:
+       SEQUENTIAL '{' Music_list '}'           {
+               $$ = new Sequential_music ($3);
+               $$->set_spot ($3->spot ());
+       }
+       | '{' Music_list '}'            {
                $$ = new Sequential_music ($2);
                $$->set_spot ($2->spot ());
        }
        ;
 
-Simultaneous_music: '<' Music_list '>' {
+Simultaneous_music:
+       SIMULTANEOUS '{' Music_list '}'{
+               $$ = new Simultaneous_music ($3);
+               $$->set_spot ($3->spot ());
+       }
+       | '<' Music_list '>'    {
                $$ = new Simultaneous_music ($2);
                $$->set_spot ($2->spot ());
        }
@@ -747,11 +772,12 @@ Simple_music:
        | property_def
        | translator_change
        | Simple_music '*' unsigned '/' unsigned        {
-               /* urg */
-               $$ = new Time_scaled_music ($3, $5, $1);
+               $$ = $1;
+               $$->compress (Moment($3, $5 ));
        }
        | Simple_music '*' unsigned              {
-               $$ = new Time_scaled_music ($3, 1, $1);
+               $$ = $1;
+               $$->compress (Moment ($3, 1));
        }
        ;
 
@@ -766,6 +792,12 @@ Composite_music:
 
                $$ = csm;
        }
+       | AUTOCHANGE STRING Music       {
+               Auto_change_music * chm = new Auto_change_music (*$2, $3);
+               delete $2;
+               $$ = chm;
+               chm->set_spot ($3->spot ());
+       }
        | GRACE Music {
                $$ = new Grace_music ($2);
        }
@@ -922,11 +954,35 @@ abbrev_command_req:
                b->span_type_str_ = "beam";
                $$ =b;
        }
+       | '[' ':' unsigned {
+               if (!Duration::duration_type_b ($3))
+                 THIS->parser_error (_f ("not a duration: %d", $3));
+               else if ($3 < 8)
+                 THIS->parser_error (_ ("Can't abbreviate"));
+               else
+                 THIS->set_abbrev_beam ($3);
+
+               Chord_tremolo_req* a = new Chord_tremolo_req;
+               a->span_dir_ = START;
+               a->type_i_ = THIS->abbrev_beam_type_i_;
+               $$=a;
+       }
        | ']'           {
-               Span_req*b= new Span_req;
-               b->span_dir_ = STOP;
-               b->span_type_str_ = "beam";
-               $$ = b;
+               if (!THIS->abbrev_beam_type_i_)
+                 {
+                    Span_req*b= new Span_req;
+                    b->span_dir_ = STOP;
+                    b->span_type_str_ = "beam";
+                    $$ = b;
+                  }
+               else
+                 {
+                   Chord_tremolo_req* a = new Chord_tremolo_req;
+                   a->span_dir_ = STOP;
+                   a->type_i_ = THIS->abbrev_beam_type_i_;
+                   THIS->set_abbrev_beam (0);
+                   $$ = a;
+                 }
        }
        | BREATHE {
                $$ = new Breathing_sign_req;
@@ -952,10 +1008,10 @@ verbose_command_req:
                m->one_beat_i_=$4;
                $$ = m;
        }
-       | PENALTY int   {
+       | PENALTY int   {
                Break_req * b = new Break_req;
-               b->penalty_i_ = $2;
-               b-> set_spot (THIS->here_input ());
+               b->penalty_f_ = $2 / 100.0;
+               b->set_spot (THIS->here_input ());
                $$ = b;
        }
        | SKIP duration_length {
@@ -1030,7 +1086,7 @@ request_with_dir:
                if (Script_req * gs = dynamic_cast<Script_req*> ($2))
                        gs->dir_ = Direction ($1);
                else if ($1)
-                       $2->warning ("Can't specify direction for this request");
+                       $2->warning (_ ("Can't specify direction for this request"));
                $$ = $2;
        }
        ;
@@ -1165,7 +1221,7 @@ explicit_duration:
 extender_req:
        EXTENDER {
                if (!THIS->lexer_p_->lyric_state_b ())
-                       THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
+                       THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
                $$ = new Extender_req;
        }
        ;
@@ -1173,7 +1229,7 @@ extender_req:
 hyphen_req:
        HYPHEN {
                if (!THIS->lexer_p_->lyric_state_b ())
-                       THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
+                       THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
                $$ = new Hyphen_req;
        }
        ;
@@ -1336,7 +1392,7 @@ abbrev_type:
                if (!Duration::duration_type_b ($2))
                        THIS->parser_error (_f ("not a duration: %d", $2));
                else if ($2 < 8)
-                       THIS->parser_error (_ ("can't abbreviate"));
+                       THIS->parser_error (_ ("Can't abbreviate"));
                $$ = $2;
        }
        ;
@@ -1345,7 +1401,7 @@ abbrev_type:
 simple_element:
        musical_pitch exclamations questions optional_notemode_duration {
                if (!THIS->lexer_p_->note_state_b ())
-                       THIS->parser_error (_ ("have to be in Note mode for notes"));
+                       THIS->parser_error (_ ("Have to be in Note mode for notes"));
 
 
                Note_req *n = new Note_req;
@@ -1354,6 +1410,13 @@ simple_element:
                delete $1;
                n->duration_ = *$4;
                delete $4;
+               if (THIS->abbrev_beam_type_i_)
+                 {
+                   if (n->duration_.plet_b ())
+                     THIS->parser_error (_ ("Can't abbreviate tuplet"));
+                   else
+                     n->duration_.set_plet (1, 2);
+                 }
                n->cautionary_b_ = $3 % 2;
                n->forceacc_b_ = $2 % 2 || n->cautionary_b_;
 
@@ -1391,13 +1454,13 @@ simple_element:
        }
        | STRING optional_notemode_duration     {
                if (!THIS->lexer_p_->lyric_state_b ())
-                       THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
+                       THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
                $$ = THIS->get_word_element (*$1, $2);
                delete $1;
        }
        | chord {
                if (!THIS->lexer_p_->chord_state_b ())
-                       THIS->parser_error (_ ("have to be in Chord mode for chords"));
+                       THIS->parser_error (_ ("Have to be in Chord mode for chords"));
                $$ = $1;
        }
        ;
@@ -1411,7 +1474,7 @@ chord_additions:
        {
                $$ = new Array<Musical_pitch>;
        } 
-       | '-' chord_notes {
+       | CHORD_MINUS chord_notes {
                $$ = $2;
        }
        ;
@@ -1430,16 +1493,12 @@ chord_subtractions:
        {
                $$ = new Array<Musical_pitch>;
        } 
-       | '^' chord_notes {
+       | CHORD_CARET chord_notes {
                $$ = $2;
        }
        ;
 
 
-/*
-       forevery : X : optional_X sucks. Devise  a solution.
-*/
-
 chord_inversion:
        {
                $$ = 0;
@@ -1458,7 +1517,7 @@ chord_step:
                $$ = new Array<Musical_pitch>;
                $$->push (*$1);
        }
-       | CHORDMODIFIER_PITCH chord_note {
+       | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
                $$ = new Array<Musical_pitch>;
                $$->push (*$1);
                $$->push (*$2);
@@ -1478,7 +1537,7 @@ chord_note:
                $$->octave_i_ = $1 > 7 ? 1 : 0;
                $$->accidental_i_ = 1;
        }
-       | unsigned '-' {
+       | unsigned CHORD_MINUS {
                $$ = new Musical_pitch;
                $$->notename_i_ = ($1 - 1) % 7;
                $$->octave_i_ = $1 > 7 ? 1 : 0;