1 %{ // -*-Fundamental-*-
4 parser.yy -- Bison/C++ parser for lilypond
6 source file of the GNU LilyPond music typesetter
8 (c) 1997--2000 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 "identifier.hh"
25 #include "command-request.hh"
26 #include "musical-request.hh"
27 #include "my-lily-parser.hh"
28 #include "context-specced-music.hh"
30 #include "music-list.hh"
31 #include "output-property-music-iterator.hh"
32 #include "property-iterator.hh"
33 #include "file-results.hh"
36 #include "relative-music.hh"
37 #include "lyric-combine-music.hh"
38 #include "transposed-music.hh"
39 #include "time-scaled-music.hh"
40 #include "repeated-music.hh"
41 #include "lilypond-input-version.hh"
42 #include "grace-music.hh"
43 #include "auto-change-music.hh"
44 #include "part-combine-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
87 #define THIS ((My_lily_parser *) my_lily_parser_l)
89 #define yyerror THIS->parser_error
90 #define ARRAY_SIZE(a,s) if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
97 Link_array<Request> *reqvec;
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
182 %token OVERRIDE SET REVERT
195 %token COMMANDSPANREQUEST
197 %token OUTPUTPROPERTY
206 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER
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 <id> SCORE_IDENTIFIER
219 %token <id> 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 <scope> 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_musical_pitch musical_pitch absolute_musical_pitch
250 %type <scm> 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;
305 delete header_global_p;
306 header_global_p = $1;
309 score_global_array.push ($1);
312 Identifier * id = new
313 Music_output_def_identifier ($1, MUSIC_OUTPUT_DEF_IDENTIFIER);
314 if (dynamic_cast<Paper_def*> ($1))
315 THIS->lexer_p_->set_identifier ("$defaultpaper", id->self_scm ());
316 else if (dynamic_cast<Midi_def*> ($1))
317 THIS->lexer_p_->set_identifier ("$defaultmidi", id->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:
361 THIS->lexer_p_-> scope_l_arr_.push ($$);
363 | lilypond_header_body assignment semicolon {
369 HEADER '{' lilypond_header_body '}' {
371 THIS->lexer_p_-> scope_l_arr_.pop ();
381 THIS->remember_spot ();
383 /* cont */ '=' identifier_init {
384 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
387 TODO: devise standard for protection in parser.
389 The parser stack lives on the C-stack, which means that
390 all objects can be unprotected as soon as they're here.
393 Identifier * id =unsmob_identifier ($4);
394 Input spot = THIS->pop_spot ();
395 if (id) id->set_spot (spot);
403 $$ = (new Score_identifier ($1, SCORE_IDENTIFIER))->self_scm();
406 $$ = (new Music_output_def_identifier ($1, MUSIC_OUTPUT_DEF_IDENTIFIER))->self_scm();
408 | translator_spec_block {
412 $$ = $1->self_scm ();
413 scm_unprotect_object ($$);
416 $$ = $1->self_scm ();
417 scm_unprotect_object ($$);
419 | explicit_duration {
422 | number_expression {
433 translator_spec_block:
434 TRANSLATOR '{' translator_spec_body '}'
440 translator_spec_body:
441 TRANSLATOR_IDENTIFIER {
442 $$ = unsmob_translator_def ($1)->clone_scm ();
443 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
445 | TYPE STRING semicolon {
446 $$ = Translator_def::make_scm ();
447 Translator_def*td = unsmob_translator_def ($$);
448 td->translator_group_type_ = $2;
449 td->set_spot (THIS->here_input ());
451 | translator_spec_body STRING '=' embedded_scm {
452 unsmob_translator_def ($$)->add_property_assign ($2, $4);
454 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
455 unsmob_translator_def ($$)
456 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
458 | translator_spec_body STRING REVERT embedded_scm {
459 unsmob_translator_def($$)->add_pop_property (
460 scm_string_to_symbol ($2), $4);
462 | translator_spec_body STRING '=' identifier_init semicolon {
463 SCM v = gh_int2scm (0);
464 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
467 THIS->parser_error (_("Wrong type for property value"));
470 unsmob_translator_def($$)->add_property_assign ($2, v);
472 | translator_spec_body NAME STRING semicolon {
473 unsmob_translator_def ($$)->type_name_ = $3;
475 | translator_spec_body CONSISTS STRING semicolon {
476 unsmob_translator_def ($$)->add_element ($3);
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 semicolon {
485 unsmob_translator_def ($$)->add_last_element ( $3);
487 | translator_spec_body ACCEPTS STRING semicolon {
488 unsmob_translator_def ($$)->set_acceptor ($3,true);
490 | translator_spec_body DENIES STRING semicolon {
491 unsmob_translator_def ($$)->set_acceptor ($3,false);
493 | translator_spec_body REMOVE STRING semicolon {
494 unsmob_translator_def ($$)->remove_element ($3);
503 THIS->remember_spot ();
505 /*cont*/ '{' score_body '}' {
508 if (!$$->def_p_arr_.size ())
511 unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
512 $$->add_output (id ? id->access_content_Music_output_def (true) : new Paper_def );
516 | SCORE '{' score_body error {
518 $$->set_spot (THIS->here_input ());
519 // THIS->here_input ().error ("SCORE INVALID");
520 $$->error ("SCORE INVALID");
521 THIS->parser_error (_f ("SCORE ERROR"));
530 $$->set_spot (THIS->here_input ());
531 SCM m = $1->self_scm ();
532 scm_unprotect_object (m);
536 $$ = $1->access_content_Score (true);
538 | score_body lilypond_header {
541 | score_body output_def {
554 music_output_def_body '}' {
556 THIS-> lexer_p_-> scope_l_arr_.pop();
560 music_output_def_body:
562 Identifier *id = unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
567 p = dynamic_cast<Midi_def*> (id->access_content_Music_output_def (true));
572 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
575 Identifier *id = unsmob_identifier (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
578 p = dynamic_cast<Paper_def*> (id->access_content_Music_output_def (true));
581 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
584 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
585 Music_output_def *p = $3->access_content_Music_output_def (true);
586 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
589 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
590 Music_output_def *p = $3->access_content_Music_output_def (true);
591 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
594 | music_output_def_body assignment semicolon {
597 | music_output_def_body translator_spec_block {
598 $$->assign_translator ($2);
600 | music_output_def_body STYLESHEET embedded_scm {
601 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
603 | music_output_def_body tempo_request semicolon {
605 junk this ? there already is tempo stuff in
608 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
609 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
610 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
612 | music_output_def_body error {
618 TEMPO steno_duration '=' bare_unsigned {
620 $$->set_mus_property ("duration", $2);
621 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
625 Music_list: /* empty */ {
626 $$ = gh_cons (SCM_EOL, SCM_EOL);
630 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
631 scm_unprotect_object ($2->self_scm ()); /* UGH */
634 if (gh_pair_p (gh_cdr (s)))
635 gh_set_cdr_x (gh_cdr (s), c); /* append */
637 gh_set_car_x (s, c); /* set first cons */
638 gh_set_cdr_x (s, c) ; /* remember last cell */
654 | ALTERNATIVE Music_sequence {
656 $2->set_spot (THIS->here_input ());
664 REPEAT STRING bare_unsigned Music Alternative_music
666 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
667 if (alts && $3 < alts->length_i ())
668 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
672 Repeated_music * r = new Repeated_music (SCM_EOL);
676 r-> set_mus_property ("body", beg->self_scm ());
677 scm_unprotect_object (beg->self_scm ());
679 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
683 alts->truncate (times);
684 r-> set_mus_property ("alternatives", alts->self_scm ());
685 scm_unprotect_object (alts->self_scm ());
687 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
688 SCM result = gh_call1 (func, $2);
690 set_music_properties (r, result);
692 r->set_spot (*$4->origin ());
697 Music_sequence: '{' Music_list '}' {
698 $$ = new Music_sequence (SCM_EOL);
699 $$->set_mus_property ("elements", gh_car ($2));
704 SEQUENTIAL '{' Music_list '}' {
705 $$ = new Sequential_music (SCM_EOL);
706 $$->set_mus_property ("elements", gh_car ($3));
708 | '{' Music_list '}' {
709 $$ = new Sequential_music (SCM_EOL);
710 $$->set_mus_property ("elements", gh_car ($2));
715 SIMULTANEOUS '{' Music_list '}'{
716 $$ = new Simultaneous_music (SCM_EOL);
717 $$->set_mus_property ("elements", gh_car ($3));
720 | '<' Music_list '>' {
721 $$ = new Simultaneous_music (SCM_EOL);
722 $$->set_mus_property ("elements", gh_car ($2));
727 request_chord { $$ = $1; }
728 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
730 if (!gh_symbol_p ($3))
732 THIS->parser_error (_("Second argument must be a symbol"));
734 /*hould check # args */
735 if (!gh_procedure_p (pred))
737 THIS->parser_error (_("First argument must be a procedure taking 1 argument"));
740 Music *m = new Music (SCM_EOL);
741 m->set_mus_property ("predicate", pred);
742 m->set_mus_property ("symbol", $3);
743 m->set_mus_property ("value", $5);
744 m->set_mus_property ("iterator-ctor",
745 Output_property_music_iterator::constructor_cxx_function);
750 $$ = unsmob_music ($1)->clone ();
754 | Simple_music '*' bare_unsigned '/' bare_unsigned {
756 $$->compress (Moment($3, $5 ));
758 | Simple_music '*' bare_unsigned {
760 $$->compress (Moment ($3, 1));
766 CONTEXT STRING Music {
767 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
768 csm->set_mus_property ("element", $3->self_scm ());
769 scm_unprotect_object ($3->self_scm ());
771 csm->set_mus_property ("context-type",$2);
772 csm->set_mus_property ("context-id", ly_str02scm (""));
776 | AUTOCHANGE STRING Music {
777 Auto_change_music * chm = new Auto_change_music (SCM_EOL);
778 chm->set_mus_property ("element", $3->self_scm ());
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 musical_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_musical_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 {
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 | MARK bare_unsigned {
1160 Mark_req *m = new Mark_req;
1161 m->set_mus_property ("label", gh_int2scm ($2));
1164 | PENALTY bare_int {
1165 Break_req * b = new Break_req;
1166 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1167 b->set_spot (THIS->here_input ());
1170 | SKIP duration_length {
1171 Skip_req * skip_p = new Skip_req;
1172 skip_p->set_mus_property ("duration", $2);
1180 Key_change_req *key_p= new Key_change_req;
1183 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1184 Key_change_req *key_p= new Key_change_req;
1186 key_p->set_mus_property ("pitch-alist", $3);
1187 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1194 $$ = new Link_array<Request>;
1196 | post_requests post_request {
1197 $2->set_spot (THIS->here_input ());
1209 request_that_take_dir:
1212 | script_abbreviation {
1213 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1214 Articulation_req *a = new Articulation_req;
1215 if (gh_string_p (s))
1216 a->set_mus_property ("articulation-type", s);
1217 else THIS->parser_error (_ ("Expecting string as script definition"));
1223 script_dir request_that_take_dir {
1224 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1225 gs->set_direction (Direction ($1));
1227 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1233 REQUEST_IDENTIFIER {
1234 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1235 $$->set_spot (THIS->here_input ());
1237 | DYNAMICSCRIPT embedded_scm {
1239 TODO: junkme, use text-type == dynamic
1241 Text_script_req *d = new Text_script_req;
1242 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1243 d->set_mus_property ("text", $2);
1244 d->set_spot (THIS->here_input ());
1247 | TEXTSCRIPT embedded_scm {
1248 Text_script_req *t = new Text_script_req;
1249 t->set_mus_property ("text", $2);
1250 t->set_spot (THIS->here_input ());
1253 | SPANREQUEST bare_int STRING {
1254 Span_req * sp_p = new Span_req;
1255 sp_p->set_span_dir( Direction($2));
1256 sp_p->set_mus_property ("span-type", $3);
1257 sp_p->set_spot (THIS->here_input ());
1261 Tremolo_req* a = new Tremolo_req;
1262 a->set_spot (THIS->here_input ());
1263 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1267 Articulation_req * a = new Articulation_req;
1268 a->set_mus_property ("articulation-type", $2);
1269 a->set_spot (THIS->here_input ());
1273 Arpeggio_req *a = new Arpeggio_req;
1274 a->set_spot (THIS->here_input ());
1278 Glissando_req *g = new Glissando_req;
1279 g->set_spot /* No pun intended */ (THIS->here_input ());
1302 steno_musical_pitch:
1306 | NOTENAME_PITCH sup_quotes {
1307 Pitch p = *unsmob_pitch ($1);
1309 $$ = p.smobbed_copy ();
1311 | NOTENAME_PITCH sub_quotes {
1312 Pitch p =* unsmob_pitch ($1);
1315 $$ = p.smobbed_copy ();
1328 | TONICNAME_PITCH sup_quotes {
1329 Pitch p = *unsmob_pitch ($1);
1331 $$ = p.smobbed_copy ();
1333 | TONICNAME_PITCH sub_quotes {
1334 Pitch p =* unsmob_pitch ($1);
1337 $$ = p.smobbed_copy ();
1343 steno_musical_pitch {
1346 | MUSICAL_PITCH embedded_scm {
1347 if (!unsmob_pitch ($2))
1348 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1350 $$ = m.smobbed_copy ();
1355 DURATION embedded_scm {
1357 if (!unsmob_duration ($2))
1359 THIS->parser_error (_("Must have duration object"));
1360 $$ = Duration ().smobbed_copy ();
1367 if (!THIS->lexer_p_->lyric_state_b ())
1368 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1369 $$ = new Extender_req;
1375 if (!THIS->lexer_p_->lyric_state_b ())
1376 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1377 $$ = new Hyphen_req;
1382 close_request_parens {
1384 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1387 close_request_parens:
1389 Span_req* s= new Span_req;
1391 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1394 Span_req*s =new Span_req;
1396 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1399 Span_req*s =new Span_req;
1401 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1407 open_request_parens {
1409 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1413 open_request_parens:
1415 Span_req *s = new Span_req;
1416 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1421 Span_req* s= new Span_req;
1423 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1429 Text_script_req *t = new Text_script_req;
1430 t->set_mus_property ("text", $1);
1431 t->set_spot (THIS->here_input ());
1435 Text_script_req *t = new Text_script_req;
1436 t->set_mus_property ("text", $1);
1437 t->set_spot (THIS->here_input ());
1441 String ds = to_str ($1);
1442 Text_script_req* t = new Text_script_req;
1444 t->set_mus_property ("text", ly_str02scm (ds.ch_C()));
1445 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1446 t->set_spot (THIS->here_input ());
1451 script_abbreviation:
1453 $$ = gh_str02scm ("hat");
1456 $$ = gh_str02scm("plus");
1459 $$ = gh_str02scm ("dash");
1462 $$ = gh_str02scm ("bar");
1465 $$ = gh_str02scm ("larger");
1468 $$ = gh_str02scm ("dot");
1476 | '-' { $$ = CENTER; }
1481 $$ = new Link_array<Request>;
1483 | pre_requests open_request {
1488 absolute_musical_pitch:
1489 steno_musical_pitch {
1498 | duration_length '*' bare_unsigned {
1499 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1501 | duration_length '/' bare_unsigned {
1502 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1506 entered_notemode_duration:
1508 THIS->set_last_duration (unsmob_duration ($1));
1512 optional_notemode_duration:
1514 $$ = THIS->default_duration_.smobbed_copy ();
1516 | entered_notemode_duration {
1522 bare_unsigned dots {
1524 if (!is_duration_b ($1))
1525 THIS->parser_error (_f ("not a duration: %d", $1));
1529 $$ = Duration (l, $2).smobbed_copy ();
1531 | DURATION_IDENTIFIER dots {
1532 Duration *d =unsmob_duration ($1);
1533 Duration k (d->duration_log (),d->dot_count () + $2);
1534 $$ = k.smobbed_copy ();
1552 | ':' bare_unsigned {
1553 if (!is_duration_b ($2))
1554 THIS->parser_error (_f ("not a duration: %d", $2));
1561 musical_pitch exclamations questions optional_notemode_duration {
1562 if (!THIS->lexer_p_->note_state_b ())
1563 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1565 Note_req *n = new Note_req;
1567 n->set_mus_property ("pitch", $1);
1568 n->set_mus_property ("duration", $4);
1571 n->set_mus_property ("cautionary", SCM_BOOL_T);
1572 if ($2 % 2 || $3 % 2)
1573 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1575 Simultaneous_music*v = new Request_chord (SCM_EOL);
1576 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1579 FIXME: location is one off, since ptich & duration don't contain origin refs.
1581 v->set_spot (THIS->here_input ());
1582 n->set_spot (THIS->here_input ());
1586 | RESTNAME optional_notemode_duration {
1588 SCM e = SCM_UNDEFINED;
1589 if (ly_scm2string ($1) =="s")
1591 Skip_req * skip_p = new Skip_req;
1592 skip_p->set_mus_property ("duration" ,$2);
1594 skip_p->set_spot (THIS->here_input());
1595 e = skip_p->self_scm ();
1599 Rest_req * rest_req_p = new Rest_req;
1600 rest_req_p->set_mus_property ("duration", $2);
1601 rest_req_p->set_spot (THIS->here_input());
1602 e = rest_req_p->self_scm ();
1604 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1605 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1606 velt_p->set_spot (THIS->here_input());
1611 | MEASURES optional_notemode_duration {
1612 Skip_req * sk = new Skip_req;
1613 sk->set_mus_property ("duration", $2);
1614 Span_req *sp1 = new Span_req;
1615 Span_req *sp2 = new Span_req;
1616 sp1-> set_span_dir ( START);
1617 sp2-> set_span_dir ( STOP);
1618 SCM r = ly_str02scm ("rest");
1619 sp1->set_mus_property ("span-type", r);
1620 sp2->set_mus_property ("span-type", r);
1622 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1623 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1624 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1625 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1626 Request_chord * rqc3 = new Request_chord(SCM_EOL);
1627 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1629 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1631 $$ = new Sequential_music (SCM_EOL);
1632 $$->set_mus_property ("elements", ms);
1635 THIS->remember_spot ();
1638 optional_notemode_duration {
1639 if (!THIS->lexer_p_->lyric_state_b ()) {
1640 THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1641 THIS->error_level_i_ = 1;
1642 THIS->parser_error (_ ("Giving up"));
1646 Lyric_req* lreq_p = new Lyric_req;
1647 lreq_p->set_mus_property ("text", $1);
1648 lreq_p->set_mus_property ("duration",$3);
1649 lreq_p->set_spot (THIS->here_input());
1650 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1651 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1658 if (!THIS->lexer_p_->chord_state_b ())
1659 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1666 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1667 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1668 $$->set_spot (THIS->here_input ());
1675 | CHORD_COLON chord_notes {
1684 | chord_notes '.' chord_step {
1685 $$ = gh_append2 ($$, $3);
1693 | CHORD_CARET chord_notes {
1703 | '/' steno_tonic_pitch {
1712 | CHORD_BASS steno_tonic_pitch {
1719 $$ = gh_cons ($1, SCM_EOL);
1721 | CHORDMODIFIER_PITCH {
1722 $$ = gh_cons ($1, SCM_EOL);
1724 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1725 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1732 m.notename_i_ = ($1 - 1) % 7;
1733 m.octave_i_ = $1 > 7 ? 1 : 0;
1734 m.alteration_i_ = 0;
1736 $$ = m.smobbed_copy ();
1738 | bare_unsigned '+' {
1740 m.notename_i_ = ($1 - 1) % 7;
1741 m.octave_i_ = $1 > 7 ? 1 : 0;
1742 m.alteration_i_ = 1;
1745 $$ = m.smobbed_copy ();
1747 | bare_unsigned CHORD_MINUS {
1749 m.notename_i_ = ($1 - 1) % 7;
1750 m.octave_i_ = $1 > 7 ? 1 : 0;
1751 m.alteration_i_ = -1;
1753 $$ = m.smobbed_copy ();
1764 | '-' number_expression %prec UNARY_MINUS {
1765 $$ = scm_difference ($2, SCM_UNDEFINED);
1767 | number_expression '*' number_expression {
1768 $$ = scm_product ($1, $3);
1770 | number_expression '/' number_expression {
1771 $$ = scm_divide ($1, $3);
1773 | number_expression '+' number_expression {
1774 $$ = scm_sum ($1, $3);
1776 | number_expression '-' number_expression {
1777 $$ = scm_difference ($1, $3);
1779 | '(' number_expression ')' {
1786 $$ = gh_int2scm ($1);
1789 $$ = gh_int2scm ($1);
1792 $$ = gh_double2scm ($1);
1794 | NUMBER_IDENTIFIER {
1798 $$ = gh_double2scm ($1 CM);
1801 $$ = gh_double2scm ($1 PT);
1804 $$ = gh_double2scm ($1 INCH);
1807 $$ = gh_double2scm ($1 MM);
1810 $$ = gh_double2scm ($1 CHAR);
1817 if (scm_integer_p ($1) == SCM_BOOL_T) {
1818 $$ = gh_scm2int ($1);
1821 THIS->parser_error (_("need integer number arg"));
1825 THIS->parser_error (_("Must be positive integer"));
1833 if (scm_integer_p ($1) == SCM_BOOL_T)
1835 int k = gh_scm2int ($1);
1839 THIS->parser_error (_("need integer number arg"));
1853 | STRING_IDENTIFIER {
1856 | string '+' string {
1857 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1864 | exclamations '!' { $$ ++; }
1869 | questions '?' { $$ ++; }
1880 My_lily_parser::set_yydebug (bool b)
1887 extern My_lily_parser * current_parser;
1890 My_lily_parser::do_yyparse ()
1893 current_parser = this;;
1894 yyparse ((void*)this);