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 ();
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);
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_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
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 ());
809 $$ = new Grace_music (SCM_EOL);
810 $$->set_mus_property ("element", $2->self_scm ());
811 scm_gc_unprotect_object ($2->self_scm ());
814 | CONTEXT string '=' string Music {
815 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
816 csm->set_mus_property ("element", $5->self_scm ());
817 scm_gc_unprotect_object ($5->self_scm ());
819 csm->set_mus_property ("context-type", $2);
820 csm->set_mus_property ("context-id", $4);
831 int n = gh_scm2int (gh_car ($3)); int d = gh_scm2int (gh_cdr ($3));
833 $$ = new Time_scaled_music (SCM_EOL);
834 $$->set_spot (THIS->pop_spot ());
837 $$->set_mus_property ("element", mp->self_scm ());
838 scm_gc_unprotect_object (mp->self_scm ());
839 $$->set_mus_property ("numerator", gh_int2scm (n));
840 $$->set_mus_property ("denominator", gh_int2scm (d));
841 $$->compress (Moment (n,d));
844 | Repeated_music { $$ = $1; }
845 | Simultaneous_music { $$ = $1; }
846 | Sequential_music { $$ = $1; }
847 | TRANSPOSE pitch Music {
848 $$ = new Transposed_music (SCM_EOL);
850 Pitch pit = *unsmob_pitch ($2);
853 $$->set_mus_property ("element", p->self_scm ());
854 scm_gc_unprotect_object (p->self_scm ());
856 | TRANSPOSE steno_tonic_pitch Music {
857 $$ = new Transposed_music (SCM_EOL);
859 Pitch pit = *unsmob_pitch ($2);
862 $$->set_mus_property ("element", p->self_scm ());
863 scm_gc_unprotect_object (p->self_scm ());
866 | APPLY embedded_scm Music {
867 SCM ret = gh_call1 ($2, $3->self_scm ());
868 Music *m = unsmob_music (ret);
870 THIS->parser_error ("\\apply must return a Music");
871 m = new Music (SCM_EOL);
876 { THIS->lexer_p_->push_note_state (); }
879 THIS->lexer_p_->pop_state ();
882 { THIS->lexer_p_->push_chord_state (); }
885 Music * chm = new Un_relativable_music ;
886 chm->set_mus_property ("element", $3->self_scm ());
889 THIS->lexer_p_->pop_state ();
892 { THIS->lexer_p_->push_lyric_state (); }
896 THIS->lexer_p_->pop_state ();
898 | relative_music { $$ = $1; }
899 | re_rhythmed_music { $$ = $1; }
900 | part_combined_music { $$ = $1; }
904 RELATIVE absolute_pitch Music {
906 Pitch pit = *unsmob_pitch ($2);
907 $$ = new Relative_octave_music (SCM_EOL);
909 $$->set_mus_property ("element", p->self_scm ());
910 scm_gc_unprotect_object (p->self_scm ());
912 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
918 ADDLYRICS Music Music {
919 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
920 l->set_mus_property ("music", $2->self_scm ());
921 l->set_mus_property ("lyrics", $3->self_scm ());
922 scm_gc_unprotect_object ($3->self_scm ());
923 scm_gc_unprotect_object ($2->self_scm ());
929 PARTCOMBINE STRING Music Music {
930 Part_combine_music * p = new Part_combine_music (SCM_EOL);
932 p->set_mus_property ("what", $2);
933 p->set_mus_property ("one", $3->self_scm ());
934 p->set_mus_property ("two", $4->self_scm ());
936 scm_gc_unprotect_object ($3->self_scm ());
937 scm_gc_unprotect_object ($4->self_scm ());
945 TRANSLATOR STRING '=' STRING {
946 Music * t = new Music (SCM_EOL);
947 t->set_mus_property ("iterator-ctor",
948 Change_iterator::constructor_cxx_function);
949 t-> set_mus_property ("change-to-type", $2);
950 t-> set_mus_property ("change-to-id", $4);
953 $$->set_spot (THIS->here_input ());
958 PROPERTY STRING '.' STRING '=' scalar {
960 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
961 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
963 csm->set_mus_property ("element", t->self_scm ());
964 scm_gc_unprotect_object (t->self_scm ());
967 $$->set_spot (THIS->here_input ());
969 csm-> set_mus_property ("context-type", $2);
971 | PROPERTY STRING '.' STRING UNSET {
972 Music *t = new Music (SCM_EOL);
974 t->set_mus_property ("iterator-ctor",
975 Property_unset_iterator::constructor_cxx_function);
976 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
978 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
979 csm->set_mus_property ("element", t->self_scm ());
980 scm_gc_unprotect_object (t->self_scm ());
983 $$->set_spot (THIS->here_input ());
985 csm-> set_mus_property ("context-type", $2);
987 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
988 Music *t = new Music (SCM_EOL);
989 t->set_mus_property ("iterator-ctor",
990 Push_property_iterator::constructor_cxx_function);
991 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
992 t->set_mus_property ("pop-first", SCM_BOOL_T);
993 t->set_mus_property ("grob-property", $6);
994 t->set_mus_property ("grob-value", $8);
995 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
996 csm->set_mus_property ("element", t->self_scm ());
997 scm_gc_unprotect_object (t->self_scm ());
999 $$->set_spot (THIS->here_input ());
1001 csm-> set_mus_property ("context-type", $2);
1003 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
1004 Music *t = new Music (SCM_EOL);
1005 t->set_mus_property ("iterator-ctor",
1006 Push_property_iterator::constructor_cxx_function);
1007 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1008 t->set_mus_property ("grob-property", $6);
1009 t->set_mus_property ("grob-value", $8);
1010 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1011 csm->set_mus_property ("element", t->self_scm ());
1012 scm_gc_unprotect_object (t->self_scm ());
1015 $$->set_spot (THIS->here_input ());
1017 csm-> set_mus_property ("context-type", $2);
1019 | PROPERTY STRING '.' STRING REVERT embedded_scm {
1020 Music *t = new Music (SCM_EOL);
1021 t->set_mus_property ("iterator-ctor",
1022 Pop_property_iterator::constructor_cxx_function);
1023 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1024 t->set_mus_property ("grob-property", $6);
1026 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1027 csm->set_mus_property ("element", t->self_scm ());
1028 scm_gc_unprotect_object (t->self_scm ());
1031 $$->set_spot (THIS->here_input ());
1033 csm-> set_mus_property ("context-type", $2);
1039 | bare_int { $$ = gh_int2scm ($1); }
1040 | embedded_scm { $$ = $1; }
1047 } /*cont */ simple_element post_requests {
1048 Music_sequence *l = dynamic_cast<Music_sequence*> ($3);
1050 for (int i=0; i < $1->size (); i++)
1051 l->append_music ($1->elem (i));
1052 for (int i=0; i < $4->size (); i++)
1053 l->append_music ($4->elem (i));
1056 programming_error ("Need Sequence to add music to");
1064 $$ = new Request_chord (SCM_EOL);
1065 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1066 $$-> set_spot (THIS->here_input ());
1067 $1-> set_spot (THIS->here_input ());
1070 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1072 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1073 csm->set_mus_property ("element", t->self_scm ());
1074 scm_gc_unprotect_object (t->self_scm ());
1077 $$->set_spot (THIS->here_input ());
1079 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1081 | PARTIAL duration_length {
1082 Moment m = - unsmob_duration ($2)->length_mom ();
1083 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1085 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1086 sp->set_mus_property ("element", p->self_scm ());
1087 scm_gc_unprotect_object (p->self_scm ());
1090 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1093 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1094 SCM result = gh_call1 (func, $2);
1097 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1098 Music * p = new Music (SCM_EOL);
1099 set_music_properties (p, gh_car (s));
1100 l = gh_cons (p->self_scm (), l);
1101 scm_gc_unprotect_object (p->self_scm ());
1103 Sequential_music * seq = new Sequential_music (SCM_EOL);
1104 seq->set_mus_property ("elements", l);
1106 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1107 sp->set_mus_property ("element", seq->self_scm ());
1108 scm_gc_unprotect_object (seq->self_scm ());
1111 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1114 Music * p1 = set_property_music (ly_symbol2scm ( "timeSignatureFraction"), $2);
1116 int l = gh_scm2int (gh_car ($2));
1117 int o = gh_scm2int (gh_cdr ($2));
1119 Moment one_beat = Moment (1)/Moment (o);
1120 Moment len = Moment (l) * one_beat;
1123 Music *p2 = set_property_music (ly_symbol2scm ("measureLength"), len.smobbed_copy ());
1124 Music *p3 = set_property_music (ly_symbol2scm ("beatLength"), one_beat.smobbed_copy ());
1126 SCM list = gh_list (p1->self_scm (), p2->self_scm (), p3->self_scm(), SCM_UNDEFINED);
1127 Sequential_music *seq = new Sequential_music (SCM_EOL);
1128 seq->set_mus_property ("elements", list);
1131 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1132 sp->set_mus_property ("element", seq->self_scm ());
1136 scm_gc_unprotect_object (p3->self_scm ());
1137 scm_gc_unprotect_object (p2->self_scm ());
1138 scm_gc_unprotect_object (p1->self_scm ());
1139 scm_gc_unprotect_object (seq->self_scm ());
1144 TODO: should make alias TimingContext for Score
1147 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1152 shorthand_command_req { $$ = $1; }
1153 | verbose_command_req { $$ = $1; }
1156 shorthand_command_req:
1164 $$ = new Barcheck_req;
1170 Span_req*b= new Span_req;
1171 b->set_span_dir (START);
1172 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1176 Span_req*b= new Span_req;
1177 b->set_span_dir ( STOP);
1178 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1182 $$ = new Breathing_sign_req;
1187 verbose_command_req:
1188 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1189 Span_req * sp_p = new Span_req;
1190 sp_p-> set_span_dir ( Direction ($2));
1191 sp_p->set_mus_property ("span-type",$3);
1192 sp_p->set_spot (THIS->here_input ());
1196 Mark_req * m = new Mark_req;
1200 Mark_req *m = new Mark_req;
1201 m->set_mus_property ("label", $2);
1208 Break_req * b = new Break_req;
1210 if (!gh_number_p (s))
1213 b->set_mus_property ("penalty", s);
1214 b->set_spot (THIS->here_input ());
1217 | SKIP duration_length {
1218 Skip_req * skip_p = new Skip_req;
1219 skip_p->set_mus_property ("duration", $2);
1227 Key_change_req *key_p= new Key_change_req;
1230 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1231 Key_change_req *key_p= new Key_change_req;
1233 key_p->set_mus_property ("pitch-alist", $3);
1234 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1241 $$ = new Link_array<Request>;
1243 | post_requests post_request {
1244 $2->set_spot (THIS->here_input ());
1256 request_that_take_dir:
1259 | script_abbreviation {
1260 SCM s = THIS->lexer_p_->lookup_identifier ("dash" + ly_scm2string ($1));
1261 Articulation_req *a = new Articulation_req;
1262 if (gh_string_p (s))
1263 a->set_mus_property ("articulation-type", s);
1264 else THIS->parser_error (_ ("Expecting string as script definition"));
1270 script_dir request_that_take_dir {
1271 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1272 gs->set_direction (Direction ($1));
1274 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1280 REQUEST_IDENTIFIER {
1281 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1282 $$->set_spot (THIS->here_input ());
1284 | DYNAMICSCRIPT embedded_scm {
1286 TODO: junkme, use text-type == dynamic
1288 Text_script_req *d = new Text_script_req;
1289 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1290 d->set_mus_property ("text", $2);
1291 d->set_spot (THIS->here_input ());
1294 | SPANREQUEST bare_int STRING {
1295 Span_req * sp_p = new Span_req;
1296 sp_p->set_span_dir ( Direction ($2));
1297 sp_p->set_mus_property ("span-type", $3);
1298 sp_p->set_spot (THIS->here_input ());
1302 Tremolo_req* a = new Tremolo_req;
1303 a->set_spot (THIS->here_input ());
1304 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1308 Articulation_req * a = new Articulation_req;
1309 a->set_mus_property ("articulation-type", $2);
1310 a->set_spot (THIS->here_input ());
1314 duh, junk this syntax from the parser, if possible.
1317 Arpeggio_req *a = new Arpeggio_req;
1318 a->set_spot (THIS->here_input ());
1322 Glissando_req *g = new Glissando_req;
1323 g->set_spot /* No pun intended */ (THIS->here_input ());
1350 | NOTENAME_PITCH sup_quotes {
1351 Pitch p = *unsmob_pitch ($1);
1353 $$ = p.smobbed_copy ();
1355 | NOTENAME_PITCH sub_quotes {
1356 Pitch p =* unsmob_pitch ($1);
1359 $$ = p.smobbed_copy ();
1372 | TONICNAME_PITCH sup_quotes {
1373 Pitch p = *unsmob_pitch ($1);
1375 $$ = p.smobbed_copy ();
1377 | TONICNAME_PITCH sub_quotes {
1378 Pitch p =* unsmob_pitch ($1);
1381 $$ = p.smobbed_copy ();
1396 PITCH embedded_scm {
1398 if (!unsmob_pitch ($2)) {
1399 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1400 $$ = Pitch ().smobbed_copy ();
1406 DURATION embedded_scm {
1408 if (!unsmob_duration ($2))
1410 THIS->parser_error (_ ("Must have duration object"));
1411 $$ = Duration ().smobbed_copy ();
1418 if (!THIS->lexer_p_->lyric_state_b ())
1419 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1420 $$ = new Extender_req;
1426 if (!THIS->lexer_p_->lyric_state_b ())
1427 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1428 $$ = new Hyphen_req;
1433 close_request_parens {
1435 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1438 close_request_parens:
1440 Span_req* s= new Span_req;
1442 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1445 Span_req* s= new Span_req;
1447 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1450 Span_req*s =new Span_req;
1452 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1455 Span_req*s =new Span_req;
1457 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1463 open_request_parens {
1465 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1469 open_request_parens:
1471 Span_req *s = new Span_req;
1472 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1477 Span_req* s= new Span_req;
1479 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1482 Span_req* s= new Span_req;
1484 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1490 Text_script_req *t = new Text_script_req;
1491 t->set_mus_property ("text", $1);
1492 t->set_spot (THIS->here_input ());
1496 Text_script_req *t = new Text_script_req;
1497 t->set_mus_property ("text", $1);
1498 t->set_spot (THIS->here_input ());
1502 String ds = to_str ($1);
1503 Text_script_req* t = new Text_script_req;
1505 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1506 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1507 t->set_spot (THIS->here_input ());
1512 script_abbreviation:
1514 $$ = gh_str02scm ("Hat");
1517 $$ = gh_str02scm ("Plus");
1520 $$ = gh_str02scm ("Dash");
1523 $$ = gh_str02scm ("Bar");
1526 $$ = gh_str02scm ("Larger");
1529 $$ = gh_str02scm ("Dot");
1537 | '-' { $$ = CENTER; }
1542 $$ = new Link_array<Request>;
1544 | pre_requests open_request {
1556 multiplied_duration {
1559 | explicit_duration {
1564 optional_notemode_duration:
1566 $$ = THIS->default_duration_.smobbed_copy ();
1568 | multiplied_duration {
1571 | explicit_duration {
1577 bare_unsigned dots {
1579 if (!is_duration_b ($1))
1580 THIS->parser_error (_f ("not a duration: %d", $1));
1584 $$ = Duration (l, $2).smobbed_copy ();
1586 THIS->set_last_duration (unsmob_duration ($$));
1588 | DURATION_IDENTIFIER dots {
1589 Duration *d =unsmob_duration ($1);
1590 Duration k (d->duration_log (),d->dot_count () + $2);
1591 $$ = k.smobbed_copy ();
1593 THIS->set_last_duration (unsmob_duration ($$));
1600 multiplied_duration:
1604 | multiplied_duration '*' bare_unsigned {
1605 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1607 | multiplied_duration '*' FRACTION {
1608 Moment m (gh_scm2int (gh_car ($3)), gh_scm2int (gh_cdr ($3)));
1610 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1615 FRACTION { $$ = $1; }
1616 | UNSIGNED '/' UNSIGNED {
1617 $$ = gh_cons (gh_int2scm ($1), gh_int2scm ($3));
1635 | ':' bare_unsigned {
1636 if (!is_duration_b ($2))
1637 THIS->parser_error (_f ("not a duration: %d", $2));
1644 pitch exclamations questions optional_notemode_duration {
1646 Input i = THIS->pop_spot ();
1647 if (!THIS->lexer_p_->note_state_b ())
1648 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1650 Note_req *n = new Note_req;
1652 n->set_mus_property ("pitch", $1);
1653 n->set_mus_property ("duration", $4);
1656 n->set_mus_property ("cautionary", SCM_BOOL_T);
1657 if ($2 % 2 || $3 % 2)
1658 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1660 Simultaneous_music*v = new Request_chord (SCM_EOL);
1661 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1667 | RESTNAME optional_notemode_duration {
1669 Input i = THIS->pop_spot ();
1670 SCM e = SCM_UNDEFINED;
1671 if (ly_scm2string ($1) =="s") {
1673 Skip_req * skip_p = new Skip_req;
1674 skip_p->set_mus_property ("duration" ,$2);
1675 skip_p->set_spot (i);
1676 e = skip_p->self_scm ();
1679 Rest_req * rest_req_p = new Rest_req;
1680 rest_req_p->set_mus_property ("duration", $2);
1681 rest_req_p->set_spot (i);
1682 e = rest_req_p->self_scm ();
1684 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1685 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1686 velt_p->set_spot (i);
1690 | MULTI_MEASURE_REST optional_notemode_duration {
1691 Input i = THIS->pop_spot ();
1693 Skip_req * sk = new Skip_req;
1694 sk->set_mus_property ("duration", $2);
1695 Span_req *sp1 = new Span_req;
1696 Span_req *sp2 = new Span_req;
1697 sp1-> set_span_dir ( START);
1698 sp2-> set_span_dir ( STOP);
1699 SCM r = ly_str02scm ("rest");
1700 sp1->set_mus_property ("span-type", r);
1701 sp2->set_mus_property ("span-type", r);
1703 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1704 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1705 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1706 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1707 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1708 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1710 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1712 $$ = new Sequential_music (SCM_EOL);
1713 $$->set_mus_property ("elements", ms);
1715 | STRING optional_notemode_duration {
1716 Input i = THIS->pop_spot ();
1718 Lyric_req* lreq_p = new Lyric_req;
1719 lreq_p->set_mus_property ("text", $1);
1720 lreq_p->set_mus_property ("duration",$2);
1721 lreq_p->set_spot (i);
1722 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1723 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1728 Input i = THIS->pop_spot ();
1730 if (!THIS->lexer_p_->chord_state_b ())
1731 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1738 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1739 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1740 $$->set_spot (THIS->here_input ());
1747 | CHORD_COLON chord_notes {
1756 | chord_notes '.' chord_step {
1757 $$ = gh_append2 ($$, $3);
1765 | CHORD_CARET chord_notes {
1775 | '/' steno_tonic_pitch {
1784 | CHORD_BASS steno_tonic_pitch {
1791 $$ = gh_cons ($1, SCM_EOL);
1793 | CHORDMODIFIER_PITCH {
1794 $$ = gh_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
1796 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1797 $$ = gh_list (unsmob_pitch ($1)->smobbed_copy (),
1805 m.notename_i_ = ($1 - 1) % 7;
1806 m.octave_i_ = $1 > 7 ? 1 : 0;
1807 m.alteration_i_ = 0;
1809 $$ = m.smobbed_copy ();
1811 | bare_unsigned '+' {
1813 m.notename_i_ = ($1 - 1) % 7;
1814 m.octave_i_ = $1 > 7 ? 1 : 0;
1815 m.alteration_i_ = 1;
1818 $$ = m.smobbed_copy ();
1820 | bare_unsigned CHORD_MINUS {
1822 m.notename_i_ = ($1 - 1) % 7;
1823 m.octave_i_ = $1 > 7 ? 1 : 0;
1824 m.alteration_i_ = -1;
1826 $$ = m.smobbed_copy ();
1834 number_expression '+' number_term {
1835 $$ = scm_sum ($1, $3);
1837 | number_expression '-' number_term {
1838 $$ = scm_difference ($1, $3);
1847 | number_factor '*' number_factor {
1848 $$ = scm_product ($1, $3);
1850 | number_factor '/' number_factor {
1851 $$ = scm_divide ($1, $3);
1856 '(' number_expression ')' {
1859 | '-' number_factor { /* %prec UNARY_MINUS */
1860 $$ = scm_difference ($2, SCM_UNDEFINED);
1868 $$ = gh_int2scm ($1);
1873 | NUMBER_IDENTIFIER {
1877 $$ = gh_double2scm (gh_scm2double ($1) CM );
1880 $$ = gh_double2scm (gh_scm2double ($1) PT);
1883 $$ = gh_double2scm (gh_scm2double ($1) INCH);
1886 $$ = gh_double2scm (gh_scm2double ($1) MM);
1889 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
1905 if (scm_integer_p ($1) == SCM_BOOL_T)
1907 int k = gh_scm2int ($1);
1911 THIS->parser_error (_ ("need integer number arg"));
1925 | STRING_IDENTIFIER {
1928 | string '+' string {
1929 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1936 | exclamations '!' { $$ ++; }
1941 | questions '?' { $$ ++; }
1948 My_lily_parser::set_yydebug (bool b)
1955 extern My_lily_parser * current_parser;
1958 My_lily_parser::do_yyparse ()
1961 current_parser = this;;
1962 yyparse ((void*)this);