1 /* -*- mode: c++; c-file-style: "linux" -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
36 #define YYLLOC_DEFAULT(Current,Rhs,N) \
37 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
42 %parse-param {Lily_parser *parser}
43 %parse-param {SCM *retval}
44 %lex-param {Lily_parser *parser}
48 /* We use SCMs to do strings, because it saves us the trouble of
49 deleting them. Let's hope that a stack overflow doesn't trigger a move
50 of the parse stack onto the heap. */
56 /* The above precedences tackle the shift/reduce problem
59 \repeat .. \alternative
61 \repeat { \repeat .. \alternative }
65 \repeat { \repeat } \alternative
71 /* ADDLYRICS needs to have lower precedence than argument scanning,
72 * or we won't be able to tell music apart from closed_music without
73 * lookahead in the context of function calls.
78 /* \default is only applied after exhausting function arguments */
80 %nonassoc FUNCTION_ARGLIST
82 /* expressions with units are permitted into argument lists */
84 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
85 UNSIGNED REAL DURATION_IDENTIFIER ':'
87 /* The above are the symbols that can start optional function arguments
88 that are recognized in the grammar rather than by predicate
91 %nonassoc NUMBER_IDENTIFIER '/'
93 /* Number-unit expressions, where permitted, are concatenated into
94 * function arguments, just like fractions and tremoli. Tremoli must
95 * not have higher precedence than UNSIGNED, or Lilypond will not
96 * join ':' with a following optional number.
109 %{ // -*-Fundamental-*-
114 * The rules for who is protecting what are very shady. Uniformise
117 * There are too many lexical modes?
128 #include "context-def.hh"
129 #include "context-mod.hh"
130 #include "dimensions.hh"
131 #include "file-path.hh"
133 #include "international.hh"
134 #include "lily-guile.hh"
135 #include "lily-lexer.hh"
136 #include "lily-parser.hh"
140 #include "output-def.hh"
141 #include "paper-book.hh"
142 #include "scm-hash.hh"
144 #include "text-interface.hh"
148 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, string s)
150 parser->parser_error (*i, s);
153 #define MYBACKUP(Token, Value, Location) \
155 if (yychar == YYEMPTY) \
158 parser->lexer_->push_extra_token (Token, Value); \
159 parser->lexer_->push_extra_token (BACKUP); \
161 parser->parser_error \
162 (Location, _("Too much lookahead")); \
167 #define MYREPARSE(Location, Pred, Token, Value) \
169 if (yychar == YYEMPTY) \
171 parser->lexer_->push_extra_token (Token, Value); \
172 parser->lexer_->push_extra_token (REPARSE, \
175 parser->parser_error \
176 (Location, _("Too much lookahead")); \
185 Output_def *outputdef;
194 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
197 - Don't use lily module, create a new module instead.
198 - delay application of the function
200 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
201 scm_apply_0 (proc, args)
202 /* Syntactic Sugar. */
203 #define MAKE_SYNTAX(name, location, ...) \
204 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED))
205 #define START_MAKE_SYNTAX(name, ...) \
206 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
207 #define FINISH_MAKE_SYNTAX(start, location, ...) \
208 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)))))
210 SCM get_next_unique_context_id ();
211 SCM get_next_unique_lyrics_context_id ();
218 #define _(x) gettext (x)
222 static Music *make_music_with_input (SCM name, Input where);
223 SCM check_scheme_arg (Lily_parser *parser, Input loc,
224 SCM arg, SCM args, SCM pred);
225 SCM loc_on_music (Input loc, SCM arg);
226 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
227 SCM make_chord_step (int step, Rational alter);
228 SCM make_simple_markup (SCM a);
229 bool is_duration (int t);
230 bool is_regular_identifier (SCM id);
231 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
232 void set_music_properties (Music *p, SCM a);
236 /* The third option is an alias that will be used to display the
237 syntax error. Bison CVS now correctly handles backslash escapes.
239 FIXME: Bison needs to translate some of these, eg, STRING.
243 /* Keyword tokens with plain escaped name. */
244 %token END_OF_FILE 0 "end of input"
245 %token ACCEPTS "\\accepts"
246 %token ADDLYRICS "\\addlyrics"
247 %token ALIAS "\\alias"
248 %token ALTERNATIVE "\\alternative"
250 %token BOOKPART "\\bookpart"
251 %token CHANGE "\\change"
252 %token CHORDMODE "\\chordmode"
253 %token CHORDS "\\chords"
254 %token CONSISTS "\\consists"
255 %token CONTEXT "\\context"
256 %token DEFAULT "\\default"
257 %token DEFAULTCHILD "\\defaultchild"
258 %token DENIES "\\denies"
259 %token DESCRIPTION "\\description"
260 %token DRUMMODE "\\drummode"
261 %token DRUMS "\\drums"
262 %token FIGUREMODE "\\figuremode"
263 %token FIGURES "\\figures"
264 %token HEADER "\\header"
265 %token INVALID "\\version-error"
266 %token LAYOUT "\\layout"
267 %token LYRICMODE "\\lyricmode"
268 %token LYRICS "\\lyrics"
269 %token LYRICSTO "\\lyricsto"
270 %token MARKUP "\\markup"
271 %token MARKUPLIST "\\markuplist"
274 %token NOTEMODE "\\notemode"
275 %token OVERRIDE "\\override"
276 %token PAPER "\\paper"
277 %token REMOVE "\\remove"
278 %token REPEAT "\\repeat"
280 %token REVERT "\\revert"
281 %token SCORE "\\score"
282 %token SEQUENTIAL "\\sequential"
284 %token SIMULTANEOUS "\\simultaneous"
285 %token TEMPO "\\tempo"
287 %token UNSET "\\unset"
290 /* Keyword token exceptions. */
291 %token NEWCONTEXT "\\new"
294 /* Other string tokens. */
296 %token CHORD_BASS "/+"
297 %token CHORD_CARET "^"
298 %token CHORD_COLON ":"
299 %token CHORD_MINUS "-"
300 %token CHORD_SLASH "/"
301 %token ANGLE_OPEN "<"
302 %token ANGLE_CLOSE ">"
303 %token DOUBLE_ANGLE_OPEN "<<"
304 %token DOUBLE_ANGLE_CLOSE ">>"
305 %token E_BACKSLASH "\\"
306 %token E_ANGLE_CLOSE "\\>"
307 %token E_CHAR "\\C[haracter]"
309 %token E_EXCLAMATION "\\!"
310 %token E_BRACKET_OPEN "\\["
312 %token E_BRACKET_CLOSE "\\]"
313 %token E_ANGLE_OPEN "\\<"
319 If we give names, Bison complains.
321 %token FIGURE_CLOSE /* "\\>" */
322 %token FIGURE_OPEN /* "\\<" */
323 %token FIGURE_SPACE "_"
326 %token CHORDMODIFIERS
328 %token MULTI_MEASURE_REST
331 %token <i> E_UNSIGNED
332 %token <scm> UNSIGNED
334 /* Artificial tokens, for more generic function syntax */
335 %token <i> EXPECT_MARKUP "markup?"
336 %token <i> EXPECT_PITCH "ly:pitch?"
337 %token <i> EXPECT_DURATION "ly:duration?"
338 %token <scm> EXPECT_SCM "scheme?"
339 %token <scm> BACKUP "(backed-up?)"
340 %token <scm> REPARSE "(reparsed?)"
341 %token <i> EXPECT_MARKUP_LIST "markup-list?"
342 %token <scm> EXPECT_OPTIONAL "optional?"
343 /* After the last argument. */
344 %token <i> EXPECT_NO_MORE_ARGS;
346 /* An artificial token for parsing embedded Lilypond */
347 %token <i> EMBEDDED_LILY "#{"
349 %token <scm> BOOK_IDENTIFIER
350 %token <scm> CHORDMODIFIER_PITCH
351 %token <scm> CHORD_MODIFIER
352 %token <scm> CHORD_REPETITION
353 %token <scm> CONTEXT_DEF_IDENTIFIER
354 %token <scm> CONTEXT_MOD_IDENTIFIER
355 %token <scm> DRUM_PITCH
356 %token <scm> PITCH_IDENTIFIER
357 %token <scm> DURATION_IDENTIFIER
358 %token <scm> EVENT_IDENTIFIER
359 %token <scm> EVENT_FUNCTION
360 %token <scm> FRACTION
361 %token <scm> LYRICS_STRING
362 %token <scm> LYRIC_ELEMENT
363 %token <scm> LYRIC_MARKUP_IDENTIFIER
364 %token <scm> MARKUP_FUNCTION
365 %token <scm> MARKUP_LIST_FUNCTION
366 %token <scm> MARKUP_IDENTIFIER
367 %token <scm> MARKUPLIST_IDENTIFIER
368 %token <scm> MUSIC_FUNCTION
369 %token <scm> MUSIC_IDENTIFIER
370 %token <scm> NOTENAME_PITCH
371 %token <scm> NUMBER_IDENTIFIER
372 %token <scm> OUTPUT_DEF_IDENTIFIER
374 %token <scm> RESTNAME
375 %token <scm> SCM_FUNCTION
376 %token <scm> SCM_IDENTIFIER
377 %token <scm> SCM_TOKEN
378 %token <scm> SCORE_IDENTIFIER
380 %token <scm> STRING_IDENTIFIER
381 %token <scm> TONICNAME_PITCH
384 %type <book> book_block
385 %type <book> book_body
386 %type <book> bookpart_block
387 %type <book> bookpart_body
389 %type <i> bare_unsigned
390 %type <scm> figured_bass_alteration
392 %type <i> exclamations
393 %type <i> optional_rest
398 %type <i> tremolo_type
401 %type <scm> composite_music
402 %type <scm> grouped_music_list
403 %type <scm> braced_music_list
404 %type <scm> closed_music
406 %type <scm> music_bare
407 %type <scm> music_arg
408 %type <scm> music_assign
409 %type <scm> music_embedded
410 %type <scm> music_or_context_def
411 %type <scm> complex_music
412 %type <scm> complex_music_prefix
413 %type <scm> mode_changed_music
414 %type <scm> repeated_music
415 %type <scm> sequential_music
416 %type <scm> simple_music
417 %type <scm> simultaneous_music
418 %type <scm> chord_body
419 %type <scm> chord_body_element
420 %type <scm> command_element
421 %type <scm> command_event
422 %type <scm> context_modification
423 %type <scm> context_change
424 %type <scm> direction_less_event
425 %type <scm> direction_reqd_event
426 %type <scm> embedded_lilypond
427 %type <scm> event_chord
428 %type <scm> fingering
429 %type <scm> gen_text_def
430 %type <scm> music_property_def
431 %type <scm> note_chord_element
432 %type <scm> post_event
433 %type <scm> post_event_nofinger
434 %type <scm> re_rhythmed_music
435 %type <scm> simple_element
436 %type <scm> simple_music_property_def
437 %type <scm> start_symbol
438 %type <scm> string_number_event
439 %type <scm> tempo_event
441 %type <outputdef> output_def_body
442 %type <outputdef> output_def_head
443 %type <outputdef> output_def_head_with_mode_switch
444 %type <outputdef> output_def
445 %type <outputdef> paper_block
447 %type <scm> music_function_call
448 %type <scm> music_list
449 %type <scm> assignment_id
450 %type <scm> bare_number
451 %type <scm> bare_number_closed
452 %type <scm> unsigned_number
453 %type <scm> bass_figure
454 %type <scm> figured_bass_modification
455 %type <scm> br_bass_figure
456 %type <scm> bass_number
457 %type <scm> chord_body_elements
458 %type <scm> chord_item
459 %type <scm> chord_items
460 %type <scm> chord_separator
461 %type <scm> context_def_mod
462 %type <scm> context_def_spec_block
463 %type <scm> context_def_spec_body
464 %type <scm> context_mod
465 %type <scm> context_mod_arg
466 %type <scm> context_mod_embedded
467 %type <scm> context_mod_list
468 %type <scm> context_prop_spec
469 %type <scm> direction_less_char
470 %type <scm> duration_length
471 %type <scm> embedded_scm
472 %type <scm> embedded_scm_arg
473 %type <scm> embedded_scm_arg_closed
474 %type <scm> embedded_scm_bare
475 %type <scm> embedded_scm_bare_arg
476 %type <scm> embedded_scm_closed
477 %type <scm> event_function_event
478 %type <scm> figure_list
479 %type <scm> figure_spec
480 %type <scm> full_markup
481 %type <scm> full_markup_list
482 %type <scm> function_arglist
483 %type <scm> function_arglist_optional
484 %type <scm> function_arglist_backup
485 %type <scm> function_arglist_nonbackup
486 %type <scm> function_arglist_nonbackup_common
487 %type <scm> function_arglist_closed_nonbackup
488 %type <scm> function_arglist_skip
489 %type <scm> function_arglist_bare
490 %type <scm> function_arglist_closed
491 %type <scm> function_arglist_closed_optional
492 %type <scm> function_arglist_common
493 %type <scm> function_arglist_common_lyric
494 %type <scm> function_arglist_common_minus
495 %type <scm> function_arglist_closed_common
496 %type <scm> function_arglist_keep
497 %type <scm> function_arglist_closed_keep
498 %type <scm> identifier_init
500 %type <scm> lilypond_header
501 %type <scm> lyric_element
502 %type <scm> lyric_element_arg
503 %type <scm> lyric_element_music
504 %type <scm> lyric_markup
506 %type <scm> markup_braced_list
507 %type <scm> markup_braced_list_body
508 %type <scm> markup_composed_list
509 %type <scm> markup_command_list
510 %type <scm> markup_command_list_arguments
511 %type <scm> markup_command_basic_arguments
512 %type <scm> markup_head_1_item
513 %type <scm> markup_head_1_list
514 %type <scm> markup_list
515 %type <scm> markup_top
516 %type <scm> maybe_notemode_duration
517 %type <scm> mode_changing_head
518 %type <scm> mode_changing_head_with_context
519 %type <scm> multiplied_duration
520 %type <scm> music_function_event
521 %type <scm> music_function_chord_body
522 %type <scm> new_chord
523 %type <scm> new_lyrics
524 %type <scm> number_expression
525 %type <scm> number_factor
526 %type <scm> number_term
527 %type <scm> octave_check
528 %type <scm> optional_context_mod
529 %type <scm> optional_id
530 %type <scm> optional_notemode_duration
532 %type <scm> pitch_also_in_chords
533 %type <scm> post_events
534 %type <scm> property_operation
535 %type <scm> property_path property_path_revved
537 %type <scm> scalar_closed
538 %type <scm> scm_function_call
539 %type <scm> scm_function_call_closed
540 %type <scm> script_abbreviation
541 %type <scm> simple_chord_elements
542 %type <scm> simple_markup
543 %type <scm> simple_string
544 %type <scm> steno_duration
545 %type <scm> steno_pitch
546 %type <scm> steno_tonic_pitch
547 %type <scm> step_number
548 %type <scm> step_numbers
550 %type <scm> tempo_range
552 %type <score> score_block
553 %type <score> score_body
558 /* We don't assign precedence to / and *, because we might need varied
559 prec levels in different prods */
568 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
569 parser->lexer_->push_note_state (nn);
570 } embedded_lilypond {
571 parser->lexer_->pop_state ();
576 lilypond: /* empty */ { }
577 | lilypond toplevel_expression {
579 | lilypond assignment {
582 parser->error_level_ = 1;
585 parser->error_level_ = 1;
592 parser->lexer_->add_scope (get_header (parser));
594 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
598 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
599 scm_call_2 (proc, parser->self_scm (), book->self_scm ());
604 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
605 scm_call_2 (proc, parser->self_scm (), bookpart->self_scm ());
606 bookpart->unprotect ();
611 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
612 scm_call_2 (proc, parser->self_scm (), score->self_scm ());
616 Music *music = unsmob_music ($1);
617 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
618 scm_call_2 (proc, parser->self_scm (), music->self_scm ());
621 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
622 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
625 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
626 scm_call_2 (proc, parser->self_scm (), $1);
630 Output_def * od = $1;
632 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
633 id = ly_symbol2scm ("$defaultpaper");
634 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
635 id = ly_symbol2scm ("$defaultmidi");
636 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
637 id = ly_symbol2scm ("$defaultlayout");
639 parser->lexer_->set_identifier (id, od->self_scm ());
647 $$ = parser->lexer_->eval_scm_token ($1);
652 embedded_scm_bare_arg:
658 | context_modification
661 $$ = $1->self_scm ();
664 | context_def_spec_block
667 $$ = $1->self_scm ();
672 $$ = $1->self_scm ();
677 $$ = $1->self_scm ();
682 /* The generic version may end in music, or not */
690 embedded_scm_bare_arg
696 SCM_FUNCTION function_arglist {
697 $$ = MAKE_SYNTAX ("music-function", @$,
705 $$ = MAKE_SYNTAX ("void-music", @$);
708 | music_embedded music_embedded music_list {
709 $3 = scm_reverse_x ($3, SCM_EOL);
710 if (unsmob_music ($2))
711 $3 = scm_cons ($2, $3);
712 if (unsmob_music ($1))
713 $3 = scm_cons ($1, $3);
714 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
717 parser->error_level_ = 1;
719 | INVALID embedded_lilypond {
720 parser->error_level_ = 1;
725 lilypond_header_body:
727 | lilypond_header_body assignment {
733 HEADER '{' lilypond_header_body '}' {
734 $$ = parser->lexer_->remove_scope ();
743 | LYRICS_STRING { $$ = $1; }
747 assignment_id '=' identifier_init {
748 parser->lexer_->set_identifier ($1, $3);
750 | assignment_id property_path '=' identifier_init {
751 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
752 parser->lexer_->set_identifier (path, $4);
755 TODO: devise standard for protection in parser.
757 The parser stack lives on the C-stack, which means that
758 all objects can be unprotected as soon as they're here.
768 $$ = $1->self_scm ();
772 $$ = $1->self_scm ();
776 $$ = $1->self_scm ();
780 $$ = $1->self_scm ();
783 | context_def_spec_block {
789 | post_event_nofinger {
792 | number_expression {
810 | context_modification {
815 context_def_spec_block:
816 CONTEXT '{' context_def_spec_body '}'
827 context_mod_embedded:
830 if (unsmob_music ($1)) {
831 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
832 $1 = scm_call_2 (proc, parser->self_scm (), $1);
834 if (unsmob_context_mod ($1))
837 parser->parser_error (@1, _ ("not a context mod"));
843 context_def_spec_body:
845 $$ = Context_def::make_scm ();
846 unsmob_context_def ($$)->origin ()->set_spot (@$);
848 | CONTEXT_DEF_IDENTIFIER {
850 unsmob_context_def ($$)->origin ()->set_spot (@$);
852 | context_def_spec_body context_mod {
853 unsmob_context_def ($$)->add_context_mod ($2);
855 | context_def_spec_body context_modification {
856 Context_def *td = unsmob_context_def ($$);
857 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
858 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
859 td->add_context_mod (scm_car (m));
862 | context_def_spec_body context_mod_embedded {
863 Context_def *td = unsmob_context_def ($$);
864 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
865 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
866 td->add_context_mod (scm_car (m));
874 BOOK '{' book_body '}' {
877 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
882 * Use 'handlers' like for toplevel-* stuff?
883 * grok \layout and \midi? */
887 init_papers (parser);
888 $$->origin ()->set_spot (@$);
889 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
890 $$->paper_->unprotect ();
891 push_paper (parser, $$->paper_);
892 $$->header_ = get_header (parser);
893 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
896 $$ = unsmob_book ($1);
898 $$->origin ()->set_spot (@$);
899 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
901 | book_body paper_block {
904 set_paper (parser, $2);
906 | book_body bookpart_block {
908 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
909 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
910 bookpart->unprotect ();
912 | book_body score_block {
914 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
915 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
918 | book_body composite_music {
919 Music *music = unsmob_music ($2);
920 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
921 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
923 | book_body full_markup {
924 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
925 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
927 | book_body full_markup_list {
928 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
929 scm_call_2 (proc, $$->self_scm (), $2);
933 parser->lexer_->add_scope ($1->header_);
935 | book_body embedded_scm { }
938 $$->scores_ = SCM_EOL;
939 $$->bookparts_ = SCM_EOL;
944 BOOKPART '{' bookpart_body '}' {
946 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
953 $$->origin ()->set_spot (@$);
954 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
957 $$ = unsmob_book ($1);
959 $$->origin ()->set_spot (@$);
960 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
962 | bookpart_body paper_block {
966 | bookpart_body score_block {
968 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
969 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
972 | bookpart_body composite_music {
973 Music *music = unsmob_music ($2);
974 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
975 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
977 | bookpart_body full_markup {
978 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
979 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
981 | bookpart_body full_markup_list {
982 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
983 scm_call_2 (proc, $$->self_scm (), $2);
987 if (!ly_is_module ($1->header_))
988 $1->header_ = ly_make_module (false);
989 parser->lexer_->add_scope ($1->header_);
991 | bookpart_body embedded_scm { }
992 | bookpart_body error {
994 $$->scores_ = SCM_EOL;
999 SCORE '{' score_body '}' {
1007 SCM scorify = ly_lily_module_constant ("scorify-music");
1008 SCM score = scm_call_2 (scorify, m, parser->self_scm ());
1010 // pass ownernship to C++ again.
1011 $$ = unsmob_score (score);
1013 $$->origin ()->set_spot (@$);
1015 | SCORE_IDENTIFIER {
1016 $$ = unsmob_score ($1);
1018 $$->origin ()->set_spot (@$);
1022 if (!ly_is_module ($1->get_header ()))
1023 $1->set_header (ly_make_module (false));
1024 parser->lexer_->add_scope ($1->get_header ());
1026 | score_body output_def {
1027 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
1029 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1034 $$->add_output_def ($2);
1038 | score_body error {
1039 $$->error_found_ = true;
1051 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1053 parser->parser_error (@1, _ ("need \\paper for paper block"));
1055 $$ = get_paper (parser);
1062 output_def_body '}' {
1065 parser->lexer_->remove_scope ();
1066 parser->lexer_->pop_state ();
1072 $$ = get_paper (parser);
1073 $$->input_origin_ = @$;
1074 parser->lexer_->add_scope ($$->scope_);
1077 Output_def *p = get_midi (parser);
1079 parser->lexer_->add_scope (p->scope_);
1082 Output_def *p = get_layout (parser);
1084 parser->lexer_->add_scope (p->scope_);
1089 output_def_head_with_mode_switch:
1091 parser->lexer_->push_initial_state ();
1096 // We need this weird nonterminal because both music as well as a
1097 // context definition can start with \context and the difference is
1098 // only apparent after looking at the next token. If it is '{', there
1099 // is still time to escape from notes mode.
1101 music_or_context_def:
1104 parser->lexer_->pop_state ();
1108 parser->lexer_->pop_state ();
1109 } '{' context_def_spec_body '}'
1116 output_def_head_with_mode_switch '{' {
1118 $$->input_origin_.set_spot (@$);
1120 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1123 Output_def *o = unsmob_output_def ($3);
1124 o->input_origin_.set_spot (@$);
1127 parser->lexer_->remove_scope ();
1128 parser->lexer_->add_scope (o->scope_);
1130 | output_def_body assignment {
1135 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1136 parser->lexer_->push_note_state (nn);
1137 } music_or_context_def
1139 if (unsmob_context_def ($3))
1140 assign_context_def ($$, $3);
1143 SCM proc = parser->lexer_->lookup_identifier
1144 ("output-def-music-handler");
1145 scm_call_3 (proc, parser->self_scm (),
1146 $1->self_scm (), $3);
1149 | output_def_body error {
1155 TEMPO steno_duration '=' tempo_range {
1156 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1158 | TEMPO scalar_closed steno_duration '=' tempo_range {
1159 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1162 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1167 The representation of a list is reversed to have efficient append. */
1173 | music_list music_embedded {
1174 if (unsmob_music ($2))
1175 $$ = scm_cons ($2, $1);
1177 | music_list error {
1178 Music *m = MY_MAKE_MUSIC("Music", @$);
1180 m->set_property ("error-found", SCM_BOOL_T);
1181 $$ = scm_cons (m->self_scm (), $1);
1182 m->unprotect (); /* UGH */
1189 $$ = scm_reverse_x ($2, SCM_EOL);
1194 | lyric_element_music
1201 if (unsmob_music ($1)
1202 || scm_is_eq ($1, SCM_UNSPECIFIED))
1206 @$.warning (_ ("Ignoring non-music expression"));
1207 $$ = SCM_UNSPECIFIED;
1215 if (unsmob_pitch ($1)) {
1216 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1217 n->set_property ("pitch", $1);
1218 n->set_property ("duration",
1219 parser->default_duration_.smobbed_copy ());
1220 $$ = n->unprotect ();
1223 | composite_music %prec COMPOSITE
1228 | composite_music %prec COMPOSITE
1229 | lyric_element_music
1233 REPEAT simple_string unsigned_number music
1235 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1237 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1239 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1244 SEQUENTIAL braced_music_list {
1245 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1247 | braced_music_list {
1248 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1253 SIMULTANEOUS braced_music_list {
1254 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1256 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1257 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1263 | music_property_def
1267 context_modification:
1268 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1270 parser->lexer_->pop_state ();
1273 | WITH CONTEXT_MOD_IDENTIFIER
1277 | CONTEXT_MOD_IDENTIFIER
1281 | WITH embedded_scm_closed
1283 if (unsmob_context_mod ($2))
1286 parser->parser_error (@2, _ ("not a context mod"));
1287 $$ = Context_mod ().smobbed_copy ();
1292 optional_context_mod:
1296 | context_modification
1304 $$ = Context_mod ().smobbed_copy ();
1306 | context_mod_list context_mod {
1307 unsmob_context_mod ($1)->add_context_mod ($2);
1309 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1310 Context_mod *md = unsmob_context_mod ($2);
1312 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1314 | context_mod_list context_mod_embedded {
1315 unsmob_context_mod ($1)->add_context_mods
1316 (unsmob_context_mod ($2)->get_mods ());
1325 /* Music that can be parsed without lookahead */
1328 | complex_music_prefix closed_music
1330 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1337 | grouped_music_list
1341 simultaneous_music { $$ = $1; }
1342 | sequential_music { $$ = $1; }
1345 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1346 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1347 and this rule returns the reversed list of arguments. */
1349 function_arglist_skip:
1350 function_arglist_common
1351 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1353 $$ = scm_cons ($1, $3);
1354 } %prec FUNCTION_ARGLIST
1355 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1357 $$ = scm_cons ($1, $3);
1358 } %prec FUNCTION_ARGLIST
1359 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1361 $$ = scm_cons ($1, $3);
1362 } %prec FUNCTION_ARGLIST
1366 function_arglist_nonbackup_common:
1367 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1368 $$ = scm_cons ($4, $3);
1370 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1371 $$ = scm_cons ($4, $3);
1373 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1375 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1377 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1379 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1381 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1383 SCM n = scm_difference ($5, SCM_UNDEFINED);
1384 if (scm_is_true (scm_call_1 ($2, n)))
1385 $$ = scm_cons (n, $3);
1387 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1388 t->set_property ("digit", $5);
1389 $$ = t->unprotect ();
1390 if (scm_is_true (scm_call_1 ($2, $$)))
1391 $$ = scm_cons ($$, $3);
1393 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1397 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1399 $$ = check_scheme_arg (parser, @4,
1400 scm_difference ($5, SCM_UNDEFINED),
1403 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1405 $$ = check_scheme_arg (parser, @4,
1406 scm_difference ($5, SCM_UNDEFINED),
1411 function_arglist_closed_nonbackup:
1412 function_arglist_nonbackup_common
1413 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1415 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1417 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1419 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1423 function_arglist_nonbackup:
1424 function_arglist_nonbackup_common
1425 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1427 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1429 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1431 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1435 function_arglist_keep:
1436 function_arglist_common
1437 | function_arglist_backup
1440 function_arglist_closed_keep:
1441 function_arglist_closed_common
1442 | function_arglist_backup
1445 function_arglist_backup:
1446 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1448 if (scm_is_true (scm_call_1 ($2, $4)))
1450 $$ = scm_cons ($4, $3);
1452 $$ = scm_cons (loc_on_music (@3, $1), $3);
1453 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1456 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1458 if (scm_is_true (scm_call_1 ($2, $4)))
1460 $$ = scm_cons ($4, $3);
1462 $$ = scm_cons (loc_on_music (@3, $1), $3);
1463 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1466 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1468 // There is no point interpreting a lyrics string as
1469 // an event, since we don't allow music possibly
1470 // followed by durations or postevent into closed
1471 // music, and we only accept closed music in optional
1472 // arguments at the moment. If this changes, more
1473 // complex schemes might become interesting here as
1474 // well: see how we do this at the mandatory argument
1476 if (scm_is_true (scm_call_1 ($2, $4)))
1477 $$ = scm_cons ($4, $3);
1479 $$ = scm_cons (loc_on_music (@3, $1), $3);
1480 MYBACKUP (LYRICS_STRING, $4, @4);
1483 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1485 if (scm_is_true (scm_call_1 ($2, $4)))
1488 MYREPARSE (@4, $2, UNSIGNED, $4);
1490 $$ = scm_cons (loc_on_music (@3, $1), $3);
1491 MYBACKUP (UNSIGNED, $4, @4);
1494 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1496 if (scm_is_true (scm_call_1 ($2, $4)))
1499 MYREPARSE (@4, $2, REAL, $4);
1501 $$ = scm_cons (loc_on_music (@3, $1), $3);
1502 MYBACKUP (REAL, $4, @4);
1505 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1507 if (scm_is_true (scm_call_1 ($2, $4)))
1509 $$ = scm_cons ($4, $3);
1511 $$ = scm_cons (loc_on_music (@3, $1), $3);
1512 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1515 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1517 if (scm_is_true (scm_call_1 ($2, $4)))
1519 $$ = scm_cons ($4, $3);
1521 $$ = scm_cons (loc_on_music (@3, $1), $3);
1522 MYBACKUP (FRACTION, $4, @4);
1525 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1527 SCM n = scm_difference ($5, SCM_UNDEFINED);
1528 if (scm_is_true (scm_call_1 ($2, n))) {
1530 MYREPARSE (@5, $2, REAL, n);
1532 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1533 t->set_property ("digit", $5);
1534 $$ = t->unprotect ();
1535 if (scm_is_true (scm_call_1 ($2, $$)))
1536 $$ = scm_cons ($$, $3);
1538 $$ = scm_cons (loc_on_music (@3, $1), $3);
1539 MYBACKUP (UNSIGNED, $5, @5);
1540 parser->lexer_->push_extra_token ('-');
1545 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1547 SCM n = scm_difference ($5, SCM_UNDEFINED);
1548 if (scm_is_true (scm_call_1 ($2, n))) {
1549 MYREPARSE (@5, $2, REAL, n);
1552 MYBACKUP (REAL, n, @5);
1555 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1557 SCM n = scm_difference ($5, SCM_UNDEFINED);
1558 if (scm_is_true (scm_call_1 ($2, n))) {
1559 $$ = scm_cons (n, $3);
1561 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1564 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1566 $$ = scm_cons ($4, $3);
1568 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1570 $$ = scm_cons ($4, $3);
1572 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1574 $$ = scm_cons ($1, $3);
1575 MYBACKUP(0, SCM_UNDEFINED, @3);
1577 | function_arglist_backup REPARSE embedded_scm_arg_closed
1579 $$ = check_scheme_arg (parser, @3,
1582 | function_arglist_backup REPARSE bare_number
1584 $$ = check_scheme_arg (parser, @3,
1590 function_arglist_common
1591 | function_arglist_nonbackup
1594 function_arglist_common:
1595 function_arglist_bare
1596 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1598 $$ = check_scheme_arg (parser, @3,
1601 | EXPECT_SCM function_arglist_closed_optional bare_number
1603 $$ = check_scheme_arg (parser, @3,
1606 | EXPECT_SCM function_arglist_closed_optional FRACTION
1608 $$ = check_scheme_arg (parser, @3,
1611 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1613 $$ = check_scheme_arg (parser, @3,
1616 | function_arglist_common_minus
1617 | function_arglist_common_lyric
1620 function_arglist_common_lyric:
1621 EXPECT_SCM function_arglist_optional lyric_element
1623 // We check how the predicate thinks about a lyrics
1624 // event or about a markup. If it accepts neither, we
1625 // backup the original token. Otherwise we commit to
1626 // taking the token. Depending on what the predicate
1627 // is willing to accept, we interpret as a string, as
1628 // a lyric event, or ambiguously (meaning that if
1629 // something looking like a duration or post event
1630 // follows, we take the event, otherwise the string).
1631 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1632 parser->default_duration_.smobbed_copy ());
1633 if (scm_is_true (scm_call_1 ($1, $3)))
1634 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1637 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1639 $$ = scm_cons ($3, $2);
1641 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1644 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1646 // This is going to flag a syntax error, we
1647 // know the predicate to be false.
1648 check_scheme_arg (parser, @3,
1652 | function_arglist_common_lyric REPARSE lyric_element_arg
1654 // This should never be false
1655 $$ = check_scheme_arg (parser, @3,
1660 function_arglist_common_minus:
1661 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1663 SCM n = scm_difference ($4, SCM_UNDEFINED);
1664 if (scm_is_true (scm_call_1 ($1, n))) {
1666 MYREPARSE (@4, $1, REAL, n);
1668 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1669 t->set_property ("digit", $4);
1670 $$ = t->unprotect ();
1671 if (scm_is_true (scm_call_1 ($1, $$)))
1672 $$ = scm_cons ($$, $2);
1674 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1678 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1681 SCM n = scm_difference ($4, SCM_UNDEFINED);
1682 MYREPARSE (@4, $1, REAL, n);
1684 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1686 SCM n = scm_difference ($4, SCM_UNDEFINED);
1687 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1689 | function_arglist_common_minus REPARSE bare_number
1691 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1695 function_arglist_closed:
1696 function_arglist_closed_common
1697 | function_arglist_closed_nonbackup
1700 function_arglist_closed_common:
1701 function_arglist_bare
1702 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1704 $$ = check_scheme_arg (parser, @3,
1707 | EXPECT_SCM function_arglist_closed_optional bare_number
1709 $$ = check_scheme_arg (parser, @3,
1712 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1714 SCM n = scm_difference ($4, SCM_UNDEFINED);
1715 if (scm_is_true (scm_call_1 ($1, n))) {
1716 $$ = scm_cons (n, $2);
1718 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1719 t->set_property ("digit", $4);
1720 $$ = t->unprotect ();
1721 if (scm_is_true (scm_call_1 ($1, $$)))
1722 $$ = scm_cons ($$, $2);
1724 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1728 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1730 $$ = check_scheme_arg (parser, @3,
1731 scm_difference ($4, SCM_UNDEFINED),
1734 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1736 $$ = check_scheme_arg (parser, @3,
1737 scm_difference ($4, SCM_UNDEFINED),
1740 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1742 $$ = check_scheme_arg (parser, @3,
1745 | EXPECT_SCM function_arglist_closed_optional FRACTION
1747 $$ = check_scheme_arg (parser, @3,
1750 | EXPECT_SCM function_arglist_optional lyric_element
1752 $$ = check_scheme_arg (parser, @3,
1757 function_arglist_optional:
1758 function_arglist_keep %prec FUNCTION_ARGLIST
1759 | function_arglist_backup BACKUP
1760 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1762 $$ = scm_cons ($1, $3);
1764 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1766 $$ = scm_cons ($1, $3);
1770 function_arglist_closed_optional:
1771 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1772 | function_arglist_backup BACKUP
1773 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1775 $$ = scm_cons ($1, $3);
1777 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1779 $$ = scm_cons ($1, $3);
1783 embedded_scm_closed:
1785 | scm_function_call_closed
1788 embedded_scm_arg_closed:
1789 embedded_scm_bare_arg
1790 | scm_function_call_closed
1794 scm_function_call_closed:
1795 SCM_FUNCTION function_arglist_closed {
1796 $$ = MAKE_SYNTAX ("music-function", @$,
1798 } %prec FUNCTION_ARGLIST
1801 function_arglist_bare:
1802 EXPECT_NO_MORE_ARGS {
1805 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1806 $$ = scm_cons ($3, $2);
1808 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1809 $$ = scm_cons ($3, $2);
1811 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1812 $$ = scm_cons ($1, $3);
1814 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1815 $$ = scm_cons ($1, $3);
1817 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1818 $$ = scm_cons ($1, $3);
1822 music_function_call:
1823 MUSIC_FUNCTION function_arglist {
1824 $$ = MAKE_SYNTAX ("music-function", @$,
1831 /**/ { $$ = SCM_EOL; }
1832 | '=' simple_string {
1839 | repeated_music { $$ = $1; }
1840 | re_rhythmed_music { $$ = $1; }
1841 | complex_music_prefix music
1843 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1847 complex_music_prefix:
1848 CONTEXT simple_string optional_id optional_context_mod {
1849 Context_mod *ctxmod = unsmob_context_mod ($4);
1852 mods = ctxmod->get_mods ();
1853 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1855 | NEWCONTEXT simple_string optional_id optional_context_mod {
1856 Context_mod *ctxmod = unsmob_context_mod ($4);
1859 mods = ctxmod->get_mods ();
1860 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1865 mode_changing_head grouped_music_list {
1866 if ($1 == ly_symbol2scm ("chords"))
1868 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1874 parser->lexer_->pop_state ();
1876 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1877 Context_mod *ctxmod = unsmob_context_mod ($2);
1880 mods = ctxmod->get_mods ();
1881 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1882 if ($1 == ly_symbol2scm ("ChordNames"))
1884 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1886 parser->lexer_->pop_state ();
1892 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1893 parser->lexer_->push_note_state (nn);
1895 $$ = ly_symbol2scm ("notes");
1899 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1900 parser->lexer_->push_note_state (nn);
1902 $$ = ly_symbol2scm ("drums");
1905 parser->lexer_->push_figuredbass_state ();
1907 $$ = ly_symbol2scm ("figures");
1910 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1911 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1912 nn = parser->lexer_->lookup_identifier ("pitchnames");
1913 parser->lexer_->push_chord_state (nn);
1914 $$ = ly_symbol2scm ("chords");
1918 { parser->lexer_->push_lyric_state ();
1919 $$ = ly_symbol2scm ("lyrics");
1923 mode_changing_head_with_context:
1925 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1926 parser->lexer_->push_note_state (nn);
1928 $$ = ly_symbol2scm ("DrumStaff");
1931 parser->lexer_->push_figuredbass_state ();
1933 $$ = ly_symbol2scm ("FiguredBass");
1936 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1937 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1938 nn = parser->lexer_->lookup_identifier ("pitchnames");
1939 parser->lexer_->push_chord_state (nn);
1940 $$ = ly_symbol2scm ("ChordNames");
1943 { parser->lexer_->push_lyric_state ();
1944 $$ = ly_symbol2scm ("Lyrics");
1949 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1952 /* Can also use music at the expensive of two S/Rs similar to
1953 \repeat \alternative */
1954 parser->lexer_->pop_state ();
1956 $$ = scm_cons ($3, SCM_EOL);
1958 | new_lyrics ADDLYRICS {
1959 parser->lexer_->push_lyric_state ();
1961 parser->lexer_->pop_state ();
1962 $$ = scm_cons ($4, $1);
1967 composite_music new_lyrics {
1968 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1970 | LYRICSTO simple_string {
1971 parser->lexer_->push_lyric_state ();
1973 parser->lexer_->pop_state ();
1974 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1979 CHANGE STRING '=' STRING {
1980 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1985 property_path_revved:
1986 embedded_scm_closed {
1987 $$ = scm_cons ($1, SCM_EOL);
1989 | property_path_revved embedded_scm_closed {
1990 $$ = scm_cons ($2, $1);
1995 property_path_revved {
1996 $$ = scm_reverse_x ($1, SCM_EOL);
2002 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2003 scm_string_to_symbol ($1), $3);
2005 | UNSET simple_string {
2006 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2007 scm_string_to_symbol ($2));
2009 | OVERRIDE simple_string property_path '=' scalar {
2010 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
2011 scm_string_to_symbol ($2), $5),
2014 | REVERT simple_string embedded_scm {
2015 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2016 scm_string_to_symbol ($2), $3);
2021 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2022 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2024 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2025 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2026 | DENIES { $$ = ly_symbol2scm ("denies"); }
2028 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2029 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2030 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2031 | NAME { $$ = ly_symbol2scm ("context-name"); }
2035 property_operation { $$ = $1; }
2036 | context_def_mod STRING {
2037 $$ = scm_list_2 ($1, $2);
2039 | context_def_mod embedded_scm
2041 if (!scm_is_string ($2)
2042 && ly_symbol2scm ("consists") != $1
2043 && ly_symbol2scm ("remove") != $1)
2046 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2050 $$ = scm_list_2 ($1, $2);
2057 if (!is_regular_identifier ($1))
2059 @$.error (_("Grob name should be alphanumeric"));
2062 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
2063 scm_string_to_symbol ($1));
2065 | simple_string '.' simple_string {
2066 $$ = scm_list_2 (scm_string_to_symbol ($1),
2067 scm_string_to_symbol ($3));
2071 simple_music_property_def:
2072 OVERRIDE context_prop_spec property_path '=' scalar {
2073 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
2074 ly_symbol2scm ("OverrideProperty"),
2079 | REVERT context_prop_spec embedded_scm {
2080 $$ = scm_list_4 (scm_car ($2),
2081 ly_symbol2scm ("RevertProperty"),
2085 | SET context_prop_spec '=' scalar {
2086 $$ = scm_list_4 (scm_car ($2),
2087 ly_symbol2scm ("PropertySet"),
2091 | UNSET context_prop_spec {
2092 $$ = scm_list_3 (scm_car ($2),
2093 ly_symbol2scm ("PropertyUnset"),
2099 simple_music_property_def {
2100 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2108 | STRING_IDENTIFIER {
2111 | string '+' string {
2112 $$ = scm_string_append (scm_list_2 ($1, $3));
2116 simple_string: STRING {
2122 | STRING_IDENTIFIER {
2135 embedded_scm_arg_closed
2143 simple_element post_events {
2144 // Let the rhythmic music iterator sort this mess out.
2145 if (scm_is_pair ($2)) {
2146 if (unsmob_pitch ($1)) {
2147 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
2148 n->set_property ("pitch", $1);
2149 n->set_property ("duration",
2150 parser->default_duration_.smobbed_copy ());
2151 $$ = n->unprotect ();
2153 unsmob_music ($$)->set_property ("articulations",
2154 scm_reverse_x ($2, SCM_EOL));
2157 | simple_chord_elements post_events {
2158 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2161 /* why is this giving wrong start location? -ns
2163 i.set_location (@1, @2);
2164 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2166 | CHORD_REPETITION optional_notemode_duration post_events {
2168 i.set_location (@1, @3);
2169 $$ = MAKE_SYNTAX ("repetition-chord", i,
2170 $2, scm_reverse_x ($3, SCM_EOL));
2172 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2174 i.set_location (@1, @3);
2175 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2176 scm_reverse_x ($3, SCM_EOL));
2179 | note_chord_element
2184 chord_body optional_notemode_duration post_events
2186 Music *m = unsmob_music ($1);
2187 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2188 SCM es = m->get_property ("elements");
2189 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2191 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2192 unsmob_music (scm_car (s))->set_property ("duration", dur);
2193 es = ly_append2 (es, postevs);
2195 m-> set_property ("elements", es);
2197 $$ = m->self_scm ();
2202 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2204 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2208 chord_body_elements:
2209 /* empty */ { $$ = SCM_EOL; }
2210 | chord_body_elements chord_body_element {
2211 if (!SCM_UNBNDP ($2))
2212 $$ = scm_cons ($2, $1);
2217 pitch exclamations questions octave_check post_events
2224 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2225 n->set_property ("pitch", $1);
2227 n->set_property ("cautionary", SCM_BOOL_T);
2228 if (ex % 2 || q % 2)
2229 n->set_property ("force-accidental", SCM_BOOL_T);
2231 if (scm_is_pair (post)) {
2232 SCM arts = scm_reverse_x (post, SCM_EOL);
2233 n->set_property ("articulations", arts);
2235 if (scm_is_number (check))
2237 int q = scm_to_int (check);
2238 n->set_property ("absolute-octave", scm_from_int (q-1));
2241 $$ = n->unprotect ();
2243 | DRUM_PITCH post_events {
2244 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2245 n->set_property ("drum-type", $1);
2247 if (scm_is_pair ($2)) {
2248 SCM arts = scm_reverse_x ($2, SCM_EOL);
2249 n->set_property ("articulations", arts);
2251 $$ = n->unprotect ();
2253 | music_function_chord_body
2255 Music *m = unsmob_music ($1);
2257 while (m && m->is_mus_type ("music-wrapper-music")) {
2258 $$ = m->get_property ("element");
2259 m = unsmob_music ($$);
2262 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2263 parser->parser_error (@$, _ ("not a rhythmic event"));
2269 music_function_chord_body:
2274 // Event functions may only take closed arglists, otherwise it would
2275 // not be clear whether a following postevent should be associated
2276 // with the last argument of the event function or with the expression
2277 // for which the function call acts itself as event.
2279 music_function_event:
2280 MUSIC_FUNCTION function_arglist_closed {
2281 $$ = MAKE_SYNTAX ("music-function", @$,
2286 event_function_event:
2287 EVENT_FUNCTION function_arglist_closed {
2288 $$ = MAKE_SYNTAX ("music-function", @$,
2298 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2299 m->set_property ("span-direction", scm_from_int (START));
2300 $$ = m->unprotect();
2303 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2304 m->set_property ("span-direction", scm_from_int (STOP));
2305 $$ = m->unprotect ();
2308 $$ = MAKE_SYNTAX ("voice-separator", @$);
2311 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2313 Music *m = unsmob_music (pipe);
2318 $$ = m->unprotect ();
2321 $$ = MAKE_SYNTAX ("bar-check", @$);
2328 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2340 | post_events post_event {
2341 unsmob_music ($2)->set_spot (@2);
2342 $$ = scm_cons ($2, $$);
2346 post_event_nofinger:
2347 direction_less_event {
2350 | script_dir music_function_event {
2354 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2358 if (!parser->lexer_->is_lyric_state ())
2359 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2360 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2363 if (!parser->lexer_->is_lyric_state ())
2364 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2365 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2367 | script_dir direction_reqd_event {
2370 Music *m = unsmob_music ($2);
2371 m->set_property ("direction", scm_from_int ($1));
2375 | script_dir direction_less_event {
2378 Music *m = unsmob_music ($2);
2379 m->set_property ("direction", scm_from_int ($1));
2386 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2391 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2402 string_number_event:
2404 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2405 s->set_property ("string-number", scm_from_int ($1));
2406 $$ = s->unprotect ();
2410 direction_less_char:
2412 $$ = ly_symbol2scm ("bracketOpenSymbol");
2415 $$ = ly_symbol2scm ("bracketCloseSymbol");
2418 $$ = ly_symbol2scm ("tildeSymbol");
2421 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2424 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2427 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2430 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2433 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2436 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2439 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2443 direction_less_event:
2444 direction_less_char {
2445 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2447 if (unsmob_music (predefd))
2449 m = unsmob_music (predefd)->clone ();
2454 m = MY_MAKE_MUSIC ("Music", @$);
2456 $$ = m->unprotect ();
2458 | string_number_event
2459 | EVENT_IDENTIFIER {
2463 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2464 a->set_property ("tremolo-type", scm_from_int ($1));
2465 $$ = a->unprotect ();
2467 | event_function_event
2470 direction_reqd_event:
2474 | script_abbreviation {
2475 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2476 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2477 if (scm_is_string (s))
2478 a->set_property ("articulation-type", s);
2479 else parser->parser_error (@1, _ ("expecting string as script definition"));
2480 $$ = a->unprotect ();
2485 /**/ { $$ = SCM_EOL; }
2486 | '=' { $$ = scm_from_int (0); }
2487 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2488 | '=' sup_quotes { $$ = scm_from_int ($2); }
2513 | NOTENAME_PITCH sup_quotes {
2514 Pitch p = *unsmob_pitch ($1);
2515 p = p.transposed (Pitch ($2,0,0));
2516 $$ = p.smobbed_copy ();
2518 | NOTENAME_PITCH sub_quotes {
2519 Pitch p =* unsmob_pitch ($1);
2520 p = p.transposed (Pitch (-$2,0,0));
2521 $$ = p.smobbed_copy ();
2533 | TONICNAME_PITCH sup_quotes {
2534 Pitch p = *unsmob_pitch ($1);
2535 p = p.transposed (Pitch ($2,0,0));
2536 $$ = p.smobbed_copy ();
2538 | TONICNAME_PITCH sub_quotes {
2539 Pitch p = *unsmob_pitch ($1);
2541 p = p.transposed (Pitch (-$2,0,0));
2542 $$ = p.smobbed_copy ();
2553 pitch_also_in_chords:
2560 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2561 t->set_property ("text", $1);
2562 $$ = t->unprotect ();
2565 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2566 t->set_property ("text",
2567 make_simple_markup ($1));
2568 $$ = t->unprotect ();
2574 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2575 t->set_property ("digit", $1);
2576 $$ = t->unprotect ();
2580 script_abbreviation:
2582 $$ = scm_from_locale_string ("Hat");
2585 $$ = scm_from_locale_string ("Plus");
2588 $$ = scm_from_locale_string ("Dash");
2591 $$ = scm_from_locale_string ("Bar");
2594 $$ = scm_from_locale_string ("Larger");
2597 $$ = scm_from_locale_string ("Dot");
2600 $$ = scm_from_locale_string ("Underscore");
2607 | '-' { $$ = CENTER; }
2611 multiplied_duration {
2616 maybe_notemode_duration:
2620 | multiplied_duration {
2622 parser->default_duration_ = *unsmob_duration ($$);
2627 optional_notemode_duration:
2628 maybe_notemode_duration
2630 if (SCM_UNBNDP ($$))
2631 $$ = parser->default_duration_.smobbed_copy ();
2636 bare_unsigned dots {
2638 if (!is_duration ($1))
2639 parser->parser_error (@1, _f ("not a duration: %d", $1));
2643 $$ = Duration (len, $2).smobbed_copy ();
2645 | DURATION_IDENTIFIER dots {
2646 Duration *d = unsmob_duration ($1);
2647 Duration k (d->duration_log (), d->dot_count () + $2);
2648 k = k.compressed (d->factor ());
2654 multiplied_duration:
2658 | multiplied_duration '*' bare_unsigned {
2659 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2661 | multiplied_duration '*' FRACTION {
2662 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2664 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2681 | ':' bare_unsigned {
2682 if (!is_duration ($2))
2683 parser->parser_error (@2, _f ("not a duration: %d", $2));
2689 UNSIGNED { $$ = $1; }
2690 | STRING { $$ = $1; }
2691 | full_markup { $$ = $1; }
2694 figured_bass_alteration:
2695 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2696 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2697 | '!' { $$ = scm_from_int (0); }
2702 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2703 $$ = bfr->unprotect ();
2706 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2707 $$ = bfr->self_scm ();
2709 if (scm_is_number ($1))
2710 bfr->set_property ("figure", $1);
2711 else if (Text_interface::is_markup ($1))
2712 bfr->set_property ("text", $1);
2718 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2720 | bass_figure figured_bass_alteration {
2721 Music *m = unsmob_music ($1);
2722 if (scm_to_double ($2)) {
2723 SCM salter = m->get_property ("alteration");
2724 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2725 m->set_property ("alteration",
2726 scm_sum (alter, $2));
2728 m->set_property ("alteration", scm_from_int (0));
2731 | bass_figure figured_bass_modification {
2732 Music *m = unsmob_music ($1);
2733 if ($2 == ly_symbol2scm ("plus"))
2735 m->set_property ("augmented", SCM_BOOL_T);
2737 else if ($2 == ly_symbol2scm ("slash"))
2739 m->set_property ("diminished", SCM_BOOL_T);
2741 else if ($2 == ly_symbol2scm ("exclamation"))
2743 m->set_property ("no-continuation", SCM_BOOL_T);
2745 else if ($2 == ly_symbol2scm ("backslash"))
2747 m->set_property ("augmented-slash", SCM_BOOL_T);
2753 figured_bass_modification:
2755 $$ = ly_symbol2scm ("plus");
2758 $$ = ly_symbol2scm ("exclamation");
2761 $$ = ly_symbol2scm ("slash");
2764 $$ = ly_symbol2scm ("backslash");
2774 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2782 | figure_list br_bass_figure {
2783 $$ = scm_cons ($2, $1);
2788 FIGURE_OPEN figure_list FIGURE_CLOSE {
2789 $$ = scm_reverse_x ($2, SCM_EOL);
2800 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2801 if (!parser->lexer_->is_note_state ())
2802 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2803 if ($2 || $3 || scm_is_number ($4) || !SCM_UNBNDP ($5) || $6)
2807 n = MY_MAKE_MUSIC ("RestEvent", @$);
2809 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2811 n->set_property ("pitch", $1);
2812 if (SCM_UNBNDP ($5))
2813 n->set_property ("duration",
2814 parser->default_duration_.smobbed_copy ());
2816 n->set_property ("duration", $5);
2818 if (scm_is_number ($4))
2820 int q = scm_to_int ($4);
2821 n->set_property ("absolute-octave", scm_from_int (q-1));
2825 n->set_property ("cautionary", SCM_BOOL_T);
2826 if ($2 % 2 || $3 % 2)
2827 n->set_property ("force-accidental", SCM_BOOL_T);
2829 $$ = n->unprotect ();
2832 | DRUM_PITCH optional_notemode_duration {
2833 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2834 n->set_property ("duration", $2);
2835 n->set_property ("drum-type", $1);
2837 $$ = n->unprotect ();
2839 | RESTNAME optional_notemode_duration {
2841 if (ly_scm2string ($1) == "s") {
2843 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2846 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2849 ev->set_property ("duration", $2);
2850 $$ = ev->unprotect ();
2854 simple_chord_elements:
2856 if (!parser->lexer_->is_chord_state ())
2857 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2860 | figure_spec optional_notemode_duration {
2861 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2863 unsmob_music (scm_car (s))->set_property ("duration", $2);
2880 | lyric_element multiplied_duration post_events {
2881 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2882 if (scm_is_pair ($3))
2883 unsmob_music ($$)->set_property
2884 ("articulations", scm_reverse_x ($3, SCM_EOL));
2886 | lyric_element post_event post_events {
2887 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2888 parser->default_duration_.smobbed_copy ());
2889 unsmob_music ($$)->set_property
2890 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2892 | LYRIC_ELEMENT optional_notemode_duration post_events {
2893 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2894 if (scm_is_pair ($3))
2895 unsmob_music ($$)->set_property
2896 ("articulations", scm_reverse_x ($3, SCM_EOL));
2901 lyric_element_music:
2902 lyric_element optional_notemode_duration post_events {
2903 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2904 if (scm_is_pair ($3))
2905 unsmob_music ($$)->set_property
2906 ("articulations", scm_reverse_x ($3, SCM_EOL));
2911 steno_tonic_pitch optional_notemode_duration {
2912 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2914 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2915 SCM its = scm_reverse_x ($4, SCM_EOL);
2916 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2924 | chord_items chord_item {
2925 $$ = scm_cons ($2, $$);
2931 $$ = ly_symbol2scm ("chord-colon");
2934 $$ = ly_symbol2scm ("chord-caret");
2936 | CHORD_SLASH steno_tonic_pitch {
2937 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2939 | CHORD_BASS steno_tonic_pitch {
2940 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2949 $$ = scm_reverse_x ($1, SCM_EOL);
2957 step_number { $$ = scm_cons ($1, SCM_EOL); }
2958 | step_numbers '.' step_number {
2959 $$ = scm_cons ($3, $$);
2965 $$ = make_chord_step ($1, 0);
2967 | bare_unsigned '+' {
2968 $$ = make_chord_step ($1, SHARP_ALTERATION);
2970 | bare_unsigned CHORD_MINUS {
2971 $$ = make_chord_step ($1, FLAT_ALTERATION);
2977 $$ = scm_from_int ($1);
2979 | bare_unsigned '~' bare_unsigned {
2980 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2987 TODO: should deprecate in favor of Scheme?
2991 number_expression '+' number_term {
2992 $$ = scm_sum ($1, $3);
2994 | number_expression '-' number_term {
2995 $$ = scm_difference ($1, $3);
3004 | number_factor '*' number_factor {
3005 $$ = scm_product ($1, $3);
3007 | number_factor '/' number_factor {
3008 $$ = scm_divide ($1, $3);
3013 '-' number_factor { /* %prec UNARY_MINUS */
3014 $$ = scm_difference ($2, SCM_UNDEFINED);
3022 | UNSIGNED NUMBER_IDENTIFIER {
3023 $$ = scm_product ($1, $2);
3025 | REAL NUMBER_IDENTIFIER {
3026 $$ = scm_product ($1, $2);
3038 $$ = scm_to_int ($1);
3049 | exclamations '!' { $$ ++; }
3054 | questions '?' { $$ ++; }
3058 This should be done more dynamically if possible.
3062 LYRIC_MARKUP_IDENTIFIER {
3066 { parser->lexer_->push_markup_state (); }
3069 parser->lexer_->pop_state ();
3074 MARKUPLIST_IDENTIFIER {
3078 { parser->lexer_->push_markup_state (); }
3081 parser->lexer_->pop_state ();
3090 { parser->lexer_->push_markup_state (); }
3093 parser->lexer_->pop_state ();
3099 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3101 | markup_head_1_list simple_markup {
3102 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3112 if (Text_interface::is_markup ($1))
3113 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3114 else if (Text_interface::is_markup_list ($1))
3115 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3117 parser->parser_error (@1, _ ("not a markup"));
3118 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3125 MARKUPLIST_IDENTIFIER {
3128 | markup_composed_list {
3131 | markup_braced_list {
3134 | markup_command_list {
3135 $$ = scm_list_1 ($1);
3137 | markup_scm MARKUPLIST_IDENTIFIER
3143 markup_composed_list:
3144 markup_head_1_list markup_braced_list {
3145 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3151 '{' markup_braced_list_body '}' {
3152 $$ = scm_reverse_x ($2, SCM_EOL);
3156 markup_braced_list_body:
3157 /* empty */ { $$ = SCM_EOL; }
3158 | markup_braced_list_body markup {
3159 $$ = scm_cons ($2, $1);
3161 | markup_braced_list_body markup_list {
3162 $$ = scm_reverse_x ($2, $1);
3166 markup_command_list:
3167 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3168 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3172 markup_command_basic_arguments:
3173 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3174 $$ = scm_cons ($3, $2);
3176 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3177 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3179 | EXPECT_NO_MORE_ARGS {
3184 markup_command_list_arguments:
3185 markup_command_basic_arguments { $$ = $1; }
3186 | EXPECT_MARKUP markup_command_list_arguments markup {
3187 $$ = scm_cons ($3, $2);
3192 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3193 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3198 markup_head_1_item {
3199 $$ = scm_list_1 ($1);
3201 | markup_head_1_list markup_head_1_item {
3202 $$ = scm_cons ($2, $1);
3208 $$ = make_simple_markup ($1);
3210 | MARKUP_IDENTIFIER {
3213 | LYRIC_MARKUP_IDENTIFIER {
3216 | STRING_IDENTIFIER {
3220 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3221 parser->lexer_->push_note_state (nn);
3222 } '{' score_body '}' {
3224 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3226 parser->lexer_->pop_state ();
3228 | MARKUP_FUNCTION markup_command_basic_arguments {
3229 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3231 | markup_scm MARKUP_IDENTIFIER
3238 markup_head_1_list simple_markup {
3239 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3240 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3250 Lily_parser::set_yydebug (bool x)
3256 Lily_parser::do_yyparse ()
3258 SCM retval = SCM_UNDEFINED;
3259 yyparse (this, &retval);
3269 It is a little strange to have this function in this file, but
3270 otherwise, we have to import music classes into the lexer.
3274 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3276 if (scm_is_string (sid)) {
3278 return STRING_IDENTIFIER;
3279 } else if (unsmob_book (sid)) {
3280 Book *book = unsmob_book (sid)->clone ();
3281 *destination = book->self_scm ();
3284 return BOOK_IDENTIFIER;
3285 } else if (scm_is_number (sid)) {
3287 return NUMBER_IDENTIFIER;
3288 } else if (unsmob_context_def (sid)) {
3289 Context_def *def= unsmob_context_def (sid)->clone ();
3291 *destination = def->self_scm ();
3294 return CONTEXT_DEF_IDENTIFIER;
3295 } else if (unsmob_context_mod (sid)) {
3296 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3298 return CONTEXT_MOD_IDENTIFIER;
3299 } else if (unsmob_score (sid)) {
3300 Score *score = new Score (*unsmob_score (sid));
3301 *destination = score->self_scm ();
3303 score->unprotect ();
3304 return SCORE_IDENTIFIER;
3305 } else if (Music *mus = unsmob_music (sid)) {
3306 mus = mus->clone ();
3307 *destination = mus->self_scm ();
3308 unsmob_music (*destination)->
3309 set_property ("origin", make_input (last_input_));
3311 bool is_event = mus->is_mus_type ("post-event");
3313 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3314 } else if (unsmob_pitch (sid)) {
3315 *destination = unsmob_pitch (sid)->smobbed_copy ();
3316 return PITCH_IDENTIFIER;
3317 } else if (unsmob_duration (sid)) {
3318 *destination = unsmob_duration (sid)->smobbed_copy ();
3319 return DURATION_IDENTIFIER;
3320 } else if (unsmob_output_def (sid)) {
3321 Output_def *p = unsmob_output_def (sid);
3324 *destination = p->self_scm ();
3326 return OUTPUT_DEF_IDENTIFIER;
3327 } else if (Text_interface::is_markup (sid)) {
3329 if (is_lyric_state ())
3330 return LYRIC_MARKUP_IDENTIFIER;
3331 return MARKUP_IDENTIFIER;
3332 } else if (Text_interface::is_markup_list (sid)) {
3334 return MARKUPLIST_IDENTIFIER;
3341 get_next_unique_context_id ()
3343 return scm_from_locale_string ("$uniqueContextId");
3348 get_next_unique_lyrics_context_id ()
3350 static int new_context_count;
3352 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3353 return scm_from_locale_string (s);
3356 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3357 SCM arg, SCM args, SCM pred)
3359 args = scm_cons (arg, args);
3360 if (scm_is_true (scm_call_1 (pred, arg)))
3362 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3363 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3364 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3368 SCM loc_on_music (Input loc, SCM arg)
3370 if (Music *m = unsmob_music (arg))
3374 return m->unprotect ();
3380 is_regular_identifier (SCM id)
3382 string str = ly_scm2string (id);
3383 char const *s = str.c_str ();
3392 v = v && isalnum (*s);
3399 make_music_with_input (SCM name, Input where)
3401 Music *m = make_music_by_name (name);
3402 m->set_spot (where);
3407 make_simple_markup (SCM a)
3415 return t && t == 1 << intlog2 (t);
3419 set_music_properties (Music *p, SCM a)
3421 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3422 p->set_property (scm_caar (k), scm_cdar (k));
3427 make_chord_step (int step, Rational alter)
3430 alter += FLAT_ALTERATION;
3434 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3435 return m.smobbed_copy ();
3440 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3442 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3443 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3444 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3446 unsmob_music (scm_car (s))->set_spot (loc);
3452 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3454 Lily_lexer *lex = parser->lexer_;
3458 lex->prepare_for_next_token ();
3459 return lex->yylex ();