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