1 %{ // -*-Fundamental-*-
4 parser.yy -- Bison/C++ parser for LilyPond
6 source file of the GNU LilyPond music typesetter
8 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 Jan Nieuwenhuizen <janneke@gnu.org>
16 * The rules for who is protecting what are very shady. Uniformise
19 * There are too many lexical modes?
30 #include "context-def.hh"
31 #include "dimensions.hh"
33 #include "file-path.hh"
34 #include "input-smob.hh"
36 #include "lily-guile.hh"
37 #include "lilypond-input-version.hh"
38 #include "ly-module.hh"
41 #include "music-list.hh"
42 #include "music-sequence.hh"
43 #include "lily-lexer.hh"
44 #include "lily-parser.hh"
45 #include "paper-book.hh"
46 #include "output-def.hh"
47 #include "scm-hash.hh"
48 #include "scm-option.hh"
50 #include "text-item.hh"
53 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
55 Music *property_op_to_music (SCM op);
56 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops);
57 SCM get_next_unique_context ();
59 #define YYERROR_VERBOSE 1
61 #define YYPARSE_PARAM my_lily_parser
62 #define YYLEX_PARAM my_lily_parser
64 ((Lily_parser *) my_lily_parser)
66 #define yyerror THIS->parser_error
68 /* Add symbols to the TAGS field of a music object. */
71 tag_music (Music *m, SCM tag, Input ip)
73 SCM tags = m->get_property ("tags");
74 if (scm_is_symbol (tag))
75 tags = scm_cons (tag, tags);
76 else if (ly_c_list_p (tag))
77 tags = ly_append2 (tag, tags);
79 ip.warning (_ ("Tag must be symbol or list of symbols."));
81 m->set_property ("tags", tags);
85 is_regular_identifier (SCM id)
87 String str = ly_scm2string (id);
88 char const *s = str.to_str0 ();
97 v = v && isalnum (*s);
105 get_first_context_id (SCM type, Music *m)
107 SCM id = m->get_property ("context-id");
108 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
109 && scm_is_string (m->get_property ("context-id"))
110 && scm_c_string_length (id) > 0)
118 make_simple_markup (SCM encoding, SCM a)
120 SCM simple = ly_scheme_function ("simple-markup");
121 if (scm_is_symbol (encoding))
122 return scm_list_3 (ly_scheme_function ("encoded-simple-markup"),
124 return scm_list_2 (simple, a);
130 return t && t == 1 << intlog2 (t);
134 set_music_properties (Music *p, SCM a)
136 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
137 p->internal_set_property (scm_caar (k), scm_cdar (k));
141 make_chord_step (int step, int alter)
148 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
149 return m.smobbed_copy ();
154 make_chord (SCM pitch, SCM dur, SCM modification_list)
156 SCM chord_ctor = ly_scheme_function ("construct-chord");
157 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
158 scm_gc_protect_object (ch);
162 /* Todo: actually also use apply iso. call too ... */
164 ly_input_procedure_p (SCM x)
166 return ly_c_procedure_p (x)
167 || (scm_is_pair (x) && ly_c_procedure_p (scm_car (x)));
171 set_property_music (SCM sym, SCM value)
173 Music *p = MY_MAKE_MUSIC ("PropertySet");
174 p->set_property ("symbol", sym);
175 p->set_property ("value", value);
180 make_music_relative (Pitch start, Music *music)
182 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
183 relative->set_property ("element", music->self_scm ());
185 Pitch last = music->to_relative_octave (start);
186 if (lily_1_8_relative)
187 music->set_property ("last-pitch", last.smobbed_copy ());
192 make_lyric_combine_music (SCM name, Music *music)
194 Music *combine = MY_MAKE_MUSIC ("NewLyricCombineMusic");
195 combine->set_property ("element", music->self_scm ());
196 combine->set_property ("associated-context", name);
202 /* We use SCMs to do strings, because it saves us the trouble of
203 deleting them. Let's hope that a stack overflow doesnt trigger a move
204 of the parse stack onto the heap. */
210 Output_def *outputdef;
220 yylex (YYSTYPE *s, void *v)
222 Lily_parser *pars = (Lily_parser*) v;
223 Lily_lexer *lex = pars->lexer_;
225 lex->lexval = (void*) s;
226 lex->prepare_for_next_token ();
227 return lex->yylex ();
236 Three shift/reduce problems:
238 2. \markup identifier.
248 \repeat .. \alternative
251 \repeat { \repeat .. \alternative }
255 \repeat { \repeat } \alternative
271 %token CHORDMODIFIERS
274 %token DOUBLE_ANGLE_OPEN
275 %token DOUBLE_ANGLE_CLOSE
277 %token COMMANDSPANREQUEST
286 %token FIGURE_OPEN FIGURE_CLOSE
287 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
288 %token GROBDESCRIPTIONS
298 %token MULTI_MEASURE_REST
305 %token OVERRIDE SET REVERT
332 /* FIXME: this sucks. The user will get to see these names:
333 syntax error, unexpected E_CHAR:
338 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
339 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
341 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH
346 %token <i> E_UNSIGNED
347 %token <id> IDENTIFIER
348 %token <scm> CHORDMODIFIER_PITCH
349 %token <scm> DRUM_PITCH
350 %token <scm> DURATION_IDENTIFIER
351 %token <scm> EVENT_IDENTIFIER
352 %token <scm> MUSIC_IDENTIFIER CONTEXT_DEF_IDENTIFIER
353 %token <scm> NOTENAME_PITCH
354 %token <scm> NUMBER_IDENTIFIER
355 %token <scm> OUTPUT_DEF_IDENTIFIER
356 %token <scm> RESTNAME
357 %token <scm> LYRICS_STRING
359 %token <scm> SCORE_IDENTIFIER
361 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
362 %token <scm> TONICNAME_PITCH
363 %token <scm> CHORD_MODIFIER
364 %token <scm> FRACTION
366 %token <scm> MARKUP_HEAD_EMPTY
367 %token <scm> MARKUP_HEAD_MARKUP0
368 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
369 %token <scm> MARKUP_HEAD_SCM0
370 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
371 %token <scm> MARKUP_HEAD_SCM0_SCM1
372 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
373 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
374 %token <scm> MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
375 %token <scm> MUSIC_FUNCTION
376 %token <scm> MUSIC_FUNCTION_MUSIC
377 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
378 %token <scm> MUSIC_FUNCTION_SCM
379 %token <scm> MUSIC_FUNCTION_SCM_SCM
380 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
381 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
382 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
383 %token <scm> MUSIC_FUNCTION_MARKUP
384 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP
385 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC
386 %token <scm> MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC
387 %token <scm> MUSIC_FUNCTION_MARKUP_MARKUP_MUSIC
393 %type <book> book_block book_body
394 %type <i> bare_int bare_unsigned
395 %type <i> exclamations questions dots optional_rest
397 %type <i> sub_quotes sup_quotes
398 %type <i> tremolo_type
401 %type <music> Composite_music Simple_music Prefix_composite_music Generic_prefix_music
402 %type <music> Grouped_music_list
403 %type <music> Music Sequential_music Simultaneous_music
404 %type <music> Repeated_music
405 %type <music> command_req
406 %type <music> gen_text_def direction_less_event direction_reqd_event
407 %type <music> music_property_def context_change
408 %type <music> note_chord_element chord_body chord_body_element
409 %type <music> post_event tagged_post_event
410 %type <music> relative_music re_rhythmed_music
411 %type <music> simple_element event_chord command_element
412 %type <music> string_number_event
413 %type <music> toplevel_music
414 %type <music> tempo_event
416 %type <outputdef> output_def_body output_def_head
417 %type <outputdef> output_def paper_block
419 %type <scm> Music_list
420 %type <scm> chord_body_elements
421 %type <scm> chord_item chord_items chord_separator new_chord
422 %type <scm> context_def_spec_block context_def_spec_body
423 %type <scm> context_mod context_def_mod optional_context_mod
424 %type <scm> context_prop_spec
425 %type <scm> direction_less_char
426 %type <scm> duration_length fraction
427 %type <scm> embedded_scm scalar
428 %type <scm> identifier_init
429 %type <scm> lilypond_header lilypond_header_body
430 %type <scm> new_lyrics
431 %type <scm> post_events
432 %type <scm> property_operation
433 %type <scm> script_abbreviation
434 %type <scm> simple_string
435 %type <scm> steno_pitch pitch absolute_pitch pitch_also_in_chords
436 %type <scm> steno_tonic_pitch
437 %type <scm> step_number step_numbers
438 %type <scm> string bare_number number_expression number_term number_factor
439 %type <scm> bass_number br_bass_figure bass_figure figure_list figure_spec
440 %type <scm> context_mod_list
441 %type <scm> octave_check
442 %type <scm> steno_duration optional_notemode_duration multiplied_duration
443 %type <scm> Generic_prefix_music_scm
444 %type <scm> lyric_element
445 %type <scm> Alternative_music
446 %type <scm> markup markup_line markup_list markup_list_body full_markup
447 %type <scm> mode_changing_head
448 %type <scm> mode_changing_head_with_context
449 %type <scm> object_id_setting
451 %type <score> score_block score_body
456 /* We don't assign precedence to / and *, because we might need varied
457 prec levels in different prods */
463 lilypond: /* empty */
464 | lilypond toplevel_expression {
466 | lilypond assignment {
469 THIS->error_level_ = 1;
472 THIS->error_level_ = 1;
478 OBJECTID STRING { $$ = $2; }
483 THIS->lexer_->set_identifier (ly_symbol2scm ("$globalheader"), $1);
490 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
491 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
492 scm_gc_unprotect_object (book->self_scm ());
497 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
498 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
499 scm_gc_unprotect_object (score->self_scm ());
503 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
504 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
505 scm_gc_unprotect_object (music->self_scm ());
509 Output_def * od = $1;
511 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
512 id = ly_symbol2scm ("$defaultpaper");
513 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
514 id = ly_symbol2scm ("$defaultmidi");
515 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
516 id = ly_symbol2scm ("$defaultlayout");
518 THIS->lexer_->set_identifier (id, od->self_scm ());
519 scm_gc_unprotect_object (od->self_scm ());
534 lilypond_header_body:
536 $$ = ly_make_anonymous_module (safe_global_b);
537 THIS->lexer_->add_scope ($$);
539 | lilypond_header_body assignment {
545 HEADER '{' lilypond_header_body '}' {
546 $$ = THIS->lexer_->remove_scope ();
558 /* cont */ '=' identifier_init {
561 Should find generic way of associating input with objects.
563 Input ip = THIS->pop_spot ();
565 if (! is_regular_identifier ($1))
567 ip.warning (_ ("Identifier should have alphabetic characters only"));
570 THIS->lexer_->set_identifier ($1, $4);
573 TODO: devise standard for protection in parser.
575 The parser stack lives on the C-stack, which means that
576 all objects can be unprotected as soon as they're here.
586 $$ = $1->self_scm ();
587 scm_gc_unprotect_object ($$);
590 $$ = $1->self_scm ();
591 scm_gc_unprotect_object ($$);
593 | context_def_spec_block {
597 $$ = $1->self_scm ();
598 scm_gc_unprotect_object ($$);
601 $$ = $1->self_scm ();
602 scm_gc_unprotect_object ($$);
604 | number_expression {
617 $$ = scm_int2num ($1);
621 context_def_spec_block:
622 CONTEXT '{' context_def_spec_body '}'
628 context_def_spec_body:
630 $$ = Context_def::make_scm ();
631 unsmob_context_def ($$)->set_spot (THIS->here_input ());
633 | CONTEXT_DEF_IDENTIFIER {
635 unsmob_context_def ($$)->set_spot (THIS->here_input ());
637 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
638 Context_def*td = unsmob_context_def ($$);
640 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
641 SCM tag = scm_caar (p);
643 /* TODO: should make new tag "grob-definition" ? */
644 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
645 tag, scm_cons (scm_cdar (p), SCM_EOL)));
648 | context_def_spec_body context_mod {
649 unsmob_context_def ($$)->add_context_mod ($2);
659 /*cont*/ '{' book_body '}' {
666 * Use 'handlers' like for toplevel-* stuff?
667 * grok \layout and \midi? */
671 $$->set_spot (THIS->here_input ());
672 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
673 scm_gc_unprotect_object ($$->paper_->self_scm ());
674 $$->header_ = THIS->lexer_->lookup_identifier ("$globalheader");
676 | book_body paper_block {
678 scm_gc_unprotect_object ($2->self_scm ());
680 | book_body score_block {
682 $$->add_score (score);
684 | book_body lilypond_header {
691 | book_body object_id_setting {
692 $$->user_key_ = ly_scm2string ($2);
700 /*cont*/ '{' score_body '}' {
710 $$->set_spot (THIS->here_input ());
713 $$ = new Score ( *unsmob_score ($1));
714 $$->set_spot (THIS->here_input ());
716 | score_body object_id_setting {
717 $$->user_key_ = ly_scm2string ($2);
720 SCM m = $2->self_scm ();
721 scm_gc_unprotect_object (m);
722 $$->set_music (m, THIS->self_scm ());
724 | score_body lilypond_header {
727 | score_body output_def {
728 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
730 THIS->parser_error (_("\\paper cannot be in \\score. Use \\layout instead"));
737 scm_gc_unprotect_object ($2->self_scm ());
740 $$->error_found_ = true;
752 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
754 THIS->parser_error (_("Need \\paper for paper block."));
755 $$ = get_paper (THIS);
762 output_def_body '}' {
765 THIS->lexer_->remove_scope ();
766 THIS->lexer_->pop_state ();
772 $$ = get_paper (THIS);
773 $$->input_origin_ = THIS->here_input ();
774 THIS->lexer_->add_scope ($$->scope_);
777 Output_def *p = get_midi (THIS);
779 THIS->lexer_->add_scope (p->scope_);
782 Output_def *p = get_layout (THIS);
784 THIS->lexer_->add_scope (p->scope_);
791 output_def_head '{' {
793 $$->input_origin_.set_spot (THIS->here_input ());
794 THIS->lexer_->push_initial_state ();
796 | output_def_head '{' OUTPUT_DEF_IDENTIFIER {
797 scm_gc_unprotect_object ($1->self_scm ());
798 Output_def *o = unsmob_output_def ($3);
799 o->input_origin_.set_spot (THIS->here_input ());
801 THIS->lexer_->remove_scope ();
802 THIS->lexer_->add_scope (o->scope_);
803 THIS->lexer_->push_initial_state ();
805 | output_def_body assignment {
808 | output_def_body context_def_spec_block {
809 assign_context_def ($$, $2);
811 | output_def_body tempo_event {
813 junk this ? there already is tempo stuff in
816 int m = scm_to_int ($2->get_property ("metronome-count"));
817 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
818 set_tempo ($$, d->get_length (), m);
819 scm_gc_unprotect_object ($2->self_scm ());
821 | output_def_body error {
827 TEMPO steno_duration '=' bare_unsigned {
828 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
829 $$->set_property ("tempo-unit", $2);
830 $$->set_property ("metronome-count", scm_int2num ( $4));
835 The representation of a list is the
839 to have efficient append. */
843 $$ = scm_cons (SCM_EOL, SCM_EOL);
847 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
848 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
850 if (scm_is_pair (scm_cdr (s)))
851 scm_set_cdr_x (scm_cdr (s), c); /* append */
853 scm_set_car_x (s, c); /* set first cons */
854 scm_set_cdr_x (s, c); /* remember last cell */
856 | Music_list embedded_scm {
860 Music * m = MY_MAKE_MUSIC("Music");
862 m->set_property ("error-found", SCM_BOOL_T);
864 SCM c = scm_cons (m->self_scm (), SCM_EOL);
865 scm_gc_unprotect_object (m->self_scm ()); /* UGH */
867 if (scm_is_pair (scm_cdr (s)))
868 scm_set_cdr_x (scm_cdr (s), c); /* append */
870 scm_set_car_x (s, c); /* set first cons */
871 scm_set_cdr_x (s, c); /* remember last cell */
884 | ALTERNATIVE '{' Music_list '}' {
891 REPEAT simple_string bare_unsigned Music Alternative_music
895 SCM alts = scm_is_pair ($5) ? scm_car ($5) : SCM_EOL;
896 if (times < scm_ilength (alts)) {
897 unsmob_music (scm_car (alts))
898 ->origin ()->warning (
899 _ ("More alternatives than repeats. Junking excess alternatives."));
900 alts = ly_truncate_list (times, alts);
904 SCM proc = ly_scheme_function ("make-repeated-music");
906 SCM mus = scm_call_1 (proc, $2);
907 scm_gc_protect_object (mus); // UGH.
908 Music *r = unsmob_music (mus);
911 r-> set_property ("element", beg->self_scm ());
912 scm_gc_unprotect_object (beg->self_scm ());
914 r->set_property ("repeat-count", scm_int2num (times >? 1));
916 r-> set_property ("elements",alts);
917 if (ly_c_equal_p ($2, scm_makfrom0str ("tremolo"))) {
919 TODO: move this code to Scheme.
923 we can not get durations and other stuff correct down the line, so we have to
924 add to the duration log here.
926 SCM func = ly_scheme_function ("shift-duration-log");
928 int dots = ($3 % 3) ? 0 : 1;
929 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
931 Sequential_music *seq = dynamic_cast<Sequential_music*> ($4);
934 int list_len = scm_ilength (seq->music_list ());
936 seq->origin ()->warning ("Chord tremolo must have 2 elements.");
938 r->compress (Moment (Rational (1, list_len)));
940 scm_call_3 (func, r->self_scm (), scm_int2num (shift),scm_int2num (dots));
943 r->set_spot (*$4->origin ());
950 SEQUENTIAL '{' Music_list '}' {
951 $$ = MY_MAKE_MUSIC ("SequentialMusic");
952 $$->set_property ("elements", scm_car ($3));
953 $$->set_spot (THIS->here_input ());
955 | '{' Music_list '}' {
956 $$ = MY_MAKE_MUSIC ("SequentialMusic");
957 $$->set_property ("elements", scm_car ($2));
958 $$->set_spot (THIS->here_input ());
963 SIMULTANEOUS '{' Music_list '}'{
964 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
965 $$->set_property ("elements", scm_car ($3));
966 $$->set_spot (THIS->here_input ());
969 | simul_open Music_list simul_close {
970 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
971 $$->set_property ("elements", scm_car ($2));
972 $$->set_spot (THIS->here_input ());
977 event_chord { $$ = $1; }
979 $$ = unsmob_music ($1);
986 optional_context_mod:
987 /**/ { $$ = SCM_EOL; }
988 | WITH { THIS->lexer_->push_initial_state (); }
989 '{' context_mod_list '}'
991 THIS->lexer_->pop_state ();
997 /* */ { $$ = SCM_EOL; }
998 | context_mod_list context_mod {
999 $$ = scm_cons ($2, $1);
1005 Prefix_composite_music { $$ = $1; }
1006 | Grouped_music_list { $$ = $1; }
1010 Simultaneous_music { $$ = $1; }
1011 | Sequential_music { $$ = $1; }
1014 Generic_prefix_music_scm:
1016 $$ = scm_list_2 ($1, make_input (THIS->here_input ()));
1018 | MUSIC_FUNCTION_SCM {
1021 $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3);
1023 | MUSIC_FUNCTION_MARKUP {
1026 $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3);
1028 | MUSIC_FUNCTION_MUSIC {
1031 $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3->self_scm ());
1032 scm_gc_unprotect_object ($3->self_scm ());
1034 | MUSIC_FUNCTION_SCM_MUSIC {
1036 } embedded_scm Music {
1037 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4->self_scm ());
1038 scm_gc_unprotect_object ($4->self_scm ());
1040 | MUSIC_FUNCTION_SCM_SCM {
1042 } embedded_scm embedded_scm {
1043 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4);
1045 | MUSIC_FUNCTION_SCM_SCM_MUSIC {
1047 } embedded_scm embedded_scm Music {
1048 $$ = scm_list_5 ($1, make_input (THIS->pop_spot ()), $3, $4, $5->self_scm ());
1050 | MUSIC_FUNCTION_MARKUP_MUSIC {
1052 } full_markup Music {
1053 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4->self_scm ());
1054 scm_gc_unprotect_object ($4->self_scm ());
1056 | MUSIC_FUNCTION_MARKUP_MARKUP {
1058 } full_markup full_markup {
1059 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4);
1061 | MUSIC_FUNCTION_MUSIC_MUSIC {
1064 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3->self_scm (), $4->self_scm ());
1065 scm_gc_unprotect_object ($3->self_scm ());
1066 scm_gc_unprotect_object ($4->self_scm ());
1068 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC {
1070 } embedded_scm Music Music {
1071 $$ = scm_list_5 ($1, make_input (THIS->pop_spot ()),
1072 $3, $4->self_scm (), $5->self_scm ());
1073 scm_gc_unprotect_object ($5->self_scm ());
1074 scm_gc_unprotect_object ($4->self_scm ());
1076 | MUSIC_FUNCTION_MARKUP_MUSIC_MUSIC {
1078 } full_markup Music Music {
1079 $$ = scm_list_5 ($1, make_input (THIS->pop_spot ()),
1080 $3, $4->self_scm (), $5->self_scm ());
1081 scm_gc_unprotect_object ($5->self_scm ());
1082 scm_gc_unprotect_object ($4->self_scm ());
1086 Generic_prefix_music:
1087 Generic_prefix_music_scm {
1088 SCM func = scm_car ($1);
1089 Input *loc = unsmob_input (scm_cadr ($1));
1090 SCM args = scm_cddr ($1);
1091 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
1093 SCM type_check_proc = ly_scheme_function ("type-check-list");
1096 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr ($1), sig, args)))
1098 THIS->error_level_ = 1;
1104 m = scm_apply_0 (func, scm_cdr ($1));
1106 if (unsmob_music (m))
1108 $$ = unsmob_music (m);
1109 scm_gc_protect_object (m);
1114 loc->error (_ ("Music head function should return Music object."));
1115 $$ = MY_MAKE_MUSIC ("Music");
1117 $$->set_spot (*loc);
1122 Prefix_composite_music:
1123 Generic_prefix_music {
1126 | CONTEXT simple_string '=' simple_string optional_context_mod Music {
1127 $$ = context_spec_music ($2, $4, $6, $5);
1130 | CONTEXT simple_string optional_context_mod Music {
1131 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1133 | NEWCONTEXT simple_string optional_context_mod Music {
1134 $$ = context_spec_music ($2, get_next_unique_context (), $4,
1145 int n = scm_to_int (scm_car ($3)); int d = scm_to_int (scm_cdr ($3));
1148 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1149 $$->set_spot (THIS->pop_spot ());
1151 $$->set_property ("element", mp->self_scm ());
1152 scm_gc_unprotect_object (mp->self_scm ());
1153 $$->set_property ("numerator", scm_int2num (n));
1154 $$->set_property ("denominator", scm_int2num (d));
1155 $$->compress (Moment (Rational (n,d)));
1158 | Repeated_music { $$ = $1; }
1159 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1160 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1162 Pitch from = *unsmob_pitch ($2);
1163 Pitch to = *unsmob_pitch ($3);
1165 p->transpose (pitch_interval (from, to));
1166 $$->set_property ("element", p->self_scm ());
1167 scm_gc_unprotect_object (p->self_scm ());
1169 | mode_changing_head Grouped_music_list {
1170 if ($1 == ly_symbol2scm ("chords"))
1172 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1173 chm->set_property ("element", $2->self_scm ());
1175 scm_gc_unprotect_object ($2->self_scm ());
1181 THIS->lexer_->pop_state ();
1183 | mode_changing_head_with_context optional_context_mod Grouped_music_list {
1184 $$ = context_spec_music ($1, get_next_unique_context (),
1186 if ($1 == ly_symbol2scm ("ChordNames"))
1188 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1189 chm->set_property ("element", $$->self_scm ());
1190 scm_gc_unprotect_object ($$->self_scm ());
1193 THIS->lexer_->pop_state ();
1195 | relative_music { $$ = $1; }
1196 | re_rhythmed_music { $$ = $1; }
1197 | TAG embedded_scm Music {
1198 tag_music ($3, $2, THIS->here_input ());
1205 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1206 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1208 $$ = ly_symbol2scm ("notes");
1212 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1213 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1215 $$ = ly_symbol2scm ("drums");
1218 THIS->lexer_->push_figuredbass_state ();
1220 $$ = ly_symbol2scm ("figures");
1223 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1224 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1225 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1226 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1227 $$ = ly_symbol2scm ("chords");
1231 { THIS->lexer_->push_lyric_state ();
1232 $$ = ly_symbol2scm ("lyrics");
1236 mode_changing_head_with_context:
1238 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1239 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1241 $$ = ly_symbol2scm ("DrumStaff");
1244 THIS->lexer_->push_figuredbass_state ();
1246 $$ = ly_symbol2scm ("FiguredBass");
1249 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1250 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1251 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1252 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1253 $$ = ly_symbol2scm ("ChordNames");
1256 { THIS->lexer_->push_lyric_state ();
1257 $$ = ly_symbol2scm ("Lyrics");
1263 RELATIVE absolute_pitch Music {
1265 Pitch start = *unsmob_pitch ($2);
1266 $$ = make_music_relative (start, m);
1267 scm_gc_unprotect_object (m->self_scm ());
1269 | RELATIVE Composite_music {
1272 Pitch middle_c (0, 0, 0);
1273 $$ = make_music_relative (middle_c, m);
1274 scm_gc_unprotect_object (m->self_scm ());
1279 ADDLYRICS { THIS->lexer_->push_lyric_state (); }
1281 Grouped_music_list {
1282 /* Can also use Music at the expensive of two S/Rs similar to
1283 \repeat \alternative */
1284 THIS->lexer_->pop_state ();
1286 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1288 | new_lyrics ADDLYRICS {
1289 THIS->lexer_->push_lyric_state ();
1290 } Grouped_music_list {
1291 THIS->lexer_->pop_state ();
1292 $$ = scm_cons ($4->self_scm (), $1);
1297 Grouped_music_list new_lyrics {
1299 SCM name = get_first_context_id (scm_makfrom0str ("Voice"), voice);
1300 if (!scm_is_string (name))
1302 name = get_next_unique_context ();
1303 voice = context_spec_music (scm_makfrom0str ("Voice"),
1308 SCM context = scm_makfrom0str ("Lyrics");
1309 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1312 for (SCM s = $2; scm_is_pair (s); s = scm_cdr (s))
1314 Music *music = unsmob_music (scm_car (s));
1315 Music *com = make_lyric_combine_music (name, music);
1316 Music *csm = context_spec_music (context,
1317 get_next_unique_context (), com, SCM_EOL);
1318 lst = scm_cons (csm->self_scm (), lst);
1320 all->set_property ("elements", scm_cons (voice->self_scm (),
1323 scm_gc_unprotect_object (voice->self_scm ());
1326 THIS->lexer_->push_lyric_state ();
1327 } simple_string Music {
1328 THIS->lexer_->pop_state ();
1331 $$ = make_lyric_combine_music (name, music);
1332 scm_gc_unprotect_object (music->self_scm ());
1337 CHANGE STRING '=' STRING {
1338 Music*t= MY_MAKE_MUSIC ("ContextChange");
1339 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1340 t-> set_property ("change-to-id", $4);
1343 $$->set_spot (THIS->here_input ());
1349 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1350 scm_string_to_symbol ($1), $3);
1352 | UNSET simple_string {
1353 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1354 scm_string_to_symbol ($2));
1356 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1357 $$ = scm_list_4 (ly_symbol2scm ("push"),
1358 scm_string_to_symbol ($2), $3, $5);
1360 | REVERT simple_string embedded_scm {
1361 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1362 scm_string_to_symbol ($2), $3);
1367 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1368 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1370 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1371 | DENIES { $$ = ly_symbol2scm ("denies"); }
1373 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1374 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1375 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1376 | NAME { $$ = ly_symbol2scm ("context-name"); }
1380 property_operation { $$ = $1; }
1381 | context_def_mod STRING {
1382 $$ = scm_list_2 ($1, $2);
1388 if (!is_regular_identifier ($1))
1390 THIS->here_input ().error (_("Grob name should be alphanumeric"));
1393 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1394 scm_string_to_symbol ($1));
1396 | simple_string '.' simple_string {
1397 $$ = scm_list_2 (scm_string_to_symbol ($1),
1398 scm_string_to_symbol ($3));
1403 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1404 $$ = property_op_to_music (scm_list_4 (
1405 ly_symbol2scm ("poppush"),
1408 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1410 | REVERT context_prop_spec embedded_scm {
1411 $$ = property_op_to_music (scm_list_3 (
1412 ly_symbol2scm ("pop"),
1416 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1418 | SET context_prop_spec '=' scalar {
1419 $$ = property_op_to_music (scm_list_3 (
1420 ly_symbol2scm ("assign"),
1423 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1425 | UNSET context_prop_spec {
1426 $$ = property_op_to_music (scm_list_2 (
1427 ly_symbol2scm ("unset"),
1429 $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1431 | ONCE music_property_def {
1432 SCM e = $2->get_property ("element");
1433 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1444 | STRING_IDENTIFIER {
1447 | string '+' string {
1448 $$ = scm_string_append (scm_list_2 ($1, $3));
1452 simple_string: STRING {
1467 $$ = scm_int2num ($1);
1476 $$ = scm_int2num ($1);
1482 pre_events doesn't contain anything. It is a trick:
1484 Adding pre_events to the simple_element
1485 makes the choice between
1491 simple_element: STRING
1493 a single shift/reduction conflict.
1495 nevertheless, this is not very clean, and we should find a different
1505 pre_events simple_element post_events {
1506 SCM elts = $2-> get_property ("elements");
1508 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1510 $2->set_property ("elements", elts);
1514 | note_chord_element
1519 chord_body optional_notemode_duration post_events
1521 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1522 SCM es = $1->get_property ("elements");
1523 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1525 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1526 unsmob_music (scm_car (s))->set_property ("duration", dur);
1527 es = ly_append2 (es, postevs);
1529 $1-> set_property ("elements", es);
1540 simul_open: DOUBLE_ANGLE_OPEN
1543 simul_close: DOUBLE_ANGLE_CLOSE
1547 chord_open chord_body_elements chord_close
1549 $$ = MY_MAKE_MUSIC ("EventChord");
1550 $$->set_property ("elements",
1551 scm_reverse_x ($2, SCM_EOL));
1555 chord_body_elements:
1556 /* empty */ { $$ = SCM_EOL; }
1557 | chord_body_elements chord_body_element {
1558 $$ = scm_cons ($2->self_scm (), $1);
1559 scm_gc_unprotect_object ($2->self_scm ());
1564 pitch exclamations questions octave_check post_events
1571 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1572 n->set_property ("pitch", $1);
1574 n->set_property ("cautionary", SCM_BOOL_T);
1575 if (ex % 2 || q % 2)
1576 n->set_property ("force-accidental", SCM_BOOL_T);
1578 if (scm_is_pair (post)) {
1579 SCM arts = scm_reverse_x (post, SCM_EOL);
1580 n->set_property ("articulations", arts);
1582 if (scm_is_number (check))
1584 int q = scm_to_int (check);
1585 n->set_property ("absolute-octave", scm_int2num (q-1));
1591 | DRUM_PITCH post_events {
1592 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1593 n->set_property ("duration", $2);
1594 n->set_property ("drum-type", $1);
1595 n->set_spot (THIS->here_input ());
1597 if (scm_is_pair ($2)) {
1598 SCM arts = scm_reverse_x ($2, SCM_EOL);
1599 n->set_property ("articulations", arts);
1606 ADDQUOTE string Music {
1607 SCM adder = ly_scheme_function ("add-quotable");
1609 scm_call_2 (adder, $2, $3->self_scm ());
1610 scm_gc_unprotect_object ($3->self_scm ());
1616 $$ = MY_MAKE_MUSIC ("EventChord");
1617 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1618 scm_gc_unprotect_object ($1->self_scm ());
1620 $$-> set_spot (THIS->here_input ());
1621 $1-> set_spot (THIS->here_input ());
1623 | SKIP duration_length {
1624 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1625 skip->set_property ("duration", $2);
1629 | OCTAVE { THIS->push_spot (); }
1631 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1633 $$->set_spot (THIS->pop_spot ());
1634 $$->set_property ("pitch", $3);
1637 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1638 m->set_property ("span-direction", scm_int2num (START));
1639 m->set_spot (THIS->here_input ());
1641 $$ = MY_MAKE_MUSIC ("EventChord");
1642 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1643 scm_gc_unprotect_object (m->self_scm ());
1644 $$->set_spot (THIS->here_input ());
1647 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1648 m->set_property ("span-direction", scm_int2num (STOP));
1649 m->set_spot (THIS->here_input ());
1651 $$ = MY_MAKE_MUSIC ("EventChord");
1652 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1653 $$->set_spot (THIS->here_input ());
1654 scm_gc_unprotect_object (m->self_scm ());
1657 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1658 $$->set_spot (THIS->here_input ());
1661 SCM pipe =THIS->lexer_->lookup_identifier ("pipeSymbol");
1663 if (Music * m = unsmob_music (pipe))
1666 $$ = MY_MAKE_MUSIC ("BarCheck");
1668 $$->set_spot (THIS->here_input ());
1670 | TRANSPOSITION pitch {
1672 Pitch sounds_as_c = pitch_interval (*unsmob_pitch ($2), middle_c);
1673 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1674 sounds_as_c.smobbed_copy());
1675 $$->set_spot (THIS-> here_input ());
1676 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1680 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1682 Music *csm = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1684 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED, csm, SCM_EOL);
1685 $$->set_spot (THIS->here_input ());
1686 t->set_spot (THIS->here_input ());
1688 | PARTIAL duration_length {
1689 Moment m = - unsmob_duration ($2)->get_length ();
1690 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1691 p->set_spot (THIS->here_input ());
1692 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1694 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1699 SCM proc = ly_scheme_function ("make-clef-set");
1701 SCM result = scm_call_1 (proc, $2);
1702 scm_gc_protect_object (result);
1703 $$ = unsmob_music (result);
1706 SCM proc= ly_scheme_function ("make-time-signature-set");
1708 SCM result = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1709 scm_gc_protect_object (result);
1710 $$ = unsmob_music (result);
1713 SCM proc = ly_scheme_function ("make-mark-set");
1715 SCM result = scm_call_1 (proc, $2);
1716 scm_gc_protect_object (result);
1717 $$ = unsmob_music (result);
1723 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1726 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1733 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1736 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1738 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1739 if (scm_ilength ($3) > 0)
1741 key->set_property ("pitch-alist", $3);
1742 key->set_property ("tonic", Pitch (0,0,0).smobbed_copy ());
1743 key->transpose (* unsmob_pitch ($2));
1745 THIS->parser_error (_ ("Second argument must be pitch list."));
1756 | post_events post_event {
1757 $2->set_spot (THIS->here_input ());
1758 $$ = scm_cons ($2->self_scm (), $$);
1759 scm_gc_unprotect_object ($2->self_scm ());
1761 | post_events tagged_post_event {
1762 $2 -> set_spot (THIS->here_input ());
1763 $$ = scm_cons ($2->self_scm (), $$);
1764 scm_gc_unprotect_object ($2->self_scm ());
1770 '-' TAG embedded_scm post_event {
1771 tag_music ($4, $3, THIS->here_input ());
1777 direction_less_event {
1781 if (!THIS->lexer_->is_lyric_state ())
1782 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1783 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1786 if (!THIS->lexer_->is_lyric_state ())
1787 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1788 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1790 | script_dir direction_reqd_event {
1792 $2->set_property ("direction", scm_int2num ($1));
1795 | script_dir direction_less_event {
1797 $2->set_property ("direction", scm_int2num ($1));
1800 | string_number_event
1803 string_number_event:
1805 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1806 s->set_property ("string-number", scm_int2num ($1));
1807 s->set_spot (THIS->here_input ());
1812 direction_less_char:
1814 $$ = ly_symbol2scm ("bracketOpenSymbol");
1817 $$ = ly_symbol2scm ("bracketCloseSymbol");
1820 $$ = ly_symbol2scm ("tildeSymbol");
1823 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1826 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1829 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1832 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1835 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1838 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1841 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1845 direction_less_event:
1846 direction_less_char {
1847 SCM predefd = THIS->lexer_->lookup_identifier_symbol ($1);
1849 if (unsmob_music (predefd))
1851 m = unsmob_music (predefd)->clone ();
1855 m = MY_MAKE_MUSIC ("Music");
1857 m->set_spot (THIS->here_input ());
1860 | EVENT_IDENTIFIER {
1861 $$ = unsmob_music ($1);
1864 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1865 a->set_spot (THIS->here_input ());
1866 a->set_property ("tremolo-type", scm_int2num ($1));
1871 direction_reqd_event:
1875 | script_abbreviation {
1876 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1877 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1878 if (scm_is_string (s))
1879 a->set_property ("articulation-type", s);
1880 else THIS->parser_error (_ ("Expecting string as script definition"));
1886 /**/ { $$ = SCM_EOL; }
1887 | '=' { $$ = scm_int2num (0); }
1888 | '=' sub_quotes { $$ = scm_int2num ($2); }
1889 | '=' sup_quotes { $$ = scm_int2num ($2); }
1914 | NOTENAME_PITCH sup_quotes {
1915 Pitch p = *unsmob_pitch ($1);
1916 p = p.transposed (Pitch ($2,0,0));
1917 $$ = p.smobbed_copy ();
1919 | NOTENAME_PITCH sub_quotes {
1920 Pitch p =* unsmob_pitch ($1);
1921 p = p.transposed (Pitch (-$2,0,0));
1922 $$ = p.smobbed_copy ();
1934 | TONICNAME_PITCH sup_quotes {
1935 Pitch p = *unsmob_pitch ($1);
1936 p = p.transposed (Pitch ($2,0,0));
1937 $$ = p.smobbed_copy ();
1939 | TONICNAME_PITCH sub_quotes {
1940 Pitch p =* unsmob_pitch ($1);
1942 p = p.transposed (Pitch (-$2,0,0));
1943 $$ = p.smobbed_copy ();
1953 pitch_also_in_chords:
1960 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1961 t->set_property ("text", $1);
1962 t->set_spot (THIS->here_input ());
1966 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1967 t->set_property ("text",
1968 make_simple_markup (THIS->lexer_->encoding (), $1));
1969 t->set_spot (THIS->here_input ());
1974 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1975 t->set_property ("digit", scm_int2num ($1));
1976 t->set_spot (THIS->here_input ());
1981 script_abbreviation:
1983 $$ = scm_makfrom0str ("Hat");
1986 $$ = scm_makfrom0str ("Plus");
1989 $$ = scm_makfrom0str ("Dash");
1992 $$ = scm_makfrom0str ("Bar");
1995 $$ = scm_makfrom0str ("Larger");
1998 $$ = scm_makfrom0str ("Dot");
2001 $$ = scm_makfrom0str ("Underscore");
2008 | '-' { $$ = CENTER; }
2019 multiplied_duration {
2024 optional_notemode_duration:
2026 Duration dd = THIS->default_duration_;
2027 $$ = dd.smobbed_copy ();
2029 THIS->beam_check ($$);
2031 | multiplied_duration {
2033 THIS->default_duration_ = *unsmob_duration ($$);
2035 THIS->beam_check ($$);
2040 bare_unsigned dots {
2042 if (!is_duration ($1))
2043 THIS->parser_error (_f ("not a duration: %d", $1));
2047 $$ = Duration (len, $2).smobbed_copy ();
2049 | DURATION_IDENTIFIER dots {
2050 Duration *d = unsmob_duration ($1);
2051 Duration k (d->duration_log (), d->dot_count () + $2);
2057 multiplied_duration:
2061 | multiplied_duration '*' bare_unsigned {
2062 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2064 | multiplied_duration '*' FRACTION {
2065 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2067 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2072 FRACTION { $$ = $1; }
2073 | UNSIGNED '/' UNSIGNED {
2074 $$ = scm_cons (scm_int2num ($1), scm_int2num ($3));
2091 | ':' bare_unsigned {
2092 if (!is_duration ($2))
2093 THIS->parser_error (_f ("not a duration: %d", $2));
2100 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2101 $$ = scm_list_2 (ly_scheme_function ("number-markup"),
2105 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2106 $$ = scm_list_2 (ly_scheme_function ("number-markup"),
2109 | STRING { $$ = $1; }
2120 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2121 $$ = bfr->self_scm ();
2122 scm_gc_unprotect_object ($$);
2125 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2126 $$ = bfr->self_scm ();
2128 bfr->set_property ("figure", $1);
2130 scm_gc_unprotect_object ($$);
2132 | bass_figure bass_mod {
2133 Music *m = unsmob_music ($1);
2135 SCM salter = m->get_property ("alteration");
2136 int alter = scm_is_number (salter) ? scm_to_int (salter) : 0;
2137 m->set_property ("alteration",
2138 scm_int2num (alter + $2));
2140 m->set_property ("alteration", scm_int2num (0));
2148 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2153 | br_bass_figure ']' {
2155 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2163 | figure_list br_bass_figure {
2164 $$ = scm_cons ($2, $1);
2169 FIGURE_OPEN figure_list FIGURE_CLOSE {
2170 Music *m = MY_MAKE_MUSIC ("EventChord");
2171 $2 = scm_reverse_x ($2, SCM_EOL);
2172 m->set_property ("elements", $2);
2173 $$ = m->self_scm ();
2184 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2186 Input i = THIS->pop_spot ();
2187 if (!THIS->lexer_->is_note_state ())
2188 THIS->parser_error (_ ("Have to be in Note mode for notes"));
2192 n = MY_MAKE_MUSIC ("RestEvent");
2194 n = MY_MAKE_MUSIC ("NoteEvent");
2196 n->set_property ("pitch", $1);
2197 n->set_property ("duration", $5);
2199 if (scm_is_number ($4))
2201 int q = scm_to_int ($4);
2202 n->set_property ("absolute-octave", scm_int2num (q-1));
2206 n->set_property ("cautionary", SCM_BOOL_T);
2207 if ($2 % 2 || $3 % 2)
2208 n->set_property ("force-accidental", SCM_BOOL_T);
2210 Music *v = MY_MAKE_MUSIC ("EventChord");
2211 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2212 scm_gc_unprotect_object (n->self_scm ());
2218 | DRUM_PITCH optional_notemode_duration {
2219 Input i = THIS->pop_spot ();
2221 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2222 n->set_property ("duration", $2);
2223 n->set_property ("drum-type", $1);
2225 Music *v = MY_MAKE_MUSIC ("EventChord");
2226 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2227 scm_gc_unprotect_object (n->self_scm ());
2233 | figure_spec optional_notemode_duration {
2234 Music *m = unsmob_music ($1);
2235 Input i = THIS->pop_spot ();
2237 for (SCM s = m->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
2239 unsmob_music (scm_car (s))->set_property ("duration", $2);
2243 | RESTNAME optional_notemode_duration {
2245 Input i = THIS->pop_spot ();
2247 if (ly_scm2string ($1) == "s") {
2249 ev = MY_MAKE_MUSIC ("SkipEvent");
2252 ev = MY_MAKE_MUSIC ("RestEvent");
2255 ev->set_property ("duration", $2);
2257 Music *velt = MY_MAKE_MUSIC ("EventChord");
2258 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2261 scm_gc_unprotect_object (ev->self_scm ());
2265 | MULTI_MEASURE_REST optional_notemode_duration {
2268 SCM proc = ly_scheme_function ("make-multi-measure-rest");
2269 SCM mus = scm_call_2 (proc, $2,
2270 make_input (THIS->here_input ()));
2271 scm_gc_protect_object (mus);
2272 $$ = unsmob_music (mus);
2275 | lyric_element optional_notemode_duration {
2276 Input i = THIS->pop_spot ();
2277 if (!THIS->lexer_->is_lyric_state ())
2278 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
2280 Music *lreq = MY_MAKE_MUSIC ("LyricEvent");
2281 lreq->set_property ("text", $1);
2282 lreq->set_property ("duration",$2);
2284 Music *velt = MY_MAKE_MUSIC ("EventChord");
2285 velt->set_property ("elements", scm_list_1 (lreq->self_scm ()));
2292 if (!THIS->lexer_->is_chord_state ())
2293 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
2294 $$ = unsmob_music ($1);
2299 /* FIXME: lyric flavoured markup would be better */
2304 $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
2309 steno_tonic_pitch optional_notemode_duration {
2310 $$ = make_chord ($1, $2, SCM_EOL);
2312 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2313 SCM its = scm_reverse_x ($4, SCM_EOL);
2314 $$ = make_chord ($1, $2, scm_cons ($3, its));
2322 | chord_items chord_item {
2323 $$ = scm_cons ($2, $$);
2329 $$ = ly_symbol2scm ("chord-colon");
2332 $$ = ly_symbol2scm ("chord-caret");
2334 | CHORD_SLASH steno_tonic_pitch {
2335 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2337 | CHORD_BASS steno_tonic_pitch {
2338 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2347 $$ = scm_reverse_x ($1, SCM_EOL);
2355 step_number { $$ = scm_cons ($1, SCM_EOL); }
2356 | step_numbers '.' step_number {
2357 $$ = scm_cons ($3, $$);
2363 $$ = make_chord_step ($1, 0);
2365 | bare_unsigned '+' {
2366 $$ = make_chord_step ($1, SHARP);
2368 | bare_unsigned CHORD_MINUS {
2369 $$ = make_chord_step ($1, FLAT);
2376 TODO: should deprecate in favor of Scheme?
2380 number_expression '+' number_term {
2381 $$ = scm_sum ($1, $3);
2383 | number_expression '-' number_term {
2384 $$ = scm_difference ($1, $3);
2393 | number_factor '*' number_factor {
2394 $$ = scm_product ($1, $3);
2396 | number_factor '/' number_factor {
2397 $$ = scm_divide ($1, $3);
2402 '-' number_factor { /* %prec UNARY_MINUS */
2403 $$ = scm_difference ($2, SCM_UNDEFINED);
2411 $$ = scm_int2num ($1);
2416 | NUMBER_IDENTIFIER {
2419 | REAL NUMBER_IDENTIFIER {
2420 $$ = scm_make_real (scm_to_double ($1) *scm_to_double ($2));
2422 | UNSIGNED NUMBER_IDENTIFIER {
2423 $$ = scm_make_real ($1 *scm_to_double ($2));
2439 if (scm_integer_p ($1) == SCM_BOOL_T)
2441 int k = scm_to_int ($1);
2445 THIS->parser_error (_ ("need integer number arg"));
2456 | exclamations '!' { $$ ++; }
2461 | questions '?' { $$ ++; }
2471 { THIS->lexer_->push_markup_state (); }
2474 THIS->lexer_->pop_state ();
2480 This should be done more dynamically if possible.
2484 $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
2486 | MARKUP_HEAD_EMPTY {
2487 $$ = scm_list_1 ($1);
2489 | MARKUP_HEAD_MARKUP0 markup {
2490 $$ = scm_list_2 ($1, $2);
2492 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2493 $$ = scm_list_3 ($1, $2, $3);
2495 | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
2496 $$ = scm_list_3 ($1, $2, $3);
2501 | MARKUP_HEAD_LIST0 markup_list {
2502 $$ = scm_list_2 ($1,$2);
2504 | MARKUP_HEAD_SCM0 embedded_scm {
2505 $$ = scm_list_2 ($1, $2);
2507 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
2508 $$ = scm_list_4 ($1, $2, $3, $4);
2510 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2511 $$ = scm_list_4 ($1, $2, $3, $4);
2513 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2514 $$ = scm_list_3 ($1, $2, $3);
2516 | MARKUP_IDENTIFIER {
2519 | STRING_IDENTIFIER {
2523 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2524 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2525 } '{' score_body '}' {
2527 $$ = scm_list_2 (ly_scheme_function ("score-markup"), sc->self_scm ());
2528 scm_gc_unprotect_object (sc->self_scm ());
2529 THIS->lexer_->pop_state ();
2534 chord_open markup_list_body chord_close { $$ = scm_reverse_x ($2, SCM_EOL); }
2538 '{' markup_list_body '}' {
2539 SCM line = ly_scheme_function ("line-markup");
2541 $$ = scm_list_2 (line, scm_reverse_x ($2, SCM_EOL));
2546 /**/ { $$ = SCM_EOL; }
2547 | markup_list_body markup {
2548 $$ = scm_cons ($2, $1);
2556 Lily_parser::set_yydebug (bool )
2564 Lily_parser::do_yyparse ()
2566 yyparse ((void*)this);
2571 Should make this optional? It will also complain when you do
2575 which is entirely legitimate.
2577 Or we can scrap it. Barchecks should detect wrong durations, and
2578 skipTypesetting speeds it up a lot.
2582 Lily_parser::beam_check (SCM dur)
2584 Duration *d = unsmob_duration (dur);
2585 if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2587 Music *m = unsmob_music (last_beam_start_);
2588 m->origin ()->warning (_ ("Suspect duration found following this beam"));
2590 last_beam_start_ = SCM_EOL;
2598 It is a little strange to have this function in this file, but
2599 otherwise, we have to import music classes into the lexer.
2603 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2605 if (scm_is_string (sid)) {
2607 return STRING_IDENTIFIER;
2608 } else if (scm_is_number (sid)) {
2610 return NUMBER_IDENTIFIER;
2611 } else if (unsmob_context_def (sid)) {
2612 *destination = unsmob_context_def (sid)->clone_scm ();
2613 return CONTEXT_DEF_IDENTIFIER;
2614 } else if (unsmob_score (sid)) {
2615 Score *score = new Score (*unsmob_score (sid));
2616 *destination = score->self_scm ();
2617 return SCORE_IDENTIFIER;
2618 } else if (Music *mus = unsmob_music (sid)) {
2619 mus = mus->clone ();
2620 *destination = mus->self_scm ();
2621 unsmob_music (*destination)->
2622 set_property ("origin", make_input (last_input_));
2623 return dynamic_cast<Event*> (mus)
2624 ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2625 } else if (unsmob_duration (sid)) {
2626 *destination = unsmob_duration (sid)->smobbed_copy ();
2627 return DURATION_IDENTIFIER;
2628 } else if (unsmob_output_def (sid)) {
2629 Output_def *p = unsmob_output_def (sid);
2632 *destination = p->self_scm ();
2633 return OUTPUT_DEF_IDENTIFIER;
2634 } else if (Text_interface::markup_p (sid)) {
2636 return MARKUP_IDENTIFIER;
2643 property_op_to_music (SCM op)
2646 SCM tag = scm_car (op);
2647 SCM symbol = scm_cadr (op);
2648 SCM args = scm_cddr (op);
2649 SCM grob_val = SCM_UNDEFINED;
2650 SCM grob_sym = SCM_UNDEFINED;
2651 SCM val = SCM_UNDEFINED;
2653 if (tag == ly_symbol2scm ("assign"))
2655 m = MY_MAKE_MUSIC ("PropertySet");
2656 val = scm_car (args);
2658 else if (tag == ly_symbol2scm ("unset"))
2659 m = MY_MAKE_MUSIC ("PropertyUnset");
2660 else if (tag == ly_symbol2scm ("poppush")
2661 || tag == ly_symbol2scm ("push"))
2663 m = MY_MAKE_MUSIC ("OverrideProperty");
2664 grob_sym = scm_car (args);
2665 grob_val = scm_cadr (args);
2667 else if (tag == ly_symbol2scm ("pop")) {
2668 m = MY_MAKE_MUSIC ("RevertProperty");
2669 grob_sym = scm_car (args);
2672 m->set_property ("symbol", symbol);
2674 if (val != SCM_UNDEFINED)
2675 m->set_property ("value", val);
2676 if (grob_val != SCM_UNDEFINED)
2677 m->set_property ("grob-value", grob_val);
2679 if (grob_sym != SCM_UNDEFINED)
2681 bool itc = internal_type_checking_global_b;
2684 bool autobeam = ly_c_equal_p (symbol, ly_symbol2scm ("autoBeamSettings"));
2686 internal_type_checking_global_b = false;
2687 m->set_property ("grob-property", grob_sym);
2689 internal_type_checking_global_b = itc;
2692 if (tag == ly_symbol2scm ("poppush"))
2693 m->set_property ("pop-first", SCM_BOOL_T);
2700 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2702 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2704 csm->set_property ("element", m->self_scm ());
2705 scm_gc_unprotect_object (m->self_scm ());
2707 csm->set_property ("context-type",
2708 scm_is_symbol (type) ? type : scm_string_to_symbol (type));
2709 csm->set_property ("property-operations", ops);
2711 if (scm_is_string (id))
2712 csm->set_property ("context-id", id);
2717 FIXME: this should be postponed until the music hits \Score
2720 get_next_unique_context ()
2722 static int new_context_count;
2724 snprintf (s, 1024, "uniqueContext%d", new_context_count++);
2725 return scm_makfrom0str (s);