]> git.donarmstrong.com Git - lilypond.git/blob - lily/parser.yy
(markup-thrower-typecheck)
[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           $$ = tab;
408         }
409         ;
410
411 lilypond_header_body:
412         {
413                 $$ = ly_make_anonymous_module (); 
414                 THIS->lexer_->add_scope ($$);
415         }
416         | lilypond_header_body assignment  { 
417                 
418         }
419         ;
420
421 lilypond_header:
422         HEADER '{' lilypond_header_body '}'     {
423                 $$ = THIS->lexer_-> remove_scope();
424         }
425         ;
426
427
428 /*
429         DECLARATIONS
430 */
431 assignment:
432         STRING {
433                 THIS->push_spot ();
434         }
435         /* cont */ '=' identifier_init  {
436
437         /*
438                 Should find generic way of associating input with objects.
439         */
440                 Input ip = THIS->pop_spot ();
441
442                 if (! regular_identifier_b ($1))
443                 {
444                         ip.warning (_ ("Identifier should have alphabetic characters only"));
445                 }
446
447                 THIS->lexer_->set_identifier ($1, $4);
448
449 /*
450  TODO: devise standard for protection in parser.
451
452   The parser stack lives on the C-stack, which means that
453 all objects can be unprotected as soon as they're here.
454
455 */
456         }
457         | embedded_scm { }
458         ;
459
460
461
462 identifier_init:
463         score_block {
464                 $$ = $1->self_scm ();
465                 scm_gc_unprotect_object ($$);
466         }
467         | full_markup {
468                 $$ = $1;
469         }
470         | output_def {
471                 $$ = $1->self_scm ();
472                 scm_gc_unprotect_object ($$);
473         }
474         | translator_spec_block {
475                 $$ = $1;
476         }
477         | Music  {
478                 $$ = $1->self_scm ();
479                 scm_gc_unprotect_object ($$);
480         }
481         | post_event {
482                 $$ = $1->self_scm ();
483                 scm_gc_unprotect_object ($$);
484         }
485         | verbose_duration {
486                 $$ = $1;
487         }
488         | number_expression {
489                 $$ = $1;
490         }
491         | string {
492                 $$ = $1;
493         }
494         | embedded_scm  {
495                 $$ = $1;
496         }
497         ;
498
499 translator_spec_block:
500         TRANSLATOR '{' translator_spec_body '}'
501                 {
502                 $$ = $3;
503         }
504         ;
505
506 translator_spec_body:
507         TRANSLATOR_IDENTIFIER   {
508                 $$ = $1;
509                 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
510         }
511         | TYPE STRING   {
512                 $$ = Translator_def::make_scm ();
513                 Translator_def*td =  unsmob_translator_def ($$);
514                 td->translator_group_type_ = $2;
515                 td->set_spot (THIS->here_input ());
516         }
517         | translator_spec_body STRING '=' embedded_scm                  {
518                 unsmob_translator_def ($$)->add_property_assign ($2, $4);
519         }
520         | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
521                 unsmob_translator_def ($$)
522                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
523         }
524         | translator_spec_body STRING SET embedded_scm '=' embedded_scm {
525                 unsmob_translator_def ($$)
526                         ->add_push_property (scm_string_to_symbol ($2), $4, $6);
527         }
528         | translator_spec_body STRING REVERT embedded_scm  {
529           unsmob_translator_def ($$)->add_pop_property (
530                 scm_string_to_symbol ($2), $4);
531         }
532         | translator_spec_body NAME STRING  {
533                 unsmob_translator_def ($$)->type_name_ = $3;
534         }
535         | translator_spec_body CONSISTS STRING  {
536                 unsmob_translator_def ($$)->add_element ($3);
537         }
538         | translator_spec_body ALIAS STRING  {
539                 Translator_def*td = unsmob_translator_def ($$);
540                 td->type_aliases_ = scm_cons ($3, td->type_aliases_);
541         }
542         | translator_spec_body GROBDESCRIPTIONS embedded_scm {
543                 Translator_def*td = unsmob_translator_def($$);
544                 // td->add_property_assign (ly_symbol2scm ("allGrobDescriptions"), $3);
545                 for (SCM p = $3; gh_pair_p (p); p = ly_cdr (p))
546                         td->add_property_assign (scm_symbol_to_string (ly_caar (p)), ly_cdar (p));
547         }
548         | translator_spec_body CONSISTSEND STRING  {
549                 unsmob_translator_def ($$)->add_last_element ( $3);
550         }
551         | translator_spec_body ACCEPTS STRING  {
552                 unsmob_translator_def ($$)->set_acceptor ($3,true);
553         }
554         | translator_spec_body DENIES STRING  {
555                 unsmob_translator_def ($$)->set_acceptor ($3,false);
556         }
557         | translator_spec_body REMOVE STRING  {
558                 unsmob_translator_def ($$)->remove_element ($3);
559         }
560         ;
561
562 /*
563         SCORE
564 */
565 score_block:
566         SCORE { 
567                 THIS->push_spot ();
568         }
569         /*cont*/ '{' score_body '}'     {
570                 THIS->pop_spot ();
571                 $$ = $4;
572                 if (!$$->defs_.size ())
573                 {
574                   Music_output_def *id =
575                         unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
576                   $$->add_output (id ? id->clone () :  new Paper_def );
577                 }
578         }
579         ;
580
581 score_body:
582         Music   {
583                 $$ = new Score;
584         
585                 $$->set_spot (THIS->here_input ());
586                 SCM m = $1->self_scm ();
587                 scm_gc_unprotect_object (m);
588
589                 /*
590                         guh.
591                 */
592                 SCM check_funcs = scm_c_eval_string ("toplevel-music-functions");
593                 for (; gh_pair_p (check_funcs); check_funcs = gh_cdr (check_funcs))
594                         m = gh_call1 (gh_car (check_funcs), m);
595                 $$->music_ = m;
596
597         }
598         | SCORE_IDENTIFIER {
599                 $$ = unsmob_score ($1);
600                 $$->set_spot (THIS->here_input ());
601         }
602         | score_body lilypond_header    {
603                 $$->header_ = $2;
604         }
605         | score_body output_def {
606                 $$->add_output ($2);
607         }
608         | score_body error {
609
610         }
611         ;
612
613
614 /*
615         MIDI
616 */
617 output_def:
618         music_output_def_body '}' {
619                 $$ = $1;
620                 THIS-> lexer_-> remove_scope ();
621         }
622         ;
623
624 music_output_def_body:
625         MIDI '{'    {
626                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
627
628
629                 Midi_def* p =0;
630                 if (id)
631                         p = dynamic_cast<Midi_def*> (id->clone ());
632                 else
633                         p = new Midi_def;
634
635                 $$ = p;
636                 THIS->lexer_->add_scope (p->scope_);
637         }
638         | PAPER '{'     {
639                 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
640                   Paper_def *p = 0;
641                 if (id)
642                         p = dynamic_cast<Paper_def*> (id->clone ());
643                 else
644                         p = new Paper_def;
645
646                 THIS->lexer_->add_scope (p->scope_);
647                 $$ = p;
648         }
649         | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER         {
650                 Music_output_def * o =  unsmob_music_output_def ($3);
651                 $$ =o;
652
653                 THIS->lexer_->add_scope (o->scope_);
654         }
655         | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER  {
656                 Music_output_def * o =  unsmob_music_output_def ($3);
657                 $$ = o;
658
659                 THIS->lexer_->add_scope (o->scope_);
660         }
661         | music_output_def_body assignment  {
662
663         }
664         | music_output_def_body translator_spec_block   {
665                 $$->assign_translator ($2);
666         }
667         | music_output_def_body tempo_event  {
668                 /*
669                         junk this ? there already is tempo stuff in
670                         music.
671                 */
672                 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
673                 Duration *d = unsmob_duration ($2->get_mus_property ("tempo-unit"));
674                 Midi_def * md = dynamic_cast<Midi_def*> ($$);
675                 if (md)
676                         md->set_tempo (d->get_length (), m);
677         }
678         | music_output_def_body error {
679
680         }
681         ;
682
683 tempo_event:
684         TEMPO steno_duration '=' bare_unsigned  {
685                 $$ = MY_MAKE_MUSIC("TempoEvent");
686                 $$->set_mus_property ("tempo-unit", $2);
687                 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
688         }
689         ;
690
691 /*
692 The representation of a  list is the
693
694   (LIST . LAST-CONS)
695
696  to have  efficient append.
697 */
698 Music_list:
699         /* empty */ {
700                 $$ = scm_cons (SCM_EOL, SCM_EOL);
701         }
702         | Music_list Music {
703                 SCM s = $$;
704                 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
705                 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
706                 if (gh_pair_p (ly_cdr (s)))
707                         gh_set_cdr_x (ly_cdr (s), c); /* append */
708                 else
709                         gh_set_car_x (s, c); /* set first cons */
710                 gh_set_cdr_x (s, c) ;  /* remember last cell */ 
711         }
712         | Music_list error {
713         }
714         ;
715
716
717 Music:
718         Simple_music
719         | Composite_music
720         ;
721
722 Alternative_music:
723         /* empty */ {
724                 $$ = SCM_EOL;
725         }
726         | ALTERNATIVE '{' Music_list '}' {
727                 $$ = $3;
728         }
729         ;
730
731 Repeated_music:
732         REPEAT string bare_unsigned Music Alternative_music
733         {
734                 Music *beg = $4;
735                 int times = $3;
736                 SCM alts = gh_pair_p ($5) ? gh_car ($5) : SCM_EOL;
737                 if (times < scm_ilength (alts)) {
738                   unsmob_music (gh_car (alts))
739                     ->origin ()->warning (
740                     _("More alternatives than repeats.  Junking excess alternatives."));
741                   alts = ly_truncate_list (times, alts);
742                 }
743
744
745                 static SCM proc;
746                 if (!proc)
747                         proc = scm_c_eval_string ("make-repeated-music");
748
749                 SCM mus = scm_call_1 (proc, $2);
750                 scm_gc_protect_object (mus); // UGH. 
751                 Music *r =unsmob_music (mus);
752                 if (beg)
753                         {
754                         r-> set_mus_property ("element", beg->self_scm ());
755                         scm_gc_unprotect_object (beg->self_scm ());
756                         }
757                 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
758
759                 r-> set_mus_property ("elements",alts);
760                 if (gh_equal_p ($2, scm_makfrom0str ("tremolo")))
761                 {
762                 /*
763                 we can not get durations and other stuff correct down the line, so we have to
764                 add to the duration log here.
765                 */
766                         SCM func = scm_primitive_eval (ly_symbol2scm ("shift-duration-log"));
767                         if (($3 % 3) == 0)
768                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3*2/3)),gh_int2scm(1));
769                         else
770                           gh_call3 (func, r->self_scm (), gh_int2scm(-intlog2 ($3)), gh_int2scm(0));
771                 }
772                 r->set_spot (*$4->origin ());
773
774                 $$ = r;
775         }
776         ;
777
778 Sequential_music:
779         SEQUENTIAL '{' Music_list '}'           {
780                 $$ = MY_MAKE_MUSIC("SequentialMusic");
781                 $$->set_mus_property ("elements", ly_car ($3));
782                 $$->set_spot(THIS->here_input());
783         }
784         | '{' Music_list '}'            {
785                 $$ = MY_MAKE_MUSIC("SequentialMusic");
786                 $$->set_mus_property ("elements", ly_car ($2));
787                 $$->set_spot(THIS->here_input());
788         }
789         ;
790
791 Simultaneous_music:
792         SIMULTANEOUS '{' Music_list '}'{
793                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
794                 $$->set_mus_property ("elements", ly_car ($3));
795                 $$->set_spot(THIS->here_input());
796
797         }
798         | '<' Music_list '>'    {
799                 $$ = MY_MAKE_MUSIC("SimultaneousMusic");
800                 $$->set_mus_property ("elements", ly_car ($2));
801                 $$->set_spot(THIS->here_input());
802         }
803         ;
804
805 Simple_music:
806         event_chord             { $$ = $1; }
807         | APPLYCONTEXT embedded_scm {
808                 if (!gh_procedure_p ($2))
809                         THIS->parser_error (_ ("\applycontext takes function argument"));
810                 $$ = MY_MAKE_MUSIC ("ApplyContext");
811                 $$->set_mus_property ("procedure", $2);
812                 $$->set_spot (THIS->here_input());
813         }
814         | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm     {
815                 SCM pred = $2;
816                 if (!gh_symbol_p ($3))
817                 {
818                         THIS->parser_error (_ ("Second argument must be a symbol")); 
819                 }
820                 /* Should check # args */
821                 if (!gh_procedure_p (pred))
822                 {
823                         THIS->parser_error (_ ("First argument must be a procedure taking one argument"));
824                 }
825
826                 Music*m = MY_MAKE_MUSIC("OutputPropertySetMusic");
827                 m->set_mus_property ("predicate", pred);
828                 m->set_mus_property ("grob-property", $3);
829                 m->set_mus_property ("grob-value",  $5);
830
831                 $$ = m;
832         }
833         | MUSIC_IDENTIFIER {
834                 $$ = unsmob_music ($1);
835         }
836         | property_def
837         | translator_change
838         ;
839
840
841 Composite_music:
842         CONTEXT STRING Music    {
843                 Music*csm =MY_MAKE_MUSIC("ContextSpeccedMusic");
844
845                 csm->set_mus_property ("element", $3->self_scm ());
846                 scm_gc_unprotect_object ($3->self_scm ());
847
848                 csm->set_mus_property ("context-type",$2);
849                 csm->set_mus_property ("context-id", scm_makfrom0str (""));
850
851                 $$ = csm;
852         }
853         | AUTOCHANGE STRING Music       {
854         Music*chm = MY_MAKE_MUSIC("AutoChangeMusic");
855                 chm->set_mus_property ("element", $3->self_scm ());
856                 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_proc);
857
858                 scm_gc_unprotect_object ($3->self_scm ());
859                 chm->set_mus_property ("what", $2); 
860
861                 $$ = chm;
862                 chm->set_spot (*$3->origin ());
863         }
864         | GRACE Music {
865 #if 1
866         /*
867                 The other version is for easier debugging  of
868                 Sequential_music_iterator in combination with grace notes.
869         */
870
871                 SCM start = THIS->lexer_->lookup_identifier ("startGraceMusic");
872                 SCM stop = THIS->lexer_->lookup_identifier ("stopGraceMusic");
873                 Music *startm = unsmob_music (start);
874                 Music *stopm = unsmob_music (stop);
875
876                 SCM ms = SCM_EOL;
877                 if (stopm) {
878                         stopm = stopm->clone ();
879                         ms = scm_cons (stopm->self_scm (), ms);
880                         scm_gc_unprotect_object (stopm->self_scm ());
881                 }
882                 ms = scm_cons ($2->self_scm (), ms);
883                 scm_gc_unprotect_object ($2->self_scm());
884                 if (startm) {
885                         startm = startm->clone ();
886                         ms = scm_cons (startm->self_scm () , ms);
887                         scm_gc_unprotect_object (startm->self_scm ());
888                 }
889
890         
891                 Music* seq = MY_MAKE_MUSIC("SequentialMusic");
892                 seq->set_mus_property ("elements", ms);
893
894                 
895                 $$ = MY_MAKE_MUSIC("GraceMusic");
896                 $$->set_mus_property ("element", seq->self_scm ());
897                 scm_gc_unprotect_object (seq->self_scm ());
898 #else
899                 $$ = MY_MAKE_MUSIC("GraceMusic");
900                 $$->set_mus_property ("element", $2->self_scm ());
901                 scm_gc_unprotect_object ($2->self_scm ());
902 #endif
903         }
904         | CONTEXT string '=' string Music {
905                 Music * csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
906
907                 csm->set_mus_property ("element", $5->self_scm ());
908                 scm_gc_unprotect_object ($5->self_scm ());
909
910                 csm->set_mus_property ("context-type", $2);
911                 csm->set_mus_property ("context-id", $4);
912
913                 $$ = csm;
914         }
915         | TIMES {
916                 THIS->push_spot ();
917         }
918         /* CONTINUED */ 
919                 fraction Music  
920
921         {
922                 int n = gh_scm2int (ly_car ($3)); int d = gh_scm2int (ly_cdr ($3));
923                 Music *mp = $4;
924         $$= MY_MAKE_MUSIC("TimeScaledMusic");
925                 $$->set_spot (THIS->pop_spot ());
926
927
928                 $$->set_mus_property ("element", mp->self_scm ());
929                 scm_gc_unprotect_object (mp->self_scm ());
930                 $$->set_mus_property ("numerator", gh_int2scm (n));
931                 $$->set_mus_property ("denominator", gh_int2scm (d));
932                 $$->compress (Moment (Rational (n,d)));
933
934         }
935         | Repeated_music                { $$ = $1; }
936         | Simultaneous_music            { $$ = $1; }
937         | Sequential_music              { $$ = $1; }
938         | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
939                 $$ = MY_MAKE_MUSIC("TransposedMusic");
940                 Music *p = $4;
941                 Pitch from = *unsmob_pitch ($2);
942                 Pitch to = *unsmob_pitch ($3);
943
944                 p->transpose (interval (from, to));
945                 $$->set_mus_property ("element", p->self_scm ());
946                 scm_gc_unprotect_object (p->self_scm ());
947         }
948         | APPLY embedded_scm Music  {
949                 SCM ret = gh_call1 ($2, $3->self_scm ());
950                 Music *m = unsmob_music (ret);
951                 if (!m) {
952                         THIS->parser_error ("\\apply must return a Music");
953                         m = MY_MAKE_MUSIC("Music");
954                         }
955                 $$ = m;
956         }
957         | NOTES
958                 { THIS->lexer_->push_note_state (); }
959         Music
960                 { $$ = $3;
961                   THIS->lexer_->pop_state ();
962                 }
963         | FIGURES
964                 { THIS->lexer_->push_figuredbass_state (); }
965         Music
966                 {
967                   Music * chm = MY_MAKE_MUSIC("UntransposableMusic");
968                   chm->set_mus_property ("element", $3->self_scm ());
969                   $$ = chm;
970                   scm_gc_unprotect_object ($3->self_scm());
971
972                   THIS->lexer_->pop_state ();
973         }
974         | CHORDS
975                 { THIS->lexer_->push_chord_state (); }
976         Music
977                 {
978                   Music * chm = MY_MAKE_MUSIC("UnrelativableMusic");
979                   chm->set_mus_property ("element", $3->self_scm ());
980                   scm_gc_unprotect_object ($3->self_scm());
981                   $$ = chm;
982
983                   THIS->lexer_->pop_state ();
984         }
985         | LYRICS
986                 { THIS->lexer_->push_lyric_state (); }
987         Music
988                 {
989                   $$ = $3;
990                   THIS->lexer_->pop_state ();
991         }
992         | relative_music        { $$ = $1; }
993         | re_rhythmed_music     { $$ = $1; } 
994         | part_combined_music   { $$ = $1; } 
995         ;
996
997 relative_music:
998         RELATIVE absolute_pitch Music {
999                 Music * p = $3;
1000                 Pitch pit = *unsmob_pitch ($2);
1001                 $$ = MY_MAKE_MUSIC("RelativeOctaveMusic");
1002
1003                 $$->set_mus_property ("element", p->self_scm ());
1004                 scm_gc_unprotect_object (p->self_scm ());
1005
1006                 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
1007
1008         }
1009         ;
1010
1011 re_rhythmed_music:
1012         ADDLYRICS Music Music {
1013         Music*l =MY_MAKE_MUSIC("LyricCombineMusic");
1014           l->set_mus_property ("elements", gh_list ($2->self_scm (), $3->self_scm (), SCM_UNDEFINED));
1015           scm_gc_unprotect_object ($3->self_scm ());
1016           scm_gc_unprotect_object ($2->self_scm ());
1017           $$ = l;
1018         }
1019         ;
1020
1021 part_combined_music:
1022         PARTCOMBINE STRING Music Music {
1023         Music * p= MY_MAKE_MUSIC("PartCombineMusic");
1024                 p->set_mus_property ("what", $2);
1025                 p->set_mus_property ("elements", gh_list ($3->self_scm (),$4->self_scm (), SCM_UNDEFINED));  
1026
1027                 scm_gc_unprotect_object ($3->self_scm ());
1028                 scm_gc_unprotect_object ($4->self_scm ());  
1029
1030                 $$ = p;
1031         }
1032         ;
1033
1034 translator_change:
1035         TRANSLATOR STRING '=' STRING  {
1036                 Music*t= MY_MAKE_MUSIC("TranslatorChange");
1037                 t-> set_mus_property ("change-to-type", $2);
1038                 t-> set_mus_property ("change-to-id", $4);
1039
1040                 $$ = t;
1041                 $$->set_spot (THIS->here_input ());
1042         }
1043         ;
1044
1045 property_def:
1046         simple_property_def
1047         | ONCE simple_property_def {
1048                 $$ = $2;
1049                 SCM e = $2->get_mus_property ("element");
1050                 unsmob_music (e)->set_mus_property ("once", SCM_BOOL_T);
1051         }
1052         ;
1053
1054 simple_property_def:
1055         PROPERTY STRING '.' STRING '='  scalar {
1056                 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
1057                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1058
1059                 csm->set_mus_property ("element", t->self_scm ());
1060                 scm_gc_unprotect_object (t->self_scm ());
1061
1062                 $$ = csm;
1063                 $$->set_spot (THIS->here_input ());
1064
1065                 csm-> set_mus_property ("context-type", $2);
1066         }
1067         | PROPERTY STRING '.' STRING UNSET {
1068                 
1069                 Music *t = MY_MAKE_MUSIC("PropertyUnset");
1070                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1071
1072                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1073                 csm->set_mus_property ("element", t->self_scm ());
1074                 scm_gc_unprotect_object (t->self_scm ());
1075
1076                 $$ = csm;
1077                 $$->set_spot (THIS->here_input ());
1078
1079                 csm-> set_mus_property ("context-type", $2);
1080         }
1081         | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
1082                 bool autobeam
1083                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1084                 bool itc = internal_type_checking_global_b;
1085                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1086                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1087                 t->set_mus_property ("pop-first", SCM_BOOL_T);
1088                 if (autobeam)
1089                         internal_type_checking_global_b = false;
1090                 t->set_mus_property ("grob-property", $6);
1091                 if (autobeam)
1092                         internal_type_checking_global_b = itc;
1093                 t->set_mus_property ("grob-value", $8);
1094
1095                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1096                 csm->set_mus_property ("element", t->self_scm ());
1097                 scm_gc_unprotect_object (t->self_scm ());
1098                 $$ = csm;
1099                 $$->set_spot (THIS->here_input ());
1100
1101                 csm-> set_mus_property ("context-type", $2);
1102         }
1103         | PROPERTY STRING '.' STRING OVERRIDE
1104                 embedded_scm '=' embedded_scm
1105         {
1106                 /*
1107                         UGH UGH UGH UGH.
1108                 */
1109                 bool autobeam
1110                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1111                 bool itc = internal_type_checking_global_b;
1112
1113                 Music *t = MY_MAKE_MUSIC("OverrideProperty");
1114                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1115                 if (autobeam)
1116                         internal_type_checking_global_b = false;
1117                 t->set_mus_property ("grob-property", $6);
1118                 t->set_mus_property ("grob-value", $8);
1119                 if (autobeam)
1120                         internal_type_checking_global_b = itc;
1121
1122                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1123                 csm->set_mus_property ("element", t->self_scm ());
1124                 scm_gc_unprotect_object (t->self_scm ());
1125
1126                 $$ = csm;
1127                 $$->set_spot (THIS->here_input ());
1128
1129                 csm-> set_mus_property ("context-type", $2);
1130
1131         }
1132         | PROPERTY STRING '.' STRING REVERT embedded_scm {
1133                 Music *t = MY_MAKE_MUSIC("RevertProperty");
1134                 bool autobeam
1135                   = gh_equal_p ($4, scm_makfrom0str ("autoBeamSettings"));
1136                 bool itc = internal_type_checking_global_b;
1137
1138                 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1139                 if (autobeam)
1140                         internal_type_checking_global_b = false;
1141                 t->set_mus_property ("grob-property", $6);
1142                 if (autobeam)
1143                         internal_type_checking_global_b = itc;
1144         
1145                 Music *csm = MY_MAKE_MUSIC("ContextSpeccedMusic");
1146                 csm->set_mus_property ("element", t->self_scm ());
1147                 scm_gc_unprotect_object (t->self_scm ());
1148
1149                 $$ = csm;
1150                 $$->set_spot (THIS->here_input ());
1151
1152                 csm-> set_mus_property ("context-type", $2);
1153         }
1154         ;
1155
1156
1157 scalar:
1158         string          { $$ = $1; }
1159         | bare_int      { $$ = gh_int2scm ($1); }
1160         | embedded_scm  { $$ = $1; }
1161         | full_markup {  $$ = $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         CHORD_OPEN markup_list_body CHORD_CLOSE { $$ = 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 }