]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
patch::: 1.1.13.uu1
[lilypond.git] / lily / parser.yy
index 72e14708f53db987b0d596d2ad7d33a80053f7ca..6ebde09668a6331e1056c17e1236c75350c571c5 100644 (file)
 #include "relative-music.hh"
 #include "transposed-music.hh"
 #include "compressed-music.hh"
+#include "repeated-music.hh"
 
 // mmm
 Mudela_version oldest_version ("1.0.7");
-Mudela_version version ("1.0.8");
+Mudela_version version ("1.0.12");
 
 
 // needed for bison.simple's malloc() and free()
@@ -103,11 +104,12 @@ Paper_def* current_paper = 0;
     Array<Musical_pitch> *pitch_arr;
     Array<String> * strvec;
     Array<int> *intvec;
+    Atom * symbol;
     Box *box;
-    Simultaneous_music *chord;
+    Notename_table *chordmodifiertab;
     Duration *duration;
+    General_script_def * script;
     Identifier *id;
-    Translator* trans;
     Music *music;
     Music_list *music_list;
     Score *score;
@@ -123,14 +125,14 @@ Paper_def* current_paper = 0;
     Paper_def *paper;
     Real real;
     Request * request;
-    General_script_def * script;
     Scalar *scalar;
+    Simultaneous_music *chord;
     String *string;
-    Atom * symbol;
     Symtable * symtable;
     Symtables* symtables;
-    Text_def * textdef;
     Tempo_req *tempo;
+    Text_def * textdef;
+    Translator* trans;
     char c;
     const char *consstr;
     int i;
@@ -158,14 +160,18 @@ yylex (YYSTYPE *s,  void * v_l)
 
 %token ABSDYNAMIC
 %token ACCEPTS
+%token ALTERNATIVE
 %token BAR
 %token BEAMPLET
 %token CADENZA
+%token CHORDMODIFIERS
+%token CHORDS
 %token CLEF
 %token CM_T
 %token CONSISTS
 %token DURATION
 %token END
+%token EXTENDER
 %token FONT
 %token GROUPING
 %token HEADER
@@ -184,7 +190,6 @@ yylex (YYSTYPE *s,  void * v_l)
 %token NOTENAMES
 %token NOTES
 %token OCTAVE
-%token OUTPUT
 %token PAPER
 %token PARTIAL
 %token PENALTY
@@ -193,7 +198,9 @@ yylex (YYSTYPE *s,  void * v_l)
 %token PT_T
 %token RELATIVE
 %token REMOVE
-%token SCHEME /* token vs typedef;  can't be named SCM */
+%token REPEAT
+%token SCM_T
+%token SCMFILE
 %token SCORE
 %token SCRIPT
 %token SHAPE
@@ -216,6 +223,8 @@ yylex (YYSTYPE *s,  void * v_l)
 %type <i>      dots
 %token <i>     DIGIT
 %token <pitch> NOTENAME_PITCH
+%token <pitch> TONICNAME_PITCH
+%token <pitch> CHORDMODIFIER_PITCH
 %token <id>    DURATION_IDENTIFIER
 %token <id>    IDENTIFIER
 %token <id>    NOTENAME_TABLE_IDENTIFIER
@@ -245,6 +254,7 @@ yylex (YYSTYPE *s,  void * v_l)
 %type <i>      open_plet_parens close_plet_parens
 %type <i>      sub_quotes sup_quotes
 %type <music>  simple_element  request_chord command_element Simple_music  Composite_music
+%type <music>  Alternative_music Repeated_music
 %type <i>      abbrev_type
 %type <i>      int unsigned
 %type <i>      script_dir
@@ -257,8 +267,12 @@ yylex (YYSTYPE *s,  void * v_l)
 %type <symtables>      symtables symtables_body
 
 %type <pitch>   explicit_musical_pitch steno_musical_pitch musical_pitch absolute_musical_pitch
+%type <pitch>   steno_tonic_pitch
 %type <notereq>        steno_notepitch
 %type <pitch_arr>      pitch_list
+%type <music>  chord notemode_chord
+%type <pitch_arr>      chord_additions chord_subtractions
+%type <pitch>  chord_addsub chord_note
 %type <midi>   midi_block midi_body
 %type <duration>       duration_length
 
@@ -272,7 +286,7 @@ yylex (YYSTYPE *s,  void * v_l)
 %type <request>        post_request structured_post_request
 %type <pair>   plet_fraction
 %type <request> command_req verbose_command_req
