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 "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
181 %token OVERRIDE SET REVERT
194 %token COMMANDSPANREQUEST
196 %token OUTPUTPROPERTY
205 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER
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 {
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 | MARK bare_unsigned {
1159 Mark_req *m = new Mark_req;
1160 m->set_mus_property ("label", gh_int2scm ($2));
1163 | PENALTY bare_int {
1164 Break_req * b = new Break_req;
1165 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1166 b->set_spot (THIS->here_input ());
1169 | SKIP duration_length {
1170 Skip_req * skip_p = new Skip_req;
1171 skip_p->set_mus_property ("duration", $2);
1179 Key_change_req *key_p= new Key_change_req;
1182 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1183 Key_change_req *key_p= new Key_change_req;
1185 key_p->set_mus_property ("pitch-alist", $3);
1186 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1193 $$ = new Link_array<Request>;
1195 | post_requests post_request {
1196 $2->set_spot (THIS->here_input ());
1208 request_that_take_dir:
1211 | script_abbreviation {
1212 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1213 Articulation_req *a = new Articulation_req;
1214 if (gh_string_p (s))
1215 a->set_mus_property ("articulation-type", s);
1216 else THIS->parser_error (_ ("Expecting string as script definition"));
1222 script_dir request_that_take_dir {
1223 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1224 gs->set_direction (Direction ($1));
1226 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1232 REQUEST_IDENTIFIER {
1233 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1234 $$->set_spot (THIS->here_input ());
1236 | DYNAMICSCRIPT embedded_scm {
1238 TODO: junkme, use text-type == dynamic
1240 Text_script_req *d = new Text_script_req;
1241 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1242 d->set_mus_property ("text", $2);
1243 d->set_spot (THIS->here_input ());
1246 | TEXTSCRIPT embedded_scm {
1247 Text_script_req *t = new Text_script_req;
1248 t->set_mus_property ("text", $2);
1249 t->set_spot (THIS->here_input ());
1252 | SPANREQUEST bare_int STRING {
1253 Span_req * sp_p = new Span_req;
1254 sp_p->set_span_dir( Direction($2));
1255 sp_p->set_mus_property ("span-type", $3);
1256 sp_p->set_spot (THIS->here_input ());
1260 Tremolo_req* a = new Tremolo_req;
1261 a->set_spot (THIS->here_input ());
1262 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1266 Articulation_req * a = new Articulation_req;
1267 a->set_mus_property ("articulation-type", $2);
1268 a->set_spot (THIS->here_input ());
1272 duh, junk this syntax from the parser, if possible.
1275 Arpeggio_req *a = new Arpeggio_req;
1276 a->set_spot (THIS->here_input ());
1280 Glissando_req *g = new Glissando_req;
1281 g->set_spot /* No pun intended */ (THIS->here_input ());
1308 | NOTENAME_PITCH sup_quotes {
1309 Pitch p = *unsmob_pitch ($1);
1311 $$ = p.smobbed_copy ();
1313 | NOTENAME_PITCH sub_quotes {
1314 Pitch p =* unsmob_pitch ($1);
1317 $$ = p.smobbed_copy ();
1330 | TONICNAME_PITCH sup_quotes {
1331 Pitch p = *unsmob_pitch ($1);
1333 $$ = p.smobbed_copy ();
1335 | TONICNAME_PITCH sub_quotes {
1336 Pitch p =* unsmob_pitch ($1);
1339 $$ = p.smobbed_copy ();
1354 PITCH embedded_scm {
1356 if (!unsmob_pitch ($2)) {
1357 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1358 $$ = Pitch ().smobbed_copy ();
1364 DURATION embedded_scm {
1366 if (!unsmob_duration ($2))
1368 THIS->parser_error (_("Must have duration object"));
1369 $$ = Duration ().smobbed_copy ();
1376 if (!THIS->lexer_p_->lyric_state_b ())
1377 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1378 $$ = new Extender_req;
1384 if (!THIS->lexer_p_->lyric_state_b ())
1385 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1386 $$ = new Hyphen_req;
1391 close_request_parens {
1393 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1396 close_request_parens:
1398 Span_req* s= new Span_req;
1400 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1403 Span_req*s =new Span_req;
1405 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1408 Span_req*s =new Span_req;
1410 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1416 open_request_parens {
1418 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1422 open_request_parens:
1424 Span_req *s = new Span_req;
1425 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1430 Span_req* s= new Span_req;
1432 s->set_mus_property ("span-type", ly_str02scm( "slur"));
1438 Text_script_req *t = new Text_script_req;
1439 t->set_mus_property ("text", $1);
1440 t->set_spot (THIS->here_input ());
1444 Text_script_req *t = new Text_script_req;
1445 t->set_mus_property ("text", $1);
1446 t->set_spot (THIS->here_input ());
1450 String ds = to_str ($1);
1451 Text_script_req* t = new Text_script_req;
1453 t->set_mus_property ("text", ly_str02scm (ds.ch_C()));
1454 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1455 t->set_spot (THIS->here_input ());
1460 script_abbreviation:
1462 $$ = gh_str02scm ("hat");
1465 $$ = gh_str02scm("plus");
1468 $$ = gh_str02scm ("dash");
1471 $$ = gh_str02scm ("bar");
1474 $$ = gh_str02scm ("larger");
1477 $$ = gh_str02scm ("dot");
1485 | '-' { $$ = CENTER; }
1490 $$ = new Link_array<Request>;
1492 | pre_requests open_request {
1507 | explicit_duration {
1510 | duration_length '*' bare_unsigned {
1511 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1513 | duration_length '/' bare_unsigned {
1514 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1518 entered_notemode_duration:
1520 THIS->set_last_duration (unsmob_duration ($1));
1524 optional_notemode_duration:
1526 $$ = THIS->default_duration_.smobbed_copy ();
1528 | entered_notemode_duration {
1531 | explicit_duration {
1537 bare_unsigned dots {
1539 if (!is_duration_b ($1))
1540 THIS->parser_error (_f ("not a duration: %d", $1));
1544 $$ = Duration (l, $2).smobbed_copy ();
1546 | DURATION_IDENTIFIER dots {
1547 Duration *d =unsmob_duration ($1);
1548 Duration k (d->duration_log (),d->dot_count () + $2);
1549 $$ = k.smobbed_copy ();
1567 | ':' bare_unsigned {
1568 if (!is_duration_b ($2))
1569 THIS->parser_error (_f ("not a duration: %d", $2));
1576 pitch exclamations questions optional_notemode_duration {
1577 if (!THIS->lexer_p_->note_state_b ())
1578 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1580 Note_req *n = new Note_req;
1582 n->set_mus_property ("pitch", $1);
1583 n->set_mus_property ("duration", $4);
1586 n->set_mus_property ("cautionary", SCM_BOOL_T);
1587 if ($2 % 2 || $3 % 2)
1588 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1590 Simultaneous_music*v = new Request_chord (SCM_EOL);
1591 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1594 FIXME: location is one off, since ptich & duration don't contain origin refs.
1596 v->set_spot (THIS->here_input ());
1597 n->set_spot (THIS->here_input ());
1601 | RESTNAME optional_notemode_duration {
1603 SCM e = SCM_UNDEFINED;
1604 if (ly_scm2string ($1) =="s")
1606 Skip_req * skip_p = new Skip_req;
1607 skip_p->set_mus_property ("duration" ,$2);
1609 skip_p->set_spot (THIS->here_input());
1610 e = skip_p->self_scm ();
1614 Rest_req * rest_req_p = new Rest_req;
1615 rest_req_p->set_mus_property ("duration", $2);
1616 rest_req_p->set_spot (THIS->here_input());
1617 e = rest_req_p->self_scm ();
1619 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1620 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1621 velt_p->set_spot (THIS->here_input());
1626 | MEASURES optional_notemode_duration {
1627 Skip_req * sk = new Skip_req;
1628 sk->set_mus_property ("duration", $2);
1629 Span_req *sp1 = new Span_req;
1630 Span_req *sp2 = new Span_req;
1631 sp1-> set_span_dir ( START);
1632 sp2-> set_span_dir ( STOP);
1633 SCM r = ly_str02scm ("rest");
1634 sp1->set_mus_property ("span-type", r);
1635 sp2->set_mus_property ("span-type", r);
1637 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1638 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1639 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1640 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1641 Request_chord * rqc3 = new Request_chord(SCM_EOL);
1642 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1644 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1646 $$ = new Sequential_music (SCM_EOL);
1647 $$->set_mus_property ("elements", ms);
1650 THIS->remember_spot ();
1653 optional_notemode_duration {
1654 if (!THIS->lexer_p_->lyric_state_b ()) {
1655 THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1656 THIS->error_level_i_ = 1;
1657 THIS->parser_error (_ ("Giving up"));
1661 Lyric_req* lreq_p = new Lyric_req;
1662 lreq_p->set_mus_property ("text", $1);
1663 lreq_p->set_mus_property ("duration",$3);
1664 lreq_p->set_spot (THIS->here_input());
1665 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1666 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1673 if (!THIS->lexer_p_->chord_state_b ())
1674 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1681 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1682 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1683 $$->set_spot (THIS->here_input ());
1690 | CHORD_COLON chord_notes {
1699 | chord_notes '.' chord_step {
1700 $$ = gh_append2 ($$, $3);
1708 | CHORD_CARET chord_notes {
1718 | '/' steno_tonic_pitch {
1727 | CHORD_BASS steno_tonic_pitch {
1734 $$ = gh_cons ($1, SCM_EOL);
1736 | CHORDMODIFIER_PITCH {
1737 $$ = gh_cons ($1, SCM_EOL);
1739 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1740 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1747 m.notename_i_ = ($1 - 1) % 7;
1748 m.octave_i_ = $1 > 7 ? 1 : 0;
1749 m.alteration_i_ = 0;
1751 $$ = m.smobbed_copy ();
1753 | bare_unsigned '+' {
1755 m.notename_i_ = ($1 - 1) % 7;
1756 m.octave_i_ = $1 > 7 ? 1 : 0;
1757 m.alteration_i_ = 1;
1760 $$ = m.smobbed_copy ();
1762 | bare_unsigned CHORD_MINUS {
1764 m.notename_i_ = ($1 - 1) % 7;
1765 m.octave_i_ = $1 > 7 ? 1 : 0;
1766 m.alteration_i_ = -1;
1768 $$ = m.smobbed_copy ();
1779 | '-' number_expression %prec UNARY_MINUS {
1780 $$ = scm_difference ($2, SCM_UNDEFINED);
1782 | number_expression '*' number_expression {
1783 $$ = scm_product ($1, $3);
1785 | number_expression '/' number_expression {
1786 $$ = scm_divide ($1, $3);
1788 | number_expression '+' number_expression {
1789 $$ = scm_sum ($1, $3);
1791 | number_expression '-' number_expression {
1792 $$ = scm_difference ($1, $3);
1794 | '(' number_expression ')' {
1801 $$ = gh_int2scm ($1);
1804 $$ = gh_int2scm ($1);
1807 $$ = gh_double2scm ($1);
1809 | NUMBER_IDENTIFIER {
1813 $$ = gh_double2scm ($1 CM);
1816 $$ = gh_double2scm ($1 PT);
1819 $$ = gh_double2scm ($1 INCH);
1822 $$ = gh_double2scm ($1 MM);
1825 $$ = gh_double2scm ($1 CHAR);
1832 if (scm_integer_p ($1) == SCM_BOOL_T) {
1833 $$ = gh_scm2int ($1);
1836 THIS->parser_error (_("need integer number arg"));
1840 THIS->parser_error (_("Must be positive integer"));
1848 if (scm_integer_p ($1) == SCM_BOOL_T)
1850 int k = gh_scm2int ($1);
1854 THIS->parser_error (_("need integer number arg"));
1868 | STRING_IDENTIFIER {
1871 | string '+' string {
1872 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1879 | exclamations '!' { $$ ++; }
1884 | questions '?' { $$ ++; }
1895 My_lily_parser::set_yydebug (bool b)
1902 extern My_lily_parser * current_parser;
1905 My_lily_parser::do_yyparse ()
1908 current_parser = this;;
1909 yyparse ((void*)this);