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. */
204 Music_output_def *outputdef;
214 yylex (YYSTYPE *s, void *v)
216 My_lily_parser *pars = (My_lily_parser*) v;
217 My_lily_lexer *lex = pars->lexer_;
219 lex->lexval = (void*) s;
220 lex->prepare_for_next_token ();
221 return lex->yylex ();
230 Three shift/reduce problems:
232 2. \markup identifier.
237 \repeat .. \alternative
240 \repeat { \repeat .. \alternative }
244 \repeat { \repeat } \alternative
266 %token CHORDMODIFIERS
271 %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 Prefix_composite_music Grouped_music_list
383 %type <music> Repeated_music
384 %type <scm> Alternative_music
385 %type <i> tremolo_type
386 %type <i> bare_int bare_unsigned
388 %type <scm> identifier_init
389 %type <scm> simple_string
391 %type <music> note_chord_element chord_body chord_body_element
392 %type <scm> chord_body_elements
393 %type <scm> steno_duration optional_notemode_duration multiplied_duration
395 %type <scm> post_events
396 %type <music> gen_text_def direction_less_event direction_reqd_event
397 %type <scm> steno_pitch pitch absolute_pitch pitch_also_in_chords
398 %type <scm> steno_tonic_pitch
399 %type <scm> duration_length fraction
401 %type <scm> new_chord step_number chord_items chord_item chord_separator step_numbers
403 %type <scm> embedded_scm scalar
404 %type <music> Music Sequential_music Simultaneous_music
405 %type <music> relative_music re_rhythmed_music
406 %type <music> music_property_def context_change
407 %type <scm> context_prop_spec
408 %type <scm> Music_list
409 %type <scm> property_operation context_mod context_def_mod optional_context_mod
410 %type <outputdef> music_output_def_body music_output_def_head
411 %type <music> post_event tagged_post_event
412 %type <music> command_req
413 %type <music> string_number_event
414 %type <scm> string bare_number number_expression number_term number_factor
415 %type <score> score_block score_body
417 %type <scm> context_def_spec_block context_def_spec_body
418 %type <music> tempo_event
419 %type <scm> script_abbreviation
425 /* We don't assign precedence to / and *, because we might need varied
426 prec levels in different prods */
432 lilypond: /* empty */
433 | lilypond toplevel_expression {
435 | lilypond assignment {
438 THIS->error_level_ = 1;
441 THIS->error_level_ = 1;
450 Music_output_def *paper = get_paper (THIS);
452 // SCM proc = paper->get_scmvar ("toplevel-music-handler");
453 SCM proc = ly_scheme_function ("ly:parser-add-book-and-score");
454 //SCM proc = ly_scheme_function ("toplevel-music-handler");
455 scm_call_2 (proc, THIS->self_scm (), $1->self_scm ());
456 scm_gc_unprotect_object (paper->self_scm ());
463 SCM header = THIS->header_;
464 Path outname = split_path (THIS->output_basename_);
465 int *c = &THIS->book_count_;
467 outname.base += "-" + to_string (*c);
469 Music_output_def *paper = get_paper (THIS);
470 book->process (outname.to_string (), paper, header);
471 scm_gc_unprotect_object (book->self_scm ());
472 scm_gc_unprotect_object (paper->self_scm ());
475 /* TODO: implicit book, depending on --no-book/--no-page-layout
478 SCM head = is_module (score->header_) ? score->header_
479 : THIS->header_.to_SCM ();
481 Path p = split_path (THIS->output_basename_);
482 int *c = &THIS->score_count_;
484 p.base += "-" + to_string (*c);
487 SCM outname = scm_makfrom0str (p.to_string ().to_str0());
489 for (int i = 0; i < score->defs_.size (); i++)
490 default_rendering (score->music_,
491 score->defs_[i]->self_scm (), head,
494 if (score->defs_.is_empty ())
496 Music_output_def *paper = get_paper (THIS);
497 default_rendering (score->music_, paper->self_scm (), head,
499 scm_gc_unprotect_object (paper->self_scm ());
501 scm_gc_unprotect_object (score->self_scm ());
505 if (dynamic_cast<Paper_def*> ($1))
506 id = scm_makfrom0str ("$defaultpaper");
507 else if (dynamic_cast<Midi_def*> ($1))
508 id = scm_makfrom0str ("$defaultmidi");
509 THIS->lexer_->set_identifier (id, $1->self_scm ());
510 scm_gc_unprotect_object ($1->self_scm ());
525 lilypond_header_body:
527 $$ = ly_make_anonymous_module ();
528 THIS->lexer_->add_scope ($$);
530 | lilypond_header_body assignment {
536 HEADER '{' lilypond_header_body '}' {
537 $$ = THIS->lexer_->remove_scope ();
549 /* cont */ '=' identifier_init {
552 Should find generic way of associating input with objects.
554 Input ip = THIS->pop_spot ();
556 if (! is_regular_identifier ($1))
558 ip.warning (_ ("Identifier should have alphabetic characters only"));
561 THIS->lexer_->set_identifier ($1, $4);
564 TODO: devise standard for protection in parser.
566 The parser stack lives on the C-stack, which means that
567 all objects can be unprotected as soon as they're here.
577 $$ = $1->self_scm ();
578 scm_gc_unprotect_object ($$);
584 $$ = $1->self_scm ();
585 scm_gc_unprotect_object ($$);
587 | context_def_spec_block {
591 $$ = $1->self_scm ();
592 scm_gc_unprotect_object ($$);
595 $$ = $1->self_scm ();
596 scm_gc_unprotect_object ($$);
598 | number_expression {
609 context_def_spec_block:
610 CONTEXT '{' context_def_spec_body '}'
616 context_def_spec_body:
618 $$ = Context_def::make_scm ();
619 unsmob_context_def ($$)->set_spot (THIS->here_input ());
621 | CONTEXT_DEF_IDENTIFIER {
623 unsmob_context_def ($$)->set_spot (THIS->here_input ());
625 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
626 Context_def*td = unsmob_context_def ($$);
628 for (SCM p = $3; ly_c_pair_p (p); p = ly_cdr (p)) {
629 SCM tag = ly_caar (p);
631 /* TODO: should make new tag "grob-definition" ? */
632 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
633 tag, scm_cons (ly_cdar (p), SCM_EOL)));
636 | context_def_spec_body context_mod {
637 unsmob_context_def ($$)->add_context_mod ($2);
645 /*cont*/ '{' book_body '}' {
654 $$->set_spot (THIS->here_input ());
656 | book_body score_block {
657 $$->scores_.push ($2);
658 scm_gc_unprotect_object ($2->self_scm ());
668 /*cont*/ '{' score_body '}' {
678 $$->set_spot (THIS->here_input ());
679 SCM m = $1->self_scm ();
680 scm_gc_unprotect_object (m);
685 SCM check_funcs = ly_scheme_function ("toplevel-music-functions");
686 for (; ly_c_pair_p (check_funcs); check_funcs = ly_cdr (check_funcs))
687 m = scm_call_1 (ly_car (check_funcs), m);
692 $$ = new Score ( *unsmob_score ($1));
693 $$->set_spot (THIS->here_input ());
695 | score_body lilypond_header {
698 | score_body output_def {
700 scm_gc_unprotect_object ($2->self_scm ());
712 music_output_def_body '}' {
714 THIS->lexer_->remove_scope ();
715 THIS->lexer_->pop_state ();
719 music_output_def_head:
721 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
726 p = dynamic_cast<Midi_def*> (id->clone ());
731 THIS->lexer_->add_scope (p->scope_);
734 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
737 p = dynamic_cast<Paper_def*> (id->clone ());
741 THIS->lexer_->add_scope (p->scope_);
747 music_output_def_body:
748 music_output_def_head '{' {
750 $$->input_origin_. set_spot (THIS->here_input ());
751 THIS->lexer_->push_initial_state ();
753 | music_output_def_head '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
754 scm_gc_unprotect_object ($1->self_scm ());
755 Music_output_def *o = unsmob_music_output_def ($3);
756 o->input_origin_.set_spot (THIS->here_input ());
758 THIS->lexer_->remove_scope ();
759 THIS->lexer_->add_scope (o->scope_);
760 THIS->lexer_->push_initial_state ();
762 | music_output_def_body assignment {
765 | music_output_def_body context_def_spec_block {
766 $$->assign_context_def ($2);
768 | music_output_def_body tempo_event {
770 junk this ? there already is tempo stuff in
773 int m = ly_scm2int ( $2->get_property ("metronome-count"));
774 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
775 Midi_def *md = dynamic_cast<Midi_def*> ($$);
777 md->set_tempo (d->get_length (), m);
778 scm_gc_unprotect_object ($2->self_scm ());
780 | music_output_def_body error {
786 TEMPO steno_duration '=' bare_unsigned {
787 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
788 $$->set_property ("tempo-unit", $2);
789 $$->set_property ("metronome-count", scm_int2num ( $4));
794 The representation of a list is the
798 to have efficient append.
802 $$ = scm_cons (SCM_EOL, SCM_EOL);
806 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
807 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
808 if (ly_c_pair_p (ly_cdr (s)))
809 scm_set_cdr_x (ly_cdr (s), c); /* append */
811 scm_set_car_x (s, c); /* set first cons */
812 scm_set_cdr_x (s, c); /* remember last cell */
828 | ALTERNATIVE '{' Music_list '}' {
835 REPEAT string bare_unsigned Music Alternative_music
839 SCM alts = ly_c_pair_p ($5) ? ly_car ($5) : SCM_EOL;
840 if (times < scm_ilength (alts)) {
841 unsmob_music (ly_car (alts))
842 ->origin ()->warning (
843 _ ("More alternatives than repeats. Junking excess alternatives."));
844 alts = ly_truncate_list (times, alts);
848 SCM proc = ly_scheme_function ("make-repeated-music");
850 SCM mus = scm_call_1 (proc, $2);
851 scm_gc_protect_object (mus); // UGH.
852 Music *r = unsmob_music (mus);
855 r-> set_property ("element", beg->self_scm ());
856 scm_gc_unprotect_object (beg->self_scm ());
858 r->set_property ("repeat-count", scm_int2num (times >? 1));
860 r-> set_property ("elements",alts);
861 if (ly_c_equal_p ($2, scm_makfrom0str ("tremolo"))) {
863 TODO: move this code to Scheme.
867 we can not get durations and other stuff correct down the line, so we have to
868 add to the duration log here.
870 SCM func = ly_scheme_function ("shift-duration-log");
872 int dots = ($3 % 3) ? 0 : 1;
873 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
875 Sequential_music *seq = dynamic_cast<Sequential_music*> ($4);
878 int list_len = scm_ilength (seq->music_list ());
880 seq->origin ()->warning ("Chord tremolo must have 2 elements.");
882 r->compress (Moment (Rational (1, list_len)));
884 scm_call_3 (func, r->self_scm (), scm_int2num (shift),scm_int2num (dots));
887 r->set_spot (*$4->origin ());
894 SEQUENTIAL '{' Music_list '}' {
895 $$ = MY_MAKE_MUSIC ("SequentialMusic");
896 $$->set_property ("elements", ly_car ($3));
897 $$->set_spot (THIS->here_input ());
899 | '{' Music_list '}' {
900 $$ = MY_MAKE_MUSIC ("SequentialMusic");
901 $$->set_property ("elements", ly_car ($2));
902 $$->set_spot (THIS->here_input ());
907 SIMULTANEOUS '{' Music_list '}'{
908 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
909 $$->set_property ("elements", ly_car ($3));
910 $$->set_spot (THIS->here_input ());
913 | simul_open Music_list simul_close {
914 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
915 $$->set_property ("elements", ly_car ($2));
916 $$->set_spot (THIS->here_input ());
921 event_chord { $$ = $1; }
922 | APPLYOUTPUT embedded_scm {
923 if (!ly_input_procedure_p ($2))
924 THIS->parser_error (_ ("\\applycontext takes function argument"));
925 $$ = MY_MAKE_MUSIC ("ApplyOutputEvent");
926 $$->set_property ("procedure", $2);
927 $$->set_spot (THIS->here_input ());
929 | APPLYCONTEXT embedded_scm {
930 if (!ly_input_procedure_p ($2))
931 THIS->parser_error (_ ("\\applycontext takes function argument"));
932 $$ = MY_MAKE_MUSIC ("ApplyContext");
933 $$->set_property ("procedure", $2);
934 $$->set_spot (THIS->here_input ());
937 $$ = unsmob_music ($1);
944 optional_context_mod:
945 /**/ { $$ = SCM_EOL; }
946 | WITH '{' context_mod_list '}' { $$ = $3; }
950 GRACE { $$ = scm_makfrom0str ("Grace"); }
951 | ACCIACCATURA { $$ = scm_makfrom0str ("Acciaccatura"); }
952 | APPOGGIATURA { $$ = scm_makfrom0str ("Appoggiatura"); }
956 /* */ { $$ = SCM_EOL; }
957 | context_mod_list context_mod {
958 $$ = scm_cons ($2, $1);
964 Prefix_composite_music { $$ = $1 ; }
965 | Grouped_music_list { $$ = $1 }
969 Simultaneous_music { $$ = $1; }
970 | Sequential_music { $$ = $1; }
973 Prefix_composite_music:
975 SCM proc = ly_scheme_function ("make-autochange-music");
977 SCM res = scm_call_1 (proc, $2->self_scm ());
978 scm_gc_unprotect_object ($2->self_scm ());
979 $$ = unsmob_music (res);
980 scm_gc_protect_object (res);
981 $$->set_spot (THIS->here_input ());
983 | PARTCOMBINE Music Music {
984 SCM proc = ly_scheme_function ("make-part-combine-music");
986 SCM res = scm_call_1 (proc, scm_listify ($2->self_scm (),
987 $3->self_scm (), SCM_UNDEFINED));
988 scm_gc_unprotect_object ($3->self_scm ());
989 scm_gc_unprotect_object ($2->self_scm ());
990 $$ = unsmob_music (res);
991 scm_gc_protect_object (res);
992 $$->set_spot (THIS->here_input ());
997 The other version is for easier debugging of
998 Sequential_music_iterator in combination with grace notes.
1003 TODO: should distinguish between both grace types in the
1004 basic music objects too, since the meaning is different.
1008 String start_str = "start" + ly_scm2string ($1) + "Music";
1009 String stop_str = "stop" + ly_scm2string ($1) + "Music";
1011 SCM start = THIS->lexer_->lookup_identifier (start_str);
1012 SCM stop = THIS->lexer_->lookup_identifier (stop_str);
1014 Music *startm = unsmob_music (start);
1015 Music *stopm = unsmob_music (stop);
1019 stopm = stopm->clone ();
1020 ms = scm_cons (stopm->self_scm (), ms);
1021 scm_gc_unprotect_object (stopm->self_scm ());
1023 ms = scm_cons ($2->self_scm (), ms);
1024 scm_gc_unprotect_object ($2->self_scm ());
1026 startm = startm->clone ();
1027 ms = scm_cons (startm->self_scm (), ms);
1028 scm_gc_unprotect_object (startm->self_scm ());
1031 Music* seq = MY_MAKE_MUSIC ("SequentialMusic");
1032 seq->set_property ("elements", ms);
1035 $$ = MY_MAKE_MUSIC ("GraceMusic");
1036 $$->set_property ("element", seq->self_scm ());
1037 scm_gc_unprotect_object (seq->self_scm ());
1039 $$ = MY_MAKE_MUSIC ("GraceMusic");
1040 $$->set_property ("element", $2->self_scm ());
1041 scm_gc_unprotect_object ($2->self_scm ());
1044 | CONTEXT string '=' string optional_context_mod Music {
1045 $$ = context_spec_music ($2, $4, $6, $5);
1048 | CONTEXT simple_string optional_context_mod Music {
1049 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1051 | NEWCONTEXT string optional_context_mod Music {
1052 $$ = context_spec_music ($2, get_next_unique_context (),
1063 int n = ly_scm2int (ly_car ($3)); int d = ly_scm2int (ly_cdr ($3));
1066 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1067 $$->set_spot (THIS->pop_spot ());
1069 $$->set_property ("element", mp->self_scm ());
1070 scm_gc_unprotect_object (mp->self_scm ());
1071 $$->set_property ("numerator", scm_int2num (n));
1072 $$->set_property ("denominator", scm_int2num (d));
1073 $$->compress (Moment (Rational (n,d)));
1076 | Repeated_music { $$ = $1; }
1077 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1078 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1080 Pitch from = *unsmob_pitch ($2);
1081 Pitch to = *unsmob_pitch ($3);
1083 p->transpose (interval (from, to));
1084 $$->set_property ("element", p->self_scm ());
1085 scm_gc_unprotect_object (p->self_scm ());
1087 | APPLY embedded_scm Music {
1088 if (!ly_input_procedure_p ($2))
1090 THIS->parser_error (_ ("\\apply takes function argument"));
1095 SCM ret = scm_call_1 ($2, $3->self_scm ());
1096 Music *m = unsmob_music (ret);
1098 THIS->parser_error ("\\apply must return a Music");
1099 m = MY_MAKE_MUSIC ("Music");
1106 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1107 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1111 THIS->lexer_->pop_state ();
1115 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1116 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1120 THIS->lexer_->pop_state ();
1123 { THIS->lexer_->push_figuredbass_state (); }
1126 Music *chm = MY_MAKE_MUSIC ("UntransposableMusic");
1127 chm->set_property ("element", $3->self_scm ());
1129 scm_gc_unprotect_object ($3->self_scm ());
1131 THIS->lexer_->pop_state ();
1134 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1135 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1136 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1137 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1140 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1141 chm->set_property ("element", $3->self_scm ());
1142 scm_gc_unprotect_object ($3->self_scm ());
1145 THIS->lexer_->pop_state ();
1148 { THIS->lexer_->push_lyric_state (); }
1152 THIS->lexer_->pop_state ();
1154 | relative_music { $$ = $1; }
1155 | re_rhythmed_music { $$ = $1; }
1156 | TAG embedded_scm Music {
1157 tag_music ($3, $2, THIS->here_input ());
1163 RELATIVE absolute_pitch Music {
1165 Pitch start = *unsmob_pitch ($2);
1166 $$ = make_music_relative (start, m);
1167 scm_gc_unprotect_object (m->self_scm ());
1169 | RELATIVE Composite_music {
1171 /* FIXME: why is octave==0 and default not middleC? */
1172 Pitch middle_c (-1, 0, 0);
1173 $$ = make_music_relative (middle_c, m);
1174 scm_gc_unprotect_object (m->self_scm ());
1179 NEWLYRICS Grouped_music_list {
1181 Can also use Music at the expensive of two S/Rs
1182 similar to \repeat \alternative
1185 | new_lyrics NEWLYRICS Grouped_music_list {
1191 ADDLYRICS Music Music {
1192 Music *m = MY_MAKE_MUSIC ("LyricCombineMusic");
1193 m->set_property ("elements", scm_listify ($2->self_scm (),
1194 $3->self_scm (), SCM_UNDEFINED));
1195 scm_gc_unprotect_object ($3->self_scm ());
1196 scm_gc_unprotect_object ($2->self_scm ());
1199 | Grouped_music_list new_lyrics {
1200 THIS->lexer_->pop_state ();
1203 SCM name = scm_makfrom0str ("");
1204 Music *combined = make_lyric_combine_music (name, music);
1205 SCM context = scm_makfrom0str ("Lyrics");
1206 $$ = context_spec_music (context, SCM_UNDEFINED, combined,
1208 scm_gc_unprotect_object (music->self_scm ());
1210 | LYRICSTO string Music {
1213 $$ = make_lyric_combine_music (name, music);
1214 scm_gc_unprotect_object (music->self_scm ());
1219 CHANGE STRING '=' STRING {
1220 Music*t= MY_MAKE_MUSIC ("ContextChange");
1221 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1222 t-> set_property ("change-to-id", $4);
1225 $$->set_spot (THIS->here_input ());
1229 simple_string: STRING {
1237 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1238 scm_string_to_symbol ($1), $3);
1240 | UNSET simple_string {
1241 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1242 scm_string_to_symbol ($2));
1244 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1245 $$ = scm_list_4 (ly_symbol2scm ("push"),
1246 scm_string_to_symbol ($2), $3, $5);
1248 | REVERT simple_string embedded_scm {
1249 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1250 scm_string_to_symbol ($2), $3);
1255 CONSISTSEND { $$ = ly_symbol2scm ("consists-end"); }
1256 | CONSISTS { $$ = ly_symbol2scm ("consists"); }
1257 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1259 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1260 | DENIES { $$ = ly_symbol2scm ("denies"); }
1262 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1263 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1264 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1265 | NAME { $$ = ly_symbol2scm ("context-name"); }
1269 property_operation { $$ = $1; }
1270 | context_def_mod STRING {
1271 $$ = scm_list_2 ($1, $2);
1277 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1278 scm_string_to_symbol ($1));
1280 | simple_string '.' simple_string {
1281 $$ = scm_list_2 (scm_string_to_symbol ($1),
1282 scm_string_to_symbol ($3));
1287 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1288 $$ = property_op_to_music (scm_list_4 (
1289 ly_symbol2scm ("poppush"),
1292 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1294 | REVERT context_prop_spec embedded_scm {
1295 $$ = property_op_to_music (scm_list_3 (
1296 ly_symbol2scm ("pop"),
1300 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1302 | SET context_prop_spec '=' scalar {
1303 $$ = property_op_to_music (scm_list_3 (
1304 ly_symbol2scm ("assign"),
1307 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1309 | UNSET context_prop_spec {
1310 $$ = property_op_to_music (scm_list_2 (
1311 ly_symbol2scm ("unset"),
1313 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1315 | ONCE music_property_def {
1316 SCM e = $2->get_property ("element");
1317 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1327 | bare_int { $$ = scm_int2num ($1); }
1328 | embedded_scm { $$ = $1; }
1329 | full_markup { $$ = $1; }
1330 | DIGIT { $$ = scm_int2num ($1); }
1336 Adding pre_events to the simple_element
1337 makes the choice between
1343 simple_element: STRING
1345 a single shift/reduction conflict.
1347 nevertheless, this is not very clean, and we should find a different
1357 pre_events simple_element post_events {
1358 SCM elts = $2-> get_property ("elements");
1360 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1362 $2->set_property ("elements", elts);
1366 | note_chord_element
1371 chord_body optional_notemode_duration post_events
1373 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1374 SCM es = $1->get_property ("elements");
1375 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1377 for (SCM s = es; ly_c_pair_p (s); s = ly_cdr (s))
1378 unsmob_music (ly_car (s))->set_property ("duration", dur);
1379 es = ly_append2 (es, postevs);
1381 $1-> set_property ("elements", es);
1392 simul_open: LESSLESS
1395 simul_close: MOREMORE
1399 chord_open chord_body_elements chord_close
1401 $$ = MY_MAKE_MUSIC ("EventChord");
1402 $$->set_property ("elements",
1403 scm_reverse_x ($2, SCM_EOL));
1407 chord_body_elements:
1408 /* empty */ { $$ = SCM_EOL; }
1409 | chord_body_elements chord_body_element {
1410 $$ = scm_cons ($2->self_scm (), $1);
1411 scm_gc_unprotect_object ($2->self_scm ());
1416 pitch exclamations questions post_events
1418 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1419 n->set_property ("pitch", $1);
1421 n->set_property ("cautionary", SCM_BOOL_T);
1422 if ($2 % 2 || $3 % 2)
1423 n->set_property ("force-accidental", SCM_BOOL_T);
1425 if (ly_c_pair_p ($4)) {
1426 SCM arts = scm_reverse_x ($4, SCM_EOL);
1427 n->set_property ("articulations", arts);
1431 | DRUM_PITCH post_events {
1432 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1433 n->set_property ("duration", $2);
1434 n->set_property ("drum-type", $1);
1435 n->set_spot (THIS->here_input ());
1437 if (ly_c_pair_p ($2)) {
1438 SCM arts = scm_reverse_x ($2, SCM_EOL);
1439 n->set_property ("articulations", arts);
1446 ADDQUOTE string Music {
1447 SCM adder = ly_scheme_function ("add-quotable");
1449 scm_call_2 (adder, $2, $3->self_scm ());
1450 scm_gc_unprotect_object ($3->self_scm ());
1456 $$ = MY_MAKE_MUSIC ("EventChord");
1457 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1458 scm_gc_unprotect_object ($1->self_scm ());
1460 $$-> set_spot (THIS->here_input ());
1461 $1-> set_spot (THIS->here_input ());
1463 | SKIP duration_length {
1464 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1465 skip->set_property ("duration", $2);
1469 | QUOTE STRING duration_length {
1470 SCM tab = THIS->lexer_->lookup_identifier ("musicQuotes");
1472 if (scm_hash_table_p (tab) == SCM_BOOL_T)
1474 SCM key = $2; // use symbol?
1475 evs = scm_hash_ref (tab, key, SCM_BOOL_F);
1478 if (ly_c_vector_p (evs))
1480 quote = MY_MAKE_MUSIC ("QuoteMusic");
1481 quote->set_property ("duration", $3);
1482 quote->set_property ("quoted-events", evs);
1484 THIS->here_input ().warning (_f ("Can\'t find music"));
1485 quote = MY_MAKE_MUSIC ("Event");
1487 quote->set_spot (THIS->here_input ());
1490 | OCTAVE { THIS->push_spot (); }
1492 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1494 $$->set_spot (THIS->pop_spot ());
1495 $$->set_property ("pitch", $3);
1498 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1499 m->set_property ("span-direction", scm_int2num (START));
1500 m->set_spot (THIS->here_input ());
1502 $$ = MY_MAKE_MUSIC ("EventChord");
1503 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1504 scm_gc_unprotect_object (m->self_scm ());
1505 $$->set_spot (THIS->here_input ());
1508 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1509 m->set_property ("span-direction", scm_int2num (STOP));
1510 m->set_spot (THIS->here_input ());
1512 $$ = MY_MAKE_MUSIC ("EventChord");
1513 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1514 $$->set_spot (THIS->here_input ());
1515 scm_gc_unprotect_object (m->self_scm ());
1518 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1519 $$->set_spot (THIS->here_input ());
1522 SCM pipe =THIS->lexer_->lookup_identifier ("pipeSymbol");
1524 if (Music * m = unsmob_music (pipe))
1527 $$ = MY_MAKE_MUSIC ("BarCheck");
1529 $$->set_spot (THIS->here_input ());
1531 | TRANSPOSITION pitch {
1532 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1534 $$->set_spot (THIS-> here_input ());
1535 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1539 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1541 Music *csm = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1543 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED, csm, SCM_EOL);
1544 $$->set_spot (THIS->here_input ());
1545 t->set_spot (THIS->here_input ());
1547 | PARTIAL duration_length {
1548 Moment m = - unsmob_duration ($2)->get_length ();
1549 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1550 p->set_spot (THIS->here_input ());
1551 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1553 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1558 SCM proc = ly_scheme_function ("make-clef-set");
1560 SCM result = scm_call_1 (proc, $2);
1561 scm_gc_protect_object (result);
1562 $$ = unsmob_music (result);
1565 SCM proc= ly_scheme_function ("make-time-signature-set");
1567 SCM result = scm_apply_2 (proc, ly_car ($2), ly_cdr ($2), SCM_EOL);
1568 scm_gc_protect_object (result);
1569 $$ = unsmob_music (result);
1572 SCM proc = ly_scheme_function ("make-mark-set");
1574 SCM result = scm_call_1 (proc, $2);
1575 scm_gc_protect_object (result);
1576 $$ = unsmob_music (result);
1582 $$ = MY_MAKE_MUSIC ("BreathingSignEvent");
1585 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1588 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1595 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1598 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1600 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1601 if (scm_ilength ($3) > 0)
1603 key->set_property ("pitch-alist", $3);
1604 key->set_property ("tonic", Pitch (0,0,0).smobbed_copy ());
1605 ((Music*)key)->transpose (* unsmob_pitch ($2));
1607 THIS->parser_error (_ ("Second argument must be pitch list."));
1618 | post_events post_event {
1619 $2->set_spot (THIS->here_input ());
1620 $$ = scm_cons ($2->self_scm (), $$);
1621 scm_gc_unprotect_object ($2->self_scm ());
1623 | post_events tagged_post_event {
1624 $2 -> set_spot (THIS->here_input ());
1625 $$ = scm_cons ($2->self_scm (), $$);
1626 scm_gc_unprotect_object ($2->self_scm ());
1632 '-' TAG embedded_scm post_event {
1633 tag_music ($4, $3, THIS->here_input ());
1639 direction_less_event {
1643 if (!THIS->lexer_->is_lyric_state ())
1644 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1645 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1648 if (!THIS->lexer_->is_lyric_state ())
1649 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1650 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1652 | script_dir direction_reqd_event {
1654 $2->set_property ("direction", scm_int2num ($1));
1657 | script_dir direction_less_event {
1659 $2->set_property ("direction", scm_int2num ($1));
1662 | string_number_event
1665 string_number_event:
1667 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1668 s->set_property ("string-number", scm_int2num ($1));
1669 s->set_spot (THIS->here_input ());
1675 direction_less_event:
1681 TODO: should take all these defs out of the parser, adn make use
1685 (set-articulation '~ "trill")
1688 Music *m = MY_MAKE_MUSIC ("BeamEvent");
1689 m->set_spot (THIS->here_input ());
1690 m->set_property ("span-direction", scm_int2num (START));
1694 Music *m = MY_MAKE_MUSIC ("BeamEvent");
1695 m->set_spot (THIS->here_input ());
1696 m->set_property ("span-direction", scm_int2num (STOP));
1700 Music *m = MY_MAKE_MUSIC ("TieEvent");
1701 m->set_spot (THIS->here_input ());
1706 dynamic_cast<Music *> ($$)->set_property ("span-direction",
1707 scm_int2num (START));
1711 dynamic_cast<Music *> ($$)->set_property ("span-direction",
1712 scm_int2num (STOP));
1714 | EVENT_IDENTIFIER {
1715 $$ = unsmob_music ($1);
1718 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1719 a->set_spot (THIS->here_input ());
1720 a->set_property ("tremolo-type", scm_int2num ($1));
1725 direction_reqd_event:
1729 | script_abbreviation {
1730 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1731 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1732 if (ly_c_string_p (s))
1733 a->set_property ("articulation-type", s);
1734 else THIS->parser_error (_ ("Expecting string as script definition"));
1740 /**/ { $$ = SCM_EOL; }
1741 | '=' { $$ = scm_int2num (0); }
1742 | '=' sub_quotes { $$ = scm_int2num ($2); }
1743 | '=' sup_quotes { $$ = scm_int2num ($2); }
1768 | NOTENAME_PITCH sup_quotes {
1769 Pitch p = *unsmob_pitch ($1);
1770 p = p.transposed (Pitch ($2,0,0));
1771 $$ = p.smobbed_copy ();
1773 | NOTENAME_PITCH sub_quotes {
1774 Pitch p =* unsmob_pitch ($1);
1775 p = p.transposed (Pitch (-$2,0,0));
1776 $$ = p.smobbed_copy ();
1788 | TONICNAME_PITCH sup_quotes {
1789 Pitch p = *unsmob_pitch ($1);
1790 p = p.transposed (Pitch ($2,0,0));
1791 $$ = p.smobbed_copy ();
1793 | TONICNAME_PITCH sub_quotes {
1794 Pitch p =* unsmob_pitch ($1);
1796 p = p.transposed (Pitch (-$2,0,0));
1797 $$ = p.smobbed_copy ();
1807 pitch_also_in_chords:
1814 Music *s = MY_MAKE_MUSIC ("SlurEvent");
1816 s->set_spot (THIS->here_input ());
1819 Music *s = MY_MAKE_MUSIC ("PhrasingSlurEvent");
1821 s->set_spot (THIS->here_input ());
1824 Music *s = MY_MAKE_MUSIC ("CrescendoEvent");
1826 s->set_spot (THIS->here_input ());
1829 Music *s = MY_MAKE_MUSIC ("DecrescendoEvent");
1831 s->set_spot (THIS->here_input ());
1838 Music *s = MY_MAKE_MUSIC ("CrescendoEvent");
1839 s->set_spot (THIS->here_input ());
1844 Music *s= MY_MAKE_MUSIC ("SlurEvent");
1846 s->set_spot (THIS->here_input ());
1850 Music *s= MY_MAKE_MUSIC ("PhrasingSlurEvent");
1852 s->set_property ("span-type",
1853 scm_makfrom0str ("phrasing-slur"));
1854 s->set_spot (THIS->here_input ());
1860 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1861 t->set_property ("text", $1);
1862 t->set_spot (THIS->here_input ());
1866 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1867 t->set_property ("text",
1868 make_simple_markup (THIS->lexer_->encoding (), $1));
1869 t->set_spot (THIS->here_input ());
1874 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1875 t->set_property ("digit", scm_int2num ($1));
1876 t->set_spot (THIS->here_input ());
1881 script_abbreviation:
1883 $$ = scm_makfrom0str ("Hat");
1886 $$ = scm_makfrom0str ("Plus");
1889 $$ = scm_makfrom0str ("Dash");
1892 $$ = scm_makfrom0str ("Bar");
1895 $$ = scm_makfrom0str ("Larger");
1898 $$ = scm_makfrom0str ("Dot");
1901 $$ = scm_makfrom0str ("Underscore");
1908 | '-' { $$ = CENTER; }
1919 multiplied_duration {
1924 optional_notemode_duration:
1926 Duration dd = THIS->default_duration_;
1927 $$ = dd.smobbed_copy ();
1929 THIS->beam_check ($$);
1931 | multiplied_duration {
1933 THIS->default_duration_ = *unsmob_duration ($$);
1935 THIS->beam_check ($$);
1940 bare_unsigned dots {
1942 if (!is_duration ($1))
1943 THIS->parser_error (_f ("not a duration: %d", $1));
1947 $$ = Duration (len, $2).smobbed_copy ();
1949 | DURATION_IDENTIFIER dots {
1950 Duration *d = unsmob_duration ($1);
1951 Duration k (d->duration_log (), d->dot_count () + $2);
1960 multiplied_duration:
1964 | multiplied_duration '*' bare_unsigned {
1965 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1967 | multiplied_duration '*' FRACTION {
1968 Rational m (ly_scm2int (ly_car ($3)), ly_scm2int (ly_cdr ($3)));
1970 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1975 FRACTION { $$ = $1; }
1976 | UNSIGNED '/' UNSIGNED {
1977 $$ = scm_cons (scm_int2num ($1), scm_int2num ($3));
1995 | ':' bare_unsigned {
1996 if (!is_duration ($2))
1997 THIS->parser_error (_f ("not a duration: %d", $2));
2004 /*****************************************************************
2006 *****************************************************************/
2009 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2012 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2014 | STRING { $$ = $1; }
2025 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2026 $$ = bfr->self_scm ();
2027 scm_gc_unprotect_object ($$);
2030 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2031 $$ = bfr->self_scm ();
2033 bfr->set_property ("figure", $1);
2035 scm_gc_unprotect_object ($$);
2037 | bass_figure bass_mod {
2038 Music *m = unsmob_music ($1);
2040 SCM salter = m->get_property ("alteration");
2041 int alter = ly_c_number_p (salter) ? ly_scm2int (salter) : 0;
2042 m->set_property ("alteration",
2043 scm_int2num (alter + $2));
2045 m->set_property ("alteration", scm_int2num (0));
2053 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2058 | br_bass_figure ']' {
2060 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2068 | figure_list br_bass_figure {
2069 $$ = scm_cons ($2, $1);
2074 FIGURE_OPEN figure_list FIGURE_CLOSE {
2075 Music *m = MY_MAKE_MUSIC ("EventChord");
2076 $2 = scm_reverse_x ($2, SCM_EOL);
2077 m->set_property ("elements", $2);
2078 $$ = m->self_scm ();
2089 pitch exclamations questions oct_check optional_notemode_duration optional_rest {
2091 Input i = THIS->pop_spot ();
2092 if (!THIS->lexer_->is_note_state ())
2093 THIS->parser_error (_ ("Have to be in Note mode for notes"));
2097 n = MY_MAKE_MUSIC ("RestEvent");
2099 n = MY_MAKE_MUSIC ("NoteEvent");
2101 n->set_property ("pitch", $1);
2102 n->set_property ("duration", $5);
2104 if (ly_c_number_p ($4))
2106 int q = ly_scm2int ($4);
2107 n->set_property ("absolute-octave", scm_int2num (q-1));
2111 n->set_property ("cautionary", SCM_BOOL_T);
2112 if ($2 % 2 || $3 % 2)
2113 n->set_property ("force-accidental", SCM_BOOL_T);
2115 Music *v = MY_MAKE_MUSIC ("EventChord");
2116 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2117 scm_gc_unprotect_object (n->self_scm ());
2123 | DRUM_PITCH optional_notemode_duration {
2124 Input i = THIS->pop_spot ();
2126 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2127 n->set_property ("duration", $2);
2128 n->set_property ("drum-type", $1);
2130 Music *v = MY_MAKE_MUSIC ("EventChord");
2131 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2132 scm_gc_unprotect_object (n->self_scm ());
2138 | figure_spec optional_notemode_duration {
2139 Music *m = unsmob_music ($1);
2140 Input i = THIS->pop_spot ();
2142 for (SCM s = m->get_property ("elements"); ly_c_pair_p (s); s = ly_cdr (s))
2144 unsmob_music (ly_car (s))->set_property ("duration", $2);
2148 | RESTNAME optional_notemode_duration {
2150 Input i = THIS->pop_spot ();
2152 if (ly_scm2string ($1) == "s") {
2154 ev = MY_MAKE_MUSIC ("SkipEvent");
2157 ev = MY_MAKE_MUSIC ("RestEvent");
2160 ev->set_property ("duration", $2);
2162 Music *velt = MY_MAKE_MUSIC ("EventChord");
2163 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2166 scm_gc_unprotect_object (ev->self_scm ());
2170 | MULTI_MEASURE_REST optional_notemode_duration {
2173 SCM proc = ly_scheme_function ("make-multi-measure-rest");
2174 SCM mus = scm_call_2 (proc, $2,
2175 make_input (THIS->here_input ()));
2176 scm_gc_protect_object (mus);
2177 $$ = unsmob_music (mus);
2180 | lyric_element optional_notemode_duration {
2181 Input i = THIS->pop_spot ();
2182 if (!THIS->lexer_->is_lyric_state ())
2183 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
2185 Music *lreq = MY_MAKE_MUSIC ("LyricEvent");
2186 lreq->set_property ("text", $1);
2187 lreq->set_property ("duration",$2);
2189 Music *velt = MY_MAKE_MUSIC ("EventChord");
2190 velt->set_property ("elements", scm_list_1 (lreq->self_scm ()));
2197 if (!THIS->lexer_->is_chord_state ())
2198 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
2199 $$ = unsmob_music ($1);
2204 /* FIXME: lyric flavoured markup would be better */
2212 steno_tonic_pitch optional_notemode_duration {
2213 $$ = make_chord ($1, $2, SCM_EOL);
2215 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2216 SCM its = scm_reverse_x ($4, SCM_EOL);
2217 $$ = make_chord ($1, $2, scm_cons ($3, its));
2225 | chord_items chord_item {
2226 $$ = scm_cons ($2, $$);
2232 $$ = ly_symbol2scm ("chord-colon");
2235 $$ = ly_symbol2scm ("chord-caret");
2237 | CHORD_SLASH steno_tonic_pitch {
2238 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2240 | CHORD_BASS steno_tonic_pitch {
2241 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2250 $$ = scm_reverse_x ($1, SCM_EOL);
2258 step_number { $$ = scm_cons ($1, SCM_EOL); }
2259 | step_numbers '.' step_number {
2260 $$ = scm_cons ($3, $$);
2266 $$ = make_chord_step ($1, 0);
2268 | bare_unsigned '+' {
2269 $$ = make_chord_step ($1, SHARP);
2271 | bare_unsigned CHORD_MINUS {
2272 $$ = make_chord_step ($1, FLAT);
2279 TODO: should deprecate in favor of Scheme?
2283 number_expression '+' number_term {
2284 $$ = scm_sum ($1, $3);
2286 | number_expression '-' number_term {
2287 $$ = scm_difference ($1, $3);
2296 | number_factor '*' number_factor {
2297 $$ = scm_product ($1, $3);
2299 | number_factor '/' number_factor {
2300 $$ = scm_divide ($1, $3);
2305 '-' number_factor { /* %prec UNARY_MINUS */
2306 $$ = scm_difference ($2, SCM_UNDEFINED);
2314 $$ = scm_int2num ($1);
2319 | NUMBER_IDENTIFIER {
2322 | REAL NUMBER_IDENTIFIER {
2323 $$ = scm_make_real (ly_scm2double ($1) *ly_scm2double ($2));
2325 | UNSIGNED NUMBER_IDENTIFIER {
2326 $$ = scm_make_real ($1 *ly_scm2double ($2));
2342 if (scm_integer_p ($1) == SCM_BOOL_T)
2344 int k = ly_scm2int ($1);
2348 THIS->parser_error (_ ("need integer number arg"));
2362 | STRING_IDENTIFIER {
2365 | string '+' string {
2366 $$ = scm_string_append (scm_list_2 ($1, $3));
2373 | exclamations '!' { $$ ++; }
2378 | questions '?' { $$ ++; }
2388 { THIS->lexer_->push_markup_state (); }
2391 THIS->lexer_->pop_state ();
2397 This should be done more dynamically if possible.
2401 $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
2403 | MARKUP_HEAD_EMPTY {
2404 $$ = scm_list_1 ($1);
2406 | MARKUP_HEAD_MARKUP0 markup {
2407 $$ = scm_list_2 ($1, $2);
2409 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2410 $$ = scm_list_3 ($1, $2, $3);
2412 | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
2413 $$ = scm_list_3 ($1, $2, $3);
2418 | MARKUP_HEAD_LIST0 markup_list {
2419 $$ = scm_list_2 ($1,$2);
2421 | MARKUP_HEAD_SCM0 embedded_scm {
2422 $$ = scm_list_2 ($1, $2);
2424 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
2425 $$ = scm_list_4 ($1, $2, $3, $4);
2427 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2428 $$ = scm_list_4 ($1, $2, $3, $4);
2430 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2431 $$ = scm_list_3 ($1, $2, $3);
2433 | MARKUP_IDENTIFIER {
2436 | STRING_IDENTIFIER {
2442 chord_open markup_list_body chord_close { $$ = scm_reverse_x ($2, SCM_EOL); }
2446 '{' markup_list_body '}' {
2447 SCM line = ly_scheme_function ("line-markup");
2449 $$ = scm_list_2 (line, scm_reverse_x ($2, SCM_EOL));
2454 /**/ { $$ = SCM_EOL; }
2455 | markup_list_body markup {
2456 $$ = scm_cons ($2, $1);
2464 My_lily_parser::set_yydebug (bool )
2472 My_lily_parser::do_yyparse ()
2474 yyparse ((void*)this);
2479 Should make this optional? It will also complain when you do
2483 which is entirely legitimate.
2485 Or we can scrap it. Barchecks should detect wrong durations, and
2486 skipTypesetting speeds it up a lot.
2490 My_lily_parser::beam_check (SCM dur)
2492 Duration *d = unsmob_duration (dur);
2493 if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2495 Music *m = unsmob_music (last_beam_start_);
2496 m->origin ()->warning (_ ("Suspect duration found following this beam"));
2498 last_beam_start_ = SCM_EOL;
2506 It is a little strange to have this function in this file, but
2507 otherwise, we have to import music classes into the lexer.
2511 My_lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2513 if (ly_c_string_p (sid)) {
2515 return STRING_IDENTIFIER;
2516 } else if (ly_c_number_p (sid)) {
2518 return NUMBER_IDENTIFIER;
2519 } else if (unsmob_context_def (sid)) {
2520 *destination = unsmob_context_def (sid)->clone_scm ();
2521 return CONTEXT_DEF_IDENTIFIER;
2522 } else if (unsmob_score (sid)) {
2523 Score *score = new Score (*unsmob_score (sid));
2524 *destination = score->self_scm ();
2525 return SCORE_IDENTIFIER;
2526 } else if (Music *mus = unsmob_music (sid)) {
2527 mus = mus->clone ();
2528 *destination = mus->self_scm ();
2529 unsmob_music (*destination)->
2530 set_property ("origin", make_input (last_input_));
2531 return dynamic_cast<Event*> (mus)
2532 ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2533 } else if (unsmob_duration (sid)) {
2534 *destination = unsmob_duration (sid)->smobbed_copy ();
2535 return DURATION_IDENTIFIER;
2536 } else if (unsmob_music_output_def (sid)) {
2537 Music_output_def *p = unsmob_music_output_def (sid);
2540 *destination = p->self_scm ();
2541 return MUSIC_OUTPUT_DEF_IDENTIFIER;
2542 } else if (Text_item::markup_p (sid)) {
2544 return MARKUP_IDENTIFIER;
2551 property_op_to_music (SCM op)
2554 SCM tag = ly_car (op);
2555 SCM symbol = ly_cadr (op);
2556 SCM args = ly_cddr (op);
2557 SCM grob_val = SCM_UNDEFINED;
2558 SCM grob_sym = SCM_UNDEFINED;
2559 SCM val = SCM_UNDEFINED;
2561 if (tag == ly_symbol2scm ("assign"))
2563 m = MY_MAKE_MUSIC ("PropertySet");
2564 val = ly_car (args);
2566 else if (tag == ly_symbol2scm ("unset"))
2567 m = MY_MAKE_MUSIC ("PropertyUnset");
2568 else if (tag == ly_symbol2scm ("poppush")
2569 || tag == ly_symbol2scm ("push"))
2571 m = MY_MAKE_MUSIC ("OverrideProperty");
2572 grob_sym = ly_car (args);
2573 grob_val = ly_cadr (args);
2575 else if (tag == ly_symbol2scm ("pop")) {
2576 m = MY_MAKE_MUSIC ("RevertProperty");
2577 grob_sym = ly_car (args);
2580 m->set_property ("symbol", symbol);
2582 if (val != SCM_UNDEFINED)
2583 m->set_property ("value", val);
2584 if (grob_val != SCM_UNDEFINED)
2585 m->set_property ("grob-value", grob_val);
2587 if (grob_sym != SCM_UNDEFINED)
2589 bool itc = internal_type_checking_global_b;
2592 bool autobeam = ly_c_equal_p (symbol, ly_symbol2scm ("autoBeamSettings"));
2594 internal_type_checking_global_b = false;
2595 m->set_property ("grob-property", grob_sym);
2597 internal_type_checking_global_b = itc;
2600 if (op == ly_symbol2scm ("poppush"))
2601 m->set_property ("pop-first", SCM_BOOL_T);
2608 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2610 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2612 csm->set_property ("element", m->self_scm ());
2613 scm_gc_unprotect_object (m->self_scm ());
2615 csm->set_property ("context-type",
2616 ly_c_symbol_p (type) ? type : scm_string_to_symbol (type));
2617 csm->set_property ("property-operations", ops);
2619 if (ly_c_string_p (id))
2620 csm->set_property ("context-id", id);
2626 get_next_unique_context ()
2628 static int new_context_count;
2631 snprintf (s, 1024, "uniqueContext%d", new_context_count ++);
2633 return scm_makfrom0str (s);