-%type <request>        script_req  dynamic_req
+%type <request>        script_req  dynamic_req extender_req
 %type <string> string
 %type <score>  score_block score_body
 %type <intarr> shape_array
@@ -283,8 +297,10 @@ yylex (YYSTYPE *s,  void * v_l)
 %type <symtable>       symtable symtable_body
 %type <trans>  translator_spec translator_spec_body
 %type <tempo>  tempo_request
-%type <notenametab> notenames_body notenames_block
-%expect 3
+%type <notenametab> notenames_body notenames_block chordmodifiers_block
+
+/* 5 extra for notemode_chord */
+%expect 15
 
 
 %left '-' '+'
@@ -304,6 +320,9 @@ toplevel_expression:
        notenames_block                 {
                THIS->lexer_p_->set_notename_table ($1);
        }
+       | chordmodifiers_block                  {
+               THIS->lexer_p_->set_chordmodifier_table ($1);
+       }
        | mudela_header {
                delete header_global_p;
                header_global_p = $1;
@@ -326,10 +345,12 @@ toplevel_expression:
        ;
 
 embedded_scm:
-       SCHEME STRING ';' {
-       #ifdef HAVE_LIBGUILE
+       SCMFILE STRING ';' {
+               read_lily_scm_file (*$2);
+               delete $2;
+       }
+       | SCM_T STRING ';' {
                gh_eval_str ($2->ch_l ());
-       #endif
                delete $2;
        };
 
@@ -348,6 +369,11 @@ check_version:
        ;
 
 
+chordmodifiers_block:
+       CHORDMODIFIERS '{' notenames_body '}'  {  $$ = $3; }
+       ;
+
+
 notenames_block:
        NOTENAMES '{' notenames_body '}'  {  $$ = $3; }
        ;
@@ -414,6 +440,9 @@ block_identifier:
                $$ = new Score_identifier ($1, SCORE_IDENTIFIER);
 
        }
+       | chordmodifiers_block {
+               $$ = new Notename_table_identifier ($1, NOTENAME_TABLE_IDENTIFIER);
+       }
        | notenames_block {
                $$ = new Notename_table_identifier ($1, NOTENAME_TABLE_IDENTIFIER);
        }
@@ -587,6 +616,11 @@ optional_semicolon:
        | ';'
        ;
 
+optional_dot:
+       /* empty */
+       | '.'
+       ;
+
 paper_def_body:
        /* empty */                     {
                Paper_def *p = THIS->default_paper_p ();
@@ -727,6 +761,25 @@ Music:
        | Composite_music
        ;
 
+Alternative_music: {
+               Music_list* m = new Music_list;
+               $$ = new Sequential_music (m);
+       }
+       | ALTERNATIVE Simultaneous_music {
+               $$ = $2;
+       }
+       | ALTERNATIVE Sequential_music {
+               $$ = $2;
+       }
+       ;
+
+Repeated_music: REPEAT unsigned Music Alternative_music        {
+               Music_sequence* m = dynamic_cast <Music_sequence*> ($4);
+               assert (m);
+               $$ = new Repeated_music ($3, $2 >? 1, m);
+       }
+       ;
+
 Sequential_music: '{' Music_list '}'           {
                $$ = new Sequential_music ($2);
        }
@@ -758,30 +811,47 @@ Composite_music:
                delete $2;
                delete $4;
        }
-       | TIMES int '/' int Music       {
-               $$ = new Compressed_music ($2, $4, $5);
+       | TIMES {
+               THIS->remember_spot ();
+       }
+       /* CONTINUED */ 
+               int '/' int Music       
 
+       {
+               $$ = new Compressed_music ($3, $5, $6);
+               $$->set_spot (THIS->pop_spot ());
        }
+       | Repeated_music                { $$ = $1; }
        | Simultaneous_music            { $$ = $1; }
        | Sequential_music              { $$ = $1; }
        | TRANSPOSE musical_pitch Music {
                $$ = new Transposed_music ($3, *$2);
                delete $2;
        }
+       | TRANSPOSE steno_tonic_pitch Music {
+               $$ = new Transposed_music ($3, *$2);
+               delete $2;
+       }
        | NOTES
                { THIS->lexer_p_->push_note_state (); }
        Music
                { $$ = $3;
                  THIS->lexer_p_->pop_state ();
                }
-
+       | CHORDS
+               { THIS->lexer_p_->push_chord_state (); }
+       Music
+               {
+                 $$ = $3;
+                 THIS->lexer_p_->pop_state ();
+       }
        | LYRICS
                { THIS->lexer_p_->push_lyric_state (); }
        Music
                {
                  $$ = $3;
                  THIS->lexer_p_->pop_state ();
-               }
+       }
        | relative_music        { $$ = $1; }
        ;
 
@@ -970,6 +1040,9 @@ post_request:
                a->type_i_ = $1;
                $$ = a;
        }
