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))
115 - Don't use lily module, create a new module instead.
116 - delay application of the function
118 #define MAKE_SYNTAX(name, location, ...) \
119 scm_apply_0 (ly_lily_module_constant (name), scm_list_n (make_input (location), __VA_ARGS__, SCM_UNDEFINED));
121 Music *property_op_to_music (SCM op);
122 SCM context_spec_music (SCM type, SCM id, SCM m, SCM ops, bool create_new);
123 SCM get_next_unique_context_id ();
124 SCM get_next_unique_lyrics_context_id ();
131 #define _(x) gettext (x)
136 SCM make_lyric_combine_music (SCM name, SCM music);
137 SCM make_music_relative (Pitch start, SCM music);
138 Music *run_music_function (Lily_parser *, SCM expr);
139 Music *set_property_music (SCM sym, SCM value);
140 SCM get_first_context_id (SCM type, Music *m);
141 SCM make_chord (SCM pitch, SCM dur, SCM modification_list);
142 SCM make_chord_step (int step, int alter);
143 SCM make_simple_markup (SCM a);
144 bool is_duration (int t);
145 bool is_regular_identifier (SCM id);
146 bool ly_input_procedure_p (SCM x);
147 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
148 void set_music_properties (Music *p, SCM a);
152 /* The third option is an alias that will be used to display the
153 syntax error. Bison CVS now correctly handles backslash escapes.
155 FIXME: Bison needs to translate some of these, eg, STRING.
159 /* Keyword tokens with plain escaped name. */
160 %token ACCEPTS "\\accepts"
161 %token ADDLYRICS "\\addlyrics"
162 %token ADDQUOTE "\\addquote"
163 %token ALIAS "\\alias"
164 %token ALTERNATIVE "\\alternative"
166 %token CHANGE "\\change"
167 %token CHORDMODE "\\chordmode"
168 %token CHORDS "\\chords"
169 %token CONSISTS "\\consists"
170 %token CONTEXT "\\context"
171 %token DEFAULT "\\default"
172 %token DEFAULTCHILD "\\defaultchild"
173 %token DENIES "\\denies"
174 %token DESCRIPTION "\\description"
175 %token DRUMMODE "\\drummode"
176 %token DRUMS "\\drums"
177 %token FIGUREMODE "\\figuremode"
178 %token FIGURES "\\figures"
179 %token GROBDESCRIPTIONS "\\grobdescriptions"
180 %token HEADER "\\header"
181 %token INVALID "\\invalid"
183 %token LAYOUT "\\layout"
184 %token LYRICMODE "\\lyricmode"
185 %token LYRICS "\\lyrics"
186 %token LYRICSTO "\\lyricsto"
188 %token MARKUP "\\markup"
191 %token NOTEMODE "\\notemode"
192 %token OBJECTID "\\objectid"
193 %token OCTAVE "\\octave"
195 %token OVERRIDE "\\override"
196 %token PAPER "\\paper"
197 %token PARTIAL "\\partial"
198 %token RELATIVE "\\relative"
199 %token REMOVE "\\remove"
200 %token REPEAT "\\repeat"
202 %token REVERT "\\revert"
203 %token SCORE "\\score"
204 %token SEQUENTIAL "\\sequential"
206 %token SIMULTANEOUS "\\simultaneous"
208 %token TEMPO "\\tempo"
209 %token TIMES "\\times"
210 %token TRANSPOSE "\\transpose"
211 %token TRANSPOSITION "\\transposition"
213 %token UNSET "\\unset"
216 /* Keyword token exceptions. */
217 %token TIME_T "\\time"
218 %token NEWCONTEXT "\\new"
221 /* Other string tokens. */
223 %token CHORD_BASS "/+"
224 %token CHORD_CARET "^"
225 %token CHORD_COLON ":"
226 %token CHORD_MINUS "-"
227 %token CHORD_SLASH "/"
228 %token DOUBLE_ANGLE_CLOSE ">>"
229 %token DOUBLE_ANGLE_OPEN "<<"
230 %token E_BACKSLASH "\\"
231 %token E_ANGLE_CLOSE "\\>"
232 %token E_CHAR "\\C[haracter]"
234 %token E_EXCLAMATION "\\!"
235 %token E_BRACKET_OPEN "\\["
237 %token E_BRACKET_CLOSE "\\]"
238 %token E_ANGLE_OPEN "\\<"
244 If we give names, Bison complains.
246 %token FIGURE_CLOSE /* "\\>" */
247 %token FIGURE_OPEN /* "\\<" */
248 %token FIGURE_SPACE "_"
251 %token CHORDMODIFIERS
253 %token MULTI_MEASURE_REST
258 %token <i> E_UNSIGNED
261 %token <scm> BOOK_IDENTIFIER
262 %token <scm> CHORDMODIFIER_PITCH
263 %token <scm> CHORD_MODIFIER
264 %token <scm> CONTEXT_DEF_IDENTIFIER
265 %token <scm> DRUM_PITCH
266 %token <scm> DURATION_IDENTIFIER
267 %token <scm> EVENT_IDENTIFIER
268 %token <scm> FRACTION
269 %token <scm> LYRICS_STRING
270 %token <scm> LYRIC_MARKUP_IDENTIFIER
271 %token <scm> MARKUP_HEAD_EMPTY
272 %token <scm> MARKUP_HEAD_LIST0
273 %token <scm> MARKUP_HEAD_MARKUP0
274 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
275 %token <scm> MARKUP_HEAD_SCM0
276 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
277 %token <scm> MARKUP_HEAD_SCM0_SCM1
278 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
279 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
280 %token <scm> MARKUP_IDENTIFIER
281 %token <scm> MUSIC_FUNCTION
282 %token <scm> MUSIC_FUNCTION_MARKUP
283 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
284 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
285 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
286 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
287 %token <scm> MUSIC_FUNCTION_MUSIC
288 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
289 %token <scm> MUSIC_FUNCTION_SCM
290 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
291 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
292 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC
293 %token <scm> MUSIC_FUNCTION_SCM_SCM
294 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
295 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM
296 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC
297 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC
298 %token <scm> MUSIC_IDENTIFIER
299 %token <scm> NOTENAME_PITCH
300 %token <scm> NUMBER_IDENTIFIER
301 %token <scm> OUTPUT_DEF_IDENTIFIER
303 %token <scm> RESTNAME
304 %token <scm> SCM_IDENTIFIER
306 %token <scm> SCORE_IDENTIFIER
308 %token <scm> STRING_IDENTIFIER
309 %token <scm> TONICNAME_PITCH
312 %type <book> book_block
313 %type <book> book_body
315 %type <i> bare_unsigned
316 %type <i> figured_bass_alteration
318 %type <i> exclamations
319 %type <i> optional_rest
324 %type <i> tremolo_type
327 %type <scm> Composite_music
328 %type <scm> Grouped_music_list
330 %type <scm> Prefix_composite_music
331 %type <scm> Repeated_music
332 %type <scm> Sequential_music
333 %type <scm> Simple_music
334 %type <scm> Simultaneous_music
335 %type <scm> chord_body
336 %type <scm> chord_body_element
337 %type <scm> command_element
338 %type <scm> command_event
339 %type <scm> context_change
340 %type <scm> direction_less_event
341 %type <scm> direction_reqd_event
342 %type <scm> event_chord
343 %type <scm> gen_text_def
344 %type <scm> music_property_def
345 %type <scm> note_chord_element
346 %type <scm> post_event
347 %type <scm> re_rhythmed_music
348 %type <scm> relative_music
349 %type <scm> simple_element
350 %type <scm> string_number_event
351 %type <scm> tempo_event
352 %type <scm> toplevel_music
354 %type <outputdef> output_def_body
355 %type <outputdef> output_def_head
356 %type <outputdef> output_def_head_with_mode_switch
357 %type <outputdef> output_def
358 %type <outputdef> paper_block
360 %type <scm> Alternative_music
361 %type <scm> Generic_prefix_music_scm
362 %type <scm> Music_list
363 %type <scm> absolute_pitch
364 %type <scm> assignment_id
365 %type <scm> bare_number
366 %type <scm> music_function_event
367 %type <scm> music_function_chord_body
368 %type <scm> music_function_musicless_prefix
369 %type <scm> bass_figure
370 %type <scm> figured_bass_modification
371 %type <scm> br_bass_figure
372 %type <scm> bass_number
373 %type <scm> chord_body_elements
374 %type <scm> chord_item
375 %type <scm> chord_items
376 %type <scm> chord_separator
377 %type <scm> context_def_mod
378 %type <scm> context_def_spec_block
379 %type <scm> context_def_spec_body
380 %type <scm> context_mod
381 %type <scm> context_mod_list
382 %type <scm> context_prop_spec
383 %type <scm> direction_less_char
384 %type <scm> duration_length
385 %type <scm> embedded_scm
386 %type <scm> figure_list
387 %type <scm> figure_spec
389 %type <scm> full_markup
390 %type <scm> identifier_init
391 %type <scm> lilypond_header
392 %type <scm> lilypond_header_body
393 %type <scm> lyric_element
394 %type <scm> lyric_markup
396 %type <scm> markup_braced_list
397 %type <scm> markup_braced_list_body
398 %type <scm> markup_composed_list
399 %type <scm> markup_head_1_item
400 %type <scm> markup_head_1_list
401 %type <scm> markup_list
402 %type <scm> markup_top
403 %type <scm> mode_changing_head
404 %type <scm> mode_changing_head_with_context
405 %type <scm> multiplied_duration
406 %type <scm> new_chord
407 %type <scm> new_lyrics
408 %type <scm> number_expression
409 %type <scm> number_factor
410 %type <scm> number_term
411 %type <scm> object_id_setting
412 %type <scm> octave_check
413 %type <scm> optional_context_mod
414 %type <scm> optional_id
415 %type <scm> optional_notemode_duration
417 %type <scm> pitch_also_in_chords
418 %type <scm> post_events
419 %type <scm> property_operation
421 %type <scm> script_abbreviation
422 %type <scm> simple_markup
423 %type <scm> simple_string
424 %type <scm> steno_duration
425 %type <scm> steno_pitch
426 %type <scm> steno_tonic_pitch
427 %type <scm> step_number
428 %type <scm> step_numbers
430 %type <scm> function_scm_argument
432 %type <score> score_block
433 %type <score> score_body
438 /* We don't assign precedence to / and *, because we might need varied
439 prec levels in different prods */
445 lilypond: /* empty */
446 | lilypond toplevel_expression {
448 | lilypond assignment {
451 THIS->error_level_ = 1;
454 THIS->error_level_ = 1;
460 OBJECTID STRING { $$ = $2; }
465 THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
469 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
470 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
476 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
477 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
481 Music *music = unsmob_music ($1);
482 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
483 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
486 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler");
487 scm_call_2 (proc, THIS->self_scm (), $1);
491 Output_def * od = $1;
493 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
494 id = ly_symbol2scm ("$defaultpaper");
495 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
496 id = ly_symbol2scm ("$defaultmidi");
497 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
498 id = ly_symbol2scm ("$defaultlayout");
500 THIS->lexer_->set_identifier (id, od->self_scm ());
516 lilypond_header_body:
518 $$ = get_header(THIS);
519 THIS->lexer_->add_scope ($$);
521 | lilypond_header_body assignment {
527 HEADER '{' lilypond_header_body '}' {
528 $$ = THIS->lexer_->remove_scope ();
537 | LYRICS_STRING { $$ = $1; }
541 assignment_id '=' identifier_init {
542 if (! is_regular_identifier ($1))
545 /* no longer valid with dashes in \paper{} block. */
546 @1.warning (_ ("identifier should have alphabetic characters only"));
551 THIS->lexer_->set_identifier ($1, $3);
554 TODO: devise standard for protection in parser.
556 The parser stack lives on the C-stack, which means that
557 all objects can be unprotected as soon as they're here.
567 $$ = $1->self_scm ();
571 $$ = $1->self_scm ();
575 $$ = $1->self_scm ();
578 | context_def_spec_block {
587 | number_expression {
600 $$ = scm_from_int ($1);
604 context_def_spec_block:
605 CONTEXT '{' context_def_spec_body '}'
611 context_def_spec_body:
613 $$ = Context_def::make_scm ();
614 unsmob_context_def ($$)->set_spot (@$);
616 | CONTEXT_DEF_IDENTIFIER {
618 unsmob_context_def ($$)->set_spot (@$);
620 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
621 Context_def*td = unsmob_context_def ($$);
623 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
624 SCM tag = scm_caar (p);
626 /* TODO: should make new tag "grob-definition" ? */
627 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
628 tag, scm_cons (scm_cdar (p), SCM_EOL)));
631 | context_def_spec_body context_mod {
632 unsmob_context_def ($$)->add_context_mod ($2);
639 BOOK '{' book_body '}' {
645 * Use 'handlers' like for toplevel-* stuff?
646 * grok \layout and \midi? */
651 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
652 $$->paper_->unprotect ();
653 $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader");
656 $$ = unsmob_book ($1);
659 | book_body paper_block {
663 | book_body score_block {
664 SCM s = $2->self_scm ();
668 | book_body full_markup {
671 | book_body lilypond_header {
676 $$->scores_ = SCM_EOL;
678 | book_body object_id_setting {
679 $$->user_key_ = ly_scm2string ($2);
684 SCORE '{' score_body '}' {
692 SCM scorify = ly_lily_module_constant ("scorify-music");
693 SCM score = scm_call_2 (scorify, m, THIS->self_scm ());
695 // pass ownernship to C++ again.
696 $$ = unsmob_score (score);
701 $$ = unsmob_score ($1);
704 | score_body object_id_setting {
705 $$->user_key_ = ly_scm2string ($2);
707 | score_body lilypond_header {
710 | score_body output_def {
711 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
713 THIS->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
718 $$->add_output_def ($2);
723 $$->error_found_ = true;
735 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
737 THIS->parser_error (@1, _ ("need \\paper for paper block"));
738 $$ = get_paper (THIS);
745 output_def_body '}' {
748 THIS->lexer_->remove_scope ();
749 THIS->lexer_->pop_state ();
755 $$ = get_paper (THIS);
756 $$->input_origin_ = @$;
757 THIS->lexer_->add_scope ($$->scope_);
760 Output_def *p = get_midi (THIS);
762 THIS->lexer_->add_scope (p->scope_);
765 Output_def *p = get_layout (THIS);
767 THIS->lexer_->add_scope (p->scope_);
772 output_def_head_with_mode_switch:
774 THIS->lexer_->push_initial_state ();
780 output_def_head_with_mode_switch '{' {
782 $$->input_origin_.set_spot (@$);
784 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
786 Output_def *o = unsmob_output_def ($3);
787 o->input_origin_.set_spot (@$);
789 THIS->lexer_->remove_scope ();
790 THIS->lexer_->add_scope (o->scope_);
792 | output_def_body assignment {
795 | output_def_body context_def_spec_block {
796 assign_context_def ($$, $2);
798 | output_def_body tempo_event {
800 junk this ? there already is tempo stuff in
803 int m = scm_to_int (unsmob_music($2)->get_property ("metronome-count"));
804 Duration *d = unsmob_duration (unsmob_music($2)->get_property ("tempo-unit"));
805 set_tempo ($$, d->get_length (), m);
807 | output_def_body error {
813 TEMPO steno_duration '=' bare_unsigned {
814 Music *m = MY_MAKE_MUSIC ("MetronomeChangeEvent");
815 m->set_property ("tempo-unit", $2);
816 m->set_property ("metronome-count", scm_from_int ( $4));
817 $$ = m->unprotect ();
822 The representation of a list is the
826 to have efficient append. */
830 $$ = scm_cons (SCM_EOL, SCM_EOL);
834 SCM c = scm_cons ($2, SCM_EOL);
836 if (scm_is_pair (scm_cdr (s)))
837 scm_set_cdr_x (scm_cdr (s), c); /* append */
839 scm_set_car_x (s, c); /* set first cons */
840 scm_set_cdr_x (s, c); /* remember last cell */
842 | Music_list embedded_scm {
846 Music *m = MY_MAKE_MUSIC("Music");
848 m->set_property ("error-found", SCM_BOOL_T);
850 SCM c = scm_cons (m->self_scm (), SCM_EOL);
851 m->unprotect (); /* UGH */
853 if (scm_is_pair (scm_cdr (s)))
854 scm_set_cdr_x (scm_cdr (s), c); /* append */
856 scm_set_car_x (s, c); /* set first cons */
857 scm_set_cdr_x (s, c); /* remember last cell */
870 | ALTERNATIVE '{' Music_list '}' {
877 REPEAT simple_string bare_unsigned Music Alternative_music
879 $$ = MAKE_SYNTAX ("repeat", @$, $2, scm_int2num ($3), $4, $5);
884 SEQUENTIAL '{' Music_list '}' {
885 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
887 | '{' Music_list '}' {
888 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
893 SIMULTANEOUS '{' Music_list '}'{
894 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
896 | simul_open Music_list simul_close {
897 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
908 optional_context_mod:
909 /**/ { $$ = SCM_EOL; }
910 | WITH { THIS->lexer_->push_initial_state (); }
911 '{' context_mod_list '}'
913 THIS->lexer_->pop_state ();
919 /* */ { $$ = SCM_EOL; }
920 | context_mod_list context_mod {
921 $$ = scm_cons ($2, $1);
926 Prefix_composite_music { $$ = $1; }
927 | Grouped_music_list { $$ = $1; }
931 Simultaneous_music { $$ = $1; }
932 | Sequential_music { $$ = $1; }
935 function_scm_argument:
941 TODO: use code generation for this
943 Generic_prefix_music_scm:
945 $$ = scm_list_2 ($1, make_input (@$));
947 | MUSIC_FUNCTION_SCM function_scm_argument {
948 $$ = scm_list_3 ($1, make_input (@$), $2);
950 | MUSIC_FUNCTION_MARKUP full_markup {
951 $$ = scm_list_3 ($1, make_input (@$), $2);
953 | music_function_musicless_prefix Music {
954 $$ = ly_append2 ($1, scm_list_1 ($2));
956 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
957 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
959 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
960 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
962 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
963 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
965 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
966 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
968 | MUSIC_FUNCTION_MUSIC_MUSIC Music Music {
969 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
971 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument Music Music {
972 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
974 | MUSIC_FUNCTION_SCM_SCM_MUSIC_MUSIC function_scm_argument function_scm_argument Music Music {
975 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
977 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup Music Music {
978 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
983 /**/ { $$ = SCM_EOL; }
984 | '=' simple_string {
990 Prefix_composite_music:
991 Generic_prefix_music_scm {
992 $$ = run_music_function (THIS, $1)->unprotect ();
994 | CONTEXT simple_string optional_id optional_context_mod Music {
995 $$ = context_spec_music ($2, $3, $5, $4, false);
997 | NEWCONTEXT simple_string optional_id optional_context_mod Music {
998 $$ = context_spec_music ($2, $3, $5, $4, true);
1001 | TIMES fraction Music
1003 int n = scm_to_int (scm_car ($2));
1004 int d = scm_to_int (scm_cdr ($2));
1006 Music *m = MY_MAKE_MUSIC ("TimeScaledMusic");
1009 m->set_property ("element", $3);
1010 m->set_property ("numerator", scm_from_int (n));
1011 m->set_property ("denominator", scm_from_int (d));
1012 m->compress (Moment (Rational (n,d)));
1013 $$ = m->unprotect ();
1015 | Repeated_music { $$ = $1; }
1016 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1017 Music *m = MY_MAKE_MUSIC ("TransposedMusic");
1018 Pitch from = *unsmob_pitch ($2);
1019 Pitch to = *unsmob_pitch ($3);
1021 Music *p = unsmob_music ($4);
1022 p->transpose (pitch_interval (from, to));
1023 m->set_property ("element", $4);
1024 $$ = m->unprotect ();
1026 | mode_changing_head Grouped_music_list {
1027 if ($1 == ly_symbol2scm ("chords"))
1029 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1030 chm->set_property ("element", $2);
1031 $$ = chm->unprotect ();
1037 THIS->lexer_->pop_state ();
1039 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1040 $$ = context_spec_music ($1, SCM_UNDEFINED, $3, $2, true);
1041 if ($1 == ly_symbol2scm ("ChordNames"))
1043 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1044 chm->set_property ("element", $$);
1045 $$ = chm->unprotect ();
1047 THIS->lexer_->pop_state ();
1049 | relative_music { $$ = $1; }
1050 | re_rhythmed_music { $$ = $1; }
1055 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1056 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1058 $$ = ly_symbol2scm ("notes");
1062 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1063 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1065 $$ = ly_symbol2scm ("drums");
1068 THIS->lexer_->push_figuredbass_state ();
1070 $$ = ly_symbol2scm ("figures");
1073 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1074 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1075 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1076 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1077 $$ = ly_symbol2scm ("chords");
1081 { THIS->lexer_->push_lyric_state ();
1082 $$ = ly_symbol2scm ("lyrics");
1086 mode_changing_head_with_context:
1088 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1089 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1091 $$ = ly_symbol2scm ("DrumStaff");
1094 THIS->lexer_->push_figuredbass_state ();
1096 $$ = ly_symbol2scm ("FiguredBass");
1099 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1100 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1101 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1102 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1103 $$ = ly_symbol2scm ("ChordNames");
1106 { THIS->lexer_->push_lyric_state ();
1107 $$ = ly_symbol2scm ("Lyrics");
1113 RELATIVE absolute_pitch Music {
1114 Pitch start = *unsmob_pitch ($2);
1115 $$ = make_music_relative (start, $3);
1117 | RELATIVE Composite_music {
1118 Pitch middle_c (0, 0, 0);
1119 $$ = make_music_relative (middle_c, $2);
1124 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1126 Grouped_music_list {
1127 /* Can also use Music at the expensive of two S/Rs similar to
1128 \repeat \alternative */
1129 THIS->lexer_->pop_state ();
1131 $$ = scm_cons ($3, SCM_EOL);
1133 | new_lyrics ADDLYRICS {
1134 THIS->lexer_->push_lyric_state ();
1135 } Grouped_music_list {
1136 THIS->lexer_->pop_state ();
1137 $$ = scm_cons ($4, $1);
1142 Grouped_music_list new_lyrics {
1144 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), unsmob_music (voice));
1145 if (!scm_is_string (name))
1147 name = get_next_unique_lyrics_context_id ();
1148 voice = context_spec_music (scm_makfrom0str ("Voice"),
1150 voice, SCM_EOL, false);
1153 SCM context = scm_makfrom0str ("Lyrics");
1154 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1157 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1159 SCM com = make_lyric_combine_music (name, scm_car (s));
1160 SCM csm = context_spec_music (context,
1161 SCM_UNDEFINED, com, SCM_EOL, true);
1162 lst = scm_cons (csm, lst);
1164 all->set_property ("elements", scm_cons (voice,
1166 $$ = all->unprotect ();
1168 | LYRICSTO simple_string {
1169 THIS->lexer_->push_lyric_state ();
1171 THIS->lexer_->pop_state ();
1173 $$ = make_lyric_combine_music (name, $4);
1178 CHANGE STRING '=' STRING {
1179 Music *t = MY_MAKE_MUSIC ("ContextChange");
1180 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1181 t-> set_property ("change-to-id", $4);
1184 $$ = t->unprotect ();
1190 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1191 scm_string_to_symbol ($1), $3);
1193 | UNSET simple_string {
1194 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1195 scm_string_to_symbol ($2));
1197 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1198 $$ = scm_list_4 (ly_symbol2scm ("push"),
1199 scm_string_to_symbol ($2), $5, $3);
1201 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1202 $$ = scm_list_5 (ly_symbol2scm ("push"),
1203 scm_string_to_symbol ($2), $6, $4, $3);
1205 | REVERT simple_string embedded_scm {
1206 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1207 scm_string_to_symbol ($2), $3);
1212 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1213 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1215 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1216 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1217 | DENIES { $$ = ly_symbol2scm ("denies"); }
1219 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1220 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1221 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1222 | NAME { $$ = ly_symbol2scm ("context-name"); }
1226 property_operation { $$ = $1; }
1227 | context_def_mod STRING {
1228 $$ = scm_list_2 ($1, $2);
1234 if (!is_regular_identifier ($1))
1236 @$.error (_("Grob name should be alphanumeric"));
1239 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1240 scm_string_to_symbol ($1));
1242 | simple_string '.' simple_string {
1243 $$ = scm_list_2 (scm_string_to_symbol ($1),
1244 scm_string_to_symbol ($3));
1249 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1250 Music *m = property_op_to_music (scm_list_4 (
1251 ly_symbol2scm ("push"),
1254 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1256 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1257 Music *m = property_op_to_music (scm_list_5 (
1258 ly_symbol2scm ("push"),
1261 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1263 | REVERT context_prop_spec embedded_scm {
1264 Music *m = property_op_to_music (scm_list_3 (
1265 ly_symbol2scm ("pop"),
1269 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1271 | SET context_prop_spec '=' scalar {
1272 Music *m = property_op_to_music (scm_list_3 (
1273 ly_symbol2scm ("assign"),
1276 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1278 | UNSET context_prop_spec {
1279 Music *m = property_op_to_music (scm_list_2 (
1280 ly_symbol2scm ("unset"),
1282 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, m->unprotect (), SCM_EOL, false);
1284 | ONCE music_property_def {
1285 Music *m = unsmob_music ($2);
1286 SCM e = m->get_property ("element");
1287 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1297 | STRING_IDENTIFIER {
1300 | string '+' string {
1301 $$ = scm_string_append (scm_list_2 ($1, $3));
1305 simple_string: STRING {
1311 | STRING_IDENTIFIER {
1332 $$ = scm_from_int ($1);
1338 pre_events doesn't contain anything. It is a trick:
1340 Adding pre_events to the simple_element
1341 makes the choice between
1347 simple_element: STRING
1349 a single shift/reduction conflict.
1351 nevertheless, this is not very clean, and we should find a different
1355 pre_events: /* empty */
1359 pre_events simple_element post_events {
1360 Music *m = unsmob_music ($2);
1362 SCM elts = m->get_property ("elements");
1364 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1366 m->set_property ("elements", elts);
1367 /* why is this giving wrong start location? -ns
1368 * $2->set_spot (@$); */
1370 i.set_location (@2, @3);
1372 $$ = m->unprotect ();
1374 | command_element { $$ = $1; }
1375 | note_chord_element
1380 chord_body optional_notemode_duration post_events
1382 Music *m = unsmob_music ($1);
1383 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1384 SCM es = m->get_property ("elements");
1385 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1387 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1388 unsmob_music (scm_car (s))->set_property ("duration", dur);
1389 es = ly_append2 (es, postevs);
1391 m-> set_property ("elements", es);
1393 $$ = m->self_scm ();
1403 simul_open: DOUBLE_ANGLE_OPEN
1406 simul_close: DOUBLE_ANGLE_CLOSE
1410 chord_open chord_body_elements chord_close
1412 Music *m = MY_MAKE_MUSIC ("EventChord");
1414 m->set_property ("elements",
1415 scm_reverse_x ($2, SCM_EOL));
1416 $$ = m->unprotect ();
1420 chord_body_elements:
1421 /* empty */ { $$ = SCM_EOL; }
1422 | chord_body_elements chord_body_element {
1423 $$ = scm_cons ($2, $1);
1428 pitch exclamations questions octave_check post_events
1435 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1436 n->set_property ("pitch", $1);
1439 n->set_property ("cautionary", SCM_BOOL_T);
1440 if (ex % 2 || q % 2)
1441 n->set_property ("force-accidental", SCM_BOOL_T);
1443 if (scm_is_pair (post)) {
1444 SCM arts = scm_reverse_x (post, SCM_EOL);
1445 n->set_property ("articulations", arts);
1447 if (scm_is_number (check))
1449 int q = scm_to_int (check);
1450 n->set_property ("absolute-octave", scm_from_int (q-1));
1453 $$ = n->unprotect ();
1455 | DRUM_PITCH post_events {
1456 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1457 n->set_property ("duration", $2);
1458 n->set_property ("drum-type", $1);
1461 if (scm_is_pair ($2)) {
1462 SCM arts = scm_reverse_x ($2, SCM_EOL);
1463 n->set_property ("articulations", arts);
1465 $$ = n->unprotect ();
1467 | music_function_chord_body {
1468 Music *m = run_music_function (THIS, $1);
1470 $$ = m->unprotect ();
1474 music_function_chord_body:
1476 $$ = scm_list_2 ($1, make_input (@$));
1478 | music_function_musicless_prefix chord_body_element {
1479 $$ = ly_append2 ($1, scm_list_1 ($2));
1483 music_function_event:
1484 music_function_musicless_prefix post_event {
1485 $$ = ly_append2 ($1, scm_list_1 ($2));
1490 TODO: use code generation for this
1492 music_function_musicless_prefix:
1493 MUSIC_FUNCTION_MUSIC {
1494 $$ = scm_list_2 ($1, make_input (@$));
1496 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument {
1497 $$ = scm_list_3 ($1, make_input (@$), $2);
1499 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument {
1500 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1502 | MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument {
1503 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1505 | MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument function_scm_argument {
1506 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
1513 Music *m = MY_MAKE_MUSIC ("EventChord");
1514 m->set_property ("elements", scm_cons ($1, SCM_EOL));
1515 Music *e = unsmob_music ($1);
1518 $$ = m->unprotect ();
1520 | SKIP duration_length {
1521 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1522 skip->set_property ("duration", $2);
1523 skip->set_spot (@$);
1524 $$ = skip->unprotect ();
1527 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1528 m->set_property ("span-direction", scm_from_int (START));
1531 Music *chord = MY_MAKE_MUSIC ("EventChord");
1532 chord->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1534 chord->set_spot (@$);
1535 $$ = chord->unprotect ();
1538 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1539 m->set_property ("span-direction", scm_from_int (STOP));
1542 Music *chord = MY_MAKE_MUSIC ("EventChord");
1543 chord->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1544 chord->set_spot (@$);
1546 $$ = chord->unprotect ();
1549 Music *m = MY_MAKE_MUSIC ("VoiceSeparator");
1551 $$ = m->unprotect ();
1554 SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
1556 Music *m = unsmob_music (pipe);
1560 m = MY_MAKE_MUSIC ("BarCheck");
1563 $$ = m->unprotect ();
1565 | TRANSPOSITION pitch {
1567 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1568 Music *m = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1569 sounds_as_c.smobbed_copy());
1571 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1572 m->unprotect (), SCM_EOL, false);
1574 | PARTIAL duration_length {
1575 Moment m = - unsmob_duration ($2)->get_length ();
1576 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1578 SCM ps = p->unprotect ();
1579 ps = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1580 ps, SCM_EOL, false);
1581 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1582 ps, SCM_EOL, false);
1586 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1588 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1591 SCM proc = ly_lily_module_constant ("make-mark-set");
1593 $$ = scm_call_1 (proc, $2);
1599 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent")->unprotect ();
1602 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1603 $$ = m->unprotect ();
1609 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1610 $$ = key->unprotect ();
1612 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1614 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1615 if (scm_ilength ($3) > 0)
1617 key->set_property ("pitch-alist", $3);
1618 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1619 key->transpose (* unsmob_pitch ($2));
1621 THIS->parser_error (@3, _ ("second argument must be pitch list"));
1624 $$ = key->unprotect ();
1633 | post_events post_event {
1634 unsmob_music ($2)->set_spot (@2);
1635 $$ = scm_cons ($2, $$);
1640 direction_less_event {
1643 | '-' music_function_event {
1644 Music *mus = run_music_function (THIS, $2);
1646 $$ = mus->unprotect ();
1649 if (!THIS->lexer_->is_lyric_state ())
1650 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1651 $$ = MY_MAKE_MUSIC ("HyphenEvent")->unprotect ();
1654 if (!THIS->lexer_->is_lyric_state ())
1655 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1656 $$ = MY_MAKE_MUSIC ("ExtenderEvent")->unprotect ();
1658 | script_dir direction_reqd_event {
1661 Music *m = unsmob_music ($2);
1662 m->set_property ("direction", scm_from_int ($1));
1666 | script_dir direction_less_event {
1669 Music *m = unsmob_music ($2);
1670 m->set_property ("direction", scm_from_int ($1));
1674 | string_number_event
1677 string_number_event:
1679 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1680 s->set_property ("string-number", scm_from_int ($1));
1682 $$ = s->unprotect ();
1686 direction_less_char:
1688 $$ = ly_symbol2scm ("bracketOpenSymbol");
1691 $$ = ly_symbol2scm ("bracketCloseSymbol");
1694 $$ = ly_symbol2scm ("tildeSymbol");
1697 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1700 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1703 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1706 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1709 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1712 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1715 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1719 direction_less_event:
1720 direction_less_char {
1721 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1723 if (unsmob_music (predefd))
1725 m = unsmob_music (predefd)->clone ();
1729 m = MY_MAKE_MUSIC ("Music");
1732 $$ = m->unprotect ();
1734 | EVENT_IDENTIFIER {
1738 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1740 a->set_property ("tremolo-type", scm_from_int ($1));
1741 $$ = a->unprotect ();
1745 direction_reqd_event:
1749 | script_abbreviation {
1750 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1751 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1752 if (scm_is_string (s))
1753 a->set_property ("articulation-type", s);
1754 else THIS->parser_error (@1, _ ("expecting string as script definition"));
1755 $$ = a->unprotect ();
1760 /**/ { $$ = SCM_EOL; }
1761 | '=' { $$ = scm_from_int (0); }
1762 | '=' sub_quotes { $$ = scm_from_int ($2); }
1763 | '=' sup_quotes { $$ = scm_from_int ($2); }
1788 | NOTENAME_PITCH sup_quotes {
1789 Pitch p = *unsmob_pitch ($1);
1790 p = p.transposed (Pitch ($2,0,0));
1791 $$ = p.smobbed_copy ();
1793 | NOTENAME_PITCH sub_quotes {
1794 Pitch p =* unsmob_pitch ($1);
1795 p = p.transposed (Pitch (-$2,0,0));
1796 $$ = p.smobbed_copy ();
1808 | TONICNAME_PITCH sup_quotes {
1809 Pitch p = *unsmob_pitch ($1);
1810 p = p.transposed (Pitch ($2,0,0));
1811 $$ = p.smobbed_copy ();
1813 | TONICNAME_PITCH sub_quotes {
1814 Pitch p =* unsmob_pitch ($1);
1816 p = p.transposed (Pitch (-$2,0,0));
1817 $$ = p.smobbed_copy ();
1827 pitch_also_in_chords:
1834 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1835 t->set_property ("text", $1);
1837 $$ = t->unprotect ();
1840 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1841 t->set_property ("text",
1842 make_simple_markup ($1));
1844 $$ = t->unprotect ();
1847 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1848 t->set_property ("digit", scm_from_int ($1));
1850 $$ = t->unprotect ();
1854 script_abbreviation:
1856 $$ = scm_makfrom0str ("Hat");
1859 $$ = scm_makfrom0str ("Plus");
1862 $$ = scm_makfrom0str ("Dash");
1865 $$ = scm_makfrom0str ("Bar");
1868 $$ = scm_makfrom0str ("Larger");
1871 $$ = scm_makfrom0str ("Dot");
1874 $$ = scm_makfrom0str ("Underscore");
1881 | '-' { $$ = CENTER; }
1892 multiplied_duration {
1897 optional_notemode_duration:
1899 Duration dd = THIS->default_duration_;
1900 $$ = dd.smobbed_copy ();
1902 | multiplied_duration {
1904 THIS->default_duration_ = *unsmob_duration ($$);
1909 bare_unsigned dots {
1911 if (!is_duration ($1))
1912 THIS->parser_error (@1, _f ("not a duration: %d", $1));
1916 $$ = Duration (len, $2).smobbed_copy ();
1918 | DURATION_IDENTIFIER dots {
1919 Duration *d = unsmob_duration ($1);
1920 Duration k (d->duration_log (), d->dot_count () + $2);
1926 multiplied_duration:
1930 | multiplied_duration '*' bare_unsigned {
1931 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1933 | multiplied_duration '*' FRACTION {
1934 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1936 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1941 FRACTION { $$ = $1; }
1942 | UNSIGNED '/' UNSIGNED {
1943 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1960 | ':' bare_unsigned {
1961 if (!is_duration ($2))
1962 THIS->parser_error (@2, _f ("not a duration: %d", $2));
1969 $$ = scm_from_int ($1);
1972 $$ = scm_from_int ($1);
1974 | STRING { $$ = $1; }
1975 | full_markup { $$ = $1; }
1978 figured_bass_alteration:
1986 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
1987 $$ = bfr->self_scm ();
1992 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
1993 $$ = bfr->self_scm ();
1995 if (scm_is_number ($1))
1996 bfr->set_property ("figure", $1);
1997 else if (Text_interface::is_markup ($1))
1998 bfr->set_property ("text", $1);
2005 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2007 | bass_figure figured_bass_alteration {
2008 Music *m = unsmob_music ($1);
2010 SCM salter = m->get_property ("alteration");
2011 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2012 m->set_property ("alteration",
2013 scm_from_int (alter + $2));
2015 m->set_property ("alteration", scm_from_int (0));
2018 | bass_figure figured_bass_modification {
2019 Music *m = unsmob_music ($1);
2020 if ($2 == ly_symbol2scm ("plus"))
2022 m->set_property ("augmented", SCM_BOOL_T);
2024 else if ($2 == ly_symbol2scm ("slash"))
2026 m->set_property ("diminished", SCM_BOOL_T);
2028 else if ($2 == ly_symbol2scm ("exclamation"))
2030 m->set_property ("no-continuation", SCM_BOOL_T);
2036 figured_bass_modification:
2038 $$ = ly_symbol2scm ("plus");
2041 $$ = ly_symbol2scm ("exclamation");
2044 $$ = ly_symbol2scm ("slash");
2054 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2062 | figure_list br_bass_figure {
2063 $$ = scm_cons ($2, $1);
2068 FIGURE_OPEN figure_list FIGURE_CLOSE {
2069 Music *m = MY_MAKE_MUSIC ("EventChord");
2070 $2 = scm_reverse_x ($2, SCM_EOL);
2071 m->set_property ("elements", $2);
2072 $$ = m->self_scm ();
2083 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2084 if (!THIS->lexer_->is_note_state ())
2085 THIS->parser_error (@1, _ ("have to be in Note mode for notes"));
2089 n = MY_MAKE_MUSIC ("RestEvent");
2091 n = MY_MAKE_MUSIC ("NoteEvent");
2093 n->set_property ("pitch", $1);
2094 n->set_property ("duration", $5);
2096 if (scm_is_number ($4))
2098 int q = scm_to_int ($4);
2099 n->set_property ("absolute-octave", scm_from_int (q-1));
2103 n->set_property ("cautionary", SCM_BOOL_T);
2104 if ($2 % 2 || $3 % 2)
2105 n->set_property ("force-accidental", SCM_BOOL_T);
2107 Music *v = MY_MAKE_MUSIC ("EventChord");
2108 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2113 $$ = v->unprotect ();
2115 | DRUM_PITCH optional_notemode_duration {
2116 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2117 n->set_property ("duration", $2);
2118 n->set_property ("drum-type", $1);
2120 Music *v = MY_MAKE_MUSIC ("EventChord");
2121 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2125 $$ = v->unprotect ();
2128 | figure_spec optional_notemode_duration {
2129 Music *m = unsmob_music ($1);
2131 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2133 unsmob_music (scm_car (s))->set_property ("duration", $2);
2135 $$ = m->unprotect ();
2137 | RESTNAME optional_notemode_duration {
2139 if (ly_scm2string ($1) == "s") {
2141 ev = MY_MAKE_MUSIC ("SkipEvent");
2144 ev = MY_MAKE_MUSIC ("RestEvent");
2147 ev->set_property ("duration", $2);
2149 Music *velt = MY_MAKE_MUSIC ("EventChord");
2150 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2151 velt->set_spot (@$);
2155 $$ = velt->unprotect ();
2157 | MULTI_MEASURE_REST optional_notemode_duration {
2158 SCM proc = ly_lily_module_constant ("make-multi-measure-rest");
2159 $$ = scm_call_2 (proc, $2, make_input (@$));
2161 | lyric_element optional_notemode_duration {
2162 if (!THIS->lexer_->is_lyric_state ())
2163 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2165 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2166 levent->set_property ("text", $1);
2167 levent->set_property ("duration",$2);
2168 levent->set_spot (@$);
2169 Music *velt = MY_MAKE_MUSIC ("EventChord");
2170 velt->set_property ("elements", scm_list_1 (levent->self_scm ()));
2172 $$= velt->unprotect ();
2175 if (!THIS->lexer_->is_chord_state ())
2176 THIS->parser_error (@1, _ ("have to be in Chord mode for chords"));
2191 steno_tonic_pitch optional_notemode_duration {
2192 $$ = make_chord ($1, $2, SCM_EOL);
2194 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2195 SCM its = scm_reverse_x ($4, SCM_EOL);
2196 $$ = make_chord ($1, $2, scm_cons ($3, its));
2204 | chord_items chord_item {
2205 $$ = scm_cons ($2, $$);
2211 $$ = ly_symbol2scm ("chord-colon");
2214 $$ = ly_symbol2scm ("chord-caret");
2216 | CHORD_SLASH steno_tonic_pitch {
2217 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2219 | CHORD_BASS steno_tonic_pitch {
2220 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2229 $$ = scm_reverse_x ($1, SCM_EOL);
2237 step_number { $$ = scm_cons ($1, SCM_EOL); }
2238 | step_numbers '.' step_number {
2239 $$ = scm_cons ($3, $$);
2245 $$ = make_chord_step ($1, 0);
2247 | bare_unsigned '+' {
2248 $$ = make_chord_step ($1, SHARP);
2250 | bare_unsigned CHORD_MINUS {
2251 $$ = make_chord_step ($1, FLAT);
2258 TODO: should deprecate in favor of Scheme?
2262 number_expression '+' number_term {
2263 $$ = scm_sum ($1, $3);
2265 | number_expression '-' number_term {
2266 $$ = scm_difference ($1, $3);
2275 | number_factor '*' number_factor {
2276 $$ = scm_product ($1, $3);
2278 | number_factor '/' number_factor {
2279 $$ = scm_divide ($1, $3);
2284 '-' number_factor { /* %prec UNARY_MINUS */
2285 $$ = scm_difference ($2, SCM_UNDEFINED);
2293 $$ = scm_from_int ($1);
2298 | NUMBER_IDENTIFIER {
2301 | REAL NUMBER_IDENTIFIER {
2302 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2304 | UNSIGNED NUMBER_IDENTIFIER {
2305 $$ = scm_from_double ($1 *scm_to_double ($2));
2321 | exclamations '!' { $$ ++; }
2326 | questions '?' { $$ ++; }
2330 This should be done more dynamically if possible.
2334 LYRIC_MARKUP_IDENTIFIER {
2338 { THIS->lexer_->push_markup_state (); }
2341 THIS->lexer_->pop_state ();
2350 { THIS->lexer_->push_markup_state (); }
2353 THIS->lexer_->pop_state ();
2359 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2361 | markup_head_1_list simple_markup {
2362 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2370 markup_composed_list {
2373 | markup_braced_list {
2378 markup_composed_list:
2379 markup_head_1_list markup_braced_list {
2380 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2386 '{' markup_braced_list_body '}' {
2387 $$ = scm_reverse_x ($2, SCM_EOL);
2391 markup_braced_list_body:
2392 /* empty */ { $$ = SCM_EOL; }
2393 | markup_braced_list_body markup {
2394 $$ = scm_cons ($2, $1);
2396 | markup_braced_list_body markup_list {
2397 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2402 MARKUP_HEAD_MARKUP0 {
2403 $$ = scm_list_1 ($1);
2405 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2406 $$ = scm_list_2 ($1, $2);
2408 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2409 $$ = scm_list_3 ($1, $2, $3);
2414 markup_head_1_item {
2415 $$ = scm_list_1 ($1);
2417 | markup_head_1_list markup_head_1_item {
2418 $$ = scm_cons ($2, $1);
2424 $$ = make_simple_markup ($1);
2426 | MARKUP_IDENTIFIER {
2429 | LYRIC_MARKUP_IDENTIFIER {
2432 | STRING_IDENTIFIER {
2436 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2437 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2438 } '{' score_body '}' {
2440 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2442 THIS->lexer_->pop_state ();
2444 | MARKUP_HEAD_SCM0 embedded_scm {
2445 $$ = scm_list_2 ($1, $2);
2447 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2448 $$ = scm_list_4 ($1, $2, $3, $4);
2450 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2451 $$ = scm_list_3 ($1, $2, $3);
2453 | MARKUP_HEAD_EMPTY {
2454 $$ = scm_list_1 ($1);
2456 | MARKUP_HEAD_LIST0 markup_list {
2457 $$ = scm_list_2 ($1,$2);
2459 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2460 $$ = scm_list_3 ($1, $2, $3);
2465 markup_head_1_list simple_markup {
2466 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2467 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2477 Lily_parser::set_yydebug (bool )
2485 Lily_parser::do_yyparse ()
2487 yyparse ((void*)this);
2496 It is a little strange to have this function in this file, but
2497 otherwise, we have to import music classes into the lexer.
2501 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2503 if (scm_is_string (sid)) {
2505 return STRING_IDENTIFIER;
2506 } else if (unsmob_book (sid)) {
2507 *destination = unsmob_book (sid)->clone ()->self_scm ();
2508 return BOOK_IDENTIFIER;
2509 } else if (scm_is_number (sid)) {
2511 return NUMBER_IDENTIFIER;
2512 } else if (unsmob_context_def (sid)) {
2513 *destination = unsmob_context_def (sid)->clone_scm ();
2514 return CONTEXT_DEF_IDENTIFIER;
2515 } else if (unsmob_score (sid)) {
2516 Score *score = new Score (*unsmob_score (sid));
2517 *destination = score->self_scm ();
2518 return SCORE_IDENTIFIER;
2519 } else if (Music *mus = unsmob_music (sid)) {
2520 mus = mus->clone ();
2521 *destination = mus->self_scm ();
2522 unsmob_music (*destination)->
2523 set_property ("origin", make_input (last_input_));
2525 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2528 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2529 } else if (unsmob_duration (sid)) {
2530 *destination = unsmob_duration (sid)->smobbed_copy ();
2531 return DURATION_IDENTIFIER;
2532 } else if (unsmob_output_def (sid)) {
2533 Output_def *p = unsmob_output_def (sid);
2536 *destination = p->self_scm ();
2537 return OUTPUT_DEF_IDENTIFIER;
2538 } else if (Text_interface::is_markup (sid)) {
2540 if (is_lyric_state ())
2541 return LYRIC_MARKUP_IDENTIFIER;
2542 return MARKUP_IDENTIFIER;
2549 property_op_to_music (SCM op)
2552 SCM tag = scm_car (op);
2553 SCM symbol = scm_cadr (op);
2554 SCM args = scm_cddr (op);
2555 SCM grob_val = SCM_UNDEFINED;
2556 SCM grob_path = SCM_UNDEFINED;
2557 SCM val = SCM_UNDEFINED;
2559 if (tag == ly_symbol2scm ("assign"))
2561 m = MY_MAKE_MUSIC ("PropertySet");
2562 val = scm_car (args);
2564 else if (tag == ly_symbol2scm ("unset"))
2565 m = MY_MAKE_MUSIC ("PropertyUnset");
2566 else if (tag == ly_symbol2scm ("push"))
2568 m = MY_MAKE_MUSIC ("OverrideProperty");
2569 grob_val = scm_car (args);
2570 grob_path = scm_cdr (args);
2571 m->set_property ("pop-first", SCM_BOOL_T);
2573 else if (tag == ly_symbol2scm ("pop")) {
2574 m = MY_MAKE_MUSIC ("RevertProperty");
2578 m->set_property ("symbol", symbol);
2580 if (val != SCM_UNDEFINED)
2581 m->set_property ("value", val);
2582 if (grob_val != SCM_UNDEFINED)
2583 m->set_property ("grob-value", grob_val);
2584 if (grob_path != SCM_UNDEFINED)
2585 m->set_property ("grob-property-path", grob_path);
2591 context_spec_music (SCM type, SCM id, SCM m, SCM ops, bool create_new)
2593 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2595 csm->set_property ("element", m);
2597 csm->set_property ("context-type",
2598 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2599 csm->set_property ("property-operations", ops);
2601 csm->set_property ("create-new", SCM_BOOL_T);
2603 if (scm_is_string (id))
2604 csm->set_property ("context-id", id);
2605 return csm->unprotect ();
2609 get_next_unique_context_id ()
2611 return scm_makfrom0str ("$uniqueContextId");
2616 get_next_unique_lyrics_context_id ()
2618 static int new_context_count;
2620 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2621 return scm_makfrom0str (s);
2626 run_music_function (Lily_parser *parser, SCM expr)
2628 SCM func = scm_car (expr);
2629 Input *loc = unsmob_input (scm_cadr (expr));
2630 SCM args = scm_cddr (expr);
2631 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2633 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2636 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2638 parser->error_level_ = 1;
2644 m = scm_apply_0 (func, scm_cons (parser->self_scm(),
2649 if (unsmob_music (m))
2651 retval = unsmob_music (m);
2657 loc->error (_ ("music head function must return Music object"));
2658 retval = MY_MAKE_MUSIC ("Music");
2660 retval->set_spot (*loc);
2665 is_regular_identifier (SCM id)
2667 string str = ly_scm2string (id);
2668 char const *s = str.c_str ();
2677 v = v && isalnum (*s);
2685 get_first_context_id (SCM type, Music *m)
2687 SCM id = m->get_property ("context-id");
2688 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2689 && scm_is_string (m->get_property ("context-id"))
2690 && scm_c_string_length (id) > 0)
2698 make_simple_markup (SCM a)
2706 return t && t == 1 << intlog2 (t);
2710 set_music_properties (Music *p, SCM a)
2712 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2713 p->internal_set_property (scm_caar (k), scm_cdar (k));
2718 make_chord_step (int step, int alter)
2725 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2726 return m.smobbed_copy ();
2731 make_chord (SCM pitch, SCM dur, SCM modification_list)
2733 SCM chord_ctor = ly_lily_module_constant ("construct-chord");
2734 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
2736 unsmob_music (ch)->protect();
2741 /* Todo: actually also use apply iso. call too ... */
2743 ly_input_procedure_p (SCM x)
2745 return ly_is_procedure (x)
2746 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2750 set_property_music (SCM sym, SCM value)
2752 Music *p = MY_MAKE_MUSIC ("PropertySet");
2753 p->set_property ("symbol", sym);
2754 p->set_property ("value", value);
2759 make_music_relative (Pitch start, SCM music)
2761 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2762 relative->set_property ("element", music);
2764 Music *m = unsmob_music (music);
2765 Pitch last = m->to_relative_octave (start);
2766 if (lily_1_8_relative)
2767 m->set_property ("last-pitch", last.smobbed_copy ());
2768 return relative->unprotect ();
2772 make_lyric_combine_music (SCM name, SCM music)
2774 Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
2775 combine->set_property ("element", music);
2776 combine->set_property ("associated-context", name);
2777 return combine->unprotect ();
2782 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2784 Lily_parser *pars = (Lily_parser*) v;
2785 Lily_lexer *lex = pars->lexer_;
2787 lex->lexval = (void*) s;
2789 lex->prepare_for_next_token ();
2790 return lex->yylex ();