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);
87 is_regular_identifier (SCM id)
89 String str = ly_scm2string (id);
90 char const *s = str.to_str0 ();
99 v = v && isalnum (*s);
106 make_simple_markup (SCM encoding, SCM a)
108 SCM simple = ly_scheme_function ("simple-markup");
109 if (ly_c_symbol_p (encoding))
110 return scm_list_3 (ly_scheme_function ("encoded-simple-markup"),
112 return scm_list_2 (simple, a);
118 return t && t == 1 << intlog2 (t);
122 set_music_properties (Music *p, SCM a)
124 for (SCM k = a; ly_c_pair_p (k); k = ly_cdr (k))
125 p->internal_set_property (ly_caar (k), ly_cdar (k));
129 make_chord_step (int step, int alter)
136 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
137 return m.smobbed_copy ();
142 make_chord (SCM pitch, SCM dur, SCM modification_list)
144 SCM chord_ctor = ly_scheme_function ("construct-chord");
145 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
146 scm_gc_protect_object (ch);
150 /* Todo: actually also use apply iso. call too ... */
152 ly_input_procedure_p (SCM x)
154 return ly_c_procedure_p (x)
155 || (ly_c_pair_p (x) && ly_c_procedure_p (ly_car (x)));
159 set_property_music (SCM sym, SCM value)
161 Music *p = MY_MAKE_MUSIC ("PropertySet");
162 p->set_property ("symbol", sym);
163 p->set_property ("value", value);
168 make_music_relative (Pitch start, Music *music)
170 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
171 relative->set_property ("element", music->self_scm ());
173 Pitch last = music->to_relative_octave (start);
174 if (lily_1_8_relative)
175 music->set_property ("last-pitch", last.smobbed_copy ());
180 make_lyric_combine_music (SCM name, Music *music)
182 Music *combine = MY_MAKE_MUSIC ("NewLyricCombineMusic");
183 combine->set_property ("element", music->self_scm ());
184 combine->set_property ("associated-context", name);
190 /* We use SCMs to do strings, because it saves us the trouble of
191 deleting them. Let's hope that a stack overflow doesnt trigger a move
192 of the parse stack onto the heap. */
197 Music_output_def *outputdef;
207 yylex (YYSTYPE *s, void *v)
209 My_lily_parser *pars = (My_lily_parser*) v;
210 My_lily_lexer *lex = pars->lexer_;
212 lex->lexval = (void*) s;
213 lex->prepare_for_next_token ();
214 return lex->yylex ();
223 Three shift/reduce problems:
225 2. \markup identifier.
230 \repeat .. \alternative
233 \repeat { \repeat .. \alternative }
237 \repeat { \repeat } \alternative
259 %token CHORDMODIFIERS
264 %token COMMANDSPANREQUEST
273 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
274 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
278 %token GROBDESCRIPTIONS
287 %token MULTI_MEASURE_REST
293 %token OVERRIDE SET REVERT
319 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
320 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
322 %token <i> E_UNSIGNED
323 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH
326 %type <book> book_block book_body
327 %type <i> exclamations questions dots optional_rest
329 %type <scm> grace_head
330 %type <scm> oct_check
331 %type <scm> context_mod_list
332 %type <scm> lyric_element
333 %type <scm> bass_number br_bass_figure bass_figure figure_list figure_spec
335 %token <scm> NOTENAME_PITCH
336 %token <scm> TONICNAME_PITCH
337 %token <scm> CHORDMODIFIER_PITCH
338 %token <scm> DURATION_IDENTIFIER
339 %token <scm> FRACTION
340 %token <id> IDENTIFIER
342 %token <scm> DRUM_PITCH
343 %token <scm> CHORD_MODIFIER
344 %token <scm> SCORE_IDENTIFIER
345 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
346 %token <scm> NUMBER_IDENTIFIER
347 %token <scm> EVENT_IDENTIFIER
348 %token <scm> MUSIC_IDENTIFIER CONTEXT_DEF_IDENTIFIER
349 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
350 %token <scm> RESTNAME
357 %token <scm> MARKUP_HEAD_MARKUP0
358 %token <scm> MARKUP_HEAD_EMPTY
359 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
360 %token <scm> MARKUP_HEAD_SCM0
361 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
362 %token <scm> MARKUP_HEAD_SCM0_SCM1
363 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
364 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
366 %token <scm> MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
367 %type <scm> markup markup_line markup_list markup_list_body full_markup
369 %type <outputdef> output_def
370 %type <scm> lilypond_header lilypond_header_body
371 %type <music> open_event close_event
372 %type <i> sub_quotes sup_quotes
373 %type <music> toplevel_music
374 %type <music> simple_element event_chord command_element
375 %type <music> Composite_music Simple_music
376 %type <music> Repeated_music
377 %type <scm> Alternative_music
378 %type <i> tremolo_type
379 %type <i> bare_int bare_unsigned
381 %type <scm> identifier_init
382 %type <scm> simple_string
384 %type <music> note_chord_element chord_body chord_body_element
385 %type <scm> chord_body_elements
386 %type <scm> steno_duration optional_notemode_duration multiplied_duration
388 %type <scm> post_events
389 %type <music> gen_text_def direction_less_event direction_reqd_event
390 %type <scm> steno_pitch pitch absolute_pitch pitch_also_in_chords
391 %type <scm> steno_tonic_pitch
392 %type <scm> duration_length fraction
394 %type <scm> new_chord step_number chord_items chord_item chord_separator step_numbers
396 %type <scm> embedded_scm scalar
397 %type <music> Music Sequential_music Simultaneous_music
398 %type <music> relative_music re_rhythmed_music
399 %type <music> music_property_def context_change
400 %type <scm> context_prop_spec
401 %type <scm> Music_list
402 %type <scm> property_operation context_mod context_def_mod optional_context_mod
403 %type <outputdef> music_output_def_body music_output_def_head
404 %type <music> post_event tagged_post_event
405 %type <music> command_req
406 %type <music> string_number_event
407 %type <scm> string bare_number number_expression number_term number_factor
408 %type <score> score_block score_body
410 %type <scm> context_def_spec_block context_def_spec_body
411 %type <music> tempo_event
412 %type <scm> script_abbreviation
418 /* We don't assign precedence to / and *, because we might need varied
419 prec levels in different prods */
425 lilypond: /* empty */
427 | lilypond toplevel_expression {}
428 | lilypond assignment { }
430 THIS->error_level_ = 1;
433 THIS->error_level_ = 1;
441 | toplevel_music EOI {
442 Score *score = new Score;
443 SCM s = $1->self_scm ();
447 = ly_scheme_function ("toplevel-music-functions");
448 for (; ly_c_pair_p (check_funcs);
449 check_funcs = ly_cdr (check_funcs))
450 s = scm_call_1 (ly_car (check_funcs), s);
453 Book *book = new Book;
454 book->scores_.push (score);
456 scm_gc_unprotect_object (score->self_scm ());
458 SCM header = THIS->header_;
459 Path outname = split_path (THIS->output_basename_);
460 int *c = &THIS->book_count_;
462 outname.base += "-" + to_string (*c);
464 Music_output_def *dp = unsmob_music_output_def
465 (THIS->lexer_->lookup_identifier ("$defaultpaper"));
466 book->process (outname.to_string (),
467 dp ? dp->clone () : new Paper_def, header);
468 scm_gc_unprotect_object (book->self_scm ());
475 SCM header = THIS->header_;
476 Path outname = split_path (THIS->output_basename_);
477 int *c = &THIS->book_count_;
479 outname.base += "-" + to_string (*c);
481 Music_output_def *dp = unsmob_music_output_def
482 (THIS->lexer_->lookup_identifier ("$defaultpaper"));
483 book->process (outname.to_string (),
484 dp ? dp->clone () : new Paper_def, header);
485 scm_gc_unprotect_object (book->self_scm ());
488 /* TODO: implicit book, depending on --no-book/--no-page-layout
491 SCM head = is_module (score->header_) ? score->header_
492 : THIS->header_.to_SCM ();
494 Path p = split_path (THIS->output_basename_);
495 int *c = &THIS->score_count_;
497 p.base += "-" + to_string (*c);
500 SCM outname = scm_makfrom0str (p.to_string ().to_str0());
502 for (int i = 0; i < score->defs_.size (); i++)
503 default_rendering (score->music_,
504 score->defs_[i]->self_scm (), head,
507 if (score->defs_.is_empty ())
509 Music_output_def *id = unsmob_music_output_def
510 (THIS->lexer_->lookup_identifier ("$defaultpaper"));
511 id = id ? id->clone () : new Paper_def;
512 default_rendering (score->music_, id->self_scm (), head,
514 scm_gc_unprotect_object (id->self_scm ());
516 scm_gc_unprotect_object (score->self_scm ());
520 if (dynamic_cast<Paper_def*> ($1))
521 id = scm_makfrom0str ("$defaultpaper");
522 else if (dynamic_cast<Midi_def*> ($1))
523 id = scm_makfrom0str ("$defaultmidi");
524 THIS->lexer_->set_identifier (id, $1->self_scm ());
525 scm_gc_unprotect_object ($1->self_scm ());
540 lilypond_header_body:
542 $$ = ly_make_anonymous_module ();
543 THIS->lexer_->add_scope ($$);
545 | lilypond_header_body assignment {
551 HEADER '{' lilypond_header_body '}' {
552 $$ = THIS->lexer_->remove_scope ();
564 /* cont */ '=' identifier_init {
567 Should find generic way of associating input with objects.
569 Input ip = THIS->pop_spot ();
571 if (! is_regular_identifier ($1))
573 ip.warning (_ ("Identifier should have alphabetic characters only"));
576 THIS->lexer_->set_identifier ($1, $4);
579 TODO: devise standard for protection in parser.
581 The parser stack lives on the C-stack, which means that
582 all objects can be unprotected as soon as they're here.
592 $$ = $1->self_scm ();
593 scm_gc_unprotect_object ($$);
599 $$ = $1->self_scm ();
600 scm_gc_unprotect_object ($$);
602 | context_def_spec_block {
606 $$ = $1->self_scm ();
607 scm_gc_unprotect_object ($$);
610 $$ = $1->self_scm ();
611 scm_gc_unprotect_object ($$);
613 | number_expression {
624 context_def_spec_block:
625 CONTEXT '{' context_def_spec_body '}'
631 context_def_spec_body:
633 $$ = Context_def::make_scm ();
634 unsmob_context_def ($$)->set_spot (THIS->here_input ());
636 | CONTEXT_DEF_IDENTIFIER {
638 unsmob_context_def ($$)->set_spot (THIS->here_input ());
640 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
641 Context_def*td = unsmob_context_def ($$);
643 for (SCM p = $3; ly_c_pair_p (p); p = ly_cdr (p)) {
644 SCM tag = ly_caar (p);
646 /* TODO: should make new tag "grob-definition" ? */
647 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
648 tag, scm_cons (ly_cdar (p), SCM_EOL)));
651 | context_def_spec_body context_mod {
652 unsmob_context_def ($$)->add_context_mod ($2);
660 /*cont*/ '{' book_body '}' {
669 $$->set_spot (THIS->here_input ());
671 | book_body score_block {
672 $$->scores_.push ($2);
673 scm_gc_unprotect_object ($2->self_scm ());
683 /*cont*/ '{' score_body '}' {
693 $$->set_spot (THIS->here_input ());
694 SCM m = $1->self_scm ();
695 scm_gc_unprotect_object (m);
700 SCM check_funcs = ly_scheme_function ("toplevel-music-functions");
701 for (; ly_c_pair_p (check_funcs); check_funcs = ly_cdr (check_funcs))
702 m = scm_call_1 (ly_car (check_funcs), m);
707 $$ = new Score ( *unsmob_score ($1));
708 $$->set_spot (THIS->here_input ());
710 | score_body lilypond_header {
713 | score_body output_def {
715 scm_gc_unprotect_object ($2->self_scm ());
727 music_output_def_body '}' {
729 THIS->lexer_->remove_scope ();
730 THIS->lexer_->pop_state ();
734 music_output_def_head:
736 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
741 p = dynamic_cast<Midi_def*> (id->clone ());
746 THIS->lexer_->add_scope (p->scope_);
749 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
752 p = dynamic_cast<Paper_def*> (id->clone ());
756 THIS->lexer_->add_scope (p->scope_);
762 music_output_def_body:
763 music_output_def_head '{' {
765 $$->input_origin_. set_spot (THIS->here_input ());
766 THIS->lexer_->push_initial_state ();
768 | music_output_def_head '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
769 scm_gc_unprotect_object ($1->self_scm ());
770 Music_output_def *o = unsmob_music_output_def ($3);
771 o->input_origin_.set_spot (THIS->here_input ());
773 THIS->lexer_->remove_scope ();
774 THIS->lexer_->add_scope (o->scope_);
775 THIS->lexer_->push_initial_state ();
777 | music_output_def_body assignment {
780 | music_output_def_body context_def_spec_block {
781 $$->assign_context_def ($2);
783 | music_output_def_body tempo_event {
785 junk this ? there already is tempo stuff in
788 int m = ly_scm2int ( $2->get_property ("metronome-count"));
789 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
790 Midi_def *md = dynamic_cast<Midi_def*> ($$);
792 md->set_tempo (d->get_length (), m);
793 scm_gc_unprotect_object ($2->self_scm ());
795 | music_output_def_body error {
801 TEMPO steno_duration '=' bare_unsigned {
802 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
803 $$->set_property ("tempo-unit", $2);
804 $$->set_property ("metronome-count", scm_int2num ( $4));
809 The representation of a list is the
813 to have efficient append.
817 $$ = scm_cons (SCM_EOL, SCM_EOL);
821 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
822 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
823 if (ly_c_pair_p (ly_cdr (s)))
824 scm_set_cdr_x (ly_cdr (s), c); /* append */
826 scm_set_car_x (s, c); /* set first cons */
827 scm_set_cdr_x (s, c); /* remember last cell */
843 | ALTERNATIVE '{' 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 { THIS->lexer_->push_lyric_state (); }
1187 THIS->lexer_->pop_state ();
1190 SCM name = scm_makfrom0str ("");
1191 Music *combined = make_lyric_combine_music (name, music);
1192 SCM context = scm_makfrom0str ("Lyrics");
1193 $$ = context_spec_music (context, SCM_UNDEFINED, combined,
1195 scm_gc_unprotect_object (music->self_scm ());
1197 | LYRICSTO string Music {
1200 $$ = make_lyric_combine_music (name, music);
1201 scm_gc_unprotect_object (music->self_scm ());
1206 CHANGE STRING '=' STRING {
1207 Music*t= MY_MAKE_MUSIC ("ContextChange");
1208 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1209 t-> set_property ("change-to-id", $4);
1212 $$->set_spot (THIS->here_input ());
1216 simple_string: STRING {
1224 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1225 scm_string_to_symbol ($1), $3);
1227 | UNSET simple_string {
1228 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1229 scm_string_to_symbol ($2));
1231 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1232 $$ = scm_list_4 (ly_symbol2scm ("push"),
1233 scm_string_to_symbol ($2), $3, $5);
1235 | REVERT simple_string embedded_scm {
1236 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1237 scm_string_to_symbol ($2), $3);
1242 CONSISTSEND { $$ = ly_symbol2scm ("consists-end"); }
1243 | CONSISTS { $$ = ly_symbol2scm ("consists"); }
1244 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1246 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1247 | DENIES { $$ = ly_symbol2scm ("denies"); }
1249 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1250 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1251 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1252 | NAME { $$ = ly_symbol2scm ("context-name"); }
1256 property_operation { $$ = $1; }
1257 | context_def_mod STRING {
1258 $$ = scm_list_2 ($1, $2);
1264 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1265 scm_string_to_symbol ($1));
1267 | simple_string '.' simple_string {
1268 $$ = scm_list_2 (scm_string_to_symbol ($1),
1269 scm_string_to_symbol ($3));
1274 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1275 $$ = property_op_to_music (scm_list_4 (
1276 ly_symbol2scm ("poppush"),
1279 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1281 | REVERT context_prop_spec embedded_scm {
1282 $$ = property_op_to_music (scm_list_3 (
1283 ly_symbol2scm ("pop"),
1287 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1289 | SET context_prop_spec '=' scalar {
1290 $$ = property_op_to_music (scm_list_3 (
1291 ly_symbol2scm ("assign"),
1294 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1296 | UNSET context_prop_spec {
1297 $$ = property_op_to_music (scm_list_2 (
1298 ly_symbol2scm ("unset"),
1300 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1302 | ONCE music_property_def {
1303 SCM e = $2->get_property ("element");
1304 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1314 | bare_int { $$ = scm_int2num ($1); }
1315 | embedded_scm { $$ = $1; }
1316 | full_markup { $$ = $1; }
1317 | DIGIT { $$ = scm_int2num ($1); }
1323 Adding pre_events to the simple_element
1324 makes the choice between
1330 simple_element: STRING
1332 a single shift/reduction conflict.
1334 nevertheless, this is not very clean, and we should find a different
1344 pre_events simple_element post_events {
1345 SCM elts = $2-> get_property ("elements");
1347 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1349 $2->set_property ("elements", elts);
1353 | note_chord_element
1358 chord_body optional_notemode_duration post_events
1360 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1361 SCM es = $1->get_property ("elements");
1362 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1364 for (SCM s = es; ly_c_pair_p (s); s = ly_cdr (s))
1365 unsmob_music (ly_car (s))->set_property ("duration", dur);
1366 es = ly_append2 (es, postevs);
1368 $1-> set_property ("elements", es);
1379 simul_open: LESSLESS
1382 simul_close: MOREMORE
1386 chord_open chord_body_elements chord_close
1388 $$ = MY_MAKE_MUSIC ("EventChord");
1389 $$->set_property ("elements",
1390 scm_reverse_x ($2, SCM_EOL));
1394 chord_body_elements:
1395 /* empty */ { $$ = SCM_EOL; }
1396 | chord_body_elements chord_body_element {
1397 $$ = scm_cons ($2->self_scm (), $1);
1398 scm_gc_unprotect_object ($2->self_scm ());
1403 pitch exclamations questions post_events
1405 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1406 n->set_property ("pitch", $1);
1408 n->set_property ("cautionary", SCM_BOOL_T);
1409 if ($2 % 2 || $3 % 2)
1410 n->set_property ("force-accidental", SCM_BOOL_T);
1412 if (ly_c_pair_p ($4)) {
1413 SCM arts = scm_reverse_x ($4, SCM_EOL);
1414 n->set_property ("articulations", arts);
1418 | DRUM_PITCH post_events {
1419 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1420 n->set_property ("duration", $2);
1421 n->set_property ("drum-type", $1);
1422 n->set_spot (THIS->here_input ());
1424 if (ly_c_pair_p ($2)) {
1425 SCM arts = scm_reverse_x ($2, SCM_EOL);
1426 n->set_property ("articulations", arts);
1433 ADDQUOTE string Music {
1434 SCM adder = ly_scheme_function ("add-quotable");
1436 scm_call_2 (adder, $2, $3->self_scm ());
1437 scm_gc_unprotect_object ($3->self_scm ());
1443 $$ = MY_MAKE_MUSIC ("EventChord");
1444 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1445 scm_gc_unprotect_object ($1->self_scm ());
1447 $$-> set_spot (THIS->here_input ());
1448 $1-> set_spot (THIS->here_input ());
1450 | SKIP duration_length {
1451 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1452 skip->set_property ("duration", $2);
1456 | QUOTE STRING duration_length {
1457 SCM tab = THIS->lexer_->lookup_identifier ("musicQuotes");
1459 if (scm_hash_table_p (tab) == SCM_BOOL_T)
1461 SCM key = $2; // use symbol?
1462 evs = scm_hash_ref (tab, key, SCM_BOOL_F);
1465 if (ly_c_vector_p (evs))
1467 quote = MY_MAKE_MUSIC ("QuoteMusic");
1468 quote->set_property ("duration", $3);
1469 quote->set_property ("quoted-events", evs);
1471 THIS->here_input ().warning (_f ("Can\'t find music"));
1472 quote = MY_MAKE_MUSIC ("Event");
1474 quote->set_spot (THIS->here_input ());
1477 | OCTAVE { THIS->push_spot (); }
1479 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1481 $$->set_spot (THIS->pop_spot ());
1482 $$->set_property ("pitch", $3);
1485 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1486 m->set_property ("span-direction", scm_int2num (START));
1487 m->set_spot (THIS->here_input ());
1489 $$ = MY_MAKE_MUSIC ("EventChord");
1490 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1491 scm_gc_unprotect_object (m->self_scm ());
1492 $$->set_spot (THIS->here_input ());
1495 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1496 m->set_property ("span-direction", scm_int2num (STOP));
1497 m->set_spot (THIS->here_input ());
1499 $$ = MY_MAKE_MUSIC ("EventChord");
1500 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1501 $$->set_spot (THIS->here_input ());
1502 scm_gc_unprotect_object (m->self_scm ());
1505 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1506 $$->set_spot (THIS->here_input ());
1509 SCM pipe =THIS->lexer_->lookup_identifier ("pipeSymbol");
1511 if (Music * m = unsmob_music (pipe))
1514 $$ = MY_MAKE_MUSIC ("BarCheck");
1516 $$->set_spot (THIS->here_input ());
1518 | TRANSPOSITION pitch {
1519 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1521 $$->set_spot (THIS-> here_input ());
1522 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1526 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1528 Music *csm = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1530 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED, csm, SCM_EOL);
1531 $$->set_spot (THIS->here_input ());
1532 t->set_spot (THIS->here_input ());
1534 | PARTIAL duration_length {
1535 Moment m = - unsmob_duration ($2)->get_length ();
1536 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1537 p->set_spot (THIS->here_input ());
1538 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1540 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1545 SCM proc = ly_scheme_function ("make-clef-set");
1547 SCM result = scm_call_1 (proc, $2);
1548 scm_gc_protect_object (result);
1549 $$ = unsmob_music (result);
1552 SCM proc= ly_scheme_function ("make-time-signature-set");
1554 SCM result = scm_apply_2 (proc, ly_car ($2), ly_cdr ($2), SCM_EOL);
1555 scm_gc_protect_object (result);
1556 $$ = unsmob_music (result);
1559 SCM proc = ly_scheme_function ("make-mark-set");
1561 SCM result = scm_call_1 (proc, $2);
1562 scm_gc_protect_object (result);
1563 $$ = unsmob_music (result);
1569 $$ = MY_MAKE_MUSIC ("BreathingSignEvent");
1572 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1575 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1582 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1585 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1587 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1588 if (scm_ilength ($3) > 0)
1590 key->set_property ("pitch-alist", $3);
1591 key->set_property ("tonic", Pitch (0,0,0).smobbed_copy ());
1592 ((Music*)key)->transpose (* unsmob_pitch ($2));
1594 THIS->parser_error (_ ("Second argument must be pitch list."));
1605 | post_events post_event {
1606 $2->set_spot (THIS->here_input ());
1607 $$ = scm_cons ($2->self_scm (), $$);
1608 scm_gc_unprotect_object ($2->self_scm ());
1610 | post_events tagged_post_event {
1611 $2 -> set_spot (THIS->here_input ());
1612 $$ = scm_cons ($2->self_scm (), $$);
1613 scm_gc_unprotect_object ($2->self_scm ());
1619 '-' TAG embedded_scm post_event {
1620 tag_music ($4, $3, THIS->here_input ());
1626 direction_less_event {
1630 if (!THIS->lexer_->is_lyric_state ())
1631 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1632 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1635 if (!THIS->lexer_->is_lyric_state ())
1636 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1637 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1639 | script_dir direction_reqd_event {
1641 $2->set_property ("direction", scm_int2num ($1));
1644 | script_dir direction_less_event {
1646 $2->set_property ("direction", scm_int2num ($1));
1649 | string_number_event
1652 string_number_event:
1654 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1655 s->set_property ("string-number", scm_int2num ($1));
1656 s->set_spot (THIS->here_input ());
1662 direction_less_event:
1668 TODO: should take all these defs out of the parser, adn make use
1672 (set-articulation '~ "trill")
1675 Music *m = MY_MAKE_MUSIC ("BeamEvent");
1676 m->set_spot (THIS->here_input ());
1677 m->set_property ("span-direction", scm_int2num (START));
1681 Music *m = MY_MAKE_MUSIC ("BeamEvent");
1682 m->set_spot (THIS->here_input ());
1683 m->set_property ("span-direction", scm_int2num (STOP));
1687 Music *m = MY_MAKE_MUSIC ("TieEvent");
1688 m->set_spot (THIS->here_input ());
1693 dynamic_cast<Music *> ($$)->set_property ("span-direction",
1694 scm_int2num (START));
1698 dynamic_cast<Music *> ($$)->set_property ("span-direction",
1699 scm_int2num (STOP));
1701 | EVENT_IDENTIFIER {
1702 $$ = unsmob_music ($1);
1705 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1706 a->set_spot (THIS->here_input ());
1707 a->set_property ("tremolo-type", scm_int2num ($1));
1712 direction_reqd_event:
1716 | script_abbreviation {
1717 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1718 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1719 if (ly_c_string_p (s))
1720 a->set_property ("articulation-type", s);
1721 else THIS->parser_error (_ ("Expecting string as script definition"));
1727 /**/ { $$ = SCM_EOL; }
1728 | '=' { $$ = scm_int2num (0); }
1729 | '=' sub_quotes { $$ = scm_int2num ($2); }
1730 | '=' sup_quotes { $$ = scm_int2num ($2); }
1755 | NOTENAME_PITCH sup_quotes {
1756 Pitch p = *unsmob_pitch ($1);
1757 p = p.transposed (Pitch ($2,0,0));
1758 $$ = p.smobbed_copy ();
1760 | NOTENAME_PITCH sub_quotes {
1761 Pitch p =* unsmob_pitch ($1);
1762 p = p.transposed (Pitch (-$2,0,0));
1763 $$ = p.smobbed_copy ();
1775 | TONICNAME_PITCH sup_quotes {
1776 Pitch p = *unsmob_pitch ($1);
1777 p = p.transposed (Pitch ($2,0,0));
1778 $$ = p.smobbed_copy ();
1780 | TONICNAME_PITCH sub_quotes {
1781 Pitch p =* unsmob_pitch ($1);
1783 p = p.transposed (Pitch (-$2,0,0));
1784 $$ = p.smobbed_copy ();
1794 pitch_also_in_chords:
1801 Music *s = MY_MAKE_MUSIC ("SlurEvent");
1803 s->set_spot (THIS->here_input ());
1806 Music *s = MY_MAKE_MUSIC ("PhrasingSlurEvent");
1808 s->set_spot (THIS->here_input ());
1811 Music *s = MY_MAKE_MUSIC ("CrescendoEvent");
1813 s->set_spot (THIS->here_input ());
1816 Music *s = MY_MAKE_MUSIC ("DecrescendoEvent");
1818 s->set_spot (THIS->here_input ());
1825 Music *s = MY_MAKE_MUSIC ("CrescendoEvent");
1826 s->set_spot (THIS->here_input ());
1831 Music *s= MY_MAKE_MUSIC ("SlurEvent");
1833 s->set_spot (THIS->here_input ());
1837 Music *s= MY_MAKE_MUSIC ("PhrasingSlurEvent");
1839 s->set_property ("span-type", scm_makfrom0str ( "phrasing-slur"));
1840 s->set_spot (THIS->here_input ());
1846 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1847 t->set_property ("text", $1);
1848 t->set_spot (THIS->here_input ());
1852 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1853 t->set_property ("text", make_simple_markup (THIS->lexer_->encoding (), $1));
1854 t->set_spot (THIS->here_input ());
1859 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1860 t->set_property ("digit", scm_int2num ($1));
1861 t->set_spot (THIS->here_input ());
1866 script_abbreviation:
1868 $$ = scm_makfrom0str ("Hat");
1871 $$ = scm_makfrom0str ("Plus");
1874 $$ = scm_makfrom0str ("Dash");
1877 $$ = scm_makfrom0str ("Bar");
1880 $$ = scm_makfrom0str ("Larger");
1883 $$ = scm_makfrom0str ("Dot");
1886 $$ = scm_makfrom0str ("Underscore");
1893 | '-' { $$ = CENTER; }
1904 multiplied_duration {
1909 optional_notemode_duration:
1911 Duration dd = THIS->default_duration_;
1912 $$ = dd.smobbed_copy ();
1914 THIS->beam_check ($$);
1916 | multiplied_duration {
1918 THIS->default_duration_ = *unsmob_duration ($$);
1920 THIS->beam_check ($$);
1925 bare_unsigned dots {
1927 if (!is_duration ($1))
1928 THIS->parser_error (_f ("not a duration: %d", $1));
1932 $$ = Duration (len, $2).smobbed_copy ();
1934 | DURATION_IDENTIFIER dots {
1935 Duration *d = unsmob_duration ($1);
1936 Duration k (d->duration_log (), d->dot_count () + $2);
1945 multiplied_duration:
1949 | multiplied_duration '*' bare_unsigned {
1950 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1952 | multiplied_duration '*' FRACTION {
1953 Rational m (ly_scm2int (ly_car ($3)), ly_scm2int (ly_cdr ($3)));
1955 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1960 FRACTION { $$ = $1; }
1961 | UNSIGNED '/' UNSIGNED {
1962 $$ = scm_cons (scm_int2num ($1), scm_int2num ($3));
1980 | ':' bare_unsigned {
1981 if (!is_duration ($2))
1982 THIS->parser_error (_f ("not a duration: %d", $2));
1989 /*****************************************************************
1991 *****************************************************************/
1994 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
1997 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
1999 | STRING { $$ = $1; }
2010 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2011 $$ = bfr->self_scm ();
2012 scm_gc_unprotect_object ($$);
2015 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2016 $$ = bfr->self_scm ();
2018 bfr->set_property ("figure", $1);
2020 scm_gc_unprotect_object ($$);
2022 | bass_figure bass_mod {
2023 Music *m = unsmob_music ($1);
2025 SCM salter = m->get_property ("alteration");
2026 int alter = ly_c_number_p (salter) ? ly_scm2int (salter) : 0;
2027 m->set_property ("alteration",
2028 scm_int2num (alter + $2));
2030 m->set_property ("alteration", scm_int2num (0));
2038 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2043 | br_bass_figure ']' {
2045 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2053 | figure_list br_bass_figure {
2054 $$ = scm_cons ($2, $1);
2059 FIGURE_OPEN figure_list FIGURE_CLOSE {
2060 Music *m = MY_MAKE_MUSIC ("EventChord");
2061 $2 = scm_reverse_x ($2, SCM_EOL);
2062 m->set_property ("elements", $2);
2063 $$ = m->self_scm ();
2074 pitch exclamations questions oct_check optional_notemode_duration optional_rest {
2076 Input i = THIS->pop_spot ();
2077 if (!THIS->lexer_->is_note_state ())
2078 THIS->parser_error (_ ("Have to be in Note mode for notes"));
2082 n = MY_MAKE_MUSIC ("RestEvent");
2084 n = MY_MAKE_MUSIC ("NoteEvent");
2086 n->set_property ("pitch", $1);
2087 n->set_property ("duration", $5);
2089 if (ly_c_number_p ($4))
2091 int q = ly_scm2int ($4);
2092 n->set_property ("absolute-octave", scm_int2num (q-1));
2096 n->set_property ("cautionary", SCM_BOOL_T);
2097 if ($2 % 2 || $3 % 2)
2098 n->set_property ("force-accidental", SCM_BOOL_T);
2100 Music *v = MY_MAKE_MUSIC ("EventChord");
2101 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2102 scm_gc_unprotect_object (n->self_scm ());
2108 | DRUM_PITCH optional_notemode_duration {
2109 Input i = THIS->pop_spot ();
2111 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2112 n->set_property ("duration", $2);
2113 n->set_property ("drum-type", $1);
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 | figure_spec optional_notemode_duration {
2124 Music *m = unsmob_music ($1);
2125 Input i = THIS->pop_spot ();
2127 for (SCM s = m->get_property ("elements"); ly_c_pair_p (s); s = ly_cdr (s))
2129 unsmob_music (ly_car (s))->set_property ("duration", $2);
2133 | RESTNAME optional_notemode_duration {
2135 Input i = THIS->pop_spot ();
2137 if (ly_scm2string ($1) == "s") {
2139 ev = MY_MAKE_MUSIC ("SkipEvent");
2142 ev = MY_MAKE_MUSIC ("RestEvent");
2145 ev->set_property ("duration", $2);
2147 Music *velt = MY_MAKE_MUSIC ("EventChord");
2148 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2151 scm_gc_unprotect_object (ev->self_scm ());
2155 | MULTI_MEASURE_REST optional_notemode_duration {
2158 SCM proc = ly_scheme_function ("make-multi-measure-rest");
2159 SCM mus = scm_call_2 (proc, $2,
2160 make_input (THIS->here_input ()));
2161 scm_gc_protect_object (mus);
2162 $$ = unsmob_music (mus);
2165 | lyric_element optional_notemode_duration {
2166 Input i = THIS->pop_spot ();
2167 if (!THIS->lexer_->is_lyric_state ())
2168 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
2170 Music *lreq = MY_MAKE_MUSIC ("LyricEvent");
2171 lreq->set_property ("text", $1);
2172 lreq->set_property ("duration",$2);
2174 Music *velt = MY_MAKE_MUSIC ("EventChord");
2175 velt->set_property ("elements", scm_list_1 (lreq->self_scm ()));
2182 if (!THIS->lexer_->is_chord_state ())
2183 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
2184 $$ = unsmob_music ($1);
2189 /* FIXME: lyric flavoured markup would be better */
2197 steno_tonic_pitch optional_notemode_duration {
2198 $$ = make_chord ($1, $2, SCM_EOL);
2200 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2201 SCM its = scm_reverse_x ($4, SCM_EOL);
2202 $$ = make_chord ($1, $2, scm_cons ($3, its));
2210 | chord_items chord_item {
2211 $$ = scm_cons ($2, $$);
2217 $$ = ly_symbol2scm ("chord-colon");
2220 $$ = ly_symbol2scm ("chord-caret");
2222 | CHORD_SLASH steno_tonic_pitch {
2223 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2225 | CHORD_BASS steno_tonic_pitch {
2226 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2235 $$ = scm_reverse_x ($1, SCM_EOL);
2243 step_number { $$ = scm_cons ($1, SCM_EOL); }
2244 | step_numbers '.' step_number {
2245 $$ = scm_cons ($3, $$);
2251 $$ = make_chord_step ($1, 0);
2253 | bare_unsigned '+' {
2254 $$ = make_chord_step ($1, SHARP);
2256 | bare_unsigned CHORD_MINUS {
2257 $$ = make_chord_step ($1, FLAT);
2264 TODO: should deprecate in favor of Scheme?
2268 number_expression '+' number_term {
2269 $$ = scm_sum ($1, $3);
2271 | number_expression '-' number_term {
2272 $$ = scm_difference ($1, $3);
2281 | number_factor '*' number_factor {
2282 $$ = scm_product ($1, $3);
2284 | number_factor '/' number_factor {
2285 $$ = scm_divide ($1, $3);
2290 '-' number_factor { /* %prec UNARY_MINUS */
2291 $$ = scm_difference ($2, SCM_UNDEFINED);
2299 $$ = scm_int2num ($1);
2304 | NUMBER_IDENTIFIER {
2307 | REAL NUMBER_IDENTIFIER {
2308 $$ = scm_make_real (ly_scm2double ($1) *ly_scm2double ($2));
2310 | UNSIGNED NUMBER_IDENTIFIER {
2311 $$ = scm_make_real ($1 *ly_scm2double ($2));
2327 if (scm_integer_p ($1) == SCM_BOOL_T)
2329 int k = ly_scm2int ($1);
2333 THIS->parser_error (_ ("need integer number arg"));
2347 | STRING_IDENTIFIER {
2350 | string '+' string {
2351 $$ = scm_string_append (scm_list_2 ($1, $3));
2358 | exclamations '!' { $$ ++; }
2363 | questions '?' { $$ ++; }
2373 { THIS->lexer_->push_markup_state (); }
2376 THIS->lexer_->pop_state ();
2382 This should be done more dynamically if possible.
2386 $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
2388 | MARKUP_HEAD_EMPTY {
2389 $$ = scm_list_1 ($1);
2391 | MARKUP_HEAD_MARKUP0 markup {
2392 $$ = scm_list_2 ($1, $2);
2394 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2395 $$ = scm_list_3 ($1, $2, $3);
2397 | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
2398 $$ = scm_list_3 ($1, $2, $3);
2403 | MARKUP_HEAD_LIST0 markup_list {
2404 $$ = scm_list_2 ($1,$2);
2406 | MARKUP_HEAD_SCM0 embedded_scm {
2407 $$ = scm_list_2 ($1, $2);
2409 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
2410 $$ = scm_list_4 ($1, $2, $3, $4);
2412 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2413 $$ = scm_list_4 ($1, $2, $3, $4);
2415 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2416 $$ = scm_list_3 ($1, $2, $3);
2418 | MARKUP_IDENTIFIER {
2421 | STRING_IDENTIFIER {
2427 chord_open markup_list_body chord_close { $$ = scm_reverse_x ($2, SCM_EOL); }
2431 '{' markup_list_body '}' {
2432 SCM line = ly_scheme_function ("line-markup");
2434 $$ = scm_list_2 (line, scm_reverse_x ($2, SCM_EOL));
2439 /**/ { $$ = SCM_EOL; }
2440 | markup_list_body markup {
2441 $$ = scm_cons ($2, $1);
2449 My_lily_parser::set_yydebug (bool )
2457 My_lily_parser::do_yyparse ()
2459 yyparse ((void*)this);
2464 Should make this optional? It will also complain when you do
2468 which is entirely legitimate.
2470 Or we can scrap it. Barchecks should detect wrong durations, and
2471 skipTypesetting speeds it up a lot.
2475 My_lily_parser::beam_check (SCM dur)
2477 Duration *d = unsmob_duration (dur);
2478 if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2480 Music *m = unsmob_music (last_beam_start_);
2481 m->origin ()->warning (_ ("Suspect duration found following this beam"));
2483 last_beam_start_ = SCM_EOL;
2491 It is a little strange to have this function in this file, but
2492 otherwise, we have to import music classes into the lexer.
2496 My_lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2498 if (ly_c_string_p (sid)) {
2500 return STRING_IDENTIFIER;
2501 } else if (ly_c_number_p (sid)) {
2503 return NUMBER_IDENTIFIER;
2504 } else if (unsmob_context_def (sid)) {
2505 *destination = unsmob_context_def (sid)->clone_scm ();
2506 return CONTEXT_DEF_IDENTIFIER;
2507 } else if (unsmob_score (sid)) {
2508 Score *score = new Score (*unsmob_score (sid));
2509 *destination = score->self_scm ();
2510 return SCORE_IDENTIFIER;
2511 } else if (Music *mus = unsmob_music (sid)) {
2512 mus = mus->clone ();
2513 *destination = mus->self_scm ();
2514 unsmob_music (*destination)->
2515 set_property ("origin", make_input (last_input_));
2516 return dynamic_cast<Event*> (mus)
2517 ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2518 } else if (unsmob_duration (sid)) {
2519 *destination = unsmob_duration (sid)->smobbed_copy ();
2520 return DURATION_IDENTIFIER;
2521 } else if (unsmob_music_output_def (sid)) {
2522 Music_output_def *p = unsmob_music_output_def (sid);
2525 *destination = p->self_scm ();
2526 return MUSIC_OUTPUT_DEF_IDENTIFIER;
2527 } else if (Text_item::markup_p (sid)) {
2529 return MARKUP_IDENTIFIER;
2536 property_op_to_music (SCM op)
2539 SCM tag = ly_car (op);
2540 SCM symbol = ly_cadr (op);
2541 SCM args = ly_cddr (op);
2542 SCM grob_val = SCM_UNDEFINED;
2543 SCM grob_sym = SCM_UNDEFINED;
2544 SCM val = SCM_UNDEFINED;
2546 if (tag == ly_symbol2scm ("assign"))
2548 m = MY_MAKE_MUSIC ("PropertySet");
2549 val = ly_car (args);
2551 else if (tag == ly_symbol2scm ("unset"))
2552 m = MY_MAKE_MUSIC ("PropertyUnset");
2553 else if (tag == ly_symbol2scm ("poppush")
2554 || tag == ly_symbol2scm ("push"))
2556 m = MY_MAKE_MUSIC ("OverrideProperty");
2557 grob_sym = ly_car (args);
2558 grob_val = ly_cadr (args);
2560 else if (tag == ly_symbol2scm ("pop")) {
2561 m = MY_MAKE_MUSIC ("RevertProperty");
2562 grob_sym = ly_car (args);
2565 m->set_property ("symbol", symbol);
2567 if (val != SCM_UNDEFINED)
2568 m->set_property ("value", val);
2569 if (grob_val != SCM_UNDEFINED)
2570 m->set_property ("grob-value", grob_val);
2572 if (grob_sym != SCM_UNDEFINED)
2574 bool itc = internal_type_checking_global_b;
2577 bool autobeam = ly_c_equal_p (symbol, ly_symbol2scm ("autoBeamSettings"));
2579 internal_type_checking_global_b = false;
2580 m->set_property ("grob-property", grob_sym);
2582 internal_type_checking_global_b = itc;
2585 if (op == ly_symbol2scm ("poppush"))
2586 m->set_property ("pop-first", SCM_BOOL_T);
2593 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2595 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2597 csm->set_property ("element", m->self_scm ());
2598 scm_gc_unprotect_object (m->self_scm ());
2600 csm->set_property ("context-type",
2601 ly_c_symbol_p (type) ? type : scm_string_to_symbol (type));
2602 csm->set_property ("property-operations", ops);
2604 if (ly_c_string_p (id))
2605 csm->set_property ("context-id", id);
2611 get_next_unique_context ()
2613 static int new_context_count;
2616 snprintf (s, 1024, "uniqueContext%d", new_context_count ++);
2618 return scm_makfrom0str (s);