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