]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
release: 1.3.138
[lilypond.git] / lily / parser.yy
1 %{ // -*-Fundamental-*-
2
3 /*
4   parser.yy -- Bison/C++ parser for lilypond
5
6   source file of the GNU LilyPond music typesetter
7
8   (c)  1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9            Jan Nieuwenhuizen <janneke@gnu.org>
10 */
11
12 #include <iostream.h>
13 #include "translator-def.hh"
14 #include "lily-guile.hh"
15 #include "change-iterator.hh"
16 #include "misc.hh"
17 #include "my-lily-lexer.hh"
18 #include "paper-def.hh"
19 #include "midi-def.hh"
20 #include "main.hh"
21 #include "file-path.hh"
22 #include "debug.hh"
23 #include "dimensions.hh"
24 #include "command-request.hh"
25 #include "musical-request.hh"
26 #include "my-lily-parser.hh"
27 #include "context-specced-music.hh"
28 #include "score.hh"
29 #include "music-list.hh"
30 #include "output-property-music-iterator.hh"
31 #include "property-iterator.hh"
32 #include "file-results.hh"
33 #include "input.hh"
34 #include "scope.hh"
35 #include "relative-music.hh"
36 #include "lyric-combine-music.hh"
37 #include "transposed-music.hh"
38 #include "time-scaled-music.hh"
39 #include "repeated-music.hh"
40 #include "lilypond-input-version.hh"
41 #include "grace-music.hh"
42 #include "part-combine-music.hh"
43 #include "scm-hash.hh"
44 #include "auto-change-iterator.hh"
45 #include "un-relativable-music.hh"
46 #include "chord.hh"
47
48 bool
49 is_duration_b (int t)
50 {
51   return t && t == 1 << intlog2 (t);
52 }
53
54
55 void
56 set_music_properties (Music *p, SCM a)
57 {
58   for (SCM k = a; gh_pair_p (k); k = gh_cdr (k))
59         {
60         p->set_mus_property (gh_caar (k), gh_cdar (k));
61         }
62 }
63
64
65 // mmm JUNKME ?
66 Lilypond_version oldest_version ("1.3.59");
67
68 void
69 print_lilypond_versions (ostream &os)
70 {
71   os << _f ("Oldest supported input version: %s", oldest_version.str ()) 
72     << endl;
73 }
74
75
76 // needed for bison.simple's malloc () and free ()
77 #include <malloc.h>
78
79 #ifndef NDEBUG
80 #define YYDEBUG 1
81 #endif
82
83 #define YYERROR_VERBOSE 1
84
85 #define YYPARSE_PARAM my_lily_parser_l
86 #define YYLEX_PARAM my_lily_parser_l
87 #define THIS\
88         ((My_lily_parser *) my_lily_parser_l)
89
90 #define yyerror THIS->parser_error
91 #define ARRAY_SIZE(a,s)   if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
92
93 %}
94
95
96 %union {
97
98     Link_array<Request> *reqvec;
99     String * string;
100     Music *music;
101     Score *score;
102     Scope *scope;
103     Scheme_hash_table *scmhash;
104     Musical_req* musreq;
105     Music_output_def * outputdef;
106
107     Midi_def* midi;
108     Real real;
109     Request * request;
110
111     /* We use SCMs to do strings, because it saves us the trouble of
112 deleting them.  Let's hope that a stack overflow doesnt trigger a move
113 of the parse stack onto the heap. */
114
115     SCM scm;
116
117     Tempo_req *tempo;
118     int i;
119 }
120 %{
121
122 int
123 yylex (YYSTYPE *s,  void * v_l)
124 {
125         My_lily_parser   *pars_l = (My_lily_parser*) v_l;
126         My_lily_lexer * lex_l = pars_l->lexer_p_;
127
128         lex_l->lexval_l = (void*) s;
129         return lex_l->yylex ();
130 }
131
132
133 %}
134
135 %pure_parser
136
137 /* tokens which are not keywords */
138 %token AUTOCHANGE
139 %token ALIAS
140 %token APPLY
141 %token ARPEGGIO
142 %token DYNAMICSCRIPT
143 %token TEXTSCRIPT
144 %token ACCEPTS
145 %token ALTERNATIVE
146 %token BAR
147 %token BREATHE
148 %token CHORDMODIFIERS
149 %token CHORDS
150 %token CHAR_T
151 %token CLEF
152 %token CM_T
153 %token CONSISTS
154 %token DURATION
155 %token SEQUENTIAL
156 %token ELEMENTDESCRIPTIONS
157 %token SIMULTANEOUS
158 %token CONSISTSEND
159 %token DENIES
160 %token DURATION
161 %token EXTENDER
162 %token FONT
163 %token GLISSANDO
164 %token GRACE
165 %token HEADER
166 %token HYPHEN
167 %token IN_T
168 %token INVALID
169 %token KEY
170 %token LYRICS
171 %token MARK
172 %token MULTI_MEASURE_REST
173 %token MIDI
174 %token MM_T
175 %token PITCH
176 %token NAME
177 %token PITCHNAMES
178 %token NOTES
179 %token PAPER
180 %token PARTIAL
181 %token PENALTY
182 %token PROPERTY
183 %token OVERRIDE SET REVERT 
184 %token PT_T
185 %token RELATIVE
186 %token REMOVE
187 %token REPEAT
188 %token ADDLYRICS
189 %token PARTCOMBINE
190 %token SCM_T
191 %token SCORE
192 %token SCRIPT
193 %token SKIP
194 %token SPANREQUEST
195 %token STYLESHEET
196 %token COMMANDSPANREQUEST
197 %token TEMPO
198 %token OUTPUTPROPERTY
199 %token TIME_T
200 %token TIMES
201 %token TRANSLATOR
202 %token TRANSPOSE
203 %token TYPE
204 %token UNSET
205 %token CONTEXT
206
207 /* escaped */
208 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
209 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET 
210
211 %type <i>       exclamations questions dots
212 %token <i>      DIGIT
213 %token <scm>    NOTENAME_PITCH
214 %token <scm>    TONICNAME_PITCH
215 %token <scm>    CHORDMODIFIER_PITCH
216 %token <scm>    DURATION_IDENTIFIER
217 %token <id>     IDENTIFIER
218
219
220 %token <scm>    SCORE_IDENTIFIER
221 %token <scm>    MUSIC_OUTPUT_DEF_IDENTIFIER
222
223 %token <scm>    NUMBER_IDENTIFIER
224 %token <scm>    REQUEST_IDENTIFIER
225 %token <scm>    MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
226 %token <scm>    STRING_IDENTIFIER SCM_IDENTIFIER 
227 %token <scm>    RESTNAME
228 %token <scm>    STRING 
229 %token <scm>    SCM_T
230 %token <i>      UNSIGNED
231 %token <real>   REAL
232
233 %type <outputdef> output_def
234 %type <scmhash>         lilypond_header lilypond_header_body
235 %type <request> open_request_parens close_request_parens open_request close_request
236 %type <request> request_with_dir request_that_take_dir verbose_request
237 %type <i>       sub_quotes sup_quotes
238 %type <music>   simple_element  request_chord command_element Simple_music  Composite_music 
239 %type <music>   Alternative_music Repeated_music
240 %type <i>       tremolo_type
241 %type <i>       bare_int  bare_unsigned
242 %type <i>       script_dir
243
244 %type <scm>     identifier_init 
245
246 %type <scm> steno_duration optional_notemode_duration
247 %type <scm> entered_notemode_duration explicit_duration
248         
249 %type <reqvec>  pre_requests post_requests
250 %type <request> gen_text_def
251 %type <scm>   steno_pitch pitch absolute_pitch
252 %type <scm>   explicit_pitch steno_tonic_pitch
253
254 %type <scm>     chord_additions chord_subtractions chord_notes chord_step
255 %type <music>   chord
256 %type <scm>     chord_note chord_inversion chord_bass
257 %type <scm>     duration_length
258
259 %type <scm>  embedded_scm scalar
260 %type <music>   Music Sequential_music Simultaneous_music Music_sequence
261 %type <music>   relative_music re_rhythmed_music part_combined_music
262 %type <music>   property_def translator_change
263 %type <scm> Music_list
264 %type <outputdef>  music_output_def_body
265 %type <request> shorthand_command_req
266 %type <request> post_request 
267 %type <music> command_req verbose_command_req
268 %type <request> extender_req
269 %type <request> hyphen_req
270 %type <scm>     string bare_number number_expression
271 %type <score>   score_block score_body
272
273 %type <scm>     translator_spec_block translator_spec_body
274 %type <tempo>   tempo_request
275 %type <scm> notenames_body notenames_block chordmodifiers_block
276 %type <scm>     script_abbreviation
277
278
279
280 %left '-' '+'
281 %left '*' '/'
282 %left UNARY_MINUS
283
284 %%
285
286 lilypond:       /* empty */
287         | lilypond toplevel_expression {}
288         | lilypond assignment  { }
289         | lilypond error {
290                 THIS->error_level_i_  = 1;
291                 //THIS->parser_error (_ ("ly invalid"));
292         }
293         | lilypond INVALID      {
294                 THIS->error_level_i_  = 1;
295                 //THIS->parser_error (_ ("ly invalid"));
296         }
297         ;
298
299 toplevel_expression:
300         notenames_block                 {
301                 THIS->lexer_p_->pitchname_tab_ =  $1;
302         }
303         | chordmodifiers_block                  {
304                 THIS->lexer_p_->chordmodifier_tab_  = $1;
305         }
306         | lilypond_header {
307                 if (global_header_p)
308                         scm_unprotect_object (global_header_p->self_scm ());
309                 global_header_p = $1;
310         }
311         | score_block {
312                 score_global_array.push ($1);
313                 
314         }
315         | output_def {
316                 if (dynamic_cast<Paper_def*> ($1))
317                         THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
318                 else if (dynamic_cast<Midi_def*> ($1))
319                         THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
320         }
321         | embedded_scm {
322                 // junk value
323         }       
324         ;
325
326 embedded_scm:
327         SCM_T
328         | SCM_IDENTIFIER 
329         ;
330
331
332 chordmodifiers_block:
333         CHORDMODIFIERS notenames_body   {  $$ = $2; }
334         ;
335
336
337 notenames_block:
338         PITCHNAMES notenames_body   {  $$ = $2; }
339         ;
340
341
342
343 notenames_body:
344         embedded_scm    {
345           int i = scm_ilength ($1);
346
347           SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
348           for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
349                 SCM pt = gh_cdar (s);
350                 if (!unsmob_pitch (pt))
351                         THIS->parser_error ("Need pitch object.");
352                 else
353                         scm_hashq_set_x (tab, gh_caar (s), pt);
354           }
355
356           $$ = tab;
357         }
358         ;
359
360 lilypond_header_body:
361         {
362                 $$ = new Scheme_hash_table;
363                 
364                 Scope *sc = new Scope ($$);
365                 THIS->lexer_p_-> scope_l_arr_.push (sc);
366         }
367         | lilypond_header_body assignment semicolon { 
368
369         }
370         ;
371
372 lilypond_header:
373         HEADER '{' lilypond_header_body '}'     {
374                 $$ = $3;
375                 delete THIS->lexer_p_-> scope_l_arr_.pop ();
376         }
377         ;
378
379
380 /*
381         DECLARATIONS
382 */
383 assignment:
384         STRING {
385                 THIS->remember_spot ();
386         }
387         /* cont */ '=' identifier_init  {
388                 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
389
390 /*
391  TODO: devise standard for protection in parser.
392
393   The parser stack lives on the C-stack, which means that
394 all objects can be unprotected as soon as they're here.
395
396 */
397         /*
398                 Should find generic way of associating input with objects.
399         */
400                 THIS->pop_spot ();
401         }
402         ;
403
404
405
406 identifier_init:
407         score_block {
408                 $$ = $1->self_scm ();
409                 scm_unprotect_object ($$);
410         }
411         | output_def {
412                 $$ = $1->self_scm ();
413                 scm_unprotect_object ($$);
414         }
415         | translator_spec_block {
416                 $$ = $1;
417         }
418         | Music  {
419                 $$ = $1->self_scm ();
420                 scm_unprotect_object ($$);
421         }
422         | post_request {
423                 $$ = $1->self_scm ();
424                 scm_unprotect_object ($$);
425         }
426         | explicit_duration {
427                 $$ = $1;
428         }
429         | number_expression {
430                 $$ = $1;
431         }
432         | string {
433                 $$ = $1;
434         }
435         | embedded_scm  {
436                 $$ = $1;
437         }
438         ;
439
440 translator_spec_block:
441         TRANSLATOR '{' translator_spec_body '}'
442                 {
443                 $$ = $3;
444         }
445         ;
446
447 translator_spec_body:
448         TRANSLATOR_IDENTIFIER   {
449                 $$ = unsmob_translator_def ($1)->clone_scm ();
450                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
451         }
452         | TYPE STRING semicolon {
453                 $$ = Translator_def::make_scm ();
454                 Translator_def*td =  unsmob_translator_def ($$);
455                 td->translator_group_type_ = $2;
456                 td->set_spot (THIS->here_input ());
457         }
458         | translator_spec_body STRING '=' embedded_scm                  {
459                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
460         }
461         | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
462                 unsmob_translator_def ($$)
463                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
464         }
465         | translator_spec_body STRING REVERT embedded_scm  {
466           unsmob_translator_def ($$)->add_pop_property (
467                 scm_string_to_symbol ($2), $4);
468         }
469         | translator_spec_body STRING '=' identifier_init semicolon     { 
470                 SCM v = gh_int2scm (0);
471                 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
472                         v = $4;
473                 else 
474                         THIS->parser_error (_ ("Wrong type for property value"));
475
476                 /* ugh*/
477                 unsmob_translator_def ($$)->add_property_assign ($2, v);
478         }
479         | translator_spec_body NAME STRING semicolon {
480                 unsmob_translator_def ($$)->type_name_ = $3;
481         }
482         | translator_spec_body CONSISTS STRING semicolon {
483                 unsmob_translator_def ($$)->add_element ($3);
484         }
485         | translator_spec_body ALIAS STRING semicolon {
486                 Translator_def*td = unsmob_translator_def ($$);
487                 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
488         }
489         | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
490                 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
491                         unsmob_translator_def ($$)
492                         ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
493
494         }
495         | translator_spec_body CONSISTSEND STRING semicolon {
496                 unsmob_translator_def ($$)->add_last_element ( $3);
497         }
498         | translator_spec_body ACCEPTS STRING semicolon {
499                 unsmob_translator_def ($$)->set_acceptor ($3,true);
500         }
501         | translator_spec_body DENIES STRING semicolon {
502                 unsmob_translator_def ($$)->set_acceptor ($3,false);
503         }
504         | translator_spec_body REMOVE STRING semicolon {
505                 unsmob_translator_def ($$)->remove_element ($3);
506         }
507         ;
508
509 /*
510         SCORE
511 */
512 score_block:
513         SCORE { 
514                 THIS->remember_spot ();
515         }
516         /*cont*/ '{' score_body '}'     {
517                 THIS->pop_spot ();
518                 $$ = $4;
519                 if (!$$->def_p_arr_.size ())
520                 {
521                   Music_output_def *id =
522                         unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
523                   $$->add_output (id ? id->clone () :  new Paper_def );
524                 }
525         }
526         ;
527
528 score_body:
529         Music   {
530                 $$ = new Score;
531         
532                 $$->set_spot (THIS->here_input ());
533                 SCM m = $1->self_scm ();
534                 scm_unprotect_object (m);
535                 $$->music_ = m;
536         }
537         | SCORE_IDENTIFIER {
538                 $$ = new Score (*unsmob_score ($1));
539                 $$->set_spot (THIS->here_input ());
540         }
541         | score_body lilypond_header    {
542                 scm_unprotect_object ($2->self_scm ()); 
543                 $$->header_p_ = $2;
544         }
545         | score_body output_def {
546                 $$->add_output ($2);
547         }
548         | score_body error {
549
550         }
551         ;
552
553
554 /*
555         MIDI
556 */
557 output_def:
558         music_output_def_body '}' {
559                 $$ = $1;
560                 THIS-> lexer_p_-> scope_l_arr_.pop ();
561         }
562         ;
563
564 music_output_def_body:
565         MIDI '{'    {
566            Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
567
568                 
569          Midi_def* p =0;
570         if (id)
571                 p = dynamic_cast<Midi_def*> (id->clone ());
572         else
573                 p = new Midi_def;
574
575          $$ = p;
576          THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
577         }
578         | PAPER '{'     {
579                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
580                   Paper_def *p = 0;
581                 if (id)
582                         p = dynamic_cast<Paper_def*> (id->clone ());
583                 else
584                         p = new Paper_def;
585                 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
586                 $$ = p;
587         }
588         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
589                 Music_output_def *p = unsmob_music_output_def ($3);
590                 p = p->clone ();
591                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
592                 $$ = p;
593         }
594         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
595                 Music_output_def *p = unsmob_music_output_def ($3);
596                 p = p->clone ();
597
598                 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
599                 $$ = p;
600         }
601         | music_output_def_body assignment semicolon {
602
603         }
604         | music_output_def_body translator_spec_block   {
605                 $$->assign_translator ($2);
606         }
607         | music_output_def_body STYLESHEET embedded_scm {
608                 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
609         }
610         | music_output_def_body tempo_request semicolon {
611                 /*
612                         junk this ? there already is tempo stuff in
613                         music.
614                 */
615                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
616                 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
617                 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
618         }
619         | music_output_def_body error {
620
621         }
622         ;
623
624 tempo_request:
625         TEMPO steno_duration '=' bare_unsigned  {
626                 $$ = new Tempo_req;
627                 $$->set_mus_property ("duration", $2);
628                 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
629         }
630         ;
631
632 Music_list: /* empty */ {
633                 $$ = gh_cons (SCM_EOL, SCM_EOL);
634         }
635         | Music_list Music {
636                 SCM s = $$;
637                 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
638                 scm_unprotect_object ($2->self_scm ()); /* UGH */
639                 if (gh_pair_p (gh_cdr (s)))
640                         gh_set_cdr_x (gh_cdr (s), c); /* append */
641                 else
642                         gh_set_car_x (s, c); /* set first cons */
643                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
644         }
645         | Music_list error {
646         }
647         ;
648
649
650 Music:
651         Simple_music
652         | Composite_music
653         ;
654
655 Alternative_music:
656         /* empty */ {
657                 $$ = 0;
658         }
659         | ALTERNATIVE Music_sequence {
660                 $$ = $2;
661                 $2->set_spot (THIS->here_input ());
662         }
663         ;
664
665
666
667
668 Repeated_music:
669         REPEAT string bare_unsigned Music Alternative_music
670         {
671                 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
672                 if (alts && $3 < alts->length_i ())
673                         $5->origin ()->warning (_ ("More alternatives than repeats.  Junking excess alternatives."));
674                 Music *beg = $4;
675                 int times = $3;
676
677                 Repeated_music * r = new Repeated_music (SCM_EOL);
678
679                 if (beg)
680                         {
681                         r-> set_mus_property ("body", beg->self_scm ());
682                         scm_unprotect_object (beg->self_scm ());
683                         }
684                 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
685
686                 if (alts)
687                         {
688                         alts->truncate (times);
689                         r-> set_mus_property ("alternatives", alts->self_scm ());
690                         scm_unprotect_object (alts->self_scm ());  
691                         }
692                 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
693                 SCM result = gh_call1 (func, $2);
694
695                 set_music_properties (r, result);
696
697                 r->set_spot (*$4->origin ());
698                 $$ = r;
699         }
700         ;
701
702 Music_sequence: '{' Music_list '}'      {
703                 $$ = new Music_sequence (SCM_EOL);
704                 $$->set_mus_property ("elements", gh_car ($2));
705         }
706         ;
707
708 Sequential_music:
709         SEQUENTIAL '{' Music_list '}'           {
710                 $$ = new Sequential_music (SCM_EOL);
711                 $$->set_mus_property ("elements", gh_car ($3));
712         }
713         | '{' Music_list '}'            {
714                 $$ = new Sequential_music (SCM_EOL);
715                 $$->set_mus_property ("elements", gh_car ($2));
716         }
717         ;
718
719 Simultaneous_music:
720         SIMULTANEOUS '{' Music_list '}'{
721                 $$ = new Simultaneous_music (SCM_EOL);
722                 $$->set_mus_property ("elements", gh_car ($3));
723
724         }
725         | '<' Music_list '>'    {
726                 $$ = new Simultaneous_music (SCM_EOL);
727                 $$->set_mus_property ("elements", gh_car ($2));
728         }
729         ;
730
731 Simple_music:
732         request_chord           { $$ = $1; }
733         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
734                 SCM pred = $2;
735                 if (!gh_symbol_p ($3))
736                 {
737                         THIS->parser_error (_ ("Second argument must be a symbol")); 
738                 }
739                 /*hould check # args */
740                 if (!gh_procedure_p (pred))
741                 {
742                         THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
743                 }
744
745                 Music *m = new Music (SCM_EOL);
746                 m->set_mus_property ("predicate", pred);
747                 m->set_mus_property ("symbol", $3);
748                 m->set_mus_property ("value",  $5);
749                 m->set_mus_property ("iterator-ctor",
750                 Output_property_music_iterator::constructor_cxx_function);
751
752                 $$ = m;
753         }
754         | MUSIC_IDENTIFIER {
755                 $$ = unsmob_music ($1)->clone ();
756         }
757         | property_def
758         | translator_change
759         | Simple_music '*' bare_unsigned '/' bare_unsigned      {
760                 $$ = $1;
761                 $$->compress (Moment ($3, $5 ));
762         }
763         | Simple_music '*' bare_unsigned                 {
764                 $$ = $1;
765                 $$->compress (Moment ($3, 1));
766         }
767         ;
768
769
770 Composite_music:
771         CONTEXT STRING Music    {
772                 Context_specced_music *csm =  new Context_specced_music (SCM_EOL);
773                 csm->set_mus_property ("element", $3->self_scm ());
774                 scm_unprotect_object ($3->self_scm ());
775
776                 csm->set_mus_property ("context-type",$2);
777                 csm->set_mus_property ("context-id", ly_str02scm (""));
778
779                 $$ = csm;
780         }
781         | AUTOCHANGE STRING Music       {
782                 Music * chm = new Music_wrapper (SCM_EOL);
783                 chm->set_mus_property ("element", $3->self_scm ());
784                 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
785
786                 scm_unprotect_object ($3->self_scm ());
787                 chm->set_mus_property ("what", $2); 
788
789                 $$ = chm;
790                 chm->set_spot (*$3->origin ());
791         }
792         | GRACE Music {
793                 $$ = new Grace_music (SCM_EOL);
794                 $$->set_mus_property ("element", $2->self_scm ());
795                 scm_unprotect_object ($2->self_scm ());
796
797         }
798         | CONTEXT STRING '=' STRING Music {
799                 Context_specced_music *csm =  new Context_specced_music (SCM_EOL);
800                 csm->set_mus_property ("element", $5->self_scm ());
801                 scm_unprotect_object ($5->self_scm ());
802
803                 csm->set_mus_property ("context-type", $2);
804                 csm->set_mus_property ("context-id", $4);
805
806                 $$ = csm;
807         }
808         | TIMES {
809                 THIS->remember_spot ();
810         }
811         /* CONTINUED */ 
812                 bare_unsigned '/' bare_unsigned Music   
813
814         {
815                 int n = $3; int d = $5;
816                 Music *mp = $6;
817                 $$ = new Time_scaled_music (SCM_EOL);
818                 $$->set_spot (THIS->pop_spot ());
819
820
821                 $$->set_mus_property ("element", mp->self_scm ());
822                 scm_unprotect_object (mp->self_scm ());
823                 $$->set_mus_property ("numerator", gh_int2scm (n));
824                 $$->set_mus_property ("denominator", gh_int2scm (d));
825                 $$->compress (Moment (n,d));
826
827         }
828         | Repeated_music                { $$ = $1; }
829         | Simultaneous_music            { $$ = $1; }
830         | Sequential_music              { $$ = $1; }
831         | TRANSPOSE pitch Music {
832                 $$ = new Transposed_music (SCM_EOL);
833                 Music *p = $3;
834                 Pitch pit = *unsmob_pitch ($2);
835
836                 p->transpose (pit);
837                 $$->set_mus_property ("element", p->self_scm ());
838                 scm_unprotect_object (p->self_scm ());
839         }
840         | TRANSPOSE steno_tonic_pitch Music {
841                 $$ = new Transposed_music (SCM_EOL);
842                 Music *p = $3;
843                 Pitch pit = *unsmob_pitch ($2);
844
845                 p->transpose (pit);
846                 $$->set_mus_property ("element", p->self_scm ());
847                 scm_unprotect_object (p->self_scm ());
848         
849         }
850         | APPLY embedded_scm Music  {
851                 SCM ret = gh_call1 ($2, $3->self_scm ());
852                 Music *m = unsmob_music (ret);
853                 if (!m) {
854                         THIS->parser_error ("\\apply must return a Music");
855                         m = new Music (SCM_EOL);
856                         }
857                 $$ = m;
858         }
859         | NOTES
860                 { THIS->lexer_p_->push_note_state (); }
861         Music
862                 { $$ = $3;
863                   THIS->lexer_p_->pop_state ();
864                 }
865         | CHORDS
866                 { THIS->lexer_p_->push_chord_state (); }
867         Music
868                 {
869                   Music * chm = new Un_relativable_music ;
870                   chm->set_mus_property ("element", $3->self_scm ());
871                   $$ = chm;
872
873                   THIS->lexer_p_->pop_state ();
874         }
875         | LYRICS
876                 { THIS->lexer_p_->push_lyric_state (); }
877         Music
878                 {
879                   $$ = $3;
880                   THIS->lexer_p_->pop_state ();
881         }
882         | relative_music        { $$ = $1; }
883         | re_rhythmed_music     { $$ = $1; } 
884         | part_combined_music   { $$ = $1; } 
885         ;
886
887 relative_music:
888         RELATIVE absolute_pitch Music {
889                 Music * p = $3;
890                 Pitch pit = *unsmob_pitch ($2);
891                 $$ = new Relative_octave_music (SCM_EOL);
892
893                 $$->set_mus_property ("element", p->self_scm ());
894                 scm_unprotect_object (p->self_scm ());
895
896                 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
897
898         }
899         ;
900
901 re_rhythmed_music:
902         ADDLYRICS Music Music {
903           Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
904           l->set_mus_property ("music", $2->self_scm ());
905           l->set_mus_property ("lyrics", $3->self_scm ());
906           scm_unprotect_object ($3->self_scm ());
907           scm_unprotect_object ($2->self_scm ());
908           $$ = l;
909         }
910         ;
911
912 part_combined_music:
913         PARTCOMBINE STRING Music Music {
914                 Part_combine_music * p = new Part_combine_music (SCM_EOL);
915
916                 p->set_mus_property ("what", $2);
917                 p->set_mus_property ("one", $3->self_scm ());
918                 p->set_mus_property ("two", $4->self_scm ());  
919
920                 scm_unprotect_object ($3->self_scm ());
921                 scm_unprotect_object ($4->self_scm ());  
922
923
924                 $$ = p;
925         }
926         ;
927
928 translator_change:
929         TRANSLATOR STRING '=' STRING  {
930                 Music * t = new Music (SCM_EOL);
931                 t->set_mus_property ("iterator-ctor",
932                         Change_iterator::constructor_cxx_function);
933                 t-> set_mus_property ("change-to-type", $2);
934                 t-> set_mus_property ("change-to-id", $4);
935
936                 $$ = t;
937                 $$->set_spot (THIS->here_input ());
938         }
939         ;
940
941 property_def:
942         PROPERTY STRING '.' STRING '='  scalar {
943                 Music *t = new Music (SCM_EOL);
944
945                 t->set_mus_property ("iterator-ctor",
946                         Property_iterator::constructor_cxx_function);
947                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
948                 t->set_mus_property ("value", $6);
949
950                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
951
952                 csm->set_mus_property ("element", t->self_scm ());
953                 scm_unprotect_object (t->self_scm ());
954
955                 $$ = csm;
956                 $$->set_spot (THIS->here_input ());
957
958                 csm-> set_mus_property ("context-type", $2);
959         }
960         | PROPERTY STRING '.' STRING UNSET {
961                 Music *t = new Music (SCM_EOL);
962
963                 t->set_mus_property ("iterator-ctor",
964                         Property_unset_iterator::constructor_cxx_function);
965                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
966
967                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
968                 csm->set_mus_property ("element", t->self_scm ());
969                 scm_unprotect_object (t->self_scm ());
970
971                 $$ = csm;
972                 $$->set_spot (THIS->here_input ());
973
974                 csm-> set_mus_property ("context-type", $2);
975         }
976         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
977                 Music *t = new Music (SCM_EOL);
978                 t->set_mus_property ("iterator-ctor",
979                         Push_property_iterator::constructor_cxx_function);
980                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
981                 t->set_mus_property ("pop-first", SCM_BOOL_T);
982                 t->set_mus_property ("grob-property", $6);
983                 t->set_mus_property ("grob-value", $8);
984                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
985                 csm->set_mus_property ("element", t->self_scm ());
986                 scm_unprotect_object (t->self_scm ());
987                 $$ = csm;
988                 $$->set_spot (THIS->here_input ());
989
990                 csm-> set_mus_property ("context-type", $2);
991         }
992         | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
993                 Music *t = new Music (SCM_EOL);
994                 t->set_mus_property ("iterator-ctor",
995                         Push_property_iterator::constructor_cxx_function);
996                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
997                 t->set_mus_property ("grob-property", $6);
998                 t->set_mus_property ("grob-value", $8);
999                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1000                 csm->set_mus_property ("element", t->self_scm ());
1001                 scm_unprotect_object (t->self_scm ());
1002
1003                 $$ = csm;
1004                 $$->set_spot (THIS->here_input ());
1005
1006                 csm-> set_mus_property ("context-type", $2);
1007         }
1008         | PROPERTY STRING '.' STRING REVERT embedded_scm {
1009                 Music *t = new Music (SCM_EOL);
1010                 t->set_mus_property ("iterator-ctor",
1011                         Pop_property_iterator::constructor_cxx_function);
1012                 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1013                 t->set_mus_property ("grob-property", $6);
1014
1015                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1016                 csm->set_mus_property ("element", t->self_scm ());
1017                 scm_unprotect_object (t->self_scm ());
1018
1019                 $$ = csm;
1020                 $$->set_spot (THIS->here_input ());
1021
1022                 csm-> set_mus_property ("context-type", $2);
1023         }
1024         ;
1025
1026 scalar:
1027         string          { $$ = $1; }
1028         | bare_int      { $$ = gh_int2scm ($1); }
1029         | embedded_scm  { $$ = $1; }
1030         ;
1031
1032
1033 request_chord:
1034         pre_requests simple_element post_requests       {
1035                 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1036                 if (l) {
1037                         for (int i=0; i < $1->size (); i++)
1038                                 l->append_music ($1->elem (i));
1039                         for (int i=0; i < $3->size (); i++)
1040                                 l->append_music ($3->elem (i));
1041                         }
1042                 else
1043                         programming_error ("Need Sequence to add music to");
1044                 $$ = $2;
1045                 
1046         }
1047         | command_element
1048         ;
1049
1050 command_element:
1051         command_req {
1052                 $$ = new Request_chord (SCM_EOL);
1053                 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1054                 $$-> set_spot (THIS->here_input ());
1055                 $1-> set_spot (THIS->here_input ());
1056         }
1057         | BAR STRING ';'                        {
1058                 Music *t = new Music (SCM_EOL);
1059
1060                 t->set_mus_property ("iterator-ctor",
1061                         Property_iterator::constructor_cxx_function);
1062                 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1063                 t->set_mus_property ("value", $2);
1064
1065                 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1066                 csm->set_mus_property ("element", t->self_scm ());
1067                 scm_unprotect_object (t->self_scm ());
1068
1069                 $$ = csm;
1070                 $$->set_spot (THIS->here_input ());
1071
1072                 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1073         }
1074         | PARTIAL duration_length ';'   {
1075                 Music * p = new Music (SCM_EOL);
1076                 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1077                 p->set_mus_property ("iterator-ctor",
1078                         Property_iterator::constructor_cxx_function);
1079
1080                 Moment m = - unsmob_duration ($2)->length_mom ();
1081                 p->set_mus_property ("value", m.smobbed_copy ());
1082
1083                 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1084                 sp->set_mus_property ("element", p->self_scm ());
1085                 scm_unprotect_object (p->self_scm ());
1086
1087                 $$ =sp ;
1088                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1089         }
1090         | CLEF STRING ';' {
1091                 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1092                 SCM result = gh_call1 (func, $2);
1093
1094                 SCM l = SCM_EOL;
1095                 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1096                         Music * p = new Music (SCM_EOL);
1097                         set_music_properties (p, gh_car (s));
1098                         l = gh_cons (p->self_scm (), l);
1099                         scm_unprotect_object (p->self_scm ());
1100                 }
1101                 Sequential_music * seq = new Sequential_music (SCM_EOL);
1102                 seq->set_mus_property ("elements", l);
1103
1104                 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1105                 sp->set_mus_property ("element", seq->self_scm ());
1106                 scm_unprotect_object (seq->self_scm ());
1107
1108                 $$ =sp ;
1109                 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1110         }
1111         | TIME_T bare_unsigned '/' bare_unsigned ';' {
1112                 Music * p = new Music (SCM_EOL);
1113                 p->set_mus_property ("symbol",
1114                         ly_symbol2scm ( "timeSignatureFraction"));
1115                 p->set_mus_property ("iterator-ctor",
1116                         Property_iterator::constructor_cxx_function);
1117
1118                 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1119                                                         gh_int2scm ($4)));
1120
1121                 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1122                 sp->set_mus_property ("element", p->self_scm ());
1123                 scm_unprotect_object (p->self_scm ());
1124
1125                 $$ = sp;
1126                 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1127         }
1128         ;
1129
1130 command_req:
1131         shorthand_command_req   { $$ = $1; }
1132         | verbose_command_req semicolon { $$ = $1; }
1133         ;
1134
1135 shorthand_command_req:
1136         extender_req {
1137                 $$ = $1;
1138         }
1139         | hyphen_req {
1140                 $$ = $1;
1141         }
1142         | '|'                           {
1143                 $$ = new Barcheck_req;
1144         }
1145         | '~'   {
1146                 $$ = new Tie_req;
1147         }
1148         | '['           {
1149                 Span_req*b= new Span_req;
1150                 b->set_span_dir (START);
1151                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1152                 $$ =b;
1153         }
1154         | ']'           {
1155                 Span_req*b= new Span_req;
1156                 b->set_span_dir ( STOP);
1157                 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1158                 $$ = b;
1159         }
1160         | BREATHE {
1161                 $$ = new Breathing_sign_req;
1162         }
1163         ;
1164
1165
1166 verbose_command_req:
1167         COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1168                 Span_req * sp_p = new Span_req;
1169                 sp_p-> set_span_dir ( Direction ($2));
1170                 sp_p->set_mus_property ("span-type",$3);
1171                 sp_p->set_spot (THIS->here_input ());
1172                 $$ = sp_p;
1173         }
1174         | MARK  {
1175                 Mark_req * m = new Mark_req;
1176                 $$ = m;
1177         }
1178         | MARK scalar {
1179                 Mark_req *m = new Mark_req;
1180                 m->set_mus_property ("label", $2);
1181                 $$ = m;
1182
1183         }
1184         | PENALTY bare_int      {
1185                 Break_req * b = new Break_req;
1186                 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1187                 b->set_spot (THIS->here_input ());
1188                 $$ = b;
1189         }
1190         | SKIP duration_length {
1191                 Skip_req * skip_p = new Skip_req;
1192                 skip_p->set_mus_property ("duration", $2);
1193
1194                 $$ = skip_p;
1195         }
1196         | tempo_request {
1197                 $$ = $1;
1198         }
1199         | KEY {
1200                 Key_change_req *key_p= new Key_change_req;
1201                 $$ = key_p;
1202         }
1203         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1204                 Key_change_req *key_p= new Key_change_req;
1205                 
1206                 key_p->set_mus_property ("pitch-alist", $3);
1207  ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1208                 $$ = key_p; 
1209         }
1210         ;
1211
1212 post_requests:
1213         {
1214                 $$ = new Link_array<Request>;
1215         }
1216         | post_requests post_request {
1217                 $2->set_spot (THIS->here_input ());
1218                 $$->push ($2);
1219         }
1220         ;
1221
1222 post_request:
1223         verbose_request
1224         | request_with_dir
1225         | close_request
1226         ;
1227
1228
1229 request_that_take_dir:
1230         gen_text_def
1231         | verbose_request
1232         | script_abbreviation {
1233                 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1234                 Articulation_req *a = new Articulation_req;
1235                 if (gh_string_p (s))
1236                         a->set_mus_property ("articulation-type", s);
1237                 else THIS->parser_error (_ ("Expecting string as script definition"));
1238                 $$ = a;
1239         }
1240         ;
1241
1242 request_with_dir:
1243         script_dir request_that_take_dir        {
1244                 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1245                         gs->set_direction (Direction ($1));
1246                 else if ($1)
1247                         $2->origin ()->warning (_ ("Can't specify direction for this request"));
1248                 $$ = $2;
1249         }
1250         ;
1251         
1252 verbose_request:
1253         REQUEST_IDENTIFIER      {
1254                 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1255                 $$->set_spot (THIS->here_input ());
1256         }
1257         | DYNAMICSCRIPT embedded_scm {
1258                 /*
1259                         TODO: junkme, use text-type == dynamic
1260                 */
1261                 Text_script_req *d = new Text_script_req;
1262                 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1263                 d->set_mus_property ("text", $2);
1264                 d->set_spot (THIS->here_input ());
1265                 $$ = d;
1266         }
1267         | TEXTSCRIPT embedded_scm {
1268                 Text_script_req *t = new Text_script_req;
1269                 t->set_mus_property ("text", $2);
1270                 t->set_spot (THIS->here_input ());
1271                 $$ = t;
1272         }
1273         | SPANREQUEST bare_int STRING {
1274                 Span_req * sp_p = new Span_req;
1275                 sp_p->set_span_dir ( Direction ($2));
1276                 sp_p->set_mus_property ("span-type", $3);
1277                 sp_p->set_spot (THIS->here_input ());
1278                 $$ = sp_p;
1279         }
1280         | tremolo_type  {
1281                Tremolo_req* a = new Tremolo_req;
1282                a->set_spot (THIS->here_input ());
1283                a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1284                $$ = a;
1285         }
1286         | SCRIPT STRING         { 
1287                 Articulation_req * a = new Articulation_req;
1288                 a->set_mus_property ("articulation-type", $2);
1289                 a->set_spot (THIS->here_input ());
1290                 $$ = a;
1291         }
1292         /*
1293 duh, junk this syntax from the parser, if possible. 
1294         */
1295         | ARPEGGIO {
1296                 Arpeggio_req *a = new Arpeggio_req;
1297                 a->set_spot (THIS->here_input ());
1298                 $$ = a;
1299         }
1300         | GLISSANDO {
1301                 Glissando_req *g = new Glissando_req;
1302                 g->set_spot /* No pun intended */ (THIS->here_input ());
1303                 $$ = g;
1304         }       
1305         ;
1306
1307 sup_quotes:
1308         '\'' {
1309                 $$ = 1;
1310         }
1311         | sup_quotes '\'' {
1312                 $$ ++;
1313         }
1314         ;
1315
1316 sub_quotes:
1317         ',' {
1318                 $$ = 1;
1319         }
1320         | sub_quotes ',' {
1321                 $$ ++ ;
1322         }
1323         ;
1324
1325 steno_pitch:
1326         NOTENAME_PITCH  {
1327                 $$ = $1;
1328         }
1329         | NOTENAME_PITCH sup_quotes     {
1330                 Pitch p = *unsmob_pitch ($1);
1331                 p.octave_i_ +=  $2;
1332                 $$ = p.smobbed_copy ();
1333         }
1334         | NOTENAME_PITCH sub_quotes      {
1335                 Pitch p =* unsmob_pitch ($1);
1336
1337                 p.octave_i_ +=  -$2;
1338                 $$ = p.smobbed_copy ();
1339
1340         }
1341         ;
1342
1343 /*
1344 ugh. duplication
1345 */
1346
1347 steno_tonic_pitch:
1348         TONICNAME_PITCH {
1349                 $$ = $1;
1350         }
1351         | TONICNAME_PITCH sup_quotes    {
1352                 Pitch p = *unsmob_pitch ($1);
1353                 p.octave_i_ +=  $2;
1354                 $$ = p.smobbed_copy ();
1355         }
1356         | TONICNAME_PITCH sub_quotes     {
1357                 Pitch p =* unsmob_pitch ($1);
1358
1359                 p.octave_i_ +=  -$2;
1360                 $$ = p.smobbed_copy ();
1361
1362         }
1363         ;
1364
1365 pitch:
1366         steno_pitch {
1367                 $$ = $1;
1368         }
1369         | explicit_pitch {
1370                 $$ = $1;
1371         }
1372         ;
1373
1374 explicit_pitch:
1375         PITCH embedded_scm {
1376                 $$ = $2;
1377                 if (!unsmob_pitch ($2)) {
1378                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1379                          $$ = Pitch ().smobbed_copy ();
1380                 }
1381         }
1382         ;
1383
1384 explicit_duration:
1385         DURATION embedded_scm   {
1386                 $$ = $2;
1387                 if (!unsmob_duration ($2))
1388                 {
1389                         THIS->parser_error (_ ("Must have duration object"));
1390                         $$ = Duration ().smobbed_copy ();
1391                 }
1392         }
1393         ;
1394
1395 extender_req:
1396         EXTENDER {
1397                 if (!THIS->lexer_p_->lyric_state_b ())
1398                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1399                 $$ = new Extender_req;
1400         }
1401         ;
1402
1403 hyphen_req:
1404         HYPHEN {
1405                 if (!THIS->lexer_p_->lyric_state_b ())
1406                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1407                 $$ = new Hyphen_req;
1408         }
1409         ;
1410
1411 close_request:
1412         close_request_parens {
1413                 $$ = $1;
1414                 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1415         }
1416         
1417 close_request_parens:
1418         '('     {
1419                 Span_req* s= new Span_req;
1420                 $$ = s;
1421                 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1422         }
1423         | E_OPEN        {
1424                 Span_req* s= new Span_req;
1425                 $$ = s;
1426                 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1427         }
1428         | E_SMALLER {
1429                 Span_req*s =new Span_req;
1430                 $$ = s;
1431                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1432         }
1433         | E_BIGGER {
1434                 Span_req*s =new Span_req;
1435                 $$ = s;
1436                 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1437         }
1438         ;
1439
1440
1441 open_request:
1442         open_request_parens {
1443                 $$ = $1;
1444                 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1445         }
1446         ;
1447
1448 open_request_parens:
1449         E_EXCLAMATION   {
1450                 Span_req *s =  new Span_req;
1451                 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1452
1453                 $$ = s;
1454         }
1455         | ')'   {
1456                 Span_req* s= new Span_req;
1457                 $$ = s;
1458                 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1459         }
1460         | E_CLOSE       {
1461                 Span_req* s= new Span_req;
1462                 $$ = s;
1463                 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1464         }
1465         ;
1466
1467 gen_text_def:
1468         embedded_scm {
1469                 Text_script_req *t = new Text_script_req;
1470                 t->set_mus_property ("text", $1);
1471                 t->set_spot (THIS->here_input ());
1472                 $$ = t;
1473         }
1474         | string {
1475                 Text_script_req *t = new Text_script_req;
1476                 t->set_mus_property ("text", $1);
1477                 t->set_spot (THIS->here_input ());
1478                 $$ = t;
1479         }
1480         | DIGIT {
1481                 String ds = to_str ($1);
1482                 Text_script_req* t = new Text_script_req;
1483
1484                 t->set_mus_property ("text",  ly_str02scm (ds.ch_C ()));
1485                 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1486                 t->set_spot (THIS->here_input ());
1487                 $$ = t;
1488         }
1489         ;
1490
1491 script_abbreviation:
1492         '^'             {
1493                 $$ = gh_str02scm ("hat");
1494         }
1495         | '+'           {
1496                 $$ = gh_str02scm ("plus");
1497         }
1498         | '-'           {
1499                 $$ = gh_str02scm ("dash");
1500         }
1501         | '|'           {
1502                 $$ = gh_str02scm ("bar");
1503         }
1504         | '>'           {
1505                 $$ = gh_str02scm ("larger");
1506         }
1507         | '.'           {
1508                 $$ = gh_str02scm ("dot");
1509         }
1510         ;
1511
1512
1513 script_dir:
1514         '_'     { $$ = DOWN; }
1515         | '^'   { $$ = UP; }
1516         | '-'   { $$ = CENTER; }
1517         ;
1518
1519 pre_requests:
1520         {
1521                 $$ = new Link_array<Request>;
1522         }
1523         | pre_requests open_request {
1524                 $$->push ($2);
1525         }
1526         ;
1527
1528 absolute_pitch:
1529         steno_pitch     {
1530                 $$ = $1;
1531         }
1532         ;
1533
1534 duration_length:
1535         steno_duration {
1536                 $$ = $1;
1537         }
1538         | explicit_duration {
1539                 $$ = $1;
1540         }       
1541         | duration_length '*' bare_unsigned {
1542                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1543         }
1544         | duration_length '/' bare_unsigned {
1545                 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1546         }
1547         ;
1548
1549 entered_notemode_duration:
1550         steno_duration  {
1551                 THIS->set_last_duration (unsmob_duration ($1));
1552         }
1553         ;
1554
1555 optional_notemode_duration:
1556         {
1557                 $$ = THIS->default_duration_.smobbed_copy ();
1558         }
1559         | entered_notemode_duration {
1560                 $$ = $1;
1561         }
1562         | explicit_duration {
1563                 $$ = $1;
1564         }       
1565         ;
1566
1567 steno_duration:
1568         bare_unsigned dots              {
1569                 int l = 0;
1570                 if (!is_duration_b ($1))
1571                         THIS->parser_error (_f ("not a duration: %d", $1));
1572                 else
1573                         l =  intlog2 ($1);
1574
1575                 $$ = Duration (l, $2).smobbed_copy ();
1576         }
1577         | DURATION_IDENTIFIER dots      {
1578                 Duration *d =unsmob_duration ($1);
1579                 Duration k (d->duration_log (),d->dot_count () + $2);
1580                 $$ = k.smobbed_copy ();         
1581         }
1582         ;
1583
1584 dots:
1585         /* empty */     {
1586                 $$ = 0;
1587         }
1588         | dots '.' {
1589                 $$ ++;
1590         }
1591         ;
1592
1593
1594 tremolo_type: 
1595         ':'     {
1596                 $$ =0;
1597         }
1598         | ':' bare_unsigned {
1599                 if (!is_duration_b ($2))
1600                         THIS->parser_error (_f ("not a duration: %d", $2));
1601                 $$ = $2;
1602         }
1603         ;
1604
1605
1606 simple_element:
1607         pitch exclamations questions optional_notemode_duration {
1608                 if (!THIS->lexer_p_->note_state_b ())
1609                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1610
1611                 Note_req *n = new Note_req;
1612                 
1613                 n->set_mus_property ("pitch", $1);
1614                 n->set_mus_property ("duration", $4);
1615
1616                 if ($3 % 2)
1617                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1618                 if ($2 % 2 || $3 % 2)
1619                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1620
1621                 Simultaneous_music*v = new Request_chord (SCM_EOL);
1622                 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1623                 
1624 /*
1625 FIXME: location is one off, since ptich & duration don't contain origin refs. 
1626 */
1627                 v->set_spot (THIS->here_input ());
1628                 n->set_spot (THIS->here_input ());
1629
1630                 $$ = v;
1631         }
1632         | RESTNAME optional_notemode_duration           {
1633
1634                 SCM e = SCM_UNDEFINED;
1635                   if (ly_scm2string ($1) =="s")
1636                     { /* Space */
1637                       Skip_req * skip_p = new Skip_req;
1638                       skip_p->set_mus_property ("duration" ,$2);
1639
1640                       skip_p->set_spot (THIS->here_input ());
1641                         e = skip_p->self_scm ();
1642                     }
1643                   else
1644                     {
1645                       Rest_req * rest_req_p = new Rest_req;
1646                       rest_req_p->set_mus_property ("duration", $2);
1647                       rest_req_p->set_spot (THIS->here_input ());
1648                         e = rest_req_p->self_scm ();
1649                     }
1650                   Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1651                 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1652                   velt_p->set_spot (THIS->here_input ());
1653
1654
1655                   $$ = velt_p;
1656         }
1657         | MULTI_MEASURE_REST optional_notemode_duration         {
1658                 Skip_req * sk = new Skip_req;
1659                 sk->set_mus_property ("duration", $2);
1660                 Span_req *sp1 = new Span_req;
1661                 Span_req *sp2 = new Span_req;
1662                 sp1-> set_span_dir ( START);
1663                 sp2-> set_span_dir ( STOP);
1664                 SCM r = ly_str02scm ("rest");
1665                 sp1->set_mus_property ("span-type", r);
1666                 sp2->set_mus_property ("span-type", r);
1667
1668                 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1669                 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1670                 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1671                 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1672                 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1673                 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1674
1675                 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1676
1677                 $$ = new Sequential_music (SCM_EOL);
1678                 $$->set_mus_property ("elements", ms);
1679         }
1680         | STRING { 
1681                 THIS->remember_spot ();
1682         } 
1683         /* cont */
1684         optional_notemode_duration      {
1685                 if (!THIS->lexer_p_->lyric_state_b ()) {
1686                         THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1687                         THIS->error_level_i_  = 1;
1688                         THIS->parser_error (_ ("Giving up"));
1689                 } 
1690                 else
1691                         THIS->pop_spot ();
1692                 Lyric_req* lreq_p = new Lyric_req;
1693                 lreq_p->set_mus_property ("text", $1);
1694                 lreq_p->set_mus_property ("duration",$3);
1695                 lreq_p->set_spot (THIS->here_input ());
1696                 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1697                 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1698
1699
1700                 $$= velt_p;
1701
1702         }
1703         | chord {
1704                 if (!THIS->lexer_p_->chord_state_b ())
1705                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1706                 $$ = $1;
1707         }
1708         ;
1709
1710
1711 chord:
1712         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1713                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1714                 $$->set_spot (THIS->here_input ());
1715         };
1716
1717 chord_additions: 
1718         {
1719                 $$ = SCM_EOL;
1720         } 
1721         | CHORD_COLON chord_notes {
1722                 $$ = $2;
1723         }
1724         ;
1725
1726 chord_notes:
1727         chord_step {
1728                 $$ = $1
1729         }
1730         | chord_notes '.' chord_step {
1731                 $$ = gh_append2 ($$, $3);
1732         }
1733         ;
1734
1735 chord_subtractions: 
1736         {
1737                 $$ = SCM_EOL;
1738         } 
1739         | CHORD_CARET chord_notes {
1740                 $$ = $2;
1741         }
1742         ;
1743
1744
1745 chord_inversion:
1746         {
1747                 $$ = SCM_EOL;
1748         }
1749         | '/' steno_tonic_pitch {
1750                 $$ = $2;
1751         }
1752         ;
1753
1754 chord_bass:
1755         {
1756                 $$ = SCM_EOL;
1757         }
1758         | CHORD_BASS steno_tonic_pitch {
1759                 $$ = $2;
1760         }
1761         ;
1762
1763 chord_step:
1764         chord_note {
1765                 $$ = gh_cons ($1, SCM_EOL);
1766         }
1767         | CHORDMODIFIER_PITCH {
1768                 $$ = gh_cons ($1, SCM_EOL);
1769         }
1770         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1771                 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1772         }
1773         ;
1774
1775 chord_note:
1776         bare_unsigned {
1777                  Pitch m;
1778                 m.notename_i_ = ($1 - 1) % 7;
1779                 m.octave_i_ = $1 > 7 ? 1 : 0;
1780                 m.alteration_i_ = 0;
1781
1782                 $$ = m.smobbed_copy ();
1783         } 
1784         | bare_unsigned '+' {
1785                 Pitch m;
1786                 m.notename_i_ = ($1 - 1) % 7;
1787                 m.octave_i_ = $1 > 7 ? 1 : 0;
1788                 m.alteration_i_ = 1;
1789
1790
1791                 $$ = m.smobbed_copy ();
1792         }
1793         | bare_unsigned CHORD_MINUS {
1794                 Pitch m;
1795                 m.notename_i_ = ($1 - 1) % 7;
1796                 m.octave_i_ = $1 > 7 ? 1 : 0;
1797                 m.alteration_i_ = -1;
1798
1799                 $$ = m.smobbed_copy ();
1800         }
1801         ;
1802
1803 /*
1804         UTILITIES
1805  */
1806 number_expression:
1807         bare_number {
1808                 $$ = $1;
1809         }
1810         | '-'  number_expression %prec UNARY_MINUS {
1811                 $$ = scm_difference ($2, SCM_UNDEFINED);
1812         }
1813         | number_expression '*' number_expression {
1814                 $$ = scm_product ($1, $3);
1815         }
1816         | number_expression '/' number_expression {
1817                 $$ = scm_divide ($1, $3);
1818         }
1819         | number_expression '+' number_expression {
1820                 $$ = scm_sum ($1, $3);
1821         }
1822         | number_expression '-' number_expression {
1823                 $$ = scm_difference ($1, $3);
1824         }
1825         | '(' number_expression ')'     {
1826                 $$ = $2;
1827         }
1828         ;
1829
1830 bare_number:
1831         UNSIGNED        {
1832                 $$ = gh_int2scm ($1);
1833         }
1834         | DIGIT         {
1835                 $$ = gh_int2scm ($1);
1836         }
1837         | REAL          {
1838                 $$ = gh_double2scm ($1);
1839         }
1840         | NUMBER_IDENTIFIER             {
1841                 $$ = $1;
1842         }
1843         | REAL CM_T     {
1844                 $$ = gh_double2scm ($1 CM);
1845         }
1846         | REAL PT_T     {
1847                 $$ = gh_double2scm ($1 PT);
1848         }
1849         | REAL IN_T     {
1850                 $$ = gh_double2scm ($1 INCH);
1851         }
1852         | REAL MM_T     {
1853                 $$ = gh_double2scm ($1 MM);
1854         }
1855         | REAL CHAR_T   {
1856                 $$ = gh_double2scm ($1 CHAR);
1857         }
1858         ;
1859
1860
1861 bare_unsigned:
1862         bare_number {
1863                 if (scm_integer_p ($1) == SCM_BOOL_T) {
1864                         $$ = gh_scm2int ($1);
1865
1866                 } else {
1867                         THIS->parser_error (_ ("need integer number arg"));
1868                         $$ = 0;
1869                 }
1870                 if ($$ < 0) {
1871                         THIS->parser_error (_ ("Must be positive integer"));
1872                         $$ = -$$;
1873                         }
1874
1875         }
1876         ;
1877 bare_int:
1878         bare_number {
1879                 if (scm_integer_p ($1) == SCM_BOOL_T)
1880                 {
1881                         int k = gh_scm2int ($1);
1882                         $$ = k;
1883                 } else
1884                 {
1885                         THIS->parser_error (_ ("need integer number arg"));
1886                         $$ = 0;
1887                 }
1888         }
1889         | '-' bare_int {
1890                 $$ = -$2;
1891         }
1892         ;
1893
1894
1895 string:
1896         STRING          {
1897                 $$ = $1;
1898         }
1899         | STRING_IDENTIFIER     {
1900                 $$ = $1;
1901         }
1902         | string '+' string {
1903                 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1904         }
1905         ;
1906
1907
1908 exclamations:
1909                 { $$ = 0; }
1910         | exclamations '!'      { $$ ++; }
1911         ;
1912
1913 questions:
1914                 { $$ = 0; }
1915         | questions '?' { $$ ++; }
1916         ;
1917
1918
1919 semicolon:
1920         ';'
1921         ;
1922
1923 %%
1924
1925 void
1926 My_lily_parser::set_yydebug (bool b)
1927 {
1928 #ifdef YYDEBUG
1929         yydebug = b;
1930 #endif
1931 }
1932
1933 extern My_lily_parser * current_parser;
1934
1935 void
1936 My_lily_parser::do_yyparse ()
1937 {
1938
1939         current_parser = this;;
1940         yyparse ((void*)this);
1941 }
1942
1943