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 multiplied_duration
246 %type <scm> 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 ();
762 CONTEXT STRING Music {
763 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
764 csm->set_mus_property ("element", $3->self_scm ());
765 scm_unprotect_object ($3->self_scm ());
767 csm->set_mus_property ("context-type",$2);
768 csm->set_mus_property ("context-id", ly_str02scm (""));
772 | AUTOCHANGE STRING Music {
773 Music * chm = new Music_wrapper (SCM_EOL);
774 chm->set_mus_property ("element", $3->self_scm ());
775 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
777 scm_unprotect_object ($3->self_scm ());
778 chm->set_mus_property ("what", $2);
781 chm->set_spot (*$3->origin ());
784 $$ = new Grace_music (SCM_EOL);
785 $$->set_mus_property ("element", $2->self_scm ());
786 scm_unprotect_object ($2->self_scm ());
789 | CONTEXT STRING '=' STRING Music {
790 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
791 csm->set_mus_property ("element", $5->self_scm ());
792 scm_unprotect_object ($5->self_scm ());
794 csm->set_mus_property ("context-type", $2);
795 csm->set_mus_property ("context-id", $4);
800 THIS->remember_spot ();
803 bare_unsigned '/' bare_unsigned Music
806 int n = $3; int d = $5;
808 $$ = new Time_scaled_music (SCM_EOL);
809 $$->set_spot (THIS->pop_spot ());
812 $$->set_mus_property ("element", mp->self_scm ());
813 scm_unprotect_object (mp->self_scm ());
814 $$->set_mus_property ("numerator", gh_int2scm (n));
815 $$->set_mus_property ("denominator", gh_int2scm (d));
816 $$->compress (Moment (n,d));
819 | Repeated_music { $$ = $1; }
820 | Simultaneous_music { $$ = $1; }
821 | Sequential_music { $$ = $1; }
822 | TRANSPOSE pitch Music {
823 $$ = new Transposed_music (SCM_EOL);
825 Pitch pit = *unsmob_pitch ($2);
828 $$->set_mus_property ("element", p->self_scm ());
829 scm_unprotect_object (p->self_scm ());
831 | TRANSPOSE steno_tonic_pitch Music {
832 $$ = new Transposed_music (SCM_EOL);
834 Pitch pit = *unsmob_pitch ($2);
837 $$->set_mus_property ("element", p->self_scm ());
838 scm_unprotect_object (p->self_scm ());
841 | APPLY embedded_scm Music {
842 SCM ret = gh_call1 ($2, $3->self_scm ());
843 Music *m = unsmob_music (ret);
845 THIS->parser_error ("\\apply must return a Music");
846 m = new Music (SCM_EOL);
851 { THIS->lexer_p_->push_note_state (); }
854 THIS->lexer_p_->pop_state ();
857 { THIS->lexer_p_->push_chord_state (); }
860 Music * chm = new Un_relativable_music ;
861 chm->set_mus_property ("element", $3->self_scm ());
864 THIS->lexer_p_->pop_state ();
867 { THIS->lexer_p_->push_lyric_state (); }
871 THIS->lexer_p_->pop_state ();
873 | relative_music { $$ = $1; }
874 | re_rhythmed_music { $$ = $1; }
875 | part_combined_music { $$ = $1; }
879 RELATIVE absolute_pitch Music {
881 Pitch pit = *unsmob_pitch ($2);
882 $$ = new Relative_octave_music (SCM_EOL);
884 $$->set_mus_property ("element", p->self_scm ());
885 scm_unprotect_object (p->self_scm ());
887 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
893 ADDLYRICS Music Music {
894 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
895 l->set_mus_property ("music", $2->self_scm ());
896 l->set_mus_property ("lyrics", $3->self_scm ());
897 scm_unprotect_object ($3->self_scm ());
898 scm_unprotect_object ($2->self_scm ());
904 PARTCOMBINE STRING Music Music {
905 Part_combine_music * p = new Part_combine_music (SCM_EOL);
907 p->set_mus_property ("what", $2);
908 p->set_mus_property ("one", $3->self_scm ());
909 p->set_mus_property ("two", $4->self_scm ());
911 scm_unprotect_object ($3->self_scm ());
912 scm_unprotect_object ($4->self_scm ());
920 TRANSLATOR STRING '=' STRING {
921 Music * t = new Music (SCM_EOL);
922 t->set_mus_property ("iterator-ctor",
923 Change_iterator::constructor_cxx_function);
924 t-> set_mus_property ("change-to-type", $2);
925 t-> set_mus_property ("change-to-id", $4);
928 $$->set_spot (THIS->here_input ());
933 PROPERTY STRING '.' STRING '=' scalar {
934 Music *t = new Music (SCM_EOL);
936 t->set_mus_property ("iterator-ctor",
937 Property_iterator::constructor_cxx_function);
938 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
939 t->set_mus_property ("value", $6);
941 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
943 csm->set_mus_property ("element", t->self_scm ());
944 scm_unprotect_object (t->self_scm ());
947 $$->set_spot (THIS->here_input ());
949 csm-> set_mus_property ("context-type", $2);
951 | PROPERTY STRING '.' STRING UNSET {
952 Music *t = new Music (SCM_EOL);
954 t->set_mus_property ("iterator-ctor",
955 Property_unset_iterator::constructor_cxx_function);
956 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
958 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
959 csm->set_mus_property ("element", t->self_scm ());
960 scm_unprotect_object (t->self_scm ());
963 $$->set_spot (THIS->here_input ());
965 csm-> set_mus_property ("context-type", $2);
967 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
968 Music *t = new Music (SCM_EOL);
969 t->set_mus_property ("iterator-ctor",
970 Push_property_iterator::constructor_cxx_function);
971 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
972 t->set_mus_property ("pop-first", SCM_BOOL_T);
973 t->set_mus_property ("grob-property", $6);
974 t->set_mus_property ("grob-value", $8);
975 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
976 csm->set_mus_property ("element", t->self_scm ());
977 scm_unprotect_object (t->self_scm ());
979 $$->set_spot (THIS->here_input ());
981 csm-> set_mus_property ("context-type", $2);
983 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
984 Music *t = new Music (SCM_EOL);
985 t->set_mus_property ("iterator-ctor",
986 Push_property_iterator::constructor_cxx_function);
987 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
988 t->set_mus_property ("grob-property", $6);
989 t->set_mus_property ("grob-value", $8);
990 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
991 csm->set_mus_property ("element", t->self_scm ());
992 scm_unprotect_object (t->self_scm ());
995 $$->set_spot (THIS->here_input ());
997 csm-> set_mus_property ("context-type", $2);
999 | PROPERTY STRING '.' STRING REVERT embedded_scm {
1000 Music *t = new Music (SCM_EOL);
1001 t->set_mus_property ("iterator-ctor",
1002 Pop_property_iterator::constructor_cxx_function);
1003 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1004 t->set_mus_property ("grob-property", $6);
1006 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1007 csm->set_mus_property ("element", t->self_scm ());
1008 scm_unprotect_object (t->self_scm ());
1011 $$->set_spot (THIS->here_input ());
1013 csm-> set_mus_property ("context-type", $2);
1019 | bare_int { $$ = gh_int2scm ($1); }
1020 | embedded_scm { $$ = $1; }
1025 pre_requests simple_element post_requests {
1026 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1028 for (int i=0; i < $1->size (); i++)
1029 l->append_music ($1->elem (i));
1030 for (int i=0; i < $3->size (); i++)
1031 l->append_music ($3->elem (i));
1034 programming_error ("Need Sequence to add music to");
1043 $$ = new Request_chord (SCM_EOL);
1044 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1045 $$-> set_spot (THIS->here_input ());
1046 $1-> set_spot (THIS->here_input ());
1049 Music *t = new Music (SCM_EOL);
1051 t->set_mus_property ("iterator-ctor",
1052 Property_iterator::constructor_cxx_function);
1053 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1054 t->set_mus_property ("value", $2);
1056 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1057 csm->set_mus_property ("element", t->self_scm ());
1058 scm_unprotect_object (t->self_scm ());
1061 $$->set_spot (THIS->here_input ());
1063 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1065 | PARTIAL duration_length ';' {
1066 Music * p = new Music (SCM_EOL);
1067 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1068 p->set_mus_property ("iterator-ctor",
1069 Property_iterator::constructor_cxx_function);
1071 Moment m = - unsmob_duration ($2)->length_mom ();
1072 p->set_mus_property ("value", m.smobbed_copy ());
1074 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1075 sp->set_mus_property ("element", p->self_scm ());
1076 scm_unprotect_object (p->self_scm ());
1079 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1082 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1083 SCM result = gh_call1 (func, $2);
1086 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1087 Music * p = new Music (SCM_EOL);
1088 set_music_properties (p, gh_car (s));
1089 l = gh_cons (p->self_scm (), l);
1090 scm_unprotect_object (p->self_scm ());
1092 Sequential_music * seq = new Sequential_music (SCM_EOL);
1093 seq->set_mus_property ("elements", l);
1095 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1096 sp->set_mus_property ("element", seq->self_scm ());
1097 scm_unprotect_object (seq->self_scm ());
1100 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1102 | TIME_T bare_unsigned '/' bare_unsigned ';' {
1103 Music * p = new Music (SCM_EOL);
1104 p->set_mus_property ("symbol",
1105 ly_symbol2scm ( "timeSignatureFraction"));
1106 p->set_mus_property ("iterator-ctor",
1107 Property_iterator::constructor_cxx_function);
1109 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1112 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1113 sp->set_mus_property ("element", p->self_scm ());
1114 scm_unprotect_object (p->self_scm ());
1119 TODO: should make alias TimingContext for Score
1122 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1127 shorthand_command_req { $$ = $1; }
1128 | verbose_command_req semicolon { $$ = $1; }
1131 shorthand_command_req:
1139 $$ = new Barcheck_req;
1145 Span_req*b= new Span_req;
1146 b->set_span_dir (START);
1147 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1151 Span_req*b= new Span_req;
1152 b->set_span_dir ( STOP);
1153 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1157 $$ = new Breathing_sign_req;
1162 verbose_command_req:
1163 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1164 Span_req * sp_p = new Span_req;
1165 sp_p-> set_span_dir ( Direction ($2));
1166 sp_p->set_mus_property ("span-type",$3);
1167 sp_p->set_spot (THIS->here_input ());
1171 Mark_req * m = new Mark_req;
1175 Mark_req *m = new Mark_req;
1176 m->set_mus_property ("label", $2);
1180 | PENALTY bare_int {
1181 Break_req * b = new Break_req;
1182 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1183 b->set_spot (THIS->here_input ());
1186 | SKIP duration_length {
1187 Skip_req * skip_p = new Skip_req;
1188 skip_p->set_mus_property ("duration", $2);
1196 Key_change_req *key_p= new Key_change_req;
1199 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1200 Key_change_req *key_p= new Key_change_req;
1202 key_p->set_mus_property ("pitch-alist", $3);
1203 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1210 $$ = new Link_array<Request>;
1212 | post_requests post_request {
1213 $2->set_spot (THIS->here_input ());
1225 request_that_take_dir:
1228 | script_abbreviation {
1229 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1230 Articulation_req *a = new Articulation_req;
1231 if (gh_string_p (s))
1232 a->set_mus_property ("articulation-type", s);
1233 else THIS->parser_error (_ ("Expecting string as script definition"));
1239 script_dir request_that_take_dir {
1240 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1241 gs->set_direction (Direction ($1));
1243 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1249 REQUEST_IDENTIFIER {
1250 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1251 $$->set_spot (THIS->here_input ());
1253 | DYNAMICSCRIPT embedded_scm {
1255 TODO: junkme, use text-type == dynamic
1257 Text_script_req *d = new Text_script_req;
1258 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1259 d->set_mus_property ("text", $2);
1260 d->set_spot (THIS->here_input ());
1263 | SPANREQUEST bare_int STRING {
1264 Span_req * sp_p = new Span_req;
1265 sp_p->set_span_dir ( Direction ($2));
1266 sp_p->set_mus_property ("span-type", $3);
1267 sp_p->set_spot (THIS->here_input ());
1271 Tremolo_req* a = new Tremolo_req;
1272 a->set_spot (THIS->here_input ());
1273 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1277 Articulation_req * a = new Articulation_req;
1278 a->set_mus_property ("articulation-type", $2);
1279 a->set_spot (THIS->here_input ());
1283 duh, junk this syntax from the parser, if possible.
1286 Arpeggio_req *a = new Arpeggio_req;
1287 a->set_spot (THIS->here_input ());
1291 Glissando_req *g = new Glissando_req;
1292 g->set_spot /* No pun intended */ (THIS->here_input ());
1319 | NOTENAME_PITCH sup_quotes {
1320 Pitch p = *unsmob_pitch ($1);
1322 $$ = p.smobbed_copy ();
1324 | NOTENAME_PITCH sub_quotes {
1325 Pitch p =* unsmob_pitch ($1);
1328 $$ = p.smobbed_copy ();
1341 | TONICNAME_PITCH sup_quotes {
1342 Pitch p = *unsmob_pitch ($1);
1344 $$ = p.smobbed_copy ();
1346 | TONICNAME_PITCH sub_quotes {
1347 Pitch p =* unsmob_pitch ($1);
1350 $$ = p.smobbed_copy ();
1365 PITCH embedded_scm {
1367 if (!unsmob_pitch ($2)) {
1368 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1369 $$ = Pitch ().smobbed_copy ();
1375 DURATION embedded_scm {
1377 if (!unsmob_duration ($2))
1379 THIS->parser_error (_ ("Must have duration object"));
1380 $$ = Duration ().smobbed_copy ();
1387 if (!THIS->lexer_p_->lyric_state_b ())
1388 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1389 $$ = new Extender_req;
1395 if (!THIS->lexer_p_->lyric_state_b ())
1396 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1397 $$ = new Hyphen_req;
1402 close_request_parens {
1404 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1407 close_request_parens:
1409 Span_req* s= new Span_req;
1411 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1414 Span_req* s= new Span_req;
1416 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1419 Span_req*s =new Span_req;
1421 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1424 Span_req*s =new Span_req;
1426 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1432 open_request_parens {
1434 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1438 open_request_parens:
1440 Span_req *s = new Span_req;
1441 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1446 Span_req* s= new Span_req;
1448 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1451 Span_req* s= new Span_req;
1453 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1459 Text_script_req *t = new Text_script_req;
1460 t->set_mus_property ("text", $1);
1461 t->set_spot (THIS->here_input ());
1465 Text_script_req *t = new Text_script_req;
1466 t->set_mus_property ("text", $1);
1467 t->set_spot (THIS->here_input ());
1471 String ds = to_str ($1);
1472 Text_script_req* t = new Text_script_req;
1474 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1475 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1476 t->set_spot (THIS->here_input ());
1481 script_abbreviation:
1483 $$ = gh_str02scm ("hat");
1486 $$ = gh_str02scm ("plus");
1489 $$ = gh_str02scm ("dash");
1492 $$ = gh_str02scm ("bar");
1495 $$ = gh_str02scm ("larger");
1498 $$ = gh_str02scm ("dot");
1506 | '-' { $$ = CENTER; }
1511 $$ = new Link_array<Request>;
1513 | pre_requests open_request {
1525 multiplied_duration {
1528 | explicit_duration {
1533 optional_notemode_duration:
1535 $$ = THIS->default_duration_.smobbed_copy ();
1537 | multiplied_duration {
1540 | explicit_duration {
1546 bare_unsigned dots {
1548 if (!is_duration_b ($1))
1549 THIS->parser_error (_f ("not a duration: %d", $1));
1553 $$ = Duration (l, $2).smobbed_copy ();
1555 THIS->set_last_duration (unsmob_duration ($$));
1557 | DURATION_IDENTIFIER dots {
1558 Duration *d =unsmob_duration ($1);
1559 Duration k (d->duration_log (),d->dot_count () + $2);
1560 $$ = k.smobbed_copy ();
1562 THIS->set_last_duration (unsmob_duration ($$));
1569 multiplied_duration:
1573 | multiplied_duration '*' bare_unsigned {
1574 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1576 | multiplied_duration '/' bare_unsigned {
1577 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1595 | ':' bare_unsigned {
1596 if (!is_duration_b ($2))
1597 THIS->parser_error (_f ("not a duration: %d", $2));
1604 pitch exclamations questions optional_notemode_duration {
1605 if (!THIS->lexer_p_->note_state_b ())
1606 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1608 Note_req *n = new Note_req;
1610 n->set_mus_property ("pitch", $1);
1611 n->set_mus_property ("duration", $4);
1614 n->set_mus_property ("cautionary", SCM_BOOL_T);
1615 if ($2 % 2 || $3 % 2)
1616 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1618 Simultaneous_music*v = new Request_chord (SCM_EOL);
1619 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1622 FIXME: location is one off, since ptich & duration don't contain origin refs.
1624 v->set_spot (THIS->here_input ());
1625 n->set_spot (THIS->here_input ());
1629 | RESTNAME optional_notemode_duration {
1631 SCM e = SCM_UNDEFINED;
1632 if (ly_scm2string ($1) =="s")
1634 Skip_req * skip_p = new Skip_req;
1635 skip_p->set_mus_property ("duration" ,$2);
1637 skip_p->set_spot (THIS->here_input ());
1638 e = skip_p->self_scm ();
1642 Rest_req * rest_req_p = new Rest_req;
1643 rest_req_p->set_mus_property ("duration", $2);
1644 rest_req_p->set_spot (THIS->here_input ());
1645 e = rest_req_p->self_scm ();
1647 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1648 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1649 velt_p->set_spot (THIS->here_input ());
1654 | MULTI_MEASURE_REST optional_notemode_duration {
1655 Skip_req * sk = new Skip_req;
1656 sk->set_mus_property ("duration", $2);
1657 Span_req *sp1 = new Span_req;
1658 Span_req *sp2 = new Span_req;
1659 sp1-> set_span_dir ( START);
1660 sp2-> set_span_dir ( STOP);
1661 SCM r = ly_str02scm ("rest");
1662 sp1->set_mus_property ("span-type", r);
1663 sp2->set_mus_property ("span-type", r);
1665 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1666 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1667 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1668 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1669 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1670 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1672 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1674 $$ = new Sequential_music (SCM_EOL);
1675 $$->set_mus_property ("elements", ms);
1678 THIS->remember_spot ();
1681 optional_notemode_duration {
1682 if (!THIS->lexer_p_->lyric_state_b ()) {
1683 THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1684 THIS->error_level_i_ = 1;
1685 THIS->parser_error (_ ("Giving up"));
1689 Lyric_req* lreq_p = new Lyric_req;
1690 lreq_p->set_mus_property ("text", $1);
1691 lreq_p->set_mus_property ("duration",$3);
1692 lreq_p->set_spot (THIS->here_input ());
1693 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1694 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1701 if (!THIS->lexer_p_->chord_state_b ())
1702 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1709 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1710 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1711 $$->set_spot (THIS->here_input ());
1718 | CHORD_COLON chord_notes {
1727 | chord_notes '.' chord_step {
1728 $$ = gh_append2 ($$, $3);
1736 | CHORD_CARET chord_notes {
1746 | '/' steno_tonic_pitch {
1755 | CHORD_BASS steno_tonic_pitch {
1762 $$ = gh_cons ($1, SCM_EOL);
1764 | CHORDMODIFIER_PITCH {
1765 $$ = gh_cons ($1, SCM_EOL);
1767 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1768 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1775 m.notename_i_ = ($1 - 1) % 7;
1776 m.octave_i_ = $1 > 7 ? 1 : 0;
1777 m.alteration_i_ = 0;
1779 $$ = m.smobbed_copy ();
1781 | bare_unsigned '+' {
1783 m.notename_i_ = ($1 - 1) % 7;
1784 m.octave_i_ = $1 > 7 ? 1 : 0;
1785 m.alteration_i_ = 1;
1788 $$ = m.smobbed_copy ();
1790 | bare_unsigned CHORD_MINUS {
1792 m.notename_i_ = ($1 - 1) % 7;
1793 m.octave_i_ = $1 > 7 ? 1 : 0;
1794 m.alteration_i_ = -1;
1796 $$ = m.smobbed_copy ();
1807 | '-' number_expression %prec UNARY_MINUS {
1808 $$ = scm_difference ($2, SCM_UNDEFINED);
1810 | number_expression '*' number_expression {
1811 $$ = scm_product ($1, $3);
1813 | number_expression '/' number_expression {
1814 $$ = scm_divide ($1, $3);
1816 | number_expression '+' number_expression {
1817 $$ = scm_sum ($1, $3);
1819 | number_expression '-' number_expression {
1820 $$ = scm_difference ($1, $3);
1822 | '(' number_expression ')' {
1829 $$ = gh_int2scm ($1);
1832 $$ = gh_int2scm ($1);
1835 $$ = gh_double2scm ($1);
1837 | NUMBER_IDENTIFIER {
1841 $$ = gh_double2scm ($1 CM);
1844 $$ = gh_double2scm ($1 PT);
1847 $$ = gh_double2scm ($1 INCH);
1850 $$ = gh_double2scm ($1 MM);
1853 $$ = gh_double2scm ($1 CHAR);
1860 if (scm_integer_p ($1) == SCM_BOOL_T) {
1861 $$ = gh_scm2int ($1);
1864 THIS->parser_error (_ ("need integer number arg"));
1868 THIS->parser_error (_ ("Must be positive integer"));
1876 if (scm_integer_p ($1) == SCM_BOOL_T)
1878 int k = gh_scm2int ($1);
1882 THIS->parser_error (_ ("need integer number arg"));
1896 | STRING_IDENTIFIER {
1899 | string '+' string {
1900 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1907 | exclamations '!' { $$ ++; }
1912 | questions '?' { $$ ++; }
1923 My_lily_parser::set_yydebug (bool b)
1930 extern My_lily_parser * current_parser;
1933 My_lily_parser::do_yyparse ()
1936 current_parser = this;;
1937 yyparse ((void*)this);