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