2 parser.yy -- Bison/C++ parser for LilyPond
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
12 #define YYERROR_VERBOSE 1
13 #define YYPARSE_PARAM my_lily_parser
14 #define YYLEX_PARAM my_lily_parser
16 ((Lily_parser *) my_lily_parser)
18 #define yyerror THIS->parser_error
20 /* We use custom location type: Input objects */
22 #define YYLLOC_DEFAULT(Current,Rhs,N) \
23 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
28 /* We use SCMs to do strings, because it saves us the trouble of
29 deleting them. Let's hope that a stack overflow doesnt trigger a move
30 of the parse stack onto the heap. */
38 /* One shift/reduce problem
41 \repeat .. \alternative
43 \repeat { \repeat .. \alternative }
47 \repeat { \repeat } \alternative
56 %{ // -*-Fundamental-*-
61 * The rules for who is protecting what are very shady. Uniformise
64 * There are too many lexical modes?
75 #include "context-def.hh"
76 #include "dimensions.hh"
77 #include "file-path.hh"
78 #include "input-smob.hh"
80 #include "international.hh"
81 #include "lily-guile.hh"
82 #include "lily-lexer.hh"
83 #include "lily-parser.hh"
84 #include "lilypond-input-version.hh"
89 #include "output-def.hh"
90 #include "paper-book.hh"
91 #include "program-option.hh"
92 #include "scm-hash.hh"
94 #include "text-interface.hh"
102 Output_def *outputdef;
112 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
114 Music *property_op_to_music (SCM op);
115 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops);
116 SCM get_next_unique_context_id ();
117 SCM get_next_unique_lyrics_context_id ();
124 #define _(x) gettext (x)
129 Music *make_lyric_combine_music (SCM name, Music *music);
130 Music *make_music_relative (Pitch start, Music *music);
131 Music *run_music_function (Lily_parser *, SCM expr);
132 Music *set_property_music (SCM sym, SCM value);
133 SCM get_first_context_id (SCM type, Music *m);
134 SCM make_chord (SCM pitch, SCM dur, SCM modification_list);
135 SCM make_chord_step (int step, int alter);
136 SCM make_simple_markup (SCM a);
137 bool is_duration (int t);
138 bool is_regular_identifier (SCM id);
139 bool ly_input_procedure_p (SCM x);
140 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
141 void set_music_properties (Music *p, SCM a);
145 /* The third option is an alias that will be used to display the
146 syntax error. Bison CVS now correctly handles backslash escapes.
148 FIXME: Bison needs to translate some of these, eg, STRING.
152 /* Keyword tokens with plain escaped name. */
153 %token ACCEPTS "\\accepts"
154 %token ADDLYRICS "\\addlyrics"
155 %token ADDQUOTE "\\addquote"
156 %token ALIAS "\\alias"
157 %token ALTERNATIVE "\\alternative"
159 %token CHANGE "\\change"
160 %token CHORDMODE "\\chordmode"
161 %token CHORDS "\\chords"
162 %token CONSISTS "\\consists"
163 %token CONTEXT "\\context"
164 %token DEFAULT "\\default"
165 %token DEFAULTCHILD "\\defaultchild"
166 %token DENIES "\\denies"
167 %token DESCRIPTION "\\description"
168 %token DRUMMODE "\\drummode"
169 %token DRUMS "\\drums"
170 %token FIGUREMODE "\\figuremode"
171 %token FIGURES "\\figures"
172 %token GROBDESCRIPTIONS "\\grobdescriptions"
173 %token HEADER "\\header"
174 %token INVALID "\\invalid"
176 %token LAYOUT "\\layout"
177 %token LYRICMODE "\\lyricmode"
178 %token LYRICS "\\lyrics"
179 %token LYRICSTO "\\lyricsto"
181 %token MARKUP "\\markup"
184 %token NOTEMODE "\\notemode"
185 %token OBJECTID "\\objectid"
186 %token OCTAVE "\\octave"
188 %token OVERRIDE "\\override"
189 %token PAPER "\\paper"
190 %token PARTIAL "\\partial"
191 %token RELATIVE "\\relative"
192 %token REMOVE "\\remove"
193 %token REPEAT "\\repeat"
195 %token REVERT "\\revert"
196 %token SCORE "\\score"
197 %token SEQUENTIAL "\\sequential"
199 %token SIMULTANEOUS "\\simultaneous"
201 %token TEMPO "\\tempo"
202 %token TIMES "\\times"
203 %token TRANSPOSE "\\transpose"
204 %token TRANSPOSITION "\\transposition"
206 %token UNSET "\\unset"
209 /* Keyword token exceptions. */
210 %token TIME_T "\\time"
211 %token NEWCONTEXT "\\new"
214 /* Other string tokens. */
216 %token CHORD_BASS "/+"
217 %token CHORD_CARET "^"
218 %token CHORD_COLON ":"
219 %token CHORD_MINUS "-"
220 %token CHORD_SLASH "/"
221 %token DOUBLE_ANGLE_CLOSE ">>"
222 %token DOUBLE_ANGLE_OPEN "<<"
223 %token E_BACKSLASH "\\"
224 %token E_ANGLE_CLOSE "\\>"
225 %token E_CHAR "\\C[haracter]"
227 %token E_EXCLAMATION "\\!"
228 %token E_BRACKET_OPEN "\\["
230 %token E_BRACKET_CLOSE "\\]"
231 %token E_ANGLE_OPEN "\\<"
237 If we give names, Bison complains.
239 %token FIGURE_CLOSE /* "\\>" */
240 %token FIGURE_OPEN /* "\\<" */
241 %token FIGURE_SPACE "_"
244 %token CHORDMODIFIERS
246 %token MULTI_MEASURE_REST
251 %token <i> E_UNSIGNED
254 %token <scm> BOOK_IDENTIFIER
255 %token <scm> CHORDMODIFIER_PITCH
256 %token <scm> CHORD_MODIFIER
257 %token <scm> CONTEXT_DEF_IDENTIFIER
258 %token <scm> DRUM_PITCH
259 %token <scm> DURATION_IDENTIFIER
260 %token <scm> EVENT_IDENTIFIER
261 %token <scm> FRACTION
262 %token <scm> LYRICS_STRING
263 %token <scm> LYRIC_MARKUP_IDENTIFIER
264 %token <scm> MARKUP_HEAD_EMPTY
265 %token <scm> MARKUP_HEAD_LIST0
266 %token <scm> MARKUP_HEAD_MARKUP0
267 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
268 %token <scm> MARKUP_HEAD_SCM0
269 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
270 %token <scm> MARKUP_HEAD_SCM0_SCM1
271 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
272 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
273 %token <scm> MARKUP_IDENTIFIER
274 %token <scm> MUSIC_FUNCTION
275 %token <scm> MUSIC_FUNCTION_MARKUP
276 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
277 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
278 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
279 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
280 %token <scm> MUSIC_FUNCTION_MUSIC
281 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
282 %token <scm> MUSIC_FUNCTION_SCM
283 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
284 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
285 %token <scm> MUSIC_FUNCTION_SCM_SCM
286 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
287 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM
288 %token <scm> MUSIC_IDENTIFIER
289 %token <scm> NOTENAME_PITCH
290 %token <scm> NUMBER_IDENTIFIER
291 %token <scm> OUTPUT_DEF_IDENTIFIER
293 %token <scm> RESTNAME
294 %token <scm> SCM_IDENTIFIER
296 %token <scm> SCORE_IDENTIFIER
298 %token <scm> STRING_IDENTIFIER
299 %token <scm> TONICNAME_PITCH
302 %type <book> book_block
303 %type <book> book_body
305 %type <i> bare_unsigned
306 %type <i> figured_bass_alteration
308 %type <i> exclamations
309 %type <i> optional_rest
314 %type <i> tremolo_type
316 %type <music> Composite_music
317 %type <music> Grouped_music_list
319 %type <music> Prefix_composite_music
320 %type <music> Repeated_music
321 %type <music> Sequential_music
322 %type <music> Simple_music
323 %type <music> Simultaneous_music
324 %type <music> chord_body
325 %type <music> chord_body_element
326 %type <music> command_element
327 %type <music> command_event
328 %type <music> context_change
329 %type <music> direction_less_event
330 %type <music> direction_reqd_event
331 %type <music> event_chord
332 %type <music> gen_text_def
333 %type <music> music_property_def
334 %type <music> note_chord_element
335 %type <music> post_event
336 %type <music> re_rhythmed_music
337 %type <music> relative_music
338 %type <music> simple_element
339 %type <music> string_number_event
340 %type <music> tempo_event
341 %type <music> toplevel_music
343 %type <outputdef> output_def_body
344 %type <outputdef> output_def_head
345 %type <outputdef> output_def
346 %type <outputdef> paper_block
348 %type <scm> Alternative_music
349 %type <scm> Generic_prefix_music_scm
350 %type <scm> Music_list
351 %type <scm> absolute_pitch
352 %type <scm> assignment_id
353 %type <scm> bare_number
354 %type <scm> music_function_event
355 %type <scm> music_function_chord_body
356 %type <scm> bass_figure
357 %type <scm> figured_bass_modification
358 %type <scm> br_bass_figure
359 %type <scm> bass_number
360 %type <scm> chord_body_elements
361 %type <scm> chord_item
362 %type <scm> chord_items
363 %type <scm> chord_separator
364 %type <scm> context_def_mod
365 %type <scm> context_def_spec_block
366 %type <scm> context_def_spec_body
367 %type <scm> context_mod
368 %type <scm> context_mod_list
369 %type <scm> context_prop_spec
370 %type <scm> direction_less_char
371 %type <scm> duration_length
372 %type <scm> embedded_scm
373 %type <scm> figure_list
374 %type <scm> figure_spec
376 %type <scm> full_markup
377 %type <scm> identifier_init
378 %type <scm> lilypond_header
379 %type <scm> lilypond_header_body
380 %type <scm> lyric_element
381 %type <scm> lyric_markup
383 %type <scm> markup_braced_list
384 %type <scm> markup_braced_list_body
385 %type <scm> markup_composed_list
386 %type <scm> markup_head_1_item
387 %type <scm> markup_head_1_list
388 %type <scm> markup_list
389 %type <scm> markup_top
390 %type <scm> mode_changing_head
391 %type <scm> mode_changing_head_with_context
392 %type <scm> multiplied_duration
393 %type <scm> new_chord
394 %type <scm> new_lyrics
395 %type <scm> number_expression
396 %type <scm> number_factor
397 %type <scm> number_term
398 %type <scm> object_id_setting
399 %type <scm> octave_check
400 %type <scm> optional_context_mod
401 %type <scm> optional_notemode_duration
403 %type <scm> pitch_also_in_chords
404 %type <scm> post_events
405 %type <scm> property_operation
407 %type <scm> script_abbreviation
408 %type <scm> simple_markup
409 %type <scm> simple_string
410 %type <scm> steno_duration
411 %type <scm> steno_pitch
412 %type <scm> steno_tonic_pitch
413 %type <scm> step_number
414 %type <scm> step_numbers
416 %type <scm> function_scm_argument
418 %type <score> score_block
419 %type <score> score_body
424 /* We don't assign precedence to / and *, because we might need varied
425 prec levels in different prods */
431 lilypond: /* empty */
432 | lilypond toplevel_expression {
434 | lilypond assignment {
437 THIS->error_level_ = 1;
440 THIS->error_level_ = 1;
446 OBJECTID STRING { $$ = $2; }
451 THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
458 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
459 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
465 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
466 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
471 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
472 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
476 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler");
477 scm_call_2 (proc, THIS->self_scm (), $1);
481 Output_def * od = $1;
483 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
484 id = ly_symbol2scm ("$defaultpaper");
485 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
486 id = ly_symbol2scm ("$defaultmidi");
487 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
488 id = ly_symbol2scm ("$defaultlayout");
490 THIS->lexer_->set_identifier (id, od->self_scm ());
506 lilypond_header_body:
508 $$ = get_header(THIS);
509 THIS->lexer_->add_scope ($$);
511 | lilypond_header_body assignment {
517 HEADER '{' lilypond_header_body '}' {
518 $$ = THIS->lexer_->remove_scope ();
527 | LYRICS_STRING { $$ = $1; }
531 assignment_id '=' identifier_init {
532 if (! is_regular_identifier ($1))
534 @1.warning (_ ("identifier should have alphabetic characters only"));
537 THIS->lexer_->set_identifier ($1, $3);
540 TODO: devise standard for protection in parser.
542 The parser stack lives on the C-stack, which means that
543 all objects can be unprotected as soon as they're here.
553 $$ = $1->self_scm ();
557 $$ = $1->self_scm ();
561 $$ = $1->self_scm ();
564 | context_def_spec_block {
568 $$ = $1->self_scm ();
572 $$ = $1->self_scm ();
575 | number_expression {
588 $$ = scm_from_int ($1);
592 context_def_spec_block:
593 CONTEXT '{' context_def_spec_body '}'
599 context_def_spec_body:
601 $$ = Context_def::make_scm ();
602 unsmob_context_def ($$)->set_spot (@$);
604 | CONTEXT_DEF_IDENTIFIER {
606 unsmob_context_def ($$)->set_spot (@$);
608 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
609 Context_def*td = unsmob_context_def ($$);
611 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
612 SCM tag = scm_caar (p);
614 /* TODO: should make new tag "grob-definition" ? */
615 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
616 tag, scm_cons (scm_cdar (p), SCM_EOL)));
619 | context_def_spec_body context_mod {
620 unsmob_context_def ($$)->add_context_mod ($2);
627 BOOK '{' book_body '}' {
633 * Use 'handlers' like for toplevel-* stuff?
634 * grok \layout and \midi? */
639 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
640 $$->paper_->unprotect ();
641 $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader");
644 $$ = unsmob_book ($1);
647 | book_body paper_block {
651 | book_body score_block {
652 SCM s = $2->self_scm ();
656 | book_body full_markup {
659 | book_body lilypond_header {
664 $$->scores_ = SCM_EOL;
666 | book_body object_id_setting {
667 $$->user_key_ = ly_scm2string ($2);
672 SCORE '{' score_body '}' {
679 SCM m = $1->self_scm ();
681 SCM scorify = ly_lily_module_constant ("scorify-music");
682 SCM score = scm_call_2 (scorify, m, THIS->self_scm ());
684 // pass ownernship to C++ again.
685 $$ = unsmob_score (score);
690 $$ = unsmob_score ($1);
693 | score_body object_id_setting {
694 $$->user_key_ = ly_scm2string ($2);
696 | score_body lilypond_header {
699 | score_body output_def {
700 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
702 THIS->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
707 $$->add_output_def ($2);
712 $$->error_found_ = true;
724 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
726 THIS->parser_error (@1, _ ("need \\paper for paper block"));
727 $$ = get_paper (THIS);
734 output_def_body '}' {
737 THIS->lexer_->remove_scope ();
738 THIS->lexer_->pop_state ();
744 $$ = get_paper (THIS);
745 $$->input_origin_ = @$;
746 THIS->lexer_->add_scope ($$->scope_);
749 Output_def *p = get_midi (THIS);
751 THIS->lexer_->add_scope (p->scope_);
754 Output_def *p = get_layout (THIS);
756 THIS->lexer_->add_scope (p->scope_);
763 output_def_head '{' {
765 $$->input_origin_.set_spot (@$);
766 THIS->lexer_->push_initial_state ();
768 | output_def_head '{' OUTPUT_DEF_IDENTIFIER {
770 Output_def *o = unsmob_output_def ($3);
771 o->input_origin_.set_spot (@$);
773 THIS->lexer_->remove_scope ();
774 THIS->lexer_->add_scope (o->scope_);
775 THIS->lexer_->push_initial_state ();
777 | output_def_body assignment {
780 | output_def_body context_def_spec_block {
781 assign_context_def ($$, $2);
783 | output_def_body tempo_event {
785 junk this ? there already is tempo stuff in
788 int m = scm_to_int ($2->get_property ("metronome-count"));
789 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
790 set_tempo ($$, d->get_length (), m);
793 | output_def_body error {
799 TEMPO steno_duration '=' bare_unsigned {
800 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
801 $$->set_property ("tempo-unit", $2);
802 $$->set_property ("metronome-count", scm_from_int ( $4));
807 The representation of a list is the
811 to have efficient append. */
815 $$ = scm_cons (SCM_EOL, SCM_EOL);
819 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
820 $2->unprotect (); /* UGH */
822 if (scm_is_pair (scm_cdr (s)))
823 scm_set_cdr_x (scm_cdr (s), c); /* append */
825 scm_set_car_x (s, c); /* set first cons */
826 scm_set_cdr_x (s, c); /* remember last cell */
828 | Music_list embedded_scm {
832 Music * m = MY_MAKE_MUSIC("Music");
834 m->set_property ("error-found", SCM_BOOL_T);
836 SCM c = scm_cons (m->self_scm (), SCM_EOL);
837 m->unprotect (); /* UGH */
839 if (scm_is_pair (scm_cdr (s)))
840 scm_set_cdr_x (scm_cdr (s), c); /* append */
842 scm_set_car_x (s, c); /* set first cons */
843 scm_set_cdr_x (s, c); /* remember last cell */
856 | ALTERNATIVE '{' Music_list '}' {
863 REPEAT simple_string bare_unsigned Music Alternative_music
867 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
868 if (times < scm_ilength (alts)) {
869 unsmob_music (scm_car (alts))
870 ->origin ()->warning (
871 _ ("more alternatives than repeats"));
872 warning ("junking excess alternatives");
873 alts = ly_truncate_list (times, alts);
877 SCM proc = ly_lily_module_constant ("make-repeated-music");
879 SCM mus = scm_call_1 (proc, $2);
880 Music *r = unsmob_music (mus);
884 r-> set_property ("element", beg->self_scm ());
887 r->set_property ("repeat-count", scm_from_int (max (times, 1)));
889 r-> set_property ("elements",alts);
890 if (ly_is_equal ($2, scm_makfrom0str ("tremolo"))) {
892 TODO: move this code to Scheme.
895 /* we cannot get durations and other stuff
896 correct down the line,
897 so we have to add to the duration log here. */
898 SCM func = ly_lily_module_constant ("shift-duration-log");
900 int dots = ($3 % 3) ? 0 : 1;
901 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
904 if ($4->is_mus_type ("sequential-music"))
906 int list_len = scm_ilength ($4->get_property ("elements"));
908 $4->origin ()->warning (_f ("expect 2 elements for Chord tremolo, found %d", list_len));
910 r->compress (Moment (Rational (1, list_len)));
912 scm_call_3 (func, r->self_scm (), scm_from_int (shift), scm_from_int (dots));
915 r->set_spot (*$4->origin ());
922 SEQUENTIAL '{' Music_list '}' {
923 $$ = MY_MAKE_MUSIC ("SequentialMusic");
924 $$->set_property ("elements", scm_car ($3));
927 | '{' Music_list '}' {
928 $$ = MY_MAKE_MUSIC ("SequentialMusic");
929 $$->set_property ("elements", scm_car ($2));
935 SIMULTANEOUS '{' Music_list '}'{
936 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
937 $$->set_property ("elements", scm_car ($3));
941 | simul_open Music_list simul_close {
942 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
943 $$->set_property ("elements", scm_car ($2));
949 event_chord { $$ = $1; }
951 $$ = unsmob_music ($1);
958 optional_context_mod:
959 /**/ { $$ = SCM_EOL; }
960 | WITH { THIS->lexer_->push_initial_state (); }
961 '{' context_mod_list '}'
963 THIS->lexer_->pop_state ();
969 /* */ { $$ = SCM_EOL; }
970 | context_mod_list context_mod {
971 $$ = scm_cons ($2, $1);
977 Prefix_composite_music { $$ = $1; }
978 | Grouped_music_list { $$ = $1; }
982 Simultaneous_music { $$ = $1; }
983 | Sequential_music { $$ = $1; }
987 function_scm_argument:
992 Generic_prefix_music_scm:
994 $$ = scm_list_2 ($1, make_input (@$));
996 | MUSIC_FUNCTION_SCM function_scm_argument {
997 $$ = scm_list_3 ($1, make_input (@$), $2);
999 | MUSIC_FUNCTION_MARKUP full_markup {
1000 $$ = scm_list_3 ($1, make_input (@$), $2);
1003 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument Music {
1004 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1007 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
1008 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1010 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
1011 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1013 | MUSIC_FUNCTION_MUSIC Music {
1014 $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
1017 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument Music {
1018 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
1020 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
1021 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1024 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
1025 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1027 | MUSIC_FUNCTION_MUSIC_MUSIC Music Music {
1028 $$ = scm_list_4 ($1, make_input (@$), $2->self_scm (), $3->self_scm ());
1032 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument Music Music {
1033 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1037 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup Music Music {
1038 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1044 Prefix_composite_music:
1045 Generic_prefix_music_scm {
1046 $$ = run_music_function (THIS, $1);
1048 | CONTEXT simple_string '=' simple_string optional_context_mod Music {
1049 $$ = context_spec_music ($2, $4, $6, $5);
1052 | CONTEXT simple_string optional_context_mod Music {
1053 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1055 | NEWCONTEXT simple_string optional_context_mod Music {
1056 $$ = context_spec_music ($2, get_next_unique_context_id (), $4,
1060 | TIMES fraction Music
1063 int n = scm_to_int (scm_car ($2)); int d = scm_to_int (scm_cdr ($2));
1066 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1069 $$->set_property ("element", mp->self_scm ());
1071 $$->set_property ("numerator", scm_from_int (n));
1072 $$->set_property ("denominator", scm_from_int (d));
1073 $$->compress (Moment (Rational (n,d)));
1076 | Repeated_music { $$ = $1; }
1077 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1078 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1080 Pitch from = *unsmob_pitch ($2);
1081 Pitch to = *unsmob_pitch ($3);
1083 p->transpose (pitch_interval (from, to));
1084 $$->set_property ("element", p->self_scm ());
1087 | mode_changing_head Grouped_music_list {
1088 if ($1 == ly_symbol2scm ("chords"))
1090 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1091 chm->set_property ("element", $2->self_scm ());
1099 THIS->lexer_->pop_state ();
1101 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1102 $$ = context_spec_music ($1, get_next_unique_context_id (),
1104 if ($1 == ly_symbol2scm ("ChordNames"))
1106 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1107 chm->set_property ("element", $$->self_scm ());
1111 THIS->lexer_->pop_state ();
1113 | relative_music { $$ = $1; }
1114 | re_rhythmed_music { $$ = $1; }
1119 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1120 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1122 $$ = ly_symbol2scm ("notes");
1126 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1127 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1129 $$ = ly_symbol2scm ("drums");
1132 THIS->lexer_->push_figuredbass_state ();
1134 $$ = ly_symbol2scm ("figures");
1137 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1138 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1139 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1140 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1141 $$ = ly_symbol2scm ("chords");
1145 { THIS->lexer_->push_lyric_state ();
1146 $$ = ly_symbol2scm ("lyrics");
1150 mode_changing_head_with_context:
1152 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1153 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1155 $$ = ly_symbol2scm ("DrumStaff");
1158 THIS->lexer_->push_figuredbass_state ();
1160 $$ = ly_symbol2scm ("FiguredBass");
1163 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1164 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1165 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1166 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1167 $$ = ly_symbol2scm ("ChordNames");
1170 { THIS->lexer_->push_lyric_state ();
1171 $$ = ly_symbol2scm ("Lyrics");
1177 RELATIVE absolute_pitch Music {
1179 Pitch start = *unsmob_pitch ($2);
1180 $$ = make_music_relative (start, m);
1183 | RELATIVE Composite_music {
1186 Pitch middle_c (0, 0, 0);
1187 $$ = make_music_relative (middle_c, m);
1193 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1195 Grouped_music_list {
1196 /* Can also use Music at the expensive of two S/Rs similar to
1197 \repeat \alternative */
1198 THIS->lexer_->pop_state ();
1200 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1202 | new_lyrics ADDLYRICS {
1203 THIS->lexer_->push_lyric_state ();
1204 } Grouped_music_list {
1205 THIS->lexer_->pop_state ();
1206 $$ = scm_cons ($4->self_scm (), $1);
1211 Grouped_music_list new_lyrics {
1213 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice);
1214 if (!scm_is_string (name))
1216 name = get_next_unique_lyrics_context_id ();
1217 voice = context_spec_music (scm_makfrom0str ("Voice"),
1222 SCM context = scm_makfrom0str ("Lyrics");
1223 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1226 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1228 Music *music = unsmob_music (scm_car (s));
1229 Music *com = make_lyric_combine_music (name, music);
1230 Music *csm = context_spec_music (context,
1231 get_next_unique_context_id (), com, SCM_EOL);
1232 lst = scm_cons (csm->self_scm (), lst);
1234 all->set_property ("elements", scm_cons (voice->self_scm (),
1237 voice->unprotect ();
1239 | LYRICSTO simple_string {
1240 THIS->lexer_->push_lyric_state ();
1242 THIS->lexer_->pop_state ();
1245 $$ = make_lyric_combine_music (name, music);
1251 CHANGE STRING '=' STRING {
1252 Music*t = MY_MAKE_MUSIC ("ContextChange");
1253 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1254 t-> set_property ("change-to-id", $4);
1263 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1264 scm_string_to_symbol ($1), $3);
1266 | UNSET simple_string {
1267 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1268 scm_string_to_symbol ($2));
1270 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1271 $$ = scm_list_4 (ly_symbol2scm ("push"),
1272 scm_string_to_symbol ($2), $5, $3);
1274 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1275 $$ = scm_list_5 (ly_symbol2scm ("push"),
1276 scm_string_to_symbol ($2), $6, $4, $3);
1278 | REVERT simple_string embedded_scm {
1279 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1280 scm_string_to_symbol ($2), $3);
1285 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1286 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1288 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1289 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1290 | DENIES { $$ = ly_symbol2scm ("denies"); }
1292 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1293 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1294 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1295 | NAME { $$ = ly_symbol2scm ("context-name"); }
1299 property_operation { $$ = $1; }
1300 | context_def_mod STRING {
1301 $$ = scm_list_2 ($1, $2);
1307 if (!is_regular_identifier ($1))
1309 @$.error (_("Grob name should be alphanumeric"));
1312 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1313 scm_string_to_symbol ($1));
1315 | simple_string '.' simple_string {
1316 $$ = scm_list_2 (scm_string_to_symbol ($1),
1317 scm_string_to_symbol ($3));
1322 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1323 $$ = property_op_to_music (scm_list_4 (
1324 ly_symbol2scm ("push"),
1327 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1329 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1330 $$ = property_op_to_music (scm_list_5 (
1331 ly_symbol2scm ("push"),
1334 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1336 | REVERT context_prop_spec embedded_scm {
1337 $$ = property_op_to_music (scm_list_3 (
1338 ly_symbol2scm ("pop"),
1342 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1344 | SET context_prop_spec '=' scalar {
1345 $$ = property_op_to_music (scm_list_3 (
1346 ly_symbol2scm ("assign"),
1349 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1351 | UNSET context_prop_spec {
1352 $$ = property_op_to_music (scm_list_2 (
1353 ly_symbol2scm ("unset"),
1355 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1357 | ONCE music_property_def {
1358 SCM e = $2->get_property ("element");
1359 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1370 | STRING_IDENTIFIER {
1373 | string '+' string {
1374 $$ = scm_string_append (scm_list_2 ($1, $3));
1378 simple_string: STRING {
1384 | STRING_IDENTIFIER {
1405 $$ = scm_from_int ($1);
1411 pre_events doesn't contain anything. It is a trick:
1413 Adding pre_events to the simple_element
1414 makes the choice between
1420 simple_element: STRING
1422 a single shift/reduction conflict.
1424 nevertheless, this is not very clean, and we should find a different
1428 pre_events: /* empty */
1432 pre_events simple_element post_events {
1433 SCM elts = $2-> get_property ("elements");
1435 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1437 $2->set_property ("elements", elts);
1438 /* why is this giving wrong start location? -ns
1439 * $2->set_spot (@$); */
1441 i.set_location (@2, @3);
1446 | note_chord_element
1451 chord_body optional_notemode_duration post_events
1453 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1454 SCM es = $1->get_property ("elements");
1455 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1457 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1458 unsmob_music (scm_car (s))->set_property ("duration", dur);
1459 es = ly_append2 (es, postevs);
1461 $1-> set_property ("elements", es);
1473 simul_open: DOUBLE_ANGLE_OPEN
1476 simul_close: DOUBLE_ANGLE_CLOSE
1480 chord_open chord_body_elements chord_close
1482 $$ = MY_MAKE_MUSIC ("EventChord");
1484 $$->set_property ("elements",
1485 scm_reverse_x ($2, SCM_EOL));
1489 chord_body_elements:
1490 /* empty */ { $$ = SCM_EOL; }
1491 | chord_body_elements chord_body_element {
1492 $$ = scm_cons ($2->self_scm (), $1);
1498 pitch exclamations questions octave_check post_events
1505 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1506 n->set_property ("pitch", $1);
1509 n->set_property ("cautionary", SCM_BOOL_T);
1510 if (ex % 2 || q % 2)
1511 n->set_property ("force-accidental", SCM_BOOL_T);
1513 if (scm_is_pair (post)) {
1514 SCM arts = scm_reverse_x (post, SCM_EOL);
1515 n->set_property ("articulations", arts);
1517 if (scm_is_number (check))
1519 int q = scm_to_int (check);
1520 n->set_property ("absolute-octave", scm_from_int (q-1));
1526 | DRUM_PITCH post_events {
1527 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1528 n->set_property ("duration", $2);
1529 n->set_property ("drum-type", $1);
1532 if (scm_is_pair ($2)) {
1533 SCM arts = scm_reverse_x ($2, SCM_EOL);
1534 n->set_property ("articulations", arts);
1538 | music_function_chord_body {
1539 $$ = run_music_function (THIS, $1);
1544 music_function_chord_body:
1546 $$ = scm_list_2 ($1, make_input (@$));
1548 | MUSIC_FUNCTION_MUSIC chord_body_element {
1549 $$ = scm_list_3 ($1, make_input (@$),
1552 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument chord_body_element {
1553 $$ = scm_list_4 ($1, make_input (@$),
1554 $2, $3->self_scm ());
1556 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument
1557 chord_body_element {
1559 $$ = scm_list_5 ($1, make_input (@$),
1560 $2, $3, $4->self_scm ());
1566 ADDQUOTE string Music {
1567 SCM adder = ly_lily_module_constant ("add-quotable");
1569 scm_call_2 (adder, $2, $3->self_scm ());
1576 $$ = MY_MAKE_MUSIC ("EventChord");
1577 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1583 | SKIP duration_length {
1584 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1585 skip->set_property ("duration", $2);
1586 skip->set_spot (@$);
1590 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1593 $$->set_property ("pitch", $2);
1596 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1597 m->set_property ("span-direction", scm_from_int (START));
1600 $$ = MY_MAKE_MUSIC ("EventChord");
1601 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1606 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1607 m->set_property ("span-direction", scm_from_int (STOP));
1610 $$ = MY_MAKE_MUSIC ("EventChord");
1611 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1616 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1620 SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
1622 if (Music * m = unsmob_music (pipe))
1625 $$ = MY_MAKE_MUSIC ("BarCheck");
1629 | TRANSPOSITION pitch {
1631 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1632 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1633 sounds_as_c.smobbed_copy());
1635 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1638 | PARTIAL duration_length {
1639 Moment m = - unsmob_duration ($2)->get_length ();
1640 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1642 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1644 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1650 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1652 SCM result = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1653 $$ = unsmob_music (result);
1657 SCM proc = ly_lily_module_constant ("make-mark-set");
1659 SCM result = scm_call_1 (proc, $2);
1660 $$ = unsmob_music (result);
1667 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1670 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1677 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1680 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1682 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1683 if (scm_ilength ($3) > 0)
1685 key->set_property ("pitch-alist", $3);
1686 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1687 key->transpose (* unsmob_pitch ($2));
1689 THIS->parser_error (@3, _ ("second argument must be pitch list"));
1701 | post_events post_event {
1703 $$ = scm_cons ($2->self_scm (), $$);
1708 music_function_event:
1709 MUSIC_FUNCTION_MUSIC post_event {
1710 $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
1712 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument post_event {
1713 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1715 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument post_event {
1716 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
1722 direction_less_event {
1725 | '-' music_function_event {
1726 Music *mus = run_music_function (THIS, $2);
1731 if (!THIS->lexer_->is_lyric_state ())
1732 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1733 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1736 if (!THIS->lexer_->is_lyric_state ())
1737 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1738 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1740 | script_dir direction_reqd_event {
1742 $2->set_property ("direction", scm_from_int ($1));
1745 | script_dir direction_less_event {
1747 $2->set_property ("direction", scm_from_int ($1));
1750 | string_number_event
1753 string_number_event:
1755 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1756 s->set_property ("string-number", scm_from_int ($1));
1762 direction_less_char:
1764 $$ = ly_symbol2scm ("bracketOpenSymbol");
1767 $$ = ly_symbol2scm ("bracketCloseSymbol");
1770 $$ = ly_symbol2scm ("tildeSymbol");
1773 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1776 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1779 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1782 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1785 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1788 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1791 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1795 direction_less_event:
1796 direction_less_char {
1797 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1799 if (unsmob_music (predefd))
1801 m = unsmob_music (predefd)->clone ();
1805 m = MY_MAKE_MUSIC ("Music");
1810 | EVENT_IDENTIFIER {
1811 $$ = unsmob_music ($1);
1814 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1816 a->set_property ("tremolo-type", scm_from_int ($1));
1821 direction_reqd_event:
1825 | script_abbreviation {
1826 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1827 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1828 if (scm_is_string (s))
1829 a->set_property ("articulation-type", s);
1830 else THIS->parser_error (@1, _ ("expecting string as script definition"));
1836 /**/ { $$ = SCM_EOL; }
1837 | '=' { $$ = scm_from_int (0); }
1838 | '=' sub_quotes { $$ = scm_from_int ($2); }
1839 | '=' sup_quotes { $$ = scm_from_int ($2); }
1864 | NOTENAME_PITCH sup_quotes {
1865 Pitch p = *unsmob_pitch ($1);
1866 p = p.transposed (Pitch ($2,0,0));
1867 $$ = p.smobbed_copy ();
1869 | NOTENAME_PITCH sub_quotes {
1870 Pitch p =* unsmob_pitch ($1);
1871 p = p.transposed (Pitch (-$2,0,0));
1872 $$ = p.smobbed_copy ();
1884 | TONICNAME_PITCH sup_quotes {
1885 Pitch p = *unsmob_pitch ($1);
1886 p = p.transposed (Pitch ($2,0,0));
1887 $$ = p.smobbed_copy ();
1889 | TONICNAME_PITCH sub_quotes {
1890 Pitch p =* unsmob_pitch ($1);
1892 p = p.transposed (Pitch (-$2,0,0));
1893 $$ = p.smobbed_copy ();
1903 pitch_also_in_chords:
1910 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1911 t->set_property ("text", $1);
1916 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1917 t->set_property ("text",
1918 make_simple_markup ($1));
1924 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1925 t->set_property ("digit", scm_from_int ($1));
1931 script_abbreviation:
1933 $$ = scm_makfrom0str ("Hat");
1936 $$ = scm_makfrom0str ("Plus");
1939 $$ = scm_makfrom0str ("Dash");
1942 $$ = scm_makfrom0str ("Bar");
1945 $$ = scm_makfrom0str ("Larger");
1948 $$ = scm_makfrom0str ("Dot");
1951 $$ = scm_makfrom0str ("Underscore");
1958 | '-' { $$ = CENTER; }
1969 multiplied_duration {
1974 optional_notemode_duration:
1976 Duration dd = THIS->default_duration_;
1977 $$ = dd.smobbed_copy ();
1979 | multiplied_duration {
1981 THIS->default_duration_ = *unsmob_duration ($$);
1986 bare_unsigned dots {
1988 if (!is_duration ($1))
1989 THIS->parser_error (@1, _f ("not a duration: %d", $1));
1993 $$ = Duration (len, $2).smobbed_copy ();
1995 | DURATION_IDENTIFIER dots {
1996 Duration *d = unsmob_duration ($1);
1997 Duration k (d->duration_log (), d->dot_count () + $2);
2003 multiplied_duration:
2007 | multiplied_duration '*' bare_unsigned {
2008 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2010 | multiplied_duration '*' FRACTION {
2011 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2013 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2018 FRACTION { $$ = $1; }
2019 | UNSIGNED '/' UNSIGNED {
2020 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2037 | ':' bare_unsigned {
2038 if (!is_duration ($2))
2039 THIS->parser_error (@2, _f ("not a duration: %d", $2));
2046 $$ = scm_from_int ($1);
2049 $$ = scm_from_int ($1);
2051 | STRING { $$ = $1; }
2052 | full_markup { $$ = $1; }
2055 figured_bass_alteration:
2063 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2064 $$ = bfr->self_scm ();
2069 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2070 $$ = bfr->self_scm ();
2072 if (scm_is_number ($1))
2073 bfr->set_property ("figure", $1);
2074 else if (Text_interface::is_markup ($1))
2075 bfr->set_property ("text", $1);
2082 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2084 | bass_figure figured_bass_alteration {
2085 Music *m = unsmob_music ($1);
2087 SCM salter = m->get_property ("alteration");
2088 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2089 m->set_property ("alteration",
2090 scm_from_int (alter + $2));
2092 m->set_property ("alteration", scm_from_int (0));
2095 | bass_figure figured_bass_modification {
2096 Music *m = unsmob_music ($1);
2097 if ($2 == ly_symbol2scm ("plus"))
2099 m->set_property ("augmented", SCM_BOOL_T);
2101 else if ($2 == ly_symbol2scm ("slash"))
2103 m->set_property ("diminished", SCM_BOOL_T);
2105 else if ($2 == ly_symbol2scm ("exclamation"))
2107 m->set_property ("no-continuation", SCM_BOOL_T);
2113 figured_bass_modification:
2115 $$ = ly_symbol2scm ("plus");
2118 $$ = ly_symbol2scm ("exclamation");
2121 $$ = ly_symbol2scm ("slash");
2131 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2139 | figure_list br_bass_figure {
2140 $$ = scm_cons ($2, $1);
2145 FIGURE_OPEN figure_list FIGURE_CLOSE {
2146 Music *m = MY_MAKE_MUSIC ("EventChord");
2147 $2 = scm_reverse_x ($2, SCM_EOL);
2148 m->set_property ("elements", $2);
2149 $$ = m->self_scm ();
2160 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2161 if (!THIS->lexer_->is_note_state ())
2162 THIS->parser_error (@1, _ ("have to be in Note mode for notes"));
2166 n = MY_MAKE_MUSIC ("RestEvent");
2168 n = MY_MAKE_MUSIC ("NoteEvent");
2170 n->set_property ("pitch", $1);
2171 n->set_property ("duration", $5);
2173 if (scm_is_number ($4))
2175 int q = scm_to_int ($4);
2176 n->set_property ("absolute-octave", scm_from_int (q-1));
2180 n->set_property ("cautionary", SCM_BOOL_T);
2181 if ($2 % 2 || $3 % 2)
2182 n->set_property ("force-accidental", SCM_BOOL_T);
2184 Music *v = MY_MAKE_MUSIC ("EventChord");
2185 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2192 | DRUM_PITCH optional_notemode_duration {
2193 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2194 n->set_property ("duration", $2);
2195 n->set_property ("drum-type", $1);
2197 Music *v = MY_MAKE_MUSIC ("EventChord");
2198 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2205 | figure_spec optional_notemode_duration {
2206 Music *m = unsmob_music ($1);
2208 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2210 unsmob_music (scm_car (s))->set_property ("duration", $2);
2214 | RESTNAME optional_notemode_duration {
2216 if (ly_scm2string ($1) == "s") {
2218 ev = MY_MAKE_MUSIC ("SkipEvent");
2221 ev = MY_MAKE_MUSIC ("RestEvent");
2224 ev->set_property ("duration", $2);
2226 Music *velt = MY_MAKE_MUSIC ("EventChord");
2227 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2228 velt->set_spot (@$);
2234 | MULTI_MEASURE_REST optional_notemode_duration {
2235 SCM proc = ly_lily_module_constant ("make-multi-measure-rest");
2236 SCM mus = scm_call_2 (proc, $2, make_input (@$));
2237 $$ = unsmob_music (mus);
2241 | lyric_element optional_notemode_duration {
2242 if (!THIS->lexer_->is_lyric_state ())
2243 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2245 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2246 levent->set_property ("text", $1);
2247 levent->set_property ("duration",$2);
2248 levent->set_spot (@$);
2249 Music *velt = MY_MAKE_MUSIC ("EventChord");
2250 velt->set_property ("elements", scm_list_1 (levent->self_scm ()));
2255 if (!THIS->lexer_->is_chord_state ())
2256 THIS->parser_error (@1, _ ("have to be in Chord mode for chords"));
2257 $$ = unsmob_music ($1);
2271 steno_tonic_pitch optional_notemode_duration {
2272 $$ = make_chord ($1, $2, SCM_EOL);
2274 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2275 SCM its = scm_reverse_x ($4, SCM_EOL);
2276 $$ = make_chord ($1, $2, scm_cons ($3, its));
2284 | chord_items chord_item {
2285 $$ = scm_cons ($2, $$);
2291 $$ = ly_symbol2scm ("chord-colon");
2294 $$ = ly_symbol2scm ("chord-caret");
2296 | CHORD_SLASH steno_tonic_pitch {
2297 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2299 | CHORD_BASS steno_tonic_pitch {
2300 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2309 $$ = scm_reverse_x ($1, SCM_EOL);
2317 step_number { $$ = scm_cons ($1, SCM_EOL); }
2318 | step_numbers '.' step_number {
2319 $$ = scm_cons ($3, $$);
2325 $$ = make_chord_step ($1, 0);
2327 | bare_unsigned '+' {
2328 $$ = make_chord_step ($1, SHARP);
2330 | bare_unsigned CHORD_MINUS {
2331 $$ = make_chord_step ($1, FLAT);
2338 TODO: should deprecate in favor of Scheme?
2342 number_expression '+' number_term {
2343 $$ = scm_sum ($1, $3);
2345 | number_expression '-' number_term {
2346 $$ = scm_difference ($1, $3);
2355 | number_factor '*' number_factor {
2356 $$ = scm_product ($1, $3);
2358 | number_factor '/' number_factor {
2359 $$ = scm_divide ($1, $3);
2364 '-' number_factor { /* %prec UNARY_MINUS */
2365 $$ = scm_difference ($2, SCM_UNDEFINED);
2373 $$ = scm_from_int ($1);
2378 | NUMBER_IDENTIFIER {
2381 | REAL NUMBER_IDENTIFIER {
2382 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2384 | UNSIGNED NUMBER_IDENTIFIER {
2385 $$ = scm_from_double ($1 *scm_to_double ($2));
2401 | exclamations '!' { $$ ++; }
2406 | questions '?' { $$ ++; }
2410 This should be done more dynamically if possible.
2414 LYRIC_MARKUP_IDENTIFIER {
2418 { THIS->lexer_->push_markup_state (); }
2421 THIS->lexer_->pop_state ();
2430 { THIS->lexer_->push_markup_state (); }
2433 THIS->lexer_->pop_state ();
2439 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2441 | markup_head_1_list simple_markup {
2442 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2450 markup_composed_list {
2453 | markup_braced_list {
2458 markup_composed_list:
2459 markup_head_1_list markup_braced_list {
2460 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2466 '{' markup_braced_list_body '}' {
2467 $$ = scm_reverse_x ($2, SCM_EOL);
2471 markup_braced_list_body:
2472 /* empty */ { $$ = SCM_EOL; }
2473 | markup_braced_list_body markup {
2474 $$ = scm_cons ($2, $1);
2476 | markup_braced_list_body markup_list {
2477 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2482 MARKUP_HEAD_MARKUP0 {
2483 $$ = scm_list_1 ($1);
2485 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2486 $$ = scm_list_2 ($1, $2);
2488 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2489 $$ = scm_list_3 ($1, $2, $3);
2494 markup_head_1_item {
2495 $$ = scm_list_1 ($1);
2497 | markup_head_1_list markup_head_1_item {
2498 $$ = scm_cons ($2, $1);
2504 $$ = make_simple_markup ($1);
2506 | MARKUP_IDENTIFIER {
2509 | LYRIC_MARKUP_IDENTIFIER {
2512 | STRING_IDENTIFIER {
2516 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2517 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2518 } '{' score_body '}' {
2520 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2522 THIS->lexer_->pop_state ();
2524 | MARKUP_HEAD_SCM0 embedded_scm {
2525 $$ = scm_list_2 ($1, $2);
2527 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2528 $$ = scm_list_4 ($1, $2, $3, $4);
2530 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2531 $$ = scm_list_3 ($1, $2, $3);
2533 | MARKUP_HEAD_EMPTY {
2534 $$ = scm_list_1 ($1);
2536 | MARKUP_HEAD_LIST0 markup_list {
2537 $$ = scm_list_2 ($1,$2);
2539 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2540 $$ = scm_list_3 ($1, $2, $3);
2545 markup_head_1_list simple_markup {
2546 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2547 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2557 Lily_parser::set_yydebug (bool )
2565 Lily_parser::do_yyparse ()
2567 yyparse ((void*)this);
2576 It is a little strange to have this function in this file, but
2577 otherwise, we have to import music classes into the lexer.
2581 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2583 if (scm_is_string (sid)) {
2585 return STRING_IDENTIFIER;
2586 } else if (unsmob_book (sid)) {
2587 *destination = unsmob_book (sid)->clone ()->self_scm ();
2588 return BOOK_IDENTIFIER;
2589 } else if (scm_is_number (sid)) {
2591 return NUMBER_IDENTIFIER;
2592 } else if (unsmob_context_def (sid)) {
2593 *destination = unsmob_context_def (sid)->clone_scm ();
2594 return CONTEXT_DEF_IDENTIFIER;
2595 } else if (unsmob_score (sid)) {
2596 Score *score = new Score (*unsmob_score (sid));
2597 *destination = score->self_scm ();
2598 return SCORE_IDENTIFIER;
2599 } else if (Music *mus = unsmob_music (sid)) {
2600 mus = mus->clone ();
2601 *destination = mus->self_scm ();
2602 unsmob_music (*destination)->
2603 set_property ("origin", make_input (last_input_));
2605 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2608 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2609 } else if (unsmob_duration (sid)) {
2610 *destination = unsmob_duration (sid)->smobbed_copy ();
2611 return DURATION_IDENTIFIER;
2612 } else if (unsmob_output_def (sid)) {
2613 Output_def *p = unsmob_output_def (sid);
2616 *destination = p->self_scm ();
2617 return OUTPUT_DEF_IDENTIFIER;
2618 } else if (Text_interface::is_markup (sid)) {
2620 if (is_lyric_state ())
2621 return LYRIC_MARKUP_IDENTIFIER;
2622 return MARKUP_IDENTIFIER;
2629 property_op_to_music (SCM op)
2632 SCM tag = scm_car (op);
2633 SCM symbol = scm_cadr (op);
2634 SCM args = scm_cddr (op);
2635 SCM grob_val = SCM_UNDEFINED;
2636 SCM grob_path = SCM_UNDEFINED;
2637 SCM val = SCM_UNDEFINED;
2639 if (tag == ly_symbol2scm ("assign"))
2641 m = MY_MAKE_MUSIC ("PropertySet");
2642 val = scm_car (args);
2644 else if (tag == ly_symbol2scm ("unset"))
2645 m = MY_MAKE_MUSIC ("PropertyUnset");
2646 else if (tag == ly_symbol2scm ("push"))
2648 m = MY_MAKE_MUSIC ("OverrideProperty");
2649 grob_val = scm_car (args);
2650 grob_path = scm_cdr (args);
2651 m->set_property ("pop-first", SCM_BOOL_T);
2653 else if (tag == ly_symbol2scm ("pop")) {
2654 m = MY_MAKE_MUSIC ("RevertProperty");
2658 m->set_property ("symbol", symbol);
2660 if (val != SCM_UNDEFINED)
2661 m->set_property ("value", val);
2662 if (grob_val != SCM_UNDEFINED)
2663 m->set_property ("grob-value", grob_val);
2664 if (grob_path != SCM_UNDEFINED)
2665 m->set_property ("grob-property-path", grob_path);
2671 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2673 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2675 csm->set_property ("element", m->self_scm ());
2678 csm->set_property ("context-type",
2679 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2680 csm->set_property ("property-operations", ops);
2682 if (scm_is_string (id))
2683 csm->set_property ("context-id", id);
2688 get_next_unique_context_id ()
2690 return scm_makfrom0str ("$uniqueContextId");
2695 get_next_unique_lyrics_context_id ()
2697 static int new_context_count;
2699 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2700 return scm_makfrom0str (s);
2705 run_music_function (Lily_parser *parser, SCM expr)
2707 SCM func = scm_car (expr);
2708 Input *loc = unsmob_input (scm_cadr (expr));
2709 SCM args = scm_cddr (expr);
2710 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2712 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2715 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2717 parser->error_level_ = 1;
2723 m = scm_apply_0 (func, scm_cons (parser->self_scm(),
2728 if (unsmob_music (m))
2730 retval = unsmob_music (m);
2736 loc->error (_ ("music head function must return Music object"));
2737 retval = MY_MAKE_MUSIC ("Music");
2739 retval->set_spot (*loc);
2744 is_regular_identifier (SCM id)
2746 std::string str = ly_scm2string (id);
2747 char const *s = str.c_str ();
2756 v = v && isalnum (*s);
2764 get_first_context_id (SCM type, Music *m)
2766 SCM id = m->get_property ("context-id");
2767 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2768 && scm_is_string (m->get_property ("context-id"))
2769 && scm_c_string_length (id) > 0)
2777 make_simple_markup (SCM a)
2785 return t && t == 1 << intlog2 (t);
2789 set_music_properties (Music *p, SCM a)
2791 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2792 p->internal_set_property (scm_caar (k), scm_cdar (k));
2797 make_chord_step (int step, int alter)
2804 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2805 return m.smobbed_copy ();
2810 make_chord (SCM pitch, SCM dur, SCM modification_list)
2812 SCM chord_ctor = ly_lily_module_constant ("construct-chord");
2813 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
2815 unsmob_music (ch)->protect();
2820 /* Todo: actually also use apply iso. call too ... */
2822 ly_input_procedure_p (SCM x)
2824 return ly_is_procedure (x)
2825 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2829 set_property_music (SCM sym, SCM value)
2831 Music *p = MY_MAKE_MUSIC ("PropertySet");
2832 p->set_property ("symbol", sym);
2833 p->set_property ("value", value);
2838 make_music_relative (Pitch start, Music *music)
2840 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2841 relative->set_property ("element", music->self_scm ());
2843 Pitch last = music->to_relative_octave (start);
2844 if (lily_1_8_relative)
2845 music->set_property ("last-pitch", last.smobbed_copy ());
2850 make_lyric_combine_music (SCM name, Music *music)
2852 Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
2853 combine->set_property ("element", music->self_scm ());
2854 combine->set_property ("associated-context", name);
2860 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2862 Lily_parser *pars = (Lily_parser*) v;
2863 Lily_lexer *lex = pars->lexer_;
2865 lex->lexval = (void*) s;
2867 lex->prepare_for_next_token ();
2868 return lex->yylex ();