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;
100 String *string; // needed by the lexer as temporary scratch area.
104 Scheme_hash_table *scmhash;
105 Music_output_def * outputdef;
109 /* We use SCMs to do strings, because it saves us the trouble of
110 deleting them. Let's hope that a stack overflow doesnt trigger a move
111 of the parse stack onto the heap. */
121 yylex (YYSTYPE *s, void * v_l)
123 My_lily_parser *pars_l = (My_lily_parser*) v_l;
124 My_lily_lexer * lex_l = pars_l->lexer_p_;
126 lex_l->lexval_l = (void*) s;
127 return lex_l->yylex ();
135 /* tokens which are not keywords */
145 %token CHORDMODIFIERS
153 %token ELEMENTDESCRIPTIONS
169 %token MULTI_MEASURE_REST
181 %token OVERRIDE SET REVERT
194 %token COMMANDSPANREQUEST
196 %token OUTPUTPROPERTY
206 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
207 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
209 %type <i> exclamations questions dots
211 %token <scm> NOTENAME_PITCH
212 %token <scm> TONICNAME_PITCH
213 %token <scm> CHORDMODIFIER_PITCH
214 %token <scm> DURATION_IDENTIFIER
215 %token <id> IDENTIFIER
218 %token <scm> SCORE_IDENTIFIER
219 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
221 %token <scm> NUMBER_IDENTIFIER
222 %token <scm> REQUEST_IDENTIFIER
223 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
224 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
225 %token <scm> RESTNAME
231 %type <outputdef> output_def
232 %type <scmhash> lilypond_header lilypond_header_body
233 %type <request> open_request_parens close_request_parens open_request close_request
234 %type <request> request_with_dir request_that_take_dir verbose_request
235 %type <i> sub_quotes sup_quotes
236 %type <music> simple_element request_chord command_element Simple_music Composite_music
237 %type <music> Alternative_music Repeated_music
238 %type <i> tremolo_type
239 %type <i> bare_int bare_unsigned
242 %type <scm> identifier_init
244 %type <scm> steno_duration optional_notemode_duration multiplied_duration
245 %type <scm> explicit_duration
247 %type <reqvec> pre_requests post_requests
248 %type <request> gen_text_def
249 %type <scm> steno_pitch pitch absolute_pitch
250 %type <scm> explicit_pitch steno_tonic_pitch
252 %type <scm> chord_additions chord_subtractions chord_notes chord_step
254 %type <scm> chord_note chord_inversion chord_bass
255 %type <scm> duration_length
257 %type <scm> embedded_scm scalar
258 %type <music> Music Sequential_music Simultaneous_music Music_sequence
259 %type <music> relative_music re_rhythmed_music part_combined_music
260 %type <music> property_def translator_change
261 %type <scm> Music_list
262 %type <outputdef> music_output_def_body
263 %type <request> shorthand_command_req
264 %type <request> post_request
265 %type <music> command_req verbose_command_req
266 %type <request> extender_req
267 %type <request> hyphen_req
268 %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 {
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 ());
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 NAME STRING {
469 unsmob_translator_def ($$)->type_name_ = $3;
471 | translator_spec_body CONSISTS STRING {
472 unsmob_translator_def ($$)->add_element ($3);
474 | translator_spec_body ALIAS STRING {
475 Translator_def*td = unsmob_translator_def ($$);
476 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
478 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
479 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
480 unsmob_translator_def ($$)
481 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
484 | translator_spec_body CONSISTSEND STRING {
485 unsmob_translator_def ($$)->add_last_element ( $3);
487 | translator_spec_body ACCEPTS STRING {
488 unsmob_translator_def ($$)->set_acceptor ($3,true);
490 | translator_spec_body DENIES STRING {
491 unsmob_translator_def ($$)->set_acceptor ($3,false);
493 | translator_spec_body REMOVE STRING {
494 unsmob_translator_def ($$)->remove_element ($3);
503 THIS->remember_spot ();
505 /*cont*/ '{' score_body '}' {
508 if (!$$->def_p_arr_.size ())
510 Music_output_def *id =
511 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
512 $$->add_output (id ? id->clone () : new Paper_def );
521 $$->set_spot (THIS->here_input ());
522 SCM m = $1->self_scm ();
523 scm_unprotect_object (m);
527 $$ = new Score (*unsmob_score ($1));
528 $$->set_spot (THIS->here_input ());
530 | score_body lilypond_header {
531 scm_unprotect_object ($2->self_scm ());
534 | score_body output_def {
547 music_output_def_body '}' {
549 THIS-> lexer_p_-> scope_l_arr_.pop ();
553 music_output_def_body:
555 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
560 p = dynamic_cast<Midi_def*> (id->clone ());
565 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
568 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
571 p = dynamic_cast<Paper_def*> (id->clone ());
574 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
577 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
578 Music_output_def *p = unsmob_music_output_def ($3);
580 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
583 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
584 Music_output_def *p = unsmob_music_output_def ($3);
587 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
590 | music_output_def_body assignment {
593 | music_output_def_body translator_spec_block {
594 $$->assign_translator ($2);
596 | music_output_def_body STYLESHEET embedded_scm {
597 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
599 | music_output_def_body tempo_request {
601 junk this ? there already is tempo stuff in
604 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
605 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
606 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
608 | music_output_def_body error {
614 TEMPO steno_duration '=' bare_unsigned {
616 $$->set_mus_property ("duration", $2);
617 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
621 Music_list: /* empty */ {
622 $$ = gh_cons (SCM_EOL, SCM_EOL);
626 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
627 scm_unprotect_object ($2->self_scm ()); /* UGH */
628 if (gh_pair_p (gh_cdr (s)))
629 gh_set_cdr_x (gh_cdr (s), c); /* append */
631 gh_set_car_x (s, c); /* set first cons */
632 gh_set_cdr_x (s, c) ; /* remember last cell */
648 | ALTERNATIVE Music_sequence {
650 $2->set_spot (THIS->here_input ());
658 REPEAT string bare_unsigned Music Alternative_music
660 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
661 if (alts && $3 < alts->length_i ())
662 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
666 Repeated_music * r = new Repeated_music (SCM_EOL);
670 r-> set_mus_property ("body", beg->self_scm ());
671 scm_unprotect_object (beg->self_scm ());
673 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
677 alts->truncate (times);
678 r-> set_mus_property ("alternatives", alts->self_scm ());
679 scm_unprotect_object (alts->self_scm ());
681 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
682 SCM result = gh_call1 (func, $2);
684 set_music_properties (r, result);
686 r->set_spot (*$4->origin ());
691 Music_sequence: '{' Music_list '}' {
692 $$ = new Music_sequence (SCM_EOL);
693 $$->set_mus_property ("elements", gh_car ($2));
698 SEQUENTIAL '{' Music_list '}' {
699 $$ = new Sequential_music (SCM_EOL);
700 $$->set_mus_property ("elements", gh_car ($3));
702 | '{' Music_list '}' {
703 $$ = new Sequential_music (SCM_EOL);
704 $$->set_mus_property ("elements", gh_car ($2));
709 SIMULTANEOUS '{' Music_list '}'{
710 $$ = new Simultaneous_music (SCM_EOL);
711 $$->set_mus_property ("elements", gh_car ($3));
714 | '<' Music_list '>' {
715 $$ = new Simultaneous_music (SCM_EOL);
716 $$->set_mus_property ("elements", gh_car ($2));
721 request_chord { $$ = $1; }
722 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
724 if (!gh_symbol_p ($3))
726 THIS->parser_error (_ ("Second argument must be a symbol"));
728 /*hould check # args */
729 if (!gh_procedure_p (pred))
731 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
734 Music *m = new Music (SCM_EOL);
735 m->set_mus_property ("predicate", pred);
736 m->set_mus_property ("symbol", $3);
737 m->set_mus_property ("value", $5);
738 m->set_mus_property ("iterator-ctor",
739 Output_property_music_iterator::constructor_cxx_function);
744 $$ = unsmob_music ($1)->clone ();
752 CONTEXT STRING Music {
753 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
754 csm->set_mus_property ("element", $3->self_scm ());
755 scm_unprotect_object ($3->self_scm ());
757 csm->set_mus_property ("context-type",$2);
758 csm->set_mus_property ("context-id", ly_str02scm (""));
762 | AUTOCHANGE STRING Music {
763 Music * chm = new Music_wrapper (SCM_EOL);
764 chm->set_mus_property ("element", $3->self_scm ());
765 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
767 scm_unprotect_object ($3->self_scm ());
768 chm->set_mus_property ("what", $2);
771 chm->set_spot (*$3->origin ());
774 $$ = new Grace_music (SCM_EOL);
775 $$->set_mus_property ("element", $2->self_scm ());
776 scm_unprotect_object ($2->self_scm ());
779 | CONTEXT string '=' string Music {
780 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
781 csm->set_mus_property ("element", $5->self_scm ());
782 scm_unprotect_object ($5->self_scm ());
784 csm->set_mus_property ("context-type", $2);
785 csm->set_mus_property ("context-id", $4);
790 THIS->remember_spot ();
793 bare_unsigned '/' bare_unsigned Music
796 int n = $3; int d = $5;
798 $$ = new Time_scaled_music (SCM_EOL);
799 $$->set_spot (THIS->pop_spot ());
802 $$->set_mus_property ("element", mp->self_scm ());
803 scm_unprotect_object (mp->self_scm ());
804 $$->set_mus_property ("numerator", gh_int2scm (n));
805 $$->set_mus_property ("denominator", gh_int2scm (d));
806 $$->compress (Moment (n,d));
809 | Repeated_music { $$ = $1; }
810 | Simultaneous_music { $$ = $1; }
811 | Sequential_music { $$ = $1; }
812 | TRANSPOSE pitch Music {
813 $$ = new Transposed_music (SCM_EOL);
815 Pitch pit = *unsmob_pitch ($2);
818 $$->set_mus_property ("element", p->self_scm ());
819 scm_unprotect_object (p->self_scm ());
821 | TRANSPOSE steno_tonic_pitch Music {
822 $$ = new Transposed_music (SCM_EOL);
824 Pitch pit = *unsmob_pitch ($2);
827 $$->set_mus_property ("element", p->self_scm ());
828 scm_unprotect_object (p->self_scm ());
831 | APPLY embedded_scm Music {
832 SCM ret = gh_call1 ($2, $3->self_scm ());
833 Music *m = unsmob_music (ret);
835 THIS->parser_error ("\\apply must return a Music");
836 m = new Music (SCM_EOL);
841 { THIS->lexer_p_->push_note_state (); }
844 THIS->lexer_p_->pop_state ();
847 { THIS->lexer_p_->push_chord_state (); }
850 Music * chm = new Un_relativable_music ;
851 chm->set_mus_property ("element", $3->self_scm ());
854 THIS->lexer_p_->pop_state ();
857 { THIS->lexer_p_->push_lyric_state (); }
861 THIS->lexer_p_->pop_state ();
863 | relative_music { $$ = $1; }
864 | re_rhythmed_music { $$ = $1; }
865 | part_combined_music { $$ = $1; }
869 RELATIVE absolute_pitch Music {
871 Pitch pit = *unsmob_pitch ($2);
872 $$ = new Relative_octave_music (SCM_EOL);
874 $$->set_mus_property ("element", p->self_scm ());
875 scm_unprotect_object (p->self_scm ());
877 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
883 ADDLYRICS Music Music {
884 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
885 l->set_mus_property ("music", $2->self_scm ());
886 l->set_mus_property ("lyrics", $3->self_scm ());
887 scm_unprotect_object ($3->self_scm ());
888 scm_unprotect_object ($2->self_scm ());
894 PARTCOMBINE STRING Music Music {
895 Part_combine_music * p = new Part_combine_music (SCM_EOL);
897 p->set_mus_property ("what", $2);
898 p->set_mus_property ("one", $3->self_scm ());
899 p->set_mus_property ("two", $4->self_scm ());
901 scm_unprotect_object ($3->self_scm ());
902 scm_unprotect_object ($4->self_scm ());
910 TRANSLATOR STRING '=' STRING {
911 Music * t = new Music (SCM_EOL);
912 t->set_mus_property ("iterator-ctor",
913 Change_iterator::constructor_cxx_function);
914 t-> set_mus_property ("change-to-type", $2);
915 t-> set_mus_property ("change-to-id", $4);
918 $$->set_spot (THIS->here_input ());
923 PROPERTY STRING '.' STRING '=' scalar {
924 Music *t = new Music (SCM_EOL);
926 t->set_mus_property ("iterator-ctor",
927 Property_iterator::constructor_cxx_function);
928 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
929 t->set_mus_property ("value", $6);
931 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
933 csm->set_mus_property ("element", t->self_scm ());
934 scm_unprotect_object (t->self_scm ());
937 $$->set_spot (THIS->here_input ());
939 csm-> set_mus_property ("context-type", $2);
941 | PROPERTY STRING '.' STRING UNSET {
942 Music *t = new Music (SCM_EOL);
944 t->set_mus_property ("iterator-ctor",
945 Property_unset_iterator::constructor_cxx_function);
946 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
948 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
949 csm->set_mus_property ("element", t->self_scm ());
950 scm_unprotect_object (t->self_scm ());
953 $$->set_spot (THIS->here_input ());
955 csm-> set_mus_property ("context-type", $2);
957 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
958 Music *t = new Music (SCM_EOL);
959 t->set_mus_property ("iterator-ctor",
960 Push_property_iterator::constructor_cxx_function);
961 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
962 t->set_mus_property ("pop-first", SCM_BOOL_T);
963 t->set_mus_property ("grob-property", $6);
964 t->set_mus_property ("grob-value", $8);
965 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
966 csm->set_mus_property ("element", t->self_scm ());
967 scm_unprotect_object (t->self_scm ());
969 $$->set_spot (THIS->here_input ());
971 csm-> set_mus_property ("context-type", $2);
973 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
974 Music *t = new Music (SCM_EOL);
975 t->set_mus_property ("iterator-ctor",
976 Push_property_iterator::constructor_cxx_function);
977 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
978 t->set_mus_property ("grob-property", $6);
979 t->set_mus_property ("grob-value", $8);
980 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
981 csm->set_mus_property ("element", t->self_scm ());
982 scm_unprotect_object (t->self_scm ());
985 $$->set_spot (THIS->here_input ());
987 csm-> set_mus_property ("context-type", $2);
989 | PROPERTY STRING '.' STRING REVERT embedded_scm {
990 Music *t = new Music (SCM_EOL);
991 t->set_mus_property ("iterator-ctor",
992 Pop_property_iterator::constructor_cxx_function);
993 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
994 t->set_mus_property ("grob-property", $6);
996 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
997 csm->set_mus_property ("element", t->self_scm ());
998 scm_unprotect_object (t->self_scm ());
1001 $$->set_spot (THIS->here_input ());
1003 csm-> set_mus_property ("context-type", $2);
1009 | bare_int { $$ = gh_int2scm ($1); }
1010 | embedded_scm { $$ = $1; }
1015 pre_requests simple_element post_requests {
1016 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1018 for (int i=0; i < $1->size (); i++)
1019 l->append_music ($1->elem (i));
1020 for (int i=0; i < $3->size (); i++)
1021 l->append_music ($3->elem (i));
1024 programming_error ("Need Sequence to add music to");
1033 $$ = new Request_chord (SCM_EOL);
1034 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1035 $$-> set_spot (THIS->here_input ());
1036 $1-> set_spot (THIS->here_input ());
1039 Music *t = new Music (SCM_EOL);
1041 t->set_mus_property ("iterator-ctor",
1042 Property_iterator::constructor_cxx_function);
1043 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1044 t->set_mus_property ("value", $2);
1046 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1047 csm->set_mus_property ("element", t->self_scm ());
1048 scm_unprotect_object (t->self_scm ());
1051 $$->set_spot (THIS->here_input ());
1053 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1055 | PARTIAL duration_length {
1056 Music * p = new Music (SCM_EOL);
1057 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1058 p->set_mus_property ("iterator-ctor",
1059 Property_iterator::constructor_cxx_function);
1061 Moment m = - unsmob_duration ($2)->length_mom ();
1062 p->set_mus_property ("value", m.smobbed_copy ());
1064 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1065 sp->set_mus_property ("element", p->self_scm ());
1066 scm_unprotect_object (p->self_scm ());
1069 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1072 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1073 SCM result = gh_call1 (func, $2);
1076 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1077 Music * p = new Music (SCM_EOL);
1078 set_music_properties (p, gh_car (s));
1079 l = gh_cons (p->self_scm (), l);
1080 scm_unprotect_object (p->self_scm ());
1082 Sequential_music * seq = new Sequential_music (SCM_EOL);
1083 seq->set_mus_property ("elements", l);
1085 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1086 sp->set_mus_property ("element", seq->self_scm ());
1087 scm_unprotect_object (seq->self_scm ());
1090 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1092 | TIME_T bare_unsigned '/' bare_unsigned {
1093 Music * p = new Music (SCM_EOL);
1094 p->set_mus_property ("symbol",
1095 ly_symbol2scm ( "timeSignatureFraction"));
1096 p->set_mus_property ("iterator-ctor",
1097 Property_iterator::constructor_cxx_function);
1099 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1102 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1103 sp->set_mus_property ("element", p->self_scm ());
1104 scm_unprotect_object (p->self_scm ());
1109 TODO: should make alias TimingContext for Score
1112 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1117 shorthand_command_req { $$ = $1; }
1118 | verbose_command_req { $$ = $1; }
1121 shorthand_command_req:
1129 $$ = new Barcheck_req;
1135 Span_req*b= new Span_req;
1136 b->set_span_dir (START);
1137 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1141 Span_req*b= new Span_req;
1142 b->set_span_dir ( STOP);
1143 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1147 $$ = new Breathing_sign_req;
1152 verbose_command_req:
1153 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1154 Span_req * sp_p = new Span_req;
1155 sp_p-> set_span_dir ( Direction ($2));
1156 sp_p->set_mus_property ("span-type",$3);
1157 sp_p->set_spot (THIS->here_input ());
1161 Mark_req * m = new Mark_req;
1165 Mark_req *m = new Mark_req;
1166 m->set_mus_property ("label", $2);
1173 Break_req * b = new Break_req;
1175 if (!gh_number_p (s))
1178 b->set_mus_property ("penalty", s);
1179 b->set_spot (THIS->here_input ());
1182 | SKIP duration_length {
1183 Skip_req * skip_p = new Skip_req;
1184 skip_p->set_mus_property ("duration", $2);
1192 Key_change_req *key_p= new Key_change_req;
1195 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1196 Key_change_req *key_p= new Key_change_req;
1198 key_p->set_mus_property ("pitch-alist", $3);
1199 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1206 $$ = new Link_array<Request>;
1208 | post_requests post_request {
1209 $2->set_spot (THIS->here_input ());
1221 request_that_take_dir:
1224 | script_abbreviation {
1225 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1226 Articulation_req *a = new Articulation_req;
1227 if (gh_string_p (s))
1228 a->set_mus_property ("articulation-type", s);
1229 else THIS->parser_error (_ ("Expecting string as script definition"));
1235 script_dir request_that_take_dir {
1236 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1237 gs->set_direction (Direction ($1));
1239 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1245 REQUEST_IDENTIFIER {
1246 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1247 $$->set_spot (THIS->here_input ());
1249 | DYNAMICSCRIPT embedded_scm {
1251 TODO: junkme, use text-type == dynamic
1253 Text_script_req *d = new Text_script_req;
1254 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1255 d->set_mus_property ("text", $2);
1256 d->set_spot (THIS->here_input ());
1259 | SPANREQUEST bare_int STRING {
1260 Span_req * sp_p = new Span_req;
1261 sp_p->set_span_dir ( Direction ($2));
1262 sp_p->set_mus_property ("span-type", $3);
1263 sp_p->set_spot (THIS->here_input ());
1267 Tremolo_req* a = new Tremolo_req;
1268 a->set_spot (THIS->here_input ());
1269 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1273 Articulation_req * a = new Articulation_req;
1274 a->set_mus_property ("articulation-type", $2);
1275 a->set_spot (THIS->here_input ());
1279 duh, junk this syntax from the parser, if possible.
1282 Arpeggio_req *a = new Arpeggio_req;
1283 a->set_spot (THIS->here_input ());
1287 Glissando_req *g = new Glissando_req;
1288 g->set_spot /* No pun intended */ (THIS->here_input ());
1315 | NOTENAME_PITCH sup_quotes {
1316 Pitch p = *unsmob_pitch ($1);
1318 $$ = p.smobbed_copy ();
1320 | NOTENAME_PITCH sub_quotes {
1321 Pitch p =* unsmob_pitch ($1);
1324 $$ = p.smobbed_copy ();
1337 | TONICNAME_PITCH sup_quotes {
1338 Pitch p = *unsmob_pitch ($1);
1340 $$ = p.smobbed_copy ();
1342 | TONICNAME_PITCH sub_quotes {
1343 Pitch p =* unsmob_pitch ($1);
1346 $$ = p.smobbed_copy ();
1361 PITCH embedded_scm {
1363 if (!unsmob_pitch ($2)) {
1364 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1365 $$ = Pitch ().smobbed_copy ();
1371 DURATION embedded_scm {
1373 if (!unsmob_duration ($2))
1375 THIS->parser_error (_ ("Must have duration object"));
1376 $$ = Duration ().smobbed_copy ();
1383 if (!THIS->lexer_p_->lyric_state_b ())
1384 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1385 $$ = new Extender_req;
1391 if (!THIS->lexer_p_->lyric_state_b ())
1392 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1393 $$ = new Hyphen_req;
1398 close_request_parens {
1400 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1403 close_request_parens:
1405 Span_req* s= new Span_req;
1407 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1410 Span_req* s= new Span_req;
1412 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1415 Span_req*s =new Span_req;
1417 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1420 Span_req*s =new Span_req;
1422 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1428 open_request_parens {
1430 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1434 open_request_parens:
1436 Span_req *s = new Span_req;
1437 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 ( "slur"));
1447 Span_req* s= new Span_req;
1449 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1455 Text_script_req *t = new Text_script_req;
1456 t->set_mus_property ("text", $1);
1457 t->set_spot (THIS->here_input ());
1461 Text_script_req *t = new Text_script_req;
1462 t->set_mus_property ("text", $1);
1463 t->set_spot (THIS->here_input ());
1467 String ds = to_str ($1);
1468 Text_script_req* t = new Text_script_req;
1470 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1471 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1472 t->set_spot (THIS->here_input ());
1477 script_abbreviation:
1479 $$ = gh_str02scm ("hat");
1482 $$ = gh_str02scm ("plus");
1485 $$ = gh_str02scm ("dash");
1488 $$ = gh_str02scm ("bar");
1491 $$ = gh_str02scm ("larger");
1494 $$ = gh_str02scm ("dot");
1502 | '-' { $$ = CENTER; }
1507 $$ = new Link_array<Request>;
1509 | pre_requests open_request {
1521 multiplied_duration {
1524 | explicit_duration {
1529 optional_notemode_duration:
1531 $$ = THIS->default_duration_.smobbed_copy ();
1533 | multiplied_duration {
1536 | explicit_duration {
1542 bare_unsigned dots {
1544 if (!is_duration_b ($1))
1545 THIS->parser_error (_f ("not a duration: %d", $1));
1549 $$ = Duration (l, $2).smobbed_copy ();
1551 THIS->set_last_duration (unsmob_duration ($$));
1553 | DURATION_IDENTIFIER dots {
1554 Duration *d =unsmob_duration ($1);
1555 Duration k (d->duration_log (),d->dot_count () + $2);
1556 $$ = k.smobbed_copy ();
1558 THIS->set_last_duration (unsmob_duration ($$));
1565 multiplied_duration:
1569 | multiplied_duration '*' bare_unsigned {
1570 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1572 | multiplied_duration '/' bare_unsigned {
1573 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).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);
1673 | STRING optional_notemode_duration {
1675 Lyric_req* lreq_p = new Lyric_req;
1676 lreq_p->set_mus_property ("text", $1);
1677 lreq_p->set_mus_property ("duration",$2);
1678 lreq_p->set_spot (THIS->here_input ());
1679 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1680 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1687 if (!THIS->lexer_p_->chord_state_b ())
1688 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1695 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1696 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1697 $$->set_spot (THIS->here_input ());
1704 | CHORD_COLON chord_notes {
1713 | chord_notes '.' chord_step {
1714 $$ = gh_append2 ($$, $3);
1722 | CHORD_CARET chord_notes {
1732 | '/' steno_tonic_pitch {
1741 | CHORD_BASS steno_tonic_pitch {
1748 $$ = gh_cons ($1, SCM_EOL);
1750 | CHORDMODIFIER_PITCH {
1751 $$ = gh_cons ($1, SCM_EOL);
1753 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1754 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1761 m.notename_i_ = ($1 - 1) % 7;
1762 m.octave_i_ = $1 > 7 ? 1 : 0;
1763 m.alteration_i_ = 0;
1765 $$ = m.smobbed_copy ();
1767 | bare_unsigned '+' {
1769 m.notename_i_ = ($1 - 1) % 7;
1770 m.octave_i_ = $1 > 7 ? 1 : 0;
1771 m.alteration_i_ = 1;
1774 $$ = m.smobbed_copy ();
1776 | bare_unsigned CHORD_MINUS {
1778 m.notename_i_ = ($1 - 1) % 7;
1779 m.octave_i_ = $1 > 7 ? 1 : 0;
1780 m.alteration_i_ = -1;
1782 $$ = m.smobbed_copy ();
1793 | '-' number_expression %prec UNARY_MINUS {
1794 $$ = scm_difference ($2, SCM_UNDEFINED);
1796 | number_expression '*' number_expression {
1797 $$ = scm_product ($1, $3);
1799 | number_expression '/' number_expression {
1800 $$ = scm_divide ($1, $3);
1802 | number_expression '+' number_expression {
1803 $$ = scm_sum ($1, $3);
1805 | number_expression '-' number_expression {
1806 $$ = scm_difference ($1, $3);
1808 | '(' number_expression ')' {
1815 $$ = gh_int2scm ($1);
1820 | NUMBER_IDENTIFIER {
1824 $$ = gh_double2scm (gh_scm2double ($1) CM );
1827 $$ = gh_double2scm (gh_scm2double ($1) PT);
1830 $$ = gh_double2scm (gh_scm2double ($1) INCH);
1833 $$ = gh_double2scm (gh_scm2double ($1) MM);
1836 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
1852 if (scm_integer_p ($1) == SCM_BOOL_T)
1854 int k = gh_scm2int ($1);
1858 THIS->parser_error (_ ("need integer number arg"));
1872 | STRING_IDENTIFIER {
1875 | string '+' string {
1876 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1883 | exclamations '!' { $$ ++; }
1888 | questions '?' { $$ ++; }
1895 My_lily_parser::set_yydebug (bool b)
1902 extern My_lily_parser * current_parser;
1905 My_lily_parser::do_yyparse ()
1908 current_parser = this;;
1909 yyparse ((void*)this);