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"
159 %token CHANGE "\\change"
160 %token CHORDMODE "\\chordmode"
161 %token CHORDS "\\chords"
163 %token CONSISTS "\\consists"
164 %token CONTEXT "\\context"
165 %token DEFAULT "\\default"
166 %token DEFAULTCHILD "\\defaultchild"
167 %token DENIES "\\denies"
168 %token DESCRIPTION "\\description"
169 %token DRUMMODE "\\drummode"
170 %token DRUMS "\\drums"
171 %token FIGUREMODE "\\figuremode"
172 %token FIGURES "\\figures"
173 %token GROBDESCRIPTIONS "\\grobdescriptions"
174 %token HEADER "\\header"
175 %token INVALID "\\invalid"
177 %token LAYOUT "\\layout"
178 %token LYRICMODE "\\lyricmode"
179 %token LYRICS "\\lyrics"
180 %token LYRICSTO "\\lyricsto"
182 %token MARKUP "\\markup"
185 %token NOTEMODE "\\notemode"
186 %token OBJECTID "\\objectid"
187 %token OCTAVE "\\octave"
189 %token OVERRIDE "\\override"
190 %token PAPER "\\paper"
191 %token PARTIAL "\\partial"
192 %token RELATIVE "\\relative"
193 %token REMOVE "\\remove"
194 %token REPEAT "\\repeat"
196 %token REVERT "\\revert"
197 %token SCORE "\\score"
198 %token SEQUENTIAL "\\sequential"
200 %token SIMULTANEOUS "\\simultaneous"
202 %token TEMPO "\\tempo"
203 %token TIMES "\\times"
204 %token TRANSPOSE "\\transpose"
205 %token TRANSPOSITION "\\transposition"
207 %token UNSET "\\unset"
210 /* Keyword token exceptions. */
211 %token TIME_T "\\time"
212 %token NEWCONTEXT "\\new"
215 /* Other string tokens. */
217 %token CHORD_BASS "/+"
218 %token CHORD_CARET "^"
219 %token CHORD_COLON ":"
220 %token CHORD_MINUS "-"
221 %token CHORD_SLASH "/"
222 %token DOUBLE_ANGLE_CLOSE ">>"
223 %token DOUBLE_ANGLE_OPEN "<<"
224 %token E_BACKSLASH "\\"
225 %token E_ANGLE_CLOSE "\\>"
226 %token E_CHAR "\\C[haracter]"
228 %token E_EXCLAMATION "\\!"
229 %token E_BRACKET_OPEN "\\["
231 %token E_BRACKET_CLOSE "\\]"
232 %token E_ANGLE_OPEN "\\<"
238 If we give names, Bison complains.
240 %token FIGURE_CLOSE /* "\\>" */
241 %token FIGURE_OPEN /* "\\<" */
242 %token FIGURE_SPACE "_"
245 %token CHORDMODIFIERS
247 %token MULTI_MEASURE_REST
252 %token <i> E_UNSIGNED
255 %token <scm> BOOK_IDENTIFIER
256 %token <scm> CHORDMODIFIER_PITCH
257 %token <scm> CHORD_MODIFIER
258 %token <scm> CONTEXT_DEF_IDENTIFIER
259 %token <scm> DRUM_PITCH
260 %token <scm> DURATION_IDENTIFIER
261 %token <scm> EVENT_IDENTIFIER
262 %token <scm> FRACTION
263 %token <scm> LYRICS_STRING
264 %token <scm> LYRIC_MARKUP_IDENTIFIER
265 %token <scm> MARKUP_HEAD_EMPTY
266 %token <scm> MARKUP_HEAD_LIST0
267 %token <scm> MARKUP_HEAD_MARKUP0
268 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
269 %token <scm> MARKUP_HEAD_SCM0
270 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
271 %token <scm> MARKUP_HEAD_SCM0_SCM1
272 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
273 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
274 %token <scm> MARKUP_IDENTIFIER
275 %token <scm> MUSIC_FUNCTION
276 %token <scm> MUSIC_FUNCTION_MARKUP
277 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
278 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
279 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
280 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
281 %token <scm> MUSIC_FUNCTION_MUSIC
282 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
283 %token <scm> MUSIC_FUNCTION_SCM
284 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
285 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
286 %token <scm> MUSIC_FUNCTION_SCM_SCM
287 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
288 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM
289 %token <scm> MUSIC_IDENTIFIER
290 %token <scm> NOTENAME_PITCH
291 %token <scm> NUMBER_IDENTIFIER
292 %token <scm> OUTPUT_DEF_IDENTIFIER
294 %token <scm> RESTNAME
295 %token <scm> SCM_IDENTIFIER
297 %token <scm> SCORE_IDENTIFIER
299 %token <scm> STRING_IDENTIFIER
300 %token <scm> TONICNAME_PITCH
303 %type <book> book_block
304 %type <book> book_body
306 %type <i> bare_unsigned
307 %type <i> figured_bass_alteration
309 %type <i> exclamations
310 %type <i> optional_rest
315 %type <i> tremolo_type
317 %type <music> Composite_music
318 %type <music> Grouped_music_list
320 %type <music> Prefix_composite_music
321 %type <music> Repeated_music
322 %type <music> Sequential_music
323 %type <music> Simple_music
324 %type <music> Simultaneous_music
325 %type <music> chord_body
326 %type <music> chord_body_element
327 %type <music> command_element
328 %type <music> command_event
329 %type <music> context_change
330 %type <music> direction_less_event
331 %type <music> direction_reqd_event
332 %type <music> event_chord
333 %type <music> gen_text_def
334 %type <music> music_property_def
335 %type <music> note_chord_element
336 %type <music> post_event
337 %type <music> re_rhythmed_music
338 %type <music> relative_music
339 %type <music> simple_element
340 %type <music> string_number_event
341 %type <music> tempo_event
342 %type <music> toplevel_music
344 %type <outputdef> output_def_body
345 %type <outputdef> output_def_head
346 %type <outputdef> output_def
347 %type <outputdef> paper_block
349 %type <scm> Alternative_music
350 %type <scm> Generic_prefix_music_scm
351 %type <scm> Music_list
352 %type <scm> absolute_pitch
353 %type <scm> assignment_id
354 %type <scm> bare_number
355 %type <scm> music_function_event
356 %type <scm> music_function_chord_body
357 %type <scm> bass_figure
358 %type <scm> figured_bass_modification
359 %type <scm> br_bass_figure
360 %type <scm> bass_number
361 %type <scm> chord_body_elements
362 %type <scm> chord_item
363 %type <scm> chord_items
364 %type <scm> chord_separator
365 %type <scm> context_def_mod
366 %type <scm> context_def_spec_block
367 %type <scm> context_def_spec_body
368 %type <scm> context_mod
369 %type <scm> context_mod_list
370 %type <scm> context_prop_spec
371 %type <scm> direction_less_char
372 %type <scm> duration_length
373 %type <scm> embedded_scm
374 %type <scm> figure_list
375 %type <scm> figure_spec
377 %type <scm> full_markup
378 %type <scm> identifier_init
379 %type <scm> lilypond_header
380 %type <scm> lilypond_header_body
381 %type <scm> lyric_element
382 %type <scm> lyric_markup
384 %type <scm> markup_braced_list
385 %type <scm> markup_braced_list_body
386 %type <scm> markup_composed_list
387 %type <scm> markup_head_1_item
388 %type <scm> markup_head_1_list
389 %type <scm> markup_list
390 %type <scm> markup_top
391 %type <scm> mode_changing_head
392 %type <scm> mode_changing_head_with_context
393 %type <scm> multiplied_duration
394 %type <scm> new_chord
395 %type <scm> new_lyrics
396 %type <scm> number_expression
397 %type <scm> number_factor
398 %type <scm> number_term
399 %type <scm> object_id_setting
400 %type <scm> octave_check
401 %type <scm> optional_context_mod
402 %type <scm> optional_notemode_duration
404 %type <scm> pitch_also_in_chords
405 %type <scm> post_events
406 %type <scm> property_operation
408 %type <scm> script_abbreviation
409 %type <scm> simple_markup
410 %type <scm> simple_string
411 %type <scm> steno_duration
412 %type <scm> steno_pitch
413 %type <scm> steno_tonic_pitch
414 %type <scm> step_number
415 %type <scm> step_numbers
417 %type <scm> function_scm_argument
419 %type <score> score_block
420 %type <score> score_body
425 /* We don't assign precedence to / and *, because we might need varied
426 prec levels in different prods */
432 lilypond: /* empty */
433 | lilypond toplevel_expression {
435 | lilypond assignment {
438 THIS->error_level_ = 1;
441 THIS->error_level_ = 1;
447 OBJECTID STRING { $$ = $2; }
452 THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
459 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
460 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
466 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
467 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
472 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
473 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
477 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler");
478 scm_call_2 (proc, THIS->self_scm (), $1);
482 Output_def * od = $1;
484 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
485 id = ly_symbol2scm ("$defaultpaper");
486 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
487 id = ly_symbol2scm ("$defaultmidi");
488 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
489 id = ly_symbol2scm ("$defaultlayout");
491 THIS->lexer_->set_identifier (id, od->self_scm ());
507 lilypond_header_body:
509 $$ = get_header(THIS);
510 THIS->lexer_->add_scope ($$);
512 | lilypond_header_body assignment {
518 HEADER '{' lilypond_header_body '}' {
519 $$ = THIS->lexer_->remove_scope ();
528 | LYRICS_STRING { $$ = $1; }
532 assignment_id '=' identifier_init {
533 if (! is_regular_identifier ($1))
535 @1.warning (_ ("identifier should have alphabetic characters only"));
538 THIS->lexer_->set_identifier ($1, $3);
541 TODO: devise standard for protection in parser.
543 The parser stack lives on the C-stack, which means that
544 all objects can be unprotected as soon as they're here.
554 $$ = $1->self_scm ();
558 $$ = $1->self_scm ();
562 $$ = $1->self_scm ();
565 | context_def_spec_block {
569 $$ = $1->self_scm ();
573 $$ = $1->self_scm ();
576 | number_expression {
589 $$ = scm_from_int ($1);
593 context_def_spec_block:
594 CONTEXT '{' context_def_spec_body '}'
600 context_def_spec_body:
602 $$ = Context_def::make_scm ();
603 unsmob_context_def ($$)->set_spot (@$);
605 | CONTEXT_DEF_IDENTIFIER {
607 unsmob_context_def ($$)->set_spot (@$);
609 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
610 Context_def*td = unsmob_context_def ($$);
612 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
613 SCM tag = scm_caar (p);
615 /* TODO: should make new tag "grob-definition" ? */
616 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
617 tag, scm_cons (scm_cdar (p), SCM_EOL)));
620 | context_def_spec_body context_mod {
621 unsmob_context_def ($$)->add_context_mod ($2);
628 BOOK '{' book_body '}' {
634 * Use 'handlers' like for toplevel-* stuff?
635 * grok \layout and \midi? */
640 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
641 $$->paper_->unprotect ();
642 $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader");
645 $$ = unsmob_book ($1);
648 | book_body paper_block {
652 | book_body score_block {
653 SCM s = $2->self_scm ();
657 | book_body full_markup {
660 | book_body lilypond_header {
665 $$->scores_ = SCM_EOL;
667 | book_body object_id_setting {
668 $$->user_key_ = ly_scm2string ($2);
673 SCORE '{' score_body '}' {
680 SCM m = $1->self_scm ();
682 SCM scorify = ly_lily_module_constant ("scorify-music");
683 SCM score = scm_call_2 (scorify, m, THIS->self_scm ());
685 // pass ownernship to C++ again.
686 $$ = unsmob_score (score);
691 $$ = unsmob_score ($1);
694 | score_body object_id_setting {
695 $$->user_key_ = ly_scm2string ($2);
697 | score_body lilypond_header {
700 | score_body output_def {
701 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
703 THIS->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
713 $$->error_found_ = true;
725 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
727 THIS->parser_error (@1, _ ("need \\paper for paper block"));
728 $$ = get_paper (THIS);
735 output_def_body '}' {
738 THIS->lexer_->remove_scope ();
739 THIS->lexer_->pop_state ();
745 $$ = get_paper (THIS);
746 $$->input_origin_ = @$;
747 THIS->lexer_->add_scope ($$->scope_);
750 Output_def *p = get_midi (THIS);
752 THIS->lexer_->add_scope (p->scope_);
755 Output_def *p = get_layout (THIS);
757 THIS->lexer_->add_scope (p->scope_);
764 output_def_head '{' {
766 $$->input_origin_.set_spot (@$);
767 THIS->lexer_->push_initial_state ();
769 | output_def_head '{' OUTPUT_DEF_IDENTIFIER {
771 Output_def *o = unsmob_output_def ($3);
772 o->input_origin_.set_spot (@$);
774 THIS->lexer_->remove_scope ();
775 THIS->lexer_->add_scope (o->scope_);
776 THIS->lexer_->push_initial_state ();
778 | output_def_body assignment {
781 | output_def_body context_def_spec_block {
782 assign_context_def ($$, $2);
784 | output_def_body tempo_event {
786 junk this ? there already is tempo stuff in
789 int m = scm_to_int ($2->get_property ("metronome-count"));
790 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
791 set_tempo ($$, d->get_length (), m);
794 | output_def_body error {
800 TEMPO steno_duration '=' bare_unsigned {
801 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
802 $$->set_property ("tempo-unit", $2);
803 $$->set_property ("metronome-count", scm_from_int ( $4));
808 The representation of a list is the
812 to have efficient append. */
816 $$ = scm_cons (SCM_EOL, SCM_EOL);
820 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
821 $2->unprotect (); /* UGH */
823 if (scm_is_pair (scm_cdr (s)))
824 scm_set_cdr_x (scm_cdr (s), c); /* append */
826 scm_set_car_x (s, c); /* set first cons */
827 scm_set_cdr_x (s, c); /* remember last cell */
829 | Music_list embedded_scm {
833 Music * m = MY_MAKE_MUSIC("Music");
835 m->set_property ("error-found", SCM_BOOL_T);
837 SCM c = scm_cons (m->self_scm (), SCM_EOL);
838 m->unprotect (); /* UGH */
840 if (scm_is_pair (scm_cdr (s)))
841 scm_set_cdr_x (scm_cdr (s), c); /* append */
843 scm_set_car_x (s, c); /* set first cons */
844 scm_set_cdr_x (s, c); /* remember last cell */
857 | ALTERNATIVE '{' Music_list '}' {
864 REPEAT simple_string bare_unsigned Music Alternative_music
868 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
869 if (times < scm_ilength (alts)) {
870 unsmob_music (scm_car (alts))
871 ->origin ()->warning (
872 _ ("more alternatives than repeats"));
873 warning ("junking excess alternatives");
874 alts = ly_truncate_list (times, alts);
878 SCM proc = ly_lily_module_constant ("make-repeated-music");
880 SCM mus = scm_call_1 (proc, $2);
881 Music *r = unsmob_music (mus);
885 r-> set_property ("element", beg->self_scm ());
888 r->set_property ("repeat-count", scm_from_int (max (times, 1)));
890 r-> set_property ("elements",alts);
891 if (ly_is_equal ($2, scm_makfrom0str ("tremolo"))) {
893 TODO: move this code to Scheme.
896 /* we cannot get durations and other stuff
897 correct down the line,
898 so we have to add to the duration log here. */
899 SCM func = ly_lily_module_constant ("shift-duration-log");
901 int dots = ($3 % 3) ? 0 : 1;
902 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
905 if ($4->is_mus_type ("sequential-music"))
907 int list_len = scm_ilength ($4->get_property ("elements"));
909 $4->origin ()->warning (_f ("expect 2 elements for Chord tremolo, found %d", list_len));
911 r->compress (Moment (Rational (1, list_len)));
913 scm_call_3 (func, r->self_scm (), scm_from_int (shift), scm_from_int (dots));
916 r->set_spot (*$4->origin ());
923 SEQUENTIAL '{' Music_list '}' {
924 $$ = MY_MAKE_MUSIC ("SequentialMusic");
925 $$->set_property ("elements", scm_car ($3));
928 | '{' Music_list '}' {
929 $$ = MY_MAKE_MUSIC ("SequentialMusic");
930 $$->set_property ("elements", scm_car ($2));
936 SIMULTANEOUS '{' Music_list '}'{
937 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
938 $$->set_property ("elements", scm_car ($3));
942 | simul_open Music_list simul_close {
943 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
944 $$->set_property ("elements", scm_car ($2));
950 event_chord { $$ = $1; }
952 $$ = unsmob_music ($1);
959 optional_context_mod:
960 /**/ { $$ = SCM_EOL; }
961 | WITH { THIS->lexer_->push_initial_state (); }
962 '{' context_mod_list '}'
964 THIS->lexer_->pop_state ();
970 /* */ { $$ = SCM_EOL; }
971 | context_mod_list context_mod {
972 $$ = scm_cons ($2, $1);
978 Prefix_composite_music { $$ = $1; }
979 | Grouped_music_list { $$ = $1; }
983 Simultaneous_music { $$ = $1; }
984 | Sequential_music { $$ = $1; }
988 function_scm_argument:
993 Generic_prefix_music_scm:
995 $$ = scm_list_2 ($1, make_input (@$));
997 | MUSIC_FUNCTION_SCM function_scm_argument {
998 $$ = scm_list_3 ($1, make_input (@$), $2);
1000 | MUSIC_FUNCTION_MARKUP full_markup {
1001 $$ = scm_list_3 ($1, make_input (@$), $2);
1004 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument Music {
1005 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1008 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
1009 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1011 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
1012 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1014 | MUSIC_FUNCTION_MUSIC Music {
1015 $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
1018 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument Music {
1019 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
1021 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
1022 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1025 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
1026 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1028 | MUSIC_FUNCTION_MUSIC_MUSIC Music Music {
1029 $$ = scm_list_4 ($1, make_input (@$), $2->self_scm (), $3->self_scm ());
1033 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument Music Music {
1034 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1038 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup Music Music {
1039 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1045 Prefix_composite_music:
1046 Generic_prefix_music_scm {
1047 $$ = run_music_function (THIS, $1);
1049 | CONTEXT simple_string '=' simple_string optional_context_mod Music {
1050 $$ = context_spec_music ($2, $4, $6, $5);
1053 | CONTEXT simple_string optional_context_mod Music {
1054 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1056 | NEWCONTEXT simple_string optional_context_mod Music {
1057 $$ = context_spec_music ($2, get_next_unique_context_id (), $4,
1061 | TIMES fraction Music
1064 int n = scm_to_int (scm_car ($2)); int d = scm_to_int (scm_cdr ($2));
1067 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1070 $$->set_property ("element", mp->self_scm ());
1072 $$->set_property ("numerator", scm_from_int (n));
1073 $$->set_property ("denominator", scm_from_int (d));
1074 $$->compress (Moment (Rational (n,d)));
1077 | Repeated_music { $$ = $1; }
1078 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1079 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1081 Pitch from = *unsmob_pitch ($2);
1082 Pitch to = *unsmob_pitch ($3);
1084 p->transpose (pitch_interval (from, to));
1085 $$->set_property ("element", p->self_scm ());
1088 | mode_changing_head Grouped_music_list {
1089 if ($1 == ly_symbol2scm ("chords"))
1091 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1092 chm->set_property ("element", $2->self_scm ());
1100 THIS->lexer_->pop_state ();
1102 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1103 $$ = context_spec_music ($1, get_next_unique_context_id (),
1105 if ($1 == ly_symbol2scm ("ChordNames"))
1107 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1108 chm->set_property ("element", $$->self_scm ());
1112 THIS->lexer_->pop_state ();
1114 | relative_music { $$ = $1; }
1115 | re_rhythmed_music { $$ = $1; }
1120 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1121 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1123 $$ = ly_symbol2scm ("notes");
1127 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1128 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1130 $$ = ly_symbol2scm ("drums");
1133 THIS->lexer_->push_figuredbass_state ();
1135 $$ = ly_symbol2scm ("figures");
1138 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1139 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1140 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1141 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1142 $$ = ly_symbol2scm ("chords");
1146 { THIS->lexer_->push_lyric_state ();
1147 $$ = ly_symbol2scm ("lyrics");
1151 mode_changing_head_with_context:
1153 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1154 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1156 $$ = ly_symbol2scm ("DrumStaff");
1159 THIS->lexer_->push_figuredbass_state ();
1161 $$ = ly_symbol2scm ("FiguredBass");
1164 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1165 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1166 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1167 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1168 $$ = ly_symbol2scm ("ChordNames");
1171 { THIS->lexer_->push_lyric_state ();
1172 $$ = ly_symbol2scm ("Lyrics");
1178 RELATIVE absolute_pitch Music {
1180 Pitch start = *unsmob_pitch ($2);
1181 $$ = make_music_relative (start, m);
1184 | RELATIVE Composite_music {
1187 Pitch middle_c (0, 0, 0);
1188 $$ = make_music_relative (middle_c, m);
1194 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1196 Grouped_music_list {
1197 /* Can also use Music at the expensive of two S/Rs similar to
1198 \repeat \alternative */
1199 THIS->lexer_->pop_state ();
1201 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1203 | new_lyrics ADDLYRICS {
1204 THIS->lexer_->push_lyric_state ();
1205 } Grouped_music_list {
1206 THIS->lexer_->pop_state ();
1207 $$ = scm_cons ($4->self_scm (), $1);
1212 Grouped_music_list new_lyrics {
1214 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice);
1215 if (!scm_is_string (name))
1217 name = get_next_unique_lyrics_context_id ();
1218 voice = context_spec_music (scm_makfrom0str ("Voice"),
1223 SCM context = scm_makfrom0str ("Lyrics");
1224 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1227 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1229 Music *music = unsmob_music (scm_car (s));
1230 Music *com = make_lyric_combine_music (name, music);
1231 Music *csm = context_spec_music (context,
1232 get_next_unique_context_id (), com, SCM_EOL);
1233 lst = scm_cons (csm->self_scm (), lst);
1235 all->set_property ("elements", scm_cons (voice->self_scm (),
1238 voice->unprotect ();
1240 | LYRICSTO simple_string {
1241 THIS->lexer_->push_lyric_state ();
1243 THIS->lexer_->pop_state ();
1246 $$ = make_lyric_combine_music (name, music);
1252 CHANGE STRING '=' STRING {
1253 Music*t = MY_MAKE_MUSIC ("ContextChange");
1254 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1255 t-> set_property ("change-to-id", $4);
1264 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1265 scm_string_to_symbol ($1), $3);
1267 | UNSET simple_string {
1268 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1269 scm_string_to_symbol ($2));
1271 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1272 $$ = scm_list_4 (ly_symbol2scm ("push"),
1273 scm_string_to_symbol ($2), $5, $3);
1275 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1276 $$ = scm_list_5 (ly_symbol2scm ("push"),
1277 scm_string_to_symbol ($2), $6, $4, $3);
1279 | REVERT simple_string embedded_scm {
1280 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1281 scm_string_to_symbol ($2), $3);
1286 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1287 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1289 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1290 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1291 | DENIES { $$ = ly_symbol2scm ("denies"); }
1293 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1294 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1295 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1296 | NAME { $$ = ly_symbol2scm ("context-name"); }
1300 property_operation { $$ = $1; }
1301 | context_def_mod STRING {
1302 $$ = scm_list_2 ($1, $2);
1308 if (!is_regular_identifier ($1))
1310 @$.error (_("Grob name should be alphanumeric"));
1313 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1314 scm_string_to_symbol ($1));
1316 | simple_string '.' simple_string {
1317 $$ = scm_list_2 (scm_string_to_symbol ($1),
1318 scm_string_to_symbol ($3));
1323 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1324 $$ = property_op_to_music (scm_list_4 (
1325 ly_symbol2scm ("push"),
1328 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1330 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1331 $$ = property_op_to_music (scm_list_5 (
1332 ly_symbol2scm ("push"),
1335 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1337 | REVERT context_prop_spec embedded_scm {
1338 $$ = property_op_to_music (scm_list_3 (
1339 ly_symbol2scm ("pop"),
1343 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1345 | SET context_prop_spec '=' scalar {
1346 $$ = property_op_to_music (scm_list_3 (
1347 ly_symbol2scm ("assign"),
1350 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1352 | UNSET context_prop_spec {
1353 $$ = property_op_to_music (scm_list_2 (
1354 ly_symbol2scm ("unset"),
1356 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1358 | ONCE music_property_def {
1359 SCM e = $2->get_property ("element");
1360 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1371 | STRING_IDENTIFIER {
1374 | string '+' string {
1375 $$ = scm_string_append (scm_list_2 ($1, $3));
1379 simple_string: STRING {
1385 | STRING_IDENTIFIER {
1406 $$ = scm_from_int ($1);
1412 pre_events doesn't contain anything. It is a trick:
1414 Adding pre_events to the simple_element
1415 makes the choice between
1421 simple_element: STRING
1423 a single shift/reduction conflict.
1425 nevertheless, this is not very clean, and we should find a different
1429 pre_events: /* empty */
1433 pre_events simple_element post_events {
1434 SCM elts = $2-> get_property ("elements");
1436 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1438 $2->set_property ("elements", elts);
1439 /* why is this giving wrong start location? -ns
1440 * $2->set_spot (@$); */
1442 i.set_location (@2, @3);
1447 | note_chord_element
1452 chord_body optional_notemode_duration post_events
1454 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1455 SCM es = $1->get_property ("elements");
1456 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1458 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1459 unsmob_music (scm_car (s))->set_property ("duration", dur);
1460 es = ly_append2 (es, postevs);
1462 $1-> set_property ("elements", es);
1474 simul_open: DOUBLE_ANGLE_OPEN
1477 simul_close: DOUBLE_ANGLE_CLOSE
1481 chord_open chord_body_elements chord_close
1483 $$ = MY_MAKE_MUSIC ("EventChord");
1485 $$->set_property ("elements",
1486 scm_reverse_x ($2, SCM_EOL));
1490 chord_body_elements:
1491 /* empty */ { $$ = SCM_EOL; }
1492 | chord_body_elements chord_body_element {
1493 $$ = scm_cons ($2->self_scm (), $1);
1499 pitch exclamations questions octave_check post_events
1506 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1507 n->set_property ("pitch", $1);
1510 n->set_property ("cautionary", SCM_BOOL_T);
1511 if (ex % 2 || q % 2)
1512 n->set_property ("force-accidental", SCM_BOOL_T);
1514 if (scm_is_pair (post)) {
1515 SCM arts = scm_reverse_x (post, SCM_EOL);
1516 n->set_property ("articulations", arts);
1518 if (scm_is_number (check))
1520 int q = scm_to_int (check);
1521 n->set_property ("absolute-octave", scm_from_int (q-1));
1527 | DRUM_PITCH post_events {
1528 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1529 n->set_property ("duration", $2);
1530 n->set_property ("drum-type", $1);
1533 if (scm_is_pair ($2)) {
1534 SCM arts = scm_reverse_x ($2, SCM_EOL);
1535 n->set_property ("articulations", arts);
1539 | music_function_chord_body {
1540 $$ = run_music_function (THIS, $1);
1545 music_function_chord_body:
1547 $$ = scm_list_2 ($1, make_input (@$));
1549 | MUSIC_FUNCTION_MUSIC chord_body_element {
1550 $$ = scm_list_3 ($1, make_input (@$),
1553 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument chord_body_element {
1554 $$ = scm_list_4 ($1, make_input (@$),
1555 $2, $3->self_scm ());
1557 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument
1558 chord_body_element {
1560 $$ = scm_list_5 ($1, make_input (@$),
1561 $2, $3, $4->self_scm ());
1567 ADDQUOTE string Music {
1568 SCM adder = ly_lily_module_constant ("add-quotable");
1570 scm_call_2 (adder, $2, $3->self_scm ());
1577 $$ = MY_MAKE_MUSIC ("EventChord");
1578 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1584 | SKIP duration_length {
1585 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1586 skip->set_property ("duration", $2);
1587 skip->set_spot (@$);
1591 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1594 $$->set_property ("pitch", $2);
1597 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1598 m->set_property ("span-direction", scm_from_int (START));
1601 $$ = MY_MAKE_MUSIC ("EventChord");
1602 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1607 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1608 m->set_property ("span-direction", scm_from_int (STOP));
1611 $$ = MY_MAKE_MUSIC ("EventChord");
1612 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1617 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1621 SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
1623 if (Music * m = unsmob_music (pipe))
1626 $$ = MY_MAKE_MUSIC ("BarCheck");
1630 | TRANSPOSITION pitch {
1632 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1633 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1634 sounds_as_c.smobbed_copy());
1636 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1640 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1642 Music *csm = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1644 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED, csm, SCM_EOL);
1648 | PARTIAL duration_length {
1649 Moment m = - unsmob_duration ($2)->get_length ();
1650 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1652 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1654 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1659 SCM proc = ly_lily_module_constant ("make-clef-set");
1661 SCM result = scm_call_1 (proc, $2);
1662 $$ = unsmob_music (result);
1666 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1668 SCM result = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1669 $$ = unsmob_music (result);
1673 SCM proc = ly_lily_module_constant ("make-mark-set");
1675 SCM result = scm_call_1 (proc, $2);
1676 $$ = unsmob_music (result);
1683 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1686 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1693 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1696 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1698 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1699 if (scm_ilength ($3) > 0)
1701 key->set_property ("pitch-alist", $3);
1702 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1703 key->transpose (* unsmob_pitch ($2));
1705 THIS->parser_error (@3, _ ("second argument must be pitch list"));
1717 | post_events post_event {
1719 $$ = scm_cons ($2->self_scm (), $$);
1724 music_function_event:
1725 MUSIC_FUNCTION_MUSIC post_event {
1726 $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
1728 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument post_event {
1729 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1731 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument post_event {
1732 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
1738 direction_less_event {
1741 | '-' music_function_event {
1742 Music *mus = run_music_function (THIS, $2);
1747 if (!THIS->lexer_->is_lyric_state ())
1748 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1749 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1752 if (!THIS->lexer_->is_lyric_state ())
1753 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1754 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1756 | script_dir direction_reqd_event {
1758 $2->set_property ("direction", scm_from_int ($1));
1761 | script_dir direction_less_event {
1763 $2->set_property ("direction", scm_from_int ($1));
1766 | string_number_event
1769 string_number_event:
1771 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1772 s->set_property ("string-number", scm_from_int ($1));
1778 direction_less_char:
1780 $$ = ly_symbol2scm ("bracketOpenSymbol");
1783 $$ = ly_symbol2scm ("bracketCloseSymbol");
1786 $$ = ly_symbol2scm ("tildeSymbol");
1789 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1792 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1795 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1798 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1801 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1804 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1807 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1811 direction_less_event:
1812 direction_less_char {
1813 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1815 if (unsmob_music (predefd))
1817 m = unsmob_music (predefd)->clone ();
1821 m = MY_MAKE_MUSIC ("Music");
1826 | EVENT_IDENTIFIER {
1827 $$ = unsmob_music ($1);
1830 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1832 a->set_property ("tremolo-type", scm_from_int ($1));
1837 direction_reqd_event:
1841 | script_abbreviation {
1842 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1843 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1844 if (scm_is_string (s))
1845 a->set_property ("articulation-type", s);
1846 else THIS->parser_error (@1, _ ("expecting string as script definition"));
1852 /**/ { $$ = SCM_EOL; }
1853 | '=' { $$ = scm_from_int (0); }
1854 | '=' sub_quotes { $$ = scm_from_int ($2); }
1855 | '=' sup_quotes { $$ = scm_from_int ($2); }
1880 | NOTENAME_PITCH sup_quotes {
1881 Pitch p = *unsmob_pitch ($1);
1882 p = p.transposed (Pitch ($2,0,0));
1883 $$ = p.smobbed_copy ();
1885 | NOTENAME_PITCH sub_quotes {
1886 Pitch p =* unsmob_pitch ($1);
1887 p = p.transposed (Pitch (-$2,0,0));
1888 $$ = p.smobbed_copy ();
1900 | TONICNAME_PITCH sup_quotes {
1901 Pitch p = *unsmob_pitch ($1);
1902 p = p.transposed (Pitch ($2,0,0));
1903 $$ = p.smobbed_copy ();
1905 | TONICNAME_PITCH sub_quotes {
1906 Pitch p =* unsmob_pitch ($1);
1908 p = p.transposed (Pitch (-$2,0,0));
1909 $$ = p.smobbed_copy ();
1919 pitch_also_in_chords:
1926 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1927 t->set_property ("text", $1);
1932 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1933 t->set_property ("text",
1934 make_simple_markup ($1));
1940 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1941 t->set_property ("digit", scm_from_int ($1));
1947 script_abbreviation:
1949 $$ = scm_makfrom0str ("Hat");
1952 $$ = scm_makfrom0str ("Plus");
1955 $$ = scm_makfrom0str ("Dash");
1958 $$ = scm_makfrom0str ("Bar");
1961 $$ = scm_makfrom0str ("Larger");
1964 $$ = scm_makfrom0str ("Dot");
1967 $$ = scm_makfrom0str ("Underscore");
1974 | '-' { $$ = CENTER; }
1985 multiplied_duration {
1990 optional_notemode_duration:
1992 Duration dd = THIS->default_duration_;
1993 $$ = dd.smobbed_copy ();
1995 | multiplied_duration {
1997 THIS->default_duration_ = *unsmob_duration ($$);
2002 bare_unsigned dots {
2004 if (!is_duration ($1))
2005 THIS->parser_error (@1, _f ("not a duration: %d", $1));
2009 $$ = Duration (len, $2).smobbed_copy ();
2011 | DURATION_IDENTIFIER dots {
2012 Duration *d = unsmob_duration ($1);
2013 Duration k (d->duration_log (), d->dot_count () + $2);
2019 multiplied_duration:
2023 | multiplied_duration '*' bare_unsigned {
2024 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2026 | multiplied_duration '*' FRACTION {
2027 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2029 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2034 FRACTION { $$ = $1; }
2035 | UNSIGNED '/' UNSIGNED {
2036 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2053 | ':' bare_unsigned {
2054 if (!is_duration ($2))
2055 THIS->parser_error (@2, _f ("not a duration: %d", $2));
2062 $$ = scm_from_int ($1);
2065 $$ = scm_from_int ($1);
2067 | STRING { $$ = $1; }
2068 | full_markup { $$ = $1; }
2071 figured_bass_alteration:
2079 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2080 $$ = bfr->self_scm ();
2084 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2085 $$ = bfr->self_scm ();
2087 if (scm_is_number ($1))
2088 bfr->set_property ("figure", $1);
2089 else if (Text_interface::is_markup ($1))
2090 bfr->set_property ("text", $1);
2096 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2098 | bass_figure figured_bass_alteration {
2099 Music *m = unsmob_music ($1);
2101 SCM salter = m->get_property ("alteration");
2102 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2103 m->set_property ("alteration",
2104 scm_from_int (alter + $2));
2106 m->set_property ("alteration", scm_from_int (0));
2109 | bass_figure figured_bass_modification {
2110 Music *m = unsmob_music ($1);
2111 if ($2 == ly_symbol2scm ("plus"))
2113 m->set_property ("augmented", SCM_BOOL_T);
2115 else if ($2 == ly_symbol2scm ("slash"))
2117 m->set_property ("diminished", SCM_BOOL_T);
2119 else if ($2 == ly_symbol2scm ("exclamation"))
2121 m->set_property ("no-continuation", SCM_BOOL_T);
2127 figured_bass_modification:
2129 $$ = ly_symbol2scm ("plus");
2132 $$ = ly_symbol2scm ("exclamation");
2135 $$ = ly_symbol2scm ("slash");
2145 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2153 | figure_list br_bass_figure {
2154 $$ = scm_cons ($2, $1);
2159 FIGURE_OPEN figure_list FIGURE_CLOSE {
2160 Music *m = MY_MAKE_MUSIC ("EventChord");
2161 $2 = scm_reverse_x ($2, SCM_EOL);
2162 m->set_property ("elements", $2);
2163 $$ = m->self_scm ();
2174 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2175 if (!THIS->lexer_->is_note_state ())
2176 THIS->parser_error (@1, _ ("have to be in Note mode for notes"));
2180 n = MY_MAKE_MUSIC ("RestEvent");
2182 n = MY_MAKE_MUSIC ("NoteEvent");
2184 n->set_property ("pitch", $1);
2185 n->set_property ("duration", $5);
2187 if (scm_is_number ($4))
2189 int q = scm_to_int ($4);
2190 n->set_property ("absolute-octave", scm_from_int (q-1));
2194 n->set_property ("cautionary", SCM_BOOL_T);
2195 if ($2 % 2 || $3 % 2)
2196 n->set_property ("force-accidental", SCM_BOOL_T);
2198 Music *v = MY_MAKE_MUSIC ("EventChord");
2199 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2206 | DRUM_PITCH optional_notemode_duration {
2207 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2208 n->set_property ("duration", $2);
2209 n->set_property ("drum-type", $1);
2211 Music *v = MY_MAKE_MUSIC ("EventChord");
2212 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2219 | figure_spec optional_notemode_duration {
2220 Music *m = unsmob_music ($1);
2222 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2224 unsmob_music (scm_car (s))->set_property ("duration", $2);
2228 | RESTNAME optional_notemode_duration {
2230 if (ly_scm2string ($1) == "s") {
2232 ev = MY_MAKE_MUSIC ("SkipEvent");
2235 ev = MY_MAKE_MUSIC ("RestEvent");
2238 ev->set_property ("duration", $2);
2240 Music *velt = MY_MAKE_MUSIC ("EventChord");
2241 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2242 velt->set_spot (@$);
2248 | MULTI_MEASURE_REST optional_notemode_duration {
2249 SCM proc = ly_lily_module_constant ("make-multi-measure-rest");
2250 SCM mus = scm_call_2 (proc, $2, make_input (@$));
2251 $$ = unsmob_music (mus);
2255 | lyric_element optional_notemode_duration {
2256 if (!THIS->lexer_->is_lyric_state ())
2257 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2259 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2260 levent->set_property ("text", $1);
2261 levent->set_property ("duration",$2);
2262 levent->set_spot (@$);
2263 Music *velt = MY_MAKE_MUSIC ("EventChord");
2264 velt->set_property ("elements", scm_list_1 (levent->self_scm ()));
2269 if (!THIS->lexer_->is_chord_state ())
2270 THIS->parser_error (@1, _ ("have to be in Chord mode for chords"));
2271 $$ = unsmob_music ($1);
2285 steno_tonic_pitch optional_notemode_duration {
2286 $$ = make_chord ($1, $2, SCM_EOL);
2288 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2289 SCM its = scm_reverse_x ($4, SCM_EOL);
2290 $$ = make_chord ($1, $2, scm_cons ($3, its));
2298 | chord_items chord_item {
2299 $$ = scm_cons ($2, $$);
2305 $$ = ly_symbol2scm ("chord-colon");
2308 $$ = ly_symbol2scm ("chord-caret");
2310 | CHORD_SLASH steno_tonic_pitch {
2311 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2313 | CHORD_BASS steno_tonic_pitch {
2314 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2323 $$ = scm_reverse_x ($1, SCM_EOL);
2331 step_number { $$ = scm_cons ($1, SCM_EOL); }
2332 | step_numbers '.' step_number {
2333 $$ = scm_cons ($3, $$);
2339 $$ = make_chord_step ($1, 0);
2341 | bare_unsigned '+' {
2342 $$ = make_chord_step ($1, SHARP);
2344 | bare_unsigned CHORD_MINUS {
2345 $$ = make_chord_step ($1, FLAT);
2352 TODO: should deprecate in favor of Scheme?
2356 number_expression '+' number_term {
2357 $$ = scm_sum ($1, $3);
2359 | number_expression '-' number_term {
2360 $$ = scm_difference ($1, $3);
2369 | number_factor '*' number_factor {
2370 $$ = scm_product ($1, $3);
2372 | number_factor '/' number_factor {
2373 $$ = scm_divide ($1, $3);
2378 '-' number_factor { /* %prec UNARY_MINUS */
2379 $$ = scm_difference ($2, SCM_UNDEFINED);
2387 $$ = scm_from_int ($1);
2392 | NUMBER_IDENTIFIER {
2395 | REAL NUMBER_IDENTIFIER {
2396 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2398 | UNSIGNED NUMBER_IDENTIFIER {
2399 $$ = scm_from_double ($1 *scm_to_double ($2));
2415 | exclamations '!' { $$ ++; }
2420 | questions '?' { $$ ++; }
2424 This should be done more dynamically if possible.
2428 LYRIC_MARKUP_IDENTIFIER {
2432 { THIS->lexer_->push_markup_state (); }
2435 THIS->lexer_->pop_state ();
2444 { THIS->lexer_->push_markup_state (); }
2447 THIS->lexer_->pop_state ();
2453 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2455 | markup_head_1_list simple_markup {
2456 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2464 markup_composed_list {
2467 | markup_braced_list {
2472 markup_composed_list:
2473 markup_head_1_list markup_braced_list {
2474 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2480 '{' markup_braced_list_body '}' {
2481 $$ = scm_reverse_x ($2, SCM_EOL);
2485 markup_braced_list_body:
2486 /* empty */ { $$ = SCM_EOL; }
2487 | markup_braced_list_body markup {
2488 $$ = scm_cons ($2, $1);
2490 | markup_braced_list_body markup_list {
2491 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2496 MARKUP_HEAD_MARKUP0 {
2497 $$ = scm_list_1 ($1);
2499 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2500 $$ = scm_list_2 ($1, $2);
2502 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2503 $$ = scm_list_3 ($1, $2, $3);
2508 markup_head_1_item {
2509 $$ = scm_list_1 ($1);
2511 | markup_head_1_list markup_head_1_item {
2512 $$ = scm_cons ($2, $1);
2518 $$ = make_simple_markup ($1);
2520 | MARKUP_IDENTIFIER {
2523 | LYRIC_MARKUP_IDENTIFIER {
2526 | STRING_IDENTIFIER {
2530 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2531 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2532 } '{' score_body '}' {
2534 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2536 THIS->lexer_->pop_state ();
2538 | MARKUP_HEAD_SCM0 embedded_scm {
2539 $$ = scm_list_2 ($1, $2);
2541 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2542 $$ = scm_list_4 ($1, $2, $3, $4);
2544 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2545 $$ = scm_list_3 ($1, $2, $3);
2547 | MARKUP_HEAD_EMPTY {
2548 $$ = scm_list_1 ($1);
2550 | MARKUP_HEAD_LIST0 markup_list {
2551 $$ = scm_list_2 ($1,$2);
2553 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2554 $$ = scm_list_3 ($1, $2, $3);
2559 markup_head_1_list simple_markup {
2560 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2561 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2571 Lily_parser::set_yydebug (bool )
2579 Lily_parser::do_yyparse ()
2581 yyparse ((void*)this);
2590 It is a little strange to have this function in this file, but
2591 otherwise, we have to import music classes into the lexer.
2595 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2597 if (scm_is_string (sid)) {
2599 return STRING_IDENTIFIER;
2600 } else if (unsmob_book (sid)) {
2601 *destination = unsmob_book (sid)->clone ()->self_scm ();
2602 return BOOK_IDENTIFIER;
2603 } else if (scm_is_number (sid)) {
2605 return NUMBER_IDENTIFIER;
2606 } else if (unsmob_context_def (sid)) {
2607 *destination = unsmob_context_def (sid)->clone_scm ();
2608 return CONTEXT_DEF_IDENTIFIER;
2609 } else if (unsmob_score (sid)) {
2610 Score *score = new Score (*unsmob_score (sid));
2611 *destination = score->self_scm ();
2612 return SCORE_IDENTIFIER;
2613 } else if (Music *mus = unsmob_music (sid)) {
2614 mus = mus->clone ();
2615 *destination = mus->self_scm ();
2616 unsmob_music (*destination)->
2617 set_property ("origin", make_input (last_input_));
2619 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2622 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2623 } else if (unsmob_duration (sid)) {
2624 *destination = unsmob_duration (sid)->smobbed_copy ();
2625 return DURATION_IDENTIFIER;
2626 } else if (unsmob_output_def (sid)) {
2627 Output_def *p = unsmob_output_def (sid);
2630 *destination = p->self_scm ();
2631 return OUTPUT_DEF_IDENTIFIER;
2632 } else if (Text_interface::is_markup (sid)) {
2634 if (is_lyric_state ())
2635 return LYRIC_MARKUP_IDENTIFIER;
2636 return MARKUP_IDENTIFIER;
2643 property_op_to_music (SCM op)
2646 SCM tag = scm_car (op);
2647 SCM symbol = scm_cadr (op);
2648 SCM args = scm_cddr (op);
2649 SCM grob_val = SCM_UNDEFINED;
2650 SCM grob_path = SCM_UNDEFINED;
2651 SCM val = SCM_UNDEFINED;
2653 if (tag == ly_symbol2scm ("assign"))
2655 m = MY_MAKE_MUSIC ("PropertySet");
2656 val = scm_car (args);
2658 else if (tag == ly_symbol2scm ("unset"))
2659 m = MY_MAKE_MUSIC ("PropertyUnset");
2660 else if (tag == ly_symbol2scm ("push"))
2662 m = MY_MAKE_MUSIC ("OverrideProperty");
2663 grob_val = scm_car (args);
2664 grob_path = scm_cdr (args);
2665 m->set_property ("pop-first", SCM_BOOL_T);
2667 else if (tag == ly_symbol2scm ("pop")) {
2668 m = MY_MAKE_MUSIC ("RevertProperty");
2672 m->set_property ("symbol", symbol);
2674 if (val != SCM_UNDEFINED)
2675 m->set_property ("value", val);
2676 if (grob_val != SCM_UNDEFINED)
2677 m->set_property ("grob-value", grob_val);
2678 if (grob_path != SCM_UNDEFINED)
2679 m->set_property ("grob-property-path", grob_path);
2685 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2687 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2689 csm->set_property ("element", m->self_scm ());
2692 csm->set_property ("context-type",
2693 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2694 csm->set_property ("property-operations", ops);
2696 if (scm_is_string (id))
2697 csm->set_property ("context-id", id);
2702 get_next_unique_context_id ()
2704 return scm_makfrom0str ("$uniqueContextId");
2709 get_next_unique_lyrics_context_id ()
2711 static int new_context_count;
2713 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2714 return scm_makfrom0str (s);
2719 run_music_function (Lily_parser *parser, SCM expr)
2721 SCM func = scm_car (expr);
2722 Input *loc = unsmob_input (scm_cadr (expr));
2723 SCM args = scm_cddr (expr);
2724 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2726 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2729 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2731 parser->error_level_ = 1;
2737 m = scm_apply_0 (func, scm_cons (parser->self_scm(),
2742 if (unsmob_music (m))
2744 retval = unsmob_music (m);
2750 loc->error (_ ("music head function must return Music object"));
2751 retval = MY_MAKE_MUSIC ("Music");
2753 retval->set_spot (*loc);
2758 is_regular_identifier (SCM id)
2760 String str = ly_scm2string (id);
2761 char const *s = str.to_str0 ();
2770 v = v && isalnum (*s);
2778 get_first_context_id (SCM type, Music *m)
2780 SCM id = m->get_property ("context-id");
2781 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2782 && scm_is_string (m->get_property ("context-id"))
2783 && scm_c_string_length (id) > 0)
2791 make_simple_markup (SCM a)
2799 return t && t == 1 << intlog2 (t);
2803 set_music_properties (Music *p, SCM a)
2805 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2806 p->internal_set_property (scm_caar (k), scm_cdar (k));
2811 make_chord_step (int step, int alter)
2818 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2819 return m.smobbed_copy ();
2824 make_chord (SCM pitch, SCM dur, SCM modification_list)
2826 SCM chord_ctor = ly_lily_module_constant ("construct-chord");
2827 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
2829 unsmob_music (ch)->protect();
2834 /* Todo: actually also use apply iso. call too ... */
2836 ly_input_procedure_p (SCM x)
2838 return ly_is_procedure (x)
2839 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2843 set_property_music (SCM sym, SCM value)
2845 Music *p = MY_MAKE_MUSIC ("PropertySet");
2846 p->set_property ("symbol", sym);
2847 p->set_property ("value", value);
2852 make_music_relative (Pitch start, Music *music)
2854 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2855 relative->set_property ("element", music->self_scm ());
2857 Pitch last = music->to_relative_octave (start);
2858 if (lily_1_8_relative)
2859 music->set_property ("last-pitch", last.smobbed_copy ());
2864 make_lyric_combine_music (SCM name, Music *music)
2866 Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
2867 combine->set_property ("element", music->self_scm ());
2868 combine->set_property ("associated-context", name);
2874 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2876 Lily_parser *pars = (Lily_parser*) v;
2877 Lily_lexer *lex = pars->lexer_;
2879 lex->lexval = (void*) s;
2881 lex->prepare_for_next_token ();
2882 return lex->yylex ();