2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Jan Nieuwenhuizen <janneke@gnu.org>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
24 #define YYERROR_VERBOSE 1
25 #define YYPARSE_PARAM my_lily_parser
26 #define YYLEX_PARAM my_lily_parser
27 #define PARSER ((Lily_parser *) my_lily_parser)
29 #define yyerror PARSER->parser_error
31 /* We use custom location type: Input objects */
33 #define YYLLOC_DEFAULT(Current,Rhs,N) \
34 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
39 /* We use SCMs to do strings, because it saves us the trouble of
40 deleting them. Let's hope that a stack overflow doesnt trigger a move
41 of the parse stack onto the heap. */
47 /* The above precedences tackle the shift/reduce problem
50 \repeat .. \alternative
52 \repeat { \repeat .. \alternative }
56 \repeat { \repeat } \alternative
62 /* ADDLYRICS needs to have lower precedence than argument scanning,
63 * or we won't be able to tell music apart from closed_music without
64 * lookahead in the context of function calls.
69 /* \default is only applied after exhausting function arguments */
71 %nonassoc FUNCTION_ARGLIST
73 /* expressions with units are permitted into argument lists */
75 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
76 UNSIGNED REAL DURATION_IDENTIFIER ':'
78 /* The above are the symbols that can start optional function arguments
79 that are recognized in the grammar rather than by predicate
82 %nonassoc NUMBER_IDENTIFIER '/'
84 /* Number-unit expressions, where permitted, are concatenated into
85 * function arguments, just like fractions and tremoli. Tremoli must
86 * not have higher precedence than UNSIGNED, or Lilypond will not
87 * join ':' with a following optional number.
100 %{ // -*-Fundamental-*-
105 * The rules for who is protecting what are very shady. Uniformise
108 * There are too many lexical modes?
119 #include "context-def.hh"
120 #include "context-mod.hh"
121 #include "dimensions.hh"
122 #include "file-path.hh"
124 #include "international.hh"
125 #include "lily-guile.hh"
126 #include "lily-lexer.hh"
127 #include "lily-parser.hh"
131 #include "output-def.hh"
132 #include "paper-book.hh"
133 #include "scm-hash.hh"
135 #include "text-interface.hh"
138 #define MYBACKUP(Token, Value, Location) \
140 if (yychar == YYEMPTY) \
143 PARSER->lexer_->push_extra_token (Token, Value); \
144 PARSER->lexer_->push_extra_token (BACKUP); \
146 PARSER->parser_error \
147 (Location, _("Too much lookahead")); \
152 #define MYREPARSE(Location, Pred, Token, Value) \
154 if (yychar == YYEMPTY) \
156 PARSER->lexer_->push_extra_token (Token, Value); \
157 PARSER->lexer_->push_extra_token (REPARSE, \
160 PARSER->parser_error \
161 (Location, _("Too much lookahead")); \
170 Output_def *outputdef;
179 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
182 - Don't use lily module, create a new module instead.
183 - delay application of the function
185 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
186 scm_apply_0 (proc, args)
187 /* Syntactic Sugar. */
188 #define MAKE_SYNTAX(name, location, ...) \
189 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (PARSER->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED));
190 #define START_MAKE_SYNTAX(name, ...) \
191 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
192 #define FINISH_MAKE_SYNTAX(start, location, ...) \
193 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (PARSER->self_scm (), make_input (location), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
195 SCM get_next_unique_context_id ();
196 SCM get_next_unique_lyrics_context_id ();
203 #define _(x) gettext (x)
207 static Music *make_music_with_input (SCM name, Input where);
208 SCM check_scheme_arg (Lily_parser *parser, Input loc,
209 SCM arg, SCM args, SCM pred);
210 SCM loc_on_music (Input loc, SCM arg);
211 SCM get_first_context_id (SCM type, Music *m);
212 SCM make_chord_elements (SCM pitch, SCM dur, SCM modification_list);
213 SCM make_chord_step (int step, Rational alter);
214 SCM make_simple_markup (SCM a);
215 bool is_duration (int t);
216 bool is_regular_identifier (SCM id);
217 bool ly_input_procedure_p (SCM x);
218 int yylex (YYSTYPE *s, YYLTYPE *loc, void *v);
219 void set_music_properties (Music *p, SCM a);
223 /* The third option is an alias that will be used to display the
224 syntax error. Bison CVS now correctly handles backslash escapes.
226 FIXME: Bison needs to translate some of these, eg, STRING.
230 /* Keyword tokens with plain escaped name. */
231 %token ACCEPTS "\\accepts"
232 %token ADDLYRICS "\\addlyrics"
233 %token ALIAS "\\alias"
234 %token ALTERNATIVE "\\alternative"
236 %token BOOKPART "\\bookpart"
237 %token CHANGE "\\change"
238 %token CHORDMODE "\\chordmode"
239 %token CHORDS "\\chords"
240 %token CONSISTS "\\consists"
241 %token CONTEXT "\\context"
242 %token DEFAULT "\\default"
243 %token DEFAULTCHILD "\\defaultchild"
244 %token DENIES "\\denies"
245 %token DESCRIPTION "\\description"
246 %token DRUMMODE "\\drummode"
247 %token DRUMS "\\drums"
248 %token FIGUREMODE "\\figuremode"
249 %token FIGURES "\\figures"
250 %token HEADER "\\header"
251 %token INVALID "\\version-error"
252 %token LAYOUT "\\layout"
253 %token LYRICMODE "\\lyricmode"
254 %token LYRICS "\\lyrics"
255 %token LYRICSTO "\\lyricsto"
256 %token MARKUP "\\markup"
257 %token MARKUPLIST "\\markuplist"
260 %token NOTEMODE "\\notemode"
261 %token OVERRIDE "\\override"
262 %token PAPER "\\paper"
263 %token REMOVE "\\remove"
264 %token REPEAT "\\repeat"
266 %token REVERT "\\revert"
267 %token SCORE "\\score"
268 %token SEQUENTIAL "\\sequential"
270 %token SIMULTANEOUS "\\simultaneous"
271 %token TEMPO "\\tempo"
273 %token UNSET "\\unset"
276 /* Keyword token exceptions. */
277 %token NEWCONTEXT "\\new"
280 /* Other string tokens. */
282 %token CHORD_BASS "/+"
283 %token CHORD_CARET "^"
284 %token CHORD_COLON ":"
285 %token CHORD_MINUS "-"
286 %token CHORD_SLASH "/"
287 %token ANGLE_OPEN "<"
288 %token ANGLE_CLOSE ">"
289 %token DOUBLE_ANGLE_OPEN "<<"
290 %token DOUBLE_ANGLE_CLOSE ">>"
291 %token E_BACKSLASH "\\"
292 %token E_ANGLE_CLOSE "\\>"
293 %token E_CHAR "\\C[haracter]"
295 %token E_EXCLAMATION "\\!"
296 %token E_BRACKET_OPEN "\\["
298 %token E_BRACKET_CLOSE "\\]"
299 %token E_ANGLE_OPEN "\\<"
305 If we give names, Bison complains.
307 %token FIGURE_CLOSE /* "\\>" */
308 %token FIGURE_OPEN /* "\\<" */
309 %token FIGURE_SPACE "_"
312 %token CHORDMODIFIERS
314 %token MULTI_MEASURE_REST
317 %token <i> E_UNSIGNED
318 %token <scm> UNSIGNED
320 /* Artificial tokens, for more generic function syntax */
321 %token <i> EXPECT_MARKUP "markup?"
322 %token <i> EXPECT_PITCH "ly:pitch?"
323 %token <i> EXPECT_DURATION "ly:duration?"
324 %token <scm> EXPECT_SCM "scheme?"
325 %token <scm> BACKUP "(backed-up?)"
326 %token <scm> REPARSE "(reparsed?)"
327 %token <i> EXPECT_MARKUP_LIST "markup-list?"
328 %token <scm> EXPECT_OPTIONAL "optional?"
329 /* After the last argument. */
330 %token <i> EXPECT_NO_MORE_ARGS;
332 /* An artificial token for parsing embedded Lilypond */
333 %token <i> EMBEDDED_LILY "#{"
335 %token <scm> BOOK_IDENTIFIER
336 %token <scm> CHORDMODIFIER_PITCH
337 %token <scm> CHORD_MODIFIER
338 %token <scm> CHORD_REPETITION
339 %token <scm> CONTEXT_DEF_IDENTIFIER
340 %token <scm> CONTEXT_MOD_IDENTIFIER
341 %token <scm> DRUM_PITCH
342 %token <scm> PITCH_IDENTIFIER
343 %token <scm> DURATION_IDENTIFIER
344 %token <scm> EVENT_IDENTIFIER
345 %token <scm> EVENT_FUNCTION
346 %token <scm> FRACTION
347 %token <scm> LYRICS_STRING
348 %token <scm> LYRIC_ELEMENT
349 %token <scm> LYRIC_ELEMENT_P
350 %token <scm> LYRIC_MARKUP_IDENTIFIER
351 %token <scm> MARKUP_FUNCTION
352 %token <scm> MARKUP_LIST_FUNCTION
353 %token <scm> MARKUP_IDENTIFIER
354 %token <scm> MARKUPLIST_IDENTIFIER
355 %token <scm> MUSIC_FUNCTION
356 %token <scm> MUSIC_IDENTIFIER
357 %token <scm> NOTENAME_PITCH
358 %token <scm> NUMBER_IDENTIFIER
359 %token <scm> OUTPUT_DEF_IDENTIFIER
361 %token <scm> RESTNAME
362 %token <scm> SCM_FUNCTION
363 %token <scm> SCM_IDENTIFIER
364 %token <scm> SCM_TOKEN
365 %token <scm> SCORE_IDENTIFIER
367 %token <scm> STRING_IDENTIFIER
368 %token <scm> TONICNAME_PITCH
371 %type <book> book_block
372 %type <book> book_body
373 %type <book> bookpart_block
374 %type <book> bookpart_body
376 %type <i> bare_unsigned
377 %type <scm> figured_bass_alteration
379 %type <i> exclamations
380 %type <i> optional_rest
385 %type <i> tremolo_type
388 %type <scm> composite_music
389 %type <scm> grouped_music_list
390 %type <scm> braced_music_list
391 %type <scm> closed_music
393 %type <scm> music_bare
394 %type <scm> music_arg
395 %type <scm> complex_music
396 %type <scm> complex_music_prefix
397 %type <scm> mode_changed_music
398 %type <scm> repeated_music
399 %type <scm> sequential_music
400 %type <scm> simple_music
401 %type <scm> simultaneous_music
402 %type <scm> chord_body
403 %type <scm> chord_body_element
404 %type <scm> command_element
405 %type <scm> command_event
406 %type <scm> context_modification
407 %type <scm> context_change
408 %type <scm> direction_less_event
409 %type <scm> direction_reqd_event
410 %type <scm> embedded_lilypond
411 %type <scm> event_chord
412 %type <scm> fingering
413 %type <scm> gen_text_def
414 %type <scm> music_property_def
415 %type <scm> note_chord_element
416 %type <scm> post_event
417 %type <scm> post_event_nofinger
418 %type <scm> re_rhythmed_music
419 %type <scm> simple_element
420 %type <scm> simple_music_property_def
421 %type <scm> start_symbol
422 %type <scm> string_number_event
423 %type <scm> tempo_event
425 %type <outputdef> output_def_body
426 %type <outputdef> output_def_head
427 %type <outputdef> output_def_head_with_mode_switch
428 %type <outputdef> output_def
429 %type <outputdef> paper_block
431 %type <scm> music_function_call
432 %type <scm> music_list
433 %type <scm> assignment_id
434 %type <scm> bare_number
435 %type <scm> bare_number_closed
436 %type <scm> unsigned_number
437 %type <scm> bass_figure
438 %type <scm> figured_bass_modification
439 %type <scm> br_bass_figure
440 %type <scm> bass_number
441 %type <scm> chord_body_elements
442 %type <scm> chord_item
443 %type <scm> chord_items
444 %type <scm> chord_separator
445 %type <scm> context_def_mod
446 %type <scm> context_def_spec_block
447 %type <scm> context_def_spec_body
448 %type <scm> context_mod
449 %type <scm> context_mod_list
450 %type <scm> context_prop_spec
451 %type <scm> direction_less_char
452 %type <scm> duration_length
453 %type <scm> embedded_scm
454 %type <scm> embedded_scm_arg
455 %type <scm> embedded_scm_arg_closed
456 %type <scm> embedded_scm_bare
457 %type <scm> embedded_scm_bare_arg
458 %type <scm> embedded_scm_closed
459 %type <scm> embedded_scm_chord_body
460 %type <scm> event_function_event
461 %type <scm> figure_list
462 %type <scm> figure_spec
464 %type <scm> full_markup
465 %type <scm> full_markup_list
466 %type <scm> function_arglist
467 %type <scm> function_arglist_optional
468 %type <scm> function_arglist_backup
469 %type <scm> function_arglist_nonbackup
470 %type <scm> function_arglist_skip
471 %type <scm> function_arglist_bare
472 %type <scm> function_arglist_closed
473 %type <scm> function_arglist_closed_optional
474 %type <scm> function_arglist_common
475 %type <scm> function_arglist_common_lyric
476 %type <scm> function_arglist_common_minus
477 %type <scm> function_arglist_closed_common
478 %type <scm> function_arglist_keep
479 %type <scm> function_arglist_closed_keep
480 %type <scm> identifier_init
482 %type <scm> lilypond_header
483 %type <scm> lilypond_header_body
484 %type <scm> lyric_element
485 %type <scm> lyric_element_arg
486 %type <scm> lyric_element_music
487 %type <scm> lyric_markup
489 %type <scm> markup_braced_list
490 %type <scm> markup_braced_list_body
491 %type <scm> markup_composed_list
492 %type <scm> markup_command_list
493 %type <scm> markup_command_list_arguments
494 %type <scm> markup_command_basic_arguments
495 %type <scm> markup_head_1_item
496 %type <scm> markup_head_1_list
497 %type <scm> markup_list
498 %type <scm> markup_top
499 %type <scm> mode_changing_head
500 %type <scm> mode_changing_head_with_context
501 %type <scm> multiplied_duration
502 %type <scm> music_function_event
503 %type <scm> music_function_chord_body
504 %type <scm> music_function_chord_body_arglist
505 %type <scm> new_chord
506 %type <scm> new_lyrics
507 %type <scm> number_expression
508 %type <scm> number_factor
509 %type <scm> number_term
510 %type <scm> octave_check
511 %type <scm> optional_context_mod
512 %type <scm> optional_id
513 %type <scm> optional_notemode_duration
515 %type <scm> pitch_also_in_chords
516 %type <scm> post_events
517 %type <scm> property_operation
518 %type <scm> property_path property_path_revved
520 %type <scm> scalar_closed
521 %type <scm> scm_function_call
522 %type <scm> scm_function_call_closed
523 %type <scm> script_abbreviation
524 %type <scm> simple_chord_elements
525 %type <scm> simple_markup
526 %type <scm> simple_string
527 %type <scm> steno_duration
528 %type <scm> steno_pitch
529 %type <scm> steno_tonic_pitch
530 %type <scm> step_number
531 %type <scm> step_numbers
533 %type <scm> tempo_range
535 %type <score> score_block
536 %type <score> score_body
541 /* We don't assign precedence to / and *, because we might need varied
542 prec levels in different prods */
551 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
552 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
553 } embedded_lilypond {
554 PARSER->lexer_->pop_state ();
555 PARSER->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
559 lilypond: /* empty */ { }
560 | lilypond toplevel_expression {
562 | lilypond assignment {
565 PARSER->error_level_ = 1;
568 PARSER->error_level_ = 1;
575 PARSER->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
579 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-book-handler");
580 scm_call_2 (proc, PARSER->self_scm (), book->self_scm ());
585 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-bookpart-handler");
586 scm_call_2 (proc, PARSER->self_scm (), bookpart->self_scm ());
587 bookpart->unprotect ();
592 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-score-handler");
593 scm_call_2 (proc, PARSER->self_scm (), score->self_scm ());
597 Music *music = unsmob_music ($1);
598 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-music-handler");
599 scm_call_2 (proc, PARSER->self_scm (), music->self_scm ());
602 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
603 scm_call_2 (proc, PARSER->self_scm (), scm_list_1 ($1));
606 SCM proc = PARSER->lexer_->lookup_identifier ("toplevel-text-handler");
607 scm_call_2 (proc, PARSER->self_scm (), $1);
611 Output_def * od = $1;
613 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
614 id = ly_symbol2scm ("$defaultpaper");
615 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
616 id = ly_symbol2scm ("$defaultmidi");
617 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
618 id = ly_symbol2scm ("$defaultlayout");
620 PARSER->lexer_->set_identifier (id, od->self_scm ());
628 $$ = PARSER->lexer_->eval_scm ($1);
633 embedded_scm_bare_arg:
639 | context_modification
642 $$ = $1->self_scm ();
645 | context_def_spec_block
648 $$ = $1->self_scm ();
653 $$ = $1->self_scm ();
658 $$ = $1->self_scm ();
663 /* The generic version may end in music, or not */
671 embedded_scm_bare_arg
677 SCM_FUNCTION function_arglist {
678 $$ = MAKE_SYNTAX ("music-function", @$,
686 $$ = MAKE_SYNTAX ("void-music", @$);
689 | music music music_list {
690 $$ = MAKE_SYNTAX ("sequential-music", @$,
691 scm_cons2 ($1, $2, scm_reverse_x ($3, SCM_EOL)));
694 PARSER->error_level_ = 1;
696 | INVALID embedded_lilypond {
697 PARSER->error_level_ = 1;
702 lilypond_header_body:
704 $$ = get_header (PARSER);
705 PARSER->lexer_->add_scope ($$);
707 | lilypond_header_body assignment {
713 HEADER '{' lilypond_header_body '}' {
714 $$ = PARSER->lexer_->remove_scope ();
723 | LYRICS_STRING { $$ = $1; }
727 assignment_id '=' identifier_init {
728 PARSER->lexer_->set_identifier ($1, $3);
730 | assignment_id property_path '=' identifier_init {
731 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
732 PARSER->lexer_->set_identifier (path, $4);
735 TODO: devise standard for protection in parser.
737 The parser stack lives on the C-stack, which means that
738 all objects can be unprotected as soon as they're here.
748 $$ = $1->self_scm ();
752 $$ = $1->self_scm ();
756 $$ = $1->self_scm ();
760 $$ = $1->self_scm ();
763 | context_def_spec_block {
767 /* Hack: Create event-chord around standalone events.
768 Prevents the identifier from being interpreted as a post-event. */
769 Music *mus = unsmob_music ($1);
770 bool is_event = mus &&
771 (scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
776 $$ = MAKE_SYNTAX ("event-chord", @$, scm_list_1 ($1));
778 | post_event_nofinger {
781 | number_expression {
796 | context_modification {
801 context_def_spec_block:
802 CONTEXT '{' context_def_spec_body '}'
808 context_def_spec_body:
810 $$ = Context_def::make_scm ();
811 unsmob_context_def ($$)->origin ()->set_spot (@$);
813 | CONTEXT_DEF_IDENTIFIER {
815 unsmob_context_def ($$)->origin ()->set_spot (@$);
817 | context_def_spec_body embedded_scm {
818 if (Context_mod *cm = unsmob_context_mod ($2)) {
819 SCM p = cm->get_mods ();
820 Context_def*td = unsmob_context_def ($$);
822 for (; scm_is_pair (p); p = scm_cdr (p)) {
823 td->add_context_mod (scm_car (p));
826 PARSER->parser_error (@2, "context-mod expected");
829 | context_def_spec_body context_mod {
830 unsmob_context_def ($$)->add_context_mod ($2);
832 | context_def_spec_body context_modification {
833 Context_def *td = unsmob_context_def ($$);
834 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
835 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
836 td->add_context_mod (scm_car (m));
844 BOOK '{' book_body '}' {
847 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
852 * Use 'handlers' like for toplevel-* stuff?
853 * grok \layout and \midi? */
857 init_papers (PARSER);
858 $$->origin ()->set_spot (@$);
859 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
860 $$->paper_->unprotect ();
861 push_paper (PARSER, $$->paper_);
862 $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader");
863 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
864 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-output-suffix"), SCM_BOOL_F);
865 PARSER->lexer_->set_identifier (ly_symbol2scm ("book-filename"), SCM_BOOL_F);
868 $$ = unsmob_book ($1);
870 $$->origin ()->set_spot (@$);
871 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
873 | book_body paper_block {
876 set_paper (PARSER, $2);
878 | book_body bookpart_block {
880 SCM proc = PARSER->lexer_->lookup_identifier ("book-bookpart-handler");
881 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
882 bookpart->unprotect ();
884 | book_body score_block {
886 SCM proc = PARSER->lexer_->lookup_identifier ("book-score-handler");
887 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
890 | book_body composite_music {
891 Music *music = unsmob_music ($2);
892 SCM proc = PARSER->lexer_->lookup_identifier ("book-music-handler");
893 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
895 | book_body full_markup {
896 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
897 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
899 | book_body full_markup_list {
900 SCM proc = PARSER->lexer_->lookup_identifier ("book-text-handler");
901 scm_call_2 (proc, $$->self_scm (), $2);
903 | book_body lilypond_header {
906 | book_body embedded_scm { }
909 $$->scores_ = SCM_EOL;
910 $$->bookparts_ = SCM_EOL;
915 BOOKPART '{' bookpart_body '}' {
917 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
924 $$->origin ()->set_spot (@$);
925 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
928 $$ = unsmob_book ($1);
930 $$->origin ()->set_spot (@$);
931 PARSER->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
933 | bookpart_body paper_block {
937 | bookpart_body score_block {
939 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-score-handler");
940 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
943 | bookpart_body composite_music {
944 Music *music = unsmob_music ($2);
945 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-music-handler");
946 scm_call_3 (proc, PARSER->self_scm (), $$->self_scm (), music->self_scm ());
948 | bookpart_body full_markup {
949 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
950 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
952 | bookpart_body full_markup_list {
953 SCM proc = PARSER->lexer_->lookup_identifier ("bookpart-text-handler");
954 scm_call_2 (proc, $$->self_scm (), $2);
956 | bookpart_body lilypond_header {
959 | bookpart_body embedded_scm { }
960 | bookpart_body error {
962 $$->scores_ = SCM_EOL;
967 SCORE '{' score_body '}' {
975 SCM scorify = ly_lily_module_constant ("scorify-music");
976 SCM score = scm_call_2 (scorify, m, PARSER->self_scm ());
978 // pass ownernship to C++ again.
979 $$ = unsmob_score (score);
981 $$->origin ()->set_spot (@$);
984 $$ = unsmob_score ($1);
986 $$->origin ()->set_spot (@$);
988 | score_body lilypond_header {
991 | score_body output_def {
992 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
994 PARSER->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
999 $$->add_output_def ($2);
1003 | score_body error {
1004 $$->error_found_ = true;
1016 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1018 PARSER->parser_error (@1, _ ("need \\paper for paper block"));
1020 $$ = get_paper (PARSER);
1027 output_def_body '}' {
1030 PARSER->lexer_->remove_scope ();
1031 PARSER->lexer_->pop_state ();
1037 $$ = get_paper (PARSER);
1038 $$->input_origin_ = @$;
1039 PARSER->lexer_->add_scope ($$->scope_);
1042 Output_def *p = get_midi (PARSER);
1044 PARSER->lexer_->add_scope (p->scope_);
1047 Output_def *p = get_layout (PARSER);
1049 PARSER->lexer_->add_scope (p->scope_);
1054 output_def_head_with_mode_switch:
1056 PARSER->lexer_->push_initial_state ();
1062 output_def_head_with_mode_switch '{' {
1064 $$->input_origin_.set_spot (@$);
1066 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1069 Output_def *o = unsmob_output_def ($3);
1070 o->input_origin_.set_spot (@$);
1073 PARSER->lexer_->remove_scope ();
1074 PARSER->lexer_->add_scope (o->scope_);
1076 | output_def_body assignment {
1079 | output_def_body context_def_spec_block {
1080 assign_context_def ($$, $2);
1082 | output_def_body error {
1088 TEMPO steno_duration '=' tempo_range {
1089 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1091 | TEMPO scalar_closed steno_duration '=' tempo_range {
1092 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1095 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1100 The representation of a list is reversed to have efficient append. */
1106 | music_list music {
1107 $$ = scm_cons ($2, $1);
1109 | music_list embedded_scm {
1112 | music_list error {
1113 Music *m = MY_MAKE_MUSIC("Music", @$);
1115 m->set_property ("error-found", SCM_BOOL_T);
1116 $$ = scm_cons (m->self_scm (), $1);
1117 m->unprotect (); /* UGH */
1124 $$ = scm_reverse_x ($2, SCM_EOL);
1129 | lyric_element_music
1130 | composite_music %prec COMPOSITE
1135 | composite_music %prec COMPOSITE
1139 REPEAT simple_string unsigned_number music
1141 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1143 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1145 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1150 SEQUENTIAL braced_music_list {
1151 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1153 | braced_music_list {
1154 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1159 SIMULTANEOUS braced_music_list {
1160 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1162 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1163 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1169 | music_property_def
1173 context_modification:
1174 WITH { PARSER->lexer_->push_initial_state (); } '{' context_mod_list '}'
1176 PARSER->lexer_->pop_state ();
1179 | WITH CONTEXT_MOD_IDENTIFIER
1183 | CONTEXT_MOD_IDENTIFIER
1187 | WITH embedded_scm_closed
1189 if (unsmob_context_mod ($2))
1192 PARSER->parser_error (@2, "context-mod expected");
1193 $$ = Context_mod ().smobbed_copy ();
1198 optional_context_mod:
1202 | context_modification
1210 $$ = Context_mod ().smobbed_copy ();
1212 | context_mod_list context_mod {
1213 unsmob_context_mod ($1)->add_context_mod ($2);
1215 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1216 Context_mod *md = unsmob_context_mod ($2);
1218 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1227 /* Music that can be parsed without lookahead */
1230 | complex_music_prefix closed_music
1232 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1239 | grouped_music_list
1243 simultaneous_music { $$ = $1; }
1244 | sequential_music { $$ = $1; }
1247 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1248 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1249 and this rule returns the reversed list of arguments. */
1251 function_arglist_skip:
1252 function_arglist_common
1253 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1255 $$ = scm_cons ($1, $3);
1256 } %prec FUNCTION_ARGLIST
1257 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1259 $$ = scm_cons ($1, $3);
1260 } %prec FUNCTION_ARGLIST
1261 | EXPECT_SCM EXPECT_DURATION function_arglist_skip
1263 $$ = scm_cons ($1, $3);
1264 } %prec FUNCTION_ARGLIST
1268 function_arglist_nonbackup:
1269 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1270 $$ = scm_cons ($4, $3);
1272 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1273 $$ = scm_cons ($4, $3);
1275 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1277 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1279 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1281 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1283 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1285 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1287 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1289 $$ = check_scheme_arg (PARSER, @4, $4, $3, $2);
1291 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1293 SCM n = scm_difference ($5, SCM_UNDEFINED);
1294 if (scm_is_true (scm_call_1 ($2, n)))
1295 $$ = scm_cons (n, $3);
1297 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1298 t->set_property ("digit", $5);
1299 $$ = t->unprotect ();
1300 if (scm_is_true (scm_call_1 ($2, $$)))
1301 $$ = scm_cons ($$, $3);
1303 $$ = check_scheme_arg (PARSER, @4, n, $3, $2);
1307 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1309 $$ = check_scheme_arg (PARSER, @4,
1310 scm_difference ($5, SCM_UNDEFINED),
1313 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1315 $$ = check_scheme_arg (PARSER, @4,
1316 scm_difference ($5, SCM_UNDEFINED),
1322 function_arglist_keep:
1323 function_arglist_common
1324 | function_arglist_backup
1327 function_arglist_closed_keep:
1328 function_arglist_closed_common
1329 | function_arglist_backup
1332 function_arglist_backup:
1333 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1335 if (scm_is_true (scm_call_1 ($2, $4)))
1337 $$ = scm_cons ($4, $3);
1339 $$ = scm_cons (loc_on_music (@3, $1), $3);
1340 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1343 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1345 if (scm_is_true (scm_call_1 ($2, $4)))
1347 $$ = scm_cons ($4, $3);
1349 $$ = scm_cons (loc_on_music (@3, $1), $3);
1350 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1353 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1355 // There is no point interpreting a lyrics string as
1356 // an event, since we don't allow music possibly
1357 // followed by durations or postevent into closed
1358 // music, and we only accept closed music in optional
1359 // arguments at the moment. If this changes, more
1360 // complex schemes might become interesting here as
1361 // well: see how we do this at the mandatory argument
1363 if (scm_is_true (scm_call_1 ($2, $4)))
1364 $$ = scm_cons ($3, $2);
1366 $$ = scm_cons (loc_on_music (@3, $1), $3);
1367 MYBACKUP (LYRIC_MARKUP_IDENTIFIER, $4, @4);
1370 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1372 if (scm_is_true (scm_call_1 ($2, $4)))
1375 MYREPARSE (@4, $2, UNSIGNED, $4);
1377 $$ = scm_cons (loc_on_music (@3, $1), $3);
1378 MYBACKUP (UNSIGNED, $4, @4);
1381 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1383 if (scm_is_true (scm_call_1 ($2, $4)))
1386 MYREPARSE (@4, $2, REAL, $4);
1388 $$ = scm_cons (loc_on_music (@3, $1), $3);
1389 MYBACKUP (REAL, $4, @4);
1392 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1394 if (scm_is_true (scm_call_1 ($2, $4)))
1396 $$ = scm_cons ($4, $3);
1398 $$ = scm_cons (loc_on_music (@3, $1), $3);
1399 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1402 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1404 if (scm_is_true (scm_call_1 ($2, $4)))
1406 $$ = scm_cons ($4, $3);
1408 $$ = scm_cons (loc_on_music (@3, $1), $3);
1409 MYBACKUP (FRACTION, $4, @4);
1412 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1414 SCM n = scm_difference ($5, SCM_UNDEFINED);
1415 if (scm_is_true (scm_call_1 ($2, n))) {
1417 MYREPARSE (@5, $2, REAL, n);
1419 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1420 t->set_property ("digit", $5);
1421 $$ = t->unprotect ();
1422 if (scm_is_true (scm_call_1 ($2, $$)))
1423 $$ = scm_cons ($$, $3);
1425 $$ = scm_cons (loc_on_music (@3, $1), $3);
1426 MYBACKUP (UNSIGNED, $5, @5);
1427 PARSER->lexer_->push_extra_token ('-');
1432 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1434 SCM n = scm_difference ($5, SCM_UNDEFINED);
1435 if (scm_is_true (scm_call_1 ($2, n))) {
1436 MYREPARSE (@5, $2, REAL, n);
1439 MYBACKUP (REAL, n, @5);
1442 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1444 SCM n = scm_difference ($5, SCM_UNDEFINED);
1445 if (scm_is_true (scm_call_1 ($2, n))) {
1446 $$ = scm_cons (n, $3);
1448 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1451 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1453 $$ = scm_cons ($4, $3);
1455 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1457 $$ = scm_cons ($4, $3);
1459 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1461 $$ = scm_cons ($1, $3);
1462 MYBACKUP(0, SCM_UNDEFINED, @3);
1464 | function_arglist_backup REPARSE embedded_scm_arg_closed
1466 $$ = check_scheme_arg (PARSER, @3,
1469 | function_arglist_backup REPARSE bare_number
1471 $$ = check_scheme_arg (PARSER, @3,
1474 | function_arglist_backup REPARSE fraction
1476 $$ = check_scheme_arg (PARSER, @3,
1482 function_arglist_common
1483 | function_arglist_nonbackup
1486 function_arglist_common:
1487 function_arglist_bare
1488 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1490 $$ = check_scheme_arg (PARSER, @3,
1493 | EXPECT_SCM function_arglist_closed_optional bare_number
1495 $$ = check_scheme_arg (PARSER, @3,
1498 | EXPECT_SCM function_arglist_closed_optional fraction
1500 $$ = check_scheme_arg (PARSER, @3,
1503 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1505 $$ = check_scheme_arg (PARSER, @3,
1508 | function_arglist_common_minus
1509 | function_arglist_common_lyric
1512 function_arglist_common_lyric:
1513 EXPECT_SCM function_arglist_optional lyric_element
1515 // We check how the predicate thinks about a lyrics
1516 // event or about a markup. If it accepts neither, we
1517 // backup the original token. Otherwise we commit to
1518 // taking the token. Depending on what the predicate
1519 // is willing to accept, we interpret as a string, as
1520 // a lyric event, or ambiguously (meaning that if
1521 // something looking like a duration or post event
1522 // follows, we take the event, otherwise the string).
1523 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1524 PARSER->default_duration_.smobbed_copy ());
1525 if (scm_is_true (scm_call_1 ($1, $3)))
1526 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1529 MYREPARSE (@3, $1, LYRIC_ELEMENT_P, $3);
1531 $$ = scm_cons ($3, $2);
1533 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1536 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1538 // This is going to flag a syntax error, we
1539 // know the predicate to be false.
1540 check_scheme_arg (PARSER, @3,
1544 | function_arglist_common_lyric REPARSE lyric_element_arg
1546 // This should never be false
1547 $$ = check_scheme_arg (PARSER, @3,
1552 function_arglist_common_minus:
1553 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1555 SCM n = scm_difference ($4, SCM_UNDEFINED);
1556 if (scm_is_true (scm_call_1 ($1, n))) {
1558 MYREPARSE (@4, $1, REAL, n);
1560 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1561 t->set_property ("digit", $4);
1562 $$ = t->unprotect ();
1563 if (scm_is_true (scm_call_1 ($1, $$)))
1564 $$ = scm_cons ($$, $2);
1566 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1570 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1573 SCM n = scm_difference ($4, SCM_UNDEFINED);
1574 MYREPARSE (@4, $1, REAL, n);
1576 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1578 SCM n = scm_difference ($4, SCM_UNDEFINED);
1579 $$ = check_scheme_arg (PARSER, @4, n, $2, $1);
1581 | function_arglist_common_minus REPARSE bare_number
1583 $$ = check_scheme_arg (PARSER, @3, $3, $1, $2);
1587 function_arglist_closed:
1588 function_arglist_closed_common
1589 | function_arglist_nonbackup
1592 function_arglist_closed_common:
1593 function_arglist_bare
1594 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1596 $$ = check_scheme_arg (PARSER, @3,
1599 | EXPECT_SCM function_arglist_closed_optional bare_number
1601 $$ = check_scheme_arg (PARSER, @3,
1604 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1606 SCM n = scm_difference ($4, SCM_UNDEFINED);
1607 if (scm_is_true (scm_call_1 ($1, n))) {
1608 $$ = scm_cons (n, $2);
1610 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1611 t->set_property ("digit", $4);
1612 $$ = t->unprotect ();
1613 if (scm_is_true (scm_call_1 ($1, $$)))
1614 $$ = scm_cons ($$, $2);
1616 $$ = check_scheme_arg (PARSER, @3, n, $2, $1);
1620 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1622 $$ = check_scheme_arg (PARSER, @3,
1623 scm_difference ($4, SCM_UNDEFINED),
1626 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1628 $$ = check_scheme_arg (PARSER, @3,
1629 scm_difference ($4, SCM_UNDEFINED),
1632 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1634 $$ = check_scheme_arg (PARSER, @3,
1637 | EXPECT_SCM function_arglist_closed_optional fraction
1639 $$ = check_scheme_arg (PARSER, @3,
1642 | EXPECT_SCM function_arglist_optional lyric_element
1644 $$ = check_scheme_arg (PARSER, @3,
1649 function_arglist_optional:
1650 function_arglist_keep %prec FUNCTION_ARGLIST
1651 | function_arglist_backup BACKUP
1652 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1654 $$ = scm_cons ($1, $3);
1656 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1658 $$ = scm_cons ($1, $3);
1662 function_arglist_closed_optional:
1663 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1664 | function_arglist_backup BACKUP
1665 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1667 $$ = scm_cons ($1, $3);
1669 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1671 $$ = scm_cons ($1, $3);
1675 embedded_scm_closed:
1677 | scm_function_call_closed
1680 embedded_scm_arg_closed:
1681 embedded_scm_bare_arg
1682 | scm_function_call_closed
1686 scm_function_call_closed:
1687 SCM_FUNCTION function_arglist_closed {
1688 $$ = MAKE_SYNTAX ("music-function", @$,
1690 } %prec FUNCTION_ARGLIST
1693 function_arglist_bare:
1694 EXPECT_NO_MORE_ARGS {
1697 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1698 $$ = scm_cons ($3, $2);
1700 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1701 $$ = scm_cons ($3, $2);
1703 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1704 $$ = scm_cons ($1, $3);
1706 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1707 $$ = scm_cons ($1, $3);
1709 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1710 $$ = scm_cons ($1, $3);
1714 music_function_call:
1715 MUSIC_FUNCTION function_arglist {
1716 $$ = MAKE_SYNTAX ("music-function", @$,
1723 /**/ { $$ = SCM_EOL; }
1724 | '=' simple_string {
1731 | repeated_music { $$ = $1; }
1732 | re_rhythmed_music { $$ = $1; }
1733 | complex_music_prefix music
1735 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1739 complex_music_prefix:
1740 CONTEXT simple_string optional_id optional_context_mod {
1741 Context_mod *ctxmod = unsmob_context_mod ($4);
1744 mods = ctxmod->get_mods ();
1745 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1747 | NEWCONTEXT simple_string optional_id optional_context_mod {
1748 Context_mod *ctxmod = unsmob_context_mod ($4);
1751 mods = ctxmod->get_mods ();
1752 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1757 mode_changing_head grouped_music_list {
1758 if ($1 == ly_symbol2scm ("chords"))
1760 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1766 PARSER->lexer_->pop_state ();
1768 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1769 Context_mod *ctxmod = unsmob_context_mod ($2);
1772 mods = ctxmod->get_mods ();
1773 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1774 if ($1 == ly_symbol2scm ("ChordNames"))
1776 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1778 PARSER->lexer_->pop_state ();
1784 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1785 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1787 $$ = ly_symbol2scm ("notes");
1791 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1792 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1794 $$ = ly_symbol2scm ("drums");
1797 PARSER->lexer_->push_figuredbass_state ();
1799 $$ = ly_symbol2scm ("figures");
1802 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1803 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1804 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1805 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1806 $$ = ly_symbol2scm ("chords");
1810 { PARSER->lexer_->push_lyric_state ();
1811 $$ = ly_symbol2scm ("lyrics");
1815 mode_changing_head_with_context:
1817 SCM nn = PARSER->lexer_->lookup_identifier ("drumPitchNames");
1818 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
1820 $$ = ly_symbol2scm ("DrumStaff");
1823 PARSER->lexer_->push_figuredbass_state ();
1825 $$ = ly_symbol2scm ("FiguredBass");
1828 SCM nn = PARSER->lexer_->lookup_identifier ("chordmodifiers");
1829 PARSER->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1830 nn = PARSER->lexer_->lookup_identifier ("pitchnames");
1831 PARSER->lexer_->push_chord_state (alist_to_hashq (nn));
1832 $$ = ly_symbol2scm ("ChordNames");
1835 { PARSER->lexer_->push_lyric_state ();
1836 $$ = ly_symbol2scm ("Lyrics");
1841 ADDLYRICS { PARSER->lexer_->push_lyric_state (); }
1844 /* Can also use music at the expensive of two S/Rs similar to
1845 \repeat \alternative */
1846 PARSER->lexer_->pop_state ();
1848 $$ = scm_cons ($3, SCM_EOL);
1850 | new_lyrics ADDLYRICS {
1851 PARSER->lexer_->push_lyric_state ();
1853 PARSER->lexer_->pop_state ();
1854 $$ = scm_cons ($4, $1);
1859 composite_music new_lyrics {
1860 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1862 | LYRICSTO simple_string {
1863 PARSER->lexer_->push_lyric_state ();
1865 PARSER->lexer_->pop_state ();
1866 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1871 CHANGE STRING '=' STRING {
1872 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1877 property_path_revved:
1878 embedded_scm_closed {
1879 $$ = scm_cons ($1, SCM_EOL);
1881 | property_path_revved embedded_scm_closed {
1882 $$ = scm_cons ($2, $1);
1887 property_path_revved {
1888 $$ = scm_reverse_x ($1, SCM_EOL);
1894 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1895 scm_string_to_symbol ($1), $3);
1897 | UNSET simple_string {
1898 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1899 scm_string_to_symbol ($2));
1901 | OVERRIDE simple_string property_path '=' scalar {
1902 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1903 scm_string_to_symbol ($2), $5),
1906 | REVERT simple_string embedded_scm {
1907 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1908 scm_string_to_symbol ($2), $3);
1913 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1914 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1916 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1917 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1918 | DENIES { $$ = ly_symbol2scm ("denies"); }
1920 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1921 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1922 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1923 | NAME { $$ = ly_symbol2scm ("context-name"); }
1927 property_operation { $$ = $1; }
1928 | context_def_mod STRING {
1929 $$ = scm_list_2 ($1, $2);
1931 | context_def_mod embedded_scm {
1932 if (ly_symbol2scm ("consists") != $1)
1935 PARSER->parser_error (@1, _ ("only \\consists takes non-string argument."));
1939 $$ = scm_list_2 ($1, $2);
1946 if (!is_regular_identifier ($1))
1948 @$.error (_("Grob name should be alphanumeric"));
1951 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1952 scm_string_to_symbol ($1));
1954 | simple_string '.' simple_string {
1955 $$ = scm_list_2 (scm_string_to_symbol ($1),
1956 scm_string_to_symbol ($3));
1960 simple_music_property_def:
1961 OVERRIDE context_prop_spec property_path '=' scalar {
1962 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1963 ly_symbol2scm ("OverrideProperty"),
1968 | REVERT context_prop_spec embedded_scm {
1969 $$ = scm_list_4 (scm_car ($2),
1970 ly_symbol2scm ("RevertProperty"),
1974 | SET context_prop_spec '=' scalar {
1975 $$ = scm_list_4 (scm_car ($2),
1976 ly_symbol2scm ("PropertySet"),
1980 | UNSET context_prop_spec {
1981 $$ = scm_list_3 (scm_car ($2),
1982 ly_symbol2scm ("PropertyUnset"),
1988 simple_music_property_def {
1989 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (PARSER->self_scm (), make_input (@$), $1));
1997 | STRING_IDENTIFIER {
2000 | string '+' string {
2001 $$ = scm_string_append (scm_list_2 ($1, $3));
2005 simple_string: STRING {
2011 | STRING_IDENTIFIER {
2023 embedded_scm_arg_closed
2030 /* TODO: Create a special case that avoids the creation of
2031 EventChords around simple_elements that have no post_events?
2033 simple_chord_elements post_events {
2034 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2037 /* why is this giving wrong start location? -ns
2039 i.set_location (@1, @2);
2040 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2042 | CHORD_REPETITION optional_notemode_duration post_events {
2044 i.set_location (@1, @3);
2045 $$ = MAKE_SYNTAX ("repetition-chord", i,
2046 PARSER->lexer_->chord_repetition_.last_chord_,
2047 PARSER->lexer_->chord_repetition_.repetition_function_,
2048 $2, scm_reverse_x ($3, SCM_EOL));
2050 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2052 i.set_location (@1, @3);
2053 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2054 scm_reverse_x ($3, SCM_EOL));
2057 /* note chord elements are memorized into
2058 PARSER->lexer_->chord_repetition_ so that the chord repetition
2059 mechanism copy them when a chord repetition symbol is found
2061 | note_chord_element {
2062 PARSER->lexer_->chord_repetition_.last_chord_ = $$;
2068 chord_body optional_notemode_duration post_events
2070 Music *m = unsmob_music ($1);
2071 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2072 SCM es = m->get_property ("elements");
2073 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2075 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2076 unsmob_music (scm_car (s))->set_property ("duration", dur);
2077 es = ly_append2 (es, postevs);
2079 m-> set_property ("elements", es);
2081 $$ = m->self_scm ();
2086 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2088 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2092 chord_body_elements:
2093 /* empty */ { $$ = SCM_EOL; }
2094 | chord_body_elements chord_body_element {
2095 $$ = scm_cons ($2, $1);
2100 pitch exclamations questions octave_check post_events
2107 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2108 n->set_property ("pitch", $1);
2110 n->set_property ("cautionary", SCM_BOOL_T);
2111 if (ex % 2 || q % 2)
2112 n->set_property ("force-accidental", SCM_BOOL_T);
2114 if (scm_is_pair (post)) {
2115 SCM arts = scm_reverse_x (post, SCM_EOL);
2116 n->set_property ("articulations", arts);
2118 if (scm_is_number (check))
2120 int q = scm_to_int (check);
2121 n->set_property ("absolute-octave", scm_from_int (q-1));
2124 $$ = n->unprotect ();
2126 | DRUM_PITCH post_events {
2127 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2128 n->set_property ("drum-type", $1);
2130 if (scm_is_pair ($2)) {
2131 SCM arts = scm_reverse_x ($2, SCM_EOL);
2132 n->set_property ("articulations", arts);
2134 $$ = n->unprotect ();
2136 | music_function_chord_body
2139 /* We can't accept a music argument, not even a closed one,
2140 * immediately before chord_body_elements, otherwise a function \fun
2141 * with a signature of two music arguments can't be sorted out
2142 * properly in a construct like
2143 * <\fun { c } \fun { c } c>
2144 * The second call could be interpreted either as a chord constituent
2145 * or a music expression.
2148 music_function_chord_body_arglist:
2149 function_arglist_bare
2150 | EXPECT_SCM music_function_chord_body_arglist embedded_scm_chord_body
2152 $$ = check_scheme_arg (PARSER, @3,
2157 embedded_scm_chord_body:
2158 embedded_scm_bare_arg
2159 | SCM_FUNCTION music_function_chord_body_arglist {
2160 $$ = MAKE_SYNTAX ("music-function", @$,
2166 | chord_body_element
2169 music_function_chord_body:
2170 MUSIC_FUNCTION music_function_chord_body_arglist {
2171 $$ = MAKE_SYNTAX ("music-function", @$,
2176 // Event functions may only take closed arglists, otherwise it would
2177 // not be clear whether a following postevent should be associated
2178 // with the last argument of the event function or with the expression
2179 // for which the function call acts itself as event.
2181 music_function_event:
2182 MUSIC_FUNCTION function_arglist_closed {
2183 $$ = MAKE_SYNTAX ("music-function", @$,
2188 event_function_event:
2189 EVENT_FUNCTION function_arglist_closed {
2190 $$ = MAKE_SYNTAX ("music-function", @$,
2200 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2201 m->set_property ("span-direction", scm_from_int (START));
2202 $$ = m->unprotect();
2205 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2206 m->set_property ("span-direction", scm_from_int (STOP));
2207 $$ = m->unprotect ();
2210 $$ = MAKE_SYNTAX ("voice-separator", @$);
2213 SCM pipe = PARSER->lexer_->lookup_identifier ("pipeSymbol");
2215 Music *m = unsmob_music (pipe);
2220 $$ = m->unprotect ();
2223 $$ = MAKE_SYNTAX ("bar-check", @$);
2230 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2242 | post_events post_event {
2243 unsmob_music ($2)->set_spot (@2);
2244 $$ = scm_cons ($2, $$);
2248 post_event_nofinger:
2249 direction_less_event {
2252 | script_dir music_function_event {
2256 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2260 if (!PARSER->lexer_->is_lyric_state ())
2261 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2262 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2265 if (!PARSER->lexer_->is_lyric_state ())
2266 PARSER->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2267 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2269 | script_dir direction_reqd_event {
2272 Music *m = unsmob_music ($2);
2273 m->set_property ("direction", scm_from_int ($1));
2277 | script_dir direction_less_event {
2280 Music *m = unsmob_music ($2);
2281 m->set_property ("direction", scm_from_int ($1));
2285 | string_number_event
2289 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2294 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2305 string_number_event:
2307 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2308 s->set_property ("string-number", scm_from_int ($1));
2309 $$ = s->unprotect ();
2313 direction_less_char:
2315 $$ = ly_symbol2scm ("bracketOpenSymbol");
2318 $$ = ly_symbol2scm ("bracketCloseSymbol");
2321 $$ = ly_symbol2scm ("tildeSymbol");
2324 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2327 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2330 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2333 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2336 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2339 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2342 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2346 direction_less_event:
2347 direction_less_char {
2348 SCM predefd = PARSER->lexer_->lookup_identifier_symbol ($1);
2350 if (unsmob_music (predefd))
2352 m = unsmob_music (predefd)->clone ();
2357 m = MY_MAKE_MUSIC ("Music", @$);
2359 $$ = m->unprotect ();
2361 | EVENT_IDENTIFIER {
2365 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2366 a->set_property ("tremolo-type", scm_from_int ($1));
2367 $$ = a->unprotect ();
2369 | event_function_event
2372 direction_reqd_event:
2376 | script_abbreviation {
2377 SCM s = PARSER->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2378 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2379 if (scm_is_string (s))
2380 a->set_property ("articulation-type", s);
2381 else PARSER->parser_error (@1, _ ("expecting string as script definition"));
2382 $$ = a->unprotect ();
2387 /**/ { $$ = SCM_EOL; }
2388 | '=' { $$ = scm_from_int (0); }
2389 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2390 | '=' sup_quotes { $$ = scm_from_int ($2); }
2415 | NOTENAME_PITCH sup_quotes {
2416 Pitch p = *unsmob_pitch ($1);
2417 p = p.transposed (Pitch ($2,0,0));
2418 $$ = p.smobbed_copy ();
2420 | NOTENAME_PITCH sub_quotes {
2421 Pitch p =* unsmob_pitch ($1);
2422 p = p.transposed (Pitch (-$2,0,0));
2423 $$ = p.smobbed_copy ();
2435 | TONICNAME_PITCH sup_quotes {
2436 Pitch p = *unsmob_pitch ($1);
2437 p = p.transposed (Pitch ($2,0,0));
2438 $$ = p.smobbed_copy ();
2440 | TONICNAME_PITCH sub_quotes {
2441 Pitch p = *unsmob_pitch ($1);
2443 p = p.transposed (Pitch (-$2,0,0));
2444 $$ = p.smobbed_copy ();
2455 pitch_also_in_chords:
2462 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2463 t->set_property ("text", $1);
2464 $$ = t->unprotect ();
2467 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2468 t->set_property ("text",
2469 make_simple_markup ($1));
2470 $$ = t->unprotect ();
2476 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2477 t->set_property ("digit", $1);
2478 $$ = t->unprotect ();
2482 script_abbreviation:
2484 $$ = scm_from_locale_string ("Hat");
2487 $$ = scm_from_locale_string ("Plus");
2490 $$ = scm_from_locale_string ("Dash");
2493 $$ = scm_from_locale_string ("Bar");
2496 $$ = scm_from_locale_string ("Larger");
2499 $$ = scm_from_locale_string ("Dot");
2502 $$ = scm_from_locale_string ("Underscore");
2509 | '-' { $$ = CENTER; }
2513 multiplied_duration {
2518 optional_notemode_duration:
2520 Duration dd = PARSER->default_duration_;
2521 $$ = dd.smobbed_copy ();
2523 | multiplied_duration {
2525 PARSER->default_duration_ = *unsmob_duration ($$);
2530 bare_unsigned dots {
2532 if (!is_duration ($1))
2533 PARSER->parser_error (@1, _f ("not a duration: %d", $1));
2537 $$ = Duration (len, $2).smobbed_copy ();
2539 | DURATION_IDENTIFIER dots {
2540 Duration *d = unsmob_duration ($1);
2541 Duration k (d->duration_log (), d->dot_count () + $2);
2542 k = k.compressed (d->factor ());
2548 multiplied_duration:
2552 | multiplied_duration '*' bare_unsigned {
2553 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2555 | multiplied_duration '*' FRACTION {
2556 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2558 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2563 FRACTION { $$ = $1; }
2564 | UNSIGNED '/' UNSIGNED {
2565 $$ = scm_cons ($1, $3);
2582 | ':' bare_unsigned {
2583 if (!is_duration ($2))
2584 PARSER->parser_error (@2, _f ("not a duration: %d", $2));
2590 UNSIGNED { $$ = $1; }
2591 | STRING { $$ = $1; }
2592 | full_markup { $$ = $1; }
2595 figured_bass_alteration:
2596 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2597 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2598 | '!' { $$ = scm_from_int (0); }
2603 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2604 $$ = bfr->unprotect ();
2607 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2608 $$ = bfr->self_scm ();
2610 if (scm_is_number ($1))
2611 bfr->set_property ("figure", $1);
2612 else if (Text_interface::is_markup ($1))
2613 bfr->set_property ("text", $1);
2619 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2621 | bass_figure figured_bass_alteration {
2622 Music *m = unsmob_music ($1);
2623 if (scm_to_double ($2)) {
2624 SCM salter = m->get_property ("alteration");
2625 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2626 m->set_property ("alteration",
2627 scm_sum (alter, $2));
2629 m->set_property ("alteration", scm_from_int (0));
2632 | bass_figure figured_bass_modification {
2633 Music *m = unsmob_music ($1);
2634 if ($2 == ly_symbol2scm ("plus"))
2636 m->set_property ("augmented", SCM_BOOL_T);
2638 else if ($2 == ly_symbol2scm ("slash"))
2640 m->set_property ("diminished", SCM_BOOL_T);
2642 else if ($2 == ly_symbol2scm ("exclamation"))
2644 m->set_property ("no-continuation", SCM_BOOL_T);
2646 else if ($2 == ly_symbol2scm ("backslash"))
2648 m->set_property ("augmented-slash", SCM_BOOL_T);
2654 figured_bass_modification:
2656 $$ = ly_symbol2scm ("plus");
2659 $$ = ly_symbol2scm ("exclamation");
2662 $$ = ly_symbol2scm ("slash");
2665 $$ = ly_symbol2scm ("backslash");
2675 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2683 | figure_list br_bass_figure {
2684 $$ = scm_cons ($2, $1);
2689 FIGURE_OPEN figure_list FIGURE_CLOSE {
2690 $$ = scm_reverse_x ($2, SCM_EOL);
2701 pitch exclamations questions octave_check optional_notemode_duration optional_rest {
2702 if (!PARSER->lexer_->is_note_state ())
2703 PARSER->parser_error (@1, _ ("have to be in Note mode for notes"));
2707 n = MY_MAKE_MUSIC ("RestEvent", @$);
2709 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2711 n->set_property ("pitch", $1);
2712 n->set_property ("duration", $5);
2714 if (scm_is_number ($4))
2716 int q = scm_to_int ($4);
2717 n->set_property ("absolute-octave", scm_from_int (q-1));
2721 n->set_property ("cautionary", SCM_BOOL_T);
2722 if ($2 % 2 || $3 % 2)
2723 n->set_property ("force-accidental", SCM_BOOL_T);
2725 $$ = n->unprotect ();
2727 | DRUM_PITCH optional_notemode_duration {
2728 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2729 n->set_property ("duration", $2);
2730 n->set_property ("drum-type", $1);
2732 $$ = n->unprotect ();
2734 | RESTNAME optional_notemode_duration {
2736 if (ly_scm2string ($1) == "s") {
2738 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2741 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2744 ev->set_property ("duration", $2);
2745 $$ = ev->unprotect ();
2749 simple_chord_elements:
2751 $$ = scm_list_1 ($1);
2754 if (!PARSER->lexer_->is_chord_state ())
2755 PARSER->parser_error (@1, _ ("have to be in Chord mode for chords"));
2758 | figure_spec optional_notemode_duration {
2759 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2761 unsmob_music (scm_car (s))->set_property ("duration", $2);
2779 | lyric_element multiplied_duration post_events {
2780 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2781 $$ = MAKE_SYNTAX ("event-chord", @$,
2782 scm_cons (lyric_event,
2783 scm_reverse_x ($3, SCM_EOL)));
2785 | lyric_element post_event post_events {
2787 MAKE_SYNTAX ("lyric-event", @$, $1,
2788 PARSER->default_duration_.smobbed_copy ());
2789 $$ = MAKE_SYNTAX ("event-chord", @$,
2790 scm_cons2 (lyric_event, $2,
2791 scm_reverse_x ($3, SCM_EOL)));
2794 | LYRIC_ELEMENT optional_notemode_duration post_events {
2795 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2796 $$ = MAKE_SYNTAX ("event-chord", @$,
2797 scm_cons (lyric_event,
2798 scm_reverse_x ($3, SCM_EOL)));
2803 lyric_element_music:
2804 lyric_element optional_notemode_duration post_events {
2805 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2806 $$ = MAKE_SYNTAX ("event-chord", @$,
2807 scm_cons (lyric_event,
2808 scm_reverse_x ($3, SCM_EOL)));
2813 steno_tonic_pitch optional_notemode_duration {
2814 $$ = make_chord_elements ($1, $2, SCM_EOL);
2816 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2817 SCM its = scm_reverse_x ($4, SCM_EOL);
2818 $$ = make_chord_elements ($1, $2, scm_cons ($3, its));
2826 | chord_items chord_item {
2827 $$ = scm_cons ($2, $$);
2833 $$ = ly_symbol2scm ("chord-colon");
2836 $$ = ly_symbol2scm ("chord-caret");
2838 | CHORD_SLASH steno_tonic_pitch {
2839 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2841 | CHORD_BASS steno_tonic_pitch {
2842 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2851 $$ = scm_reverse_x ($1, SCM_EOL);
2859 step_number { $$ = scm_cons ($1, SCM_EOL); }
2860 | step_numbers '.' step_number {
2861 $$ = scm_cons ($3, $$);
2867 $$ = make_chord_step ($1, 0);
2869 | bare_unsigned '+' {
2870 $$ = make_chord_step ($1, SHARP_ALTERATION);
2872 | bare_unsigned CHORD_MINUS {
2873 $$ = make_chord_step ($1, FLAT_ALTERATION);
2879 $$ = scm_from_int ($1);
2881 | bare_unsigned '~' bare_unsigned {
2882 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2889 TODO: should deprecate in favor of Scheme?
2893 number_expression '+' number_term {
2894 $$ = scm_sum ($1, $3);
2896 | number_expression '-' number_term {
2897 $$ = scm_difference ($1, $3);
2906 | number_factor '*' number_factor {
2907 $$ = scm_product ($1, $3);
2909 | number_factor '/' number_factor {
2910 $$ = scm_divide ($1, $3);
2915 '-' number_factor { /* %prec UNARY_MINUS */
2916 $$ = scm_difference ($2, SCM_UNDEFINED);
2924 | UNSIGNED NUMBER_IDENTIFIER {
2925 $$ = scm_product ($1, $2)
2927 | REAL NUMBER_IDENTIFIER {
2928 $$ = scm_product ($1, $2)
2940 $$ = scm_to_int ($1);
2951 | exclamations '!' { $$ ++; }
2956 | questions '?' { $$ ++; }
2960 This should be done more dynamically if possible.
2964 LYRIC_MARKUP_IDENTIFIER {
2968 { PARSER->lexer_->push_markup_state (); }
2971 PARSER->lexer_->pop_state ();
2976 MARKUPLIST_IDENTIFIER {
2980 { PARSER->lexer_->push_markup_state (); }
2983 PARSER->lexer_->pop_state ();
2992 { PARSER->lexer_->push_markup_state (); }
2995 PARSER->lexer_->pop_state ();
3001 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3003 | markup_head_1_list simple_markup {
3004 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3014 if (Text_interface::is_markup ($1))
3015 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3016 else if (Text_interface::is_markup_list ($1))
3017 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3019 PARSER->parser_error (@1, _("markup expected"));
3020 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3027 MARKUPLIST_IDENTIFIER {
3030 | markup_composed_list {
3033 | markup_braced_list {
3036 | markup_command_list {
3037 $$ = scm_list_1 ($1);
3039 | markup_scm MARKUPLIST_IDENTIFIER
3045 markup_composed_list:
3046 markup_head_1_list markup_braced_list {
3047 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3053 '{' markup_braced_list_body '}' {
3054 $$ = scm_reverse_x ($2, SCM_EOL);
3058 markup_braced_list_body:
3059 /* empty */ { $$ = SCM_EOL; }
3060 | markup_braced_list_body markup {
3061 $$ = scm_cons ($2, $1);
3063 | markup_braced_list_body markup_list {
3064 $$ = scm_reverse_x ($2, $1);
3068 markup_command_list:
3069 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3070 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3074 markup_command_basic_arguments:
3075 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3076 $$ = scm_cons ($3, $2);
3078 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3079 $$ = check_scheme_arg (PARSER, @3, $3, $2, $1);
3081 | EXPECT_NO_MORE_ARGS {
3086 markup_command_list_arguments:
3087 markup_command_basic_arguments { $$ = $1; }
3088 | EXPECT_MARKUP markup_command_list_arguments markup {
3089 $$ = scm_cons ($3, $2);
3094 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3095 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3100 markup_head_1_item {
3101 $$ = scm_list_1 ($1);
3103 | markup_head_1_list markup_head_1_item {
3104 $$ = scm_cons ($2, $1);
3110 $$ = make_simple_markup ($1);
3112 | MARKUP_IDENTIFIER {
3115 | LYRIC_MARKUP_IDENTIFIER {
3118 | STRING_IDENTIFIER {
3122 SCM nn = PARSER->lexer_->lookup_identifier ("pitchnames");
3123 PARSER->lexer_->push_note_state (alist_to_hashq (nn));
3124 } '{' score_body '}' {
3126 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3128 PARSER->lexer_->pop_state ();
3130 | MARKUP_FUNCTION markup_command_basic_arguments {
3131 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3133 | markup_scm MARKUP_IDENTIFIER
3140 markup_head_1_list simple_markup {
3141 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3142 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3152 Lily_parser::set_yydebug (bool x)
3158 Lily_parser::do_yyparse ()
3160 yyparse ((void*)this);
3169 It is a little strange to have this function in this file, but
3170 otherwise, we have to import music classes into the lexer.
3174 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3176 if (scm_is_string (sid)) {
3178 return STRING_IDENTIFIER;
3179 } else if (unsmob_book (sid)) {
3180 Book *book = unsmob_book (sid)->clone ();
3181 *destination = book->self_scm ();
3184 return BOOK_IDENTIFIER;
3185 } else if (scm_is_number (sid)) {
3187 return NUMBER_IDENTIFIER;
3188 } else if (unsmob_context_def (sid)) {
3189 Context_def *def= unsmob_context_def (sid)->clone ();
3191 *destination = def->self_scm ();
3194 return CONTEXT_DEF_IDENTIFIER;
3195 } else if (unsmob_context_mod (sid)) {
3196 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3198 return CONTEXT_MOD_IDENTIFIER;
3199 } else if (unsmob_score (sid)) {
3200 Score *score = new Score (*unsmob_score (sid));
3201 *destination = score->self_scm ();
3203 score->unprotect ();
3204 return SCORE_IDENTIFIER;
3205 } else if (Music *mus = unsmob_music (sid)) {
3206 mus = mus->clone ();
3207 *destination = mus->self_scm ();
3208 unsmob_music (*destination)->
3209 set_property ("origin", make_input (last_input_));
3211 bool is_event = scm_memq (ly_symbol2scm ("event"), mus->get_property ("types"))
3215 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3216 } else if (unsmob_pitch (sid)) {
3217 *destination = unsmob_pitch (sid)->smobbed_copy ();
3218 return PITCH_IDENTIFIER;
3219 } else if (unsmob_duration (sid)) {
3220 *destination = unsmob_duration (sid)->smobbed_copy ();
3221 return DURATION_IDENTIFIER;
3222 } else if (unsmob_output_def (sid)) {
3223 Output_def *p = unsmob_output_def (sid);
3226 *destination = p->self_scm ();
3228 return OUTPUT_DEF_IDENTIFIER;
3229 } else if (Text_interface::is_markup (sid)) {
3231 if (is_lyric_state ())
3232 return LYRIC_MARKUP_IDENTIFIER;
3233 return MARKUP_IDENTIFIER;
3234 } else if (Text_interface::is_markup_list (sid)) {
3236 return MARKUPLIST_IDENTIFIER;
3243 get_next_unique_context_id ()
3245 return scm_from_locale_string ("$uniqueContextId");
3250 get_next_unique_lyrics_context_id ()
3252 static int new_context_count;
3254 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3255 return scm_from_locale_string (s);
3258 SCM check_scheme_arg (Lily_parser *my_lily_parser, Input loc,
3259 SCM arg, SCM args, SCM pred)
3261 args = scm_cons (arg, args);
3262 if (scm_is_true (scm_call_1 (pred, arg)))
3264 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3265 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3266 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3270 SCM loc_on_music (Input loc, SCM arg)
3272 if (Music *m = unsmob_music (arg))
3276 return m->unprotect ();
3282 is_regular_identifier (SCM id)
3284 string str = ly_scm2string (id);
3285 char const *s = str.c_str ();
3294 v = v && isalnum (*s);
3301 make_music_with_input (SCM name, Input where)
3303 Music *m = make_music_by_name (name);
3304 m->set_spot (where);
3309 get_first_context_id (SCM type, Music *m)
3311 SCM id = m->get_property ("context-id");
3312 if (SCM_BOOL_T == scm_equal_p (m->get_property ("context-type"), type)
3313 && scm_is_string (m->get_property ("context-id"))
3314 && scm_c_string_length (id) > 0)
3322 make_simple_markup (SCM a)
3330 return t && t == 1 << intlog2 (t);
3334 set_music_properties (Music *p, SCM a)
3336 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3337 p->set_property (scm_caar (k), scm_cdar (k));
3342 make_chord_step (int step, Rational alter)
3345 alter += FLAT_ALTERATION;
3349 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3350 return m.smobbed_copy ();
3355 make_chord_elements (SCM pitch, SCM dur, SCM modification_list)
3357 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3358 return scm_call_3 (chord_ctor, pitch, dur, modification_list);
3362 try_unpack_lyrics (SCM pred, SCM arg)
3364 if (Music *m = unsmob_music (arg))
3365 if (m->is_mus_type ("lyric-event")) {
3366 SCM text = m->get_property ("text");
3367 if (scm_is_true (scm_call_1 (pred, text)))
3370 return SCM_UNDEFINED;
3373 /* Todo: actually also use apply iso. call too ... */
3375 ly_input_procedure_p (SCM x)
3377 return ly_is_procedure (x)
3378 || (scm_is_pair (x) && ly_is_procedure (scm_car (x)));
3382 yylex (YYSTYPE *s, YYLTYPE *loc, void *v)
3384 Lily_parser *pars = (Lily_parser*) v;
3385 Lily_lexer *lex = pars->lexer_;
3387 lex->lexval_ = (void*) s;
3389 lex->prepare_for_next_token ();
3390 return lex->yylex ();