1 %{ // -*-Fundamental-*-
4 parser.yy -- Bison/C++ parser for lilypond
6 source file of the GNU LilyPond music typesetter
8 (c) 1997--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 Jan Nieuwenhuizen <janneke@gnu.org>
14 #include "translator-def.hh"
15 #include "lily-guile.hh"
16 #include "change-iterator.hh"
18 #include "my-lily-lexer.hh"
19 #include "paper-def.hh"
20 #include "midi-def.hh"
22 #include "file-path.hh"
24 #include "dimensions.hh"
25 #include "command-request.hh"
26 #include "musical-request.hh"
27 #include "my-lily-parser.hh"
28 #include "context-specced-music.hh"
30 #include "music-list.hh"
31 #include "output-property-music-iterator.hh"
32 #include "property-iterator.hh"
33 #include "file-results.hh"
36 #include "relative-music.hh"
37 #include "lyric-combine-music.hh"
38 #include "transposed-music.hh"
39 #include "time-scaled-music.hh"
40 #include "repeated-music.hh"
41 #include "lilypond-input-version.hh"
42 #include "grace-music.hh"
43 #include "part-combine-music.hh"
44 #include "scm-hash.hh"
45 #include "auto-change-iterator.hh"
46 #include "un-relativable-music.hh"
52 regular_identifier_b (SCM id)
54 String str = ly_scm2string (id);
55 char const *s = str.ch_C() ;
60 v = v && isalpha (*s);
70 return t && t == 1 << intlog2 (t);
75 set_music_properties (Music *p, SCM a)
77 for (SCM k = a; gh_pair_p (k); k = gh_cdr (k))
79 p->set_mus_property (gh_caar (k), gh_cdar (k));
85 Lilypond_version oldest_version ("1.3.59");
88 print_lilypond_versions (ostream &os)
90 os << _f ("Oldest supported input version: %s", oldest_version.str ())
95 // needed for bison.simple's malloc () and free ()
102 #define YYERROR_VERBOSE 1
104 #define YYPARSE_PARAM my_lily_parser_l
105 #define YYLEX_PARAM my_lily_parser_l
107 ((My_lily_parser *) my_lily_parser_l)
109 #define yyerror THIS->parser_error
110 #define ARRAY_SIZE(a,s) if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
117 Link_array<Request> *reqvec;
119 String *string; // needed by the lexer as temporary scratch area.
123 Scheme_hash_table *scmhash;
124 Music_output_def * outputdef;
128 /* We use SCMs to do strings, because it saves us the trouble of
129 deleting them. Let's hope that a stack overflow doesnt trigger a move
130 of the parse stack onto the heap. */
140 yylex (YYSTYPE *s, void * v_l)
142 My_lily_parser *pars_l = (My_lily_parser*) v_l;
143 My_lily_lexer * lex_l = pars_l->lexer_p_;
145 lex_l->lexval_l = (void*) s;
146 return lex_l->yylex ();
154 /* tokens which are not keywords */
164 %token CHORDMODIFIERS
172 %token ELEMENTDESCRIPTIONS
188 %token MULTI_MEASURE_REST
200 %token OVERRIDE SET REVERT
213 %token COMMANDSPANREQUEST
215 %token OUTPUTPROPERTY
225 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
226 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
228 %type <i> exclamations questions dots
230 %token <scm> NOTENAME_PITCH
231 %token <scm> TONICNAME_PITCH
232 %token <scm> CHORDMODIFIER_PITCH
233 %token <scm> DURATION_IDENTIFIER
234 %token <id> IDENTIFIER
237 %token <scm> SCORE_IDENTIFIER
238 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
240 %token <scm> NUMBER_IDENTIFIER
241 %token <scm> REQUEST_IDENTIFIER
242 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
243 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
244 %token <scm> RESTNAME
250 %type <outputdef> output_def
251 %type <scmhash> lilypond_header lilypond_header_body
252 %type <request> open_request_parens close_request_parens open_request close_request
253 %type <request> request_with_dir request_that_take_dir verbose_request
254 %type <i> sub_quotes sup_quotes
255 %type <music> simple_element request_chord command_element Simple_music Composite_music
256 %type <music> Alternative_music Repeated_music
257 %type <i> tremolo_type
258 %type <i> bare_int bare_unsigned
261 %type <scm> identifier_init
263 %type <scm> steno_duration optional_notemode_duration multiplied_duration
264 %type <scm> explicit_duration
266 %type <reqvec> pre_requests post_requests
267 %type <request> gen_text_def
268 %type <scm> steno_pitch pitch absolute_pitch
269 %type <scm> explicit_pitch steno_tonic_pitch
271 %type <scm> chord_additions chord_subtractions chord_notes chord_step
273 %type <scm> chord_note chord_inversion chord_bass
274 %type <scm> duration_length
276 %type <scm> embedded_scm scalar
277 %type <music> Music Sequential_music Simultaneous_music Music_sequence
278 %type <music> relative_music re_rhythmed_music part_combined_music
279 %type <music> property_def translator_change
280 %type <scm> Music_list
281 %type <outputdef> music_output_def_body
282 %type <request> shorthand_command_req
283 %type <request> post_request
284 %type <music> command_req verbose_command_req
285 %type <request> extender_req
286 %type <request> hyphen_req
287 %type <scm> string bare_number number_expression
289 %type <score> score_block score_body
291 %type <scm> translator_spec_block translator_spec_body
292 %type <tempo> tempo_request
293 %type <scm> notenames_body notenames_block chordmodifiers_block
294 %type <scm> script_abbreviation
304 lilypond: /* empty */
305 | lilypond toplevel_expression {}
306 | lilypond assignment { }
308 THIS->error_level_i_ = 1;
309 //THIS->parser_error (_ ("ly invalid"));
312 THIS->error_level_i_ = 1;
313 //THIS->parser_error (_ ("ly invalid"));
319 THIS->lexer_p_->pitchname_tab_ = $1;
321 | chordmodifiers_block {
322 THIS->lexer_p_->chordmodifier_tab_ = $1;
326 scm_unprotect_object (global_header_p->self_scm ());
327 global_header_p = $1;
330 score_global_array.push ($1);
334 if (dynamic_cast<Paper_def*> ($1))
335 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
336 else if (dynamic_cast<Midi_def*> ($1))
337 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
350 chordmodifiers_block:
351 CHORDMODIFIERS notenames_body { $$ = $2; }
356 PITCHNAMES notenames_body { $$ = $2; }
363 int i = scm_ilength ($1);
365 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
366 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
367 SCM pt = gh_cdar (s);
368 if (!unsmob_pitch (pt))
369 THIS->parser_error ("Need pitch object.");
371 scm_hashq_set_x (tab, gh_caar (s), pt);
378 lilypond_header_body:
380 $$ = new Scheme_hash_table;
382 Scope *sc = new Scope ($$);
383 THIS->lexer_p_-> scope_l_arr_.push (sc);
385 | lilypond_header_body assignment {
391 HEADER '{' lilypond_header_body '}' {
393 delete THIS->lexer_p_-> scope_l_arr_.pop ();
403 THIS->remember_spot ();
405 /* cont */ '=' identifier_init {
406 if (! regular_identifier_b ($1))
407 THIS->parser_error (_ ("Identifier should have alphabetic characters only"));
409 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
412 TODO: devise standard for protection in parser.
414 The parser stack lives on the C-stack, which means that
415 all objects can be unprotected as soon as they're here.
419 Should find generic way of associating input with objects.
429 $$ = $1->self_scm ();
430 scm_unprotect_object ($$);
433 $$ = $1->self_scm ();
434 scm_unprotect_object ($$);
436 | translator_spec_block {
440 $$ = $1->self_scm ();
441 scm_unprotect_object ($$);
444 $$ = $1->self_scm ();
445 scm_unprotect_object ($$);
447 | explicit_duration {
450 | number_expression {
461 translator_spec_block:
462 TRANSLATOR '{' translator_spec_body '}'
468 translator_spec_body:
469 TRANSLATOR_IDENTIFIER {
470 $$ = unsmob_translator_def ($1)->clone_scm ();
471 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
474 $$ = Translator_def::make_scm ();
475 Translator_def*td = unsmob_translator_def ($$);
476 td->translator_group_type_ = $2;
477 td->set_spot (THIS->here_input ());
479 | translator_spec_body STRING '=' embedded_scm {
480 unsmob_translator_def ($$)->add_property_assign ($2, $4);
482 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
483 unsmob_translator_def ($$)
484 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
486 | translator_spec_body STRING REVERT embedded_scm {
487 unsmob_translator_def ($$)->add_pop_property (
488 scm_string_to_symbol ($2), $4);
490 | translator_spec_body NAME STRING {
491 unsmob_translator_def ($$)->type_name_ = $3;
493 | translator_spec_body CONSISTS STRING {
494 unsmob_translator_def ($$)->add_element ($3);
496 | translator_spec_body ALIAS STRING {
497 Translator_def*td = unsmob_translator_def ($$);
498 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
500 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
501 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
502 unsmob_translator_def ($$)
503 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
506 | translator_spec_body CONSISTSEND STRING {
507 unsmob_translator_def ($$)->add_last_element ( $3);
509 | translator_spec_body ACCEPTS STRING {
510 unsmob_translator_def ($$)->set_acceptor ($3,true);
512 | translator_spec_body DENIES STRING {
513 unsmob_translator_def ($$)->set_acceptor ($3,false);
515 | translator_spec_body REMOVE STRING {
516 unsmob_translator_def ($$)->remove_element ($3);
525 THIS->remember_spot ();
527 /*cont*/ '{' score_body '}' {
530 if (!$$->def_p_arr_.size ())
532 Music_output_def *id =
533 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
534 $$->add_output (id ? id->clone () : new Paper_def );
543 $$->set_spot (THIS->here_input ());
544 SCM m = $1->self_scm ();
545 scm_unprotect_object (m);
549 $$ = new Score (*unsmob_score ($1));
550 $$->set_spot (THIS->here_input ());
552 | score_body lilypond_header {
553 scm_unprotect_object ($2->self_scm ());
556 | score_body output_def {
569 music_output_def_body '}' {
571 THIS-> lexer_p_-> scope_l_arr_.pop ();
575 music_output_def_body:
577 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
582 p = dynamic_cast<Midi_def*> (id->clone ());
587 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
590 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
593 p = dynamic_cast<Paper_def*> (id->clone ());
596 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
599 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
600 Music_output_def *p = unsmob_music_output_def ($3);
602 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
605 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
606 Music_output_def *p = unsmob_music_output_def ($3);
609 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
612 | music_output_def_body assignment {
615 | music_output_def_body translator_spec_block {
616 $$->assign_translator ($2);
618 | music_output_def_body STYLESHEET embedded_scm {
619 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
621 | music_output_def_body tempo_request {
623 junk this ? there already is tempo stuff in
626 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
627 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
628 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
630 | music_output_def_body error {
636 TEMPO steno_duration '=' bare_unsigned {
638 $$->set_mus_property ("duration", $2);
639 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
643 Music_list: /* empty */ {
644 $$ = gh_cons (SCM_EOL, SCM_EOL);
648 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
649 scm_unprotect_object ($2->self_scm ()); /* UGH */
650 if (gh_pair_p (gh_cdr (s)))
651 gh_set_cdr_x (gh_cdr (s), c); /* append */
653 gh_set_car_x (s, c); /* set first cons */
654 gh_set_cdr_x (s, c) ; /* remember last cell */
670 | ALTERNATIVE Music_sequence {
672 $2->set_spot (THIS->here_input ());
680 REPEAT string bare_unsigned Music Alternative_music
682 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
683 if (alts && $3 < alts->length_i ())
684 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
688 Repeated_music * r = new Repeated_music (SCM_EOL);
692 r-> set_mus_property ("body", beg->self_scm ());
693 scm_unprotect_object (beg->self_scm ());
695 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
699 alts->truncate (times);
700 r-> set_mus_property ("alternatives", alts->self_scm ());
701 scm_unprotect_object (alts->self_scm ());
703 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
704 SCM result = gh_call1 (func, $2);
706 set_music_properties (r, result);
708 r->set_spot (*$4->origin ());
713 Music_sequence: '{' Music_list '}' {
714 $$ = new Music_sequence (SCM_EOL);
715 $$->set_mus_property ("elements", gh_car ($2));
720 SEQUENTIAL '{' Music_list '}' {
721 $$ = new Sequential_music (SCM_EOL);
722 $$->set_mus_property ("elements", gh_car ($3));
724 | '{' Music_list '}' {
725 $$ = new Sequential_music (SCM_EOL);
726 $$->set_mus_property ("elements", gh_car ($2));
731 SIMULTANEOUS '{' Music_list '}'{
732 $$ = new Simultaneous_music (SCM_EOL);
733 $$->set_mus_property ("elements", gh_car ($3));
736 | '<' Music_list '>' {
737 $$ = new Simultaneous_music (SCM_EOL);
738 $$->set_mus_property ("elements", gh_car ($2));
743 request_chord { $$ = $1; }
744 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
746 if (!gh_symbol_p ($3))
748 THIS->parser_error (_ ("Second argument must be a symbol"));
750 /*hould check # args */
751 if (!gh_procedure_p (pred))
753 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
756 Music *m = new Music (SCM_EOL);
757 m->set_mus_property ("predicate", pred);
758 m->set_mus_property ("symbol", $3);
759 m->set_mus_property ("value", $5);
760 m->set_mus_property ("iterator-ctor",
761 Output_property_music_iterator::constructor_cxx_function);
766 $$ = unsmob_music ($1)->clone ();
774 CONTEXT STRING Music {
775 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
776 csm->set_mus_property ("element", $3->self_scm ());
777 scm_unprotect_object ($3->self_scm ());
779 csm->set_mus_property ("context-type",$2);
780 csm->set_mus_property ("context-id", ly_str02scm (""));
784 | AUTOCHANGE STRING Music {
785 Music * chm = new Music_wrapper (SCM_EOL);
786 chm->set_mus_property ("element", $3->self_scm ());
787 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
789 scm_unprotect_object ($3->self_scm ());
790 chm->set_mus_property ("what", $2);
793 chm->set_spot (*$3->origin ());
796 $$ = new Grace_music (SCM_EOL);
797 $$->set_mus_property ("element", $2->self_scm ());
798 scm_unprotect_object ($2->self_scm ());
801 | CONTEXT string '=' string Music {
802 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
803 csm->set_mus_property ("element", $5->self_scm ());
804 scm_unprotect_object ($5->self_scm ());
806 csm->set_mus_property ("context-type", $2);
807 csm->set_mus_property ("context-id", $4);
812 THIS->remember_spot ();
815 bare_unsigned '/' bare_unsigned Music
818 int n = $3; int d = $5;
820 $$ = new Time_scaled_music (SCM_EOL);
821 $$->set_spot (THIS->pop_spot ());
824 $$->set_mus_property ("element", mp->self_scm ());
825 scm_unprotect_object (mp->self_scm ());
826 $$->set_mus_property ("numerator", gh_int2scm (n));
827 $$->set_mus_property ("denominator", gh_int2scm (d));
828 $$->compress (Moment (n,d));
831 | Repeated_music { $$ = $1; }
832 | Simultaneous_music { $$ = $1; }
833 | Sequential_music { $$ = $1; }
834 | TRANSPOSE pitch Music {
835 $$ = new Transposed_music (SCM_EOL);
837 Pitch pit = *unsmob_pitch ($2);
840 $$->set_mus_property ("element", p->self_scm ());
841 scm_unprotect_object (p->self_scm ());
843 | TRANSPOSE steno_tonic_pitch Music {
844 $$ = new Transposed_music (SCM_EOL);
846 Pitch pit = *unsmob_pitch ($2);
849 $$->set_mus_property ("element", p->self_scm ());
850 scm_unprotect_object (p->self_scm ());
853 | APPLY embedded_scm Music {
854 SCM ret = gh_call1 ($2, $3->self_scm ());
855 Music *m = unsmob_music (ret);
857 THIS->parser_error ("\\apply must return a Music");
858 m = new Music (SCM_EOL);
863 { THIS->lexer_p_->push_note_state (); }
866 THIS->lexer_p_->pop_state ();
869 { THIS->lexer_p_->push_chord_state (); }
872 Music * chm = new Un_relativable_music ;
873 chm->set_mus_property ("element", $3->self_scm ());
876 THIS->lexer_p_->pop_state ();
879 { THIS->lexer_p_->push_lyric_state (); }
883 THIS->lexer_p_->pop_state ();
885 | relative_music { $$ = $1; }
886 | re_rhythmed_music { $$ = $1; }
887 | part_combined_music { $$ = $1; }
891 RELATIVE absolute_pitch Music {
893 Pitch pit = *unsmob_pitch ($2);
894 $$ = new Relative_octave_music (SCM_EOL);
896 $$->set_mus_property ("element", p->self_scm ());
897 scm_unprotect_object (p->self_scm ());
899 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
905 ADDLYRICS Music Music {
906 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
907 l->set_mus_property ("music", $2->self_scm ());
908 l->set_mus_property ("lyrics", $3->self_scm ());
909 scm_unprotect_object ($3->self_scm ());
910 scm_unprotect_object ($2->self_scm ());
916 PARTCOMBINE STRING Music Music {
917 Part_combine_music * p = new Part_combine_music (SCM_EOL);
919 p->set_mus_property ("what", $2);
920 p->set_mus_property ("one", $3->self_scm ());
921 p->set_mus_property ("two", $4->self_scm ());
923 scm_unprotect_object ($3->self_scm ());
924 scm_unprotect_object ($4->self_scm ());
932 TRANSLATOR STRING '=' STRING {
933 Music * t = new Music (SCM_EOL);
934 t->set_mus_property ("iterator-ctor",
935 Change_iterator::constructor_cxx_function);
936 t-> set_mus_property ("change-to-type", $2);
937 t-> set_mus_property ("change-to-id", $4);
940 $$->set_spot (THIS->here_input ());
945 PROPERTY STRING '.' STRING '=' scalar {
946 Music *t = new Music (SCM_EOL);
948 t->set_mus_property ("iterator-ctor",
949 Property_iterator::constructor_cxx_function);
950 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
951 t->set_mus_property ("value", $6);
953 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
955 csm->set_mus_property ("element", t->self_scm ());
956 scm_unprotect_object (t->self_scm ());
959 $$->set_spot (THIS->here_input ());
961 csm-> set_mus_property ("context-type", $2);
963 | PROPERTY STRING '.' STRING UNSET {
964 Music *t = new Music (SCM_EOL);
966 t->set_mus_property ("iterator-ctor",
967 Property_unset_iterator::constructor_cxx_function);
968 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
970 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
971 csm->set_mus_property ("element", t->self_scm ());
972 scm_unprotect_object (t->self_scm ());
975 $$->set_spot (THIS->here_input ());
977 csm-> set_mus_property ("context-type", $2);
979 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
980 Music *t = new Music (SCM_EOL);
981 t->set_mus_property ("iterator-ctor",
982 Push_property_iterator::constructor_cxx_function);
983 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
984 t->set_mus_property ("pop-first", SCM_BOOL_T);
985 t->set_mus_property ("grob-property", $6);
986 t->set_mus_property ("grob-value", $8);
987 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
988 csm->set_mus_property ("element", t->self_scm ());
989 scm_unprotect_object (t->self_scm ());
991 $$->set_spot (THIS->here_input ());
993 csm-> set_mus_property ("context-type", $2);
995 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
996 Music *t = new Music (SCM_EOL);
997 t->set_mus_property ("iterator-ctor",
998 Push_property_iterator::constructor_cxx_function);
999 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1000 t->set_mus_property ("grob-property", $6);
1001 t->set_mus_property ("grob-value", $8);
1002 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1003 csm->set_mus_property ("element", t->self_scm ());
1004 scm_unprotect_object (t->self_scm ());
1007 $$->set_spot (THIS->here_input ());
1009 csm-> set_mus_property ("context-type", $2);
1011 | PROPERTY STRING '.' STRING REVERT embedded_scm {
1012 Music *t = new Music (SCM_EOL);
1013 t->set_mus_property ("iterator-ctor",
1014 Pop_property_iterator::constructor_cxx_function);
1015 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1016 t->set_mus_property ("grob-property", $6);
1018 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1019 csm->set_mus_property ("element", t->self_scm ());
1020 scm_unprotect_object (t->self_scm ());
1023 $$->set_spot (THIS->here_input ());
1025 csm-> set_mus_property ("context-type", $2);
1031 | bare_int { $$ = gh_int2scm ($1); }
1032 | embedded_scm { $$ = $1; }
1037 pre_requests simple_element post_requests {
1038 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1040 for (int i=0; i < $1->size (); i++)
1041 l->append_music ($1->elem (i));
1042 for (int i=0; i < $3->size (); i++)
1043 l->append_music ($3->elem (i));
1046 programming_error ("Need Sequence to add music to");
1055 $$ = new Request_chord (SCM_EOL);
1056 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1057 $$-> set_spot (THIS->here_input ());
1058 $1-> set_spot (THIS->here_input ());
1061 Music *t = new Music (SCM_EOL);
1063 t->set_mus_property ("iterator-ctor",
1064 Property_iterator::constructor_cxx_function);
1065 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1066 t->set_mus_property ("value", $2);
1068 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1069 csm->set_mus_property ("element", t->self_scm ());
1070 scm_unprotect_object (t->self_scm ());
1073 $$->set_spot (THIS->here_input ());
1075 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1077 | PARTIAL duration_length {
1078 Music * p = new Music (SCM_EOL);
1079 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1080 p->set_mus_property ("iterator-ctor",
1081 Property_iterator::constructor_cxx_function);
1083 Moment m = - unsmob_duration ($2)->length_mom ();
1084 p->set_mus_property ("value", m.smobbed_copy ());
1086 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1087 sp->set_mus_property ("element", p->self_scm ());
1088 scm_unprotect_object (p->self_scm ());
1091 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1094 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1095 SCM result = gh_call1 (func, $2);
1098 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1099 Music * p = new Music (SCM_EOL);
1100 set_music_properties (p, gh_car (s));
1101 l = gh_cons (p->self_scm (), l);
1102 scm_unprotect_object (p->self_scm ());
1104 Sequential_music * seq = new Sequential_music (SCM_EOL);
1105 seq->set_mus_property ("elements", l);
1107 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1108 sp->set_mus_property ("element", seq->self_scm ());
1109 scm_unprotect_object (seq->self_scm ());
1112 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1114 | TIME_T bare_unsigned '/' bare_unsigned {
1115 Music * p = new Music (SCM_EOL);
1116 p->set_mus_property ("symbol",
1117 ly_symbol2scm ( "timeSignatureFraction"));
1118 p->set_mus_property ("iterator-ctor",
1119 Property_iterator::constructor_cxx_function);
1121 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1124 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1125 sp->set_mus_property ("element", p->self_scm ());
1126 scm_unprotect_object (p->self_scm ());
1131 TODO: should make alias TimingContext for Score
1134 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1139 shorthand_command_req { $$ = $1; }
1140 | verbose_command_req { $$ = $1; }
1143 shorthand_command_req:
1151 $$ = new Barcheck_req;
1157 Span_req*b= new Span_req;
1158 b->set_span_dir (START);
1159 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1163 Span_req*b= new Span_req;
1164 b->set_span_dir ( STOP);
1165 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1169 $$ = new Breathing_sign_req;
1174 verbose_command_req:
1175 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1176 Span_req * sp_p = new Span_req;
1177 sp_p-> set_span_dir ( Direction ($2));
1178 sp_p->set_mus_property ("span-type",$3);
1179 sp_p->set_spot (THIS->here_input ());
1183 Mark_req * m = new Mark_req;
1187 Mark_req *m = new Mark_req;
1188 m->set_mus_property ("label", $2);
1195 Break_req * b = new Break_req;
1197 if (!gh_number_p (s))
1200 b->set_mus_property ("penalty", s);
1201 b->set_spot (THIS->here_input ());
1204 | SKIP duration_length {
1205 Skip_req * skip_p = new Skip_req;
1206 skip_p->set_mus_property ("duration", $2);
1214 Key_change_req *key_p= new Key_change_req;
1217 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1218 Key_change_req *key_p= new Key_change_req;
1220 key_p->set_mus_property ("pitch-alist", $3);
1221 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1228 $$ = new Link_array<Request>;
1230 | post_requests post_request {
1231 $2->set_spot (THIS->here_input ());
1243 request_that_take_dir:
1246 | script_abbreviation {
1247 SCM s = THIS->lexer_p_->lookup_identifier ("dash" + ly_scm2string ($1));
1248 Articulation_req *a = new Articulation_req;
1249 if (gh_string_p (s))
1250 a->set_mus_property ("articulation-type", s);
1251 else THIS->parser_error (_ ("Expecting string as script definition"));
1257 script_dir request_that_take_dir {
1258 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1259 gs->set_direction (Direction ($1));
1261 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1267 REQUEST_IDENTIFIER {
1268 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1269 $$->set_spot (THIS->here_input ());
1271 | DYNAMICSCRIPT embedded_scm {
1273 TODO: junkme, use text-type == dynamic
1275 Text_script_req *d = new Text_script_req;
1276 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1277 d->set_mus_property ("text", $2);
1278 d->set_spot (THIS->here_input ());
1281 | SPANREQUEST bare_int STRING {
1282 Span_req * sp_p = new Span_req;
1283 sp_p->set_span_dir ( Direction ($2));
1284 sp_p->set_mus_property ("span-type", $3);
1285 sp_p->set_spot (THIS->here_input ());
1289 Tremolo_req* a = new Tremolo_req;
1290 a->set_spot (THIS->here_input ());
1291 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1295 Articulation_req * a = new Articulation_req;
1296 a->set_mus_property ("articulation-type", $2);
1297 a->set_spot (THIS->here_input ());
1301 duh, junk this syntax from the parser, if possible.
1304 Arpeggio_req *a = new Arpeggio_req;
1305 a->set_spot (THIS->here_input ());
1309 Glissando_req *g = new Glissando_req;
1310 g->set_spot /* No pun intended */ (THIS->here_input ());
1337 | NOTENAME_PITCH sup_quotes {
1338 Pitch p = *unsmob_pitch ($1);
1340 $$ = p.smobbed_copy ();
1342 | NOTENAME_PITCH sub_quotes {
1343 Pitch p =* unsmob_pitch ($1);
1346 $$ = p.smobbed_copy ();
1359 | TONICNAME_PITCH sup_quotes {
1360 Pitch p = *unsmob_pitch ($1);
1362 $$ = p.smobbed_copy ();
1364 | TONICNAME_PITCH sub_quotes {
1365 Pitch p =* unsmob_pitch ($1);
1368 $$ = p.smobbed_copy ();
1383 PITCH embedded_scm {
1385 if (!unsmob_pitch ($2)) {
1386 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1387 $$ = Pitch ().smobbed_copy ();
1393 DURATION embedded_scm {
1395 if (!unsmob_duration ($2))
1397 THIS->parser_error (_ ("Must have duration object"));
1398 $$ = Duration ().smobbed_copy ();
1405 if (!THIS->lexer_p_->lyric_state_b ())
1406 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1407 $$ = new Extender_req;
1413 if (!THIS->lexer_p_->lyric_state_b ())
1414 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1415 $$ = new Hyphen_req;
1420 close_request_parens {
1422 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1425 close_request_parens:
1427 Span_req* s= new Span_req;
1429 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1432 Span_req* s= new Span_req;
1434 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1437 Span_req*s =new Span_req;
1439 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1442 Span_req*s =new Span_req;
1444 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1450 open_request_parens {
1452 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1456 open_request_parens:
1458 Span_req *s = new Span_req;
1459 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1464 Span_req* s= new Span_req;
1466 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1469 Span_req* s= new Span_req;
1471 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1477 Text_script_req *t = new Text_script_req;
1478 t->set_mus_property ("text", $1);
1479 t->set_spot (THIS->here_input ());
1483 Text_script_req *t = new Text_script_req;
1484 t->set_mus_property ("text", $1);
1485 t->set_spot (THIS->here_input ());
1489 String ds = to_str ($1);
1490 Text_script_req* t = new Text_script_req;
1492 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1493 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1494 t->set_spot (THIS->here_input ());
1499 script_abbreviation:
1501 $$ = gh_str02scm ("Hat");
1504 $$ = gh_str02scm ("Plus");
1507 $$ = gh_str02scm ("Dash");
1510 $$ = gh_str02scm ("Bar");
1513 $$ = gh_str02scm ("Larger");
1516 $$ = gh_str02scm ("Dot");
1524 | '-' { $$ = CENTER; }
1529 $$ = new Link_array<Request>;
1531 | pre_requests open_request {
1543 multiplied_duration {
1546 | explicit_duration {
1551 optional_notemode_duration:
1553 $$ = THIS->default_duration_.smobbed_copy ();
1555 | multiplied_duration {
1558 | explicit_duration {
1564 bare_unsigned dots {
1566 if (!is_duration_b ($1))
1567 THIS->parser_error (_f ("not a duration: %d", $1));
1571 $$ = Duration (l, $2).smobbed_copy ();
1573 THIS->set_last_duration (unsmob_duration ($$));
1575 | DURATION_IDENTIFIER dots {
1576 Duration *d =unsmob_duration ($1);
1577 Duration k (d->duration_log (),d->dot_count () + $2);
1578 $$ = k.smobbed_copy ();
1580 THIS->set_last_duration (unsmob_duration ($$));
1587 multiplied_duration:
1591 | multiplied_duration '*' bare_unsigned {
1592 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1594 | multiplied_duration '/' bare_unsigned {
1595 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1613 | ':' bare_unsigned {
1614 if (!is_duration_b ($2))
1615 THIS->parser_error (_f ("not a duration: %d", $2));
1622 pitch exclamations questions optional_notemode_duration {
1623 if (!THIS->lexer_p_->note_state_b ())
1624 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1626 Note_req *n = new Note_req;
1628 n->set_mus_property ("pitch", $1);
1629 n->set_mus_property ("duration", $4);
1632 n->set_mus_property ("cautionary", SCM_BOOL_T);
1633 if ($2 % 2 || $3 % 2)
1634 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1636 Simultaneous_music*v = new Request_chord (SCM_EOL);
1637 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1640 FIXME: location is one off, since ptich & duration don't contain origin refs.
1642 v->set_spot (THIS->here_input ());
1643 n->set_spot (THIS->here_input ());
1647 | RESTNAME optional_notemode_duration {
1649 SCM e = SCM_UNDEFINED;
1650 if (ly_scm2string ($1) =="s")
1652 Skip_req * skip_p = new Skip_req;
1653 skip_p->set_mus_property ("duration" ,$2);
1655 skip_p->set_spot (THIS->here_input ());
1656 e = skip_p->self_scm ();
1660 Rest_req * rest_req_p = new Rest_req;
1661 rest_req_p->set_mus_property ("duration", $2);
1662 rest_req_p->set_spot (THIS->here_input ());
1663 e = rest_req_p->self_scm ();
1665 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1666 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1667 velt_p->set_spot (THIS->here_input ());
1672 | MULTI_MEASURE_REST optional_notemode_duration {
1673 Skip_req * sk = new Skip_req;
1674 sk->set_mus_property ("duration", $2);
1675 Span_req *sp1 = new Span_req;
1676 Span_req *sp2 = new Span_req;
1677 sp1-> set_span_dir ( START);
1678 sp2-> set_span_dir ( STOP);
1679 SCM r = ly_str02scm ("rest");
1680 sp1->set_mus_property ("span-type", r);
1681 sp2->set_mus_property ("span-type", r);
1683 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1684 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1685 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1686 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1687 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1688 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1690 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1692 $$ = new Sequential_music (SCM_EOL);
1693 $$->set_mus_property ("elements", ms);
1695 | STRING optional_notemode_duration {
1697 Lyric_req* lreq_p = new Lyric_req;
1698 lreq_p->set_mus_property ("text", $1);
1699 lreq_p->set_mus_property ("duration",$2);
1700 lreq_p->set_spot (THIS->here_input ());
1701 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1702 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1709 if (!THIS->lexer_p_->chord_state_b ())
1710 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1717 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1718 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1719 $$->set_spot (THIS->here_input ());
1726 | CHORD_COLON chord_notes {
1735 | chord_notes '.' chord_step {
1736 $$ = gh_append2 ($$, $3);
1744 | CHORD_CARET chord_notes {
1754 | '/' steno_tonic_pitch {
1763 | CHORD_BASS steno_tonic_pitch {
1770 $$ = gh_cons ($1, SCM_EOL);
1772 | CHORDMODIFIER_PITCH {
1773 $$ = gh_cons ($1, SCM_EOL);
1775 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1776 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1783 m.notename_i_ = ($1 - 1) % 7;
1784 m.octave_i_ = $1 > 7 ? 1 : 0;
1785 m.alteration_i_ = 0;
1787 $$ = m.smobbed_copy ();
1789 | bare_unsigned '+' {
1791 m.notename_i_ = ($1 - 1) % 7;
1792 m.octave_i_ = $1 > 7 ? 1 : 0;
1793 m.alteration_i_ = 1;
1796 $$ = m.smobbed_copy ();
1798 | bare_unsigned CHORD_MINUS {
1800 m.notename_i_ = ($1 - 1) % 7;
1801 m.octave_i_ = $1 > 7 ? 1 : 0;
1802 m.alteration_i_ = -1;
1804 $$ = m.smobbed_copy ();
1815 | '-' number_expression %prec UNARY_MINUS {
1816 $$ = scm_difference ($2, SCM_UNDEFINED);
1818 | number_expression '*' number_expression {
1819 $$ = scm_product ($1, $3);
1821 | number_expression '/' number_expression {
1822 $$ = scm_divide ($1, $3);
1824 | number_expression '+' number_expression {
1825 $$ = scm_sum ($1, $3);
1827 | number_expression '-' number_expression {
1828 $$ = scm_difference ($1, $3);
1830 | '(' number_expression ')' {
1837 $$ = gh_int2scm ($1);
1842 | NUMBER_IDENTIFIER {
1846 $$ = gh_double2scm (gh_scm2double ($1) CM );
1849 $$ = gh_double2scm (gh_scm2double ($1) PT);
1852 $$ = gh_double2scm (gh_scm2double ($1) INCH);
1855 $$ = gh_double2scm (gh_scm2double ($1) MM);
1858 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
1874 if (scm_integer_p ($1) == SCM_BOOL_T)
1876 int k = gh_scm2int ($1);
1880 THIS->parser_error (_ ("need integer number arg"));
1894 | STRING_IDENTIFIER {
1897 | string '+' string {
1898 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1905 | exclamations '!' { $$ ++; }
1910 | questions '?' { $$ ++; }
1917 My_lily_parser::set_yydebug (bool b)
1924 extern My_lily_parser * current_parser;
1927 My_lily_parser::do_yyparse ()
1930 current_parser = this;;
1931 yyparse ((void*)this);