+       | extender_req {
+               $$ = $1;
+       }
        ;
 
 optional_modality:
@@ -1012,6 +1085,20 @@ steno_musical_pitch:
        }
        ;
 
+steno_tonic_pitch:
+       TONICNAME_PITCH {
+               $$ = $1;
+       }
+       | TONICNAME_PITCH sup_quotes    {
+               $$ = $1;
+               $$->octave_i_ +=  $2;
+       }
+       | TONICNAME_PITCH sub_quotes     {
+               $$ = $1;
+               $$->octave_i_ += - $2;
+       }
+       ;
+
 explicit_musical_pitch:
        MUSICAL_PITCH '{' int_list '}'  {/* ugh */
                Array<int> &a = *$3;
@@ -1059,6 +1146,16 @@ explicit_duration:
        }
        ;
 
+extender_req:
+       EXTENDER {
+               if (!THIS->lexer_p_->lyric_state_b ())
+                       THIS->parser_error (_ ("have to be in Lyric mode for lyrics"));
+               Extender_req * e_p = new Extender_req;
+               e_p->spantype = Span_req::START;
+               $$ = e_p;
+               THIS->extender_req = e_p;
+       };
+
 dynamic_req:
        ABSDYNAMIC '{' unsigned '}'     {
                Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
@@ -1257,8 +1354,17 @@ script_dir:
 
 pre_requests:
        {
+               if (THIS->extender_req)
+                 {
+                   Extender_req * e_p = new Extender_req;
+                   e_p->spantype = Span_req::STOP;
+                   THIS->pre_reqs.push (e_p);
+                   THIS->extender_req = 0;
+                 }
+                       
        }
        | pre_requests open_request_parens {
+
                Array<Request*>& r = *THIS->get_parens_request ($2);
                for (int i = 0; i < r.size (); i++ )
                        r[i]->set_spot (THIS->here_input ());
@@ -1370,8 +1476,71 @@ simple_element:
                $$ = 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"));
+               $$ = $2;
+       }
+       ;
+
+
+chord:
+        notemode_duration steno_musical_pitch chord_additions chord_subtractions {
+                $$ = THIS->get_chord (*$2, $3, $4, *$1);
+        };
+
+chord_additions:
+       {
+               $$ = new Array<Musical_pitch>;
+       } 
+       | chord_additions chord_note {
+               $1->push (*$2);
+               $$ = $1;
+       }
+       | chord_additions CHORDMODIFIER_PITCH {
+               /* 
+                 urg, this is kind of ugly.
+                 all but "sus" chord modifiers can be
+                 handled as chord_additions...
+                */
+               $1->push (*$2);
+               $$ = $1;
+       }
        ;
 
+chord_note:
+        UNSIGNED {
+               $$ = new Musical_pitch;
+               $$->notename_i_ = ($1 - 1) % 7;
+               $$->octave_i_ = $1 > 7 ? 1 : 0;
+               $$->accidental_i_ = 0;
+        } 
+       | UNSIGNED '+' {
+               $$ = new Musical_pitch;
+               $$->notename_i_ = ($1 - 1) % 7;
+               $$->octave_i_ = $1 > 7 ? 1 : 0;
+               $$->accidental_i_ = 1;
+       }
+       | UNSIGNED '-' {
+               $$ = new Musical_pitch;
+               $$->notename_i_ = ($1 - 1) % 7;
+               $$->octave_i_ = $1 > 7 ? 1 : 0;
+               $$->accidental_i_ = -1;
+       }
+        ;
+
+chord_subtractions:
+       {
+               $$ = new Array<Musical_pitch>;
+       }
+       | '^' {
+               $$ = new Array<Musical_pitch>;
+       }
+       | chord_subtractions chord_addsub {
+               $$ = $1;
+               $$->push (*$2);
+       }
+       ;
 
 /*
        UTILITIES