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