1 %{ // -*-Fundamental-*-
4 parser.yy -- Bison/C++ parser for LilyPond
6 source file of the GNU LilyPond music typesetter
8 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 Jan Nieuwenhuizen <janneke@gnu.org>
16 * The rules for who is protecting what are very shady. Uniformise
19 * There are too many lexical modes?
30 #include "context-def.hh"
31 #include "dimensions.hh"
33 #include "file-path.hh"
34 #include "input-smob.hh"
36 #include "lily-guile.hh"
37 #include "lilypond-input-version.hh"
38 #include "ly-module.hh"
41 #include "music-list.hh"
42 #include "music-sequence.hh"
43 #include "lily-lexer.hh"
44 #include "lily-parser.hh"
45 #include "paper-book.hh"
46 #include "output-def.hh"
47 #include "scm-hash.hh"
48 #include "scm-option.hh"
50 #include "text-item.hh"
53 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
55 Music *property_op_to_music (SCM op);
56 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops);
57 SCM get_next_unique_context ();
59 #define YYERROR_VERBOSE 1
61 #define YYPARSE_PARAM my_lily_parser
62 #define YYLEX_PARAM my_lily_parser
64 ((Lily_parser *) my_lily_parser)
66 #define yyerror THIS->parser_error
68 /* Add symbols to the TAGS field of a music object. */
71 tag_music (Music *m, SCM tag, Input ip)
73 SCM tags = m->get_property ("tags");
74 if (scm_is_symbol (tag))
75 tags = scm_cons (tag, tags);
76 else if (ly_c_list_p (tag))
77 tags = ly_append2 (tag, tags);
79 ip.warning (_ ("Tag must be symbol or list of symbols."));
81 m->set_property ("tags", tags);
85 is_regular_identifier (SCM id)
87 String str = ly_scm2string (id);
88 char const *s = str.to_str0 ();
97 v = v && isalnum (*s);
105 get_first_context_id (SCM type, Music *m)
107 SCM id = m->get_property ("context-id");
108 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
109 && scm_is_string (m->get_property ("context-id"))
110 && scm_c_string_length (id) > 0)
118 make_simple_markup (SCM encoding, SCM a)
120 SCM simple = ly_scheme_function ("simple-markup");
121 if (scm_is_symbol (encoding))
122 return scm_list_3 (ly_scheme_function ("encoded-simple-markup"),
124 return scm_list_2 (simple, a);
130 return t && t == 1 << intlog2 (t);
134 set_music_properties (Music *p, SCM a)
136 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
137 p->internal_set_property (scm_caar (k), scm_cdar (k));
141 make_chord_step (int step, int alter)
148 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
149 return m.smobbed_copy ();
154 make_chord (SCM pitch, SCM dur, SCM modification_list)
156 SCM chord_ctor = ly_scheme_function ("construct-chord");
157 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
158 scm_gc_protect_object (ch);
162 /* Todo: actually also use apply iso. call too ... */
164 ly_input_procedure_p (SCM x)
166 return ly_c_procedure_p (x)
167 || (scm_is_pair (x) && ly_c_procedure_p (scm_car (x)));
171 set_property_music (SCM sym, SCM value)
173 Music *p = MY_MAKE_MUSIC ("PropertySet");
174 p->set_property ("symbol", sym);
175 p->set_property ("value", value);
180 make_music_relative (Pitch start, Music *music)
182 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
183 relative->set_property ("element", music->self_scm ());
185 Pitch last = music->to_relative_octave (start);
186 if (lily_1_8_relative)
187 music->set_property ("last-pitch", last.smobbed_copy ());
192 make_lyric_combine_music (SCM name, Music *music)
194 Music *combine = MY_MAKE_MUSIC ("NewLyricCombineMusic");
195 combine->set_property ("element", music->self_scm ());
196 combine->set_property ("associated-context", name);
202 /* We use SCMs to do strings, because it saves us the trouble of
203 deleting them. Let's hope that a stack overflow doesnt trigger a move
204 of the parse stack onto the heap. */
210 Output_def *outputdef;
220 yylex (YYSTYPE *s, void *v)
222 Lily_parser *pars = (Lily_parser*) v;
223 Lily_lexer *lex = pars->lexer_;
225 lex->lexval = (void*) s;
226 lex->prepare_for_next_token ();
227 return lex->yylex ();
236 Three shift/reduce problems:
238 2. \markup identifier.
248 \repeat .. \alternative
251 \repeat { \repeat .. \alternative }
255 \repeat { \repeat } \alternative
271 %token CHORDMODIFIERS
274 %token DOUBLE_ANGLE_OPEN
275 %token DOUBLE_ANGLE_CLOSE
277 %token COMMANDSPANREQUEST
286 %token FIGURE_OPEN FIGURE_CLOSE
287 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
288 %token GROBDESCRIPTIONS
298 %token MULTI_MEASURE_REST
304 %token OVERRIDE SET REVERT
331 /* FIXME: this sucks. The user will get to see these names:
332 syntax error, unexpected E_CHAR:
337 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
338 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
340 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH
345 %token <i> E_UNSIGNED
346 %token <id> IDENTIFIER
347 %token <scm> CHORDMODIFIER_PITCH
348 %token <scm> DRUM_PITCH
349 %token <scm> DURATION_IDENTIFIER
350 %token <scm> EVENT_IDENTIFIER
351 %token <scm> MUSIC_IDENTIFIER CONTEXT_DEF_IDENTIFIER
352 %token <scm> NOTENAME_PITCH
353 %token <scm> NUMBER_IDENTIFIER
354 %token <scm> OUTPUT_DEF_IDENTIFIER
355 %token <scm> RESTNAME
356 %token <scm> LYRICS_STRING
358 %token <scm> SCORE_IDENTIFIER
360 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
361 %token <scm> TONICNAME_PITCH
362 %token <scm> CHORD_MODIFIER
363 %token <scm> FRACTION
365 %token <scm> MARKUP_HEAD_EMPTY
366 %token <scm> MARKUP_HEAD_MARKUP0
367 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
368 %token <scm> MARKUP_HEAD_SCM0
369 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
370 %token <scm> MARKUP_HEAD_SCM0_SCM1
371 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
372 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
373 %token <scm> MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
374 %token <scm> MUSIC_FUNCTION
375 %token <scm> MUSIC_FUNCTION_MUSIC
376 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
377 %token <scm> MUSIC_FUNCTION_SCM
378 %token <scm> MUSIC_FUNCTION_SCM_SCM
379 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
380 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
381 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
382 %token <scm> MUSIC_FUNCTION_MARKUP
383 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
384 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
385 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
386 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
392 %type <book> book_block book_body
393 %type <i> bare_int bare_unsigned
394 %type <i> exclamations questions dots optional_rest
396 %type <i> sub_quotes sup_quotes
397 %type <i> tremolo_type
400 %type <music> Composite_music Simple_music Prefix_composite_music Generic_prefix_music
401 %type <music> Grouped_music_list
402 %type <music> Music Sequential_music Simultaneous_music
403 %type <music> Repeated_music
404 %type <music> command_req
405 %type <music> gen_text_def direction_less_event direction_reqd_event
406 %type <music> music_property_def context_change
407 %type <music> note_chord_element chord_body chord_body_element
408 %type <music> post_event tagged_post_event
409 %type <music> relative_music re_rhythmed_music
410 %type <music> simple_element event_chord command_element
411 %type <music> string_number_event
412 %type <music> toplevel_music
413 %type <music> tempo_event
415 %type <outputdef> output_def_body output_def_head
416 %type <outputdef> output_def paper_block
418 %type <scm> Music_list
419 %type <scm> chord_body_elements
420 %type <scm> chord_item chord_items chord_separator new_chord
421 %type <scm> context_def_spec_block context_def_spec_body
422 %type <scm> context_mod context_def_mod optional_context_mod
423 %type <scm> context_prop_spec
424 %type <scm> direction_less_char
425 %type <scm> duration_length fraction
426 %type <scm> embedded_scm scalar
427 %type <scm> identifier_init
428 %type <scm> lilypond_header lilypond_header_body
429 %type <scm> new_lyrics
430 %type <scm> post_events
431 %type <scm> property_operation
432 %type <scm> script_abbreviation
433 %type <scm> simple_string
434 %type <scm> steno_pitch pitch absolute_pitch pitch_also_in_chords
435 %type <scm> steno_tonic_pitch
436 %type <scm> step_number step_numbers
437 %type <scm> string bare_number number_expression number_term number_factor
438 %type <scm> bass_number br_bass_figure bass_figure figure_list figure_spec
439 %type <scm> context_mod_list
440 %type <scm> octave_check
441 %type <scm> steno_duration optional_notemode_duration multiplied_duration
442 %type <scm> Generic_prefix_music_scm
443 %type <scm> lyric_element
444 %type <scm> Alternative_music
445 %type <scm> markup markup_line markup_list markup_list_body full_markup
446 %type <scm> mode_changing_head
447 %type <scm> mode_changing_head_with_context
449 %type <score> score_block score_body
454 /* We don't assign precedence to / and *, because we might need varied
455 prec levels in different prods */
461 lilypond: /* empty */
462 | lilypond toplevel_expression {
464 | lilypond assignment {
467 THIS->error_level_ = 1;
470 THIS->error_level_ = 1;
476 THIS->lexer_->set_identifier (ly_symbol2scm ("$globalheader"), $1);
483 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
484 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
485 scm_gc_unprotect_object (book->self_scm ());
490 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
491 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
492 scm_gc_unprotect_object (score->self_scm ());
496 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
497 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
498 scm_gc_unprotect_object (music->self_scm ());
502 Output_def * od = $1;
504 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
505 id = ly_symbol2scm ("$defaultpaper");
506 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
507 id = ly_symbol2scm ("$defaultmidi");
508 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
509 id = ly_symbol2scm ("$defaultlayout");
511 THIS->lexer_->set_identifier (id, od->self_scm ());
512 scm_gc_unprotect_object (od->self_scm ());
527 lilypond_header_body:
529 $$ = ly_make_anonymous_module (safe_global_b);
530 THIS->lexer_->add_scope ($$);
532 | lilypond_header_body assignment {
538 HEADER '{' lilypond_header_body '}' {
539 $$ = THIS->lexer_->remove_scope ();
551 /* cont */ '=' identifier_init {
554 Should find generic way of associating input with objects.
556 Input ip = THIS->pop_spot ();
558 if (! is_regular_identifier ($1))
560 ip.warning (_ ("Identifier should have alphabetic characters only"));
563 THIS->lexer_->set_identifier ($1, $4);
566 TODO: devise standard for protection in parser.
568 The parser stack lives on the C-stack, which means that
569 all objects can be unprotected as soon as they're here.
579 $$ = $1->self_scm ();
580 scm_gc_unprotect_object ($$);
583 $$ = $1->self_scm ();
584 scm_gc_unprotect_object ($$);
586 | context_def_spec_block {
590 $$ = $1->self_scm ();
591 scm_gc_unprotect_object ($$);
594 $$ = $1->self_scm ();
595 scm_gc_unprotect_object ($$);
597 | number_expression {
610 $$ = scm_int2num ($1);
614 context_def_spec_block:
615 CONTEXT '{' context_def_spec_body '}'
621 context_def_spec_body:
623 $$ = Context_def::make_scm ();
624 unsmob_context_def ($$)->set_spot (THIS->here_input ());
626 | CONTEXT_DEF_IDENTIFIER {
628 unsmob_context_def ($$)->set_spot (THIS->here_input ());
630 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
631 Context_def*td = unsmob_context_def ($$);
633 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
634 SCM tag = scm_caar (p);
636 /* TODO: should make new tag "grob-definition" ? */
637 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
638 tag, scm_cons (scm_cdar (p), SCM_EOL)));
641 | context_def_spec_body context_mod {
642 unsmob_context_def ($$)->add_context_mod ($2);
652 /*cont*/ '{' book_body '}' {
659 * Use 'handlers' like for toplevel-* stuff?
660 * grok \layout and \midi? */
664 $$->set_spot (THIS->here_input ());
665 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
666 scm_gc_unprotect_object ($$->paper_->self_scm ());
667 $$->header_ = THIS->lexer_->lookup_identifier ("$globalheader");
669 | book_body paper_block {
671 scm_gc_unprotect_object ($2->self_scm ());
673 | book_body score_block {
675 $$->scores_.push (score);
676 scm_gc_unprotect_object (score->self_scm ());
678 | book_body lilypond_header {
691 /*cont*/ '{' score_body '}' {
701 $$->set_spot (THIS->here_input ());
704 $$ = new Score ( *unsmob_score ($1));
705 $$->set_spot (THIS->here_input ());
708 SCM m = $2->self_scm ();
709 scm_gc_unprotect_object (m);
710 $$->set_music (m, THIS->self_scm ());
712 | score_body lilypond_header {
715 | score_body output_def {
716 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
718 THIS->parser_error (_("\\paper cannot be in \\score. Use \\layout instead"));
725 scm_gc_unprotect_object ($2->self_scm ());
728 $$->error_found_ = true;
740 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
742 THIS->parser_error (_("Need \\paper for paper block."));
743 $$ = get_paper (THIS);
750 output_def_body '}' {
753 THIS->lexer_->remove_scope ();
754 THIS->lexer_->pop_state ();
760 $$ = get_paper (THIS);
761 $$->input_origin_ = THIS->here_input ();
762 THIS->lexer_->add_scope ($$->scope_);
765 Output_def *p = get_midi (THIS);
767 THIS->lexer_->add_scope (p->scope_);
770 Output_def *p = get_layout (THIS);
772 THIS->lexer_->add_scope (p->scope_);
779 output_def_head '{' {
781 $$->input_origin_.set_spot (THIS->here_input ());
782 THIS->lexer_->push_initial_state ();
784 | output_def_head '{' OUTPUT_DEF_IDENTIFIER {
785 scm_gc_unprotect_object ($1->self_scm ());
786 Output_def *o = unsmob_output_def ($3);
787 o->input_origin_.set_spot (THIS->here_input ());
789 THIS->lexer_->remove_scope ();
790 THIS->lexer_->add_scope (o->scope_);
791 THIS->lexer_->push_initial_state ();
793 | output_def_body assignment {
796 | output_def_body context_def_spec_block {
797 assign_context_def ($$, $2);
799 | output_def_body tempo_event {
801 junk this ? there already is tempo stuff in
804 int m = scm_to_int ($2->get_property ("metronome-count"));
805 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
806 set_tempo ($$, d->get_length (), m);
807 scm_gc_unprotect_object ($2->self_scm ());
809 | output_def_body error {
815 TEMPO steno_duration '=' bare_unsigned {
816 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
817 $$->set_property ("tempo-unit", $2);
818 $$->set_property ("metronome-count", scm_int2num ( $4));
823 The representation of a list is the
827 to have efficient append. */
831 $$ = scm_cons (SCM_EOL, SCM_EOL);
835 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
836 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
838 if (scm_is_pair (scm_cdr (s)))
839 scm_set_cdr_x (scm_cdr (s), c); /* append */
841 scm_set_car_x (s, c); /* set first cons */
842 scm_set_cdr_x (s, c); /* remember last cell */
844 | Music_list embedded_scm {
848 Music * m = MY_MAKE_MUSIC("Music");
850 m->set_property ("error-found", SCM_BOOL_T);
852 SCM c = scm_cons (m->self_scm (), SCM_EOL);
853 scm_gc_unprotect_object (m->self_scm ()); /* UGH */
855 if (scm_is_pair (scm_cdr (s)))
856 scm_set_cdr_x (scm_cdr (s), c); /* append */
858 scm_set_car_x (s, c); /* set first cons */
859 scm_set_cdr_x (s, c); /* remember last cell */
872 | ALTERNATIVE '{' Music_list '}' {
879 REPEAT simple_string bare_unsigned Music Alternative_music
883 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
884 if (times < scm_ilength (alts)) {
885 unsmob_music (scm_car (alts))
886 ->origin ()->warning (
887 _ ("More alternatives than repeats. Junking excess alternatives."));
888 alts = ly_truncate_list (times, alts);
892 SCM proc = ly_scheme_function ("make-repeated-music");
894 SCM mus = scm_call_1 (proc, $2);
895 scm_gc_protect_object (mus); // UGH.
896 Music *r = unsmob_music (mus);
899 r-> set_property ("element", beg->self_scm ());
900 scm_gc_unprotect_object (beg->self_scm ());
902 r->set_property ("repeat-count", scm_int2num (times >? 1));
904 r-> set_property ("elements",alts);
905 if (ly_c_equal_p ($2, scm_makfrom0str ("tremolo"))) {
907 TODO: move this code to Scheme.
911 we can not get durations and other stuff correct down the line, so we have to
912 add to the duration log here.
914 SCM func = ly_scheme_function ("shift-duration-log");
916 int dots = ($3 % 3) ? 0 : 1;
917 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
919 Sequential_music *seq = dynamic_cast<Sequential_music*> ($4);
922 int list_len = scm_ilength (seq->music_list ());
924 seq->origin ()->warning ("Chord tremolo must have 2 elements.");
926 r->compress (Moment (Rational (1, list_len)));
928 scm_call_3 (func, r->self_scm (), scm_int2num (shift),scm_int2num (dots));
931 r->set_spot (*$4->origin ());
938 SEQUENTIAL '{' Music_list '}' {
939 $$ = MY_MAKE_MUSIC ("SequentialMusic");
940 $$->set_property ("elements", scm_car ($3));
941 $$->set_spot (THIS->here_input ());
943 | '{' Music_list '}' {
944 $$ = MY_MAKE_MUSIC ("SequentialMusic");
945 $$->set_property ("elements", scm_car ($2));
946 $$->set_spot (THIS->here_input ());
951 SIMULTANEOUS '{' Music_list '}'{
952 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
953 $$->set_property ("elements", scm_car ($3));
954 $$->set_spot (THIS->here_input ());
957 | simul_open Music_list simul_close {
958 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
959 $$->set_property ("elements", scm_car ($2));
960 $$->set_spot (THIS->here_input ());
965 event_chord { $$ = $1; }
967 $$ = unsmob_music ($1);
974 optional_context_mod:
975 /**/ { $$ = SCM_EOL; }
976 | WITH { THIS->lexer_->push_initial_state (); }
977 '{' context_mod_list '}'
979 THIS->lexer_->pop_state ();
985 /* */ { $$ = SCM_EOL; }
986 | context_mod_list context_mod {
987 $$ = scm_cons ($2, $1);
993 Prefix_composite_music { $$ = $1; }
994 | Grouped_music_list { $$ = $1; }
998 Simultaneous_music { $$ = $1; }
999 | Sequential_music { $$ = $1; }
1002 Generic_prefix_music_scm:
1004 $$ = scm_list_2 ($1, make_input (THIS->here_input ()));
1006 | MUSIC_FUNCTION_SCM {
1009 $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3);
1011 | MUSIC_FUNCTION_MARKUP {
1014 $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3);
1016 | MUSIC_FUNCTION_MUSIC {
1019 $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3->self_scm ());
1020 scm_gc_unprotect_object ($3->self_scm ());
1022 | MUSIC_FUNCTION_SCM_MUSIC {
1024 } embedded_scm Music {
1025 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4->self_scm ());
1026 scm_gc_unprotect_object ($4->self_scm ());
1028 | MUSIC_FUNCTION_SCM_SCM {
1030 } embedded_scm embedded_scm {
1031 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4);
1033 | MUSIC_FUNCTION_SCM_SCM_MUSIC {
1035 } embedded_scm embedded_scm Music {
1036 $$ = scm_list_5 ($1, make_input (THIS->pop_spot ()), $3, $4, $5->self_scm ());
1038 | MUSIC_FUNCTION_MARKUP_MUSIC {
1040 } full_markup Music {
1041 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4->self_scm ());
1042 scm_gc_unprotect_object ($4->self_scm ());
1044 | MUSIC_FUNCTION_MARKUP_MARKUP {
1046 } full_markup full_markup {
1047 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4);
1049 | MUSIC_FUNCTION_MUSIC_MUSIC {
1052 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3->self_scm (), $4->self_scm ());
1053 scm_gc_unprotect_object ($3->self_scm ());
1054 scm_gc_unprotect_object ($4->self_scm ());
1056 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC {
1058 } embedded_scm Music Music {
1059 $$ = scm_list_5 ($1, make_input (THIS->pop_spot ()),
1060 $3, $4->self_scm (), $5->self_scm ());
1061 scm_gc_unprotect_object ($5->self_scm ());
1062 scm_gc_unprotect_object ($4->self_scm ());
1064 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC {
1066 } full_markup Music Music {
1067 $$ = scm_list_5 ($1, make_input (THIS->pop_spot ()),
1068 $3, $4->self_scm (), $5->self_scm ());
1069 scm_gc_unprotect_object ($5->self_scm ());
1070 scm_gc_unprotect_object ($4->self_scm ());
1074 Generic_prefix_music:
1075 Generic_prefix_music_scm {
1076 SCM func = scm_car ($1);
1077 Input *loc = unsmob_input (scm_cadr ($1));
1078 SCM args = scm_cddr ($1);
1079 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
1081 SCM type_check_proc = ly_scheme_function ("type-check-list");
1084 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr ($1), sig, args)))
1086 THIS->error_level_ = 1;
1092 m = scm_apply_0 (func, scm_cdr ($1));
1094 if (unsmob_music (m))
1096 $$ = unsmob_music (m);
1097 scm_gc_protect_object (m);
1102 loc->error (_ ("Music head function should return Music object."));
1103 $$ = MY_MAKE_MUSIC ("Music");
1105 $$->set_spot (*loc);
1110 Prefix_composite_music:
1111 Generic_prefix_music {
1114 | CONTEXT simple_string '=' simple_string optional_context_mod Music {
1115 $$ = context_spec_music ($2, $4, $6, $5);
1118 | CONTEXT simple_string optional_context_mod Music {
1119 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1121 | NEWCONTEXT simple_string optional_context_mod Music {
1122 $$ = context_spec_music ($2, get_next_unique_context (), $4,
1133 int n = scm_to_int (scm_car ($3)); int d = scm_to_int (scm_cdr ($3));
1136 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1137 $$->set_spot (THIS->pop_spot ());
1139 $$->set_property ("element", mp->self_scm ());
1140 scm_gc_unprotect_object (mp->self_scm ());
1141 $$->set_property ("numerator", scm_int2num (n));
1142 $$->set_property ("denominator", scm_int2num (d));
1143 $$->compress (Moment (Rational (n,d)));
1146 | Repeated_music { $$ = $1; }
1147 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1148 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1150 Pitch from = *unsmob_pitch ($2);
1151 Pitch to = *unsmob_pitch ($3);
1153 p->transpose (pitch_interval (from, to));
1154 $$->set_property ("element", p->self_scm ());
1155 scm_gc_unprotect_object (p->self_scm ());
1157 | mode_changing_head Grouped_music_list {
1158 if ($1 == ly_symbol2scm ("chords"))
1160 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1161 chm->set_property ("element", $2->self_scm ());
1163 scm_gc_unprotect_object ($2->self_scm ());
1169 THIS->lexer_->pop_state ();
1171 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1172 $$ = context_spec_music ($1, get_next_unique_context (),
1174 if ($1 == ly_symbol2scm ("ChordNames"))
1176 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1177 chm->set_property ("element", $$->self_scm ());
1178 scm_gc_unprotect_object ($$->self_scm ());
1181 THIS->lexer_->pop_state ();
1183 | relative_music { $$ = $1; }
1184 | re_rhythmed_music { $$ = $1; }
1185 | TAG embedded_scm Music {
1186 tag_music ($3, $2, THIS->here_input ());
1193 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1194 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1196 $$ = ly_symbol2scm ("notes");
1200 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1201 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1203 $$ = ly_symbol2scm ("drums");
1206 THIS->lexer_->push_figuredbass_state ();
1208 $$ = ly_symbol2scm ("figures");
1211 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1212 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1213 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1214 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1215 $$ = ly_symbol2scm ("chords");
1219 { THIS->lexer_->push_lyric_state ();
1220 $$ = ly_symbol2scm ("lyrics");
1224 mode_changing_head_with_context:
1226 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1227 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1229 $$ = ly_symbol2scm ("DrumStaff");
1232 THIS->lexer_->push_figuredbass_state ();
1234 $$ = ly_symbol2scm ("FiguredBass");
1237 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1238 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1239 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1240 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1241 $$ = ly_symbol2scm ("ChordNames");
1244 { THIS->lexer_->push_lyric_state ();
1245 $$ = ly_symbol2scm ("Lyrics");
1251 RELATIVE absolute_pitch Music {
1253 Pitch start = *unsmob_pitch ($2);
1254 $$ = make_music_relative (start, m);
1255 scm_gc_unprotect_object (m->self_scm ());
1257 | RELATIVE Composite_music {
1260 Pitch middle_c (0, 0, 0);
1261 $$ = make_music_relative (middle_c, m);
1262 scm_gc_unprotect_object (m->self_scm ());
1267 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1269 Grouped_music_list {
1270 /* Can also use Music at the expensive of two S/Rs similar to
1271 \repeat \alternative */
1272 THIS->lexer_->pop_state ();
1274 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1276 | new_lyrics ADDLYRICS {
1277 THIS->lexer_->push_lyric_state ();
1278 } Grouped_music_list {
1279 THIS->lexer_->pop_state ();
1280 $$ = scm_cons ($4->self_scm (), $1);
1285 Grouped_music_list new_lyrics {
1287 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice);
1288 if (!scm_is_string (name))
1290 name = get_next_unique_context ();
1291 voice = context_spec_music (scm_makfrom0str ("Voice"),
1296 SCM context = scm_makfrom0str ("Lyrics");
1297 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1300 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1302 Music *music = unsmob_music (scm_car (s));
1303 Music *com = make_lyric_combine_music (name, music);
1304 Music *csm = context_spec_music (context,
1305 get_next_unique_context (), com, SCM_EOL);
1306 lst = scm_cons (csm->self_scm (), lst);
1308 all->set_property ("elements", scm_cons (voice->self_scm (),
1311 scm_gc_unprotect_object (voice->self_scm ());
1314 THIS->lexer_->push_lyric_state ();
1315 } simple_string Music {
1316 THIS->lexer_->pop_state ();
1319 $$ = make_lyric_combine_music (name, music);
1320 scm_gc_unprotect_object (music->self_scm ());
1325 CHANGE STRING '=' STRING {
1326 Music*t= MY_MAKE_MUSIC ("ContextChange");
1327 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1328 t-> set_property ("change-to-id", $4);
1331 $$->set_spot (THIS->here_input ());
1337 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1338 scm_string_to_symbol ($1), $3);
1340 | UNSET simple_string {
1341 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1342 scm_string_to_symbol ($2));
1344 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1345 $$ = scm_list_4 (ly_symbol2scm ("push"),
1346 scm_string_to_symbol ($2), $3, $5);
1348 | REVERT simple_string embedded_scm {
1349 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1350 scm_string_to_symbol ($2), $3);
1355 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1356 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1358 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1359 | DENIES { $$ = ly_symbol2scm ("denies"); }
1361 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1362 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1363 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1364 | NAME { $$ = ly_symbol2scm ("context-name"); }
1368 property_operation { $$ = $1; }
1369 | context_def_mod STRING {
1370 $$ = scm_list_2 ($1, $2);
1376 if (!is_regular_identifier ($1))
1378 THIS->here_input ().error (_("Grob name should be alphanumeric"));
1381 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1382 scm_string_to_symbol ($1));
1384 | simple_string '.' simple_string {
1385 $$ = scm_list_2 (scm_string_to_symbol ($1),
1386 scm_string_to_symbol ($3));
1391 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1392 $$ = property_op_to_music (scm_list_4 (
1393 ly_symbol2scm ("poppush"),
1396 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1398 | REVERT context_prop_spec embedded_scm {
1399 $$ = property_op_to_music (scm_list_3 (
1400 ly_symbol2scm ("pop"),
1404 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1406 | SET context_prop_spec '=' scalar {
1407 $$ = property_op_to_music (scm_list_3 (
1408 ly_symbol2scm ("assign"),
1411 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1413 | UNSET context_prop_spec {
1414 $$ = property_op_to_music (scm_list_2 (
1415 ly_symbol2scm ("unset"),
1417 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1419 | ONCE music_property_def {
1420 SCM e = $2->get_property ("element");
1421 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1432 | STRING_IDENTIFIER {
1435 | string '+' string {
1436 $$ = scm_string_append (scm_list_2 ($1, $3));
1440 simple_string: STRING {
1455 $$ = scm_int2num ($1);
1464 $$ = scm_int2num ($1);
1470 pre_events doesn't contain anything. It is a trick:
1472 Adding pre_events to the simple_element
1473 makes the choice between
1479 simple_element: STRING
1481 a single shift/reduction conflict.
1483 nevertheless, this is not very clean, and we should find a different
1493 pre_events simple_element post_events {
1494 SCM elts = $2-> get_property ("elements");
1496 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1498 $2->set_property ("elements", elts);
1502 | note_chord_element
1507 chord_body optional_notemode_duration post_events
1509 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1510 SCM es = $1->get_property ("elements");
1511 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1513 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1514 unsmob_music (scm_car (s))->set_property ("duration", dur);
1515 es = ly_append2 (es, postevs);
1517 $1-> set_property ("elements", es);
1528 simul_open: DOUBLE_ANGLE_OPEN
1531 simul_close: DOUBLE_ANGLE_CLOSE
1535 chord_open chord_body_elements chord_close
1537 $$ = MY_MAKE_MUSIC ("EventChord");
1538 $$->set_property ("elements",
1539 scm_reverse_x ($2, SCM_EOL));
1543 chord_body_elements:
1544 /* empty */ { $$ = SCM_EOL; }
1545 | chord_body_elements chord_body_element {
1546 $$ = scm_cons ($2->self_scm (), $1);
1547 scm_gc_unprotect_object ($2->self_scm ());
1552 pitch exclamations questions octave_check post_events
1559 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1560 n->set_property ("pitch", $1);
1562 n->set_property ("cautionary", SCM_BOOL_T);
1563 if (ex % 2 || q % 2)
1564 n->set_property ("force-accidental", SCM_BOOL_T);
1566 if (scm_is_pair (post)) {
1567 SCM arts = scm_reverse_x (post, SCM_EOL);
1568 n->set_property ("articulations", arts);
1570 if (scm_is_number (check))
1572 int q = scm_to_int (check);
1573 n->set_property ("absolute-octave", scm_int2num (q-1));
1579 | DRUM_PITCH post_events {
1580 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1581 n->set_property ("duration", $2);
1582 n->set_property ("drum-type", $1);
1583 n->set_spot (THIS->here_input ());
1585 if (scm_is_pair ($2)) {
1586 SCM arts = scm_reverse_x ($2, SCM_EOL);
1587 n->set_property ("articulations", arts);
1594 ADDQUOTE string Music {
1595 SCM adder = ly_scheme_function ("add-quotable");
1597 scm_call_2 (adder, $2, $3->self_scm ());
1598 scm_gc_unprotect_object ($3->self_scm ());
1604 $$ = MY_MAKE_MUSIC ("EventChord");
1605 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1606 scm_gc_unprotect_object ($1->self_scm ());
1608 $$-> set_spot (THIS->here_input ());
1609 $1-> set_spot (THIS->here_input ());
1611 | SKIP duration_length {
1612 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1613 skip->set_property ("duration", $2);
1617 | OCTAVE { THIS->push_spot (); }
1619 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1621 $$->set_spot (THIS->pop_spot ());
1622 $$->set_property ("pitch", $3);
1625 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1626 m->set_property ("span-direction", scm_int2num (START));
1627 m->set_spot (THIS->here_input ());
1629 $$ = MY_MAKE_MUSIC ("EventChord");
1630 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1631 scm_gc_unprotect_object (m->self_scm ());
1632 $$->set_spot (THIS->here_input ());
1635 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1636 m->set_property ("span-direction", scm_int2num (STOP));
1637 m->set_spot (THIS->here_input ());
1639 $$ = MY_MAKE_MUSIC ("EventChord");
1640 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1641 $$->set_spot (THIS->here_input ());
1642 scm_gc_unprotect_object (m->self_scm ());
1645 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1646 $$->set_spot (THIS->here_input ());
1649 SCM pipe =THIS->lexer_->lookup_identifier ("pipeSymbol");
1651 if (Music * m = unsmob_music (pipe))
1654 $$ = MY_MAKE_MUSIC ("BarCheck");
1656 $$->set_spot (THIS->here_input ());
1658 | TRANSPOSITION pitch {
1660 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1661 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1662 sounds_as_c.smobbed_copy());
1663 $$->set_spot (THIS-> here_input ());
1664 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1668 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1670 Music *csm = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1672 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED, csm, SCM_EOL);
1673 $$->set_spot (THIS->here_input ());
1674 t->set_spot (THIS->here_input ());
1676 | PARTIAL duration_length {
1677 Moment m = - unsmob_duration ($2)->get_length ();
1678 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1679 p->set_spot (THIS->here_input ());
1680 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1682 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1687 SCM proc = ly_scheme_function ("make-clef-set");
1689 SCM result = scm_call_1 (proc, $2);
1690 scm_gc_protect_object (result);
1691 $$ = unsmob_music (result);
1694 SCM proc= ly_scheme_function ("make-time-signature-set");
1696 SCM result = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1697 scm_gc_protect_object (result);
1698 $$ = unsmob_music (result);
1701 SCM proc = ly_scheme_function ("make-mark-set");
1703 SCM result = scm_call_1 (proc, $2);
1704 scm_gc_protect_object (result);
1705 $$ = unsmob_music (result);
1711 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1714 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1721 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1724 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1726 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1727 if (scm_ilength ($3) > 0)
1729 key->set_property ("pitch-alist", $3);
1730 key->set_property ("tonic", Pitch (0,0,0).smobbed_copy ());
1731 ((Music*)key)->transpose (* unsmob_pitch ($2));
1733 THIS->parser_error (_ ("Second argument must be pitch list."));
1744 | post_events post_event {
1745 $2->set_spot (THIS->here_input ());
1746 $$ = scm_cons ($2->self_scm (), $$);
1747 scm_gc_unprotect_object ($2->self_scm ());
1749 | post_events tagged_post_event {
1750 $2 -> set_spot (THIS->here_input ());
1751 $$ = scm_cons ($2->self_scm (), $$);
1752 scm_gc_unprotect_object ($2->self_scm ());
1758 '-' TAG embedded_scm post_event {
1759 tag_music ($4, $3, THIS->here_input ());
1765 direction_less_event {
1769 if (!THIS->lexer_->is_lyric_state ())
1770 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1771 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1774 if (!THIS->lexer_->is_lyric_state ())
1775 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1776 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1778 | script_dir direction_reqd_event {
1780 $2->set_property ("direction", scm_int2num ($1));
1783 | script_dir direction_less_event {
1785 $2->set_property ("direction", scm_int2num ($1));
1788 | string_number_event
1791 string_number_event:
1793 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1794 s->set_property ("string-number", scm_int2num ($1));
1795 s->set_spot (THIS->here_input ());
1800 direction_less_char:
1802 $$ = ly_symbol2scm ("bracketOpenSymbol");
1805 $$ = ly_symbol2scm ("bracketCloseSymbol");
1808 $$ = ly_symbol2scm ("tildeSymbol");
1811 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1814 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1817 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1820 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1823 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1826 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1829 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1833 direction_less_event:
1834 direction_less_char {
1835 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1837 if (unsmob_music (predefd))
1839 m = unsmob_music (predefd)->clone ();
1843 m = MY_MAKE_MUSIC ("Music");
1845 m->set_spot (THIS->here_input ());
1848 | EVENT_IDENTIFIER {
1849 $$ = unsmob_music ($1);
1852 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1853 a->set_spot (THIS->here_input ());
1854 a->set_property ("tremolo-type", scm_int2num ($1));
1859 direction_reqd_event:
1863 | script_abbreviation {
1864 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1865 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1866 if (scm_is_string (s))
1867 a->set_property ("articulation-type", s);
1868 else THIS->parser_error (_ ("Expecting string as script definition"));
1874 /**/ { $$ = SCM_EOL; }
1875 | '=' { $$ = scm_int2num (0); }
1876 | '=' sub_quotes { $$ = scm_int2num ($2); }
1877 | '=' sup_quotes { $$ = scm_int2num ($2); }
1902 | NOTENAME_PITCH sup_quotes {
1903 Pitch p = *unsmob_pitch ($1);
1904 p = p.transposed (Pitch ($2,0,0));
1905 $$ = p.smobbed_copy ();
1907 | NOTENAME_PITCH sub_quotes {
1908 Pitch p =* unsmob_pitch ($1);
1909 p = p.transposed (Pitch (-$2,0,0));
1910 $$ = p.smobbed_copy ();
1922 | TONICNAME_PITCH sup_quotes {
1923 Pitch p = *unsmob_pitch ($1);
1924 p = p.transposed (Pitch ($2,0,0));
1925 $$ = p.smobbed_copy ();
1927 | TONICNAME_PITCH sub_quotes {
1928 Pitch p =* unsmob_pitch ($1);
1930 p = p.transposed (Pitch (-$2,0,0));
1931 $$ = p.smobbed_copy ();
1941 pitch_also_in_chords:
1948 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1949 t->set_property ("text", $1);
1950 t->set_spot (THIS->here_input ());
1954 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1955 t->set_property ("text",
1956 make_simple_markup (THIS->lexer_->encoding (), $1));
1957 t->set_spot (THIS->here_input ());
1962 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1963 t->set_property ("digit", scm_int2num ($1));
1964 t->set_spot (THIS->here_input ());
1969 script_abbreviation:
1971 $$ = scm_makfrom0str ("Hat");
1974 $$ = scm_makfrom0str ("Plus");
1977 $$ = scm_makfrom0str ("Dash");
1980 $$ = scm_makfrom0str ("Bar");
1983 $$ = scm_makfrom0str ("Larger");
1986 $$ = scm_makfrom0str ("Dot");
1989 $$ = scm_makfrom0str ("Underscore");
1996 | '-' { $$ = CENTER; }
2007 multiplied_duration {
2012 optional_notemode_duration:
2014 Duration dd = THIS->default_duration_;
2015 $$ = dd.smobbed_copy ();
2017 THIS->beam_check ($$);
2019 | multiplied_duration {
2021 THIS->default_duration_ = *unsmob_duration ($$);
2023 THIS->beam_check ($$);
2028 bare_unsigned dots {
2030 if (!is_duration ($1))
2031 THIS->parser_error (_f ("not a duration: %d", $1));
2035 $$ = Duration (len, $2).smobbed_copy ();
2037 | DURATION_IDENTIFIER dots {
2038 Duration *d = unsmob_duration ($1);
2039 Duration k (d->duration_log (), d->dot_count () + $2);
2045 multiplied_duration:
2049 | multiplied_duration '*' bare_unsigned {
2050 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2052 | multiplied_duration '*' FRACTION {
2053 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2055 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2060 FRACTION { $$ = $1; }
2061 | UNSIGNED '/' UNSIGNED {
2062 $$ = scm_cons (scm_int2num ($1), scm_int2num ($3));
2079 | ':' bare_unsigned {
2080 if (!is_duration ($2))
2081 THIS->parser_error (_f ("not a duration: %d", $2));
2088 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2089 $$ = scm_list_2 (ly_scheme_function ("number-markup"),
2093 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2094 $$ = scm_list_2 (ly_scheme_function ("number-markup"),
2097 | STRING { $$ = $1; }
2108 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2109 $$ = bfr->self_scm ();
2110 scm_gc_unprotect_object ($$);
2113 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2114 $$ = bfr->self_scm ();
2116 bfr->set_property ("figure", $1);
2118 scm_gc_unprotect_object ($$);
2120 | bass_figure bass_mod {
2121 Music *m = unsmob_music ($1);
2123 SCM salter = m->get_property ("alteration");
2124 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2125 m->set_property ("alteration",
2126 scm_int2num (alter + $2));
2128 m->set_property ("alteration", scm_int2num (0));
2136 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2141 | br_bass_figure ']' {
2143 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2151 | figure_list br_bass_figure {
2152 $$ = scm_cons ($2, $1);
2157 FIGURE_OPEN figure_list FIGURE_CLOSE {
2158 Music *m = MY_MAKE_MUSIC ("EventChord");
2159 $2 = scm_reverse_x ($2, SCM_EOL);
2160 m->set_property ("elements", $2);
2161 $$ = m->self_scm ();
2172 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2174 Input i = THIS->pop_spot ();
2175 if (!THIS->lexer_->is_note_state ())
2176 THIS->parser_error (_ ("Have to be in Note mode for notes"));
2180 n = MY_MAKE_MUSIC ("RestEvent");
2182 n = MY_MAKE_MUSIC ("NoteEvent");
2184 n->set_property ("pitch", $1);
2185 n->set_property ("duration", $5);
2187 if (scm_is_number ($4))
2189 int q = scm_to_int ($4);
2190 n->set_property ("absolute-octave", scm_int2num (q-1));
2194 n->set_property ("cautionary", SCM_BOOL_T);
2195 if ($2 % 2 || $3 % 2)
2196 n->set_property ("force-accidental", SCM_BOOL_T);
2198 Music *v = MY_MAKE_MUSIC ("EventChord");
2199 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2200 scm_gc_unprotect_object (n->self_scm ());
2206 | DRUM_PITCH optional_notemode_duration {
2207 Input i = THIS->pop_spot ();
2209 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2210 n->set_property ("duration", $2);
2211 n->set_property ("drum-type", $1);
2213 Music *v = MY_MAKE_MUSIC ("EventChord");
2214 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2215 scm_gc_unprotect_object (n->self_scm ());
2221 | figure_spec optional_notemode_duration {
2222 Music *m = unsmob_music ($1);
2223 Input i = THIS->pop_spot ();
2225 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2227 unsmob_music (scm_car (s))->set_property ("duration", $2);
2231 | RESTNAME optional_notemode_duration {
2233 Input i = THIS->pop_spot ();
2235 if (ly_scm2string ($1) == "s") {
2237 ev = MY_MAKE_MUSIC ("SkipEvent");
2240 ev = MY_MAKE_MUSIC ("RestEvent");
2243 ev->set_property ("duration", $2);
2245 Music *velt = MY_MAKE_MUSIC ("EventChord");
2246 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2249 scm_gc_unprotect_object (ev->self_scm ());
2253 | MULTI_MEASURE_REST optional_notemode_duration {
2256 SCM proc = ly_scheme_function ("make-multi-measure-rest");
2257 SCM mus = scm_call_2 (proc, $2,
2258 make_input (THIS->here_input ()));
2259 scm_gc_protect_object (mus);
2260 $$ = unsmob_music (mus);
2263 | lyric_element optional_notemode_duration {
2264 Input i = THIS->pop_spot ();
2265 if (!THIS->lexer_->is_lyric_state ())
2266 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
2268 Music *lreq = MY_MAKE_MUSIC ("LyricEvent");
2269 lreq->set_property ("text", $1);
2270 lreq->set_property ("duration",$2);
2272 Music *velt = MY_MAKE_MUSIC ("EventChord");
2273 velt->set_property ("elements", scm_list_1 (lreq->self_scm ()));
2280 if (!THIS->lexer_->is_chord_state ())
2281 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
2282 $$ = unsmob_music ($1);
2287 /* FIXME: lyric flavoured markup would be better */
2292 $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
2297 steno_tonic_pitch optional_notemode_duration {
2298 $$ = make_chord ($1, $2, SCM_EOL);
2300 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2301 SCM its = scm_reverse_x ($4, SCM_EOL);
2302 $$ = make_chord ($1, $2, scm_cons ($3, its));
2310 | chord_items chord_item {
2311 $$ = scm_cons ($2, $$);
2317 $$ = ly_symbol2scm ("chord-colon");
2320 $$ = ly_symbol2scm ("chord-caret");
2322 | CHORD_SLASH steno_tonic_pitch {
2323 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2325 | CHORD_BASS steno_tonic_pitch {
2326 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2335 $$ = scm_reverse_x ($1, SCM_EOL);
2343 step_number { $$ = scm_cons ($1, SCM_EOL); }
2344 | step_numbers '.' step_number {
2345 $$ = scm_cons ($3, $$);
2351 $$ = make_chord_step ($1, 0);
2353 | bare_unsigned '+' {
2354 $$ = make_chord_step ($1, SHARP);
2356 | bare_unsigned CHORD_MINUS {
2357 $$ = make_chord_step ($1, FLAT);
2364 TODO: should deprecate in favor of Scheme?
2368 number_expression '+' number_term {
2369 $$ = scm_sum ($1, $3);
2371 | number_expression '-' number_term {
2372 $$ = scm_difference ($1, $3);
2381 | number_factor '*' number_factor {
2382 $$ = scm_product ($1, $3);
2384 | number_factor '/' number_factor {
2385 $$ = scm_divide ($1, $3);
2390 '-' number_factor { /* %prec UNARY_MINUS */
2391 $$ = scm_difference ($2, SCM_UNDEFINED);
2399 $$ = scm_int2num ($1);
2404 | NUMBER_IDENTIFIER {
2407 | REAL NUMBER_IDENTIFIER {
2408 $$ = scm_make_real (scm_to_double ($1) *scm_to_double ($2));
2410 | UNSIGNED NUMBER_IDENTIFIER {
2411 $$ = scm_make_real ($1 *scm_to_double ($2));
2427 if (scm_integer_p ($1) == SCM_BOOL_T)
2429 int k = scm_to_int ($1);
2433 THIS->parser_error (_ ("need integer number arg"));
2444 | exclamations '!' { $$ ++; }
2449 | questions '?' { $$ ++; }
2459 { THIS->lexer_->push_markup_state (); }
2462 THIS->lexer_->pop_state ();
2468 This should be done more dynamically if possible.
2472 $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
2474 | MARKUP_HEAD_EMPTY {
2475 $$ = scm_list_1 ($1);
2477 | MARKUP_HEAD_MARKUP0 markup {
2478 $$ = scm_list_2 ($1, $2);
2480 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2481 $$ = scm_list_3 ($1, $2, $3);
2483 | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
2484 $$ = scm_list_3 ($1, $2, $3);
2489 | MARKUP_HEAD_LIST0 markup_list {
2490 $$ = scm_list_2 ($1,$2);
2492 | MARKUP_HEAD_SCM0 embedded_scm {
2493 $$ = scm_list_2 ($1, $2);
2495 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
2496 $$ = scm_list_4 ($1, $2, $3, $4);
2498 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2499 $$ = scm_list_4 ($1, $2, $3, $4);
2501 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2502 $$ = scm_list_3 ($1, $2, $3);
2504 | MARKUP_IDENTIFIER {
2507 | STRING_IDENTIFIER {
2511 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2512 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2513 } '{' score_body '}' {
2515 $$ = scm_list_2 (ly_scheme_function ("score-markup"), sc->self_scm ());
2516 scm_gc_unprotect_object (sc->self_scm ());
2517 THIS->lexer_->pop_state ();
2522 chord_open markup_list_body chord_close { $$ = scm_reverse_x ($2, SCM_EOL); }
2526 '{' markup_list_body '}' {
2527 SCM line = ly_scheme_function ("line-markup");
2529 $$ = scm_list_2 (line, scm_reverse_x ($2, SCM_EOL));
2534 /**/ { $$ = SCM_EOL; }
2535 | markup_list_body markup {
2536 $$ = scm_cons ($2, $1);
2544 Lily_parser::set_yydebug (bool )
2552 Lily_parser::do_yyparse ()
2554 yyparse ((void*)this);
2559 Should make this optional? It will also complain when you do
2563 which is entirely legitimate.
2565 Or we can scrap it. Barchecks should detect wrong durations, and
2566 skipTypesetting speeds it up a lot.
2570 Lily_parser::beam_check (SCM dur)
2572 Duration *d = unsmob_duration (dur);
2573 if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2575 Music *m = unsmob_music (last_beam_start_);
2576 m->origin ()->warning (_ ("Suspect duration found following this beam"));
2578 last_beam_start_ = SCM_EOL;
2586 It is a little strange to have this function in this file, but
2587 otherwise, we have to import music classes into the lexer.
2591 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2593 if (scm_is_string (sid)) {
2595 return STRING_IDENTIFIER;
2596 } else if (scm_is_number (sid)) {
2598 return NUMBER_IDENTIFIER;
2599 } else if (unsmob_context_def (sid)) {
2600 *destination = unsmob_context_def (sid)->clone_scm ();
2601 return CONTEXT_DEF_IDENTIFIER;
2602 } else if (unsmob_score (sid)) {
2603 Score *score = new Score (*unsmob_score (sid));
2604 *destination = score->self_scm ();
2605 return SCORE_IDENTIFIER;
2606 } else if (Music *mus = unsmob_music (sid)) {
2607 mus = mus->clone ();
2608 *destination = mus->self_scm ();
2609 unsmob_music (*destination)->
2610 set_property ("origin", make_input (last_input_));
2611 return dynamic_cast<Event*> (mus)
2612 ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2613 } else if (unsmob_duration (sid)) {
2614 *destination = unsmob_duration (sid)->smobbed_copy ();
2615 return DURATION_IDENTIFIER;
2616 } else if (unsmob_output_def (sid)) {
2617 Output_def *p = unsmob_output_def (sid);
2620 *destination = p->self_scm ();
2621 return OUTPUT_DEF_IDENTIFIER;
2622 } else if (Text_interface::markup_p (sid)) {
2624 return MARKUP_IDENTIFIER;
2631 property_op_to_music (SCM op)
2634 SCM tag = scm_car (op);
2635 SCM symbol = scm_cadr (op);
2636 SCM args = scm_cddr (op);
2637 SCM grob_val = SCM_UNDEFINED;
2638 SCM grob_sym = SCM_UNDEFINED;
2639 SCM val = SCM_UNDEFINED;
2641 if (tag == ly_symbol2scm ("assign"))
2643 m = MY_MAKE_MUSIC ("PropertySet");
2644 val = scm_car (args);
2646 else if (tag == ly_symbol2scm ("unset"))
2647 m = MY_MAKE_MUSIC ("PropertyUnset");
2648 else if (tag == ly_symbol2scm ("poppush")
2649 || tag == ly_symbol2scm ("push"))
2651 m = MY_MAKE_MUSIC ("OverrideProperty");
2652 grob_sym = scm_car (args);
2653 grob_val = scm_cadr (args);
2655 else if (tag == ly_symbol2scm ("pop")) {
2656 m = MY_MAKE_MUSIC ("RevertProperty");
2657 grob_sym = scm_car (args);
2660 m->set_property ("symbol", symbol);
2662 if (val != SCM_UNDEFINED)
2663 m->set_property ("value", val);
2664 if (grob_val != SCM_UNDEFINED)
2665 m->set_property ("grob-value", grob_val);
2667 if (grob_sym != SCM_UNDEFINED)
2669 bool itc = internal_type_checking_global_b;
2672 bool autobeam = ly_c_equal_p (symbol, ly_symbol2scm ("autoBeamSettings"));
2674 internal_type_checking_global_b = false;
2675 m->set_property ("grob-property", grob_sym);
2677 internal_type_checking_global_b = itc;
2680 if (tag == ly_symbol2scm ("poppush"))
2681 m->set_property ("pop-first", SCM_BOOL_T);
2688 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2690 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2692 csm->set_property ("element", m->self_scm ());
2693 scm_gc_unprotect_object (m->self_scm ());
2695 csm->set_property ("context-type",
2696 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2697 csm->set_property ("property-operations", ops);
2699 if (scm_is_string (id))
2700 csm->set_property ("context-id", id);
2705 FIXME: this should be postponed until the music hits \Score
2708 get_next_unique_context ()
2710 static int new_context_count;
2712 snprintf (s, 1024, "uniqueContext%d", new_context_count++);
2713 return scm_makfrom0str (s);