]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
d5a3d3f4b0c612d075a27dfb96572d7aea848aab
[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--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9            Jan Nieuwenhuizen <janneke@gnu.org>
10 */
11
12 /*
13   Two shift/reduce problems:
14
15 1.      foo = bar.
16
17         "bar" -> String -> Lyric -> Music -> music-assignment
18
19         "bar" -> String -> string-assignment
20
21
22 2.  \repeat
23         \repeat .. \alternative
24
25
26     \repeat { \repeat .. \alternative }
27
28 or
29
30     \repeat { \repeat } \alternative 
31
32 )
33
34 --hwn
35
36  */
37
38 /*
39
40 TODO:
41
42 * The rules for who is protecting what are very shady. Uniformise
43   this.
44
45 * There are too many lexical modes. 
46
47
48 */
49
50 #include <ctype.h>
51
52 #include "translator-def.hh"
53 #include "lily-guile.hh"
54 #include "misc.hh"
55 #include "my-lily-lexer.hh"
56 #include "paper-def.hh"
57 #include "midi-def.hh"
58 #include "main.hh"
59 #include "file-path.hh"
60 #include "warn.hh"
61 #include "dimensions.hh"
62 #include "my-lily-parser.hh"
63 #include "score.hh"
64 #include "input-file-results.hh"
65 #include "input.hh"
66 #include "lilypond-input-version.hh"
67 #include "scm-hash.hh"
68 #include "auto-change-iterator.hh"
69 #include "chord.hh"
70 #include "ly-modules.hh"
71 #include "music-sequence.hh"
72 #include "input-smob.hh"
73 #include "event.hh"
74 #include "text-item.hh"
75
76 bool
77 regular_identifier_b (SCM id)
78 {
79   String str = ly_scm2string (id);
80   char const *s = str.to_str0 () ;
81
82   bool v = true;
83   while (*s && v)
84    {
85         v = v && isalpha (*s);
86         s++;
87    }
88   return v;
89 }
90
91 SCM
92 make_simple_markup (SCM a)
93 {
94         static SCM simple;
95         if (!simple)
96         simple = scm_c_eval_string ("simple-markup");
97
98         return scm_list_n (simple, a, SCM_UNDEFINED);
99 }
100
101
102 bool
103 is_duration_b (int t)
104 {
105   return t && t == 1 << intlog2 (t);
106 }
107
108 void
109 set_music_properties (Music *p, SCM a)
110 {
111   for (SCM k = a; gh_pair_p (k); k = ly_cdr (k))
112         {
113         p->internal_set_mus_property (ly_caar (k), ly_cdar (k));
114         }
115 }
116
117
118
119 #define MY_MAKE_MUSIC(x)  make_music_by_name (ly_symbol2scm (x))
120
121 Music* 
122 set_property_music (SCM sym, SCM value)
123 {
124         Music * p = MY_MAKE_MUSIC("PropertySet");
125         p->set_mus_property ("symbol", sym);
126         p->set_mus_property ("value", value);
127         return p;
128 }
129
130
131 // needed for bison.simple's malloc () and free ()
132
133 // #include <malloc.h>
134 #include <stdlib.h>
135
136
137
138 #define YYERROR_VERBOSE 1
139
140 My_lily_parser* my_lily_parser;
141 #define YYPARSE_PARAM my_lily_parser
142 #define YYLEX_PARAM my_lily_parser
143 #define THIS\
144         ((My_lily_parser *) my_lily_parser)
145
146 #define yyerror THIS->parser_error
147
148 %}
149
150 /* We use SCMs to do strings, because it saves us the trouble of
151 deleting them.  Let's hope that a stack overflow doesnt trigger a move
152 of the parse stack onto the heap. */
153
154
155 %union {
156         String * string;
157     Music *music;
158     Score *score;
159     Music_output_def * outputdef;
160     SCM scm;
161     int i;
162 }
163 %{
164
165 int
166 yylex (YYSTYPE *s,  void * v)
167 {
168         My_lily_parser   *pars = (My_lily_parser*) v;
169         My_lily_lexer * lex = pars->lexer_;
170
171         lex->lexval = (void*) s;
172         lex->prepare_for_next_token();
173         return lex->yylex ();
174 }
175
176
177 %}
178
179 %pure_parser
180
181 /* tokens which are not keywords */
182 %token AUTOCHANGE
183 %token ALIAS
184 %token APPLYCONTEXT 
185 %token APPLY
186 %token ACCEPTS
187 %token ALTERNATIVE
188 %token BAR
189 %token BREATHE
190 %token CHORDMODIFIERS
191 %token CHORDS
192 %token CLEF
193 %token CONSISTS
194 %token DURATION
195 %token SEQUENTIAL
196 %token GROBDESCRIPTIONS
197 %token SIMULTANEOUS
198 %token CONSISTSEND
199 %token DENIES
200 %token EXTENDER
201 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
202 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
203 %token GRACE 
204 %token HEADER
205 %token HYPHEN
206 %token INVALID
207 %token KEY
208 %token LYRICS
209 %token MARK
210 %token MULTI_MEASURE_REST
211 %token MIDI
212 %token PITCH
213 %token DEFAULT
214 %token NAME
215 %token PITCHNAMES
216 %token NOTES
217 %token ONCE
218 %token PAPER
219 %token PARTIAL
220 %token PROPERTY
221 %token OVERRIDE SET REVERT 
222 %token RELATIVE
223 %token REMOVE
224 %token REPEAT
225 %token ADDLYRICS
226 %token PARTCOMBINE
227 %token SCM_T
228 %token SCORE
229 %token SKIP
230 %token SPANREQUEST
231 %token COMMANDSPANREQUEST
232 %token TEMPO
233 %token OUTPUTPROPERTY
234 %token TIME_T
235 %token TIMES
236 %token TRANSLATOR
237 %token TRANSPOSE
238 %token TYPE
239 %token UNSET
240 %token CONTEXT
241 %token REST
242
243 %token CHORD_OPEN
244 %token CHORD_CLOSE
245
246
247 /* escaped */
248 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
249 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
250 %token E_BACKSLASH
251 %token <i> E_UNSIGNED
252 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET  CHORD_SLASH
253 %token FIGURE_SPACE
254
255 %type <i>       exclamations questions dots optional_rest
256 %type <i>       bass_number bass_mod
257 %type <scm>     br_bass_figure bass_figure figure_list figure_spec
258 %token <i>      DIGIT
259 %token <scm>    NOTENAME_PITCH
260 %token <scm>    TONICNAME_PITCH
261 %token <scm>    CHORDMODIFIER_PITCH
262 %token <scm>    DURATION_IDENTIFIER
263 %token <scm>    FRACTION
264 %token <id>     IDENTIFIER
265 %token <scm>    CHORDNAMES CHORDNAMES_IDENTIFIER
266 %type <scm>     chordnames_block chordnames_list chord_scm
267
268
269 %token <scm>    SCORE_IDENTIFIER
270 %token <scm>    MUSIC_OUTPUT_DEF_IDENTIFIER
271 %token <scm>    NUMBER_IDENTIFIER
272 %token <scm>    EVENT_IDENTIFIER
273 %token <scm>    MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
274 %token <scm>    STRING_IDENTIFIER SCM_IDENTIFIER 
275 %token <scm>    RESTNAME
276 %token <scm>    STRING   
277 %token <scm>    SCM_T
278 %token <i>      UNSIGNED
279 %token <scm>   REAL
280
281 %token MARKUP
282 %token <scm> MARKUP_HEAD_MARKUP0
283 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
284 %token <scm> MARKUP_HEAD_SCM0
285 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
286 %token <scm> MARKUP_HEAD_SCM0_SCM1 
287 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
288
289 %token <scm> MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
290 %type <scm> markup markup_line markup_list  markup_list_body full_markup 
291
292 %type <outputdef> output_def
293 %type <scm>     lilypond_header lilypond_header_body
294 %type <music>   open_event_parens close_event_parens open_event close_event
295 %type <music> event_with_dir event_that_take_dir verbose_event
296 %type <i>       sub_quotes sup_quotes
297 %type <music>   simple_element  event_chord command_element Simple_music  Composite_music 
298 %type <music>   Repeated_music
299 %type <scm>     Alternative_music
300 %type <i>       tremolo_type
301 %type <i>       bare_int  bare_unsigned
302 %type <i>       script_dir
303 %type <scm>     identifier_init 
304
305 %type <music> note_chord_element chord_body chord_body_element
306 %type <scm>  chord_body_elements 
307 %type <scm> steno_duration optional_notemode_duration multiplied_duration
308 %type <scm>  verbose_duration
309         
310 %type <scm>  pre_events post_events
311 %type <music> gen_text_def
312 %type <scm>   steno_pitch pitch absolute_pitch pitch_also_in_chords
313 %type <scm>   explicit_pitch steno_tonic_pitch
314
315 %type <scm>     chord_additions chord_subtractions chord_notes chord_step
316 %type <music>   chord
317 %type <scm>     chord_note chord_inversion chord_bass
318 %type <scm>     duration_length fraction
319
320 %type <scm>  embedded_scm scalar
321 %type <music>   Music Sequential_music Simultaneous_music 
322 %type <music>   relative_music re_rhythmed_music part_combined_music
323 %type <music>   property_def translator_change  simple_property_def
324 %type <scm> Music_list
325 %type <outputdef>  music_output_def_body
326 %type <music> shorthand_command_req
327 %type <music>   post_event 
328 %type <music> command_req verbose_command_req
329 %type <music>   extender_req
330 %type <music> hyphen_req
331 %type <music> string_event
332 %type <scm>     string bare_number number_expression number_term number_factor 
333 %type <score>   score_block score_body
334
335 %type <scm>     translator_spec_block translator_spec_body
336 %type <music>   tempo_event
337 %type <scm> notenames_body notenames_block chordmodifiers_block
338 %type <scm>     script_abbreviation
339
340
341
342 %left '-' '+'
343
344 /* We don't assign precedence to / and *, because we might need varied
345 prec levels in different prods */
346
347 %left UNARY_MINUS
348
349 %%
350
351 lilypond:       /* empty */
352         | lilypond toplevel_expression {}
353         | lilypond assignment  { }
354         | lilypond error {
355                 THIS->error_level_  = 1;
356         }
357         | lilypond INVALID      {
358                 THIS->error_level_  = 1;
359         }
360         ;
361
362 toplevel_expression:
363         notenames_block                 {
364                 THIS->lexer_->pitchname_tab_ =  $1;
365         }
366         | chordmodifiers_block                  {
367                 THIS->lexer_->chordmodifier_tab_  = $1;
368         }
369         | lilypond_header {
370                 THIS->input_file_->header_ = $1;
371         }
372         | score_block {
373                 THIS->input_file_->scores_.push ($1);
374         }
375         | output_def {
376                 if (dynamic_cast<Paper_def*> ($1))
377                         THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultpaper"), $1->self_scm ());
378                 else if (dynamic_cast<Midi_def*> ($1))
379                         THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultmidi"), $1->self_scm ());
380         }
381         ;
382
383 embedded_scm:
384         SCM_T
385         | SCM_IDENTIFIER 
386         ;
387
388
389 chordmodifiers_block:
390         CHORDMODIFIERS notenames_body   {  $$ = $2; }
391         ;
392
393 notenames_block:
394         PITCHNAMES notenames_body   {  $$ = $2; }
395         ;
396
397 notenames_body:
398         embedded_scm    {
399           int i = scm_ilength ($1);
400
401           SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
402           for (SCM s = $1; gh_pair_p (s); s = ly_cdr (s)) {
403                 SCM pt = ly_cdar (s);
404                 if (!unsmob_pitch (pt))
405                         THIS->parser_error ("Need pitch object.");
406                 else
407                         scm_hashq_set_x (tab, ly_caar (s), pt);
408           }
409           $$ = tab;
410         }
411         ;
412
413 lilypond_header_body:
414         {
415                 $$ = ly_make_anonymous_module (); 
416                 THIS->lexer_->add_scope ($$);
417         }
418         | lilypond_header_body assignment  { 
419                 
420         }
421         ;
422
423 lilypond_header:
424         HEADER '{' lilypond_header_body '}'     {
425                 $$ = THIS->lexer_-> remove_scope();
426         }
427         ;
428
429
430 /*
431         DECLARATIONS
432 */
433 assignment:
434         STRING {
435                 THIS->push_spot ();
436         }
437         /* cont */ '=' identifier_init  {
438
439         /*
440                 Should find generic way of associating input with objects.
441         */
442                 Input ip = THIS->pop_spot ();
443
444                 if (! regular_identifier_b ($1))
445                 {
446                         ip.warning (_ ("Identifier should have alphabetic characters only"));
447                 }
448
449                 THIS->lexer_->set_identifier ($1, $4);
450
451 /*
452  TODO: devise standard for protection in parser.
453
454   The parser stack lives on the C-stack, which means that
455 all objects can be unprotected as soon as they're here.
456
457 */
458         }
459         | embedded_scm { }
460         ;
461
462
463
464 identifier_init:
465         score_block {
466                 $$ = $1->self_scm ();
467                 scm_gc_unprotect_object ($$);
468         }
469         | full_markup {
470                 $$ = $1;
471         }
472         | output_def {
473                 $$ = $1->self_scm ();
474                 scm_gc_unprotect_object ($$);
475         }
476         | translator_spec_block {
477                 $$ = $1;
478         }
479         | Music  {
480                 $$ = $1->self_scm ();
481                 scm_gc_unprotect_object ($$);
482         }
483         | post_event {
484                 $$ = $1->self_scm ();
485                 scm_gc_unprotect_object ($$);
486         }
487         | verbose_duration {
488                 $$ = $1;
489         }
490         | number_expression {
491                 $$ = $1;
492         }
493         | string {
494                 $$ = $1;
495         }
496         | embedded_scm  {
497                 $$ = $1;
498         }
499         | chordnames_block {
500                 $$ = $1;
501         }       
502         ;
503
504 chordnames_block:
505         CHORDNAMES '{'
506                 { THIS->lexer_->push_chord_state (); }
507                 chordnames_list
508                 { THIS->lexer_->pop_state (); }
509         '}'
510         {
511                 $$ = $4;
512         }
513         ;
514
515 chordnames_list:
516         /* empty */ {
517                 $$ = SCM_EOL;
518         }
519         | CHORDNAMES_IDENTIFIER chordnames_list {
520                 $$ = scm_append (scm_list_2 ($1, $2));
521         }
522         | chord_scm '=' full_markup chordnames_list {
523                 $$ = scm_cons (scm_cons ($1, $3), $4);
524         };
525
526 chord_scm:
527         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
528                 $$ = Chord::tonic_add_sub_to_pitches ($1, $3, $4);
529                 /* junk bass and inversion for now */
530         };
531
532 translator_spec_block:
533         TRANSLATOR '{' translator_spec_body '}'
534                 {
535                 $$ = $3;
536         }
537         ;
538
539 translator_spec_body:
540         TRANSLATOR_IDENTIFIER   {
541                 $$ = $1;
542                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
543         }
544         | TYPE STRING   {
545                 $$ = Translator_def::make_scm ();
546                 Translator_def*td =  unsmob_translator_def ($$);
547                 td->translator_group_type_ = $2;
548                 td->set_spot (THIS->here_input ());
549         }
550         | translator_spec_body STRING '=' embedded_scm                  {
551                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
552         }
553         | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
554                 unsmob_translator_def ($$)
555                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
556         }
557         | translator_spec_body STRING SET embedded_scm '=' embedded_scm {
558                 unsmob_translator_def ($$)
559                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
560         }
561         | translator_spec_body STRING REVERT embedded_scm  {
562           unsmob_translator_def ($$)->add_pop_property (
563                 scm_string_to_symbol ($2), $4);
564         }
565         | translator_spec_body NAME STRING  {
566                 unsmob_translator_def ($$)->type_name_ = $3;
567         }
568         | translator_spec_body CONSISTS STRING  {
569                 unsmob_translator_def ($$)->add_element ($3);
570         }
571         | translator_spec_body ALIAS STRING  {
572                 Translator_def*td = unsmob_translator_def ($$);
573                 td->type_aliases_ = scm_cons ($3, td->type_aliases_);
574         }
575         | translator_spec_body GROBDESCRIPTIONS embedded_scm {
576                 Translator_def*td = unsmob_translator_def($$);
577                 // td->add_property_assign (ly_symbol2scm ("allGrobDescriptions"), $3);
578                 for (SCM p = $3; gh_pair_p (p); p = ly_cdr (p))
579                         td->add_property_assign (scm_symbol_to_string (ly_caar (p)), ly_cdar (p));
580         }
581         | translator_spec_body CONSISTSEND STRING  {
582                 unsmob_translator_def ($$)->add_last_element ( $3);
583         }
584         | translator_spec_body ACCEPTS STRING  {
585                 unsmob_translator_def ($$)->set_acceptor ($3,true);
586         }
587         | translator_spec_body DENIES STRING  {
588                 unsmob_translator_def ($$)->set_acceptor ($3,false);
589         }
590         | translator_spec_body REMOVE STRING  {
591                 unsmob_translator_def ($$)->remove_element ($3);
592         }
593         ;
594
595 /*
596         SCORE
597 */
598 score_block:
599         SCORE { 
600                 THIS->push_spot ();
601         }
602         /*cont*/ '{' score_body '}'     {
603                 THIS->pop_spot ();
604                 $$ = $4;
605                 if (!$$->defs_.size ())
606                 {
607                   Music_output_def *id =
608                         unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
609                   $$->add_output (id ? id->clone () :  new Paper_def );
610                 }
611         }
612         ;
613
614 score_body:
615         Music   {
616                 $$ = new Score;
617         
618                 $$->set_spot (THIS->here_input ());
619                 SCM m = $1->self_scm ();
620                 scm_gc_unprotect_object (m);
621
622                 /*
623                         guh.
624                 */
625                 SCM check_funcs = scm_c_eval_string ("toplevel-music-functions");
626                 for (; gh_pair_p (check_funcs); check_funcs = gh_cdr (check_funcs))
627                         m = gh_call1 (gh_car (check_funcs), m);
628                 $$->music_ = m;
629
630         }
631         | SCORE_IDENTIFIER {
632                 $$ = unsmob_score ($1);
633                 $$->set_spot (THIS->here_input ());
634         }
635         | score_body lilypond_header    {
636                 $$->header_ = $2;
637         }
638         | score_body output_def {
639                 $$->add_output ($2);
640         }
641         | score_body error {
642
643         }
644         ;
645
646
647 /*
648         MIDI
649 */
650 output_def:
651         music_output_def_body '}' {
652                 $$ = $1;
653                 THIS-> lexer_-> remove_scope ();
654         }
655         ;
656
657 music_output_def_body:
658         MIDI '{'    {
659                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
660
661
662                 Midi_def* p =0;
663                 if (id)
664                         p = dynamic_cast<Midi_def*> (id->clone ());
665                 else
666                         p = new Midi_def;
667
668                 $$ = p;
669                 THIS->lexer_->add_scope (p->scope_);
670         }
671         | PAPER '{'     {
672                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
673                   Paper_def *p = 0;
674                 if (id)
675                         p = dynamic_cast<Paper_def*> (id->clone ());
676                 else
677                         p = new Paper_def;
678
679                 THIS->lexer_->add_scope (p->scope_);
680                 $$ = p;
681         }
682         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
683                 Music_output_def * o =  unsmob_music_output_def ($3);
684                 $$ =o;
685
686                 THIS->lexer_->add_scope (o->scope_);
687         }
688         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
689                 Music_output_def * o =  unsmob_music_output_def ($3);
690                 $$ = o;
691
692                 THIS->lexer_->add_scope (o->scope_);
693         }
694         | music_output_def_body assignment  {
695
696         }
697         | music_output_def_body translator_spec_block   {
698                 $$->assign_translator ($2);
699         }
700         | music_output_def_body tempo_event  {
701                 /*
702                         junk this ? there already is tempo stuff in
703                         music.
704                 */
705                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
706                 Duration *d = unsmob_duration ($2->get_mus_property ("tempo-unit"));
707                 Midi_def * md = dynamic_cast<Midi_def*> ($$);
708                 if (md)
709                         md->set_tempo (d->get_length (), m);
710         }
711         | music_output_def_body error {
712
713         }
714         ;
715
716 tempo_event:
717         TEMPO steno_duration '=' bare_unsigned  {
718                 $$ = MY_MAKE_MUSIC("TempoEvent");
719                 $$->set_mus_property ("tempo-unit", $2);
720                 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
721         }
722         ;
723
724 /*
725 The representation of a  list is the
726
727   (LIST . LAST-CONS)
728
729  to have  efficient append.
730 */
731 Music_list:
732         /* empty */ {
733                 $$ = scm_cons (SCM_EOL, SCM_EOL);
734         }
735         | Music_list Music {
736                 SCM s = $$;
737                 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
738                 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
739                 if (gh_pair_p (ly_cdr (s)))
740                         gh_set_cdr_x (ly_cdr (s), c); /* append */
741                 else
742                         gh_set_car_x (s, c); /* set first cons */
743                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
744         }
745         | Music_list error {
746         }
747         ;
748
749
750 Music:
751         Simple_music
752         | Composite_music
753         ;
754
755 Alternative_music:
756         /* empty */ {
757                 $$ = SCM_EOL;
758         }
759         | ALTERNATIVE '{' Music_list '}' {
760                 $$ = $3;
761         }
762         ;
763
764 Repeated_music:
765         REPEAT string bare_unsigned Music Alternative_music
766         {
767                 Music *beg = $4;
768                 int times = $3;
769                 SCM alts = gh_pair_p ($5) ? gh_car ($5) : SCM_EOL;
770                 if (times < scm_ilength (alts)) {
771                   unsmob_music (gh_car (alts))
772                     ->origin ()->warning (
773                     _("More alternatives than repeats.  Junking excess alternatives."));
774                   alts = ly_truncate_list (times, alts);
775                 }
776
777
778                 static SCM proc;
779                 if (!proc)
780                         proc = scm_c_eval_string ("make-repeated-music");
781
782                 SCM mus = scm_call_1 (proc, $2);
783                 scm_gc_protect_object (mus); // UGH. 
784                 Music *r =unsmob_music (mus);
785                 if (beg)
786                         {
787                         r-> set_mus_property ("element", beg->self_scm ());
788                         scm_gc_unprotect_object (beg->self_scm ());
789                         }
790                 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
791
792                 r-> set_mus_property ("elements",alts);
793                 if (gh_equal_p ($2, scm_makfrom0str ("tremolo")))
794                 {
795                 /*
796                 we can not get durations and other stuff correct down the line, so we have to
797                 add to the duration log here.
798                 */
799                         SCM func = scm_primitive_eval (ly_symbol2scm ("shift-duration-log"));
800                         if (($3 % 3) == 0)
801                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3*2/3)),gh_int2scm(1));
802                         else
803                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3)), gh_int2scm(0));
804                 }
805                 r->set_spot (*$4->origin ());
806
807                 $$ = r;
808         }
809         ;
810
811 Sequential_music:
812         SEQUENTIAL '{' Music_list '}'           {
813                 $$ = MY_MAKE_MUSIC("SequentialMusic");
814                 $$->set_mus_property ("elements", ly_car ($3));
815                 $$->set_spot(THIS->here_input());
816         }
817         | '{' Music_list '}'            {
818                 $$ = MY_MAKE_MUSIC("SequentialMusic");
819                 $$->set_mus_property ("elements", ly_car ($2));
820                 $$->set_spot(THIS->here_input());
821         }
822         ;
823
824 Simultaneous_music:
825         SIMULTANEOUS '{' Music_list '}'{
826                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
827                 $$->set_mus_property ("elements", ly_car ($3));
828                 $$->set_spot(THIS->here_input());
829
830         }
831         | '<' Music_list '>'    {
832                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
833                 $$->set_mus_property ("elements", ly_car ($2));
834                 $$->set_spot(THIS->here_input());
835         }
836         ;
837
838 Simple_music:
839         event_chord             { $$ = $1; }
840         | APPLYCONTEXT embedded_scm {
841                 if (!gh_procedure_p ($2))
842                         THIS->parser_error (_ ("\applycontext takes function argument"));
843                 $$ = MY_MAKE_MUSIC ("ApplyContext");
844                 $$->set_mus_property ("procedure", $2);
845                 $$->set_spot (THIS->here_input());
846         }
847         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
848                 SCM pred = $2;
849                 if (!gh_symbol_p ($3))
850                 {
851                         THIS->parser_error (_ ("Second argument must be a symbol")); 
852                 }
853                 /* Should check # args */
854                 if (!gh_procedure_p (pred))
855                 {
856                         THIS->parser_error (_ ("First argument must be a procedure taking one argument"));
857                 }
858
859                 Music*m = MY_MAKE_MUSIC("OutputPropertySetMusic");
860                 m->set_mus_property ("predicate", pred);
861                 m->set_mus_property ("grob-property", $3);
862                 m->set_mus_property ("grob-value",  $5);
863
864                 $$ = m;
865         }
866         | MUSIC_IDENTIFIER {
867                 $$ = unsmob_music ($1);
868         }
869         | property_def
870         | translator_change
871         ;
872
873
874 Composite_music:
875         CONTEXT STRING Music    {
876                 Music*csm =MY_MAKE_MUSIC("ContextSpeccedMusic");
877
878                 csm->set_mus_property ("element", $3->self_scm ());
879                 scm_gc_unprotect_object ($3->self_scm ());
880
881                 csm->set_mus_property ("context-type",$2);
882                 csm->set_mus_property ("context-id", scm_makfrom0str (""));
883
884                 $$ = csm;
885         }
886         | AUTOCHANGE STRING Music       {
887         Music*chm = MY_MAKE_MUSIC("AutoChangeMusic");
888                 chm->set_mus_property ("element", $3->self_scm ());
889                 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_proc);
890
891                 scm_gc_unprotect_object ($3->self_scm ());
892                 chm->set_mus_property ("what", $2); 
893
894                 $$ = chm;
895                 chm->set_spot (*$3->origin ());
896         }
897         | GRACE Music {
898 #if 1
899         /*
900                 The other version is for easier debugging  of
901                 Sequential_music_iterator in combination with grace notes.
902         */
903
904                 SCM start = THIS->lexer_->lookup_identifier ("startGraceMusic");
905                 SCM stop = THIS->lexer_->lookup_identifier ("stopGraceMusic");
906                 Music *startm = unsmob_music (start);
907                 Music *stopm = unsmob_music (stop);
908
909                 SCM ms = SCM_EOL;
910                 if (stopm) {
911                         stopm = stopm->clone ();
912                         ms = scm_cons (stopm->self_scm (), ms);
913                         scm_gc_unprotect_object (stopm->self_scm ());
914                 }
915                 ms = scm_cons ($2->self_scm (), ms);
916                 scm_gc_unprotect_object ($2->self_scm());
917                 if (startm) {
918                         startm = startm->clone ();
919                         ms = scm_cons (startm->self_scm () , ms);
920                         scm_gc_unprotect_object (startm->self_scm ());
921                 }
922
923         
924                 Music* seq = MY_MAKE_MUSIC("SequentialMusic");
925                 seq->set_mus_property ("elements", ms);
926
927                 
928                 $$ = MY_MAKE_MUSIC("GraceMusic");
929                 $$->set_mus_property ("element", seq->self_scm ());
930                 scm_gc_unprotect_object (seq->self_scm ());
931 #else
932                 $$ = MY_MAKE_MUSIC("GraceMusic");
933                 $$->set_mus_property ("element", $2->self_scm ());
934                 scm_gc_unprotect_object ($2->self_scm ());
935 #endif
936         }
937         | CONTEXT string '=' string Music {
938                 Music * csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
939
940                 csm->set_mus_property ("element", $5->self_scm ());
941                 scm_gc_unprotect_object ($5->self_scm ());
942
943                 csm->set_mus_property ("context-type", $2);
944                 csm->set_mus_property ("context-id", $4);
945
946                 $$ = csm;
947         }
948         | TIMES {
949                 THIS->push_spot ();
950         }
951         /* CONTINUED */ 
952                 fraction Music  
953
954         {
955                 int n = gh_scm2int (ly_car ($3)); int d = gh_scm2int (ly_cdr ($3));
956                 Music *mp = $4;
957         $$= MY_MAKE_MUSIC("TimeScaledMusic");
958                 $$->set_spot (THIS->pop_spot ());
959
960
961                 $$->set_mus_property ("element", mp->self_scm ());
962                 scm_gc_unprotect_object (mp->self_scm ());
963                 $$->set_mus_property ("numerator", gh_int2scm (n));
964                 $$->set_mus_property ("denominator", gh_int2scm (d));
965                 $$->compress (Moment (Rational (n,d)));
966
967         }
968         | Repeated_music                { $$ = $1; }
969         | Simultaneous_music            { $$ = $1; }
970         | Sequential_music              { $$ = $1; }
971         | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
972                 $$ = MY_MAKE_MUSIC("TransposedMusic");
973                 Music *p = $4;
974                 Pitch from = *unsmob_pitch ($2);
975                 Pitch to = *unsmob_pitch ($3);
976
977                 p->transpose (interval (from, to));
978                 $$->set_mus_property ("element", p->self_scm ());
979                 scm_gc_unprotect_object (p->self_scm ());
980         }
981         | APPLY embedded_scm Music  {
982                 SCM ret = gh_call1 ($2, $3->self_scm ());
983                 Music *m = unsmob_music (ret);
984                 if (!m) {
985                         THIS->parser_error ("\\apply must return a Music");
986                         m = MY_MAKE_MUSIC("Music");
987                         }
988                 $$ = m;
989         }
990         | NOTES
991                 { THIS->lexer_->push_note_state (); }
992         Music
993                 { $$ = $3;
994                   THIS->lexer_->pop_state ();
995                 }
996         | FIGURES
997                 { THIS->lexer_->push_figuredbass_state (); }
998         Music
999                 {
1000                   Music * chm = MY_MAKE_MUSIC("UntransposableMusic");
1001                   chm->set_mus_property ("element", $3->self_scm ());
1002                   $$ = chm;
1003                   scm_gc_unprotect_object ($3->self_scm());
1004
1005                   THIS->lexer_->pop_state ();
1006         }
1007         | CHORDS
1008                 { THIS->lexer_->push_chord_state (); }
1009         Music
1010                 {
1011                   Music * chm = MY_MAKE_MUSIC("UnrelativableMusic");
1012                   chm->set_mus_property ("element", $3->self_scm ());
1013                   scm_gc_unprotect_object ($3->self_scm());
1014                   $$ = chm;
1015
1016                   THIS->lexer_->pop_state ();
1017         }
1018         | LYRICS
1019                 { THIS->lexer_->push_lyric_state (); }
1020         Music
1021                 {
1022                   $$ = $3;
1023                   THIS->lexer_->pop_state ();
1024         }
1025         | relative_music        { $$ = $1; }
1026         | re_rhythmed_music     { $$ = $1; } 
1027         | part_combined_music   { $$ = $1; } 
1028         ;
1029
1030 relative_music:
1031         RELATIVE absolute_pitch Music {
1032                 Music * p = $3;
1033                 Pitch pit = *unsmob_pitch ($2);
1034                 $$ = MY_MAKE_MUSIC("RelativeOctaveMusic");
1035
1036                 $$->set_mus_property ("element", p->self_scm ());
1037                 scm_gc_unprotect_object (p->self_scm ());
1038
1039                 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
1040
1041         }
1042         ;
1043
1044 re_rhythmed_music:
1045         ADDLYRICS Music Music {
1046         Music*l =MY_MAKE_MUSIC("LyricCombineMusic");
1047           l->set_mus_property ("elements", gh_list ($2->self_scm (), $3->self_scm (), SCM_UNDEFINED));
1048           scm_gc_unprotect_object ($3->self_scm ());
1049           scm_gc_unprotect_object ($2->self_scm ());
1050           $$ = l;
1051         }
1052         ;
1053
1054 part_combined_music:
1055         PARTCOMBINE STRING Music Music {
1056         Music * p= MY_MAKE_MUSIC("PartCombineMusic");
1057                 p->set_mus_property ("what", $2);
1058                 p->set_mus_property ("elements", gh_list ($3->self_scm (),$4->self_scm (), SCM_UNDEFINED));  
1059
1060                 scm_gc_unprotect_object ($3->self_scm ());
1061                 scm_gc_unprotect_object ($4->self_scm ());  
1062
1063                 $$ = p;
1064         }
1065         ;
1066
1067 translator_change:
1068         TRANSLATOR STRING '=' STRING  {
1069                 Music*t= MY_MAKE_MUSIC("TranslatorChange");
1070                 t-> set_mus_property ("change-to-type", $2);
1071                 t-> set_mus_property ("change-to-id", $4);
1072
1073                 $$ = t;
1074                 $$->set_spot (THIS->here_input ());
1075         }
1076         ;
1077
1078 property_def:
1079         simple_property_def
1080         | ONCE simple_property_def {
1081                 $$ = $2;
1082                 SCM e = $2->get_mus_property ("element");
1083                 unsmob_music (e)->set_mus_property ("once", SCM_BOOL_T);
1084         }
1085         ;
1086
1087 simple_property_def:
1088         PROPERTY STRING '.' STRING '='  scalar {
1089                 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
1090                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1091
1092                 csm->set_mus_property ("element", t->self_scm ());
1093                 scm_gc_unprotect_object (t->self_scm ());
1094
1095                 $$ = csm;
1096                 $$->set_spot (THIS->here_input ());
1097
1098                 csm-> set_mus_property ("context-type", $2);
1099         }
1100         | PROPERTY STRING '.' STRING UNSET {
1101                 
1102                 Music *t = MY_MAKE_MUSIC("PropertyUnset");
1103                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1104
1105                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1106                 csm->set_mus_property ("element", t->self_scm ());
1107                 scm_gc_unprotect_object (t->self_scm ());
1108
1109                 $$ = csm;
1110                 $$->set_spot (THIS->here_input ());
1111
1112                 csm-> set_mus_property ("context-type", $2);
1113         }
1114         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
1115                 bool autobeam
1116                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1117                 bool itc = internal_type_checking_global_b;
1118                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1119                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1120                 t->set_mus_property ("pop-first", SCM_BOOL_T);
1121                 if (autobeam)
1122                         internal_type_checking_global_b = false;
1123                 t->set_mus_property ("grob-property", $6);
1124                 if (autobeam)
1125                         internal_type_checking_global_b = itc;
1126                 t->set_mus_property ("grob-value", $8);
1127
1128                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1129                 csm->set_mus_property ("element", t->self_scm ());
1130                 scm_gc_unprotect_object (t->self_scm ());
1131                 $$ = csm;
1132                 $$->set_spot (THIS->here_input ());
1133
1134                 csm-> set_mus_property ("context-type", $2);
1135         }
1136         | PROPERTY STRING '.' STRING OVERRIDE
1137                 embedded_scm '=' embedded_scm
1138         {
1139                 /*
1140                         UGH UGH UGH UGH.
1141                 */
1142                 bool autobeam
1143                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1144                 bool itc = internal_type_checking_global_b;
1145
1146                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1147                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1148                 if (autobeam)
1149                         internal_type_checking_global_b = false;
1150                 t->set_mus_property ("grob-property", $6);
1151                 t->set_mus_property ("grob-value", $8);
1152                 if (autobeam)
1153                         internal_type_checking_global_b = itc;
1154
1155                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1156                 csm->set_mus_property ("element", t->self_scm ());
1157                 scm_gc_unprotect_object (t->self_scm ());
1158
1159                 $$ = csm;
1160                 $$->set_spot (THIS->here_input ());
1161
1162                 csm-> set_mus_property ("context-type", $2);
1163
1164         }
1165         | PROPERTY STRING '.' STRING REVERT embedded_scm {
1166                 Music *t = MY_MAKE_MUSIC("RevertProperty");
1167                 bool autobeam
1168                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1169                 bool itc = internal_type_checking_global_b;
1170
1171                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1172                 if (autobeam)
1173                         internal_type_checking_global_b = false;
1174                 t->set_mus_property ("grob-property", $6);
1175                 if (autobeam)
1176                         internal_type_checking_global_b = itc;
1177         
1178                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1179                 csm->set_mus_property ("element", t->self_scm ());
1180                 scm_gc_unprotect_object (t->self_scm ());
1181
1182                 $$ = csm;
1183                 $$->set_spot (THIS->here_input ());
1184
1185                 csm-> set_mus_property ("context-type", $2);
1186         }
1187         ;
1188
1189
1190 scalar:
1191         string          { $$ = $1; }
1192         | bare_int      { $$ = gh_int2scm ($1); }
1193         | embedded_scm  { $$ = $1; }
1194         | full_markup {  $$ = $1; }
1195         ;
1196
1197
1198 event_chord:
1199         pre_events {
1200                 THIS->push_spot ();
1201         } /*cont */ simple_element post_events  {
1202                 SCM elts = $3-> get_mus_property ("elements");
1203
1204                 elts = gh_append3 (elts, scm_reverse_x ($1, SCM_EOL),
1205                                    scm_reverse_x ($4, SCM_EOL));
1206
1207                 $3-> set_mus_property ("elements", elts);
1208                 $$ = $3;
1209         }
1210         | command_element
1211         | note_chord_element
1212         ;
1213
1214
1215 note_chord_element:
1216         chord_body optional_notemode_duration post_events
1217         {
1218                 SCM dur = unsmob_duration ($2)->smobbed_copy();
1219                 SCM es = $1->get_mus_property ("elements");
1220                 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1221
1222                 for (SCM s = es; gh_pair_p (s); s = gh_cdr (s))
1223                   unsmob_music (gh_car(s))->set_mus_property ("duration", dur);
1224                 es = gh_append2 (es, postevs);
1225
1226                 $1-> set_mus_property ("elements", es);
1227                 $$ = $1;
1228         }
1229         ;
1230
1231 chord_body:
1232         CHORD_OPEN chord_body_elements CHORD_CLOSE
1233         {
1234                 $$ = MY_MAKE_MUSIC("EventChord");
1235                 $$->set_mus_property ("elements",
1236                         scm_reverse_x ($2, SCM_EOL));
1237         }
1238         ;
1239
1240 chord_body_elements:
1241         /* empty */             { $$ = SCM_EOL; }
1242         | chord_body_elements chord_body_element {
1243                 $$ = gh_cons ($2->self_scm(), $1);
1244                 scm_gc_unprotect_object ($2->self_scm());
1245         }
1246         ;
1247
1248 chord_body_element:
1249         pitch exclamations questions post_events
1250         {
1251                 Music * n = MY_MAKE_MUSIC("NoteEvent");
1252                 n->set_mus_property ("pitch", $1);
1253                 if ($3 % 2)
1254                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1255                 if ($2 % 2 || $3 % 2)
1256                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1257
1258                 SCM arts = scm_reverse_x ($4, SCM_EOL);
1259                 n->set_mus_property ("articulations", arts);
1260
1261                 $$ = n;
1262         }
1263         ;
1264
1265 command_element:
1266         command_req {
1267                 $$ = MY_MAKE_MUSIC("EventChord");
1268                 $$->set_mus_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1269           scm_gc_unprotect_object ($1->self_scm());
1270
1271                 $$-> set_spot (THIS->here_input ());
1272                 $1-> set_spot (THIS->here_input ());
1273         }
1274         | E_LEFTSQUARE {
1275                 Music *l = MY_MAKE_MUSIC("LigatureEvent");
1276                 l->set_mus_property ("span-direction", gh_int2scm (START));
1277                 l->set_spot (THIS->here_input ());
1278
1279                 $$ = MY_MAKE_MUSIC("EventChord");
1280                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1281                 scm_gc_unprotect_object (l->self_scm());
1282                 $$->set_spot (THIS->here_input ());
1283         }
1284         | E_RIGHTSQUARE {
1285                 Music *l = MY_MAKE_MUSIC("LigatureEvent");
1286                 l->set_mus_property ("span-direction", gh_int2scm (STOP));
1287                 l->set_spot (THIS->here_input ());
1288
1289                 $$ = MY_MAKE_MUSIC("EventChord");
1290                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1291                 $$->set_spot (THIS->here_input ());
1292                 scm_gc_unprotect_object (l->self_scm());
1293         }
1294         | E_BACKSLASH {
1295                 $$ = MY_MAKE_MUSIC("VoiceSeparator");
1296                 $$->set_spot (THIS->here_input ());
1297         }
1298         | '|'      {
1299
1300                 $$ = MY_MAKE_MUSIC("BarCheck");
1301                 $$->set_spot (THIS->here_input ());
1302         }
1303         | BAR STRING                    {
1304                 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1305
1306                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1307                 csm->set_mus_property ("element", t->self_scm ());
1308                 scm_gc_unprotect_object (t->self_scm ());
1309
1310                 $$ = csm;
1311                 $$->set_spot (THIS->here_input ());
1312
1313                 csm->set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1314         }
1315         | PARTIAL duration_length       {
1316                 Moment m = - unsmob_duration ($2)->get_length ();
1317                 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1318
1319                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1320                 sp->set_mus_property ("element", p->self_scm ());
1321                 scm_gc_unprotect_object (p->self_scm ());
1322
1323                 $$ =sp ;
1324                 sp-> set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1325         }
1326         | CLEF STRING  {
1327                 static SCM proc ;
1328                 if (!proc)
1329                         proc = scm_c_eval_string ("make-clef-set");
1330
1331                 SCM result = scm_call_1 (proc, $2);
1332                 scm_gc_protect_object (result);
1333                 $$ = unsmob_music (result);
1334         }
1335         | TIME_T fraction  {
1336                 static SCM proc;
1337                 if (!proc)
1338                         proc = scm_c_eval_string ("make-time-signature-set");
1339
1340                 SCM result = scm_apply_2   (proc, gh_car ($2), gh_cdr ($2), SCM_EOL);
1341                 scm_gc_protect_object (result);
1342                 $$ = unsmob_music (result);
1343         }
1344         ;
1345
1346 command_req:
1347         shorthand_command_req   { $$ = $1; }
1348         | verbose_command_req   { $$ = $1; }
1349         ;
1350
1351 shorthand_command_req:
1352         extender_req {
1353                 $$ = $1;
1354         }
1355         | hyphen_req {
1356                 $$ = $1;
1357         }
1358         | '~'   {
1359                 $$ = MY_MAKE_MUSIC("TieEvent");
1360         }
1361         | '['           {
1362                 Music *b= MY_MAKE_MUSIC("BeamEvent");
1363                 b->set_mus_property ("span-direction", gh_int2scm (START));
1364                 $$ = b;
1365
1366                 THIS->last_beam_start_ = b->self_scm ();
1367         }
1368         | ']'           {
1369                 Music *b= MY_MAKE_MUSIC("BeamEvent");
1370                 b->set_mus_property ("span-direction", gh_int2scm (STOP));
1371                 $$ = b;
1372         }
1373         | BREATHE {
1374                 $$ = MY_MAKE_MUSIC("BreathingSignEvent");
1375         }
1376         | E_TILDE {
1377                 $$ = MY_MAKE_MUSIC("PorrectusEvent");
1378         }
1379         ;
1380
1381 verbose_command_req:
1382         MARK DEFAULT  {
1383                 Music * m = MY_MAKE_MUSIC("MarkEvent");
1384                 $$ = m;
1385         }
1386         | MARK scalar {
1387                 Music *m = MY_MAKE_MUSIC("MarkEvent");
1388                 m->set_mus_property ("label", $2);
1389                 $$ = m;
1390         }
1391         | SKIP duration_length {
1392                 Music * skip = MY_MAKE_MUSIC("SkipEvent");
1393                 skip->set_mus_property ("duration", $2);
1394
1395                 $$ = skip;
1396         }
1397         | tempo_event {
1398                 $$ = $1;
1399         }
1400         | KEY DEFAULT {
1401                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1402                 $$ = key;
1403         }
1404         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1405                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1406                 
1407                 key->set_mus_property ("pitch-alist", $3);
1408                 ((Music*)key)->transpose (* unsmob_pitch ($2));
1409                 $$ = key; 
1410         }
1411         ;
1412
1413 post_events:
1414         /* empty */ {
1415                 $$ = SCM_EOL;
1416         }
1417         | post_events post_event {
1418                 $2->set_spot (THIS->here_input ());
1419                 $$ = gh_cons ($2->self_scm(), $$);
1420                 scm_gc_unprotect_object ($2->self_scm());
1421         }
1422         ;
1423
1424 post_event:
1425         verbose_event
1426         | event_with_dir
1427         | close_event
1428         | string_event
1429         ;
1430
1431 string_event:
1432         E_UNSIGNED {
1433                 Music * s = MY_MAKE_MUSIC("StringNumberEvent");
1434                 s->set_mus_property ("string-number",  gh_int2scm($1));
1435                 s->set_spot (THIS->here_input ());
1436                 $$ = s;
1437         }
1438         ;
1439
1440
1441 event_that_take_dir:
1442         gen_text_def
1443         | verbose_event
1444         | close_event
1445         | open_event
1446         | '['  {
1447                 Music * m = MY_MAKE_MUSIC ("NewBeamEvent");
1448                 m->set_spot (THIS->here_input());
1449                 m->set_mus_property ("span-direction" , gh_int2scm (START));
1450                 $$ = m;
1451         }
1452         | ']'  {
1453                 Music * m = MY_MAKE_MUSIC ("NewBeamEvent");
1454                 m->set_spot (THIS->here_input());
1455                 m->set_mus_property ("span-direction" , gh_int2scm (STOP));
1456                 $$ = m;
1457         }
1458         | '~' {
1459                 Music * m = MY_MAKE_MUSIC ("NewTieEvent");
1460                 m->set_spot (THIS->here_input());
1461                 $$ = m;
1462         }
1463         | script_abbreviation {
1464                 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1465                 Music *a = MY_MAKE_MUSIC("ArticulationEvent");
1466                 if (gh_string_p (s))
1467                         a->set_mus_property ("articulation-type", s);
1468                 else THIS->parser_error (_ ("Expecting string as script definition"));
1469                 $$ = a;
1470         }
1471         ;
1472
1473 event_with_dir:
1474         script_dir event_that_take_dir  {
1475                 $2->set_mus_property ("direction", gh_int2scm ($1));
1476                 $$ = $2;
1477         }
1478         ;
1479         
1480 verbose_event:
1481         EVENT_IDENTIFIER        {
1482                 $$ = unsmob_music ($1);
1483         }
1484         | tremolo_type  {
1485                Music * a = MY_MAKE_MUSIC("TremoloEvent");
1486                a->set_spot (THIS->here_input ());
1487                a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1488                $$ = a;
1489         }
1490         ;
1491
1492 sup_quotes:
1493         '\'' {
1494                 $$ = 1;
1495         }
1496         | sup_quotes '\'' {
1497                 $$ ++;
1498         }
1499         ;
1500
1501 sub_quotes:
1502         ',' {
1503                 $$ = 1;
1504         }
1505         | sub_quotes ',' {
1506                 $$ ++ ;
1507         }
1508         ;
1509
1510 steno_pitch:
1511         NOTENAME_PITCH  {
1512                 $$ = $1;
1513         }
1514         | NOTENAME_PITCH sup_quotes     {
1515                 Pitch p = *unsmob_pitch ($1);
1516                 p.octave_ +=  $2;
1517                 $$ = p.smobbed_copy ();
1518         }
1519         | NOTENAME_PITCH sub_quotes      {
1520                 Pitch p =* unsmob_pitch ($1);
1521
1522                 p.octave_ +=  -$2;
1523                 $$ = p.smobbed_copy ();
1524
1525         }
1526         ;
1527
1528 /*
1529 ugh. duplication
1530 */
1531
1532 steno_tonic_pitch:
1533         TONICNAME_PITCH {
1534                 $$ = $1;
1535         }
1536         | TONICNAME_PITCH sup_quotes    {
1537                 Pitch p = *unsmob_pitch ($1);
1538                 p.octave_ +=  $2;
1539                 $$ = p.smobbed_copy ();
1540         }
1541         | TONICNAME_PITCH sub_quotes     {
1542                 Pitch p =* unsmob_pitch ($1);
1543
1544                 p.octave_ +=  -$2;
1545                 $$ = p.smobbed_copy ();
1546
1547         }
1548         ;
1549
1550 pitch:
1551         steno_pitch {
1552                 $$ = $1;
1553         }
1554         | explicit_pitch {
1555                 $$ = $1;
1556         }
1557         ;
1558
1559 pitch_also_in_chords:
1560         pitch
1561         | steno_tonic_pitch
1562         ;
1563
1564 explicit_pitch:
1565         PITCH embedded_scm {
1566                 $$ = $2;
1567                 if (!unsmob_pitch ($2)) {
1568                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1569                          $$ = Pitch ().smobbed_copy ();
1570                 }
1571         }
1572         ;
1573
1574 verbose_duration:
1575         DURATION embedded_scm   {
1576                 $$ = $2;
1577                 if (!unsmob_duration ($2))
1578                 {
1579                         THIS->parser_error (_ ("Must have duration object"));
1580                         $$ = Duration ().smobbed_copy ();
1581                 }
1582         }
1583         ;
1584
1585 extender_req:
1586         EXTENDER {
1587                 if (!THIS->lexer_->lyric_state_b ())
1588                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1589                 $$ = MY_MAKE_MUSIC("ExtenderEvent");
1590         }
1591         ;
1592
1593 hyphen_req:
1594         HYPHEN {
1595                 if (!THIS->lexer_->lyric_state_b ())
1596                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1597                 $$ = MY_MAKE_MUSIC("HyphenEvent");
1598         }
1599         ;
1600
1601 close_event:
1602         close_event_parens {
1603                 $$ = $1;
1604                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (START))
1605 ;
1606         }
1607         ;
1608  
1609 close_event_parens:
1610         '('     {
1611                 Music * s= MY_MAKE_MUSIC("SlurEvent");
1612                 $$ = s;
1613                 s->set_spot (THIS->here_input());
1614         }
1615         | E_OPEN        {
1616                 Music * s= MY_MAKE_MUSIC("PhrasingSlurEvent");
1617                 $$ = s;
1618                 s->set_spot (THIS->here_input());
1619         }
1620         | E_SMALLER {
1621                 Music *s =MY_MAKE_MUSIC("CrescendoEvent");
1622                 $$ = s;
1623                 s->set_spot (THIS->here_input());
1624         }
1625         | E_BIGGER {
1626                 Music *s =MY_MAKE_MUSIC("DecrescendoEvent");
1627                 $$ = s;
1628                 s->set_spot (THIS->here_input());
1629         }
1630         ;
1631
1632
1633 open_event:
1634         open_event_parens {
1635                 $$ = $1;
1636                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (STOP))
1637 ;
1638         }
1639         ;
1640
1641 open_event_parens:
1642         E_EXCLAMATION   {
1643                 Music *s =  MY_MAKE_MUSIC("CrescendoEvent");
1644                 s->set_spot (THIS->here_input());
1645
1646                 $$ = s;
1647         }
1648         | ')'   {
1649                 Music * s= MY_MAKE_MUSIC("SlurEvent");
1650                 $$ = s;
1651                 s->set_spot (THIS->here_input());
1652
1653         }
1654         | E_CLOSE       {
1655                 Music * s= MY_MAKE_MUSIC("PhrasingSlurEvent");
1656                 $$ = s;
1657                 s->set_mus_property ("span-type", scm_makfrom0str ( "phrasing-slur"));
1658                 s->set_spot (THIS->here_input());
1659         }
1660         ;
1661
1662 gen_text_def:
1663         embedded_scm {
1664                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1665                 t->set_mus_property ("text", $1);
1666                 t->set_spot (THIS->here_input ());
1667                 $$ = t;
1668         }
1669         | full_markup {
1670                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1671                 t->set_mus_property ("text", $1);
1672                 t->set_spot (THIS->here_input ());
1673                 $$ = t; 
1674         }
1675         | string {
1676                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1677                 t->set_mus_property ("text", make_simple_markup ($1));
1678                 t->set_spot (THIS->here_input ());
1679                 $$ = t;
1680         
1681         }
1682         | DIGIT {
1683                 Music * t = MY_MAKE_MUSIC("FingerEvent");
1684                 t->set_mus_property ("digit",  gh_int2scm ($1));
1685                 t->set_spot (THIS->here_input ());
1686                 $$ = t;
1687         }
1688         ;
1689
1690 script_abbreviation:
1691         '^'             {
1692                 $$ = scm_makfrom0str ("Hat");
1693         }
1694         | '+'           {
1695                 $$ = scm_makfrom0str ("Plus");
1696         }
1697         | '-'           {
1698                 $$ = scm_makfrom0str ("Dash");
1699         }
1700         | '|'           {
1701                 $$ = scm_makfrom0str ("Bar");
1702         }
1703         | '>'           {
1704                 $$ = scm_makfrom0str ("Larger");
1705         }
1706         | '.'           {
1707                 $$ = scm_makfrom0str ("Dot");
1708         }
1709         | '_' {
1710                 $$ = scm_makfrom0str ("Underscore");
1711         }
1712         ;
1713
1714 script_dir:
1715         '_'     { $$ = DOWN; }
1716         | '^'   { $$ = UP; }
1717         | '-'   { $$ = CENTER; }
1718         ;
1719
1720 pre_events:
1721         /* empty */ { 
1722                 $$ = SCM_EOL;
1723         }
1724         | pre_events open_event {
1725                 $$ = gh_cons ($2->self_scm(), $$);
1726                 scm_gc_unprotect_object ($2->self_scm());
1727         }
1728         ;
1729
1730 absolute_pitch:
1731         steno_pitch     {
1732                 $$ = $1;
1733         }
1734         ;
1735
1736 duration_length:
1737         multiplied_duration {
1738                 $$ = $1;
1739         }
1740         | verbose_duration {
1741                 $$ = $1;
1742         }       
1743         ;
1744
1745 optional_notemode_duration:
1746         {
1747                 Duration dd = THIS->default_duration_;
1748                 $$ = dd.smobbed_copy ();
1749
1750                 THIS->beam_check ($$);
1751         }
1752         | multiplied_duration   {
1753                 $$ = $1;
1754                 THIS->default_duration_ = *unsmob_duration ($$);
1755
1756                 THIS->beam_check ($$);
1757         }
1758         | verbose_duration {
1759                 $$ = $1;
1760                 THIS->default_duration_ = *unsmob_duration ($$);
1761         }       
1762         ;
1763
1764 steno_duration:
1765         bare_unsigned dots              {
1766                 int l = 0;
1767                 if (!is_duration_b ($1))
1768                         THIS->parser_error (_f ("not a duration: %d", $1));
1769                 else
1770                         l =  intlog2 ($1);
1771
1772                 $$ = Duration (l, $2).smobbed_copy ();
1773         }
1774         | DURATION_IDENTIFIER dots      {
1775                 Duration *d =unsmob_duration ($1);
1776                 Duration k (d->duration_log (),d->dot_count () + $2);
1777
1778                 *d = k;
1779                 $$ = $1;
1780         }
1781         ;
1782
1783
1784
1785
1786 multiplied_duration:
1787         steno_duration {
1788                 $$ = $1;
1789         }
1790         | multiplied_duration '*' bare_unsigned {
1791                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1792         }
1793         | multiplied_duration '*' FRACTION {
1794                 Rational  m (gh_scm2int (ly_car ($3)), gh_scm2int (ly_cdr ($3)));
1795
1796                 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1797         }
1798         ;
1799
1800 fraction:
1801         FRACTION { $$ = $1; }
1802         | UNSIGNED '/' UNSIGNED {
1803                 $$ = scm_cons (gh_int2scm ($1), gh_int2scm ($3));
1804         }
1805         ;
1806
1807 dots:
1808         /* empty */     {
1809                 $$ = 0;
1810         }
1811         | dots '.' {
1812                 $$ ++;
1813         }
1814         ;
1815
1816
1817 tremolo_type: 
1818         ':'     {
1819                 $$ =0;
1820         }
1821         | ':' bare_unsigned {
1822                 if (!is_duration_b ($2))
1823                         THIS->parser_error (_f ("not a duration: %d", $2));
1824                 $$ = $2;
1825         }
1826         ;
1827
1828
1829
1830 /*****************************************************************
1831                 BASS FIGURES
1832 *****************************************************************/
1833 bass_number:
1834         DIGIT
1835         | UNSIGNED 
1836         ;
1837
1838 bass_mod:
1839         '-'     { $$ = -1; }
1840         | '+'   { $$ = 1; } 
1841         | '!'   { $$ = 0; }
1842         ;
1843
1844 bass_figure:
1845         FIGURE_SPACE {
1846                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1847                 $$ = bfr->self_scm();
1848                 scm_gc_unprotect_object ($$);
1849         }
1850         | bass_number  {
1851                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1852                 $$ = bfr->self_scm();
1853
1854                 bfr->set_mus_property ("figure", gh_int2scm ($1));
1855
1856                 scm_gc_unprotect_object ($$);
1857         }
1858         | bass_figure bass_mod {
1859                 Music *m = unsmob_music ($1);
1860                 if ($2) {
1861                         SCM salter =m->get_mus_property ("alteration");
1862                         int alter = gh_number_p ( salter) ? gh_scm2int (salter) : 0;
1863                         m->set_mus_property ("alteration",
1864                                 gh_int2scm (alter + $2));
1865                 } else {
1866                         m->set_mus_property ("alteration", gh_int2scm (0));
1867                 }
1868         }
1869         ;
1870
1871 br_bass_figure:
1872         '[' bass_figure {
1873                 $$ = $2;
1874                 unsmob_music ($$)->set_mus_property ("bracket-start", SCM_BOOL_T);
1875         }
1876         | bass_figure   {
1877                 $$ = $1;
1878         }
1879         | br_bass_figure ']' {
1880                 $$ = $1;
1881                 unsmob_music ($1)->set_mus_property ("bracket-stop", SCM_BOOL_T);
1882         }
1883         ;
1884
1885 figure_list:
1886         /**/            {
1887                 $$ = SCM_EOL;
1888         }
1889         | figure_list br_bass_figure {
1890                 $$ = scm_cons ($2, $1); 
1891         }
1892         ;
1893
1894 figure_spec:
1895         FIGURE_OPEN figure_list FIGURE_CLOSE {
1896                 Music * m = MY_MAKE_MUSIC("EventChord");
1897                 $2 = scm_reverse_x ($2, SCM_EOL);
1898                 m->set_mus_property ("elements",  $2);
1899                 $$ = m->self_scm ();
1900         }
1901         ;
1902
1903
1904 optional_rest:
1905         /**/   { $$ = 0; }
1906         | REST { $$ = 1; }
1907         ;
1908
1909 simple_element:
1910         pitch exclamations questions optional_notemode_duration optional_rest {
1911
1912                 Input i = THIS->pop_spot ();
1913                 if (!THIS->lexer_->note_state_b ())
1914                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1915
1916                 Music *n = 0;
1917                 if ($5)
1918                         n =  MY_MAKE_MUSIC("RestEvent");
1919                 else
1920                         n =  MY_MAKE_MUSIC("NoteEvent");
1921                 
1922                 n->set_mus_property ("pitch", $1);
1923                 n->set_mus_property ("duration", $4);
1924
1925
1926                 if ($3 % 2)
1927                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1928                 if ($2 % 2 || $3 % 2)
1929                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1930
1931                 Music *v = MY_MAKE_MUSIC("EventChord");
1932                 v->set_mus_property ("elements", scm_list_n (n->self_scm (), SCM_UNDEFINED));
1933                 scm_gc_unprotect_object (n->self_scm());
1934
1935                 v->set_spot (i);
1936                 n->set_spot (i);
1937                 $$ = v;
1938         }
1939         | figure_spec optional_notemode_duration {
1940                 Music * m = unsmob_music ($1);
1941                 Input i = THIS->pop_spot (); 
1942                 m->set_spot (i);
1943                 for (SCM s = m->get_mus_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
1944                 {
1945                         unsmob_music (ly_car (s))->set_mus_property ("duration", $2);
1946                 }
1947                 $$ = m;
1948         }       
1949         | RESTNAME optional_notemode_duration           {
1950
1951                 Input i = THIS->pop_spot ();
1952                 Music * ev = 0;
1953                 if (ly_scm2string ($1) =="s") {
1954                         /* Space */
1955                         ev = MY_MAKE_MUSIC("SkipEvent");
1956                   }
1957                 else {
1958                         ev = MY_MAKE_MUSIC("RestEvent");
1959                 
1960                     }
1961                 ev->set_mus_property ("duration" ,$2);
1962                 ev->set_spot (i);
1963                 Music * velt = MY_MAKE_MUSIC("EventChord");
1964                 velt->set_mus_property ("elements", scm_list_n (ev->self_scm (),SCM_UNDEFINED));
1965                 velt->set_spot (i);
1966
1967                 $$ = velt;
1968         }
1969         | MULTI_MEASURE_REST optional_notemode_duration         {
1970                 THIS->pop_spot ();
1971
1972                 static SCM proc ;
1973                 if (!proc)
1974                         proc = scm_c_eval_string ("make-multi-measure-rest");
1975
1976                 SCM mus = scm_call_2 (proc, $2,
1977                         make_input (THIS->here_input()));       
1978                 scm_gc_protect_object (mus);
1979                 $$ = unsmob_music (mus);
1980         }
1981         | STRING optional_notemode_duration     {
1982                 Input i = THIS->pop_spot ();
1983
1984                 Music * lreq = MY_MAKE_MUSIC("LyricEvent");
1985                 lreq->set_mus_property ("text", $1);
1986                 lreq->set_mus_property ("duration",$2);
1987                 lreq->set_spot (i);
1988                 Music * velt = MY_MAKE_MUSIC("EventChord");
1989                 velt->set_mus_property ("elements", scm_list_n (lreq->self_scm (), SCM_UNDEFINED));
1990
1991                 $$= velt;
1992         }
1993         | chord {
1994                 THIS->pop_spot ();
1995
1996                 if (!THIS->lexer_->chord_state_b ())
1997                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1998                 $$ = $1;
1999         }
2000         ;
2001
2002
2003 chord:
2004         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
2005                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
2006                 $$->set_spot (THIS->here_input ());
2007         };
2008
2009 chord_additions: 
2010         {
2011                 $$ = SCM_EOL;
2012         } 
2013         | CHORD_COLON chord_notes {
2014                 $$ = $2;
2015         }
2016         ;
2017
2018 chord_notes:
2019         chord_step {
2020                 $$ = $1;
2021         }
2022         | chord_notes '.' chord_step {
2023                 $$ = gh_append2 ($$, $3);
2024         }
2025         ;
2026
2027 chord_subtractions: 
2028         {
2029                 $$ = SCM_EOL;
2030         } 
2031         | CHORD_CARET chord_notes {
2032                 $$ = $2;
2033         }
2034         ;
2035
2036
2037 chord_inversion:
2038         {
2039                 $$ = SCM_EOL;
2040         }
2041         | CHORD_SLASH steno_tonic_pitch {
2042                 $$ = $2;
2043         }
2044         ;
2045
2046 chord_bass:
2047         {
2048                 $$ = SCM_EOL;
2049         }
2050         | CHORD_BASS steno_tonic_pitch {
2051                 $$ = $2;
2052         }
2053         ;
2054
2055 chord_step:
2056         chord_note {
2057                 $$ = scm_cons ($1, SCM_EOL);
2058         }
2059         | CHORDMODIFIER_PITCH {
2060                 $$ = scm_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
2061         }
2062         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
2063                 $$ = scm_list_n (unsmob_pitch ($1)->smobbed_copy (),
2064                         $2, SCM_UNDEFINED);
2065         }
2066         ;
2067
2068 chord_note:
2069         bare_unsigned {
2070                  Pitch m;
2071                 m.notename_ = ($1 - 1) % 7;
2072                 m.octave_ = $1 > 7 ? 1 : 0;
2073                 m.alteration_ = 0;
2074
2075                 $$ = m.smobbed_copy ();
2076         } 
2077         | bare_unsigned '+' {
2078                 Pitch m;
2079                 m.notename_ = ($1 - 1) % 7;
2080                 m.octave_ = $1 > 7 ? 1 : 0;
2081                 m.alteration_ = 1;
2082
2083
2084                 $$ = m.smobbed_copy ();
2085         }
2086         | bare_unsigned CHORD_MINUS {
2087                 Pitch m;
2088                 m.notename_ = ($1 - 1) % 7;
2089                 m.octave_ = $1 > 7 ? 1 : 0;
2090                 m.alteration_ = -1;
2091
2092                 $$ = m.smobbed_copy ();
2093         }
2094         ;
2095
2096 /*
2097         UTILITIES
2098  */
2099 number_expression:
2100         number_expression '+' number_term {
2101                 $$ = scm_sum ($1, $3);
2102         }
2103         | number_expression '-' number_term {
2104                 $$ = scm_difference ($1, $3);
2105         }
2106         | number_term 
2107         ;
2108
2109 number_term:
2110         number_factor {
2111                 $$ = $1;
2112         }
2113         | number_factor '*' number_factor {
2114                 $$ = scm_product ($1, $3);
2115         }
2116         | number_factor '/' number_factor {
2117                 $$ = scm_divide ($1, $3);
2118         }
2119         ;
2120
2121 number_factor:
2122         '-'  number_factor { /* %prec UNARY_MINUS */
2123                 $$ = scm_difference ($2, SCM_UNDEFINED);
2124         }
2125         | bare_number
2126         ;
2127
2128
2129 bare_number:
2130         UNSIGNED        {
2131                 $$ = gh_int2scm ($1);
2132         }
2133         | REAL          {
2134                 $$ = $1;
2135         }
2136         | NUMBER_IDENTIFIER             {
2137                 $$ = $1;
2138         }
2139         | REAL NUMBER_IDENTIFIER        {
2140                 $$ = gh_double2scm (gh_scm2double ($1) * gh_scm2double ($2));
2141         }
2142         | UNSIGNED NUMBER_IDENTIFIER    {
2143                 $$ = gh_double2scm ($1 * gh_scm2double ($2));
2144         }
2145         ;
2146
2147
2148 bare_unsigned:
2149         UNSIGNED {
2150                         $$ = $1;
2151         }
2152         | DIGIT {
2153                 $$ = $1;
2154         }
2155         ;
2156
2157 bare_int:
2158         bare_number {
2159                 if (scm_integer_p ($1) == SCM_BOOL_T)
2160                 {
2161                         int k = gh_scm2int ($1);
2162                         $$ = k;
2163                 } else
2164                 {
2165                         THIS->parser_error (_ ("need integer number arg"));
2166                         $$ = 0;
2167                 }
2168         }
2169         | '-' bare_int {
2170                 $$ = -$2;
2171         }
2172         ;
2173
2174
2175 string:
2176         STRING          {
2177                 $$ = $1;
2178         }
2179         | STRING_IDENTIFIER     {
2180                 $$ = $1;
2181         }
2182         | string '+' string {
2183                 $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
2184         }
2185         ;
2186
2187
2188 exclamations:
2189                 { $$ = 0; }
2190         | exclamations '!'      { $$ ++; }
2191         ;
2192
2193 questions:
2194                 { $$ = 0; }
2195         | questions '?' { $$ ++; }
2196         ;
2197
2198
2199
2200 full_markup:
2201         MARKUP_IDENTIFIER {
2202                 $$ = $1;
2203         }
2204         | MARKUP 
2205                 { THIS->lexer_->push_markup_state (); }
2206         markup
2207                 { $$ = $3;
2208                   THIS->lexer_->pop_state ();
2209                 }
2210         ;
2211         
2212 markup:
2213         STRING {
2214                 $$ = make_simple_markup ($1);
2215         }
2216         | MARKUP_HEAD_MARKUP0 markup {
2217                 $$ = scm_list_n ($1, $2, SCM_UNDEFINED);
2218         }
2219         | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2220                 $$ = scm_list_n ($1, $2, $3, SCM_UNDEFINED);
2221         }
2222         | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
2223                 $$  = scm_list_n ($1, $2, $3, SCM_UNDEFINED); 
2224         }
2225         | markup_line {
2226                 $$ = $1;
2227         }
2228         | MARKUP_HEAD_LIST0 markup_list {
2229                 $$ = scm_list_n ($1,$2, SCM_UNDEFINED);
2230         }
2231         | MARKUP_HEAD_SCM0 embedded_scm {
2232                 $$ = scm_list_n ($1, $2, SCM_UNDEFINED);
2233         }
2234         | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
2235                 $$ = scm_list_n ($1, $2, $3, $4, SCM_UNDEFINED);
2236         }
2237         | MARKUP_IDENTIFIER {
2238                 $$ = $1;
2239         }
2240         
2241         ;
2242
2243 markup_list:
2244         CHORD_OPEN markup_list_body CHORD_CLOSE { $$ = scm_reverse_x ($2, SCM_EOL); }
2245         ;
2246
2247 markup_line:
2248         '{' markup_list_body '}' {
2249                 static SCM line ;
2250                 if (!line)
2251                         line = scm_c_eval_string ("line-markup");
2252         
2253                 $$ = scm_list_n (line, scm_reverse_x ($2, SCM_EOL), SCM_UNDEFINED);
2254         }
2255         ;
2256
2257 markup_list_body:
2258         /**/ {  $$ = SCM_EOL; }
2259         | markup_list_body markup {
2260                 $$ = gh_cons ($2, $1) ;
2261         }
2262         ;
2263
2264
2265 %%
2266
2267 void
2268 My_lily_parser::set_yydebug (bool )
2269 {
2270 #if 0
2271         yydebug = 1;
2272 #endif
2273 }
2274
2275 extern My_lily_parser * current_parser;
2276
2277 void
2278 My_lily_parser::do_yyparse ()
2279 {
2280         current_parser = this;;
2281         yyparse ((void*)this);
2282 }
2283
2284
2285 /*
2286 Should make this optional?    It will also complain when you do
2287
2288         [s4]
2289
2290 which is entirely legitimate.
2291
2292 Or we can scrap it. Barchecks should detect wrong durations, and
2293 skipTypesetting speeds it up a lot.
2294 */
2295
2296 void
2297 My_lily_parser::beam_check (SCM dur)
2298 {
2299   Duration *d = unsmob_duration (dur);
2300   if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2301     {
2302       Music * m = unsmob_music (last_beam_start_);
2303       m->origin ()->warning (_("Suspect duration found following this beam"));
2304     }
2305   last_beam_start_ = SCM_EOL;
2306 }
2307
2308
2309
2310 bool
2311 markup_p (SCM x)
2312 {
2313         return gh_pair_p (x)
2314                 && SCM_BOOL_F != scm_object_property (gh_car (x), ly_symbol2scm ("markup-signature"));
2315 }
2316 /*
2317 It is a little strange, to have this function in this file, but
2318 otherwise, we have to import music classes into the lexer.
2319
2320 */
2321 int
2322 My_lily_lexer::try_special_identifiers (SCM * destination, SCM sid)
2323 {
2324         if (gh_string_p (sid)) {
2325                 *destination = sid;
2326                 return STRING_IDENTIFIER;
2327         } else if (gh_number_p (sid)) {
2328                 *destination = sid;
2329                 return NUMBER_IDENTIFIER;
2330         } else if (unsmob_translator_def (sid)) {
2331                 *destination = unsmob_translator_def (sid)->clone_scm();
2332                 return TRANSLATOR_IDENTIFIER;
2333         } else if (unsmob_score (sid)) {
2334                 Score *sc =  new Score (*unsmob_score (sid));
2335                 *destination =sc->self_scm ();
2336                 return SCORE_IDENTIFIER;
2337         } else if (Music * mus =unsmob_music (sid)) {
2338                 *destination = unsmob_music (sid)->clone ()->self_scm();
2339                 unsmob_music (*destination)->
2340                         set_mus_property ("origin", make_input (last_input_));
2341                 return dynamic_cast<Event*> (mus)
2342                         ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2343         } else if (unsmob_duration (sid)) {
2344                 *destination = unsmob_duration (sid)->smobbed_copy();
2345                 return DURATION_IDENTIFIER;
2346         } else if (unsmob_music_output_def (sid)) {
2347                 Music_output_def *p = unsmob_music_output_def (sid);
2348                 p = p->clone ();
2349
2350                 *destination = p->self_scm();
2351                 return MUSIC_OUTPUT_DEF_IDENTIFIER;
2352         } else if (new_markup_p (sid)) {
2353                 *destination = sid;
2354                 return MARKUP_IDENTIFIER;
2355         }
2356
2357         return -1;      
2358 }