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 Two shift/reduce problems:
21 #include "translator-def.hh"
22 #include "lily-guile.hh"
23 #include "change-iterator.hh"
25 #include "my-lily-lexer.hh"
26 #include "paper-def.hh"
27 #include "midi-def.hh"
29 #include "file-path.hh"
31 #include "dimensions.hh"
32 #include "command-request.hh"
33 #include "musical-request.hh"
34 #include "my-lily-parser.hh"
35 #include "context-specced-music.hh"
37 #include "music-list.hh"
38 #include "output-property-music-iterator.hh"
39 #include "property-iterator.hh"
40 #include "file-results.hh"
43 #include "relative-music.hh"
44 #include "lyric-combine-music.hh"
45 #include "transposed-music.hh"
46 #include "time-scaled-music.hh"
47 #include "repeated-music.hh"
49 #include "lilypond-input-version.hh"
50 #include "grace-music.hh"
51 #include "part-combine-music.hh"
52 #include "scm-hash.hh"
53 #include "auto-change-iterator.hh"
54 #include "un-relativable-music.hh"
58 regular_identifier_b (SCM id)
60 String str = ly_scm2string (id);
61 char const *s = str.ch_C() ;
66 v = v && isalpha (*s);
74 set_property_music (SCM sym, SCM value)
76 Music * p = new Music (SCM_EOL);
77 p->set_mus_property ("symbol", sym);
78 p->set_mus_property ("iterator-ctor",
79 Property_iterator::constructor_cxx_function);
81 p->set_mus_property ("value", value);
88 return t && t == 1 << intlog2 (t);
92 set_music_properties (Music *p, SCM a)
94 for (SCM k = a; gh_pair_p (k); k = gh_cdr (k))
96 p->set_mus_property (gh_caar (k), gh_cdar (k));
106 // needed for bison.simple's malloc () and free ()
113 #define YYERROR_VERBOSE 1
115 #define YYPARSE_PARAM my_lily_parser_l
116 #define YYLEX_PARAM my_lily_parser_l
118 ((My_lily_parser *) my_lily_parser_l)
120 #define yyerror THIS->parser_error
121 #define ARRAY_SIZE(a,s) if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
128 Link_array<Request> *reqvec;
130 String *string; // needed by the lexer as temporary scratch area.
134 Scheme_hash_table *scmhash;
135 Music_output_def * outputdef;
139 /* We use SCMs to do strings, because it saves us the trouble of
140 deleting them. Let's hope that a stack overflow doesnt trigger a move
141 of the parse stack onto the heap. */
151 yylex (YYSTYPE *s, void * v_l)
153 My_lily_parser *pars_l = (My_lily_parser*) v_l;
154 My_lily_lexer * lex_l = pars_l->lexer_p_;
156 lex_l->lexval_l = (void*) s;
157 return lex_l->yylex ();
165 /* tokens which are not keywords */
175 %token CHORDMODIFIERS
183 %token ELEMENTDESCRIPTIONS
199 %token MULTI_MEASURE_REST
211 %token OVERRIDE SET REVERT
224 %token COMMANDSPANREQUEST
226 %token OUTPUTPROPERTY
236 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
237 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
239 %type <i> exclamations questions dots
241 %token <scm> NOTENAME_PITCH
242 %token <scm> TONICNAME_PITCH
243 %token <scm> CHORDMODIFIER_PITCH
244 %token <scm> DURATION_IDENTIFIER
245 %token <scm> FRACTION
246 %token <id> IDENTIFIER
249 %token <scm> SCORE_IDENTIFIER
250 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
252 %token <scm> NUMBER_IDENTIFIER
253 %token <scm> REQUEST_IDENTIFIER
254 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
255 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
256 %token <scm> RESTNAME
262 %type <outputdef> output_def
263 %type <scmhash> lilypond_header lilypond_header_body
264 %type <request> open_request_parens close_request_parens open_request close_request
265 %type <request> request_with_dir request_that_take_dir verbose_request
266 %type <i> sub_quotes sup_quotes
267 %type <music> simple_element request_chord command_element Simple_music Composite_music
268 %type <music> Alternative_music Repeated_music
269 %type <i> tremolo_type
270 %type <i> bare_int bare_unsigned
273 %type <scm> identifier_init
275 %type <scm> steno_duration optional_notemode_duration multiplied_duration
276 %type <scm> explicit_duration
278 %type <reqvec> pre_requests post_requests
279 %type <request> gen_text_def
280 %type <scm> steno_pitch pitch absolute_pitch
281 %type <scm> explicit_pitch steno_tonic_pitch
283 %type <scm> chord_additions chord_subtractions chord_notes chord_step
285 %type <scm> chord_note chord_inversion chord_bass
286 %type <scm> duration_length fraction
288 %type <scm> embedded_scm scalar
289 %type <music> Music Sequential_music Simultaneous_music Music_sequence
290 %type <music> relative_music re_rhythmed_music part_combined_music
291 %type <music> property_def translator_change
292 %type <scm> Music_list
293 %type <outputdef> music_output_def_body
294 %type <request> shorthand_command_req
295 %type <request> post_request
296 %type <music> command_req verbose_command_req
297 %type <request> extender_req
298 %type <request> hyphen_req
299 %type <scm> string bare_number number_expression number_term number_factor
301 %type <score> score_block score_body
303 %type <scm> translator_spec_block translator_spec_body
304 %type <tempo> tempo_request
305 %type <scm> notenames_body notenames_block chordmodifiers_block
306 %type <scm> script_abbreviation
312 /* We don't assign precedence to / and *, because we might need varied
313 prec levels in different prods */
319 lilypond: /* empty */
320 | lilypond toplevel_expression {}
321 | lilypond assignment { }
323 THIS->error_level_i_ = 1;
326 THIS->error_level_i_ = 1;
332 THIS->lexer_p_->pitchname_tab_ = $1;
334 | chordmodifiers_block {
335 THIS->lexer_p_->chordmodifier_tab_ = $1;
339 scm_gc_unprotect_object (global_header_p->self_scm ());
340 global_header_p = $1;
343 score_global_array.push ($1);
346 if (dynamic_cast<Paper_def*> ($1))
347 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
348 else if (dynamic_cast<Midi_def*> ($1))
349 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
362 chordmodifiers_block:
363 CHORDMODIFIERS notenames_body { $$ = $2; }
367 PITCHNAMES notenames_body { $$ = $2; }
372 int i = scm_ilength ($1);
374 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
375 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
376 SCM pt = gh_cdar (s);
377 if (!unsmob_pitch (pt))
378 THIS->parser_error ("Need pitch object.");
380 scm_hashq_set_x (tab, gh_caar (s), pt);
387 lilypond_header_body:
389 $$ = new Scheme_hash_table;
391 Scope *sc = new Scope ($$);
392 THIS->lexer_p_-> scope_l_arr_.push (sc);
394 | lilypond_header_body assignment {
400 HEADER '{' lilypond_header_body '}' {
402 delete THIS->lexer_p_-> scope_l_arr_.pop ();
412 THIS->remember_spot ();
414 /* cont */ '=' identifier_init {
417 Should find generic way of associating input with objects.
419 Input ip = THIS->pop_spot ();
421 if (! regular_identifier_b ($1))
423 ip.warning (_ ("Identifier should have alphabetic characters only"));
426 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
429 TODO: devise standard for protection in parser.
431 The parser stack lives on the C-stack, which means that
432 all objects can be unprotected as soon as they're here.
442 $$ = $1->self_scm ();
443 scm_gc_unprotect_object ($$);
446 $$ = $1->self_scm ();
447 scm_gc_unprotect_object ($$);
449 | translator_spec_block {
453 $$ = $1->self_scm ();
454 scm_gc_unprotect_object ($$);
457 $$ = $1->self_scm ();
458 scm_gc_unprotect_object ($$);
460 | explicit_duration {
463 | number_expression {
474 translator_spec_block:
475 TRANSLATOR '{' translator_spec_body '}'
481 translator_spec_body:
482 TRANSLATOR_IDENTIFIER {
483 $$ = unsmob_translator_def ($1)->clone_scm ();
484 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
487 $$ = Translator_def::make_scm ();
488 Translator_def*td = unsmob_translator_def ($$);
489 td->translator_group_type_ = $2;
490 td->set_spot (THIS->here_input ());
492 | translator_spec_body STRING '=' embedded_scm {
493 unsmob_translator_def ($$)->add_property_assign ($2, $4);
495 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
496 unsmob_translator_def ($$)
497 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
499 | translator_spec_body STRING REVERT embedded_scm {
500 unsmob_translator_def ($$)->add_pop_property (
501 scm_string_to_symbol ($2), $4);
503 | translator_spec_body NAME STRING {
504 unsmob_translator_def ($$)->type_name_ = $3;
506 | translator_spec_body CONSISTS STRING {
507 unsmob_translator_def ($$)->add_element ($3);
509 | translator_spec_body ALIAS STRING {
510 Translator_def*td = unsmob_translator_def ($$);
511 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
513 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
514 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
515 unsmob_translator_def ($$)
516 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
519 | translator_spec_body CONSISTSEND STRING {
520 unsmob_translator_def ($$)->add_last_element ( $3);
522 | translator_spec_body ACCEPTS STRING {
523 unsmob_translator_def ($$)->set_acceptor ($3,true);
525 | translator_spec_body DENIES STRING {
526 unsmob_translator_def ($$)->set_acceptor ($3,false);
528 | translator_spec_body REMOVE STRING {
529 unsmob_translator_def ($$)->remove_element ($3);
538 THIS->remember_spot ();
540 /*cont*/ '{' score_body '}' {
543 if (!$$->def_p_arr_.size ())
545 Music_output_def *id =
546 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
547 $$->add_output (id ? id->clone () : new Paper_def );
556 $$->set_spot (THIS->here_input ());
557 SCM m = $1->self_scm ();
558 scm_gc_unprotect_object (m);
562 $$ = new Score (*unsmob_score ($1));
563 $$->set_spot (THIS->here_input ());
565 | score_body lilypond_header {
566 scm_gc_unprotect_object ($2->self_scm ());
569 | score_body output_def {
582 music_output_def_body '}' {
584 THIS-> lexer_p_-> scope_l_arr_.pop ();
588 music_output_def_body:
590 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
595 p = dynamic_cast<Midi_def*> (id->clone ());
600 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
603 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
606 p = dynamic_cast<Paper_def*> (id->clone ());
609 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
612 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
613 Music_output_def *p = unsmob_music_output_def ($3);
615 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
618 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
619 Music_output_def *p = unsmob_music_output_def ($3);
622 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
625 | music_output_def_body assignment {
628 | music_output_def_body translator_spec_block {
629 $$->assign_translator ($2);
631 | music_output_def_body STYLESHEET embedded_scm {
632 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
634 | music_output_def_body tempo_request {
636 junk this ? there already is tempo stuff in
639 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
640 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
641 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
643 | music_output_def_body error {
649 TEMPO steno_duration '=' bare_unsigned {
651 $$->set_mus_property ("duration", $2);
652 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
656 Music_list: /* empty */ {
657 $$ = gh_cons (SCM_EOL, SCM_EOL);
661 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
662 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
663 if (gh_pair_p (gh_cdr (s)))
664 gh_set_cdr_x (gh_cdr (s), c); /* append */
666 gh_set_car_x (s, c); /* set first cons */
667 gh_set_cdr_x (s, c) ; /* remember last cell */
683 | ALTERNATIVE Music_sequence {
685 $2->set_spot (THIS->here_input ());
693 REPEAT string bare_unsigned Music Alternative_music
695 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
696 if (alts && $3 < alts->length_i ())
697 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
701 Repeated_music * r = new Repeated_music (SCM_EOL);
705 r-> set_mus_property ("body", beg->self_scm ());
706 scm_gc_unprotect_object (beg->self_scm ());
708 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
712 alts->truncate (times);
713 r-> set_mus_property ("alternatives", alts->self_scm ());
714 scm_gc_unprotect_object (alts->self_scm ());
716 SCM func = scm_primitive_eval (ly_symbol2scm ("repeat-name-to-ctor"));
717 SCM result = gh_call1 (func, $2);
719 set_music_properties (r, result);
721 r->set_spot (*$4->origin ());
726 Music_sequence: '{' Music_list '}' {
727 $$ = new Music_sequence (SCM_EOL);
728 $$->set_mus_property ("elements", gh_car ($2));
733 SEQUENTIAL '{' Music_list '}' {
734 $$ = new Sequential_music (SCM_EOL);
735 $$->set_mus_property ("elements", gh_car ($3));
737 | '{' Music_list '}' {
738 $$ = new Sequential_music (SCM_EOL);
739 $$->set_mus_property ("elements", gh_car ($2));
744 SIMULTANEOUS '{' Music_list '}'{
745 $$ = new Simultaneous_music (SCM_EOL);
746 $$->set_mus_property ("elements", gh_car ($3));
749 | '<' Music_list '>' {
750 $$ = new Simultaneous_music (SCM_EOL);
751 $$->set_mus_property ("elements", gh_car ($2));
756 request_chord { $$ = $1; }
757 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
759 if (!gh_symbol_p ($3))
761 THIS->parser_error (_ ("Second argument must be a symbol"));
763 /*hould check # args */
764 if (!gh_procedure_p (pred))
766 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
769 Music *m = new Music (SCM_EOL);
770 m->set_mus_property ("predicate", pred);
771 m->set_mus_property ("grob-property", $3);
772 m->set_mus_property ("grob-value", $5);
773 m->set_mus_property ("iterator-ctor",
774 Output_property_music_iterator::constructor_cxx_function);
779 $$ = unsmob_music ($1)->clone ();
787 CONTEXT STRING Music {
788 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
789 csm->set_mus_property ("element", $3->self_scm ());
790 scm_gc_unprotect_object ($3->self_scm ());
792 csm->set_mus_property ("context-type",$2);
793 csm->set_mus_property ("context-id", ly_str02scm (""));
797 | AUTOCHANGE STRING Music {
798 Music * chm = new Music_wrapper (SCM_EOL);
799 chm->set_mus_property ("element", $3->self_scm ());
800 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
802 scm_gc_unprotect_object ($3->self_scm ());
803 chm->set_mus_property ("what", $2);
806 chm->set_spot (*$3->origin ());
811 The other version is for easier debugging of
812 Sequential_music_iterator in combination with grace notes.
815 SCM start = THIS->lexer_p_->lookup_identifier ("startGraceMusic");
816 SCM stop = THIS->lexer_p_->lookup_identifier ("stopGraceMusic");
817 Music *startm = unsmob_music (start);
818 Music *stopm = unsmob_music (stop);
822 stopm = stopm->clone ();
823 ms = gh_cons (stopm->self_scm (), ms);
824 scm_gc_unprotect_object (stopm->self_scm ());
826 ms = gh_cons ($2->self_scm (), ms);
827 scm_gc_unprotect_object ($2->self_scm());
829 startm = startm->clone ();
830 ms = gh_cons (startm->self_scm () , ms);
831 scm_gc_unprotect_object (startm->self_scm ());
834 Music* seq = new Sequential_music (SCM_EOL);
835 seq->set_mus_property ("elements", ms);
837 $$ = new Grace_music (SCM_EOL);
838 $$->set_mus_property ("element", seq->self_scm ());
839 scm_gc_unprotect_object (seq->self_scm ());
841 $$ = new Grace_music (SCM_EOL);
842 $$->set_mus_property ("element", $2->self_scm ());
843 scm_gc_unprotect_object ($2->self_scm ());
848 | CONTEXT string '=' string Music {
849 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
850 csm->set_mus_property ("element", $5->self_scm ());
851 scm_gc_unprotect_object ($5->self_scm ());
853 csm->set_mus_property ("context-type", $2);
854 csm->set_mus_property ("context-id", $4);
859 THIS->remember_spot ();
865 int n = gh_scm2int (gh_car ($3)); int d = gh_scm2int (gh_cdr ($3));
867 $$ = new Time_scaled_music (SCM_EOL);
868 $$->set_spot (THIS->pop_spot ());
871 $$->set_mus_property ("element", mp->self_scm ());
872 scm_gc_unprotect_object (mp->self_scm ());
873 $$->set_mus_property ("numerator", gh_int2scm (n));
874 $$->set_mus_property ("denominator", gh_int2scm (d));
875 $$->compress (Moment (n,d));
878 | Repeated_music { $$ = $1; }
879 | Simultaneous_music { $$ = $1; }
880 | Sequential_music { $$ = $1; }
881 | TRANSPOSE pitch Music {
882 $$ = new Transposed_music (SCM_EOL);
884 Pitch pit = *unsmob_pitch ($2);
887 $$->set_mus_property ("element", p->self_scm ());
888 scm_gc_unprotect_object (p->self_scm ());
890 | TRANSPOSE steno_tonic_pitch Music {
891 $$ = new Transposed_music (SCM_EOL);
893 Pitch pit = *unsmob_pitch ($2);
896 $$->set_mus_property ("element", p->self_scm ());
897 scm_gc_unprotect_object (p->self_scm ());
900 | APPLY embedded_scm Music {
901 SCM ret = gh_call1 ($2, $3->self_scm ());
902 Music *m = unsmob_music (ret);
904 THIS->parser_error ("\\apply must return a Music");
905 m = new Music (SCM_EOL);
910 { THIS->lexer_p_->push_note_state (); }
913 THIS->lexer_p_->pop_state ();
916 { THIS->lexer_p_->push_chord_state (); }
919 Music * chm = new Un_relativable_music ;
920 chm->set_mus_property ("element", $3->self_scm ());
923 THIS->lexer_p_->pop_state ();
926 { THIS->lexer_p_->push_lyric_state (); }
930 THIS->lexer_p_->pop_state ();
932 | relative_music { $$ = $1; }
933 | re_rhythmed_music { $$ = $1; }
934 | part_combined_music { $$ = $1; }
938 RELATIVE absolute_pitch Music {
940 Pitch pit = *unsmob_pitch ($2);
941 $$ = new Relative_octave_music (SCM_EOL);
943 $$->set_mus_property ("element", p->self_scm ());
944 scm_gc_unprotect_object (p->self_scm ());
946 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
952 ADDLYRICS Music Music {
953 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
954 l->set_mus_property ("music", $2->self_scm ());
955 l->set_mus_property ("lyrics", $3->self_scm ());
956 scm_gc_unprotect_object ($3->self_scm ());
957 scm_gc_unprotect_object ($2->self_scm ());
963 PARTCOMBINE STRING Music Music {
964 Part_combine_music * p = new Part_combine_music (SCM_EOL);
966 p->set_mus_property ("what", $2);
967 p->set_mus_property ("one", $3->self_scm ());
968 p->set_mus_property ("two", $4->self_scm ());
970 scm_gc_unprotect_object ($3->self_scm ());
971 scm_gc_unprotect_object ($4->self_scm ());
979 TRANSLATOR STRING '=' STRING {
980 Music * t = new Music (SCM_EOL);
981 t->set_mus_property ("iterator-ctor",
982 Change_iterator::constructor_cxx_function);
983 t-> set_mus_property ("change-to-type", $2);
984 t-> set_mus_property ("change-to-id", $4);
987 $$->set_spot (THIS->here_input ());
992 PROPERTY STRING '.' STRING '=' scalar {
994 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
995 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
997 csm->set_mus_property ("element", t->self_scm ());
998 scm_gc_unprotect_object (t->self_scm ());
1001 $$->set_spot (THIS->here_input ());
1003 csm-> set_mus_property ("context-type", $2);
1005 | PROPERTY STRING '.' STRING UNSET {
1006 Music *t = new Music (SCM_EOL);
1008 t->set_mus_property ("iterator-ctor",
1009 Property_unset_iterator::constructor_cxx_function);
1010 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
1012 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1013 csm->set_mus_property ("element", t->self_scm ());
1014 scm_gc_unprotect_object (t->self_scm ());
1017 $$->set_spot (THIS->here_input ());
1019 csm-> set_mus_property ("context-type", $2);
1021 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
1022 Music *t = new Music (SCM_EOL);
1023 t->set_mus_property ("iterator-ctor",
1024 Push_property_iterator::constructor_cxx_function);
1025 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1026 t->set_mus_property ("pop-first", SCM_BOOL_T);
1027 t->set_mus_property ("grob-property", $6);
1028 t->set_mus_property ("grob-value", $8);
1029 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1030 csm->set_mus_property ("element", t->self_scm ());
1031 scm_gc_unprotect_object (t->self_scm ());
1033 $$->set_spot (THIS->here_input ());
1035 csm-> set_mus_property ("context-type", $2);
1037 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
1038 Music *t = new Music (SCM_EOL);
1039 t->set_mus_property ("iterator-ctor",
1040 Push_property_iterator::constructor_cxx_function);
1041 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1042 t->set_mus_property ("grob-property", $6);
1043 t->set_mus_property ("grob-value", $8);
1044 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1045 csm->set_mus_property ("element", t->self_scm ());
1046 scm_gc_unprotect_object (t->self_scm ());
1049 $$->set_spot (THIS->here_input ());
1051 csm-> set_mus_property ("context-type", $2);
1053 | PROPERTY STRING '.' STRING REVERT embedded_scm {
1054 Music *t = new Music (SCM_EOL);
1055 t->set_mus_property ("iterator-ctor",
1056 Pop_property_iterator::constructor_cxx_function);
1057 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1058 t->set_mus_property ("grob-property", $6);
1060 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1061 csm->set_mus_property ("element", t->self_scm ());
1062 scm_gc_unprotect_object (t->self_scm ());
1065 $$->set_spot (THIS->here_input ());
1067 csm-> set_mus_property ("context-type", $2);
1073 | bare_int { $$ = gh_int2scm ($1); }
1074 | embedded_scm { $$ = $1; }
1079 pre_requests simple_element post_requests {
1080 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1082 for (int i=0; i < $1->size (); i++)
1083 l->append_music ($1->elem (i));
1084 for (int i=0; i < $3->size (); i++)
1085 l->append_music ($3->elem (i));
1088 programming_error ("Need Sequence to add music to");
1097 $$ = new Request_chord (SCM_EOL);
1098 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1099 $$-> set_spot (THIS->here_input ());
1100 $1-> set_spot (THIS->here_input ());
1103 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1105 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1106 csm->set_mus_property ("element", t->self_scm ());
1107 scm_gc_unprotect_object (t->self_scm ());
1110 $$->set_spot (THIS->here_input ());
1112 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1114 | PARTIAL duration_length {
1115 Moment m = - unsmob_duration ($2)->length_mom ();
1116 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1118 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1119 sp->set_mus_property ("element", p->self_scm ());
1120 scm_gc_unprotect_object (p->self_scm ());
1123 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1126 SCM func = scm_primitive_eval (ly_symbol2scm ("clef-name-to-properties"));
1127 SCM result = gh_call1 (func, $2);
1130 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1131 Music * p = new Music (SCM_EOL);
1132 set_music_properties (p, gh_car (s));
1133 l = gh_cons (p->self_scm (), l);
1134 scm_gc_unprotect_object (p->self_scm ());
1136 Sequential_music * seq = new Sequential_music (SCM_EOL);
1137 seq->set_mus_property ("elements", l);
1139 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1140 sp->set_mus_property ("element", seq->self_scm ());
1141 scm_gc_unprotect_object (seq->self_scm ());
1144 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1147 Music * p1 = set_property_music (ly_symbol2scm ( "timeSignatureFraction"), $2);
1149 int l = gh_scm2int (gh_car ($2));
1150 int o = gh_scm2int (gh_cdr ($2));
1152 Moment one_beat = Moment (1)/Moment (o);
1153 Moment len = Moment (l) * one_beat;
1156 Music *p2 = set_property_music (ly_symbol2scm ("measureLength"), len.smobbed_copy ());
1157 Music *p3 = set_property_music (ly_symbol2scm ("beatLength"), one_beat.smobbed_copy ());
1159 SCM list = gh_list (p1->self_scm (), p2->self_scm (), p3->self_scm(), SCM_UNDEFINED);
1160 Sequential_music *seq = new Sequential_music (SCM_EOL);
1161 seq->set_mus_property ("elements", list);
1164 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1165 sp->set_mus_property ("element", seq->self_scm ());
1169 scm_gc_unprotect_object (p3->self_scm ());
1170 scm_gc_unprotect_object (p2->self_scm ());
1171 scm_gc_unprotect_object (p1->self_scm ());
1172 scm_gc_unprotect_object (seq->self_scm ());
1177 TODO: should make alias TimingContext for Score
1180 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1185 shorthand_command_req { $$ = $1; }
1186 | verbose_command_req { $$ = $1; }
1189 shorthand_command_req:
1197 $$ = new Barcheck_req;
1203 Span_req*b= new Span_req;
1204 b->set_span_dir (START);
1205 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1209 Span_req*b= new Span_req;
1210 b->set_span_dir ( STOP);
1211 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1215 $$ = new Breathing_sign_req;
1220 verbose_command_req:
1221 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1222 Span_req * sp_p = new Span_req;
1223 sp_p-> set_span_dir ( Direction ($2));
1224 sp_p->set_mus_property ("span-type",$3);
1225 sp_p->set_spot (THIS->here_input ());
1229 Mark_req * m = new Mark_req;
1233 Mark_req *m = new Mark_req;
1234 m->set_mus_property ("label", $2);
1241 Break_req * b = new Break_req;
1243 if (!gh_number_p (s))
1246 b->set_mus_property ("penalty", s);
1247 b->set_spot (THIS->here_input ());
1250 | SKIP duration_length {
1251 Skip_req * skip_p = new Skip_req;
1252 skip_p->set_mus_property ("duration", $2);
1260 Key_change_req *key_p= new Key_change_req;
1263 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1264 Key_change_req *key_p= new Key_change_req;
1266 key_p->set_mus_property ("pitch-alist", $3);
1267 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1274 $$ = new Link_array<Request>;
1276 | post_requests post_request {
1277 $2->set_spot (THIS->here_input ());
1289 request_that_take_dir:
1292 | script_abbreviation {
1293 SCM s = THIS->lexer_p_->lookup_identifier ("dash" + ly_scm2string ($1));
1294 Articulation_req *a = new Articulation_req;
1295 if (gh_string_p (s))
1296 a->set_mus_property ("articulation-type", s);
1297 else THIS->parser_error (_ ("Expecting string as script definition"));
1303 script_dir request_that_take_dir {
1304 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1305 gs->set_direction (Direction ($1));
1307 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1313 REQUEST_IDENTIFIER {
1314 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1315 $$->set_spot (THIS->here_input ());
1317 | DYNAMICSCRIPT embedded_scm {
1319 TODO: junkme, use text-type == dynamic
1321 Text_script_req *d = new Text_script_req;
1322 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1323 d->set_mus_property ("text", $2);
1324 d->set_spot (THIS->here_input ());
1327 | SPANREQUEST bare_int STRING {
1328 Span_req * sp_p = new Span_req;
1329 sp_p->set_span_dir ( Direction ($2));
1330 sp_p->set_mus_property ("span-type", $3);
1331 sp_p->set_spot (THIS->here_input ());
1335 Tremolo_req* a = new Tremolo_req;
1336 a->set_spot (THIS->here_input ());
1337 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1341 Articulation_req * a = new Articulation_req;
1342 a->set_mus_property ("articulation-type", $2);
1343 a->set_spot (THIS->here_input ());
1347 duh, junk this syntax from the parser, if possible.
1350 Arpeggio_req *a = new Arpeggio_req;
1351 a->set_spot (THIS->here_input ());
1355 Glissando_req *g = new Glissando_req;
1356 g->set_spot /* No pun intended */ (THIS->here_input ());
1383 | NOTENAME_PITCH sup_quotes {
1384 Pitch p = *unsmob_pitch ($1);
1386 $$ = p.smobbed_copy ();
1388 | NOTENAME_PITCH sub_quotes {
1389 Pitch p =* unsmob_pitch ($1);
1392 $$ = p.smobbed_copy ();
1405 | TONICNAME_PITCH sup_quotes {
1406 Pitch p = *unsmob_pitch ($1);
1408 $$ = p.smobbed_copy ();
1410 | TONICNAME_PITCH sub_quotes {
1411 Pitch p =* unsmob_pitch ($1);
1414 $$ = p.smobbed_copy ();
1429 PITCH embedded_scm {
1431 if (!unsmob_pitch ($2)) {
1432 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1433 $$ = Pitch ().smobbed_copy ();
1439 DURATION embedded_scm {
1441 if (!unsmob_duration ($2))
1443 THIS->parser_error (_ ("Must have duration object"));
1444 $$ = Duration ().smobbed_copy ();
1451 if (!THIS->lexer_p_->lyric_state_b ())
1452 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1453 $$ = new Extender_req;
1459 if (!THIS->lexer_p_->lyric_state_b ())
1460 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1461 $$ = new Hyphen_req;
1466 close_request_parens {
1468 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1471 close_request_parens:
1473 Span_req* s= new Span_req;
1475 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1478 Span_req* s= new Span_req;
1480 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1483 Span_req*s =new Span_req;
1485 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1488 Span_req*s =new Span_req;
1490 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1496 open_request_parens {
1498 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1502 open_request_parens:
1504 Span_req *s = new Span_req;
1505 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1510 Span_req* s= new Span_req;
1512 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1515 Span_req* s= new Span_req;
1517 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1523 Text_script_req *t = new Text_script_req;
1524 t->set_mus_property ("text", $1);
1525 t->set_spot (THIS->here_input ());
1529 Text_script_req *t = new Text_script_req;
1530 t->set_mus_property ("text", $1);
1531 t->set_spot (THIS->here_input ());
1535 String ds = to_str ($1);
1536 Text_script_req* t = new Text_script_req;
1538 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1539 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1540 t->set_spot (THIS->here_input ());
1545 script_abbreviation:
1547 $$ = gh_str02scm ("Hat");
1550 $$ = gh_str02scm ("Plus");
1553 $$ = gh_str02scm ("Dash");
1556 $$ = gh_str02scm ("Bar");
1559 $$ = gh_str02scm ("Larger");
1562 $$ = gh_str02scm ("Dot");
1570 | '-' { $$ = CENTER; }
1575 $$ = new Link_array<Request>;
1577 | pre_requests open_request {
1589 multiplied_duration {
1592 | explicit_duration {
1597 optional_notemode_duration:
1599 $$ = THIS->default_duration_.smobbed_copy ();
1601 | multiplied_duration {
1604 | explicit_duration {
1610 bare_unsigned dots {
1612 if (!is_duration_b ($1))
1613 THIS->parser_error (_f ("not a duration: %d", $1));
1617 $$ = Duration (l, $2).smobbed_copy ();
1619 THIS->set_last_duration (unsmob_duration ($$));
1621 | DURATION_IDENTIFIER dots {
1622 Duration *d =unsmob_duration ($1);
1623 Duration k (d->duration_log (),d->dot_count () + $2);
1624 $$ = k.smobbed_copy ();
1626 THIS->set_last_duration (unsmob_duration ($$));
1633 multiplied_duration:
1637 | multiplied_duration '*' bare_unsigned {
1638 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1640 | multiplied_duration '*' FRACTION {
1641 Rational m (gh_scm2int (gh_car ($3)), gh_scm2int (gh_cdr ($3)));
1643 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1648 FRACTION { $$ = $1; }
1649 | UNSIGNED '/' UNSIGNED {
1650 $$ = gh_cons (gh_int2scm ($1), gh_int2scm ($3));
1668 | ':' bare_unsigned {
1669 if (!is_duration_b ($2))
1670 THIS->parser_error (_f ("not a duration: %d", $2));
1677 pitch exclamations questions optional_notemode_duration {
1678 if (!THIS->lexer_p_->note_state_b ())
1679 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1681 Note_req *n = new Note_req;
1683 n->set_mus_property ("pitch", $1);
1684 n->set_mus_property ("duration", $4);
1687 n->set_mus_property ("cautionary", SCM_BOOL_T);
1688 if ($2 % 2 || $3 % 2)
1689 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1691 Simultaneous_music*v = new Request_chord (SCM_EOL);
1692 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1695 FIXME: location is one off, since ptich & duration don't contain origin refs.
1697 v->set_spot (THIS->here_input ());
1698 n->set_spot (THIS->here_input ());
1702 | RESTNAME optional_notemode_duration {
1704 SCM e = SCM_UNDEFINED;
1705 if (ly_scm2string ($1) =="s")
1707 Skip_req * skip_p = new Skip_req;
1708 skip_p->set_mus_property ("duration" ,$2);
1710 skip_p->set_spot (THIS->here_input ());
1711 e = skip_p->self_scm ();
1715 Rest_req * rest_req_p = new Rest_req;
1716 rest_req_p->set_mus_property ("duration", $2);
1717 rest_req_p->set_spot (THIS->here_input ());
1718 e = rest_req_p->self_scm ();
1720 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1721 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1722 velt_p->set_spot (THIS->here_input ());
1727 | MULTI_MEASURE_REST optional_notemode_duration {
1728 Skip_req * sk = new Skip_req;
1729 sk->set_mus_property ("duration", $2);
1730 Span_req *sp1 = new Span_req;
1731 Span_req *sp2 = new Span_req;
1732 sp1-> set_span_dir ( START);
1733 sp2-> set_span_dir ( STOP);
1734 SCM r = ly_str02scm ("rest");
1735 sp1->set_mus_property ("span-type", r);
1736 sp2->set_mus_property ("span-type", r);
1738 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1739 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1740 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1741 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1742 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1743 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1745 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1747 $$ = new Sequential_music (SCM_EOL);
1748 $$->set_mus_property ("elements", ms);
1750 | STRING optional_notemode_duration {
1752 Lyric_req* lreq_p = new Lyric_req;
1753 lreq_p->set_mus_property ("text", $1);
1754 lreq_p->set_mus_property ("duration",$2);
1755 lreq_p->set_spot (THIS->here_input ());
1756 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1757 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1764 if (!THIS->lexer_p_->chord_state_b ())
1765 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1772 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1773 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1774 $$->set_spot (THIS->here_input ());
1781 | CHORD_COLON chord_notes {
1790 | chord_notes '.' chord_step {
1791 $$ = gh_append2 ($$, $3);
1799 | CHORD_CARET chord_notes {
1809 | '/' steno_tonic_pitch {
1818 | CHORD_BASS steno_tonic_pitch {
1825 $$ = gh_cons ($1, SCM_EOL);
1827 | CHORDMODIFIER_PITCH {
1828 $$ = gh_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
1830 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1831 $$ = gh_list (unsmob_pitch ($1)->smobbed_copy (),
1839 m.notename_i_ = ($1 - 1) % 7;
1840 m.octave_i_ = $1 > 7 ? 1 : 0;
1841 m.alteration_i_ = 0;
1843 $$ = m.smobbed_copy ();
1845 | bare_unsigned '+' {
1847 m.notename_i_ = ($1 - 1) % 7;
1848 m.octave_i_ = $1 > 7 ? 1 : 0;
1849 m.alteration_i_ = 1;
1852 $$ = m.smobbed_copy ();
1854 | bare_unsigned CHORD_MINUS {
1856 m.notename_i_ = ($1 - 1) % 7;
1857 m.octave_i_ = $1 > 7 ? 1 : 0;
1858 m.alteration_i_ = -1;
1860 $$ = m.smobbed_copy ();
1868 number_expression '+' number_term {
1869 $$ = scm_sum ($1, $3);
1871 | number_expression '-' number_term {
1872 $$ = scm_difference ($1, $3);
1881 | number_factor '*' number_factor {
1882 $$ = scm_product ($1, $3);
1884 | number_factor '/' number_factor {
1885 $$ = scm_divide ($1, $3);
1890 '(' number_expression ')' {
1893 | '-' number_factor { /* %prec UNARY_MINUS */
1894 $$ = scm_difference ($2, SCM_UNDEFINED);
1902 $$ = gh_int2scm ($1);
1907 | NUMBER_IDENTIFIER {
1911 $$ = gh_double2scm (gh_scm2double ($1) CM );
1914 $$ = gh_double2scm (gh_scm2double ($1) PT);
1917 $$ = gh_double2scm (gh_scm2double ($1) INCH);
1920 $$ = gh_double2scm (gh_scm2double ($1) MM);
1923 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
1939 if (scm_integer_p ($1) == SCM_BOOL_T)
1941 int k = gh_scm2int ($1);
1945 THIS->parser_error (_ ("need integer number arg"));
1959 | STRING_IDENTIFIER {
1962 | string '+' string {
1963 $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
1970 | exclamations '!' { $$ ++; }
1975 | questions '?' { $$ ++; }
1982 My_lily_parser::set_yydebug (bool b)
1989 extern My_lily_parser * current_parser;
1992 My_lily_parser::do_yyparse ()
1995 current_parser = this;;
1996 yyparse ((void*)this);