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