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 #define MAKE_SYNTAX_EXPRESSION(name, ...) \
115 scm_apply_0 (ly_lily_module_constant (name), scm_list (__VA_ARGS__, SCM_UNDEFINED));
117 Music *property_op_to_music (SCM op);
118 SCM context_spec_music (SCM type, SCM id, SCM m, SCM ops, bool create_new);
119 SCM get_next_unique_context_id ();
120 SCM get_next_unique_lyrics_context_id ();
127 #define _(x) gettext (x)
132 SCM make_lyric_combine_music (SCM name, SCM music);
133 SCM make_music_relative (Pitch start, SCM music);
134 Music *run_music_function (Lily_parser *, SCM expr);
135 Music *set_property_music (SCM sym, SCM value);
136 SCM get_first_context_id (SCM type, Music *m);
137 SCM make_chord (SCM pitch, SCM dur, SCM modification_list);
138 SCM make_chord_step (int step, int alter);
139 SCM make_simple_markup (SCM a);
140 bool is_duration (int t);
141 bool is_regular_identifier (SCM id);
142 bool ly_input_procedure_p (SCM x);
143 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
144 void set_music_properties (Music *p, SCM a);
148 /* The third option is an alias that will be used to display the
149 syntax error. Bison CVS now correctly handles backslash escapes.
151 FIXME: Bison needs to translate some of these, eg, STRING.
155 /* Keyword tokens with plain escaped name. */
156 %token ACCEPTS "\\accepts"
157 %token ADDLYRICS "\\addlyrics"
158 %token ADDQUOTE "\\addquote"
159 %token ALIAS "\\alias"
160 %token ALTERNATIVE "\\alternative"
162 %token CHANGE "\\change"
163 %token CHORDMODE "\\chordmode"
164 %token CHORDS "\\chords"
165 %token CONSISTS "\\consists"
166 %token CONTEXT "\\context"
167 %token DEFAULT "\\default"
168 %token DEFAULTCHILD "\\defaultchild"
169 %token DENIES "\\denies"
170 %token DESCRIPTION "\\description"
171 %token DRUMMODE "\\drummode"
172 %token DRUMS "\\drums"
173 %token FIGUREMODE "\\figuremode"
174 %token FIGURES "\\figures"
175 %token GROBDESCRIPTIONS "\\grobdescriptions"
176 %token HEADER "\\header"
177 %token INVALID "\\invalid"
179 %token LAYOUT "\\layout"
180 %token LYRICMODE "\\lyricmode"
181 %token LYRICS "\\lyrics"
182 %token LYRICSTO "\\lyricsto"
184 %token MARKUP "\\markup"
187 %token NOTEMODE "\\notemode"
188 %token OBJECTID "\\objectid"
189 %token OCTAVE "\\octave"
191 %token OVERRIDE "\\override"
192 %token PAPER "\\paper"
193 %token PARTIAL "\\partial"
194 %token RELATIVE "\\relative"
195 %token REMOVE "\\remove"
196 %token REPEAT "\\repeat"
198 %token REVERT "\\revert"
199 %token SCORE "\\score"
200 %token SEQUENTIAL "\\sequential"
202 %token SIMULTANEOUS "\\simultaneous"
204 %token TEMPO "\\tempo"
205 %token TIMES "\\times"
206 %token TRANSPOSE "\\transpose"
207 %token TRANSPOSITION "\\transposition"
209 %token UNSET "\\unset"
212 /* Keyword token exceptions. */
213 %token TIME_T "\\time"
214 %token NEWCONTEXT "\\new"
217 /* Other string tokens. */
219 %token CHORD_BASS "/+"
220 %token CHORD_CARET "^"
221 %token CHORD_COLON ":"
222 %token CHORD_MINUS "-"
223 %token CHORD_SLASH "/"
224 %token DOUBLE_ANGLE_CLOSE ">>"
225 %token DOUBLE_ANGLE_OPEN "<<"
226 %token E_BACKSLASH "\\"
227 %token E_ANGLE_CLOSE "\\>"
228 %token E_CHAR "\\C[haracter]"
230 %token E_EXCLAMATION "\\!"
231 %token E_BRACKET_OPEN "\\["
233 %token E_BRACKET_CLOSE "\\]"
234 %token E_ANGLE_OPEN "\\<"
240 If we give names, Bison complains.
242 %token FIGURE_CLOSE /* "\\>" */
243 %token FIGURE_OPEN /* "\\<" */
244 %token FIGURE_SPACE "_"
247 %token CHORDMODIFIERS
249 %token MULTI_MEASURE_REST
254 %token <i> E_UNSIGNED
257 %token <scm> BOOK_IDENTIFIER
258 %token <scm> CHORDMODIFIER_PITCH
259 %token <scm> CHORD_MODIFIER
260 %token <scm> CONTEXT_DEF_IDENTIFIER
261 %token <scm> DRUM_PITCH
262 %token <scm> DURATION_IDENTIFIER
263 %token <scm> EVENT_IDENTIFIER
264 %token <scm> FRACTION
265 %token <scm> LYRICS_STRING
266 %token <scm> LYRIC_MARKUP_IDENTIFIER
267 %token <scm> MARKUP_HEAD_EMPTY
268 %token <scm> MARKUP_HEAD_LIST0
269 %token <scm> MARKUP_HEAD_MARKUP0
270 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
271 %token <scm> MARKUP_HEAD_SCM0
272 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
273 %token <scm> MARKUP_HEAD_SCM0_SCM1
274 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
275 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
276 %token <scm> MARKUP_IDENTIFIER
277 %token <scm> MUSIC_FUNCTION
278 %token <scm> MUSIC_FUNCTION_MARKUP
279 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
280 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
281 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
282 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
283 %token <scm> MUSIC_FUNCTION_MUSIC
284 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
285 %token <scm> MUSIC_FUNCTION_SCM
286 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
287 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
288 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC
289 %token <scm> MUSIC_FUNCTION_SCM_SCM
290 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
291 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM
292 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC
293 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC
294 %token <scm> MUSIC_IDENTIFIER
295 %token <scm> NOTENAME_PITCH
296 %token <scm> NUMBER_IDENTIFIER
297 %token <scm> OUTPUT_DEF_IDENTIFIER
299 %token <scm> RESTNAME
300 %token <scm> SCM_IDENTIFIER
302 %token <scm> SCORE_IDENTIFIER
304 %token <scm> STRING_IDENTIFIER
305 %token <scm> TONICNAME_PITCH
308 %type <book> book_block
309 %type <book> book_body
311 %type <i> bare_unsigned
312 %type <i> figured_bass_alteration
314 %type <i> exclamations
315 %type <i> optional_rest
320 %type <i> tremolo_type
323 %type <scm> Composite_music
324 %type <scm> Grouped_music_list
326 %type <scm> Prefix_composite_music
327 %type <scm> Repeated_music
328 %type <scm> Sequential_music
329 %type <scm> Simple_music
330 %type <scm> Simultaneous_music
331 %type <scm> chord_body
332 %type <scm> chord_body_element
333 %type <scm> command_element
334 %type <scm> command_event
335 %type <scm> context_change
336 %type <scm> direction_less_event
337 %type <scm> direction_reqd_event
338 %type <scm> event_chord
339 %type <scm> gen_text_def
340 %type <scm> music_property_def
341 %type <scm> note_chord_element
342 %type <scm> post_event
343 %type <scm> re_rhythmed_music
344 %type <scm> relative_music
345 %type <scm> simple_element
346 %type <scm> string_number_event
347 %type <scm> tempo_event
348 %type <scm> toplevel_music
350 %type <outputdef> output_def_body
351 %type <outputdef> output_def_head
352 %type <outputdef> output_def_head_with_mode_switch
353 %type <outputdef> output_def
354 %type <outputdef> paper_block
356 %type <scm> Alternative_music
357 %type <scm> Generic_prefix_music_scm
358 %type <scm> Music_list
359 %type <scm> absolute_pitch
360 %type <scm> assignment_id
361 %type <scm> bare_number
362 %type <scm> music_function_event
363 %type <scm> music_function_chord_body
364 %type <scm> music_function_musicless_prefix
365 %type <scm> bass_figure
366 %type <scm> figured_bass_modification
367 %type <scm> br_bass_figure
368 %type <scm> bass_number
369 %type <scm> chord_body_elements
370 %type <scm> chord_item
371 %type <scm> chord_items
372 %type <scm> chord_separator
373 %type <scm> context_def_mod
374 %type <scm> context_def_spec_block
375 %type <scm> context_def_spec_body
376 %type <scm> context_mod
377 %type <scm> context_mod_list
378 %type <scm> context_prop_spec
379 %type <scm> direction_less_char
380 %type <scm> duration_length
381 %type <scm> embedded_scm
382 %type <scm> figure_list
383 %type <scm> figure_spec
385 %type <scm> full_markup
386 %type <scm> identifier_init
387 %type <scm> lilypond_header
388 %type <scm> lilypond_header_body
389 %type <scm> lyric_element
390 %type <scm> lyric_markup
392 %type <scm> markup_braced_list
393 %type <scm> markup_braced_list_body
394 %type <scm> markup_composed_list
395 %type <scm> markup_head_1_item
396 %type <scm> markup_head_1_list
397 %type <scm> markup_list
398 %type <scm> markup_top
399 %type <scm> mode_changing_head
400 %type <scm> mode_changing_head_with_context
401 %type <scm> multiplied_duration
402 %type <scm> new_chord
403 %type <scm> new_lyrics
404 %type <scm> number_expression
405 %type <scm> number_factor
406 %type <scm> number_term
407 %type <scm> object_id_setting
408 %type <scm> octave_check
409 %type <scm> optional_context_mod
410 %type <scm> optional_id
411 %type <scm> optional_notemode_duration
413 %type <scm> pitch_also_in_chords
414 %type <scm> post_events
415 %type <scm> property_operation
417 %type <scm> script_abbreviation
418 %type <scm> simple_markup
419 %type <scm> simple_string
420 %type <scm> steno_duration
421 %type <scm> steno_pitch
422 %type <scm> steno_tonic_pitch
423 %type <scm> step_number
424 %type <scm> step_numbers
426 %type <scm> function_scm_argument
428 %type <score> score_block
429 %type <score> score_body
434 /* We don't assign precedence to / and *, because we might need varied
435 prec levels in different prods */
441 lilypond: /* empty */
442 | lilypond toplevel_expression {
444 | lilypond assignment {
447 THIS->error_level_ = 1;
450 THIS->error_level_ = 1;
456 OBJECTID STRING { $$ = $2; }
461 THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
465 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
466 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
472 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
473 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
477 Music *music = unsmob_music ($1);
478 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
479 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
482 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler");
483 scm_call_2 (proc, THIS->self_scm (), $1);
487 Output_def * od = $1;
489 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
490 id = ly_symbol2scm ("$defaultpaper");
491 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
492 id = ly_symbol2scm ("$defaultmidi");
493 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
494 id = ly_symbol2scm ("$defaultlayout");
496 THIS->lexer_->set_identifier (id, od->self_scm ());
512 lilypond_header_body:
514 $$ = get_header(THIS);
515 THIS->lexer_->add_scope ($$);
517 | lilypond_header_body assignment {
523 HEADER '{' lilypond_header_body '}' {
524 $$ = THIS->lexer_->remove_scope ();
533 | LYRICS_STRING { $$ = $1; }
537 assignment_id '=' identifier_init {
538 if (! is_regular_identifier ($1))
541 /* no longer valid with dashes in \paper{} block. */
542 @1.warning (_ ("identifier should have alphabetic characters only"));
547 THIS->lexer_->set_identifier ($1, $3);
550 TODO: devise standard for protection in parser.
552 The parser stack lives on the C-stack, which means that
553 all objects can be unprotected as soon as they're here.
563 $$ = $1->self_scm ();
567 $$ = $1->self_scm ();
571 $$ = $1->self_scm ();
574 | context_def_spec_block {
583 | number_expression {
596 $$ = scm_from_int ($1);
600 context_def_spec_block:
601 CONTEXT '{' context_def_spec_body '}'
607 context_def_spec_body:
609 $$ = Context_def::make_scm ();
610 unsmob_context_def ($$)->set_spot (@$);
612 | CONTEXT_DEF_IDENTIFIER {
614 unsmob_context_def ($$)->set_spot (@$);
616 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
617 Context_def*td = unsmob_context_def ($$);
619 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
620 SCM tag = scm_caar (p);
622 /* TODO: should make new tag "grob-definition" ? */
623 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
624 tag, scm_cons (scm_cdar (p), SCM_EOL)));
627 | context_def_spec_body context_mod {
628 unsmob_context_def ($$)->add_context_mod ($2);
635 BOOK '{' book_body '}' {
641 * Use 'handlers' like for toplevel-* stuff?
642 * grok \layout and \midi? */
647 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
648 $$->paper_->unprotect ();
649 $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader");
652 $$ = unsmob_book ($1);
655 | book_body paper_block {
659 | book_body score_block {
660 SCM s = $2->self_scm ();
664 | book_body full_markup {
667 | book_body lilypond_header {
672 $$->scores_ = SCM_EOL;
674 | book_body object_id_setting {
675 $$->user_key_ = ly_scm2string ($2);
680 SCORE '{' score_body '}' {
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 (unsmob_music($2)->get_property ("metronome-count"));
800 Duration *d = unsmob_duration (unsmob_music($2)->get_property ("tempo-unit"));
801 set_tempo ($$, d->get_length (), m);
803 | output_def_body error {
809 TEMPO steno_duration '=' bare_unsigned {
810 Music *m = MY_MAKE_MUSIC ("MetronomeChangeEvent");
811 m->set_property ("tempo-unit", $2);
812 m->set_property ("metronome-count", scm_from_int ( $4));
813 $$ = m->unprotect ();
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, SCM_EOL);
832 if (scm_is_pair (scm_cdr (s)))
833 scm_set_cdr_x (scm_cdr (s), c); /* append */
835 scm_set_car_x (s, c); /* set first cons */
836 scm_set_cdr_x (s, c); /* remember last cell */
838 | Music_list embedded_scm {
842 Music *m = MY_MAKE_MUSIC("Music");
844 m->set_property ("error-found", SCM_BOOL_T);
846 SCM c = scm_cons (m->self_scm (), SCM_EOL);
847 m->unprotect (); /* UGH */
849 if (scm_is_pair (scm_cdr (s)))
850 scm_set_cdr_x (scm_cdr (s), c); /* append */
852 scm_set_car_x (s, c); /* set first cons */
853 scm_set_cdr_x (s, c); /* remember last cell */
866 | ALTERNATIVE '{' Music_list '}' {
873 REPEAT simple_string bare_unsigned Music Alternative_music
875 SCM proc = ly_lily_module_constant ("make-repeat");
876 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
877 assert (unsmob_music ($4));
878 SCM mus = scm_call_4 (proc, $2, scm_int2num ($3), $4, alts);
879 Music *r = unsmob_music (mus);
880 r->set_spot (*unsmob_music($4)->origin ());
886 SEQUENTIAL '{' Music_list '}' {
887 Music *m = MY_MAKE_MUSIC ("SequentialMusic");
888 m->set_property ("elements", scm_car ($3));
890 $$ = m->unprotect ();
892 | '{' Music_list '}' {
893 Music *m = MY_MAKE_MUSIC ("SequentialMusic");
894 m->set_property ("elements", scm_car ($2));
896 $$ = m->unprotect ();
901 SIMULTANEOUS '{' Music_list '}'{
902 Music *m = MY_MAKE_MUSIC ("SimultaneousMusic");
903 m->set_property ("elements", scm_car ($3));
905 $$ = m->unprotect ();
907 | simul_open Music_list simul_close {
908 Music *m = MY_MAKE_MUSIC ("SimultaneousMusic");
909 m->set_property ("elements", scm_car ($2));
911 $$ = m->unprotect ();
916 event_chord { $$ = $1; }
922 optional_context_mod:
923 /**/ { $$ = SCM_EOL; }
924 | WITH { THIS->lexer_->push_initial_state (); }
925 '{' context_mod_list '}'
927 THIS->lexer_->pop_state ();
933 /* */ { $$ = SCM_EOL; }
934 | context_mod_list context_mod {
935 $$ = scm_cons ($2, $1);
940 Prefix_composite_music { $$ = $1; }
941 | Grouped_music_list { $$ = $1; }
945 Simultaneous_music { $$ = $1; }
946 | Sequential_music { $$ = $1; }
949 function_scm_argument:
955 TODO: use code generation for this
957 Generic_prefix_music_scm:
959 $$ = scm_list_2 ($1, make_input (@$));
961 | MUSIC_FUNCTION_SCM function_scm_argument {
962 $$ = scm_list_3 ($1, make_input (@$), $2);
964 | MUSIC_FUNCTION_MARKUP full_markup {
965 $$ = scm_list_3 ($1, make_input (@$), $2);
967 | music_function_musicless_prefix Music {
968 $$ = ly_append2 ($1, scm_list_1 ($2));
970 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
971 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
973 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
974 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
976 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
977 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
979 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
980 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
982 | MUSIC_FUNCTION_MUSIC_MUSIC Music Music {
983 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
985 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument Music Music {
986 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
988 | MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC function_scm_argument function_scm_argument Music Music {
989 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
991 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup Music Music {
992 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
997 /**/ { $$ = SCM_EOL; }
998 | '=' simple_string {
1004 Prefix_composite_music:
1005 Generic_prefix_music_scm {
1006 $$ = run_music_function (THIS, $1)->unprotect ();
1008 | CONTEXT simple_string optional_id optional_context_mod Music {
1009 $$ = context_spec_music ($2, $3, $5, $4, false);
1011 | NEWCONTEXT simple_string optional_id optional_context_mod Music {
1012 $$ = context_spec_music ($2, $3, $5, $4, true);
1015 | TIMES fraction Music
1017 int n = scm_to_int (scm_car ($2));
1018 int d = scm_to_int (scm_cdr ($2));
1020 Music *m = MY_MAKE_MUSIC ("TimeScaledMusic");
1023 m->set_property ("element", $3);
1024 m->set_property ("numerator", scm_from_int (n));
1025 m->set_property ("denominator", scm_from_int (d));
1026 m->compress (Moment (Rational (n,d)));
1027 $$ = m->unprotect ();
1029 | Repeated_music { $$ = $1; }
1030 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1031 Music *m = MY_MAKE_MUSIC ("TransposedMusic");
1032 Pitch from = *unsmob_pitch ($2);
1033 Pitch to = *unsmob_pitch ($3);
1035 Music *p = unsmob_music ($4);
1036 p->transpose (pitch_interval (from, to));
1037 m->set_property ("element", $4);
1038 $$ = m->unprotect ();
1040 | mode_changing_head Grouped_music_list {
1041 if ($1 == ly_symbol2scm ("chords"))
1043 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1044 chm->set_property ("element", $2);
1045 $$ = chm->unprotect ();
1051 THIS->lexer_->pop_state ();
1053 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1054 $$ = context_spec_music ($1, SCM_UNDEFINED, $3, $2, true);
1055 if ($1 == ly_symbol2scm ("ChordNames"))
1057 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1058 chm->set_property ("element", $$);
1059 $$ = chm->unprotect ();
1061 THIS->lexer_->pop_state ();
1063 | relative_music { $$ = $1; }
1064 | re_rhythmed_music { $$ = $1; }
1069 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1070 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1072 $$ = ly_symbol2scm ("notes");
1076 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1077 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1079 $$ = ly_symbol2scm ("drums");
1082 THIS->lexer_->push_figuredbass_state ();
1084 $$ = ly_symbol2scm ("figures");
1087 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1088 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1089 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1090 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1091 $$ = ly_symbol2scm ("chords");
1095 { THIS->lexer_->push_lyric_state ();
1096 $$ = ly_symbol2scm ("lyrics");
1100 mode_changing_head_with_context:
1102 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1103 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1105 $$ = ly_symbol2scm ("DrumStaff");
1108 THIS->lexer_->push_figuredbass_state ();
1110 $$ = ly_symbol2scm ("FiguredBass");
1113 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1114 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1115 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1116 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1117 $$ = ly_symbol2scm ("ChordNames");
1120 { THIS->lexer_->push_lyric_state ();
1121 $$ = ly_symbol2scm ("Lyrics");
1127 RELATIVE absolute_pitch Music {
1128 Pitch start = *unsmob_pitch ($2);
1129 $$ = make_music_relative (start, $3);
1131 | RELATIVE Composite_music {
1132 Pitch middle_c (0, 0, 0);
1133 $$ = make_music_relative (middle_c, $2);
1138 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1140 Grouped_music_list {
1141 /* Can also use Music at the expensive of two S/Rs similar to
1142 \repeat \alternative */
1143 THIS->lexer_->pop_state ();
1145 $$ = scm_cons ($3, SCM_EOL);
1147 | new_lyrics ADDLYRICS {
1148 THIS->lexer_->push_lyric_state ();
1149 } Grouped_music_list {
1150 THIS->lexer_->pop_state ();
1151 $$ = scm_cons ($4, $1);
1156 Grouped_music_list new_lyrics {
1158 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), unsmob_music (voice));
1159 if (!scm_is_string (name))
1161 name = get_next_unique_lyrics_context_id ();
1162 voice = context_spec_music (scm_makfrom0str ("Voice"),
1164 voice, SCM_EOL, false);
1167 SCM context = scm_makfrom0str ("Lyrics");
1168 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1171 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1173 SCM com = make_lyric_combine_music (name, scm_car (s));
1174 SCM csm = context_spec_music (context,
1175 SCM_UNDEFINED, com, SCM_EOL, true);
1176 lst = scm_cons (csm, lst);
1178 all->set_property ("elements", scm_cons (voice,
1180 $$ = all->unprotect ();
1182 | LYRICSTO simple_string {
1183 THIS->lexer_->push_lyric_state ();
1185 THIS->lexer_->pop_state ();
1187 $$ = make_lyric_combine_music (name, $4);
1192 CHANGE STRING '=' STRING {
1193 Music *t = MY_MAKE_MUSIC ("ContextChange");
1194 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1195 t-> set_property ("change-to-id", $4);
1198 $$ = t->unprotect ();
1204 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1205 scm_string_to_symbol ($1), $3);
1207 | UNSET simple_string {
1208 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1209 scm_string_to_symbol ($2));
1211 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1212 $$ = scm_list_4 (ly_symbol2scm ("push"),
1213 scm_string_to_symbol ($2), $5, $3);
1215 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1216 $$ = scm_list_5 (ly_symbol2scm ("push"),
1217 scm_string_to_symbol ($2), $6, $4, $3);
1219 | REVERT simple_string embedded_scm {
1220 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1221 scm_string_to_symbol ($2), $3);
1226 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1227 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1229 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1230 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1231 | DENIES { $$ = ly_symbol2scm ("denies"); }
1233 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1234 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1235 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1236 | NAME { $$ = ly_symbol2scm ("context-name"); }
1240 property_operation { $$ = $1; }
1241 | context_def_mod STRING {
1242 $$ = scm_list_2 ($1, $2);
1248 if (!is_regular_identifier ($1))
1250 @$.error (_("Grob name should be alphanumeric"));
1253 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1254 scm_string_to_symbol ($1));
1256 | simple_string '.' simple_string {
1257 $$ = scm_list_2 (scm_string_to_symbol ($1),
1258 scm_string_to_symbol ($3));
1263 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1264 Music *m = property_op_to_music (scm_list_4 (
1265 ly_symbol2scm ("push"),
1268 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1270 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1271 Music *m = property_op_to_music (scm_list_5 (
1272 ly_symbol2scm ("push"),
1275 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1277 | REVERT context_prop_spec embedded_scm {
1278 Music *m = property_op_to_music (scm_list_3 (
1279 ly_symbol2scm ("pop"),
1283 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1285 | SET context_prop_spec '=' scalar {
1286 Music *m = property_op_to_music (scm_list_3 (
1287 ly_symbol2scm ("assign"),
1290 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1292 | UNSET context_prop_spec {
1293 Music *m = property_op_to_music (scm_list_2 (
1294 ly_symbol2scm ("unset"),
1296 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1298 | ONCE music_property_def {
1299 Music *m = unsmob_music ($2);
1300 SCM e = m->get_property ("element");
1301 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1311 | STRING_IDENTIFIER {
1314 | string '+' string {
1315 $$ = scm_string_append (scm_list_2 ($1, $3));
1319 simple_string: STRING {
1325 | STRING_IDENTIFIER {
1346 $$ = scm_from_int ($1);
1352 pre_events doesn't contain anything. It is a trick:
1354 Adding pre_events to the simple_element
1355 makes the choice between
1361 simple_element: STRING
1363 a single shift/reduction conflict.
1365 nevertheless, this is not very clean, and we should find a different
1369 pre_events: /* empty */
1373 pre_events simple_element post_events {
1374 Music *m = unsmob_music ($2);
1376 SCM elts = m->get_property ("elements");
1378 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1380 m->set_property ("elements", elts);
1381 /* why is this giving wrong start location? -ns
1382 * $2->set_spot (@$); */
1384 i.set_location (@2, @3);
1386 $$ = m->unprotect ();
1388 | command_element { $$ = $1; }
1389 | note_chord_element
1394 chord_body optional_notemode_duration post_events
1396 Music *m = unsmob_music ($1);
1397 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1398 SCM es = m->get_property ("elements");
1399 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1401 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1402 unsmob_music (scm_car (s))->set_property ("duration", dur);
1403 es = ly_append2 (es, postevs);
1405 m-> set_property ("elements", es);
1407 $$ = m->self_scm ();
1417 simul_open: DOUBLE_ANGLE_OPEN
1420 simul_close: DOUBLE_ANGLE_CLOSE
1424 chord_open chord_body_elements chord_close
1426 Music *m = MY_MAKE_MUSIC ("EventChord");
1428 m->set_property ("elements",
1429 scm_reverse_x ($2, SCM_EOL));
1430 $$ = m->unprotect ();
1434 chord_body_elements:
1435 /* empty */ { $$ = SCM_EOL; }
1436 | chord_body_elements chord_body_element {
1437 $$ = scm_cons ($2, $1);
1442 pitch exclamations questions octave_check post_events
1449 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1450 n->set_property ("pitch", $1);
1453 n->set_property ("cautionary", SCM_BOOL_T);
1454 if (ex % 2 || q % 2)
1455 n->set_property ("force-accidental", SCM_BOOL_T);
1457 if (scm_is_pair (post)) {
1458 SCM arts = scm_reverse_x (post, SCM_EOL);
1459 n->set_property ("articulations", arts);
1461 if (scm_is_number (check))
1463 int q = scm_to_int (check);
1464 n->set_property ("absolute-octave", scm_from_int (q-1));
1467 $$ = n->unprotect ();
1469 | DRUM_PITCH post_events {
1470 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1471 n->set_property ("duration", $2);
1472 n->set_property ("drum-type", $1);
1475 if (scm_is_pair ($2)) {
1476 SCM arts = scm_reverse_x ($2, SCM_EOL);
1477 n->set_property ("articulations", arts);
1479 $$ = n->unprotect ();
1481 | music_function_chord_body {
1482 Music *m = run_music_function (THIS, $1);
1484 $$ = m->unprotect ();
1488 music_function_chord_body:
1490 $$ = scm_list_2 ($1, make_input (@$));
1492 | music_function_musicless_prefix chord_body_element {
1493 $$ = ly_append2 ($1, scm_list_1 ($2));
1497 music_function_event:
1498 music_function_musicless_prefix post_event {
1499 $$ = ly_append2 ($1, scm_list_1 ($2));
1504 TODO: use code generation for this
1506 music_function_musicless_prefix:
1507 MUSIC_FUNCTION_MUSIC {
1508 $$ = scm_list_2 ($1, make_input (@$));
1510 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument {
1511 $$ = scm_list_3 ($1, make_input (@$), $2);
1513 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument {
1514 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1516 | MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument {
1517 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1519 | MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument function_scm_argument {
1520 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
1527 Music *m = MY_MAKE_MUSIC ("EventChord");
1528 m->set_property ("elements", scm_cons ($1, SCM_EOL));
1529 Music *e = unsmob_music ($1);
1532 $$ = m->unprotect ();
1534 | SKIP duration_length {
1535 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1536 skip->set_property ("duration", $2);
1537 skip->set_spot (@$);
1538 $$ = skip->unprotect ();
1541 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1542 m->set_property ("span-direction", scm_from_int (START));
1545 Music *chord = MY_MAKE_MUSIC ("EventChord");
1546 chord->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1548 chord->set_spot (@$);
1549 $$ = chord->unprotect ();
1552 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1553 m->set_property ("span-direction", scm_from_int (STOP));
1556 Music *chord = MY_MAKE_MUSIC ("EventChord");
1557 chord->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1558 chord->set_spot (@$);
1560 $$ = chord->unprotect ();
1563 Music *m = MY_MAKE_MUSIC ("VoiceSeparator");
1565 $$ = m->unprotect ();
1568 SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
1570 Music *m = unsmob_music (pipe);
1574 m = MY_MAKE_MUSIC ("BarCheck");
1577 $$ = m->unprotect ();
1579 | TRANSPOSITION pitch {
1581 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1582 Music *m = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1583 sounds_as_c.smobbed_copy());
1585 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1586 m->unprotect (), SCM_EOL, false);
1588 | PARTIAL duration_length {
1589 Moment m = - unsmob_duration ($2)->get_length ();
1590 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1592 SCM ps = p->unprotect ();
1593 ps = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1594 ps, SCM_EOL, false);
1595 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1596 ps, SCM_EOL, false);
1600 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1602 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1605 SCM proc = ly_lily_module_constant ("make-mark-set");
1607 $$ = scm_call_1 (proc, $2);
1613 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent")->unprotect ();
1616 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1617 $$ = m->unprotect ();
1623 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1624 $$ = key->unprotect ();
1626 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1628 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1629 if (scm_ilength ($3) > 0)
1631 key->set_property ("pitch-alist", $3);
1632 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1633 key->transpose (* unsmob_pitch ($2));
1635 THIS->parser_error (@3, _ ("second argument must be pitch list"));
1638 $$ = key->unprotect ();
1647 | post_events post_event {
1648 unsmob_music ($2)->set_spot (@2);
1649 $$ = scm_cons ($2, $$);
1654 direction_less_event {
1657 | '-' music_function_event {
1658 Music *mus = run_music_function (THIS, $2);
1660 $$ = mus->unprotect ();
1663 if (!THIS->lexer_->is_lyric_state ())
1664 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1665 $$ = MY_MAKE_MUSIC ("HyphenEvent")->unprotect ();
1668 if (!THIS->lexer_->is_lyric_state ())
1669 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1670 $$ = MY_MAKE_MUSIC ("ExtenderEvent")->unprotect ();
1672 | script_dir direction_reqd_event {
1675 Music *m = unsmob_music ($2);
1676 m->set_property ("direction", scm_from_int ($1));
1680 | script_dir direction_less_event {
1683 Music *m = unsmob_music ($2);
1684 m->set_property ("direction", scm_from_int ($1));
1688 | string_number_event
1691 string_number_event:
1693 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1694 s->set_property ("string-number", scm_from_int ($1));
1696 $$ = s->unprotect ();
1700 direction_less_char:
1702 $$ = ly_symbol2scm ("bracketOpenSymbol");
1705 $$ = ly_symbol2scm ("bracketCloseSymbol");
1708 $$ = ly_symbol2scm ("tildeSymbol");
1711 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1714 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1717 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1720 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1723 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1726 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1729 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1733 direction_less_event:
1734 direction_less_char {
1735 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1737 if (unsmob_music (predefd))
1739 m = unsmob_music (predefd)->clone ();
1743 m = MY_MAKE_MUSIC ("Music");
1746 $$ = m->unprotect ();
1748 | EVENT_IDENTIFIER {
1752 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1754 a->set_property ("tremolo-type", scm_from_int ($1));
1755 $$ = a->unprotect ();
1759 direction_reqd_event:
1763 | script_abbreviation {
1764 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1765 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1766 if (scm_is_string (s))
1767 a->set_property ("articulation-type", s);
1768 else THIS->parser_error (@1, _ ("expecting string as script definition"));
1769 $$ = a->unprotect ();
1774 /**/ { $$ = SCM_EOL; }
1775 | '=' { $$ = scm_from_int (0); }
1776 | '=' sub_quotes { $$ = scm_from_int ($2); }
1777 | '=' sup_quotes { $$ = scm_from_int ($2); }
1802 | NOTENAME_PITCH sup_quotes {
1803 Pitch p = *unsmob_pitch ($1);
1804 p = p.transposed (Pitch ($2,0,0));
1805 $$ = p.smobbed_copy ();
1807 | NOTENAME_PITCH sub_quotes {
1808 Pitch p =* unsmob_pitch ($1);
1809 p = p.transposed (Pitch (-$2,0,0));
1810 $$ = p.smobbed_copy ();
1822 | TONICNAME_PITCH sup_quotes {
1823 Pitch p = *unsmob_pitch ($1);
1824 p = p.transposed (Pitch ($2,0,0));
1825 $$ = p.smobbed_copy ();
1827 | TONICNAME_PITCH sub_quotes {
1828 Pitch p =* unsmob_pitch ($1);
1830 p = p.transposed (Pitch (-$2,0,0));
1831 $$ = p.smobbed_copy ();
1841 pitch_also_in_chords:
1848 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1849 t->set_property ("text", $1);
1851 $$ = t->unprotect ();
1854 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1855 t->set_property ("text",
1856 make_simple_markup ($1));
1858 $$ = t->unprotect ();
1861 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1862 t->set_property ("digit", scm_from_int ($1));
1864 $$ = t->unprotect ();
1868 script_abbreviation:
1870 $$ = scm_makfrom0str ("Hat");
1873 $$ = scm_makfrom0str ("Plus");
1876 $$ = scm_makfrom0str ("Dash");
1879 $$ = scm_makfrom0str ("Bar");
1882 $$ = scm_makfrom0str ("Larger");
1885 $$ = scm_makfrom0str ("Dot");
1888 $$ = scm_makfrom0str ("Underscore");
1895 | '-' { $$ = CENTER; }
1906 multiplied_duration {
1911 optional_notemode_duration:
1913 Duration dd = THIS->default_duration_;
1914 $$ = dd.smobbed_copy ();
1916 | multiplied_duration {
1918 THIS->default_duration_ = *unsmob_duration ($$);
1923 bare_unsigned dots {
1925 if (!is_duration ($1))
1926 THIS->parser_error (@1, _f ("not a duration: %d", $1));
1930 $$ = Duration (len, $2).smobbed_copy ();
1932 | DURATION_IDENTIFIER dots {
1933 Duration *d = unsmob_duration ($1);
1934 Duration k (d->duration_log (), d->dot_count () + $2);
1940 multiplied_duration:
1944 | multiplied_duration '*' bare_unsigned {
1945 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1947 | multiplied_duration '*' FRACTION {
1948 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1950 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1955 FRACTION { $$ = $1; }
1956 | UNSIGNED '/' UNSIGNED {
1957 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1974 | ':' bare_unsigned {
1975 if (!is_duration ($2))
1976 THIS->parser_error (@2, _f ("not a duration: %d", $2));
1983 $$ = scm_from_int ($1);
1986 $$ = scm_from_int ($1);
1988 | STRING { $$ = $1; }
1989 | full_markup { $$ = $1; }
1992 figured_bass_alteration:
2000 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2001 $$ = bfr->self_scm ();
2006 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2007 $$ = bfr->self_scm ();
2009 if (scm_is_number ($1))
2010 bfr->set_property ("figure", $1);
2011 else if (Text_interface::is_markup ($1))
2012 bfr->set_property ("text", $1);
2019 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2021 | bass_figure figured_bass_alteration {
2022 Music *m = unsmob_music ($1);
2024 SCM salter = m->get_property ("alteration");
2025 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2026 m->set_property ("alteration",
2027 scm_from_int (alter + $2));
2029 m->set_property ("alteration", scm_from_int (0));
2032 | bass_figure figured_bass_modification {
2033 Music *m = unsmob_music ($1);
2034 if ($2 == ly_symbol2scm ("plus"))
2036 m->set_property ("augmented", SCM_BOOL_T);
2038 else if ($2 == ly_symbol2scm ("slash"))
2040 m->set_property ("diminished", SCM_BOOL_T);
2042 else if ($2 == ly_symbol2scm ("exclamation"))
2044 m->set_property ("no-continuation", SCM_BOOL_T);
2050 figured_bass_modification:
2052 $$ = ly_symbol2scm ("plus");
2055 $$ = ly_symbol2scm ("exclamation");
2058 $$ = ly_symbol2scm ("slash");
2068 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2076 | figure_list br_bass_figure {
2077 $$ = scm_cons ($2, $1);
2082 FIGURE_OPEN figure_list FIGURE_CLOSE {
2083 Music *m = MY_MAKE_MUSIC ("EventChord");
2084 $2 = scm_reverse_x ($2, SCM_EOL);
2085 m->set_property ("elements", $2);
2086 $$ = m->self_scm ();
2097 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2098 if (!THIS->lexer_->is_note_state ())
2099 THIS->parser_error (@1, _ ("have to be in Note mode for notes"));
2103 n = MY_MAKE_MUSIC ("RestEvent");
2105 n = MY_MAKE_MUSIC ("NoteEvent");
2107 n->set_property ("pitch", $1);
2108 n->set_property ("duration", $5);
2110 if (scm_is_number ($4))
2112 int q = scm_to_int ($4);
2113 n->set_property ("absolute-octave", scm_from_int (q-1));
2117 n->set_property ("cautionary", SCM_BOOL_T);
2118 if ($2 % 2 || $3 % 2)
2119 n->set_property ("force-accidental", SCM_BOOL_T);
2121 Music *v = MY_MAKE_MUSIC ("EventChord");
2122 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2127 $$ = v->unprotect ();
2129 | DRUM_PITCH optional_notemode_duration {
2130 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2131 n->set_property ("duration", $2);
2132 n->set_property ("drum-type", $1);
2134 Music *v = MY_MAKE_MUSIC ("EventChord");
2135 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2139 $$ = v->unprotect ();
2142 | figure_spec optional_notemode_duration {
2143 Music *m = unsmob_music ($1);
2145 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2147 unsmob_music (scm_car (s))->set_property ("duration", $2);
2149 $$ = m->unprotect ();
2151 | RESTNAME optional_notemode_duration {
2153 if (ly_scm2string ($1) == "s") {
2155 ev = MY_MAKE_MUSIC ("SkipEvent");
2158 ev = MY_MAKE_MUSIC ("RestEvent");
2161 ev->set_property ("duration", $2);
2163 Music *velt = MY_MAKE_MUSIC ("EventChord");
2164 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2165 velt->set_spot (@$);
2169 $$ = velt->unprotect ();
2171 | MULTI_MEASURE_REST optional_notemode_duration {
2172 SCM proc = ly_lily_module_constant ("make-multi-measure-rest");
2173 $$ = scm_call_2 (proc, $2, make_input (@$));
2175 | lyric_element optional_notemode_duration {
2176 if (!THIS->lexer_->is_lyric_state ())
2177 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2179 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2180 levent->set_property ("text", $1);
2181 levent->set_property ("duration",$2);
2182 levent->set_spot (@$);
2183 Music *velt = MY_MAKE_MUSIC ("EventChord");
2184 velt->set_property ("elements", scm_list_1 (levent->self_scm ()));
2186 $$= velt->unprotect ();
2189 if (!THIS->lexer_->is_chord_state ())
2190 THIS->parser_error (@1, _ ("have to be in Chord mode for chords"));
2205 steno_tonic_pitch optional_notemode_duration {
2206 $$ = make_chord ($1, $2, SCM_EOL);
2208 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2209 SCM its = scm_reverse_x ($4, SCM_EOL);
2210 $$ = make_chord ($1, $2, scm_cons ($3, its));
2218 | chord_items chord_item {
2219 $$ = scm_cons ($2, $$);
2225 $$ = ly_symbol2scm ("chord-colon");
2228 $$ = ly_symbol2scm ("chord-caret");
2230 | CHORD_SLASH steno_tonic_pitch {
2231 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2233 | CHORD_BASS steno_tonic_pitch {
2234 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2243 $$ = scm_reverse_x ($1, SCM_EOL);
2251 step_number { $$ = scm_cons ($1, SCM_EOL); }
2252 | step_numbers '.' step_number {
2253 $$ = scm_cons ($3, $$);
2259 $$ = make_chord_step ($1, 0);
2261 | bare_unsigned '+' {
2262 $$ = make_chord_step ($1, SHARP);
2264 | bare_unsigned CHORD_MINUS {
2265 $$ = make_chord_step ($1, FLAT);
2272 TODO: should deprecate in favor of Scheme?
2276 number_expression '+' number_term {
2277 $$ = scm_sum ($1, $3);
2279 | number_expression '-' number_term {
2280 $$ = scm_difference ($1, $3);
2289 | number_factor '*' number_factor {
2290 $$ = scm_product ($1, $3);
2292 | number_factor '/' number_factor {
2293 $$ = scm_divide ($1, $3);
2298 '-' number_factor { /* %prec UNARY_MINUS */
2299 $$ = scm_difference ($2, SCM_UNDEFINED);
2307 $$ = scm_from_int ($1);
2312 | NUMBER_IDENTIFIER {
2315 | REAL NUMBER_IDENTIFIER {
2316 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2318 | UNSIGNED NUMBER_IDENTIFIER {
2319 $$ = scm_from_double ($1 *scm_to_double ($2));
2335 | exclamations '!' { $$ ++; }
2340 | questions '?' { $$ ++; }
2344 This should be done more dynamically if possible.
2348 LYRIC_MARKUP_IDENTIFIER {
2352 { THIS->lexer_->push_markup_state (); }
2355 THIS->lexer_->pop_state ();
2364 { THIS->lexer_->push_markup_state (); }
2367 THIS->lexer_->pop_state ();
2373 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2375 | markup_head_1_list simple_markup {
2376 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2384 markup_composed_list {
2387 | markup_braced_list {
2392 markup_composed_list:
2393 markup_head_1_list markup_braced_list {
2394 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2400 '{' markup_braced_list_body '}' {
2401 $$ = scm_reverse_x ($2, SCM_EOL);
2405 markup_braced_list_body:
2406 /* empty */ { $$ = SCM_EOL; }
2407 | markup_braced_list_body markup {
2408 $$ = scm_cons ($2, $1);
2410 | markup_braced_list_body markup_list {
2411 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2416 MARKUP_HEAD_MARKUP0 {
2417 $$ = scm_list_1 ($1);
2419 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2420 $$ = scm_list_2 ($1, $2);
2422 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2423 $$ = scm_list_3 ($1, $2, $3);
2428 markup_head_1_item {
2429 $$ = scm_list_1 ($1);
2431 | markup_head_1_list markup_head_1_item {
2432 $$ = scm_cons ($2, $1);
2438 $$ = make_simple_markup ($1);
2440 | MARKUP_IDENTIFIER {
2443 | LYRIC_MARKUP_IDENTIFIER {
2446 | STRING_IDENTIFIER {
2450 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2451 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2452 } '{' score_body '}' {
2454 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2456 THIS->lexer_->pop_state ();
2458 | MARKUP_HEAD_SCM0 embedded_scm {
2459 $$ = scm_list_2 ($1, $2);
2461 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2462 $$ = scm_list_4 ($1, $2, $3, $4);
2464 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2465 $$ = scm_list_3 ($1, $2, $3);
2467 | MARKUP_HEAD_EMPTY {
2468 $$ = scm_list_1 ($1);
2470 | MARKUP_HEAD_LIST0 markup_list {
2471 $$ = scm_list_2 ($1,$2);
2473 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2474 $$ = scm_list_3 ($1, $2, $3);
2479 markup_head_1_list simple_markup {
2480 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2481 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2491 Lily_parser::set_yydebug (bool )
2499 Lily_parser::do_yyparse ()
2501 yyparse ((void*)this);
2510 It is a little strange to have this function in this file, but
2511 otherwise, we have to import music classes into the lexer.
2515 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2517 if (scm_is_string (sid)) {
2519 return STRING_IDENTIFIER;
2520 } else if (unsmob_book (sid)) {
2521 *destination = unsmob_book (sid)->clone ()->self_scm ();
2522 return BOOK_IDENTIFIER;
2523 } else if (scm_is_number (sid)) {
2525 return NUMBER_IDENTIFIER;
2526 } else if (unsmob_context_def (sid)) {
2527 *destination = unsmob_context_def (sid)->clone_scm ();
2528 return CONTEXT_DEF_IDENTIFIER;
2529 } else if (unsmob_score (sid)) {
2530 Score *score = new Score (*unsmob_score (sid));
2531 *destination = score->self_scm ();
2532 return SCORE_IDENTIFIER;
2533 } else if (Music *mus = unsmob_music (sid)) {
2534 mus = mus->clone ();
2535 *destination = mus->self_scm ();
2536 unsmob_music (*destination)->
2537 set_property ("origin", make_input (last_input_));
2539 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2542 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2543 } else if (unsmob_duration (sid)) {
2544 *destination = unsmob_duration (sid)->smobbed_copy ();
2545 return DURATION_IDENTIFIER;
2546 } else if (unsmob_output_def (sid)) {
2547 Output_def *p = unsmob_output_def (sid);
2550 *destination = p->self_scm ();
2551 return OUTPUT_DEF_IDENTIFIER;
2552 } else if (Text_interface::is_markup (sid)) {
2554 if (is_lyric_state ())
2555 return LYRIC_MARKUP_IDENTIFIER;
2556 return MARKUP_IDENTIFIER;
2563 property_op_to_music (SCM op)
2566 SCM tag = scm_car (op);
2567 SCM symbol = scm_cadr (op);
2568 SCM args = scm_cddr (op);
2569 SCM grob_val = SCM_UNDEFINED;
2570 SCM grob_path = SCM_UNDEFINED;
2571 SCM val = SCM_UNDEFINED;
2573 if (tag == ly_symbol2scm ("assign"))
2575 m = MY_MAKE_MUSIC ("PropertySet");
2576 val = scm_car (args);
2578 else if (tag == ly_symbol2scm ("unset"))
2579 m = MY_MAKE_MUSIC ("PropertyUnset");
2580 else if (tag == ly_symbol2scm ("push"))
2582 m = MY_MAKE_MUSIC ("OverrideProperty");
2583 grob_val = scm_car (args);
2584 grob_path = scm_cdr (args);
2585 m->set_property ("pop-first", SCM_BOOL_T);
2587 else if (tag == ly_symbol2scm ("pop")) {
2588 m = MY_MAKE_MUSIC ("RevertProperty");
2592 m->set_property ("symbol", symbol);
2594 if (val != SCM_UNDEFINED)
2595 m->set_property ("value", val);
2596 if (grob_val != SCM_UNDEFINED)
2597 m->set_property ("grob-value", grob_val);
2598 if (grob_path != SCM_UNDEFINED)
2599 m->set_property ("grob-property-path", grob_path);
2605 context_spec_music (SCM type, SCM id, SCM m, SCM ops, bool create_new)
2607 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2609 csm->set_property ("element", m);
2611 csm->set_property ("context-type",
2612 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2613 csm->set_property ("property-operations", ops);
2615 csm->set_property ("create-new", SCM_BOOL_T);
2617 if (scm_is_string (id))
2618 csm->set_property ("context-id", id);
2619 return csm->unprotect ();
2623 get_next_unique_context_id ()
2625 return scm_makfrom0str ("$uniqueContextId");
2630 get_next_unique_lyrics_context_id ()
2632 static int new_context_count;
2634 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2635 return scm_makfrom0str (s);
2640 run_music_function (Lily_parser *parser, SCM expr)
2642 SCM func = scm_car (expr);
2643 Input *loc = unsmob_input (scm_cadr (expr));
2644 SCM args = scm_cddr (expr);
2645 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2647 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2650 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2652 parser->error_level_ = 1;
2658 m = scm_apply_0 (func, scm_cons (parser->self_scm(),
2663 if (unsmob_music (m))
2665 retval = unsmob_music (m);
2671 loc->error (_ ("music head function must return Music object"));
2672 retval = MY_MAKE_MUSIC ("Music");
2674 retval->set_spot (*loc);
2679 is_regular_identifier (SCM id)
2681 string str = ly_scm2string (id);
2682 char const *s = str.c_str ();
2691 v = v && isalnum (*s);
2699 get_first_context_id (SCM type, Music *m)
2701 SCM id = m->get_property ("context-id");
2702 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2703 && scm_is_string (m->get_property ("context-id"))
2704 && scm_c_string_length (id) > 0)
2712 make_simple_markup (SCM a)
2720 return t && t == 1 << intlog2 (t);
2724 set_music_properties (Music *p, SCM a)
2726 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2727 p->internal_set_property (scm_caar (k), scm_cdar (k));
2732 make_chord_step (int step, int alter)
2739 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2740 return m.smobbed_copy ();
2745 make_chord (SCM pitch, SCM dur, SCM modification_list)
2747 SCM chord_ctor = ly_lily_module_constant ("construct-chord");
2748 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
2750 unsmob_music (ch)->protect();
2755 /* Todo: actually also use apply iso. call too ... */
2757 ly_input_procedure_p (SCM x)
2759 return ly_is_procedure (x)
2760 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2764 set_property_music (SCM sym, SCM value)
2766 Music *p = MY_MAKE_MUSIC ("PropertySet");
2767 p->set_property ("symbol", sym);
2768 p->set_property ("value", value);
2773 make_music_relative (Pitch start, SCM music)
2775 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2776 relative->set_property ("element", music);
2778 Music *m = unsmob_music (music);
2779 Pitch last = m->to_relative_octave (start);
2780 if (lily_1_8_relative)
2781 m->set_property ("last-pitch", last.smobbed_copy ());
2782 return relative->unprotect ();
2786 make_lyric_combine_music (SCM name, SCM music)
2788 Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
2789 combine->set_property ("element", music);
2790 combine->set_property ("associated-context", name);
2791 return combine->unprotect ();
2796 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2798 Lily_parser *pars = (Lily_parser*) v;
2799 Lily_lexer *lex = pars->lexer_;
2801 lex->lexval = (void*) s;
2803 lex->prepare_for_next_token ();
2804 return lex->yylex ();