2 parser.yy -- Bison/C++ parser for LilyPond
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
12 #define YYERROR_VERBOSE 1
13 #define YYPARSE_PARAM my_lily_parser
14 #define YYLEX_PARAM my_lily_parser
16 ((Lily_parser *) my_lily_parser)
18 #define yyerror THIS->parser_error
20 /* We use custom location type: Input objects */
22 #define YYLLOC_DEFAULT(Current,Rhs,N) \
23 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
28 /* We use SCMs to do strings, because it saves us the trouble of
29 deleting them. Let's hope that a stack overflow doesnt trigger a move
30 of the parse stack onto the heap. */
38 /* One shift/reduce problem
41 \repeat .. \alternative
43 \repeat { \repeat .. \alternative }
47 \repeat { \repeat } \alternative
56 %{ // -*-Fundamental-*-
61 * The rules for who is protecting what are very shady. Uniformise
64 * There are too many lexical modes?
75 #include "context-def.hh"
76 #include "dimensions.hh"
77 #include "file-path.hh"
78 #include "input-smob.hh"
80 #include "international.hh"
81 #include "lily-guile.hh"
82 #include "lily-lexer.hh"
83 #include "lily-parser.hh"
84 #include "lilypond-input-version.hh"
89 #include "output-def.hh"
90 #include "paper-book.hh"
91 #include "program-option.hh"
92 #include "scm-hash.hh"
94 #include "text-interface.hh"
102 Output_def *outputdef;
112 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
114 Music *property_op_to_music (SCM op);
115 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops, bool create_new);
116 SCM get_next_unique_context_id ();
117 SCM get_next_unique_lyrics_context_id ();
124 #define _(x) gettext (x)
129 Music *make_lyric_combine_music (SCM name, Music *music);
130 Music *make_music_relative (Pitch start, Music *music);
131 Music *run_music_function (Lily_parser *, SCM expr);
132 Music *set_property_music (SCM sym, SCM value);
133 SCM get_first_context_id (SCM type, Music *m);
134 SCM make_chord (SCM pitch, SCM dur, SCM modification_list);
135 SCM make_chord_step (int step, int alter);
136 SCM make_simple_markup (SCM a);
137 bool is_duration (int t);
138 bool is_regular_identifier (SCM id);
139 bool ly_input_procedure_p (SCM x);
140 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
141 void set_music_properties (Music *p, SCM a);
145 /* The third option is an alias that will be used to display the
146 syntax error. Bison CVS now correctly handles backslash escapes.
148 FIXME: Bison needs to translate some of these, eg, STRING.
152 /* Keyword tokens with plain escaped name. */
153 %token ACCEPTS "\\accepts"
154 %token ADDLYRICS "\\addlyrics"
155 %token ADDQUOTE "\\addquote"
156 %token ALIAS "\\alias"
157 %token ALTERNATIVE "\\alternative"
159 %token CHANGE "\\change"
160 %token CHORDMODE "\\chordmode"
161 %token CHORDS "\\chords"
162 %token CONSISTS "\\consists"
163 %token CONTEXT "\\context"
164 %token DEFAULT "\\default"
165 %token DEFAULTCHILD "\\defaultchild"
166 %token DENIES "\\denies"
167 %token DESCRIPTION "\\description"
168 %token DRUMMODE "\\drummode"
169 %token DRUMS "\\drums"
170 %token FIGUREMODE "\\figuremode"
171 %token FIGURES "\\figures"
172 %token GROBDESCRIPTIONS "\\grobdescriptions"
173 %token HEADER "\\header"
174 %token INVALID "\\invalid"
176 %token LAYOUT "\\layout"
177 %token LYRICMODE "\\lyricmode"
178 %token LYRICS "\\lyrics"
179 %token LYRICSTO "\\lyricsto"
181 %token MARKUP "\\markup"
184 %token NOTEMODE "\\notemode"
185 %token OBJECTID "\\objectid"
186 %token OCTAVE "\\octave"
188 %token OVERRIDE "\\override"
189 %token PAPER "\\paper"
190 %token PARTIAL "\\partial"
191 %token RELATIVE "\\relative"
192 %token REMOVE "\\remove"
193 %token REPEAT "\\repeat"
195 %token REVERT "\\revert"
196 %token SCORE "\\score"
197 %token SEQUENTIAL "\\sequential"
199 %token SIMULTANEOUS "\\simultaneous"
201 %token TEMPO "\\tempo"
202 %token TIMES "\\times"
203 %token TRANSPOSE "\\transpose"
204 %token TRANSPOSITION "\\transposition"
206 %token UNSET "\\unset"
209 /* Keyword token exceptions. */
210 %token TIME_T "\\time"
211 %token NEWCONTEXT "\\new"
214 /* Other string tokens. */
216 %token CHORD_BASS "/+"
217 %token CHORD_CARET "^"
218 %token CHORD_COLON ":"
219 %token CHORD_MINUS "-"
220 %token CHORD_SLASH "/"
221 %token DOUBLE_ANGLE_CLOSE ">>"
222 %token DOUBLE_ANGLE_OPEN "<<"
223 %token E_BACKSLASH "\\"
224 %token E_ANGLE_CLOSE "\\>"
225 %token E_CHAR "\\C[haracter]"
227 %token E_EXCLAMATION "\\!"
228 %token E_BRACKET_OPEN "\\["
230 %token E_BRACKET_CLOSE "\\]"
231 %token E_ANGLE_OPEN "\\<"
237 If we give names, Bison complains.
239 %token FIGURE_CLOSE /* "\\>" */
240 %token FIGURE_OPEN /* "\\<" */
241 %token FIGURE_SPACE "_"
244 %token CHORDMODIFIERS
246 %token MULTI_MEASURE_REST
251 %token <i> E_UNSIGNED
254 %token <scm> BOOK_IDENTIFIER
255 %token <scm> CHORDMODIFIER_PITCH
256 %token <scm> CHORD_MODIFIER
257 %token <scm> CONTEXT_DEF_IDENTIFIER
258 %token <scm> DRUM_PITCH
259 %token <scm> DURATION_IDENTIFIER
260 %token <scm> EVENT_IDENTIFIER
261 %token <scm> FRACTION
262 %token <scm> LYRICS_STRING
263 %token <scm> LYRIC_MARKUP_IDENTIFIER
264 %token <scm> MARKUP_HEAD_EMPTY
265 %token <scm> MARKUP_HEAD_LIST0
266 %token <scm> MARKUP_HEAD_MARKUP0
267 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
268 %token <scm> MARKUP_HEAD_SCM0
269 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
270 %token <scm> MARKUP_HEAD_SCM0_SCM1
271 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
272 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
273 %token <scm> MARKUP_IDENTIFIER
274 %token <scm> MUSIC_FUNCTION
275 %token <scm> MUSIC_FUNCTION_MARKUP
276 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
277 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
278 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
279 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
280 %token <scm> MUSIC_FUNCTION_MUSIC
281 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
282 %token <scm> MUSIC_FUNCTION_SCM
283 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
284 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
285 %token <scm> MUSIC_FUNCTION_SCM_SCM
286 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
287 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM
288 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC
289 %token <scm> MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC
290 %token <scm> MUSIC_IDENTIFIER
291 %token <scm> NOTENAME_PITCH
292 %token <scm> NUMBER_IDENTIFIER
293 %token <scm> OUTPUT_DEF_IDENTIFIER
295 %token <scm> RESTNAME
296 %token <scm> SCM_IDENTIFIER
298 %token <scm> SCORE_IDENTIFIER
300 %token <scm> STRING_IDENTIFIER
301 %token <scm> TONICNAME_PITCH
304 %type <book> book_block
305 %type <book> book_body
307 %type <i> bare_unsigned
308 %type <i> figured_bass_alteration
310 %type <i> exclamations
311 %type <i> optional_rest
316 %type <i> tremolo_type
318 %type <music> Composite_music
319 %type <music> Grouped_music_list
321 %type <music> Prefix_composite_music
322 %type <music> Repeated_music
323 %type <music> Sequential_music
324 %type <music> Simple_music
325 %type <music> Simultaneous_music
326 %type <music> chord_body
327 %type <music> chord_body_element
328 %type <music> command_element
329 %type <music> command_event
330 %type <music> context_change
331 %type <music> direction_less_event
332 %type <music> direction_reqd_event
333 %type <music> event_chord
334 %type <music> gen_text_def
335 %type <music> music_property_def
336 %type <music> note_chord_element
337 %type <music> post_event
338 %type <music> re_rhythmed_music
339 %type <music> relative_music
340 %type <music> simple_element
341 %type <music> string_number_event
342 %type <music> tempo_event
343 %type <music> toplevel_music
345 %type <outputdef> output_def_body
346 %type <outputdef> output_def_head
347 %type <outputdef> output_def_head_with_mode_switch
348 %type <outputdef> output_def
349 %type <outputdef> paper_block
351 %type <scm> Alternative_music
352 %type <scm> Generic_prefix_music_scm
353 %type <scm> Music_list
354 %type <scm> absolute_pitch
355 %type <scm> assignment_id
356 %type <scm> bare_number
357 %type <scm> music_function_event
358 %type <scm> music_function_chord_body
359 %type <scm> music_function_musicless_prefix
360 %type <scm> bass_figure
361 %type <scm> figured_bass_modification
362 %type <scm> br_bass_figure
363 %type <scm> bass_number
364 %type <scm> chord_body_elements
365 %type <scm> chord_item
366 %type <scm> chord_items
367 %type <scm> chord_separator
368 %type <scm> context_def_mod
369 %type <scm> context_def_spec_block
370 %type <scm> context_def_spec_body
371 %type <scm> context_mod
372 %type <scm> context_mod_list
373 %type <scm> context_prop_spec
374 %type <scm> direction_less_char
375 %type <scm> duration_length
376 %type <scm> embedded_scm
377 %type <scm> figure_list
378 %type <scm> figure_spec
380 %type <scm> full_markup
381 %type <scm> identifier_init
382 %type <scm> lilypond_header
383 %type <scm> lilypond_header_body
384 %type <scm> lyric_element
385 %type <scm> lyric_markup
387 %type <scm> markup_braced_list
388 %type <scm> markup_braced_list_body
389 %type <scm> markup_composed_list
390 %type <scm> markup_head_1_item
391 %type <scm> markup_head_1_list
392 %type <scm> markup_list
393 %type <scm> markup_top
394 %type <scm> mode_changing_head
395 %type <scm> mode_changing_head_with_context
396 %type <scm> multiplied_duration
397 %type <scm> new_chord
398 %type <scm> new_lyrics
399 %type <scm> number_expression
400 %type <scm> number_factor
401 %type <scm> number_term
402 %type <scm> object_id_setting
403 %type <scm> octave_check
404 %type <scm> optional_context_mod
405 %type <scm> optional_id
406 %type <scm> optional_notemode_duration
408 %type <scm> pitch_also_in_chords
409 %type <scm> post_events
410 %type <scm> property_operation
412 %type <scm> script_abbreviation
413 %type <scm> simple_markup
414 %type <scm> simple_string
415 %type <scm> steno_duration
416 %type <scm> steno_pitch
417 %type <scm> steno_tonic_pitch
418 %type <scm> step_number
419 %type <scm> step_numbers
421 %type <scm> function_scm_argument
423 %type <score> score_block
424 %type <score> score_body
429 /* We don't assign precedence to / and *, because we might need varied
430 prec levels in different prods */
436 lilypond: /* empty */
437 | lilypond toplevel_expression {
439 | lilypond assignment {
442 THIS->error_level_ = 1;
445 THIS->error_level_ = 1;
451 OBJECTID STRING { $$ = $2; }
456 THIS->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
460 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
461 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
467 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
468 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
473 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
474 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
478 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler");
479 scm_call_2 (proc, THIS->self_scm (), $1);
483 Output_def * od = $1;
485 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
486 id = ly_symbol2scm ("$defaultpaper");
487 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
488 id = ly_symbol2scm ("$defaultmidi");
489 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
490 id = ly_symbol2scm ("$defaultlayout");
492 THIS->lexer_->set_identifier (id, od->self_scm ());
508 lilypond_header_body:
510 $$ = get_header(THIS);
511 THIS->lexer_->add_scope ($$);
513 | lilypond_header_body assignment {
519 HEADER '{' lilypond_header_body '}' {
520 $$ = THIS->lexer_->remove_scope ();
529 | LYRICS_STRING { $$ = $1; }
533 assignment_id '=' identifier_init {
534 if (! is_regular_identifier ($1))
537 /* no longer valid with dashes in \paper{} block. */
538 @1.warning (_ ("identifier should have alphabetic characters only"));
543 THIS->lexer_->set_identifier ($1, $3);
546 TODO: devise standard for protection in parser.
548 The parser stack lives on the C-stack, which means that
549 all objects can be unprotected as soon as they're here.
559 $$ = $1->self_scm ();
563 $$ = $1->self_scm ();
567 $$ = $1->self_scm ();
570 | context_def_spec_block {
574 $$ = $1->self_scm ();
578 $$ = $1->self_scm ();
581 | number_expression {
594 $$ = scm_from_int ($1);
598 context_def_spec_block:
599 CONTEXT '{' context_def_spec_body '}'
605 context_def_spec_body:
607 $$ = Context_def::make_scm ();
608 unsmob_context_def ($$)->set_spot (@$);
610 | CONTEXT_DEF_IDENTIFIER {
612 unsmob_context_def ($$)->set_spot (@$);
614 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
615 Context_def*td = unsmob_context_def ($$);
617 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
618 SCM tag = scm_caar (p);
620 /* TODO: should make new tag "grob-definition" ? */
621 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
622 tag, scm_cons (scm_cdar (p), SCM_EOL)));
625 | context_def_spec_body context_mod {
626 unsmob_context_def ($$)->add_context_mod ($2);
633 BOOK '{' book_body '}' {
639 * Use 'handlers' like for toplevel-* stuff?
640 * grok \layout and \midi? */
645 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
646 $$->paper_->unprotect ();
647 $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader");
650 $$ = unsmob_book ($1);
653 | book_body paper_block {
657 | book_body score_block {
658 SCM s = $2->self_scm ();
662 | book_body full_markup {
665 | book_body lilypond_header {
670 $$->scores_ = SCM_EOL;
672 | book_body object_id_setting {
673 $$->user_key_ = ly_scm2string ($2);
678 SCORE '{' score_body '}' {
685 SCM m = $1->self_scm ();
687 SCM scorify = ly_lily_module_constant ("scorify-music");
688 SCM score = scm_call_2 (scorify, m, THIS->self_scm ());
690 // pass ownernship to C++ again.
691 $$ = unsmob_score (score);
696 $$ = unsmob_score ($1);
699 | score_body object_id_setting {
700 $$->user_key_ = ly_scm2string ($2);
702 | score_body lilypond_header {
705 | score_body output_def {
706 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
708 THIS->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
713 $$->add_output_def ($2);
718 $$->error_found_ = true;
730 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
732 THIS->parser_error (@1, _ ("need \\paper for paper block"));
733 $$ = get_paper (THIS);
740 output_def_body '}' {
743 THIS->lexer_->remove_scope ();
744 THIS->lexer_->pop_state ();
750 $$ = get_paper (THIS);
751 $$->input_origin_ = @$;
752 THIS->lexer_->add_scope ($$->scope_);
755 Output_def *p = get_midi (THIS);
757 THIS->lexer_->add_scope (p->scope_);
760 Output_def *p = get_layout (THIS);
762 THIS->lexer_->add_scope (p->scope_);
767 output_def_head_with_mode_switch:
769 THIS->lexer_->push_initial_state ();
775 output_def_head_with_mode_switch '{' {
777 $$->input_origin_.set_spot (@$);
779 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
781 Output_def *o = unsmob_output_def ($3);
782 o->input_origin_.set_spot (@$);
784 THIS->lexer_->remove_scope ();
785 THIS->lexer_->add_scope (o->scope_);
787 | output_def_body assignment {
790 | output_def_body context_def_spec_block {
791 assign_context_def ($$, $2);
793 | output_def_body tempo_event {
795 junk this ? there already is tempo stuff in
798 int m = scm_to_int ($2->get_property ("metronome-count"));
799 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
800 set_tempo ($$, d->get_length (), m);
803 | output_def_body error {
809 TEMPO steno_duration '=' bare_unsigned {
810 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
811 $$->set_property ("tempo-unit", $2);
812 $$->set_property ("metronome-count", scm_from_int ( $4));
817 The representation of a list is the
821 to have efficient append. */
825 $$ = scm_cons (SCM_EOL, SCM_EOL);
829 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
830 $2->unprotect (); /* UGH */
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 /*TODO: move to Scheme.*/
878 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
879 if (times < scm_ilength (alts)) {
880 unsmob_music (scm_car (alts))
881 ->origin ()->warning (
882 _ ("more alternatives than repeats"));
883 warning ("junking excess alternatives");
884 alts = ly_truncate_list (times, alts);
888 SCM proc = ly_lily_module_constant ("make-repeated-music");
890 SCM mus = scm_call_1 (proc, $2);
891 Music *r = unsmob_music (mus);
895 r-> set_property ("element", beg->self_scm ());
898 r->set_property ("repeat-count", scm_from_int (max (times, 1)));
900 r-> set_property ("elements",alts);
901 if (ly_is_equal ($2, scm_makfrom0str ("tremolo"))) {
903 TODO: move this code to Scheme.
906 /* we cannot get durations and other stuff
907 correct down the line,
908 so we have to add to the duration log here. */
909 SCM func = ly_lily_module_constant ("shift-duration-log");
911 int dots = ($3 % 3) ? 0 : 1;
912 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
915 if ($4->is_mus_type ("sequential-music"))
917 int list_len = scm_ilength ($4->get_property ("elements"));
919 $4->origin ()->warning (_f ("expect 2 elements for Chord tremolo, found %d", list_len));
921 r->compress (Moment (Rational (1, list_len)));
923 scm_call_3 (func, r->self_scm (), scm_from_int (shift), scm_from_int (dots));
926 r->set_spot (*$4->origin ());
933 SEQUENTIAL '{' Music_list '}' {
934 $$ = MY_MAKE_MUSIC ("SequentialMusic");
935 $$->set_property ("elements", scm_car ($3));
938 | '{' Music_list '}' {
939 $$ = MY_MAKE_MUSIC ("SequentialMusic");
940 $$->set_property ("elements", scm_car ($2));
946 SIMULTANEOUS '{' Music_list '}'{
947 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
948 $$->set_property ("elements", scm_car ($3));
952 | simul_open Music_list simul_close {
953 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
954 $$->set_property ("elements", scm_car ($2));
960 event_chord { $$ = $1; }
962 $$ = unsmob_music ($1);
968 optional_context_mod:
969 /**/ { $$ = SCM_EOL; }
970 | WITH { THIS->lexer_->push_initial_state (); }
971 '{' context_mod_list '}'
973 THIS->lexer_->pop_state ();
979 /* */ { $$ = SCM_EOL; }
980 | context_mod_list context_mod {
981 $$ = scm_cons ($2, $1);
986 Prefix_composite_music { $$ = $1; }
987 | Grouped_music_list { $$ = $1; }
991 Simultaneous_music { $$ = $1; }
992 | Sequential_music { $$ = $1; }
995 function_scm_argument:
1001 TODO: use code generation for this
1003 Generic_prefix_music_scm:
1005 $$ = scm_list_2 ($1, make_input (@$));
1007 | MUSIC_FUNCTION_SCM function_scm_argument {
1008 $$ = scm_list_3 ($1, make_input (@$), $2);
1010 | MUSIC_FUNCTION_MARKUP full_markup {
1011 $$ = scm_list_3 ($1, make_input (@$), $2);
1013 | music_function_musicless_prefix Music {
1014 $$ = ly_append2 ($1, scm_list_1 ($2->self_scm ()));
1017 | MUSIC_FUNCTION_SCM_SCM function_scm_argument function_scm_argument {
1018 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1020 | MUSIC_FUNCTION_SCM_SCM_SCM function_scm_argument function_scm_argument function_scm_argument {
1021 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1023 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
1024 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1027 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
1028 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1030 | MUSIC_FUNCTION_MUSIC_MUSIC Music Music {
1031 $$ = scm_list_4 ($1, make_input (@$), $2->self_scm (), $3->self_scm ());
1035 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC function_scm_argument Music Music {
1036 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1040 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup Music Music {
1041 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1048 /**/ { $$ = SCM_EOL; }
1049 | '=' simple_string {
1055 Prefix_composite_music:
1056 Generic_prefix_music_scm {
1057 $$ = run_music_function (THIS, $1);
1059 | CONTEXT simple_string optional_id optional_context_mod Music {
1060 $$ = context_spec_music ($2, $3, $5, $4, false);
1062 | NEWCONTEXT simple_string optional_id optional_context_mod Music {
1063 $$ = context_spec_music ($2, $3, $5, $4, true);
1066 | TIMES fraction Music
1068 int n = scm_to_int (scm_car ($2));
1069 int d = scm_to_int (scm_cdr ($2));
1072 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1075 $$->set_property ("element", mp->self_scm ());
1077 $$->set_property ("numerator", scm_from_int (n));
1078 $$->set_property ("denominator", scm_from_int (d));
1079 $$->compress (Moment (Rational (n,d)));
1082 | Repeated_music { $$ = $1; }
1083 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1084 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1086 Pitch from = *unsmob_pitch ($2);
1087 Pitch to = *unsmob_pitch ($3);
1089 p->transpose (pitch_interval (from, to));
1090 $$->set_property ("element", p->self_scm ());
1093 | mode_changing_head Grouped_music_list {
1094 if ($1 == ly_symbol2scm ("chords"))
1096 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1097 chm->set_property ("element", $2->self_scm ());
1105 THIS->lexer_->pop_state ();
1107 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1108 $$ = context_spec_music ($1, SCM_UNDEFINED, $3, $2, true);
1109 if ($1 == ly_symbol2scm ("ChordNames"))
1111 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1112 chm->set_property ("element", $$->self_scm ());
1116 THIS->lexer_->pop_state ();
1118 | relative_music { $$ = $1; }
1119 | re_rhythmed_music { $$ = $1; }
1124 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1125 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1127 $$ = ly_symbol2scm ("notes");
1131 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1132 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1134 $$ = ly_symbol2scm ("drums");
1137 THIS->lexer_->push_figuredbass_state ();
1139 $$ = ly_symbol2scm ("figures");
1142 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1143 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1144 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1145 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1146 $$ = ly_symbol2scm ("chords");
1150 { THIS->lexer_->push_lyric_state ();
1151 $$ = ly_symbol2scm ("lyrics");
1155 mode_changing_head_with_context:
1157 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1158 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1160 $$ = ly_symbol2scm ("DrumStaff");
1163 THIS->lexer_->push_figuredbass_state ();
1165 $$ = ly_symbol2scm ("FiguredBass");
1168 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1169 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1170 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1171 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1172 $$ = ly_symbol2scm ("ChordNames");
1175 { THIS->lexer_->push_lyric_state ();
1176 $$ = ly_symbol2scm ("Lyrics");
1182 RELATIVE absolute_pitch Music {
1184 Pitch start = *unsmob_pitch ($2);
1185 $$ = make_music_relative (start, m);
1188 | RELATIVE Composite_music {
1191 Pitch middle_c (0, 0, 0);
1192 $$ = make_music_relative (middle_c, m);
1198 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1200 Grouped_music_list {
1201 /* Can also use Music at the expensive of two S/Rs similar to
1202 \repeat \alternative */
1203 THIS->lexer_->pop_state ();
1205 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1207 | new_lyrics ADDLYRICS {
1208 THIS->lexer_->push_lyric_state ();
1209 } Grouped_music_list {
1210 THIS->lexer_->pop_state ();
1211 $$ = scm_cons ($4->self_scm (), $1);
1216 Grouped_music_list new_lyrics {
1218 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice);
1219 if (!scm_is_string (name))
1221 name = get_next_unique_lyrics_context_id ();
1222 voice = context_spec_music (scm_makfrom0str ("Voice"),
1224 voice, SCM_EOL, false);
1227 SCM context = scm_makfrom0str ("Lyrics");
1228 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1231 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1233 Music *music = unsmob_music (scm_car (s));
1234 Music *com = make_lyric_combine_music (name, music);
1235 Music *csm = context_spec_music (context,
1236 SCM_UNDEFINED, com, SCM_EOL, true);
1237 lst = scm_cons (csm->self_scm (), lst);
1239 all->set_property ("elements", scm_cons (voice->self_scm (),
1242 voice->unprotect ();
1244 | LYRICSTO simple_string {
1245 THIS->lexer_->push_lyric_state ();
1247 THIS->lexer_->pop_state ();
1250 $$ = make_lyric_combine_music (name, music);
1256 CHANGE STRING '=' STRING {
1257 Music*t = MY_MAKE_MUSIC ("ContextChange");
1258 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1259 t-> set_property ("change-to-id", $4);
1268 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1269 scm_string_to_symbol ($1), $3);
1271 | UNSET simple_string {
1272 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1273 scm_string_to_symbol ($2));
1275 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1276 $$ = scm_list_4 (ly_symbol2scm ("push"),
1277 scm_string_to_symbol ($2), $5, $3);
1279 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1280 $$ = scm_list_5 (ly_symbol2scm ("push"),
1281 scm_string_to_symbol ($2), $6, $4, $3);
1283 | REVERT simple_string embedded_scm {
1284 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1285 scm_string_to_symbol ($2), $3);
1290 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1291 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1293 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1294 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1295 | DENIES { $$ = ly_symbol2scm ("denies"); }
1297 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1298 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1299 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1300 | NAME { $$ = ly_symbol2scm ("context-name"); }
1304 property_operation { $$ = $1; }
1305 | context_def_mod STRING {
1306 $$ = scm_list_2 ($1, $2);
1312 if (!is_regular_identifier ($1))
1314 @$.error (_("Grob name should be alphanumeric"));
1317 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1318 scm_string_to_symbol ($1));
1320 | simple_string '.' simple_string {
1321 $$ = scm_list_2 (scm_string_to_symbol ($1),
1322 scm_string_to_symbol ($3));
1327 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1328 $$ = property_op_to_music (scm_list_4 (
1329 ly_symbol2scm ("push"),
1332 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1334 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1335 $$ = property_op_to_music (scm_list_5 (
1336 ly_symbol2scm ("push"),
1339 $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1341 | REVERT context_prop_spec embedded_scm {
1342 $$ = property_op_to_music (scm_list_3 (
1343 ly_symbol2scm ("pop"),
1347 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1349 | SET context_prop_spec '=' scalar {
1350 $$ = property_op_to_music (scm_list_3 (
1351 ly_symbol2scm ("assign"),
1354 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1356 | UNSET context_prop_spec {
1357 $$ = property_op_to_music (scm_list_2 (
1358 ly_symbol2scm ("unset"),
1360 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL, false);
1362 | ONCE music_property_def {
1363 SCM e = $2->get_property ("element");
1364 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1375 | STRING_IDENTIFIER {
1378 | string '+' string {
1379 $$ = scm_string_append (scm_list_2 ($1, $3));
1383 simple_string: STRING {
1389 | STRING_IDENTIFIER {
1410 $$ = scm_from_int ($1);
1416 pre_events doesn't contain anything. It is a trick:
1418 Adding pre_events to the simple_element
1419 makes the choice between
1425 simple_element: STRING
1427 a single shift/reduction conflict.
1429 nevertheless, this is not very clean, and we should find a different
1433 pre_events: /* empty */
1437 pre_events simple_element post_events {
1438 SCM elts = $2-> get_property ("elements");
1440 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1442 $2->set_property ("elements", elts);
1443 /* why is this giving wrong start location? -ns
1444 * $2->set_spot (@$); */
1446 i.set_location (@2, @3);
1451 | note_chord_element
1456 chord_body optional_notemode_duration post_events
1458 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1459 SCM es = $1->get_property ("elements");
1460 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1462 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1463 unsmob_music (scm_car (s))->set_property ("duration", dur);
1464 es = ly_append2 (es, postevs);
1466 $1-> set_property ("elements", es);
1478 simul_open: DOUBLE_ANGLE_OPEN
1481 simul_close: DOUBLE_ANGLE_CLOSE
1485 chord_open chord_body_elements chord_close
1487 $$ = MY_MAKE_MUSIC ("EventChord");
1489 $$->set_property ("elements",
1490 scm_reverse_x ($2, SCM_EOL));
1494 chord_body_elements:
1495 /* empty */ { $$ = SCM_EOL; }
1496 | chord_body_elements chord_body_element {
1497 $$ = scm_cons ($2->self_scm (), $1);
1503 pitch exclamations questions octave_check post_events
1510 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1511 n->set_property ("pitch", $1);
1514 n->set_property ("cautionary", SCM_BOOL_T);
1515 if (ex % 2 || q % 2)
1516 n->set_property ("force-accidental", SCM_BOOL_T);
1518 if (scm_is_pair (post)) {
1519 SCM arts = scm_reverse_x (post, SCM_EOL);
1520 n->set_property ("articulations", arts);
1522 if (scm_is_number (check))
1524 int q = scm_to_int (check);
1525 n->set_property ("absolute-octave", scm_from_int (q-1));
1531 | DRUM_PITCH post_events {
1532 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1533 n->set_property ("duration", $2);
1534 n->set_property ("drum-type", $1);
1537 if (scm_is_pair ($2)) {
1538 SCM arts = scm_reverse_x ($2, SCM_EOL);
1539 n->set_property ("articulations", arts);
1543 | music_function_chord_body {
1544 $$ = run_music_function (THIS, $1);
1549 music_function_chord_body:
1551 $$ = scm_list_2 ($1, make_input (@$));
1553 | music_function_musicless_prefix chord_body_element {
1554 $$ = ly_append2 ($1, scm_list_1 ($2->self_scm ()));
1559 music_function_event:
1560 music_function_musicless_prefix post_event {
1561 $$ = ly_append2 ($1, scm_list_1 ($2->self_scm ()));
1567 TODO: use code generation for this
1569 music_function_musicless_prefix:
1570 MUSIC_FUNCTION_MUSIC {
1571 $$ = scm_list_2 ($1, make_input (@$));
1573 | MUSIC_FUNCTION_SCM_MUSIC function_scm_argument {
1574 $$ = scm_list_3 ($1, make_input (@$), $2);
1576 | MUSIC_FUNCTION_SCM_SCM_MUSIC function_scm_argument function_scm_argument {
1577 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1579 | MUSIC_FUNCTION_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument {
1580 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
1582 | MUSIC_FUNCTION_SCM_SCM_SCM_SCM_MUSIC function_scm_argument function_scm_argument function_scm_argument function_scm_argument {
1583 $$ = scm_list_n ($1, make_input (@$), $2, $3, $4, $5, SCM_UNDEFINED);
1590 $$ = MY_MAKE_MUSIC ("EventChord");
1591 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1597 | SKIP duration_length {
1598 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1599 skip->set_property ("duration", $2);
1600 skip->set_spot (@$);
1604 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1605 m->set_property ("span-direction", scm_from_int (START));
1608 $$ = MY_MAKE_MUSIC ("EventChord");
1609 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1614 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1615 m->set_property ("span-direction", scm_from_int (STOP));
1618 $$ = MY_MAKE_MUSIC ("EventChord");
1619 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1624 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1628 SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
1630 if (Music * m = unsmob_music (pipe))
1633 $$ = MY_MAKE_MUSIC ("BarCheck");
1637 | TRANSPOSITION pitch {
1639 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1640 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1641 sounds_as_c.smobbed_copy());
1643 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1644 $$, SCM_EOL, false);
1646 | PARTIAL duration_length {
1647 Moment m = - unsmob_duration ($2)->get_length ();
1648 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1650 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1652 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1658 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1660 SCM result = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1661 $$ = unsmob_music (result);
1665 SCM proc = ly_lily_module_constant ("make-mark-set");
1667 SCM result = scm_call_1 (proc, $2);
1668 $$ = unsmob_music (result);
1675 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1678 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1685 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1688 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1690 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1691 if (scm_ilength ($3) > 0)
1693 key->set_property ("pitch-alist", $3);
1694 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1695 key->transpose (* unsmob_pitch ($2));
1697 THIS->parser_error (@3, _ ("second argument must be pitch list"));
1709 | post_events post_event {
1711 $$ = scm_cons ($2->self_scm (), $$);
1717 direction_less_event {
1720 | '-' music_function_event {
1721 Music *mus = run_music_function (THIS, $2);
1726 if (!THIS->lexer_->is_lyric_state ())
1727 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1728 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1731 if (!THIS->lexer_->is_lyric_state ())
1732 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1733 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1735 | script_dir direction_reqd_event {
1737 $2->set_property ("direction", scm_from_int ($1));
1740 | script_dir direction_less_event {
1742 $2->set_property ("direction", scm_from_int ($1));
1745 | string_number_event
1748 string_number_event:
1750 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1751 s->set_property ("string-number", scm_from_int ($1));
1757 direction_less_char:
1759 $$ = ly_symbol2scm ("bracketOpenSymbol");
1762 $$ = ly_symbol2scm ("bracketCloseSymbol");
1765 $$ = ly_symbol2scm ("tildeSymbol");
1768 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1771 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1774 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1777 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1780 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1783 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1786 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1790 direction_less_event:
1791 direction_less_char {
1792 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1794 if (unsmob_music (predefd))
1796 m = unsmob_music (predefd)->clone ();
1800 m = MY_MAKE_MUSIC ("Music");
1805 | EVENT_IDENTIFIER {
1806 $$ = unsmob_music ($1);
1809 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1811 a->set_property ("tremolo-type", scm_from_int ($1));
1816 direction_reqd_event:
1820 | script_abbreviation {
1821 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1822 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1823 if (scm_is_string (s))
1824 a->set_property ("articulation-type", s);
1825 else THIS->parser_error (@1, _ ("expecting string as script definition"));
1831 /**/ { $$ = SCM_EOL; }
1832 | '=' { $$ = scm_from_int (0); }
1833 | '=' sub_quotes { $$ = scm_from_int ($2); }
1834 | '=' sup_quotes { $$ = scm_from_int ($2); }
1859 | NOTENAME_PITCH sup_quotes {
1860 Pitch p = *unsmob_pitch ($1);
1861 p = p.transposed (Pitch ($2,0,0));
1862 $$ = p.smobbed_copy ();
1864 | NOTENAME_PITCH sub_quotes {
1865 Pitch p =* unsmob_pitch ($1);
1866 p = p.transposed (Pitch (-$2,0,0));
1867 $$ = p.smobbed_copy ();
1879 | TONICNAME_PITCH sup_quotes {
1880 Pitch p = *unsmob_pitch ($1);
1881 p = p.transposed (Pitch ($2,0,0));
1882 $$ = p.smobbed_copy ();
1884 | TONICNAME_PITCH sub_quotes {
1885 Pitch p =* unsmob_pitch ($1);
1887 p = p.transposed (Pitch (-$2,0,0));
1888 $$ = p.smobbed_copy ();
1898 pitch_also_in_chords:
1905 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1906 t->set_property ("text", $1);
1911 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1912 t->set_property ("text",
1913 make_simple_markup ($1));
1919 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1920 t->set_property ("digit", scm_from_int ($1));
1926 script_abbreviation:
1928 $$ = scm_makfrom0str ("Hat");
1931 $$ = scm_makfrom0str ("Plus");
1934 $$ = scm_makfrom0str ("Dash");
1937 $$ = scm_makfrom0str ("Bar");
1940 $$ = scm_makfrom0str ("Larger");
1943 $$ = scm_makfrom0str ("Dot");
1946 $$ = scm_makfrom0str ("Underscore");
1953 | '-' { $$ = CENTER; }
1964 multiplied_duration {
1969 optional_notemode_duration:
1971 Duration dd = THIS->default_duration_;
1972 $$ = dd.smobbed_copy ();
1974 | multiplied_duration {
1976 THIS->default_duration_ = *unsmob_duration ($$);
1981 bare_unsigned dots {
1983 if (!is_duration ($1))
1984 THIS->parser_error (@1, _f ("not a duration: %d", $1));
1988 $$ = Duration (len, $2).smobbed_copy ();
1990 | DURATION_IDENTIFIER dots {
1991 Duration *d = unsmob_duration ($1);
1992 Duration k (d->duration_log (), d->dot_count () + $2);
1998 multiplied_duration:
2002 | multiplied_duration '*' bare_unsigned {
2003 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2005 | multiplied_duration '*' FRACTION {
2006 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2008 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2013 FRACTION { $$ = $1; }
2014 | UNSIGNED '/' UNSIGNED {
2015 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2032 | ':' bare_unsigned {
2033 if (!is_duration ($2))
2034 THIS->parser_error (@2, _f ("not a duration: %d", $2));
2041 $$ = scm_from_int ($1);
2044 $$ = scm_from_int ($1);
2046 | STRING { $$ = $1; }
2047 | full_markup { $$ = $1; }
2050 figured_bass_alteration:
2058 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2059 $$ = bfr->self_scm ();
2064 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2065 $$ = bfr->self_scm ();
2067 if (scm_is_number ($1))
2068 bfr->set_property ("figure", $1);
2069 else if (Text_interface::is_markup ($1))
2070 bfr->set_property ("text", $1);
2077 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2079 | bass_figure figured_bass_alteration {
2080 Music *m = unsmob_music ($1);
2082 SCM salter = m->get_property ("alteration");
2083 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2084 m->set_property ("alteration",
2085 scm_from_int (alter + $2));
2087 m->set_property ("alteration", scm_from_int (0));
2090 | bass_figure figured_bass_modification {
2091 Music *m = unsmob_music ($1);
2092 if ($2 == ly_symbol2scm ("plus"))
2094 m->set_property ("augmented", SCM_BOOL_T);
2096 else if ($2 == ly_symbol2scm ("slash"))
2098 m->set_property ("diminished", SCM_BOOL_T);
2100 else if ($2 == ly_symbol2scm ("exclamation"))
2102 m->set_property ("no-continuation", SCM_BOOL_T);
2108 figured_bass_modification:
2110 $$ = ly_symbol2scm ("plus");
2113 $$ = ly_symbol2scm ("exclamation");
2116 $$ = ly_symbol2scm ("slash");
2126 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2134 | figure_list br_bass_figure {
2135 $$ = scm_cons ($2, $1);
2140 FIGURE_OPEN figure_list FIGURE_CLOSE {
2141 Music *m = MY_MAKE_MUSIC ("EventChord");
2142 $2 = scm_reverse_x ($2, SCM_EOL);
2143 m->set_property ("elements", $2);
2144 $$ = m->self_scm ();
2155 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2156 if (!THIS->lexer_->is_note_state ())
2157 THIS->parser_error (@1, _ ("have to be in Note mode for notes"));
2161 n = MY_MAKE_MUSIC ("RestEvent");
2163 n = MY_MAKE_MUSIC ("NoteEvent");
2165 n->set_property ("pitch", $1);
2166 n->set_property ("duration", $5);
2168 if (scm_is_number ($4))
2170 int q = scm_to_int ($4);
2171 n->set_property ("absolute-octave", scm_from_int (q-1));
2175 n->set_property ("cautionary", SCM_BOOL_T);
2176 if ($2 % 2 || $3 % 2)
2177 n->set_property ("force-accidental", SCM_BOOL_T);
2179 Music *v = MY_MAKE_MUSIC ("EventChord");
2180 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2187 | DRUM_PITCH optional_notemode_duration {
2188 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2189 n->set_property ("duration", $2);
2190 n->set_property ("drum-type", $1);
2192 Music *v = MY_MAKE_MUSIC ("EventChord");
2193 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2200 | figure_spec optional_notemode_duration {
2201 Music *m = unsmob_music ($1);
2203 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2205 unsmob_music (scm_car (s))->set_property ("duration", $2);
2209 | RESTNAME optional_notemode_duration {
2211 if (ly_scm2string ($1) == "s") {
2213 ev = MY_MAKE_MUSIC ("SkipEvent");
2216 ev = MY_MAKE_MUSIC ("RestEvent");
2219 ev->set_property ("duration", $2);
2221 Music *velt = MY_MAKE_MUSIC ("EventChord");
2222 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2223 velt->set_spot (@$);
2229 | MULTI_MEASURE_REST optional_notemode_duration {
2230 SCM proc = ly_lily_module_constant ("make-multi-measure-rest");
2231 SCM mus = scm_call_2 (proc, $2, make_input (@$));
2232 $$ = unsmob_music (mus);
2236 | lyric_element optional_notemode_duration {
2237 if (!THIS->lexer_->is_lyric_state ())
2238 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2240 Music *levent = MY_MAKE_MUSIC ("LyricEvent");
2241 levent->set_property ("text", $1);
2242 levent->set_property ("duration",$2);
2243 levent->set_spot (@$);
2244 Music *velt = MY_MAKE_MUSIC ("EventChord");
2245 velt->set_property ("elements", scm_list_1 (levent->self_scm ()));
2250 if (!THIS->lexer_->is_chord_state ())
2251 THIS->parser_error (@1, _ ("have to be in Chord mode for chords"));
2252 $$ = unsmob_music ($1);
2266 steno_tonic_pitch optional_notemode_duration {
2267 $$ = make_chord ($1, $2, SCM_EOL);
2269 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2270 SCM its = scm_reverse_x ($4, SCM_EOL);
2271 $$ = make_chord ($1, $2, scm_cons ($3, its));
2279 | chord_items chord_item {
2280 $$ = scm_cons ($2, $$);
2286 $$ = ly_symbol2scm ("chord-colon");
2289 $$ = ly_symbol2scm ("chord-caret");
2291 | CHORD_SLASH steno_tonic_pitch {
2292 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2294 | CHORD_BASS steno_tonic_pitch {
2295 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2304 $$ = scm_reverse_x ($1, SCM_EOL);
2312 step_number { $$ = scm_cons ($1, SCM_EOL); }
2313 | step_numbers '.' step_number {
2314 $$ = scm_cons ($3, $$);
2320 $$ = make_chord_step ($1, 0);
2322 | bare_unsigned '+' {
2323 $$ = make_chord_step ($1, SHARP);
2325 | bare_unsigned CHORD_MINUS {
2326 $$ = make_chord_step ($1, FLAT);
2333 TODO: should deprecate in favor of Scheme?
2337 number_expression '+' number_term {
2338 $$ = scm_sum ($1, $3);
2340 | number_expression '-' number_term {
2341 $$ = scm_difference ($1, $3);
2350 | number_factor '*' number_factor {
2351 $$ = scm_product ($1, $3);
2353 | number_factor '/' number_factor {
2354 $$ = scm_divide ($1, $3);
2359 '-' number_factor { /* %prec UNARY_MINUS */
2360 $$ = scm_difference ($2, SCM_UNDEFINED);
2368 $$ = scm_from_int ($1);
2373 | NUMBER_IDENTIFIER {
2376 | REAL NUMBER_IDENTIFIER {
2377 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2379 | UNSIGNED NUMBER_IDENTIFIER {
2380 $$ = scm_from_double ($1 *scm_to_double ($2));
2396 | exclamations '!' { $$ ++; }
2401 | questions '?' { $$ ++; }
2405 This should be done more dynamically if possible.
2409 LYRIC_MARKUP_IDENTIFIER {
2413 { THIS->lexer_->push_markup_state (); }
2416 THIS->lexer_->pop_state ();
2425 { THIS->lexer_->push_markup_state (); }
2428 THIS->lexer_->pop_state ();
2434 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2436 | markup_head_1_list simple_markup {
2437 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2445 markup_composed_list {
2448 | markup_braced_list {
2453 markup_composed_list:
2454 markup_head_1_list markup_braced_list {
2455 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2461 '{' markup_braced_list_body '}' {
2462 $$ = scm_reverse_x ($2, SCM_EOL);
2466 markup_braced_list_body:
2467 /* empty */ { $$ = SCM_EOL; }
2468 | markup_braced_list_body markup {
2469 $$ = scm_cons ($2, $1);
2471 | markup_braced_list_body markup_list {
2472 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2477 MARKUP_HEAD_MARKUP0 {
2478 $$ = scm_list_1 ($1);
2480 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2481 $$ = scm_list_2 ($1, $2);
2483 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2484 $$ = scm_list_3 ($1, $2, $3);
2489 markup_head_1_item {
2490 $$ = scm_list_1 ($1);
2492 | markup_head_1_list markup_head_1_item {
2493 $$ = scm_cons ($2, $1);
2499 $$ = make_simple_markup ($1);
2501 | MARKUP_IDENTIFIER {
2504 | LYRIC_MARKUP_IDENTIFIER {
2507 | STRING_IDENTIFIER {
2511 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2512 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2513 } '{' score_body '}' {
2515 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2517 THIS->lexer_->pop_state ();
2519 | MARKUP_HEAD_SCM0 embedded_scm {
2520 $$ = scm_list_2 ($1, $2);
2522 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2523 $$ = scm_list_4 ($1, $2, $3, $4);
2525 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2526 $$ = scm_list_3 ($1, $2, $3);
2528 | MARKUP_HEAD_EMPTY {
2529 $$ = scm_list_1 ($1);
2531 | MARKUP_HEAD_LIST0 markup_list {
2532 $$ = scm_list_2 ($1,$2);
2534 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2535 $$ = scm_list_3 ($1, $2, $3);
2540 markup_head_1_list simple_markup {
2541 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2542 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2552 Lily_parser::set_yydebug (bool )
2560 Lily_parser::do_yyparse ()
2562 yyparse ((void*)this);
2571 It is a little strange to have this function in this file, but
2572 otherwise, we have to import music classes into the lexer.
2576 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2578 if (scm_is_string (sid)) {
2580 return STRING_IDENTIFIER;
2581 } else if (unsmob_book (sid)) {
2582 *destination = unsmob_book (sid)->clone ()->self_scm ();
2583 return BOOK_IDENTIFIER;
2584 } else if (scm_is_number (sid)) {
2586 return NUMBER_IDENTIFIER;
2587 } else if (unsmob_context_def (sid)) {
2588 *destination = unsmob_context_def (sid)->clone_scm ();
2589 return CONTEXT_DEF_IDENTIFIER;
2590 } else if (unsmob_score (sid)) {
2591 Score *score = new Score (*unsmob_score (sid));
2592 *destination = score->self_scm ();
2593 return SCORE_IDENTIFIER;
2594 } else if (Music *mus = unsmob_music (sid)) {
2595 mus = mus->clone ();
2596 *destination = mus->self_scm ();
2597 unsmob_music (*destination)->
2598 set_property ("origin", make_input (last_input_));
2600 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2603 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2604 } else if (unsmob_duration (sid)) {
2605 *destination = unsmob_duration (sid)->smobbed_copy ();
2606 return DURATION_IDENTIFIER;
2607 } else if (unsmob_output_def (sid)) {
2608 Output_def *p = unsmob_output_def (sid);
2611 *destination = p->self_scm ();
2612 return OUTPUT_DEF_IDENTIFIER;
2613 } else if (Text_interface::is_markup (sid)) {
2615 if (is_lyric_state ())
2616 return LYRIC_MARKUP_IDENTIFIER;
2617 return MARKUP_IDENTIFIER;
2624 property_op_to_music (SCM op)
2627 SCM tag = scm_car (op);
2628 SCM symbol = scm_cadr (op);
2629 SCM args = scm_cddr (op);
2630 SCM grob_val = SCM_UNDEFINED;
2631 SCM grob_path = SCM_UNDEFINED;
2632 SCM val = SCM_UNDEFINED;
2634 if (tag == ly_symbol2scm ("assign"))
2636 m = MY_MAKE_MUSIC ("PropertySet");
2637 val = scm_car (args);
2639 else if (tag == ly_symbol2scm ("unset"))
2640 m = MY_MAKE_MUSIC ("PropertyUnset");
2641 else if (tag == ly_symbol2scm ("push"))
2643 m = MY_MAKE_MUSIC ("OverrideProperty");
2644 grob_val = scm_car (args);
2645 grob_path = scm_cdr (args);
2646 m->set_property ("pop-first", SCM_BOOL_T);
2648 else if (tag == ly_symbol2scm ("pop")) {
2649 m = MY_MAKE_MUSIC ("RevertProperty");
2653 m->set_property ("symbol", symbol);
2655 if (val != SCM_UNDEFINED)
2656 m->set_property ("value", val);
2657 if (grob_val != SCM_UNDEFINED)
2658 m->set_property ("grob-value", grob_val);
2659 if (grob_path != SCM_UNDEFINED)
2660 m->set_property ("grob-property-path", grob_path);
2666 context_spec_music (SCM type, SCM id, Music *m, SCM ops, bool create_new)
2668 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2670 csm->set_property ("element", m->self_scm ());
2673 csm->set_property ("context-type",
2674 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2675 csm->set_property ("property-operations", ops);
2677 csm->set_property ("create-new", SCM_BOOL_T);
2679 if (scm_is_string (id))
2680 csm->set_property ("context-id", id);
2685 get_next_unique_context_id ()
2687 return scm_makfrom0str ("$uniqueContextId");
2692 get_next_unique_lyrics_context_id ()
2694 static int new_context_count;
2696 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2697 return scm_makfrom0str (s);
2702 run_music_function (Lily_parser *parser, SCM expr)
2704 SCM func = scm_car (expr);
2705 Input *loc = unsmob_input (scm_cadr (expr));
2706 SCM args = scm_cddr (expr);
2707 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2709 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2712 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2714 parser->error_level_ = 1;
2720 m = scm_apply_0 (func, scm_cons (parser->self_scm(),
2725 if (unsmob_music (m))
2727 retval = unsmob_music (m);
2733 loc->error (_ ("music head function must return Music object"));
2734 retval = MY_MAKE_MUSIC ("Music");
2736 retval->set_spot (*loc);
2741 is_regular_identifier (SCM id)
2743 string str = ly_scm2string (id);
2744 char const *s = str.c_str ();
2753 v = v && isalnum (*s);
2761 get_first_context_id (SCM type, Music *m)
2763 SCM id = m->get_property ("context-id");
2764 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2765 && scm_is_string (m->get_property ("context-id"))
2766 && scm_c_string_length (id) > 0)
2774 make_simple_markup (SCM a)
2782 return t && t == 1 << intlog2 (t);
2786 set_music_properties (Music *p, SCM a)
2788 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2789 p->internal_set_property (scm_caar (k), scm_cdar (k));
2794 make_chord_step (int step, int alter)
2801 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2802 return m.smobbed_copy ();
2807 make_chord (SCM pitch, SCM dur, SCM modification_list)
2809 SCM chord_ctor = ly_lily_module_constant ("construct-chord");
2810 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
2812 unsmob_music (ch)->protect();
2817 /* Todo: actually also use apply iso. call too ... */
2819 ly_input_procedure_p (SCM x)
2821 return ly_is_procedure (x)
2822 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2826 set_property_music (SCM sym, SCM value)
2828 Music *p = MY_MAKE_MUSIC ("PropertySet");
2829 p->set_property ("symbol", sym);
2830 p->set_property ("value", value);
2835 make_music_relative (Pitch start, Music *music)
2837 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
2838 relative->set_property ("element", music->self_scm ());
2840 Pitch last = music->to_relative_octave (start);
2841 if (lily_1_8_relative)
2842 music->set_property ("last-pitch", last.smobbed_copy ());
2847 make_lyric_combine_music (SCM name, Music *music)
2849 Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
2850 combine->set_property ("element", music->self_scm ());
2851 combine->set_property ("associated-context", name);
2857 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2859 Lily_parser *pars = (Lily_parser*) v;
2860 Lily_lexer *lex = pars->lexer_;
2862 lex->lexval = (void*) s;
2864 lex->prepare_for_next_token ();
2865 return lex->yylex ();