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