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"
48 #include "lilypond-input-version.hh"
49 #include "grace-music.hh"
50 #include "part-combine-music.hh"
51 #include "scm-hash.hh"
52 #include "auto-change-iterator.hh"
53 #include "un-relativable-music.hh"
59 regular_identifier_b (SCM id)
61 String str = ly_scm2string (id);
62 char const *s = str.ch_C() ;
67 v = v && isalpha (*s);
77 return t && t == 1 << intlog2 (t);
82 set_music_properties (Music *p, SCM a)
84 for (SCM k = a; gh_pair_p (k); k = gh_cdr (k))
86 p->set_mus_property (gh_caar (k), gh_cdar (k));
92 Lilypond_version oldest_version ("1.3.59");
95 print_lilypond_versions (ostream &os)
97 os << _f ("Oldest supported input version: %s", oldest_version.str ())
102 // needed for bison.simple's malloc () and free ()
109 #define YYERROR_VERBOSE 1
111 #define YYPARSE_PARAM my_lily_parser_l
112 #define YYLEX_PARAM my_lily_parser_l
114 ((My_lily_parser *) my_lily_parser_l)
116 #define yyerror THIS->parser_error
117 #define ARRAY_SIZE(a,s) if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
124 Link_array<Request> *reqvec;
126 String *string; // needed by the lexer as temporary scratch area.
130 Scheme_hash_table *scmhash;
131 Music_output_def * outputdef;
135 /* We use SCMs to do strings, because it saves us the trouble of
136 deleting them. Let's hope that a stack overflow doesnt trigger a move
137 of the parse stack onto the heap. */
147 yylex (YYSTYPE *s, void * v_l)
149 My_lily_parser *pars_l = (My_lily_parser*) v_l;
150 My_lily_lexer * lex_l = pars_l->lexer_p_;
152 lex_l->lexval_l = (void*) s;
153 return lex_l->yylex ();
161 /* tokens which are not keywords */
171 %token CHORDMODIFIERS
179 %token ELEMENTDESCRIPTIONS
195 %token MULTI_MEASURE_REST
207 %token OVERRIDE SET REVERT
220 %token COMMANDSPANREQUEST
222 %token OUTPUTPROPERTY
232 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
233 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
235 %type <i> exclamations questions dots
237 %token <scm> NOTENAME_PITCH
238 %token <scm> TONICNAME_PITCH
239 %token <scm> CHORDMODIFIER_PITCH
240 %token <scm> DURATION_IDENTIFIER
241 %token <id> IDENTIFIER
244 %token <scm> SCORE_IDENTIFIER
245 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
247 %token <scm> NUMBER_IDENTIFIER
248 %token <scm> REQUEST_IDENTIFIER
249 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
250 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
251 %token <scm> RESTNAME
257 %type <outputdef> output_def
258 %type <scmhash> lilypond_header lilypond_header_body
259 %type <request> open_request_parens close_request_parens open_request close_request
260 %type <request> request_with_dir request_that_take_dir verbose_request
261 %type <i> sub_quotes sup_quotes
262 %type <music> simple_element request_chord command_element Simple_music Composite_music
263 %type <music> Alternative_music Repeated_music
264 %type <i> tremolo_type
265 %type <i> bare_int bare_unsigned
268 %type <scm> identifier_init
270 %type <scm> steno_duration optional_notemode_duration multiplied_duration
271 %type <scm> explicit_duration
273 %type <reqvec> pre_requests post_requests
274 %type <request> gen_text_def
275 %type <scm> steno_pitch pitch absolute_pitch
276 %type <scm> explicit_pitch steno_tonic_pitch
278 %type <scm> chord_additions chord_subtractions chord_notes chord_step
280 %type <scm> chord_note chord_inversion chord_bass
281 %type <scm> duration_length
283 %type <scm> embedded_scm scalar
284 %type <music> Music Sequential_music Simultaneous_music Music_sequence
285 %type <music> relative_music re_rhythmed_music part_combined_music
286 %type <music> property_def translator_change
287 %type <scm> Music_list
288 %type <outputdef> music_output_def_body
289 %type <request> shorthand_command_req
290 %type <request> post_request
291 %type <music> command_req verbose_command_req
292 %type <request> extender_req
293 %type <request> hyphen_req
294 %type <scm> string bare_number number_expression
296 %type <score> score_block score_body
298 %type <scm> translator_spec_block translator_spec_body
299 %type <tempo> tempo_request
300 %type <scm> notenames_body notenames_block chordmodifiers_block
301 %type <scm> script_abbreviation
305 left association: must reduce
306 a - b - c = (a - b) - c
315 multiplied_duration precedence
316 `* 3 / c' and `* 1 / 2' should be equal, try shift rather than
317 forced reduce, and take higher precedence than plain `*' and `/'
319 -- ugr, but it doesn't really work? input/no-notation/parse5.ly
322 %left *forces* reduce
323 %right *forces* shift
325 but we need (the default): *try* shift, and we can't override
326 above %left '*' '/' with `%prec default setting'?
329 %right MUL1 MUL2 INVERSION
333 lilypond: /* empty */
334 | lilypond toplevel_expression {}
335 | lilypond assignment { }
337 THIS->error_level_i_ = 1;
338 //THIS->parser_error (_ ("ly invalid"));
341 THIS->error_level_i_ = 1;
342 //THIS->parser_error (_ ("ly invalid"));
348 THIS->lexer_p_->pitchname_tab_ = $1;
350 | chordmodifiers_block {
351 THIS->lexer_p_->chordmodifier_tab_ = $1;
355 scm_unprotect_object (global_header_p->self_scm ());
356 global_header_p = $1;
359 score_global_array.push ($1);
363 if (dynamic_cast<Paper_def*> ($1))
364 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
365 else if (dynamic_cast<Midi_def*> ($1))
366 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
379 chordmodifiers_block:
380 CHORDMODIFIERS notenames_body { $$ = $2; }
385 PITCHNAMES notenames_body { $$ = $2; }
392 int i = scm_ilength ($1);
394 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
395 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
396 SCM pt = gh_cdar (s);
397 if (!unsmob_pitch (pt))
398 THIS->parser_error ("Need pitch object.");
400 scm_hashq_set_x (tab, gh_caar (s), pt);
407 lilypond_header_body:
409 $$ = new Scheme_hash_table;
411 Scope *sc = new Scope ($$);
412 THIS->lexer_p_-> scope_l_arr_.push (sc);
414 | lilypond_header_body assignment {
420 HEADER '{' lilypond_header_body '}' {
422 delete THIS->lexer_p_-> scope_l_arr_.pop ();
432 THIS->remember_spot ();
434 /* cont */ '=' identifier_init {
435 if (! regular_identifier_b ($1))
436 THIS->parser_error (_ ("Identifier should have alphabetic characters only"));
438 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
441 TODO: devise standard for protection in parser.
443 The parser stack lives on the C-stack, which means that
444 all objects can be unprotected as soon as they're here.
448 Should find generic way of associating input with objects.
458 $$ = $1->self_scm ();
459 scm_unprotect_object ($$);
462 $$ = $1->self_scm ();
463 scm_unprotect_object ($$);
465 | translator_spec_block {
469 $$ = $1->self_scm ();
470 scm_unprotect_object ($$);
473 $$ = $1->self_scm ();
474 scm_unprotect_object ($$);
476 | explicit_duration {
479 | number_expression {
490 translator_spec_block:
491 TRANSLATOR '{' translator_spec_body '}'
497 translator_spec_body:
498 TRANSLATOR_IDENTIFIER {
499 $$ = unsmob_translator_def ($1)->clone_scm ();
500 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
503 $$ = Translator_def::make_scm ();
504 Translator_def*td = unsmob_translator_def ($$);
505 td->translator_group_type_ = $2;
506 td->set_spot (THIS->here_input ());
508 | translator_spec_body STRING '=' embedded_scm {
509 unsmob_translator_def ($$)->add_property_assign ($2, $4);
511 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
512 unsmob_translator_def ($$)
513 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
515 | translator_spec_body STRING REVERT embedded_scm {
516 unsmob_translator_def ($$)->add_pop_property (
517 scm_string_to_symbol ($2), $4);
519 | translator_spec_body NAME STRING {
520 unsmob_translator_def ($$)->type_name_ = $3;
522 | translator_spec_body CONSISTS STRING {
523 unsmob_translator_def ($$)->add_element ($3);
525 | translator_spec_body ALIAS STRING {
526 Translator_def*td = unsmob_translator_def ($$);
527 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
529 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
530 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
531 unsmob_translator_def ($$)
532 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
535 | translator_spec_body CONSISTSEND STRING {
536 unsmob_translator_def ($$)->add_last_element ( $3);
538 | translator_spec_body ACCEPTS STRING {
539 unsmob_translator_def ($$)->set_acceptor ($3,true);
541 | translator_spec_body DENIES STRING {
542 unsmob_translator_def ($$)->set_acceptor ($3,false);
544 | translator_spec_body REMOVE STRING {
545 unsmob_translator_def ($$)->remove_element ($3);
554 THIS->remember_spot ();
556 /*cont*/ '{' score_body '}' {
559 if (!$$->def_p_arr_.size ())
561 Music_output_def *id =
562 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
563 $$->add_output (id ? id->clone () : new Paper_def );
572 $$->set_spot (THIS->here_input ());
573 SCM m = $1->self_scm ();
574 scm_unprotect_object (m);
578 $$ = new Score (*unsmob_score ($1));
579 $$->set_spot (THIS->here_input ());
581 | score_body lilypond_header {
582 scm_unprotect_object ($2->self_scm ());
585 | score_body output_def {
598 music_output_def_body '}' {
600 THIS-> lexer_p_-> scope_l_arr_.pop ();
604 music_output_def_body:
606 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
611 p = dynamic_cast<Midi_def*> (id->clone ());
616 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
619 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
622 p = dynamic_cast<Paper_def*> (id->clone ());
625 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
628 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
629 Music_output_def *p = unsmob_music_output_def ($3);
631 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
634 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
635 Music_output_def *p = unsmob_music_output_def ($3);
638 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
641 | music_output_def_body assignment {
644 | music_output_def_body translator_spec_block {
645 $$->assign_translator ($2);
647 | music_output_def_body STYLESHEET embedded_scm {
648 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
650 | music_output_def_body tempo_request {
652 junk this ? there already is tempo stuff in
655 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
656 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
657 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
659 | music_output_def_body error {
665 TEMPO steno_duration '=' bare_unsigned {
667 $$->set_mus_property ("duration", $2);
668 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
672 Music_list: /* empty */ {
673 $$ = gh_cons (SCM_EOL, SCM_EOL);
677 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
678 scm_unprotect_object ($2->self_scm ()); /* UGH */
679 if (gh_pair_p (gh_cdr (s)))
680 gh_set_cdr_x (gh_cdr (s), c); /* append */
682 gh_set_car_x (s, c); /* set first cons */
683 gh_set_cdr_x (s, c) ; /* remember last cell */
699 | ALTERNATIVE Music_sequence {
701 $2->set_spot (THIS->here_input ());
709 REPEAT string bare_unsigned Music Alternative_music
711 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
712 if (alts && $3 < alts->length_i ())
713 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
717 Repeated_music * r = new Repeated_music (SCM_EOL);
721 r-> set_mus_property ("body", beg->self_scm ());
722 scm_unprotect_object (beg->self_scm ());
724 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
728 alts->truncate (times);
729 r-> set_mus_property ("alternatives", alts->self_scm ());
730 scm_unprotect_object (alts->self_scm ());
732 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
733 SCM result = gh_call1 (func, $2);
735 set_music_properties (r, result);
737 r->set_spot (*$4->origin ());
742 Music_sequence: '{' Music_list '}' {
743 $$ = new Music_sequence (SCM_EOL);
744 $$->set_mus_property ("elements", gh_car ($2));
749 SEQUENTIAL '{' Music_list '}' {
750 $$ = new Sequential_music (SCM_EOL);
751 $$->set_mus_property ("elements", gh_car ($3));
753 | '{' Music_list '}' {
754 $$ = new Sequential_music (SCM_EOL);
755 $$->set_mus_property ("elements", gh_car ($2));
760 SIMULTANEOUS '{' Music_list '}'{
761 $$ = new Simultaneous_music (SCM_EOL);
762 $$->set_mus_property ("elements", gh_car ($3));
765 | '<' Music_list '>' {
766 $$ = new Simultaneous_music (SCM_EOL);
767 $$->set_mus_property ("elements", gh_car ($2));
772 request_chord { $$ = $1; }
773 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
775 if (!gh_symbol_p ($3))
777 THIS->parser_error (_ ("Second argument must be a symbol"));
779 /*hould check # args */
780 if (!gh_procedure_p (pred))
782 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
785 Music *m = new Music (SCM_EOL);
786 m->set_mus_property ("predicate", pred);
787 m->set_mus_property ("grob-property", $3);
788 m->set_mus_property ("grob-value", $5);
789 m->set_mus_property ("iterator-ctor",
790 Output_property_music_iterator::constructor_cxx_function);
795 $$ = unsmob_music ($1)->clone ();
803 CONTEXT STRING Music {
804 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
805 csm->set_mus_property ("element", $3->self_scm ());
806 scm_unprotect_object ($3->self_scm ());
808 csm->set_mus_property ("context-type",$2);
809 csm->set_mus_property ("context-id", ly_str02scm (""));
813 | AUTOCHANGE STRING Music {
814 Music * chm = new Music_wrapper (SCM_EOL);
815 chm->set_mus_property ("element", $3->self_scm ());
816 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
818 scm_unprotect_object ($3->self_scm ());
819 chm->set_mus_property ("what", $2);
822 chm->set_spot (*$3->origin ());
825 $$ = new Grace_music (SCM_EOL);
826 $$->set_mus_property ("element", $2->self_scm ());
827 scm_unprotect_object ($2->self_scm ());
830 | CONTEXT string '=' string Music {
831 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
832 csm->set_mus_property ("element", $5->self_scm ());
833 scm_unprotect_object ($5->self_scm ());
835 csm->set_mus_property ("context-type", $2);
836 csm->set_mus_property ("context-id", $4);
841 THIS->remember_spot ();
844 bare_unsigned '/' bare_unsigned Music
847 int n = $3; int d = $5;
849 $$ = new Time_scaled_music (SCM_EOL);
850 $$->set_spot (THIS->pop_spot ());
853 $$->set_mus_property ("element", mp->self_scm ());
854 scm_unprotect_object (mp->self_scm ());
855 $$->set_mus_property ("numerator", gh_int2scm (n));
856 $$->set_mus_property ("denominator", gh_int2scm (d));
857 $$->compress (Moment (n,d));
860 | Repeated_music { $$ = $1; }
861 | Simultaneous_music { $$ = $1; }
862 | Sequential_music { $$ = $1; }
863 | TRANSPOSE pitch Music {
864 $$ = new Transposed_music (SCM_EOL);
866 Pitch pit = *unsmob_pitch ($2);
869 $$->set_mus_property ("element", p->self_scm ());
870 scm_unprotect_object (p->self_scm ());
872 | TRANSPOSE steno_tonic_pitch Music {
873 $$ = new Transposed_music (SCM_EOL);
875 Pitch pit = *unsmob_pitch ($2);
878 $$->set_mus_property ("element", p->self_scm ());
879 scm_unprotect_object (p->self_scm ());
882 | APPLY embedded_scm Music {
883 SCM ret = gh_call1 ($2, $3->self_scm ());
884 Music *m = unsmob_music (ret);
886 THIS->parser_error ("\\apply must return a Music");
887 m = new Music (SCM_EOL);
892 { THIS->lexer_p_->push_note_state (); }
895 THIS->lexer_p_->pop_state ();
898 { THIS->lexer_p_->push_chord_state (); }
901 Music * chm = new Un_relativable_music ;
902 chm->set_mus_property ("element", $3->self_scm ());
905 THIS->lexer_p_->pop_state ();
908 { THIS->lexer_p_->push_lyric_state (); }
912 THIS->lexer_p_->pop_state ();
914 | relative_music { $$ = $1; }
915 | re_rhythmed_music { $$ = $1; }
916 | part_combined_music { $$ = $1; }
920 RELATIVE absolute_pitch Music {
922 Pitch pit = *unsmob_pitch ($2);
923 $$ = new Relative_octave_music (SCM_EOL);
925 $$->set_mus_property ("element", p->self_scm ());
926 scm_unprotect_object (p->self_scm ());
928 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
934 ADDLYRICS Music Music {
935 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
936 l->set_mus_property ("music", $2->self_scm ());
937 l->set_mus_property ("lyrics", $3->self_scm ());
938 scm_unprotect_object ($3->self_scm ());
939 scm_unprotect_object ($2->self_scm ());
945 PARTCOMBINE STRING Music Music {
946 Part_combine_music * p = new Part_combine_music (SCM_EOL);
948 p->set_mus_property ("what", $2);
949 p->set_mus_property ("one", $3->self_scm ());
950 p->set_mus_property ("two", $4->self_scm ());
952 scm_unprotect_object ($3->self_scm ());
953 scm_unprotect_object ($4->self_scm ());
961 TRANSLATOR STRING '=' STRING {
962 Music * t = new Music (SCM_EOL);
963 t->set_mus_property ("iterator-ctor",
964 Change_iterator::constructor_cxx_function);
965 t-> set_mus_property ("change-to-type", $2);
966 t-> set_mus_property ("change-to-id", $4);
969 $$->set_spot (THIS->here_input ());
974 PROPERTY STRING '.' STRING '=' scalar {
975 Music *t = new Music (SCM_EOL);
977 t->set_mus_property ("iterator-ctor",
978 Property_iterator::constructor_cxx_function);
979 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
980 t->set_mus_property ("value", $6);
982 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
984 csm->set_mus_property ("element", t->self_scm ());
985 scm_unprotect_object (t->self_scm ());
988 $$->set_spot (THIS->here_input ());
990 csm-> set_mus_property ("context-type", $2);
992 | PROPERTY STRING '.' STRING UNSET {
993 Music *t = new Music (SCM_EOL);
995 t->set_mus_property ("iterator-ctor",
996 Property_unset_iterator::constructor_cxx_function);
997 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
999 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1000 csm->set_mus_property ("element", t->self_scm ());
1001 scm_unprotect_object (t->self_scm ());
1004 $$->set_spot (THIS->here_input ());
1006 csm-> set_mus_property ("context-type", $2);
1008 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
1009 Music *t = new Music (SCM_EOL);
1010 t->set_mus_property ("iterator-ctor",
1011 Push_property_iterator::constructor_cxx_function);
1012 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1013 t->set_mus_property ("pop-first", SCM_BOOL_T);
1014 t->set_mus_property ("grob-property", $6);
1015 t->set_mus_property ("grob-value", $8);
1016 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1017 csm->set_mus_property ("element", t->self_scm ());
1018 scm_unprotect_object (t->self_scm ());
1020 $$->set_spot (THIS->here_input ());
1022 csm-> set_mus_property ("context-type", $2);
1024 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
1025 Music *t = new Music (SCM_EOL);
1026 t->set_mus_property ("iterator-ctor",
1027 Push_property_iterator::constructor_cxx_function);
1028 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1029 t->set_mus_property ("grob-property", $6);
1030 t->set_mus_property ("grob-value", $8);
1031 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1032 csm->set_mus_property ("element", t->self_scm ());
1033 scm_unprotect_object (t->self_scm ());
1036 $$->set_spot (THIS->here_input ());
1038 csm-> set_mus_property ("context-type", $2);
1040 | PROPERTY STRING '.' STRING REVERT embedded_scm {
1041 Music *t = new Music (SCM_EOL);
1042 t->set_mus_property ("iterator-ctor",
1043 Pop_property_iterator::constructor_cxx_function);
1044 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1045 t->set_mus_property ("grob-property", $6);
1047 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1048 csm->set_mus_property ("element", t->self_scm ());
1049 scm_unprotect_object (t->self_scm ());
1052 $$->set_spot (THIS->here_input ());
1054 csm-> set_mus_property ("context-type", $2);
1060 | bare_int { $$ = gh_int2scm ($1); }
1061 | embedded_scm { $$ = $1; }
1066 pre_requests simple_element post_requests {
1067 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1069 for (int i=0; i < $1->size (); i++)
1070 l->append_music ($1->elem (i));
1071 for (int i=0; i < $3->size (); i++)
1072 l->append_music ($3->elem (i));
1075 programming_error ("Need Sequence to add music to");
1084 $$ = new Request_chord (SCM_EOL);
1085 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1086 $$-> set_spot (THIS->here_input ());
1087 $1-> set_spot (THIS->here_input ());
1090 Music *t = new Music (SCM_EOL);
1092 t->set_mus_property ("iterator-ctor",
1093 Property_iterator::constructor_cxx_function);
1094 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1095 t->set_mus_property ("value", $2);
1097 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1098 csm->set_mus_property ("element", t->self_scm ());
1099 scm_unprotect_object (t->self_scm ());
1102 $$->set_spot (THIS->here_input ());
1104 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1106 | PARTIAL duration_length {
1107 Music * p = new Music (SCM_EOL);
1108 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1109 p->set_mus_property ("iterator-ctor",
1110 Property_iterator::constructor_cxx_function);
1112 Moment m = - unsmob_duration ($2)->length_mom ();
1113 p->set_mus_property ("value", m.smobbed_copy ());
1115 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1116 sp->set_mus_property ("element", p->self_scm ());
1117 scm_unprotect_object (p->self_scm ());
1120 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1123 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1124 SCM result = gh_call1 (func, $2);
1127 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1128 Music * p = new Music (SCM_EOL);
1129 set_music_properties (p, gh_car (s));
1130 l = gh_cons (p->self_scm (), l);
1131 scm_unprotect_object (p->self_scm ());
1133 Sequential_music * seq = new Sequential_music (SCM_EOL);
1134 seq->set_mus_property ("elements", l);
1136 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1137 sp->set_mus_property ("element", seq->self_scm ());
1138 scm_unprotect_object (seq->self_scm ());
1141 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1143 | TIME_T bare_unsigned '/' bare_unsigned {
1144 Music * p = new Music (SCM_EOL);
1145 p->set_mus_property ("symbol",
1146 ly_symbol2scm ( "timeSignatureFraction"));
1147 p->set_mus_property ("iterator-ctor",
1148 Property_iterator::constructor_cxx_function);
1150 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1153 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1154 sp->set_mus_property ("element", p->self_scm ());
1155 scm_unprotect_object (p->self_scm ());
1160 TODO: should make alias TimingContext for Score
1163 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1168 shorthand_command_req { $$ = $1; }
1169 | verbose_command_req { $$ = $1; }
1172 shorthand_command_req:
1180 $$ = new Barcheck_req;
1186 Span_req*b= new Span_req;
1187 b->set_span_dir (START);
1188 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1192 Span_req*b= new Span_req;
1193 b->set_span_dir ( STOP);
1194 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1198 $$ = new Breathing_sign_req;
1203 verbose_command_req:
1204 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1205 Span_req * sp_p = new Span_req;
1206 sp_p-> set_span_dir ( Direction ($2));
1207 sp_p->set_mus_property ("span-type",$3);
1208 sp_p->set_spot (THIS->here_input ());
1212 Mark_req * m = new Mark_req;
1216 Mark_req *m = new Mark_req;
1217 m->set_mus_property ("label", $2);
1224 Break_req * b = new Break_req;
1226 if (!gh_number_p (s))
1229 b->set_mus_property ("penalty", s);
1230 b->set_spot (THIS->here_input ());
1233 | SKIP duration_length {
1234 Skip_req * skip_p = new Skip_req;
1235 skip_p->set_mus_property ("duration", $2);
1243 Key_change_req *key_p= new Key_change_req;
1246 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1247 Key_change_req *key_p= new Key_change_req;
1249 key_p->set_mus_property ("pitch-alist", $3);
1250 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1257 $$ = new Link_array<Request>;
1259 | post_requests post_request {
1260 $2->set_spot (THIS->here_input ());
1272 request_that_take_dir:
1275 | script_abbreviation {
1276 SCM s = THIS->lexer_p_->lookup_identifier ("dash" + ly_scm2string ($1));
1277 Articulation_req *a = new Articulation_req;
1278 if (gh_string_p (s))
1279 a->set_mus_property ("articulation-type", s);
1280 else THIS->parser_error (_ ("Expecting string as script definition"));
1286 script_dir request_that_take_dir {
1287 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1288 gs->set_direction (Direction ($1));
1290 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1296 REQUEST_IDENTIFIER {
1297 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1298 $$->set_spot (THIS->here_input ());
1300 | DYNAMICSCRIPT embedded_scm {
1302 TODO: junkme, use text-type == dynamic
1304 Text_script_req *d = new Text_script_req;
1305 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1306 d->set_mus_property ("text", $2);
1307 d->set_spot (THIS->here_input ());
1310 | SPANREQUEST bare_int STRING {
1311 Span_req * sp_p = new Span_req;
1312 sp_p->set_span_dir ( Direction ($2));
1313 sp_p->set_mus_property ("span-type", $3);
1314 sp_p->set_spot (THIS->here_input ());
1318 Tremolo_req* a = new Tremolo_req;
1319 a->set_spot (THIS->here_input ());
1320 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1324 Articulation_req * a = new Articulation_req;
1325 a->set_mus_property ("articulation-type", $2);
1326 a->set_spot (THIS->here_input ());
1330 duh, junk this syntax from the parser, if possible.
1333 Arpeggio_req *a = new Arpeggio_req;
1334 a->set_spot (THIS->here_input ());
1338 Glissando_req *g = new Glissando_req;
1339 g->set_spot /* No pun intended */ (THIS->here_input ());
1366 | NOTENAME_PITCH sup_quotes {
1367 Pitch p = *unsmob_pitch ($1);
1369 $$ = p.smobbed_copy ();
1371 | NOTENAME_PITCH sub_quotes {
1372 Pitch p =* unsmob_pitch ($1);
1375 $$ = p.smobbed_copy ();
1388 | TONICNAME_PITCH sup_quotes {
1389 Pitch p = *unsmob_pitch ($1);
1391 $$ = p.smobbed_copy ();
1393 | TONICNAME_PITCH sub_quotes {
1394 Pitch p =* unsmob_pitch ($1);
1397 $$ = p.smobbed_copy ();
1412 PITCH embedded_scm {
1414 if (!unsmob_pitch ($2)) {
1415 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1416 $$ = Pitch ().smobbed_copy ();
1422 DURATION embedded_scm {
1424 if (!unsmob_duration ($2))
1426 THIS->parser_error (_ ("Must have duration object"));
1427 $$ = Duration ().smobbed_copy ();
1434 if (!THIS->lexer_p_->lyric_state_b ())
1435 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1436 $$ = new Extender_req;
1442 if (!THIS->lexer_p_->lyric_state_b ())
1443 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1444 $$ = new Hyphen_req;
1449 close_request_parens {
1451 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1454 close_request_parens:
1456 Span_req* s= new Span_req;
1458 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1461 Span_req* s= new Span_req;
1463 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1466 Span_req*s =new Span_req;
1468 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1471 Span_req*s =new Span_req;
1473 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1479 open_request_parens {
1481 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1485 open_request_parens:
1487 Span_req *s = new Span_req;
1488 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1493 Span_req* s= new Span_req;
1495 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1498 Span_req* s= new Span_req;
1500 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1506 Text_script_req *t = new Text_script_req;
1507 t->set_mus_property ("text", $1);
1508 t->set_spot (THIS->here_input ());
1512 Text_script_req *t = new Text_script_req;
1513 t->set_mus_property ("text", $1);
1514 t->set_spot (THIS->here_input ());
1518 String ds = to_str ($1);
1519 Text_script_req* t = new Text_script_req;
1521 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1522 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1523 t->set_spot (THIS->here_input ());
1528 script_abbreviation:
1530 $$ = gh_str02scm ("Hat");
1533 $$ = gh_str02scm ("Plus");
1536 $$ = gh_str02scm ("Dash");
1539 $$ = gh_str02scm ("Bar");
1542 $$ = gh_str02scm ("Larger");
1545 $$ = gh_str02scm ("Dot");
1553 | '-' { $$ = CENTER; }
1558 $$ = new Link_array<Request>;
1560 | pre_requests open_request {
1572 multiplied_duration {
1575 | explicit_duration {
1580 optional_notemode_duration:
1582 $$ = THIS->default_duration_.smobbed_copy ();
1584 | multiplied_duration {
1587 | explicit_duration {
1593 bare_unsigned dots {
1595 if (!is_duration_b ($1))
1596 THIS->parser_error (_f ("not a duration: %d", $1));
1600 $$ = Duration (l, $2).smobbed_copy ();
1602 THIS->set_last_duration (unsmob_duration ($$));
1604 | DURATION_IDENTIFIER dots {
1605 Duration *d =unsmob_duration ($1);
1606 Duration k (d->duration_log (),d->dot_count () + $2);
1607 $$ = k.smobbed_copy ();
1609 THIS->set_last_duration (unsmob_duration ($$));
1617 Multiplied durations are always multiplied, ie,
1618 c1 * INT or c1 * RAT.
1620 No support for c1 /4 and c1 /2/2.
1622 '*' and '/' are declared %left, with makes them reduce rather than
1625 Because there are no a/b/c association problems anymore, it is
1626 safe to allow '*' and '/' to shift.
1628 * 1 / 4 shifts to match second rule: '* 1 / 4'
1630 '/' TONIC_NAME shifts to match rule: chord_inversion
1633 multiplied_duration:
1637 | multiplied_duration '*' bare_unsigned %prec MUL1 {
1638 $$ = unsmob_duration ($$)->compressed ($3).smobbed_copy ();
1640 | multiplied_duration '*' bare_unsigned '/' bare_unsigned %prec MUL2 {
1641 $$ = unsmob_duration ($$)->compressed (Moment ($3, $5)).smobbed_copy ();
1659 | ':' bare_unsigned {
1660 if (!is_duration_b ($2))
1661 THIS->parser_error (_f ("not a duration: %d", $2));
1668 pitch exclamations questions optional_notemode_duration {
1669 if (!THIS->lexer_p_->note_state_b ())
1670 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1672 Note_req *n = new Note_req;
1674 n->set_mus_property ("pitch", $1);
1675 n->set_mus_property ("duration", $4);
1678 n->set_mus_property ("cautionary", SCM_BOOL_T);
1679 if ($2 % 2 || $3 % 2)
1680 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1682 Simultaneous_music*v = new Request_chord (SCM_EOL);
1683 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1686 FIXME: location is one off, since ptich & duration don't contain origin refs.
1688 v->set_spot (THIS->here_input ());
1689 n->set_spot (THIS->here_input ());
1693 | RESTNAME optional_notemode_duration {
1695 SCM e = SCM_UNDEFINED;
1696 if (ly_scm2string ($1) =="s")
1698 Skip_req * skip_p = new Skip_req;
1699 skip_p->set_mus_property ("duration" ,$2);
1701 skip_p->set_spot (THIS->here_input ());
1702 e = skip_p->self_scm ();
1706 Rest_req * rest_req_p = new Rest_req;
1707 rest_req_p->set_mus_property ("duration", $2);
1708 rest_req_p->set_spot (THIS->here_input ());
1709 e = rest_req_p->self_scm ();
1711 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1712 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1713 velt_p->set_spot (THIS->here_input ());
1718 | MULTI_MEASURE_REST optional_notemode_duration {
1719 Skip_req * sk = new Skip_req;
1720 sk->set_mus_property ("duration", $2);
1721 Span_req *sp1 = new Span_req;
1722 Span_req *sp2 = new Span_req;
1723 sp1-> set_span_dir ( START);
1724 sp2-> set_span_dir ( STOP);
1725 SCM r = ly_str02scm ("rest");
1726 sp1->set_mus_property ("span-type", r);
1727 sp2->set_mus_property ("span-type", r);
1729 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1730 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1731 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1732 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1733 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1734 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1736 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1738 $$ = new Sequential_music (SCM_EOL);
1739 $$->set_mus_property ("elements", ms);
1741 | STRING optional_notemode_duration {
1743 Lyric_req* lreq_p = new Lyric_req;
1744 lreq_p->set_mus_property ("text", $1);
1745 lreq_p->set_mus_property ("duration",$2);
1746 lreq_p->set_spot (THIS->here_input ());
1747 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1748 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1755 if (!THIS->lexer_p_->chord_state_b ())
1756 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1763 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1764 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1765 $$->set_spot (THIS->here_input ());
1772 | CHORD_COLON chord_notes {
1781 | chord_notes '.' chord_step {
1782 $$ = gh_append2 ($$, $3);
1790 | CHORD_CARET chord_notes {
1800 | '/' steno_tonic_pitch %prec INVERSION {
1809 | CHORD_BASS steno_tonic_pitch {
1816 $$ = gh_cons ($1, SCM_EOL);
1818 | CHORDMODIFIER_PITCH {
1819 $$ = gh_cons ($1, SCM_EOL);
1821 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1822 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1829 m.notename_i_ = ($1 - 1) % 7;
1830 m.octave_i_ = $1 > 7 ? 1 : 0;
1831 m.alteration_i_ = 0;
1833 $$ = m.smobbed_copy ();
1835 | bare_unsigned '+' {
1837 m.notename_i_ = ($1 - 1) % 7;
1838 m.octave_i_ = $1 > 7 ? 1 : 0;
1839 m.alteration_i_ = 1;
1842 $$ = m.smobbed_copy ();
1844 | bare_unsigned CHORD_MINUS {
1846 m.notename_i_ = ($1 - 1) % 7;
1847 m.octave_i_ = $1 > 7 ? 1 : 0;
1848 m.alteration_i_ = -1;
1850 $$ = m.smobbed_copy ();
1861 | '-' number_expression %prec UNARY_MINUS {
1862 $$ = scm_difference ($2, SCM_UNDEFINED);
1864 | number_expression '*' number_expression {
1865 $$ = scm_product ($1, $3);
1867 | number_expression '/' number_expression {
1868 $$ = scm_divide ($1, $3);
1870 | number_expression '+' number_expression {
1871 $$ = scm_sum ($1, $3);
1873 | number_expression '-' number_expression {
1874 $$ = scm_difference ($1, $3);
1876 | '(' number_expression ')' {
1883 $$ = gh_int2scm ($1);
1888 | NUMBER_IDENTIFIER {
1892 $$ = gh_double2scm (gh_scm2double ($1) CM );
1895 $$ = gh_double2scm (gh_scm2double ($1) PT);
1898 $$ = gh_double2scm (gh_scm2double ($1) INCH);
1901 $$ = gh_double2scm (gh_scm2double ($1) MM);
1904 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
1920 if (scm_integer_p ($1) == SCM_BOOL_T)
1922 int k = gh_scm2int ($1);
1926 THIS->parser_error (_ ("need integer number arg"));
1940 | STRING_IDENTIFIER {
1943 | string '+' string {
1944 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1951 | exclamations '!' { $$ ++; }
1956 | questions '?' { $$ ++; }
1963 My_lily_parser::set_yydebug (bool b)
1970 extern My_lily_parser * current_parser;
1973 My_lily_parser::do_yyparse ()
1976 current_parser = this;;
1977 yyparse ((void*)this);