2 parser.yy -- Bison/C++ parser for LilyPond
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 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"
78 #include "file-path.hh"
79 #include "input-smob.hh"
81 #include "lily-guile.hh"
82 #include "lilypond-input-version.hh"
85 #include "lily-lexer.hh"
86 #include "lily-parser.hh"
87 #include "paper-book.hh"
88 #include "output-def.hh"
89 #include "scm-hash.hh"
90 #include "program-option.hh"
92 #include "text-interface.hh"
101 Output_def *outputdef;
111 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
113 Music *property_op_to_music (SCM op);
114 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops);
115 SCM get_next_unique_context_id ();
116 SCM get_next_unique_lyrics_context_id ();
123 #define _(x) gettext (x)
128 Music *make_lyric_combine_music (SCM name, Music *music);
129 Music *make_music_relative (Pitch start, Music *music);
130 Music *run_music_function (Lily_parser *, SCM expr);
131 Music *set_property_music (SCM sym, SCM value);
132 SCM get_first_context_id (SCM type, Music *m);
133 SCM make_chord (SCM pitch, SCM dur, SCM modification_list);
134 SCM make_chord_step (int step, int alter);
135 SCM make_simple_markup (SCM a);
136 bool is_duration (int t);
137 bool is_regular_identifier (SCM id);
138 bool ly_input_procedure_p (SCM x);
139 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
140 void set_music_properties (Music *p, SCM a);
144 /* The third option is an alias that will be used to display the
145 syntax error. Bison CVS now correctly handles backslash escapes.
147 FIXME: Bison needs to translate some of these, eg, STRING.
151 /* Keyword tokens with plain escaped name. */
152 %token ACCEPTS "\\accepts"
153 %token ADDLYRICS "\\addlyrics"
154 %token ADDQUOTE "\\addquote"
155 %token ALIAS "\\alias"
156 %token ALTERNATIVE "\\alternative"
158 %token CHANGE "\\change"
159 %token CHORDMODE "\\chordmode"
160 %token CHORDS "\\chords"
161 %token CONSISTS "\\consists"
162 %token CONTEXT "\\context"
163 %token DEFAULT "\\default"
164 %token DEFAULTCHILD "\\defaultchild"
165 %token DENIES "\\denies"
166 %token DESCRIPTION "\\description"
167 %token DRUMMODE "\\drummode"
168 %token DRUMS "\\drums"
169 %token FIGUREMODE "\\figuremode"
170 %token FIGURES "\\figures"
171 %token GROBDESCRIPTIONS "\\grobdescriptions"
172 %token HEADER "\\header"
173 %token INVALID "\\invalid"
175 %token LAYOUT "\\layout"
176 %token LYRICMODE "\\lyricmode"
177 %token LYRICS "\\lyrics"
178 %token LYRICSTO "\\lyricsto"
180 %token MARKUP "\\markup"
183 %token NOTEMODE "\\notemode"
184 %token OBJECTID "\\objectid"
185 %token OCTAVE "\\octave"
187 %token OVERRIDE "\\override"
188 %token PAPER "\\paper"
189 %token PARTIAL "\\partial"
190 %token RELATIVE "\\relative"
191 %token REMOVE "\\remove"
192 %token REPEAT "\\repeat"
194 %token REVERT "\\revert"
195 %token SCORE "\\score"
196 %token SEQUENTIAL "\\sequential"
198 %token SIMULTANEOUS "\\simultaneous"
200 %token TEMPO "\\tempo"
201 %token TIMES "\\times"
202 %token TRANSPOSE "\\transpose"
203 %token TRANSPOSITION "\\transposition"
205 %token UNSET "\\unset"
208 /* Keyword token exceptions. */
209 %token TIME_T "\\time"
210 %token NEWCONTEXT "\\new"
213 /* Other string tokens. */
215 %token CHORD_BASS "/+"
216 %token CHORD_CARET "^"
217 %token CHORD_COLON ":"
218 %token CHORD_MINUS "-"
219 %token CHORD_SLASH "/"
220 %token DOUBLE_ANGLE_CLOSE ">>"
221 %token DOUBLE_ANGLE_OPEN "<<"
222 %token E_BACKSLASH "\\"
223 %token E_ANGLE_CLOSE "\\>"
224 %token E_CHAR "\\C[haracter]"
226 %token E_EXCLAMATION "\\!"
227 %token E_BRACKET_OPEN "\\["
229 %token E_BRACKET_CLOSE "\\]"
230 %token E_ANGLE_OPEN "\\<"
236 If we give names, Bison complains.
238 %token FIGURE_CLOSE /* "\\>" */
239 %token FIGURE_OPEN /* "\\<" */
240 %token FIGURE_SPACE "_"
243 %token CHORDMODIFIERS
245 %token MULTI_MEASURE_REST
250 %token <i> E_UNSIGNED
253 %token <scm> BOOK_IDENTIFIER
254 %token <scm> CHORDMODIFIER_PITCH
255 %token <scm> CHORD_MODIFIER
256 %token <scm> CONTEXT_DEF_IDENTIFIER
257 %token <scm> DRUM_PITCH
258 %token <scm> DURATION_IDENTIFIER
259 %token <scm> EVENT_IDENTIFIER
260 %token <scm> FRACTION
261 %token <scm> LYRICS_STRING
262 %token <scm> LYRIC_MARKUP_IDENTIFIER
263 %token <scm> MARKUP_HEAD_EMPTY
264 %token <scm> MARKUP_HEAD_LIST0
265 %token <scm> MARKUP_HEAD_MARKUP0
266 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
267 %token <scm> MARKUP_HEAD_SCM0
268 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
269 %token <scm> MARKUP_HEAD_SCM0_SCM1
270 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
271 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
272 %token <scm> MARKUP_IDENTIFIER
273 %token <scm> MUSIC_FUNCTION
274 %token <scm> MUSIC_FUNCTION_MARKUP
275 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
276 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
277 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
278 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
279 %token <scm> MUSIC_FUNCTION_MUSIC
280 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
281 %token <scm> MUSIC_FUNCTION_SCM
282 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
283 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
284 %token <scm> MUSIC_FUNCTION_SCM_SCM
285 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
286 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM
287 %token <scm> MUSIC_IDENTIFIER
288 %token <scm> NOTENAME_PITCH
289 %token <scm> NUMBER_IDENTIFIER
290 %token <scm> OUTPUT_DEF_IDENTIFIER
292 %token <scm> RESTNAME
293 %token <scm> SCM_IDENTIFIER
295 %token <scm> SCORE_IDENTIFIER
297 %token <scm> STRING_IDENTIFIER
298 %token <scm> TONICNAME_PITCH
301 %type <book> book_block
302 %type <book> book_body
304 %type <i> bare_unsigned
305 %type <i> figured_bass_alteration
307 %type <i> exclamations
308 %type <i> optional_rest
313 %type <i> tremolo_type
315 %type <music> Composite_music
316 %type <music> Grouped_music_list
318 %type <music> Prefix_composite_music
319 %type <music> Repeated_music
320 %type <music> Sequential_music
321 %type <music> Simple_music
322 %type <music> Simultaneous_music
323 %type <music> chord_body
324 %type <music> chord_body_element
325 %type <music> command_element
326 %type <music> command_event
327 %type <music> context_change
328 %type <music> direction_less_event
329 %type <music> direction_reqd_event
330 %type <music> event_chord
331 %type <music> gen_text_def
332 %type <music> music_property_def
333 %type <music> note_chord_element
334 %type <music> post_event
335 %type <music> re_rhythmed_music
336 %type <music> relative_music
337 %type <music> simple_element
338 %type <music> string_number_event
339 %type <music> tempo_event
340 %type <music> toplevel_music
342 %type <outputdef> output_def_body
343 %type <outputdef> output_def_head
344 %type <outputdef> output_def
345 %type <outputdef> paper_block
347 %type <scm> Alternative_music
348 %type <scm> Generic_prefix_music_scm
349 %type <scm> Music_list
350 %type <scm> absolute_pitch
351 %type <scm> assignment_id
352 %type <scm> bare_number
353 %type <scm> music_function_event
354 %type <scm> music_function_chord_body
355 %type <scm> bass_figure
356 %type <scm> figured_bass_modification
357 %type <scm> br_bass_figure
358 %type <scm> bass_number
359 %type <scm> chord_body_elements
360 %type <scm> chord_item
361 %type <scm> chord_items
362 %type <scm> chord_separator
363 %type <scm> context_def_mod
364 %type <scm> context_def_spec_block
365 %type <scm> context_def_spec_body
366 %type <scm> context_mod
367 %type <scm> context_mod_list
368 %type <scm> context_prop_spec
369 %type <scm> direction_less_char
370 %type <scm> duration_length
371 %type <scm> embedded_scm
372 %type <scm> figure_list
373 %type <scm> figure_spec
375 %type <scm> full_markup
376 %type <scm> identifier_init
377 %type <scm> lilypond_header
378 %type <scm> lilypond_header_body
379 %type <scm> lyric_element
380 %type <scm> lyric_markup
382 %type <scm> markup_braced_list
383 %type <scm> markup_braced_list_body
384 %type <scm> markup_composed_list
385 %type <scm> markup_head_1_item
386 %type <scm> markup_head_1_list
387 %type <scm> markup_list
388 %type <scm> markup_top
389 %type <scm> mode_changing_head
390 %type <scm> mode_changing_head_with_context
391 %type <scm> multiplied_duration
392 %type <scm> new_chord
393 %type <scm> new_lyrics
394 %type <scm> number_expression
395 %type <scm> number_factor
396 %type <scm> number_term
397 %type <scm> object_id_setting
398 %type <scm> octave_check
399 %type <scm> optional_context_mod
400 %type <scm> optional_notemode_duration
402 %type <scm> pitch_also_in_chords
403 %type <scm> post_events
404 %type <scm> property_operation
406 %type <scm> script_abbreviation
407 %type <scm> simple_markup
408 %type <scm> simple_string
409 %type <scm> steno_duration
410 %type <scm> steno_pitch
411 %type <scm> steno_tonic_pitch
412 %type <scm> step_number
413 %type <scm> step_numbers
415 %type <scm> function_scm_argument
417 %type <score> score_block
418 %type <score> score_body
423 /* We don't assign precedence to / and *, because we might need varied
424 prec levels in different prods */
430 lilypond: /* empty */
431 | lilypond toplevel_expression {
433 | lilypond assignment {
436 THIS->error_level_ = 1;
439 THIS->error_level_ = 1;
445 OBJECTID STRING { $$ = $2; }
450 THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
457 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
458 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
464 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
465 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
470 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
471 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
475 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler");
476 scm_call_2 (proc, THIS->self_scm (), $1);
480 Output_def * od = $1;
482 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
483 id = ly_symbol2scm ("$defaultpaper");
484 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
485 id = ly_symbol2scm ("$defaultmidi");
486 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
487 id = ly_symbol2scm ("$defaultlayout");
489 THIS->lexer_->set_identifier (id, od->self_scm ());
505 lilypond_header_body:
507 $$ = get_header(THIS);
508 THIS->lexer_->add_scope ($$);
510 | lilypond_header_body assignment {
516 HEADER '{' lilypond_header_body '}' {
517 $$ = THIS->lexer_->remove_scope ();
526 | LYRICS_STRING { $$ = $1; }
530 assignment_id '=' identifier_init {
531 if (! is_regular_identifier ($1))
533 @1.warning (_ ("identifier should have alphabetic characters only"));
536 THIS->lexer_->set_identifier ($1, $3);
539 TODO: devise standard for protection in parser.
541 The parser stack lives on the C-stack, which means that
542 all objects can be unprotected as soon as they're here.
552 $$ = $1->self_scm ();
556 $$ = $1->self_scm ();
560 $$ = $1->self_scm ();
563 | context_def_spec_block {
567 $$ = $1->self_scm ();
571 $$ = $1->self_scm ();
574 | number_expression {
587 $$ = scm_from_int ($1);
591 context_def_spec_block:
592 CONTEXT '{' context_def_spec_body '}'
598 context_def_spec_body:
600 $$ = Context_def::make_scm ();
601 unsmob_context_def ($$)->set_spot (@$);
603 | CONTEXT_DEF_IDENTIFIER {
605 unsmob_context_def ($$)->set_spot (@$);
607 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
608 Context_def*td = unsmob_context_def ($$);
610 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
611 SCM tag = scm_caar (p);
613 /* TODO: should make new tag "grob-definition" ? */
614 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
615 tag, scm_cons (scm_cdar (p), SCM_EOL)));
618 | context_def_spec_body context_mod {
619 unsmob_context_def ($$)->add_context_mod ($2);
626 BOOK '{' book_body '}' {
632 * Use 'handlers' like for toplevel-* stuff?
633 * grok \layout and \midi? */
638 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
639 $$->paper_->unprotect ();
640 $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader");
643 $$ = unsmob_book ($1);
646 | book_body paper_block {
650 | book_body score_block {
651 SCM s = $2->self_scm ();
655 | book_body full_markup {
658 | book_body lilypond_header {
663 $$->scores_ = SCM_EOL;
665 | book_body object_id_setting {
666 $$->user_key_ = ly_scm2string ($2);
671 SCORE '{' score_body '}' {
678 SCM m = $1->self_scm ();
680 SCM scorify = ly_lily_module_constant ("scorify-music");
681 SCM score = scm_call_2 (scorify, m, THIS->self_scm ());
683 // pass ownernship to C++ again.
684 $$ = unsmob_score (score);
689 $$ = unsmob_score ($1);
692 | score_body object_id_setting {
693 $$->user_key_ = ly_scm2string ($2);
695 | score_body lilypond_header {
698 | score_body output_def {
699 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
701 THIS->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
711 $$->error_found_ = true;
723 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
725 THIS->parser_error (@1, _ ("need \\paper for paper block"));
726 $$ = get_paper (THIS);
733 output_def_body '}' {
736 THIS->lexer_->remove_scope ();
737 THIS->lexer_->pop_state ();
743 $$ = get_paper (THIS);
744 $$->input_origin_ = @$;
745 THIS->lexer_->add_scope ($$->scope_);
748 Output_def *p = get_midi (THIS);
750 THIS->lexer_->add_scope (p->scope_);
753 Output_def *p = get_layout (THIS);
755 THIS->lexer_->add_scope (p->scope_);
762 output_def_head '{' {
764 $$->input_origin_.set_spot (@$);
765 THIS->lexer_->push_initial_state ();
767 | output_def_head '{' OUTPUT_DEF_IDENTIFIER {
769 Output_def *o = unsmob_output_def ($3);
770 o->input_origin_.set_spot (@$);
772 THIS->lexer_->remove_scope ();
773 THIS->lexer_->add_scope (o->scope_);
774 THIS->lexer_->push_initial_state ();
776 | output_def_body assignment {
779 | output_def_body context_def_spec_block {
780 assign_context_def ($$, $2);
782 | output_def_body tempo_event {
784 junk this ? there already is tempo stuff in
787 int m = scm_to_int ($2->get_property ("metronome-count"));
788 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
789 set_tempo ($$, d->get_length (), m);
792 | output_def_body error {
798 TEMPO steno_duration '=' bare_unsigned {
799 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
800 $$->set_property ("tempo-unit", $2);
801 $$->set_property ("metronome-count", scm_from_int ( $4));
806 The representation of a list is the
810 to have efficient append. */
814 $$ = scm_cons (SCM_EOL, SCM_EOL);
818 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
819 $2->unprotect (); /* UGH */
821 if (scm_is_pair (scm_cdr (s)))
822 scm_set_cdr_x (scm_cdr (s), c); /* append */
824 scm_set_car_x (s, c); /* set first cons */
825 scm_set_cdr_x (s, c); /* remember last cell */
827 | Music_list embedded_scm {
831 Music * m = MY_MAKE_MUSIC("Music");
833 m->set_property ("error-found", SCM_BOOL_T);
835 SCM c = scm_cons (m->self_scm (), SCM_EOL);
836 m->unprotect (); /* 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 */
855 | ALTERNATIVE '{' Music_list '}' {
862 REPEAT simple_string bare_unsigned Music Alternative_music
866 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
867 if (times < scm_ilength (alts)) {
868 unsmob_music (scm_car (alts))
869 ->origin ()->warning (
870 _ ("more alternatives than repeats"));
871 warning ("junking excess alternatives");
872 alts = ly_truncate_list (times, alts);
876 SCM proc = ly_lily_module_constant ("make-repeated-music");
878 SCM mus = scm_call_1 (proc, $2);
879 Music *r = unsmob_music (mus);
883 r-> set_property ("element", beg->self_scm ());
886 r->set_property ("repeat-count", scm_from_int (max (times, 1)));
888 r-> set_property ("elements",alts);
889 if (ly_is_equal ($2, scm_makfrom0str ("tremolo"))) {
891 TODO: move this code to Scheme.
894 /* we cannot get durations and other stuff
895 correct down the line,
896 so we have to add to the duration log here. */
897 SCM func = ly_lily_module_constant ("shift-duration-log");
899 int dots = ($3 % 3) ? 0 : 1;
900 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
903 if ($4->is_mus_type ("sequential-music"))
905 int list_len = scm_ilength ($4->get_property ("elements"));
907 $4->origin ()->warning (_f ("expect 2 elements for Chord tremolo, found %d", list_len));
909 r->compress (Moment (Rational (1, list_len)));
911 scm_call_3 (func, r->self_scm (), scm_from_int (shift), scm_from_int (dots));
914 r->set_spot (*$4->origin ());
921 SEQUENTIAL '{' Music_list '}' {
922 $$ = MY_MAKE_MUSIC ("SequentialMusic");
923 $$->set_property ("elements", scm_car ($3));
926 | '{' Music_list '}' {
927 $$ = MY_MAKE_MUSIC ("SequentialMusic");
928 $$->set_property ("elements", scm_car ($2));
934 SIMULTANEOUS '{' Music_list '}'{
935 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
936 $$->set_property ("elements", scm_car ($3));
940 | simul_open Music_list simul_close {
941 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
942 $$->set_property ("elements", scm_car ($2));
948 event_chord { $$ = $1; }
950 $$ = unsmob_music ($1);
957 optional_context_mod:
958 /**/ { $$ = SCM_EOL; }
959 | WITH { THIS->lexer_->push_initial_state (); }
960 '{' context_mod_list '}'
962 THIS->lexer_->pop_state ();
968 /* */ { $$ = SCM_EOL; }
969 | context_mod_list context_mod {
970 $$ = scm_cons ($2, $1);
976 Prefix_composite_music { $$ = $1; }
977 | Grouped_music_list { $$ = $1; }
981 Simultaneous_music { $$ = $1; }
982 | Sequential_music { $$ = $1; }
986 function_scm_argument:
991 Generic_prefix_music_scm:
993 $$ = scm_list_2 ($1, make_input (@$));
995 | MUSIC_FUNCTION_SCM function_scm_argument {
996 $$ = scm_list_3 ($1, make_input (@$), $2);
998 | MUSIC_FUNCTION_MARKUP full_markup {
999 $$ = scm_list_3 ($1, make_input (@$), $2);
1002 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument Music {
1003 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1006 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
1007 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1009 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
1010 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1012 | MUSIC_FUNCTION_MUSIC Music {
1013 $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
1016 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument Music {
1017 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
1019 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
1020 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1023 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
1024 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1026 | MUSIC_FUNCTION_MUSIC_MUSIC Music Music {
1027 $$ = scm_list_4 ($1, make_input (@$), $2->self_scm (), $3->self_scm ());
1031 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument Music Music {
1032 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1036 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup Music Music {
1037 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1043 Prefix_composite_music:
1044 Generic_prefix_music_scm {
1045 $$ = run_music_function (THIS, $1);
1047 | CONTEXT simple_string '=' simple_string optional_context_mod Music {
1048 $$ = context_spec_music ($2, $4, $6, $5);
1051 | CONTEXT simple_string optional_context_mod Music {
1052 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1054 | NEWCONTEXT simple_string optional_context_mod Music {
1055 $$ = context_spec_music ($2, get_next_unique_context_id (), $4,
1059 | TIMES fraction Music
1062 int n = scm_to_int (scm_car ($2)); int d = scm_to_int (scm_cdr ($2));
1065 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1068 $$->set_property ("element", mp->self_scm ());
1070 $$->set_property ("numerator", scm_from_int (n));
1071 $$->set_property ("denominator", scm_from_int (d));
1072 $$->compress (Moment (Rational (n,d)));
1075 | Repeated_music { $$ = $1; }
1076 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1077 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1079 Pitch from = *unsmob_pitch ($2);
1080 Pitch to = *unsmob_pitch ($3);
1082 p->transpose (pitch_interval (from, to));
1083 $$->set_property ("element", p->self_scm ());
1086 | mode_changing_head Grouped_music_list {
1087 if ($1 == ly_symbol2scm ("chords"))
1089 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1090 chm->set_property ("element", $2->self_scm ());
1098 THIS->lexer_->pop_state ();
1100 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1101 $$ = context_spec_music ($1, get_next_unique_context_id (),
1103 if ($1 == ly_symbol2scm ("ChordNames"))
1105 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1106 chm->set_property ("element", $$->self_scm ());
1110 THIS->lexer_->pop_state ();
1112 | relative_music { $$ = $1; }
1113 | re_rhythmed_music { $$ = $1; }
1118 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1119 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1121 $$ = ly_symbol2scm ("notes");
1125 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1126 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1128 $$ = ly_symbol2scm ("drums");
1131 THIS->lexer_->push_figuredbass_state ();
1133 $$ = ly_symbol2scm ("figures");
1136 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1137 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1138 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1139 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1140 $$ = ly_symbol2scm ("chords");
1144 { THIS->lexer_->push_lyric_state ();
1145 $$ = ly_symbol2scm ("lyrics");
1149 mode_changing_head_with_context:
1151 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1152 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1154 $$ = ly_symbol2scm ("DrumStaff");
1157 THIS->lexer_->push_figuredbass_state ();
1159 $$ = ly_symbol2scm ("FiguredBass");
1162 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1163 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1164 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1165 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1166 $$ = ly_symbol2scm ("ChordNames");
1169 { THIS->lexer_->push_lyric_state ();
1170 $$ = ly_symbol2scm ("Lyrics");
1176 RELATIVE absolute_pitch Music {
1178 Pitch start = *unsmob_pitch ($2);
1179 $$ = make_music_relative (start, m);
1182 | RELATIVE Composite_music {
1185 Pitch middle_c (0, 0, 0);
1186 $$ = make_music_relative (middle_c, m);
1192 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1194 Grouped_music_list {
1195 /* Can also use Music at the expensive of two S/Rs similar to
1196 \repeat \alternative */
1197 THIS->lexer_->pop_state ();
1199 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1201 | new_lyrics ADDLYRICS {
1202 THIS->lexer_->push_lyric_state ();
1203 } Grouped_music_list {
1204 THIS->lexer_->pop_state ();
1205 $$ = scm_cons ($4->self_scm (), $1);
1210 Grouped_music_list new_lyrics {
1212 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice);
1213 if (!scm_is_string (name))
1215 name = get_next_unique_lyrics_context_id ();
1216 voice = context_spec_music (scm_makfrom0str ("Voice"),
1221 SCM context = scm_makfrom0str ("Lyrics");
1222 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1225 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1227 Music *music = unsmob_music (scm_car (s));
1228 Music *com = make_lyric_combine_music (name, music);
1229 Music *csm = context_spec_music (context,
1230 get_next_unique_context_id (), com, SCM_EOL);
1231 lst = scm_cons (csm->self_scm (), lst);
1233 all->set_property ("elements", scm_cons (voice->self_scm (),
1236 voice->unprotect ();
1238 | LYRICSTO simple_string {
1239 THIS->lexer_->push_lyric_state ();
1241 THIS->lexer_->pop_state ();
1244 $$ = make_lyric_combine_music (name, music);
1250 CHANGE STRING '=' STRING {
1251 Music*t = MY_MAKE_MUSIC ("ContextChange");
1252 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1253 t-> set_property ("change-to-id", $4);
1262 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1263 scm_string_to_symbol ($1), $3);
1265 | UNSET simple_string {
1266 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1267 scm_string_to_symbol ($2));
1269 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1270 $$ = scm_list_4 (ly_symbol2scm ("push"),
1271 scm_string_to_symbol ($2), $5, $3);
1273 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1274 $$ = scm_list_5 (ly_symbol2scm ("push"),
1275 scm_string_to_symbol ($2), $6, $4, $3);
1277 | REVERT simple_string embedded_scm {
1278 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1279 scm_string_to_symbol ($2), $3);
1284 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1285 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1287 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1288 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1289 | DENIES { $$ = ly_symbol2scm ("denies"); }
1291 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1292 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1293 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1294 | NAME { $$ = ly_symbol2scm ("context-name"); }
1298 property_operation { $$ = $1; }
1299 | context_def_mod STRING {
1300 $$ = scm_list_2 ($1, $2);
1306 if (!is_regular_identifier ($1))
1308 @$.error (_("Grob name should be alphanumeric"));
1311 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1312 scm_string_to_symbol ($1));
1314 | simple_string '.' simple_string {
1315 $$ = scm_list_2 (scm_string_to_symbol ($1),
1316 scm_string_to_symbol ($3));
1321 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1322 $$ = property_op_to_music (scm_list_4 (
1323 ly_symbol2scm ("push"),
1326 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1328 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1329 $$ = property_op_to_music (scm_list_5 (
1330 ly_symbol2scm ("push"),
1333 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1335 | REVERT context_prop_spec embedded_scm {
1336 $$ = property_op_to_music (scm_list_3 (
1337 ly_symbol2scm ("pop"),
1341 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1343 | SET context_prop_spec '=' scalar {
1344 $$ = property_op_to_music (scm_list_3 (
1345 ly_symbol2scm ("assign"),
1348 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1350 | UNSET context_prop_spec {
1351 $$ = property_op_to_music (scm_list_2 (
1352 ly_symbol2scm ("unset"),
1354 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1356 | ONCE music_property_def {
1357 SCM e = $2->get_property ("element");
1358 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1369 | STRING_IDENTIFIER {
1372 | string '+' string {
1373 $$ = scm_string_append (scm_list_2 ($1, $3));
1377 simple_string: STRING {
1383 | STRING_IDENTIFIER {
1404 $$ = scm_from_int ($1);
1410 pre_events doesn't contain anything. It is a trick:
1412 Adding pre_events to the simple_element
1413 makes the choice between
1419 simple_element: STRING
1421 a single shift/reduction conflict.
1423 nevertheless, this is not very clean, and we should find a different
1427 pre_events: /* empty */
1431 pre_events simple_element post_events {
1432 SCM elts = $2-> get_property ("elements");
1434 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1436 $2->set_property ("elements", elts);
1437 /* why is this giving wrong start location? -ns
1438 * $2->set_spot (@$); */
1440 i.set_location (@2, @3);
1445 | note_chord_element
1450 chord_body optional_notemode_duration post_events
1452 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1453 SCM es = $1->get_property ("elements");
1454 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1456 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1457 unsmob_music (scm_car (s))->set_property ("duration", dur);
1458 es = ly_append2 (es, postevs);
1460 $1-> set_property ("elements", es);
1472 simul_open: DOUBLE_ANGLE_OPEN
1475 simul_close: DOUBLE_ANGLE_CLOSE
1479 chord_open chord_body_elements chord_close
1481 $$ = MY_MAKE_MUSIC ("EventChord");
1483 $$->set_property ("elements",
1484 scm_reverse_x ($2, SCM_EOL));
1488 chord_body_elements:
1489 /* empty */ { $$ = SCM_EOL; }
1490 | chord_body_elements chord_body_element {
1491 $$ = scm_cons ($2->self_scm (), $1);
1497 pitch exclamations questions octave_check post_events
1504 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1505 n->set_property ("pitch", $1);
1508 n->set_property ("cautionary", SCM_BOOL_T);
1509 if (ex % 2 || q % 2)
1510 n->set_property ("force-accidental", SCM_BOOL_T);
1512 if (scm_is_pair (post)) {
1513 SCM arts = scm_reverse_x (post, SCM_EOL);
1514 n->set_property ("articulations", arts);
1516 if (scm_is_number (check))
1518 int q = scm_to_int (check);
1519 n->set_property ("absolute-octave", scm_from_int (q-1));
1525 | DRUM_PITCH post_events {
1526 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1527 n->set_property ("duration", $2);
1528 n->set_property ("drum-type", $1);
1531 if (scm_is_pair ($2)) {
1532 SCM arts = scm_reverse_x ($2, SCM_EOL);
1533 n->set_property ("articulations", arts);
1537 | music_function_chord_body {
1538 $$ = run_music_function (THIS, $1);
1543 music_function_chord_body:
1545 $$ = scm_list_2 ($1, make_input (@$));
1547 | MUSIC_FUNCTION_MUSIC chord_body_element {
1548 $$ = scm_list_3 ($1, make_input (@$),
1551 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument chord_body_element {
1552 $$ = scm_list_4 ($1, make_input (@$),
1553 $2, $3->self_scm ());
1555 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument
1556 chord_body_element {
1558 $$ = scm_list_5 ($1, make_input (@$),
1559 $2, $3, $4->self_scm ());
1565 ADDQUOTE string Music {
1566 SCM adder = ly_lily_module_constant ("add-quotable");
1568 scm_call_2 (adder, $2, $3->self_scm ());
1575 $$ = MY_MAKE_MUSIC ("EventChord");
1576 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1582 | SKIP duration_length {
1583 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1584 skip->set_property ("duration", $2);
1585 skip->set_spot (@$);
1589 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1592 $$->set_property ("pitch", $2);
1595 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1596 m->set_property ("span-direction", scm_from_int (START));
1599 $$ = MY_MAKE_MUSIC ("EventChord");
1600 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1605 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1606 m->set_property ("span-direction", scm_from_int (STOP));
1609 $$ = MY_MAKE_MUSIC ("EventChord");
1610 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1615 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1619 SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
1621 if (Music * m = unsmob_music (pipe))
1624 $$ = MY_MAKE_MUSIC ("BarCheck");
1628 | TRANSPOSITION pitch {
1630 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1631 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1632 sounds_as_c.smobbed_copy());
1634 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1637 | PARTIAL duration_length {
1638 Moment m = - unsmob_duration ($2)->get_length ();
1639 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1641 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1643 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1649 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1651 SCM result = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1652 $$ = unsmob_music (result);
1656 SCM proc = ly_lily_module_constant ("make-mark-set");
1658 SCM result = scm_call_1 (proc, $2);
1659 $$ = unsmob_music (result);
1666 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1669 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1676 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1679 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1681 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1682 if (scm_ilength ($3) > 0)
1684 key->set_property ("pitch-alist", $3);
1685 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1686 key->transpose (* unsmob_pitch ($2));
1688 THIS->parser_error (@3, _ ("second argument must be pitch list"));
1700 | post_events post_event {
1702 $$ = scm_cons ($2->self_scm (), $$);
1707 music_function_event:
1708 MUSIC_FUNCTION_MUSIC post_event {
1709 $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
1711 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument post_event {
1712 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1714 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument post_event {
1715 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
1721 direction_less_event {
1724 | '-' music_function_event {
1725 Music *mus = run_music_function (THIS, $2);
1730 if (!THIS->lexer_->is_lyric_state ())
1731 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1732 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1735 if (!THIS->lexer_->is_lyric_state ())
1736 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1737 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1739 | script_dir direction_reqd_event {
1741 $2->set_property ("direction", scm_from_int ($1));
1744 | script_dir direction_less_event {
1746 $2->set_property ("direction", scm_from_int ($1));
1749 | string_number_event
1752 string_number_event:
1754 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1755 s->set_property ("string-number", scm_from_int ($1));
1761 direction_less_char:
1763 $$ = ly_symbol2scm ("bracketOpenSymbol");
1766 $$ = ly_symbol2scm ("bracketCloseSymbol");
1769 $$ = ly_symbol2scm ("tildeSymbol");
1772 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1775 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1778 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1781 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1784 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1787 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1790 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1794 direction_less_event:
1795 direction_less_char {
1796 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1798 if (unsmob_music (predefd))
1800 m = unsmob_music (predefd)->clone ();
1804 m = MY_MAKE_MUSIC ("Music");
1809 | EVENT_IDENTIFIER {
1810 $$ = unsmob_music ($1);
1813 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1815 a->set_property ("tremolo-type", scm_from_int ($1));
1820 direction_reqd_event:
1824 | script_abbreviation {
1825 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1826 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1827 if (scm_is_string (s))
1828 a->set_property ("articulation-type", s);
1829 else THIS->parser_error (@1, _ ("expecting string as script definition"));
1835 /**/ { $$ = SCM_EOL; }
1836 | '=' { $$ = scm_from_int (0); }
1837 | '=' sub_quotes { $$ = scm_from_int ($2); }
1838 | '=' sup_quotes { $$ = scm_from_int ($2); }
1863 | NOTENAME_PITCH sup_quotes {
1864 Pitch p = *unsmob_pitch ($1);
1865 p = p.transposed (Pitch ($2,0,0));
1866 $$ = p.smobbed_copy ();
1868 | NOTENAME_PITCH sub_quotes {
1869 Pitch p =* unsmob_pitch ($1);
1870 p = p.transposed (Pitch (-$2,0,0));
1871 $$ = p.smobbed_copy ();
1883 | TONICNAME_PITCH sup_quotes {
1884 Pitch p = *unsmob_pitch ($1);
1885 p = p.transposed (Pitch ($2,0,0));
1886 $$ = p.smobbed_copy ();
1888 | TONICNAME_PITCH sub_quotes {
1889 Pitch p =* unsmob_pitch ($1);
1891 p = p.transposed (Pitch (-$2,0,0));
1892 $$ = p.smobbed_copy ();
1902 pitch_also_in_chords:
1909 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1910 t->set_property ("text", $1);
1915 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1916 t->set_property ("text",
1917 make_simple_markup ($1));
1923 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1924 t->set_property ("digit", scm_from_int ($1));
1930 script_abbreviation:
1932 $$ = scm_makfrom0str ("Hat");
1935 $$ = scm_makfrom0str ("Plus");
1938 $$ = scm_makfrom0str ("Dash");
1941 $$ = scm_makfrom0str ("Bar");
1944 $$ = scm_makfrom0str ("Larger");
1947 $$ = scm_makfrom0str ("Dot");
1950 $$ = scm_makfrom0str ("Underscore");
1957 | '-' { $$ = CENTER; }
1968 multiplied_duration {
1973 optional_notemode_duration:
1975 Duration dd = THIS->default_duration_;
1976 $$ = dd.smobbed_copy ();
1978 | multiplied_duration {
1980 THIS->default_duration_ = *unsmob_duration ($$);
1985 bare_unsigned dots {
1987 if (!is_duration ($1))
1988 THIS->parser_error (@1, _f ("not a duration: %d", $1));
1992 $$ = Duration (len, $2).smobbed_copy ();
1994 | DURATION_IDENTIFIER dots {
1995 Duration *d = unsmob_duration ($1);
1996 Duration k (d->duration_log (), d->dot_count () + $2);
2002 multiplied_duration:
2006 | multiplied_duration '*' bare_unsigned {
2007 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2009 | multiplied_duration '*' FRACTION {
2010 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2012 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2017 FRACTION { $$ = $1; }
2018 | UNSIGNED '/' UNSIGNED {
2019 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2036 | ':' bare_unsigned {
2037 if (!is_duration ($2))
2038 THIS->parser_error (@2, _f ("not a duration: %d", $2));
2045 $$ = scm_from_int ($1);
2048 $$ = scm_from_int ($1);
2050 | STRING { $$ = $1; }
2051 | full_markup { $$ = $1; }
2054 figured_bass_alteration:
2062 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2063 $$ = bfr->self_scm ();
2068 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2069 $$ = bfr->self_scm ();
2071 if (scm_is_number ($1))
2072 bfr->set_property ("figure", $1);
2073 else if (Text_interface::is_markup ($1))
2074 bfr->set_property ("text", $1);
2081 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2083 | bass_figure figured_bass_alteration {
2084 Music *m = unsmob_music ($1);
2086 SCM salter = m->get_property ("alteration");
2087 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2088 m->set_property ("alteration",
2089 scm_from_int (alter + $2));
2091 m->set_property ("alteration", scm_from_int (0));
2094 | bass_figure figured_bass_modification {
2095 Music *m = unsmob_music ($1);
2096 if ($2 == ly_symbol2scm ("plus"))
2098 m->set_property ("augmented", SCM_BOOL_T);
2100 else if ($2 == ly_symbol2scm ("slash"))
2102 m->set_property ("diminished", SCM_BOOL_T);
2104 else if ($2 == ly_symbol2scm ("exclamation"))
2106 m->set_property ("no-continuation", SCM_BOOL_T);
2112 figured_bass_modification:
2114 $$ = ly_symbol2scm ("plus");
2117 $$ = ly_symbol2scm ("exclamation");
2120 $$ = ly_symbol2scm ("slash");
2130 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2138 | figure_list br_bass_figure {
2139 $$ = scm_cons ($2, $1);
2144 FIGURE_OPEN figure_list FIGURE_CLOSE {
2145 Music *m = MY_MAKE_MUSIC ("EventChord");
2146 $2 = scm_reverse_x ($2, SCM_EOL);
2147 m->set_property ("elements", $2);
2148 $$ = m->self_scm ();
2159 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2160 if (!THIS->lexer_->is_note_state ())
2161 THIS->parser_error (@1, _ ("have to be in Note mode for notes"));
2165 n = MY_MAKE_MUSIC ("RestEvent");
2167 n = MY_MAKE_MUSIC ("NoteEvent");
2169 n->set_property ("pitch", $1);
2170 n->set_property ("duration", $5);
2172 if (scm_is_number ($4))
2174 int q = scm_to_int ($4);
2175 n->set_property ("absolute-octave", scm_from_int (q-1));
2179 n->set_property ("cautionary", SCM_BOOL_T);
2180 if ($2 % 2 || $3 % 2)
2181 n->set_property ("force-accidental", SCM_BOOL_T);
2183 Music *v = MY_MAKE_MUSIC ("EventChord");
2184 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2191 | DRUM_PITCH optional_notemode_duration {
2192 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2193 n->set_property ("duration", $2);
2194 n->set_property ("drum-type", $1);
2196 Music *v = MY_MAKE_MUSIC ("EventChord");
2197 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2204 | figure_spec optional_notemode_duration {
2205 Music *m = unsmob_music ($1);
2207 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2209 unsmob_music (scm_car (s))->set_property ("duration", $2);
2213 | RESTNAME optional_notemode_duration {
2215 if (ly_scm2string ($1) == "s") {
2217 ev = MY_MAKE_MUSIC ("SkipEvent");
2220 ev = MY_MAKE_MUSIC ("RestEvent");
2223 ev->set_property ("duration", $2);
2225 Music *velt = MY_MAKE_MUSIC ("EventChord");
2226 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2227 velt->set_spot (@$);
2233 | MULTI_MEASURE_REST optional_notemode_duration {
2234 SCM proc = ly_lily_module_constant ("make-multi-measure-rest");
2235 SCM mus = scm_call_2 (proc, $2, make_input (@$));
2236 $$ = unsmob_music (mus);
2240 | lyric_element optional_notemode_duration {
2241 if (!THIS->lexer_->is_lyric_state ())
2242 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2244 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2245 levent->set_property ("text", $1);
2246 levent->set_property ("duration",$2);
2247 levent->set_spot (@$);
2248 Music *velt = MY_MAKE_MUSIC ("EventChord");
2249 velt->set_property ("elements", scm_list_1 (levent->self_scm ()));
2254 if (!THIS->lexer_->is_chord_state ())
2255 THIS->parser_error (@1, _ ("have to be in Chord mode for chords"));
2256 $$ = unsmob_music ($1);
2270 steno_tonic_pitch optional_notemode_duration {
2271 $$ = make_chord ($1, $2, SCM_EOL);
2273 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2274 SCM its = scm_reverse_x ($4, SCM_EOL);
2275 $$ = make_chord ($1, $2, scm_cons ($3, its));
2283 | chord_items chord_item {
2284 $$ = scm_cons ($2, $$);
2290 $$ = ly_symbol2scm ("chord-colon");
2293 $$ = ly_symbol2scm ("chord-caret");
2295 | CHORD_SLASH steno_tonic_pitch {
2296 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2298 | CHORD_BASS steno_tonic_pitch {
2299 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2308 $$ = scm_reverse_x ($1, SCM_EOL);
2316 step_number { $$ = scm_cons ($1, SCM_EOL); }
2317 | step_numbers '.' step_number {
2318 $$ = scm_cons ($3, $$);
2324 $$ = make_chord_step ($1, 0);
2326 | bare_unsigned '+' {
2327 $$ = make_chord_step ($1, SHARP);
2329 | bare_unsigned CHORD_MINUS {
2330 $$ = make_chord_step ($1, FLAT);
2337 TODO: should deprecate in favor of Scheme?
2341 number_expression '+' number_term {
2342 $$ = scm_sum ($1, $3);
2344 | number_expression '-' number_term {
2345 $$ = scm_difference ($1, $3);
2354 | number_factor '*' number_factor {
2355 $$ = scm_product ($1, $3);
2357 | number_factor '/' number_factor {
2358 $$ = scm_divide ($1, $3);
2363 '-' number_factor { /* %prec UNARY_MINUS */
2364 $$ = scm_difference ($2, SCM_UNDEFINED);
2372 $$ = scm_from_int ($1);
2377 | NUMBER_IDENTIFIER {
2380 | REAL NUMBER_IDENTIFIER {
2381 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2383 | UNSIGNED NUMBER_IDENTIFIER {
2384 $$ = scm_from_double ($1 *scm_to_double ($2));
2400 | exclamations '!' { $$ ++; }
2405 | questions '?' { $$ ++; }
2409 This should be done more dynamically if possible.
2413 LYRIC_MARKUP_IDENTIFIER {
2417 { THIS->lexer_->push_markup_state (); }
2420 THIS->lexer_->pop_state ();
2429 { THIS->lexer_->push_markup_state (); }
2432 THIS->lexer_->pop_state ();
2438 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2440 | markup_head_1_list simple_markup {
2441 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2449 markup_composed_list {
2452 | markup_braced_list {
2457 markup_composed_list:
2458 markup_head_1_list markup_braced_list {
2459 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2465 '{' markup_braced_list_body '}' {
2466 $$ = scm_reverse_x ($2, SCM_EOL);
2470 markup_braced_list_body:
2471 /* empty */ { $$ = SCM_EOL; }
2472 | markup_braced_list_body markup {
2473 $$ = scm_cons ($2, $1);
2475 | markup_braced_list_body markup_list {
2476 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2481 MARKUP_HEAD_MARKUP0 {
2482 $$ = scm_list_1 ($1);
2484 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2485 $$ = scm_list_2 ($1, $2);
2487 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2488 $$ = scm_list_3 ($1, $2, $3);
2493 markup_head_1_item {
2494 $$ = scm_list_1 ($1);
2496 | markup_head_1_list markup_head_1_item {
2497 $$ = scm_cons ($2, $1);
2503 $$ = make_simple_markup ($1);
2505 | MARKUP_IDENTIFIER {
2508 | LYRIC_MARKUP_IDENTIFIER {
2511 | STRING_IDENTIFIER {
2515 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2516 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2517 } '{' score_body '}' {
2519 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2521 THIS->lexer_->pop_state ();
2523 | MARKUP_HEAD_SCM0 embedded_scm {
2524 $$ = scm_list_2 ($1, $2);
2526 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2527 $$ = scm_list_4 ($1, $2, $3, $4);
2529 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2530 $$ = scm_list_3 ($1, $2, $3);
2532 | MARKUP_HEAD_EMPTY {
2533 $$ = scm_list_1 ($1);
2535 | MARKUP_HEAD_LIST0 markup_list {
2536 $$ = scm_list_2 ($1,$2);
2538 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2539 $$ = scm_list_3 ($1, $2, $3);
2544 markup_head_1_list simple_markup {
2545 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2546 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2556 Lily_parser::set_yydebug (bool )
2564 Lily_parser::do_yyparse ()
2566 yyparse ((void*)this);
2575 It is a little strange to have this function in this file, but
2576 otherwise, we have to import music classes into the lexer.
2580 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2582 if (scm_is_string (sid)) {
2584 return STRING_IDENTIFIER;
2585 } else if (unsmob_book (sid)) {
2586 *destination = unsmob_book (sid)->clone ()->self_scm ();
2587 return BOOK_IDENTIFIER;
2588 } else if (scm_is_number (sid)) {
2590 return NUMBER_IDENTIFIER;
2591 } else if (unsmob_context_def (sid)) {
2592 *destination = unsmob_context_def (sid)->clone_scm ();
2593 return CONTEXT_DEF_IDENTIFIER;
2594 } else if (unsmob_score (sid)) {
2595 Score *score = new Score (*unsmob_score (sid));
2596 *destination = score->self_scm ();
2597 return SCORE_IDENTIFIER;
2598 } else if (Music *mus = unsmob_music (sid)) {
2599 mus = mus->clone ();
2600 *destination = mus->self_scm ();
2601 unsmob_music (*destination)->
2602 set_property ("origin", make_input (last_input_));
2604 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2607 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2608 } else if (unsmob_duration (sid)) {
2609 *destination = unsmob_duration (sid)->smobbed_copy ();
2610 return DURATION_IDENTIFIER;
2611 } else if (unsmob_output_def (sid)) {
2612 Output_def *p = unsmob_output_def (sid);
2615 *destination = p->self_scm ();
2616 return OUTPUT_DEF_IDENTIFIER;
2617 } else if (Text_interface::is_markup (sid)) {
2619 if (is_lyric_state ())
2620 return LYRIC_MARKUP_IDENTIFIER;
2621 return MARKUP_IDENTIFIER;
2628 property_op_to_music (SCM op)
2631 SCM tag = scm_car (op);
2632 SCM symbol = scm_cadr (op);
2633 SCM args = scm_cddr (op);
2634 SCM grob_val = SCM_UNDEFINED;
2635 SCM grob_path = SCM_UNDEFINED;
2636 SCM val = SCM_UNDEFINED;
2638 if (tag == ly_symbol2scm ("assign"))
2640 m = MY_MAKE_MUSIC ("PropertySet");
2641 val = scm_car (args);
2643 else if (tag == ly_symbol2scm ("unset"))
2644 m = MY_MAKE_MUSIC ("PropertyUnset");
2645 else if (tag == ly_symbol2scm ("push"))
2647 m = MY_MAKE_MUSIC ("OverrideProperty");
2648 grob_val = scm_car (args);
2649 grob_path = scm_cdr (args);
2650 m->set_property ("pop-first", SCM_BOOL_T);
2652 else if (tag == ly_symbol2scm ("pop")) {
2653 m = MY_MAKE_MUSIC ("RevertProperty");
2657 m->set_property ("symbol", symbol);
2659 if (val != SCM_UNDEFINED)
2660 m->set_property ("value", val);
2661 if (grob_val != SCM_UNDEFINED)
2662 m->set_property ("grob-value", grob_val);
2663 if (grob_path != SCM_UNDEFINED)
2664 m->set_property ("grob-property-path", grob_path);
2670 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2672 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2674 csm->set_property ("element", m->self_scm ());
2677 csm->set_property ("context-type",
2678 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2679 csm->set_property ("property-operations", ops);
2681 if (scm_is_string (id))
2682 csm->set_property ("context-id", id);
2687 get_next_unique_context_id ()
2689 return scm_makfrom0str ("$uniqueContextId");
2694 get_next_unique_lyrics_context_id ()
2696 static int new_context_count;
2698 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2699 return scm_makfrom0str (s);
2704 run_music_function (Lily_parser *parser, SCM expr)
2706 SCM func = scm_car (expr);
2707 Input *loc = unsmob_input (scm_cadr (expr));
2708 SCM args = scm_cddr (expr);
2709 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2711 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2714 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2716 parser->error_level_ = 1;
2722 m = scm_apply_0 (func, scm_cons (parser->self_scm(),
2727 if (unsmob_music (m))
2729 retval = unsmob_music (m);
2735 loc->error (_ ("music head function must return Music object"));
2736 retval = MY_MAKE_MUSIC ("Music");
2738 retval->set_spot (*loc);
2743 is_regular_identifier (SCM id)
2745 String str = ly_scm2string (id);
2746 char const *s = str.to_str0 ();
2755 v = v && isalnum (*s);
2763 get_first_context_id (SCM type, Music *m)
2765 SCM id = m->get_property ("context-id");
2766 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2767 && scm_is_string (m->get_property ("context-id"))
2768 && scm_c_string_length (id) > 0)
2776 make_simple_markup (SCM a)
2784 return t && t == 1 << intlog2 (t);
2788 set_music_properties (Music *p, SCM a)
2790 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2791 p->internal_set_property (scm_caar (k), scm_cdar (k));
2796 make_chord_step (int step, int alter)
2803 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2804 return m.smobbed_copy ();
2809 make_chord (SCM pitch, SCM dur, SCM modification_list)
2811 SCM chord_ctor = ly_lily_module_constant ("construct-chord");
2812 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
2814 unsmob_music (ch)->protect();
2819 /* Todo: actually also use apply iso. call too ... */
2821 ly_input_procedure_p (SCM x)
2823 return ly_is_procedure (x)
2824 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2828 set_property_music (SCM sym, SCM value)
2830 Music *p = MY_MAKE_MUSIC ("PropertySet");
2831 p->set_property ("symbol", sym);
2832 p->set_property ("value", value);
2837 make_music_relative (Pitch start, Music *music)
2839 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2840 relative->set_property ("element", music->self_scm ());
2842 Pitch last = music->to_relative_octave (start);
2843 if (lily_1_8_relative)
2844 music->set_property ("last-pitch", last.smobbed_copy ());
2849 make_lyric_combine_music (SCM name, Music *music)
2851 Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
2852 combine->set_property ("element", music->self_scm ());
2853 combine->set_property ("associated-context", name);
2859 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2861 Lily_parser *pars = (Lily_parser*) v;
2862 Lily_lexer *lex = pars->lexer_;
2864 lex->lexval = (void*) s;
2866 lex->prepare_for_next_token ();
2867 return lex->yylex ();