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>
13 #include "translator-def.hh"
14 #include "lily-guile.hh"
15 #include "change-iterator.hh"
17 #include "my-lily-lexer.hh"
18 #include "paper-def.hh"
19 #include "midi-def.hh"
21 #include "file-path.hh"
23 #include "dimensions.hh"
24 #include "command-request.hh"
25 #include "musical-request.hh"
26 #include "my-lily-parser.hh"
27 #include "context-specced-music.hh"
29 #include "music-list.hh"
30 #include "output-property-music-iterator.hh"
31 #include "property-iterator.hh"
32 #include "file-results.hh"
35 #include "relative-music.hh"
36 #include "lyric-combine-music.hh"
37 #include "transposed-music.hh"
38 #include "time-scaled-music.hh"
39 #include "repeated-music.hh"
40 #include "lilypond-input-version.hh"
41 #include "grace-music.hh"
42 #include "part-combine-music.hh"
43 #include "scm-hash.hh"
44 #include "auto-change-iterator.hh"
45 #include "un-relativable-music.hh"
51 return t && t == 1 << intlog2 (t);
56 set_music_properties (Music *p, SCM a)
58 for (SCM k = a; gh_pair_p (k); k = gh_cdr (k))
60 p->set_mus_property (gh_caar (k), gh_cdar (k));
66 Lilypond_version oldest_version ("1.3.59");
69 print_lilypond_versions (ostream &os)
71 os << _f ("Oldest supported input version: %s", oldest_version.str ())
76 // needed for bison.simple's malloc () and free ()
83 #define YYERROR_VERBOSE 1
85 #define YYPARSE_PARAM my_lily_parser_l
86 #define YYLEX_PARAM my_lily_parser_l
88 ((My_lily_parser *) my_lily_parser_l)
90 #define yyerror THIS->parser_error
91 #define ARRAY_SIZE(a,s) if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
98 Link_array<Request> *reqvec;
103 Scheme_hash_table *scmhash;
105 Music_output_def * outputdef;
111 /* We use SCMs to do strings, because it saves us the trouble of
112 deleting them. Let's hope that a stack overflow doesnt trigger a move
113 of the parse stack onto the heap. */
123 yylex (YYSTYPE *s, void * v_l)
125 My_lily_parser *pars_l = (My_lily_parser*) v_l;
126 My_lily_lexer * lex_l = pars_l->lexer_p_;
128 lex_l->lexval_l = (void*) s;
129 return lex_l->yylex ();
137 /* tokens which are not keywords */
147 %token CHORDMODIFIERS
155 %token ELEMENTDESCRIPTIONS
171 %token MULTI_MEASURE_REST
182 %token OVERRIDE SET REVERT
195 %token COMMANDSPANREQUEST
197 %token OUTPUTPROPERTY
207 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
208 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
210 %type <i> exclamations questions dots
212 %token <scm> NOTENAME_PITCH
213 %token <scm> TONICNAME_PITCH
214 %token <scm> CHORDMODIFIER_PITCH
215 %token <scm> DURATION_IDENTIFIER
216 %token <id> IDENTIFIER
219 %token <scm> SCORE_IDENTIFIER
220 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
222 %token <scm> NUMBER_IDENTIFIER
223 %token <scm> REQUEST_IDENTIFIER
224 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
225 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
226 %token <scm> RESTNAME
232 %type <outputdef> output_def
233 %type <scmhash> lilypond_header lilypond_header_body
234 %type <request> open_request_parens close_request_parens open_request close_request
235 %type <request> request_with_dir request_that_take_dir verbose_request
236 %type <i> sub_quotes sup_quotes
237 %type <music> simple_element request_chord command_element Simple_music Composite_music
238 %type <music> Alternative_music Repeated_music
239 %type <i> tremolo_type
240 %type <i> bare_int bare_unsigned
243 %type <scm> identifier_init
245 %type <scm> steno_duration optional_notemode_duration
246 %type <scm> entered_notemode_duration explicit_duration
248 %type <reqvec> pre_requests post_requests
249 %type <request> gen_text_def
250 %type <scm> steno_pitch pitch absolute_pitch
251 %type <scm> explicit_pitch steno_tonic_pitch
253 %type <scm> chord_additions chord_subtractions chord_notes chord_step
255 %type <scm> chord_note chord_inversion chord_bass
256 %type <scm> duration_length
258 %type <scm> embedded_scm scalar
259 %type <music> Music Sequential_music Simultaneous_music Music_sequence
260 %type <music> relative_music re_rhythmed_music part_combined_music
261 %type <music> property_def translator_change
262 %type <scm> Music_list
263 %type <outputdef> music_output_def_body
264 %type <request> shorthand_command_req
265 %type <request> post_request
266 %type <music> command_req verbose_command_req
267 %type <request> extender_req
268 %type <request> hyphen_req
269 %type <scm> string bare_number number_expression
270 %type <score> score_block score_body
272 %type <scm> translator_spec_block translator_spec_body
273 %type <tempo> tempo_request
274 %type <scm> notenames_body notenames_block chordmodifiers_block
275 %type <scm> script_abbreviation
285 lilypond: /* empty */
286 | lilypond toplevel_expression {}
287 | lilypond assignment { }
289 THIS->error_level_i_ = 1;
290 //THIS->parser_error (_ ("ly invalid"));
293 THIS->error_level_i_ = 1;
294 //THIS->parser_error (_ ("ly invalid"));
300 THIS->lexer_p_->pitchname_tab_ = $1;
302 | chordmodifiers_block {
303 THIS->lexer_p_->chordmodifier_tab_ = $1;
307 scm_unprotect_object (global_header_p->self_scm ());
308 global_header_p = $1;
311 score_global_array.push ($1);
315 if (dynamic_cast<Paper_def*> ($1))
316 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
317 else if (dynamic_cast<Midi_def*> ($1))
318 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
331 chordmodifiers_block:
332 CHORDMODIFIERS notenames_body { $$ = $2; }
337 PITCHNAMES notenames_body { $$ = $2; }
344 int i = scm_ilength ($1);
346 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
347 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
348 SCM pt = gh_cdar (s);
349 if (!unsmob_pitch (pt))
350 THIS->parser_error ("Need pitch object.");
352 scm_hashq_set_x (tab, gh_caar (s), pt);
359 lilypond_header_body:
361 $$ = new Scheme_hash_table;
363 Scope *sc = new Scope ($$);
364 THIS->lexer_p_-> scope_l_arr_.push (sc);
366 | lilypond_header_body assignment semicolon {
372 HEADER '{' lilypond_header_body '}' {
374 delete THIS->lexer_p_-> scope_l_arr_.pop ();
384 THIS->remember_spot ();
386 /* cont */ '=' identifier_init {
387 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
390 TODO: devise standard for protection in parser.
392 The parser stack lives on the C-stack, which means that
393 all objects can be unprotected as soon as they're here.
397 Should find generic way of associating input with objects.
407 $$ = $1->self_scm ();
408 scm_unprotect_object ($$);
411 $$ = $1->self_scm ();
412 scm_unprotect_object ($$);
414 | translator_spec_block {
418 $$ = $1->self_scm ();
419 scm_unprotect_object ($$);
422 $$ = $1->self_scm ();
423 scm_unprotect_object ($$);
425 | explicit_duration {
428 | number_expression {
439 translator_spec_block:
440 TRANSLATOR '{' translator_spec_body '}'
446 translator_spec_body:
447 TRANSLATOR_IDENTIFIER {
448 $$ = unsmob_translator_def ($1)->clone_scm ();
449 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
451 | TYPE STRING semicolon {
452 $$ = Translator_def::make_scm ();
453 Translator_def*td = unsmob_translator_def ($$);
454 td->translator_group_type_ = $2;
455 td->set_spot (THIS->here_input ());
457 | translator_spec_body STRING '=' embedded_scm {
458 unsmob_translator_def ($$)->add_property_assign ($2, $4);
460 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
461 unsmob_translator_def ($$)
462 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
464 | translator_spec_body STRING REVERT embedded_scm {
465 unsmob_translator_def ($$)->add_pop_property (
466 scm_string_to_symbol ($2), $4);
468 | translator_spec_body STRING '=' identifier_init semicolon {
469 SCM v = gh_int2scm (0);
470 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
473 THIS->parser_error (_ ("Wrong type for property value"));
476 unsmob_translator_def ($$)->add_property_assign ($2, v);
478 | translator_spec_body NAME STRING semicolon {
479 unsmob_translator_def ($$)->type_name_ = $3;
481 | translator_spec_body CONSISTS STRING semicolon {
482 unsmob_translator_def ($$)->add_element ($3);
484 | translator_spec_body ALIAS STRING semicolon {
485 Translator_def*td = unsmob_translator_def ($$);
486 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
488 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
489 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
490 unsmob_translator_def ($$)
491 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
494 | translator_spec_body CONSISTSEND STRING semicolon {
495 unsmob_translator_def ($$)->add_last_element ( $3);
497 | translator_spec_body ACCEPTS STRING semicolon {
498 unsmob_translator_def ($$)->set_acceptor ($3,true);
500 | translator_spec_body DENIES STRING semicolon {
501 unsmob_translator_def ($$)->set_acceptor ($3,false);
503 | translator_spec_body REMOVE STRING semicolon {
504 unsmob_translator_def ($$)->remove_element ($3);
513 THIS->remember_spot ();
515 /*cont*/ '{' score_body '}' {
518 if (!$$->def_p_arr_.size ())
520 Music_output_def *id =
521 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
522 $$->add_output (id ? id->clone () : new Paper_def );
531 $$->set_spot (THIS->here_input ());
532 SCM m = $1->self_scm ();
533 scm_unprotect_object (m);
537 $$ = new Score (*unsmob_score ($1));
538 $$->set_spot (THIS->here_input ());
540 | score_body lilypond_header {
541 scm_unprotect_object ($2->self_scm ());
544 | score_body output_def {
557 music_output_def_body '}' {
559 THIS-> lexer_p_-> scope_l_arr_.pop ();
563 music_output_def_body:
565 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
570 p = dynamic_cast<Midi_def*> (id->clone ());
575 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
578 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
581 p = dynamic_cast<Paper_def*> (id->clone ());
584 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
587 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
588 Music_output_def *p = unsmob_music_output_def ($3);
590 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
593 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
594 Music_output_def *p = unsmob_music_output_def ($3);
597 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
600 | music_output_def_body assignment semicolon {
603 | music_output_def_body translator_spec_block {
604 $$->assign_translator ($2);
606 | music_output_def_body STYLESHEET embedded_scm {
607 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
609 | music_output_def_body tempo_request semicolon {
611 junk this ? there already is tempo stuff in
614 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
615 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
616 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
618 | music_output_def_body error {
624 TEMPO steno_duration '=' bare_unsigned {
626 $$->set_mus_property ("duration", $2);
627 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
631 Music_list: /* empty */ {
632 $$ = gh_cons (SCM_EOL, SCM_EOL);
636 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
637 scm_unprotect_object ($2->self_scm ()); /* UGH */
638 if (gh_pair_p (gh_cdr (s)))
639 gh_set_cdr_x (gh_cdr (s), c); /* append */
641 gh_set_car_x (s, c); /* set first cons */
642 gh_set_cdr_x (s, c) ; /* remember last cell */
658 | ALTERNATIVE Music_sequence {
660 $2->set_spot (THIS->here_input ());
668 REPEAT string bare_unsigned Music Alternative_music
670 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
671 if (alts && $3 < alts->length_i ())
672 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
676 Repeated_music * r = new Repeated_music (SCM_EOL);
680 r-> set_mus_property ("body", beg->self_scm ());
681 scm_unprotect_object (beg->self_scm ());
683 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
687 alts->truncate (times);
688 r-> set_mus_property ("alternatives", alts->self_scm ());
689 scm_unprotect_object (alts->self_scm ());
691 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
692 SCM result = gh_call1 (func, $2);
694 set_music_properties (r, result);
696 r->set_spot (*$4->origin ());
701 Music_sequence: '{' Music_list '}' {
702 $$ = new Music_sequence (SCM_EOL);
703 $$->set_mus_property ("elements", gh_car ($2));
708 SEQUENTIAL '{' Music_list '}' {
709 $$ = new Sequential_music (SCM_EOL);
710 $$->set_mus_property ("elements", gh_car ($3));
712 | '{' Music_list '}' {
713 $$ = new Sequential_music (SCM_EOL);
714 $$->set_mus_property ("elements", gh_car ($2));
719 SIMULTANEOUS '{' Music_list '}'{
720 $$ = new Simultaneous_music (SCM_EOL);
721 $$->set_mus_property ("elements", gh_car ($3));
724 | '<' Music_list '>' {
725 $$ = new Simultaneous_music (SCM_EOL);
726 $$->set_mus_property ("elements", gh_car ($2));
731 request_chord { $$ = $1; }
732 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
734 if (!gh_symbol_p ($3))
736 THIS->parser_error (_ ("Second argument must be a symbol"));
738 /*hould check # args */
739 if (!gh_procedure_p (pred))
741 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
744 Music *m = new Music (SCM_EOL);
745 m->set_mus_property ("predicate", pred);
746 m->set_mus_property ("symbol", $3);
747 m->set_mus_property ("value", $5);
748 m->set_mus_property ("iterator-ctor",
749 Output_property_music_iterator::constructor_cxx_function);
754 $$ = unsmob_music ($1)->clone ();
758 | Simple_music '*' bare_unsigned '/' bare_unsigned {
760 $$->compress (Moment ($3, $5 ));
762 | Simple_music '*' bare_unsigned {
764 $$->compress (Moment ($3, 1));
770 CONTEXT STRING Music {
771 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
772 csm->set_mus_property ("element", $3->self_scm ());
773 scm_unprotect_object ($3->self_scm ());
775 csm->set_mus_property ("context-type",$2);
776 csm->set_mus_property ("context-id", ly_str02scm (""));
780 | AUTOCHANGE STRING Music {
781 Music * chm = new Music_wrapper (SCM_EOL);
782 chm->set_mus_property ("element", $3->self_scm ());
783 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
785 scm_unprotect_object ($3->self_scm ());
786 chm->set_mus_property ("what", $2);
789 chm->set_spot (*$3->origin ());
792 $$ = new Grace_music (SCM_EOL);
793 $$->set_mus_property ("element", $2->self_scm ());
794 scm_unprotect_object ($2->self_scm ());
797 | CONTEXT STRING '=' STRING Music {
798 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
799 csm->set_mus_property ("element", $5->self_scm ());
800 scm_unprotect_object ($5->self_scm ());
802 csm->set_mus_property ("context-type", $2);
803 csm->set_mus_property ("context-id", $4);
808 THIS->remember_spot ();
811 bare_unsigned '/' bare_unsigned Music
814 int n = $3; int d = $5;
816 $$ = new Time_scaled_music (SCM_EOL);
817 $$->set_spot (THIS->pop_spot ());
820 $$->set_mus_property ("element", mp->self_scm ());
821 scm_unprotect_object (mp->self_scm ());
822 $$->set_mus_property ("numerator", gh_int2scm (n));
823 $$->set_mus_property ("denominator", gh_int2scm (d));
824 $$->compress (Moment (n,d));
827 | Repeated_music { $$ = $1; }
828 | Simultaneous_music { $$ = $1; }
829 | Sequential_music { $$ = $1; }
830 | TRANSPOSE pitch Music {
831 $$ = new Transposed_music (SCM_EOL);
833 Pitch pit = *unsmob_pitch ($2);
836 $$->set_mus_property ("element", p->self_scm ());
837 scm_unprotect_object (p->self_scm ());
839 | TRANSPOSE steno_tonic_pitch Music {
840 $$ = new Transposed_music (SCM_EOL);
842 Pitch pit = *unsmob_pitch ($2);
845 $$->set_mus_property ("element", p->self_scm ());
846 scm_unprotect_object (p->self_scm ());
849 | APPLY embedded_scm Music {
850 SCM ret = gh_call1 ($2, $3->self_scm ());
851 Music *m = unsmob_music (ret);
853 THIS->parser_error ("\\apply must return a Music");
854 m = new Music (SCM_EOL);
859 { THIS->lexer_p_->push_note_state (); }
862 THIS->lexer_p_->pop_state ();
865 { THIS->lexer_p_->push_chord_state (); }
868 Music * chm = new Un_relativable_music ;
869 chm->set_mus_property ("element", $3->self_scm ());
872 THIS->lexer_p_->pop_state ();
875 { THIS->lexer_p_->push_lyric_state (); }
879 THIS->lexer_p_->pop_state ();
881 | relative_music { $$ = $1; }
882 | re_rhythmed_music { $$ = $1; }
883 | part_combined_music { $$ = $1; }
887 RELATIVE absolute_pitch Music {
889 Pitch pit = *unsmob_pitch ($2);
890 $$ = new Relative_octave_music (SCM_EOL);
892 $$->set_mus_property ("element", p->self_scm ());
893 scm_unprotect_object (p->self_scm ());
895 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
901 ADDLYRICS Music Music {
902 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
903 l->set_mus_property ("music", $2->self_scm ());
904 l->set_mus_property ("lyrics", $3->self_scm ());
905 scm_unprotect_object ($3->self_scm ());
906 scm_unprotect_object ($2->self_scm ());
912 PARTCOMBINE STRING Music Music {
913 Part_combine_music * p = new Part_combine_music (SCM_EOL);
915 p->set_mus_property ("what", $2);
916 p->set_mus_property ("one", $3->self_scm ());
917 p->set_mus_property ("two", $4->self_scm ());
919 scm_unprotect_object ($3->self_scm ());
920 scm_unprotect_object ($4->self_scm ());
928 TRANSLATOR STRING '=' STRING {
929 Music * t = new Music (SCM_EOL);
930 t->set_mus_property ("iterator-ctor",
931 Change_iterator::constructor_cxx_function);
932 t-> set_mus_property ("change-to-type", $2);
933 t-> set_mus_property ("change-to-id", $4);
936 $$->set_spot (THIS->here_input ());
941 PROPERTY STRING '.' STRING '=' scalar {
942 Music *t = new Music (SCM_EOL);
944 t->set_mus_property ("iterator-ctor",
945 Property_iterator::constructor_cxx_function);
946 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
947 t->set_mus_property ("value", $6);
949 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
951 csm->set_mus_property ("element", t->self_scm ());
952 scm_unprotect_object (t->self_scm ());
955 $$->set_spot (THIS->here_input ());
957 csm-> set_mus_property ("context-type", $2);
959 | PROPERTY STRING '.' STRING UNSET {
960 Music *t = new Music (SCM_EOL);
962 t->set_mus_property ("iterator-ctor",
963 Property_unset_iterator::constructor_cxx_function);
964 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
966 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
967 csm->set_mus_property ("element", t->self_scm ());
968 scm_unprotect_object (t->self_scm ());
971 $$->set_spot (THIS->here_input ());
973 csm-> set_mus_property ("context-type", $2);
975 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
976 Music *t = new Music (SCM_EOL);
977 t->set_mus_property ("iterator-ctor",
978 Push_property_iterator::constructor_cxx_function);
979 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
980 t->set_mus_property ("pop-first", SCM_BOOL_T);
981 t->set_mus_property ("grob-property", $6);
982 t->set_mus_property ("grob-value", $8);
983 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
984 csm->set_mus_property ("element", t->self_scm ());
985 scm_unprotect_object (t->self_scm ());
987 $$->set_spot (THIS->here_input ());
989 csm-> set_mus_property ("context-type", $2);
991 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
992 Music *t = new Music (SCM_EOL);
993 t->set_mus_property ("iterator-ctor",
994 Push_property_iterator::constructor_cxx_function);
995 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
996 t->set_mus_property ("grob-property", $6);
997 t->set_mus_property ("grob-value", $8);
998 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
999 csm->set_mus_property ("element", t->self_scm ());
1000 scm_unprotect_object (t->self_scm ());
1003 $$->set_spot (THIS->here_input ());
1005 csm-> set_mus_property ("context-type", $2);
1007 | PROPERTY STRING '.' STRING REVERT embedded_scm {
1008 Music *t = new Music (SCM_EOL);
1009 t->set_mus_property ("iterator-ctor",
1010 Pop_property_iterator::constructor_cxx_function);
1011 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1012 t->set_mus_property ("grob-property", $6);
1014 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1015 csm->set_mus_property ("element", t->self_scm ());
1016 scm_unprotect_object (t->self_scm ());
1019 $$->set_spot (THIS->here_input ());
1021 csm-> set_mus_property ("context-type", $2);
1027 | bare_int { $$ = gh_int2scm ($1); }
1028 | embedded_scm { $$ = $1; }
1033 pre_requests simple_element post_requests {
1034 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1036 for (int i=0; i < $1->size (); i++)
1037 l->append_music ($1->elem (i));
1038 for (int i=0; i < $3->size (); i++)
1039 l->append_music ($3->elem (i));
1042 programming_error ("Need Sequence to add music to");
1051 $$ = new Request_chord (SCM_EOL);
1052 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1053 $$-> set_spot (THIS->here_input ());
1054 $1-> set_spot (THIS->here_input ());
1057 Music *t = new Music (SCM_EOL);
1059 t->set_mus_property ("iterator-ctor",
1060 Property_iterator::constructor_cxx_function);
1061 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1062 t->set_mus_property ("value", $2);
1064 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1065 csm->set_mus_property ("element", t->self_scm ());
1066 scm_unprotect_object (t->self_scm ());
1069 $$->set_spot (THIS->here_input ());
1071 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1073 | PARTIAL duration_length ';' {
1074 Music * p = new Music (SCM_EOL);
1075 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1076 p->set_mus_property ("iterator-ctor",
1077 Property_iterator::constructor_cxx_function);
1079 Moment m = - unsmob_duration ($2)->length_mom ();
1080 p->set_mus_property ("value", m.smobbed_copy ());
1082 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1083 sp->set_mus_property ("element", p->self_scm ());
1084 scm_unprotect_object (p->self_scm ());
1087 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1090 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1091 SCM result = gh_call1 (func, $2);
1094 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1095 Music * p = new Music (SCM_EOL);
1096 set_music_properties (p, gh_car (s));
1097 l = gh_cons (p->self_scm (), l);
1098 scm_unprotect_object (p->self_scm ());
1100 Sequential_music * seq = new Sequential_music (SCM_EOL);
1101 seq->set_mus_property ("elements", l);
1103 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1104 sp->set_mus_property ("element", seq->self_scm ());
1105 scm_unprotect_object (seq->self_scm ());
1108 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1110 | TIME_T bare_unsigned '/' bare_unsigned ';' {
1111 Music * p = new Music (SCM_EOL);
1112 p->set_mus_property ("symbol",
1113 ly_symbol2scm ( "timeSignatureFraction"));
1114 p->set_mus_property ("iterator-ctor",
1115 Property_iterator::constructor_cxx_function);
1117 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1120 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1121 sp->set_mus_property ("element", p->self_scm ());
1122 scm_unprotect_object (p->self_scm ());
1125 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1130 shorthand_command_req { $$ = $1; }
1131 | verbose_command_req semicolon { $$ = $1; }
1134 shorthand_command_req:
1142 $$ = new Barcheck_req;
1148 Span_req*b= new Span_req;
1149 b->set_span_dir (START);
1150 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1154 Span_req*b= new Span_req;
1155 b->set_span_dir ( STOP);
1156 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1160 $$ = new Breathing_sign_req;
1165 verbose_command_req:
1166 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1167 Span_req * sp_p = new Span_req;
1168 sp_p-> set_span_dir ( Direction ($2));
1169 sp_p->set_mus_property ("span-type",$3);
1170 sp_p->set_spot (THIS->here_input ());
1174 Mark_req * m = new Mark_req;
1178 Mark_req *m = new Mark_req;
1179 m->set_mus_property ("label", $2);
1183 | PENALTY bare_int {
1184 Break_req * b = new Break_req;
1185 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1186 b->set_spot (THIS->here_input ());
1189 | SKIP duration_length {
1190 Skip_req * skip_p = new Skip_req;
1191 skip_p->set_mus_property ("duration", $2);
1199 Key_change_req *key_p= new Key_change_req;
1202 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1203 Key_change_req *key_p= new Key_change_req;
1205 key_p->set_mus_property ("pitch-alist", $3);
1206 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1213 $$ = new Link_array<Request>;
1215 | post_requests post_request {
1216 $2->set_spot (THIS->here_input ());
1228 request_that_take_dir:
1231 | script_abbreviation {
1232 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1233 Articulation_req *a = new Articulation_req;
1234 if (gh_string_p (s))
1235 a->set_mus_property ("articulation-type", s);
1236 else THIS->parser_error (_ ("Expecting string as script definition"));
1242 script_dir request_that_take_dir {
1243 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1244 gs->set_direction (Direction ($1));
1246 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1252 REQUEST_IDENTIFIER {
1253 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1254 $$->set_spot (THIS->here_input ());
1256 | DYNAMICSCRIPT embedded_scm {
1258 TODO: junkme, use text-type == dynamic
1260 Text_script_req *d = new Text_script_req;
1261 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1262 d->set_mus_property ("text", $2);
1263 d->set_spot (THIS->here_input ());
1266 | SPANREQUEST bare_int STRING {
1267 Span_req * sp_p = new Span_req;
1268 sp_p->set_span_dir ( Direction ($2));
1269 sp_p->set_mus_property ("span-type", $3);
1270 sp_p->set_spot (THIS->here_input ());
1274 Tremolo_req* a = new Tremolo_req;
1275 a->set_spot (THIS->here_input ());
1276 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1280 Articulation_req * a = new Articulation_req;
1281 a->set_mus_property ("articulation-type", $2);
1282 a->set_spot (THIS->here_input ());
1286 duh, junk this syntax from the parser, if possible.
1289 Arpeggio_req *a = new Arpeggio_req;
1290 a->set_spot (THIS->here_input ());
1294 Glissando_req *g = new Glissando_req;
1295 g->set_spot /* No pun intended */ (THIS->here_input ());
1322 | NOTENAME_PITCH sup_quotes {
1323 Pitch p = *unsmob_pitch ($1);
1325 $$ = p.smobbed_copy ();
1327 | NOTENAME_PITCH sub_quotes {
1328 Pitch p =* unsmob_pitch ($1);
1331 $$ = p.smobbed_copy ();
1344 | TONICNAME_PITCH sup_quotes {
1345 Pitch p = *unsmob_pitch ($1);
1347 $$ = p.smobbed_copy ();
1349 | TONICNAME_PITCH sub_quotes {
1350 Pitch p =* unsmob_pitch ($1);
1353 $$ = p.smobbed_copy ();
1368 PITCH embedded_scm {
1370 if (!unsmob_pitch ($2)) {
1371 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1372 $$ = Pitch ().smobbed_copy ();
1378 DURATION embedded_scm {
1380 if (!unsmob_duration ($2))
1382 THIS->parser_error (_ ("Must have duration object"));
1383 $$ = Duration ().smobbed_copy ();
1390 if (!THIS->lexer_p_->lyric_state_b ())
1391 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1392 $$ = new Extender_req;
1398 if (!THIS->lexer_p_->lyric_state_b ())
1399 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1400 $$ = new Hyphen_req;
1405 close_request_parens {
1407 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1410 close_request_parens:
1412 Span_req* s= new Span_req;
1414 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1417 Span_req* s= new Span_req;
1419 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1422 Span_req*s =new Span_req;
1424 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1427 Span_req*s =new Span_req;
1429 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1435 open_request_parens {
1437 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1441 open_request_parens:
1443 Span_req *s = new Span_req;
1444 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1449 Span_req* s= new Span_req;
1451 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1454 Span_req* s= new Span_req;
1456 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1462 Text_script_req *t = new Text_script_req;
1463 t->set_mus_property ("text", $1);
1464 t->set_spot (THIS->here_input ());
1468 Text_script_req *t = new Text_script_req;
1469 t->set_mus_property ("text", $1);
1470 t->set_spot (THIS->here_input ());
1474 String ds = to_str ($1);
1475 Text_script_req* t = new Text_script_req;
1477 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1478 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1479 t->set_spot (THIS->here_input ());
1484 script_abbreviation:
1486 $$ = gh_str02scm ("hat");
1489 $$ = gh_str02scm ("plus");
1492 $$ = gh_str02scm ("dash");
1495 $$ = gh_str02scm ("bar");
1498 $$ = gh_str02scm ("larger");
1501 $$ = gh_str02scm ("dot");
1509 | '-' { $$ = CENTER; }
1514 $$ = new Link_array<Request>;
1516 | pre_requests open_request {
1531 | explicit_duration {
1534 | duration_length '*' bare_unsigned {
1535 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1537 | duration_length '/' bare_unsigned {
1538 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1542 entered_notemode_duration:
1544 THIS->set_last_duration (unsmob_duration ($1));
1548 optional_notemode_duration:
1550 $$ = THIS->default_duration_.smobbed_copy ();
1552 | entered_notemode_duration {
1555 | explicit_duration {
1561 bare_unsigned dots {
1563 if (!is_duration_b ($1))
1564 THIS->parser_error (_f ("not a duration: %d", $1));
1568 $$ = Duration (l, $2).smobbed_copy ();
1570 | DURATION_IDENTIFIER dots {
1571 Duration *d =unsmob_duration ($1);
1572 Duration k (d->duration_log (),d->dot_count () + $2);
1573 $$ = k.smobbed_copy ();
1591 | ':' bare_unsigned {
1592 if (!is_duration_b ($2))
1593 THIS->parser_error (_f ("not a duration: %d", $2));
1600 pitch exclamations questions optional_notemode_duration {
1601 if (!THIS->lexer_p_->note_state_b ())
1602 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1604 Note_req *n = new Note_req;
1606 n->set_mus_property ("pitch", $1);
1607 n->set_mus_property ("duration", $4);
1610 n->set_mus_property ("cautionary", SCM_BOOL_T);
1611 if ($2 % 2 || $3 % 2)
1612 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1614 Simultaneous_music*v = new Request_chord (SCM_EOL);
1615 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1618 FIXME: location is one off, since ptich & duration don't contain origin refs.
1620 v->set_spot (THIS->here_input ());
1621 n->set_spot (THIS->here_input ());
1625 | RESTNAME optional_notemode_duration {
1627 SCM e = SCM_UNDEFINED;
1628 if (ly_scm2string ($1) =="s")
1630 Skip_req * skip_p = new Skip_req;
1631 skip_p->set_mus_property ("duration" ,$2);
1633 skip_p->set_spot (THIS->here_input ());
1634 e = skip_p->self_scm ();
1638 Rest_req * rest_req_p = new Rest_req;
1639 rest_req_p->set_mus_property ("duration", $2);
1640 rest_req_p->set_spot (THIS->here_input ());
1641 e = rest_req_p->self_scm ();
1643 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1644 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1645 velt_p->set_spot (THIS->here_input ());
1650 | MULTI_MEASURE_REST optional_notemode_duration {
1651 Skip_req * sk = new Skip_req;
1652 sk->set_mus_property ("duration", $2);
1653 Span_req *sp1 = new Span_req;
1654 Span_req *sp2 = new Span_req;
1655 sp1-> set_span_dir ( START);
1656 sp2-> set_span_dir ( STOP);
1657 SCM r = ly_str02scm ("rest");
1658 sp1->set_mus_property ("span-type", r);
1659 sp2->set_mus_property ("span-type", r);
1661 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1662 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1663 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1664 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1665 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1666 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1668 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1670 $$ = new Sequential_music (SCM_EOL);
1671 $$->set_mus_property ("elements", ms);
1674 THIS->remember_spot ();
1677 optional_notemode_duration {
1678 if (!THIS->lexer_p_->lyric_state_b ()) {
1679 THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1680 THIS->error_level_i_ = 1;
1681 THIS->parser_error (_ ("Giving up"));
1685 Lyric_req* lreq_p = new Lyric_req;
1686 lreq_p->set_mus_property ("text", $1);
1687 lreq_p->set_mus_property ("duration",$3);
1688 lreq_p->set_spot (THIS->here_input ());
1689 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1690 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1697 if (!THIS->lexer_p_->chord_state_b ())
1698 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1705 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1706 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1707 $$->set_spot (THIS->here_input ());
1714 | CHORD_COLON chord_notes {
1723 | chord_notes '.' chord_step {
1724 $$ = gh_append2 ($$, $3);
1732 | CHORD_CARET chord_notes {
1742 | '/' steno_tonic_pitch {
1751 | CHORD_BASS steno_tonic_pitch {
1758 $$ = gh_cons ($1, SCM_EOL);
1760 | CHORDMODIFIER_PITCH {
1761 $$ = gh_cons ($1, SCM_EOL);
1763 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1764 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1771 m.notename_i_ = ($1 - 1) % 7;
1772 m.octave_i_ = $1 > 7 ? 1 : 0;
1773 m.alteration_i_ = 0;
1775 $$ = m.smobbed_copy ();
1777 | bare_unsigned '+' {
1779 m.notename_i_ = ($1 - 1) % 7;
1780 m.octave_i_ = $1 > 7 ? 1 : 0;
1781 m.alteration_i_ = 1;
1784 $$ = m.smobbed_copy ();
1786 | bare_unsigned CHORD_MINUS {
1788 m.notename_i_ = ($1 - 1) % 7;
1789 m.octave_i_ = $1 > 7 ? 1 : 0;
1790 m.alteration_i_ = -1;
1792 $$ = m.smobbed_copy ();
1803 | '-' number_expression %prec UNARY_MINUS {
1804 $$ = scm_difference ($2, SCM_UNDEFINED);
1806 | number_expression '*' number_expression {
1807 $$ = scm_product ($1, $3);
1809 | number_expression '/' number_expression {
1810 $$ = scm_divide ($1, $3);
1812 | number_expression '+' number_expression {
1813 $$ = scm_sum ($1, $3);
1815 | number_expression '-' number_expression {
1816 $$ = scm_difference ($1, $3);
1818 | '(' number_expression ')' {
1825 $$ = gh_int2scm ($1);
1828 $$ = gh_int2scm ($1);
1831 $$ = gh_double2scm ($1);
1833 | NUMBER_IDENTIFIER {
1837 $$ = gh_double2scm ($1 CM);
1840 $$ = gh_double2scm ($1 PT);
1843 $$ = gh_double2scm ($1 INCH);
1846 $$ = gh_double2scm ($1 MM);
1849 $$ = gh_double2scm ($1 CHAR);
1856 if (scm_integer_p ($1) == SCM_BOOL_T) {
1857 $$ = gh_scm2int ($1);
1860 THIS->parser_error (_ ("need integer number arg"));
1864 THIS->parser_error (_ ("Must be positive integer"));
1872 if (scm_integer_p ($1) == SCM_BOOL_T)
1874 int k = gh_scm2int ($1);
1878 THIS->parser_error (_ ("need integer number arg"));
1892 | STRING_IDENTIFIER {
1895 | string '+' string {
1896 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1903 | exclamations '!' { $$ ++; }
1908 | questions '?' { $$ ++; }
1919 My_lily_parser::set_yydebug (bool b)
1926 extern My_lily_parser * current_parser;
1929 My_lily_parser::do_yyparse ()
1932 current_parser = this;;
1933 yyparse ((void*)this);