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 #include "translator-def.hh"
14 #include "lily-guile.hh"
15 #include "change-iterator.hh"
17 #include "my-lily-lexer.hh"
18 #include "paper-def.hh"
19 #include "midi-def.hh"
21 #include "file-path.hh"
23 #include "dimensions.hh"
24 #include "command-request.hh"
25 #include "musical-request.hh"
26 #include "my-lily-parser.hh"
27 #include "context-specced-music.hh"
29 #include "music-list.hh"
30 #include "output-property-music-iterator.hh"
31 #include "property-iterator.hh"
32 #include "file-results.hh"
35 #include "relative-music.hh"
36 #include "lyric-combine-music.hh"
37 #include "transposed-music.hh"
38 #include "time-scaled-music.hh"
39 #include "repeated-music.hh"
40 #include "lilypond-input-version.hh"
41 #include "grace-music.hh"
42 #include "part-combine-music.hh"
43 #include "scm-hash.hh"
44 #include "auto-change-iterator.hh"
45 #include "un-relativable-music.hh"
51 return t && t == 1 << intlog2 (t);
56 set_music_properties (Music *p, SCM a)
58 for (SCM k = a; gh_pair_p (k); k = gh_cdr (k))
60 p->set_mus_property (gh_caar (k), gh_cdar (k));
66 Lilypond_version oldest_version ("1.3.59");
69 print_lilypond_versions (ostream &os)
71 os << _f ("Oldest supported input version: %s", oldest_version.str ())
76 // needed for bison.simple's malloc () and free ()
83 #define YYERROR_VERBOSE 1
85 #define YYPARSE_PARAM my_lily_parser_l
86 #define YYLEX_PARAM my_lily_parser_l
88 ((My_lily_parser *) my_lily_parser_l)
90 #define yyerror THIS->parser_error
91 #define ARRAY_SIZE(a,s) if (a.size () != s) THIS->parser_error (_f ("Expecting %d arguments", s))
98 Link_array<Request> *reqvec;
103 Scheme_hash_table *scmhash;
105 Music_output_def * outputdef;
111 /* We use SCMs to do strings, because it saves us the trouble of
112 deleting them. Let's hope that a stack overflow doesnt trigger a move
113 of the parse stack onto the heap. */
123 yylex (YYSTYPE *s, void * v_l)
125 My_lily_parser *pars_l = (My_lily_parser*) v_l;
126 My_lily_lexer * lex_l = pars_l->lexer_p_;
128 lex_l->lexval_l = (void*) s;
129 return lex_l->yylex ();
137 /* tokens which are not keywords */
148 %token CHORDMODIFIERS
156 %token ELEMENTDESCRIPTIONS
172 %token MULTI_MEASURE_REST
183 %token OVERRIDE SET REVERT
196 %token COMMANDSPANREQUEST
198 %token OUTPUTPROPERTY
208 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
209 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
211 %type <i> exclamations questions dots
213 %token <scm> NOTENAME_PITCH
214 %token <scm> TONICNAME_PITCH
215 %token <scm> CHORDMODIFIER_PITCH
216 %token <scm> DURATION_IDENTIFIER
217 %token <id> IDENTIFIER
220 %token <scm> SCORE_IDENTIFIER
221 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
223 %token <scm> NUMBER_IDENTIFIER
224 %token <scm> REQUEST_IDENTIFIER
225 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
226 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
227 %token <scm> RESTNAME
233 %type <outputdef> output_def
234 %type <scmhash> lilypond_header lilypond_header_body
235 %type <request> open_request_parens close_request_parens open_request close_request
236 %type <request> request_with_dir request_that_take_dir verbose_request
237 %type <i> sub_quotes sup_quotes
238 %type <music> simple_element request_chord command_element Simple_music Composite_music
239 %type <music> Alternative_music Repeated_music
240 %type <i> tremolo_type
241 %type <i> bare_int bare_unsigned
244 %type <scm> identifier_init
246 %type <scm> steno_duration optional_notemode_duration
247 %type <scm> entered_notemode_duration explicit_duration
249 %type <reqvec> pre_requests post_requests
250 %type <request> gen_text_def
251 %type <scm> steno_pitch pitch absolute_pitch
252 %type <scm> explicit_pitch steno_tonic_pitch
254 %type <scm> chord_additions chord_subtractions chord_notes chord_step
256 %type <scm> chord_note chord_inversion chord_bass
257 %type <scm> duration_length
259 %type <scm> embedded_scm scalar
260 %type <music> Music Sequential_music Simultaneous_music Music_sequence
261 %type <music> relative_music re_rhythmed_music part_combined_music
262 %type <music> property_def translator_change
263 %type <scm> Music_list
264 %type <outputdef> music_output_def_body
265 %type <request> shorthand_command_req
266 %type <request> post_request
267 %type <music> command_req verbose_command_req
268 %type <request> extender_req
269 %type <request> hyphen_req
270 %type <scm> string bare_number number_expression
271 %type <score> score_block score_body
273 %type <scm> translator_spec_block translator_spec_body
274 %type <tempo> tempo_request
275 %type <scm> notenames_body notenames_block chordmodifiers_block
276 %type <scm> script_abbreviation
286 lilypond: /* empty */
287 | lilypond toplevel_expression {}
288 | lilypond assignment { }
290 THIS->error_level_i_ = 1;
291 //THIS->parser_error (_ ("ly invalid"));
294 THIS->error_level_i_ = 1;
295 //THIS->parser_error (_ ("ly invalid"));
301 THIS->lexer_p_->pitchname_tab_ = $1;
303 | chordmodifiers_block {
304 THIS->lexer_p_->chordmodifier_tab_ = $1;
308 scm_unprotect_object (global_header_p->self_scm ());
309 global_header_p = $1;
312 score_global_array.push ($1);
316 if (dynamic_cast<Paper_def*> ($1))
317 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
318 else if (dynamic_cast<Midi_def*> ($1))
319 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
332 chordmodifiers_block:
333 CHORDMODIFIERS notenames_body { $$ = $2; }
338 PITCHNAMES notenames_body { $$ = $2; }
345 int i = scm_ilength ($1);
347 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
348 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
349 SCM pt = gh_cdar (s);
350 if (!unsmob_pitch (pt))
351 THIS->parser_error ("Need pitch object.");
353 scm_hashq_set_x (tab, gh_caar (s), pt);
360 lilypond_header_body:
362 $$ = new Scheme_hash_table;
364 Scope *sc = new Scope ($$);
365 THIS->lexer_p_-> scope_l_arr_.push (sc);
367 | lilypond_header_body assignment semicolon {
373 HEADER '{' lilypond_header_body '}' {
375 delete THIS->lexer_p_-> scope_l_arr_.pop ();
385 THIS->remember_spot ();
387 /* cont */ '=' identifier_init {
388 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
391 TODO: devise standard for protection in parser.
393 The parser stack lives on the C-stack, which means that
394 all objects can be unprotected as soon as they're here.
398 Should find generic way of associating input with objects.
408 $$ = $1->self_scm ();
409 scm_unprotect_object ($$);
412 $$ = $1->self_scm ();
413 scm_unprotect_object ($$);
415 | translator_spec_block {
419 $$ = $1->self_scm ();
420 scm_unprotect_object ($$);
423 $$ = $1->self_scm ();
424 scm_unprotect_object ($$);
426 | explicit_duration {
429 | number_expression {
440 translator_spec_block:
441 TRANSLATOR '{' translator_spec_body '}'
447 translator_spec_body:
448 TRANSLATOR_IDENTIFIER {
449 $$ = unsmob_translator_def ($1)->clone_scm ();
450 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
452 | TYPE STRING semicolon {
453 $$ = Translator_def::make_scm ();
454 Translator_def*td = unsmob_translator_def ($$);
455 td->translator_group_type_ = $2;
456 td->set_spot (THIS->here_input ());
458 | translator_spec_body STRING '=' embedded_scm {
459 unsmob_translator_def ($$)->add_property_assign ($2, $4);
461 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
462 unsmob_translator_def ($$)
463 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
465 | translator_spec_body STRING REVERT embedded_scm {
466 unsmob_translator_def ($$)->add_pop_property (
467 scm_string_to_symbol ($2), $4);
469 | translator_spec_body STRING '=' identifier_init semicolon {
470 SCM v = gh_int2scm (0);
471 if (gh_string_p ($4) || gh_number_p ($4) || gh_boolean_p ($4))
474 THIS->parser_error (_ ("Wrong type for property value"));
477 unsmob_translator_def ($$)->add_property_assign ($2, v);
479 | translator_spec_body NAME STRING semicolon {
480 unsmob_translator_def ($$)->type_name_ = $3;
482 | translator_spec_body CONSISTS STRING semicolon {
483 unsmob_translator_def ($$)->add_element ($3);
485 | translator_spec_body ALIAS STRING semicolon {
486 Translator_def*td = unsmob_translator_def ($$);
487 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
489 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
490 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
491 unsmob_translator_def ($$)
492 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
495 | translator_spec_body CONSISTSEND STRING semicolon {
496 unsmob_translator_def ($$)->add_last_element ( $3);
498 | translator_spec_body ACCEPTS STRING semicolon {
499 unsmob_translator_def ($$)->set_acceptor ($3,true);
501 | translator_spec_body DENIES STRING semicolon {
502 unsmob_translator_def ($$)->set_acceptor ($3,false);
504 | translator_spec_body REMOVE STRING semicolon {
505 unsmob_translator_def ($$)->remove_element ($3);
514 THIS->remember_spot ();
516 /*cont*/ '{' score_body '}' {
519 if (!$$->def_p_arr_.size ())
521 Music_output_def *id =
522 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
523 $$->add_output (id ? id->clone () : new Paper_def );
532 $$->set_spot (THIS->here_input ());
533 SCM m = $1->self_scm ();
534 scm_unprotect_object (m);
538 $$ = new Score (*unsmob_score ($1));
539 $$->set_spot (THIS->here_input ());
541 | score_body lilypond_header {
542 scm_unprotect_object ($2->self_scm ());
545 | score_body output_def {
558 music_output_def_body '}' {
560 THIS-> lexer_p_-> scope_l_arr_.pop ();
564 music_output_def_body:
566 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
571 p = dynamic_cast<Midi_def*> (id->clone ());
576 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
579 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
582 p = dynamic_cast<Paper_def*> (id->clone ());
585 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
588 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
589 Music_output_def *p = unsmob_music_output_def ($3);
591 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
594 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
595 Music_output_def *p = unsmob_music_output_def ($3);
598 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
601 | music_output_def_body assignment semicolon {
604 | music_output_def_body translator_spec_block {
605 $$->assign_translator ($2);
607 | music_output_def_body STYLESHEET embedded_scm {
608 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
610 | music_output_def_body tempo_request semicolon {
612 junk this ? there already is tempo stuff in
615 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
616 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
617 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
619 | music_output_def_body error {
625 TEMPO steno_duration '=' bare_unsigned {
627 $$->set_mus_property ("duration", $2);
628 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
632 Music_list: /* empty */ {
633 $$ = gh_cons (SCM_EOL, SCM_EOL);
637 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
638 scm_unprotect_object ($2->self_scm ()); /* UGH */
639 if (gh_pair_p (gh_cdr (s)))
640 gh_set_cdr_x (gh_cdr (s), c); /* append */
642 gh_set_car_x (s, c); /* set first cons */
643 gh_set_cdr_x (s, c) ; /* remember last cell */
659 | ALTERNATIVE Music_sequence {
661 $2->set_spot (THIS->here_input ());
669 REPEAT string bare_unsigned Music Alternative_music
671 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
672 if (alts && $3 < alts->length_i ())
673 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
677 Repeated_music * r = new Repeated_music (SCM_EOL);
681 r-> set_mus_property ("body", beg->self_scm ());
682 scm_unprotect_object (beg->self_scm ());
684 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
688 alts->truncate (times);
689 r-> set_mus_property ("alternatives", alts->self_scm ());
690 scm_unprotect_object (alts->self_scm ());
692 SCM func = scm_eval2 (ly_symbol2scm ("repeat-name-to-ctor"), SCM_EOL);
693 SCM result = gh_call1 (func, $2);
695 set_music_properties (r, result);
697 r->set_spot (*$4->origin ());
702 Music_sequence: '{' Music_list '}' {
703 $$ = new Music_sequence (SCM_EOL);
704 $$->set_mus_property ("elements", gh_car ($2));
709 SEQUENTIAL '{' Music_list '}' {
710 $$ = new Sequential_music (SCM_EOL);
711 $$->set_mus_property ("elements", gh_car ($3));
713 | '{' Music_list '}' {
714 $$ = new Sequential_music (SCM_EOL);
715 $$->set_mus_property ("elements", gh_car ($2));
720 SIMULTANEOUS '{' Music_list '}'{
721 $$ = new Simultaneous_music (SCM_EOL);
722 $$->set_mus_property ("elements", gh_car ($3));
725 | '<' Music_list '>' {
726 $$ = new Simultaneous_music (SCM_EOL);
727 $$->set_mus_property ("elements", gh_car ($2));
732 request_chord { $$ = $1; }
733 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
735 if (!gh_symbol_p ($3))
737 THIS->parser_error (_ ("Second argument must be a symbol"));
739 /*hould check # args */
740 if (!gh_procedure_p (pred))
742 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
745 Music *m = new Music (SCM_EOL);
746 m->set_mus_property ("predicate", pred);
747 m->set_mus_property ("symbol", $3);
748 m->set_mus_property ("value", $5);
749 m->set_mus_property ("iterator-ctor",
750 Output_property_music_iterator::constructor_cxx_function);
755 $$ = unsmob_music ($1)->clone ();
759 | Simple_music '*' bare_unsigned '/' bare_unsigned {
761 $$->compress (Moment ($3, $5 ));
763 | Simple_music '*' bare_unsigned {
765 $$->compress (Moment ($3, 1));
771 CONTEXT STRING Music {
772 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
773 csm->set_mus_property ("element", $3->self_scm ());
774 scm_unprotect_object ($3->self_scm ());
776 csm->set_mus_property ("context-type",$2);
777 csm->set_mus_property ("context-id", ly_str02scm (""));
781 | AUTOCHANGE STRING Music {
782 Music * chm = new Music_wrapper (SCM_EOL);
783 chm->set_mus_property ("element", $3->self_scm ());
784 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
786 scm_unprotect_object ($3->self_scm ());
787 chm->set_mus_property ("what", $2);
790 chm->set_spot (*$3->origin ());
793 $$ = new Grace_music (SCM_EOL);
794 $$->set_mus_property ("element", $2->self_scm ());
795 scm_unprotect_object ($2->self_scm ());
798 | CONTEXT STRING '=' STRING Music {
799 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
800 csm->set_mus_property ("element", $5->self_scm ());
801 scm_unprotect_object ($5->self_scm ());
803 csm->set_mus_property ("context-type", $2);
804 csm->set_mus_property ("context-id", $4);
809 THIS->remember_spot ();
812 bare_unsigned '/' bare_unsigned Music
815 int n = $3; int d = $5;
817 $$ = new Time_scaled_music (SCM_EOL);
818 $$->set_spot (THIS->pop_spot ());
821 $$->set_mus_property ("element", mp->self_scm ());
822 scm_unprotect_object (mp->self_scm ());
823 $$->set_mus_property ("numerator", gh_int2scm (n));
824 $$->set_mus_property ("denominator", gh_int2scm (d));
825 $$->compress (Moment (n,d));
828 | Repeated_music { $$ = $1; }
829 | Simultaneous_music { $$ = $1; }
830 | Sequential_music { $$ = $1; }
831 | TRANSPOSE pitch Music {
832 $$ = new Transposed_music (SCM_EOL);
834 Pitch pit = *unsmob_pitch ($2);
837 $$->set_mus_property ("element", p->self_scm ());
838 scm_unprotect_object (p->self_scm ());
840 | TRANSPOSE steno_tonic_pitch Music {
841 $$ = new Transposed_music (SCM_EOL);
843 Pitch pit = *unsmob_pitch ($2);
846 $$->set_mus_property ("element", p->self_scm ());
847 scm_unprotect_object (p->self_scm ());
850 | APPLY embedded_scm Music {
851 SCM ret = gh_call1 ($2, $3->self_scm ());
852 Music *m = unsmob_music (ret);
854 THIS->parser_error ("\\apply must return a Music");
855 m = new Music (SCM_EOL);
860 { THIS->lexer_p_->push_note_state (); }
863 THIS->lexer_p_->pop_state ();
866 { THIS->lexer_p_->push_chord_state (); }
869 Music * chm = new Un_relativable_music ;
870 chm->set_mus_property ("element", $3->self_scm ());
873 THIS->lexer_p_->pop_state ();
876 { THIS->lexer_p_->push_lyric_state (); }
880 THIS->lexer_p_->pop_state ();
882 | relative_music { $$ = $1; }
883 | re_rhythmed_music { $$ = $1; }
884 | part_combined_music { $$ = $1; }
888 RELATIVE absolute_pitch Music {
890 Pitch pit = *unsmob_pitch ($2);
891 $$ = new Relative_octave_music (SCM_EOL);
893 $$->set_mus_property ("element", p->self_scm ());
894 scm_unprotect_object (p->self_scm ());
896 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
902 ADDLYRICS Music Music {
903 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
904 l->set_mus_property ("music", $2->self_scm ());
905 l->set_mus_property ("lyrics", $3->self_scm ());
906 scm_unprotect_object ($3->self_scm ());
907 scm_unprotect_object ($2->self_scm ());
913 PARTCOMBINE STRING Music Music {
914 Part_combine_music * p = new Part_combine_music (SCM_EOL);
916 p->set_mus_property ("what", $2);
917 p->set_mus_property ("one", $3->self_scm ());
918 p->set_mus_property ("two", $4->self_scm ());
920 scm_unprotect_object ($3->self_scm ());
921 scm_unprotect_object ($4->self_scm ());
929 TRANSLATOR STRING '=' STRING {
930 Music * t = new Music (SCM_EOL);
931 t->set_mus_property ("iterator-ctor",
932 Change_iterator::constructor_cxx_function);
933 t-> set_mus_property ("change-to-type", $2);
934 t-> set_mus_property ("change-to-id", $4);
937 $$->set_spot (THIS->here_input ());
942 PROPERTY STRING '.' STRING '=' scalar {
943 Music *t = new Music (SCM_EOL);
945 t->set_mus_property ("iterator-ctor",
946 Property_iterator::constructor_cxx_function);
947 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
948 t->set_mus_property ("value", $6);
950 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
952 csm->set_mus_property ("element", t->self_scm ());
953 scm_unprotect_object (t->self_scm ());
956 $$->set_spot (THIS->here_input ());
958 csm-> set_mus_property ("context-type", $2);
960 | PROPERTY STRING '.' STRING UNSET {
961 Music *t = new Music (SCM_EOL);
963 t->set_mus_property ("iterator-ctor",
964 Property_unset_iterator::constructor_cxx_function);
965 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
967 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
968 csm->set_mus_property ("element", t->self_scm ());
969 scm_unprotect_object (t->self_scm ());
972 $$->set_spot (THIS->here_input ());
974 csm-> set_mus_property ("context-type", $2);
976 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
977 Music *t = new Music (SCM_EOL);
978 t->set_mus_property ("iterator-ctor",
979 Push_property_iterator::constructor_cxx_function);
980 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
981 t->set_mus_property ("pop-first", SCM_BOOL_T);
982 t->set_mus_property ("grob-property", $6);
983 t->set_mus_property ("grob-value", $8);
984 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
985 csm->set_mus_property ("element", t->self_scm ());
986 scm_unprotect_object (t->self_scm ());
988 $$->set_spot (THIS->here_input ());
990 csm-> set_mus_property ("context-type", $2);
992 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
993 Music *t = new Music (SCM_EOL);
994 t->set_mus_property ("iterator-ctor",
995 Push_property_iterator::constructor_cxx_function);
996 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
997 t->set_mus_property ("grob-property", $6);
998 t->set_mus_property ("grob-value", $8);
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 REVERT embedded_scm {
1009 Music *t = new Music (SCM_EOL);
1010 t->set_mus_property ("iterator-ctor",
1011 Pop_property_iterator::constructor_cxx_function);
1012 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1013 t->set_mus_property ("grob-property", $6);
1015 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1016 csm->set_mus_property ("element", t->self_scm ());
1017 scm_unprotect_object (t->self_scm ());
1020 $$->set_spot (THIS->here_input ());
1022 csm-> set_mus_property ("context-type", $2);
1028 | bare_int { $$ = gh_int2scm ($1); }
1029 | embedded_scm { $$ = $1; }
1034 pre_requests simple_element post_requests {
1035 Music_sequence *l = dynamic_cast<Music_sequence*> ($2);
1037 for (int i=0; i < $1->size (); i++)
1038 l->append_music ($1->elem (i));
1039 for (int i=0; i < $3->size (); i++)
1040 l->append_music ($3->elem (i));
1043 programming_error ("Need Sequence to add music to");
1052 $$ = new Request_chord (SCM_EOL);
1053 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1054 $$-> set_spot (THIS->here_input ());
1055 $1-> set_spot (THIS->here_input ());
1058 Music *t = new Music (SCM_EOL);
1060 t->set_mus_property ("iterator-ctor",
1061 Property_iterator::constructor_cxx_function);
1062 t->set_mus_property ("symbol", ly_symbol2scm ("whichBar"));
1063 t->set_mus_property ("value", $2);
1065 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1066 csm->set_mus_property ("element", t->self_scm ());
1067 scm_unprotect_object (t->self_scm ());
1070 $$->set_spot (THIS->here_input ());
1072 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1074 | PARTIAL duration_length ';' {
1075 Music * p = new Music (SCM_EOL);
1076 p->set_mus_property ("symbol", ly_symbol2scm ( "measurePosition"));
1077 p->set_mus_property ("iterator-ctor",
1078 Property_iterator::constructor_cxx_function);
1080 Moment m = - unsmob_duration ($2)->length_mom ();
1081 p->set_mus_property ("value", m.smobbed_copy ());
1083 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1084 sp->set_mus_property ("element", p->self_scm ());
1085 scm_unprotect_object (p->self_scm ());
1088 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1091 SCM func = scm_eval2 (ly_symbol2scm ("clef-name-to-properties"), SCM_EOL);
1092 SCM result = gh_call1 (func, $2);
1095 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1096 Music * p = new Music (SCM_EOL);
1097 set_music_properties (p, gh_car (s));
1098 l = gh_cons (p->self_scm (), l);
1099 scm_unprotect_object (p->self_scm ());
1101 Sequential_music * seq = new Sequential_music (SCM_EOL);
1102 seq->set_mus_property ("elements", l);
1104 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1105 sp->set_mus_property ("element", seq->self_scm ());
1106 scm_unprotect_object (seq->self_scm ());
1109 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1111 | TIME_T bare_unsigned '/' bare_unsigned ';' {
1112 Music * p = new Music (SCM_EOL);
1113 p->set_mus_property ("symbol",
1114 ly_symbol2scm ( "timeSignatureFraction"));
1115 p->set_mus_property ("iterator-ctor",
1116 Property_iterator::constructor_cxx_function);
1118 p->set_mus_property ("value", gh_cons (gh_int2scm ($2),
1121 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1122 sp->set_mus_property ("element", p->self_scm ());
1123 scm_unprotect_object (p->self_scm ());
1126 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1131 shorthand_command_req { $$ = $1; }
1132 | verbose_command_req semicolon { $$ = $1; }
1135 shorthand_command_req:
1143 $$ = new Barcheck_req;
1149 Span_req*b= new Span_req;
1150 b->set_span_dir (START);
1151 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1155 Span_req*b= new Span_req;
1156 b->set_span_dir ( STOP);
1157 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1161 $$ = new Breathing_sign_req;
1166 verbose_command_req:
1167 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1168 Span_req * sp_p = new Span_req;
1169 sp_p-> set_span_dir ( Direction ($2));
1170 sp_p->set_mus_property ("span-type",$3);
1171 sp_p->set_spot (THIS->here_input ());
1175 Mark_req * m = new Mark_req;
1179 Mark_req *m = new Mark_req;
1180 m->set_mus_property ("label", $2);
1184 | PENALTY bare_int {
1185 Break_req * b = new Break_req;
1186 b->set_mus_property ("penalty", gh_double2scm ( $2 / 100.0));
1187 b->set_spot (THIS->here_input ());
1190 | SKIP duration_length {
1191 Skip_req * skip_p = new Skip_req;
1192 skip_p->set_mus_property ("duration", $2);
1200 Key_change_req *key_p= new Key_change_req;
1203 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1204 Key_change_req *key_p= new Key_change_req;
1206 key_p->set_mus_property ("pitch-alist", $3);
1207 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1214 $$ = new Link_array<Request>;
1216 | post_requests post_request {
1217 $2->set_spot (THIS->here_input ());
1229 request_that_take_dir:
1232 | script_abbreviation {
1233 SCM s = THIS->lexer_p_->lookup_identifier ("dash-" + ly_scm2string ($1));
1234 Articulation_req *a = new Articulation_req;
1235 if (gh_string_p (s))
1236 a->set_mus_property ("articulation-type", s);
1237 else THIS->parser_error (_ ("Expecting string as script definition"));
1243 script_dir request_that_take_dir {
1244 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1245 gs->set_direction (Direction ($1));
1247 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1253 REQUEST_IDENTIFIER {
1254 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1255 $$->set_spot (THIS->here_input ());
1257 | DYNAMICSCRIPT embedded_scm {
1259 TODO: junkme, use text-type == dynamic
1261 Text_script_req *d = new Text_script_req;
1262 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1263 d->set_mus_property ("text", $2);
1264 d->set_spot (THIS->here_input ());
1267 | TEXTSCRIPT embedded_scm {
1268 Text_script_req *t = new Text_script_req;
1269 t->set_mus_property ("text", $2);
1270 t->set_spot (THIS->here_input ());
1273 | SPANREQUEST bare_int STRING {
1274 Span_req * sp_p = new Span_req;
1275 sp_p->set_span_dir ( Direction ($2));
1276 sp_p->set_mus_property ("span-type", $3);
1277 sp_p->set_spot (THIS->here_input ());
1281 Tremolo_req* a = new Tremolo_req;
1282 a->set_spot (THIS->here_input ());
1283 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1287 Articulation_req * a = new Articulation_req;
1288 a->set_mus_property ("articulation-type", $2);
1289 a->set_spot (THIS->here_input ());
1293 duh, junk this syntax from the parser, if possible.
1296 Arpeggio_req *a = new Arpeggio_req;
1297 a->set_spot (THIS->here_input ());
1301 Glissando_req *g = new Glissando_req;
1302 g->set_spot /* No pun intended */ (THIS->here_input ());
1329 | NOTENAME_PITCH sup_quotes {
1330 Pitch p = *unsmob_pitch ($1);
1332 $$ = p.smobbed_copy ();
1334 | NOTENAME_PITCH sub_quotes {
1335 Pitch p =* unsmob_pitch ($1);
1338 $$ = p.smobbed_copy ();
1351 | TONICNAME_PITCH sup_quotes {
1352 Pitch p = *unsmob_pitch ($1);
1354 $$ = p.smobbed_copy ();
1356 | TONICNAME_PITCH sub_quotes {
1357 Pitch p =* unsmob_pitch ($1);
1360 $$ = p.smobbed_copy ();
1375 PITCH embedded_scm {
1377 if (!unsmob_pitch ($2)) {
1378 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1379 $$ = Pitch ().smobbed_copy ();
1385 DURATION embedded_scm {
1387 if (!unsmob_duration ($2))
1389 THIS->parser_error (_ ("Must have duration object"));
1390 $$ = Duration ().smobbed_copy ();
1397 if (!THIS->lexer_p_->lyric_state_b ())
1398 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1399 $$ = new Extender_req;
1405 if (!THIS->lexer_p_->lyric_state_b ())
1406 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1407 $$ = new Hyphen_req;
1412 close_request_parens {
1414 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1417 close_request_parens:
1419 Span_req* s= new Span_req;
1421 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1424 Span_req* s= new Span_req;
1426 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1429 Span_req*s =new Span_req;
1431 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1434 Span_req*s =new Span_req;
1436 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1442 open_request_parens {
1444 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1448 open_request_parens:
1450 Span_req *s = new Span_req;
1451 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
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"));
1469 Text_script_req *t = new Text_script_req;
1470 t->set_mus_property ("text", $1);
1471 t->set_spot (THIS->here_input ());
1475 Text_script_req *t = new Text_script_req;
1476 t->set_mus_property ("text", $1);
1477 t->set_spot (THIS->here_input ());
1481 String ds = to_str ($1);
1482 Text_script_req* t = new Text_script_req;
1484 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1485 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1486 t->set_spot (THIS->here_input ());
1491 script_abbreviation:
1493 $$ = gh_str02scm ("hat");
1496 $$ = gh_str02scm ("plus");
1499 $$ = gh_str02scm ("dash");
1502 $$ = gh_str02scm ("bar");
1505 $$ = gh_str02scm ("larger");
1508 $$ = gh_str02scm ("dot");
1516 | '-' { $$ = CENTER; }
1521 $$ = new Link_array<Request>;
1523 | pre_requests open_request {
1538 | explicit_duration {
1541 | duration_length '*' bare_unsigned {
1542 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1544 | duration_length '/' bare_unsigned {
1545 $$ = unsmob_duration ($$)->compressed (Moment (1,$3)).smobbed_copy ();
1549 entered_notemode_duration:
1551 THIS->set_last_duration (unsmob_duration ($1));
1555 optional_notemode_duration:
1557 $$ = THIS->default_duration_.smobbed_copy ();
1559 | entered_notemode_duration {
1562 | explicit_duration {
1568 bare_unsigned dots {
1570 if (!is_duration_b ($1))
1571 THIS->parser_error (_f ("not a duration: %d", $1));
1575 $$ = Duration (l, $2).smobbed_copy ();
1577 | DURATION_IDENTIFIER dots {
1578 Duration *d =unsmob_duration ($1);
1579 Duration k (d->duration_log (),d->dot_count () + $2);
1580 $$ = k.smobbed_copy ();
1598 | ':' bare_unsigned {
1599 if (!is_duration_b ($2))
1600 THIS->parser_error (_f ("not a duration: %d", $2));
1607 pitch exclamations questions optional_notemode_duration {
1608 if (!THIS->lexer_p_->note_state_b ())
1609 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1611 Note_req *n = new Note_req;
1613 n->set_mus_property ("pitch", $1);
1614 n->set_mus_property ("duration", $4);
1617 n->set_mus_property ("cautionary", SCM_BOOL_T);
1618 if ($2 % 2 || $3 % 2)
1619 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1621 Simultaneous_music*v = new Request_chord (SCM_EOL);
1622 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1625 FIXME: location is one off, since ptich & duration don't contain origin refs.
1627 v->set_spot (THIS->here_input ());
1628 n->set_spot (THIS->here_input ());
1632 | RESTNAME optional_notemode_duration {
1634 SCM e = SCM_UNDEFINED;
1635 if (ly_scm2string ($1) =="s")
1637 Skip_req * skip_p = new Skip_req;
1638 skip_p->set_mus_property ("duration" ,$2);
1640 skip_p->set_spot (THIS->here_input ());
1641 e = skip_p->self_scm ();
1645 Rest_req * rest_req_p = new Rest_req;
1646 rest_req_p->set_mus_property ("duration", $2);
1647 rest_req_p->set_spot (THIS->here_input ());
1648 e = rest_req_p->self_scm ();
1650 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1651 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1652 velt_p->set_spot (THIS->here_input ());
1657 | MULTI_MEASURE_REST optional_notemode_duration {
1658 Skip_req * sk = new Skip_req;
1659 sk->set_mus_property ("duration", $2);
1660 Span_req *sp1 = new Span_req;
1661 Span_req *sp2 = new Span_req;
1662 sp1-> set_span_dir ( START);
1663 sp2-> set_span_dir ( STOP);
1664 SCM r = ly_str02scm ("rest");
1665 sp1->set_mus_property ("span-type", r);
1666 sp2->set_mus_property ("span-type", r);
1668 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1669 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1670 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1671 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1672 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1673 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1675 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1677 $$ = new Sequential_music (SCM_EOL);
1678 $$->set_mus_property ("elements", ms);
1681 THIS->remember_spot ();
1684 optional_notemode_duration {
1685 if (!THIS->lexer_p_->lyric_state_b ()) {
1686 THIS->pop_spot ().error (_ ("Have to be in Lyric mode for lyrics"));
1687 THIS->error_level_i_ = 1;
1688 THIS->parser_error (_ ("Giving up"));
1692 Lyric_req* lreq_p = new Lyric_req;
1693 lreq_p->set_mus_property ("text", $1);
1694 lreq_p->set_mus_property ("duration",$3);
1695 lreq_p->set_spot (THIS->here_input ());
1696 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1697 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1704 if (!THIS->lexer_p_->chord_state_b ())
1705 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1712 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1713 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1714 $$->set_spot (THIS->here_input ());
1721 | CHORD_COLON chord_notes {
1730 | chord_notes '.' chord_step {
1731 $$ = gh_append2 ($$, $3);
1739 | CHORD_CARET chord_notes {
1749 | '/' steno_tonic_pitch {
1758 | CHORD_BASS steno_tonic_pitch {
1765 $$ = gh_cons ($1, SCM_EOL);
1767 | CHORDMODIFIER_PITCH {
1768 $$ = gh_cons ($1, SCM_EOL);
1770 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1771 $$ = gh_list ($1, $2, SCM_UNDEFINED);
1778 m.notename_i_ = ($1 - 1) % 7;
1779 m.octave_i_ = $1 > 7 ? 1 : 0;
1780 m.alteration_i_ = 0;
1782 $$ = m.smobbed_copy ();
1784 | bare_unsigned '+' {
1786 m.notename_i_ = ($1 - 1) % 7;
1787 m.octave_i_ = $1 > 7 ? 1 : 0;
1788 m.alteration_i_ = 1;
1791 $$ = m.smobbed_copy ();
1793 | bare_unsigned CHORD_MINUS {
1795 m.notename_i_ = ($1 - 1) % 7;
1796 m.octave_i_ = $1 > 7 ? 1 : 0;
1797 m.alteration_i_ = -1;
1799 $$ = m.smobbed_copy ();
1810 | '-' number_expression %prec UNARY_MINUS {
1811 $$ = scm_difference ($2, SCM_UNDEFINED);
1813 | number_expression '*' number_expression {
1814 $$ = scm_product ($1, $3);
1816 | number_expression '/' number_expression {
1817 $$ = scm_divide ($1, $3);
1819 | number_expression '+' number_expression {
1820 $$ = scm_sum ($1, $3);
1822 | number_expression '-' number_expression {
1823 $$ = scm_difference ($1, $3);
1825 | '(' number_expression ')' {
1832 $$ = gh_int2scm ($1);
1835 $$ = gh_int2scm ($1);
1838 $$ = gh_double2scm ($1);
1840 | NUMBER_IDENTIFIER {
1844 $$ = gh_double2scm ($1 CM);
1847 $$ = gh_double2scm ($1 PT);
1850 $$ = gh_double2scm ($1 INCH);
1853 $$ = gh_double2scm ($1 MM);
1856 $$ = gh_double2scm ($1 CHAR);
1863 if (scm_integer_p ($1) == SCM_BOOL_T) {
1864 $$ = gh_scm2int ($1);
1867 THIS->parser_error (_ ("need integer number arg"));
1871 THIS->parser_error (_ ("Must be positive integer"));
1879 if (scm_integer_p ($1) == SCM_BOOL_T)
1881 int k = gh_scm2int ($1);
1885 THIS->parser_error (_ ("need integer number arg"));
1899 | STRING_IDENTIFIER {
1902 | string '+' string {
1903 $$ = scm_string_append (scm_listify ($1, $3, SCM_UNDEFINED));
1910 | exclamations '!' { $$ ++; }
1915 | questions '?' { $$ ++; }
1926 My_lily_parser::set_yydebug (bool b)
1933 extern My_lily_parser * current_parser;
1936 My_lily_parser::do_yyparse ()
1939 current_parser = this;;
1940 yyparse ((void*)this);