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