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