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
237 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
239 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET
241 %type <i> exclamations questions dots optional_rest
243 %token <scm> NOTENAME_PITCH
244 %token <scm> TONICNAME_PITCH
245 %token <scm> CHORDMODIFIER_PITCH
246 %token <scm> DURATION_IDENTIFIER
247 %token <scm> FRACTION
248 %token <id> IDENTIFIER
251 %token <scm> SCORE_IDENTIFIER
252 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
254 %token <scm> NUMBER_IDENTIFIER
255 %token <scm> REQUEST_IDENTIFIER
256 %token <scm> MUSIC_IDENTIFIER TRANSLATOR_IDENTIFIER
257 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
258 %token <scm> RESTNAME
264 %type <outputdef> output_def
265 %type <scmhash> lilypond_header lilypond_header_body
266 %type <request> open_request_parens close_request_parens open_request close_request
267 %type <request> request_with_dir request_that_take_dir verbose_request
268 %type <i> sub_quotes sup_quotes
269 %type <music> simple_element request_chord command_element Simple_music Composite_music
270 %type <music> Alternative_music Repeated_music
271 %type <i> tremolo_type
272 %type <i> bare_int bare_unsigned
275 %type <scm> identifier_init
277 %type <scm> steno_duration optional_notemode_duration multiplied_duration
278 %type <scm> explicit_duration
280 %type <reqvec> pre_requests post_requests
281 %type <request> gen_text_def
282 %type <scm> steno_pitch pitch absolute_pitch
283 %type <scm> explicit_pitch steno_tonic_pitch
285 %type <scm> chord_additions chord_subtractions chord_notes chord_step
287 %type <scm> chord_note chord_inversion chord_bass
288 %type <scm> duration_length fraction
290 %type <scm> embedded_scm scalar
291 %type <music> Music Sequential_music Simultaneous_music Music_sequence
292 %type <music> relative_music re_rhythmed_music part_combined_music
293 %type <music> property_def translator_change
294 %type <scm> Music_list
295 %type <outputdef> music_output_def_body
296 %type <request> shorthand_command_req
297 %type <request> post_request
298 %type <music> command_req verbose_command_req
299 %type <request> extender_req
300 %type <request> hyphen_req
301 %type <scm> string bare_number number_expression number_term number_factor
303 %type <score> score_block score_body
305 %type <scm> translator_spec_block translator_spec_body
306 %type <tempo> tempo_request
307 %type <scm> notenames_body notenames_block chordmodifiers_block
308 %type <scm> script_abbreviation
314 /* We don't assign precedence to / and *, because we might need varied
315 prec levels in different prods */
321 lilypond: /* empty */
322 | lilypond toplevel_expression {}
323 | lilypond assignment { }
325 THIS->error_level_i_ = 1;
328 THIS->error_level_i_ = 1;
334 THIS->lexer_p_->pitchname_tab_ = $1;
336 | chordmodifiers_block {
337 THIS->lexer_p_->chordmodifier_tab_ = $1;
341 scm_gc_unprotect_object (global_header_p->self_scm ());
342 global_header_p = $1;
345 score_global_array.push ($1);
348 if (dynamic_cast<Paper_def*> ($1))
349 THIS->lexer_p_->set_identifier ("$defaultpaper", $1->self_scm ());
350 else if (dynamic_cast<Midi_def*> ($1))
351 THIS->lexer_p_->set_identifier ("$defaultmidi", $1->self_scm ());
364 chordmodifiers_block:
365 CHORDMODIFIERS notenames_body { $$ = $2; }
369 PITCHNAMES notenames_body { $$ = $2; }
374 int i = scm_ilength ($1);
376 SCM tab = scm_make_vector (gh_int2scm (i), SCM_EOL);
377 for (SCM s = $1; gh_pair_p (s); s = gh_cdr (s)) {
378 SCM pt = gh_cdar (s);
379 if (!unsmob_pitch (pt))
380 THIS->parser_error ("Need pitch object.");
382 scm_hashq_set_x (tab, gh_caar (s), pt);
389 lilypond_header_body:
391 $$ = new Scheme_hash_table;
393 Scope *sc = new Scope ($$);
394 THIS->lexer_p_-> scope_l_arr_.push (sc);
396 | lilypond_header_body assignment {
402 HEADER '{' lilypond_header_body '}' {
404 delete THIS->lexer_p_-> scope_l_arr_.pop ();
416 /* cont */ '=' identifier_init {
419 Should find generic way of associating input with objects.
421 Input ip = THIS->pop_spot ();
423 if (! regular_identifier_b ($1))
425 ip.warning (_ ("Identifier should have alphabetic characters only"));
428 THIS->lexer_p_->set_identifier (ly_scm2string ($1), $4);
431 TODO: devise standard for protection in parser.
433 The parser stack lives on the C-stack, which means that
434 all objects can be unprotected as soon as they're here.
444 $$ = $1->self_scm ();
445 scm_gc_unprotect_object ($$);
448 $$ = $1->self_scm ();
449 scm_gc_unprotect_object ($$);
451 | translator_spec_block {
455 $$ = $1->self_scm ();
456 scm_gc_unprotect_object ($$);
459 $$ = $1->self_scm ();
460 scm_gc_unprotect_object ($$);
462 | explicit_duration {
465 | number_expression {
476 translator_spec_block:
477 TRANSLATOR '{' translator_spec_body '}'
483 translator_spec_body:
484 TRANSLATOR_IDENTIFIER {
485 $$ = unsmob_translator_def ($1)->clone_scm ();
486 unsmob_translator_def ($$)-> set_spot (THIS->here_input ());
489 $$ = Translator_def::make_scm ();
490 Translator_def*td = unsmob_translator_def ($$);
491 td->translator_group_type_ = $2;
492 td->set_spot (THIS->here_input ());
494 | translator_spec_body STRING '=' embedded_scm {
495 unsmob_translator_def ($$)->add_property_assign ($2, $4);
497 | translator_spec_body STRING OVERRIDE embedded_scm '=' embedded_scm {
498 unsmob_translator_def ($$)
499 ->add_push_property (scm_string_to_symbol ($2), $4, $6);
501 | translator_spec_body STRING REVERT embedded_scm {
502 unsmob_translator_def ($$)->add_pop_property (
503 scm_string_to_symbol ($2), $4);
505 | translator_spec_body NAME STRING {
506 unsmob_translator_def ($$)->type_name_ = $3;
508 | translator_spec_body CONSISTS STRING {
509 unsmob_translator_def ($$)->add_element ($3);
511 | translator_spec_body ALIAS STRING {
512 Translator_def*td = unsmob_translator_def ($$);
513 td->type_aliases_ = gh_cons ($3, td->type_aliases_);
515 | translator_spec_body ELEMENTDESCRIPTIONS embedded_scm {
516 for (SCM p = $3; gh_pair_p (p); p = gh_cdr (p))
517 unsmob_translator_def ($$)
518 ->add_property_assign (scm_symbol_to_string (gh_caar (p)), gh_cdar (p));
521 | translator_spec_body CONSISTSEND STRING {
522 unsmob_translator_def ($$)->add_last_element ( $3);
524 | translator_spec_body ACCEPTS STRING {
525 unsmob_translator_def ($$)->set_acceptor ($3,true);
527 | translator_spec_body DENIES STRING {
528 unsmob_translator_def ($$)->set_acceptor ($3,false);
530 | translator_spec_body REMOVE STRING {
531 unsmob_translator_def ($$)->remove_element ($3);
542 /*cont*/ '{' score_body '}' {
545 if (!$$->def_p_arr_.size ())
547 Music_output_def *id =
548 unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
549 $$->add_output (id ? id->clone () : new Paper_def );
558 $$->set_spot (THIS->here_input ());
559 SCM m = $1->self_scm ();
560 scm_gc_unprotect_object (m);
564 $$ = new Score (*unsmob_score ($1));
565 $$->set_spot (THIS->here_input ());
567 | score_body lilypond_header {
568 scm_gc_unprotect_object ($2->self_scm ());
571 | score_body output_def {
584 music_output_def_body '}' {
586 THIS-> lexer_p_-> scope_l_arr_.pop ();
590 music_output_def_body:
592 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultmidi"));
597 p = dynamic_cast<Midi_def*> (id->clone ());
602 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
605 Music_output_def *id = unsmob_music_output_def (THIS->lexer_p_->lookup_identifier ("$defaultpaper"));
608 p = dynamic_cast<Paper_def*> (id->clone ());
611 THIS-> lexer_p_-> scope_l_arr_.push (p->scope_p_);
614 | PAPER '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
615 Music_output_def *p = unsmob_music_output_def ($3);
617 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
620 | MIDI '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
621 Music_output_def *p = unsmob_music_output_def ($3);
624 THIS->lexer_p_->scope_l_arr_.push (p->scope_p_);
627 | music_output_def_body assignment {
630 | music_output_def_body translator_spec_block {
631 $$->assign_translator ($2);
633 | music_output_def_body STYLESHEET embedded_scm {
634 dynamic_cast<Paper_def*> ($$)-> style_sheet_ = $3;
636 | music_output_def_body tempo_request {
638 junk this ? there already is tempo stuff in
641 int m = gh_scm2int ( $2->get_mus_property ("metronome-count"));
642 Duration *d = unsmob_duration ($2->get_mus_property ("duration"));
643 dynamic_cast<Midi_def*> ($$)->set_tempo (d->length_mom (), m);
645 | music_output_def_body error {
651 TEMPO steno_duration '=' bare_unsigned {
653 $$->set_mus_property ("duration", $2);
654 $$->set_mus_property ("metronome-count", gh_int2scm ( $4));
658 Music_list: /* empty */ {
659 $$ = gh_cons (SCM_EOL, SCM_EOL);
663 SCM c = gh_cons ($2->self_scm (), SCM_EOL);
664 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
665 if (gh_pair_p (gh_cdr (s)))
666 gh_set_cdr_x (gh_cdr (s), c); /* append */
668 gh_set_car_x (s, c); /* set first cons */
669 gh_set_cdr_x (s, c) ; /* remember last cell */
685 | ALTERNATIVE Music_sequence {
687 $2->set_spot (THIS->here_input ());
695 REPEAT string bare_unsigned Music Alternative_music
697 Music_sequence* alts = dynamic_cast <Music_sequence*> ($5);
698 if (alts && $3 < alts->length_i ())
699 $5->origin ()->warning (_ ("More alternatives than repeats. Junking excess alternatives."));
703 Repeated_music * r = new Repeated_music (SCM_EOL);
707 r-> set_mus_property ("body", beg->self_scm ());
708 scm_gc_unprotect_object (beg->self_scm ());
710 r->set_mus_property ("repeat-count", gh_int2scm (times >? 1));
714 alts->truncate (times);
715 r-> set_mus_property ("alternatives", alts->self_scm ());
716 scm_gc_unprotect_object (alts->self_scm ());
718 SCM func = scm_primitive_eval (ly_symbol2scm ("repeat-name-to-ctor"));
719 SCM result = gh_call1 (func, $2);
721 set_music_properties (r, result);
723 r->set_spot (*$4->origin ());
728 Music_sequence: '{' Music_list '}' {
729 $$ = new Music_sequence (SCM_EOL);
730 $$->set_mus_property ("elements", gh_car ($2));
735 SEQUENTIAL '{' Music_list '}' {
736 $$ = new Sequential_music (SCM_EOL);
737 $$->set_mus_property ("elements", gh_car ($3));
739 | '{' Music_list '}' {
740 $$ = new Sequential_music (SCM_EOL);
741 $$->set_mus_property ("elements", gh_car ($2));
746 SIMULTANEOUS '{' Music_list '}'{
747 $$ = new Simultaneous_music (SCM_EOL);
748 $$->set_mus_property ("elements", gh_car ($3));
751 | '<' Music_list '>' {
752 $$ = new Simultaneous_music (SCM_EOL);
753 $$->set_mus_property ("elements", gh_car ($2));
758 request_chord { $$ = $1; }
759 | OUTPUTPROPERTY embedded_scm embedded_scm '=' embedded_scm {
761 if (!gh_symbol_p ($3))
763 THIS->parser_error (_ ("Second argument must be a symbol"));
765 /*hould check # args */
766 if (!gh_procedure_p (pred))
768 THIS->parser_error (_ ("First argument must be a procedure taking 1 argument"));
771 Music *m = new Music (SCM_EOL);
772 m->set_mus_property ("predicate", pred);
773 m->set_mus_property ("grob-property", $3);
774 m->set_mus_property ("grob-value", $5);
775 m->set_mus_property ("iterator-ctor",
776 Output_property_music_iterator::constructor_cxx_function);
781 $$ = unsmob_music ($1)->clone ();
789 CONTEXT STRING Music {
790 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
791 csm->set_mus_property ("element", $3->self_scm ());
792 scm_gc_unprotect_object ($3->self_scm ());
794 csm->set_mus_property ("context-type",$2);
795 csm->set_mus_property ("context-id", ly_str02scm (""));
799 | AUTOCHANGE STRING Music {
800 Music * chm = new Music_wrapper (SCM_EOL);
801 chm->set_mus_property ("element", $3->self_scm ());
802 chm->set_mus_property ("iterator-ctor", Auto_change_iterator::constructor_cxx_function);
804 scm_gc_unprotect_object ($3->self_scm ());
805 chm->set_mus_property ("what", $2);
808 chm->set_spot (*$3->origin ());
811 $$ = new Grace_music (SCM_EOL);
812 $$->set_mus_property ("element", $2->self_scm ());
813 scm_gc_unprotect_object ($2->self_scm ());
816 | CONTEXT string '=' string Music {
817 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
818 csm->set_mus_property ("element", $5->self_scm ());
819 scm_gc_unprotect_object ($5->self_scm ());
821 csm->set_mus_property ("context-type", $2);
822 csm->set_mus_property ("context-id", $4);
833 int n = gh_scm2int (gh_car ($3)); int d = gh_scm2int (gh_cdr ($3));
835 $$ = new Time_scaled_music (SCM_EOL);
836 $$->set_spot (THIS->pop_spot ());
839 $$->set_mus_property ("element", mp->self_scm ());
840 scm_gc_unprotect_object (mp->self_scm ());
841 $$->set_mus_property ("numerator", gh_int2scm (n));
842 $$->set_mus_property ("denominator", gh_int2scm (d));
843 $$->compress (Moment (n,d));
846 | Repeated_music { $$ = $1; }
847 | Simultaneous_music { $$ = $1; }
848 | Sequential_music { $$ = $1; }
849 | TRANSPOSE pitch Music {
850 $$ = new Transposed_music (SCM_EOL);
852 Pitch pit = *unsmob_pitch ($2);
855 $$->set_mus_property ("element", p->self_scm ());
856 scm_gc_unprotect_object (p->self_scm ());
858 | TRANSPOSE steno_tonic_pitch Music {
859 $$ = new Transposed_music (SCM_EOL);
861 Pitch pit = *unsmob_pitch ($2);
864 $$->set_mus_property ("element", p->self_scm ());
865 scm_gc_unprotect_object (p->self_scm ());
868 | APPLY embedded_scm Music {
869 SCM ret = gh_call1 ($2, $3->self_scm ());
870 Music *m = unsmob_music (ret);
872 THIS->parser_error ("\\apply must return a Music");
873 m = new Music (SCM_EOL);
878 { THIS->lexer_p_->push_note_state (); }
881 THIS->lexer_p_->pop_state ();
884 { THIS->lexer_p_->push_chord_state (); }
887 Music * chm = new Un_relativable_music ;
888 chm->set_mus_property ("element", $3->self_scm ());
891 THIS->lexer_p_->pop_state ();
894 { THIS->lexer_p_->push_lyric_state (); }
898 THIS->lexer_p_->pop_state ();
900 | relative_music { $$ = $1; }
901 | re_rhythmed_music { $$ = $1; }
902 | part_combined_music { $$ = $1; }
906 RELATIVE absolute_pitch Music {
908 Pitch pit = *unsmob_pitch ($2);
909 $$ = new Relative_octave_music (SCM_EOL);
911 $$->set_mus_property ("element", p->self_scm ());
912 scm_gc_unprotect_object (p->self_scm ());
914 $$->set_mus_property ("last-pitch", p->to_relative_octave (pit).smobbed_copy ());
920 ADDLYRICS Music Music {
921 Lyric_combine_music * l = new Lyric_combine_music (SCM_EOL);
922 l->set_mus_property ("music", $2->self_scm ());
923 l->set_mus_property ("lyrics", $3->self_scm ());
924 scm_gc_unprotect_object ($3->self_scm ());
925 scm_gc_unprotect_object ($2->self_scm ());
931 PARTCOMBINE STRING Music Music {
932 Part_combine_music * p = new Part_combine_music (SCM_EOL);
934 p->set_mus_property ("what", $2);
935 p->set_mus_property ("one", $3->self_scm ());
936 p->set_mus_property ("two", $4->self_scm ());
938 scm_gc_unprotect_object ($3->self_scm ());
939 scm_gc_unprotect_object ($4->self_scm ());
947 TRANSLATOR STRING '=' STRING {
948 Music * t = new Music (SCM_EOL);
949 t->set_mus_property ("iterator-ctor",
950 Change_iterator::constructor_cxx_function);
951 t-> set_mus_property ("change-to-type", $2);
952 t-> set_mus_property ("change-to-id", $4);
955 $$->set_spot (THIS->here_input ());
960 PROPERTY STRING '.' STRING '=' scalar {
962 Music *t = set_property_music (scm_string_to_symbol ($4), $6);
963 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
965 csm->set_mus_property ("element", t->self_scm ());
966 scm_gc_unprotect_object (t->self_scm ());
969 $$->set_spot (THIS->here_input ());
971 csm-> set_mus_property ("context-type", $2);
973 | PROPERTY STRING '.' STRING UNSET {
974 Music *t = new Music (SCM_EOL);
976 t->set_mus_property ("iterator-ctor",
977 Property_unset_iterator::constructor_cxx_function);
978 t->set_mus_property ("symbol", scm_string_to_symbol ($4));
980 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
981 csm->set_mus_property ("element", t->self_scm ());
982 scm_gc_unprotect_object (t->self_scm ());
985 $$->set_spot (THIS->here_input ());
987 csm-> set_mus_property ("context-type", $2);
989 | PROPERTY STRING '.' STRING SET embedded_scm '=' embedded_scm {
990 Music *t = new Music (SCM_EOL);
991 t->set_mus_property ("iterator-ctor",
992 Push_property_iterator::constructor_cxx_function);
993 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
994 t->set_mus_property ("pop-first", SCM_BOOL_T);
995 t->set_mus_property ("grob-property", $6);
996 t->set_mus_property ("grob-value", $8);
997 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
998 csm->set_mus_property ("element", t->self_scm ());
999 scm_gc_unprotect_object (t->self_scm ());
1001 $$->set_spot (THIS->here_input ());
1003 csm-> set_mus_property ("context-type", $2);
1005 | PROPERTY STRING '.' STRING OVERRIDE embedded_scm '=' embedded_scm {
1006 Music *t = new Music (SCM_EOL);
1007 t->set_mus_property ("iterator-ctor",
1008 Push_property_iterator::constructor_cxx_function);
1009 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1010 t->set_mus_property ("grob-property", $6);
1011 t->set_mus_property ("grob-value", $8);
1012 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1013 csm->set_mus_property ("element", t->self_scm ());
1014 scm_gc_unprotect_object (t->self_scm ());
1017 $$->set_spot (THIS->here_input ());
1019 csm-> set_mus_property ("context-type", $2);
1021 | PROPERTY STRING '.' STRING REVERT embedded_scm {
1022 Music *t = new Music (SCM_EOL);
1023 t->set_mus_property ("iterator-ctor",
1024 Pop_property_iterator::constructor_cxx_function);
1025 t->set_mus_property ("symbols", scm_string_to_symbol ($4));
1026 t->set_mus_property ("grob-property", $6);
1028 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1029 csm->set_mus_property ("element", t->self_scm ());
1030 scm_gc_unprotect_object (t->self_scm ());
1033 $$->set_spot (THIS->here_input ());
1035 csm-> set_mus_property ("context-type", $2);
1041 | bare_int { $$ = gh_int2scm ($1); }
1042 | embedded_scm { $$ = $1; }
1049 } /*cont */ simple_element post_requests {
1050 Music_sequence *l = dynamic_cast<Music_sequence*> ($3);
1052 for (int i=0; i < $1->size (); i++)
1053 l->append_music ($1->elem (i));
1054 for (int i=0; i < $4->size (); i++)
1055 l->append_music ($4->elem (i));
1058 programming_error ("Need Sequence to add music to");
1066 $$ = new Request_chord (SCM_EOL);
1067 $$->set_mus_property ("elements", gh_cons ($1->self_scm (), SCM_EOL));
1068 $$-> set_spot (THIS->here_input ());
1069 $1-> set_spot (THIS->here_input ());
1072 $$ = new Music (gh_list (gh_cons (ly_symbol2scm ("name"), ly_symbol2scm ("separator")), SCM_UNDEFINED));
1073 $$->set_spot (THIS->here_input ());
1076 extern Music * get_barcheck();
1077 $$ = get_barcheck ();
1078 $$->set_spot (THIS->here_input ());
1081 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1083 Context_specced_music *csm = new Context_specced_music (SCM_EOL);
1084 csm->set_mus_property ("element", t->self_scm ());
1085 scm_gc_unprotect_object (t->self_scm ());
1088 $$->set_spot (THIS->here_input ());
1090 csm->set_mus_property ("context-type", ly_str02scm ("Score"));
1092 | PARTIAL duration_length {
1093 Moment m = - unsmob_duration ($2)->length_mom ();
1094 Music * p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1096 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1097 sp->set_mus_property ("element", p->self_scm ());
1098 scm_gc_unprotect_object (p->self_scm ());
1101 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1104 SCM func = scm_primitive_eval (ly_symbol2scm ("clef-name-to-properties"));
1105 SCM result = gh_call1 (func, $2);
1108 for (SCM s = result ; gh_pair_p (s); s = gh_cdr (s)) {
1109 Music * p = new Music (SCM_EOL);
1110 set_music_properties (p, gh_car (s));
1111 l = gh_cons (p->self_scm (), l);
1112 scm_gc_unprotect_object (p->self_scm ());
1114 Sequential_music * seq = new Sequential_music (SCM_EOL);
1115 seq->set_mus_property ("elements", l);
1117 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1118 sp->set_mus_property ("element", seq->self_scm ());
1119 scm_gc_unprotect_object (seq->self_scm ());
1122 sp-> set_mus_property ("context-type", ly_str02scm ("Staff"));
1125 Music * p1 = set_property_music (ly_symbol2scm ( "timeSignatureFraction"), $2);
1127 int l = gh_scm2int (gh_car ($2));
1128 int o = gh_scm2int (gh_cdr ($2));
1130 Moment one_beat = Moment (1)/Moment (o);
1131 Moment len = Moment (l) * one_beat;
1134 Music *p2 = set_property_music (ly_symbol2scm ("measureLength"), len.smobbed_copy ());
1135 Music *p3 = set_property_music (ly_symbol2scm ("beatLength"), one_beat.smobbed_copy ());
1137 SCM list = gh_list (p1->self_scm (), p2->self_scm (), p3->self_scm(), SCM_UNDEFINED);
1138 Sequential_music *seq = new Sequential_music (SCM_EOL);
1139 seq->set_mus_property ("elements", list);
1142 Context_specced_music * sp = new Context_specced_music (SCM_EOL);
1143 sp->set_mus_property ("element", seq->self_scm ());
1147 scm_gc_unprotect_object (p3->self_scm ());
1148 scm_gc_unprotect_object (p2->self_scm ());
1149 scm_gc_unprotect_object (p1->self_scm ());
1150 scm_gc_unprotect_object (seq->self_scm ());
1155 TODO: should make alias TimingContext for Score
1158 sp-> set_mus_property ("context-type", ly_str02scm ( "Score"));
1163 shorthand_command_req { $$ = $1; }
1164 | verbose_command_req { $$ = $1; }
1167 shorthand_command_req:
1178 Span_req*b= new Span_req;
1179 b->set_span_dir (START);
1180 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1184 Span_req*b= new Span_req;
1185 b->set_span_dir ( STOP);
1186 b->set_mus_property ("span-type", ly_str02scm ("beam"));
1190 $$ = new Breathing_sign_req;
1195 verbose_command_req:
1196 COMMANDSPANREQUEST bare_int STRING { /*TODO: junkme */
1197 Span_req * sp_p = new Span_req;
1198 sp_p-> set_span_dir ( Direction ($2));
1199 sp_p->set_mus_property ("span-type",$3);
1200 sp_p->set_spot (THIS->here_input ());
1204 Mark_req * m = new Mark_req;
1208 Mark_req *m = new Mark_req;
1209 m->set_mus_property ("label", $2);
1216 Break_req * b = new Break_req;
1218 if (!gh_number_p (s))
1221 b->set_mus_property ("penalty", s);
1222 b->set_spot (THIS->here_input ());
1225 | SKIP duration_length {
1226 Skip_req * skip_p = new Skip_req;
1227 skip_p->set_mus_property ("duration", $2);
1235 Key_change_req *key_p= new Key_change_req;
1238 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1239 Key_change_req *key_p= new Key_change_req;
1241 key_p->set_mus_property ("pitch-alist", $3);
1242 ((Music* )key_p)->transpose (* unsmob_pitch ($2));
1249 $$ = new Link_array<Request>;
1251 | post_requests post_request {
1252 $2->set_spot (THIS->here_input ());
1264 request_that_take_dir:
1267 | script_abbreviation {
1268 SCM s = THIS->lexer_p_->lookup_identifier ("dash" + ly_scm2string ($1));
1269 Articulation_req *a = new Articulation_req;
1270 if (gh_string_p (s))
1271 a->set_mus_property ("articulation-type", s);
1272 else THIS->parser_error (_ ("Expecting string as script definition"));
1278 script_dir request_that_take_dir {
1279 if (Script_req * gs = dynamic_cast<Script_req*> ($2))
1280 gs->set_direction (Direction ($1));
1282 $2->origin ()->warning (_ ("Can't specify direction for this request"));
1288 REQUEST_IDENTIFIER {
1289 $$ = dynamic_cast<Request*> (unsmob_music ($1)->clone ());
1290 $$->set_spot (THIS->here_input ());
1292 | DYNAMICSCRIPT embedded_scm {
1294 TODO: junkme, use text-type == dynamic
1296 Text_script_req *d = new Text_script_req;
1297 d->set_mus_property ("text-type" , ly_symbol2scm ("dynamic"));
1298 d->set_mus_property ("text", $2);
1299 d->set_spot (THIS->here_input ());
1302 | SPANREQUEST bare_int STRING {
1303 Span_req * sp_p = new Span_req;
1304 sp_p->set_span_dir ( Direction ($2));
1305 sp_p->set_mus_property ("span-type", $3);
1306 sp_p->set_spot (THIS->here_input ());
1310 Tremolo_req* a = new Tremolo_req;
1311 a->set_spot (THIS->here_input ());
1312 a->set_mus_property ("tremolo-type", gh_int2scm ($1));
1316 Articulation_req * a = new Articulation_req;
1317 a->set_mus_property ("articulation-type", $2);
1318 a->set_spot (THIS->here_input ());
1322 duh, junk this syntax from the parser, if possible.
1325 Arpeggio_req *a = new Arpeggio_req;
1326 a->set_spot (THIS->here_input ());
1330 Glissando_req *g = new Glissando_req;
1331 g->set_spot /* No pun intended */ (THIS->here_input ());
1358 | NOTENAME_PITCH sup_quotes {
1359 Pitch p = *unsmob_pitch ($1);
1361 $$ = p.smobbed_copy ();
1363 | NOTENAME_PITCH sub_quotes {
1364 Pitch p =* unsmob_pitch ($1);
1367 $$ = p.smobbed_copy ();
1380 | TONICNAME_PITCH sup_quotes {
1381 Pitch p = *unsmob_pitch ($1);
1383 $$ = p.smobbed_copy ();
1385 | TONICNAME_PITCH sub_quotes {
1386 Pitch p =* unsmob_pitch ($1);
1389 $$ = p.smobbed_copy ();
1404 PITCH embedded_scm {
1406 if (!unsmob_pitch ($2)) {
1407 THIS->parser_error (_f ("Expecting musical-pitch value", 3));
1408 $$ = Pitch ().smobbed_copy ();
1414 DURATION embedded_scm {
1416 if (!unsmob_duration ($2))
1418 THIS->parser_error (_ ("Must have duration object"));
1419 $$ = Duration ().smobbed_copy ();
1426 if (!THIS->lexer_p_->lyric_state_b ())
1427 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1428 $$ = new Extender_req;
1434 if (!THIS->lexer_p_->lyric_state_b ())
1435 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1436 $$ = new Hyphen_req;
1441 close_request_parens {
1443 dynamic_cast<Span_req*> ($$)->set_span_dir ( START);
1446 close_request_parens:
1448 Span_req* s= new Span_req;
1450 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1453 Span_req* s= new Span_req;
1455 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1458 Span_req*s =new Span_req;
1460 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1463 Span_req*s =new Span_req;
1465 s->set_mus_property ("span-type", ly_str02scm ("decrescendo"));
1471 open_request_parens {
1473 dynamic_cast<Span_req*> ($$)->set_span_dir (STOP);
1477 open_request_parens:
1479 Span_req *s = new Span_req;
1480 s->set_mus_property ("span-type", ly_str02scm ( "crescendo"));
1485 Span_req* s= new Span_req;
1487 s->set_mus_property ("span-type", ly_str02scm ( "slur"));
1490 Span_req* s= new Span_req;
1492 s->set_mus_property ("span-type", ly_str02scm ( "phrasing-slur"));
1498 Text_script_req *t = new Text_script_req;
1499 t->set_mus_property ("text", $1);
1500 t->set_spot (THIS->here_input ());
1504 Text_script_req *t = new Text_script_req;
1505 t->set_mus_property ("text", $1);
1506 t->set_spot (THIS->here_input ());
1510 String ds = to_str ($1);
1511 Text_script_req* t = new Text_script_req;
1513 t->set_mus_property ("text", ly_str02scm (ds.ch_C ()));
1514 t->set_mus_property ("text-type" , ly_symbol2scm ("finger"));
1515 t->set_spot (THIS->here_input ());
1520 script_abbreviation:
1522 $$ = gh_str02scm ("Hat");
1525 $$ = gh_str02scm ("Plus");
1528 $$ = gh_str02scm ("Dash");
1531 $$ = gh_str02scm ("Bar");
1534 $$ = gh_str02scm ("Larger");
1537 $$ = gh_str02scm ("Dot");
1545 | '-' { $$ = CENTER; }
1550 $$ = new Link_array<Request>;
1552 | pre_requests open_request {
1564 multiplied_duration {
1567 | explicit_duration {
1572 optional_notemode_duration:
1574 $$ = THIS->default_duration_.smobbed_copy ();
1576 | multiplied_duration {
1578 THIS->default_duration_ = *unsmob_duration ($$);
1580 | explicit_duration {
1582 THIS->default_duration_ = *unsmob_duration ($$);
1587 bare_unsigned dots {
1589 if (!is_duration_b ($1))
1590 THIS->parser_error (_f ("not a duration: %d", $1));
1594 $$ = Duration (l, $2).smobbed_copy ();
1596 | DURATION_IDENTIFIER dots {
1597 Duration *d =unsmob_duration ($1);
1598 Duration k (d->duration_log (),d->dot_count () + $2);
1599 $$ = k.smobbed_copy ();
1606 multiplied_duration:
1610 | multiplied_duration '*' bare_unsigned {
1611 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1613 | multiplied_duration '*' FRACTION {
1614 Moment m (gh_scm2int (gh_car ($3)), gh_scm2int (gh_cdr ($3)));
1616 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1621 FRACTION { $$ = $1; }
1622 | UNSIGNED '/' UNSIGNED {
1623 $$ = gh_cons (gh_int2scm ($1), gh_int2scm ($3));
1641 | ':' bare_unsigned {
1642 if (!is_duration_b ($2))
1643 THIS->parser_error (_f ("not a duration: %d", $2));
1656 pitch exclamations questions optional_notemode_duration optional_rest {
1658 Input i = THIS->pop_spot ();
1659 if (!THIS->lexer_p_->note_state_b ())
1660 THIS->parser_error (_ ("Have to be in Note mode for notes"));
1668 n->set_mus_property ("pitch", $1);
1669 n->set_mus_property ("duration", $4);
1673 n->set_mus_property ("cautionary", SCM_BOOL_T);
1674 if ($2 % 2 || $3 % 2)
1675 n->set_mus_property ("force-accidental", SCM_BOOL_T);
1677 Simultaneous_music*v = new Request_chord (SCM_EOL);
1678 v->set_mus_property ("elements", gh_list (n->self_scm (), SCM_UNDEFINED));
1684 | RESTNAME optional_notemode_duration {
1686 Input i = THIS->pop_spot ();
1687 SCM e = SCM_UNDEFINED;
1688 if (ly_scm2string ($1) =="s") {
1690 Skip_req * skip_p = new Skip_req;
1691 skip_p->set_mus_property ("duration" ,$2);
1692 skip_p->set_spot (i);
1693 e = skip_p->self_scm ();
1696 Rest_req * rest_req_p = new Rest_req;
1697 rest_req_p->set_mus_property ("duration", $2);
1698 rest_req_p->set_spot (i);
1699 e = rest_req_p->self_scm ();
1701 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1702 velt_p-> set_mus_property ("elements", gh_list (e,SCM_UNDEFINED));
1703 velt_p->set_spot (i);
1707 | MULTI_MEASURE_REST optional_notemode_duration {
1708 Input i = THIS->pop_spot ();
1710 Skip_req * sk = new Skip_req;
1711 sk->set_mus_property ("duration", $2);
1712 Span_req *sp1 = new Span_req;
1713 Span_req *sp2 = new Span_req;
1714 sp1-> set_span_dir ( START);
1715 sp2-> set_span_dir ( STOP);
1716 SCM r = ly_str02scm ("rest");
1717 sp1->set_mus_property ("span-type", r);
1718 sp2->set_mus_property ("span-type", r);
1720 Request_chord * rqc1 = new Request_chord (SCM_EOL);
1721 rqc1->set_mus_property ("elements", gh_list (sp1->self_scm (), SCM_UNDEFINED));
1722 Request_chord * rqc2 = new Request_chord (SCM_EOL);
1723 rqc2->set_mus_property ("elements", gh_list (sk->self_scm (), SCM_UNDEFINED));;
1724 Request_chord * rqc3 = new Request_chord (SCM_EOL);
1725 rqc3->set_mus_property ("elements", gh_list (sp2->self_scm (), SCM_UNDEFINED));;
1727 SCM ms = gh_list (rqc1->self_scm (), rqc2->self_scm (), rqc3->self_scm (), SCM_UNDEFINED);
1729 $$ = new Sequential_music (SCM_EOL);
1730 $$->set_mus_property ("elements", ms);
1732 | STRING optional_notemode_duration {
1733 Input i = THIS->pop_spot ();
1735 Lyric_req* lreq_p = new Lyric_req;
1736 lreq_p->set_mus_property ("text", $1);
1737 lreq_p->set_mus_property ("duration",$2);
1738 lreq_p->set_spot (i);
1739 Simultaneous_music* velt_p = new Request_chord (SCM_EOL);
1740 velt_p->set_mus_property ("elements", gh_list (lreq_p->self_scm (), SCM_UNDEFINED));
1745 Input i = THIS->pop_spot ();
1747 if (!THIS->lexer_p_->chord_state_b ())
1748 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
1755 steno_tonic_pitch optional_notemode_duration chord_additions chord_subtractions chord_inversion chord_bass {
1756 $$ = Chord::get_chord ($1, $3, $4, $5, $6, $2);
1757 $$->set_spot (THIS->here_input ());
1764 | CHORD_COLON chord_notes {
1773 | chord_notes '.' chord_step {
1774 $$ = gh_append2 ($$, $3);
1782 | CHORD_CARET chord_notes {
1792 | '/' steno_tonic_pitch {
1801 | CHORD_BASS steno_tonic_pitch {
1808 $$ = gh_cons ($1, SCM_EOL);
1810 | CHORDMODIFIER_PITCH {
1811 $$ = gh_cons (unsmob_pitch ($1)->smobbed_copy (), SCM_EOL);
1813 | CHORDMODIFIER_PITCH chord_note { /* Ugh. */
1814 $$ = gh_list (unsmob_pitch ($1)->smobbed_copy (),
1822 m.notename_i_ = ($1 - 1) % 7;
1823 m.octave_i_ = $1 > 7 ? 1 : 0;
1824 m.alteration_i_ = 0;
1826 $$ = m.smobbed_copy ();
1828 | bare_unsigned '+' {
1830 m.notename_i_ = ($1 - 1) % 7;
1831 m.octave_i_ = $1 > 7 ? 1 : 0;
1832 m.alteration_i_ = 1;
1835 $$ = m.smobbed_copy ();
1837 | bare_unsigned CHORD_MINUS {
1839 m.notename_i_ = ($1 - 1) % 7;
1840 m.octave_i_ = $1 > 7 ? 1 : 0;
1841 m.alteration_i_ = -1;
1843 $$ = m.smobbed_copy ();
1851 number_expression '+' number_term {
1852 $$ = scm_sum ($1, $3);
1854 | number_expression '-' number_term {
1855 $$ = scm_difference ($1, $3);
1864 | number_factor '*' number_factor {
1865 $$ = scm_product ($1, $3);
1867 | number_factor '/' number_factor {
1868 $$ = scm_divide ($1, $3);
1873 '(' number_expression ')' {
1876 | '-' number_factor { /* %prec UNARY_MINUS */
1877 $$ = scm_difference ($2, SCM_UNDEFINED);
1885 $$ = gh_int2scm ($1);
1890 | NUMBER_IDENTIFIER {
1894 $$ = gh_double2scm (gh_scm2double ($1) CM );
1897 $$ = gh_double2scm (gh_scm2double ($1) PT);
1900 $$ = gh_double2scm (gh_scm2double ($1) INCH);
1903 $$ = gh_double2scm (gh_scm2double ($1) MM);
1906 $$ = gh_double2scm (gh_scm2double ($1) CHAR);
1922 if (scm_integer_p ($1) == SCM_BOOL_T)
1924 int k = gh_scm2int ($1);
1928 THIS->parser_error (_ ("need integer number arg"));
1942 | STRING_IDENTIFIER {
1945 | string '+' string {
1946 $$ = scm_string_append (scm_list_n ($1, $3, SCM_UNDEFINED));
1953 | exclamations '!' { $$ ++; }
1958 | questions '?' { $$ ++; }
1965 My_lily_parser::set_yydebug (bool b)
1972 extern My_lily_parser * current_parser;
1975 My_lily_parser::do_yyparse ()
1978 current_parser = this;;
1979 yyparse ((void*)this);