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?
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"
37 #include "ly-module.hh"
39 #include "midi-def.hh"
41 #include "music-list.hh"
42 #include "music-sequence.hh"
43 #include "my-lily-lexer.hh"
44 #include "my-lily-parser.hh"
45 #include "paper-book.hh"
46 #include "paper-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 ((My_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 (ly_c_symbol_p (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 get_paper (My_lily_parser *parser)
87 SCM id = parser->lexer_->lookup_identifier ("$defaultpaper");
88 Music_output_def *paper = unsmob_music_output_def (id);
89 return paper ? paper->clone () : new Paper_def;
93 is_regular_identifier (SCM id)
95 String str = ly_scm2string (id);
96 char const *s = str.to_str0 ();
105 v = v && isalnum (*s);
112 make_simple_markup (SCM encoding, SCM a)
114 SCM simple = ly_scheme_function ("simple-markup");
115 if (ly_c_symbol_p (encoding))
116 return scm_list_3 (ly_scheme_function ("encoded-simple-markup"),
118 return scm_list_2 (simple, a);
124 return t && t == 1 << intlog2 (t);
128 set_music_properties (Music *p, SCM a)
130 for (SCM k = a; ly_c_pair_p (k); k = ly_cdr (k))
131 p->internal_set_property (ly_caar (k), ly_cdar (k));
135 make_chord_step (int step, int alter)
142 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
143 return m.smobbed_copy ();
148 make_chord (SCM pitch, SCM dur, SCM modification_list)
150 SCM chord_ctor = ly_scheme_function ("construct-chord");
151 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
152 scm_gc_protect_object (ch);
156 /* Todo: actually also use apply iso. call too ... */
158 ly_input_procedure_p (SCM x)
160 return ly_c_procedure_p (x)
161 || (ly_c_pair_p (x) && ly_c_procedure_p (ly_car (x)));
165 set_property_music (SCM sym, SCM value)
167 Music *p = MY_MAKE_MUSIC ("PropertySet");
168 p->set_property ("symbol", sym);
169 p->set_property ("value", value);
174 make_music_relative (Pitch start, Music *music)
176 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
177 relative->set_property ("element", music->self_scm ());
179 Pitch last = music->to_relative_octave (start);
180 if (lily_1_8_relative)
181 music->set_property ("last-pitch", last.smobbed_copy ());
186 make_lyric_combine_music (SCM name, Music *music)
188 Music *combine = MY_MAKE_MUSIC ("NewLyricCombineMusic");
189 combine->set_property ("element", music->self_scm ());
190 combine->set_property ("associated-context", name);
196 /* We use SCMs to do strings, because it saves us the trouble of
197 deleting them. Let's hope that a stack overflow doesnt trigger a move
198 of the parse stack onto the heap. */
203 Music_output_def *outputdef;
213 yylex (YYSTYPE *s, void *v)
215 My_lily_parser *pars = (My_lily_parser*) v;
216 My_lily_lexer *lex = pars->lexer_;
218 lex->lexval = (void*) s;
219 lex->prepare_for_next_token ();
220 return lex->yylex ();
229 Three shift/reduce problems:
231 2. \markup identifier.
236 \repeat .. \alternative
239 \repeat { \repeat .. \alternative }
243 \repeat { \repeat } \alternative
265 %token CHORDMODIFIERS
270 %token COMMANDSPANREQUEST
279 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
280 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
284 %token GROBDESCRIPTIONS
293 %token MULTI_MEASURE_REST
299 %token OVERRIDE SET REVERT
326 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
327 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
329 %token <i> E_UNSIGNED
330 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH
333 %type <book> book_block book_body
334 %type <i> exclamations questions dots optional_rest
336 %type <scm> grace_head
337 %type <scm> oct_check
338 %type <scm> context_mod_list
339 %type <scm> lyric_element
340 %type <scm> bass_number br_bass_figure bass_figure figure_list figure_spec
342 %token <scm> NOTENAME_PITCH
343 %token <scm> TONICNAME_PITCH
344 %token <scm> CHORDMODIFIER_PITCH
345 %token <scm> DURATION_IDENTIFIER
346 %token <scm> FRACTION
347 %token <id> IDENTIFIER
349 %token <scm> DRUM_PITCH
350 %token <scm> CHORD_MODIFIER
351 %token <scm> SCORE_IDENTIFIER
352 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
353 %token <scm> NUMBER_IDENTIFIER
354 %token <scm> EVENT_IDENTIFIER
355 %token <scm> MUSIC_IDENTIFIER CONTEXT_DEF_IDENTIFIER
356 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
357 %token <scm> RESTNAME
364 %token <scm> MARKUP_HEAD_MARKUP0
365 %token <scm> MARKUP_HEAD_EMPTY
366 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
367 %token <scm> MARKUP_HEAD_SCM0
368 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
369 %token <scm> MARKUP_HEAD_SCM0_SCM1
370 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
371 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
373 %token <scm> MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
374 %type <scm> markup markup_line markup_list markup_list_body full_markup
376 %type <outputdef> output_def
377 %type <scm> lilypond_header lilypond_header_body
378 %type <music> open_event close_event
379 %type <i> sub_quotes sup_quotes
380 %type <music> toplevel_music
381 %type <music> simple_element event_chord command_element
382 %type <music> Composite_music Simple_music
383 %type <music> Repeated_music
384 %type <scm> Alternative_music
385 //%type <scm> Composite_music_list
386 %type <i> tremolo_type
387 %type <i> bare_int bare_unsigned
389 %type <scm> identifier_init
390 %type <scm> simple_string
392 %type <music> note_chord_element chord_body chord_body_element
393 %type <scm> chord_body_elements
394 %type <scm> steno_duration optional_notemode_duration multiplied_duration
396 %type <scm> post_events
397 %type <music> gen_text_def direction_less_event direction_reqd_event
398 %type <scm> steno_pitch pitch absolute_pitch pitch_also_in_chords
399 %type <scm> steno_tonic_pitch
400 %type <scm> duration_length fraction
402 %type <scm> new_chord step_number chord_items chord_item chord_separator step_numbers
404 %type <scm> embedded_scm scalar
405 %type <music> Music Sequential_music Simultaneous_music
406 %type <music> relative_music re_rhythmed_music
407 %type <music> music_property_def context_change
408 %type <scm> context_prop_spec
409 %type <scm> Music_list
410 %type <scm> property_operation context_mod context_def_mod optional_context_mod
411 %type <outputdef> music_output_def_body music_output_def_head
412 %type <music> post_event tagged_post_event
413 %type <music> command_req
414 %type <music> string_number_event
415 %type <scm> string bare_number number_expression number_term number_factor
416 %type <score> score_block score_body
418 %type <scm> context_def_spec_block context_def_spec_body
419 %type <music> tempo_event
420 %type <scm> script_abbreviation
426 /* We don't assign precedence to / and *, because we might need varied
427 prec levels in different prods */
433 lilypond: /* empty */
435 | lilypond toplevel_expression {
437 | lilypond assignment {
440 THIS->error_level_ = 1;
443 THIS->error_level_ = 1;
451 | toplevel_music EOI {
452 Music_output_def *paper = get_paper (THIS);
455 // SCM proc = paper->get_scmvar ("toplevel-music-handler");
456 SCM proc = ly_scheme_function ("ly:parser-add-book-and-score");
457 //SCM proc = ly_scheme_function ("toplevel-music-handler");
458 scm_call_2 (proc, THIS->self_scm (), $1->self_scm ());
459 scm_gc_unprotect_object (paper->self_scm ());
466 SCM header = THIS->header_;
467 Path outname = split_path (THIS->output_basename_);
468 int *c = &THIS->book_count_;
470 outname.base += "-" + to_string (*c);
472 Music_output_def *paper = get_paper (THIS);
473 book->process (outname.to_string (), paper, header);
474 scm_gc_unprotect_object (book->self_scm ());
475 scm_gc_unprotect_object (paper->self_scm ());
478 /* TODO: implicit book, depending on --no-book/--no-page-layout
481 SCM head = is_module (score->header_) ? score->header_
482 : THIS->header_.to_SCM ();
484 Path p = split_path (THIS->output_basename_);
485 int *c = &THIS->score_count_;
487 p.base += "-" + to_string (*c);
490 SCM outname = scm_makfrom0str (p.to_string ().to_str0());
492 for (int i = 0; i < score->defs_.size (); i++)
493 default_rendering (score->music_,
494 score->defs_[i]->self_scm (), head,
497 if (score->defs_.is_empty ())
499 Music_output_def *paper = get_paper (THIS);
500 default_rendering (score->music_, paper->self_scm (), head,
502 scm_gc_unprotect_object (paper->self_scm ());
504 scm_gc_unprotect_object (score->self_scm ());
508 if (dynamic_cast<Paper_def*> ($1))
509 id = scm_makfrom0str ("$defaultpaper");
510 else if (dynamic_cast<Midi_def*> ($1))
511 id = scm_makfrom0str ("$defaultmidi");
512 THIS->lexer_->set_identifier (id, $1->self_scm ());
513 scm_gc_unprotect_object ($1->self_scm ());
528 lilypond_header_body:
530 $$ = ly_make_anonymous_module ();
531 THIS->lexer_->add_scope ($$);
533 | lilypond_header_body assignment {
539 HEADER '{' lilypond_header_body '}' {
540 $$ = THIS->lexer_->remove_scope ();
552 /* cont */ '=' identifier_init {
555 Should find generic way of associating input with objects.
557 Input ip = THIS->pop_spot ();
559 if (! is_regular_identifier ($1))
561 ip.warning (_ ("Identifier should have alphabetic characters only"));
564 THIS->lexer_->set_identifier ($1, $4);
567 TODO: devise standard for protection in parser.
569 The parser stack lives on the C-stack, which means that
570 all objects can be unprotected as soon as they're here.
580 $$ = $1->self_scm ();
581 scm_gc_unprotect_object ($$);
587 $$ = $1->self_scm ();
588 scm_gc_unprotect_object ($$);
590 | context_def_spec_block {
594 $$ = $1->self_scm ();
595 scm_gc_unprotect_object ($$);
598 $$ = $1->self_scm ();
599 scm_gc_unprotect_object ($$);
601 | number_expression {
612 context_def_spec_block:
613 CONTEXT '{' context_def_spec_body '}'
619 context_def_spec_body:
621 $$ = Context_def::make_scm ();
622 unsmob_context_def ($$)->set_spot (THIS->here_input ());
624 | CONTEXT_DEF_IDENTIFIER {
626 unsmob_context_def ($$)->set_spot (THIS->here_input ());
628 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
629 Context_def*td = unsmob_context_def ($$);
631 for (SCM p = $3; ly_c_pair_p (p); p = ly_cdr (p)) {
632 SCM tag = ly_caar (p);
634 /* TODO: should make new tag "grob-definition" ? */
635 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
636 tag, scm_cons (ly_cdar (p), SCM_EOL)));
639 | context_def_spec_body context_mod {
640 unsmob_context_def ($$)->add_context_mod ($2);
648 /*cont*/ '{' book_body '}' {
657 $$->set_spot (THIS->here_input ());
659 | book_body score_block {
660 $$->scores_.push ($2);
661 scm_gc_unprotect_object ($2->self_scm ());
671 /*cont*/ '{' score_body '}' {
681 $$->set_spot (THIS->here_input ());
682 SCM m = $1->self_scm ();
683 scm_gc_unprotect_object (m);
688 SCM check_funcs = ly_scheme_function ("toplevel-music-functions");
689 for (; ly_c_pair_p (check_funcs); check_funcs = ly_cdr (check_funcs))
690 m = scm_call_1 (ly_car (check_funcs), m);
695 $$ = new Score ( *unsmob_score ($1));
696 $$->set_spot (THIS->here_input ());
698 | score_body lilypond_header {
701 | score_body output_def {
703 scm_gc_unprotect_object ($2->self_scm ());
715 music_output_def_body '}' {
717 THIS->lexer_->remove_scope ();
718 THIS->lexer_->pop_state ();
722 music_output_def_head:
724 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
729 p = dynamic_cast<Midi_def*> (id->clone ());
734 THIS->lexer_->add_scope (p->scope_);
737 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
740 p = dynamic_cast<Paper_def*> (id->clone ());
744 THIS->lexer_->add_scope (p->scope_);
750 music_output_def_body:
751 music_output_def_head '{' {
753 $$->input_origin_. set_spot (THIS->here_input ());
754 THIS->lexer_->push_initial_state ();
756 | music_output_def_head '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
757 scm_gc_unprotect_object ($1->self_scm ());
758 Music_output_def *o = unsmob_music_output_def ($3);
759 o->input_origin_.set_spot (THIS->here_input ());
761 THIS->lexer_->remove_scope ();
762 THIS->lexer_->add_scope (o->scope_);
763 THIS->lexer_->push_initial_state ();
765 | music_output_def_body assignment {
768 | music_output_def_body context_def_spec_block {
769 $$->assign_context_def ($2);
771 | music_output_def_body tempo_event {
773 junk this ? there already is tempo stuff in
776 int m = ly_scm2int ( $2->get_property ("metronome-count"));
777 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
778 Midi_def *md = dynamic_cast<Midi_def*> ($$);
780 md->set_tempo (d->get_length (), m);
781 scm_gc_unprotect_object ($2->self_scm ());
783 | music_output_def_body error {
789 TEMPO steno_duration '=' bare_unsigned {
790 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
791 $$->set_property ("tempo-unit", $2);
792 $$->set_property ("metronome-count", scm_int2num ( $4));
797 The representation of a list is the
801 to have efficient append.
805 $$ = scm_cons (SCM_EOL, SCM_EOL);
809 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
810 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
811 if (ly_c_pair_p (ly_cdr (s)))
812 scm_set_cdr_x (ly_cdr (s), c); /* append */
814 scm_set_car_x (s, c); /* set first cons */
815 scm_set_cdr_x (s, c); /* remember last cell */
831 | ALTERNATIVE '{' Music_list '}' {
837 Composite_music_list: {};
838 Too many s/r r/r problems
840 $$ = scm_cons ($1, SCM_EOL);
842 | '{' Music_list '}' {
849 REPEAT string bare_unsigned Music Alternative_music
853 SCM alts = ly_c_pair_p ($5) ? ly_car ($5) : SCM_EOL;
854 if (times < scm_ilength (alts)) {
855 unsmob_music (ly_car (alts))
856 ->origin ()->warning (
857 _ ("More alternatives than repeats. Junking excess alternatives."));
858 alts = ly_truncate_list (times, alts);
862 SCM proc = ly_scheme_function ("make-repeated-music");
864 SCM mus = scm_call_1 (proc, $2);
865 scm_gc_protect_object (mus); // UGH.
866 Music *r = unsmob_music (mus);
869 r-> set_property ("element", beg->self_scm ());
870 scm_gc_unprotect_object (beg->self_scm ());
872 r->set_property ("repeat-count", scm_int2num (times >? 1));
874 r-> set_property ("elements",alts);
875 if (ly_c_equal_p ($2, scm_makfrom0str ("tremolo"))) {
877 TODO: move this code to Scheme.
881 we can not get durations and other stuff correct down the line, so we have to
882 add to the duration log here.
884 SCM func = ly_scheme_function ("shift-duration-log");
886 int dots = ($3 % 3) ? 0 : 1;
887 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
889 Sequential_music *seq = dynamic_cast<Sequential_music*> ($4);
892 int list_len = scm_ilength (seq->music_list ());
894 seq->origin ()->warning ("Chord tremolo must have 2 elements.");
896 r->compress (Moment (Rational (1, list_len)));
898 scm_call_3 (func, r->self_scm (), scm_int2num (shift),scm_int2num (dots));
901 r->set_spot (*$4->origin ());
908 SEQUENTIAL '{' Music_list '}' {
909 $$ = MY_MAKE_MUSIC ("SequentialMusic");
910 $$->set_property ("elements", ly_car ($3));
911 $$->set_spot (THIS->here_input ());
913 | '{' Music_list '}' {
914 $$ = MY_MAKE_MUSIC ("SequentialMusic");
915 $$->set_property ("elements", ly_car ($2));
916 $$->set_spot (THIS->here_input ());
921 SIMULTANEOUS '{' Music_list '}'{
922 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
923 $$->set_property ("elements", ly_car ($3));
924 $$->set_spot (THIS->here_input ());
927 | simul_open Music_list simul_close {
928 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
929 $$->set_property ("elements", ly_car ($2));
930 $$->set_spot (THIS->here_input ());
935 event_chord { $$ = $1; }
936 | APPLYOUTPUT embedded_scm {
937 if (!ly_input_procedure_p ($2))
938 THIS->parser_error (_ ("\\applycontext takes function argument"));
939 $$ = MY_MAKE_MUSIC ("ApplyOutputEvent");
940 $$->set_property ("procedure", $2);
941 $$->set_spot (THIS->here_input ());
943 | APPLYCONTEXT embedded_scm {
944 if (!ly_input_procedure_p ($2))
945 THIS->parser_error (_ ("\\applycontext takes function argument"));
946 $$ = MY_MAKE_MUSIC ("ApplyContext");
947 $$->set_property ("procedure", $2);
948 $$->set_spot (THIS->here_input ());
951 $$ = unsmob_music ($1);
958 optional_context_mod:
959 /**/ { $$ = SCM_EOL; }
960 | WITH '{' context_mod_list '}' { $$ = $3; }
964 GRACE { $$ = scm_makfrom0str ("Grace"); }
965 | ACCIACCATURA { $$ = scm_makfrom0str ("Acciaccatura"); }
966 | APPOGGIATURA { $$ = scm_makfrom0str ("Appoggiatura"); }
970 /* */ { $$ = SCM_EOL; }
971 | context_mod_list context_mod {
972 $$ = scm_cons ($2, $1);
978 SCM proc = ly_scheme_function ("make-autochange-music");
980 SCM res = scm_call_1 (proc, $2->self_scm ());
981 scm_gc_unprotect_object ($2->self_scm ());
982 $$ = unsmob_music (res);
983 scm_gc_protect_object (res);
984 $$->set_spot (THIS->here_input ());
986 | PARTCOMBINE Music Music {
987 SCM proc = ly_scheme_function ("make-part-combine-music");
989 SCM res = scm_call_1 (proc, scm_listify ($2->self_scm (),
990 $3->self_scm (), SCM_UNDEFINED));
991 scm_gc_unprotect_object ($3->self_scm ());
992 scm_gc_unprotect_object ($2->self_scm ());
993 $$ = unsmob_music (res);
994 scm_gc_protect_object (res);
995 $$->set_spot (THIS->here_input ());
1000 The other version is for easier debugging of
1001 Sequential_music_iterator in combination with grace notes.
1006 TODO: should distinguish between both grace types in the
1007 basic music objects too, since the meaning is different.
1011 String start_str = "start" + ly_scm2string ($1) + "Music";
1012 String stop_str = "stop" + ly_scm2string ($1) + "Music";
1014 SCM start = THIS->lexer_->lookup_identifier (start_str);
1015 SCM stop = THIS->lexer_->lookup_identifier (stop_str);
1017 Music *startm = unsmob_music (start);
1018 Music *stopm = unsmob_music (stop);
1022 stopm = stopm->clone ();
1023 ms = scm_cons (stopm->self_scm (), ms);
1024 scm_gc_unprotect_object (stopm->self_scm ());
1026 ms = scm_cons ($2->self_scm (), ms);
1027 scm_gc_unprotect_object ($2->self_scm ());
1029 startm = startm->clone ();
1030 ms = scm_cons (startm->self_scm (), ms);
1031 scm_gc_unprotect_object (startm->self_scm ());
1034 Music* seq = MY_MAKE_MUSIC ("SequentialMusic");
1035 seq->set_property ("elements", ms);
1038 $$ = MY_MAKE_MUSIC ("GraceMusic");
1039 $$->set_property ("element", seq->self_scm ());
1040 scm_gc_unprotect_object (seq->self_scm ());
1042 $$ = MY_MAKE_MUSIC ("GraceMusic");
1043 $$->set_property ("element", $2->self_scm ());
1044 scm_gc_unprotect_object ($2->self_scm ());
1047 | CONTEXT string '=' string optional_context_mod Music {
1048 $$ = context_spec_music ($2, $4, $6, $5);
1051 | CONTEXT simple_string optional_context_mod Music {
1052 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1054 | NEWCONTEXT string optional_context_mod Music {
1055 $$ = context_spec_music ($2, get_next_unique_context (),
1066 int n = ly_scm2int (ly_car ($3)); int d = ly_scm2int (ly_cdr ($3));
1069 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1070 $$->set_spot (THIS->pop_spot ());
1072 $$->set_property ("element", mp->self_scm ());
1073 scm_gc_unprotect_object (mp->self_scm ());
1074 $$->set_property ("numerator", scm_int2num (n));
1075 $$->set_property ("denominator", scm_int2num (d));
1076 $$->compress (Moment (Rational (n,d)));
1079 | Repeated_music { $$ = $1; }
1080 | Simultaneous_music { $$ = $1; }
1081 | Sequential_music { $$ = $1; }
1082 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1083 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1085 Pitch from = *unsmob_pitch ($2);
1086 Pitch to = *unsmob_pitch ($3);
1088 p->transpose (interval (from, to));
1089 $$->set_property ("element", p->self_scm ());
1090 scm_gc_unprotect_object (p->self_scm ());
1092 | APPLY embedded_scm Music {
1093 if (!ly_input_procedure_p ($2))
1095 THIS->parser_error (_ ("\\apply takes function argument"));
1100 SCM ret = scm_call_1 ($2, $3->self_scm ());
1101 Music *m = unsmob_music (ret);
1103 THIS->parser_error ("\\apply must return a Music");
1104 m = MY_MAKE_MUSIC ("Music");
1111 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1112 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1116 THIS->lexer_->pop_state ();
1120 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1121 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1125 THIS->lexer_->pop_state ();
1128 { THIS->lexer_->push_figuredbass_state (); }
1131 Music *chm = MY_MAKE_MUSIC ("UntransposableMusic");
1132 chm->set_property ("element", $3->self_scm ());
1134 scm_gc_unprotect_object ($3->self_scm ());
1136 THIS->lexer_->pop_state ();
1139 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1140 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1141 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1142 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1145 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1146 chm->set_property ("element", $3->self_scm ());
1147 scm_gc_unprotect_object ($3->self_scm ());
1150 THIS->lexer_->pop_state ();
1153 { THIS->lexer_->push_lyric_state (); }
1157 THIS->lexer_->pop_state ();
1159 | relative_music { $$ = $1; }
1160 | re_rhythmed_music { $$ = $1; }
1161 | TAG embedded_scm Music {
1162 tag_music ($3, $2, THIS->here_input ());
1168 RELATIVE absolute_pitch Music {
1170 Pitch start = *unsmob_pitch ($2);
1171 $$ = make_music_relative (start, m);
1172 scm_gc_unprotect_object (m->self_scm ());
1174 | RELATIVE Composite_music {
1176 /* FIXME: why is octave==0 and default not middleC? */
1177 Pitch middle_c (-1, 0, 0);
1178 $$ = make_music_relative (middle_c, m);
1179 scm_gc_unprotect_object (m->self_scm ());
1184 ADDLYRICS Music Music {
1185 Music *m = MY_MAKE_MUSIC ("LyricCombineMusic");
1186 m->set_property ("elements", scm_listify ($2->self_scm (),
1187 $3->self_scm (), SCM_UNDEFINED));
1188 scm_gc_unprotect_object ($3->self_scm ());
1189 scm_gc_unprotect_object ($2->self_scm ());
1193 /* Too many s/r r/r problems
1196 NEWLYRICS { THIS->lexer_->push_lyric_state (); }
1198 /* Too many s/r r/r problems
1199 Composite_music_list
1202 THIS->lexer_->pop_state ();
1205 SCM name = scm_makfrom0str ("");
1206 Music *combined = make_lyric_combine_music (name, music);
1207 SCM context = scm_makfrom0str ("Lyrics");
1208 $$ = context_spec_music (context, SCM_UNDEFINED, combined,
1210 scm_gc_unprotect_object (music->self_scm ());
1212 | LYRICSTO string Music {
1215 $$ = make_lyric_combine_music (name, music);
1216 scm_gc_unprotect_object (music->self_scm ());
1221 CHANGE STRING '=' STRING {
1222 Music*t= MY_MAKE_MUSIC ("ContextChange");
1223 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1224 t-> set_property ("change-to-id", $4);
1227 $$->set_spot (THIS->here_input ());
1231 simple_string: STRING {
1239 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1240 scm_string_to_symbol ($1), $3);
1242 | UNSET simple_string {
1243 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1244 scm_string_to_symbol ($2));
1246 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1247 $$ = scm_list_4 (ly_symbol2scm ("push"),
1248 scm_string_to_symbol ($2), $3, $5);
1250 | REVERT simple_string embedded_scm {
1251 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1252 scm_string_to_symbol ($2), $3);
1257 CONSISTSEND { $$ = ly_symbol2scm ("consists-end"); }
1258 | CONSISTS { $$ = ly_symbol2scm ("consists"); }
1259 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1261 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1262 | DENIES { $$ = ly_symbol2scm ("denies"); }
1264 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1265 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1266 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1267 | NAME { $$ = ly_symbol2scm ("context-name"); }
1271 property_operation { $$ = $1; }
1272 | context_def_mod STRING {
1273 $$ = scm_list_2 ($1, $2);
1279 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1280 scm_string_to_symbol ($1));
1282 | simple_string '.' simple_string {
1283 $$ = scm_list_2 (scm_string_to_symbol ($1),
1284 scm_string_to_symbol ($3));
1289 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1290 $$ = property_op_to_music (scm_list_4 (
1291 ly_symbol2scm ("poppush"),
1294 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1296 | REVERT context_prop_spec embedded_scm {
1297 $$ = property_op_to_music (scm_list_3 (
1298 ly_symbol2scm ("pop"),
1302 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1304 | SET context_prop_spec '=' scalar {
1305 $$ = property_op_to_music (scm_list_3 (
1306 ly_symbol2scm ("assign"),
1309 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1311 | UNSET context_prop_spec {
1312 $$ = property_op_to_music (scm_list_2 (
1313 ly_symbol2scm ("unset"),
1315 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1317 | ONCE music_property_def {
1318 SCM e = $2->get_property ("element");
1319 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1329 | bare_int { $$ = scm_int2num ($1); }
1330 | embedded_scm { $$ = $1; }
1331 | full_markup { $$ = $1; }
1332 | DIGIT { $$ = scm_int2num ($1); }
1338 Adding pre_events to the simple_element
1339 makes the choice between
1345 simple_element: STRING
1347 a single shift/reduction conflict.
1349 nevertheless, this is not very clean, and we should find a different
1359 pre_events simple_element post_events {
1360 SCM elts = $2-> get_property ("elements");
1362 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1364 $2->set_property ("elements", elts);
1368 | note_chord_element
1373 chord_body optional_notemode_duration post_events
1375 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1376 SCM es = $1->get_property ("elements");
1377 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1379 for (SCM s = es; ly_c_pair_p (s); s = ly_cdr (s))
1380 unsmob_music (ly_car (s))->set_property ("duration", dur);
1381 es = ly_append2 (es, postevs);
1383 $1-> set_property ("elements", es);
1394 simul_open: LESSLESS
1397 simul_close: MOREMORE
1401 chord_open chord_body_elements chord_close
1403 $$ = MY_MAKE_MUSIC ("EventChord");
1404 $$->set_property ("elements",
1405 scm_reverse_x ($2, SCM_EOL));
1409 chord_body_elements:
1410 /* empty */ { $$ = SCM_EOL; }
1411 | chord_body_elements chord_body_element {
1412 $$ = scm_cons ($2->self_scm (), $1);
1413 scm_gc_unprotect_object ($2->self_scm ());
1418 pitch exclamations questions post_events
1420 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1421 n->set_property ("pitch", $1);
1423 n->set_property ("cautionary", SCM_BOOL_T);
1424 if ($2 % 2 || $3 % 2)
1425 n->set_property ("force-accidental", SCM_BOOL_T);
1427 if (ly_c_pair_p ($4)) {
1428 SCM arts = scm_reverse_x ($4, SCM_EOL);
1429 n->set_property ("articulations", arts);
1433 | DRUM_PITCH post_events {
1434 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1435 n->set_property ("duration", $2);
1436 n->set_property ("drum-type", $1);
1437 n->set_spot (THIS->here_input ());
1439 if (ly_c_pair_p ($2)) {
1440 SCM arts = scm_reverse_x ($2, SCM_EOL);
1441 n->set_property ("articulations", arts);
1448 ADDQUOTE string Music {
1449 SCM adder = ly_scheme_function ("add-quotable");
1451 scm_call_2 (adder, $2, $3->self_scm ());
1452 scm_gc_unprotect_object ($3->self_scm ());
1458 $$ = MY_MAKE_MUSIC ("EventChord");
1459 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1460 scm_gc_unprotect_object ($1->self_scm ());
1462 $$-> set_spot (THIS->here_input ());
1463 $1-> set_spot (THIS->here_input ());
1465 | SKIP duration_length {
1466 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1467 skip->set_property ("duration", $2);
1471 | QUOTE STRING duration_length {
1472 SCM tab = THIS->lexer_->lookup_identifier ("musicQuotes");
1474 if (scm_hash_table_p (tab) == SCM_BOOL_T)
1476 SCM key = $2; // use symbol?
1477 evs = scm_hash_ref (tab, key, SCM_BOOL_F);
1480 if (ly_c_vector_p (evs))
1482 quote = MY_MAKE_MUSIC ("QuoteMusic");
1483 quote->set_property ("duration", $3);
1484 quote->set_property ("quoted-events", evs);
1486 THIS->here_input ().warning (_f ("Can\'t find music"));
1487 quote = MY_MAKE_MUSIC ("Event");
1489 quote->set_spot (THIS->here_input ());
1492 | OCTAVE { THIS->push_spot (); }
1494 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1496 $$->set_spot (THIS->pop_spot ());
1497 $$->set_property ("pitch", $3);
1500 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1501 m->set_property ("span-direction", scm_int2num (START));
1502 m->set_spot (THIS->here_input ());
1504 $$ = MY_MAKE_MUSIC ("EventChord");
1505 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1506 scm_gc_unprotect_object (m->self_scm ());
1507 $$->set_spot (THIS->here_input ());
1510 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1511 m->set_property ("span-direction", scm_int2num (STOP));
1512 m->set_spot (THIS->here_input ());
1514 $$ = MY_MAKE_MUSIC ("EventChord");
1515 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1516 $$->set_spot (THIS->here_input ());
1517 scm_gc_unprotect_object (m->self_scm ());
1520 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1521 $$->set_spot (THIS->here_input ());
1524 SCM pipe =THIS->lexer_->lookup_identifier ("pipeSymbol");
1526 if (Music * m = unsmob_music (pipe))
1529 $$ = MY_MAKE_MUSIC ("BarCheck");
1531 $$->set_spot (THIS->here_input ());
1533 | TRANSPOSITION pitch {
1534 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1536 $$->set_spot (THIS-> here_input ());
1537 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1541 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1543 Music *csm = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1545 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED, csm, SCM_EOL);
1546 $$->set_spot (THIS->here_input ());
1547 t->set_spot (THIS->here_input ());
1549 | PARTIAL duration_length {
1550 Moment m = - unsmob_duration ($2)->get_length ();
1551 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1552 p->set_spot (THIS->here_input ());
1553 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1555 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1560 SCM proc = ly_scheme_function ("make-clef-set");
1562 SCM result = scm_call_1 (proc, $2);
1563 scm_gc_protect_object (result);
1564 $$ = unsmob_music (result);
1567 SCM proc= ly_scheme_function ("make-time-signature-set");
1569 SCM result = scm_apply_2 (proc, ly_car ($2), ly_cdr ($2), SCM_EOL);
1570 scm_gc_protect_object (result);
1571 $$ = unsmob_music (result);
1574 SCM proc = ly_scheme_function ("make-mark-set");
1576 SCM result = scm_call_1 (proc, $2);
1577 scm_gc_protect_object (result);
1578 $$ = unsmob_music (result);
1584 $$ = MY_MAKE_MUSIC ("BreathingSignEvent");
1587 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1590 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1597 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1600 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1602 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1603 if (scm_ilength ($3) > 0)
1605 key->set_property ("pitch-alist", $3);
1606 key->set_property ("tonic", Pitch (0,0,0).smobbed_copy ());
1607 ((Music*)key)->transpose (* unsmob_pitch ($2));
1609 THIS->parser_error (_ ("Second argument must be pitch list."));
1620 | post_events post_event {
1621 $2->set_spot (THIS->here_input ());
1622 $$ = scm_cons ($2->self_scm (), $$);
1623 scm_gc_unprotect_object ($2->self_scm ());
1625 | post_events tagged_post_event {
1626 $2 -> set_spot (THIS->here_input ());
1627 $$ = scm_cons ($2->self_scm (), $$);
1628 scm_gc_unprotect_object ($2->self_scm ());
1634 '-' TAG embedded_scm post_event {
1635 tag_music ($4, $3, THIS->here_input ());
1641 direction_less_event {
1645 if (!THIS->lexer_->is_lyric_state ())
1646 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1647 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1650 if (!THIS->lexer_->is_lyric_state ())
1651 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1652 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1654 | script_dir direction_reqd_event {
1656 $2->set_property ("direction", scm_int2num ($1));
1659 | script_dir direction_less_event {
1661 $2->set_property ("direction", scm_int2num ($1));
1664 | string_number_event
1667 string_number_event:
1669 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1670 s->set_property ("string-number", scm_int2num ($1));
1671 s->set_spot (THIS->here_input ());
1677 direction_less_event:
1683 TODO: should take all these defs out of the parser, adn make use
1687 (set-articulation '~ "trill")
1690 Music *m = MY_MAKE_MUSIC ("BeamEvent");
1691 m->set_spot (THIS->here_input ());
1692 m->set_property ("span-direction", scm_int2num (START));
1696 Music *m = MY_MAKE_MUSIC ("BeamEvent");
1697 m->set_spot (THIS->here_input ());
1698 m->set_property ("span-direction", scm_int2num (STOP));
1702 Music *m = MY_MAKE_MUSIC ("TieEvent");
1703 m->set_spot (THIS->here_input ());
1708 dynamic_cast<Music *> ($$)->set_property ("span-direction",
1709 scm_int2num (START));
1713 dynamic_cast<Music *> ($$)->set_property ("span-direction",
1714 scm_int2num (STOP));
1716 | EVENT_IDENTIFIER {
1717 $$ = unsmob_music ($1);
1720 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1721 a->set_spot (THIS->here_input ());
1722 a->set_property ("tremolo-type", scm_int2num ($1));
1727 direction_reqd_event:
1731 | script_abbreviation {
1732 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1733 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1734 if (ly_c_string_p (s))
1735 a->set_property ("articulation-type", s);
1736 else THIS->parser_error (_ ("Expecting string as script definition"));
1742 /**/ { $$ = SCM_EOL; }
1743 | '=' { $$ = scm_int2num (0); }
1744 | '=' sub_quotes { $$ = scm_int2num ($2); }
1745 | '=' sup_quotes { $$ = scm_int2num ($2); }
1770 | NOTENAME_PITCH sup_quotes {
1771 Pitch p = *unsmob_pitch ($1);
1772 p = p.transposed (Pitch ($2,0,0));
1773 $$ = p.smobbed_copy ();
1775 | NOTENAME_PITCH sub_quotes {
1776 Pitch p =* unsmob_pitch ($1);
1777 p = p.transposed (Pitch (-$2,0,0));
1778 $$ = p.smobbed_copy ();
1790 | TONICNAME_PITCH sup_quotes {
1791 Pitch p = *unsmob_pitch ($1);
1792 p = p.transposed (Pitch ($2,0,0));
1793 $$ = p.smobbed_copy ();
1795 | TONICNAME_PITCH sub_quotes {
1796 Pitch p =* unsmob_pitch ($1);
1798 p = p.transposed (Pitch (-$2,0,0));
1799 $$ = p.smobbed_copy ();
1809 pitch_also_in_chords:
1816 Music *s = MY_MAKE_MUSIC ("SlurEvent");
1818 s->set_spot (THIS->here_input ());
1821 Music *s = MY_MAKE_MUSIC ("PhrasingSlurEvent");
1823 s->set_spot (THIS->here_input ());
1826 Music *s = MY_MAKE_MUSIC ("CrescendoEvent");
1828 s->set_spot (THIS->here_input ());
1831 Music *s = MY_MAKE_MUSIC ("DecrescendoEvent");
1833 s->set_spot (THIS->here_input ());
1840 Music *s = MY_MAKE_MUSIC ("CrescendoEvent");
1841 s->set_spot (THIS->here_input ());
1846 Music *s= MY_MAKE_MUSIC ("SlurEvent");
1848 s->set_spot (THIS->here_input ());
1852 Music *s= MY_MAKE_MUSIC ("PhrasingSlurEvent");
1854 s->set_property ("span-type",
1855 scm_makfrom0str ("phrasing-slur"));
1856 s->set_spot (THIS->here_input ());
1862 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1863 t->set_property ("text", $1);
1864 t->set_spot (THIS->here_input ());
1868 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1869 t->set_property ("text",
1870 make_simple_markup (THIS->lexer_->encoding (), $1));
1871 t->set_spot (THIS->here_input ());
1876 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1877 t->set_property ("digit", scm_int2num ($1));
1878 t->set_spot (THIS->here_input ());
1883 script_abbreviation:
1885 $$ = scm_makfrom0str ("Hat");
1888 $$ = scm_makfrom0str ("Plus");
1891 $$ = scm_makfrom0str ("Dash");
1894 $$ = scm_makfrom0str ("Bar");
1897 $$ = scm_makfrom0str ("Larger");
1900 $$ = scm_makfrom0str ("Dot");
1903 $$ = scm_makfrom0str ("Underscore");
1910 | '-' { $$ = CENTER; }
1921 multiplied_duration {
1926 optional_notemode_duration:
1928 Duration dd = THIS->default_duration_;
1929 $$ = dd.smobbed_copy ();
1931 THIS->beam_check ($$);
1933 | multiplied_duration {
1935 THIS->default_duration_ = *unsmob_duration ($$);
1937 THIS->beam_check ($$);
1942 bare_unsigned dots {
1944 if (!is_duration ($1))
1945 THIS->parser_error (_f ("not a duration: %d", $1));
1949 $$ = Duration (len, $2).smobbed_copy ();
1951 | DURATION_IDENTIFIER dots {
1952 Duration *d = unsmob_duration ($1);
1953 Duration k (d->duration_log (), d->dot_count () + $2);
1962 multiplied_duration:
1966 | multiplied_duration '*' bare_unsigned {
1967 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1969 | multiplied_duration '*' FRACTION {
1970 Rational m (ly_scm2int (ly_car ($3)), ly_scm2int (ly_cdr ($3)));
1972 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1977 FRACTION { $$ = $1; }
1978 | UNSIGNED '/' UNSIGNED {
1979 $$ = scm_cons (scm_int2num ($1), scm_int2num ($3));
1997 | ':' bare_unsigned {
1998 if (!is_duration ($2))
1999 THIS->parser_error (_f ("not a duration: %d", $2));
2006 /*****************************************************************
2008 *****************************************************************/
2011 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2014 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2016 | STRING { $$ = $1; }
2027 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2028 $$ = bfr->self_scm ();
2029 scm_gc_unprotect_object ($$);
2032 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2033 $$ = bfr->self_scm ();
2035 bfr->set_property ("figure", $1);
2037 scm_gc_unprotect_object ($$);
2039 | bass_figure bass_mod {
2040 Music *m = unsmob_music ($1);
2042 SCM salter = m->get_property ("alteration");
2043 int alter = ly_c_number_p (salter) ? ly_scm2int (salter) : 0;
2044 m->set_property ("alteration",
2045 scm_int2num (alter + $2));
2047 m->set_property ("alteration", scm_int2num (0));
2055 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2060 | br_bass_figure ']' {
2062 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2070 | figure_list br_bass_figure {
2071 $$ = scm_cons ($2, $1);
2076 FIGURE_OPEN figure_list FIGURE_CLOSE {
2077 Music *m = MY_MAKE_MUSIC ("EventChord");
2078 $2 = scm_reverse_x ($2, SCM_EOL);
2079 m->set_property ("elements", $2);
2080 $$ = m->self_scm ();
2091 pitch exclamations questions oct_check optional_notemode_duration optional_rest {
2093 Input i = THIS->pop_spot ();
2094 if (!THIS->lexer_->is_note_state ())
2095 THIS->parser_error (_ ("Have to be in Note mode for notes"));
2099 n = MY_MAKE_MUSIC ("RestEvent");
2101 n = MY_MAKE_MUSIC ("NoteEvent");
2103 n->set_property ("pitch", $1);
2104 n->set_property ("duration", $5);
2106 if (ly_c_number_p ($4))
2108 int q = ly_scm2int ($4);
2109 n->set_property ("absolute-octave", scm_int2num (q-1));
2113 n->set_property ("cautionary", SCM_BOOL_T);
2114 if ($2 % 2 || $3 % 2)
2115 n->set_property ("force-accidental", SCM_BOOL_T);
2117 Music *v = MY_MAKE_MUSIC ("EventChord");
2118 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2119 scm_gc_unprotect_object (n->self_scm ());
2125 | DRUM_PITCH optional_notemode_duration {
2126 Input i = THIS->pop_spot ();
2128 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2129 n->set_property ("duration", $2);
2130 n->set_property ("drum-type", $1);
2132 Music *v = MY_MAKE_MUSIC ("EventChord");
2133 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2134 scm_gc_unprotect_object (n->self_scm ());
2140 | figure_spec optional_notemode_duration {
2141 Music *m = unsmob_music ($1);
2142 Input i = THIS->pop_spot ();
2144 for (SCM s = m->get_property ("elements"); ly_c_pair_p (s); s = ly_cdr (s))
2146 unsmob_music (ly_car (s))->set_property ("duration", $2);
2150 | RESTNAME optional_notemode_duration {
2152 Input i = THIS->pop_spot ();
2154 if (ly_scm2string ($1) == "s") {
2156 ev = MY_MAKE_MUSIC ("SkipEvent");
2159 ev = MY_MAKE_MUSIC ("RestEvent");
2162 ev->set_property ("duration", $2);
2164 Music *velt = MY_MAKE_MUSIC ("EventChord");
2165 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2168 scm_gc_unprotect_object (ev->self_scm ());
2172 | MULTI_MEASURE_REST optional_notemode_duration {
2175 SCM proc = ly_scheme_function ("make-multi-measure-rest");
2176 SCM mus = scm_call_2 (proc, $2,
2177 make_input (THIS->here_input ()));
2178 scm_gc_protect_object (mus);
2179 $$ = unsmob_music (mus);
2182 | lyric_element optional_notemode_duration {
2183 Input i = THIS->pop_spot ();
2184 if (!THIS->lexer_->is_lyric_state ())
2185 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
2187 Music *lreq = MY_MAKE_MUSIC ("LyricEvent");
2188 lreq->set_property ("text", $1);
2189 lreq->set_property ("duration",$2);
2191 Music *velt = MY_MAKE_MUSIC ("EventChord");
2192 velt->set_property ("elements", scm_list_1 (lreq->self_scm ()));
2199 if (!THIS->lexer_->is_chord_state ())
2200 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
2201 $$ = unsmob_music ($1);
2206 /* FIXME: lyric flavoured markup would be better */
2214 steno_tonic_pitch optional_notemode_duration {
2215 $$ = make_chord ($1, $2, SCM_EOL);
2217 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2218 SCM its = scm_reverse_x ($4, SCM_EOL);
2219 $$ = make_chord ($1, $2, scm_cons ($3, its));
2227 | chord_items chord_item {
2228 $$ = scm_cons ($2, $$);
2234 $$ = ly_symbol2scm ("chord-colon");
2237 $$ = ly_symbol2scm ("chord-caret");
2239 | CHORD_SLASH steno_tonic_pitch {
2240 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2242 | CHORD_BASS steno_tonic_pitch {
2243 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2252 $$ = scm_reverse_x ($1, SCM_EOL);
2260 step_number { $$ = scm_cons ($1, SCM_EOL); }
2261 | step_numbers '.' step_number {
2262 $$ = scm_cons ($3, $$);
2268 $$ = make_chord_step ($1, 0);
2270 | bare_unsigned '+' {
2271 $$ = make_chord_step ($1, SHARP);
2273 | bare_unsigned CHORD_MINUS {
2274 $$ = make_chord_step ($1, FLAT);
2281 TODO: should deprecate in favor of Scheme?
2285 number_expression '+' number_term {
2286 $$ = scm_sum ($1, $3);
2288 | number_expression '-' number_term {
2289 $$ = scm_difference ($1, $3);
2298 | number_factor '*' number_factor {
2299 $$ = scm_product ($1, $3);
2301 | number_factor '/' number_factor {
2302 $$ = scm_divide ($1, $3);
2307 '-' number_factor { /* %prec UNARY_MINUS */
2308 $$ = scm_difference ($2, SCM_UNDEFINED);
2316 $$ = scm_int2num ($1);
2321 | NUMBER_IDENTIFIER {
2324 | REAL NUMBER_IDENTIFIER {
2325 $$ = scm_make_real (ly_scm2double ($1) *ly_scm2double ($2));
2327 | UNSIGNED NUMBER_IDENTIFIER {
2328 $$ = scm_make_real ($1 *ly_scm2double ($2));
2344 if (scm_integer_p ($1) == SCM_BOOL_T)
2346 int k = ly_scm2int ($1);
2350 THIS->parser_error (_ ("need integer number arg"));
2364 | STRING_IDENTIFIER {
2367 | string '+' string {
2368 $$ = scm_string_append (scm_list_2 ($1, $3));
2375 | exclamations '!' { $$ ++; }
2380 | questions '?' { $$ ++; }
2390 { THIS->lexer_->push_markup_state (); }
2393 THIS->lexer_->pop_state ();
2399 This should be done more dynamically if possible.
2403 $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
2405 | MARKUP_HEAD_EMPTY {
2406 $$ = scm_list_1 ($1);
2408 | MARKUP_HEAD_MARKUP0 markup {
2409 $$ = scm_list_2 ($1, $2);
2411 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2412 $$ = scm_list_3 ($1, $2, $3);
2414 | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
2415 $$ = scm_list_3 ($1, $2, $3);
2420 | MARKUP_HEAD_LIST0 markup_list {
2421 $$ = scm_list_2 ($1,$2);
2423 | MARKUP_HEAD_SCM0 embedded_scm {
2424 $$ = scm_list_2 ($1, $2);
2426 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
2427 $$ = scm_list_4 ($1, $2, $3, $4);
2429 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2430 $$ = scm_list_4 ($1, $2, $3, $4);
2432 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2433 $$ = scm_list_3 ($1, $2, $3);
2435 | MARKUP_IDENTIFIER {
2438 | STRING_IDENTIFIER {
2444 chord_open markup_list_body chord_close { $$ = scm_reverse_x ($2, SCM_EOL); }
2448 '{' markup_list_body '}' {
2449 SCM line = ly_scheme_function ("line-markup");
2451 $$ = scm_list_2 (line, scm_reverse_x ($2, SCM_EOL));
2456 /**/ { $$ = SCM_EOL; }
2457 | markup_list_body markup {
2458 $$ = scm_cons ($2, $1);
2466 My_lily_parser::set_yydebug (bool )
2474 My_lily_parser::do_yyparse ()
2476 yyparse ((void*)this);
2481 Should make this optional? It will also complain when you do
2485 which is entirely legitimate.
2487 Or we can scrap it. Barchecks should detect wrong durations, and
2488 skipTypesetting speeds it up a lot.
2492 My_lily_parser::beam_check (SCM dur)
2494 Duration *d = unsmob_duration (dur);
2495 if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2497 Music *m = unsmob_music (last_beam_start_);
2498 m->origin ()->warning (_ ("Suspect duration found following this beam"));
2500 last_beam_start_ = SCM_EOL;
2508 It is a little strange to have this function in this file, but
2509 otherwise, we have to import music classes into the lexer.
2513 My_lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2515 if (ly_c_string_p (sid)) {
2517 return STRING_IDENTIFIER;
2518 } else if (ly_c_number_p (sid)) {
2520 return NUMBER_IDENTIFIER;
2521 } else if (unsmob_context_def (sid)) {
2522 *destination = unsmob_context_def (sid)->clone_scm ();
2523 return CONTEXT_DEF_IDENTIFIER;
2524 } else if (unsmob_score (sid)) {
2525 Score *score = new Score (*unsmob_score (sid));
2526 *destination = score->self_scm ();
2527 return SCORE_IDENTIFIER;
2528 } else if (Music *mus = unsmob_music (sid)) {
2529 mus = mus->clone ();
2530 *destination = mus->self_scm ();
2531 unsmob_music (*destination)->
2532 set_property ("origin", make_input (last_input_));
2533 return dynamic_cast<Event*> (mus)
2534 ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2535 } else if (unsmob_duration (sid)) {
2536 *destination = unsmob_duration (sid)->smobbed_copy ();
2537 return DURATION_IDENTIFIER;
2538 } else if (unsmob_music_output_def (sid)) {
2539 Music_output_def *p = unsmob_music_output_def (sid);
2542 *destination = p->self_scm ();
2543 return MUSIC_OUTPUT_DEF_IDENTIFIER;
2544 } else if (Text_item::markup_p (sid)) {
2546 return MARKUP_IDENTIFIER;
2553 property_op_to_music (SCM op)
2556 SCM tag = ly_car (op);
2557 SCM symbol = ly_cadr (op);
2558 SCM args = ly_cddr (op);
2559 SCM grob_val = SCM_UNDEFINED;
2560 SCM grob_sym = SCM_UNDEFINED;
2561 SCM val = SCM_UNDEFINED;
2563 if (tag == ly_symbol2scm ("assign"))
2565 m = MY_MAKE_MUSIC ("PropertySet");
2566 val = ly_car (args);
2568 else if (tag == ly_symbol2scm ("unset"))
2569 m = MY_MAKE_MUSIC ("PropertyUnset");
2570 else if (tag == ly_symbol2scm ("poppush")
2571 || tag == ly_symbol2scm ("push"))
2573 m = MY_MAKE_MUSIC ("OverrideProperty");
2574 grob_sym = ly_car (args);
2575 grob_val = ly_cadr (args);
2577 else if (tag == ly_symbol2scm ("pop")) {
2578 m = MY_MAKE_MUSIC ("RevertProperty");
2579 grob_sym = ly_car (args);
2582 m->set_property ("symbol", symbol);
2584 if (val != SCM_UNDEFINED)
2585 m->set_property ("value", val);
2586 if (grob_val != SCM_UNDEFINED)
2587 m->set_property ("grob-value", grob_val);
2589 if (grob_sym != SCM_UNDEFINED)
2591 bool itc = internal_type_checking_global_b;
2594 bool autobeam = ly_c_equal_p (symbol, ly_symbol2scm ("autoBeamSettings"));
2596 internal_type_checking_global_b = false;
2597 m->set_property ("grob-property", grob_sym);
2599 internal_type_checking_global_b = itc;
2602 if (op == ly_symbol2scm ("poppush"))
2603 m->set_property ("pop-first", SCM_BOOL_T);
2610 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2612 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2614 csm->set_property ("element", m->self_scm ());
2615 scm_gc_unprotect_object (m->self_scm ());
2617 csm->set_property ("context-type",
2618 ly_c_symbol_p (type) ? type : scm_string_to_symbol (type));
2619 csm->set_property ("property-operations", ops);
2621 if (ly_c_string_p (id))
2622 csm->set_property ("context-id", id);
2628 get_next_unique_context ()
2630 static int new_context_count;
2633 snprintf (s, 1024, "uniqueContext%d", new_context_count ++);
2635 return scm_makfrom0str (s);