1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
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 */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 char *p = scm_to_locale_string \
45 (scm_simple_format (SCM_BOOL_F, \
46 scm_from_locale_string ("~S"), \
47 scm_list_1 (value))); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 /* ADDLYRICS needs to have lower precedence than argument scanning,
84 * or we won't be able to tell music apart from closed_music without
85 * lookahead in the context of function calls.
90 /* \default is only applied after exhausting function arguments */
92 %nonassoc FUNCTION_ARGLIST
94 /* expressions with units are permitted into argument lists */
96 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
97 UNSIGNED REAL DURATION_IDENTIFIER ':'
99 /* The above are the symbols that can start optional function arguments
100 that are recognized in the grammar rather than by predicate
103 %nonassoc NUMBER_IDENTIFIER '/'
105 /* Number-unit expressions, where permitted, are concatenated into
106 * function arguments, just like fractions and tremoli. Tremoli must
107 * not have higher precedence than UNSIGNED, or Lilypond will not
108 * join ':' with a following optional number.
121 %{ // -*-Fundamental-*-
126 * The rules for who is protecting what are very shady. Uniformise
129 * There are too many lexical modes?
140 #include "context-def.hh"
141 #include "context-mod.hh"
142 #include "dimensions.hh"
143 #include "file-path.hh"
145 #include "international.hh"
146 #include "lily-guile.hh"
147 #include "lily-lexer.hh"
148 #include "lily-parser.hh"
152 #include "output-def.hh"
153 #include "paper-book.hh"
154 #include "scm-hash.hh"
156 #include "text-interface.hh"
160 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, string s)
162 parser->parser_error (*i, s);
165 #define MYBACKUP(Token, Value, Location) \
167 if (yychar == YYEMPTY) \
170 parser->lexer_->push_extra_token (Token, Value); \
171 parser->lexer_->push_extra_token (BACKUP); \
173 parser->parser_error \
174 (Location, _("Too much lookahead")); \
179 #define MYREPARSE(Location, Pred, Token, Value) \
181 if (yychar == YYEMPTY) \
183 parser->lexer_->push_extra_token (Token, Value); \
184 parser->lexer_->push_extra_token (REPARSE, \
187 parser->parser_error \
188 (Location, _("Too much lookahead")); \
197 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
200 - Don't use lily module, create a new module instead.
201 - delay application of the function
203 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
204 scm_apply_0 (proc, args)
205 /* Syntactic Sugar. */
206 #define MAKE_SYNTAX(name, location, ...) \
207 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED))
208 #define START_MAKE_SYNTAX(name, ...) \
209 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
210 #define FINISH_MAKE_SYNTAX(start, location, ...) \
211 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)))))
213 SCM get_next_unique_context_id ();
214 SCM get_next_unique_lyrics_context_id ();
221 #define _(x) gettext (x)
225 static Music *make_music_with_input (SCM name, Input where);
226 SCM check_scheme_arg (Lily_parser *parser, Input loc,
227 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
228 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
229 SCM loc_on_music (Input loc, SCM arg);
230 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
231 SCM make_chord_step (SCM step, Rational alter);
232 SCM make_simple_markup (SCM a);
233 bool is_duration (int t);
234 bool is_regular_identifier (SCM id, bool multiple=false);
235 SCM try_string_variants (SCM pred, SCM str);
236 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
240 /* The third option is an alias that will be used to display the
241 syntax error. Bison CVS now correctly handles backslash escapes.
243 FIXME: Bison needs to translate some of these, eg, STRING.
247 /* Keyword tokens with plain escaped name. */
248 %token END_OF_FILE 0 "end of input"
249 %token ACCEPTS "\\accepts"
250 %token ADDLYRICS "\\addlyrics"
251 %token ALIAS "\\alias"
252 %token ALTERNATIVE "\\alternative"
254 %token BOOKPART "\\bookpart"
255 %token CHANGE "\\change"
256 %token CHORDMODE "\\chordmode"
257 %token CHORDS "\\chords"
258 %token CONSISTS "\\consists"
259 %token CONTEXT "\\context"
260 %token DEFAULT "\\default"
261 %token DEFAULTCHILD "\\defaultchild"
262 %token DENIES "\\denies"
263 %token DESCRIPTION "\\description"
264 %token DRUMMODE "\\drummode"
265 %token DRUMS "\\drums"
266 %token FIGUREMODE "\\figuremode"
267 %token FIGURES "\\figures"
268 %token HEADER "\\header"
269 %token INVALID "\\version-error"
270 %token LAYOUT "\\layout"
271 %token LYRICMODE "\\lyricmode"
272 %token LYRICS "\\lyrics"
273 %token LYRICSTO "\\lyricsto"
274 %token MARKUP "\\markup"
275 %token MARKUPLIST "\\markuplist"
278 %token NOTEMODE "\\notemode"
279 %token OVERRIDE "\\override"
280 %token PAPER "\\paper"
281 %token REMOVE "\\remove"
282 %token REPEAT "\\repeat"
284 %token REVERT "\\revert"
285 %token SCORE "\\score"
286 %token SEQUENTIAL "\\sequential"
288 %token SIMULTANEOUS "\\simultaneous"
289 %token TEMPO "\\tempo"
291 %token UNSET "\\unset"
294 /* Keyword token exceptions. */
295 %token NEWCONTEXT "\\new"
298 /* Other string tokens. */
300 %token CHORD_BASS "/+"
301 %token CHORD_CARET "^"
302 %token CHORD_COLON ":"
303 %token CHORD_MINUS "-"
304 %token CHORD_SLASH "/"
305 %token ANGLE_OPEN "<"
306 %token ANGLE_CLOSE ">"
307 %token DOUBLE_ANGLE_OPEN "<<"
308 %token DOUBLE_ANGLE_CLOSE ">>"
309 %token E_BACKSLASH "\\"
310 %token E_ANGLE_CLOSE "\\>"
311 %token E_CHAR "\\C[haracter]"
313 %token E_EXCLAMATION "\\!"
314 %token E_BRACKET_OPEN "\\["
316 %token E_BRACKET_CLOSE "\\]"
317 %token E_ANGLE_OPEN "\\<"
323 If we give names, Bison complains.
325 %token FIGURE_CLOSE /* "\\>" */
326 %token FIGURE_OPEN /* "\\<" */
327 %token FIGURE_SPACE "_"
330 %token CHORDMODIFIERS
332 %token MULTI_MEASURE_REST
338 /* Artificial tokens, for more generic function syntax */
339 %token EXPECT_MARKUP "markup?"
340 %token EXPECT_PITCH "ly:pitch?"
341 %token EXPECT_DURATION "ly:duration?"
342 %token EXPECT_SCM "scheme?"
343 %token BACKUP "(backed-up?)"
344 %token REPARSE "(reparsed?)"
345 %token EXPECT_MARKUP_LIST "markup-list?"
346 %token EXPECT_OPTIONAL "optional?"
347 /* After the last argument. */
348 %token EXPECT_NO_MORE_ARGS;
350 /* An artificial token for parsing embedded Lilypond */
351 %token EMBEDDED_LILY "#{"
353 %token BOOK_IDENTIFIER
354 %token CHORDMODIFIER_PITCH
355 %token CHORD_MODIFIER
356 %token CHORD_REPETITION
357 %token CONTEXT_DEF_IDENTIFIER
358 %token CONTEXT_MOD_IDENTIFIER
360 %token PITCH_IDENTIFIER
361 %token DURATION_IDENTIFIER
362 %token EVENT_IDENTIFIER
363 %token EVENT_FUNCTION
367 %token MARKUP_FUNCTION
368 %token MARKUP_LIST_FUNCTION
369 %token MARKUP_IDENTIFIER
370 %token MARKUPLIST_IDENTIFIER
371 %token MUSIC_FUNCTION
372 %token MUSIC_IDENTIFIER
373 %token NOTENAME_PITCH
374 %token NUMBER_IDENTIFIER
375 %token OUTPUT_DEF_IDENTIFIER
380 %token SCM_IDENTIFIER
384 %token TONICNAME_PITCH
388 /* We don't assign precedence to / and *, because we might need varied
389 prec levels in different prods */
398 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
399 parser->lexer_->push_note_state (nn);
400 } embedded_lilypond {
401 parser->lexer_->pop_state ();
406 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
407 | lilypond toplevel_expression {
409 | lilypond assignment {
412 parser->error_level_ = 1;
415 parser->error_level_ = 1;
422 parser->lexer_->add_scope (get_header (parser));
424 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
428 scm_call_2 (proc, parser->self_scm (), $1);
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
432 scm_call_2 (proc, parser->self_scm (), $1);
435 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
436 scm_call_2 (proc, parser->self_scm (), $1);
439 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
440 scm_call_2 (proc, parser->self_scm (), $1);
443 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
444 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
447 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
448 scm_call_2 (proc, parser->self_scm (), $1);
451 // Evaluate and ignore #xxx, as opposed to \xxx
452 parser->lexer_->eval_scm_token ($1);
454 | embedded_scm_active
456 SCM out = SCM_UNDEFINED;
457 if (Text_interface::is_markup ($1))
458 out = scm_list_1 ($1);
459 else if (Text_interface::is_markup_list ($1))
461 if (scm_is_pair (out))
463 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
464 scm_call_2 (proc, parser->self_scm (), out);
465 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
466 parser->parser_error (@1, _("bad expression type"));
470 Output_def * od = unsmob_output_def ($1);
472 if (od->c_variable ("is-paper") == SCM_BOOL_T)
473 id = ly_symbol2scm ("$defaultpaper");
474 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
475 id = ly_symbol2scm ("$defaultmidi");
476 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
477 id = ly_symbol2scm ("$defaultlayout");
479 parser->lexer_->set_identifier (id, $1);
486 $$ = parser->lexer_->eval_scm_token ($1);
496 embedded_scm_bare_arg:
500 $$ = parser->lexer_->eval_scm_token ($1);
504 | context_modification
506 | context_def_spec_block
512 /* The generic version may end in music, or not */
520 embedded_scm_bare_arg
526 SCM_FUNCTION function_arglist {
527 $$ = MAKE_SYNTAX ("music-function", @$,
535 $$ = MAKE_SYNTAX ("void-music", @$);
538 | music_embedded music_embedded music_list {
539 $3 = scm_reverse_x ($3, SCM_EOL);
540 if (unsmob_music ($2))
541 $3 = scm_cons ($2, $3);
542 if (unsmob_music ($1))
543 $3 = scm_cons ($1, $3);
544 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
547 parser->error_level_ = 1;
548 $$ = SCM_UNSPECIFIED;
550 | INVALID embedded_lilypond {
551 parser->error_level_ = 1;
557 lilypond_header_body:
558 /* empty */ { $$ = SCM_UNSPECIFIED; }
559 | lilypond_header_body assignment {
562 | lilypond_header_body embedded_scm {
568 HEADER '{' lilypond_header_body '}' {
569 $$ = parser->lexer_->remove_scope ();
578 | LYRICS_STRING { $$ = $1; }
582 assignment_id '=' identifier_init {
583 parser->lexer_->set_identifier ($1, $3);
584 $$ = SCM_UNSPECIFIED;
586 | assignment_id property_path '=' identifier_init {
587 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
588 parser->lexer_->set_identifier (path, $4);
589 $$ = SCM_UNSPECIFIED;
599 | context_def_spec_block
601 | post_event_nofinger
607 | context_modification
610 context_def_spec_block:
611 CONTEXT '{' context_def_spec_body '}'
622 context_mod_embedded:
625 if (unsmob_music ($1)) {
626 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
627 $1 = scm_call_2 (proc, parser->self_scm (), $1);
629 if (unsmob_context_mod ($1))
632 parser->parser_error (@1, _ ("not a context mod"));
638 context_def_spec_body:
640 $$ = Context_def::make_scm ();
641 unsmob_context_def ($$)->origin ()->set_spot (@$);
643 | CONTEXT_DEF_IDENTIFIER {
645 unsmob_context_def ($$)->origin ()->set_spot (@$);
647 | context_def_spec_body context_mod {
648 if (!SCM_UNBNDP ($2))
649 unsmob_context_def ($$)->add_context_mod ($2);
651 | context_def_spec_body context_modification {
652 Context_def *td = unsmob_context_def ($$);
653 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
654 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
655 td->add_context_mod (scm_car (m));
658 | context_def_spec_body context_mod_embedded {
659 Context_def *td = unsmob_context_def ($$);
660 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
661 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
662 td->add_context_mod (scm_car (m));
670 BOOK '{' book_body '}' {
673 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
678 * Use 'handlers' like for toplevel-* stuff?
679 * grok \layout and \midi? */
682 Book *book = new Book;
683 init_papers (parser);
684 book->origin ()->set_spot (@$);
685 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
686 book->paper_->unprotect ();
687 push_paper (parser, book->paper_);
688 book->header_ = get_header (parser);
689 $$ = book->unprotect ();
690 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
693 unsmob_book ($1)->origin ()->set_spot (@$);
694 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
696 | book_body paper_block {
697 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
698 set_paper (parser, unsmob_output_def ($2));
700 | book_body bookpart_block {
701 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
702 scm_call_2 (proc, $1, $2);
704 | book_body score_block {
705 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
706 scm_call_2 (proc, $1, $2);
708 | book_body composite_music {
709 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
710 scm_call_3 (proc, parser->self_scm (), $1, $2);
712 | book_body full_markup {
713 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
714 scm_call_2 (proc, $1, scm_list_1 ($2));
716 | book_body full_markup_list {
717 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
718 scm_call_2 (proc, $1, $2);
720 | book_body SCM_TOKEN {
721 // Evaluate and ignore #xxx, as opposed to \xxx
722 parser->lexer_->eval_scm_token ($2);
724 | book_body embedded_scm_active
726 SCM out = SCM_UNDEFINED;
727 if (Text_interface::is_markup ($2))
728 out = scm_list_1 ($2);
729 else if (Text_interface::is_markup_list ($2))
731 if (scm_is_pair (out))
733 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
734 scm_call_2 (proc, $1, out);
735 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
736 parser->parser_error (@2, _("bad expression type"));
740 parser->lexer_->add_scope (unsmob_book ($1)->header_);
743 Book *book = unsmob_book ($1);
745 book->scores_ = SCM_EOL;
746 book->bookparts_ = SCM_EOL;
751 BOOKPART '{' bookpart_body '}' {
753 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
759 Book *book = new Book;
760 book->origin ()->set_spot (@$);
761 $$ = book->unprotect ();
762 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
765 unsmob_book ($1)->origin ()->set_spot (@$);
766 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
768 | bookpart_body paper_block {
769 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
771 | bookpart_body score_block {
772 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
773 scm_call_2 (proc, $1, $2);
775 | bookpart_body composite_music {
776 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
777 scm_call_3 (proc, parser->self_scm (), $1, $2);
779 | bookpart_body full_markup {
780 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
781 scm_call_2 (proc, $1, scm_list_1 ($2));
783 | bookpart_body full_markup_list {
784 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
785 scm_call_2 (proc, $1, $2);
787 | bookpart_body SCM_TOKEN {
788 // Evaluate and ignore #xxx, as opposed to \xxx
789 parser->lexer_->eval_scm_token ($2);
791 | bookpart_body embedded_scm_active
793 SCM out = SCM_UNDEFINED;
794 if (Text_interface::is_markup ($2))
795 out = scm_list_1 ($2);
796 else if (Text_interface::is_markup_list ($2))
798 if (scm_is_pair (out))
800 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
801 scm_call_2 (proc, $1, out);
802 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
803 parser->parser_error (@2, _("bad expression type"));
807 Book *book = unsmob_book ($1);
808 if (!ly_is_module (book->header_))
809 book->header_ = ly_make_module (false);
810 parser->lexer_->add_scope (book->header_);
812 | bookpart_body error {
813 Book *book = unsmob_book ($1);
815 book->scores_ = SCM_EOL;
820 SCORE '{' score_body '}' {
827 SCM scorify = ly_lily_module_constant ("scorify-music");
828 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
830 unsmob_score ($$)->origin ()->set_spot (@$);
832 | embedded_scm_active {
834 if (unsmob_score ($1))
835 score = new Score (*unsmob_score ($1));
838 parser->parser_error (@1, _("score expected"));
840 unsmob_score ($$)->origin ()->set_spot (@$);
841 $$ = score->unprotect ();
845 Score *score = unsmob_score ($1);
846 if (!ly_is_module (score->get_header ()))
847 score->set_header (ly_make_module (false));
848 parser->lexer_->add_scope (score->get_header ());
850 | score_body output_def {
851 Output_def *od = unsmob_output_def ($2);
852 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
854 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
859 unsmob_score ($1)->add_output_def (od);
863 unsmob_score ($$)->error_found_ = true;
874 Output_def *od = unsmob_output_def ($1);
876 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
878 parser->parser_error (@1, _ ("need \\paper for paper block"));
879 $$ = get_paper (parser)->unprotect ();
886 output_def_body '}' {
889 parser->lexer_->remove_scope ();
890 parser->lexer_->pop_state ();
896 Output_def *p = get_paper (parser);
897 p->input_origin_ = @$;
898 parser->lexer_->add_scope (p->scope_);
899 $$ = p->unprotect ();
902 Output_def *p = get_midi (parser);
903 $$ = p->unprotect ();
904 parser->lexer_->add_scope (p->scope_);
907 Output_def *p = get_layout (parser);
909 parser->lexer_->add_scope (p->scope_);
910 $$ = p->unprotect ();
914 output_def_head_with_mode_switch:
916 parser->lexer_->push_initial_state ();
921 // We need this weird nonterminal because both music as well as a
922 // context definition can start with \context and the difference is
923 // only apparent after looking at the next token. If it is '{', there
924 // is still time to escape from notes mode.
926 music_or_context_def:
929 parser->lexer_->pop_state ();
933 parser->lexer_->pop_state ();
934 } '{' context_def_spec_body '}'
941 output_def_head_with_mode_switch '{' {
943 unsmob_output_def ($$)->input_origin_.set_spot (@$);
945 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
946 Output_def *o = unsmob_output_def ($3);
947 o->input_origin_.set_spot (@$);
949 parser->lexer_->remove_scope ();
950 parser->lexer_->add_scope (o->scope_);
952 | output_def_body assignment {
955 | output_def_body embedded_scm {
960 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
961 parser->lexer_->push_note_state (nn);
962 } music_or_context_def
964 if (unsmob_context_def ($3))
965 assign_context_def (unsmob_output_def ($1), $3);
968 SCM proc = parser->lexer_->lookup_identifier
969 ("output-def-music-handler");
970 scm_call_3 (proc, parser->self_scm (),
974 | output_def_body error {
980 TEMPO steno_duration '=' tempo_range {
981 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
983 | TEMPO scalar_closed steno_duration '=' tempo_range {
984 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
987 $$ = MAKE_SYNTAX ("tempo", @$, $2);
992 The representation of a list is reversed to have efficient append. */
998 | music_list music_embedded {
999 if (unsmob_music ($2))
1000 $$ = scm_cons ($2, $1);
1002 | music_list error {
1003 Music *m = MY_MAKE_MUSIC("Music", @$);
1005 m->set_property ("error-found", SCM_BOOL_T);
1006 $$ = scm_cons (m->self_scm (), $1);
1007 m->unprotect (); /* UGH */
1014 $$ = scm_reverse_x ($2, SCM_EOL);
1019 | lyric_element_music
1026 if (unsmob_music ($1)
1027 || scm_is_eq ($1, SCM_UNSPECIFIED))
1031 @$.warning (_ ("Ignoring non-music expression"));
1032 $$ = SCM_UNSPECIFIED;
1040 $$ = make_music_from_simple (parser, @1, $1);
1041 if (!unsmob_music ($$))
1042 parser->parser_error (@1, _ ("music expected"));
1044 | composite_music %prec COMPOSITE
1049 | composite_music %prec COMPOSITE
1053 REPEAT simple_string unsigned_number music
1055 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1057 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1059 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1064 SEQUENTIAL braced_music_list {
1065 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1067 | braced_music_list {
1068 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1073 SIMULTANEOUS braced_music_list {
1074 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1076 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1077 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1083 | music_property_def
1087 context_modification:
1088 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1090 parser->lexer_->pop_state ();
1093 | WITH CONTEXT_MOD_IDENTIFIER
1097 | CONTEXT_MOD_IDENTIFIER
1101 | WITH embedded_scm_closed
1103 if (unsmob_context_mod ($2))
1106 parser->parser_error (@2, _ ("not a context mod"));
1107 $$ = Context_mod ().smobbed_copy ();
1112 optional_context_mod:
1116 | context_modification
1124 $$ = Context_mod ().smobbed_copy ();
1126 | context_mod_list context_mod {
1127 if (!SCM_UNBNDP ($2))
1128 unsmob_context_mod ($1)->add_context_mod ($2);
1130 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1131 Context_mod *md = unsmob_context_mod ($2);
1133 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1135 | context_mod_list context_mod_embedded {
1136 unsmob_context_mod ($1)->add_context_mods
1137 (unsmob_context_mod ($2)->get_mods ());
1146 /* Music that can be parsed without lookahead */
1149 | complex_music_prefix closed_music
1151 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1153 | music_function_call_closed
1159 | grouped_music_list
1163 simultaneous_music { $$ = $1; }
1164 | sequential_music { $$ = $1; }
1167 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1168 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1169 and this rule returns the reversed list of arguments. */
1171 /* Function argument lists come in a number of flavors. Whenever
1172 * LilyPond has to pick between different flavors, the decision is
1173 * either made because of tokens it has already seen, or it is
1174 * postponed until tokens suitable for making the decision come up.
1175 * For postponing decisions, it may be necessary that the competing
1176 * rules are written in a way making them compatible until a decision
1177 * can be made. Sometimes this is done by putting common traits into
1178 * a separate "common" rule set.
1180 * function_arglist: a full argument list. Optional arguments at the
1181 * end of the list can only be skipped by writing \default in their
1184 * function_arglist_backup: an argument list ending in an optional
1185 * argument that may be skipped depending on its predicate.
1187 * function_arglist_skip: an argument list _not_ ending in an optional
1188 * argument that is actually taken.
1190 * function_arglist_nonbackup: an argument list ending in an optional
1191 * argument that may not be skipped because it is in end position and
1192 * has not been shortcircuited with \default.
1194 * function_arglist* / function_arglist_closed*: The closed variants
1195 * don't end in simple music expressions that might still accept
1196 * things like a duration or a postevent.
1199 function_arglist_skip:
1200 function_arglist_common
1201 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1203 $$ = scm_cons ($1, $3);
1204 } %prec FUNCTION_ARGLIST
1205 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1207 $$ = scm_cons ($1, $3);
1208 } %prec FUNCTION_ARGLIST
1209 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1211 $$ = scm_cons ($1, $3);
1212 } %prec FUNCTION_ARGLIST
1216 function_arglist_nonbackup_common:
1217 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1218 $$ = scm_cons ($4, $3);
1220 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1221 $$ = scm_cons ($4, $3);
1223 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1225 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1227 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1229 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1231 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1233 SCM n = scm_difference ($5, SCM_UNDEFINED);
1234 if (scm_is_true (scm_call_1 ($2, n)))
1235 $$ = scm_cons (n, $3);
1237 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1238 t->set_property ("digit", $5);
1239 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1244 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1246 $$ = check_scheme_arg (parser, @4,
1247 scm_difference ($5, SCM_UNDEFINED),
1250 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1252 $$ = check_scheme_arg (parser, @4,
1253 scm_difference ($5, SCM_UNDEFINED),
1258 function_arglist_closed_nonbackup:
1259 function_arglist_nonbackup_common
1260 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1262 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1264 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1266 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1268 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1270 $$ = check_scheme_arg (parser, @4,
1271 try_string_variants ($2, $4),
1274 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1276 $$ = check_scheme_arg (parser, @4,
1277 try_string_variants ($2, $4),
1280 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_STRING
1282 $$ = check_scheme_arg (parser, @4,
1283 try_string_variants ($2, $4),
1286 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1288 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1294 | SYMBOL_LIST '.' symbol_list_rev
1296 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1302 | symbol_list_rev '.' symbol_list_part
1304 $$ = scm_append_x (scm_list_2 ($3, $1));
1308 // symbol_list_part delivers elements in reverse copy.
1313 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1314 $$ = try_string_variants (sym_l_p, $1);
1315 if (SCM_UNBNDP ($$)) {
1316 parser->parser_error (@1, _("not a symbol"));
1319 $$ = scm_reverse ($$);
1324 symbol_list_element:
1331 function_arglist_nonbackup:
1332 function_arglist_nonbackup_common
1333 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1335 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1337 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1339 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1341 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1343 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1345 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1347 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1349 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1351 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1355 function_arglist_nonbackup_reparse:
1356 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1359 SCM res = try_string_variants ($2, $4);
1360 if (!SCM_UNBNDP (res))
1361 if (scm_is_pair (res))
1362 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1364 MYREPARSE (@4, $2, SCM_ARG, res);
1365 else if (scm_is_true
1367 ($2, make_music_from_simple
1369 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1371 MYREPARSE (@4, $2, SCM_ARG, $4);
1373 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_STRING
1376 SCM res = try_string_variants ($2, $4);
1377 if (!SCM_UNBNDP (res))
1378 if (scm_is_pair (res))
1379 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1381 MYREPARSE (@4, $2, SCM_ARG, res);
1382 else if (scm_is_true
1384 ($2, make_music_from_simple
1386 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1388 MYREPARSE (@4, $2, SCM_ARG, $4);
1390 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1393 SCM res = try_string_variants ($2, $4);
1394 if (!SCM_UNBNDP (res))
1395 if (scm_is_pair (res))
1396 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1398 MYREPARSE (@4, $2, SCM_ARG, res);
1400 MYREPARSE (@4, $2, SCM_ARG, $4);
1402 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1405 if (scm_is_true (scm_call_1 ($2, $4)))
1406 MYREPARSE (@4, $2, SCM_ARG, $4);
1407 else if (scm_is_true
1409 ($2, make_music_from_simple
1411 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1413 MYREPARSE (@4, $2, SCM_ARG, $4);
1417 function_arglist_keep:
1418 function_arglist_common
1419 | function_arglist_backup
1422 function_arglist_closed_keep:
1423 function_arglist_closed_common
1424 | function_arglist_backup
1427 function_arglist_backup:
1428 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1430 if (scm_is_true (scm_call_1 ($2, $4)))
1432 $$ = scm_cons ($4, $3);
1434 $$ = scm_cons (loc_on_music (@3, $1), $3);
1435 MYBACKUP (SCM_ARG, $4, @4);
1438 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1440 if (scm_is_true (scm_call_1 ($2, $4)))
1442 $$ = scm_cons ($4, $3);
1444 $$ = scm_cons (loc_on_music (@3, $1), $3);
1445 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1448 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_markup
1450 if (scm_is_true (scm_call_1 ($2, $4)))
1451 $$ = scm_cons ($4, $3);
1453 $$ = scm_cons (loc_on_music (@3, $1), $3);
1454 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1457 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1459 if (scm_is_true (scm_call_1 ($2, $4)))
1462 MYREPARSE (@4, $2, UNSIGNED, $4);
1464 $$ = scm_cons (loc_on_music (@3, $1), $3);
1465 MYBACKUP (UNSIGNED, $4, @4);
1468 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1470 if (scm_is_true (scm_call_1 ($2, $4)))
1473 MYREPARSE (@4, $2, REAL, $4);
1475 $$ = scm_cons (loc_on_music (@3, $1), $3);
1476 MYBACKUP (REAL, $4, @4);
1479 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1481 if (scm_is_true (scm_call_1 ($2, $4)))
1483 $$ = scm_cons ($4, $3);
1485 $$ = scm_cons (loc_on_music (@3, $1), $3);
1486 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1489 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1491 if (scm_is_true (scm_call_1 ($2, $4)))
1493 $$ = scm_cons ($4, $3);
1495 $$ = scm_cons (loc_on_music (@3, $1), $3);
1496 MYBACKUP (FRACTION, $4, @4);
1499 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1501 SCM n = scm_difference ($5, SCM_UNDEFINED);
1502 if (scm_is_true (scm_call_1 ($2, n))) {
1504 MYREPARSE (@5, $2, REAL, n);
1506 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1507 t->set_property ("digit", $5);
1508 $$ = t->unprotect ();
1509 if (scm_is_true (scm_call_1 ($2, $$)))
1510 $$ = scm_cons ($$, $3);
1512 $$ = scm_cons (loc_on_music (@3, $1), $3);
1513 MYBACKUP (UNSIGNED, $5, @5);
1514 parser->lexer_->push_extra_token ('-');
1519 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1521 SCM n = scm_difference ($5, SCM_UNDEFINED);
1522 if (scm_is_true (scm_call_1 ($2, n))) {
1523 MYREPARSE (@5, $2, REAL, n);
1526 $$ = scm_cons (loc_on_music (@3, $1), $3);
1527 MYBACKUP (REAL, n, @5);
1530 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1532 SCM n = scm_difference ($5, SCM_UNDEFINED);
1533 if (scm_is_true (scm_call_1 ($2, n))) {
1534 $$ = scm_cons (n, $3);
1536 $$ = scm_cons (loc_on_music (@3, $1), $3);
1537 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1540 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1542 $$ = scm_cons ($4, $3);
1544 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1546 $$ = scm_cons ($4, $3);
1548 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1550 SCM res = try_string_variants ($2, $4);
1551 if (!SCM_UNBNDP (res))
1552 if (scm_is_pair (res)) {
1554 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1557 $$ = scm_cons (res, $3);
1559 $$ = scm_cons (loc_on_music (@3, $1), $3);
1560 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1563 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1565 SCM res = try_string_variants ($2, $4);
1566 if (!SCM_UNBNDP (res))
1567 if (scm_is_pair (res)) {
1569 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1572 $$ = scm_cons (res, $3);
1574 $$ = scm_cons (loc_on_music (@3, $1), $3);
1575 MYBACKUP (STRING, $4, @4);
1578 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep LYRICS_STRING
1580 SCM res = try_string_variants ($2, $4);
1581 if (!SCM_UNBNDP (res))
1582 if (scm_is_pair (res)) {
1584 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1587 $$ = scm_cons (res, $3);
1589 $$ = scm_cons (loc_on_music (@3, $1), $3);
1590 MYBACKUP (LYRICS_STRING, $4, @4);
1593 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1595 $$ = scm_cons ($1, $3);
1596 MYBACKUP(0, SCM_UNDEFINED, @3);
1598 | function_arglist_backup REPARSE bare_number
1600 $$ = check_scheme_arg (parser, @3,
1603 | function_arglist_backup REPARSE symbol_list_arg
1605 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1610 function_arglist_common
1611 | function_arglist_nonbackup
1614 function_arglist_common:
1615 function_arglist_bare
1616 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1618 $$ = check_scheme_arg (parser, @3,
1621 | EXPECT_SCM function_arglist_closed_optional bare_number
1623 $$ = check_scheme_arg (parser, @3,
1626 | EXPECT_SCM function_arglist_optional FRACTION
1628 $$ = check_scheme_arg (parser, @3,
1631 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1633 $$ = check_scheme_arg (parser, @3,
1636 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1638 SCM n = scm_difference ($4, SCM_UNDEFINED);
1639 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1641 | function_arglist_common_reparse REPARSE SCM_ARG
1643 $$ = check_scheme_arg (parser, @3,
1646 | function_arglist_common_reparse REPARSE lyric_element_music
1648 $$ = check_scheme_arg (parser, @3,
1651 | function_arglist_common_reparse REPARSE bare_number
1653 $$ = check_scheme_arg (parser, @3,
1656 | function_arglist_common_reparse REPARSE symbol_list_arg
1658 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1662 function_arglist_common_reparse:
1663 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1666 SCM res = try_string_variants ($1, $3);
1667 if (!SCM_UNBNDP (res))
1668 if (scm_is_pair (res))
1669 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1671 MYREPARSE (@3, $1, SCM_ARG, res);
1672 else if (scm_is_true
1674 ($1, make_music_from_simple (parser, @3, $3))))
1675 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1677 // This is going to flag a syntax error, we
1678 // know the predicate to be false.
1679 MYREPARSE (@3, $1, SCM_ARG, $3);
1681 | EXPECT_SCM function_arglist_optional STRING
1684 SCM res = try_string_variants ($1, $3);
1685 if (!SCM_UNBNDP (res))
1686 if (scm_is_pair (res))
1687 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1689 MYREPARSE (@3, $1, SCM_ARG, res);
1691 // This is going to flag a syntax error, we
1692 // know the predicate to be false.
1693 MYREPARSE (@3, $1, SCM_ARG, $3);
1695 | EXPECT_SCM function_arglist_optional LYRICS_STRING
1698 SCM res = try_string_variants ($1, $3);
1699 if (!SCM_UNBNDP (res))
1700 if (scm_is_pair (res))
1701 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1703 MYREPARSE (@3, $1, SCM_ARG, res);
1704 else if (scm_is_true
1706 ($1, make_music_from_simple (parser, @3, $3))))
1707 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1709 // This is going to flag a syntax error, we
1710 // know the predicate to be false.
1711 MYREPARSE (@3, $1, SCM_ARG, $3);
1713 | EXPECT_SCM function_arglist_optional lyric_markup
1716 if (scm_is_true (scm_call_1 ($1, $3)))
1717 MYREPARSE (@3, $1, SCM_ARG, $3);
1718 else if (scm_is_true
1720 ($1, make_music_from_simple (parser, @3, $3))))
1721 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1723 // This is going to flag a syntax error, we
1724 // know the predicate to be false.
1725 MYREPARSE (@3, $1, SCM_ARG, $3);
1727 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1730 SCM n = scm_difference ($4, SCM_UNDEFINED);
1731 if (scm_is_true (scm_call_1 ($1, n)))
1732 MYREPARSE (@4, $1, REAL, n);
1734 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1735 t->set_property ("digit", $4);
1736 SCM m = t->unprotect ();
1737 if (scm_is_true (scm_call_1 ($1, m)))
1738 MYREPARSE (@4, $1, SCM_ARG, m);
1740 MYREPARSE (@4, $1, SCM_ARG, $4);
1744 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1747 SCM n = scm_difference ($4, SCM_UNDEFINED);
1748 MYREPARSE (@4, $1, REAL, n);
1752 function_arglist_closed:
1753 function_arglist_closed_common
1754 | function_arglist_closed_nonbackup
1757 function_arglist_closed_common:
1758 function_arglist_bare
1759 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1761 $$ = check_scheme_arg (parser, @3,
1764 | EXPECT_SCM function_arglist_closed_optional bare_number
1766 $$ = check_scheme_arg (parser, @3,
1769 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1771 $$ = check_scheme_arg (parser, @3,
1772 scm_difference ($4, SCM_UNDEFINED),
1775 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1777 $$ = check_scheme_arg (parser, @3,
1780 | EXPECT_SCM function_arglist_optional FRACTION
1782 $$ = check_scheme_arg (parser, @3,
1785 | function_arglist_common_reparse REPARSE SCM_ARG
1787 $$ = check_scheme_arg (parser, @3,
1790 | function_arglist_common_reparse REPARSE bare_number
1792 $$ = check_scheme_arg (parser, @3,
1795 | function_arglist_common_reparse REPARSE symbol_list_arg
1797 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1801 function_arglist_optional:
1802 function_arglist_keep %prec FUNCTION_ARGLIST
1803 | function_arglist_backup BACKUP
1804 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1806 $$ = scm_cons ($1, $3);
1808 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1810 $$ = scm_cons ($1, $3);
1814 function_arglist_closed_optional:
1815 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1816 | function_arglist_backup BACKUP
1817 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1819 $$ = scm_cons ($1, $3);
1821 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1823 $$ = scm_cons ($1, $3);
1827 embedded_scm_closed:
1829 | scm_function_call_closed
1832 embedded_scm_arg_closed:
1833 embedded_scm_bare_arg
1834 | scm_function_call_closed
1838 scm_function_call_closed:
1839 SCM_FUNCTION function_arglist_closed {
1840 $$ = MAKE_SYNTAX ("music-function", @$,
1842 } %prec FUNCTION_ARGLIST
1845 function_arglist_bare:
1846 EXPECT_NO_MORE_ARGS {
1849 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1850 $$ = scm_cons ($3, $2);
1852 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1853 $$ = scm_cons ($3, $2);
1855 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1856 $$ = scm_cons ($1, $3);
1858 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1859 $$ = scm_cons ($1, $3);
1861 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1862 $$ = scm_cons ($1, $3);
1866 music_function_call:
1867 MUSIC_FUNCTION function_arglist {
1868 $$ = MAKE_SYNTAX ("music-function", @$,
1875 /**/ { $$ = SCM_EOL; }
1876 | '=' simple_string {
1883 | repeated_music { $$ = $1; }
1884 | re_rhythmed_music { $$ = $1; }
1885 | complex_music_prefix music
1887 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1891 complex_music_prefix:
1892 CONTEXT simple_string optional_id optional_context_mod {
1893 Context_mod *ctxmod = unsmob_context_mod ($4);
1896 mods = ctxmod->get_mods ();
1897 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1899 | NEWCONTEXT simple_string optional_id optional_context_mod {
1900 Context_mod *ctxmod = unsmob_context_mod ($4);
1903 mods = ctxmod->get_mods ();
1904 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1909 mode_changing_head grouped_music_list {
1910 if ($1 == ly_symbol2scm ("chords"))
1912 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1918 parser->lexer_->pop_state ();
1920 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1921 Context_mod *ctxmod = unsmob_context_mod ($2);
1924 mods = ctxmod->get_mods ();
1925 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1926 if ($1 == ly_symbol2scm ("ChordNames"))
1928 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1930 parser->lexer_->pop_state ();
1936 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1937 parser->lexer_->push_note_state (nn);
1939 $$ = ly_symbol2scm ("notes");
1943 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1944 parser->lexer_->push_note_state (nn);
1946 $$ = ly_symbol2scm ("drums");
1949 parser->lexer_->push_figuredbass_state ();
1951 $$ = ly_symbol2scm ("figures");
1954 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1955 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1956 nn = parser->lexer_->lookup_identifier ("pitchnames");
1957 parser->lexer_->push_chord_state (nn);
1958 $$ = ly_symbol2scm ("chords");
1962 { parser->lexer_->push_lyric_state ();
1963 $$ = ly_symbol2scm ("lyrics");
1967 mode_changing_head_with_context:
1969 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1970 parser->lexer_->push_note_state (nn);
1972 $$ = ly_symbol2scm ("DrumStaff");
1975 parser->lexer_->push_figuredbass_state ();
1977 $$ = ly_symbol2scm ("FiguredBass");
1980 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1981 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1982 nn = parser->lexer_->lookup_identifier ("pitchnames");
1983 parser->lexer_->push_chord_state (nn);
1984 $$ = ly_symbol2scm ("ChordNames");
1987 { parser->lexer_->push_lyric_state ();
1988 $$ = ly_symbol2scm ("Lyrics");
1993 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1996 /* Can also use music at the expensive of two S/Rs similar to
1997 \repeat \alternative */
1998 parser->lexer_->pop_state ();
2000 $$ = scm_cons ($3, SCM_EOL);
2002 | new_lyrics ADDLYRICS {
2003 parser->lexer_->push_lyric_state ();
2005 parser->lexer_->pop_state ();
2006 $$ = scm_cons ($4, $1);
2011 composite_music new_lyrics {
2012 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2014 | LYRICSTO simple_string {
2015 parser->lexer_->push_lyric_state ();
2017 parser->lexer_->pop_state ();
2018 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2023 CHANGE STRING '=' STRING {
2024 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2031 $$ = scm_reverse_x ($1, SCM_EOL);
2033 | symbol_list_rev property_path {
2034 $$ = scm_reverse_x ($1, $2);
2040 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2041 scm_string_to_symbol ($1), $3);
2043 | UNSET simple_string {
2044 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2045 scm_string_to_symbol ($2));
2047 | OVERRIDE property_path '=' scalar {
2048 if (scm_ilength ($2) < 2) {
2049 parser->parser_error (@2, _("bad grob property path"));
2052 $$ = scm_cons (ly_symbol2scm ("push"),
2053 scm_cons2 (scm_car ($2),
2058 | REVERT revert_arg {
2059 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2065 // This is all quite awkward for the sake of substantial backward
2066 // compatibility while at the same time allowing a more "natural" form
2067 // of specification not separating grob specification from grob
2068 // property path. The purpose of this definition of revert_arg is to
2069 // allow the symbol list which specifies grob and property to revert
2070 // to be optionally be split into two parts after the grob (which in
2071 // this case is just the first element of the list). symbol_list_part
2072 // is only one path component, but it can be parsed without lookahead,
2073 // so we can follow it with a synthetic BACKUP token when needed. If
2074 // the first symbol_list_part already contains multiple elements (only
2075 // possible if a Scheme expression provides them), we just parse for
2076 // additional elements introduced by '.', which is what the
2077 // SYMBOL_LIST backup in connection with the immediately following
2078 // rule using symbol_list_arg does.
2080 // As long as we don't have our coffers filled with both grob and at
2081 // least one grob property specification, the rest of the required
2082 // symbol list chain may be provided either with or without a leading
2083 // dot. This is for both allowing the traditional
2084 // \revert Accidental #'color
2085 // as well as well as the "naive" form
2086 // \revert Accidental.color
2091 if (scm_is_null ($1)
2092 || scm_is_null (scm_cdr ($1)))
2093 MYBACKUP (SCM_ARG, $1, @1);
2095 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2097 | revert_arg BACKUP symbol_list_arg
2103 // revert_arg_part delivers results in reverse
2106 | revert_arg BACKUP SCM_ARG '.' symbol_list_part
2108 $$ = scm_append_x (scm_list_2 ($5, $3));
2110 | revert_arg BACKUP SCM_ARG symbol_list_part
2112 $$ = scm_append_x (scm_list_2 ($4, $3));
2117 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2118 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2120 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2121 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2122 | DENIES { $$ = ly_symbol2scm ("denies"); }
2124 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2125 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2126 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2127 | NAME { $$ = ly_symbol2scm ("context-name"); }
2131 property_operation { $$ = $1; }
2132 | context_def_mod STRING {
2133 $$ = scm_list_2 ($1, $2);
2135 | context_def_mod embedded_scm
2137 if (!scm_is_string ($2)
2138 && ly_symbol2scm ("consists") != $1
2139 && ly_symbol2scm ("remove") != $1)
2142 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2146 $$ = scm_list_2 ($1, $2);
2151 // If defined, at least two members.
2155 SCM l = scm_reverse_x ($1, SCM_EOL);
2158 (scm_object_property (scm_car (l),
2159 ly_symbol2scm ("is-grob?"))))
2160 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2161 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2162 parser->parser_error (@1, _ ("bad grob property path"));
2169 // If defined, at least three members
2173 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2175 parser->parser_error (@1, _ ("bad grob property path"));
2179 | grob_prop_spec property_path
2181 if (!SCM_UNBNDP ($1)) {
2182 $$ = scm_append_x (scm_list_2 ($1, $2));
2183 if (scm_is_null (scm_cddr ($$))) {
2184 parser->parser_error (@$, _ ("bad grob property path"));
2192 // Exactly two elements or undefined
2196 SCM l = scm_reverse_x ($1, SCM_EOL);
2197 switch (scm_ilength (l)) {
2199 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2203 parser->parser_error (@1, _ ("bad context property path"));
2210 simple_music_property_def:
2211 OVERRIDE grob_prop_path '=' scalar {
2212 if (SCM_UNBNDP ($2))
2215 $$ = scm_list_5 (scm_car ($2),
2216 ly_symbol2scm ("OverrideProperty"),
2222 | REVERT simple_revert_context revert_arg {
2223 $$ = scm_list_4 ($2,
2224 ly_symbol2scm ("RevertProperty"),
2228 | SET context_prop_spec '=' scalar {
2229 if (SCM_UNBNDP ($2))
2232 $$ = scm_list_4 (scm_car ($2),
2233 ly_symbol2scm ("PropertySet"),
2237 | UNSET context_prop_spec {
2238 if (SCM_UNBNDP ($2))
2241 $$ = scm_list_3 (scm_car ($2),
2242 ly_symbol2scm ("PropertyUnset"),
2248 // This is all quite awkward for the sake of substantial backward
2249 // compatibility while at the same time allowing a more "natural" form
2250 // of specification not separating grob specification from grob
2251 // property path. The purpose of this definition of
2252 // simple_revert_context is to allow the symbol list which specifies
2253 // grob and property to revert to be optionally be split into two
2254 // parts after the grob (which may be preceded by a context
2255 // specification, a case which we distinguish by checking whether the
2256 // first symbol is a valid grob symbol instead).
2258 // See revert_arg above for the main work horse of this arrangement.
2259 // simple_revert_context just caters for the context and delegates the
2260 // rest of the job to revert_arg.
2262 simple_revert_context:
2265 $1 = scm_reverse_x ($1, SCM_EOL);
2266 if (scm_is_null ($1)
2268 (scm_object_property (scm_car ($1),
2269 ly_symbol2scm ("is-grob?")))) {
2270 $$ = ly_symbol2scm ("Bottom");
2271 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2274 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2281 simple_music_property_def {
2282 if (SCM_UNBNDP ($1))
2283 $$ = MAKE_SYNTAX ("void-music", @1);
2285 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2294 | string '+' string {
2295 if (!scm_is_string ($1)) {
2296 parser->parser_error (@1, (_ ("simple string expected")));
2297 $1 = scm_string (SCM_EOL);
2299 if (!scm_is_string ($3)) {
2300 parser->parser_error (@3, (_ ("simple string expected")));
2301 $3 = scm_string (SCM_EOL);
2303 $$ = scm_string_append (scm_list_2 ($1, $3));
2307 simple_string: STRING {
2315 if (scm_is_string ($1)) {
2318 parser->parser_error (@1, (_ ("simple string expected")));
2319 $$ = scm_string (SCM_EOL);
2334 embedded_scm_arg_closed
2344 simple_element post_events {
2345 // Let the rhythmic music iterator sort this mess out.
2346 if (scm_is_pair ($2)) {
2347 $$ = make_music_from_simple (parser, @1, $1);
2348 if (unsmob_music ($$))
2349 unsmob_music ($$)->set_property ("articulations",
2350 scm_reverse_x ($2, SCM_EOL));
2352 parser->parser_error (@1, _("music expected"));
2355 | simple_chord_elements post_events {
2356 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2359 /* why is this giving wrong start location? -ns
2361 i.set_location (@1, @2);
2362 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2364 | CHORD_REPETITION optional_notemode_duration post_events {
2366 i.set_location (@1, @3);
2367 $$ = MAKE_SYNTAX ("repetition-chord", i,
2368 $2, scm_reverse_x ($3, SCM_EOL));
2370 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2372 i.set_location (@1, @3);
2373 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2374 scm_reverse_x ($3, SCM_EOL));
2377 | note_chord_element
2382 chord_body optional_notemode_duration post_events
2384 Music *m = unsmob_music ($1);
2385 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2386 SCM es = m->get_property ("elements");
2387 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2389 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2390 unsmob_music (scm_car (s))->set_property ("duration", dur);
2391 es = ly_append2 (es, postevs);
2393 m-> set_property ("elements", es);
2395 $$ = m->self_scm ();
2400 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2402 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2406 chord_body_elements:
2407 /* empty */ { $$ = SCM_EOL; }
2408 | chord_body_elements chord_body_element {
2409 if (!SCM_UNBNDP ($2))
2410 $$ = scm_cons ($2, $1);
2415 pitch exclamations questions octave_check post_events
2417 bool q = to_boolean ($3);
2418 bool ex = to_boolean ($2);
2422 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2423 n->set_property ("pitch", $1);
2425 n->set_property ("cautionary", SCM_BOOL_T);
2427 n->set_property ("force-accidental", SCM_BOOL_T);
2429 if (scm_is_pair (post)) {
2430 SCM arts = scm_reverse_x (post, SCM_EOL);
2431 n->set_property ("articulations", arts);
2433 if (scm_is_number (check))
2435 int q = scm_to_int (check);
2436 n->set_property ("absolute-octave", scm_from_int (q-1));
2439 $$ = n->unprotect ();
2441 | DRUM_PITCH post_events {
2442 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2443 n->set_property ("drum-type", $1);
2445 if (scm_is_pair ($2)) {
2446 SCM arts = scm_reverse_x ($2, SCM_EOL);
2447 n->set_property ("articulations", arts);
2449 $$ = n->unprotect ();
2451 | music_function_chord_body
2453 Music *m = unsmob_music ($1);
2455 while (m && m->is_mus_type ("music-wrapper-music")) {
2456 $$ = m->get_property ("element");
2457 m = unsmob_music ($$);
2460 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2461 parser->parser_error (@$, _ ("not a rhythmic event"));
2467 music_function_chord_body:
2472 // Event functions may only take closed arglists, otherwise it would
2473 // not be clear whether a following postevent should be associated
2474 // with the last argument of the event function or with the expression
2475 // for which the function call acts itself as event.
2477 music_function_call_closed:
2478 MUSIC_FUNCTION function_arglist_closed {
2479 $$ = MAKE_SYNTAX ("music-function", @$,
2484 event_function_event:
2485 EVENT_FUNCTION function_arglist_closed {
2486 $$ = MAKE_SYNTAX ("music-function", @$,
2496 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2497 m->set_property ("span-direction", scm_from_int (START));
2498 $$ = m->unprotect();
2501 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2502 m->set_property ("span-direction", scm_from_int (STOP));
2503 $$ = m->unprotect ();
2506 $$ = MAKE_SYNTAX ("voice-separator", @$);
2509 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2511 Music *m = unsmob_music (pipe);
2516 $$ = m->unprotect ();
2519 $$ = MAKE_SYNTAX ("bar-check", @$);
2526 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2538 | post_events post_event {
2539 unsmob_music ($2)->set_spot (@2);
2540 $$ = scm_cons ($2, $$);
2544 post_event_nofinger:
2545 direction_less_event {
2548 | script_dir music_function_call_closed {
2550 if (!SCM_UNBNDP ($1))
2552 unsmob_music ($$)->set_property ("direction", $1);
2556 if (!parser->lexer_->is_lyric_state ())
2557 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2558 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2561 if (!parser->lexer_->is_lyric_state ())
2562 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2563 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2565 | script_dir direction_reqd_event {
2566 if (!SCM_UNBNDP ($1))
2568 Music *m = unsmob_music ($2);
2569 m->set_property ("direction", $1);
2573 | script_dir direction_less_event {
2574 if (!SCM_UNBNDP ($1))
2576 Music *m = unsmob_music ($2);
2577 m->set_property ("direction", $1);
2584 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2589 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2600 string_number_event:
2602 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2603 s->set_property ("string-number", $1);
2604 $$ = s->unprotect ();
2608 direction_less_char:
2610 $$ = ly_symbol2scm ("bracketOpenSymbol");
2613 $$ = ly_symbol2scm ("bracketCloseSymbol");
2616 $$ = ly_symbol2scm ("tildeSymbol");
2619 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2622 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2625 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2628 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2631 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2634 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2637 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2641 direction_less_event:
2642 direction_less_char {
2643 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2645 if (unsmob_music (predefd))
2647 m = unsmob_music (predefd)->clone ();
2652 m = MY_MAKE_MUSIC ("Music", @$);
2654 $$ = m->unprotect ();
2656 | string_number_event
2657 | EVENT_IDENTIFIER {
2661 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2662 a->set_property ("tremolo-type", $1);
2663 $$ = a->unprotect ();
2665 | event_function_event
2668 direction_reqd_event:
2672 | script_abbreviation {
2673 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2674 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2675 if (scm_is_string (s))
2676 a->set_property ("articulation-type", s);
2677 else parser->parser_error (@1, _ ("expecting string as script definition"));
2678 $$ = a->unprotect ();
2683 /**/ { $$ = SCM_EOL; }
2684 | '=' quotes { $$ = $2; }
2698 $$ = scm_from_int (1);
2701 $$ = scm_oneplus ($1);
2707 $$ = scm_from_int (-1);
2710 $$ = scm_oneminus ($1);
2715 NOTENAME_PITCH quotes {
2716 if (!scm_is_eq (SCM_INUM0, $2))
2718 Pitch p = *unsmob_pitch ($1);
2719 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2720 $$ = p.smobbed_copy ();
2730 TONICNAME_PITCH quotes {
2731 if (!scm_is_eq (SCM_INUM0, $2))
2733 Pitch p = *unsmob_pitch ($1);
2734 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2735 $$ = p.smobbed_copy ();
2745 pitch_also_in_chords:
2752 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2753 t->set_property ("text", $1);
2754 $$ = t->unprotect ();
2757 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2758 t->set_property ("text",
2759 make_simple_markup ($1));
2760 $$ = t->unprotect ();
2763 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2764 t->set_property ("text",
2765 make_simple_markup ($1));
2766 $$ = t->unprotect ();
2768 | embedded_scm_closed
2770 Music *m = unsmob_music ($1);
2771 if (m && m->is_mus_type ("post-event"))
2773 else if (Text_interface::is_markup ($1)) {
2774 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2775 t->set_property ("text", $1);
2776 $$ = t->unprotect ();
2778 parser->parser_error (@1, _ ("not an articulation"));
2784 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2785 t->set_property ("digit", $1);
2786 $$ = t->unprotect ();
2790 script_abbreviation:
2792 $$ = scm_from_locale_string ("Hat");
2795 $$ = scm_from_locale_string ("Plus");
2798 $$ = scm_from_locale_string ("Dash");
2801 $$ = scm_from_locale_string ("Bar");
2804 $$ = scm_from_locale_string ("Larger");
2807 $$ = scm_from_locale_string ("Dot");
2810 $$ = scm_from_locale_string ("Underscore");
2815 '_' { $$ = scm_from_int (DOWN); }
2816 | '^' { $$ = scm_from_int (UP); }
2817 | '-' { $$ = SCM_UNDEFINED; }
2821 multiplied_duration {
2826 maybe_notemode_duration:
2830 | multiplied_duration {
2832 parser->default_duration_ = *unsmob_duration ($$);
2837 optional_notemode_duration:
2838 maybe_notemode_duration
2840 if (SCM_UNBNDP ($$))
2841 $$ = parser->default_duration_.smobbed_copy ();
2848 int n = scm_to_int ($1);
2849 if (!is_duration (n))
2850 parser->parser_error (@1, _f ("not a duration: %d", n));
2854 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2856 | DURATION_IDENTIFIER dots {
2857 Duration *d = unsmob_duration ($1);
2858 Duration k (d->duration_log (),
2859 d->dot_count () + scm_to_int ($2));
2860 k = k.compressed (d->factor ());
2861 scm_remember_upto_here_1 ($1);
2862 $$ = k.smobbed_copy ();
2866 multiplied_duration:
2870 | multiplied_duration '*' UNSIGNED {
2871 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2873 | multiplied_duration '*' FRACTION {
2874 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2876 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2885 $$ = scm_oneplus ($1);
2894 int n = scm_to_int ($2);
2895 if (!is_duration (n))
2896 parser->parser_error (@2, _f ("not a duration: %d", n));
2902 UNSIGNED { $$ = $1; }
2903 | STRING { $$ = $1; }
2904 | full_markup { $$ = $1; }
2907 // as an integer, it needs to be non-negative, and otherwise
2908 // it needs to be suitable as a markup.
2909 if (scm_is_integer ($1)
2910 ? scm_is_true (scm_negative_p ($1))
2911 : !Text_interface::is_markup ($1))
2913 parser->parser_error (@1, _ ("bass number expected"));
2919 figured_bass_alteration:
2920 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2921 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2922 | '!' { $$ = scm_from_int (0); }
2927 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2928 $$ = bfr->unprotect ();
2931 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2932 $$ = bfr->self_scm ();
2934 if (scm_is_number ($1))
2935 bfr->set_property ("figure", $1);
2936 else if (Text_interface::is_markup ($1))
2937 bfr->set_property ("text", $1);
2943 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2945 | bass_figure figured_bass_alteration {
2946 Music *m = unsmob_music ($1);
2947 if (scm_to_double ($2)) {
2948 SCM salter = m->get_property ("alteration");
2949 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2950 m->set_property ("alteration",
2951 scm_sum (alter, $2));
2953 m->set_property ("alteration", scm_from_int (0));
2956 | bass_figure figured_bass_modification {
2957 Music *m = unsmob_music ($1);
2958 if ($2 == ly_symbol2scm ("plus"))
2960 m->set_property ("augmented", SCM_BOOL_T);
2962 else if ($2 == ly_symbol2scm ("slash"))
2964 m->set_property ("diminished", SCM_BOOL_T);
2966 else if ($2 == ly_symbol2scm ("exclamation"))
2968 m->set_property ("no-continuation", SCM_BOOL_T);
2970 else if ($2 == ly_symbol2scm ("backslash"))
2972 m->set_property ("augmented-slash", SCM_BOOL_T);
2978 figured_bass_modification:
2980 $$ = ly_symbol2scm ("plus");
2983 $$ = ly_symbol2scm ("exclamation");
2986 $$ = ly_symbol2scm ("slash");
2989 $$ = ly_symbol2scm ("backslash");
2999 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3007 | figure_list br_bass_figure {
3008 $$ = scm_cons ($2, $1);
3013 FIGURE_OPEN figure_list FIGURE_CLOSE {
3014 $$ = scm_reverse_x ($2, SCM_EOL);
3020 /**/ { $$ = SCM_BOOL_F; }
3021 | REST { $$ = SCM_BOOL_T; }
3025 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3026 if (!parser->lexer_->is_note_state ())
3027 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3028 if (!SCM_UNBNDP ($2)
3030 || scm_is_number ($4)
3032 || scm_is_true ($6))
3035 if (scm_is_true ($6))
3036 n = MY_MAKE_MUSIC ("RestEvent", @$);
3038 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3040 n->set_property ("pitch", $1);
3041 if (SCM_UNBNDP ($5))
3042 n->set_property ("duration",
3043 parser->default_duration_.smobbed_copy ());
3045 n->set_property ("duration", $5);
3047 if (scm_is_number ($4))
3049 int q = scm_to_int ($4);
3050 n->set_property ("absolute-octave", scm_from_int (q-1));
3053 if (to_boolean ($3))
3054 n->set_property ("cautionary", SCM_BOOL_T);
3055 if (to_boolean ($2) || to_boolean ($3))
3056 n->set_property ("force-accidental", SCM_BOOL_T);
3058 $$ = n->unprotect ();
3061 | DRUM_PITCH optional_notemode_duration {
3062 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3063 n->set_property ("duration", $2);
3064 n->set_property ("drum-type", $1);
3066 $$ = n->unprotect ();
3068 | RESTNAME optional_notemode_duration {
3070 if (ly_scm2string ($1) == "s") {
3072 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3075 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3078 ev->set_property ("duration", $2);
3079 $$ = ev->unprotect ();
3083 simple_chord_elements:
3085 if (!parser->lexer_->is_chord_state ())
3086 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3089 | figure_spec optional_notemode_duration {
3090 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3092 unsmob_music (scm_car (s))->set_property ("duration", $2);
3108 lyric_element_music:
3109 lyric_element optional_notemode_duration post_events {
3110 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3111 if (scm_is_pair ($3))
3112 unsmob_music ($$)->set_property
3113 ("articulations", scm_reverse_x ($3, SCM_EOL));
3118 steno_tonic_pitch optional_notemode_duration {
3119 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3121 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3122 SCM its = scm_reverse_x ($4, SCM_EOL);
3123 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3131 | chord_items chord_item {
3132 $$ = scm_cons ($2, $$);
3138 $$ = ly_symbol2scm ("chord-colon");
3141 $$ = ly_symbol2scm ("chord-caret");
3143 | CHORD_SLASH steno_tonic_pitch {
3144 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3146 | CHORD_BASS steno_tonic_pitch {
3147 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3156 $$ = scm_reverse_x ($1, SCM_EOL);
3164 step_number { $$ = scm_cons ($1, SCM_EOL); }
3165 | step_numbers '.' step_number {
3166 $$ = scm_cons ($3, $$);
3172 $$ = make_chord_step ($1, 0);
3175 $$ = make_chord_step ($1, SHARP_ALTERATION);
3177 | UNSIGNED CHORD_MINUS {
3178 $$ = make_chord_step ($1, FLAT_ALTERATION);
3186 | UNSIGNED '~' UNSIGNED {
3187 $$ = scm_cons ($1, $3);
3194 TODO: should deprecate in favor of Scheme?
3198 number_expression '+' number_term {
3199 $$ = scm_sum ($1, $3);
3201 | number_expression '-' number_term {
3202 $$ = scm_difference ($1, $3);
3211 | number_factor '*' number_factor {
3212 $$ = scm_product ($1, $3);
3214 | number_factor '/' number_factor {
3215 $$ = scm_divide ($1, $3);
3220 '-' number_factor { /* %prec UNARY_MINUS */
3221 $$ = scm_difference ($2, SCM_UNDEFINED);
3229 | UNSIGNED NUMBER_IDENTIFIER {
3230 $$ = scm_product ($1, $2);
3232 | REAL NUMBER_IDENTIFIER {
3233 $$ = scm_product ($1, $2);
3249 { $$ = SCM_UNDEFINED; }
3252 if (SCM_UNBNDP ($1))
3260 { $$ = SCM_UNDEFINED; }
3263 if (SCM_UNBNDP ($1))
3271 This should be done more dynamically if possible.
3276 { parser->lexer_->push_markup_state (); }
3279 parser->lexer_->pop_state ();
3285 { parser->lexer_->push_markup_state (); }
3288 parser->lexer_->pop_state ();
3294 { parser->lexer_->push_markup_state (); }
3297 parser->lexer_->pop_state ();
3303 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3305 | markup_head_1_list simple_markup {
3306 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3316 if (Text_interface::is_markup ($1))
3317 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3318 else if (Text_interface::is_markup_list ($1))
3319 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3321 parser->parser_error (@1, _ ("not a markup"));
3322 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3329 markup_composed_list {
3332 | markup_braced_list {
3335 | markup_command_list {
3336 $$ = scm_list_1 ($1);
3338 | markup_scm MARKUPLIST_IDENTIFIER
3344 markup_composed_list:
3345 markup_head_1_list markup_braced_list {
3346 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3352 '{' markup_braced_list_body '}' {
3353 $$ = scm_reverse_x ($2, SCM_EOL);
3357 markup_braced_list_body:
3358 /* empty */ { $$ = SCM_EOL; }
3359 | markup_braced_list_body markup {
3360 $$ = scm_cons ($2, $1);
3362 | markup_braced_list_body markup_list {
3363 $$ = scm_reverse_x ($2, $1);
3367 markup_command_list:
3368 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3369 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3373 markup_command_basic_arguments:
3374 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3375 $$ = scm_cons ($3, $2);
3377 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3378 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3380 | EXPECT_NO_MORE_ARGS {
3385 markup_command_list_arguments:
3386 markup_command_basic_arguments { $$ = $1; }
3387 | EXPECT_MARKUP markup_command_list_arguments markup {
3388 $$ = scm_cons ($3, $2);
3393 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3394 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3399 markup_head_1_item {
3400 $$ = scm_list_1 ($1);
3402 | markup_head_1_list markup_head_1_item {
3403 $$ = scm_cons ($2, $1);
3409 $$ = make_simple_markup ($1);
3412 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3413 parser->lexer_->push_note_state (nn);
3414 } '{' score_body '}' {
3415 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3416 parser->lexer_->pop_state ();
3418 | MARKUP_FUNCTION markup_command_basic_arguments {
3419 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3421 | markup_scm MARKUP_IDENTIFIER
3428 markup_head_1_list simple_markup {
3429 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3430 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3440 Lily_parser::set_yydebug (bool x)
3446 Lily_parser::do_yyparse ()
3448 SCM retval = SCM_UNDEFINED;
3449 yyparse (this, &retval);
3459 It is a little strange to have this function in this file, but
3460 otherwise, we have to import music classes into the lexer.
3464 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3466 if (unsmob_book (sid)) {
3467 Book *book = unsmob_book (sid)->clone ();
3468 *destination = book->self_scm ();
3471 return BOOK_IDENTIFIER;
3472 } else if (scm_is_number (sid)) {
3474 return NUMBER_IDENTIFIER;
3475 } else if (unsmob_context_def (sid)) {
3476 Context_def *def= unsmob_context_def (sid)->clone ();
3478 *destination = def->self_scm ();
3481 return CONTEXT_DEF_IDENTIFIER;
3482 } else if (unsmob_context_mod (sid)) {
3483 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3485 return CONTEXT_MOD_IDENTIFIER;
3486 } else if (Music *mus = unsmob_music (sid)) {
3487 mus = mus->clone ();
3488 *destination = mus->self_scm ();
3489 unsmob_music (*destination)->
3490 set_property ("origin", make_input (last_input_));
3492 bool is_event = mus->is_mus_type ("post-event");
3494 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3495 } else if (unsmob_pitch (sid)) {
3496 *destination = unsmob_pitch (sid)->smobbed_copy ();
3497 return PITCH_IDENTIFIER;
3498 } else if (unsmob_duration (sid)) {
3499 *destination = unsmob_duration (sid)->smobbed_copy ();
3500 return DURATION_IDENTIFIER;
3501 } else if (unsmob_output_def (sid)) {
3502 Output_def *p = unsmob_output_def (sid);
3505 *destination = p->self_scm ();
3507 return OUTPUT_DEF_IDENTIFIER;
3514 get_next_unique_context_id ()
3516 return scm_from_locale_string ("$uniqueContextId");
3521 get_next_unique_lyrics_context_id ()
3523 static int new_context_count;
3525 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3526 return scm_from_locale_string (s);
3529 // check_scheme_arg checks one argument with a given predicate for use
3530 // in an argument list and throws a syntax error if it is unusable.
3531 // The argument is prepended to the argument list in any case. After
3532 // throwing a syntax error, the argument list is terminated with #f as
3533 // its last cdr in order to mark it as uncallable while not losing
3534 // track of its total length.
3536 // There are a few special considerations: if optional argument disp
3537 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3538 // instead of arg in a prospective error message. This is useful if
3539 // arg is not the actual argument but rather a transformation of it.
3541 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3542 // and an error message using disp is produced unconditionally.
3544 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3545 SCM arg, SCM args, SCM pred, SCM disp)
3547 if (SCM_UNBNDP (arg))
3548 args = scm_cons (disp, args);
3550 args = scm_cons (arg, args);
3551 if (scm_is_true (scm_call_1 (pred, arg)))
3554 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3555 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3556 SCM_UNBNDP (disp) ? arg : disp);
3557 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3561 SCM loc_on_music (Input loc, SCM arg)
3563 if (Music *m = unsmob_music (arg))
3567 return m->unprotect ();
3573 try_string_variants (SCM pred, SCM str)
3575 // a matching predicate is always ok
3576 if (scm_is_true (scm_call_1 (pred, str)))
3578 // a symbol may be interpreted as a list of symbols if it helps
3579 if (scm_is_symbol (str)) {
3580 str = scm_list_1 (str);
3581 if (scm_is_true (scm_call_1 (pred, str)))
3583 return SCM_UNDEFINED;
3586 // If this cannot be a string representation of a symbol list,
3589 if (!is_regular_identifier (str, true))
3590 return SCM_UNDEFINED;
3592 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3593 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3594 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3596 // Let's attempt the symbol list interpretation first.
3598 if (scm_is_true (scm_call_1 (pred, str)))
3601 // If there is just one symbol in the list, we might interpret
3602 // it as a single symbol
3604 if (scm_is_null (scm_cdr (str)))
3606 str = scm_car (str);
3607 if (scm_is_true (scm_call_1 (pred, str)))
3611 return SCM_UNDEFINED;
3615 is_regular_identifier (SCM id, bool multiple)
3617 if (!scm_is_string (id))
3620 string str = ly_scm2string (id);
3622 bool middle = false;
3624 for (string::iterator it=str.begin(); it != str.end (); it++)
3627 if ((c >= 'a' && c <= 'z')
3628 || (c >= 'A' && c <= 'Z')
3631 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3640 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3642 if (unsmob_music (simple))
3644 if (parser->lexer_->is_note_state ()) {
3645 if (scm_is_symbol (simple)) {
3646 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3647 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3648 n->set_property ("drum-type", simple);
3649 return n->unprotect ();
3651 if (unsmob_pitch (simple)) {
3652 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3653 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3654 n->set_property ("pitch", simple);
3655 return n->unprotect ();
3658 } else if (parser->lexer_->is_lyric_state ()) {
3659 if (Text_interface::is_markup (simple))
3660 return MAKE_SYNTAX ("lyric-event", loc, simple,
3661 parser->default_duration_.smobbed_copy ());
3662 } else if (parser->lexer_->is_chord_state ()) {
3663 if (unsmob_pitch (simple))
3664 return make_chord_elements (loc, simple,
3665 parser->default_duration_.smobbed_copy (),
3672 make_music_with_input (SCM name, Input where)
3674 Music *m = make_music_by_name (name);
3675 m->set_spot (where);
3680 make_simple_markup (SCM a)
3688 return t && t == 1 << intlog2 (t);
3692 make_chord_step (SCM step_scm, Rational alter)
3694 int step = scm_to_int (step_scm);
3697 alter += FLAT_ALTERATION;
3701 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3702 return m.smobbed_copy ();
3707 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3709 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3710 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3711 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3713 unsmob_music (scm_car (s))->set_spot (loc);
3719 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3721 Lily_lexer *lex = parser->lexer_;
3725 lex->prepare_for_next_token ();
3726 return lex->yylex ();