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 "book-paper-def.hh"
30 #include "context-def.hh"
31 #include "dimensions.hh"
33 #include "file-path.hh"
34 #include "input-smob.hh"
36 #include "lily-guile.hh"
37 #include "lilypond-input-version.hh"
38 #include "ly-module.hh"
40 #include "midi-def.hh"
42 #include "music-list.hh"
43 #include "music-sequence.hh"
44 #include "my-lily-lexer.hh"
45 #include "my-lily-parser.hh"
46 #include "paper-book.hh"
47 #include "paper-def.hh"
48 #include "scm-hash.hh"
49 #include "scm-option.hh"
51 #include "text-item.hh"
54 #define MY_MAKE_MUSIC(x) make_music_by_name (ly_symbol2scm (x))
56 Music *property_op_to_music (SCM op);
57 Music *context_spec_music (SCM type, SCM id, Music *m, SCM ops_);
58 SCM get_next_unique_context ();
60 #define YYERROR_VERBOSE 1
62 #define YYPARSE_PARAM my_lily_parser
63 #define YYLEX_PARAM my_lily_parser
65 ((My_lily_parser *) my_lily_parser)
67 #define yyerror THIS->parser_error
69 /* Add symbols to the TAGS field of a music object. */
72 tag_music (Music *m, SCM tag, Input ip)
74 SCM tags = m->get_property ("tags");
75 if (ly_c_symbol_p (tag))
76 tags = scm_cons (tag, tags);
77 else if (ly_c_list_p (tag))
78 tags = ly_append2 (tag, tags);
80 ip.warning (_ ("Tag must be symbol or list of symbols."));
82 m->set_property ("tags", tags);
86 is_regular_identifier (SCM id)
88 String str = ly_scm2string (id);
89 char const *s = str.to_str0 ();
98 v = v && isalnum (*s);
105 make_simple_markup (SCM encoding, SCM a)
107 SCM simple = ly_scheme_function ("simple-markup");
108 if (ly_c_symbol_p (encoding))
109 return scm_list_3 (ly_scheme_function ("encoded-simple-markup"),
111 return scm_list_2 (simple, a);
117 return t && t == 1 << intlog2 (t);
121 set_music_properties (Music *p, SCM a)
123 for (SCM k = a; ly_c_pair_p (k); k = ly_cdr (k))
124 p->internal_set_property (ly_caar (k), ly_cdar (k));
128 make_chord_step (int step, int alter)
135 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
136 return m.smobbed_copy ();
141 make_chord (SCM pitch, SCM dur, SCM modification_list)
143 SCM chord_ctor = ly_scheme_function ("construct-chord");
144 SCM ch = scm_call_3 (chord_ctor, pitch, dur, modification_list);
145 scm_gc_protect_object (ch);
149 /* Todo: actually also use apply iso. call too ... */
151 ly_input_procedure_p (SCM x)
153 return ly_c_procedure_p (x)
154 || (ly_c_pair_p (x) && ly_c_procedure_p (ly_car (x)));
158 set_property_music (SCM sym, SCM value)
160 Music *p = MY_MAKE_MUSIC ("PropertySet");
161 p->set_property ("symbol", sym);
162 p->set_property ("value", value);
167 make_music_relative (Pitch start, Music *music)
169 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic");
170 relative->set_property ("element", music->self_scm ());
172 Pitch last = music->to_relative_octave (start);
173 if (lily_1_8_relative)
174 music->set_property ("last-pitch", last.smobbed_copy ());
179 make_lyric_combine_music (SCM name, Music *music)
181 Music *combine = MY_MAKE_MUSIC ("NewLyricCombineMusic");
182 combine->set_property ("element", music->self_scm ());
183 combine->set_property ("associated-context", name);
189 /* We use SCMs to do strings, because it saves us the trouble of
190 deleting them. Let's hope that a stack overflow doesnt trigger a move
191 of the parse stack onto the heap. */
197 Book_paper_def *bookpaper;
198 Music_output_def *outputdef;
208 yylex (YYSTYPE *s, void *v)
210 My_lily_parser *pars = (My_lily_parser*) v;
211 My_lily_lexer *lex = pars->lexer_;
213 lex->lexval = (void*) s;
214 lex->prepare_for_next_token ();
215 return lex->yylex ();
224 Three shift/reduce problems:
226 2. \markup identifier.
231 \repeat .. \alternative
234 \repeat { \repeat .. \alternative }
238 \repeat { \repeat } \alternative
255 %token CHORDMODIFIERS
257 %token DOUBLE_ANGLE_OPEN
258 %token DOUBLE_ANGLE_CLOSE
260 %token COMMANDSPANREQUEST
268 %token FIGURES FIGURE_OPEN FIGURE_CLOSE
269 %token FIGURE_BRACKET_CLOSE FIGURE_BRACKET_OPEN
270 %token GROBDESCRIPTIONS
279 %token MULTI_MEASURE_REST
285 %token OVERRIDE SET REVERT
311 /* FIXME: this sucks. The user will get to see these names:
312 syntax error, unexpected E_CHAR:
316 %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE
317 %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE
319 %token <i> E_UNSIGNED
320 %token CHORD_BASS CHORD_COLON CHORD_MINUS CHORD_CARET CHORD_SLASH
324 %token <scm> NOTENAME_PITCH
325 %token <scm> TONICNAME_PITCH
326 %token <scm> CHORDMODIFIER_PITCH
327 %token <scm> DURATION_IDENTIFIER
328 %token <scm> FRACTION
329 %token <id> IDENTIFIER
331 %token <scm> DRUM_PITCH
332 %token <scm> CHORD_MODIFIER
333 %token <scm> SCORE_IDENTIFIER
334 %token <scm> MUSIC_OUTPUT_DEF_IDENTIFIER
335 %token <scm> NUMBER_IDENTIFIER
336 %token <scm> EVENT_IDENTIFIER
337 %token <scm> MUSIC_IDENTIFIER CONTEXT_DEF_IDENTIFIER
338 %token <scm> STRING_IDENTIFIER SCM_IDENTIFIER
339 %token <scm> RESTNAME
346 %token <scm> MARKUP_HEAD_MARKUP0
347 %token <scm> MARKUP_HEAD_EMPTY
348 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
349 %token <scm> MARKUP_HEAD_SCM0
350 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
351 %token <scm> MARKUP_HEAD_SCM0_SCM1
352 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
353 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
355 %token <scm> MUSIC_FUNCTION
356 %token <scm> MUSIC_FUNCTION_SCM
357 %token <scm> MUSIC_FUNCTION_MUSIC
358 %token <scm> MUSIC_FUNCTION_SCM_MUSIC
359 %token <scm> MUSIC_FUNCTION_MUSIC_MUSIC
360 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC
361 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC
363 %token <scm> MARKUP_IDENTIFIER MARKUP_HEAD_LIST0
364 %type <scm> markup markup_line markup_list markup_list_body full_markup
366 %type <book> book_block book_body
367 %type <bookpaper> book_paper_head book_paper_block book_paper_body
369 %type <i> exclamations questions dots optional_rest
371 %type <scm> oct_check
372 %type <scm> context_mod_list
373 %type <scm> lyric_element
374 %type <scm> bass_number br_bass_figure bass_figure figure_list figure_spec
375 %type <scm> new_lyrics
376 %type <outputdef> output_def
377 %type <scm> lilypond_header lilypond_header_body
378 %type <music> open_event close_event
379 %type <i> sub_quotes sup_quotes
380 %type <music> toplevel_music
381 %type <music> simple_element event_chord command_element
382 %type <music> Composite_music Simple_music Prefix_composite_music Generic_prefix_music
383 %type <scm> Generic_prefix_music_scm
384 %type <music> Grouped_music_list
385 %type <music> Repeated_music
386 %type <scm> Alternative_music
387 %type <i> tremolo_type
388 %type <i> bare_int bare_unsigned
390 %type <scm> identifier_init
391 %type <scm> simple_string
393 %type <music> note_chord_element chord_body chord_body_element
394 %type <scm> chord_body_elements
395 %type <scm> steno_duration optional_notemode_duration multiplied_duration
397 %type <scm> post_events
398 %type <music> gen_text_def direction_less_event direction_reqd_event
399 %type <scm> steno_pitch pitch absolute_pitch pitch_also_in_chords
400 %type <scm> steno_tonic_pitch
401 %type <scm> duration_length fraction
403 %type <scm> chord_item chord_items chord_separator new_chord
404 %type <scm> step_number step_numbers
406 %type <scm> embedded_scm scalar
407 %type <music> Music Sequential_music Simultaneous_music
408 %type <music> relative_music re_rhythmed_music
409 %type <music> music_property_def context_change
410 %type <scm> context_prop_spec
411 %type <scm> Music_list
412 %type <scm> property_operation
413 %type <scm> context_mod context_def_mod optional_context_mod
414 %type <outputdef> music_output_def_body music_output_def_head
415 %type <music> post_event tagged_post_event
416 %type <music> command_req
417 %type <music> string_number_event
418 %type <scm> string bare_number number_expression number_term number_factor
419 %type <score> score_block score_body
421 %type <scm> context_def_spec_block context_def_spec_body
422 %type <music> tempo_event
423 %type <scm> script_abbreviation
429 /* We don't assign precedence to / and *, because we might need varied
430 prec levels in different prods */
436 lilypond: /* empty */
437 | lilypond toplevel_expression {
439 | lilypond assignment {
442 THIS->error_level_ = 1;
445 THIS->error_level_ = 1;
458 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-book-handler");
459 scm_call_2 (proc, THIS->self_scm (), book->self_scm ());
460 scm_gc_unprotect_object (book->self_scm ());
465 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-score-handler");
466 scm_call_2 (proc, THIS->self_scm (), score->self_scm ());
467 scm_gc_unprotect_object (score->self_scm ());
471 SCM proc = THIS->lexer_->lookup_identifier ("toplevel-music-handler");
472 scm_call_2 (proc, THIS->self_scm (), music->self_scm ());
473 scm_gc_unprotect_object (music->self_scm ());
477 if (dynamic_cast<Paper_def*> ($1))
478 id = scm_makfrom0str ("$defaultpaper");
479 else if (dynamic_cast<Midi_def*> ($1))
480 id = scm_makfrom0str ("$defaultmidi");
481 THIS->lexer_->set_identifier (id, $1->self_scm ());
482 scm_gc_unprotect_object ($1->self_scm ());
485 THIS->lexer_->set_identifier (scm_makfrom0str ("$defaultbookpaper"), $1->self_scm ());
486 scm_gc_unprotect_object ($1->self_scm ());
501 lilypond_header_body:
503 $$ = ly_make_anonymous_module (safe_global_b);
504 THIS->lexer_->add_scope ($$);
506 | lilypond_header_body assignment {
512 HEADER '{' lilypond_header_body '}' {
513 $$ = THIS->lexer_->remove_scope ();
525 /* cont */ '=' identifier_init {
528 Should find generic way of associating input with objects.
530 Input ip = THIS->pop_spot ();
532 if (! is_regular_identifier ($1))
534 ip.warning (_ ("Identifier should have alphabetic characters only"));
537 THIS->lexer_->set_identifier ($1, $4);
540 TODO: devise standard for protection in parser.
542 The parser stack lives on the C-stack, which means that
543 all objects can be unprotected as soon as they're here.
553 $$ = $1->self_scm ();
554 scm_gc_unprotect_object ($$);
560 $$ = $1->self_scm ();
561 scm_gc_unprotect_object ($$);
563 | context_def_spec_block {
567 $$ = $1->self_scm ();
568 scm_gc_unprotect_object ($$);
571 $$ = $1->self_scm ();
572 scm_gc_unprotect_object ($$);
574 | number_expression {
585 context_def_spec_block:
586 CONTEXT '{' context_def_spec_body '}'
592 context_def_spec_body:
594 $$ = Context_def::make_scm ();
595 unsmob_context_def ($$)->set_spot (THIS->here_input ());
597 | CONTEXT_DEF_IDENTIFIER {
599 unsmob_context_def ($$)->set_spot (THIS->here_input ());
601 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
602 Context_def*td = unsmob_context_def ($$);
604 for (SCM p = $3; ly_c_pair_p (p); p = ly_cdr (p)) {
605 SCM tag = ly_caar (p);
607 /* TODO: should make new tag "grob-definition" ? */
608 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
609 tag, scm_cons (ly_cdar (p), SCM_EOL)));
612 | context_def_spec_body context_mod {
613 unsmob_context_def ($$)->add_context_mod ($2);
619 book_paper_body '}' {
625 $$ = unsmob_book_paper_def (THIS->lexer_->lookup_identifier ("$defaultbookpaper"))->clone ();
626 THIS->lexer_->add_scope ($$->scope_);
632 | book_paper_body assignment { }
641 /*cont*/ '{' book_body '}' {
648 * Use 'handlers' like for toplevel-* stuff?
649 * grok \paper and \midi? */
653 $$->set_spot (THIS->here_input ());
654 $$->bookpaper_ = unsmob_book_paper_def (THIS->lexer_->lookup_identifier ("$defaultbookpaper"))->clone ();
655 scm_gc_unprotect_object ($$->bookpaper_->self_scm ());
657 | book_body book_paper_block {
659 scm_gc_unprotect_object ($2->self_scm ());
661 | book_body score_block {
663 $$->scores_.push (score);
664 scm_gc_unprotect_object (score->self_scm ());
666 | book_body Composite_music {
669 = unsmob_score (ly_music_scorify (music->self_scm ()));
670 $$->scores_.push (score);
671 scm_gc_unprotect_object (music->self_scm ());
685 /*cont*/ '{' score_body '}' {
695 $$->set_spot (THIS->here_input ());
696 SCM m = $1->self_scm ();
697 scm_gc_unprotect_object (m);
702 SCM check_funcs = ly_scheme_function ("toplevel-music-functions");
703 for (; ly_c_pair_p (check_funcs); check_funcs = ly_cdr (check_funcs))
704 m = scm_call_1 (ly_car (check_funcs), m);
709 $$ = new Score ( *unsmob_score ($1));
710 $$->set_spot (THIS->here_input ());
712 | score_body lilypond_header {
715 | score_body output_def {
717 scm_gc_unprotect_object ($2->self_scm ());
729 music_output_def_body '}' {
731 THIS->lexer_->remove_scope ();
732 THIS->lexer_->pop_state ();
736 music_output_def_head:
738 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultmidi"));
743 p = dynamic_cast<Midi_def*> (id->clone ());
748 THIS->lexer_->add_scope (p->scope_);
751 Music_output_def *id = unsmob_music_output_def (THIS->lexer_->lookup_identifier ("$defaultpaper"));
754 p = dynamic_cast<Paper_def*> (id->clone ());
758 THIS->lexer_->add_scope (p->scope_);
764 music_output_def_body:
765 music_output_def_head '{' {
767 $$->input_origin_. set_spot (THIS->here_input ());
768 THIS->lexer_->push_initial_state ();
770 | music_output_def_head '{' MUSIC_OUTPUT_DEF_IDENTIFIER {
771 scm_gc_unprotect_object ($1->self_scm ());
772 Music_output_def *o = unsmob_music_output_def ($3);
773 o->input_origin_.set_spot (THIS->here_input ());
775 THIS->lexer_->remove_scope ();
776 THIS->lexer_->add_scope (o->scope_);
777 THIS->lexer_->push_initial_state ();
779 | music_output_def_body assignment {
782 | music_output_def_body context_def_spec_block {
783 $$->assign_context_def ($2);
785 | music_output_def_body tempo_event {
787 junk this ? there already is tempo stuff in
790 int m = ly_scm2int ( $2->get_property ("metronome-count"));
791 Duration *d = unsmob_duration ($2->get_property ("tempo-unit"));
792 Midi_def *md = dynamic_cast<Midi_def*> ($$);
794 md->set_tempo (d->get_length (), m);
795 scm_gc_unprotect_object ($2->self_scm ());
797 | music_output_def_body error {
803 TEMPO steno_duration '=' bare_unsigned {
804 $$ = MY_MAKE_MUSIC ("MetronomeChangeEvent");
805 $$->set_property ("tempo-unit", $2);
806 $$->set_property ("metronome-count", scm_int2num ( $4));
811 The representation of a list is the
815 to have efficient append.
819 $$ = scm_cons (SCM_EOL, SCM_EOL);
823 SCM c = scm_cons ($2->self_scm (), SCM_EOL);
824 scm_gc_unprotect_object ($2->self_scm ()); /* UGH */
825 if (ly_c_pair_p (ly_cdr (s)))
826 scm_set_cdr_x (ly_cdr (s), c); /* append */
828 scm_set_car_x (s, c); /* set first cons */
829 scm_set_cdr_x (s, c); /* remember last cell */
831 | Music_list embedded_scm {
847 | ALTERNATIVE '{' Music_list '}' {
854 REPEAT simple_string bare_unsigned Music Alternative_music
858 SCM alts = ly_c_pair_p ($5) ? ly_car ($5) : SCM_EOL;
859 if (times < scm_ilength (alts)) {
860 unsmob_music (ly_car (alts))
861 ->origin ()->warning (
862 _ ("More alternatives than repeats. Junking excess alternatives."));
863 alts = ly_truncate_list (times, alts);
867 SCM proc = ly_scheme_function ("make-repeated-music");
869 SCM mus = scm_call_1 (proc, $2);
870 scm_gc_protect_object (mus); // UGH.
871 Music *r = unsmob_music (mus);
874 r-> set_property ("element", beg->self_scm ());
875 scm_gc_unprotect_object (beg->self_scm ());
877 r->set_property ("repeat-count", scm_int2num (times >? 1));
879 r-> set_property ("elements",alts);
880 if (ly_c_equal_p ($2, scm_makfrom0str ("tremolo"))) {
882 TODO: move this code to Scheme.
886 we can not get durations and other stuff correct down the line, so we have to
887 add to the duration log here.
889 SCM func = ly_scheme_function ("shift-duration-log");
891 int dots = ($3 % 3) ? 0 : 1;
892 int shift = -intlog2 ((dots) ? ($3*2/3) : $3);
894 Sequential_music *seq = dynamic_cast<Sequential_music*> ($4);
897 int list_len = scm_ilength (seq->music_list ());
899 seq->origin ()->warning ("Chord tremolo must have 2 elements.");
901 r->compress (Moment (Rational (1, list_len)));
903 scm_call_3 (func, r->self_scm (), scm_int2num (shift),scm_int2num (dots));
906 r->set_spot (*$4->origin ());
913 SEQUENTIAL '{' Music_list '}' {
914 $$ = MY_MAKE_MUSIC ("SequentialMusic");
915 $$->set_property ("elements", ly_car ($3));
916 $$->set_spot (THIS->here_input ());
918 | '{' Music_list '}' {
919 $$ = MY_MAKE_MUSIC ("SequentialMusic");
920 $$->set_property ("elements", ly_car ($2));
921 $$->set_spot (THIS->here_input ());
926 SIMULTANEOUS '{' Music_list '}'{
927 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
928 $$->set_property ("elements", ly_car ($3));
929 $$->set_spot (THIS->here_input ());
932 | simul_open Music_list simul_close {
933 $$ = MY_MAKE_MUSIC ("SimultaneousMusic");
934 $$->set_property ("elements", ly_car ($2));
935 $$->set_spot (THIS->here_input ());
940 event_chord { $$ = $1; }
942 $$ = unsmob_music ($1);
949 optional_context_mod:
950 /**/ { $$ = SCM_EOL; }
951 | WITH { THIS->lexer_->push_initial_state (); }
952 '{' context_mod_list '}'
954 THIS->lexer_->pop_state ();
960 /* */ { $$ = SCM_EOL; }
961 | context_mod_list context_mod {
962 $$ = scm_cons ($2, $1);
968 Prefix_composite_music { $$ = $1; }
969 | Grouped_music_list { $$ = $1; }
973 Simultaneous_music { $$ = $1; }
974 | Sequential_music { $$ = $1; }
977 Generic_prefix_music_scm:
979 $$ = scm_list_2 ($1, make_input (THIS->here_input ()));
981 | MUSIC_FUNCTION_SCM {
984 $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3);
986 | MUSIC_FUNCTION_MUSIC {
989 $$ = scm_list_3 ($1, make_input (THIS->pop_spot ()), $3->self_scm ());
990 scm_gc_unprotect_object ($3->self_scm ());
992 | MUSIC_FUNCTION_SCM_MUSIC {
994 } embedded_scm Music {
995 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3, $4->self_scm ());
996 scm_gc_unprotect_object ($4->self_scm ());
998 | MUSIC_FUNCTION_MUSIC_MUSIC {
1001 $$ = scm_list_4 ($1, make_input (THIS->pop_spot ()), $3->self_scm (), $4->self_scm ());
1002 scm_gc_unprotect_object ($3->self_scm ());
1003 scm_gc_unprotect_object ($4->self_scm ());
1005 | MUSIC_FUNCTION_SCM_MUSIC_MUSIC {
1007 } embedded_scm Music Music {
1008 $$ = scm_list_5 ($1, make_input (THIS->pop_spot ()),
1009 $3, $4->self_scm (), $5->self_scm ());
1010 scm_gc_unprotect_object ($5->self_scm ());
1011 scm_gc_unprotect_object ($4->self_scm ());
1015 Generic_prefix_music:
1016 Generic_prefix_music_scm {
1017 SCM func = ly_car ($1);
1018 Input *loc = unsmob_input (ly_cadr ($1));
1019 SCM args = ly_cddr ($1);
1020 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
1023 for (SCM s = sig, t = args;
1024 ok && ly_c_pair_p (s) && ly_c_pair_p (t);
1025 s = ly_cdr (s), t = ly_cdr (t)) {
1027 if (scm_call_1 (ly_car (s), ly_car (t)) != SCM_BOOL_T)
1029 loc->error (_f ("Argument %d failed typecheck", k));
1030 THIS->error_level_ = 1;
1036 m = scm_apply_0 (func, ly_cdr ($1));
1037 if (unsmob_music (m))
1039 $$ = unsmob_music (m);
1040 scm_gc_protect_object (m);
1045 loc->error (_ ("Music head function should return Music object."));
1046 $$ = MY_MAKE_MUSIC ("Music");
1048 $$->set_spot (*loc);
1053 Prefix_composite_music:
1054 Generic_prefix_music {
1057 | CONTEXT simple_string '=' simple_string optional_context_mod Music {
1058 $$ = context_spec_music ($2, $4, $6, $5);
1061 | CONTEXT simple_string optional_context_mod Music {
1062 $$ = context_spec_music ($2, SCM_UNDEFINED, $4, $3);
1064 | NEWCONTEXT simple_string optional_context_mod Music {
1065 $$ = context_spec_music ($2, get_next_unique_context (), $4,
1076 int n = ly_scm2int (ly_car ($3)); int d = ly_scm2int (ly_cdr ($3));
1079 $$= MY_MAKE_MUSIC ("TimeScaledMusic");
1080 $$->set_spot (THIS->pop_spot ());
1082 $$->set_property ("element", mp->self_scm ());
1083 scm_gc_unprotect_object (mp->self_scm ());
1084 $$->set_property ("numerator", scm_int2num (n));
1085 $$->set_property ("denominator", scm_int2num (d));
1086 $$->compress (Moment (Rational (n,d)));
1089 | Repeated_music { $$ = $1; }
1090 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords Music {
1091 $$ = MY_MAKE_MUSIC ("TransposedMusic");
1093 Pitch from = *unsmob_pitch ($2);
1094 Pitch to = *unsmob_pitch ($3);
1096 p->transpose (interval (from, to));
1097 $$->set_property ("element", p->self_scm ());
1098 scm_gc_unprotect_object (p->self_scm ());
1102 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
1103 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1107 THIS->lexer_->pop_state ();
1111 SCM nn = THIS->lexer_->lookup_identifier ("drumPitchNames");
1112 THIS->lexer_->push_note_state (alist_to_hashq (nn));
1114 /* FIXME: This used to be: */
1116 /* Grouped_music_list */
1118 THIS->lexer_->pop_state ();
1121 { THIS->lexer_->push_figuredbass_state (); }
1122 /* FIXME: This used to be:
1124 but that breaks web build
1128 Music *chm = MY_MAKE_MUSIC ("UntransposableMusic");
1129 chm->set_property ("element", $3->self_scm ());
1131 scm_gc_unprotect_object ($3->self_scm ());
1133 THIS->lexer_->pop_state ();
1136 SCM nn = THIS->lexer_->lookup_identifier ("chordmodifiers");
1137 THIS->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1138 nn = THIS->lexer_->lookup_identifier ("pitchnames");
1139 THIS->lexer_->push_chord_state (alist_to_hashq (nn));
1147 Music *chm = MY_MAKE_MUSIC ("UnrelativableMusic");
1148 chm->set_property ("element", $3->self_scm ());
1149 scm_gc_unprotect_object ($3->self_scm ());
1152 THIS->lexer_->pop_state ();
1155 { THIS->lexer_->push_lyric_state (); }
1162 THIS->lexer_->pop_state ();
1164 | relative_music { $$ = $1; }
1165 | re_rhythmed_music { $$ = $1; }
1166 | TAG embedded_scm Music {
1167 tag_music ($3, $2, THIS->here_input ());
1173 RELATIVE absolute_pitch Music {
1175 Pitch start = *unsmob_pitch ($2);
1176 $$ = make_music_relative (start, m);
1177 scm_gc_unprotect_object (m->self_scm ());
1179 | RELATIVE Composite_music {
1181 /* FIXME: why is octave==0 and default not middleC? */
1182 Pitch middle_c (-1, 0, 0);
1183 $$ = make_music_relative (middle_c, m);
1184 scm_gc_unprotect_object (m->self_scm ());
1189 NEWLYRICS { THIS->lexer_->push_lyric_state (); }
1191 Grouped_music_list {
1192 /* Can also use Music at the expensive of two S/Rs similar to
1193 \repeat \alternative */
1194 THIS->lexer_->pop_state ();
1196 Music *music = MY_MAKE_MUSIC ("SimultaneousMusic");
1197 music->set_property ("elements", scm_list_1 ($3->self_scm ()));
1200 $$ = scm_cons ($3->self_scm (), SCM_EOL);
1203 | new_lyrics NEWLYRICS { THIS->lexer_->push_lyric_state (); }
1204 Grouped_music_list {
1205 THIS->lexer_->pop_state ();
1206 $$ = scm_cons ($4->self_scm (), $1);
1211 Grouped_music_list new_lyrics {
1213 /* FIXME: should find out uniqueXXX name from music */
1214 SCM name = $1->get_property ("context-id");
1215 //if (name == SCM_EOL)
1216 if (!ly_c_string_p (name))
1217 name = scm_makfrom0str ("");
1219 SCM context = scm_makfrom0str ("Lyrics");
1220 Music *all = MY_MAKE_MUSIC ("SimultaneousMusic");
1223 for (SCM s = $2; ly_c_pair_p (s); s = ly_cdr (s))
1225 Music *music = unsmob_music (ly_car (s));
1226 Music *com = make_lyric_combine_music (name, music);
1227 Music *csm = context_spec_music (context,
1228 get_next_unique_context (), com, SCM_EOL);
1229 lst = scm_cons (csm->self_scm (), lst);
1231 /* FIXME: only first lyric music is accepted,
1232 the rest is junked */
1233 all->set_property ("elements", scm_cons ($1->self_scm (),
1236 scm_gc_unprotect_object ($1->self_scm ());
1238 | LYRICSTO string Music {
1241 $$ = make_lyric_combine_music (name, music);
1242 scm_gc_unprotect_object (music->self_scm ());
1247 CHANGE STRING '=' STRING {
1248 Music*t= MY_MAKE_MUSIC ("ContextChange");
1249 t-> set_property ("change-to-type", scm_string_to_symbol ($2));
1250 t-> set_property ("change-to-id", $4);
1253 $$->set_spot (THIS->here_input ());
1259 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1260 scm_string_to_symbol ($1), $3);
1262 | UNSET simple_string {
1263 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1264 scm_string_to_symbol ($2));
1266 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1267 $$ = scm_list_4 (ly_symbol2scm ("push"),
1268 scm_string_to_symbol ($2), $3, $5);
1270 | REVERT simple_string embedded_scm {
1271 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1272 scm_string_to_symbol ($2), $3);
1277 CONSISTSEND { $$ = ly_symbol2scm ("consists-end"); }
1278 | CONSISTS { $$ = ly_symbol2scm ("consists"); }
1279 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1281 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1282 | DENIES { $$ = ly_symbol2scm ("denies"); }
1284 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1285 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1286 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1287 | NAME { $$ = ly_symbol2scm ("context-name"); }
1291 property_operation { $$ = $1; }
1292 | context_def_mod STRING {
1293 $$ = scm_list_2 ($1, $2);
1299 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1300 scm_string_to_symbol ($1));
1302 | simple_string '.' simple_string {
1303 $$ = scm_list_2 (scm_string_to_symbol ($1),
1304 scm_string_to_symbol ($3));
1309 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1310 $$ = property_op_to_music (scm_list_4 (
1311 ly_symbol2scm ("poppush"),
1314 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1316 | REVERT context_prop_spec embedded_scm {
1317 $$ = property_op_to_music (scm_list_3 (
1318 ly_symbol2scm ("pop"),
1322 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1324 | SET context_prop_spec '=' scalar {
1325 $$ = property_op_to_music (scm_list_3 (
1326 ly_symbol2scm ("assign"),
1329 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1331 | UNSET context_prop_spec {
1332 $$ = property_op_to_music (scm_list_2 (
1333 ly_symbol2scm ("unset"),
1335 $$= context_spec_music (ly_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
1337 | ONCE music_property_def {
1338 SCM e = $2->get_property ("element");
1339 unsmob_music (e)->set_property ("once", SCM_BOOL_T);
1350 | STRING_IDENTIFIER {
1353 | string '+' string {
1354 $$ = scm_string_append (scm_list_2 ($1, $3));
1358 simple_string: STRING {
1369 $$ = scm_int2num ($1);
1376 $$ = scm_int2num ($1);
1381 FIXME: remove or fix this comment. What is `This'?
1385 Adding pre_events to the simple_element
1386 makes the choice between
1392 simple_element: STRING
1394 a single shift/reduction conflict.
1396 nevertheless, this is not very clean, and we should find a different
1406 pre_events simple_element post_events {
1407 SCM elts = $2-> get_property ("elements");
1409 elts = ly_append2 (elts, scm_reverse_x ($3, SCM_EOL));
1411 $2->set_property ("elements", elts);
1415 | note_chord_element
1420 chord_body optional_notemode_duration post_events
1422 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1423 SCM es = $1->get_property ("elements");
1424 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1426 for (SCM s = es; ly_c_pair_p (s); s = ly_cdr (s))
1427 unsmob_music (ly_car (s))->set_property ("duration", dur);
1428 es = ly_append2 (es, postevs);
1430 $1-> set_property ("elements", es);
1441 simul_open: DOUBLE_ANGLE_OPEN
1444 simul_close: DOUBLE_ANGLE_CLOSE
1448 chord_open chord_body_elements chord_close
1450 $$ = MY_MAKE_MUSIC ("EventChord");
1451 $$->set_property ("elements",
1452 scm_reverse_x ($2, SCM_EOL));
1456 chord_body_elements:
1457 /* empty */ { $$ = SCM_EOL; }
1458 | chord_body_elements chord_body_element {
1459 $$ = scm_cons ($2->self_scm (), $1);
1460 scm_gc_unprotect_object ($2->self_scm ());
1465 pitch exclamations questions post_events
1467 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1468 n->set_property ("pitch", $1);
1470 n->set_property ("cautionary", SCM_BOOL_T);
1471 if ($2 % 2 || $3 % 2)
1472 n->set_property ("force-accidental", SCM_BOOL_T);
1474 if (ly_c_pair_p ($4)) {
1475 SCM arts = scm_reverse_x ($4, SCM_EOL);
1476 n->set_property ("articulations", arts);
1480 | DRUM_PITCH post_events {
1481 Music *n = MY_MAKE_MUSIC ("NoteEvent");
1482 n->set_property ("duration", $2);
1483 n->set_property ("drum-type", $1);
1484 n->set_spot (THIS->here_input ());
1486 if (ly_c_pair_p ($2)) {
1487 SCM arts = scm_reverse_x ($2, SCM_EOL);
1488 n->set_property ("articulations", arts);
1495 ADDQUOTE string Music {
1496 SCM adder = ly_scheme_function ("add-quotable");
1498 scm_call_2 (adder, $2, $3->self_scm ());
1499 scm_gc_unprotect_object ($3->self_scm ());
1505 $$ = MY_MAKE_MUSIC ("EventChord");
1506 $$->set_property ("elements", scm_cons ($1->self_scm (), SCM_EOL));
1507 scm_gc_unprotect_object ($1->self_scm ());
1509 $$-> set_spot (THIS->here_input ());
1510 $1-> set_spot (THIS->here_input ());
1512 | SKIP duration_length {
1513 Music *skip = MY_MAKE_MUSIC ("SkipMusic");
1514 skip->set_property ("duration", $2);
1518 | QUOTE STRING duration_length {
1519 SCM tab = THIS->lexer_->lookup_identifier ("musicQuotes");
1521 if (scm_hash_table_p (tab) == SCM_BOOL_T)
1523 SCM key = $2; // use symbol?
1524 evs = scm_hash_ref (tab, key, SCM_BOOL_F);
1527 if (ly_c_vector_p (evs))
1529 quote = MY_MAKE_MUSIC ("QuoteMusic");
1530 quote->set_property ("duration", $3);
1531 quote->set_property ("quoted-events", evs);
1533 THIS->here_input ().warning (_f ("Can\'t find music"));
1534 quote = MY_MAKE_MUSIC ("Event");
1536 quote->set_spot (THIS->here_input ());
1539 | OCTAVE { THIS->push_spot (); }
1541 Music *m = MY_MAKE_MUSIC ("RelativeOctaveCheck");
1543 $$->set_spot (THIS->pop_spot ());
1544 $$->set_property ("pitch", $3);
1547 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1548 m->set_property ("span-direction", scm_int2num (START));
1549 m->set_spot (THIS->here_input ());
1551 $$ = MY_MAKE_MUSIC ("EventChord");
1552 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1553 scm_gc_unprotect_object (m->self_scm ());
1554 $$->set_spot (THIS->here_input ());
1557 Music *m = MY_MAKE_MUSIC ("LigatureEvent");
1558 m->set_property ("span-direction", scm_int2num (STOP));
1559 m->set_spot (THIS->here_input ());
1561 $$ = MY_MAKE_MUSIC ("EventChord");
1562 $$->set_property ("elements", scm_cons (m->self_scm (), SCM_EOL));
1563 $$->set_spot (THIS->here_input ());
1564 scm_gc_unprotect_object (m->self_scm ());
1567 $$ = MY_MAKE_MUSIC ("VoiceSeparator");
1568 $$->set_spot (THIS->here_input ());
1571 SCM pipe =THIS->lexer_->lookup_identifier ("pipeSymbol");
1573 if (Music * m = unsmob_music (pipe))
1576 $$ = MY_MAKE_MUSIC ("BarCheck");
1578 $$->set_spot (THIS->here_input ());
1580 | TRANSPOSITION pitch {
1581 $$ = set_property_music (ly_symbol2scm ("instrumentTransposition"),
1583 $$->set_spot (THIS-> here_input ());
1584 $$ = context_spec_music (ly_symbol2scm ("Staff"), SCM_UNDEFINED,
1588 Music *t = set_property_music (ly_symbol2scm ("whichBar"), $2);
1590 Music *csm = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1592 $$ = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED, csm, SCM_EOL);
1593 $$->set_spot (THIS->here_input ());
1594 t->set_spot (THIS->here_input ());
1596 | PARTIAL duration_length {
1597 Moment m = - unsmob_duration ($2)->get_length ();
1598 Music *p = set_property_music (ly_symbol2scm ( "measurePosition"),m.smobbed_copy ());
1599 p->set_spot (THIS->here_input ());
1600 p = context_spec_music (ly_symbol2scm ("Timing"), SCM_UNDEFINED,
1602 p = context_spec_music (ly_symbol2scm ("Score"), SCM_UNDEFINED,
1607 SCM proc = ly_scheme_function ("make-clef-set");
1609 SCM result = scm_call_1 (proc, $2);
1610 scm_gc_protect_object (result);
1611 $$ = unsmob_music (result);
1614 SCM proc= ly_scheme_function ("make-time-signature-set");
1616 SCM result = scm_apply_2 (proc, ly_car ($2), ly_cdr ($2), SCM_EOL);
1617 scm_gc_protect_object (result);
1618 $$ = unsmob_music (result);
1621 SCM proc = ly_scheme_function ("make-mark-set");
1623 SCM result = scm_call_1 (proc, $2);
1624 scm_gc_protect_object (result);
1625 $$ = unsmob_music (result);
1631 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent");
1634 Music *m = MY_MAKE_MUSIC ("MarkEvent");
1641 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1644 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1646 Music *key= MY_MAKE_MUSIC ("KeyChangeEvent");
1647 if (scm_ilength ($3) > 0)
1649 key->set_property ("pitch-alist", $3);
1650 key->set_property ("tonic", Pitch (0,0,0).smobbed_copy ());
1651 ((Music*)key)->transpose (* unsmob_pitch ($2));
1653 THIS->parser_error (_ ("Second argument must be pitch list."));
1664 | post_events post_event {
1665 $2->set_spot (THIS->here_input ());
1666 $$ = scm_cons ($2->self_scm (), $$);
1667 scm_gc_unprotect_object ($2->self_scm ());
1669 | post_events tagged_post_event {
1670 $2 -> set_spot (THIS->here_input ());
1671 $$ = scm_cons ($2->self_scm (), $$);
1672 scm_gc_unprotect_object ($2->self_scm ());
1678 '-' TAG embedded_scm post_event {
1679 tag_music ($4, $3, THIS->here_input ());
1685 direction_less_event {
1689 if (!THIS->lexer_->is_lyric_state ())
1690 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1691 $$ = MY_MAKE_MUSIC ("HyphenEvent");
1694 if (!THIS->lexer_->is_lyric_state ())
1695 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
1696 $$ = MY_MAKE_MUSIC ("ExtenderEvent");
1698 | script_dir direction_reqd_event {
1700 $2->set_property ("direction", scm_int2num ($1));
1703 | script_dir direction_less_event {
1705 $2->set_property ("direction", scm_int2num ($1));
1708 | string_number_event
1711 string_number_event:
1713 Music *s = MY_MAKE_MUSIC ("StringNumberEvent");
1714 s->set_property ("string-number", scm_int2num ($1));
1715 s->set_spot (THIS->here_input ());
1721 direction_less_event:
1727 TODO: should take all these defs out of the parser, adn make use
1731 (set-articulation '~ "trill")
1734 Music *m = MY_MAKE_MUSIC ("BeamEvent");
1735 m->set_spot (THIS->here_input ());
1736 m->set_property ("span-direction", scm_int2num (START));
1740 Music *m = MY_MAKE_MUSIC ("BeamEvent");
1741 m->set_spot (THIS->here_input ());
1742 m->set_property ("span-direction", scm_int2num (STOP));
1746 Music *m = MY_MAKE_MUSIC ("TieEvent");
1747 m->set_spot (THIS->here_input ());
1752 dynamic_cast<Music *> ($$)->set_property ("span-direction",
1753 scm_int2num (START));
1757 dynamic_cast<Music *> ($$)->set_property ("span-direction",
1758 scm_int2num (STOP));
1760 | EVENT_IDENTIFIER {
1761 $$ = unsmob_music ($1);
1764 Music *a = MY_MAKE_MUSIC ("TremoloEvent");
1765 a->set_spot (THIS->here_input ());
1766 a->set_property ("tremolo-type", scm_int2num ($1));
1771 direction_reqd_event:
1775 | script_abbreviation {
1776 SCM s = THIS->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1777 Music *a = MY_MAKE_MUSIC ("ArticulationEvent");
1778 if (ly_c_string_p (s))
1779 a->set_property ("articulation-type", s);
1780 else THIS->parser_error (_ ("Expecting string as script definition"));
1786 /**/ { $$ = SCM_EOL; }
1787 | '=' { $$ = scm_int2num (0); }
1788 | '=' sub_quotes { $$ = scm_int2num ($2); }
1789 | '=' sup_quotes { $$ = scm_int2num ($2); }
1814 | NOTENAME_PITCH sup_quotes {
1815 Pitch p = *unsmob_pitch ($1);
1816 p = p.transposed (Pitch ($2,0,0));
1817 $$ = p.smobbed_copy ();
1819 | NOTENAME_PITCH sub_quotes {
1820 Pitch p =* unsmob_pitch ($1);
1821 p = p.transposed (Pitch (-$2,0,0));
1822 $$ = p.smobbed_copy ();
1834 | TONICNAME_PITCH sup_quotes {
1835 Pitch p = *unsmob_pitch ($1);
1836 p = p.transposed (Pitch ($2,0,0));
1837 $$ = p.smobbed_copy ();
1839 | TONICNAME_PITCH sub_quotes {
1840 Pitch p =* unsmob_pitch ($1);
1842 p = p.transposed (Pitch (-$2,0,0));
1843 $$ = p.smobbed_copy ();
1853 pitch_also_in_chords:
1860 Music *s = MY_MAKE_MUSIC ("SlurEvent");
1862 s->set_spot (THIS->here_input ());
1865 Music *s = MY_MAKE_MUSIC ("PhrasingSlurEvent");
1867 s->set_spot (THIS->here_input ());
1870 Music *s = MY_MAKE_MUSIC ("CrescendoEvent");
1872 s->set_spot (THIS->here_input ());
1875 Music *s = MY_MAKE_MUSIC ("DecrescendoEvent");
1877 s->set_spot (THIS->here_input ());
1884 Music *s = MY_MAKE_MUSIC ("CrescendoEvent");
1885 s->set_spot (THIS->here_input ());
1890 Music *s= MY_MAKE_MUSIC ("SlurEvent");
1892 s->set_spot (THIS->here_input ());
1896 Music *s= MY_MAKE_MUSIC ("PhrasingSlurEvent");
1898 s->set_property ("span-type",
1899 scm_makfrom0str ("phrasing-slur"));
1900 s->set_spot (THIS->here_input ());
1906 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1907 t->set_property ("text", $1);
1908 t->set_spot (THIS->here_input ());
1912 Music *t = MY_MAKE_MUSIC ("TextScriptEvent");
1913 t->set_property ("text",
1914 make_simple_markup (THIS->lexer_->encoding (), $1));
1915 t->set_spot (THIS->here_input ());
1920 Music *t = MY_MAKE_MUSIC ("FingerEvent");
1921 t->set_property ("digit", scm_int2num ($1));
1922 t->set_spot (THIS->here_input ());
1927 script_abbreviation:
1929 $$ = scm_makfrom0str ("Hat");
1932 $$ = scm_makfrom0str ("Plus");
1935 $$ = scm_makfrom0str ("Dash");
1938 $$ = scm_makfrom0str ("Bar");
1941 $$ = scm_makfrom0str ("Larger");
1944 $$ = scm_makfrom0str ("Dot");
1947 $$ = scm_makfrom0str ("Underscore");
1954 | '-' { $$ = CENTER; }
1965 multiplied_duration {
1970 optional_notemode_duration:
1972 Duration dd = THIS->default_duration_;
1973 $$ = dd.smobbed_copy ();
1975 THIS->beam_check ($$);
1977 | multiplied_duration {
1979 THIS->default_duration_ = *unsmob_duration ($$);
1981 THIS->beam_check ($$);
1986 bare_unsigned dots {
1988 if (!is_duration ($1))
1989 THIS->parser_error (_f ("not a duration: %d", $1));
1993 $$ = Duration (len, $2).smobbed_copy ();
1995 | DURATION_IDENTIFIER dots {
1996 Duration *d = unsmob_duration ($1);
1997 Duration k (d->duration_log (), d->dot_count () + $2);
2003 multiplied_duration:
2007 | multiplied_duration '*' bare_unsigned {
2008 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2010 | multiplied_duration '*' FRACTION {
2011 Rational m (ly_scm2int (ly_car ($3)), ly_scm2int (ly_cdr ($3)));
2013 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2018 FRACTION { $$ = $1; }
2019 | UNSIGNED '/' UNSIGNED {
2020 $$ = scm_cons (scm_int2num ($1), scm_int2num ($3));
2037 | ':' bare_unsigned {
2038 if (!is_duration ($2))
2039 THIS->parser_error (_f ("not a duration: %d", $2));
2046 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2047 $$ = scm_list_2 (ly_scheme_function ("number-markup"),
2051 $$ = scm_number_to_string (scm_int2num ($1), scm_int2num (10));
2052 $$ = scm_list_2 (ly_scheme_function ("number-markup"),
2055 | STRING { $$ = $1; }
2066 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2067 $$ = bfr->self_scm ();
2068 scm_gc_unprotect_object ($$);
2071 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
2072 $$ = bfr->self_scm ();
2074 bfr->set_property ("figure", $1);
2076 scm_gc_unprotect_object ($$);
2078 | bass_figure bass_mod {
2079 Music *m = unsmob_music ($1);
2081 SCM salter = m->get_property ("alteration");
2082 int alter = ly_c_number_p (salter) ? ly_scm2int (salter) : 0;
2083 m->set_property ("alteration",
2084 scm_int2num (alter + $2));
2086 m->set_property ("alteration", scm_int2num (0));
2094 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2099 | br_bass_figure ']' {
2101 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2109 | figure_list br_bass_figure {
2110 $$ = scm_cons ($2, $1);
2115 FIGURE_OPEN figure_list FIGURE_CLOSE {
2116 Music *m = MY_MAKE_MUSIC ("EventChord");
2117 $2 = scm_reverse_x ($2, SCM_EOL);
2118 m->set_property ("elements", $2);
2119 $$ = m->self_scm ();
2130 pitch exclamations questions oct_check optional_notemode_duration optional_rest {
2132 Input i = THIS->pop_spot ();
2133 if (!THIS->lexer_->is_note_state ())
2134 THIS->parser_error (_ ("Have to be in Note mode for notes"));
2138 n = MY_MAKE_MUSIC ("RestEvent");
2140 n = MY_MAKE_MUSIC ("NoteEvent");
2142 n->set_property ("pitch", $1);
2143 n->set_property ("duration", $5);
2145 if (ly_c_number_p ($4))
2147 int q = ly_scm2int ($4);
2148 n->set_property ("absolute-octave", scm_int2num (q-1));
2152 n->set_property ("cautionary", SCM_BOOL_T);
2153 if ($2 % 2 || $3 % 2)
2154 n->set_property ("force-accidental", SCM_BOOL_T);
2156 Music *v = MY_MAKE_MUSIC ("EventChord");
2157 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2158 scm_gc_unprotect_object (n->self_scm ());
2164 | DRUM_PITCH optional_notemode_duration {
2165 Input i = THIS->pop_spot ();
2167 Music *n = MY_MAKE_MUSIC ("NoteEvent");
2168 n->set_property ("duration", $2);
2169 n->set_property ("drum-type", $1);
2171 Music *v = MY_MAKE_MUSIC ("EventChord");
2172 v->set_property ("elements", scm_list_1 (n->self_scm ()));
2173 scm_gc_unprotect_object (n->self_scm ());
2179 | figure_spec optional_notemode_duration {
2180 Music *m = unsmob_music ($1);
2181 Input i = THIS->pop_spot ();
2183 for (SCM s = m->get_property ("elements"); ly_c_pair_p (s); s = ly_cdr (s))
2185 unsmob_music (ly_car (s))->set_property ("duration", $2);
2189 | RESTNAME optional_notemode_duration {
2191 Input i = THIS->pop_spot ();
2193 if (ly_scm2string ($1) == "s") {
2195 ev = MY_MAKE_MUSIC ("SkipEvent");
2198 ev = MY_MAKE_MUSIC ("RestEvent");
2201 ev->set_property ("duration", $2);
2203 Music *velt = MY_MAKE_MUSIC ("EventChord");
2204 velt->set_property ("elements", scm_list_1 (ev->self_scm ()));
2207 scm_gc_unprotect_object (ev->self_scm ());
2211 | MULTI_MEASURE_REST optional_notemode_duration {
2214 SCM proc = ly_scheme_function ("make-multi-measure-rest");
2215 SCM mus = scm_call_2 (proc, $2,
2216 make_input (THIS->here_input ()));
2217 scm_gc_protect_object (mus);
2218 $$ = unsmob_music (mus);
2221 | lyric_element optional_notemode_duration {
2222 Input i = THIS->pop_spot ();
2223 if (!THIS->lexer_->is_lyric_state ())
2224 THIS->parser_error (_ ("Have to be in Lyric mode for lyrics"));
2226 Music *lreq = MY_MAKE_MUSIC ("LyricEvent");
2227 lreq->set_property ("text", $1);
2228 lreq->set_property ("duration",$2);
2230 Music *velt = MY_MAKE_MUSIC ("EventChord");
2231 velt->set_property ("elements", scm_list_1 (lreq->self_scm ()));
2238 if (!THIS->lexer_->is_chord_state ())
2239 THIS->parser_error (_ ("Have to be in Chord mode for chords"));
2240 $$ = unsmob_music ($1);
2245 /* FIXME: lyric flavoured markup would be better */
2253 steno_tonic_pitch optional_notemode_duration {
2254 $$ = make_chord ($1, $2, SCM_EOL);
2256 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2257 SCM its = scm_reverse_x ($4, SCM_EOL);
2258 $$ = make_chord ($1, $2, scm_cons ($3, its));
2266 | chord_items chord_item {
2267 $$ = scm_cons ($2, $$);
2273 $$ = ly_symbol2scm ("chord-colon");
2276 $$ = ly_symbol2scm ("chord-caret");
2278 | CHORD_SLASH steno_tonic_pitch {
2279 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2281 | CHORD_BASS steno_tonic_pitch {
2282 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2291 $$ = scm_reverse_x ($1, SCM_EOL);
2299 step_number { $$ = scm_cons ($1, SCM_EOL); }
2300 | step_numbers '.' step_number {
2301 $$ = scm_cons ($3, $$);
2307 $$ = make_chord_step ($1, 0);
2309 | bare_unsigned '+' {
2310 $$ = make_chord_step ($1, SHARP);
2312 | bare_unsigned CHORD_MINUS {
2313 $$ = make_chord_step ($1, FLAT);
2320 TODO: should deprecate in favor of Scheme?
2324 number_expression '+' number_term {
2325 $$ = scm_sum ($1, $3);
2327 | number_expression '-' number_term {
2328 $$ = scm_difference ($1, $3);
2337 | number_factor '*' number_factor {
2338 $$ = scm_product ($1, $3);
2340 | number_factor '/' number_factor {
2341 $$ = scm_divide ($1, $3);
2346 '-' number_factor { /* %prec UNARY_MINUS */
2347 $$ = scm_difference ($2, SCM_UNDEFINED);
2355 $$ = scm_int2num ($1);
2360 | NUMBER_IDENTIFIER {
2363 | REAL NUMBER_IDENTIFIER {
2364 $$ = scm_make_real (ly_scm2double ($1) *ly_scm2double ($2));
2366 | UNSIGNED NUMBER_IDENTIFIER {
2367 $$ = scm_make_real ($1 *ly_scm2double ($2));
2383 if (scm_integer_p ($1) == SCM_BOOL_T)
2385 int k = ly_scm2int ($1);
2389 THIS->parser_error (_ ("need integer number arg"));
2400 | exclamations '!' { $$ ++; }
2405 | questions '?' { $$ ++; }
2415 { THIS->lexer_->push_markup_state (); }
2418 THIS->lexer_->pop_state ();
2424 This should be done more dynamically if possible.
2428 $$ = make_simple_markup (THIS->lexer_->encoding (), $1);
2430 | MARKUP_HEAD_EMPTY {
2431 $$ = scm_list_1 ($1);
2433 | MARKUP_HEAD_MARKUP0 markup {
2434 $$ = scm_list_2 ($1, $2);
2436 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2437 $$ = scm_list_3 ($1, $2, $3);
2439 | MARKUP_HEAD_SCM0_MARKUP1 SCM_T markup {
2440 $$ = scm_list_3 ($1, $2, $3);
2445 | MARKUP_HEAD_LIST0 markup_list {
2446 $$ = scm_list_2 ($1,$2);
2448 | MARKUP_HEAD_SCM0 embedded_scm {
2449 $$ = scm_list_2 ($1, $2);
2451 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm markup {
2452 $$ = scm_list_4 ($1, $2, $3, $4);
2454 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2455 $$ = scm_list_4 ($1, $2, $3, $4);
2457 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2458 $$ = scm_list_3 ($1, $2, $3);
2460 | MARKUP_IDENTIFIER {
2463 | STRING_IDENTIFIER {
2467 SCM nn = THIS->lexer_->lookup_identifier ("pitchnames");
2468 THIS->lexer_->push_note_state (alist_to_hashq (nn));
2470 /* cont */ score_block {
2471 /* WIP this is a bit arbitrary,
2472 we should also allow \book or Composite_music.
2473 However, you'd typically want to change paper
2474 settings, and need a \score block anyway. */
2476 THIS->lexer_->pop_state ();
2478 Book *book = new Book;
2479 book->scores_.push (score);
2481 Music_output_def *paper = get_paper (THIS);
2482 book->bookpaper_ = get_bookpaper (THIS);
2484 SCM s = book->to_stencil (paper, THIS->header_);
2485 scm_gc_unprotect_object (score->self_scm ());
2486 scm_gc_unprotect_object (book->self_scm ());
2487 $$ = scm_list_2 (ly_scheme_function ("stencil-markup"), s);
2492 chord_open markup_list_body chord_close { $$ = scm_reverse_x ($2, SCM_EOL); }
2496 '{' markup_list_body '}' {
2497 SCM line = ly_scheme_function ("line-markup");
2499 $$ = scm_list_2 (line, scm_reverse_x ($2, SCM_EOL));
2504 /**/ { $$ = SCM_EOL; }
2505 | markup_list_body markup {
2506 $$ = scm_cons ($2, $1);
2514 My_lily_parser::set_yydebug (bool )
2522 My_lily_parser::do_yyparse ()
2524 yyparse ((void*)this);
2529 Should make this optional? It will also complain when you do
2533 which is entirely legitimate.
2535 Or we can scrap it. Barchecks should detect wrong durations, and
2536 skipTypesetting speeds it up a lot.
2540 My_lily_parser::beam_check (SCM dur)
2542 Duration *d = unsmob_duration (dur);
2543 if (unsmob_music (last_beam_start_) && d->duration_log () <= 2)
2545 Music *m = unsmob_music (last_beam_start_);
2546 m->origin ()->warning (_ ("Suspect duration found following this beam"));
2548 last_beam_start_ = SCM_EOL;
2556 It is a little strange to have this function in this file, but
2557 otherwise, we have to import music classes into the lexer.
2561 My_lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2563 if (ly_c_string_p (sid)) {
2565 return STRING_IDENTIFIER;
2566 } else if (ly_c_number_p (sid)) {
2568 return NUMBER_IDENTIFIER;
2569 } else if (unsmob_context_def (sid)) {
2570 *destination = unsmob_context_def (sid)->clone_scm ();
2571 return CONTEXT_DEF_IDENTIFIER;
2572 } else if (unsmob_score (sid)) {
2573 Score *score = new Score (*unsmob_score (sid));
2574 *destination = score->self_scm ();
2575 return SCORE_IDENTIFIER;
2576 } else if (Music *mus = unsmob_music (sid)) {
2577 mus = mus->clone ();
2578 *destination = mus->self_scm ();
2579 unsmob_music (*destination)->
2580 set_property ("origin", make_input (last_input_));
2581 return dynamic_cast<Event*> (mus)
2582 ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2583 } else if (unsmob_duration (sid)) {
2584 *destination = unsmob_duration (sid)->smobbed_copy ();
2585 return DURATION_IDENTIFIER;
2586 } else if (unsmob_music_output_def (sid)) {
2587 Music_output_def *p = unsmob_music_output_def (sid);
2590 *destination = p->self_scm ();
2591 return MUSIC_OUTPUT_DEF_IDENTIFIER;
2592 } else if (Text_item::markup_p (sid)) {
2594 return MARKUP_IDENTIFIER;
2601 property_op_to_music (SCM op)
2604 SCM tag = ly_car (op);
2605 SCM symbol = ly_cadr (op);
2606 SCM args = ly_cddr (op);
2607 SCM grob_val = SCM_UNDEFINED;
2608 SCM grob_sym = SCM_UNDEFINED;
2609 SCM val = SCM_UNDEFINED;
2611 if (tag == ly_symbol2scm ("assign"))
2613 m = MY_MAKE_MUSIC ("PropertySet");
2614 val = ly_car (args);
2616 else if (tag == ly_symbol2scm ("unset"))
2617 m = MY_MAKE_MUSIC ("PropertyUnset");
2618 else if (tag == ly_symbol2scm ("poppush")
2619 || tag == ly_symbol2scm ("push"))
2621 m = MY_MAKE_MUSIC ("OverrideProperty");
2622 grob_sym = ly_car (args);
2623 grob_val = ly_cadr (args);
2625 else if (tag == ly_symbol2scm ("pop")) {
2626 m = MY_MAKE_MUSIC ("RevertProperty");
2627 grob_sym = ly_car (args);
2630 m->set_property ("symbol", symbol);
2632 if (val != SCM_UNDEFINED)
2633 m->set_property ("value", val);
2634 if (grob_val != SCM_UNDEFINED)
2635 m->set_property ("grob-value", grob_val);
2637 if (grob_sym != SCM_UNDEFINED)
2639 bool itc = internal_type_checking_global_b;
2642 bool autobeam = ly_c_equal_p (symbol, ly_symbol2scm ("autoBeamSettings"));
2644 internal_type_checking_global_b = false;
2645 m->set_property ("grob-property", grob_sym);
2647 internal_type_checking_global_b = itc;
2650 if (tag == ly_symbol2scm ("poppush"))
2651 m->set_property ("pop-first", SCM_BOOL_T);
2658 context_spec_music (SCM type, SCM id, Music *m, SCM ops)
2660 Music *csm = MY_MAKE_MUSIC ("ContextSpeccedMusic");
2662 csm->set_property ("element", m->self_scm ());
2663 scm_gc_unprotect_object (m->self_scm ());
2665 csm->set_property ("context-type",
2666 ly_c_symbol_p (type) ? type : scm_string_to_symbol (type));
2667 csm->set_property ("property-operations", ops);
2669 if (ly_c_string_p (id))
2670 csm->set_property ("context-id", id);
2675 get_next_unique_context ()
2677 static int new_context_count;
2679 snprintf (s, 1024, "uniqueContext%d", new_context_count++);
2680 return scm_makfrom0str (s);