1 %{ // -*-Fundamental-*-
4 parser.yy -- Bison/C++ parser for LilyPond
6 source file of the GNU LilyPond music typesetter
8 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 Jan Nieuwenhuizen <janneke@gnu.org>
16 * The rules for who is protecting what are very shady. Uniformise
19 * There are too many lexical modes?
29 #include "context-def.hh"
30 #include "dimensions.hh"
32 #include "file-path.hh"
33 #include "input-smob.hh"
35 #include "lily-guile.hh"
36 #include "lilypond-input-version.hh"
37 #include "ly-module.hh"
39 #include "midi-def.hh"
41 #include "music-list.hh"
42 #include "music-sequence.hh"
43 #include "my-lily-lexer.hh"
44 #include "my-lily-parser.hh"
45 #include "paper-book.hh"
46 #include "paper-def.hh"
47 #include "scm-hash.hh"
48 #include "scm-option.hh"
50 #include "text-item.hh"
53 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
55 Music *property_op_to_music (SCM op);
56 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops_);
57 SCM get_next_unique_context ();
59 #define YYERROR_VERBOSE 1
61 #define YYPARSE_PARAM my_lily_parser
62 #define YYLEX_PARAM my_lily_parser
64 ((My_lily_parser *) my_lily_parser)
66 #define yyerror THIS->parser_error
68 /* Add symbols to the TAGS field of a music object. */
71 tag_music (Music *m, SCM tag, Input ip)
73 SCM tags = m->get_property ("tags");
74 if (ly_c_symbol_p (tag))
75 tags = scm_cons (tag, tags);
76 else if (ly_c_list_p (tag))
77 tags = ly_append2 (tag, tags);
79 ip.warning (_ ("Tag must be symbol or list of symbols."));
81 m->set_property ("tags", tags);
85 get_paper (My_lily_parser *parser)
87 SCM id = parser->lexer_->lookup_identifier ("$defaultpaper");
88 Music_output_def *paper = unsmob_music_output_def (id);
89 return paper ? paper->clone () : new Paper_def;
93 is_regular_identifier (SCM id)
95 String str = ly_scm2string (id);
96 char const *s = str.to_str0 ();
105 v = v && isalnum (*s);
112 make_simple_markup (SCM encoding, SCM a)
114 SCM simple = ly_scheme_function ("simple-markup");
115 if (ly_c_symbol_p (encoding))
116 return scm_list_3 (ly_scheme_function ("encoded-simple-markup"),
118 return scm_list_2 (simple, a);
124 return t && t == 1 << intlog2 (t);
128 set_music_properties (Music *p, SCM a)
130 for (SCM k = a; ly_c_pair_p (k); k = ly_cdr (k))
131 p->internal_set_property (ly_caar (k), ly_cdar (k));
135 make_chord_step (int step, int alter)
142 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
143 return m.smobbed_copy ();
148 make_chord (SCM pitch, SCM dur, SCM modification_list)
150 SCM chord_ctor = ly_scheme_function ("construct-chord");
151 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
152 scm_gc_protect_object (ch);
156 /* Todo: actually also use apply iso. call too ... */
158 ly_input_procedure_p (SCM x)
160 return ly_c_procedure_p (x)
161 || (ly_c_pair_p (x) && ly_c_procedure_p (ly_car (x)));
165 set_property_music (SCM sym, SCM value)
167 Music *p = MY_MAKE_MUSIC ("PropertySet");
168 p->set_property ("symbol", sym);
169 p->set_property ("value", value);
174 make_music_relative (Pitch start, Music *music)
176 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
177 relative->set_property ("element", music->self_scm ());
179 Pitch last = music->to_relative_octave (start);
180 if (lily_1_8_relative)
181 music->set_property ("last-pitch", last.smobbed_copy ());
186 make_lyric_combine_music (SCM name, Music *music)
188 Music *combine = MY_MAKE_MUSIC ("NewLyricCombineMusic");
189 combine->set_property ("element", music->self_scm ());
190 combine->set_property ("associated-context", name);
196 /* We use SCMs to do strings, because it saves us the trouble of
197 deleting them. Let's hope that a stack overflow doesnt trigger a move
198 of the parse stack onto the heap. */
203 Music_output_def *outputdef;
213 yylex (YYSTYPE *s, void *v)
215 My_lily_parser *pars = (My_lily_parser*) v;
216 My_lily_lexer *lex = pars->lexer_;
218 lex->lexval = (void*) s;
219 lex->prepare_for_next_token ();
220 return lex->yylex ();
229 Three shift/reduce problems:
231 2. \markup identifier.
236 \repeat .. \alternative
239 \repeat { \repeat .. \alternative }
243 \repeat { \repeat } \alternative
265 %token CHORDMODIFIERS
270 %token COMMANDSPANREQUEST
279 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
280 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
284 %token GROBDESCRIPTIONS
293 %token MULTI_MEASURE_REST
299 %token OVERRIDE SET REVERT
326 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
327 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
329 %token <i> E_UNSIGNED
330 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH
333 %type <book> book_block book_body
334 %type <i> exclamations questions dots optional_rest
336 %type <scm> grace_head
337 %type <scm> oct_check
338 %type <scm> context_mod_list
339 %type <scm> lyric_element
340 %type <scm> bass_number br_bass_figure bass_figure figure_list figure_spec
342 %token <scm> NOTENAME_PITCH
343 %token <scm> TONICNAME_PITCH
344 %token <scm> CHORDMODIFIER_PITCH
345 %token <scm> DURATION_IDENTIFIER
346 %token <scm> FRACTION
347 %token <id> IDENTIFIER
349 %token <scm> DRUM_PITCH
350 %token <scm> CHORD_MODIFIER
351 %token <scm> SCORE_IDENTIFIER
352 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
353 %token <scm> NUMBER_IDENTIFIER
354 %token <scm> EVENT_IDENTIFIER
355 %token <scm> MUSIC_IDENTIFIER CONTEXT_DEF_IDENTIFIER
356 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
357 %token <scm> RESTNAME
364 %token <scm> MARKUP_HEAD_MARKUP0
365 %token <scm> MARKUP_HEAD_EMPTY
366 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
367 %token <scm> MARKUP_HEAD_SCM0
368 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
369 %token <scm> MARKUP_HEAD_SCM0_SCM1
370 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
371 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
373 %token <scm> MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
374 %type <scm> markup markup_line markup_list markup_list_body full_markup
376 %type <outputdef> output_def
377 %type <scm> lilypond_header lilypond_header_body
378 %type <music> open_event close_event
379 %type <i> sub_quotes sup_quotes
380 %type <music> toplevel_music
381 %type <music> simple_element event_chord command_element
382 %type <music> Composite_music Simple_music
383 %type <music> Repeated_music
384 %type <scm> Alternative_music
385 //%type <scm> Composite_music_list
386 %type <i> tremolo_type
387 %type <i> bare_int bare_unsigned
389 %type <scm> identifier_init
390 %type <scm> simple_string
392 %type <music> note_chord_element chord_body chord_body_element
393 %type <scm> chord_body_elements
394 %type <scm> steno_duration optional_notemode_duration multiplied_duration
396 %type <scm> post_events
397 %type <music> gen_text_def direction_less_event direction_reqd_event
398 %type <scm> steno_pitch pitch absolute_pitch pitch_also_in_chords
399 %type <scm> steno_tonic_pitch
400 %type <scm> duration_length fraction
402 %type <scm> new_chord step_number chord_items chord_item chord_separator step_numbers
404 %type <scm> embedded_scm scalar
405 %type <music> Music Sequential_music Simultaneous_music
406 %type <music> relative_music re_rhythmed_music
407 %type <music> music_property_def context_change
408 %type <scm> context_prop_spec
409 %type <scm> Music_list
410 %type <scm> property_operation context_mod context_def_mod optional_context_mod
411 %type <outputdef> music_output_def_body music_output_def_head
412 %type <music> post_event tagged_post_event
413 %type <music> command_req
414 %type <music> string_number_event
415 %type <scm> string bare_number number_expression number_term number_factor
416 %type <score> score_block score_body
418 %type <scm> context_def_spec_block context_def_spec_body
419 %type <music> tempo_event
420 %type <scm> script_abbreviation
426 /* We don't assign precedence to / and *, because we might need varied
427 prec levels in different prods */
433 lilypond: /* empty */
435 | lilypond toplevel_expression {
437 | lilypond assignment {
440 THIS->error_level_ = 1;
443 THIS->error_level_ = 1;
451 | toplevel_music EOI {
452 Music_output_def *paper = get_paper (THIS);
454 // SCM proc = paper->get_scmvar ("toplevel-music-handler");
455 SCM proc = ly_scheme_function ("ly:parser-add-book-and-score");
456 scm_call_2 (proc, THIS->self_scm (), $1->self_scm ());
457 scm_gc_unprotect_object (paper->self_scm ());
464 SCM header = THIS->header_;
465 Path outname = split_path (THIS->output_basename_);
466 int *c = &THIS->book_count_;
468 outname.base += "-" + to_string (*c);
470 Music_output_def *paper = get_paper (THIS);
471 book->process (outname.to_string (), paper, header);
472 scm_gc_unprotect_object (book->self_scm ());
473 scm_gc_unprotect_object (paper->self_scm ());
476 /* TODO: implicit book, depending on --no-book/--no-page-layout
479 SCM head = is_module (score->header_) ? score->header_
480 : THIS->header_.to_SCM ();
482 Path p = split_path (THIS->output_basename_);
483 int *c = &THIS->score_count_;
485 p.base += "-" + to_string (*c);
488 SCM outname = scm_makfrom0str (p.to_string ().to_str0());
490 for (int i = 0; i < score->defs_.size (); i++)
491 default_rendering (score->music_,
492 score->defs_[i]->self_scm (), head,
495 if (score->defs_.is_empty ())
497 Music_output_def *paper = get_paper (THIS);
498 default_rendering (score->music_, paper->self_scm (), head,
500 scm_gc_unprotect_object (paper->self_scm ());
502 scm_gc_unprotect_object (score->self_scm ());
506 if (dynamic_cast<Paper_def*> ($1))
507 id = scm_makfrom0str ("$defaultpaper");
508 else if (dynamic_cast<Midi_def*> ($1))
509 id = scm_makfrom0str ("$defaultmidi");
510 THIS->lexer_->set_identifier (id, $1->self_scm ());
511 scm_gc_unprotect_object ($1->self_scm ());
526 lilypond_header_body:
528 $$ = ly_make_anonymous_module ();
529 THIS->lexer_->add_scope ($$);
531 | lilypond_header_body assignment {
537 HEADER '{' lilypond_header_body '}' {
538 $$ = THIS->lexer_->remove_scope ();
550 /* cont */ '=' identifier_init {
553 Should find generic way of associating input with objects.
555 Input ip = THIS->pop_spot ();
557 if (! is_regular_identifier ($1))
559 ip.warning (_ ("Identifier should have alphabetic characters only"));
562 THIS->lexer_->set_identifier ($1, $4);
565 TODO: devise standard for protection in parser.
567 The parser stack lives on the C-stack, which means that
568 all objects can be unprotected as soon as they're here.
578 $$ = $1->self_scm ();
579 scm_gc_unprotect_object ($$);
585 $$ = $1->self_scm ();
586 scm_gc_unprotect_object ($$);
588 | context_def_spec_block {
592 $$ = $1->self_scm ();
593 scm_gc_unprotect_object ($$);
596 $$ = $1->self_scm ();
597 scm_gc_unprotect_object ($$);
599 | number_expression {
610 context_def_spec_block:
611 CONTEXT '{' context_def_spec_body '}'
617 context_def_spec_body:
619 $$ = Context_def::make_scm ();
620 unsmob_context_def ($$)->set_spot (THIS->here_input ());
622 | CONTEXT_DEF_IDENTIFIER {
624 unsmob_context_def ($$)->set_spot (THIS->here_input ());
626 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
627 Context_def*td = unsmob_context_def ($$);
629 for (SCM p = $3; ly_c_pair_p (p); p = ly_cdr (p)) {
630 SCM tag = ly_caar (p);
632 /* TODO: should make new tag "grob-definition" ? */
633 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
634 tag, scm_cons (ly_cdar (p), SCM_EOL)));
637 | context_def_spec_body context_mod {
638 unsmob_context_def ($$)->add_context_mod ($2);
646 /*cont*/ '{' book_body '}' {
655 $$->set_spot (THIS->here_input ());
657 | book_body score_block {
658 $$->scores_.push ($2);
659 scm_gc_unprotect_object ($2->self_scm ());
669 /*cont*/ '{' score_body '}' {
679 $$->set_spot (THIS->here_input ());
680 SCM m = $1->self_scm ();
681 scm_gc_unprotect_object (m);
686 SCM check_funcs = ly_scheme_function ("toplevel-music-functions");
687 for (; ly_c_pair_p (check_funcs); check_funcs = ly_cdr (check_funcs))
688 m = scm_call_1 (ly_car (check_funcs), m);
693 $$ = new Score ( *unsmob_score ($1));
694 $$->set_spot (THIS->here_input ());
696 | score_body lilypond_header {
699 | score_body output_def {
701 scm_gc_unprotect_object ($2->self_scm ());
713 music_output_def_body '}' {
715 THIS->lexer_->remove_scope ();
716 THIS->lexer_->pop_state ();
720 music_output_def_head:
722 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
727 p = dynamic_cast<Midi_def*> (id->clone ());
732 THIS->lexer_->add_scope (p->scope_);
735 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
738 p = dynamic_cast<Paper_def*> (id->clone ());
742 THIS->lexer_->add_scope (p->scope_);
748 music_output_def_body:
749 music_output_def_head '{' {
751 $$->input_origin_. set_spot (THIS->here_input ());
752 THIS->lexer_->push_initial_state ();
754 | music_output_def_head '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
755 scm_gc_unprotect_object ($1->self_scm ());
756 Music_output_def *o = unsmob_music_output_def ($3);
757 o->input_origin_.set_spot (THIS->here_input ());
759 THIS->lexer_->remove_scope ();
760 THIS->lexer_->add_scope (o->scope_);
761 THIS->lexer_->push_initial_state ();
763 | music_output_def_body assignment {
766 | music_output_def_body context_def_spec_block {
767 $$->assign_context_def ($2);
769 | music_output_def_body tempo_event {
771 junk this ? there already is tempo stuff in
774 int m = ly_scm2int ( $2->get_property ("metronome-count"));
775 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
776 Midi_def *md = dynamic_cast<Midi_def*> ($$);
778 md->set_tempo (d->get_length (), m);
779 scm_gc_unprotect_object ($2->self_scm ());
781 | music_output_def_body error {
787 TEMPO steno_duration '=' bare_unsigned {
788 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
789 $$->set_property ("tempo-unit", $2);
790 $$->set_property ("metronome-count", scm_int2num ( $4));
795 The representation of a list is the
799 to have efficient append.
803 $$ = scm_cons (SCM_EOL, SCM_EOL);
807 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
808 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
809 if (ly_c_pair_p (ly_cdr (s)))
810 scm_set_cdr_x (ly_cdr (s), c); /* append */
812 scm_set_car_x (s, c); /* set first cons */
813 scm_set_cdr_x (s, c); /* remember last cell */
829 | ALTERNATIVE '{' Music_list '}' {
835 Composite_music_list: {};
836 Too many s/r r/r problems
838 $$ = scm_cons ($1, SCM_EOL);
840 | '{' Music_list '}' {
847 REPEAT string bare_unsigned Music Alternative_music
851 SCM alts = ly_c_pair_p ($5) ? ly_car ($5) : SCM_EOL;
852 if (times < scm_ilength (alts)) {
853 unsmob_music (ly_car (alts))
854 ->origin ()->warning (
855 _ ("More alternatives than repeats. Junking excess alternatives."));
856 alts = ly_truncate_list (times, alts);
860 SCM proc = ly_scheme_function ("make-repeated-music");
862 SCM mus = scm_call_1 (proc, $2);
863 scm_gc_protect_object (mus); // UGH.
864 Music *r = unsmob_music (mus);
867 r-> set_property ("element", beg->self_scm ());
868 scm_gc_unprotect_object (beg->self_scm ());
870 r->set_property ("repeat-count", scm_int2num (times >? 1));
872 r-> set_property ("elements",alts);
873 if (ly_c_equal_p ($2, scm_makfrom0str ("tremolo"))) {
875 TODO: move this code to Scheme.
879 we can not get durations and other stuff correct down the line, so we have to
880 add to the duration log here.
882 SCM func = ly_scheme_function ("shift-duration-log");
884 int dots = ($3 % 3) ? 0 : 1;
885 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
887 Sequential_music *seq = dynamic_cast<Sequential_music*> ($4);
890 int list_len = scm_ilength (seq->music_list ());
892 seq->origin ()->warning ("Chord tremolo must have 2 elements.");
894 r->compress (Moment (Rational (1, list_len)));
896 scm_call_3 (func, r->self_scm (), scm_int2num (shift),scm_int2num (dots));
899 r->set_spot (*$4->origin ());
906 SEQUENTIAL '{' Music_list '}' {
907 $$ = MY_MAKE_MUSIC ("SequentialMusic");
908 $$->set_property ("elements", ly_car ($3));
909 $$->set_spot (THIS->here_input ());
911 | '{' Music_list '}' {
912 $$ = MY_MAKE_MUSIC ("SequentialMusic");
913 $$->set_property ("elements", ly_car ($2));
914 $$->set_spot (THIS->here_input ());
919 SIMULTANEOUS '{' Music_list '}'{
920 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
921 $$->set_property ("elements", ly_car ($3));
922 $$->set_spot (THIS->here_input ());
925 | simul_open Music_list simul_close {
926 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
927 $$->set_property ("elements", ly_car ($2));
928 $$->set_spot (THIS->here_input ());
933 event_chord { $$ = $1; }
934 | APPLYOUTPUT embedded_scm {
935 if (!ly_input_procedure_p ($2))
936 THIS->parser_error (_ ("\\applycontext takes function argument"));
937 $$ = MY_MAKE_MUSIC ("ApplyOutputEvent");
938 $$->set_property ("procedure", $2);
939 $$->set_spot (THIS->here_input ());
941 | APPLYCONTEXT embedded_scm {
942 if (!ly_input_procedure_p ($2))
943 THIS->parser_error (_ ("\\applycontext takes function argument"));
944 $$ = MY_MAKE_MUSIC ("ApplyContext");
945 $$->set_property ("procedure", $2);
946 $$->set_spot (THIS->here_input ());
949 $$ = unsmob_music ($1);
956 optional_context_mod:
957 /**/ { $$ = SCM_EOL; }
958 | WITH '{' context_mod_list '}' { $$ = $3; }
962 GRACE { $$ = scm_makfrom0str ("Grace"); }
963 | ACCIACCATURA { $$ = scm_makfrom0str ("Acciaccatura"); }
964 | APPOGGIATURA { $$ = scm_makfrom0str ("Appoggiatura"); }
968 /* */ { $$ = SCM_EOL; }
969 | context_mod_list context_mod {
970 $$ = scm_cons ($2, $1);
976 SCM proc = ly_scheme_function ("make-autochange-music");
978 SCM res = scm_call_1 (proc, $2->self_scm ());
979 scm_gc_unprotect_object ($2->self_scm ());
980 $$ = unsmob_music (res);
981 scm_gc_protect_object (res);
982 $$->set_spot (THIS->here_input ());
984 | PARTCOMBINE Music Music {
985 SCM proc = ly_scheme_function ("make-part-combine-music");
987 SCM res = scm_call_1 (proc, scm_listify ($2->self_scm (),
988 $3->self_scm (), SCM_UNDEFINED));
989 scm_gc_unprotect_object ($3->self_scm ());
990 scm_gc_unprotect_object ($2->self_scm ());
991 $$ = unsmob_music (res);
992 scm_gc_protect_object (res);
993 $$->set_spot (THIS->here_input ());
998 The other version is for easier debugging of
999 Sequential_music_iterator in combination with grace notes.
1004 TODO: should distinguish between both grace types in the
1005 basic music objects too, since the meaning is different.
1009 String start_str = "start" + ly_scm2string ($1) + "Music";
1010 String stop_str = "stop" + ly_scm2string ($1) + "Music";
1012 SCM start = THIS->lexer_->lookup_identifier (start_str);
1013 SCM stop = THIS->lexer_->lookup_identifier (stop_str);
1015 Music *startm = unsmob_music (start);
1016 Music *stopm = unsmob_music (stop);
1020 stopm = stopm->clone ();
1021 ms = scm_cons (stopm->self_scm (), ms);
1022 scm_gc_unprotect_object (stopm->self_scm ());
1024 ms = scm_cons ($2->self_scm (), ms);
1025 scm_gc_unprotect_object ($2->self_scm ());
1027 startm = startm->clone ();
1028 ms = scm_cons (startm->self_scm (), ms);
1029 scm_gc_unprotect_object (startm->self_scm ());
1032 Music* seq = MY_MAKE_MUSIC ("SequentialMusic");
1033 seq->set_property ("elements", ms);
1036 $$ = MY_MAKE_MUSIC ("GraceMusic");
1037 $$->set_property ("element", seq->self_scm ());
1038 scm_gc_unprotect_object (seq->self_scm ());
1040 $$ = MY_MAKE_MUSIC ("GraceMusic");
1041 $$->set_property ("element", $2->self_scm ());
1042 scm_gc_unprotect_object ($2->self_scm ());
1045 | CONTEXT string '=' string optional_context_mod Music {
1046 $$ = context_spec_music ($2, $4, $6, $5);
1049 | CONTEXT simple_string optional_context_mod Music {
1050 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1052 | NEWCONTEXT string optional_context_mod Music {
1053 $$ = context_spec_music ($2, get_next_unique_context (),
1064 int n = ly_scm2int (ly_car ($3)); int d = ly_scm2int (ly_cdr ($3));
1067 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1068 $$->set_spot (THIS->pop_spot ());
1070 $$->set_property ("element", mp->self_scm ());
1071 scm_gc_unprotect_object (mp->self_scm ());
1072 $$->set_property ("numerator", scm_int2num (n));
1073 $$->set_property ("denominator", scm_int2num (d));
1074 $$->compress (Moment (Rational (n,d)));
1077 | Repeated_music { $$ = $1; }
1078 | Simultaneous_music { $$ = $1; }
1079 | Sequential_music { $$ = $1; }
1080 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1081 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1083 Pitch from = *unsmob_pitch ($2);
1084 Pitch to = *unsmob_pitch ($3);
1086 p->transpose (interval (from, to));
1087 $$->set_property ("element", p->self_scm ());
1088 scm_gc_unprotect_object (p->self_scm ());
1090 | APPLY embedded_scm Music {
1091 if (!ly_input_procedure_p ($2))
1093 THIS->parser_error (_ ("\\apply takes function argument"));
1098 SCM ret = scm_call_1 ($2, $3->self_scm ());
1099 Music *m = unsmob_music (ret);
1101 THIS->parser_error ("\\apply must return a Music");
1102 m = MY_MAKE_MUSIC ("Music");
1109 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1110 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1114 THIS->lexer_->pop_state ();
1118 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1119 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1123 THIS->lexer_->pop_state ();
1126 { THIS->lexer_->push_figuredbass_state (); }
1129 Music *chm = MY_MAKE_MUSIC ("UntransposableMusic");
1130 chm->set_property ("element", $3->self_scm ());
1132 scm_gc_unprotect_object ($3->self_scm ());
1134 THIS->lexer_->pop_state ();
1137 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1138 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1139 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1140 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1143 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1144 chm->set_property ("element", $3->self_scm ());
1145 scm_gc_unprotect_object ($3->self_scm ());
1148 THIS->lexer_->pop_state ();
1151 { THIS->lexer_->push_lyric_state (); }
1155 THIS->lexer_->pop_state ();
1157 | relative_music { $$ = $1; }
1158 | re_rhythmed_music { $$ = $1; }
1159 | TAG embedded_scm Music {
1160 tag_music ($3, $2, THIS->here_input ());
1166 RELATIVE absolute_pitch Music {
1168 Pitch start = *unsmob_pitch ($2);
1169 $$ = make_music_relative (start, m);
1170 scm_gc_unprotect_object (m->self_scm ());
1172 | RELATIVE Composite_music {
1174 /* FIXME: why is octave==0 and default not middleC? */
1175 Pitch middle_c (-1, 0, 0);
1176 $$ = make_music_relative (middle_c, m);
1177 scm_gc_unprotect_object (m->self_scm ());
1182 ADDLYRICS Music Music {
1183 Music *m = MY_MAKE_MUSIC ("LyricCombineMusic");
1184 m->set_property ("elements", scm_listify ($2->self_scm (),
1185 $3->self_scm (), SCM_UNDEFINED));
1186 scm_gc_unprotect_object ($3->self_scm ());
1187 scm_gc_unprotect_object ($2->self_scm ());
1191 /* Too many s/r r/r problems
1194 NEWLYRICS { THIS->lexer_->push_lyric_state (); }
1196 /* Too many s/r r/r problems
1197 Composite_music_list
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);