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