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