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