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
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;
102 Scheme_hash_table *scmhash;
104 Music_output_def * outputdef;
110 /* We use SCMs to do strings, because it saves us the trouble of
111 deleting them. Let's hope that a stack overflow doesnt trigger a move
112 of the parse stack onto the heap. */
122 yylex (YYSTYPE *s, void * v_l)
124 My_lily_parser *pars_l = (My_lily_parser*) v_l;
125 My_lily_lexer * lex_l = pars_l->lexer_p_;
127 lex_l->lexval_l = (void*) s;
128 return lex_l->yylex ();
136 /* tokens which are not keywords */
146 %token CHORDMODIFIERS
154 %token ELEMENTDESCRIPTIONS
170 %token MULTI_MEASURE_REST
181 %token OVERRIDE SET REVERT
194 %token COMMANDSPANREQUEST
196 %token OUTPUTPROPERTY
205 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
206 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
208 %type <i> exclamations questions dots
210 %token <scm> NOTENAME_PITCH
211 %token <scm> TONICNAME_PITCH
212 %token <scm> CHORDMODIFIER_PITCH
213 %token <scm> DURATION_IDENTIFIER
214 %token <id> IDENTIFIER
217 %token <scm> SCORE_IDENTIFIER
218 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
220 %token <scm> NUMBER_IDENTIFIER
221 %token <scm> REQUEST_IDENTIFIER
222 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
223 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
224 %token <scm> RESTNAME
230 %type <outputdef> output_def
231 %type <scmhash> lilypond_header lilypond_header_body
232 %type <request> open_request_parens close_request_parens open_request close_request
233 %type <request> request_with_dir request_that_take_dir verbose_request
234 %type <i> sub_quotes sup_quotes
235 %type <music> simple_element request_chord command_element Simple_music Composite_music
236 %type <music> Alternative_music Repeated_music
237 %type <i> tremolo_type
238 %type <i> bare_int bare_unsigned
241 %type <scm> identifier_init
243 %type <scm> steno_duration optional_notemode_duration
244 %type <scm> entered_notemode_duration explicit_duration
246 %type <reqvec> pre_requests post_requests
247 %type <request> gen_text_def
248 %type <scm> steno_pitch pitch absolute_pitch
249 %type <scm> explicit_pitch steno_tonic_pitch
251 %type <scm> chord_additions chord_subtractions chord_notes chord_step
253 %type <scm> chord_note chord_inversion chord_bass
254 %type <scm> duration_length
256 %type <scm> embedded_scm scalar
257 %type <music> Music Sequential_music Simultaneous_music Music_sequence
258 %type <music> relative_music re_rhythmed_music part_combined_music
259 %type <music> property_def translator_change
260 %type <scm> Music_list
261 %type <outputdef> music_output_def_body
262 %type <request> shorthand_command_req
263 %type <request> post_request
264 %type <music> command_req verbose_command_req
265 %type <request> extender_req
266 %type <request> hyphen_req
267 %type <scm> string bare_number number_expression
268 %type <score> score_block score_body
270 %type <scm> translator_spec_block translator_spec_body
271 %type <tempo> tempo_request
272 %type <scm> notenames_body notenames_block chordmodifiers_block
273 %type <scm> script_abbreviation
283 lilypond: /* empty */
284 | lilypond toplevel_expression {}
285 | lilypond assignment { }
287 THIS->error_level_i_ = 1;
288 //THIS->parser_error (_ ("ly invalid"));
291 THIS->error_level_i_ = 1;
292 //THIS->parser_error (_ ("ly invalid"));
298 THIS->lexer_p_->pitchname_tab_ = $1;
300 | chordmodifiers_block {
301 THIS->lexer_p_->chordmodifier_tab_ = $1;
305 scm_unprotect_object (global_header_p->self_scm ());
306 global_header_p = $1;
309 score_global_array.push ($1);
313 if (dynamic_cast<Paper_def*> ($1))
314 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
315 else if (dynamic_cast<Midi_def*> ($1))
316 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
329 chordmodifiers_block:
330 CHORDMODIFIERS notenames_body { $$ = $2; }
335 PITCHNAMES notenames_body { $$ = $2; }
342 int i = scm_ilength ($1);
344 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
345 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
346 SCM pt = gh_cdar (s);
347 if (!unsmob_pitch (pt))
348 THIS->parser_error ("Need pitch object.");
350 scm_hashq_set_x (tab, gh_caar(s), pt);
357 lilypond_header_body:
359 $$ = new Scheme_hash_table;
361 Scope *sc = new Scope ($$);
362 THIS->lexer_p_-> scope_l_arr_.push (sc);
364 | lilypond_header_body assignment semicolon {
370 HEADER '{' lilypond_header_body '}' {
372 delete THIS->lexer_p_-> scope_l_arr_.pop ();
382 THIS->remember_spot ();
384 /* cont */ '=' identifier_init {
385 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
388 TODO: devise standard for protection in parser.
390 The parser stack lives on the C-stack, which means that
391 all objects can be unprotected as soon as they're here.
395 Should find generic way of associating input with objects.
405 $$ = $1->self_scm ();
406 scm_unprotect_object ($$);
409 $$ = $1->self_scm ();
410 scm_unprotect_object ($$);
412 | translator_spec_block {
416 $$ = $1->self_scm ();
417 scm_unprotect_object ($$);
420 $$ = $1->self_scm ();
421 scm_unprotect_object ($$);
423 | explicit_duration {
426 | number_expression {
437 translator_spec_block:
438 TRANSLATOR '{' translator_spec_body '}'
444 translator_spec_body:
445 TRANSLATOR_IDENTIFIER {
446 $$ = unsmob_translator_def ($1)->clone_scm ();
447 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
449 | TYPE STRING semicolon {
450 $$ = Translator_def::make_scm ();
451 Translator_def*td = unsmob_translator_def ($$);
452 td->translator_group_type_ = $2;
453 td->set_spot (THIS->here_input ());
455 | translator_spec_body STRING '=' embedded_scm {
456 unsmob_translator_def ($$)->add_property_assign ($2, $4);
458 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
459 unsmob_translator_def ($$)
460 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
462 | translator_spec_body STRING REVERT embedded_scm {
463 unsmob_translator_def($$)->add_pop_property (
464 scm_string_to_symbol ($2), $4);
466 | translator_spec_body STRING '=' identifier_init semicolon {
467 SCM v = gh_int2scm (0);
468 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
471 THIS->parser_error (_("Wrong type for property value"));
474 unsmob_translator_def($$)->add_property_assign ($2, v);
476 | translator_spec_body NAME STRING semicolon {
477 unsmob_translator_def ($$)->type_name_ = $3;
479 | translator_spec_body CONSISTS STRING semicolon {
480 unsmob_translator_def ($$)->add_element ($3);
482 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
483 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
484 unsmob_translator_def ($$)
485 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
488 | translator_spec_body CONSISTSEND STRING semicolon {
489 unsmob_translator_def ($$)->add_last_element ( $3);
491 | translator_spec_body ACCEPTS STRING semicolon {
492 unsmob_translator_def ($$)->set_acceptor ($3,true);
494 | translator_spec_body DENIES STRING semicolon {
495 unsmob_translator_def ($$)->set_acceptor ($3,false);
497 | translator_spec_body REMOVE STRING semicolon {
498 unsmob_translator_def ($$)->remove_element ($3);
507 THIS->remember_spot ();
509 /*cont*/ '{' score_body '}' {
512 if (!$$->def_p_arr_.size ())
514 Music_output_def *id =
515 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
516 $$->add_output (id ? id->clone () : new Paper_def );
525 $$->set_spot (THIS->here_input ());
526 SCM m = $1->self_scm ();
527 scm_unprotect_object (m);
531 $$ = new Score (*unsmob_score ($1));
532 $$->set_spot (THIS->here_input ());
534 | score_body lilypond_header {
535 scm_unprotect_object ($2->self_scm ());
538 | score_body output_def {
551 music_output_def_body '}' {
553 THIS-> lexer_p_-> scope_l_arr_.pop();
557 music_output_def_body:
559 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
564 p = dynamic_cast<Midi_def*> (id->clone ());
569 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
572 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
575 p = dynamic_cast<Paper_def*> (id->clone ());
578 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
581 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
582 Music_output_def *p = unsmob_music_output_def ($3);
584 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
587 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
588 Music_output_def *p = unsmob_music_output_def ($3);
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 */
632 if (gh_pair_p (gh_cdr (s)))
633 gh_set_cdr_x (gh_cdr (s), c); /* append */
635 gh_set_car_x (s, c); /* set first cons */
636 gh_set_cdr_x (s, c) ; /* remember last cell */
652 | ALTERNATIVE Music_sequence {
654 $2->set_spot (THIS->here_input ());
662 REPEAT string bare_unsigned Music Alternative_music
664 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
665 if (alts && $3 < alts->length_i ())
666 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
670 Repeated_music * r = new Repeated_music (SCM_EOL);
674 r-> set_mus_property ("body", beg->self_scm ());
675 scm_unprotect_object (beg->self_scm ());
677 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
681 alts->truncate (times);
682 r-> set_mus_property ("alternatives", alts->self_scm ());
683 scm_unprotect_object (alts->self_scm ());
685 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
686 SCM result = gh_call1 (func, $2);
688 set_music_properties (r, result);
690 r->set_spot (*$4->origin ());
695 Music_sequence: '{' Music_list '}' {
696 $$ = new Music_sequence (SCM_EOL);
697 $$->set_mus_property ("elements", gh_car ($2));
702 SEQUENTIAL '{' Music_list '}' {
703 $$ = new Sequential_music (SCM_EOL);
704 $$->set_mus_property ("elements", gh_car ($3));
706 | '{' Music_list '}' {
707 $$ = new Sequential_music (SCM_EOL);
708 $$->set_mus_property ("elements", gh_car ($2));
713 SIMULTANEOUS '{' Music_list '}'{
714 $$ = new Simultaneous_music (SCM_EOL);
715 $$->set_mus_property ("elements", gh_car ($3));
718 | '<' Music_list '>' {
719 $$ = new Simultaneous_music (SCM_EOL);
720 $$->set_mus_property ("elements", gh_car ($2));
725 request_chord { $$ = $1; }
726 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
728 if (!gh_symbol_p ($3))
730 THIS->parser_error (_("Second argument must be a symbol"));
732 /*hould check # args */
733 if (!gh_procedure_p (pred))
735 THIS->parser_error (_("First argument must be a procedure taking 1 argument"));
738 Music *m = new Music (SCM_EOL);
739 m->set_mus_property ("predicate", pred);
740 m->set_mus_property ("symbol", $3);
741 m->set_mus_property ("value", $5);
742 m->set_mus_property ("iterator-ctor",
743 Output_property_music_iterator::constructor_cxx_function);
748 $$ = unsmob_music ($1)->clone ();
752 | Simple_music '*' bare_unsigned '/' bare_unsigned {
754 $$->compress (Moment($3, $5 ));
756 | Simple_music '*' bare_unsigned {
758 $$->compress (Moment ($3, 1));
764 CONTEXT STRING Music {
765 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
766 csm->set_mus_property ("element", $3->self_scm ());
767 scm_unprotect_object ($3->self_scm ());
769 csm->set_mus_property ("context-type",$2);
770 csm->set_mus_property ("context-id", ly_str02scm (""));
774 | AUTOCHANGE STRING Music {
775 Music * chm = new Music_wrapper (SCM_EOL);
776 chm->set_mus_property ("element", $3->self_scm ());
777 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
779 scm_unprotect_object ($3->self_scm ());
780 chm->set_mus_property ("what", $2);
783 chm->set_spot (*$3->origin ());
786 $$ = new Grace_music (SCM_EOL);
787 $$->set_mus_property ("element", $2->self_scm ());
788 scm_unprotect_object ($2->self_scm ());
791 | CONTEXT STRING '=' STRING Music {
792 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
793 csm->set_mus_property ("element", $5->self_scm ());
794 scm_unprotect_object ($5->self_scm ());
796 csm->set_mus_property ("context-type", $2);
797 csm->set_mus_property ("context-id", $4);
802 THIS->remember_spot ();
805 bare_unsigned '/' bare_unsigned Music
808 int n = $3; int d = $5;
810 $$ = new Time_scaled_music (SCM_EOL);
811 $$->set_spot (THIS->pop_spot ());
814 $$->set_mus_property ("element", mp->self_scm ());
815 scm_unprotect_object (mp->self_scm ());
816 $$->set_mus_property ("numerator", gh_int2scm (n));
817 $$->set_mus_property ("denominator", gh_int2scm (d));
818 $$->compress (Moment (n,d));
821 | Repeated_music { $$ = $1; }
822 | Simultaneous_music { $$ = $1; }
823 | Sequential_music { $$ = $1; }
824 | TRANSPOSE pitch Music {
825 $$ = new Transposed_music (SCM_EOL);
827 Pitch pit = *unsmob_pitch ($2);
830 $$->set_mus_property ("element", p->self_scm ());
831 scm_unprotect_object (p->self_scm ());
833 | TRANSPOSE steno_tonic_pitch Music {
834 $$ = new Transposed_music (SCM_EOL);
836 Pitch pit = *unsmob_pitch ($2);
839 $$->set_mus_property ("element", p->self_scm ());
840 scm_unprotect_object (p->self_scm ());
843 | APPLY embedded_scm Music {
844 SCM ret = gh_call1 ($2, $3->self_scm ());
845 Music *m = unsmob_music (ret);
847 THIS->parser_error ("\\apply must return a Music");
848 m = new Music (SCM_EOL);
853 { THIS->lexer_p_->push_note_state (); }
856 THIS->lexer_p_->pop_state ();
859 { THIS->lexer_p_->push_chord_state (); }
863 THIS->lexer_p_->pop_state ();
866 { THIS->lexer_p_->push_lyric_state (); }
870 THIS->lexer_p_->pop_state ();
872 | relative_music { $$ = $1; }
873 | re_rhythmed_music { $$ = $1; }
874 | part_combined_music { $$ = $1; }
878 RELATIVE absolute_pitch Music {
880 Pitch pit = *unsmob_pitch ($2);
881 $$ = new Relative_octave_music (SCM_EOL);
883 $$->set_mus_property ("element", p->self_scm ());
884 scm_unprotect_object (p->self_scm ());
886 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
892 ADDLYRICS Music Music {
893 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
894 l->set_mus_property ("music", $2->self_scm ());
895 l->set_mus_property ("lyrics", $3->self_scm ());
896 scm_unprotect_object ($3->self_scm ());
897 scm_unprotect_object ($2->self_scm ());
903 PARTCOMBINE STRING Music Music {
904 Part_combine_music * p = new Part_combine_music (SCM_EOL);
906 p->set_mus_property ("what", $2);
907 p->set_mus_property ("one", $3->self_scm ());
908 p->set_mus_property ("two", $4->self_scm ());
910 scm_unprotect_object ($3->self_scm());
911 scm_unprotect_object ($4->self_scm());
919 TRANSLATOR STRING '=' STRING {
920 Music * t = new Music (SCM_EOL);
921 t->set_mus_property ("iterator-ctor",
922 Change_iterator::constructor_cxx_function);
923 t-> set_mus_property ("change-to-type", $2);
924 t-> set_mus_property ("change-to-id", $4);
927 $$->set_spot (THIS->here_input ());
932 PROPERTY STRING '.' STRING '=' scalar {
933 Music *t = new Music (SCM_EOL);
935 t->set_mus_property ("iterator-ctor",
936 Property_iterator::constructor_cxx_function);
937 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
938 t->set_mus_property ("value", $6);
940 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
942 csm->set_mus_property ("element", t->self_scm ());
943 scm_unprotect_object (t->self_scm ());
946 $$->set_spot (THIS->here_input ());
948 csm-> set_mus_property ("context-type", $2);
950 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
951 Music *t = new Music (SCM_EOL);
952 t->set_mus_property ("iterator-ctor",
953 Push_property_iterator::constructor_cxx_function);
954 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
955 t->set_mus_property ("pop-first", SCM_BOOL_T);
956 t->set_mus_property ("grob-property", $6);
957 t->set_mus_property ("grob-value", $8);
958 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
959 csm->set_mus_property ("element", t->self_scm ());
960 scm_unprotect_object (t->self_scm ());
962 $$->set_spot (THIS->here_input ());
964 csm-> set_mus_property ("context-type", $2);
966 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
967 Music *t = new Music (SCM_EOL);
968 t->set_mus_property ("iterator-ctor",
969 Push_property_iterator::constructor_cxx_function);
970 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
971 t->set_mus_property ("grob-property", $6);
972 t->set_mus_property ("grob-value", $8);
973 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
974 csm->set_mus_property ("element", t->self_scm ());
975 scm_unprotect_object (t->self_scm ());
978 $$->set_spot (THIS->here_input ());
980 csm-> set_mus_property ("context-type", $2);
982 | PROPERTY STRING '.' STRING REVERT embedded_scm {
983 Music *t = new Music (SCM_EOL);
984 t->set_mus_property ("iterator-ctor",
985 Pop_property_iterator::constructor_cxx_function);
986 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
987 t->set_mus_property ("grob-property", $6);
989 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
990 csm->set_mus_property ("element", t->self_scm ());
991 scm_unprotect_object (t->self_scm ());
994 $$->set_spot (THIS->here_input ());
996 csm-> set_mus_property ("context-type", $2);
1002 | bare_int { $$ = gh_int2scm ($1); }
1003 | embedded_scm { $$ = $1; }
1008 pre_requests simple_element post_requests {
1009 Music_sequence *l = dynamic_cast<Music_sequence*>($2);
1011 for (int i=0; i < $1->size(); i++)
1012 l->append_music ($1->elem(i));
1013 for (int i=0; i < $3->size(); i++)
1014 l->append_music ($3->elem(i));
1017 programming_error ("Need Sequence to add music to");
1026 $$ = new Request_chord (SCM_EOL);
1027 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1028 $$-> set_spot (THIS->here_input ());
1029 $1-> set_spot (THIS->here_input ());
1032 Music *t = new Music (SCM_EOL);
1034 t->set_mus_property ("iterator-ctor",
1035 Property_iterator::constructor_cxx_function);
1036 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1037 t->set_mus_property ("value", $2);
1039 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1040 csm->set_mus_property ("element", t->self_scm ());
1041 scm_unprotect_object (t->self_scm ());
1044 $$->set_spot (THIS->here_input ());
1046 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1048 | PARTIAL duration_length ';' {
1049 Music * p = new Music (SCM_EOL);
1050 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1051 p->set_mus_property ("iterator-ctor",
1052 Property_iterator::constructor_cxx_function);
1054 Moment m = - unsmob_duration($2)->length_mom ();
1055 p->set_mus_property ("value", m.smobbed_copy ());
1057 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1058 sp->set_mus_property ("element", p->self_scm ());
1059 scm_unprotect_object (p->self_scm ());
1062 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1065 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1066 SCM result = gh_call1 (func, $2);
1069 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1070 Music * p = new Music (SCM_EOL);
1071 set_music_properties(p, gh_car (s));
1072 l = gh_cons (p->self_scm (), l);
1073 scm_unprotect_object (p->self_scm ());
1075 Sequential_music * seq = new Sequential_music (SCM_EOL);
1076 seq->set_mus_property ("elements", l);
1078 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1079 sp->set_mus_property ("element", seq->self_scm ());
1080 scm_unprotect_object (seq->self_scm ());
1083 sp-> set_mus_property("context-type", ly_str02scm("Staff"));
1085 | TIME_T bare_unsigned '/' bare_unsigned ';' {
1086 Music * p = new Music (SCM_EOL);
1087 p->set_mus_property ("symbol",
1088 ly_symbol2scm ( "timeSignatureFraction"));
1089 p->set_mus_property ("iterator-ctor",
1090 Property_iterator::constructor_cxx_function);
1092 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1095 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1096 sp->set_mus_property ("element", p->self_scm ());
1097 scm_unprotect_object (p->self_scm ());
1100 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1105 shorthand_command_req { $$ = $1; }
1106 | verbose_command_req semicolon { $$ = $1; }
1109 shorthand_command_req:
1117 $$ = new Barcheck_req;
1123 Span_req*b= new Span_req;
1124 b->set_span_dir(START);
1125 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1129 Span_req*b= new Span_req;
1130 b->set_span_dir( STOP);
1131 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1135 $$ = new Breathing_sign_req;
1140 verbose_command_req:
1141 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1142 Span_req * sp_p = new Span_req;
1143 sp_p-> set_span_dir ( Direction($2));
1144 sp_p->set_mus_property ("span-type",$3);
1145 sp_p->set_spot (THIS->here_input ());
1149 Mark_req * m = new Mark_req;
1153 Mark_req *m = new Mark_req;
1154 m->set_mus_property ("label", $2);
1158 | PENALTY bare_int {
1159 Break_req * b = new Break_req;
1160 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1161 b->set_spot (THIS->here_input ());
1164 | SKIP duration_length {
1165 Skip_req * skip_p = new Skip_req;
1166 skip_p->set_mus_property ("duration", $2);
1174 Key_change_req *key_p= new Key_change_req;
1177 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1178 Key_change_req *key_p= new Key_change_req;
1180 key_p->set_mus_property ("pitch-alist", $3);
1181 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1188 $$ = new Link_array<Request>;
1190 | post_requests post_request {
1191 $2->set_spot (THIS->here_input ());
1203 request_that_take_dir:
1206 | script_abbreviation {
1207 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1208 Articulation_req *a = new Articulation_req;
1209 if (gh_string_p (s))
1210 a->set_mus_property ("articulation-type", s);
1211 else THIS->parser_error (_ ("Expecting string as script definition"));
1217 script_dir request_that_take_dir {
1218 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1219 gs->set_direction (Direction ($1));
1221 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1227 REQUEST_IDENTIFIER {
1228 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1229 $$->set_spot (THIS->here_input ());
1231 | DYNAMICSCRIPT embedded_scm {
1233 TODO: junkme, use text-type == dynamic
1235 Text_script_req *d = new Text_script_req;
1236 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1237 d->set_mus_property ("text", $2);
1238 d->set_spot (THIS->here_input ());
1241 | TEXTSCRIPT embedded_scm {
1242 Text_script_req *t = new Text_script_req;
1243 t->set_mus_property ("text", $2);
1244 t->set_spot (THIS->here_input ());
1247 | SPANREQUEST bare_int STRING {
1248 Span_req * sp_p = new Span_req;
1249 sp_p->set_span_dir( Direction($2));
1250 sp_p->set_mus_property ("span-type", $3);
1251 sp_p->set_spot (THIS->here_input ());
1255 Tremolo_req* a = new Tremolo_req;
1256 a->set_spot (THIS->here_input ());
1257 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1262 Articulation_req * a = new Articulation_req;
1263 a->set_mus_property ("articulation-type", $2);
1264 a->set_spot (THIS->here_input ());
1268 duh, junk this syntax from the parser, if possible.
1271 Arpeggio_req *a = new Arpeggio_req;
1272 a->set_spot (THIS->here_input ());
1276 Glissando_req *g = new Glissando_req;
1277 g->set_spot /* No pun intended */ (THIS->here_input ());
1304 | NOTENAME_PITCH sup_quotes {
1305 Pitch p = *unsmob_pitch ($1);
1307 $$ = p.smobbed_copy ();
1309 | NOTENAME_PITCH sub_quotes {
1310 Pitch p =* unsmob_pitch ($1);
1313 $$ = p.smobbed_copy ();
1326 | TONICNAME_PITCH sup_quotes {
1327 Pitch p = *unsmob_pitch ($1);
1329 $$ = p.smobbed_copy ();
1331 | TONICNAME_PITCH sub_quotes {
1332 Pitch p =* unsmob_pitch ($1);
1335 $$ = p.smobbed_copy ();
1350 PITCH embedded_scm {
1352 if (!unsmob_pitch ($2)) {
1353 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1354 $$ = Pitch ().smobbed_copy ();
1360 DURATION embedded_scm {
1362 if (!unsmob_duration ($2))
1364 THIS->parser_error (_("Must have duration object"));
1365 $$ = Duration ().smobbed_copy ();
1372 if (!THIS->lexer_p_->lyric_state_b ())
1373 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1374 $$ = new Extender_req;
1380 if (!THIS->lexer_p_->lyric_state_b ())
1381 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1382 $$ = new Hyphen_req;
1387 close_request_parens {
1389 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1392 close_request_parens:
1394 Span_req* s= new Span_req;
1396 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1399 Span_req* s= new Span_req;
1401 s->set_mus_property ("span-type", ly_str02scm( "phrasing-slur"));
1404 Span_req*s =new Span_req;
1406 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1409 Span_req*s =new Span_req;
1411 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1417 open_request_parens {
1419 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1423 open_request_parens:
1425 Span_req *s = new Span_req;
1426 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1431 Span_req* s= new Span_req;
1433 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1436 Span_req* s= new Span_req;
1438 s->set_mus_property ("span-type", ly_str02scm( "phrasing-slur"));
1444 Text_script_req *t = new Text_script_req;
1445 t->set_mus_property ("text", $1);
1446 t->set_spot (THIS->here_input ());
1450 Text_script_req *t = new Text_script_req;
1451 t->set_mus_property ("text", $1);
1452 t->set_spot (THIS->here_input ());
1456 String ds = to_str ($1);
1457 Text_script_req* t = new Text_script_req;
1459 t->set_mus_property ("text", ly_str02scm (ds.ch_C()));
1460 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1461 t->set_spot (THIS->here_input ());
1466 script_abbreviation:
1468 $$ = gh_str02scm ("hat");
1471 $$ = gh_str02scm("plus");
1474 $$ = gh_str02scm ("dash");
1477 $$ = gh_str02scm ("bar");
1480 $$ = gh_str02scm ("larger");
1483 $$ = gh_str02scm ("dot");
1491 | '-' { $$ = CENTER; }
1496 $$ = new Link_array<Request>;
1498 | pre_requests open_request {
1513 | explicit_duration {
1516 | duration_length '*' bare_unsigned {
1517 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1519 | duration_length '/' bare_unsigned {
1520 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1524 entered_notemode_duration:
1526 THIS->set_last_duration (unsmob_duration ($1));
1530 optional_notemode_duration:
1532 $$ = THIS->default_duration_.smobbed_copy ();
1534 | entered_notemode_duration {
1537 | explicit_duration {
1543 bare_unsigned dots {
1545 if (!is_duration_b ($1))
1546 THIS->parser_error (_f ("not a duration: %d", $1));
1550 $$ = Duration (l, $2).smobbed_copy ();
1552 | DURATION_IDENTIFIER dots {
1553 Duration *d =unsmob_duration ($1);
1554 Duration k (d->duration_log (),d->dot_count () + $2);
1555 $$ = k.smobbed_copy ();
1573 | ':' bare_unsigned {
1574 if (!is_duration_b ($2))
1575 THIS->parser_error (_f ("not a duration: %d", $2));
1582 pitch exclamations questions optional_notemode_duration {
1583 if (!THIS->lexer_p_->note_state_b ())
1584 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1586 Note_req *n = new Note_req;
1588 n->set_mus_property ("pitch", $1);
1589 n->set_mus_property ("duration", $4);
1592 n->set_mus_property ("cautionary", SCM_BOOL_T);
1593 if ($2 % 2 || $3 % 2)
1594 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1596 Simultaneous_music*v = new Request_chord (SCM_EOL);
1597 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1600 FIXME: location is one off, since ptich & duration don't contain origin refs.
1602 v->set_spot (THIS->here_input ());
1603 n->set_spot (THIS->here_input ());
1607 | RESTNAME optional_notemode_duration {
1609 SCM e = SCM_UNDEFINED;
1610 if (ly_scm2string ($1) =="s")
1612 Skip_req * skip_p = new Skip_req;
1613 skip_p->set_mus_property ("duration" ,$2);
1615 skip_p->set_spot (THIS->here_input());
1616 e = skip_p->self_scm ();
1620 Rest_req * rest_req_p = new Rest_req;
1621 rest_req_p->set_mus_property ("duration", $2);
1622 rest_req_p->set_spot (THIS->here_input());
1623 e = rest_req_p->self_scm ();
1625 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1626 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1627 velt_p->set_spot (THIS->here_input());
1632 | MULTI_MEASURE_REST optional_notemode_duration {
1633 Skip_req * sk = new Skip_req;
1634 sk->set_mus_property ("duration", $2);
1635 Span_req *sp1 = new Span_req;
1636 Span_req *sp2 = new Span_req;
1637 sp1-> set_span_dir ( START);
1638 sp2-> set_span_dir ( STOP);
1639 SCM r = ly_str02scm ("rest");
1640 sp1->set_mus_property ("span-type", r);
1641 sp2->set_mus_property ("span-type", r);
1643 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1644 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1645 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1646 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1647 Request_chord * rqc3 = new Request_chord(SCM_EOL);
1648 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1650 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1652 $$ = new Sequential_music (SCM_EOL);
1653 $$->set_mus_property ("elements", ms);
1656 THIS->remember_spot ();
1659 optional_notemode_duration {
1660 if (!THIS->lexer_p_->lyric_state_b ()) {
1661 THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1662 THIS->error_level_i_ = 1;
1663 THIS->parser_error (_ ("Giving up"));
1667 Lyric_req* lreq_p = new Lyric_req;
1668 lreq_p->set_mus_property ("text", $1);
1669 lreq_p->set_mus_property ("duration",$3);
1670 lreq_p->set_spot (THIS->here_input());
1671 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1672 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1679 if (!THIS->lexer_p_->chord_state_b ())
1680 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1687 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1688 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1689 $$->set_spot (THIS->here_input ());
1696 | CHORD_COLON chord_notes {
1705 | chord_notes '.' chord_step {
1706 $$ = gh_append2 ($$, $3);
1714 | CHORD_CARET chord_notes {
1724 | '/' steno_tonic_pitch {
1733 | CHORD_BASS steno_tonic_pitch {
1740 $$ = gh_cons ($1, SCM_EOL);
1742 | CHORDMODIFIER_PITCH {
1743 $$ = gh_cons ($1, SCM_EOL);
1745 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1746 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1753 m.notename_i_ = ($1 - 1) % 7;
1754 m.octave_i_ = $1 > 7 ? 1 : 0;
1755 m.alteration_i_ = 0;
1757 $$ = m.smobbed_copy ();
1759 | bare_unsigned '+' {
1761 m.notename_i_ = ($1 - 1) % 7;
1762 m.octave_i_ = $1 > 7 ? 1 : 0;
1763 m.alteration_i_ = 1;
1766 $$ = m.smobbed_copy ();
1768 | bare_unsigned CHORD_MINUS {
1770 m.notename_i_ = ($1 - 1) % 7;
1771 m.octave_i_ = $1 > 7 ? 1 : 0;
1772 m.alteration_i_ = -1;
1774 $$ = m.smobbed_copy ();
1785 | '-' number_expression %prec UNARY_MINUS {
1786 $$ = scm_difference ($2, SCM_UNDEFINED);
1788 | number_expression '*' number_expression {
1789 $$ = scm_product ($1, $3);
1791 | number_expression '/' number_expression {
1792 $$ = scm_divide ($1, $3);
1794 | number_expression '+' number_expression {
1795 $$ = scm_sum ($1, $3);
1797 | number_expression '-' number_expression {
1798 $$ = scm_difference ($1, $3);
1800 | '(' number_expression ')' {
1807 $$ = gh_int2scm ($1);
1810 $$ = gh_int2scm ($1);
1813 $$ = gh_double2scm ($1);
1815 | NUMBER_IDENTIFIER {
1819 $$ = gh_double2scm ($1 CM);
1822 $$ = gh_double2scm ($1 PT);
1825 $$ = gh_double2scm ($1 INCH);
1828 $$ = gh_double2scm ($1 MM);
1831 $$ = gh_double2scm ($1 CHAR);
1838 if (scm_integer_p ($1) == SCM_BOOL_T) {
1839 $$ = gh_scm2int ($1);
1842 THIS->parser_error (_("need integer number arg"));
1846 THIS->parser_error (_("Must be positive integer"));
1854 if (scm_integer_p ($1) == SCM_BOOL_T)
1856 int k = gh_scm2int ($1);
1860 THIS->parser_error (_("need integer number arg"));
1874 | STRING_IDENTIFIER {
1877 | string '+' string {
1878 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1885 | exclamations '!' { $$ ++; }
1890 | questions '?' { $$ ++; }
1901 My_lily_parser::set_yydebug (bool b)
1908 extern My_lily_parser * current_parser;
1911 My_lily_parser::do_yyparse ()
1914 current_parser = this;;
1915 yyparse ((void*)this);