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"
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
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
245 %type <scm> entered_notemode_duration 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
269 %type <score> score_block score_body
271 %type <scm> translator_spec_block translator_spec_body
272 %type <tempo> tempo_request
273 %type <scm> notenames_body notenames_block chordmodifiers_block
274 %type <scm> script_abbreviation
284 lilypond: /* empty */
285 | lilypond toplevel_expression {}
286 | lilypond assignment { }
288 THIS->error_level_i_ = 1;
289 //THIS->parser_error (_ ("ly invalid"));
292 THIS->error_level_i_ = 1;
293 //THIS->parser_error (_ ("ly invalid"));
299 THIS->lexer_p_->pitchname_tab_ = $1;
301 | chordmodifiers_block {
302 THIS->lexer_p_->chordmodifier_tab_ = $1;
306 scm_unprotect_object (global_header_p->self_scm ());
307 global_header_p = $1;
310 score_global_array.push ($1);
314 if (dynamic_cast<Paper_def*> ($1))
315 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
316 else if (dynamic_cast<Midi_def*> ($1))
317 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
330 chordmodifiers_block:
331 CHORDMODIFIERS notenames_body { $$ = $2; }
336 PITCHNAMES notenames_body { $$ = $2; }
343 int i = scm_ilength ($1);
345 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
346 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
347 SCM pt = gh_cdar (s);
348 if (!unsmob_pitch (pt))
349 THIS->parser_error ("Need pitch object.");
351 scm_hashq_set_x (tab, gh_caar (s), pt);
358 lilypond_header_body:
360 $$ = new Scheme_hash_table;
362 Scope *sc = new Scope ($$);
363 THIS->lexer_p_-> scope_l_arr_.push (sc);
365 | lilypond_header_body assignment semicolon {
371 HEADER '{' lilypond_header_body '}' {
373 delete THIS->lexer_p_-> scope_l_arr_.pop ();
383 THIS->remember_spot ();
385 /* cont */ '=' identifier_init {
386 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
389 TODO: devise standard for protection in parser.
391 The parser stack lives on the C-stack, which means that
392 all objects can be unprotected as soon as they're here.
396 Should find generic way of associating input with objects.
406 $$ = $1->self_scm ();
407 scm_unprotect_object ($$);
410 $$ = $1->self_scm ();
411 scm_unprotect_object ($$);
413 | translator_spec_block {
417 $$ = $1->self_scm ();
418 scm_unprotect_object ($$);
421 $$ = $1->self_scm ();
422 scm_unprotect_object ($$);
424 | explicit_duration {
427 | number_expression {
438 translator_spec_block:
439 TRANSLATOR '{' translator_spec_body '}'
445 translator_spec_body:
446 TRANSLATOR_IDENTIFIER {
447 $$ = unsmob_translator_def ($1)->clone_scm ();
448 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
450 | TYPE STRING semicolon {
451 $$ = Translator_def::make_scm ();
452 Translator_def*td = unsmob_translator_def ($$);
453 td->translator_group_type_ = $2;
454 td->set_spot (THIS->here_input ());
456 | translator_spec_body STRING '=' embedded_scm {
457 unsmob_translator_def ($$)->add_property_assign ($2, $4);
459 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
460 unsmob_translator_def ($$)
461 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
463 | translator_spec_body STRING REVERT embedded_scm {
464 unsmob_translator_def ($$)->add_pop_property (
465 scm_string_to_symbol ($2), $4);
467 | translator_spec_body STRING '=' identifier_init semicolon {
468 SCM v = gh_int2scm (0);
469 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
472 THIS->parser_error (_ ("Wrong type for property value"));
475 unsmob_translator_def ($$)->add_property_assign ($2, v);
477 | translator_spec_body NAME STRING semicolon {
478 unsmob_translator_def ($$)->type_name_ = $3;
480 | translator_spec_body CONSISTS STRING semicolon {
481 unsmob_translator_def ($$)->add_element ($3);
483 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
484 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
485 unsmob_translator_def ($$)
486 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
489 | translator_spec_body CONSISTSEND STRING semicolon {
490 unsmob_translator_def ($$)->add_last_element ( $3);
492 | translator_spec_body ACCEPTS STRING semicolon {
493 unsmob_translator_def ($$)->set_acceptor ($3,true);
495 | translator_spec_body DENIES STRING semicolon {
496 unsmob_translator_def ($$)->set_acceptor ($3,false);
498 | translator_spec_body REMOVE STRING semicolon {
499 unsmob_translator_def ($$)->remove_element ($3);
508 THIS->remember_spot ();
510 /*cont*/ '{' score_body '}' {
513 if (!$$->def_p_arr_.size ())
515 Music_output_def *id =
516 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
517 $$->add_output (id ? id->clone () : new Paper_def );
526 $$->set_spot (THIS->here_input ());
527 SCM m = $1->self_scm ();
528 scm_unprotect_object (m);
532 $$ = new Score (*unsmob_score ($1));
533 $$->set_spot (THIS->here_input ());
535 | score_body lilypond_header {
536 scm_unprotect_object ($2->self_scm ());
539 | score_body output_def {
552 music_output_def_body '}' {
554 THIS-> lexer_p_-> scope_l_arr_.pop ();
558 music_output_def_body:
560 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
565 p = dynamic_cast<Midi_def*> (id->clone ());
570 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
573 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
576 p = dynamic_cast<Paper_def*> (id->clone ());
579 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
582 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
583 Music_output_def *p = unsmob_music_output_def ($3);
585 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
588 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
589 Music_output_def *p = unsmob_music_output_def ($3);
592 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
595 | music_output_def_body assignment semicolon {
598 | music_output_def_body translator_spec_block {
599 $$->assign_translator ($2);
601 | music_output_def_body STYLESHEET embedded_scm {
602 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
604 | music_output_def_body tempo_request semicolon {
606 junk this ? there already is tempo stuff in
609 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
610 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
611 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
613 | music_output_def_body error {
619 TEMPO steno_duration '=' bare_unsigned {
621 $$->set_mus_property ("duration", $2);
622 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
626 Music_list: /* empty */ {
627 $$ = gh_cons (SCM_EOL, SCM_EOL);
631 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
632 scm_unprotect_object ($2->self_scm ()); /* UGH */
633 if (gh_pair_p (gh_cdr (s)))
634 gh_set_cdr_x (gh_cdr (s), c); /* append */
636 gh_set_car_x (s, c); /* set first cons */
637 gh_set_cdr_x (s, c) ; /* remember last cell */
653 | ALTERNATIVE Music_sequence {
655 $2->set_spot (THIS->here_input ());
663 REPEAT string bare_unsigned Music Alternative_music
665 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
666 if (alts && $3 < alts->length_i ())
667 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
671 Repeated_music * r = new Repeated_music (SCM_EOL);
675 r-> set_mus_property ("body", beg->self_scm ());
676 scm_unprotect_object (beg->self_scm ());
678 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
682 alts->truncate (times);
683 r-> set_mus_property ("alternatives", alts->self_scm ());
684 scm_unprotect_object (alts->self_scm ());
686 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
687 SCM result = gh_call1 (func, $2);
689 set_music_properties (r, result);
691 r->set_spot (*$4->origin ());
696 Music_sequence: '{' Music_list '}' {
697 $$ = new Music_sequence (SCM_EOL);
698 $$->set_mus_property ("elements", gh_car ($2));
703 SEQUENTIAL '{' Music_list '}' {
704 $$ = new Sequential_music (SCM_EOL);
705 $$->set_mus_property ("elements", gh_car ($3));
707 | '{' Music_list '}' {
708 $$ = new Sequential_music (SCM_EOL);
709 $$->set_mus_property ("elements", gh_car ($2));
714 SIMULTANEOUS '{' Music_list '}'{
715 $$ = new Simultaneous_music (SCM_EOL);
716 $$->set_mus_property ("elements", gh_car ($3));
719 | '<' Music_list '>' {
720 $$ = new Simultaneous_music (SCM_EOL);
721 $$->set_mus_property ("elements", gh_car ($2));
726 request_chord { $$ = $1; }
727 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
729 if (!gh_symbol_p ($3))
731 THIS->parser_error (_ ("Second argument must be a symbol"));
733 /*hould check # args */
734 if (!gh_procedure_p (pred))
736 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
739 Music *m = new Music (SCM_EOL);
740 m->set_mus_property ("predicate", pred);
741 m->set_mus_property ("symbol", $3);
742 m->set_mus_property ("value", $5);
743 m->set_mus_property ("iterator-ctor",
744 Output_property_music_iterator::constructor_cxx_function);
749 $$ = unsmob_music ($1)->clone ();
753 | Simple_music '*' bare_unsigned '/' bare_unsigned {
755 $$->compress (Moment ($3, $5 ));
757 | Simple_music '*' bare_unsigned {
759 $$->compress (Moment ($3, 1));
765 CONTEXT STRING Music {
766 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
767 csm->set_mus_property ("element", $3->self_scm ());
768 scm_unprotect_object ($3->self_scm ());
770 csm->set_mus_property ("context-type",$2);
771 csm->set_mus_property ("context-id", ly_str02scm (""));
775 | AUTOCHANGE STRING Music {
776 Music * chm = new Music_wrapper (SCM_EOL);
777 chm->set_mus_property ("element", $3->self_scm ());
778 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
780 scm_unprotect_object ($3->self_scm ());
781 chm->set_mus_property ("what", $2);
784 chm->set_spot (*$3->origin ());
787 $$ = new Grace_music (SCM_EOL);
788 $$->set_mus_property ("element", $2->self_scm ());
789 scm_unprotect_object ($2->self_scm ());
792 | CONTEXT STRING '=' STRING Music {
793 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
794 csm->set_mus_property ("element", $5->self_scm ());
795 scm_unprotect_object ($5->self_scm ());
797 csm->set_mus_property ("context-type", $2);
798 csm->set_mus_property ("context-id", $4);
803 THIS->remember_spot ();
806 bare_unsigned '/' bare_unsigned Music
809 int n = $3; int d = $5;
811 $$ = new Time_scaled_music (SCM_EOL);
812 $$->set_spot (THIS->pop_spot ());
815 $$->set_mus_property ("element", mp->self_scm ());
816 scm_unprotect_object (mp->self_scm ());
817 $$->set_mus_property ("numerator", gh_int2scm (n));
818 $$->set_mus_property ("denominator", gh_int2scm (d));
819 $$->compress (Moment (n,d));
822 | Repeated_music { $$ = $1; }
823 | Simultaneous_music { $$ = $1; }
824 | Sequential_music { $$ = $1; }
825 | TRANSPOSE pitch Music {
826 $$ = new Transposed_music (SCM_EOL);
828 Pitch pit = *unsmob_pitch ($2);
831 $$->set_mus_property ("element", p->self_scm ());
832 scm_unprotect_object (p->self_scm ());
834 | TRANSPOSE steno_tonic_pitch Music {
835 $$ = new Transposed_music (SCM_EOL);
837 Pitch pit = *unsmob_pitch ($2);
840 $$->set_mus_property ("element", p->self_scm ());
841 scm_unprotect_object (p->self_scm ());
844 | APPLY embedded_scm Music {
845 SCM ret = gh_call1 ($2, $3->self_scm ());
846 Music *m = unsmob_music (ret);
848 THIS->parser_error ("\\apply must return a Music");
849 m = new Music (SCM_EOL);
854 { THIS->lexer_p_->push_note_state (); }
857 THIS->lexer_p_->pop_state ();
860 { THIS->lexer_p_->push_chord_state (); }
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 SET embedded_scm '=' embedded_scm {
952 Music *t = new Music (SCM_EOL);
953 t->set_mus_property ("iterator-ctor",
954 Push_property_iterator::constructor_cxx_function);
955 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
956 t->set_mus_property ("pop-first", SCM_BOOL_T);
957 t->set_mus_property ("grob-property", $6);
958 t->set_mus_property ("grob-value", $8);
959 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
960 csm->set_mus_property ("element", t->self_scm ());
961 scm_unprotect_object (t->self_scm ());
963 $$->set_spot (THIS->here_input ());
965 csm-> set_mus_property ("context-type", $2);
967 | PROPERTY STRING '.' STRING OVERRIDE 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 ("grob-property", $6);
973 t->set_mus_property ("grob-value", $8);
974 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
975 csm->set_mus_property ("element", t->self_scm ());
976 scm_unprotect_object (t->self_scm ());
979 $$->set_spot (THIS->here_input ());
981 csm-> set_mus_property ("context-type", $2);
983 | PROPERTY STRING '.' STRING REVERT embedded_scm {
984 Music *t = new Music (SCM_EOL);
985 t->set_mus_property ("iterator-ctor",
986 Pop_property_iterator::constructor_cxx_function);
987 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
988 t->set_mus_property ("grob-property", $6);
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);
1003 | bare_int { $$ = gh_int2scm ($1); }
1004 | embedded_scm { $$ = $1; }
1009 pre_requests simple_element post_requests {
1010 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1012 for (int i=0; i < $1->size (); i++)
1013 l->append_music ($1->elem (i));
1014 for (int i=0; i < $3->size (); i++)
1015 l->append_music ($3->elem (i));
1018 programming_error ("Need Sequence to add music to");
1027 $$ = new Request_chord (SCM_EOL);
1028 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1029 $$-> set_spot (THIS->here_input ());
1030 $1-> set_spot (THIS->here_input ());
1033 Music *t = new Music (SCM_EOL);
1035 t->set_mus_property ("iterator-ctor",
1036 Property_iterator::constructor_cxx_function);
1037 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1038 t->set_mus_property ("value", $2);
1040 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1041 csm->set_mus_property ("element", t->self_scm ());
1042 scm_unprotect_object (t->self_scm ());
1045 $$->set_spot (THIS->here_input ());
1047 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1049 | PARTIAL duration_length ';' {
1050 Music * p = new Music (SCM_EOL);
1051 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1052 p->set_mus_property ("iterator-ctor",
1053 Property_iterator::constructor_cxx_function);
1055 Moment m = - unsmob_duration ($2)->length_mom ();
1056 p->set_mus_property ("value", m.smobbed_copy ());
1058 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1059 sp->set_mus_property ("element", p->self_scm ());
1060 scm_unprotect_object (p->self_scm ());
1063 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1066 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1067 SCM result = gh_call1 (func, $2);
1070 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1071 Music * p = new Music (SCM_EOL);
1072 set_music_properties (p, gh_car (s));
1073 l = gh_cons (p->self_scm (), l);
1074 scm_unprotect_object (p->self_scm ());
1076 Sequential_music * seq = new Sequential_music (SCM_EOL);
1077 seq->set_mus_property ("elements", l);
1079 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1080 sp->set_mus_property ("element", seq->self_scm ());
1081 scm_unprotect_object (seq->self_scm ());
1084 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1086 | TIME_T bare_unsigned '/' bare_unsigned ';' {
1087 Music * p = new Music (SCM_EOL);
1088 p->set_mus_property ("symbol",
1089 ly_symbol2scm ( "timeSignatureFraction"));
1090 p->set_mus_property ("iterator-ctor",
1091 Property_iterator::constructor_cxx_function);
1093 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1096 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1097 sp->set_mus_property ("element", p->self_scm ());
1098 scm_unprotect_object (p->self_scm ());
1101 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1106 shorthand_command_req { $$ = $1; }
1107 | verbose_command_req semicolon { $$ = $1; }
1110 shorthand_command_req:
1118 $$ = new Barcheck_req;
1124 Span_req*b= new Span_req;
1125 b->set_span_dir (START);
1126 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1130 Span_req*b= new Span_req;
1131 b->set_span_dir ( STOP);
1132 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1136 $$ = new Breathing_sign_req;
1141 verbose_command_req:
1142 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1143 Span_req * sp_p = new Span_req;
1144 sp_p-> set_span_dir ( Direction ($2));
1145 sp_p->set_mus_property ("span-type",$3);
1146 sp_p->set_spot (THIS->here_input ());
1150 Mark_req * m = new Mark_req;
1154 Mark_req *m = new Mark_req;
1155 m->set_mus_property ("label", $2);
1159 | PENALTY bare_int {
1160 Break_req * b = new Break_req;
1161 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1162 b->set_spot (THIS->here_input ());
1165 | SKIP duration_length {
1166 Skip_req * skip_p = new Skip_req;
1167 skip_p->set_mus_property ("duration", $2);
1175 Key_change_req *key_p= new Key_change_req;
1178 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1179 Key_change_req *key_p= new Key_change_req;
1181 key_p->set_mus_property ("pitch-alist", $3);
1182 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1189 $$ = new Link_array<Request>;
1191 | post_requests post_request {
1192 $2->set_spot (THIS->here_input ());
1204 request_that_take_dir:
1207 | script_abbreviation {
1208 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1209 Articulation_req *a = new Articulation_req;
1210 if (gh_string_p (s))
1211 a->set_mus_property ("articulation-type", s);
1212 else THIS->parser_error (_ ("Expecting string as script definition"));
1218 script_dir request_that_take_dir {
1219 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1220 gs->set_direction (Direction ($1));
1222 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1228 REQUEST_IDENTIFIER {
1229 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1230 $$->set_spot (THIS->here_input ());
1232 | DYNAMICSCRIPT embedded_scm {
1234 TODO: junkme, use text-type == dynamic
1236 Text_script_req *d = new Text_script_req;
1237 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1238 d->set_mus_property ("text", $2);
1239 d->set_spot (THIS->here_input ());
1242 | TEXTSCRIPT embedded_scm {
1243 Text_script_req *t = new Text_script_req;
1244 t->set_mus_property ("text", $2);
1245 t->set_spot (THIS->here_input ());
1248 | SPANREQUEST bare_int STRING {
1249 Span_req * sp_p = new Span_req;
1250 sp_p->set_span_dir ( Direction ($2));
1251 sp_p->set_mus_property ("span-type", $3);
1252 sp_p->set_spot (THIS->here_input ());
1256 Tremolo_req* a = new Tremolo_req;
1257 a->set_spot (THIS->here_input ());
1258 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1263 Articulation_req * a = new Articulation_req;
1264 a->set_mus_property ("articulation-type", $2);
1265 a->set_spot (THIS->here_input ());
1269 duh, junk this syntax from the parser, if possible.
1272 Arpeggio_req *a = new Arpeggio_req;
1273 a->set_spot (THIS->here_input ());
1277 Glissando_req *g = new Glissando_req;
1278 g->set_spot /* No pun intended */ (THIS->here_input ());
1305 | NOTENAME_PITCH sup_quotes {
1306 Pitch p = *unsmob_pitch ($1);
1308 $$ = p.smobbed_copy ();
1310 | NOTENAME_PITCH sub_quotes {
1311 Pitch p =* unsmob_pitch ($1);
1314 $$ = p.smobbed_copy ();
1327 | TONICNAME_PITCH sup_quotes {
1328 Pitch p = *unsmob_pitch ($1);
1330 $$ = p.smobbed_copy ();
1332 | TONICNAME_PITCH sub_quotes {
1333 Pitch p =* unsmob_pitch ($1);
1336 $$ = p.smobbed_copy ();
1351 PITCH embedded_scm {
1353 if (!unsmob_pitch ($2)) {
1354 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1355 $$ = Pitch ().smobbed_copy ();
1361 DURATION embedded_scm {
1363 if (!unsmob_duration ($2))
1365 THIS->parser_error (_ ("Must have duration object"));
1366 $$ = Duration ().smobbed_copy ();
1373 if (!THIS->lexer_p_->lyric_state_b ())
1374 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1375 $$ = new Extender_req;
1381 if (!THIS->lexer_p_->lyric_state_b ())
1382 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1383 $$ = new Hyphen_req;
1388 close_request_parens {
1390 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1393 close_request_parens:
1395 Span_req* s= new Span_req;
1397 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1400 Span_req* s= new Span_req;
1402 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1405 Span_req*s =new Span_req;
1407 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1410 Span_req*s =new Span_req;
1412 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1418 open_request_parens {
1420 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1424 open_request_parens:
1426 Span_req *s = new Span_req;
1427 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1432 Span_req* s= new Span_req;
1434 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1437 Span_req* s= new Span_req;
1439 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1445 Text_script_req *t = new Text_script_req;
1446 t->set_mus_property ("text", $1);
1447 t->set_spot (THIS->here_input ());
1451 Text_script_req *t = new Text_script_req;
1452 t->set_mus_property ("text", $1);
1453 t->set_spot (THIS->here_input ());
1457 String ds = to_str ($1);
1458 Text_script_req* t = new Text_script_req;
1460 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1461 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1462 t->set_spot (THIS->here_input ());
1467 script_abbreviation:
1469 $$ = gh_str02scm ("hat");
1472 $$ = gh_str02scm ("plus");
1475 $$ = gh_str02scm ("dash");
1478 $$ = gh_str02scm ("bar");
1481 $$ = gh_str02scm ("larger");
1484 $$ = gh_str02scm ("dot");
1492 | '-' { $$ = CENTER; }
1497 $$ = new Link_array<Request>;
1499 | pre_requests open_request {
1514 | explicit_duration {
1517 | duration_length '*' bare_unsigned {
1518 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1520 | duration_length '/' bare_unsigned {
1521 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1525 entered_notemode_duration:
1527 THIS->set_last_duration (unsmob_duration ($1));
1531 optional_notemode_duration:
1533 $$ = THIS->default_duration_.smobbed_copy ();
1535 | entered_notemode_duration {
1538 | explicit_duration {
1544 bare_unsigned dots {
1546 if (!is_duration_b ($1))
1547 THIS->parser_error (_f ("not a duration: %d", $1));
1551 $$ = Duration (l, $2).smobbed_copy ();
1553 | DURATION_IDENTIFIER dots {
1554 Duration *d =unsmob_duration ($1);
1555 Duration k (d->duration_log (),d->dot_count () + $2);
1556 $$ = k.smobbed_copy ();
1574 | ':' bare_unsigned {
1575 if (!is_duration_b ($2))
1576 THIS->parser_error (_f ("not a duration: %d", $2));
1583 pitch exclamations questions optional_notemode_duration {
1584 if (!THIS->lexer_p_->note_state_b ())
1585 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1587 Note_req *n = new Note_req;
1589 n->set_mus_property ("pitch", $1);
1590 n->set_mus_property ("duration", $4);
1593 n->set_mus_property ("cautionary", SCM_BOOL_T);
1594 if ($2 % 2 || $3 % 2)
1595 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1597 Simultaneous_music*v = new Request_chord (SCM_EOL);
1598 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1601 FIXME: location is one off, since ptich & duration don't contain origin refs.
1603 v->set_spot (THIS->here_input ());
1604 n->set_spot (THIS->here_input ());
1608 | RESTNAME optional_notemode_duration {
1610 SCM e = SCM_UNDEFINED;
1611 if (ly_scm2string ($1) =="s")
1613 Skip_req * skip_p = new Skip_req;
1614 skip_p->set_mus_property ("duration" ,$2);
1616 skip_p->set_spot (THIS->here_input ());
1617 e = skip_p->self_scm ();
1621 Rest_req * rest_req_p = new Rest_req;
1622 rest_req_p->set_mus_property ("duration", $2);
1623 rest_req_p->set_spot (THIS->here_input ());
1624 e = rest_req_p->self_scm ();
1626 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1627 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1628 velt_p->set_spot (THIS->here_input ());
1633 | MULTI_MEASURE_REST optional_notemode_duration {
1634 Skip_req * sk = new Skip_req;
1635 sk->set_mus_property ("duration", $2);
1636 Span_req *sp1 = new Span_req;
1637 Span_req *sp2 = new Span_req;
1638 sp1-> set_span_dir ( START);
1639 sp2-> set_span_dir ( STOP);
1640 SCM r = ly_str02scm ("rest");
1641 sp1->set_mus_property ("span-type", r);
1642 sp2->set_mus_property ("span-type", r);
1644 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1645 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1646 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1647 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1648 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1649 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1651 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1653 $$ = new Sequential_music (SCM_EOL);
1654 $$->set_mus_property ("elements", ms);
1657 THIS->remember_spot ();
1660 optional_notemode_duration {
1661 if (!THIS->lexer_p_->lyric_state_b ()) {
1662 THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1663 THIS->error_level_i_ = 1;
1664 THIS->parser_error (_ ("Giving up"));
1668 Lyric_req* lreq_p = new Lyric_req;
1669 lreq_p->set_mus_property ("text", $1);
1670 lreq_p->set_mus_property ("duration",$3);
1671 lreq_p->set_spot (THIS->here_input ());
1672 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1673 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1680 if (!THIS->lexer_p_->chord_state_b ())
1681 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1688 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1689 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1690 $$->set_spot (THIS->here_input ());
1697 | CHORD_COLON chord_notes {
1706 | chord_notes '.' chord_step {
1707 $$ = gh_append2 ($$, $3);
1715 | CHORD_CARET chord_notes {
1725 | '/' steno_tonic_pitch {
1734 | CHORD_BASS steno_tonic_pitch {
1741 $$ = gh_cons ($1, SCM_EOL);
1743 | CHORDMODIFIER_PITCH {
1744 $$ = gh_cons ($1, SCM_EOL);
1746 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1747 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1754 m.notename_i_ = ($1 - 1) % 7;
1755 m.octave_i_ = $1 > 7 ? 1 : 0;
1756 m.alteration_i_ = 0;
1758 $$ = m.smobbed_copy ();
1760 | bare_unsigned '+' {
1762 m.notename_i_ = ($1 - 1) % 7;
1763 m.octave_i_ = $1 > 7 ? 1 : 0;
1764 m.alteration_i_ = 1;
1767 $$ = m.smobbed_copy ();
1769 | bare_unsigned CHORD_MINUS {
1771 m.notename_i_ = ($1 - 1) % 7;
1772 m.octave_i_ = $1 > 7 ? 1 : 0;
1773 m.alteration_i_ = -1;
1775 $$ = m.smobbed_copy ();
1786 | '-' number_expression %prec UNARY_MINUS {
1787 $$ = scm_difference ($2, SCM_UNDEFINED);
1789 | number_expression '*' number_expression {
1790 $$ = scm_product ($1, $3);
1792 | number_expression '/' number_expression {
1793 $$ = scm_divide ($1, $3);
1795 | number_expression '+' number_expression {
1796 $$ = scm_sum ($1, $3);
1798 | number_expression '-' number_expression {
1799 $$ = scm_difference ($1, $3);
1801 | '(' number_expression ')' {
1808 $$ = gh_int2scm ($1);
1811 $$ = gh_int2scm ($1);
1814 $$ = gh_double2scm ($1);
1816 | NUMBER_IDENTIFIER {
1820 $$ = gh_double2scm ($1 CM);
1823 $$ = gh_double2scm ($1 PT);
1826 $$ = gh_double2scm ($1 INCH);
1829 $$ = gh_double2scm ($1 MM);
1832 $$ = gh_double2scm ($1 CHAR);
1839 if (scm_integer_p ($1) == SCM_BOOL_T) {
1840 $$ = gh_scm2int ($1);
1843 THIS->parser_error (_ ("need integer number arg"));
1847 THIS->parser_error (_ ("Must be positive integer"));
1855 if (scm_integer_p ($1) == SCM_BOOL_T)
1857 int k = gh_scm2int ($1);
1861 THIS->parser_error (_ ("need integer number arg"));
1875 | STRING_IDENTIFIER {
1878 | string '+' string {
1879 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1886 | exclamations '!' { $$ ++; }
1891 | questions '?' { $$ ++; }
1902 My_lily_parser::set_yydebug (bool b)
1909 extern My_lily_parser * current_parser;
1912 My_lily_parser::do_yyparse ()
1915 current_parser = this;;
1916 yyparse ((void*)this);