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