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 %lex-param {Lily_parser *parser}
47 /* We use SCMs to do strings, because it saves us the trouble of
48 deleting them. Let's hope that a stack overflow doesn't trigger a move
49 of the parse stack onto the heap. */
55 /* The above precedences tackle the shift/reduce problem
58 \repeat .. \alternative
60 \repeat { \repeat .. \alternative }
64 \repeat { \repeat } \alternative
70 /* ADDLYRICS needs to have lower precedence than argument scanning,
71 * or we won't be able to tell music apart from closed_music without
72 * lookahead in the context of function calls.
77 /* \default is only applied after exhausting function arguments */
79 %nonassoc FUNCTION_ARGLIST
81 /* expressions with units are permitted into argument lists */
83 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
84 UNSIGNED REAL DURATION_IDENTIFIER ':'
86 /* The above are the symbols that can start optional function arguments
87 that are recognized in the grammar rather than by predicate
90 %nonassoc NUMBER_IDENTIFIER '/'
92 /* Number-unit expressions, where permitted, are concatenated into
93 * function arguments, just like fractions and tremoli. Tremoli must
94 * not have higher precedence than UNSIGNED, or Lilypond will not
95 * join ':' with a following optional number.
108 %{ // -*-Fundamental-*-
113 * The rules for who is protecting what are very shady. Uniformise
116 * There are too many lexical modes?
127 #include "context-def.hh"
128 #include "context-mod.hh"
129 #include "dimensions.hh"
130 #include "file-path.hh"
132 #include "international.hh"
133 #include "lily-guile.hh"
134 #include "lily-lexer.hh"
135 #include "lily-parser.hh"
139 #include "output-def.hh"
140 #include "paper-book.hh"
141 #include "scm-hash.hh"
143 #include "text-interface.hh"
147 Lily_parser::parser_error (Input const *i, Lily_parser *parser, string s)
149 parser->parser_error (*i, s);
152 #define MYBACKUP(Token, Value, Location) \
154 if (yychar == YYEMPTY) \
157 parser->lexer_->push_extra_token (Token, Value); \
158 parser->lexer_->push_extra_token (BACKUP); \
160 parser->parser_error \
161 (Location, _("Too much lookahead")); \
166 #define MYREPARSE(Location, Pred, Token, Value) \
168 if (yychar == YYEMPTY) \
170 parser->lexer_->push_extra_token (Token, Value); \
171 parser->lexer_->push_extra_token (REPARSE, \
174 parser->parser_error \
175 (Location, _("Too much lookahead")); \
184 Output_def *outputdef;
193 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
196 - Don't use lily module, create a new module instead.
197 - delay application of the function
199 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
200 scm_apply_0 (proc, args)
201 /* Syntactic Sugar. */
202 #define MAKE_SYNTAX(name, location, ...) \
203 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED))
204 #define START_MAKE_SYNTAX(name, ...) \
205 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
206 #define FINISH_MAKE_SYNTAX(start, location, ...) \
207 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)))))
209 SCM get_next_unique_context_id ();
210 SCM get_next_unique_lyrics_context_id ();
217 #define _(x) gettext (x)
221 static Music *make_music_with_input (SCM name, Input where);
222 SCM check_scheme_arg (Lily_parser *parser, Input loc,
223 SCM arg, SCM args, SCM pred);
224 SCM loc_on_music (Input loc, SCM arg);
225 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
226 SCM make_chord_step (int step, Rational alter);
227 SCM make_simple_markup (SCM a);
228 bool is_duration (int t);
229 bool is_regular_identifier (SCM id);
230 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
231 void set_music_properties (Music *p, SCM a);
235 /* The third option is an alias that will be used to display the
236 syntax error. Bison CVS now correctly handles backslash escapes.
238 FIXME: Bison needs to translate some of these, eg, STRING.
242 /* Keyword tokens with plain escaped name. */
243 %token END_OF_FILE 0 "end of input"
244 %token ACCEPTS "\\accepts"
245 %token ADDLYRICS "\\addlyrics"
246 %token ALIAS "\\alias"
247 %token ALTERNATIVE "\\alternative"
249 %token BOOKPART "\\bookpart"
250 %token CHANGE "\\change"
251 %token CHORDMODE "\\chordmode"
252 %token CHORDS "\\chords"
253 %token CONSISTS "\\consists"
254 %token CONTEXT "\\context"
255 %token DEFAULT "\\default"
256 %token DEFAULTCHILD "\\defaultchild"
257 %token DENIES "\\denies"
258 %token DESCRIPTION "\\description"
259 %token DRUMMODE "\\drummode"
260 %token DRUMS "\\drums"
261 %token FIGUREMODE "\\figuremode"
262 %token FIGURES "\\figures"
263 %token HEADER "\\header"
264 %token INVALID "\\version-error"
265 %token LAYOUT "\\layout"
266 %token LYRICMODE "\\lyricmode"
267 %token LYRICS "\\lyrics"
268 %token LYRICSTO "\\lyricsto"
269 %token MARKUP "\\markup"
270 %token MARKUPLIST "\\markuplist"
273 %token NOTEMODE "\\notemode"
274 %token OVERRIDE "\\override"
275 %token PAPER "\\paper"
276 %token REMOVE "\\remove"
277 %token REPEAT "\\repeat"
279 %token REVERT "\\revert"
280 %token SCORE "\\score"
281 %token SEQUENTIAL "\\sequential"
283 %token SIMULTANEOUS "\\simultaneous"
284 %token TEMPO "\\tempo"
286 %token UNSET "\\unset"
289 /* Keyword token exceptions. */
290 %token NEWCONTEXT "\\new"
293 /* Other string tokens. */
295 %token CHORD_BASS "/+"
296 %token CHORD_CARET "^"
297 %token CHORD_COLON ":"
298 %token CHORD_MINUS "-"
299 %token CHORD_SLASH "/"
300 %token ANGLE_OPEN "<"
301 %token ANGLE_CLOSE ">"
302 %token DOUBLE_ANGLE_OPEN "<<"
303 %token DOUBLE_ANGLE_CLOSE ">>"
304 %token E_BACKSLASH "\\"
305 %token E_ANGLE_CLOSE "\\>"
306 %token E_CHAR "\\C[haracter]"
308 %token E_EXCLAMATION "\\!"
309 %token E_BRACKET_OPEN "\\["
311 %token E_BRACKET_CLOSE "\\]"
312 %token E_ANGLE_OPEN "\\<"
318 If we give names, Bison complains.
320 %token FIGURE_CLOSE /* "\\>" */
321 %token FIGURE_OPEN /* "\\<" */
322 %token FIGURE_SPACE "_"
325 %token CHORDMODIFIERS
327 %token MULTI_MEASURE_REST
330 %token <i> E_UNSIGNED
331 %token <scm> UNSIGNED
333 /* Artificial tokens, for more generic function syntax */
334 %token <i> EXPECT_MARKUP "markup?"
335 %token <i> EXPECT_PITCH "ly:pitch?"
336 %token <i> EXPECT_DURATION "ly:duration?"
337 %token <scm> EXPECT_SCM "scheme?"
338 %token <scm> BACKUP "(backed-up?)"
339 %token <scm> REPARSE "(reparsed?)"
340 %token <i> EXPECT_MARKUP_LIST "markup-list?"
341 %token <scm> EXPECT_OPTIONAL "optional?"
342 /* After the last argument. */
343 %token <i> EXPECT_NO_MORE_ARGS;
345 /* An artificial token for parsing embedded Lilypond */
346 %token <i> EMBEDDED_LILY "#{"
348 %token <scm> BOOK_IDENTIFIER
349 %token <scm> CHORDMODIFIER_PITCH
350 %token <scm> CHORD_MODIFIER
351 %token <scm> CHORD_REPETITION
352 %token <scm> CONTEXT_DEF_IDENTIFIER
353 %token <scm> CONTEXT_MOD_IDENTIFIER
354 %token <scm> DRUM_PITCH
355 %token <scm> PITCH_IDENTIFIER
356 %token <scm> DURATION_IDENTIFIER
357 %token <scm> EVENT_IDENTIFIER
358 %token <scm> EVENT_FUNCTION
359 %token <scm> FRACTION
360 %token <scm> LYRICS_STRING
361 %token <scm> LYRIC_ELEMENT
362 %token <scm> LYRIC_MARKUP_IDENTIFIER
363 %token <scm> MARKUP_FUNCTION
364 %token <scm> MARKUP_LIST_FUNCTION
365 %token <scm> MARKUP_IDENTIFIER
366 %token <scm> MARKUPLIST_IDENTIFIER
367 %token <scm> MUSIC_FUNCTION
368 %token <scm> MUSIC_IDENTIFIER
369 %token <scm> NOTENAME_PITCH
370 %token <scm> NUMBER_IDENTIFIER
371 %token <scm> OUTPUT_DEF_IDENTIFIER
373 %token <scm> RESTNAME
374 %token <scm> SCM_FUNCTION
375 %token <scm> SCM_IDENTIFIER
376 %token <scm> SCM_TOKEN
377 %token <scm> SCORE_IDENTIFIER
379 %token <scm> STRING_IDENTIFIER
380 %token <scm> TONICNAME_PITCH
383 %type <book> book_block
384 %type <book> book_body
385 %type <book> bookpart_block
386 %type <book> bookpart_body
388 %type <i> bare_unsigned
389 %type <scm> figured_bass_alteration
391 %type <i> exclamations
392 %type <i> optional_rest
397 %type <i> tremolo_type
400 %type <scm> composite_music
401 %type <scm> grouped_music_list
402 %type <scm> braced_music_list
403 %type <scm> closed_music
405 %type <scm> music_bare
406 %type <scm> music_arg
407 %type <scm> music_assign
408 %type <scm> music_embedded
409 %type <scm> music_or_context_def
410 %type <scm> complex_music
411 %type <scm> complex_music_prefix
412 %type <scm> mode_changed_music
413 %type <scm> repeated_music
414 %type <scm> sequential_music
415 %type <scm> simple_music
416 %type <scm> simultaneous_music
417 %type <scm> chord_body
418 %type <scm> chord_body_element
419 %type <scm> command_element
420 %type <scm> command_event
421 %type <scm> context_modification
422 %type <scm> context_change
423 %type <scm> direction_less_event
424 %type <scm> direction_reqd_event
425 %type <scm> embedded_lilypond
426 %type <scm> event_chord
427 %type <scm> fingering
428 %type <scm> gen_text_def
429 %type <scm> music_property_def
430 %type <scm> note_chord_element
431 %type <scm> post_event
432 %type <scm> post_event_nofinger
433 %type <scm> re_rhythmed_music
434 %type <scm> simple_element
435 %type <scm> simple_music_property_def
436 %type <scm> start_symbol
437 %type <scm> string_number_event
438 %type <scm> tempo_event
440 %type <outputdef> output_def_body
441 %type <outputdef> output_def_head
442 %type <outputdef> output_def_head_with_mode_switch
443 %type <outputdef> output_def
444 %type <outputdef> paper_block
446 %type <scm> music_function_call
447 %type <scm> music_list
448 %type <scm> assignment_id
449 %type <scm> bare_number
450 %type <scm> bare_number_closed
451 %type <scm> unsigned_number
452 %type <scm> bass_figure
453 %type <scm> figured_bass_modification
454 %type <scm> br_bass_figure
455 %type <scm> bass_number
456 %type <scm> chord_body_elements
457 %type <scm> chord_item
458 %type <scm> chord_items
459 %type <scm> chord_separator
460 %type <scm> context_def_mod
461 %type <scm> context_def_spec_block
462 %type <scm> context_def_spec_body
463 %type <scm> context_mod
464 %type <scm> context_mod_arg
465 %type <scm> context_mod_embedded
466 %type <scm> context_mod_list
467 %type <scm> context_prop_spec
468 %type <scm> direction_less_char
469 %type <scm> duration_length
470 %type <scm> embedded_scm
471 %type <scm> embedded_scm_arg
472 %type <scm> embedded_scm_arg_closed
473 %type <scm> embedded_scm_bare
474 %type <scm> embedded_scm_bare_arg
475 %type <scm> embedded_scm_closed
476 %type <scm> event_function_event
477 %type <scm> figure_list
478 %type <scm> figure_spec
479 %type <scm> full_markup
480 %type <scm> full_markup_list
481 %type <scm> function_arglist
482 %type <scm> function_arglist_optional
483 %type <scm> function_arglist_backup
484 %type <scm> function_arglist_nonbackup
485 %type <scm> function_arglist_nonbackup_common
486 %type <scm> function_arglist_closed_nonbackup
487 %type <scm> function_arglist_skip
488 %type <scm> function_arglist_bare
489 %type <scm> function_arglist_closed
490 %type <scm> function_arglist_closed_optional
491 %type <scm> function_arglist_common
492 %type <scm> function_arglist_common_lyric
493 %type <scm> function_arglist_common_minus
494 %type <scm> function_arglist_closed_common
495 %type <scm> function_arglist_keep
496 %type <scm> function_arglist_closed_keep
497 %type <scm> identifier_init
499 %type <scm> lilypond_header
500 %type <scm> lyric_element
501 %type <scm> lyric_element_arg
502 %type <scm> lyric_element_music
503 %type <scm> lyric_markup
505 %type <scm> markup_braced_list
506 %type <scm> markup_braced_list_body
507 %type <scm> markup_composed_list
508 %type <scm> markup_command_list
509 %type <scm> markup_command_list_arguments
510 %type <scm> markup_command_basic_arguments
511 %type <scm> markup_head_1_item
512 %type <scm> markup_head_1_list
513 %type <scm> markup_list
514 %type <scm> markup_top
515 %type <scm> maybe_notemode_duration
516 %type <scm> mode_changing_head
517 %type <scm> mode_changing_head_with_context
518 %type <scm> multiplied_duration
519 %type <scm> music_function_event
520 %type <scm> music_function_chord_body
521 %type <scm> new_chord
522 %type <scm> new_lyrics
523 %type <scm> number_expression
524 %type <scm> number_factor
525 %type <scm> number_term
526 %type <scm> octave_check
527 %type <scm> optional_context_mod
528 %type <scm> optional_id
529 %type <scm> optional_notemode_duration
531 %type <scm> pitch_also_in_chords
532 %type <scm> post_events
533 %type <scm> property_operation
534 %type <scm> property_path property_path_revved
536 %type <scm> scalar_closed
537 %type <scm> scm_function_call
538 %type <scm> scm_function_call_closed
539 %type <scm> script_abbreviation
540 %type <scm> simple_chord_elements
541 %type <scm> simple_markup
542 %type <scm> simple_string
543 %type <scm> steno_duration
544 %type <scm> steno_pitch
545 %type <scm> steno_tonic_pitch
546 %type <scm> step_number
547 %type <scm> step_numbers
549 %type <scm> tempo_range
551 %type <score> score_block
552 %type <score> score_body
557 /* We don't assign precedence to / and *, because we might need varied
558 prec levels in different prods */
567 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
568 parser->lexer_->push_note_state (nn);
569 } embedded_lilypond {
570 parser->lexer_->pop_state ();
571 parser->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
575 lilypond: /* empty */ { }
576 | lilypond toplevel_expression {
578 | lilypond assignment {
581 parser->error_level_ = 1;
584 parser->error_level_ = 1;
591 parser->lexer_->add_scope (get_header (parser));
593 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
597 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
598 scm_call_2 (proc, parser->self_scm (), book->self_scm ());
603 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
604 scm_call_2 (proc, parser->self_scm (), bookpart->self_scm ());
605 bookpart->unprotect ();
610 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
611 scm_call_2 (proc, parser->self_scm (), score->self_scm ());
615 Music *music = unsmob_music ($1);
616 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
617 scm_call_2 (proc, parser->self_scm (), music->self_scm ());
620 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
621 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
624 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
625 scm_call_2 (proc, parser->self_scm (), $1);
629 Output_def * od = $1;
631 if ($1->c_variable ("is-paper") == SCM_BOOL_T)
632 id = ly_symbol2scm ("$defaultpaper");
633 else if ($1->c_variable ("is-midi") == SCM_BOOL_T)
634 id = ly_symbol2scm ("$defaultmidi");
635 else if ($1->c_variable ("is-layout") == SCM_BOOL_T)
636 id = ly_symbol2scm ("$defaultlayout");
638 parser->lexer_->set_identifier (id, od->self_scm ());
646 $$ = parser->lexer_->eval_scm_token ($1);
651 embedded_scm_bare_arg:
657 | context_modification
660 $$ = $1->self_scm ();
663 | context_def_spec_block
666 $$ = $1->self_scm ();
671 $$ = $1->self_scm ();
676 $$ = $1->self_scm ();
681 /* The generic version may end in music, or not */
689 embedded_scm_bare_arg
695 SCM_FUNCTION function_arglist {
696 $$ = MAKE_SYNTAX ("music-function", @$,
704 $$ = MAKE_SYNTAX ("void-music", @$);
707 | music_embedded music_embedded music_list {
708 $3 = scm_reverse_x ($3, SCM_EOL);
709 if (unsmob_music ($2))
710 $3 = scm_cons ($2, $3);
711 if (unsmob_music ($1))
712 $3 = scm_cons ($1, $3);
713 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
716 parser->error_level_ = 1;
718 | INVALID embedded_lilypond {
719 parser->error_level_ = 1;
724 lilypond_header_body:
726 | lilypond_header_body assignment {
732 HEADER '{' lilypond_header_body '}' {
733 $$ = parser->lexer_->remove_scope ();
742 | LYRICS_STRING { $$ = $1; }
746 assignment_id '=' identifier_init {
747 parser->lexer_->set_identifier ($1, $3);
749 | assignment_id property_path '=' identifier_init {
750 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
751 parser->lexer_->set_identifier (path, $4);
754 TODO: devise standard for protection in parser.
756 The parser stack lives on the C-stack, which means that
757 all objects can be unprotected as soon as they're here.
767 $$ = $1->self_scm ();
771 $$ = $1->self_scm ();
775 $$ = $1->self_scm ();
779 $$ = $1->self_scm ();
782 | context_def_spec_block {
788 | post_event_nofinger {
791 | number_expression {
809 | context_modification {
814 context_def_spec_block:
815 CONTEXT '{' context_def_spec_body '}'
826 context_mod_embedded:
829 if (unsmob_music ($1)) {
830 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
831 $1 = scm_call_2 (proc, parser->self_scm (), $1);
833 if (unsmob_context_mod ($1))
836 parser->parser_error (@1, _ ("not a context mod"));
842 context_def_spec_body:
844 $$ = Context_def::make_scm ();
845 unsmob_context_def ($$)->origin ()->set_spot (@$);
847 | CONTEXT_DEF_IDENTIFIER {
849 unsmob_context_def ($$)->origin ()->set_spot (@$);
851 | context_def_spec_body context_mod {
852 unsmob_context_def ($$)->add_context_mod ($2);
854 | context_def_spec_body context_modification {
855 Context_def *td = unsmob_context_def ($$);
856 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
857 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
858 td->add_context_mod (scm_car (m));
861 | context_def_spec_body context_mod_embedded {
862 Context_def *td = unsmob_context_def ($$);
863 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
864 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
865 td->add_context_mod (scm_car (m));
873 BOOK '{' book_body '}' {
876 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
881 * Use 'handlers' like for toplevel-* stuff?
882 * grok \layout and \midi? */
886 init_papers (parser);
887 $$->origin ()->set_spot (@$);
888 $$->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
889 $$->paper_->unprotect ();
890 push_paper (parser, $$->paper_);
891 $$->header_ = get_header (parser);
892 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$->self_scm ());
895 $$ = unsmob_book ($1);
897 $$->origin ()->set_spot (@$);
898 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
900 | book_body paper_block {
903 set_paper (parser, $2);
905 | book_body bookpart_block {
907 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
908 scm_call_2 (proc, $$->self_scm (), bookpart->self_scm ());
909 bookpart->unprotect ();
911 | book_body score_block {
913 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
914 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
917 | book_body composite_music {
918 Music *music = unsmob_music ($2);
919 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
920 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
922 | book_body full_markup {
923 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
924 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
926 | book_body full_markup_list {
927 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
928 scm_call_2 (proc, $$->self_scm (), $2);
932 parser->lexer_->add_scope ($1->header_);
934 | book_body embedded_scm { }
937 $$->scores_ = SCM_EOL;
938 $$->bookparts_ = SCM_EOL;
943 BOOKPART '{' bookpart_body '}' {
945 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
952 $$->origin ()->set_spot (@$);
953 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$->self_scm ());
956 $$ = unsmob_book ($1);
958 $$->origin ()->set_spot (@$);
959 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
961 | bookpart_body paper_block {
965 | bookpart_body score_block {
967 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
968 scm_call_2 (proc, $$->self_scm (), score->self_scm ());
971 | bookpart_body composite_music {
972 Music *music = unsmob_music ($2);
973 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
974 scm_call_3 (proc, parser->self_scm (), $$->self_scm (), music->self_scm ());
976 | bookpart_body full_markup {
977 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
978 scm_call_2 (proc, $$->self_scm (), scm_list_1 ($2));
980 | bookpart_body full_markup_list {
981 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
982 scm_call_2 (proc, $$->self_scm (), $2);
986 if (!ly_is_module ($1->header_))
987 $1->header_ = ly_make_module (false);
988 parser->lexer_->add_scope ($1->header_);
990 | bookpart_body embedded_scm { }
991 | bookpart_body error {
993 $$->scores_ = SCM_EOL;
998 SCORE '{' score_body '}' {
1006 SCM scorify = ly_lily_module_constant ("scorify-music");
1007 SCM score = scm_call_2 (scorify, m, parser->self_scm ());
1009 // pass ownernship to C++ again.
1010 $$ = unsmob_score (score);
1012 $$->origin ()->set_spot (@$);
1014 | SCORE_IDENTIFIER {
1015 $$ = unsmob_score ($1);
1017 $$->origin ()->set_spot (@$);
1021 if (!ly_is_module ($1->get_header ()))
1022 $1->set_header (ly_make_module (false));
1023 parser->lexer_->add_scope ($1->get_header ());
1025 | score_body output_def {
1026 if ($2->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
1028 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1033 $$->add_output_def ($2);
1037 | score_body error {
1038 $$->error_found_ = true;
1050 if ($$->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
1052 parser->parser_error (@1, _ ("need \\paper for paper block"));
1054 $$ = get_paper (parser);
1061 output_def_body '}' {
1064 parser->lexer_->remove_scope ();
1065 parser->lexer_->pop_state ();
1071 $$ = get_paper (parser);
1072 $$->input_origin_ = @$;
1073 parser->lexer_->add_scope ($$->scope_);
1076 Output_def *p = get_midi (parser);
1078 parser->lexer_->add_scope (p->scope_);
1081 Output_def *p = get_layout (parser);
1083 parser->lexer_->add_scope (p->scope_);
1088 output_def_head_with_mode_switch:
1090 parser->lexer_->push_initial_state ();
1095 // We need this weird nonterminal because both music as well as a
1096 // context definition can start with \context and the difference is
1097 // only apparent after looking at the next token. If it is '{', there
1098 // is still time to escape from notes mode.
1100 music_or_context_def:
1103 parser->lexer_->pop_state ();
1107 parser->lexer_->pop_state ();
1108 } '{' context_def_spec_body '}'
1115 output_def_head_with_mode_switch '{' {
1117 $$->input_origin_.set_spot (@$);
1119 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
1122 Output_def *o = unsmob_output_def ($3);
1123 o->input_origin_.set_spot (@$);
1126 parser->lexer_->remove_scope ();
1127 parser->lexer_->add_scope (o->scope_);
1129 | output_def_body assignment {
1134 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1135 parser->lexer_->push_note_state (nn);
1136 } music_or_context_def
1138 if (unsmob_context_def ($3))
1139 assign_context_def ($$, $3);
1142 SCM proc = parser->lexer_->lookup_identifier
1143 ("output-def-music-handler");
1144 scm_call_3 (proc, parser->self_scm (),
1145 $1->self_scm (), $3);
1148 | output_def_body error {
1154 TEMPO steno_duration '=' tempo_range {
1155 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1157 | TEMPO scalar_closed steno_duration '=' tempo_range {
1158 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1161 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1166 The representation of a list is reversed to have efficient append. */
1172 | music_list music_embedded {
1173 if (unsmob_music ($2))
1174 $$ = scm_cons ($2, $1);
1176 | music_list error {
1177 Music *m = MY_MAKE_MUSIC("Music", @$);
1179 m->set_property ("error-found", SCM_BOOL_T);
1180 $$ = scm_cons (m->self_scm (), $1);
1181 m->unprotect (); /* UGH */
1188 $$ = scm_reverse_x ($2, SCM_EOL);
1193 | lyric_element_music
1200 if (unsmob_music ($1)
1201 || scm_is_eq ($1, SCM_UNSPECIFIED))
1205 @$.warning (_ ("Ignoring non-music expression"));
1206 $$ = SCM_UNSPECIFIED;
1214 if (unsmob_pitch ($1)) {
1215 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1216 n->set_property ("pitch", $1);
1217 n->set_property ("duration",
1218 parser->default_duration_.smobbed_copy ());
1219 $$ = n->unprotect ();
1222 | composite_music %prec COMPOSITE
1227 | composite_music %prec COMPOSITE
1228 | lyric_element_music
1232 REPEAT simple_string unsigned_number music
1234 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1236 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1238 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1243 SEQUENTIAL braced_music_list {
1244 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1246 | braced_music_list {
1247 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1252 SIMULTANEOUS braced_music_list {
1253 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1255 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1256 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1262 | music_property_def
1266 context_modification:
1267 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1269 parser->lexer_->pop_state ();
1272 | WITH CONTEXT_MOD_IDENTIFIER
1276 | CONTEXT_MOD_IDENTIFIER
1280 | WITH embedded_scm_closed
1282 if (unsmob_context_mod ($2))
1285 parser->parser_error (@2, _ ("not a context mod"));
1286 $$ = Context_mod ().smobbed_copy ();
1291 optional_context_mod:
1295 | context_modification
1303 $$ = Context_mod ().smobbed_copy ();
1305 | context_mod_list context_mod {
1306 unsmob_context_mod ($1)->add_context_mod ($2);
1308 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1309 Context_mod *md = unsmob_context_mod ($2);
1311 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1313 | context_mod_list context_mod_embedded {
1314 unsmob_context_mod ($1)->add_context_mods
1315 (unsmob_context_mod ($2)->get_mods ());
1324 /* Music that can be parsed without lookahead */
1327 | complex_music_prefix closed_music
1329 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1336 | grouped_music_list
1340 simultaneous_music { $$ = $1; }
1341 | sequential_music { $$ = $1; }
1344 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1345 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1346 and this rule returns the reversed list of arguments. */
1348 function_arglist_skip:
1349 function_arglist_common
1350 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1352 $$ = scm_cons ($1, $3);
1353 } %prec FUNCTION_ARGLIST
1354 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1356 $$ = scm_cons ($1, $3);
1357 } %prec FUNCTION_ARGLIST
1358 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1360 $$ = scm_cons ($1, $3);
1361 } %prec FUNCTION_ARGLIST
1365 function_arglist_nonbackup_common:
1366 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1367 $$ = scm_cons ($4, $3);
1369 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1370 $$ = scm_cons ($4, $3);
1372 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1374 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1376 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1378 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1380 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1382 SCM n = scm_difference ($5, SCM_UNDEFINED);
1383 if (scm_is_true (scm_call_1 ($2, n)))
1384 $$ = scm_cons (n, $3);
1386 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1387 t->set_property ("digit", $5);
1388 $$ = t->unprotect ();
1389 if (scm_is_true (scm_call_1 ($2, $$)))
1390 $$ = scm_cons ($$, $3);
1392 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1396 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1398 $$ = check_scheme_arg (parser, @4,
1399 scm_difference ($5, SCM_UNDEFINED),
1402 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1404 $$ = check_scheme_arg (parser, @4,
1405 scm_difference ($5, SCM_UNDEFINED),
1410 function_arglist_closed_nonbackup:
1411 function_arglist_nonbackup_common
1412 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1414 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1416 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1418 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1422 function_arglist_nonbackup:
1423 function_arglist_nonbackup_common
1424 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1426 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1428 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1430 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1434 function_arglist_keep:
1435 function_arglist_common
1436 | function_arglist_backup
1439 function_arglist_closed_keep:
1440 function_arglist_closed_common
1441 | function_arglist_backup
1444 function_arglist_backup:
1445 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1447 if (scm_is_true (scm_call_1 ($2, $4)))
1449 $$ = scm_cons ($4, $3);
1451 $$ = scm_cons (loc_on_music (@3, $1), $3);
1452 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1455 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1457 if (scm_is_true (scm_call_1 ($2, $4)))
1459 $$ = scm_cons ($4, $3);
1461 $$ = scm_cons (loc_on_music (@3, $1), $3);
1462 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1465 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1467 // There is no point interpreting a lyrics string as
1468 // an event, since we don't allow music possibly
1469 // followed by durations or postevent into closed
1470 // music, and we only accept closed music in optional
1471 // arguments at the moment. If this changes, more
1472 // complex schemes might become interesting here as
1473 // well: see how we do this at the mandatory argument
1475 if (scm_is_true (scm_call_1 ($2, $4)))
1476 $$ = scm_cons ($4, $3);
1478 $$ = scm_cons (loc_on_music (@3, $1), $3);
1479 MYBACKUP (LYRICS_STRING, $4, @4);
1482 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1484 if (scm_is_true (scm_call_1 ($2, $4)))
1487 MYREPARSE (@4, $2, UNSIGNED, $4);
1489 $$ = scm_cons (loc_on_music (@3, $1), $3);
1490 MYBACKUP (UNSIGNED, $4, @4);
1493 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1495 if (scm_is_true (scm_call_1 ($2, $4)))
1498 MYREPARSE (@4, $2, REAL, $4);
1500 $$ = scm_cons (loc_on_music (@3, $1), $3);
1501 MYBACKUP (REAL, $4, @4);
1504 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1506 if (scm_is_true (scm_call_1 ($2, $4)))
1508 $$ = scm_cons ($4, $3);
1510 $$ = scm_cons (loc_on_music (@3, $1), $3);
1511 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1514 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1516 if (scm_is_true (scm_call_1 ($2, $4)))
1518 $$ = scm_cons ($4, $3);
1520 $$ = scm_cons (loc_on_music (@3, $1), $3);
1521 MYBACKUP (FRACTION, $4, @4);
1524 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1526 SCM n = scm_difference ($5, SCM_UNDEFINED);
1527 if (scm_is_true (scm_call_1 ($2, n))) {
1529 MYREPARSE (@5, $2, REAL, n);
1531 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1532 t->set_property ("digit", $5);
1533 $$ = t->unprotect ();
1534 if (scm_is_true (scm_call_1 ($2, $$)))
1535 $$ = scm_cons ($$, $3);
1537 $$ = scm_cons (loc_on_music (@3, $1), $3);
1538 MYBACKUP (UNSIGNED, $5, @5);
1539 parser->lexer_->push_extra_token ('-');
1544 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1546 SCM n = scm_difference ($5, SCM_UNDEFINED);
1547 if (scm_is_true (scm_call_1 ($2, n))) {
1548 MYREPARSE (@5, $2, REAL, n);
1551 MYBACKUP (REAL, n, @5);
1554 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1556 SCM n = scm_difference ($5, SCM_UNDEFINED);
1557 if (scm_is_true (scm_call_1 ($2, n))) {
1558 $$ = scm_cons (n, $3);
1560 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1563 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1565 $$ = scm_cons ($4, $3);
1567 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1569 $$ = scm_cons ($4, $3);
1571 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1573 $$ = scm_cons ($1, $3);
1574 MYBACKUP(0, SCM_UNDEFINED, @3);
1576 | function_arglist_backup REPARSE embedded_scm_arg_closed
1578 $$ = check_scheme_arg (parser, @3,
1581 | function_arglist_backup REPARSE bare_number
1583 $$ = check_scheme_arg (parser, @3,
1589 function_arglist_common
1590 | function_arglist_nonbackup
1593 function_arglist_common:
1594 function_arglist_bare
1595 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1597 $$ = check_scheme_arg (parser, @3,
1600 | EXPECT_SCM function_arglist_closed_optional bare_number
1602 $$ = check_scheme_arg (parser, @3,
1605 | EXPECT_SCM function_arglist_closed_optional FRACTION
1607 $$ = check_scheme_arg (parser, @3,
1610 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1612 $$ = check_scheme_arg (parser, @3,
1615 | function_arglist_common_minus
1616 | function_arglist_common_lyric
1619 function_arglist_common_lyric:
1620 EXPECT_SCM function_arglist_optional lyric_element
1622 // We check how the predicate thinks about a lyrics
1623 // event or about a markup. If it accepts neither, we
1624 // backup the original token. Otherwise we commit to
1625 // taking the token. Depending on what the predicate
1626 // is willing to accept, we interpret as a string, as
1627 // a lyric event, or ambiguously (meaning that if
1628 // something looking like a duration or post event
1629 // follows, we take the event, otherwise the string).
1630 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1631 parser->default_duration_.smobbed_copy ());
1632 if (scm_is_true (scm_call_1 ($1, $3)))
1633 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1636 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1638 $$ = scm_cons ($3, $2);
1640 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1643 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1645 // This is going to flag a syntax error, we
1646 // know the predicate to be false.
1647 check_scheme_arg (parser, @3,
1651 | function_arglist_common_lyric REPARSE lyric_element_arg
1653 // This should never be false
1654 $$ = check_scheme_arg (parser, @3,
1659 function_arglist_common_minus:
1660 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1662 SCM n = scm_difference ($4, SCM_UNDEFINED);
1663 if (scm_is_true (scm_call_1 ($1, n))) {
1665 MYREPARSE (@4, $1, REAL, n);
1667 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1668 t->set_property ("digit", $4);
1669 $$ = t->unprotect ();
1670 if (scm_is_true (scm_call_1 ($1, $$)))
1671 $$ = scm_cons ($$, $2);
1673 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1677 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1680 SCM n = scm_difference ($4, SCM_UNDEFINED);
1681 MYREPARSE (@4, $1, REAL, n);
1683 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1685 SCM n = scm_difference ($4, SCM_UNDEFINED);
1686 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1688 | function_arglist_common_minus REPARSE bare_number
1690 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1694 function_arglist_closed:
1695 function_arglist_closed_common
1696 | function_arglist_closed_nonbackup
1699 function_arglist_closed_common:
1700 function_arglist_bare
1701 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1703 $$ = check_scheme_arg (parser, @3,
1706 | EXPECT_SCM function_arglist_closed_optional bare_number
1708 $$ = check_scheme_arg (parser, @3,
1711 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1713 SCM n = scm_difference ($4, SCM_UNDEFINED);
1714 if (scm_is_true (scm_call_1 ($1, n))) {
1715 $$ = scm_cons (n, $2);
1717 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1718 t->set_property ("digit", $4);
1719 $$ = t->unprotect ();
1720 if (scm_is_true (scm_call_1 ($1, $$)))
1721 $$ = scm_cons ($$, $2);
1723 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1727 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1729 $$ = check_scheme_arg (parser, @3,
1730 scm_difference ($4, SCM_UNDEFINED),
1733 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1735 $$ = check_scheme_arg (parser, @3,
1736 scm_difference ($4, SCM_UNDEFINED),
1739 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1741 $$ = check_scheme_arg (parser, @3,
1744 | EXPECT_SCM function_arglist_closed_optional FRACTION
1746 $$ = check_scheme_arg (parser, @3,
1749 | EXPECT_SCM function_arglist_optional lyric_element
1751 $$ = check_scheme_arg (parser, @3,
1756 function_arglist_optional:
1757 function_arglist_keep %prec FUNCTION_ARGLIST
1758 | function_arglist_backup BACKUP
1759 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1761 $$ = scm_cons ($1, $3);
1763 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1765 $$ = scm_cons ($1, $3);
1769 function_arglist_closed_optional:
1770 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1771 | function_arglist_backup BACKUP
1772 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1774 $$ = scm_cons ($1, $3);
1776 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1778 $$ = scm_cons ($1, $3);
1782 embedded_scm_closed:
1784 | scm_function_call_closed
1787 embedded_scm_arg_closed:
1788 embedded_scm_bare_arg
1789 | scm_function_call_closed
1793 scm_function_call_closed:
1794 SCM_FUNCTION function_arglist_closed {
1795 $$ = MAKE_SYNTAX ("music-function", @$,
1797 } %prec FUNCTION_ARGLIST
1800 function_arglist_bare:
1801 EXPECT_NO_MORE_ARGS {
1804 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1805 $$ = scm_cons ($3, $2);
1807 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1808 $$ = scm_cons ($3, $2);
1810 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1811 $$ = scm_cons ($1, $3);
1813 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1814 $$ = scm_cons ($1, $3);
1816 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1817 $$ = scm_cons ($1, $3);
1821 music_function_call:
1822 MUSIC_FUNCTION function_arglist {
1823 $$ = MAKE_SYNTAX ("music-function", @$,
1830 /**/ { $$ = SCM_EOL; }
1831 | '=' simple_string {
1838 | repeated_music { $$ = $1; }
1839 | re_rhythmed_music { $$ = $1; }
1840 | complex_music_prefix music
1842 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1846 complex_music_prefix:
1847 CONTEXT simple_string optional_id optional_context_mod {
1848 Context_mod *ctxmod = unsmob_context_mod ($4);
1851 mods = ctxmod->get_mods ();
1852 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1854 | NEWCONTEXT simple_string optional_id optional_context_mod {
1855 Context_mod *ctxmod = unsmob_context_mod ($4);
1858 mods = ctxmod->get_mods ();
1859 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1864 mode_changing_head grouped_music_list {
1865 if ($1 == ly_symbol2scm ("chords"))
1867 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1873 parser->lexer_->pop_state ();
1875 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1876 Context_mod *ctxmod = unsmob_context_mod ($2);
1879 mods = ctxmod->get_mods ();
1880 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1881 if ($1 == ly_symbol2scm ("ChordNames"))
1883 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1885 parser->lexer_->pop_state ();
1891 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1892 parser->lexer_->push_note_state (nn);
1894 $$ = ly_symbol2scm ("notes");
1898 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1899 parser->lexer_->push_note_state (nn);
1901 $$ = ly_symbol2scm ("drums");
1904 parser->lexer_->push_figuredbass_state ();
1906 $$ = ly_symbol2scm ("figures");
1909 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1910 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1911 nn = parser->lexer_->lookup_identifier ("pitchnames");
1912 parser->lexer_->push_chord_state (nn);
1913 $$ = ly_symbol2scm ("chords");
1917 { parser->lexer_->push_lyric_state ();
1918 $$ = ly_symbol2scm ("lyrics");
1922 mode_changing_head_with_context:
1924 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1925 parser->lexer_->push_note_state (nn);
1927 $$ = ly_symbol2scm ("DrumStaff");
1930 parser->lexer_->push_figuredbass_state ();
1932 $$ = ly_symbol2scm ("FiguredBass");
1935 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1936 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1937 nn = parser->lexer_->lookup_identifier ("pitchnames");
1938 parser->lexer_->push_chord_state (nn);
1939 $$ = ly_symbol2scm ("ChordNames");
1942 { parser->lexer_->push_lyric_state ();
1943 $$ = ly_symbol2scm ("Lyrics");
1948 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1951 /* Can also use music at the expensive of two S/Rs similar to
1952 \repeat \alternative */
1953 parser->lexer_->pop_state ();
1955 $$ = scm_cons ($3, SCM_EOL);
1957 | new_lyrics ADDLYRICS {
1958 parser->lexer_->push_lyric_state ();
1960 parser->lexer_->pop_state ();
1961 $$ = scm_cons ($4, $1);
1966 composite_music new_lyrics {
1967 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1969 | LYRICSTO simple_string {
1970 parser->lexer_->push_lyric_state ();
1972 parser->lexer_->pop_state ();
1973 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1978 CHANGE STRING '=' STRING {
1979 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1984 property_path_revved:
1985 embedded_scm_closed {
1986 $$ = scm_cons ($1, SCM_EOL);
1988 | property_path_revved embedded_scm_closed {
1989 $$ = scm_cons ($2, $1);
1994 property_path_revved {
1995 $$ = scm_reverse_x ($1, SCM_EOL);
2001 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2002 scm_string_to_symbol ($1), $3);
2004 | UNSET simple_string {
2005 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2006 scm_string_to_symbol ($2));
2008 | OVERRIDE simple_string property_path '=' scalar {
2009 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
2010 scm_string_to_symbol ($2), $5),
2013 | REVERT simple_string embedded_scm {
2014 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2015 scm_string_to_symbol ($2), $3);
2020 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2021 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2023 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2024 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2025 | DENIES { $$ = ly_symbol2scm ("denies"); }
2027 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2028 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2029 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2030 | NAME { $$ = ly_symbol2scm ("context-name"); }
2034 property_operation { $$ = $1; }
2035 | context_def_mod STRING {
2036 $$ = scm_list_2 ($1, $2);
2038 | context_def_mod embedded_scm
2040 if (!scm_is_string ($2)
2041 && ly_symbol2scm ("consists") != $1
2042 && ly_symbol2scm ("remove") != $1)
2045 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2049 $$ = scm_list_2 ($1, $2);
2056 if (!is_regular_identifier ($1))
2058 @$.error (_("Grob name should be alphanumeric"));
2061 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
2062 scm_string_to_symbol ($1));
2064 | simple_string '.' simple_string {
2065 $$ = scm_list_2 (scm_string_to_symbol ($1),
2066 scm_string_to_symbol ($3));
2070 simple_music_property_def:
2071 OVERRIDE context_prop_spec property_path '=' scalar {
2072 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
2073 ly_symbol2scm ("OverrideProperty"),
2078 | REVERT context_prop_spec embedded_scm {
2079 $$ = scm_list_4 (scm_car ($2),
2080 ly_symbol2scm ("RevertProperty"),
2084 | SET context_prop_spec '=' scalar {
2085 $$ = scm_list_4 (scm_car ($2),
2086 ly_symbol2scm ("PropertySet"),
2090 | UNSET context_prop_spec {
2091 $$ = scm_list_3 (scm_car ($2),
2092 ly_symbol2scm ("PropertyUnset"),
2098 simple_music_property_def {
2099 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2107 | STRING_IDENTIFIER {
2110 | string '+' string {
2111 $$ = scm_string_append (scm_list_2 ($1, $3));
2115 simple_string: STRING {
2121 | STRING_IDENTIFIER {
2134 embedded_scm_arg_closed
2142 simple_element post_events {
2143 // Let the rhythmic music iterator sort this mess out.
2144 if (scm_is_pair ($2)) {
2145 if (unsmob_pitch ($1)) {
2146 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
2147 n->set_property ("pitch", $1);
2148 n->set_property ("duration",
2149 parser->default_duration_.smobbed_copy ());
2150 $$ = n->unprotect ();
2152 unsmob_music ($$)->set_property ("articulations",
2153 scm_reverse_x ($2, SCM_EOL));
2156 | simple_chord_elements post_events {
2157 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2160 /* why is this giving wrong start location? -ns
2162 i.set_location (@1, @2);
2163 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2165 | CHORD_REPETITION optional_notemode_duration post_events {
2167 i.set_location (@1, @3);
2168 $$ = MAKE_SYNTAX ("repetition-chord", i,
2169 $2, scm_reverse_x ($3, SCM_EOL));
2171 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2173 i.set_location (@1, @3);
2174 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2175 scm_reverse_x ($3, SCM_EOL));
2178 | note_chord_element
2183 chord_body optional_notemode_duration post_events
2185 Music *m = unsmob_music ($1);
2186 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2187 SCM es = m->get_property ("elements");
2188 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2190 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2191 unsmob_music (scm_car (s))->set_property ("duration", dur);
2192 es = ly_append2 (es, postevs);
2194 m-> set_property ("elements", es);
2196 $$ = m->self_scm ();
2201 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2203 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2207 chord_body_elements:
2208 /* empty */ { $$ = SCM_EOL; }
2209 | chord_body_elements chord_body_element {
2210 if (!SCM_UNBNDP ($2))
2211 $$ = scm_cons ($2, $1);
2216 pitch exclamations questions octave_check post_events
2223 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2224 n->set_property ("pitch", $1);
2226 n->set_property ("cautionary", SCM_BOOL_T);
2227 if (ex % 2 || q % 2)
2228 n->set_property ("force-accidental", SCM_BOOL_T);
2230 if (scm_is_pair (post)) {
2231 SCM arts = scm_reverse_x (post, SCM_EOL);
2232 n->set_property ("articulations", arts);
2234 if (scm_is_number (check))
2236 int q = scm_to_int (check);
2237 n->set_property ("absolute-octave", scm_from_int (q-1));
2240 $$ = n->unprotect ();
2242 | DRUM_PITCH post_events {
2243 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2244 n->set_property ("drum-type", $1);
2246 if (scm_is_pair ($2)) {
2247 SCM arts = scm_reverse_x ($2, SCM_EOL);
2248 n->set_property ("articulations", arts);
2250 $$ = n->unprotect ();
2252 | music_function_chord_body
2254 Music *m = unsmob_music ($1);
2256 while (m && m->is_mus_type ("music-wrapper-music")) {
2257 $$ = m->get_property ("element");
2258 m = unsmob_music ($$);
2261 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2262 parser->parser_error (@$, _ ("not a rhythmic event"));
2268 music_function_chord_body:
2273 // Event functions may only take closed arglists, otherwise it would
2274 // not be clear whether a following postevent should be associated
2275 // with the last argument of the event function or with the expression
2276 // for which the function call acts itself as event.
2278 music_function_event:
2279 MUSIC_FUNCTION function_arglist_closed {
2280 $$ = MAKE_SYNTAX ("music-function", @$,
2285 event_function_event:
2286 EVENT_FUNCTION function_arglist_closed {
2287 $$ = MAKE_SYNTAX ("music-function", @$,
2297 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2298 m->set_property ("span-direction", scm_from_int (START));
2299 $$ = m->unprotect();
2302 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2303 m->set_property ("span-direction", scm_from_int (STOP));
2304 $$ = m->unprotect ();
2307 $$ = MAKE_SYNTAX ("voice-separator", @$);
2310 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2312 Music *m = unsmob_music (pipe);
2317 $$ = m->unprotect ();
2320 $$ = MAKE_SYNTAX ("bar-check", @$);
2327 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2339 | post_events post_event {
2340 unsmob_music ($2)->set_spot (@2);
2341 $$ = scm_cons ($2, $$);
2345 post_event_nofinger:
2346 direction_less_event {
2349 | script_dir music_function_event {
2353 unsmob_music ($$)->set_property ("direction", scm_from_int ($1));
2357 if (!parser->lexer_->is_lyric_state ())
2358 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2359 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2362 if (!parser->lexer_->is_lyric_state ())
2363 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2364 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2366 | script_dir direction_reqd_event {
2369 Music *m = unsmob_music ($2);
2370 m->set_property ("direction", scm_from_int ($1));
2374 | script_dir direction_less_event {
2377 Music *m = unsmob_music ($2);
2378 m->set_property ("direction", scm_from_int ($1));
2382 | string_number_event
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 | EVENT_IDENTIFIER {
2462 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2463 a->set_property ("tremolo-type", scm_from_int ($1));
2464 $$ = a->unprotect ();
2466 | event_function_event
2469 direction_reqd_event:
2473 | script_abbreviation {
2474 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2475 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2476 if (scm_is_string (s))
2477 a->set_property ("articulation-type", s);
2478 else parser->parser_error (@1, _ ("expecting string as script definition"));
2479 $$ = a->unprotect ();
2484 /**/ { $$ = SCM_EOL; }
2485 | '=' { $$ = scm_from_int (0); }
2486 | '=' sub_quotes { $$ = scm_from_int (-$2); }
2487 | '=' sup_quotes { $$ = scm_from_int ($2); }
2512 | NOTENAME_PITCH sup_quotes {
2513 Pitch p = *unsmob_pitch ($1);
2514 p = p.transposed (Pitch ($2,0,0));
2515 $$ = p.smobbed_copy ();
2517 | NOTENAME_PITCH sub_quotes {
2518 Pitch p =* unsmob_pitch ($1);
2519 p = p.transposed (Pitch (-$2,0,0));
2520 $$ = p.smobbed_copy ();
2532 | TONICNAME_PITCH sup_quotes {
2533 Pitch p = *unsmob_pitch ($1);
2534 p = p.transposed (Pitch ($2,0,0));
2535 $$ = p.smobbed_copy ();
2537 | TONICNAME_PITCH sub_quotes {
2538 Pitch p = *unsmob_pitch ($1);
2540 p = p.transposed (Pitch (-$2,0,0));
2541 $$ = p.smobbed_copy ();
2552 pitch_also_in_chords:
2559 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2560 t->set_property ("text", $1);
2561 $$ = t->unprotect ();
2564 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2565 t->set_property ("text",
2566 make_simple_markup ($1));
2567 $$ = t->unprotect ();
2573 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2574 t->set_property ("digit", $1);
2575 $$ = t->unprotect ();
2579 script_abbreviation:
2581 $$ = scm_from_locale_string ("Hat");
2584 $$ = scm_from_locale_string ("Plus");
2587 $$ = scm_from_locale_string ("Dash");
2590 $$ = scm_from_locale_string ("Bar");
2593 $$ = scm_from_locale_string ("Larger");
2596 $$ = scm_from_locale_string ("Dot");
2599 $$ = scm_from_locale_string ("Underscore");
2606 | '-' { $$ = CENTER; }
2610 multiplied_duration {
2615 maybe_notemode_duration:
2619 | multiplied_duration {
2621 parser->default_duration_ = *unsmob_duration ($$);
2626 optional_notemode_duration:
2627 maybe_notemode_duration
2629 if (SCM_UNBNDP ($$))
2630 $$ = parser->default_duration_.smobbed_copy ();
2635 bare_unsigned dots {
2637 if (!is_duration ($1))
2638 parser->parser_error (@1, _f ("not a duration: %d", $1));
2642 $$ = Duration (len, $2).smobbed_copy ();
2644 | DURATION_IDENTIFIER dots {
2645 Duration *d = unsmob_duration ($1);
2646 Duration k (d->duration_log (), d->dot_count () + $2);
2647 k = k.compressed (d->factor ());
2653 multiplied_duration:
2657 | multiplied_duration '*' bare_unsigned {
2658 $$ = unsmob_duration ($$)->compressed ( $3) .smobbed_copy ();
2660 | multiplied_duration '*' FRACTION {
2661 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2663 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2680 | ':' bare_unsigned {
2681 if (!is_duration ($2))
2682 parser->parser_error (@2, _f ("not a duration: %d", $2));
2688 UNSIGNED { $$ = $1; }
2689 | STRING { $$ = $1; }
2690 | full_markup { $$ = $1; }
2693 figured_bass_alteration:
2694 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2695 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2696 | '!' { $$ = scm_from_int (0); }
2701 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2702 $$ = bfr->unprotect ();
2705 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2706 $$ = bfr->self_scm ();
2708 if (scm_is_number ($1))
2709 bfr->set_property ("figure", $1);
2710 else if (Text_interface::is_markup ($1))
2711 bfr->set_property ("text", $1);
2717 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2719 | bass_figure figured_bass_alteration {
2720 Music *m = unsmob_music ($1);
2721 if (scm_to_double ($2)) {
2722 SCM salter = m->get_property ("alteration");
2723 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2724 m->set_property ("alteration",
2725 scm_sum (alter, $2));
2727 m->set_property ("alteration", scm_from_int (0));
2730 | bass_figure figured_bass_modification {
2731 Music *m = unsmob_music ($1);
2732 if ($2 == ly_symbol2scm ("plus"))
2734 m->set_property ("augmented", SCM_BOOL_T);
2736 else if ($2 == ly_symbol2scm ("slash"))
2738 m->set_property ("diminished", SCM_BOOL_T);
2740 else if ($2 == ly_symbol2scm ("exclamation"))
2742 m->set_property ("no-continuation", SCM_BOOL_T);
2744 else if ($2 == ly_symbol2scm ("backslash"))
2746 m->set_property ("augmented-slash", SCM_BOOL_T);
2752 figured_bass_modification:
2754 $$ = ly_symbol2scm ("plus");
2757 $$ = ly_symbol2scm ("exclamation");
2760 $$ = ly_symbol2scm ("slash");
2763 $$ = ly_symbol2scm ("backslash");
2773 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2781 | figure_list br_bass_figure {
2782 $$ = scm_cons ($2, $1);
2787 FIGURE_OPEN figure_list FIGURE_CLOSE {
2788 $$ = scm_reverse_x ($2, SCM_EOL);
2799 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2800 if (!parser->lexer_->is_note_state ())
2801 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2802 if ($2 || $3 || scm_is_number ($4) || !SCM_UNBNDP ($5) || $6)
2806 n = MY_MAKE_MUSIC ("RestEvent", @$);
2808 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2810 n->set_property ("pitch", $1);
2811 if (SCM_UNBNDP ($5))
2812 n->set_property ("duration",
2813 parser->default_duration_.smobbed_copy ());
2815 n->set_property ("duration", $5);
2817 if (scm_is_number ($4))
2819 int q = scm_to_int ($4);
2820 n->set_property ("absolute-octave", scm_from_int (q-1));
2824 n->set_property ("cautionary", SCM_BOOL_T);
2825 if ($2 % 2 || $3 % 2)
2826 n->set_property ("force-accidental", SCM_BOOL_T);
2828 $$ = n->unprotect ();
2831 | DRUM_PITCH optional_notemode_duration {
2832 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2833 n->set_property ("duration", $2);
2834 n->set_property ("drum-type", $1);
2836 $$ = n->unprotect ();
2838 | RESTNAME optional_notemode_duration {
2840 if (ly_scm2string ($1) == "s") {
2842 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2845 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2848 ev->set_property ("duration", $2);
2849 $$ = ev->unprotect ();
2853 simple_chord_elements:
2855 if (!parser->lexer_->is_chord_state ())
2856 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2859 | figure_spec optional_notemode_duration {
2860 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2862 unsmob_music (scm_car (s))->set_property ("duration", $2);
2879 | lyric_element multiplied_duration post_events {
2880 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2881 if (scm_is_pair ($3))
2882 unsmob_music ($$)->set_property
2883 ("articulations", scm_reverse_x ($3, SCM_EOL));
2885 | lyric_element post_event post_events {
2886 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2887 parser->default_duration_.smobbed_copy ());
2888 unsmob_music ($$)->set_property
2889 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2891 | LYRIC_ELEMENT optional_notemode_duration post_events {
2892 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2893 if (scm_is_pair ($3))
2894 unsmob_music ($$)->set_property
2895 ("articulations", scm_reverse_x ($3, SCM_EOL));
2900 lyric_element_music:
2901 lyric_element optional_notemode_duration post_events {
2902 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2903 if (scm_is_pair ($3))
2904 unsmob_music ($$)->set_property
2905 ("articulations", scm_reverse_x ($3, SCM_EOL));
2910 steno_tonic_pitch optional_notemode_duration {
2911 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2913 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2914 SCM its = scm_reverse_x ($4, SCM_EOL);
2915 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2923 | chord_items chord_item {
2924 $$ = scm_cons ($2, $$);
2930 $$ = ly_symbol2scm ("chord-colon");
2933 $$ = ly_symbol2scm ("chord-caret");
2935 | CHORD_SLASH steno_tonic_pitch {
2936 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2938 | CHORD_BASS steno_tonic_pitch {
2939 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2948 $$ = scm_reverse_x ($1, SCM_EOL);
2956 step_number { $$ = scm_cons ($1, SCM_EOL); }
2957 | step_numbers '.' step_number {
2958 $$ = scm_cons ($3, $$);
2964 $$ = make_chord_step ($1, 0);
2966 | bare_unsigned '+' {
2967 $$ = make_chord_step ($1, SHARP_ALTERATION);
2969 | bare_unsigned CHORD_MINUS {
2970 $$ = make_chord_step ($1, FLAT_ALTERATION);
2976 $$ = scm_from_int ($1);
2978 | bare_unsigned '~' bare_unsigned {
2979 $$ = scm_cons (scm_from_int ($1), scm_from_int ($3));
2986 TODO: should deprecate in favor of Scheme?
2990 number_expression '+' number_term {
2991 $$ = scm_sum ($1, $3);
2993 | number_expression '-' number_term {
2994 $$ = scm_difference ($1, $3);
3003 | number_factor '*' number_factor {
3004 $$ = scm_product ($1, $3);
3006 | number_factor '/' number_factor {
3007 $$ = scm_divide ($1, $3);
3012 '-' number_factor { /* %prec UNARY_MINUS */
3013 $$ = scm_difference ($2, SCM_UNDEFINED);
3021 | UNSIGNED NUMBER_IDENTIFIER {
3022 $$ = scm_product ($1, $2);
3024 | REAL NUMBER_IDENTIFIER {
3025 $$ = scm_product ($1, $2);
3037 $$ = scm_to_int ($1);
3048 | exclamations '!' { $$ ++; }
3053 | questions '?' { $$ ++; }
3057 This should be done more dynamically if possible.
3061 LYRIC_MARKUP_IDENTIFIER {
3065 { parser->lexer_->push_markup_state (); }
3068 parser->lexer_->pop_state ();
3073 MARKUPLIST_IDENTIFIER {
3077 { parser->lexer_->push_markup_state (); }
3080 parser->lexer_->pop_state ();
3089 { parser->lexer_->push_markup_state (); }
3092 parser->lexer_->pop_state ();
3098 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3100 | markup_head_1_list simple_markup {
3101 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3111 if (Text_interface::is_markup ($1))
3112 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3113 else if (Text_interface::is_markup_list ($1))
3114 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3116 parser->parser_error (@1, _ ("not a markup"));
3117 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3124 MARKUPLIST_IDENTIFIER {
3127 | markup_composed_list {
3130 | markup_braced_list {
3133 | markup_command_list {
3134 $$ = scm_list_1 ($1);
3136 | markup_scm MARKUPLIST_IDENTIFIER
3142 markup_composed_list:
3143 markup_head_1_list markup_braced_list {
3144 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3150 '{' markup_braced_list_body '}' {
3151 $$ = scm_reverse_x ($2, SCM_EOL);
3155 markup_braced_list_body:
3156 /* empty */ { $$ = SCM_EOL; }
3157 | markup_braced_list_body markup {
3158 $$ = scm_cons ($2, $1);
3160 | markup_braced_list_body markup_list {
3161 $$ = scm_reverse_x ($2, $1);
3165 markup_command_list:
3166 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3167 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3171 markup_command_basic_arguments:
3172 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3173 $$ = scm_cons ($3, $2);
3175 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3176 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3178 | EXPECT_NO_MORE_ARGS {
3183 markup_command_list_arguments:
3184 markup_command_basic_arguments { $$ = $1; }
3185 | EXPECT_MARKUP markup_command_list_arguments markup {
3186 $$ = scm_cons ($3, $2);
3191 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3192 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3197 markup_head_1_item {
3198 $$ = scm_list_1 ($1);
3200 | markup_head_1_list markup_head_1_item {
3201 $$ = scm_cons ($2, $1);
3207 $$ = make_simple_markup ($1);
3209 | MARKUP_IDENTIFIER {
3212 | LYRIC_MARKUP_IDENTIFIER {
3215 | STRING_IDENTIFIER {
3219 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3220 parser->lexer_->push_note_state (nn);
3221 } '{' score_body '}' {
3223 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());
3225 parser->lexer_->pop_state ();
3227 | MARKUP_FUNCTION markup_command_basic_arguments {
3228 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3230 | markup_scm MARKUP_IDENTIFIER
3237 markup_head_1_list simple_markup {
3238 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3239 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3249 Lily_parser::set_yydebug (bool x)
3255 Lily_parser::do_yyparse ()
3266 It is a little strange to have this function in this file, but
3267 otherwise, we have to import music classes into the lexer.
3271 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3273 if (scm_is_string (sid)) {
3275 return STRING_IDENTIFIER;
3276 } else if (unsmob_book (sid)) {
3277 Book *book = unsmob_book (sid)->clone ();
3278 *destination = book->self_scm ();
3281 return BOOK_IDENTIFIER;
3282 } else if (scm_is_number (sid)) {
3284 return NUMBER_IDENTIFIER;
3285 } else if (unsmob_context_def (sid)) {
3286 Context_def *def= unsmob_context_def (sid)->clone ();
3288 *destination = def->self_scm ();
3291 return CONTEXT_DEF_IDENTIFIER;
3292 } else if (unsmob_context_mod (sid)) {
3293 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3295 return CONTEXT_MOD_IDENTIFIER;
3296 } else if (unsmob_score (sid)) {
3297 Score *score = new Score (*unsmob_score (sid));
3298 *destination = score->self_scm ();
3300 score->unprotect ();
3301 return SCORE_IDENTIFIER;
3302 } else if (Music *mus = unsmob_music (sid)) {
3303 mus = mus->clone ();
3304 *destination = mus->self_scm ();
3305 unsmob_music (*destination)->
3306 set_property ("origin", make_input (last_input_));
3308 bool is_event = mus->is_mus_type ("post-event");
3310 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3311 } else if (unsmob_pitch (sid)) {
3312 *destination = unsmob_pitch (sid)->smobbed_copy ();
3313 return PITCH_IDENTIFIER;
3314 } else if (unsmob_duration (sid)) {
3315 *destination = unsmob_duration (sid)->smobbed_copy ();
3316 return DURATION_IDENTIFIER;
3317 } else if (unsmob_output_def (sid)) {
3318 Output_def *p = unsmob_output_def (sid);
3321 *destination = p->self_scm ();
3323 return OUTPUT_DEF_IDENTIFIER;
3324 } else if (Text_interface::is_markup (sid)) {
3326 if (is_lyric_state ())
3327 return LYRIC_MARKUP_IDENTIFIER;
3328 return MARKUP_IDENTIFIER;
3329 } else if (Text_interface::is_markup_list (sid)) {
3331 return MARKUPLIST_IDENTIFIER;
3338 get_next_unique_context_id ()
3340 return scm_from_locale_string ("$uniqueContextId");
3345 get_next_unique_lyrics_context_id ()
3347 static int new_context_count;
3349 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3350 return scm_from_locale_string (s);
3353 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3354 SCM arg, SCM args, SCM pred)
3356 args = scm_cons (arg, args);
3357 if (scm_is_true (scm_call_1 (pred, arg)))
3359 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3360 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3361 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3365 SCM loc_on_music (Input loc, SCM arg)
3367 if (Music *m = unsmob_music (arg))
3371 return m->unprotect ();
3377 is_regular_identifier (SCM id)
3379 string str = ly_scm2string (id);
3380 char const *s = str.c_str ();
3389 v = v && isalnum (*s);
3396 make_music_with_input (SCM name, Input where)
3398 Music *m = make_music_by_name (name);
3399 m->set_spot (where);
3404 make_simple_markup (SCM a)
3412 return t && t == 1 << intlog2 (t);
3416 set_music_properties (Music *p, SCM a)
3418 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3419 p->set_property (scm_caar (k), scm_cdar (k));
3424 make_chord_step (int step, Rational alter)
3427 alter += FLAT_ALTERATION;
3431 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3432 return m.smobbed_copy ();
3437 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3439 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3440 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3441 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3443 unsmob_music (scm_car (s))->set_spot (loc);
3449 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3451 Lily_lexer *lex = parser->lexer_;
3455 lex->prepare_for_next_token ();
3456 return lex->yylex ();