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>
14 #include "translator-def.hh"
15 #include "lily-guile.hh"
16 #include "change-iterator.hh"
18 #include "my-lily-lexer.hh"
19 #include "paper-def.hh"
20 #include "midi-def.hh"
22 #include "file-path.hh"
24 #include "dimensions.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"
42 #include "lilypond-input-version.hh"
43 #include "grace-music.hh"
44 #include "part-combine-music.hh"
45 #include "scm-hash.hh"
46 #include "auto-change-iterator.hh"
47 #include "un-relativable-music.hh"
51 regular_identifier_b (SCM id)
53 String str = ly_scm2string (id);
54 char const *s = str.ch_C() ;
59 v = v && isalpha (*s);
67 set_property_music (SCM sym, SCM value)
69 Music * p = new Music (SCM_EOL);
70 p->set_mus_property ("symbol", sym);
71 p->set_mus_property ("iterator-ctor",
72 Property_iterator::constructor_cxx_function);
74 p->set_mus_property ("value", value);
81 return t && t == 1 << intlog2 (t);
85 set_music_properties (Music *p, SCM a)
87 for (SCM k = a; gh_pair_p (k); k = gh_cdr (k))
89 p->set_mus_property (gh_caar (k), gh_cdar (k));
99 // needed for bison.simple's malloc () and free ()
106 #define YYERROR_VERBOSE 1
108 #define YYPARSE_PARAM my_lily_parser_l
109 #define YYLEX_PARAM my_lily_parser_l
111 ((My_lily_parser *) my_lily_parser_l)
113 #define yyerror THIS->parser_error
114 #define ARRAY_SIZE(a,s) if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
121 Link_array<Request> *reqvec;
123 String *string; // needed by the lexer as temporary scratch area.
127 Scheme_hash_table *scmhash;
128 Music_output_def * outputdef;
132 /* We use SCMs to do strings, because it saves us the trouble of
133 deleting them. Let's hope that a stack overflow doesnt trigger a move
134 of the parse stack onto the heap. */
144 yylex (YYSTYPE *s, void * v_l)
146 My_lily_parser *pars_l = (My_lily_parser*) v_l;
147 My_lily_lexer * lex_l = pars_l->lexer_p_;
149 lex_l->lexval_l = (void*) s;
150 return lex_l->yylex ();
158 /* tokens which are not keywords */
168 %token CHORDMODIFIERS
176 %token ELEMENTDESCRIPTIONS
192 %token MULTI_MEASURE_REST
204 %token OVERRIDE SET REVERT
217 %token COMMANDSPANREQUEST
219 %token OUTPUTPROPERTY
229 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
230 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
232 %type <i> exclamations questions dots
234 %token <scm> NOTENAME_PITCH
235 %token <scm> TONICNAME_PITCH
236 %token <scm> CHORDMODIFIER_PITCH
237 %token <scm> DURATION_IDENTIFIER
238 %token <scm> FRACTION
239 %token <id> IDENTIFIER
242 %token <scm> SCORE_IDENTIFIER
243 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
245 %token <scm> NUMBER_IDENTIFIER
246 %token <scm> REQUEST_IDENTIFIER
247 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
248 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
249 %token <scm> RESTNAME
255 %type <outputdef> output_def
256 %type <scmhash> lilypond_header lilypond_header_body
257 %type <request> open_request_parens close_request_parens open_request close_request
258 %type <request> request_with_dir request_that_take_dir verbose_request
259 %type <i> sub_quotes sup_quotes
260 %type <music> simple_element request_chord command_element Simple_music Composite_music
261 %type <music> Alternative_music Repeated_music
262 %type <i> tremolo_type
263 %type <i> bare_int bare_unsigned
266 %type <scm> identifier_init
268 %type <scm> steno_duration optional_notemode_duration multiplied_duration
269 %type <scm> explicit_duration
271 %type <reqvec> pre_requests post_requests
272 %type <request> gen_text_def
273 %type <scm> steno_pitch pitch absolute_pitch
274 %type <scm> explicit_pitch steno_tonic_pitch
276 %type <scm> chord_additions chord_subtractions chord_notes chord_step
278 %type <scm> chord_note chord_inversion chord_bass
279 %type <scm> duration_length fraction
281 %type <scm> embedded_scm scalar
282 %type <music> Music Sequential_music Simultaneous_music Music_sequence
283 %type <music> relative_music re_rhythmed_music part_combined_music
284 %type <music> property_def translator_change
285 %type <scm> Music_list
286 %type <outputdef> music_output_def_body
287 %type <request> shorthand_command_req
288 %type <request> post_request
289 %type <music> command_req verbose_command_req
290 %type <request> extender_req
291 %type <request> hyphen_req
292 %type <scm> string bare_number number_expression number_term number_factor
294 %type <score> score_block score_body
296 %type <scm> translator_spec_block translator_spec_body
297 %type <tempo> tempo_request
298 %type <scm> notenames_body notenames_block chordmodifiers_block
299 %type <scm> script_abbreviation
305 /* We don't assign precedence to / and *, because we might need varied
306 prec levels in different prods */
312 lilypond: /* empty */
313 | lilypond toplevel_expression {}
314 | lilypond assignment { }
316 THIS->error_level_i_ = 1;
319 THIS->error_level_i_ = 1;
325 THIS->lexer_p_->pitchname_tab_ = $1;
327 | chordmodifiers_block {
328 THIS->lexer_p_->chordmodifier_tab_ = $1;
332 scm_unprotect_object (global_header_p->self_scm ());
333 global_header_p = $1;
336 score_global_array.push ($1);
339 if (dynamic_cast<Paper_def*> ($1))
340 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
341 else if (dynamic_cast<Midi_def*> ($1))
342 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
355 chordmodifiers_block:
356 CHORDMODIFIERS notenames_body { $$ = $2; }
360 PITCHNAMES notenames_body { $$ = $2; }
365 int i = scm_ilength ($1);
367 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
368 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
369 SCM pt = gh_cdar (s);
370 if (!unsmob_pitch (pt))
371 THIS->parser_error ("Need pitch object.");
373 scm_hashq_set_x (tab, gh_caar (s), pt);
380 lilypond_header_body:
382 $$ = new Scheme_hash_table;
384 Scope *sc = new Scope ($$);
385 THIS->lexer_p_-> scope_l_arr_.push (sc);
387 | lilypond_header_body assignment {
393 HEADER '{' lilypond_header_body '}' {
395 delete THIS->lexer_p_-> scope_l_arr_.pop ();
405 THIS->remember_spot ();
407 /* cont */ '=' identifier_init {
410 Should find generic way of associating input with objects.
412 Input ip = THIS->pop_spot ();
414 if (! regular_identifier_b ($1))
416 ip.warning (_ ("Identifier should have alphabetic characters only"));
419 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
422 TODO: devise standard for protection in parser.
424 The parser stack lives on the C-stack, which means that
425 all objects can be unprotected as soon as they're here.
435 $$ = $1->self_scm ();
436 scm_unprotect_object ($$);
439 $$ = $1->self_scm ();
440 scm_unprotect_object ($$);
442 | translator_spec_block {
446 $$ = $1->self_scm ();
447 scm_unprotect_object ($$);
450 $$ = $1->self_scm ();
451 scm_unprotect_object ($$);
453 | explicit_duration {
456 | number_expression {
467 translator_spec_block:
468 TRANSLATOR '{' translator_spec_body '}'
474 translator_spec_body:
475 TRANSLATOR_IDENTIFIER {
476 $$ = unsmob_translator_def ($1)->clone_scm ();
477 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
480 $$ = Translator_def::make_scm ();
481 Translator_def*td = unsmob_translator_def ($$);
482 td->translator_group_type_ = $2;
483 td->set_spot (THIS->here_input ());
485 | translator_spec_body STRING '=' embedded_scm {
486 unsmob_translator_def ($$)->add_property_assign ($2, $4);
488 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
489 unsmob_translator_def ($$)
490 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
492 | translator_spec_body STRING REVERT embedded_scm {
493 unsmob_translator_def ($$)->add_pop_property (
494 scm_string_to_symbol ($2), $4);
496 | translator_spec_body NAME STRING {
497 unsmob_translator_def ($$)->type_name_ = $3;
499 | translator_spec_body CONSISTS STRING {
500 unsmob_translator_def ($$)->add_element ($3);
502 | translator_spec_body ALIAS STRING {
503 Translator_def*td = unsmob_translator_def ($$);
504 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
506 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
507 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
508 unsmob_translator_def ($$)
509 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
512 | translator_spec_body CONSISTSEND STRING {
513 unsmob_translator_def ($$)->add_last_element ( $3);
515 | translator_spec_body ACCEPTS STRING {
516 unsmob_translator_def ($$)->set_acceptor ($3,true);
518 | translator_spec_body DENIES STRING {
519 unsmob_translator_def ($$)->set_acceptor ($3,false);
521 | translator_spec_body REMOVE STRING {
522 unsmob_translator_def ($$)->remove_element ($3);
531 THIS->remember_spot ();
533 /*cont*/ '{' score_body '}' {
536 if (!$$->def_p_arr_.size ())
538 Music_output_def *id =
539 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
540 $$->add_output (id ? id->clone () : new Paper_def );
549 $$->set_spot (THIS->here_input ());
550 SCM m = $1->self_scm ();
551 scm_unprotect_object (m);
555 $$ = new Score (*unsmob_score ($1));
556 $$->set_spot (THIS->here_input ());
558 | score_body lilypond_header {
559 scm_unprotect_object ($2->self_scm ());
562 | score_body output_def {
575 music_output_def_body '}' {
577 THIS-> lexer_p_-> scope_l_arr_.pop ();
581 music_output_def_body:
583 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
588 p = dynamic_cast<Midi_def*> (id->clone ());
593 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
596 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
599 p = dynamic_cast<Paper_def*> (id->clone ());
602 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
605 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
606 Music_output_def *p = unsmob_music_output_def ($3);
608 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
611 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
612 Music_output_def *p = unsmob_music_output_def ($3);
615 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
618 | music_output_def_body assignment {
621 | music_output_def_body translator_spec_block {
622 $$->assign_translator ($2);
624 | music_output_def_body STYLESHEET embedded_scm {
625 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
627 | music_output_def_body tempo_request {
629 junk this ? there already is tempo stuff in
632 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
633 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
634 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
636 | music_output_def_body error {
642 TEMPO steno_duration '=' bare_unsigned {
644 $$->set_mus_property ("duration", $2);
645 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
649 Music_list: /* empty */ {
650 $$ = gh_cons (SCM_EOL, SCM_EOL);
654 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
655 scm_unprotect_object ($2->self_scm ()); /* UGH */
656 if (gh_pair_p (gh_cdr (s)))
657 gh_set_cdr_x (gh_cdr (s), c); /* append */
659 gh_set_car_x (s, c); /* set first cons */
660 gh_set_cdr_x (s, c) ; /* remember last cell */
676 | ALTERNATIVE Music_sequence {
678 $2->set_spot (THIS->here_input ());
686 REPEAT string bare_unsigned Music Alternative_music
688 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
689 if (alts && $3 < alts->length_i ())
690 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
694 Repeated_music * r = new Repeated_music (SCM_EOL);
698 r-> set_mus_property ("body", beg->self_scm ());
699 scm_unprotect_object (beg->self_scm ());
701 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
705 alts->truncate (times);
706 r-> set_mus_property ("alternatives", alts->self_scm ());
707 scm_unprotect_object (alts->self_scm ());
709 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
710 SCM result = gh_call1 (func, $2);
712 set_music_properties (r, result);
714 r->set_spot (*$4->origin ());
719 Music_sequence: '{' Music_list '}' {
720 $$ = new Music_sequence (SCM_EOL);
721 $$->set_mus_property ("elements", gh_car ($2));
726 SEQUENTIAL '{' Music_list '}' {
727 $$ = new Sequential_music (SCM_EOL);
728 $$->set_mus_property ("elements", gh_car ($3));
730 | '{' Music_list '}' {
731 $$ = new Sequential_music (SCM_EOL);
732 $$->set_mus_property ("elements", gh_car ($2));
737 SIMULTANEOUS '{' Music_list '}'{
738 $$ = new Simultaneous_music (SCM_EOL);
739 $$->set_mus_property ("elements", gh_car ($3));
742 | '<' Music_list '>' {
743 $$ = new Simultaneous_music (SCM_EOL);
744 $$->set_mus_property ("elements", gh_car ($2));
749 request_chord { $$ = $1; }
750 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
752 if (!gh_symbol_p ($3))
754 THIS->parser_error (_ ("Second argument must be a symbol"));
756 /*hould check # args */
757 if (!gh_procedure_p (pred))
759 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
762 Music *m = new Music (SCM_EOL);
763 m->set_mus_property ("predicate", pred);
764 m->set_mus_property ("grob-property", $3);
765 m->set_mus_property ("grob-value", $5);
766 m->set_mus_property ("iterator-ctor",
767 Output_property_music_iterator::constructor_cxx_function);
772 $$ = unsmob_music ($1)->clone ();
780 CONTEXT STRING Music {
781 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
782 csm->set_mus_property ("element", $3->self_scm ());
783 scm_unprotect_object ($3->self_scm ());
785 csm->set_mus_property ("context-type",$2);
786 csm->set_mus_property ("context-id", ly_str02scm (""));
790 | AUTOCHANGE STRING Music {
791 Music * chm = new Music_wrapper (SCM_EOL);
792 chm->set_mus_property ("element", $3->self_scm ());
793 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
795 scm_unprotect_object ($3->self_scm ());
796 chm->set_mus_property ("what", $2);
799 chm->set_spot (*$3->origin ());
802 $$ = new Grace_music (SCM_EOL);
803 $$->set_mus_property ("element", $2->self_scm ());
804 scm_unprotect_object ($2->self_scm ());
807 | CONTEXT string '=' string Music {
808 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
809 csm->set_mus_property ("element", $5->self_scm ());
810 scm_unprotect_object ($5->self_scm ());
812 csm->set_mus_property ("context-type", $2);
813 csm->set_mus_property ("context-id", $4);
818 THIS->remember_spot ();
824 int n = gh_scm2int (gh_car ($3)); int d = gh_scm2int (gh_cdr ($3));
826 $$ = new Time_scaled_music (SCM_EOL);
827 $$->set_spot (THIS->pop_spot ());
830 $$->set_mus_property ("element", mp->self_scm ());
831 scm_unprotect_object (mp->self_scm ());
832 $$->set_mus_property ("numerator", gh_int2scm (n));
833 $$->set_mus_property ("denominator", gh_int2scm (d));
834 $$->compress (Moment (n,d));
837 | Repeated_music { $$ = $1; }
838 | Simultaneous_music { $$ = $1; }
839 | Sequential_music { $$ = $1; }
840 | TRANSPOSE pitch Music {
841 $$ = new Transposed_music (SCM_EOL);
843 Pitch pit = *unsmob_pitch ($2);
846 $$->set_mus_property ("element", p->self_scm ());
847 scm_unprotect_object (p->self_scm ());
849 | TRANSPOSE steno_tonic_pitch Music {
850 $$ = new Transposed_music (SCM_EOL);
852 Pitch pit = *unsmob_pitch ($2);
855 $$->set_mus_property ("element", p->self_scm ());
856 scm_unprotect_object (p->self_scm ());
859 | APPLY embedded_scm Music {
860 SCM ret = gh_call1 ($2, $3->self_scm ());
861 Music *m = unsmob_music (ret);
863 THIS->parser_error ("\\apply must return a Music");
864 m = new Music (SCM_EOL);
869 { THIS->lexer_p_->push_note_state (); }
872 THIS->lexer_p_->pop_state ();
875 { THIS->lexer_p_->push_chord_state (); }
878 Music * chm = new Un_relativable_music ;
879 chm->set_mus_property ("element", $3->self_scm ());
882 THIS->lexer_p_->pop_state ();
885 { THIS->lexer_p_->push_lyric_state (); }
889 THIS->lexer_p_->pop_state ();
891 | relative_music { $$ = $1; }
892 | re_rhythmed_music { $$ = $1; }
893 | part_combined_music { $$ = $1; }
897 RELATIVE absolute_pitch Music {
899 Pitch pit = *unsmob_pitch ($2);
900 $$ = new Relative_octave_music (SCM_EOL);
902 $$->set_mus_property ("element", p->self_scm ());
903 scm_unprotect_object (p->self_scm ());
905 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
911 ADDLYRICS Music Music {
912 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
913 l->set_mus_property ("music", $2->self_scm ());
914 l->set_mus_property ("lyrics", $3->self_scm ());
915 scm_unprotect_object ($3->self_scm ());
916 scm_unprotect_object ($2->self_scm ());
922 PARTCOMBINE STRING Music Music {
923 Part_combine_music * p = new Part_combine_music (SCM_EOL);
925 p->set_mus_property ("what", $2);
926 p->set_mus_property ("one", $3->self_scm ());
927 p->set_mus_property ("two", $4->self_scm ());
929 scm_unprotect_object ($3->self_scm ());
930 scm_unprotect_object ($4->self_scm ());
938 TRANSLATOR STRING '=' STRING {
939 Music * t = new Music (SCM_EOL);
940 t->set_mus_property ("iterator-ctor",
941 Change_iterator::constructor_cxx_function);
942 t-> set_mus_property ("change-to-type", $2);
943 t-> set_mus_property ("change-to-id", $4);
946 $$->set_spot (THIS->here_input ());
951 PROPERTY STRING '.' STRING '=' scalar {
953 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
954 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
956 csm->set_mus_property ("element", t->self_scm ());
957 scm_unprotect_object (t->self_scm ());
960 $$->set_spot (THIS->here_input ());
962 csm-> set_mus_property ("context-type", $2);
964 | PROPERTY STRING '.' STRING UNSET {
965 Music *t = new Music (SCM_EOL);
967 t->set_mus_property ("iterator-ctor",
968 Property_unset_iterator::constructor_cxx_function);
969 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
971 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
972 csm->set_mus_property ("element", t->self_scm ());
973 scm_unprotect_object (t->self_scm ());
976 $$->set_spot (THIS->here_input ());
978 csm-> set_mus_property ("context-type", $2);
980 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
981 Music *t = new Music (SCM_EOL);
982 t->set_mus_property ("iterator-ctor",
983 Push_property_iterator::constructor_cxx_function);
984 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
985 t->set_mus_property ("pop-first", SCM_BOOL_T);
986 t->set_mus_property ("grob-property", $6);
987 t->set_mus_property ("grob-value", $8);
988 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
989 csm->set_mus_property ("element", t->self_scm ());
990 scm_unprotect_object (t->self_scm ());
992 $$->set_spot (THIS->here_input ());
994 csm-> set_mus_property ("context-type", $2);
996 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
997 Music *t = new Music (SCM_EOL);
998 t->set_mus_property ("iterator-ctor",
999 Push_property_iterator::constructor_cxx_function);
1000 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1001 t->set_mus_property ("grob-property", $6);
1002 t->set_mus_property ("grob-value", $8);
1003 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1004 csm->set_mus_property ("element", t->self_scm ());
1005 scm_unprotect_object (t->self_scm ());
1008 $$->set_spot (THIS->here_input ());
1010 csm-> set_mus_property ("context-type", $2);
1012 | PROPERTY STRING '.' STRING REVERT embedded_scm {
1013 Music *t = new Music (SCM_EOL);
1014 t->set_mus_property ("iterator-ctor",
1015 Pop_property_iterator::constructor_cxx_function);
1016 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1017 t->set_mus_property ("grob-property", $6);
1019 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1020 csm->set_mus_property ("element", t->self_scm ());
1021 scm_unprotect_object (t->self_scm ());
1024 $$->set_spot (THIS->here_input ());
1026 csm-> set_mus_property ("context-type", $2);
1032 | bare_int { $$ = gh_int2scm ($1); }
1033 | embedded_scm { $$ = $1; }
1038 pre_requests simple_element post_requests {
1039 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1041 for (int i=0; i < $1->size (); i++)
1042 l->append_music ($1->elem (i));
1043 for (int i=0; i < $3->size (); i++)
1044 l->append_music ($3->elem (i));
1047 programming_error ("Need Sequence to add music to");
1056 $$ = new Request_chord (SCM_EOL);
1057 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1058 $$-> set_spot (THIS->here_input ());
1059 $1-> set_spot (THIS->here_input ());
1062 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1064 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1065 csm->set_mus_property ("element", t->self_scm ());
1066 scm_unprotect_object (t->self_scm ());
1069 $$->set_spot (THIS->here_input ());
1071 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1073 | PARTIAL duration_length {
1074 Moment m = - unsmob_duration ($2)->length_mom ();
1075 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1077 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1078 sp->set_mus_property ("element", p->self_scm ());
1079 scm_unprotect_object (p->self_scm ());
1082 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1085 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1086 SCM result = gh_call1 (func, $2);
1089 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1090 Music * p = new Music (SCM_EOL);
1091 set_music_properties (p, gh_car (s));
1092 l = gh_cons (p->self_scm (), l);
1093 scm_unprotect_object (p->self_scm ());
1095 Sequential_music * seq = new Sequential_music (SCM_EOL);
1096 seq->set_mus_property ("elements", l);
1098 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1099 sp->set_mus_property ("element", seq->self_scm ());
1100 scm_unprotect_object (seq->self_scm ());
1103 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1106 Music * p1 = set_property_music (ly_symbol2scm ( "timeSignatureFraction"), $2);
1108 int l = gh_scm2int (gh_car ($2));
1109 int o = gh_scm2int (gh_cdr ($2));
1111 Moment one_beat = Moment (1)/Moment (o);
1112 Moment len = Moment (l) * one_beat;
1115 Music *p2 = set_property_music (ly_symbol2scm ("measureLength"), len.smobbed_copy ());
1116 Music *p3 = set_property_music (ly_symbol2scm ("beatLength"), one_beat.smobbed_copy ());
1118 SCM list = gh_list (p1->self_scm (), p2->self_scm (), p3->self_scm(), SCM_UNDEFINED);
1119 Sequential_music *seq = new Sequential_music (SCM_EOL);
1120 seq->set_mus_property ("elements", list);
1123 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1124 sp->set_mus_property ("element", seq->self_scm ());
1128 scm_unprotect_object (p3->self_scm ());
1129 scm_unprotect_object (p2->self_scm ());
1130 scm_unprotect_object (p1->self_scm ());
1131 scm_unprotect_object (seq->self_scm ());
1136 TODO: should make alias TimingContext for Score
1139 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1144 shorthand_command_req { $$ = $1; }
1145 | verbose_command_req { $$ = $1; }
1148 shorthand_command_req:
1156 $$ = new Barcheck_req;
1162 Span_req*b= new Span_req;
1163 b->set_span_dir (START);
1164 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1168 Span_req*b= new Span_req;
1169 b->set_span_dir ( STOP);
1170 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1174 $$ = new Breathing_sign_req;
1179 verbose_command_req:
1180 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1181 Span_req * sp_p = new Span_req;
1182 sp_p-> set_span_dir ( Direction ($2));
1183 sp_p->set_mus_property ("span-type",$3);
1184 sp_p->set_spot (THIS->here_input ());
1188 Mark_req * m = new Mark_req;
1192 Mark_req *m = new Mark_req;
1193 m->set_mus_property ("label", $2);
1200 Break_req * b = new Break_req;
1202 if (!gh_number_p (s))
1205 b->set_mus_property ("penalty", s);
1206 b->set_spot (THIS->here_input ());
1209 | SKIP duration_length {
1210 Skip_req * skip_p = new Skip_req;
1211 skip_p->set_mus_property ("duration", $2);
1219 Key_change_req *key_p= new Key_change_req;
1222 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1223 Key_change_req *key_p= new Key_change_req;
1225 key_p->set_mus_property ("pitch-alist", $3);
1226 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1233 $$ = new Link_array<Request>;
1235 | post_requests post_request {
1236 $2->set_spot (THIS->here_input ());
1248 request_that_take_dir:
1251 | script_abbreviation {
1252 SCM s = THIS->lexer_p_->lookup_identifier ("dash" + ly_scm2string ($1));
1253 Articulation_req *a = new Articulation_req;
1254 if (gh_string_p (s))
1255 a->set_mus_property ("articulation-type", s);
1256 else THIS->parser_error (_ ("Expecting string as script definition"));
1262 script_dir request_that_take_dir {
1263 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1264 gs->set_direction (Direction ($1));
1266 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1272 REQUEST_IDENTIFIER {
1273 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1274 $$->set_spot (THIS->here_input ());
1276 | DYNAMICSCRIPT embedded_scm {
1278 TODO: junkme, use text-type == dynamic
1280 Text_script_req *d = new Text_script_req;
1281 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1282 d->set_mus_property ("text", $2);
1283 d->set_spot (THIS->here_input ());
1286 | SPANREQUEST bare_int STRING {
1287 Span_req * sp_p = new Span_req;
1288 sp_p->set_span_dir ( Direction ($2));
1289 sp_p->set_mus_property ("span-type", $3);
1290 sp_p->set_spot (THIS->here_input ());
1294 Tremolo_req* a = new Tremolo_req;
1295 a->set_spot (THIS->here_input ());
1296 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1300 Articulation_req * a = new Articulation_req;
1301 a->set_mus_property ("articulation-type", $2);
1302 a->set_spot (THIS->here_input ());
1306 duh, junk this syntax from the parser, if possible.
1309 Arpeggio_req *a = new Arpeggio_req;
1310 a->set_spot (THIS->here_input ());
1314 Glissando_req *g = new Glissando_req;
1315 g->set_spot /* No pun intended */ (THIS->here_input ());
1342 | NOTENAME_PITCH sup_quotes {
1343 Pitch p = *unsmob_pitch ($1);
1345 $$ = p.smobbed_copy ();
1347 | NOTENAME_PITCH sub_quotes {
1348 Pitch p =* unsmob_pitch ($1);
1351 $$ = p.smobbed_copy ();
1364 | TONICNAME_PITCH sup_quotes {
1365 Pitch p = *unsmob_pitch ($1);
1367 $$ = p.smobbed_copy ();
1369 | TONICNAME_PITCH sub_quotes {
1370 Pitch p =* unsmob_pitch ($1);
1373 $$ = p.smobbed_copy ();
1388 PITCH embedded_scm {
1390 if (!unsmob_pitch ($2)) {
1391 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1392 $$ = Pitch ().smobbed_copy ();
1398 DURATION embedded_scm {
1400 if (!unsmob_duration ($2))
1402 THIS->parser_error (_ ("Must have duration object"));
1403 $$ = Duration ().smobbed_copy ();
1410 if (!THIS->lexer_p_->lyric_state_b ())
1411 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1412 $$ = new Extender_req;
1418 if (!THIS->lexer_p_->lyric_state_b ())
1419 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1420 $$ = new Hyphen_req;
1425 close_request_parens {
1427 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1430 close_request_parens:
1432 Span_req* s= new Span_req;
1434 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1437 Span_req* s= new Span_req;
1439 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1442 Span_req*s =new Span_req;
1444 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1447 Span_req*s =new Span_req;
1449 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1455 open_request_parens {
1457 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1461 open_request_parens:
1463 Span_req *s = new Span_req;
1464 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1469 Span_req* s= new Span_req;
1471 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1474 Span_req* s= new Span_req;
1476 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1482 Text_script_req *t = new Text_script_req;
1483 t->set_mus_property ("text", $1);
1484 t->set_spot (THIS->here_input ());
1488 Text_script_req *t = new Text_script_req;
1489 t->set_mus_property ("text", $1);
1490 t->set_spot (THIS->here_input ());
1494 String ds = to_str ($1);
1495 Text_script_req* t = new Text_script_req;
1497 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1498 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1499 t->set_spot (THIS->here_input ());
1504 script_abbreviation:
1506 $$ = gh_str02scm ("Hat");
1509 $$ = gh_str02scm ("Plus");
1512 $$ = gh_str02scm ("Dash");
1515 $$ = gh_str02scm ("Bar");
1518 $$ = gh_str02scm ("Larger");
1521 $$ = gh_str02scm ("Dot");
1529 | '-' { $$ = CENTER; }
1534 $$ = new Link_array<Request>;
1536 | pre_requests open_request {
1548 multiplied_duration {
1551 | explicit_duration {
1556 optional_notemode_duration:
1558 $$ = THIS->default_duration_.smobbed_copy ();
1560 | multiplied_duration {
1563 | explicit_duration {
1569 bare_unsigned dots {
1571 if (!is_duration_b ($1))
1572 THIS->parser_error (_f ("not a duration: %d", $1));
1576 $$ = Duration (l, $2).smobbed_copy ();
1578 THIS->set_last_duration (unsmob_duration ($$));
1580 | DURATION_IDENTIFIER dots {
1581 Duration *d =unsmob_duration ($1);
1582 Duration k (d->duration_log (),d->dot_count () + $2);
1583 $$ = k.smobbed_copy ();
1585 THIS->set_last_duration (unsmob_duration ($$));
1592 multiplied_duration:
1596 | steno_duration '*' bare_unsigned {
1597 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1599 | steno_duration '*' FRACTION {
1600 Moment m (gh_scm2int (gh_car ($3)), gh_scm2int (gh_cdr ($3)));
1602 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1607 FRACTION { $$ = $1; }
1608 | UNSIGNED '/' UNSIGNED {
1609 $$ = gh_cons (gh_int2scm ($1), gh_int2scm ($3));
1627 | ':' bare_unsigned {
1628 if (!is_duration_b ($2))
1629 THIS->parser_error (_f ("not a duration: %d", $2));
1636 pitch exclamations questions optional_notemode_duration {
1637 if (!THIS->lexer_p_->note_state_b ())
1638 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1640 Note_req *n = new Note_req;
1642 n->set_mus_property ("pitch", $1);
1643 n->set_mus_property ("duration", $4);
1646 n->set_mus_property ("cautionary", SCM_BOOL_T);
1647 if ($2 % 2 || $3 % 2)
1648 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1650 Simultaneous_music*v = new Request_chord (SCM_EOL);
1651 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1654 FIXME: location is one off, since ptich & duration don't contain origin refs.
1656 v->set_spot (THIS->here_input ());
1657 n->set_spot (THIS->here_input ());
1661 | RESTNAME optional_notemode_duration {
1663 SCM e = SCM_UNDEFINED;
1664 if (ly_scm2string ($1) =="s")
1666 Skip_req * skip_p = new Skip_req;
1667 skip_p->set_mus_property ("duration" ,$2);
1669 skip_p->set_spot (THIS->here_input ());
1670 e = skip_p->self_scm ();
1674 Rest_req * rest_req_p = new Rest_req;
1675 rest_req_p->set_mus_property ("duration", $2);
1676 rest_req_p->set_spot (THIS->here_input ());
1677 e = rest_req_p->self_scm ();
1679 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1680 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1681 velt_p->set_spot (THIS->here_input ());
1686 | MULTI_MEASURE_REST optional_notemode_duration {
1687 Skip_req * sk = new Skip_req;
1688 sk->set_mus_property ("duration", $2);
1689 Span_req *sp1 = new Span_req;
1690 Span_req *sp2 = new Span_req;
1691 sp1-> set_span_dir ( START);
1692 sp2-> set_span_dir ( STOP);
1693 SCM r = ly_str02scm ("rest");
1694 sp1->set_mus_property ("span-type", r);
1695 sp2->set_mus_property ("span-type", r);
1697 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1698 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1699 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1700 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1701 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1702 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1704 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1706 $$ = new Sequential_music (SCM_EOL);
1707 $$->set_mus_property ("elements", ms);
1709 | STRING optional_notemode_duration {
1711 Lyric_req* lreq_p = new Lyric_req;
1712 lreq_p->set_mus_property ("text", $1);
1713 lreq_p->set_mus_property ("duration",$2);
1714 lreq_p->set_spot (THIS->here_input ());
1715 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1716 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1723 if (!THIS->lexer_p_->chord_state_b ())
1724 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1731 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1732 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1733 $$->set_spot (THIS->here_input ());
1740 | CHORD_COLON chord_notes {
1749 | chord_notes '.' chord_step {
1750 $$ = gh_append2 ($$, $3);
1758 | CHORD_CARET chord_notes {
1768 | '/' steno_tonic_pitch {
1777 | CHORD_BASS steno_tonic_pitch {
1784 $$ = gh_cons ($1, SCM_EOL);
1786 | CHORDMODIFIER_PITCH {
1787 $$ = gh_cons ($1, SCM_EOL);
1789 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1790 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1797 m.notename_i_ = ($1 - 1) % 7;
1798 m.octave_i_ = $1 > 7 ? 1 : 0;
1799 m.alteration_i_ = 0;
1801 $$ = m.smobbed_copy ();
1803 | bare_unsigned '+' {
1805 m.notename_i_ = ($1 - 1) % 7;
1806 m.octave_i_ = $1 > 7 ? 1 : 0;
1807 m.alteration_i_ = 1;
1810 $$ = m.smobbed_copy ();
1812 | bare_unsigned CHORD_MINUS {
1814 m.notename_i_ = ($1 - 1) % 7;
1815 m.octave_i_ = $1 > 7 ? 1 : 0;
1816 m.alteration_i_ = -1;
1818 $$ = m.smobbed_copy ();
1826 number_expression '+' number_term {
1827 $$ = scm_sum ($1, $3);
1829 | number_expression '-' number_term {
1830 $$ = scm_difference ($1, $3);
1839 | number_factor '*' number_factor {
1840 $$ = scm_product ($1, $3);
1842 | number_factor '/' number_factor {
1843 $$ = scm_divide ($1, $3);
1848 '(' number_expression ')' {
1851 | '-' number_factor { /* %prec UNARY_MINUS */
1852 $$ = scm_difference ($2, SCM_UNDEFINED);
1860 $$ = gh_int2scm ($1);
1865 | NUMBER_IDENTIFIER {
1869 $$ = gh_double2scm (gh_scm2double ($1) CM );
1872 $$ = gh_double2scm (gh_scm2double ($1) PT);
1875 $$ = gh_double2scm (gh_scm2double ($1) INCH);
1878 $$ = gh_double2scm (gh_scm2double ($1) MM);
1881 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
1897 if (scm_integer_p ($1) == SCM_BOOL_T)
1899 int k = gh_scm2int ($1);
1903 THIS->parser_error (_ ("need integer number arg"));
1917 | STRING_IDENTIFIER {
1920 | string '+' string {
1921 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1928 | exclamations '!' { $$ ++; }
1933 | questions '?' { $$ ++; }
1940 My_lily_parser::set_yydebug (bool b)
1947 extern My_lily_parser * current_parser;
1950 My_lily_parser::do_yyparse ()
1953 current_parser = this;;
1954 yyparse ((void*)this);