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