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