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