2 parser.yy -- Bison/C++ parser for LilyPond
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
13 #define YYERROR_VERBOSE 1
14 #define YYPARSE_PARAM my_lily_parser
15 #define YYLEX_PARAM my_lily_parser
16 #define PARSER ((Lily_parser *) my_lily_parser)
18 #define yyerror PARSER->parser_error
20 /* We use custom location type: Input objects */
22 #define YYLLOC_DEFAULT(Current,Rhs,N) \
23 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
28 /* We use SCMs to do strings, because it saves us the trouble of
29 deleting them. Let's hope that a stack overflow doesnt trigger a move
30 of the parse stack onto the heap. */
38 /* One shift/reduce problem
41 \repeat .. \alternative
43 \repeat { \repeat .. \alternative }
47 \repeat { \repeat } \alternative
56 %{ // -*-Fundamental-*-
61 * The rules for who is protecting what are very shady. Uniformise
64 * There are too many lexical modes?
75 #include "context-def.hh"
76 #include "dimensions.hh"
77 #include "file-path.hh"
79 #include "international.hh"
80 #include "lily-guile.hh"
81 #include "lily-lexer.hh"
82 #include "lily-parser.hh"
87 #include "output-def.hh"
88 #include "paper-book.hh"
89 #include "program-option.hh"
90 #include "scm-hash.hh"
92 #include "text-interface.hh"
100 Output_def *outputdef;
110 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
113 - Don't use lily module, create a new module instead.
114 - delay application of the function
116 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
117 scm_apply_0 (proc, args)
118 /* Syntactic Sugar. */
119 #define MAKE_SYNTAX(name, location, ...) \
120 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location), __VA_ARGS__, SCM_UNDEFINED));
122 SCM get_next_unique_context_id ();
123 SCM get_next_unique_lyrics_context_id ();
130 #define _(x) gettext (x)
134 static Music *make_music_with_input (SCM name, Input where);
135 SCM make_music_relative (Pitch start, SCM music, Input loc);
136 SCM run_music_function (Lily_parser *, SCM expr);
137 SCM get_first_context_id (SCM type, Music *m);
138 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
139 SCM make_chord_step (int step, Rational alter);
140 SCM make_simple_markup (SCM a);
141 bool is_duration (int t);
142 bool is_regular_identifier (SCM id);
143 bool ly_input_procedure_p (SCM x);
144 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
145 void set_music_properties (Music *p, SCM a);
149 /* The third option is an alias that will be used to display the
150 syntax error. Bison CVS now correctly handles backslash escapes.
152 FIXME: Bison needs to translate some of these, eg, STRING.
156 /* Keyword tokens with plain escaped name. */
157 %token ACCEPTS "\\accepts"
158 %token ADDLYRICS "\\addlyrics"
159 %token ALIAS "\\alias"
160 %token ALTERNATIVE "\\alternative"
162 %token CHANGE "\\change"
163 %token CHORDMODE "\\chordmode"
164 %token CHORDS "\\chords"
165 %token CONSISTS "\\consists"
166 %token CONTEXT "\\context"
167 %token DEFAULT "\\default"
168 %token DEFAULTCHILD "\\defaultchild"
169 %token DENIES "\\denies"
170 %token DESCRIPTION "\\description"
171 %token DRUMMODE "\\drummode"
172 %token DRUMS "\\drums"
173 %token FIGUREMODE "\\figuremode"
174 %token FIGURES "\\figures"
175 %token GROBDESCRIPTIONS "\\grobdescriptions"
176 %token HEADER "\\header"
177 %token INVALID "\\invalid"
179 %token LAYOUT "\\layout"
180 %token LYRICMODE "\\lyricmode"
181 %token LYRICS "\\lyrics"
182 %token LYRICSTO "\\lyricsto"
184 %token MARKUP "\\markup"
187 %token NOTEMODE "\\notemode"
188 %token OBJECTID "\\objectid"
189 %token OCTAVE "\\octave"
191 %token OVERRIDE "\\override"
192 %token PAPER "\\paper"
193 %token PARTIAL "\\partial"
194 %token RELATIVE "\\relative"
195 %token REMOVE "\\remove"
196 %token REPEAT "\\repeat"
198 %token REVERT "\\revert"
199 %token SCORE "\\score"
200 %token SEQUENTIAL "\\sequential"
202 %token SIMULTANEOUS "\\simultaneous"
204 %token TEMPO "\\tempo"
205 %token TIMES "\\times"
206 %token TRANSPOSE "\\transpose"
208 %token UNSET "\\unset"
211 /* Keyword token exceptions. */
212 %token TIME_T "\\time"
213 %token NEWCONTEXT "\\new"
216 /* Other string tokens. */
218 %token CHORD_BASS "/+"
219 %token CHORD_CARET "^"
220 %token CHORD_COLON ":"
221 %token CHORD_MINUS "-"
222 %token CHORD_SLASH "/"
223 %token ANGLE_OPEN "<"
224 %token ANGLE_CLOSE ">"
225 %token DOUBLE_ANGLE_OPEN "<<"
226 %token DOUBLE_ANGLE_CLOSE ">>"
227 %token E_BACKSLASH "\\"
228 %token E_ANGLE_CLOSE "\\>"
229 %token E_CHAR "\\C[haracter]"
231 %token E_EXCLAMATION "\\!"
232 %token E_BRACKET_OPEN "\\["
234 %token E_BRACKET_CLOSE "\\]"
235 %token E_ANGLE_OPEN "\\<"
241 If we give names, Bison complains.
243 %token FIGURE_CLOSE /* "\\>" */
244 %token FIGURE_OPEN /* "\\<" */
245 %token FIGURE_SPACE "_"
248 %token CHORDMODIFIERS
250 %token MULTI_MEASURE_REST
254 %token <i> E_UNSIGNED
257 /* Artificial tokens, for more generic function syntax */
258 %token <i> EXPECT_MARKUP;
259 %token <i> EXPECT_MUSIC;
260 %token <i> EXPECT_SCM;
261 /* After the last argument. */
262 %token <i> EXPECT_NO_MORE_ARGS;
264 %token <scm> BOOK_IDENTIFIER
265 %token <scm> CHORDMODIFIER_PITCH
266 %token <scm> CHORD_MODIFIER
267 %token <scm> CONTEXT_DEF_IDENTIFIER
268 %token <scm> DRUM_PITCH
269 %token <scm> DURATION_IDENTIFIER
270 %token <scm> EVENT_IDENTIFIER
271 %token <scm> FRACTION
272 %token <scm> LYRICS_STRING
273 %token <scm> LYRIC_MARKUP_IDENTIFIER
274 %token <scm> MARKUP_HEAD_EMPTY
275 %token <scm> MARKUP_HEAD_LIST0
276 %token <scm> MARKUP_HEAD_MARKUP0
277 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
278 %token <scm> MARKUP_HEAD_SCM0
279 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
280 %token <scm> MARKUP_HEAD_SCM0_SCM1
281 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
282 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
283 %token <scm> MARKUP_IDENTIFIER
284 %token <scm> MUSIC_FUNCTION
285 %token <scm> MUSIC_IDENTIFIER
286 %token <scm> NOTENAME_PITCH
287 %token <scm> NUMBER_IDENTIFIER
288 %token <scm> OUTPUT_DEF_IDENTIFIER
290 %token <scm> RESTNAME
291 %token <scm> SCM_IDENTIFIER
292 %token <scm> SCM_TOKEN
293 %token <scm> SCORE_IDENTIFIER
295 %token <scm> STRING_IDENTIFIER
296 %token <scm> TONICNAME_PITCH
299 %type <book> book_block
300 %type <book> book_body
302 %type <i> bare_unsigned
303 %type <scm> figured_bass_alteration
305 %type <i> exclamations
306 %type <i> optional_rest
311 %type <i> tremolo_type
314 %type <scm> composite_music
315 %type <scm> grouped_music_list
317 %type <scm> prefix_composite_music
318 %type <scm> repeated_music
319 %type <scm> sequential_music
320 %type <scm> simple_music
321 %type <scm> simultaneous_music
322 %type <scm> chord_body
323 %type <scm> chord_body_element
324 %type <scm> command_element
325 %type <scm> command_event
326 %type <scm> context_change
327 %type <scm> direction_less_event
328 %type <scm> direction_reqd_event
329 %type <scm> event_chord
330 %type <scm> gen_text_def
331 %type <scm> music_property_def
332 %type <scm> note_chord_element
333 %type <scm> post_event
334 %type <scm> re_rhythmed_music
335 %type <scm> relative_music
336 %type <scm> simple_element
337 %type <scm> simple_music_property_def
338 %type <scm> string_number_event
339 %type <scm> tempo_event
341 %type <outputdef> output_def_body
342 %type <outputdef> output_def_head
343 %type <outputdef> output_def_head_with_mode_switch
344 %type <outputdef> output_def
345 %type <outputdef> paper_block
347 %type <scm> alternative_music
348 %type <scm> generic_prefix_music_scm
349 %type <scm> music_list
350 %type <scm> absolute_pitch
351 %type <scm> assignment_id
352 %type <scm> bare_number
353 %type <scm> unsigned_number
354 %type <scm> bass_figure
355 %type <scm> figured_bass_modification
356 %type <scm> br_bass_figure
357 %type <scm> bass_number
358 %type <scm> chord_body_elements
359 %type <scm> chord_item
360 %type <scm> chord_items
361 %type <scm> chord_separator
362 %type <scm> context_def_mod
363 %type <scm> context_def_spec_block
364 %type <scm> context_def_spec_body
365 %type <scm> context_mod
366 %type <scm> context_mod_list
367 %type <scm> context_prop_spec
368 %type <scm> direction_less_char
369 %type <scm> duration_length
370 %type <scm> embedded_scm
371 %type <scm> figure_list
372 %type <scm> figure_spec
374 %type <scm> full_markup
375 %type <scm> function_scm_argument
376 %type <scm> function_arglist
377 %type <scm> function_arglist_music_last
378 %type <scm> function_arglist_nonmusic_last
379 %type <scm> function_arglist_nonmusic
380 %type <scm> identifier_init
381 %type <scm> lilypond_header
382 %type <scm> lilypond_header_body
383 %type <scm> lyric_element
384 %type <scm> lyric_markup
386 %type <scm> markup_braced_list
387 %type <scm> markup_braced_list_body
388 %type <scm> markup_composed_list
389 %type <scm> markup_head_1_item
390 %type <scm> markup_head_1_list
391 %type <scm> markup_list
392 %type <scm> markup_top
393 %type <scm> mode_changing_head
394 %type <scm> mode_changing_head_with_context
395 %type <scm> multiplied_duration
396 %type <scm> music_function_identifier_musicless_prefix
397 %type <scm> music_function_event
398 %type <scm> music_function_chord_body
399 %type <scm> new_chord
400 %type <scm> new_lyrics
401 %type <scm> number_expression
402 %type <scm> number_factor
403 %type <scm> number_term
404 %type <scm> object_id_setting
405 %type <scm> octave_check
406 %type <scm> optional_context_mod
407 %type <scm> optional_id
408 %type <scm> optional_notemode_duration
410 %type <scm> pitch_also_in_chords
411 %type <scm> post_events
412 %type <scm> property_operation
414 %type <scm> script_abbreviation
415 %type <scm> simple_chord_elements
416 %type <scm> simple_markup
417 %type <scm> simple_string
418 %type <scm> steno_duration
419 %type <scm> steno_pitch
420 %type <scm> steno_tonic_pitch
421 %type <scm> step_number
422 %type <scm> step_numbers
425 %type <score> score_block
426 %type <score> score_body
431 /* We don't assign precedence to / and *, because we might need varied
432 prec levels in different prods */
438 lilypond: /* empty */
439 | lilypond toplevel_expression {
441 | lilypond assignment {
444 PARSER->error_level_ = 1;
447 PARSER->error_level_ = 1;
453 OBJECTID STRING { $$ = $2; }
458 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
462 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
463 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
469 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
470 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
474 Music *music = unsmob_music ($1);
475 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
476 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
479 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
480 scm_call_2 (proc, PARSER->self_scm (), $1);
484 Output_def * od = $1;
486 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
487 id = ly_symbol2scm ("$defaultpaper");
488 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
489 id = ly_symbol2scm ("$defaultmidi");
490 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
491 id = ly_symbol2scm ("$defaultlayout");
493 PARSER->lexer_->set_identifier (id, od->self_scm ());
504 lilypond_header_body:
506 $$ = get_header (PARSER);
507 PARSER->lexer_->add_scope ($$);
509 | lilypond_header_body assignment {
515 HEADER '{' lilypond_header_body '}' {
516 $$ = PARSER->lexer_->remove_scope ();
525 | LYRICS_STRING { $$ = $1; }
529 assignment_id '=' identifier_init {
530 PARSER->lexer_->set_identifier ($1, $3);
533 TODO: devise standard for protection in parser.
535 The parser stack lives on the C-stack, which means that
536 all objects can be unprotected as soon as they're here.
546 $$ = $1->self_scm ();
550 $$ = $1->self_scm ();
554 $$ = $1->self_scm ();
557 | context_def_spec_block {
561 /* Hack: Create event-chord around standalone events.
562 Prevents the identifier from being interpreted as a post-event. */
563 Music *mus = unsmob_music ($1);
564 bool is_event = mus &&
565 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
570 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
575 | number_expression {
588 $$ = scm_from_int ($1);
592 context_def_spec_block:
593 CONTEXT '{' context_def_spec_body '}'
599 context_def_spec_body:
601 $$ = Context_def::make_scm ();
602 unsmob_context_def ($$)->origin ()->set_spot (@$);
604 | CONTEXT_DEF_IDENTIFIER {
606 unsmob_context_def ($$)->origin ()->set_spot (@$);
608 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
609 Context_def*td = unsmob_context_def ($$);
611 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
612 SCM tag = scm_caar (p);
614 /* TODO: should make new tag "grob-definition" ? */
615 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
616 tag, scm_cons (scm_cdar (p), SCM_EOL)));
619 | context_def_spec_body context_mod {
620 unsmob_context_def ($$)->add_context_mod ($2);
627 BOOK '{' book_body '}' {
633 * Use 'handlers' like for toplevel-* stuff?
634 * grok \layout and \midi? */
638 $$->origin ()->set_spot (@$);
639 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
640 $$->paper_->unprotect ();
641 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
644 $$ = unsmob_book ($1);
646 $$->origin ()->set_spot (@$);
648 | book_body paper_block {
652 | book_body score_block {
653 SCM s = $2->self_scm ();
657 | book_body full_markup {
660 | book_body lilypond_header {
665 $$->scores_ = SCM_EOL;
667 | book_body object_id_setting {
668 $$->user_key_ = ly_scm2string ($2);
673 SCORE '{' score_body '}' {
681 SCM scorify = ly_lily_module_constant ("scorify-music");
682 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
684 // pass ownernship to C++ again.
685 $$ = unsmob_score (score);
687 $$->origin ()->set_spot (@$);
690 $$ = unsmob_score ($1);
692 $$->origin ()->set_spot (@$);
694 | score_body object_id_setting {
695 $$->user_key_ = ly_scm2string ($2);
697 | score_body lilypond_header {
700 | score_body output_def {
701 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
703 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
708 $$->add_output_def ($2);
713 $$->error_found_ = true;
725 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
727 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
729 $$ = get_paper (PARSER);
736 output_def_body '}' {
739 PARSER->lexer_->remove_scope ();
740 PARSER->lexer_->pop_state ();
746 $$ = get_paper (PARSER);
747 $$->input_origin_ = @$;
748 PARSER->lexer_->add_scope ($$->scope_);
751 Output_def *p = get_midi (PARSER);
753 PARSER->lexer_->add_scope (p->scope_);
756 Output_def *p = get_layout (PARSER);
758 PARSER->lexer_->add_scope (p->scope_);
763 output_def_head_with_mode_switch:
765 PARSER->lexer_->push_initial_state ();
771 output_def_head_with_mode_switch '{' {
773 $$->input_origin_.set_spot (@$);
775 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
778 Output_def *o = unsmob_output_def ($3);
779 o->input_origin_.set_spot (@$);
782 PARSER->lexer_->remove_scope ();
783 PARSER->lexer_->add_scope (o->scope_);
785 | output_def_body assignment {
788 | output_def_body context_def_spec_block {
789 assign_context_def ($$, $2);
791 | output_def_body error {
797 TEMPO steno_duration '=' bare_unsigned {
798 $$ = MAKE_SYNTAX ("tempo", @$, $2, scm_int2num ($4));
803 The representation of a list is the
807 to have efficient append. */
811 $$ = scm_cons (SCM_EOL, SCM_EOL);
815 SCM c = scm_cons ($2, SCM_EOL);
817 if (scm_is_pair (scm_cdr (s)))
818 scm_set_cdr_x (scm_cdr (s), c); /* append */
820 scm_set_car_x (s, c); /* set first cons */
821 scm_set_cdr_x (s, c); /* remember last cell */
823 | music_list embedded_scm {
827 Music *m = MY_MAKE_MUSIC("Music", @$);
829 m->set_property ("error-found", SCM_BOOL_T);
831 SCM c = scm_cons (m->self_scm (), SCM_EOL);
832 m->unprotect (); /* UGH */
834 if (scm_is_pair (scm_cdr (s)))
835 scm_set_cdr_x (scm_cdr (s), c); /* append */
837 scm_set_car_x (s, c); /* set first cons */
838 scm_set_cdr_x (s, c); /* remember last cell */
851 | ALTERNATIVE '{' music_list '}' {
858 REPEAT simple_string unsigned_number music alternative_music
860 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
865 SEQUENTIAL '{' music_list '}' {
866 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
868 | '{' music_list '}' {
869 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
874 SIMULTANEOUS '{' music_list '}'{
875 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
877 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
878 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
889 optional_context_mod:
890 /**/ { $$ = SCM_EOL; }
891 | WITH { PARSER->lexer_->push_initial_state (); }
892 '{' context_mod_list '}'
894 PARSER->lexer_->pop_state ();
900 /* */ { $$ = SCM_EOL; }
901 | context_mod_list context_mod {
902 $$ = scm_cons ($2, $1);
907 prefix_composite_music { $$ = $1; }
908 | grouped_music_list { $$ = $1; }
912 simultaneous_music { $$ = $1; }
913 | sequential_music { $$ = $1; }
916 function_scm_argument:
921 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
922 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM
923 and this rule returns the reversed list of arguments. */
925 function_arglist_music_last:
926 EXPECT_MUSIC function_arglist music {
927 $$ = scm_cons ($3, $2);
931 function_arglist_nonmusic_last:
932 EXPECT_MARKUP function_arglist full_markup {
933 $$ = scm_cons ($3, $2);
935 | EXPECT_SCM function_arglist function_scm_argument {
936 $$ = scm_cons ($3, $2);
940 function_arglist_nonmusic: EXPECT_NO_MORE_ARGS {
943 | EXPECT_MARKUP function_arglist_nonmusic full_markup {
944 $$ = scm_cons ($3, $2);
946 | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
947 $$ = scm_cons ($3, $2);
951 function_arglist: EXPECT_NO_MORE_ARGS {
952 /* This is for 0-ary functions, so they don't need to
953 read a lookahead token */
956 | function_arglist_music_last
957 | function_arglist_nonmusic_last
960 generic_prefix_music_scm:
961 MUSIC_FUNCTION function_arglist {
962 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
968 /**/ { $$ = SCM_EOL; }
969 | '=' simple_string {
975 prefix_composite_music:
976 generic_prefix_music_scm {
977 $$ = run_music_function (PARSER, $1);
979 | CONTEXT simple_string optional_id optional_context_mod music {
980 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
982 | NEWCONTEXT simple_string optional_id optional_context_mod music {
983 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
986 | TIMES fraction music {
987 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
989 | repeated_music { $$ = $1; }
990 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
991 Pitch from = *unsmob_pitch ($2);
992 Pitch to = *unsmob_pitch ($3);
993 SCM pitch = pitch_interval (from, to).smobbed_copy ();
994 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
996 | mode_changing_head grouped_music_list {
997 if ($1 == ly_symbol2scm ("chords"))
999 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1005 PARSER->lexer_->pop_state ();
1007 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1008 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1009 if ($1 == ly_symbol2scm ("ChordNames"))
1011 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1013 PARSER->lexer_->pop_state ();
1015 | relative_music { $$ = $1; }
1016 | re_rhythmed_music { $$ = $1; }
1021 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1022 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1024 $$ = ly_symbol2scm ("notes");
1028 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1029 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1031 $$ = ly_symbol2scm ("drums");
1034 PARSER->lexer_->push_figuredbass_state ();
1036 $$ = ly_symbol2scm ("figures");
1039 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1040 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1041 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1042 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1043 $$ = ly_symbol2scm ("chords");
1047 { PARSER->lexer_->push_lyric_state ();
1048 $$ = ly_symbol2scm ("lyrics");
1052 mode_changing_head_with_context:
1054 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1055 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1057 $$ = ly_symbol2scm ("DrumStaff");
1060 PARSER->lexer_->push_figuredbass_state ();
1062 $$ = ly_symbol2scm ("FiguredBass");
1065 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1066 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1067 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1068 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1069 $$ = ly_symbol2scm ("ChordNames");
1072 { PARSER->lexer_->push_lyric_state ();
1073 $$ = ly_symbol2scm ("Lyrics");
1079 RELATIVE absolute_pitch music {
1080 Pitch start = *unsmob_pitch ($2);
1081 $$ = make_music_relative (start, $3, @$);
1083 | RELATIVE composite_music {
1084 Pitch middle_c (0, 0, 0);
1085 $$ = make_music_relative (middle_c, $2, @$);
1090 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1092 grouped_music_list {
1093 /* Can also use music at the expensive of two S/Rs similar to
1094 \repeat \alternative */
1095 PARSER->lexer_->pop_state ();
1097 $$ = scm_cons ($3, SCM_EOL);
1099 | new_lyrics ADDLYRICS {
1100 PARSER->lexer_->push_lyric_state ();
1101 } grouped_music_list {
1102 PARSER->lexer_->pop_state ();
1103 $$ = scm_cons ($4, $1);
1108 grouped_music_list new_lyrics {
1109 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1111 | LYRICSTO simple_string {
1112 PARSER->lexer_->push_lyric_state ();
1114 PARSER->lexer_->pop_state ();
1115 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1120 CHANGE STRING '=' STRING {
1121 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1127 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1128 scm_string_to_symbol ($1), $3);
1130 | UNSET simple_string {
1131 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1132 scm_string_to_symbol ($2));
1134 | OVERRIDE simple_string embedded_scm '=' embedded_scm {
1135 $$ = scm_list_4 (ly_symbol2scm ("push"),
1136 scm_string_to_symbol ($2), $5, $3);
1138 | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
1139 $$ = scm_list_5 (ly_symbol2scm ("push"),
1140 scm_string_to_symbol ($2), $6, $4, $3);
1142 | REVERT simple_string embedded_scm {
1143 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1144 scm_string_to_symbol ($2), $3);
1149 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1150 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1152 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1153 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1154 | DENIES { $$ = ly_symbol2scm ("denies"); }
1156 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1157 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1158 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1159 | NAME { $$ = ly_symbol2scm ("context-name"); }
1163 property_operation { $$ = $1; }
1164 | context_def_mod STRING {
1165 $$ = scm_list_2 ($1, $2);
1171 if (!is_regular_identifier ($1))
1173 @$.error (_("Grob name should be alphanumeric"));
1176 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1177 scm_string_to_symbol ($1));
1179 | simple_string '.' simple_string {
1180 $$ = scm_list_2 (scm_string_to_symbol ($1),
1181 scm_string_to_symbol ($3));
1185 simple_music_property_def:
1186 OVERRIDE context_prop_spec embedded_scm '=' scalar {
1187 $$ = scm_list_5 (scm_car ($2),
1188 ly_symbol2scm ("OverrideProperty"),
1192 | OVERRIDE context_prop_spec embedded_scm embedded_scm '=' scalar {
1193 $$ = scm_list_n (scm_car ($2),
1194 ly_symbol2scm ("OverrideProperty"),
1196 $6, $4, $3, SCM_UNDEFINED);
1198 | REVERT context_prop_spec embedded_scm {
1199 $$ = scm_list_4 (scm_car ($2),
1200 ly_symbol2scm ("RevertProperty"),
1204 | SET context_prop_spec '=' scalar {
1205 $$ = scm_list_4 (scm_car ($2),
1206 ly_symbol2scm ("PropertySet"),
1210 | UNSET context_prop_spec {
1211 $$ = scm_list_3 (scm_car ($2),
1212 ly_symbol2scm ("PropertyUnset"),
1218 simple_music_property_def {
1219 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1221 | ONCE simple_music_property_def {
1222 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1230 | STRING_IDENTIFIER {
1233 | string '+' string {
1234 $$ = scm_string_append (scm_list_2 ($1, $3));
1238 simple_string: STRING {
1244 | STRING_IDENTIFIER {
1265 $$ = scm_from_int ($1);
1270 /* TODO: Create a special case that avoids the creation of
1271 EventChords around simple_elements that have no post_events?
1273 simple_chord_elements post_events {
1274 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1277 /* why is this giving wrong start location? -ns
1279 i.set_location (@1, @2);
1280 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1282 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1284 i.set_location (@1, @3);
1285 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1288 | note_chord_element
1293 chord_body optional_notemode_duration post_events
1295 Music *m = unsmob_music ($1);
1296 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1297 SCM es = m->get_property ("elements");
1298 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1300 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1301 unsmob_music (scm_car (s))->set_property ("duration", dur);
1302 es = ly_append2 (es, postevs);
1304 m-> set_property ("elements", es);
1306 $$ = m->self_scm ();
1311 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1313 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1317 chord_body_elements:
1318 /* empty */ { $$ = SCM_EOL; }
1319 | chord_body_elements chord_body_element {
1320 $$ = scm_cons ($2, $1);
1325 pitch exclamations questions octave_check post_events
1332 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1333 n->set_property ("pitch", $1);
1335 n->set_property ("cautionary", SCM_BOOL_T);
1336 if (ex % 2 || q % 2)
1337 n->set_property ("force-accidental", SCM_BOOL_T);
1339 if (scm_is_pair (post)) {
1340 SCM arts = scm_reverse_x (post, SCM_EOL);
1341 n->set_property ("articulations", arts);
1343 if (scm_is_number (check))
1345 int q = scm_to_int (check);
1346 n->set_property ("absolute-octave", scm_from_int (q-1));
1349 $$ = n->unprotect ();
1351 | DRUM_PITCH post_events {
1352 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1353 n->set_property ("duration", $2);
1354 n->set_property ("drum-type", $1);
1356 if (scm_is_pair ($2)) {
1357 SCM arts = scm_reverse_x ($2, SCM_EOL);
1358 n->set_property ("articulations", arts);
1360 $$ = n->unprotect ();
1362 | music_function_chord_body {
1363 $$ = run_music_function (PARSER, $1);
1367 music_function_identifier_musicless_prefix: MUSIC_FUNCTION {
1368 SCM sig = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
1369 if (scm_is_pair (sig) && to_boolean (scm_memq (ly_music_p_proc, scm_cdr (scm_reverse (sig)))))
1371 PARSER->parser_error (@$, "Music function applied to event may not have a Music argument, except as the last argument.");
1376 music_function_chord_body:
1377 /* We could allow chord functions to have multiple music arguments,
1378 but it's more consistent with music_function_event if we
1379 prohibit it here too */
1380 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic chord_body_element {
1381 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1383 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1384 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1388 music_function_event:
1389 /* Post-events can only have the last argument as music, without this
1390 restriction we get a shift/reduce conflict from e.g.
1391 c8-\partcombine c8 -. */
1392 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic post_event {
1393 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1395 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1396 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1404 | SKIP duration_length {
1405 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1408 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1409 m->set_property ("span-direction", scm_from_int (START));
1410 $$ = m->unprotect();
1413 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1414 m->set_property ("span-direction", scm_from_int (STOP));
1415 $$ = m->unprotect ();
1418 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1421 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1423 Music *m = unsmob_music (pipe);
1428 $$ = m->unprotect ();
1431 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1434 | PARTIAL duration_length {
1435 Moment m = - unsmob_duration ($2)->get_length ();
1436 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1437 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1441 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1443 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1446 SCM proc = ly_lily_module_constant ("make-mark-set");
1448 $$ = scm_call_1 (proc, $2);
1454 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1457 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1458 $$ = m->unprotect ();
1464 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1465 $$ = key->unprotect ();
1467 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1469 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1470 if (scm_ilength ($3) > 0)
1472 key->set_property ("pitch-alist", $3);
1473 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1474 key->transpose (* unsmob_pitch ($2));
1476 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1479 $$ = key->unprotect ();
1488 | post_events post_event {
1489 unsmob_music ($2)->set_spot (@2);
1490 $$ = scm_cons ($2, $$);
1495 direction_less_event {
1498 | '-' music_function_event {
1499 $$ = run_music_function (PARSER, $2);
1502 if (!PARSER->lexer_->is_lyric_state ())
1503 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1504 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1507 if (!PARSER->lexer_->is_lyric_state ())
1508 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1509 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1511 | script_dir direction_reqd_event {
1514 Music *m = unsmob_music ($2);
1515 m->set_property ("direction", scm_from_int ($1));
1519 | script_dir direction_less_event {
1522 Music *m = unsmob_music ($2);
1523 m->set_property ("direction", scm_from_int ($1));
1527 | string_number_event
1530 string_number_event:
1532 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1533 s->set_property ("string-number", scm_from_int ($1));
1534 $$ = s->unprotect ();
1538 direction_less_char:
1540 $$ = ly_symbol2scm ("bracketOpenSymbol");
1543 $$ = ly_symbol2scm ("bracketCloseSymbol");
1546 $$ = ly_symbol2scm ("tildeSymbol");
1549 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1552 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1555 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1558 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1561 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1564 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1567 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1571 direction_less_event:
1572 direction_less_char {
1573 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1575 if (unsmob_music (predefd))
1577 m = unsmob_music (predefd)->clone ();
1582 m = MY_MAKE_MUSIC ("Music", @$);
1584 $$ = m->unprotect ();
1586 | EVENT_IDENTIFIER {
1590 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1591 a->set_property ("tremolo-type", scm_from_int ($1));
1592 $$ = a->unprotect ();
1596 direction_reqd_event:
1600 | script_abbreviation {
1601 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1602 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1603 if (scm_is_string (s))
1604 a->set_property ("articulation-type", s);
1605 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1606 $$ = a->unprotect ();
1611 /**/ { $$ = SCM_EOL; }
1612 | '=' { $$ = scm_from_int (0); }
1613 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1614 | '=' sup_quotes { $$ = scm_from_int ($2); }
1639 | NOTENAME_PITCH sup_quotes {
1640 Pitch p = *unsmob_pitch ($1);
1641 p = p.transposed (Pitch ($2,0,0));
1642 $$ = p.smobbed_copy ();
1644 | NOTENAME_PITCH sub_quotes {
1645 Pitch p =* unsmob_pitch ($1);
1646 p = p.transposed (Pitch (-$2,0,0));
1647 $$ = p.smobbed_copy ();
1659 | TONICNAME_PITCH sup_quotes {
1660 Pitch p = *unsmob_pitch ($1);
1661 p = p.transposed (Pitch ($2,0,0));
1662 $$ = p.smobbed_copy ();
1664 | TONICNAME_PITCH sub_quotes {
1665 Pitch p = *unsmob_pitch ($1);
1667 p = p.transposed (Pitch (-$2,0,0));
1668 $$ = p.smobbed_copy ();
1678 pitch_also_in_chords:
1685 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1686 t->set_property ("text", $1);
1687 $$ = t->unprotect ();
1690 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1691 t->set_property ("text",
1692 make_simple_markup ($1));
1693 $$ = t->unprotect ();
1696 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1697 t->set_property ("digit", scm_from_int ($1));
1698 $$ = t->unprotect ();
1702 script_abbreviation:
1704 $$ = scm_from_locale_string ("Hat");
1707 $$ = scm_from_locale_string ("Plus");
1710 $$ = scm_from_locale_string ("Dash");
1713 $$ = scm_from_locale_string ("Bar");
1716 $$ = scm_from_locale_string ("Larger");
1719 $$ = scm_from_locale_string ("Dot");
1722 $$ = scm_from_locale_string ("Underscore");
1729 | '-' { $$ = CENTER; }
1740 multiplied_duration {
1745 optional_notemode_duration:
1747 Duration dd = PARSER->default_duration_;
1748 $$ = dd.smobbed_copy ();
1750 | multiplied_duration {
1752 PARSER->default_duration_ = *unsmob_duration ($$);
1757 bare_unsigned dots {
1759 if (!is_duration ($1))
1760 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1764 $$ = Duration (len, $2).smobbed_copy ();
1766 | DURATION_IDENTIFIER dots {
1767 Duration *d = unsmob_duration ($1);
1768 Duration k (d->duration_log (), d->dot_count () + $2);
1774 multiplied_duration:
1778 | multiplied_duration '*' bare_unsigned {
1779 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1781 | multiplied_duration '*' FRACTION {
1782 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1784 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1789 FRACTION { $$ = $1; }
1790 | UNSIGNED '/' UNSIGNED {
1791 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1808 | ':' bare_unsigned {
1809 if (!is_duration ($2))
1810 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1817 $$ = scm_from_int ($1);
1820 $$ = scm_from_int ($1);
1822 | STRING { $$ = $1; }
1823 | full_markup { $$ = $1; }
1826 figured_bass_alteration:
1827 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
1828 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
1829 | '!' { $$ = scm_from_int (0); }
1834 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1835 $$ = bfr->unprotect ();
1838 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1839 $$ = bfr->self_scm ();
1841 if (scm_is_number ($1))
1842 bfr->set_property ("figure", $1);
1843 else if (Text_interface::is_markup ($1))
1844 bfr->set_property ("text", $1);
1850 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
1852 | bass_figure figured_bass_alteration {
1853 Music *m = unsmob_music ($1);
1854 if (scm_to_double ($2)) {
1855 SCM salter = m->get_property ("alteration");
1856 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
1857 m->set_property ("alteration",
1858 scm_sum (alter, $2));
1860 m->set_property ("alteration", scm_from_int (0));
1863 | bass_figure figured_bass_modification {
1864 Music *m = unsmob_music ($1);
1865 if ($2 == ly_symbol2scm ("plus"))
1867 m->set_property ("augmented", SCM_BOOL_T);
1869 else if ($2 == ly_symbol2scm ("slash"))
1871 m->set_property ("diminished", SCM_BOOL_T);
1873 else if ($2 == ly_symbol2scm ("exclamation"))
1875 m->set_property ("no-continuation", SCM_BOOL_T);
1881 figured_bass_modification:
1883 $$ = ly_symbol2scm ("plus");
1886 $$ = ly_symbol2scm ("exclamation");
1889 $$ = ly_symbol2scm ("slash");
1899 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
1907 | figure_list br_bass_figure {
1908 $$ = scm_cons ($2, $1);
1913 FIGURE_OPEN figure_list FIGURE_CLOSE {
1914 $$ = scm_reverse_x ($2, SCM_EOL);
1925 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
1926 if (!PARSER->lexer_->is_note_state ())
1927 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
1931 n = MY_MAKE_MUSIC ("RestEvent", @$);
1933 n = MY_MAKE_MUSIC ("NoteEvent", @$);
1935 n->set_property ("pitch", $1);
1936 n->set_property ("duration", $5);
1938 if (scm_is_number ($4))
1940 int q = scm_to_int ($4);
1941 n->set_property ("absolute-octave", scm_from_int (q-1));
1945 n->set_property ("cautionary", SCM_BOOL_T);
1946 if ($2 % 2 || $3 % 2)
1947 n->set_property ("force-accidental", SCM_BOOL_T);
1949 $$ = n->unprotect ();
1951 | DRUM_PITCH optional_notemode_duration {
1952 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1953 n->set_property ("duration", $2);
1954 n->set_property ("drum-type", $1);
1956 $$ = n->unprotect ();
1958 | RESTNAME optional_notemode_duration {
1960 if (ly_scm2string ($1) == "s") {
1962 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
1965 ev = MY_MAKE_MUSIC ("RestEvent", @$);
1968 ev->set_property ("duration", $2);
1969 $$ = ev->unprotect ();
1971 | lyric_element optional_notemode_duration {
1972 if (!PARSER->lexer_->is_lyric_state ())
1973 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1975 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
1976 levent->set_property ("text", $1);
1977 levent->set_property ("duration",$2);
1978 $$= levent->unprotect ();
1982 simple_chord_elements:
1984 $$ = scm_list_1 ($1);
1987 if (!PARSER->lexer_->is_chord_state ())
1988 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
1991 | figure_spec optional_notemode_duration {
1992 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
1994 unsmob_music (scm_car (s))->set_property ("duration", $2);
2010 steno_tonic_pitch optional_notemode_duration {
2011 $$ = make_chord_elements ($1, $2, SCM_EOL);
2013 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2014 SCM its = scm_reverse_x ($4, SCM_EOL);
2015 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2023 | chord_items chord_item {
2024 $$ = scm_cons ($2, $$);
2030 $$ = ly_symbol2scm ("chord-colon");
2033 $$ = ly_symbol2scm ("chord-caret");
2035 | CHORD_SLASH steno_tonic_pitch {
2036 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2038 | CHORD_BASS steno_tonic_pitch {
2039 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2048 $$ = scm_reverse_x ($1, SCM_EOL);
2056 step_number { $$ = scm_cons ($1, SCM_EOL); }
2057 | step_numbers '.' step_number {
2058 $$ = scm_cons ($3, $$);
2064 $$ = make_chord_step ($1, 0);
2066 | bare_unsigned '+' {
2067 $$ = make_chord_step ($1, SHARP_ALTERATION);
2069 | bare_unsigned CHORD_MINUS {
2070 $$ = make_chord_step ($1, FLAT_ALTERATION);
2077 TODO: should deprecate in favor of Scheme?
2081 number_expression '+' number_term {
2082 $$ = scm_sum ($1, $3);
2084 | number_expression '-' number_term {
2085 $$ = scm_difference ($1, $3);
2094 | number_factor '*' number_factor {
2095 $$ = scm_product ($1, $3);
2097 | number_factor '/' number_factor {
2098 $$ = scm_divide ($1, $3);
2103 '-' number_factor { /* %prec UNARY_MINUS */
2104 $$ = scm_difference ($2, SCM_UNDEFINED);
2112 $$ = scm_from_int ($1);
2117 | NUMBER_IDENTIFIER {
2120 | REAL NUMBER_IDENTIFIER {
2121 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2123 | UNSIGNED NUMBER_IDENTIFIER {
2124 $$ = scm_from_double ($1 *scm_to_double ($2));
2139 bare_unsigned { $$ = scm_from_int ($1); }
2140 | NUMBER_IDENTIFIER {
2148 | exclamations '!' { $$ ++; }
2153 | questions '?' { $$ ++; }
2157 This should be done more dynamically if possible.
2161 LYRIC_MARKUP_IDENTIFIER {
2165 { PARSER->lexer_->push_markup_state (); }
2168 PARSER->lexer_->pop_state ();
2177 { PARSER->lexer_->push_markup_state (); }
2180 PARSER->lexer_->pop_state ();
2186 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2188 | markup_head_1_list simple_markup {
2189 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2197 markup_composed_list {
2200 | markup_braced_list {
2205 markup_composed_list:
2206 markup_head_1_list markup_braced_list {
2207 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2213 '{' markup_braced_list_body '}' {
2214 $$ = scm_reverse_x ($2, SCM_EOL);
2218 markup_braced_list_body:
2219 /* empty */ { $$ = SCM_EOL; }
2220 | markup_braced_list_body markup {
2221 $$ = scm_cons ($2, $1);
2223 | markup_braced_list_body markup_list {
2224 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2229 MARKUP_HEAD_MARKUP0 {
2230 $$ = scm_list_1 ($1);
2232 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2233 $$ = scm_list_2 ($1, $2);
2235 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2236 $$ = scm_list_3 ($1, $2, $3);
2241 markup_head_1_item {
2242 $$ = scm_list_1 ($1);
2244 | markup_head_1_list markup_head_1_item {
2245 $$ = scm_cons ($2, $1);
2251 $$ = make_simple_markup ($1);
2253 | MARKUP_IDENTIFIER {
2256 | LYRIC_MARKUP_IDENTIFIER {
2259 | STRING_IDENTIFIER {
2263 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2264 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2265 } '{' score_body '}' {
2267 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2269 PARSER->lexer_->pop_state ();
2271 | MARKUP_HEAD_SCM0 embedded_scm {
2272 $$ = scm_list_2 ($1, $2);
2274 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2275 $$ = scm_list_4 ($1, $2, $3, $4);
2277 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2278 $$ = scm_list_3 ($1, $2, $3);
2280 | MARKUP_HEAD_EMPTY {
2281 $$ = scm_list_1 ($1);
2283 | MARKUP_HEAD_LIST0 markup_list {
2284 $$ = scm_list_2 ($1,$2);
2286 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2287 $$ = scm_list_3 ($1, $2, $3);
2292 markup_head_1_list simple_markup {
2293 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2294 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2304 Lily_parser::set_yydebug (bool x)
2310 Lily_parser::do_yyparse ()
2312 yyparse ((void*)this);
2321 It is a little strange to have this function in this file, but
2322 otherwise, we have to import music classes into the lexer.
2326 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2328 if (scm_is_string (sid)) {
2330 return STRING_IDENTIFIER;
2331 } else if (unsmob_book (sid)) {
2332 Book *book = unsmob_book (sid)->clone ();
2333 *destination = book->self_scm ();
2336 return BOOK_IDENTIFIER;
2337 } else if (scm_is_number (sid)) {
2339 return NUMBER_IDENTIFIER;
2340 } else if (unsmob_context_def (sid)) {
2341 Context_def *def= unsmob_context_def (sid)->clone ();
2343 *destination = def->self_scm ();
2346 return CONTEXT_DEF_IDENTIFIER;
2347 } else if (unsmob_score (sid)) {
2348 Score *score = new Score (*unsmob_score (sid));
2349 *destination = score->self_scm ();
2351 score->unprotect ();
2352 return SCORE_IDENTIFIER;
2353 } else if (Music *mus = unsmob_music (sid)) {
2354 mus = mus->clone ();
2355 *destination = mus->self_scm ();
2356 unsmob_music (*destination)->
2357 set_property ("origin", make_input (last_input_));
2359 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2363 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2364 } else if (unsmob_duration (sid)) {
2365 *destination = unsmob_duration (sid)->smobbed_copy ();
2366 return DURATION_IDENTIFIER;
2367 } else if (unsmob_output_def (sid)) {
2368 Output_def *p = unsmob_output_def (sid);
2371 *destination = p->self_scm ();
2373 return OUTPUT_DEF_IDENTIFIER;
2374 } else if (Text_interface::is_markup (sid)) {
2376 if (is_lyric_state ())
2377 return LYRIC_MARKUP_IDENTIFIER;
2378 return MARKUP_IDENTIFIER;
2385 get_next_unique_context_id ()
2387 return scm_from_locale_string ("$uniqueContextId");
2392 get_next_unique_lyrics_context_id ()
2394 static int new_context_count;
2396 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2397 return scm_from_locale_string (s);
2402 run_music_function (Lily_parser *parser, SCM expr)
2404 SCM func = scm_car (expr);
2405 Input *loc = unsmob_input (scm_cadr (expr));
2406 SCM args = scm_cddr (expr);
2407 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2409 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2411 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2413 parser->error_level_ = 1;
2414 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2417 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2418 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2422 is_regular_identifier (SCM id)
2424 string str = ly_scm2string (id);
2425 char const *s = str.c_str ();
2434 v = v && isalnum (*s);
2441 make_music_with_input (SCM name, Input where)
2443 Music *m = make_music_by_name (name);
2444 m->set_spot (where);
2449 get_first_context_id (SCM type, Music *m)
2451 SCM id = m->get_property ("context-id");
2452 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2453 && scm_is_string (m->get_property ("context-id"))
2454 && scm_c_string_length (id) > 0)
2462 make_simple_markup (SCM a)
2470 return t && t == 1 << intlog2 (t);
2474 set_music_properties (Music *p, SCM a)
2476 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2477 p->set_property (scm_caar (k), scm_cdar (k));
2482 make_chord_step (int step, Rational alter)
2485 alter += FLAT_ALTERATION;
2489 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2490 return m.smobbed_copy ();
2495 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2497 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2498 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2502 /* Todo: actually also use apply iso. call too ... */
2504 ly_input_procedure_p (SCM x)
2506 return ly_is_procedure (x)
2507 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2511 make_music_relative (Pitch start, SCM music, Input loc)
2513 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2514 relative->set_property ("element", music);
2516 Music *m = unsmob_music (music);
2517 Pitch last = m->to_relative_octave (start);
2518 if (lily_1_8_relative)
2519 m->set_property ("last-pitch", last.smobbed_copy ());
2520 return relative->unprotect ();
2524 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2526 Lily_parser *pars = (Lily_parser*) v;
2527 Lily_lexer *lex = pars->lexer_;
2529 lex->lexval = (void*) s;
2531 lex->prepare_for_next_token ();
2532 return lex->yylex ();