]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
* Documentation/user/refman.itely (Text markup): rewrite manual section.
[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         | full_markup {  $$ = $1; }
1163         ;
1164
1165
1166 event_chord:
1167         pre_events {
1168                 THIS->push_spot ();
1169         } /*cont */ simple_element post_events  {
1170                 SCM elts = $3-> get_mus_property ("elements");
1171
1172                 elts = gh_append3 (elts, scm_reverse_x ($1, SCM_EOL),
1173                                    scm_reverse_x ($4, SCM_EOL));
1174
1175                 $3-> set_mus_property ("elements", elts);
1176                 $$ = $3;
1177         }
1178         | command_element
1179         | note_chord_element
1180         ;
1181
1182
1183 note_chord_element:
1184         chord_body optional_notemode_duration post_events
1185         {
1186                 SCM dur = unsmob_duration ($2)->smobbed_copy();
1187                 SCM es = $1->get_mus_property ("elements");
1188                 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1189
1190                 for (SCM s = es; gh_pair_p (s); s = gh_cdr (s))
1191                   unsmob_music (gh_car(s))->set_mus_property ("duration", dur);
1192                 es = gh_append2 (es, postevs);
1193
1194                 $1-> set_mus_property ("elements", es);
1195                 $$ = $1;
1196         }
1197         ;
1198
1199 chord_body:
1200         CHORD_OPEN chord_body_elements CHORD_CLOSE
1201         {
1202                 $$ = MY_MAKE_MUSIC("EventChord");
1203                 $$->set_mus_property ("elements",
1204                         scm_reverse_x ($2, SCM_EOL));
1205         }
1206         ;
1207
1208 chord_body_elements:
1209         /* empty */             { $$ = SCM_EOL; }
1210         | chord_body_elements chord_body_element {
1211                 $$ = gh_cons ($2->self_scm(), $1);
1212                 scm_gc_unprotect_object ($2->self_scm());
1213         }
1214         ;
1215
1216 chord_body_element:
1217         pitch exclamations questions post_events
1218         {
1219                 Music * n = MY_MAKE_MUSIC("NoteEvent");
1220                 n->set_mus_property ("pitch", $1);
1221                 if ($3 % 2)
1222                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1223                 if ($2 % 2 || $3 % 2)
1224                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1225
1226                 SCM arts = scm_reverse_x ($4, SCM_EOL);
1227                 n->set_mus_property ("articulations", arts);
1228
1229                 $$ = n;
1230         }
1231         ;
1232
1233 command_element:
1234         command_req {
1235                 $$ = MY_MAKE_MUSIC("EventChord");
1236                 $$->set_mus_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1237           scm_gc_unprotect_object ($1->self_scm());
1238
1239                 $$-> set_spot (THIS->here_input ());
1240                 $1-> set_spot (THIS->here_input ());
1241         }
1242         | E_LEFTSQUARE {
1243                 Music *l = MY_MAKE_MUSIC("LigatureEvent");
1244                 l->set_mus_property ("span-direction", gh_int2scm (START));
1245                 l->set_spot (THIS->here_input ());
1246
1247                 $$ = MY_MAKE_MUSIC("EventChord");
1248                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1249                 scm_gc_unprotect_object (l->self_scm());
1250                 $$->set_spot (THIS->here_input ());
1251         }
1252         | E_RIGHTSQUARE {
1253                 Music *l = MY_MAKE_MUSIC("LigatureEvent");
1254                 l->set_mus_property ("span-direction", gh_int2scm (STOP));
1255                 l->set_spot (THIS->here_input ());
1256
1257                 $$ = MY_MAKE_MUSIC("EventChord");
1258                 $$->set_mus_property ("elements", scm_cons (l->self_scm (), SCM_EOL));
1259                 $$->set_spot (THIS->here_input ());
1260                 scm_gc_unprotect_object (l->self_scm());
1261         }
1262         | E_BACKSLASH {
1263                 $$ = MY_MAKE_MUSIC("VoiceSeparator");
1264                 $$->set_spot (THIS->here_input ());
1265         }
1266         | '|'      {
1267
1268                 $$ = MY_MAKE_MUSIC("BarCheck");
1269                 $$->set_spot (THIS->here_input ());
1270         }
1271         | BAR STRING                    {
1272                 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1273
1274                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1275                 csm->set_mus_property ("element", t->self_scm ());
1276                 scm_gc_unprotect_object (t->self_scm ());
1277
1278                 $$ = csm;
1279                 $$->set_spot (THIS->here_input ());
1280
1281                 csm->set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1282         }
1283         | PARTIAL duration_length       {
1284                 Moment m = - unsmob_duration ($2)->get_length ();
1285                 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1286
1287                 Music * sp = MY_MAKE_MUSIC("ContextSpeccedMusic");
1288                 sp->set_mus_property ("element", p->self_scm ());
1289                 scm_gc_unprotect_object (p->self_scm ());
1290
1291                 $$ =sp ;
1292                 sp-> set_mus_property ("context-type", scm_makfrom0str ("Timing"));
1293         }
1294         | CLEF STRING  {
1295                 static SCM proc ;
1296                 if (!proc)
1297                         proc = scm_c_eval_string ("make-clef-set");
1298
1299                 SCM result = scm_call_1 (proc, $2);
1300                 scm_gc_protect_object (result);
1301                 $$ = unsmob_music (result);
1302         }
1303         | TIME_T fraction  {
1304                 static SCM proc;
1305                 if (!proc)
1306                         proc = scm_c_eval_string ("make-time-signature-set");
1307
1308                 SCM result = scm_apply_2   (proc, gh_car ($2), gh_cdr ($2), SCM_EOL);
1309                 scm_gc_protect_object (result);
1310                 $$ = unsmob_music (result);
1311         }
1312         ;
1313
1314 command_req:
1315         shorthand_command_req   { $$ = $1; }
1316         | verbose_command_req   { $$ = $1; }
1317         ;
1318
1319 shorthand_command_req:
1320         extender_req {
1321                 $$ = $1;
1322         }
1323         | hyphen_req {
1324                 $$ = $1;
1325         }
1326         | '~'   {
1327                 $$ = MY_MAKE_MUSIC("TieEvent");
1328         }
1329         | '['           {
1330                 Music *b= MY_MAKE_MUSIC("BeamEvent");
1331                 b->set_mus_property ("span-direction", gh_int2scm (START));
1332                 $$ = b;
1333
1334                 THIS->last_beam_start_ = b->self_scm ();
1335         }
1336         | ']'           {
1337                 Music *b= MY_MAKE_MUSIC("BeamEvent");
1338                 b->set_mus_property ("span-direction", gh_int2scm (STOP));
1339                 $$ = b;
1340         }
1341         | BREATHE {
1342                 $$ = MY_MAKE_MUSIC("BreathingSignEvent");
1343         }
1344         | E_TILDE {
1345                 $$ = MY_MAKE_MUSIC("PorrectusEvent");
1346         }
1347         ;
1348
1349 verbose_command_req:
1350         MARK DEFAULT  {
1351                 Music * m = MY_MAKE_MUSIC("MarkEvent");
1352                 $$ = m;
1353         }
1354         | MARK scalar {
1355                 Music *m = MY_MAKE_MUSIC("MarkEvent");
1356                 m->set_mus_property ("label", $2);
1357                 $$ = m;
1358         }
1359         | SKIP duration_length {
1360                 Music * skip = MY_MAKE_MUSIC("SkipEvent");
1361                 skip->set_mus_property ("duration", $2);
1362
1363                 $$ = skip;
1364         }
1365         | tempo_event {
1366                 $$ = $1;
1367         }
1368         | KEY DEFAULT {
1369                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1370                 $$ = key;
1371         }
1372         | KEY NOTENAME_PITCH SCM_IDENTIFIER     {
1373                 Music *key= MY_MAKE_MUSIC("KeyChangeEvent");
1374                 
1375                 key->set_mus_property ("pitch-alist", $3);
1376                 ((Music*)key)->transpose (* unsmob_pitch ($2));
1377                 $$ = key; 
1378         }
1379         ;
1380
1381 post_events:
1382         /* empty */ {
1383                 $$ = SCM_EOL;
1384         }
1385         | post_events post_event {
1386                 $2->set_spot (THIS->here_input ());
1387                 $$ = gh_cons ($2->self_scm(), $$);
1388                 scm_gc_unprotect_object ($2->self_scm());
1389         }
1390         ;
1391
1392 post_event:
1393         verbose_event
1394         | event_with_dir
1395         | close_event
1396         | string_event
1397         ;
1398
1399 string_event:
1400         E_UNSIGNED {
1401                 Music * s = MY_MAKE_MUSIC("StringNumberEvent");
1402                 s->set_mus_property ("string-number",  gh_int2scm($1));
1403                 s->set_spot (THIS->here_input ());
1404                 $$ = s;
1405         }
1406         ;
1407
1408
1409 event_that_take_dir:
1410         gen_text_def
1411         | verbose_event
1412         | close_event
1413         | open_event
1414         | '['  {
1415                 Music * m = MY_MAKE_MUSIC ("NewBeamEvent");
1416                 m->set_spot (THIS->here_input());
1417                 m->set_mus_property ("span-direction" , gh_int2scm (START));
1418                 $$ = m;
1419         }
1420         | ']'  {
1421                 Music * m = MY_MAKE_MUSIC ("NewBeamEvent");
1422                 m->set_spot (THIS->here_input());
1423                 m->set_mus_property ("span-direction" , gh_int2scm (STOP));
1424                 $$ = m;
1425         }
1426         | '~' {
1427                 Music * m = MY_MAKE_MUSIC ("NewTieEvent");
1428                 m->set_spot (THIS->here_input());
1429                 $$ = m;
1430         }
1431         | script_abbreviation {
1432                 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1433                 Music *a = MY_MAKE_MUSIC("ArticulationEvent");
1434                 if (gh_string_p (s))
1435                         a->set_mus_property ("articulation-type", s);
1436                 else THIS->parser_error (_ ("Expecting string as script definition"));
1437                 $$ = a;
1438         }
1439         ;
1440
1441 event_with_dir:
1442         script_dir event_that_take_dir  {
1443                 $2->set_mus_property ("direction", gh_int2scm ($1));
1444                 $$ = $2;
1445         }
1446         ;
1447         
1448 verbose_event:
1449         EVENT_IDENTIFIER        {
1450                 $$ = unsmob_music ($1);
1451         }
1452         | tremolo_type  {
1453                Music * a = MY_MAKE_MUSIC("TremoloEvent");
1454                a->set_spot (THIS->here_input ());
1455                a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1456                $$ = a;
1457         }
1458         ;
1459
1460 sup_quotes:
1461         '\'' {
1462                 $$ = 1;
1463         }
1464         | sup_quotes '\'' {
1465                 $$ ++;
1466         }
1467         ;
1468
1469 sub_quotes:
1470         ',' {
1471                 $$ = 1;
1472         }
1473         | sub_quotes ',' {
1474                 $$ ++ ;
1475         }
1476         ;
1477
1478 steno_pitch:
1479         NOTENAME_PITCH  {
1480                 $$ = $1;
1481         }
1482         | NOTENAME_PITCH sup_quotes     {
1483                 Pitch p = *unsmob_pitch ($1);
1484                 p.octave_ +=  $2;
1485                 $$ = p.smobbed_copy ();
1486         }
1487         | NOTENAME_PITCH sub_quotes      {
1488                 Pitch p =* unsmob_pitch ($1);
1489
1490                 p.octave_ +=  -$2;
1491                 $$ = p.smobbed_copy ();
1492
1493         }
1494         ;
1495
1496 /*
1497 ugh. duplication
1498 */
1499
1500 steno_tonic_pitch:
1501         TONICNAME_PITCH {
1502                 $$ = $1;
1503         }
1504         | TONICNAME_PITCH sup_quotes    {
1505                 Pitch p = *unsmob_pitch ($1);
1506                 p.octave_ +=  $2;
1507                 $$ = p.smobbed_copy ();
1508         }
1509         | TONICNAME_PITCH sub_quotes     {
1510                 Pitch p =* unsmob_pitch ($1);
1511
1512                 p.octave_ +=  -$2;
1513                 $$ = p.smobbed_copy ();
1514
1515         }
1516         ;
1517
1518 pitch:
1519         steno_pitch {
1520                 $$ = $1;
1521         }
1522         | explicit_pitch {
1523                 $$ = $1;
1524         }
1525         ;
1526
1527 pitch_also_in_chords:
1528         pitch
1529         | steno_tonic_pitch
1530         ;
1531
1532 explicit_pitch:
1533         PITCH embedded_scm {
1534                 $$ = $2;
1535                 if (!unsmob_pitch ($2)) {
1536                         THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1537                          $$ = Pitch ().smobbed_copy ();
1538                 }
1539         }
1540         ;
1541
1542 verbose_duration:
1543         DURATION embedded_scm   {
1544                 $$ = $2;
1545                 if (!unsmob_duration ($2))
1546                 {
1547                         THIS->parser_error (_ ("Must have duration object"));
1548                         $$ = Duration ().smobbed_copy ();
1549                 }
1550         }
1551         ;
1552
1553 extender_req:
1554         EXTENDER {
1555                 if (!THIS->lexer_->lyric_state_b ())
1556                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1557                 $$ = MY_MAKE_MUSIC("ExtenderEvent");
1558         }
1559         ;
1560
1561 hyphen_req:
1562         HYPHEN {
1563                 if (!THIS->lexer_->lyric_state_b ())
1564                         THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1565                 $$ = MY_MAKE_MUSIC("HyphenEvent");
1566         }
1567         ;
1568
1569 close_event:
1570         close_event_parens {
1571                 $$ = $1;
1572                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (START))
1573 ;
1574         }
1575         ;
1576  
1577 close_event_parens:
1578         '('     {
1579                 Music * s= MY_MAKE_MUSIC("SlurEvent");
1580                 $$ = s;
1581                 s->set_spot (THIS->here_input());
1582         }
1583         | E_OPEN        {
1584                 Music * s= MY_MAKE_MUSIC("PhrasingSlurEvent");
1585                 $$ = s;
1586                 s->set_spot (THIS->here_input());
1587         }
1588         | E_SMALLER {
1589                 Music *s =MY_MAKE_MUSIC("CrescendoEvent");
1590                 $$ = s;
1591                 s->set_spot (THIS->here_input());
1592         }
1593         | E_BIGGER {
1594                 Music *s =MY_MAKE_MUSIC("DecrescendoEvent");
1595                 $$ = s;
1596                 s->set_spot (THIS->here_input());
1597         }
1598         ;
1599
1600
1601 open_event:
1602         open_event_parens {
1603                 $$ = $1;
1604                 dynamic_cast<Music *> ($$)->set_mus_property ("span-direction", gh_int2scm (STOP))
1605 ;
1606         }
1607         ;
1608
1609 open_event_parens:
1610         E_EXCLAMATION   {
1611                 Music *s =  MY_MAKE_MUSIC("CrescendoEvent");
1612                 s->set_spot (THIS->here_input());
1613
1614                 $$ = s;
1615         }
1616         | ')'   {
1617                 Music * s= MY_MAKE_MUSIC("SlurEvent");
1618                 $$ = s;
1619                 s->set_spot (THIS->here_input());
1620
1621         }
1622         | E_CLOSE       {
1623                 Music * s= MY_MAKE_MUSIC("PhrasingSlurEvent");
1624                 $$ = s;
1625                 s->set_mus_property ("span-type", scm_makfrom0str ( "phrasing-slur"));
1626                 s->set_spot (THIS->here_input());
1627         }
1628         ;
1629
1630 gen_text_def:
1631         embedded_scm {
1632                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1633                 t->set_mus_property ("text", $1);
1634                 t->set_spot (THIS->here_input ());
1635                 $$ = t;
1636         }
1637         | full_markup {
1638                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1639                 t->set_mus_property ("text", $1);
1640                 t->set_spot (THIS->here_input ());
1641                 $$ = t; 
1642         }
1643         | string {
1644                 Music *t = MY_MAKE_MUSIC("TextScriptEvent");
1645                 t->set_mus_property ("text", make_simple_markup ($1));
1646                 t->set_spot (THIS->here_input ());
1647                 $$ = t;
1648         
1649         }
1650         | DIGIT {
1651                 Music * t = MY_MAKE_MUSIC("FingerEvent");
1652                 t->set_mus_property ("digit",  gh_int2scm ($1));
1653                 t->set_spot (THIS->here_input ());
1654                 $$ = t;
1655         }
1656         ;
1657
1658 script_abbreviation:
1659         '^'             {
1660                 $$ = scm_makfrom0str ("Hat");
1661         }
1662         | '+'           {
1663                 $$ = scm_makfrom0str ("Plus");
1664         }
1665         | '-'           {
1666                 $$ = scm_makfrom0str ("Dash");
1667         }
1668         | '|'           {
1669                 $$ = scm_makfrom0str ("Bar");
1670         }
1671         | '>'           {
1672                 $$ = scm_makfrom0str ("Larger");
1673         }
1674         | '.'           {
1675                 $$ = scm_makfrom0str ("Dot");
1676         }
1677         | '_' {
1678                 $$ = scm_makfrom0str ("Underscore");
1679         }
1680         ;
1681
1682 script_dir:
1683         '_'     { $$ = DOWN; }
1684         | '^'   { $$ = UP; }
1685         | '-'   { $$ = CENTER; }
1686         ;
1687
1688 pre_events:
1689         /* empty */ { 
1690                 $$ = SCM_EOL;
1691         }
1692         | pre_events open_event {
1693                 $$ = gh_cons ($2->self_scm(), $$);
1694                 scm_gc_unprotect_object ($2->self_scm());
1695         }
1696         ;
1697
1698 absolute_pitch:
1699         steno_pitch     {
1700                 $$ = $1;
1701         }
1702         ;
1703
1704 duration_length:
1705         multiplied_duration {
1706                 $$ = $1;
1707         }
1708         | verbose_duration {
1709                 $$ = $1;
1710         }       
1711         ;
1712
1713 optional_notemode_duration:
1714         {
1715                 Duration dd = THIS->default_duration_;
1716                 $$ = dd.smobbed_copy ();
1717
1718                 THIS->beam_check ($$);
1719         }
1720         | multiplied_duration   {
1721                 $$ = $1;
1722                 THIS->default_duration_ = *unsmob_duration ($$);
1723
1724                 THIS->beam_check ($$);
1725         }
1726         | verbose_duration {
1727                 $$ = $1;
1728                 THIS->default_duration_ = *unsmob_duration ($$);
1729         }       
1730         ;
1731
1732 steno_duration:
1733         bare_unsigned dots              {
1734                 int l = 0;
1735                 if (!is_duration_b ($1))
1736                         THIS->parser_error (_f ("not a duration: %d", $1));
1737                 else
1738                         l =  intlog2 ($1);
1739
1740                 $$ = Duration (l, $2).smobbed_copy ();
1741         }
1742         | DURATION_IDENTIFIER dots      {
1743                 Duration *d =unsmob_duration ($1);
1744                 Duration k (d->duration_log (),d->dot_count () + $2);
1745
1746                 *d = k;
1747                 $$ = $1;
1748         }
1749         ;
1750
1751
1752
1753
1754 multiplied_duration:
1755         steno_duration {
1756                 $$ = $1;
1757         }
1758         | multiplied_duration '*' bare_unsigned {
1759                 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1760         }
1761         | multiplied_duration '*' FRACTION {
1762                 Rational  m (gh_scm2int (ly_car ($3)), gh_scm2int (ly_cdr ($3)));
1763
1764                 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1765         }
1766         ;
1767
1768 fraction:
1769         FRACTION { $$ = $1; }
1770         | UNSIGNED '/' UNSIGNED {
1771                 $$ = scm_cons (gh_int2scm ($1), gh_int2scm ($3));
1772         }
1773         ;
1774
1775 dots:
1776         /* empty */     {
1777                 $$ = 0;
1778         }
1779         | dots '.' {
1780                 $$ ++;
1781         }
1782         ;
1783
1784
1785 tremolo_type: 
1786         ':'     {
1787                 $$ =0;
1788         }
1789         | ':' bare_unsigned {
1790                 if (!is_duration_b ($2))
1791                         THIS->parser_error (_f ("not a duration: %d", $2));
1792                 $$ = $2;
1793         }
1794         ;
1795
1796
1797
1798 /*****************************************************************
1799                 BASS FIGURES
1800 *****************************************************************/
1801 bass_number:
1802         DIGIT
1803         | UNSIGNED 
1804         ;
1805
1806 bass_mod:
1807         '-'     { $$ = -1; }
1808         | '+'   { $$ = 1; } 
1809         | '!'   { $$ = 0; }
1810         ;
1811
1812 bass_figure:
1813         FIGURE_SPACE {
1814                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1815                 $$ = bfr->self_scm();
1816                 scm_gc_unprotect_object ($$);
1817         }
1818         | bass_number  {
1819                 Music *bfr = MY_MAKE_MUSIC("BassFigureEvent");
1820                 $$ = bfr->self_scm();
1821
1822                 bfr->set_mus_property ("figure", gh_int2scm ($1));
1823
1824                 scm_gc_unprotect_object ($$);
1825         }
1826         | bass_figure bass_mod {
1827                 Music *m = unsmob_music ($1);
1828                 if ($2) {
1829                         SCM salter =m->get_mus_property ("alteration");
1830                         int alter = gh_number_p ( salter) ? gh_scm2int (salter) : 0;
1831                         m->set_mus_property ("alteration",
1832                                 gh_int2scm (alter + $2));
1833                 } else {
1834                         m->set_mus_property ("alteration", gh_int2scm (0));
1835                 }
1836         }
1837         ;
1838
1839 br_bass_figure:
1840         '[' bass_figure {
1841                 $$ = $2;
1842                 unsmob_music ($$)->set_mus_property ("bracket-start", SCM_BOOL_T);
1843         }
1844         | bass_figure   {
1845                 $$ = $1;
1846         }
1847         | br_bass_figure ']' {
1848                 $$ = $1;
1849                 unsmob_music ($1)->set_mus_property ("bracket-stop", SCM_BOOL_T);
1850         }
1851         ;
1852
1853 figure_list:
1854         /**/            {
1855                 $$ = SCM_EOL;
1856         }
1857         | figure_list br_bass_figure {
1858                 $$ = scm_cons ($2, $1); 
1859         }
1860         ;
1861
1862 figure_spec:
1863         FIGURE_OPEN figure_list FIGURE_CLOSE {
1864                 Music * m = MY_MAKE_MUSIC("EventChord");
1865                 $2 = scm_reverse_x ($2, SCM_EOL);
1866                 m->set_mus_property ("elements",  $2);
1867                 $$ = m->self_scm ();
1868         }
1869         ;
1870
1871
1872 optional_rest:
1873         /**/   { $$ = 0; }
1874         | REST { $$ = 1; }
1875         ;
1876
1877 simple_element:
1878         pitch exclamations questions optional_notemode_duration optional_rest {
1879
1880                 Input i = THIS->pop_spot ();
1881                 if (!THIS->lexer_->note_state_b ())
1882                         THIS->parser_error (_ ("Have to be in Note mode for notes"));
1883
1884                 Music *n = 0;
1885                 if ($5)
1886                         n =  MY_MAKE_MUSIC("RestEvent");
1887                 else
1888                         n =  MY_MAKE_MUSIC("NoteEvent");
1889                 
1890                 n->set_mus_property ("pitch", $1);
1891                 n->set_mus_property ("duration", $4);
1892
1893
1894                 if ($3 % 2)
1895                         n->set_mus_property ("cautionary", SCM_BOOL_T);
1896                 if ($2 % 2 || $3 % 2)
1897                         n->set_mus_property ("force-accidental", SCM_BOOL_T);
1898
1899                 Music *v = MY_MAKE_MUSIC("EventChord");
1900                 v->set_mus_property ("elements", scm_list_n (n->self_scm (), SCM_UNDEFINED));
1901                 scm_gc_unprotect_object (n->self_scm());
1902
1903                 v->set_spot (i);
1904                 n->set_spot (i);
1905                 $$ = v;
1906         }
1907         | figure_spec optional_notemode_duration {
1908                 Music * m = unsmob_music ($1);
1909                 Input i = THIS->pop_spot (); 
1910                 m->set_spot (i);
1911                 for (SCM s = m->get_mus_property ("elements"); gh_pair_p (s); s = ly_cdr (s))
1912                 {
1913                         unsmob_music (ly_car (s))->set_mus_property ("duration", $2);
1914                 }
1915                 $$ = m;
1916         }       
1917         | RESTNAME optional_notemode_duration           {
1918
1919                 Input i = THIS->pop_spot ();
1920                 Music * ev = 0;
1921                 if (ly_scm2string ($1) =="s") {
1922                         /* Space */
1923                         ev = MY_MAKE_MUSIC("SkipEvent");
1924                   }
1925                 else {
1926                         ev = MY_MAKE_MUSIC("RestEvent");
1927                 
1928                     }
1929                 ev->set_mus_property ("duration" ,$2);
1930                 ev->set_spot (i);
1931                 Music * velt = MY_MAKE_MUSIC("EventChord");
1932                 velt->set_mus_property ("elements", scm_list_n (ev->self_scm (),SCM_UNDEFINED));
1933                 velt->set_spot (i);
1934
1935                 $$ = velt;
1936         }
1937         | MULTI_MEASURE_REST optional_notemode_duration         {
1938                 THIS->pop_spot ();
1939
1940                 static SCM proc ;
1941                 if (!proc)
1942                         proc = scm_c_eval_string ("make-multi-measure-rest");
1943
1944                 SCM mus = scm_call_2 (proc, $2,
1945                         make_input (THIS->here_input()));       
1946                 scm_gc_protect_object (mus);
1947                 $$ = unsmob_music (mus);
1948         }
1949         | STRING optional_notemode_duration     {
1950                 Input i = THIS->pop_spot ();
1951
1952                 Music * lreq = MY_MAKE_MUSIC("LyricEvent");
1953                 lreq->set_mus_property ("text", $1);
1954                 lreq->set_mus_property ("duration",$2);
1955                 lreq->set_spot (i);
1956                 Music * velt = MY_MAKE_MUSIC("EventChord");
1957                 velt->set_mus_property ("elements", scm_list_n (lreq->self_scm (), SCM_UNDEFINED));
1958
1959                 $$= velt;
1960         }
1961         | chord {
1962                 THIS->pop_spot ();
1963
1964                 if (!THIS->lexer_->chord_state_b ())
1965                         THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1966                 $$ = $1;
1967         }
1968         ;
1969
1970
1971 chord:
1972         steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1973                 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1974                 $$->set_spot (THIS->here_input ());
1975         };
1976
1977 chord_additions: 
1978         {
1979                 $$ = SCM_EOL;
1980         } 
1981         | CHORD_COLON chord_notes {
1982                 $$ = $2;
1983         }
1984         ;
1985
1986 chord_notes:
1987         chord_step {
1988                 $$ = $1;
1989         }
1990         | chord_notes '.' chord_step {
1991                 $$ = gh_append2 ($$, $3);
1992         }
1993         ;
1994
1995 chord_subtractions: 
1996         {
1997                 $$ = SCM_EOL;
1998         } 
1999         | CHORD_CARET chord_notes {
2000                 $$ = $2;
2001         }
2002         ;
2003
2004
2005 chord_inversion:
2006         {
2007                 $$ = SCM_EOL;
2008         }
2009         | CHORD_SLASH steno_tonic_pitch {
2010                 $$ = $2;
2011         }
2012         ;
2013
2014 chord_bass:
2015         {
2016                 $$ = SCM_EOL;
2017         }
2018         | CHORD_BASS steno_tonic_pitch {
2019                 $$ = $2;
2020         }
2021         ;
2022
2023 chord_step:
2024         chord_note {
2025                 $$ = scm_cons ($1, SCM_EOL);
2026         }
2027         | CHORDMODIFIER_PITCH {
2028                 $$ = scm_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
2029         }
2030         | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
2031                 $$ = scm_list_n (unsmob_pitch ($1)->smobbed_copy (),
2032                         $2, SCM_UNDEFINED);
2033         }
2034         ;
2035
2036 chord_note:
2037         bare_unsigned {
2038                  Pitch m;
2039                 m.notename_ = ($1 - 1) % 7;
2040                 m.octave_ = $1 > 7 ? 1 : 0;
2041                 m.alteration_ = 0;
2042
2043                 $$ = m.smobbed_copy ();
2044         } 
2045         | bare_unsigned '+' {
2046                 Pitch m;
2047                 m.notename_ = ($1 - 1) % 7;
2048                 m.octave_ = $1 > 7 ? 1 : 0;
2049                 m.alteration_ = 1;
2050
2051
2052                 $$ = m.smobbed_copy ();
2053         }
2054         | bare_unsigned CHORD_MINUS {
2055                 Pitch m;
2056                 m.notename_ = ($1 - 1) % 7;
2057                 m.octave_ = $1 > 7 ? 1 : 0;
2058                 m.alteration_ = -1;
2059
2060                 $$ = m.smobbed_copy ();
2061         }
2062         ;
2063
2064 /*
2065         UTILITIES
2066  */
2067 number_expression:
2068         number_expression '+' number_term {
2069                 $$ = scm_sum ($1, $3);
2070         }
2071         | number_expression '-' number_term {
2072                 $$ = scm_difference ($1, $3);
2073         }
2074         | number_term 
2075         ;
2076
2077 number_term:
2078         number_factor {
2079                 $$ = $1;
2080         }
2081         | number_factor '*' number_factor {
2082                 $$ = scm_product ($1, $3);
2083         }
2084         | number_factor '/' number_factor {
2085                 $$ = scm_divide ($1, $3);
2086         }
2087         ;
2088
2089 number_factor:
2090         '-'  number_factor { /* %prec UNARY_MINUS */
2091                 $$ = scm_difference ($2, SCM_UNDEFINED);
2092         }
2093         | bare_number
2094         ;
2095
2096
2097 bare_number:
2098         UNSIGNED        {
2099                 $$ = gh_int2scm ($1);
2100         }
2101         | REAL          {
2102                 $$ = $1;
2103         }
2104         | NUMBER_IDENTIFIER             {
2105                 $$ = $1;
2106         }
2107         | REAL NUMBER_IDENTIFIER        {
2108                 $$ = gh_double2scm (gh_scm2double ($1) * gh_scm2double ($2));
2109         }
2110         | UNSIGNED NUMBER_IDENTIFIER    {
2111                 $$ = gh_double2scm ($1 * gh_scm2double ($2));
2112         }
2113         ;
2114
2115
2116 bare_unsigned:
2117         UNSIGNED {
2118                         $$ = $1;
2119         }
2120         | DIGIT {
2121                 $$ = $1;
2122         }
2123         ;
2124
2125 bare_int:
2126         bare_number {
2127                 if (scm_integer_p ($1) == SCM_BOOL_T)
2128                 {
2129                         int k = gh_scm2int ($1);
2130                         $$ = k;
2131                 } else
2132                 {
2133                         THIS->parser_error (_ ("need integer number arg"));
2134                         $$ = 0;
2135                 }
2136         }
2137         | '-' bare_int {
2138                 $$ = -$2;
2139         }
2140         ;
2141
2142
2143 string:
2144         STRING          {
2145                 $$ = $1;
2146         }
2147         | STRING_IDENTIFIER     {
2148                 $$ = $1;
2149         }
2150         | string '+' string {
2151                 $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
2152         }
2153         ;
2154
2155
2156 exclamations:
2157                 { $$ = 0; }
2158         | exclamations '!'      { $$ ++; }
2159         ;
2160
2161 questions:
2162                 { $$ = 0; }
2163         | questions '?' { $$ ++; }
2164         ;
2165
2166
2167
2168 full_markup:
2169         MARKUP_IDENTIFIER {
2170                 $$ = $1;
2171         }
2172         | MARKUP 
2173                 { THIS->lexer_->push_markup_state (); }
2174         markup
2175                 { $$ = $3;
2176                   THIS->lexer_->pop_state ();
2177                 }
2178         ;
2179         
2180 markup:
2181         STRING {
2182                 $$ = make_simple_markup ($1);
2183         }
2184         | MARKUP_HEAD_MARKUP0 markup {
2185                 $$ = scm_list_n ($1, $2, SCM_UNDEFINED);
2186         }
2187         | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2188                 $$ = scm_list_n ($1, $2, $3, SCM_UNDEFINED);
2189         }
2190         | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
2191                 $$  = scm_list_n ($1, $2, $3, SCM_UNDEFINED); 
2192         }
2193         | markup_line {
2194                 $$ = $1;
2195         }
2196         | MARKUP_HEAD_LIST0 markup_list {
2197                 $$ = scm_list_n ($1,$2, SCM_UNDEFINED);
2198         }
2199         | MARKUP_HEAD_SCM0 embedded_scm {
2200                 $$ = scm_list_n ($1, $2, SCM_UNDEFINED);
2201         }
2202         | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
2203                 $$ = scm_list_n ($1, $2, $3, $4, SCM_UNDEFINED);
2204         }
2205         | MARKUP_IDENTIFIER {
2206                 $$ = $1;
2207         }
2208         
2209         ;
2210
2211 markup_list:
2212         CHORD_OPEN markup_list_body CHORD_CLOSE { $$ = scm_reverse_x ($2, SCM_EOL); }
2213         ;
2214
2215 markup_line:
2216         '{' markup_list_body '}' {
2217                 static SCM line ;
2218                 if (!line)
2219                         line = scm_c_eval_string ("line-markup");
2220         
2221                 $$ = scm_list_n (line, scm_reverse_x ($2, SCM_EOL), SCM_UNDEFINED);
2222         }
2223         ;
2224
2225 markup_list_body:
2226         /**/ {  $$ = SCM_EOL; }
2227         | markup_list_body markup {
2228                 $$ = gh_cons ($2, $1) ;
2229         }
2230         ;
2231
2232
2233 %%
2234
2235 void
2236 My_lily_parser::set_yydebug (bool )
2237 {
2238 #if 0
2239         yydebug = 1;
2240 #endif
2241 }
2242
2243 extern My_lily_parser * current_parser;
2244
2245 void
2246 My_lily_parser::do_yyparse ()
2247 {
2248         current_parser = this;;
2249         yyparse ((void*)this);
2250 }
2251
2252
2253 /*
2254 Should make this optional?    It will also complain when you do
2255
2256         [s4]
2257
2258 which is entirely legitimate.
2259
2260 Or we can scrap it. Barchecks should detect wrong durations, and
2261 skipTypesetting speeds it up a lot.
2262 */
2263
2264 void
2265 My_lily_parser::beam_check (SCM dur)
2266 {
2267   Duration *d = unsmob_duration (dur);
2268   if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2269     {
2270       Music * m = unsmob_music (last_beam_start_);
2271       m->origin ()->warning (_("Suspect duration found following this beam"));
2272     }
2273   last_beam_start_ = SCM_EOL;
2274 }
2275
2276
2277
2278 bool
2279 markup_p (SCM x)
2280 {
2281         return gh_pair_p (x)
2282                 && SCM_BOOL_F != scm_object_property (gh_car (x), ly_symbol2scm ("markup-signature"));
2283 }
2284 /*
2285 It is a little strange, to have this function in this file, but
2286 otherwise, we have to import music classes into the lexer.
2287
2288 */
2289 int
2290 My_lily_lexer::try_special_identifiers (SCM * destination, SCM sid)
2291 {
2292         if (gh_string_p (sid)) {
2293                 *destination = sid;
2294                 return STRING_IDENTIFIER;
2295         } else if (gh_number_p (sid)) {
2296                 *destination = sid;
2297                 return NUMBER_IDENTIFIER;
2298         } else if (unsmob_translator_def (sid)) {
2299                 *destination = unsmob_translator_def (sid)->clone_scm();
2300                 return TRANSLATOR_IDENTIFIER;
2301         } else if (unsmob_score (sid)) {
2302                 Score *sc =  new Score (*unsmob_score (sid));
2303                 *destination =sc->self_scm ();
2304                 return SCORE_IDENTIFIER;
2305         } else if (Music * mus =unsmob_music (sid)) {
2306                 *destination = unsmob_music (sid)->clone ()->self_scm();
2307                 unsmob_music (*destination)->
2308                         set_mus_property ("origin", make_input (last_input_));
2309                 return dynamic_cast<Event*> (mus)
2310                         ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2311         } else if (unsmob_duration (sid)) {
2312                 *destination = unsmob_duration (sid)->smobbed_copy();
2313                 return DURATION_IDENTIFIER;
2314         } else if (unsmob_music_output_def (sid)) {
2315                 Music_output_def *p = unsmob_music_output_def (sid);
2316                 p = p->clone ();
2317
2318                 *destination = p->self_scm();
2319                 return MUSIC_OUTPUT_DEF_IDENTIFIER;
2320         } else if (new_markup_p (sid)) {
2321                 *destination = sid;
2322                 return MARKUP_IDENTIFIER;
2323         }
2324
2325         return -1;      
2326 }