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