1 %{ // -*-Fundamental-*-
4 parser.yy -- Bison/C++ parser for LilyPond
6 source file of the GNU LilyPond music typesetter
8 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 Jan Nieuwenhuizen <janneke@gnu.org>
15 * The rules for who is protecting what are very shady. Uniformise
18 * There are too many lexical modes?
29 #include "context-def.hh"
30 #include "dimensions.hh"
32 #include "file-path.hh"
33 #include "input-smob.hh"
35 #include "lily-guile.hh"
36 #include "lilypond-input-version.hh"
39 #include "lily-lexer.hh"
40 #include "lily-parser.hh"
41 #include "paper-book.hh"
42 #include "output-def.hh"
43 #include "scm-hash.hh"
44 #include "program-option.hh"
46 #include "text-interface.hh"
50 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
52 Music *property_op_to_music (SCM op);
53 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops);
54 SCM get_next_unique_context_id ();
55 SCM get_next_unique_lyrics_context_id ();
62 #define _(x) gettext (x)
65 #define YYERROR_VERBOSE 1
67 #define YYPARSE_PARAM my_lily_parser
68 #define YYLEX_PARAM my_lily_parser
70 ((Lily_parser *) my_lily_parser)
72 #define yyerror THIS->parser_error
74 /* We use custom location type: Input objects */
76 #define YYLLOC_DEFAULT(Current,Rhs,N) \
77 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
80 /* Add symbols to the TAGS field of a music object. */
83 tag_music (Music *m, SCM tag, Input ip)
85 SCM tags = m->get_property ("tags");
86 if (scm_is_symbol (tag))
87 tags = scm_cons (tag, tags);
88 else if (ly_is_list (tag))
89 tags = ly_append2 (tag, tags);
91 ip.warning (_ ("tag must be symbol or list of symbols"));
93 m->set_property ("tags", tags);
97 is_regular_identifier (SCM id)
99 String str = ly_scm2string (id);
100 char const *s = str.to_str0 ();
109 v = v && isalnum (*s);
117 get_first_context_id (SCM type, Music *m)
119 SCM id = m->get_property ("context-id");
120 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
121 && scm_is_string (m->get_property ("context-id"))
122 && scm_c_string_length (id) > 0)
130 make_simple_markup (SCM a)
132 SCM simple = ly_lily_module_constant ("simple-markup");
133 return scm_list_2 (simple, a);
139 return t && t == 1 << intlog2 (t);
143 set_music_properties (Music *p, SCM a)
145 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
146 p->internal_set_property (scm_caar (k), scm_cdar (k));
150 make_chord_step (int step, int alter)
157 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
158 return m.smobbed_copy ();
163 make_chord (SCM pitch, SCM dur, SCM modification_list)
165 SCM chord_ctor = ly_lily_module_constant ("construct-chord");
166 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
167 scm_gc_protect_object (ch);
171 /* Todo: actually also use apply iso. call too ... */
173 ly_input_procedure_p (SCM x)
175 return ly_is_procedure (x)
176 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
180 set_property_music (SCM sym, SCM value)
182 Music *p = MY_MAKE_MUSIC ("PropertySet");
183 p->set_property ("symbol", sym);
184 p->set_property ("value", value);
189 make_music_relative (Pitch start, Music *music)
191 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
192 relative->set_property ("element", music->self_scm ());
194 Pitch last = music->to_relative_octave (start);
195 if (lily_1_8_relative)
196 music->set_property ("last-pitch", last.smobbed_copy ());
201 make_lyric_combine_music (SCM name, Music *music)
203 Music *combine = MY_MAKE_MUSIC ("LyricCombineMusic");
204 combine->set_property ("element", music->self_scm ());
205 combine->set_property ("associated-context", name);
211 /* We use SCMs to do strings, because it saves us the trouble of
212 deleting them. Let's hope that a stack overflow doesnt trigger a move
213 of the parse stack onto the heap. */
219 Output_def *outputdef;
229 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
231 Lily_parser *pars = (Lily_parser*) v;
232 Lily_lexer *lex = pars->lexer_;
234 lex->lexval = (void*) s;
236 lex->prepare_for_next_token ();
237 return lex->yylex ();
245 /* One shift/reduce problem
248 \repeat .. \alternative
250 \repeat { \repeat .. \alternative }
254 \repeat { \repeat } \alternative
261 /* The third option is an alias that will be used to display the
262 syntax error. Bison CVS now correctly handles backslash escapes.
264 FIXME: Bison needs to translate some of these, eg, STRING.
268 /* Keyword tokens with plain escaped name. */
269 %token ACCEPTS "\\accepts"
270 %token ADDLYRICS "\\addlyrics"
271 %token ADDQUOTE "\\addquote"
272 %token ALIAS "\\alias"
273 %token ALTERNATIVE "\\alternative"
276 %token CHANGE "\\change"
277 %token CHORDMODE "\\chordmode"
278 %token CHORDS "\\chords"
280 %token CONSISTS "\\consists"
281 %token CONTEXT "\\context"
282 %token DEFAULT "\\default"
283 %token DEFAULTCHILD "\\defaultchild"
284 %token DENIES "\\denies"
285 %token DESCRIPTION "\\description"
286 %token DRUMMODE "\\drummode"
287 %token DRUMS "\\drums"
288 %token FIGUREMODE "\\figuremode"
289 %token FIGURES "\\figures"
290 %token GROBDESCRIPTIONS "\\grobdescriptions"
291 %token HEADER "\\header"
292 %token INVALID "\\invalid"
294 %token LAYOUT "\\layout"
295 %token LYRICMODE "\\lyricmode"
296 %token LYRICS "\\lyrics"
297 %token LYRICSTO "\\lyricsto"
299 %token MARKUP "\\markup"
302 %token NOTEMODE "\\notemode"
303 %token OBJECTID "\\objectid"
304 %token OCTAVE "\\octave"
306 %token OVERRIDE "\\override"
307 %token PAPER "\\paper"
308 %token PARTIAL "\\partial"
309 %token RELATIVE "\\relative"
310 %token REMOVE "\\remove"
311 %token REPEAT "\\repeat"
313 %token REVERT "\\revert"
314 %token SCORE "\\score"
315 %token SEQUENTIAL "\\sequential"
317 %token SIMULTANEOUS "\\simultaneous"
320 %token TEMPO "\\tempo"
321 %token TIMES "\\times"
322 %token TRANSPOSE "\\transpose"
323 %token TRANSPOSITION "\\transposition"
325 %token UNSET "\\unset"
328 /* Keyword token exceptions. */
329 %token TIME_T "\\time"
330 %token NEWCONTEXT "\\new"
333 /* Other string tokens. */
335 %token CHORD_BASS "/+"
336 %token CHORD_CARET "^"
337 %token CHORD_COLON ":"
338 %token CHORD_MINUS "-"
339 %token CHORD_SLASH "/"
340 %token DOUBLE_ANGLE_CLOSE ">>"
341 %token DOUBLE_ANGLE_OPEN "<<"
342 %token E_BACKSLASH "\\"
343 %token E_ANGLE_CLOSE "\\>"
344 %token E_CHAR "\\C[haracter]"
346 %token E_EXCLAMATION "\\!"
347 %token E_BRACKET_OPEN "\\["
349 %token E_BRACKET_CLOSE "\\]"
350 %token E_ANGLE_OPEN "\\<"
353 /* These used at all?
354 %token FIGURE_BRACKET_CLOSE
355 %token FIGURE_BRACKET_OPEN
357 parser.yy:348.8-25: warning: symbol `"\\>"' used more than once as a literal string
358 parser.yy:352.8-24: warning: symbol `"\\<"' used more than once as a literal string
361 %token FIGURE_CLOSE /* "\\>" */
362 %token FIGURE_OPEN /* "\\<" */
363 %token FIGURE_SPACE "_"
366 %token CHORDMODIFIERS
367 %token COMMANDSPANREQUEST
369 %token MULTI_MEASURE_REST
374 %token <i> E_UNSIGNED
377 %token <id> IDENTIFIER
379 %token <scm> CHORDMODIFIER_PITCH
380 %token <scm> CHORD_MODIFIER
381 %token <scm> CONTEXT_DEF_IDENTIFIER
382 %token <scm> DRUM_PITCH
383 %token <scm> DURATION_IDENTIFIER
384 %token <scm> EVENT_IDENTIFIER
385 %token <scm> FRACTION
386 %token <scm> LYRICS_STRING
387 %token <scm> LYRIC_MARKUP_IDENTIFIER
388 %token <scm> MARKUP_HEAD_EMPTY
389 %token <scm> MARKUP_HEAD_LIST0
390 %token <scm> MARKUP_HEAD_MARKUP0
391 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
392 %token <scm> MARKUP_HEAD_SCM0
393 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
394 %token <scm> MARKUP_HEAD_SCM0_SCM1
395 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
396 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
397 %token <scm> MARKUP_IDENTIFIER
398 %token <scm> MUSIC_FUNCTION
399 %token <scm> MUSIC_FUNCTION_MARKUP
400 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
401 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
402 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
403 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
404 %token <scm> MUSIC_FUNCTION_MUSIC
405 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
406 %token <scm> MUSIC_FUNCTION_SCM
407 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
408 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
409 %token <scm> MUSIC_FUNCTION_SCM_SCM
410 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
411 %token <scm> MUSIC_IDENTIFIER
412 %token <scm> NOTENAME_PITCH
413 %token <scm> NUMBER_IDENTIFIER
414 %token <scm> OUTPUT_DEF_IDENTIFIER
416 %token <scm> RESTNAME
417 %token <scm> SCM_IDENTIFIER
419 %token <scm> SCORE_IDENTIFIER
421 %token <scm> STRING_IDENTIFIER
422 %token <scm> TONICNAME_PITCH
425 %type <book> book_block
426 %type <book> book_body
428 %type <i> bare_unsigned
431 %type <i> exclamations
432 %type <i> optional_rest
437 %type <i> tremolo_type
439 %type <music> Composite_music
440 %type <music> Generic_prefix_music
441 %type <music> Grouped_music_list
443 %type <music> Prefix_composite_music
444 %type <music> Repeated_music
445 %type <music> Sequential_music
446 %type <music> Simple_music
447 %type <music> Simultaneous_music
448 %type <music> chord_body
449 %type <music> chord_body_element
450 %type <music> command_element
451 %type <music> command_req
452 %type <music> context_change
453 %type <music> direction_less_event
454 %type <music> direction_reqd_event
455 %type <music> event_chord
456 %type <music> gen_text_def
457 %type <music> music_property_def
458 %type <music> note_chord_element
459 %type <music> post_event
460 %type <music> re_rhythmed_music
461 %type <music> relative_music
462 %type <music> simple_element
463 %type <music> string_number_event
464 %type <music> tagged_post_event
465 %type <music> tempo_event
466 %type <music> toplevel_music
468 %type <outputdef> output_def_body
469 %type <outputdef> output_def_head
470 %type <outputdef> output_def
471 %type <outputdef> paper_block
473 %type <scm> Alternative_music
474 %type <scm> Generic_prefix_music_scm
475 %type <scm> Music_list
476 %type <scm> absolute_pitch
477 %type <scm> assignment_id
478 %type <scm> bare_number
479 %type <scm> bass_figure
480 %type <scm> bass_number
481 %type <scm> br_bass_figure
482 %type <scm> chord_body_elements
483 %type <scm> chord_item
484 %type <scm> chord_items
485 %type <scm> chord_separator
486 %type <scm> context_def_mod
487 %type <scm> context_def_spec_block
488 %type <scm> context_def_spec_body
489 %type <scm> context_mod
490 %type <scm> context_mod_list
491 %type <scm> context_prop_spec
492 %type <scm> direction_less_char
493 %type <scm> duration_length
494 %type <scm> embedded_scm
495 %type <scm> figure_list
496 %type <scm> figure_spec
498 %type <scm> full_markup
499 %type <scm> identifier_init
500 %type <scm> lilypond_header
501 %type <scm> lilypond_header_body
502 %type <scm> lyric_element
503 %type <scm> lyric_markup
505 %type <scm> markup_braced_list
506 %type <scm> markup_braced_list_body
507 %type <scm> markup_composed_list
508 %type <scm> markup_head_1_item
509 %type <scm> markup_head_1_list
510 %type <scm> markup_list
511 %type <scm> markup_top
512 %type <scm> mode_changing_head
513 %type <scm> mode_changing_head_with_context
514 %type <scm> multiplied_duration
515 %type <scm> new_chord
516 %type <scm> new_lyrics
517 %type <scm> number_expression
518 %type <scm> number_factor
519 %type <scm> number_term
520 %type <scm> object_id_setting
521 %type <scm> octave_check
522 %type <scm> optional_context_mod
523 %type <scm> optional_notemode_duration
525 %type <scm> pitch_also_in_chords
526 %type <scm> post_events
527 %type <scm> property_operation
529 %type <scm> script_abbreviation
530 %type <scm> simple_markup
531 %type <scm> simple_string
532 %type <scm> steno_duration
533 %type <scm> steno_pitch
534 %type <scm> steno_tonic_pitch
535 %type <scm> step_number
536 %type <scm> step_numbers
539 %type <score> score_block
540 %type <score> score_body
545 /* We don't assign precedence to / and *, because we might need varied
546 prec levels in different prods */
552 lilypond: /* empty */
553 | lilypond toplevel_expression {
555 | lilypond assignment {
558 THIS->error_level_ = 1;
561 THIS->error_level_ = 1;
567 OBJECTID STRING { $$ = $2; }
572 THIS->lexer_->set_identifier (ly_symbol2scm ("$globalheader"), $1);
579 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
580 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
581 scm_gc_unprotect_object (book->self_scm ());
586 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
587 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
588 scm_gc_unprotect_object (score->self_scm ());
592 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
593 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
594 scm_gc_unprotect_object (music->self_scm ());
597 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-text-handler");
598 scm_call_2 (proc, THIS->self_scm (), $1);
602 Output_def * od = $1;
604 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
605 id = ly_symbol2scm ("$defaultpaper");
606 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
607 id = ly_symbol2scm ("$defaultmidi");
608 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
609 id = ly_symbol2scm ("$defaultlayout");
611 THIS->lexer_->set_identifier (id, od->self_scm ());
612 scm_gc_unprotect_object (od->self_scm ());
627 lilypond_header_body:
629 $$ = ly_make_anonymous_module (be_safe_global);
630 THIS->lexer_->add_scope ($$);
632 | lilypond_header_body assignment {
638 HEADER '{' lilypond_header_body '}' {
639 $$ = THIS->lexer_->remove_scope ();
648 | LYRICS_STRING { $$ = $1; }
652 assignment_id '=' identifier_init {
653 if (! is_regular_identifier ($1))
655 @1.warning (_ ("identifier should have alphabetic characters only"));
658 THIS->lexer_->set_identifier ($1, $3);
661 TODO: devise standard for protection in parser.
663 The parser stack lives on the C-stack, which means that
664 all objects can be unprotected as soon as they're here.
674 $$ = $1->self_scm ();
675 scm_gc_unprotect_object ($$);
678 $$ = $1->self_scm ();
679 scm_gc_unprotect_object ($$);
681 | context_def_spec_block {
685 $$ = $1->self_scm ();
686 scm_gc_unprotect_object ($$);
689 $$ = $1->self_scm ();
690 scm_gc_unprotect_object ($$);
692 | number_expression {
705 $$ = scm_int2num ($1);
709 context_def_spec_block:
710 CONTEXT '{' context_def_spec_body '}'
716 context_def_spec_body:
718 $$ = Context_def::make_scm ();
719 unsmob_context_def ($$)->set_spot (@$);
721 | CONTEXT_DEF_IDENTIFIER {
723 unsmob_context_def ($$)->set_spot (@$);
725 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
726 Context_def*td = unsmob_context_def ($$);
728 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
729 SCM tag = scm_caar (p);
731 /* TODO: should make new tag "grob-definition" ? */
732 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
733 tag, scm_cons (scm_cdar (p), SCM_EOL)));
736 | context_def_spec_body context_mod {
737 unsmob_context_def ($$)->add_context_mod ($2);
744 BOOK '{' book_body '}' {
750 * Use 'handlers' like for toplevel-* stuff?
751 * grok \layout and \midi? */
756 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
757 scm_gc_unprotect_object ($$->paper_->self_scm ());
758 $$->header_ = THIS->lexer_->lookup_identifier ("$globalheader");
760 | book_body paper_block {
762 scm_gc_unprotect_object ($2->self_scm ());
764 | book_body score_block {
765 SCM s = $2->self_scm ();
767 scm_gc_unprotect_object (s);
769 | book_body full_markup {
772 | book_body lilypond_header {
777 $$->scores_ = SCM_EOL;
779 | book_body object_id_setting {
780 $$->user_key_ = ly_scm2string ($2);
785 SCORE '{' score_body '}' {
792 SCM m = $1->self_scm ();
793 scm_gc_unprotect_object (m);
794 SCM scorify = ly_lily_module_constant ("scorify-music");
795 SCM score = scm_call_2 (scorify, m, THIS->self_scm ());
797 // pass ownernship to C++ again.
798 scm_gc_protect_object (score);
799 $$ = unsmob_score (score);
803 $$ = unsmob_score ($1);
806 | score_body object_id_setting {
807 $$->user_key_ = ly_scm2string ($2);
809 | score_body lilypond_header {
812 | score_body output_def {
813 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
815 THIS->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
822 scm_gc_unprotect_object ($2->self_scm ());
825 $$->error_found_ = true;
837 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
839 THIS->parser_error (@1, _ ("need \\paper for paper block"));
840 $$ = get_paper (THIS);
847 output_def_body '}' {
850 THIS->lexer_->remove_scope ();
851 THIS->lexer_->pop_state ();
857 $$ = get_paper (THIS);
858 $$->input_origin_ = @$;
859 THIS->lexer_->add_scope ($$->scope_);
862 Output_def *p = get_midi (THIS);
864 THIS->lexer_->add_scope (p->scope_);
867 Output_def *p = get_layout (THIS);
869 THIS->lexer_->add_scope (p->scope_);
876 output_def_head '{' {
878 $$->input_origin_.set_spot (@$);
879 THIS->lexer_->push_initial_state ();
881 | output_def_head '{' OUTPUT_DEF_IDENTIFIER {
882 scm_gc_unprotect_object ($1->self_scm ());
883 Output_def *o = unsmob_output_def ($3);
884 o->input_origin_.set_spot (@$);
886 THIS->lexer_->remove_scope ();
887 THIS->lexer_->add_scope (o->scope_);
888 THIS->lexer_->push_initial_state ();
890 | output_def_body assignment {
893 | output_def_body context_def_spec_block {
894 assign_context_def ($$, $2);
896 | output_def_body tempo_event {
898 junk this ? there already is tempo stuff in
901 int m = scm_to_int ($2->get_property ("metronome-count"));
902 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
903 set_tempo ($$, d->get_length (), m);
904 scm_gc_unprotect_object ($2->self_scm ());
906 | output_def_body error {
912 TEMPO steno_duration '=' bare_unsigned {
913 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
914 $$->set_property ("tempo-unit", $2);
915 $$->set_property ("metronome-count", scm_int2num ( $4));
920 The representation of a list is the
924 to have efficient append. */
928 $$ = scm_cons (SCM_EOL, SCM_EOL);
932 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
933 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
935 if (scm_is_pair (scm_cdr (s)))
936 scm_set_cdr_x (scm_cdr (s), c); /* append */
938 scm_set_car_x (s, c); /* set first cons */
939 scm_set_cdr_x (s, c); /* remember last cell */
941 | Music_list embedded_scm {
945 Music * m = MY_MAKE_MUSIC("Music");
947 m->set_property ("error-found", SCM_BOOL_T);
949 SCM c = scm_cons (m->self_scm (), SCM_EOL);
950 scm_gc_unprotect_object (m->self_scm ()); /* UGH */
952 if (scm_is_pair (scm_cdr (s)))
953 scm_set_cdr_x (scm_cdr (s), c); /* append */
955 scm_set_car_x (s, c); /* set first cons */
956 scm_set_cdr_x (s, c); /* remember last cell */
969 | ALTERNATIVE '{' Music_list '}' {
976 REPEAT simple_string bare_unsigned Music Alternative_music
980 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
981 if (times < scm_ilength (alts)) {
982 unsmob_music (scm_car (alts))
983 ->origin ()->warning (
984 _ ("more alternatives than repeats"));
985 warning ("junking excess alternatives");
986 alts = ly_truncate_list (times, alts);
990 SCM proc = ly_lily_module_constant ("make-repeated-music");
992 SCM mus = scm_call_1 (proc, $2);
993 scm_gc_protect_object (mus); // UGH.
994 Music *r = unsmob_music (mus);
997 r-> set_property ("element", beg->self_scm ());
998 scm_gc_unprotect_object (beg->self_scm ());
1000 r->set_property ("repeat-count", scm_int2num (max (times, 1)));
1002 r-> set_property ("elements",alts);
1003 if (ly_is_equal ($2, scm_makfrom0str ("tremolo"))) {
1005 TODO: move this code to Scheme.
1008 /* we cannot get durations and other stuff
1009 correct down the line,
1010 so we have to add to the duration log here. */
1011 SCM func = ly_lily_module_constant ("shift-duration-log");
1013 int dots = ($3 % 3) ? 0 : 1;
1014 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
1017 if ($4->is_mus_type ("sequential-music"))
1019 int list_len = scm_ilength ($4->get_property ("elements"));
1021 $4->origin ()->warning (_f ("expect 2 elements for Chord tremolo, found %d", list_len));
1023 r->compress (Moment (Rational (1, list_len)));
1025 scm_call_3 (func, r->self_scm (), scm_int2num (shift), scm_int2num (dots));
1028 r->set_spot (*$4->origin ());
1035 SEQUENTIAL '{' Music_list '}' {
1036 $$ = MY_MAKE_MUSIC ("SequentialMusic");
1037 $$->set_property ("elements", scm_car ($3));
1040 | '{' Music_list '}' {
1041 $$ = MY_MAKE_MUSIC ("SequentialMusic");
1042 $$->set_property ("elements", scm_car ($2));
1048 SIMULTANEOUS '{' Music_list '}'{
1049 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
1050 $$->set_property ("elements", scm_car ($3));
1054 | simul_open Music_list simul_close {
1055 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
1056 $$->set_property ("elements", scm_car ($2));
1062 event_chord { $$ = $1; }
1063 | MUSIC_IDENTIFIER {
1064 $$ = unsmob_music ($1);
1066 | music_property_def
1071 optional_context_mod:
1072 /**/ { $$ = SCM_EOL; }
1073 | WITH { THIS->lexer_->push_initial_state (); }
1074 '{' context_mod_list '}'
1076 THIS->lexer_->pop_state ();
1082 /* */ { $$ = SCM_EOL; }
1083 | context_mod_list context_mod {
1084 $$ = scm_cons ($2, $1);
1090 Prefix_composite_music { $$ = $1; }
1091 | Grouped_music_list { $$ = $1; }
1095 Simultaneous_music { $$ = $1; }
1096 | Sequential_music { $$ = $1; }
1099 Generic_prefix_music_scm:
1101 $$ = scm_list_2 ($1, make_input (@$));
1103 | MUSIC_FUNCTION_SCM embedded_scm {
1104 $$ = scm_list_3 ($1, make_input (@$), $2);
1106 | MUSIC_FUNCTION_MARKUP full_markup {
1107 $$ = scm_list_3 ($1, make_input (@$), $2);
1109 | MUSIC_FUNCTION_MUSIC Music {
1110 $$ = scm_list_3 ($1, make_input (@$), $2->self_scm ());
1111 scm_gc_unprotect_object ($2->self_scm ());
1113 | MUSIC_FUNCTION_SCM_MUSIC embedded_scm Music {
1114 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1115 scm_gc_unprotect_object ($3->self_scm ());
1117 | MUSIC_FUNCTION_SCM_SCM embedded_scm embedded_scm {
1118 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1120 | MUSIC_FUNCTION_SCM_SCM_MUSIC embedded_scm embedded_scm Music {
1121 $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
1123 | MUSIC_FUNCTION_MARKUP_MUSIC full_markup Music {
1124 $$ = scm_list_4 ($1, make_input (@$), $2, $3->self_scm ());
1125 scm_gc_unprotect_object ($3->self_scm ());
1127 | MUSIC_FUNCTION_MARKUP_MARKUP full_markup full_markup {
1128 $$ = scm_list_4 ($1, make_input (@$), $2, $3);
1130 | MUSIC_FUNCTION_MUSIC_MUSIC Music Music {
1131 $$ = scm_list_4 ($1, make_input (@$), $2->self_scm (), $3->self_scm ());
1132 scm_gc_unprotect_object ($2->self_scm ());
1133 scm_gc_unprotect_object ($3->self_scm ());
1135 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC embedded_scm Music Music {
1136 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1137 scm_gc_unprotect_object ($4->self_scm ());
1138 scm_gc_unprotect_object ($3->self_scm ());
1140 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC full_markup Music Music {
1141 $$ = scm_list_5 ($1, make_input (@$), $2, $3->self_scm (), $4->self_scm ());
1142 scm_gc_unprotect_object ($3->self_scm ());
1143 scm_gc_unprotect_object ($4->self_scm ());
1147 Generic_prefix_music:
1148 Generic_prefix_music_scm {
1149 SCM func = scm_car ($1);
1150 Input *loc = unsmob_input (scm_cadr ($1));
1151 SCM args = scm_cddr ($1);
1152 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
1154 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
1157 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr ($1), sig, args)))
1159 THIS->error_level_ = 1;
1165 m = scm_apply_0 (func, scm_cons (THIS->self_scm(),
1168 if (unsmob_music (m))
1170 $$ = unsmob_music (m);
1171 scm_gc_protect_object (m);
1176 loc->error (_ ("music head function must return Music object"));
1177 $$ = MY_MAKE_MUSIC ("Music");
1179 $$->set_spot (*loc);
1184 Prefix_composite_music:
1185 Generic_prefix_music {
1188 | CONTEXT simple_string '=' simple_string optional_context_mod Music {
1189 $$ = context_spec_music ($2, $4, $6, $5);
1192 | CONTEXT simple_string optional_context_mod Music {
1193 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1195 | NEWCONTEXT simple_string optional_context_mod Music {
1196 $$ = context_spec_music ($2, get_next_unique_context_id (), $4,
1200 | TIMES fraction Music
1203 int n = scm_to_int (scm_car ($2)); int d = scm_to_int (scm_cdr ($2));
1206 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1209 $$->set_property ("element", mp->self_scm ());
1210 scm_gc_unprotect_object (mp->self_scm ());
1211 $$->set_property ("numerator", scm_int2num (n));
1212 $$->set_property ("denominator", scm_int2num (d));
1213 $$->compress (Moment (Rational (n,d)));
1216 | Repeated_music { $$ = $1; }
1217 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1218 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1220 Pitch from = *unsmob_pitch ($2);
1221 Pitch to = *unsmob_pitch ($3);
1223 p->transpose (pitch_interval (from, to));
1224 $$->set_property ("element", p->self_scm ());
1225 scm_gc_unprotect_object (p->self_scm ());
1227 | mode_changing_head Grouped_music_list {
1228 if ($1 == ly_symbol2scm ("chords"))
1230 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1231 chm->set_property ("element", $2->self_scm ());
1233 scm_gc_unprotect_object ($2->self_scm ());
1239 THIS->lexer_->pop_state ();
1241 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1242 $$ = context_spec_music ($1, get_next_unique_context_id (),
1244 if ($1 == ly_symbol2scm ("ChordNames"))
1246 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1247 chm->set_property ("element", $$->self_scm ());
1248 scm_gc_unprotect_object ($$->self_scm ());
1251 THIS->lexer_->pop_state ();
1253 | relative_music { $$ = $1; }
1254 | re_rhythmed_music { $$ = $1; }
1255 | TAG embedded_scm Music {
1256 tag_music ($3, $2, @$);
1263 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1264 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1266 $$ = ly_symbol2scm ("notes");
1270 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1271 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1273 $$ = ly_symbol2scm ("drums");
1276 THIS->lexer_->push_figuredbass_state ();
1278 $$ = ly_symbol2scm ("figures");
1281 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1282 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1283 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1284 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1285 $$ = ly_symbol2scm ("chords");
1289 { THIS->lexer_->push_lyric_state ();
1290 $$ = ly_symbol2scm ("lyrics");
1294 mode_changing_head_with_context:
1296 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1297 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1299 $$ = ly_symbol2scm ("DrumStaff");
1302 THIS->lexer_->push_figuredbass_state ();
1304 $$ = ly_symbol2scm ("FiguredBass");
1307 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1308 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1309 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1310 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1311 $$ = ly_symbol2scm ("ChordNames");
1314 { THIS->lexer_->push_lyric_state ();
1315 $$ = ly_symbol2scm ("Lyrics");
1321 RELATIVE absolute_pitch Music {
1323 Pitch start = *unsmob_pitch ($2);
1324 $$ = make_music_relative (start, m);
1325 scm_gc_unprotect_object (m->self_scm ());
1327 | RELATIVE Composite_music {
1330 Pitch middle_c (0, 0, 0);
1331 $$ = make_music_relative (middle_c, m);
1332 scm_gc_unprotect_object (m->self_scm ());
1337 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1339 Grouped_music_list {
1340 /* Can also use Music at the expensive of two S/Rs similar to
1341 \repeat \alternative */
1342 THIS->lexer_->pop_state ();
1344 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1346 | new_lyrics ADDLYRICS {
1347 THIS->lexer_->push_lyric_state ();
1348 } Grouped_music_list {
1349 THIS->lexer_->pop_state ();
1350 $$ = scm_cons ($4->self_scm (), $1);
1355 Grouped_music_list new_lyrics {
1357 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice);
1358 if (!scm_is_string (name))
1360 name = get_next_unique_lyrics_context_id ();
1361 voice = context_spec_music (scm_makfrom0str ("Voice"),
1366 SCM context = scm_makfrom0str ("Lyrics");
1367 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1370 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1372 Music *music = unsmob_music (scm_car (s));
1373 Music *com = make_lyric_combine_music (name, music);
1374 Music *csm = context_spec_music (context,
1375 get_next_unique_context_id (), com, SCM_EOL);
1376 lst = scm_cons (csm->self_scm (), lst);
1378 all->set_property ("elements", scm_cons (voice->self_scm (),
1381 scm_gc_unprotect_object (voice->self_scm ());
1383 | LYRICSTO simple_string {
1384 THIS->lexer_->push_lyric_state ();
1386 THIS->lexer_->pop_state ();
1389 $$ = make_lyric_combine_music (name, music);
1390 scm_gc_unprotect_object (music->self_scm ());
1395 CHANGE STRING '=' STRING {
1396 Music*t = MY_MAKE_MUSIC ("ContextChange");
1397 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1398 t-> set_property ("change-to-id", $4);
1407 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1408 scm_string_to_symbol ($1), $3);
1410 | UNSET simple_string {
1411 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1412 scm_string_to_symbol ($2));
1414 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1415 $$ = scm_list_4 (ly_symbol2scm ("push"),
1416 scm_string_to_symbol ($2), $3, $5);
1418 | REVERT simple_string embedded_scm {
1419 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1420 scm_string_to_symbol ($2), $3);
1425 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1426 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1428 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1429 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1430 | DENIES { $$ = ly_symbol2scm ("denies"); }
1432 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1433 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1434 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1435 | NAME { $$ = ly_symbol2scm ("context-name"); }
1439 property_operation { $$ = $1; }
1440 | context_def_mod STRING {
1441 $$ = scm_list_2 ($1, $2);
1447 if (!is_regular_identifier ($1))
1449 @$.error (_("Grob name should be alphanumeric"));
1452 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1453 scm_string_to_symbol ($1));
1455 | simple_string '.' simple_string {
1456 $$ = scm_list_2 (scm_string_to_symbol ($1),
1457 scm_string_to_symbol ($3));
1462 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1463 $$ = property_op_to_music (scm_list_4 (
1464 ly_symbol2scm ("poppush"),
1467 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1469 | REVERT context_prop_spec embedded_scm {
1470 $$ = property_op_to_music (scm_list_3 (
1471 ly_symbol2scm ("pop"),
1475 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1477 | SET context_prop_spec '=' scalar {
1478 $$ = property_op_to_music (scm_list_3 (
1479 ly_symbol2scm ("assign"),
1482 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1484 | UNSET context_prop_spec {
1485 $$ = property_op_to_music (scm_list_2 (
1486 ly_symbol2scm ("unset"),
1488 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1490 | ONCE music_property_def {
1491 SCM e = $2->get_property ("element");
1492 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1503 | STRING_IDENTIFIER {
1506 | string '+' string {
1507 $$ = scm_string_append (scm_list_2 ($1, $3));
1511 simple_string: STRING {
1527 /* if (scm_integer_p ($1) == SCM_BOOL_T)
1529 int k = scm_to_int (scm_inexact_to_exact ($1));
1533 THIS->parser_error (@1, _ ("need integer number arg"));
1544 $$ = scm_int2num ($1);
1550 pre_events doesn't contain anything. It is a trick:
1552 Adding pre_events to the simple_element
1553 makes the choice between
1559 simple_element: STRING
1561 a single shift/reduction conflict.
1563 nevertheless, this is not very clean, and we should find a different
1567 pre_events: /* empty */
1571 pre_events simple_element post_events {
1572 SCM elts = $2-> get_property ("elements");
1574 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1576 $2->set_property ("elements", elts);
1577 /* why is this giving wrong start location? -ns
1578 * $2->set_spot (@$); */
1580 i.set_location (@2, @3);
1585 | note_chord_element
1590 chord_body optional_notemode_duration post_events
1592 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1593 SCM es = $1->get_property ("elements");
1594 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1596 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1597 unsmob_music (scm_car (s))->set_property ("duration", dur);
1598 es = ly_append2 (es, postevs);
1600 $1-> set_property ("elements", es);
1612 simul_open: DOUBLE_ANGLE_OPEN
1615 simul_close: DOUBLE_ANGLE_CLOSE
1619 chord_open chord_body_elements chord_close
1621 $$ = MY_MAKE_MUSIC ("EventChord");
1623 $$->set_property ("elements",
1624 scm_reverse_x ($2, SCM_EOL));
1628 chord_body_elements:
1629 /* empty */ { $$ = SCM_EOL; }
1630 | chord_body_elements chord_body_element {
1631 $$ = scm_cons ($2->self_scm (), $1);
1632 scm_gc_unprotect_object ($2->self_scm ());
1637 pitch exclamations questions octave_check post_events
1644 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1645 n->set_property ("pitch", $1);
1648 n->set_property ("cautionary", SCM_BOOL_T);
1649 if (ex % 2 || q % 2)
1650 n->set_property ("force-accidental", SCM_BOOL_T);
1652 if (scm_is_pair (post)) {
1653 SCM arts = scm_reverse_x (post, SCM_EOL);
1654 n->set_property ("articulations", arts);
1656 if (scm_is_number (check))
1658 int q = scm_to_int (check);
1659 n->set_property ("absolute-octave", scm_int2num (q-1));
1665 | DRUM_PITCH post_events {
1666 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1667 n->set_property ("duration", $2);
1668 n->set_property ("drum-type", $1);
1671 if (scm_is_pair ($2)) {
1672 SCM arts = scm_reverse_x ($2, SCM_EOL);
1673 n->set_property ("articulations", arts);
1680 ADDQUOTE string Music {
1681 SCM adder = ly_lily_module_constant ("add-quotable");
1683 scm_call_2 (adder, $2, $3->self_scm ());
1684 scm_gc_unprotect_object ($3->self_scm ());
1690 $$ = MY_MAKE_MUSIC ("EventChord");
1691 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1692 scm_gc_unprotect_object ($1->self_scm ());
1697 | SKIP duration_length {
1698 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1699 skip->set_property ("duration", $2);
1700 skip->set_spot (@$);
1704 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1707 $$->set_property ("pitch", $2);
1710 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1711 m->set_property ("span-direction", scm_int2num (START));
1714 $$ = MY_MAKE_MUSIC ("EventChord");
1715 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1716 scm_gc_unprotect_object (m->self_scm ());
1720 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1721 m->set_property ("span-direction", scm_int2num (STOP));
1724 $$ = MY_MAKE_MUSIC ("EventChord");
1725 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1727 scm_gc_unprotect_object (m->self_scm ());
1730 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1734 SCM pipe = THIS->lexer_->lookup_identifier ("pipeSymbol");
1736 if (Music * m = unsmob_music (pipe))
1739 $$ = MY_MAKE_MUSIC ("BarCheck");
1743 | TRANSPOSITION pitch {
1745 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1746 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1747 sounds_as_c.smobbed_copy());
1749 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1753 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1755 Music *csm = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1757 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED, csm, SCM_EOL);
1761 | PARTIAL duration_length {
1762 Moment m = - unsmob_duration ($2)->get_length ();
1763 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1765 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1767 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1772 SCM proc = ly_lily_module_constant ("make-clef-set");
1774 SCM result = scm_call_1 (proc, $2);
1775 scm_gc_protect_object (result);
1776 $$ = unsmob_music (result);
1779 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1781 SCM result = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1782 scm_gc_protect_object (result);
1783 $$ = unsmob_music (result);
1786 SCM proc = ly_lily_module_constant ("make-mark-set");
1788 SCM result = scm_call_1 (proc, $2);
1789 scm_gc_protect_object (result);
1790 $$ = unsmob_music (result);
1796 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1799 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1806 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1809 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1811 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent");
1812 if (scm_ilength ($3) > 0)
1814 key->set_property ("pitch-alist", $3);
1815 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1816 key->transpose (* unsmob_pitch ($2));
1818 THIS->parser_error (@3, _ ("second argument must be pitch list"));
1830 | post_events post_event {
1832 $$ = scm_cons ($2->self_scm (), $$);
1833 scm_gc_unprotect_object ($2->self_scm ());
1835 | post_events tagged_post_event {
1836 $2 -> set_spot (@2);
1837 $$ = scm_cons ($2->self_scm (), $$);
1838 scm_gc_unprotect_object ($2->self_scm ());
1844 '-' TAG embedded_scm post_event {
1845 tag_music ($4, $3, @$);
1852 direction_less_event {
1856 if (!THIS->lexer_->is_lyric_state ())
1857 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1858 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1861 if (!THIS->lexer_->is_lyric_state ())
1862 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1863 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1865 | script_dir direction_reqd_event {
1867 $2->set_property ("direction", scm_int2num ($1));
1870 | script_dir direction_less_event {
1872 $2->set_property ("direction", scm_int2num ($1));
1875 | string_number_event
1878 string_number_event:
1880 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1881 s->set_property ("string-number", scm_int2num ($1));
1887 direction_less_char:
1889 $$ = ly_symbol2scm ("bracketOpenSymbol");
1892 $$ = ly_symbol2scm ("bracketCloseSymbol");
1895 $$ = ly_symbol2scm ("tildeSymbol");
1898 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1901 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1904 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1907 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1910 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1913 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1916 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1920 direction_less_event:
1921 direction_less_char {
1922 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1924 if (unsmob_music (predefd))
1926 m = unsmob_music (predefd)->clone ();
1930 m = MY_MAKE_MUSIC ("Music");
1935 | EVENT_IDENTIFIER {
1936 $$ = unsmob_music ($1);
1939 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1941 a->set_property ("tremolo-type", scm_int2num ($1));
1946 direction_reqd_event:
1950 | script_abbreviation {
1951 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1952 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1953 if (scm_is_string (s))
1954 a->set_property ("articulation-type", s);
1955 else THIS->parser_error (@1, _ ("expecting string as script definition"));
1961 /**/ { $$ = SCM_EOL; }
1962 | '=' { $$ = scm_int2num (0); }
1963 | '=' sub_quotes { $$ = scm_int2num ($2); }
1964 | '=' sup_quotes { $$ = scm_int2num ($2); }
1989 | NOTENAME_PITCH sup_quotes {
1990 Pitch p = *unsmob_pitch ($1);
1991 p = p.transposed (Pitch ($2,0,0));
1992 $$ = p.smobbed_copy ();
1994 | NOTENAME_PITCH sub_quotes {
1995 Pitch p =* unsmob_pitch ($1);
1996 p = p.transposed (Pitch (-$2,0,0));
1997 $$ = p.smobbed_copy ();
2009 | TONICNAME_PITCH sup_quotes {
2010 Pitch p = *unsmob_pitch ($1);
2011 p = p.transposed (Pitch ($2,0,0));
2012 $$ = p.smobbed_copy ();
2014 | TONICNAME_PITCH sub_quotes {
2015 Pitch p =* unsmob_pitch ($1);
2017 p = p.transposed (Pitch (-$2,0,0));
2018 $$ = p.smobbed_copy ();
2028 pitch_also_in_chords:
2035 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
2036 t->set_property ("text", $1);
2041 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
2042 t->set_property ("text",
2043 make_simple_markup ($1));
2049 Music *t = MY_MAKE_MUSIC ("FingerEvent");
2050 t->set_property ("digit", scm_int2num ($1));
2056 script_abbreviation:
2058 $$ = scm_makfrom0str ("Hat");
2061 $$ = scm_makfrom0str ("Plus");
2064 $$ = scm_makfrom0str ("Dash");
2067 $$ = scm_makfrom0str ("Bar");
2070 $$ = scm_makfrom0str ("Larger");
2073 $$ = scm_makfrom0str ("Dot");
2076 $$ = scm_makfrom0str ("Underscore");
2083 | '-' { $$ = CENTER; }
2094 multiplied_duration {
2099 optional_notemode_duration:
2101 Duration dd = THIS->default_duration_;
2102 $$ = dd.smobbed_copy ();
2104 | multiplied_duration {
2106 THIS->default_duration_ = *unsmob_duration ($$);
2111 bare_unsigned dots {
2113 if (!is_duration ($1))
2114 THIS->parser_error (@1, _f ("not a duration: %d", $1));
2118 $$ = Duration (len, $2).smobbed_copy ();
2120 | DURATION_IDENTIFIER dots {
2121 Duration *d = unsmob_duration ($1);
2122 Duration k (d->duration_log (), d->dot_count () + $2);
2128 multiplied_duration:
2132 | multiplied_duration '*' bare_unsigned {
2133 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2135 | multiplied_duration '*' FRACTION {
2136 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2138 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2143 FRACTION { $$ = $1; }
2144 | UNSIGNED '/' UNSIGNED {
2145 $$ = scm_cons (scm_int2num ($1), scm_int2num ($3));
2162 | ':' bare_unsigned {
2163 if (!is_duration ($2))
2164 THIS->parser_error (@2, _f ("not a duration: %d", $2));
2171 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2172 $$ = scm_list_2 (ly_lily_module_constant ("number-markup"),
2176 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2177 $$ = scm_list_2 (ly_lily_module_constant ("number-markup"),
2180 | STRING { $$ = $1; }
2181 | full_markup { $$ = $1; }
2192 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2193 $$ = bfr->self_scm ();
2194 scm_gc_unprotect_object ($$);
2197 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2198 $$ = bfr->self_scm ();
2200 bfr->set_property ("figure", $1);
2202 scm_gc_unprotect_object ($$);
2204 | bass_figure bass_mod {
2205 Music *m = unsmob_music ($1);
2207 SCM salter = m->get_property ("alteration");
2208 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2209 m->set_property ("alteration",
2210 scm_int2num (alter + $2));
2212 m->set_property ("alteration", scm_int2num (0));
2220 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2225 | br_bass_figure ']' {
2227 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2235 | figure_list br_bass_figure {
2236 $$ = scm_cons ($2, $1);
2241 FIGURE_OPEN figure_list FIGURE_CLOSE {
2242 Music *m = MY_MAKE_MUSIC ("EventChord");
2243 $2 = scm_reverse_x ($2, SCM_EOL);
2244 m->set_property ("elements", $2);
2245 $$ = m->self_scm ();
2256 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2257 if (!THIS->lexer_->is_note_state ())
2258 THIS->parser_error (@1, _ ("have to be in Note mode for notes"));
2262 n = MY_MAKE_MUSIC ("RestEvent");
2264 n = MY_MAKE_MUSIC ("NoteEvent");
2266 n->set_property ("pitch", $1);
2267 n->set_property ("duration", $5);
2269 if (scm_is_number ($4))
2271 int q = scm_to_int ($4);
2272 n->set_property ("absolute-octave", scm_int2num (q-1));
2276 n->set_property ("cautionary", SCM_BOOL_T);
2277 if ($2 % 2 || $3 % 2)
2278 n->set_property ("force-accidental", SCM_BOOL_T);
2280 Music *v = MY_MAKE_MUSIC ("EventChord");
2281 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2282 scm_gc_unprotect_object (n->self_scm ());
2288 | DRUM_PITCH optional_notemode_duration {
2289 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2290 n->set_property ("duration", $2);
2291 n->set_property ("drum-type", $1);
2293 Music *v = MY_MAKE_MUSIC ("EventChord");
2294 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2295 scm_gc_unprotect_object (n->self_scm ());
2301 | figure_spec optional_notemode_duration {
2302 Music *m = unsmob_music ($1);
2304 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2306 unsmob_music (scm_car (s))->set_property ("duration", $2);
2310 | RESTNAME optional_notemode_duration {
2312 if (ly_scm2string ($1) == "s") {
2314 ev = MY_MAKE_MUSIC ("SkipEvent");
2317 ev = MY_MAKE_MUSIC ("RestEvent");
2320 ev->set_property ("duration", $2);
2322 Music *velt = MY_MAKE_MUSIC ("EventChord");
2323 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2324 velt->set_spot (@$);
2326 scm_gc_unprotect_object (ev->self_scm ());
2330 | MULTI_MEASURE_REST optional_notemode_duration {
2331 SCM proc = ly_lily_module_constant ("make-multi-measure-rest");
2332 SCM mus = scm_call_2 (proc, $2, make_input (@$));
2333 scm_gc_protect_object (mus);
2334 $$ = unsmob_music (mus);
2337 | lyric_element optional_notemode_duration {
2338 if (!THIS->lexer_->is_lyric_state ())
2339 THIS->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2341 Music *lreq = MY_MAKE_MUSIC ("LyricEvent");
2342 lreq->set_property ("text", $1);
2343 lreq->set_property ("duration",$2);
2344 lreq->set_spot (@$);
2345 Music *velt = MY_MAKE_MUSIC ("EventChord");
2346 velt->set_property ("elements", scm_list_1 (lreq->self_scm ()));
2351 if (!THIS->lexer_->is_chord_state ())
2352 THIS->parser_error (@1, _ ("have to be in Chord mode for chords"));
2353 $$ = unsmob_music ($1);
2362 $$ = make_simple_markup ($1);
2367 steno_tonic_pitch optional_notemode_duration {
2368 $$ = make_chord ($1, $2, SCM_EOL);
2370 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2371 SCM its = scm_reverse_x ($4, SCM_EOL);
2372 $$ = make_chord ($1, $2, scm_cons ($3, its));
2380 | chord_items chord_item {
2381 $$ = scm_cons ($2, $$);
2387 $$ = ly_symbol2scm ("chord-colon");
2390 $$ = ly_symbol2scm ("chord-caret");
2392 | CHORD_SLASH steno_tonic_pitch {
2393 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2395 | CHORD_BASS steno_tonic_pitch {
2396 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2405 $$ = scm_reverse_x ($1, SCM_EOL);
2413 step_number { $$ = scm_cons ($1, SCM_EOL); }
2414 | step_numbers '.' step_number {
2415 $$ = scm_cons ($3, $$);
2421 $$ = make_chord_step ($1, 0);
2423 | bare_unsigned '+' {
2424 $$ = make_chord_step ($1, SHARP);
2426 | bare_unsigned CHORD_MINUS {
2427 $$ = make_chord_step ($1, FLAT);
2434 TODO: should deprecate in favor of Scheme?
2438 number_expression '+' number_term {
2439 $$ = scm_sum ($1, $3);
2441 | number_expression '-' number_term {
2442 $$ = scm_difference ($1, $3);
2451 | number_factor '*' number_factor {
2452 $$ = scm_product ($1, $3);
2454 | number_factor '/' number_factor {
2455 $$ = scm_divide ($1, $3);
2460 '-' number_factor { /* %prec UNARY_MINUS */
2461 $$ = scm_difference ($2, SCM_UNDEFINED);
2469 $$ = scm_int2num ($1);
2474 | NUMBER_IDENTIFIER {
2477 | REAL NUMBER_IDENTIFIER {
2478 $$ = scm_make_real (scm_to_double ($1) *scm_to_double ($2));
2480 | UNSIGNED NUMBER_IDENTIFIER {
2481 $$ = scm_make_real ($1 *scm_to_double ($2));
2497 | exclamations '!' { $$ ++; }
2502 | questions '?' { $$ ++; }
2506 This should be done more dynamically if possible.
2510 LYRIC_MARKUP_IDENTIFIER {
2514 { THIS->lexer_->push_markup_state (); }
2517 THIS->lexer_->pop_state ();
2526 { THIS->lexer_->push_markup_state (); }
2529 THIS->lexer_->pop_state ();
2535 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2537 | markup_head_1_list simple_markup {
2538 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2546 markup_composed_list {
2549 | markup_braced_list {
2554 markup_composed_list:
2555 markup_head_1_list markup_braced_list {
2556 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2562 '{' markup_braced_list_body '}' {
2563 $$ = scm_reverse_x ($2, SCM_EOL);
2567 markup_braced_list_body:
2568 /* empty */ { $$ = SCM_EOL; }
2569 | markup_braced_list_body markup {
2570 $$ = scm_cons ($2, $1);
2572 | markup_braced_list_body markup_list {
2573 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2578 MARKUP_HEAD_MARKUP0 {
2579 $$ = scm_list_1 ($1);
2581 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2582 $$ = scm_list_2 ($1, $2);
2584 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2585 $$ = scm_list_3 ($1, $2, $3);
2590 markup_head_1_item {
2591 $$ = scm_list_1 ($1);
2593 | markup_head_1_list markup_head_1_item {
2594 $$ = scm_cons ($2, $1);
2600 $$ = make_simple_markup ($1);
2602 | MARKUP_IDENTIFIER {
2605 | LYRIC_MARKUP_IDENTIFIER {
2608 | STRING_IDENTIFIER {
2612 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2613 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2614 } '{' score_body '}' {
2616 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2617 scm_gc_unprotect_object (sc->self_scm ());
2618 THIS->lexer_->pop_state ();
2620 | MARKUP_HEAD_SCM0 embedded_scm {
2621 $$ = scm_list_2 ($1, $2);
2623 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2624 $$ = scm_list_4 ($1, $2, $3, $4);
2626 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2627 $$ = scm_list_3 ($1, $2, $3);
2629 | MARKUP_HEAD_EMPTY {
2630 $$ = scm_list_1 ($1);
2632 | MARKUP_HEAD_LIST0 markup_list {
2633 $$ = scm_list_2 ($1,$2);
2635 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2636 $$ = scm_list_3 ($1, $2, $3);
2641 markup_head_1_list simple_markup {
2642 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2643 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2653 Lily_parser::set_yydebug (bool )
2661 Lily_parser::do_yyparse ()
2663 yyparse ((void*)this);
2672 It is a little strange to have this function in this file, but
2673 otherwise, we have to import music classes into the lexer.
2677 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2679 if (scm_is_string (sid)) {
2681 return STRING_IDENTIFIER;
2682 } else if (scm_is_number (sid)) {
2684 return NUMBER_IDENTIFIER;
2685 } else if (unsmob_context_def (sid)) {
2686 *destination = unsmob_context_def (sid)->clone_scm ();
2687 return CONTEXT_DEF_IDENTIFIER;
2688 } else if (unsmob_score (sid)) {
2689 Score *score = new Score (*unsmob_score (sid));
2690 *destination = score->self_scm ();
2691 return SCORE_IDENTIFIER;
2692 } else if (Music *mus = unsmob_music (sid)) {
2693 mus = mus->clone ();
2694 *destination = mus->self_scm ();
2695 unsmob_music (*destination)->
2696 set_property ("origin", make_input (last_input_));
2698 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2701 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2702 } else if (unsmob_duration (sid)) {
2703 *destination = unsmob_duration (sid)->smobbed_copy ();
2704 return DURATION_IDENTIFIER;
2705 } else if (unsmob_output_def (sid)) {
2706 Output_def *p = unsmob_output_def (sid);
2709 *destination = p->self_scm ();
2710 return OUTPUT_DEF_IDENTIFIER;
2711 } else if (Text_interface::markup_p (sid)) {
2713 if (is_lyric_state ())
2714 return LYRIC_MARKUP_IDENTIFIER;
2715 return MARKUP_IDENTIFIER;
2722 property_op_to_music (SCM op)
2725 SCM tag = scm_car (op);
2726 SCM symbol = scm_cadr (op);
2727 SCM args = scm_cddr (op);
2728 SCM grob_val = SCM_UNDEFINED;
2729 SCM grob_sym = SCM_UNDEFINED;
2730 SCM val = SCM_UNDEFINED;
2732 if (tag == ly_symbol2scm ("assign"))
2734 m = MY_MAKE_MUSIC ("PropertySet");
2735 val = scm_car (args);
2737 else if (tag == ly_symbol2scm ("unset"))
2738 m = MY_MAKE_MUSIC ("PropertyUnset");
2739 else if (tag == ly_symbol2scm ("poppush")
2740 || tag == ly_symbol2scm ("push"))
2742 m = MY_MAKE_MUSIC ("OverrideProperty");
2743 grob_sym = scm_car (args);
2744 grob_val = scm_cadr (args);
2746 else if (tag == ly_symbol2scm ("pop")) {
2747 m = MY_MAKE_MUSIC ("RevertProperty");
2748 grob_sym = scm_car (args);
2751 m->set_property ("symbol", symbol);
2753 if (val != SCM_UNDEFINED)
2754 m->set_property ("value", val);
2755 if (grob_val != SCM_UNDEFINED)
2756 m->set_property ("grob-value", grob_val);
2758 if (grob_sym != SCM_UNDEFINED)
2760 bool itc = do_internal_type_checking_global;
2763 bool autobeam = ly_is_equal (symbol, ly_symbol2scm ("autoBeamSettings"));
2765 do_internal_type_checking_global = false;
2766 m->set_property ("grob-property", grob_sym);
2768 do_internal_type_checking_global = itc;
2771 if (tag == ly_symbol2scm ("poppush"))
2772 m->set_property ("pop-first", SCM_BOOL_T);
2779 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2781 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2783 csm->set_property ("element", m->self_scm ());
2784 scm_gc_unprotect_object (m->self_scm ());
2786 csm->set_property ("context-type",
2787 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2788 csm->set_property ("property-operations", ops);
2790 if (scm_is_string (id))
2791 csm->set_property ("context-id", id);
2796 get_next_unique_context_id ()
2798 return scm_makfrom0str ("$uniqueContextId");
2803 get_next_unique_lyrics_context_id ()
2805 static int new_context_count;
2807 snprintf (s, 1024, "uniqueContext%d", new_context_count++);
2808 return scm_makfrom0str (s);