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