2 parser.yy -- Bison/C++ parser for LilyPond
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
12 #define YYERROR_VERBOSE 1
13 #define YYPARSE_PARAM my_lily_parser
14 #define YYLEX_PARAM my_lily_parser
16 ((Lily_parser *) my_lily_parser)
18 #define yyerror THIS->parser_error
20 /* We use custom location type: Input objects */
22 #define YYLLOC_DEFAULT(Current,Rhs,N) \
23 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
28 /* We use SCMs to do strings, because it saves us the trouble of
29 deleting them. Let's hope that a stack overflow doesnt trigger a move
30 of the parse stack onto the heap. */
38 /* One shift/reduce problem
41 \repeat .. \alternative
43 \repeat { \repeat .. \alternative }
47 \repeat { \repeat } \alternative
56 %{ // -*-Fundamental-*-
61 * The rules for who is protecting what are very shady. Uniformise
64 * There are too many lexical modes?
75 #include "context-def.hh"
76 #include "dimensions.hh"
77 #include "file-path.hh"
78 #include "input-smob.hh"
80 #include "international.hh"
81 #include "lily-guile.hh"
82 #include "lily-lexer.hh"
83 #include "lily-parser.hh"
84 #include "lilypond-input-version.hh"
89 #include "output-def.hh"
90 #include "paper-book.hh"
91 #include "program-option.hh"
92 #include "scm-hash.hh"
94 #include "text-interface.hh"
102 Output_def *outputdef;
112 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
114 Music *property_op_to_music (SCM op);
115 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops, bool create_new);
116 SCM get_next_unique_context_id ();
117 SCM get_next_unique_lyrics_context_id ();
124 #define _(x) gettext (x)
129 Music *make_lyric_combine_music (SCM name, Music *music);
130 Music *make_music_relative (Pitch start, Music *music);
131 Music *run_music_function (Lily_parser *, SCM expr);
132 Music *set_property_music (SCM sym, SCM value);
133 SCM get_first_context_id (SCM type, Music *m);
134 SCM make_chord (SCM pitch, SCM dur, SCM modification_list);
135 SCM make_chord_step (int step, int alter);
136 SCM make_simple_markup (SCM a);
137 bool is_duration (int t);
138 bool is_regular_identifier (SCM id);
139 bool ly_input_procedure_p (SCM x);
140 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
141 void set_music_properties (Music *p, SCM a);
145 /* The third option is an alias that will be used to display the
146 syntax error. Bison CVS now correctly handles backslash escapes.
148 FIXME: Bison needs to translate some of these, eg, STRING.
152 /* Keyword tokens with plain escaped name. */
153 %token ACCEPTS "\\accepts"
154 %token ADDLYRICS "\\addlyrics"
155 %token ADDQUOTE "\\addquote"
156 %token ALIAS "\\alias"
157 %token ALTERNATIVE "\\alternative"
159 %token CHANGE "\\change"
160 %token CHORDMODE "\\chordmode"
161 %token CHORDS "\\chords"
162 %token CONSISTS "\\consists"
163 %token CONTEXT "\\context"
164 %token DEFAULT "\\default"
165 %token DEFAULTCHILD "\\defaultchild"
166 %token DENIES "\\denies"
167 %token DESCRIPTION "\\description"
168 %token DRUMMODE "\\drummode"
169 %token DRUMS "\\drums"
170 %token FIGUREMODE "\\figuremode"
171 %token FIGURES "\\figures"
172 %token GROBDESCRIPTIONS "\\grobdescriptions"
173 %token HEADER "\\header"
174 %token INVALID "\\invalid"
176 %token LAYOUT "\\layout"
177 %token LYRICMODE "\\lyricmode"
178 %token LYRICS "\\lyrics"
179 %token LYRICSTO "\\lyricsto"
181 %token MARKUP "\\markup"
184 %token NOTEMODE "\\notemode"
185 %token OBJECTID "\\objectid"
186 %token OCTAVE "\\octave"
188 %token OVERRIDE "\\override"
189 %token PAPER "\\paper"
190 %token PARTIAL "\\partial"
191 %token RELATIVE "\\relative"
192 %token REMOVE "\\remove"
193 %token REPEAT "\\repeat"
195 %token REVERT "\\revert"
196 %token SCORE "\\score"
197 %token SEQUENTIAL "\\sequential"
199 %token SIMULTANEOUS "\\simultaneous"
201 %token TEMPO "\\tempo"
202 %token TIMES "\\times"
203 %token TRANSPOSE "\\transpose"
204 %token TRANSPOSITION "\\transposition"
206 %token UNSET "\\unset"
209 /* Keyword token exceptions. */
210 %token TIME_T "\\time"
211 %token NEWCONTEXT "\\new"
214 /* Other string tokens. */
216 %token CHORD_BASS "/+"
217 %token CHORD_CARET "^"
218 %token CHORD_COLON ":"
219 %token CHORD_MINUS "-"
220 %token CHORD_SLASH "/"
221 %token DOUBLE_ANGLE_CLOSE ">>"
222 %token DOUBLE_ANGLE_OPEN "<<"
223 %token E_BACKSLASH "\\"
224 %token E_ANGLE_CLOSE "\\>"
225 %token E_CHAR "\\C[haracter]"
227 %token E_EXCLAMATION "\\!"
228 %token E_BRACKET_OPEN "\\["
230 %token E_BRACKET_CLOSE "\\]"
231 %token E_ANGLE_OPEN "\\<"
237 If we give names, Bison complains.
239 %token FIGURE_CLOSE /* "\\>" */
240 %token FIGURE_OPEN /* "\\<" */
241 %token FIGURE_SPACE "_"
244 %token CHORDMODIFIERS
246 %token MULTI_MEASURE_REST
251 %token <i> E_UNSIGNED
254 %token <scm> BOOK_IDENTIFIER
255 %token <scm> CHORDMODIFIER_PITCH
256 %token <scm> CHORD_MODIFIER
257 %token <scm> CONTEXT_DEF_IDENTIFIER
258 %token <scm> DRUM_PITCH
259 %token <scm> DURATION_IDENTIFIER
260 %token <scm> EVENT_IDENTIFIER
261 %token <scm> FRACTION
262 %token <scm> LYRICS_STRING
263 %token <scm> LYRIC_MARKUP_IDENTIFIER
264 %token <scm> MARKUP_HEAD_EMPTY
265 %token <scm> MARKUP_HEAD_LIST0
266 %token <scm> MARKUP_HEAD_MARKUP0
267 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
268 %token <scm> MARKUP_HEAD_SCM0
269 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
270 %token <scm> MARKUP_HEAD_SCM0_SCM1
271 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
272 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
273 %token <scm> MARKUP_IDENTIFIER
274 %token <scm> MUSIC_FUNCTION
275 %token <scm> MUSIC_FUNCTION_MARKUP
276 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
277 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
278 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
279 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
280 %token <scm> MUSIC_FUNCTION_MUSIC
281 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
282 %token <scm> MUSIC_FUNCTION_SCM
283 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
284 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
285 %token <scm> MUSIC_FUNCTION_SCM_SCM_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_FUNCTION_SCM_SCM_SCM_MUSIC
290 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC
291 %token <scm> MUSIC_IDENTIFIER
292 %token <scm> NOTENAME_PITCH
293 %token <scm> NUMBER_IDENTIFIER
294 %token <scm> OUTPUT_DEF_IDENTIFIER
296 %token <scm> RESTNAME
297 %token <scm> SCM_IDENTIFIER
299 %token <scm> SCORE_IDENTIFIER
301 %token <scm> STRING_IDENTIFIER
302 %token <scm> TONICNAME_PITCH
305 %type <book> book_block
306 %type <book> book_body
308 %type <i> bare_unsigned
309 %type <i> figured_bass_alteration
311 %type <i> exclamations
312 %type <i> optional_rest
317 %type <i> tremolo_type
319 %type <music> Composite_music
320 %type <music> Grouped_music_list
322 %type <music> Prefix_composite_music
323 %type <music> Repeated_music
324 %type <music> Sequential_music
325 %type <music> Simple_music
326 %type <music> Simultaneous_music
327 %type <music> chord_body
328 %type <music> chord_body_element
329 %type <music> command_element
330 %type <music> command_event
331 %type <music> context_change
332 %type <music> direction_less_event
333 %type <music> direction_reqd_event
334 %type <music> event_chord
335 %type <music> gen_text_def
336 %type <music> music_property_def
337 %type <music> note_chord_element
338 %type <music> post_event
339 %type <music> re_rhythmed_music
340 %type <music> relative_music
341 %type <music> simple_element
342 %type <music> string_number_event
343 %type <music> tempo_event
344 %type <music> toplevel_music
346 %type <outputdef> output_def_body
347 %type <outputdef> output_def_head
348 %type <outputdef> output_def_head_with_mode_switch
349 %type <outputdef> output_def
350 %type <outputdef> paper_block
352 %type <scm> Alternative_music
353 %type <scm> Generic_prefix_music_scm
354 %type <scm> Music_list
355 %type <scm> absolute_pitch
356 %type <scm> assignment_id
357 %type <scm> bare_number
358 %type <scm> music_function_event
359 %type <scm> music_function_chord_body
360 %type <scm> music_function_musicless_prefix
361 %type <scm> bass_figure
362 %type <scm> figured_bass_modification
363 %type <scm> br_bass_figure
364 %type <scm> bass_number
365 %type <scm> chord_body_elements
366 %type <scm> chord_item
367 %type <scm> chord_items
368 %type <scm> chord_separator
369 %type <scm> context_def_mod
370 %type <scm> context_def_spec_block
371 %type <scm> context_def_spec_body
372 %type <scm> context_mod
373 %type <scm> context_mod_list
374 %type <scm> context_prop_spec
375 %type <scm> direction_less_char
376 %type <scm> duration_length
377 %type <scm> embedded_scm
378 %type <scm> figure_list
379 %type <scm> figure_spec
381 %type <scm> full_markup
382 %type <scm> identifier_init
383 %type <scm> lilypond_header
384 %type <scm> lilypond_header_body
385 %type <scm> lyric_element
386 %type <scm> lyric_markup
388 %type <scm> markup_braced_list
389 %type <scm> markup_braced_list_body
390 %type <scm> markup_composed_list
391 %type <scm> markup_head_1_item
392 %type <scm> markup_head_1_list
393 %type <scm> markup_list
394 %type <scm> markup_top
395 %type <scm> mode_changing_head
396 %type <scm> mode_changing_head_with_context
397 %type <scm> multiplied_duration
398 %type <scm> new_chord
399 %type <scm> new_lyrics
400 %type <scm> number_expression
401 %type <scm> number_factor
402 %type <scm> number_term
403 %type <scm> object_id_setting
404 %type <scm> octave_check
405 %type <scm> optional_context_mod
406 %type <scm> optional_id
407 %type <scm> optional_notemode_duration
409 %type <scm> pitch_also_in_chords
410 %type <scm> post_events
411 %type <scm> property_operation
413 %type <scm> script_abbreviation
414 %type <scm> simple_markup
415 %type <scm> simple_string
416 %type <scm> steno_duration
417 %type <scm> steno_pitch
418 %type <scm> steno_tonic_pitch
419 %type <scm> step_number
420 %type <scm> step_numbers
422 %type <scm> function_scm_argument
424 %type <score> score_block
425 %type <score> score_body
430 /* We don't assign precedence to / and *, because we might need varied
431 prec levels in different prods */
437 lilypond: /* empty */
438 | lilypond toplevel_expression {
440 | lilypond assignment {
443 THIS->error_level_ = 1;
446 THIS->error_level_ = 1;
452 OBJECTID STRING { $$ = $2; }
457 THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
461 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
462 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
468 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
469 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
474 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
475 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
479 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler");
480 scm_call_2 (proc, THIS->self_scm (), $1);
484 Output_def * od = $1;
486 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
487 id = ly_symbol2scm ("$defaultpaper");
488 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
489 id = ly_symbol2scm ("$defaultmidi");
490 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
491 id = ly_symbol2scm ("$defaultlayout");
493 THIS->lexer_->set_identifier (id, od->self_scm ());
509 lilypond_header_body:
511 $$ = get_header(THIS);
512 THIS->lexer_->add_scope ($$);
514 | lilypond_header_body assignment {
520 HEADER '{' lilypond_header_body '}' {
521 $$ = THIS->lexer_->remove_scope ();
530 | LYRICS_STRING { $$ = $1; }
534 assignment_id '=' identifier_init {
535 if (! is_regular_identifier ($1))
538 /* no longer valid with dashes in \paper{} block. */
539 @1.warning (_ ("identifier should have alphabetic characters only"));
544 THIS->lexer_->set_identifier ($1, $3);
547 TODO: devise standard for protection in parser.
549 The parser stack lives on the C-stack, which means that
550 all objects can be unprotected as soon as they're here.
560 $$ = $1->self_scm ();
564 $$ = $1->self_scm ();
568 $$ = $1->self_scm ();
571 | context_def_spec_block {
575 $$ = $1->self_scm ();
579 $$ = $1->self_scm ();
582 | number_expression {
595 $$ = scm_from_int ($1);
599 context_def_spec_block:
600 CONTEXT '{' context_def_spec_body '}'
606 context_def_spec_body:
608 $$ = Context_def::make_scm ();
609 unsmob_context_def ($$)->set_spot (@$);
611 | CONTEXT_DEF_IDENTIFIER {
613 unsmob_context_def ($$)->set_spot (@$);
615 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
616 Context_def*td = unsmob_context_def ($$);
618 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
619 SCM tag = scm_caar (p);
621 /* TODO: should make new tag "grob-definition" ? */
622 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
623 tag, scm_cons (scm_cdar (p), SCM_EOL)));
626 | context_def_spec_body context_mod {
627 unsmob_context_def ($$)->add_context_mod ($2);
634 BOOK '{' book_body '}' {
640 * Use 'handlers' like for toplevel-* stuff?
641 * grok \layout and \midi? */
646 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
647 $$->paper_->unprotect ();
648 $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader");
651 $$ = unsmob_book ($1);
654 | book_body paper_block {
658 | book_body score_block {
659 SCM s = $2->self_scm ();
663 | book_body full_markup {
666 | book_body lilypond_header {
671 $$->scores_ = SCM_EOL;
673 | book_body object_id_setting {
674 $$->user_key_ = ly_scm2string ($2);
679 SCORE '{' score_body '}' {
686 SCM m = $1->self_scm ();
688 SCM scorify = ly_lily_module_constant ("scorify-music");
689 SCM score = scm_call_2 (scorify, m, THIS->self_scm ());
691 // pass ownernship to C++ again.
692 $$ = unsmob_score (score);
697 $$ = unsmob_score ($1);
700 | score_body object_id_setting {
701 $$->user_key_ = ly_scm2string ($2);
703 | score_body lilypond_header {
706 | score_body output_def {
707 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
709 THIS->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
714 $$->add_output_def ($2);
719 $$->error_found_ = true;
731 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
733 THIS->parser_error (@1, _ ("need \\paper for paper block"));
734 $$ = get_paper (THIS);
741 output_def_body '}' {
744 THIS->lexer_->remove_scope ();
745 THIS->lexer_->pop_state ();
751 $$ = get_paper (THIS);
752 $$->input_origin_ = @$;
753 THIS->lexer_->add_scope ($$->scope_);
756 Output_def *p = get_midi (THIS);
758 THIS->lexer_->add_scope (p->scope_);
761 Output_def *p = get_layout (THIS);
763 THIS->lexer_->add_scope (p->scope_);
768 output_def_head_with_mode_switch:
770 THIS->lexer_->push_initial_state ();
776 output_def_head_with_mode_switch '{' {
778 $$->input_origin_.set_spot (@$);
780 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
782 Output_def *o = unsmob_output_def ($3);
783 o->input_origin_.set_spot (@$);
785 THIS->lexer_->remove_scope ();
786 THIS->lexer_->add_scope (o->scope_);
788 | output_def_body assignment {
791 | output_def_body context_def_spec_block {
792 assign_context_def ($$, $2);
794 | output_def_body tempo_event {
796 junk this ? there already is tempo stuff in
799 int m = scm_to_int ($2->get_property ("metronome-count"));
800 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
801 set_tempo ($$, d->get_length (), m);
804 | output_def_body error {
810 TEMPO steno_duration '=' bare_unsigned {
811 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
812 $$->set_property ("tempo-unit", $2);
813 $$->set_property ("metronome-count", scm_from_int ( $4));
818 The representation of a list is the
822 to have efficient append. */
826 $$ = scm_cons (SCM_EOL, SCM_EOL);
830 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
831 $2->unprotect (); /* UGH */
833 if (scm_is_pair (scm_cdr (s)))
834 scm_set_cdr_x (scm_cdr (s), c); /* append */
836 scm_set_car_x (s, c); /* set first cons */
837 scm_set_cdr_x (s, c); /* remember last cell */
839 | Music_list embedded_scm {
843 Music * m = MY_MAKE_MUSIC("Music");
845 m->set_property ("error-found", SCM_BOOL_T);
847 SCM c = scm_cons (m->self_scm (), SCM_EOL);
848 m->unprotect (); /* UGH */
850 if (scm_is_pair (scm_cdr (s)))
851 scm_set_cdr_x (scm_cdr (s), c); /* append */
853 scm_set_car_x (s, c); /* set first cons */
854 scm_set_cdr_x (s, c); /* remember last cell */
867 | ALTERNATIVE '{' Music_list '}' {
874 REPEAT simple_string bare_unsigned Music Alternative_music
876 SCM proc = ly_lily_module_constant ("make-repeat");
877 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
879 SCM mus = scm_call_4 (proc, $2, scm_int2num ($3), $4->self_scm (), alts);
880 Music *r = unsmob_music (mus);
884 r->set_spot (*$4->origin ());
891 SEQUENTIAL '{' Music_list '}' {
892 $$ = MY_MAKE_MUSIC ("SequentialMusic");
893 $$->set_property ("elements", scm_car ($3));
896 | '{' Music_list '}' {
897 $$ = MY_MAKE_MUSIC ("SequentialMusic");
898 $$->set_property ("elements", scm_car ($2));
904 SIMULTANEOUS '{' Music_list '}'{
905 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
906 $$->set_property ("elements", scm_car ($3));
910 | simul_open Music_list simul_close {
911 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
912 $$->set_property ("elements", scm_car ($2));
918 event_chord { $$ = $1; }
920 $$ = unsmob_music ($1);
926 optional_context_mod:
927 /**/ { $$ = SCM_EOL; }
928 | WITH { THIS->lexer_->push_initial_state (); }
929 '{' context_mod_list '}'
931 THIS->lexer_->pop_state ();
937 /* */ { $$ = SCM_EOL; }
938 | context_mod_list context_mod {
939 $$ = scm_cons ($2, $1);
944 Prefix_composite_music { $$ = $1; }
945 | Grouped_music_list { $$ = $1; }
949 Simultaneous_music { $$ = $1; }
950 | Sequential_music { $$ = $1; }
953 function_scm_argument:
959 TODO: use code generation for this
961 Generic_prefix_music_scm:
963 $$ = scm_list_2 ($1, make_input (@$));
965 | MUSIC_FUNCTION_SCM function_scm_argument {
966 $$ = scm_list_3 ($1, make_input (@$), $2);
968 | MUSIC_FUNCTION_MARKUP full_markup {
969 $$ = scm_list_3 ($1, make_input (@$), $2);
971 | music_function_musicless_prefix Music {
972 $$ = ly_append2 ($1, scm_list_1 ($2->self_scm ()));
975 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
976 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
978 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
979 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
981 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
982 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
985 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
986 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
988 | MUSIC_FUNCTION_MUSIC_MUSIC Music Music {
989 $$ = scm_list_4 ($1, make_input (@$), $2->self_scm (), $3->self_scm ());
993 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument Music Music {
994 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
998 | MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC function_scm_argument function_scm_argument Music Music {
999 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4->self_scm (), $5->self_scm (), SCM_UNDEFINED);
1003 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup Music Music {
1004 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1011 /**/ { $$ = SCM_EOL; }
1012 | '=' simple_string {
1018 Prefix_composite_music:
1019 Generic_prefix_music_scm {
1020 $$ = run_music_function (THIS, $1);
1022 | CONTEXT simple_string optional_id optional_context_mod Music {
1023 $$ = context_spec_music ($2, $3, $5, $4, false);
1025 | NEWCONTEXT simple_string optional_id optional_context_mod Music {
1026 $$ = context_spec_music ($2, $3, $5, $4, true);
1029 | TIMES fraction Music
1031 int n = scm_to_int (scm_car ($2));
1032 int d = scm_to_int (scm_cdr ($2));
1035 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1038 $$->set_property ("element", mp->self_scm ());
1040 $$->set_property ("numerator", scm_from_int (n));
1041 $$->set_property ("denominator", scm_from_int (d));
1042 $$->compress (Moment (Rational (n,d)));
1044 | Repeated_music { $$ = $1; }
1045 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1046 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1048 Pitch from = *unsmob_pitch ($2);
1049 Pitch to = *unsmob_pitch ($3);
1051 p->transpose (pitch_interval (from, to));
1052 $$->set_property ("element", p->self_scm ());
1055 | mode_changing_head Grouped_music_list {
1056 if ($1 == ly_symbol2scm ("chords"))
1058 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1059 chm->set_property ("element", $2->self_scm ());
1067 THIS->lexer_->pop_state ();
1069 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1070 $$ = context_spec_music ($1, SCM_UNDEFINED, $3, $2, true);
1071 if ($1 == ly_symbol2scm ("ChordNames"))
1073 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1074 chm->set_property ("element", $$->self_scm ());
1078 THIS->lexer_->pop_state ();
1080 | relative_music { $$ = $1; }
1081 | re_rhythmed_music { $$ = $1; }
1086 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1087 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1089 $$ = ly_symbol2scm ("notes");
1093 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1094 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1096 $$ = ly_symbol2scm ("drums");
1099 THIS->lexer_->push_figuredbass_state ();
1101 $$ = ly_symbol2scm ("figures");
1104 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1105 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1106 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1107 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1108 $$ = ly_symbol2scm ("chords");
1112 { THIS->lexer_->push_lyric_state ();
1113 $$ = ly_symbol2scm ("lyrics");
1117 mode_changing_head_with_context:
1119 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1120 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1122 $$ = ly_symbol2scm ("DrumStaff");
1125 THIS->lexer_->push_figuredbass_state ();
1127 $$ = ly_symbol2scm ("FiguredBass");
1130 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1131 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1132 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1133 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1134 $$ = ly_symbol2scm ("ChordNames");
1137 { THIS->lexer_->push_lyric_state ();
1138 $$ = ly_symbol2scm ("Lyrics");
1144 RELATIVE absolute_pitch Music {
1146 Pitch start = *unsmob_pitch ($2);
1147 $$ = make_music_relative (start, m);
1150 | RELATIVE Composite_music {
1153 Pitch middle_c (0, 0, 0);
1154 $$ = make_music_relative (middle_c, m);
1160 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1162 Grouped_music_list {
1163 /* Can also use Music at the expensive of two S/Rs similar to
1164 \repeat \alternative */
1165 THIS->lexer_->pop_state ();
1167 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1169 | new_lyrics ADDLYRICS {
1170 THIS->lexer_->push_lyric_state ();
1171 } Grouped_music_list {
1172 THIS->lexer_->pop_state ();
1173 $$ = scm_cons ($4->self_scm (), $1);
1178 Grouped_music_list new_lyrics {
1180 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice);
1181 if (!scm_is_string (name))
1183 name = get_next_unique_lyrics_context_id ();
1184 voice = context_spec_music (scm_makfrom0str ("Voice"),
1186 voice, SCM_EOL, false);
1189 SCM context = scm_makfrom0str ("Lyrics");
1190 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1193 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1195 Music *music = unsmob_music (scm_car (s));
1196 Music *com = make_lyric_combine_music (name, music);
1197 Music *csm = context_spec_music (context,
1198 SCM_UNDEFINED, com, SCM_EOL, true);
1199 lst = scm_cons (csm->self_scm (), lst);
1201 all->set_property ("elements", scm_cons (voice->self_scm (),
1204 voice->unprotect ();
1206 | LYRICSTO simple_string {
1207 THIS->lexer_->push_lyric_state ();
1209 THIS->lexer_->pop_state ();
1212 $$ = make_lyric_combine_music (name, music);
1218 CHANGE STRING '=' STRING {
1219 Music*t = MY_MAKE_MUSIC ("ContextChange");
1220 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1221 t-> set_property ("change-to-id", $4);
1230 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1231 scm_string_to_symbol ($1), $3);
1233 | UNSET simple_string {
1234 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1235 scm_string_to_symbol ($2));
1237 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1238 $$ = scm_list_4 (ly_symbol2scm ("push"),
1239 scm_string_to_symbol ($2), $5, $3);
1241 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1242 $$ = scm_list_5 (ly_symbol2scm ("push"),
1243 scm_string_to_symbol ($2), $6, $4, $3);
1245 | REVERT simple_string embedded_scm {
1246 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1247 scm_string_to_symbol ($2), $3);
1252 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1253 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1255 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1256 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1257 | DENIES { $$ = ly_symbol2scm ("denies"); }
1259 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1260 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1261 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1262 | NAME { $$ = ly_symbol2scm ("context-name"); }
1266 property_operation { $$ = $1; }
1267 | context_def_mod STRING {
1268 $$ = scm_list_2 ($1, $2);
1274 if (!is_regular_identifier ($1))
1276 @$.error (_("Grob name should be alphanumeric"));
1279 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1280 scm_string_to_symbol ($1));
1282 | simple_string '.' simple_string {
1283 $$ = scm_list_2 (scm_string_to_symbol ($1),
1284 scm_string_to_symbol ($3));
1289 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1290 $$ = property_op_to_music (scm_list_4 (
1291 ly_symbol2scm ("push"),
1294 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1296 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1297 $$ = property_op_to_music (scm_list_5 (
1298 ly_symbol2scm ("push"),
1301 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1303 | REVERT context_prop_spec embedded_scm {
1304 $$ = property_op_to_music (scm_list_3 (
1305 ly_symbol2scm ("pop"),
1309 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1311 | SET context_prop_spec '=' scalar {
1312 $$ = property_op_to_music (scm_list_3 (
1313 ly_symbol2scm ("assign"),
1316 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1318 | UNSET context_prop_spec {
1319 $$ = property_op_to_music (scm_list_2 (
1320 ly_symbol2scm ("unset"),
1322 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1324 | ONCE music_property_def {
1325 SCM e = $2->get_property ("element");
1326 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1337 | STRING_IDENTIFIER {
1340 | string '+' string {
1341 $$ = scm_string_append (scm_list_2 ($1, $3));
1345 simple_string: STRING {
1351 | STRING_IDENTIFIER {
1372 $$ = scm_from_int ($1);
1378 pre_events doesn't contain anything. It is a trick:
1380 Adding pre_events to the simple_element
1381 makes the choice between
1387 simple_element: STRING
1389 a single shift/reduction conflict.
1391 nevertheless, this is not very clean, and we should find a different
1395 pre_events: /* empty */
1399 pre_events simple_element post_events {
1400 SCM elts = $2-> get_property ("elements");
1402 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1404 $2->set_property ("elements", elts);
1405 /* why is this giving wrong start location? -ns
1406 * $2->set_spot (@$); */
1408 i.set_location (@2, @3);
1413 | note_chord_element
1418 chord_body optional_notemode_duration post_events
1420 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1421 SCM es = $1->get_property ("elements");
1422 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1424 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1425 unsmob_music (scm_car (s))->set_property ("duration", dur);
1426 es = ly_append2 (es, postevs);
1428 $1-> set_property ("elements", es);
1440 simul_open: DOUBLE_ANGLE_OPEN
1443 simul_close: DOUBLE_ANGLE_CLOSE
1447 chord_open chord_body_elements chord_close
1449 $$ = MY_MAKE_MUSIC ("EventChord");
1451 $$->set_property ("elements",
1452 scm_reverse_x ($2, SCM_EOL));
1456 chord_body_elements:
1457 /* empty */ { $$ = SCM_EOL; }
1458 | chord_body_elements chord_body_element {
1459 $$ = scm_cons ($2->self_scm (), $1);
1465 pitch exclamations questions octave_check post_events
1472 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1473 n->set_property ("pitch", $1);
1476 n->set_property ("cautionary", SCM_BOOL_T);
1477 if (ex % 2 || q % 2)
1478 n->set_property ("force-accidental", SCM_BOOL_T);
1480 if (scm_is_pair (post)) {
1481 SCM arts = scm_reverse_x (post, SCM_EOL);
1482 n->set_property ("articulations", arts);
1484 if (scm_is_number (check))
1486 int q = scm_to_int (check);
1487 n->set_property ("absolute-octave", scm_from_int (q-1));
1493 | DRUM_PITCH post_events {
1494 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1495 n->set_property ("duration", $2);
1496 n->set_property ("drum-type", $1);
1499 if (scm_is_pair ($2)) {
1500 SCM arts = scm_reverse_x ($2, SCM_EOL);
1501 n->set_property ("articulations", arts);
1505 | music_function_chord_body {
1506 $$ = run_music_function (THIS, $1);
1511 music_function_chord_body:
1513 $$ = scm_list_2 ($1, make_input (@$));
1515 | music_function_musicless_prefix chord_body_element {
1516 $$ = ly_append2 ($1, scm_list_1 ($2->self_scm ()));
1521 music_function_event:
1522 music_function_musicless_prefix post_event {
1523 $$ = ly_append2 ($1, scm_list_1 ($2->self_scm ()));
1529 TODO: use code generation for this
1531 music_function_musicless_prefix:
1532 MUSIC_FUNCTION_MUSIC {
1533 $$ = scm_list_2 ($1, make_input (@$));
1535 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument {
1536 $$ = scm_list_3 ($1, make_input (@$), $2);
1538 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument {
1539 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1541 | MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument {
1542 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1544 | MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument function_scm_argument {
1545 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
1552 $$ = MY_MAKE_MUSIC ("EventChord");
1553 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1559 | SKIP duration_length {
1560 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1561 skip->set_property ("duration", $2);
1562 skip->set_spot (@$);
1566 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1567 m->set_property ("span-direction", scm_from_int (START));
1570 $$ = MY_MAKE_MUSIC ("EventChord");
1571 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1576 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1577 m->set_property ("span-direction", scm_from_int (STOP));
1580 $$ = MY_MAKE_MUSIC ("EventChord");
1581 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1586 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1590 SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
1592 if (Music * m = unsmob_music (pipe))
1595 $$ = MY_MAKE_MUSIC ("BarCheck");
1599 | TRANSPOSITION pitch {
1601 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1602 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1603 sounds_as_c.smobbed_copy());
1605 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1606 $$, SCM_EOL, false);
1608 | PARTIAL duration_length {
1609 Moment m = - unsmob_duration ($2)->get_length ();
1610 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1612 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1614 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1620 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1622 SCM result = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1623 $$ = unsmob_music (result);
1627 SCM proc = ly_lily_module_constant ("make-mark-set");
1629 SCM result = scm_call_1 (proc, $2);
1630 $$ = unsmob_music (result);
1637 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1640 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1647 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1650 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1652 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1653 if (scm_ilength ($3) > 0)
1655 key->set_property ("pitch-alist", $3);
1656 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1657 key->transpose (* unsmob_pitch ($2));
1659 THIS->parser_error (@3, _ ("second argument must be pitch list"));
1671 | post_events post_event {
1673 $$ = scm_cons ($2->self_scm (), $$);
1679 direction_less_event {
1682 | '-' music_function_event {
1683 Music *mus = run_music_function (THIS, $2);
1688 if (!THIS->lexer_->is_lyric_state ())
1689 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1690 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1693 if (!THIS->lexer_->is_lyric_state ())
1694 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1695 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1697 | script_dir direction_reqd_event {
1699 $2->set_property ("direction", scm_from_int ($1));
1702 | script_dir direction_less_event {
1704 $2->set_property ("direction", scm_from_int ($1));
1707 | string_number_event
1710 string_number_event:
1712 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1713 s->set_property ("string-number", scm_from_int ($1));
1719 direction_less_char:
1721 $$ = ly_symbol2scm ("bracketOpenSymbol");
1724 $$ = ly_symbol2scm ("bracketCloseSymbol");
1727 $$ = ly_symbol2scm ("tildeSymbol");
1730 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1733 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1736 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1739 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1742 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1745 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1748 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1752 direction_less_event:
1753 direction_less_char {
1754 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1756 if (unsmob_music (predefd))
1758 m = unsmob_music (predefd)->clone ();
1762 m = MY_MAKE_MUSIC ("Music");
1767 | EVENT_IDENTIFIER {
1768 $$ = unsmob_music ($1);
1771 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1773 a->set_property ("tremolo-type", scm_from_int ($1));
1778 direction_reqd_event:
1782 | script_abbreviation {
1783 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1784 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1785 if (scm_is_string (s))
1786 a->set_property ("articulation-type", s);
1787 else THIS->parser_error (@1, _ ("expecting string as script definition"));
1793 /**/ { $$ = SCM_EOL; }
1794 | '=' { $$ = scm_from_int (0); }
1795 | '=' sub_quotes { $$ = scm_from_int ($2); }
1796 | '=' sup_quotes { $$ = scm_from_int ($2); }
1821 | NOTENAME_PITCH sup_quotes {
1822 Pitch p = *unsmob_pitch ($1);
1823 p = p.transposed (Pitch ($2,0,0));
1824 $$ = p.smobbed_copy ();
1826 | NOTENAME_PITCH sub_quotes {
1827 Pitch p =* unsmob_pitch ($1);
1828 p = p.transposed (Pitch (-$2,0,0));
1829 $$ = p.smobbed_copy ();
1841 | TONICNAME_PITCH sup_quotes {
1842 Pitch p = *unsmob_pitch ($1);
1843 p = p.transposed (Pitch ($2,0,0));
1844 $$ = p.smobbed_copy ();
1846 | TONICNAME_PITCH sub_quotes {
1847 Pitch p =* unsmob_pitch ($1);
1849 p = p.transposed (Pitch (-$2,0,0));
1850 $$ = p.smobbed_copy ();
1860 pitch_also_in_chords:
1867 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1868 t->set_property ("text", $1);
1873 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1874 t->set_property ("text",
1875 make_simple_markup ($1));
1881 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1882 t->set_property ("digit", scm_from_int ($1));
1888 script_abbreviation:
1890 $$ = scm_makfrom0str ("Hat");
1893 $$ = scm_makfrom0str ("Plus");
1896 $$ = scm_makfrom0str ("Dash");
1899 $$ = scm_makfrom0str ("Bar");
1902 $$ = scm_makfrom0str ("Larger");
1905 $$ = scm_makfrom0str ("Dot");
1908 $$ = scm_makfrom0str ("Underscore");
1915 | '-' { $$ = CENTER; }
1926 multiplied_duration {
1931 optional_notemode_duration:
1933 Duration dd = THIS->default_duration_;
1934 $$ = dd.smobbed_copy ();
1936 | multiplied_duration {
1938 THIS->default_duration_ = *unsmob_duration ($$);
1943 bare_unsigned dots {
1945 if (!is_duration ($1))
1946 THIS->parser_error (@1, _f ("not a duration: %d", $1));
1950 $$ = Duration (len, $2).smobbed_copy ();
1952 | DURATION_IDENTIFIER dots {
1953 Duration *d = unsmob_duration ($1);
1954 Duration k (d->duration_log (), d->dot_count () + $2);
1960 multiplied_duration:
1964 | multiplied_duration '*' bare_unsigned {
1965 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1967 | multiplied_duration '*' FRACTION {
1968 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1970 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1975 FRACTION { $$ = $1; }
1976 | UNSIGNED '/' UNSIGNED {
1977 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1994 | ':' bare_unsigned {
1995 if (!is_duration ($2))
1996 THIS->parser_error (@2, _f ("not a duration: %d", $2));
2003 $$ = scm_from_int ($1);
2006 $$ = scm_from_int ($1);
2008 | STRING { $$ = $1; }
2009 | full_markup { $$ = $1; }
2012 figured_bass_alteration:
2020 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2021 $$ = bfr->self_scm ();
2026 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2027 $$ = bfr->self_scm ();
2029 if (scm_is_number ($1))
2030 bfr->set_property ("figure", $1);
2031 else if (Text_interface::is_markup ($1))
2032 bfr->set_property ("text", $1);
2039 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2041 | bass_figure figured_bass_alteration {
2042 Music *m = unsmob_music ($1);
2044 SCM salter = m->get_property ("alteration");
2045 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2046 m->set_property ("alteration",
2047 scm_from_int (alter + $2));
2049 m->set_property ("alteration", scm_from_int (0));
2052 | bass_figure figured_bass_modification {
2053 Music *m = unsmob_music ($1);
2054 if ($2 == ly_symbol2scm ("plus"))
2056 m->set_property ("augmented", SCM_BOOL_T);
2058 else if ($2 == ly_symbol2scm ("slash"))
2060 m->set_property ("diminished", SCM_BOOL_T);
2062 else if ($2 == ly_symbol2scm ("exclamation"))
2064 m->set_property ("no-continuation", SCM_BOOL_T);
2070 figured_bass_modification:
2072 $$ = ly_symbol2scm ("plus");
2075 $$ = ly_symbol2scm ("exclamation");
2078 $$ = ly_symbol2scm ("slash");
2088 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2096 | figure_list br_bass_figure {
2097 $$ = scm_cons ($2, $1);
2102 FIGURE_OPEN figure_list FIGURE_CLOSE {
2103 Music *m = MY_MAKE_MUSIC ("EventChord");
2104 $2 = scm_reverse_x ($2, SCM_EOL);
2105 m->set_property ("elements", $2);
2106 $$ = m->self_scm ();
2117 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2118 if (!THIS->lexer_->is_note_state ())
2119 THIS->parser_error (@1, _ ("have to be in Note mode for notes"));
2123 n = MY_MAKE_MUSIC ("RestEvent");
2125 n = MY_MAKE_MUSIC ("NoteEvent");
2127 n->set_property ("pitch", $1);
2128 n->set_property ("duration", $5);
2130 if (scm_is_number ($4))
2132 int q = scm_to_int ($4);
2133 n->set_property ("absolute-octave", scm_from_int (q-1));
2137 n->set_property ("cautionary", SCM_BOOL_T);
2138 if ($2 % 2 || $3 % 2)
2139 n->set_property ("force-accidental", SCM_BOOL_T);
2141 Music *v = MY_MAKE_MUSIC ("EventChord");
2142 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2149 | DRUM_PITCH optional_notemode_duration {
2150 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2151 n->set_property ("duration", $2);
2152 n->set_property ("drum-type", $1);
2154 Music *v = MY_MAKE_MUSIC ("EventChord");
2155 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2162 | figure_spec optional_notemode_duration {
2163 Music *m = unsmob_music ($1);
2165 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2167 unsmob_music (scm_car (s))->set_property ("duration", $2);
2171 | RESTNAME optional_notemode_duration {
2173 if (ly_scm2string ($1) == "s") {
2175 ev = MY_MAKE_MUSIC ("SkipEvent");
2178 ev = MY_MAKE_MUSIC ("RestEvent");
2181 ev->set_property ("duration", $2);
2183 Music *velt = MY_MAKE_MUSIC ("EventChord");
2184 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2185 velt->set_spot (@$);
2191 | MULTI_MEASURE_REST optional_notemode_duration {
2192 SCM proc = ly_lily_module_constant ("make-multi-measure-rest");
2193 SCM mus = scm_call_2 (proc, $2, make_input (@$));
2194 $$ = unsmob_music (mus);
2198 | lyric_element optional_notemode_duration {
2199 if (!THIS->lexer_->is_lyric_state ())
2200 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2202 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2203 levent->set_property ("text", $1);
2204 levent->set_property ("duration",$2);
2205 levent->set_spot (@$);
2206 Music *velt = MY_MAKE_MUSIC ("EventChord");
2207 velt->set_property ("elements", scm_list_1 (levent->self_scm ()));
2212 if (!THIS->lexer_->is_chord_state ())
2213 THIS->parser_error (@1, _ ("have to be in Chord mode for chords"));
2214 $$ = unsmob_music ($1);
2228 steno_tonic_pitch optional_notemode_duration {
2229 $$ = make_chord ($1, $2, SCM_EOL);
2231 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2232 SCM its = scm_reverse_x ($4, SCM_EOL);
2233 $$ = make_chord ($1, $2, scm_cons ($3, its));
2241 | chord_items chord_item {
2242 $$ = scm_cons ($2, $$);
2248 $$ = ly_symbol2scm ("chord-colon");
2251 $$ = ly_symbol2scm ("chord-caret");
2253 | CHORD_SLASH steno_tonic_pitch {
2254 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2256 | CHORD_BASS steno_tonic_pitch {
2257 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2266 $$ = scm_reverse_x ($1, SCM_EOL);
2274 step_number { $$ = scm_cons ($1, SCM_EOL); }
2275 | step_numbers '.' step_number {
2276 $$ = scm_cons ($3, $$);
2282 $$ = make_chord_step ($1, 0);
2284 | bare_unsigned '+' {
2285 $$ = make_chord_step ($1, SHARP);
2287 | bare_unsigned CHORD_MINUS {
2288 $$ = make_chord_step ($1, FLAT);
2295 TODO: should deprecate in favor of Scheme?
2299 number_expression '+' number_term {
2300 $$ = scm_sum ($1, $3);
2302 | number_expression '-' number_term {
2303 $$ = scm_difference ($1, $3);
2312 | number_factor '*' number_factor {
2313 $$ = scm_product ($1, $3);
2315 | number_factor '/' number_factor {
2316 $$ = scm_divide ($1, $3);
2321 '-' number_factor { /* %prec UNARY_MINUS */
2322 $$ = scm_difference ($2, SCM_UNDEFINED);
2330 $$ = scm_from_int ($1);
2335 | NUMBER_IDENTIFIER {
2338 | REAL NUMBER_IDENTIFIER {
2339 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2341 | UNSIGNED NUMBER_IDENTIFIER {
2342 $$ = scm_from_double ($1 *scm_to_double ($2));
2358 | exclamations '!' { $$ ++; }
2363 | questions '?' { $$ ++; }
2367 This should be done more dynamically if possible.
2371 LYRIC_MARKUP_IDENTIFIER {
2375 { THIS->lexer_->push_markup_state (); }
2378 THIS->lexer_->pop_state ();
2387 { THIS->lexer_->push_markup_state (); }
2390 THIS->lexer_->pop_state ();
2396 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2398 | markup_head_1_list simple_markup {
2399 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2407 markup_composed_list {
2410 | markup_braced_list {
2415 markup_composed_list:
2416 markup_head_1_list markup_braced_list {
2417 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2423 '{' markup_braced_list_body '}' {
2424 $$ = scm_reverse_x ($2, SCM_EOL);
2428 markup_braced_list_body:
2429 /* empty */ { $$ = SCM_EOL; }
2430 | markup_braced_list_body markup {
2431 $$ = scm_cons ($2, $1);
2433 | markup_braced_list_body markup_list {
2434 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2439 MARKUP_HEAD_MARKUP0 {
2440 $$ = scm_list_1 ($1);
2442 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2443 $$ = scm_list_2 ($1, $2);
2445 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2446 $$ = scm_list_3 ($1, $2, $3);
2451 markup_head_1_item {
2452 $$ = scm_list_1 ($1);
2454 | markup_head_1_list markup_head_1_item {
2455 $$ = scm_cons ($2, $1);
2461 $$ = make_simple_markup ($1);
2463 | MARKUP_IDENTIFIER {
2466 | LYRIC_MARKUP_IDENTIFIER {
2469 | STRING_IDENTIFIER {
2473 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2474 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2475 } '{' score_body '}' {
2477 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2479 THIS->lexer_->pop_state ();
2481 | MARKUP_HEAD_SCM0 embedded_scm {
2482 $$ = scm_list_2 ($1, $2);
2484 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2485 $$ = scm_list_4 ($1, $2, $3, $4);
2487 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2488 $$ = scm_list_3 ($1, $2, $3);
2490 | MARKUP_HEAD_EMPTY {
2491 $$ = scm_list_1 ($1);
2493 | MARKUP_HEAD_LIST0 markup_list {
2494 $$ = scm_list_2 ($1,$2);
2496 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2497 $$ = scm_list_3 ($1, $2, $3);
2502 markup_head_1_list simple_markup {
2503 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2504 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2514 Lily_parser::set_yydebug (bool )
2522 Lily_parser::do_yyparse ()
2524 yyparse ((void*)this);
2533 It is a little strange to have this function in this file, but
2534 otherwise, we have to import music classes into the lexer.
2538 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2540 if (scm_is_string (sid)) {
2542 return STRING_IDENTIFIER;
2543 } else if (unsmob_book (sid)) {
2544 *destination = unsmob_book (sid)->clone ()->self_scm ();
2545 return BOOK_IDENTIFIER;
2546 } else if (scm_is_number (sid)) {
2548 return NUMBER_IDENTIFIER;
2549 } else if (unsmob_context_def (sid)) {
2550 *destination = unsmob_context_def (sid)->clone_scm ();
2551 return CONTEXT_DEF_IDENTIFIER;
2552 } else if (unsmob_score (sid)) {
2553 Score *score = new Score (*unsmob_score (sid));
2554 *destination = score->self_scm ();
2555 return SCORE_IDENTIFIER;
2556 } else if (Music *mus = unsmob_music (sid)) {
2557 mus = mus->clone ();
2558 *destination = mus->self_scm ();
2559 unsmob_music (*destination)->
2560 set_property ("origin", make_input (last_input_));
2562 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2565 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2566 } else if (unsmob_duration (sid)) {
2567 *destination = unsmob_duration (sid)->smobbed_copy ();
2568 return DURATION_IDENTIFIER;
2569 } else if (unsmob_output_def (sid)) {
2570 Output_def *p = unsmob_output_def (sid);
2573 *destination = p->self_scm ();
2574 return OUTPUT_DEF_IDENTIFIER;
2575 } else if (Text_interface::is_markup (sid)) {
2577 if (is_lyric_state ())
2578 return LYRIC_MARKUP_IDENTIFIER;
2579 return MARKUP_IDENTIFIER;
2586 property_op_to_music (SCM op)
2589 SCM tag = scm_car (op);
2590 SCM symbol = scm_cadr (op);
2591 SCM args = scm_cddr (op);
2592 SCM grob_val = SCM_UNDEFINED;
2593 SCM grob_path = SCM_UNDEFINED;
2594 SCM val = SCM_UNDEFINED;
2596 if (tag == ly_symbol2scm ("assign"))
2598 m = MY_MAKE_MUSIC ("PropertySet");
2599 val = scm_car (args);
2601 else if (tag == ly_symbol2scm ("unset"))
2602 m = MY_MAKE_MUSIC ("PropertyUnset");
2603 else if (tag == ly_symbol2scm ("push"))
2605 m = MY_MAKE_MUSIC ("OverrideProperty");
2606 grob_val = scm_car (args);
2607 grob_path = scm_cdr (args);
2608 m->set_property ("pop-first", SCM_BOOL_T);
2610 else if (tag == ly_symbol2scm ("pop")) {
2611 m = MY_MAKE_MUSIC ("RevertProperty");
2615 m->set_property ("symbol", symbol);
2617 if (val != SCM_UNDEFINED)
2618 m->set_property ("value", val);
2619 if (grob_val != SCM_UNDEFINED)
2620 m->set_property ("grob-value", grob_val);
2621 if (grob_path != SCM_UNDEFINED)
2622 m->set_property ("grob-property-path", grob_path);
2628 context_spec_music (SCM type, SCM id, Music *m, SCM ops, bool create_new)
2630 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2632 csm->set_property ("element", m->self_scm ());
2635 csm->set_property ("context-type",
2636 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2637 csm->set_property ("property-operations", ops);
2639 csm->set_property ("create-new", SCM_BOOL_T);
2641 if (scm_is_string (id))
2642 csm->set_property ("context-id", id);
2647 get_next_unique_context_id ()
2649 return scm_makfrom0str ("$uniqueContextId");
2654 get_next_unique_lyrics_context_id ()
2656 static int new_context_count;
2658 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2659 return scm_makfrom0str (s);
2664 run_music_function (Lily_parser *parser, SCM expr)
2666 SCM func = scm_car (expr);
2667 Input *loc = unsmob_input (scm_cadr (expr));
2668 SCM args = scm_cddr (expr);
2669 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2671 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2674 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2676 parser->error_level_ = 1;
2682 m = scm_apply_0 (func, scm_cons (parser->self_scm(),
2687 if (unsmob_music (m))
2689 retval = unsmob_music (m);
2695 loc->error (_ ("music head function must return Music object"));
2696 retval = MY_MAKE_MUSIC ("Music");
2698 retval->set_spot (*loc);
2703 is_regular_identifier (SCM id)
2705 string str = ly_scm2string (id);
2706 char const *s = str.c_str ();
2715 v = v && isalnum (*s);
2723 get_first_context_id (SCM type, Music *m)
2725 SCM id = m->get_property ("context-id");
2726 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2727 && scm_is_string (m->get_property ("context-id"))
2728 && scm_c_string_length (id) > 0)
2736 make_simple_markup (SCM a)
2744 return t && t == 1 << intlog2 (t);
2748 set_music_properties (Music *p, SCM a)
2750 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2751 p->internal_set_property (scm_caar (k), scm_cdar (k));
2756 make_chord_step (int step, int alter)
2763 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2764 return m.smobbed_copy ();
2769 make_chord (SCM pitch, SCM dur, SCM modification_list)
2771 SCM chord_ctor = ly_lily_module_constant ("construct-chord");
2772 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
2774 unsmob_music (ch)->protect();
2779 /* Todo: actually also use apply iso. call too ... */
2781 ly_input_procedure_p (SCM x)
2783 return ly_is_procedure (x)
2784 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2788 set_property_music (SCM sym, SCM value)
2790 Music *p = MY_MAKE_MUSIC ("PropertySet");
2791 p->set_property ("symbol", sym);
2792 p->set_property ("value", value);
2797 make_music_relative (Pitch start, Music *music)
2799 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2800 relative->set_property ("element", music->self_scm ());
2802 Pitch last = music->to_relative_octave (start);
2803 if (lily_1_8_relative)
2804 music->set_property ("last-pitch", last.smobbed_copy ());
2809 make_lyric_combine_music (SCM name, Music *music)
2811 Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
2812 combine->set_property ("element", music->self_scm ());
2813 combine->set_property ("associated-context", name);
2819 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2821 Lily_parser *pars = (Lily_parser*) v;
2822 Lily_lexer *lex = pars->lexer_;
2824 lex->lexval = (void*) s;
2826 lex->prepare_for_next_token ();
2827 return lex->yylex ();