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 BOOKPART "\\bookpart"
163 %token CHANGE "\\change"
164 %token CHORDMODE "\\chordmode"
165 %token CHORDS "\\chords"
166 %token CONSISTS "\\consists"
167 %token CONTEXT "\\context"
168 %token DEFAULT "\\default"
169 %token DEFAULTCHILD "\\defaultchild"
170 %token DENIES "\\denies"
171 %token DESCRIPTION "\\description"
172 %token DRUMMODE "\\drummode"
173 %token DRUMS "\\drums"
174 %token FIGUREMODE "\\figuremode"
175 %token FIGURES "\\figures"
176 %token GROBDESCRIPTIONS "\\grobdescriptions"
177 %token HEADER "\\header"
178 %token INVALID "\\invalid"
180 %token LAYOUT "\\layout"
181 %token LYRICMODE "\\lyricmode"
182 %token LYRICS "\\lyrics"
183 %token LYRICSTO "\\lyricsto"
185 %token MARKUP "\\markup"
186 %token MARKUPLINES "\\markuplines"
189 %token NOTEMODE "\\notemode"
190 %token OBJECTID "\\objectid"
191 %token OCTAVE "\\octave"
193 %token OVERRIDE "\\override"
194 %token PAPER "\\paper"
195 %token PARTIAL "\\partial"
196 %token RELATIVE "\\relative"
197 %token REMOVE "\\remove"
198 %token REPEAT "\\repeat"
200 %token REVERT "\\revert"
201 %token SCORE "\\score"
202 %token SEQUENTIAL "\\sequential"
204 %token SIMULTANEOUS "\\simultaneous"
206 %token TEMPO "\\tempo"
207 %token TIMES "\\times"
208 %token TRANSPOSE "\\transpose"
210 %token UNSET "\\unset"
213 /* Keyword token exceptions. */
214 %token TIME_T "\\time"
215 %token NEWCONTEXT "\\new"
218 /* Other string tokens. */
220 %token CHORD_BASS "/+"
221 %token CHORD_CARET "^"
222 %token CHORD_COLON ":"
223 %token CHORD_MINUS "-"
224 %token CHORD_SLASH "/"
225 %token ANGLE_OPEN "<"
226 %token ANGLE_CLOSE ">"
227 %token DOUBLE_ANGLE_OPEN "<<"
228 %token DOUBLE_ANGLE_CLOSE ">>"
229 %token E_BACKSLASH "\\"
230 %token E_ANGLE_CLOSE "\\>"
231 %token E_CHAR "\\C[haracter]"
233 %token E_EXCLAMATION "\\!"
234 %token E_BRACKET_OPEN "\\["
236 %token E_BRACKET_CLOSE "\\]"
237 %token E_ANGLE_OPEN "\\<"
243 If we give names, Bison complains.
245 %token FIGURE_CLOSE /* "\\>" */
246 %token FIGURE_OPEN /* "\\<" */
247 %token FIGURE_SPACE "_"
250 %token CHORDMODIFIERS
252 %token MULTI_MEASURE_REST
256 %token <i> E_UNSIGNED
259 /* Artificial tokens, for more generic function syntax */
260 %token <i> EXPECT_MARKUP;
261 %token <i> EXPECT_MUSIC;
262 %token <i> EXPECT_SCM;
263 /* After the last argument. */
264 %token <i> EXPECT_NO_MORE_ARGS;
266 %token <scm> BOOK_IDENTIFIER
267 %token <scm> CHORDMODIFIER_PITCH
268 %token <scm> CHORD_MODIFIER
269 %token <scm> CONTEXT_DEF_IDENTIFIER
270 %token <scm> DRUM_PITCH
271 %token <scm> DURATION_IDENTIFIER
272 %token <scm> EVENT_IDENTIFIER
273 %token <scm> FRACTION
274 %token <scm> LYRICS_STRING
275 %token <scm> LYRIC_MARKUP_IDENTIFIER
276 %token <scm> MARKUP_HEAD_EMPTY
277 %token <scm> MARKUP_HEAD_LIST0
278 %token <scm> MARKUP_HEAD_MARKUP0
279 %token <scm> MARKUP_HEAD_MARKUP0_MARKUP1
280 %token <scm> MARKUP_HEAD_SCM0
281 %token <scm> MARKUP_HEAD_SCM0_MARKUP1
282 %token <scm> MARKUP_HEAD_SCM0_SCM1
283 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2
284 %token <scm> MARKUP_HEAD_SCM0_SCM1_MARKUP2_MARKUP3
285 %token <scm> MARKUP_HEAD_SCM0_MARKUP1_MARKUP2
286 %token <scm> MARKUP_HEAD_SCM0_SCM1_SCM2
287 %token <scm> MARKUP_LIST_HEAD_EMPTY
288 %token <scm> MARKUP_LIST_HEAD_LIST0
289 %token <scm> MARKUP_LIST_HEAD_SCM0
290 %token <scm> MARKUP_LIST_HEAD_SCM0_LIST1
291 %token <scm> MARKUP_LIST_HEAD_SCM0_SCM1_LIST2
292 %token <scm> MARKUP_IDENTIFIER
293 %token <scm> MUSIC_FUNCTION
294 %token <scm> MUSIC_IDENTIFIER
295 %token <scm> NOTENAME_PITCH
296 %token <scm> NUMBER_IDENTIFIER
297 %token <scm> OUTPUT_DEF_IDENTIFIER
299 %token <scm> RESTNAME
300 %token <scm> SCM_IDENTIFIER
301 %token <scm> SCM_TOKEN
302 %token <scm> SCORE_IDENTIFIER
304 %token <scm> STRING_IDENTIFIER
305 %token <scm> TONICNAME_PITCH
308 %type <book> book_block
309 %type <book> book_body
310 %type <book> bookpart_block
311 %type <book> bookpart_body
313 %type <i> bare_unsigned
314 %type <scm> figured_bass_alteration
316 %type <i> exclamations
317 %type <i> optional_rest
322 %type <i> tremolo_type
325 %type <scm> composite_music
326 %type <scm> grouped_music_list
328 %type <scm> prefix_composite_music
329 %type <scm> repeated_music
330 %type <scm> sequential_music
331 %type <scm> simple_music
332 %type <scm> simultaneous_music
333 %type <scm> chord_body
334 %type <scm> chord_body_element
335 %type <scm> command_element
336 %type <scm> command_event
337 %type <scm> context_change
338 %type <scm> direction_less_event
339 %type <scm> direction_reqd_event
340 %type <scm> event_chord
341 %type <scm> gen_text_def
342 %type <scm> music_property_def
343 %type <scm> note_chord_element
344 %type <scm> post_event
345 %type <scm> re_rhythmed_music
346 %type <scm> relative_music
347 %type <scm> simple_element
348 %type <scm> simple_music_property_def
349 %type <scm> string_number_event
350 %type <scm> tempo_event
352 %type <outputdef> output_def_body
353 %type <outputdef> output_def_head
354 %type <outputdef> output_def_head_with_mode_switch
355 %type <outputdef> output_def
356 %type <outputdef> paper_block
358 %type <scm> alternative_music
359 %type <scm> generic_prefix_music_scm
360 %type <scm> music_list
361 %type <scm> absolute_pitch
362 %type <scm> assignment_id
363 %type <scm> bare_number
364 %type <scm> unsigned_number
365 %type <scm> bass_figure
366 %type <scm> figured_bass_modification
367 %type <scm> br_bass_figure
368 %type <scm> bass_number
369 %type <scm> chord_body_elements
370 %type <scm> chord_item
371 %type <scm> chord_items
372 %type <scm> chord_separator
373 %type <scm> context_def_mod
374 %type <scm> context_def_spec_block
375 %type <scm> context_def_spec_body
376 %type <scm> context_mod
377 %type <scm> context_mod_list
378 %type <scm> context_prop_spec
379 %type <scm> direction_less_char
380 %type <scm> duration_length
381 %type <scm> embedded_scm
382 %type <scm> figure_list
383 %type <scm> figure_spec
385 %type <scm> full_markup
386 %type <scm> full_markup_list
387 %type <scm> function_scm_argument
388 %type <scm> function_arglist
389 %type <scm> function_arglist_music_last
390 %type <scm> function_arglist_nonmusic_last
391 %type <scm> function_arglist_nonmusic
392 %type <scm> identifier_init
393 %type <scm> lilypond_header
394 %type <scm> lilypond_header_body
395 %type <scm> lyric_element
396 %type <scm> lyric_markup
398 %type <scm> markup_braced_list
399 %type <scm> markup_braced_list_body
400 %type <scm> markup_composed_list
401 %type <scm> markup_command_list
402 %type <scm> markup_head_1_item
403 %type <scm> markup_head_1_list
404 %type <scm> markup_list
405 %type <scm> markup_top
406 %type <scm> mode_changing_head
407 %type <scm> mode_changing_head_with_context
408 %type <scm> multiplied_duration
409 %type <scm> music_function_identifier_musicless_prefix
410 %type <scm> music_function_event
411 %type <scm> music_function_chord_body
412 %type <scm> new_chord
413 %type <scm> new_lyrics
414 %type <scm> number_expression
415 %type <scm> number_factor
416 %type <scm> number_term
417 %type <scm> object_id_setting
418 %type <scm> octave_check
419 %type <scm> optional_context_mod
420 %type <scm> optional_id
421 %type <scm> optional_notemode_duration
423 %type <scm> pitch_also_in_chords
424 %type <scm> post_events
425 %type <scm> property_operation
426 %type <scm> property_path property_path_revved
428 %type <scm> script_abbreviation
429 %type <scm> simple_chord_elements
430 %type <scm> simple_markup
431 %type <scm> simple_string
432 %type <scm> steno_duration
433 %type <scm> steno_pitch
434 %type <scm> steno_tonic_pitch
435 %type <scm> step_number
436 %type <scm> step_numbers
439 %type <score> score_block
440 %type <score> score_body
445 /* We don't assign precedence to / and *, because we might need varied
446 prec levels in different prods */
452 lilypond: /* empty */
453 | lilypond toplevel_expression {
455 | lilypond assignment {
458 PARSER->error_level_ = 1;
461 PARSER->error_level_ = 1;
467 OBJECTID STRING { $$ = $2; }
472 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
476 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
477 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
482 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
483 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
484 bookpart->unprotect ();
489 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
490 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
494 Music *music = unsmob_music ($1);
495 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
496 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
499 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
500 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
503 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
504 scm_call_2 (proc, PARSER->self_scm (), $1);
508 Output_def * od = $1;
510 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
512 id = ly_symbol2scm ("$defaultpaper");
513 init_papers (PARSER, od);
515 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
516 id = ly_symbol2scm ("$defaultmidi");
517 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
518 id = ly_symbol2scm ("$defaultlayout");
520 PARSER->lexer_->set_identifier (id, od->self_scm ());
531 lilypond_header_body:
533 $$ = get_header (PARSER);
534 PARSER->lexer_->add_scope ($$);
536 | lilypond_header_body assignment {
542 HEADER '{' lilypond_header_body '}' {
543 $$ = PARSER->lexer_->remove_scope ();
552 | LYRICS_STRING { $$ = $1; }
556 assignment_id '=' identifier_init {
557 PARSER->lexer_->set_identifier ($1, $3);
560 TODO: devise standard for protection in parser.
562 The parser stack lives on the C-stack, which means that
563 all objects can be unprotected as soon as they're here.
573 $$ = $1->self_scm ();
577 $$ = $1->self_scm ();
581 $$ = $1->self_scm ();
585 $$ = $1->self_scm ();
588 | context_def_spec_block {
592 /* Hack: Create event-chord around standalone events.
593 Prevents the identifier from being interpreted as a post-event. */
594 Music *mus = unsmob_music ($1);
595 bool is_event = mus &&
596 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
601 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
606 | number_expression {
619 $$ = scm_from_int ($1);
623 context_def_spec_block:
624 CONTEXT '{' context_def_spec_body '}'
630 context_def_spec_body:
632 $$ = Context_def::make_scm ();
633 unsmob_context_def ($$)->origin ()->set_spot (@$);
635 | CONTEXT_DEF_IDENTIFIER {
637 unsmob_context_def ($$)->origin ()->set_spot (@$);
639 | context_def_spec_body GROBDESCRIPTIONS embedded_scm {
640 Context_def*td = unsmob_context_def ($$);
642 for (SCM p = $3; scm_is_pair (p); p = scm_cdr (p)) {
643 SCM tag = scm_caar (p);
645 /* TODO: should make new tag "grob-definition" ? */
646 td->add_context_mod (scm_list_3 (ly_symbol2scm ("assign"),
647 tag, scm_cons (scm_cdar (p), SCM_EOL)));
650 | context_def_spec_body context_mod {
651 unsmob_context_def ($$)->add_context_mod ($2);
658 BOOK '{' book_body '}' {
660 unstack_paper (PARSER);
665 * Use 'handlers' like for toplevel-* stuff?
666 * grok \layout and \midi? */
670 $$->origin ()->set_spot (@$);
671 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
672 $$->paper_->unprotect ();
673 stack_paper (PARSER, $$->paper_);
674 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
677 $$ = unsmob_book ($1);
679 $$->origin ()->set_spot (@$);
681 | book_body paper_block {
684 set_paper (PARSER, $2);
686 | book_body bookpart_block {
688 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
689 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
690 bookpart->unprotect ();
692 | book_body score_block {
694 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
695 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
698 | book_body composite_music {
699 Music *music = unsmob_music ($2);
700 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
701 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
703 | book_body full_markup {
704 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
705 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
707 | book_body full_markup_list {
708 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
709 scm_call_2 (proc, $$->self_scm (), $2);
711 | book_body lilypond_header {
716 $$->scores_ = SCM_EOL;
717 $$->bookparts_ = SCM_EOL;
719 | book_body object_id_setting {
720 $$->user_key_ = ly_scm2string ($2);
725 BOOKPART '{' bookpart_body '}' {
733 $$->origin ()->set_spot (@$);
736 $$ = unsmob_book ($1);
738 $$->origin ()->set_spot (@$);
740 | bookpart_body paper_block {
744 | bookpart_body score_block {
746 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
747 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
750 | bookpart_body composite_music {
751 Music *music = unsmob_music ($2);
752 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
753 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
755 | bookpart_body full_markup {
756 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
757 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
759 | bookpart_body full_markup_list {
760 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
761 scm_call_2 (proc, $$->self_scm (), $2);
763 | bookpart_body lilypond_header {
766 | bookpart_body error {
768 $$->scores_ = SCM_EOL;
770 | bookpart_body object_id_setting {
771 $$->user_key_ = ly_scm2string ($2);
776 SCORE '{' score_body '}' {
784 SCM scorify = ly_lily_module_constant ("scorify-music");
785 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
787 // pass ownernship to C++ again.
788 $$ = unsmob_score (score);
790 $$->origin ()->set_spot (@$);
793 $$ = unsmob_score ($1);
795 $$->origin ()->set_spot (@$);
797 | score_body object_id_setting {
798 $$->user_key_ = ly_scm2string ($2);
800 | score_body lilypond_header {
803 | score_body output_def {
804 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
806 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
811 $$->add_output_def ($2);
816 $$->error_found_ = true;
828 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
830 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
832 $$ = get_paper (PARSER);
839 output_def_body '}' {
842 PARSER->lexer_->remove_scope ();
843 PARSER->lexer_->pop_state ();
849 $$ = get_paper (PARSER);
850 $$->input_origin_ = @$;
851 PARSER->lexer_->add_scope ($$->scope_);
854 Output_def *p = get_midi (PARSER);
856 PARSER->lexer_->add_scope (p->scope_);
859 Output_def *p = get_layout (PARSER);
861 PARSER->lexer_->add_scope (p->scope_);
866 output_def_head_with_mode_switch:
868 PARSER->lexer_->push_initial_state ();
874 output_def_head_with_mode_switch '{' {
876 $$->input_origin_.set_spot (@$);
878 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
881 Output_def *o = unsmob_output_def ($3);
882 o->input_origin_.set_spot (@$);
885 PARSER->lexer_->remove_scope ();
886 PARSER->lexer_->add_scope (o->scope_);
888 | output_def_body assignment {
891 | output_def_body context_def_spec_block {
892 assign_context_def ($$, $2);
894 | output_def_body error {
900 TEMPO steno_duration '=' bare_unsigned {
901 $$ = MAKE_SYNTAX ("tempo", @$, SCM_BOOL_F, $2, scm_int2num ($4));
903 | TEMPO string steno_duration '=' bare_unsigned {
904 $$ = MAKE_SYNTAX ("tempo", @$, make_simple_markup($2), $3, scm_int2num ($5));
906 | TEMPO full_markup steno_duration '=' bare_unsigned {
907 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, scm_int2num ($5));
910 $$ = MAKE_SYNTAX ("tempoText", @$, make_simple_markup($2) );
912 | TEMPO full_markup {
913 $$ = MAKE_SYNTAX ("tempoText", @$, $2 );
918 The representation of a list is the
922 to have efficient append. */
926 $$ = scm_cons (SCM_EOL, SCM_EOL);
930 SCM c = scm_cons ($2, SCM_EOL);
932 if (scm_is_pair (scm_cdr (s)))
933 scm_set_cdr_x (scm_cdr (s), c); /* append */
935 scm_set_car_x (s, c); /* set first cons */
936 scm_set_cdr_x (s, c); /* remember last cell */
938 | music_list embedded_scm {
942 Music *m = MY_MAKE_MUSIC("Music", @$);
944 m->set_property ("error-found", SCM_BOOL_T);
946 SCM c = scm_cons (m->self_scm (), SCM_EOL);
947 m->unprotect (); /* UGH */
949 if (scm_is_pair (scm_cdr (s)))
950 scm_set_cdr_x (scm_cdr (s), c); /* append */
952 scm_set_car_x (s, c); /* set first cons */
953 scm_set_cdr_x (s, c); /* remember last cell */
966 | ALTERNATIVE '{' music_list '}' {
973 REPEAT simple_string unsigned_number music alternative_music
975 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $5);
980 SEQUENTIAL '{' music_list '}' {
981 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($3));
983 | '{' music_list '}' {
984 $$ = MAKE_SYNTAX ("sequential-music", @$, scm_car ($2));
989 SIMULTANEOUS '{' music_list '}'{
990 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($3));
992 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
993 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_car ($2));
1000 | music_property_def
1004 optional_context_mod:
1005 /**/ { $$ = SCM_EOL; }
1006 | WITH { PARSER->lexer_->push_initial_state (); }
1007 '{' context_mod_list '}'
1009 PARSER->lexer_->pop_state ();
1015 /* */ { $$ = SCM_EOL; }
1016 | context_mod_list context_mod {
1017 $$ = scm_cons ($2, $1);
1022 prefix_composite_music { $$ = $1; }
1023 | grouped_music_list { $$ = $1; }
1027 simultaneous_music { $$ = $1; }
1028 | sequential_music { $$ = $1; }
1031 function_scm_argument:
1036 /* An argument list. If a function \foo expects scm scm music, then the lexer expands \foo into the token sequence:
1037 MUSIC_FUNCTION EXPECT_MUSIC EXPECT_SCM EXPECT_SCM
1038 and this rule returns the reversed list of arguments. */
1040 function_arglist_music_last:
1041 EXPECT_MUSIC function_arglist music {
1042 $$ = scm_cons ($3, $2);
1046 function_arglist_nonmusic_last:
1047 EXPECT_MARKUP function_arglist full_markup {
1048 $$ = scm_cons ($3, $2);
1050 | EXPECT_SCM function_arglist function_scm_argument {
1051 $$ = scm_cons ($3, $2);
1055 function_arglist_nonmusic: EXPECT_NO_MORE_ARGS {
1058 | EXPECT_MARKUP function_arglist_nonmusic full_markup {
1059 $$ = scm_cons ($3, $2);
1061 | EXPECT_SCM function_arglist_nonmusic function_scm_argument {
1062 $$ = scm_cons ($3, $2);
1066 function_arglist: EXPECT_NO_MORE_ARGS {
1067 /* This is for 0-ary functions, so they don't need to
1068 read a lookahead token */
1071 | function_arglist_music_last
1072 | function_arglist_nonmusic_last
1075 generic_prefix_music_scm:
1076 MUSIC_FUNCTION function_arglist {
1077 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1083 /**/ { $$ = SCM_EOL; }
1084 | '=' simple_string {
1090 prefix_composite_music:
1091 generic_prefix_music_scm {
1092 $$ = run_music_function (PARSER, $1);
1094 | CONTEXT simple_string optional_id optional_context_mod music {
1095 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_F);
1097 | NEWCONTEXT simple_string optional_id optional_context_mod music {
1098 $$ = MAKE_SYNTAX ("context-specification", @$, $2, $3, $5, $4, SCM_BOOL_T);
1101 | TIMES fraction music {
1102 $$ = MAKE_SYNTAX ("time-scaled-music", @$, $2, $3);
1104 | repeated_music { $$ = $1; }
1105 | TRANSPOSE pitch_also_in_chords pitch_also_in_chords music {
1106 Pitch from = *unsmob_pitch ($2);
1107 Pitch to = *unsmob_pitch ($3);
1108 SCM pitch = pitch_interval (from, to).smobbed_copy ();
1109 $$ = MAKE_SYNTAX ("transpose-music", @$, pitch, $4);
1111 | mode_changing_head grouped_music_list {
1112 if ($1 == ly_symbol2scm ("chords"))
1114 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1120 PARSER->lexer_->pop_state ();
1122 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1123 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, $3, $2, SCM_BOOL_T);
1124 if ($1 == ly_symbol2scm ("ChordNames"))
1126 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1128 PARSER->lexer_->pop_state ();
1130 | relative_music { $$ = $1; }
1131 | re_rhythmed_music { $$ = $1; }
1136 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1137 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1139 $$ = ly_symbol2scm ("notes");
1143 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1144 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1146 $$ = ly_symbol2scm ("drums");
1149 PARSER->lexer_->push_figuredbass_state ();
1151 $$ = ly_symbol2scm ("figures");
1154 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1155 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1156 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1157 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1158 $$ = ly_symbol2scm ("chords");
1162 { PARSER->lexer_->push_lyric_state ();
1163 $$ = ly_symbol2scm ("lyrics");
1167 mode_changing_head_with_context:
1169 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1170 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1172 $$ = ly_symbol2scm ("DrumStaff");
1175 PARSER->lexer_->push_figuredbass_state ();
1177 $$ = ly_symbol2scm ("FiguredBass");
1180 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1181 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1182 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1183 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1184 $$ = ly_symbol2scm ("ChordNames");
1187 { PARSER->lexer_->push_lyric_state ();
1188 $$ = ly_symbol2scm ("Lyrics");
1194 RELATIVE absolute_pitch music {
1195 Pitch start = *unsmob_pitch ($2);
1196 $$ = make_music_relative (start, $3, @$);
1198 | RELATIVE composite_music {
1199 Pitch middle_c (0, 0, 0);
1200 $$ = make_music_relative (middle_c, $2, @$);
1205 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1207 grouped_music_list {
1208 /* Can also use music at the expensive of two S/Rs similar to
1209 \repeat \alternative */
1210 PARSER->lexer_->pop_state ();
1212 $$ = scm_cons ($3, SCM_EOL);
1214 | new_lyrics ADDLYRICS {
1215 PARSER->lexer_->push_lyric_state ();
1216 } grouped_music_list {
1217 PARSER->lexer_->pop_state ();
1218 $$ = scm_cons ($4, $1);
1223 grouped_music_list new_lyrics {
1224 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1226 | LYRICSTO simple_string {
1227 PARSER->lexer_->push_lyric_state ();
1229 PARSER->lexer_->pop_state ();
1230 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1235 CHANGE STRING '=' STRING {
1236 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1241 property_path_revved:
1243 $$ = scm_cons ($1, SCM_EOL);
1245 | property_path_revved embedded_scm {
1246 $$ = scm_cons ($2, $1);
1251 property_path_revved {
1252 $$ = scm_reverse_x ($1, SCM_EOL);
1258 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1259 scm_string_to_symbol ($1), $3);
1261 | UNSET simple_string {
1262 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1263 scm_string_to_symbol ($2));
1265 | OVERRIDE simple_string property_path '=' embedded_scm {
1266 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1267 scm_string_to_symbol ($2), $5),
1270 | REVERT simple_string embedded_scm {
1271 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1272 scm_string_to_symbol ($2), $3);
1277 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1278 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1280 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1281 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
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 if (!is_regular_identifier ($1))
1301 @$.error (_("Grob name should be alphanumeric"));
1304 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1305 scm_string_to_symbol ($1));
1307 | simple_string '.' simple_string {
1308 $$ = scm_list_2 (scm_string_to_symbol ($1),
1309 scm_string_to_symbol ($3));
1313 simple_music_property_def:
1314 OVERRIDE context_prop_spec property_path '=' scalar {
1315 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1316 ly_symbol2scm ("OverrideProperty"),
1321 | REVERT context_prop_spec embedded_scm {
1322 $$ = scm_list_4 (scm_car ($2),
1323 ly_symbol2scm ("RevertProperty"),
1327 | SET context_prop_spec '=' scalar {
1328 $$ = scm_list_4 (scm_car ($2),
1329 ly_symbol2scm ("PropertySet"),
1333 | UNSET context_prop_spec {
1334 $$ = scm_list_3 (scm_car ($2),
1335 ly_symbol2scm ("PropertyUnset"),
1341 simple_music_property_def {
1342 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_F, $1)));
1344 | ONCE simple_music_property_def {
1345 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons (PARSER->self_scm (), scm_cons2 (make_input (@$), SCM_BOOL_T, $2)));
1353 | STRING_IDENTIFIER {
1356 | string '+' string {
1357 $$ = scm_string_append (scm_list_2 ($1, $3));
1361 simple_string: STRING {
1367 | STRING_IDENTIFIER {
1388 $$ = scm_from_int ($1);
1393 /* TODO: Create a special case that avoids the creation of
1394 EventChords around simple_elements that have no post_events?
1396 simple_chord_elements post_events {
1397 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1400 /* why is this giving wrong start location? -ns
1402 i.set_location (@1, @2);
1403 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1405 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1407 i.set_location (@1, @3);
1408 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2, $3);
1411 | note_chord_element
1416 chord_body optional_notemode_duration post_events
1418 Music *m = unsmob_music ($1);
1419 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1420 SCM es = m->get_property ("elements");
1421 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1423 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1424 unsmob_music (scm_car (s))->set_property ("duration", dur);
1425 es = ly_append2 (es, postevs);
1427 m-> set_property ("elements", es);
1429 $$ = m->self_scm ();
1434 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1436 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1440 chord_body_elements:
1441 /* empty */ { $$ = SCM_EOL; }
1442 | chord_body_elements chord_body_element {
1443 $$ = scm_cons ($2, $1);
1448 pitch exclamations questions octave_check post_events
1455 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1456 n->set_property ("pitch", $1);
1458 n->set_property ("cautionary", SCM_BOOL_T);
1459 if (ex % 2 || q % 2)
1460 n->set_property ("force-accidental", SCM_BOOL_T);
1462 if (scm_is_pair (post)) {
1463 SCM arts = scm_reverse_x (post, SCM_EOL);
1464 n->set_property ("articulations", arts);
1466 if (scm_is_number (check))
1468 int q = scm_to_int (check);
1469 n->set_property ("absolute-octave", scm_from_int (q-1));
1472 $$ = n->unprotect ();
1474 | DRUM_PITCH post_events {
1475 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1476 n->set_property ("duration", $2);
1477 n->set_property ("drum-type", $1);
1479 if (scm_is_pair ($2)) {
1480 SCM arts = scm_reverse_x ($2, SCM_EOL);
1481 n->set_property ("articulations", arts);
1483 $$ = n->unprotect ();
1485 | music_function_chord_body {
1486 $$ = run_music_function (PARSER, $1);
1490 music_function_identifier_musicless_prefix: MUSIC_FUNCTION {
1491 SCM sig = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
1492 if (scm_is_pair (sig) && to_boolean (scm_memq (ly_music_p_proc, scm_cdr (scm_reverse (sig)))))
1494 PARSER->parser_error (@$, "Music function applied to event may not have a Music argument, except as the last argument.");
1499 music_function_chord_body:
1500 /* We could allow chord functions to have multiple music arguments,
1501 but it's more consistent with music_function_event if we
1502 prohibit it here too */
1503 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic chord_body_element {
1504 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1506 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1507 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1511 music_function_event:
1512 /* Post-events can only have the last argument as music, without this
1513 restriction we get a shift/reduce conflict from e.g.
1514 c8-\partcombine c8 -. */
1515 music_function_identifier_musicless_prefix EXPECT_MUSIC function_arglist_nonmusic post_event {
1516 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($3, scm_list_1 ($4)));
1518 | music_function_identifier_musicless_prefix function_arglist_nonmusic {
1519 $$ = ly_append2 (scm_list_2 ($1, make_input (@$)), scm_reverse_x ($2, SCM_EOL));
1527 | SKIP duration_length {
1528 $$ = MAKE_SYNTAX ("skip-music", @$, $2);
1531 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1532 m->set_property ("span-direction", scm_from_int (START));
1533 $$ = m->unprotect();
1536 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
1537 m->set_property ("span-direction", scm_from_int (STOP));
1538 $$ = m->unprotect ();
1541 $$ = MAKE_SYNTAX ("voice-separator", @$, SCM_UNDEFINED);
1544 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
1546 Music *m = unsmob_music (pipe);
1551 $$ = m->unprotect ();
1554 $$ = MAKE_SYNTAX ("bar-check", @$, SCM_UNDEFINED);
1557 | PARTIAL duration_length {
1558 Moment m = - unsmob_duration ($2)->get_length ();
1559 $$ = MAKE_SYNTAX ("property-operation", @$, SCM_BOOL_F, ly_symbol2scm ("Timing"), ly_symbol2scm ("PropertySet"), ly_symbol2scm ("measurePosition"), m.smobbed_copy ());
1560 $$ = MAKE_SYNTAX ("context-specification", @$, ly_symbol2scm ("Score"), SCM_BOOL_F, $$, SCM_EOL, SCM_BOOL_F);
1564 SCM proc = ly_lily_module_constant ("make-time-signature-set");
1566 $$ = scm_apply_2 (proc, scm_car ($2), scm_cdr ($2), SCM_EOL);
1569 SCM proc = ly_lily_module_constant ("make-mark-set");
1571 $$ = scm_call_1 (proc, $2);
1577 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
1580 Music *m = MY_MAKE_MUSIC ("MarkEvent", @$);
1581 $$ = m->unprotect ();
1587 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1588 $$ = key->unprotect ();
1590 | KEY NOTENAME_PITCH SCM_IDENTIFIER {
1592 Music *key = MY_MAKE_MUSIC ("KeyChangeEvent", @$);
1593 if (scm_ilength ($3) > 0)
1595 key->set_property ("pitch-alist", $3);
1596 key->set_property ("tonic", Pitch (0, 0, 0).smobbed_copy ());
1597 key->transpose (* unsmob_pitch ($2));
1599 PARSER->parser_error (@3, _ ("second argument must be pitch list"));
1602 $$ = key->unprotect ();
1611 | post_events post_event {
1612 unsmob_music ($2)->set_spot (@2);
1613 $$ = scm_cons ($2, $$);
1618 direction_less_event {
1621 | '-' music_function_event {
1622 $$ = run_music_function (PARSER, $2);
1625 if (!PARSER->lexer_->is_lyric_state ())
1626 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1627 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
1630 if (!PARSER->lexer_->is_lyric_state ())
1631 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
1632 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
1634 | script_dir direction_reqd_event {
1637 Music *m = unsmob_music ($2);
1638 m->set_property ("direction", scm_from_int ($1));
1642 | script_dir direction_less_event {
1645 Music *m = unsmob_music ($2);
1646 m->set_property ("direction", scm_from_int ($1));
1650 | string_number_event
1653 string_number_event:
1655 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
1656 s->set_property ("string-number", scm_from_int ($1));
1657 $$ = s->unprotect ();
1661 direction_less_char:
1663 $$ = ly_symbol2scm ("bracketOpenSymbol");
1666 $$ = ly_symbol2scm ("bracketCloseSymbol");
1669 $$ = ly_symbol2scm ("tildeSymbol");
1672 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
1675 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
1678 $$ = ly_symbol2scm ("escapedExclamationSymbol");
1681 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
1684 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
1687 $$ = ly_symbol2scm ("escapedBiggerSymbol");
1690 $$ = ly_symbol2scm ("escapedSmallerSymbol");
1694 direction_less_event:
1695 direction_less_char {
1696 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
1698 if (unsmob_music (predefd))
1700 m = unsmob_music (predefd)->clone ();
1705 m = MY_MAKE_MUSIC ("Music", @$);
1707 $$ = m->unprotect ();
1709 | EVENT_IDENTIFIER {
1713 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
1714 a->set_property ("tremolo-type", scm_from_int ($1));
1715 $$ = a->unprotect ();
1719 direction_reqd_event:
1723 | script_abbreviation {
1724 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
1725 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
1726 if (scm_is_string (s))
1727 a->set_property ("articulation-type", s);
1728 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
1729 $$ = a->unprotect ();
1734 /**/ { $$ = SCM_EOL; }
1735 | '=' { $$ = scm_from_int (0); }
1736 | '=' sub_quotes { $$ = scm_from_int (-$2); }
1737 | '=' sup_quotes { $$ = scm_from_int ($2); }
1762 | NOTENAME_PITCH sup_quotes {
1763 Pitch p = *unsmob_pitch ($1);
1764 p = p.transposed (Pitch ($2,0,0));
1765 $$ = p.smobbed_copy ();
1767 | NOTENAME_PITCH sub_quotes {
1768 Pitch p =* unsmob_pitch ($1);
1769 p = p.transposed (Pitch (-$2,0,0));
1770 $$ = p.smobbed_copy ();
1782 | TONICNAME_PITCH sup_quotes {
1783 Pitch p = *unsmob_pitch ($1);
1784 p = p.transposed (Pitch ($2,0,0));
1785 $$ = p.smobbed_copy ();
1787 | TONICNAME_PITCH sub_quotes {
1788 Pitch p = *unsmob_pitch ($1);
1790 p = p.transposed (Pitch (-$2,0,0));
1791 $$ = p.smobbed_copy ();
1801 pitch_also_in_chords:
1808 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1809 t->set_property ("text", $1);
1810 $$ = t->unprotect ();
1813 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
1814 t->set_property ("text",
1815 make_simple_markup ($1));
1816 $$ = t->unprotect ();
1819 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
1820 t->set_property ("digit", scm_from_int ($1));
1821 $$ = t->unprotect ();
1825 script_abbreviation:
1827 $$ = scm_from_locale_string ("Hat");
1830 $$ = scm_from_locale_string ("Plus");
1833 $$ = scm_from_locale_string ("Dash");
1836 $$ = scm_from_locale_string ("Bar");
1839 $$ = scm_from_locale_string ("Larger");
1842 $$ = scm_from_locale_string ("Dot");
1845 $$ = scm_from_locale_string ("Underscore");
1852 | '-' { $$ = CENTER; }
1863 multiplied_duration {
1868 optional_notemode_duration:
1870 Duration dd = PARSER->default_duration_;
1871 $$ = dd.smobbed_copy ();
1873 | multiplied_duration {
1875 PARSER->default_duration_ = *unsmob_duration ($$);
1880 bare_unsigned dots {
1882 if (!is_duration ($1))
1883 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
1887 $$ = Duration (len, $2).smobbed_copy ();
1889 | DURATION_IDENTIFIER dots {
1890 Duration *d = unsmob_duration ($1);
1891 Duration k (d->duration_log (), d->dot_count () + $2);
1897 multiplied_duration:
1901 | multiplied_duration '*' bare_unsigned {
1902 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
1904 | multiplied_duration '*' FRACTION {
1905 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
1907 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
1912 FRACTION { $$ = $1; }
1913 | UNSIGNED '/' UNSIGNED {
1914 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
1931 | ':' bare_unsigned {
1932 if (!is_duration ($2))
1933 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
1940 $$ = scm_from_int ($1);
1943 $$ = scm_from_int ($1);
1945 | STRING { $$ = $1; }
1946 | full_markup { $$ = $1; }
1949 figured_bass_alteration:
1950 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
1951 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
1952 | '!' { $$ = scm_from_int (0); }
1957 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1958 $$ = bfr->unprotect ();
1961 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
1962 $$ = bfr->self_scm ();
1964 if (scm_is_number ($1))
1965 bfr->set_property ("figure", $1);
1966 else if (Text_interface::is_markup ($1))
1967 bfr->set_property ("text", $1);
1973 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
1975 | bass_figure figured_bass_alteration {
1976 Music *m = unsmob_music ($1);
1977 if (scm_to_double ($2)) {
1978 SCM salter = m->get_property ("alteration");
1979 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
1980 m->set_property ("alteration",
1981 scm_sum (alter, $2));
1983 m->set_property ("alteration", scm_from_int (0));
1986 | bass_figure figured_bass_modification {
1987 Music *m = unsmob_music ($1);
1988 if ($2 == ly_symbol2scm ("plus"))
1990 m->set_property ("augmented", SCM_BOOL_T);
1992 else if ($2 == ly_symbol2scm ("slash"))
1994 m->set_property ("diminished", SCM_BOOL_T);
1996 else if ($2 == ly_symbol2scm ("exclamation"))
1998 m->set_property ("no-continuation", SCM_BOOL_T);
2000 else if ($2 == ly_symbol2scm ("backslash"))
2002 m->set_property ("augmented-slash", SCM_BOOL_T);
2008 figured_bass_modification:
2010 $$ = ly_symbol2scm ("plus");
2013 $$ = ly_symbol2scm ("exclamation");
2016 $$ = ly_symbol2scm ("slash");
2019 $$ = ly_symbol2scm ("backslash");
2029 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2037 | figure_list br_bass_figure {
2038 $$ = scm_cons ($2, $1);
2043 FIGURE_OPEN figure_list FIGURE_CLOSE {
2044 $$ = scm_reverse_x ($2, SCM_EOL);
2055 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2056 if (!PARSER->lexer_->is_note_state ())
2057 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2061 n = MY_MAKE_MUSIC ("RestEvent", @$);
2063 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2065 n->set_property ("pitch", $1);
2066 n->set_property ("duration", $5);
2068 if (scm_is_number ($4))
2070 int q = scm_to_int ($4);
2071 n->set_property ("absolute-octave", scm_from_int (q-1));
2075 n->set_property ("cautionary", SCM_BOOL_T);
2076 if ($2 % 2 || $3 % 2)
2077 n->set_property ("force-accidental", SCM_BOOL_T);
2079 $$ = n->unprotect ();
2081 | DRUM_PITCH optional_notemode_duration {
2082 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2083 n->set_property ("duration", $2);
2084 n->set_property ("drum-type", $1);
2086 $$ = n->unprotect ();
2088 | RESTNAME optional_notemode_duration {
2090 if (ly_scm2string ($1) == "s") {
2092 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2095 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2098 ev->set_property ("duration", $2);
2099 $$ = ev->unprotect ();
2101 | lyric_element optional_notemode_duration {
2102 if (!PARSER->lexer_->is_lyric_state ())
2103 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2105 Music *levent = MY_MAKE_MUSIC ("LyricEvent", @$);
2106 levent->set_property ("text", $1);
2107 levent->set_property ("duration",$2);
2108 $$= levent->unprotect ();
2112 simple_chord_elements:
2114 $$ = scm_list_1 ($1);
2117 if (!PARSER->lexer_->is_chord_state ())
2118 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2121 | figure_spec optional_notemode_duration {
2122 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2124 unsmob_music (scm_car (s))->set_property ("duration", $2);
2140 steno_tonic_pitch optional_notemode_duration {
2141 $$ = make_chord_elements ($1, $2, SCM_EOL);
2143 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2144 SCM its = scm_reverse_x ($4, SCM_EOL);
2145 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2153 | chord_items chord_item {
2154 $$ = scm_cons ($2, $$);
2160 $$ = ly_symbol2scm ("chord-colon");
2163 $$ = ly_symbol2scm ("chord-caret");
2165 | CHORD_SLASH steno_tonic_pitch {
2166 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2168 | CHORD_BASS steno_tonic_pitch {
2169 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2178 $$ = scm_reverse_x ($1, SCM_EOL);
2186 step_number { $$ = scm_cons ($1, SCM_EOL); }
2187 | step_numbers '.' step_number {
2188 $$ = scm_cons ($3, $$);
2194 $$ = make_chord_step ($1, 0);
2196 | bare_unsigned '+' {
2197 $$ = make_chord_step ($1, SHARP_ALTERATION);
2199 | bare_unsigned CHORD_MINUS {
2200 $$ = make_chord_step ($1, FLAT_ALTERATION);
2207 TODO: should deprecate in favor of Scheme?
2211 number_expression '+' number_term {
2212 $$ = scm_sum ($1, $3);
2214 | number_expression '-' number_term {
2215 $$ = scm_difference ($1, $3);
2224 | number_factor '*' number_factor {
2225 $$ = scm_product ($1, $3);
2227 | number_factor '/' number_factor {
2228 $$ = scm_divide ($1, $3);
2233 '-' number_factor { /* %prec UNARY_MINUS */
2234 $$ = scm_difference ($2, SCM_UNDEFINED);
2242 $$ = scm_from_int ($1);
2247 | NUMBER_IDENTIFIER {
2250 | REAL NUMBER_IDENTIFIER {
2251 $$ = scm_from_double (scm_to_double ($1) *scm_to_double ($2));
2253 | UNSIGNED NUMBER_IDENTIFIER {
2254 $$ = scm_from_double ($1 *scm_to_double ($2));
2269 bare_unsigned { $$ = scm_from_int ($1); }
2270 | NUMBER_IDENTIFIER {
2278 | exclamations '!' { $$ ++; }
2283 | questions '?' { $$ ++; }
2287 This should be done more dynamically if possible.
2291 LYRIC_MARKUP_IDENTIFIER {
2295 { PARSER->lexer_->push_markup_state (); }
2298 PARSER->lexer_->pop_state ();
2304 { PARSER->lexer_->push_markup_state (); }
2307 PARSER->lexer_->pop_state ();
2316 { PARSER->lexer_->push_markup_state (); }
2319 PARSER->lexer_->pop_state ();
2325 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2327 | markup_head_1_list simple_markup {
2328 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2336 markup_composed_list {
2339 | markup_braced_list {
2342 | markup_command_list {
2343 $$ = scm_list_1 ($1);
2347 markup_composed_list:
2348 markup_head_1_list markup_braced_list {
2349 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2355 '{' markup_braced_list_body '}' {
2356 $$ = scm_reverse_x ($2, SCM_EOL);
2360 markup_braced_list_body:
2361 /* empty */ { $$ = SCM_EOL; }
2362 | markup_braced_list_body markup {
2363 $$ = scm_cons ($2, $1);
2365 | markup_braced_list_body markup_list {
2366 $$ = scm_append_x (scm_list_2 (scm_reverse_x ($2, SCM_EOL), $1));
2370 markup_command_list:
2371 MARKUP_LIST_HEAD_EMPTY {
2372 $$ = scm_list_1 ($1);
2374 | MARKUP_LIST_HEAD_LIST0 markup_list {
2375 $$ = scm_list_2 ($1, $2);
2377 | MARKUP_LIST_HEAD_SCM0 embedded_scm {
2378 $$ = scm_list_2 ($1, $2);
2380 | MARKUP_LIST_HEAD_SCM0_LIST1 embedded_scm markup_list {
2381 $$ = scm_list_3 ($1, $2, $3);
2383 | MARKUP_LIST_HEAD_SCM0_SCM1_LIST2 embedded_scm embedded_scm markup_list {
2384 $$ = scm_list_4 ($1, $2, $3, $4);
2389 MARKUP_HEAD_MARKUP0 {
2390 $$ = scm_list_1 ($1);
2392 | MARKUP_HEAD_SCM0_MARKUP1 embedded_scm {
2393 $$ = scm_list_2 ($1, $2);
2395 | MARKUP_HEAD_SCM0_SCM1_MARKUP2 embedded_scm embedded_scm {
2396 $$ = scm_list_3 ($1, $2, $3);
2401 markup_head_1_item {
2402 $$ = scm_list_1 ($1);
2404 | markup_head_1_list markup_head_1_item {
2405 $$ = scm_cons ($2, $1);
2411 $$ = make_simple_markup ($1);
2413 | MARKUP_IDENTIFIER {
2416 | LYRIC_MARKUP_IDENTIFIER {
2419 | STRING_IDENTIFIER {
2423 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
2424 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
2425 } '{' score_body '}' {
2427 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
2429 PARSER->lexer_->pop_state ();
2431 | MARKUP_HEAD_SCM0 embedded_scm {
2432 $$ = scm_list_2 ($1, $2);
2434 | MARKUP_HEAD_SCM0_SCM1_SCM2 embedded_scm embedded_scm embedded_scm {
2435 $$ = scm_list_4 ($1, $2, $3, $4);
2437 | MARKUP_HEAD_SCM0_SCM1 embedded_scm embedded_scm {
2438 $$ = scm_list_3 ($1, $2, $3);
2440 | MARKUP_HEAD_SCM0_MARKUP1_MARKUP2 embedded_scm markup markup {
2441 $$ = scm_list_4 ($1, $2, $3, $4);
2443 | MARKUP_HEAD_SCM0_SCM1_MARKUP2_MARKUP3 embedded_scm embedded_scm markup markup {
2444 $$ = scm_list_5 ($1, $2, $3, $4, $5);
2446 | MARKUP_HEAD_EMPTY {
2447 $$ = scm_list_1 ($1);
2449 | MARKUP_HEAD_LIST0 markup_list {
2450 $$ = scm_list_2 ($1,$2);
2452 | MARKUP_HEAD_MARKUP0_MARKUP1 markup markup {
2453 $$ = scm_list_3 ($1, $2, $3);
2458 markup_head_1_list simple_markup {
2459 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2460 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
2470 Lily_parser::set_yydebug (bool x)
2476 Lily_parser::do_yyparse ()
2478 yyparse ((void*)this);
2487 It is a little strange to have this function in this file, but
2488 otherwise, we have to import music classes into the lexer.
2492 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
2494 if (scm_is_string (sid)) {
2496 return STRING_IDENTIFIER;
2497 } else if (unsmob_book (sid)) {
2498 Book *book = unsmob_book (sid)->clone ();
2499 *destination = book->self_scm ();
2502 return BOOK_IDENTIFIER;
2503 } else if (scm_is_number (sid)) {
2505 return NUMBER_IDENTIFIER;
2506 } else if (unsmob_context_def (sid)) {
2507 Context_def *def= unsmob_context_def (sid)->clone ();
2509 *destination = def->self_scm ();
2512 return CONTEXT_DEF_IDENTIFIER;
2513 } else if (unsmob_score (sid)) {
2514 Score *score = new Score (*unsmob_score (sid));
2515 *destination = score->self_scm ();
2517 score->unprotect ();
2518 return SCORE_IDENTIFIER;
2519 } else if (Music *mus = unsmob_music (sid)) {
2520 mus = mus->clone ();
2521 *destination = mus->self_scm ();
2522 unsmob_music (*destination)->
2523 set_property ("origin", make_input (last_input_));
2525 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
2529 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
2530 } else if (unsmob_duration (sid)) {
2531 *destination = unsmob_duration (sid)->smobbed_copy ();
2532 return DURATION_IDENTIFIER;
2533 } else if (unsmob_output_def (sid)) {
2534 Output_def *p = unsmob_output_def (sid);
2537 *destination = p->self_scm ();
2539 return OUTPUT_DEF_IDENTIFIER;
2540 } else if (Text_interface::is_markup (sid)) {
2542 if (is_lyric_state ())
2543 return LYRIC_MARKUP_IDENTIFIER;
2544 return MARKUP_IDENTIFIER;
2551 get_next_unique_context_id ()
2553 return scm_from_locale_string ("$uniqueContextId");
2558 get_next_unique_lyrics_context_id ()
2560 static int new_context_count;
2562 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
2563 return scm_from_locale_string (s);
2568 run_music_function (Lily_parser *parser, SCM expr)
2570 SCM func = scm_car (expr);
2571 Input *loc = unsmob_input (scm_cadr (expr));
2572 SCM args = scm_cddr (expr);
2573 SCM sig = scm_object_property (func, ly_symbol2scm ("music-function-signature"));
2575 SCM type_check_proc = ly_lily_module_constant ("type-check-list");
2577 if (!to_boolean (scm_call_3 (type_check_proc, scm_cadr (expr), sig, args)))
2579 parser->error_level_ = 1;
2580 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("void-music"), scm_list_2 (parser->self_scm (), make_input (*loc)));
2583 SCM syntax_args = scm_list_4 (parser->self_scm (), make_input (*loc), func, args);
2584 return LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("music-function"), syntax_args);
2588 is_regular_identifier (SCM id)
2590 string str = ly_scm2string (id);
2591 char const *s = str.c_str ();
2600 v = v && isalnum (*s);
2607 make_music_with_input (SCM name, Input where)
2609 Music *m = make_music_by_name (name);
2610 m->set_spot (where);
2615 get_first_context_id (SCM type, Music *m)
2617 SCM id = m->get_property ("context-id");
2618 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
2619 && scm_is_string (m->get_property ("context-id"))
2620 && scm_c_string_length (id) > 0)
2628 make_simple_markup (SCM a)
2636 return t && t == 1 << intlog2 (t);
2640 set_music_properties (Music *p, SCM a)
2642 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
2643 p->set_property (scm_caar (k), scm_cdar (k));
2648 make_chord_step (int step, Rational alter)
2651 alter += FLAT_ALTERATION;
2655 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
2656 return m.smobbed_copy ();
2661 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
2663 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
2664 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
2668 /* Todo: actually also use apply iso. call too ... */
2670 ly_input_procedure_p (SCM x)
2672 return ly_is_procedure (x)
2673 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
2677 make_music_relative (Pitch start, SCM music, Input loc)
2679 Music *relative = MY_MAKE_MUSIC ("RelativeOctaveMusic", loc);
2680 relative->set_property ("element", music);
2682 Music *m = unsmob_music (music);
2683 Pitch last = m->to_relative_octave (start);
2684 if (lily_1_8_relative)
2685 m->set_property ("last-pitch", last.smobbed_copy ());
2686 return relative->unprotect ();
2690 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
2692 Lily_parser *pars = (Lily_parser*) v;
2693 Lily_lexer *lex = pars->lexer_;
2695 lex->lexval = (void*) s;
2697 lex->prepare_for_next_token ();
2698 return lex->yylex ();