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 $$ = t->unprotect ();
1240 if (scm_is_true (scm_call_1 ($2, $$)))
1241 $$ = scm_cons ($$, $3);
1243 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1247 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1249 $$ = check_scheme_arg (parser, @4,
1250 scm_difference ($5, SCM_UNDEFINED),
1253 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1255 $$ = check_scheme_arg (parser, @4,
1256 scm_difference ($5, SCM_UNDEFINED),
1261 function_arglist_closed_nonbackup:
1262 function_arglist_nonbackup_common
1263 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1265 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1267 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1269 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1271 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1273 SCM res = try_string_variants ($2, $4);
1274 if (SCM_UNBNDP (res))
1275 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1277 $$ = scm_cons (res, $3);
1279 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1281 SCM res = try_string_variants ($2, $4);
1282 if (SCM_UNBNDP (res))
1283 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1285 $$ = scm_cons (res, $3);
1287 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_STRING
1289 SCM res = try_string_variants ($2, $4);
1290 if (SCM_UNBNDP (res))
1291 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1293 $$ = scm_cons (res, $3);
1295 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1297 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1303 | SYMBOL_LIST '.' symbol_list_rev
1305 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1311 | symbol_list_rev '.' symbol_list_part
1313 $$ = scm_append_x (scm_list_2 ($3, $1));
1317 // symbol_list_part delivers elements in reverse copy.
1322 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1323 $$ = try_string_variants (sym_l_p, $1);
1324 if (SCM_UNBNDP ($$)) {
1325 parser->parser_error (@1, _("not a symbol"));
1328 $$ = scm_reverse ($$);
1333 symbol_list_element:
1340 function_arglist_nonbackup:
1341 function_arglist_nonbackup_common
1342 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1344 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1346 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1348 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1350 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1352 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1354 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1356 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1358 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1360 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1364 function_arglist_nonbackup_reparse:
1365 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1368 SCM res = try_string_variants ($2, $4);
1369 if (!SCM_UNBNDP (res))
1370 if (scm_is_pair (res))
1371 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1373 MYREPARSE (@4, $2, SCM_ARG, res);
1374 else if (scm_is_true
1376 ($2, make_music_from_simple
1378 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1380 MYREPARSE (@4, $2, SCM_ARG, $4);
1382 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_STRING
1385 SCM res = try_string_variants ($2, $4);
1386 if (!SCM_UNBNDP (res))
1387 if (scm_is_pair (res))
1388 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1390 MYREPARSE (@4, $2, SCM_ARG, res);
1391 else if (scm_is_true
1393 ($2, make_music_from_simple
1395 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1397 MYREPARSE (@4, $2, SCM_ARG, $4);
1399 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1402 SCM res = try_string_variants ($2, $4);
1403 if (!SCM_UNBNDP (res))
1404 if (scm_is_pair (res))
1405 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1407 MYREPARSE (@4, $2, SCM_ARG, res);
1409 MYREPARSE (@4, $2, SCM_ARG, $4);
1411 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1414 if (scm_is_true (scm_call_1 ($2, $4)))
1415 MYREPARSE (@4, $2, SCM_ARG, $4);
1416 else if (scm_is_true
1418 ($2, make_music_from_simple
1420 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1422 MYREPARSE (@4, $2, SCM_ARG, $4);
1426 function_arglist_keep:
1427 function_arglist_common
1428 | function_arglist_backup
1431 function_arglist_closed_keep:
1432 function_arglist_closed_common
1433 | function_arglist_backup
1436 function_arglist_backup:
1437 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1439 if (scm_is_true (scm_call_1 ($2, $4)))
1441 $$ = scm_cons ($4, $3);
1443 $$ = scm_cons (loc_on_music (@3, $1), $3);
1444 MYBACKUP (SCM_ARG, $4, @4);
1447 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1449 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 (EVENT_IDENTIFIER, $4, @4);
1457 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_markup
1459 if (scm_is_true (scm_call_1 ($2, $4)))
1460 $$ = scm_cons ($4, $3);
1462 $$ = scm_cons (loc_on_music (@3, $1), $3);
1463 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1466 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1468 if (scm_is_true (scm_call_1 ($2, $4)))
1471 MYREPARSE (@4, $2, UNSIGNED, $4);
1473 $$ = scm_cons (loc_on_music (@3, $1), $3);
1474 MYBACKUP (UNSIGNED, $4, @4);
1477 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1479 if (scm_is_true (scm_call_1 ($2, $4)))
1482 MYREPARSE (@4, $2, REAL, $4);
1484 $$ = scm_cons (loc_on_music (@3, $1), $3);
1485 MYBACKUP (REAL, $4, @4);
1488 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1490 if (scm_is_true (scm_call_1 ($2, $4)))
1492 $$ = scm_cons ($4, $3);
1494 $$ = scm_cons (loc_on_music (@3, $1), $3);
1495 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1498 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1500 if (scm_is_true (scm_call_1 ($2, $4)))
1502 $$ = scm_cons ($4, $3);
1504 $$ = scm_cons (loc_on_music (@3, $1), $3);
1505 MYBACKUP (FRACTION, $4, @4);
1508 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1510 SCM n = scm_difference ($5, SCM_UNDEFINED);
1511 if (scm_is_true (scm_call_1 ($2, n))) {
1513 MYREPARSE (@5, $2, REAL, n);
1515 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1516 t->set_property ("digit", $5);
1517 $$ = t->unprotect ();
1518 if (scm_is_true (scm_call_1 ($2, $$)))
1519 $$ = scm_cons ($$, $3);
1521 $$ = scm_cons (loc_on_music (@3, $1), $3);
1522 MYBACKUP (UNSIGNED, $5, @5);
1523 parser->lexer_->push_extra_token ('-');
1528 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1530 SCM n = scm_difference ($5, SCM_UNDEFINED);
1531 if (scm_is_true (scm_call_1 ($2, n))) {
1532 MYREPARSE (@5, $2, REAL, n);
1535 $$ = scm_cons (loc_on_music (@3, $1), $3);
1536 MYBACKUP (REAL, n, @5);
1539 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1541 SCM n = scm_difference ($5, SCM_UNDEFINED);
1542 if (scm_is_true (scm_call_1 ($2, n))) {
1543 $$ = scm_cons (n, $3);
1545 $$ = scm_cons (loc_on_music (@3, $1), $3);
1546 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1549 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1551 $$ = scm_cons ($4, $3);
1553 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1555 $$ = scm_cons ($4, $3);
1557 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1559 SCM res = try_string_variants ($2, $4);
1560 if (!SCM_UNBNDP (res))
1561 if (scm_is_pair (res)) {
1563 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1566 $$ = scm_cons (res, $3);
1568 $$ = scm_cons (loc_on_music (@3, $1), $3);
1569 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1572 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1574 SCM res = try_string_variants ($2, $4);
1575 if (!SCM_UNBNDP (res))
1576 if (scm_is_pair (res)) {
1578 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1581 $$ = scm_cons (res, $3);
1583 $$ = scm_cons (loc_on_music (@3, $1), $3);
1584 MYBACKUP (STRING, $4, @4);
1587 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep LYRICS_STRING
1589 SCM res = try_string_variants ($2, $4);
1590 if (!SCM_UNBNDP (res))
1591 if (scm_is_pair (res)) {
1593 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1596 $$ = scm_cons (res, $3);
1598 $$ = scm_cons (loc_on_music (@3, $1), $3);
1599 MYBACKUP (LYRICS_STRING, $4, @4);
1602 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1604 $$ = scm_cons ($1, $3);
1605 MYBACKUP(0, SCM_UNDEFINED, @3);
1607 | function_arglist_backup REPARSE bare_number
1609 $$ = check_scheme_arg (parser, @3,
1612 | function_arglist_backup REPARSE symbol_list_arg
1614 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1619 function_arglist_common
1620 | function_arglist_nonbackup
1623 function_arglist_common:
1624 function_arglist_bare
1625 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1627 $$ = check_scheme_arg (parser, @3,
1630 | EXPECT_SCM function_arglist_closed_optional bare_number
1632 $$ = check_scheme_arg (parser, @3,
1635 | EXPECT_SCM function_arglist_optional FRACTION
1637 $$ = check_scheme_arg (parser, @3,
1640 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1642 $$ = check_scheme_arg (parser, @3,
1645 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1647 SCM n = scm_difference ($4, SCM_UNDEFINED);
1648 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1650 | function_arglist_common_reparse REPARSE SCM_ARG
1652 $$ = check_scheme_arg (parser, @3,
1655 | function_arglist_common_reparse REPARSE lyric_element_music
1657 $$ = check_scheme_arg (parser, @3,
1660 | function_arglist_common_reparse REPARSE bare_number
1662 $$ = check_scheme_arg (parser, @3,
1665 | function_arglist_common_reparse REPARSE symbol_list_arg
1667 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1671 function_arglist_common_reparse:
1672 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1675 SCM res = try_string_variants ($1, $3);
1676 if (!SCM_UNBNDP (res))
1677 if (scm_is_pair (res))
1678 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1680 MYREPARSE (@3, $1, SCM_ARG, res);
1681 else if (scm_is_true
1683 ($1, make_music_from_simple (parser, @3, $3))))
1684 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1686 // This is going to flag a syntax error, we
1687 // know the predicate to be false.
1688 MYREPARSE (@3, $1, SCM_ARG, $3);
1690 | EXPECT_SCM function_arglist_optional STRING
1693 SCM res = try_string_variants ($1, $3);
1694 if (!SCM_UNBNDP (res))
1695 if (scm_is_pair (res))
1696 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1698 MYREPARSE (@3, $1, SCM_ARG, res);
1700 // This is going to flag a syntax error, we
1701 // know the predicate to be false.
1702 MYREPARSE (@3, $1, SCM_ARG, $3);
1704 | EXPECT_SCM function_arglist_optional LYRICS_STRING
1707 SCM res = try_string_variants ($1, $3);
1708 if (!SCM_UNBNDP (res))
1709 if (scm_is_pair (res))
1710 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1712 MYREPARSE (@3, $1, SCM_ARG, res);
1713 else if (scm_is_true
1715 ($1, make_music_from_simple (parser, @3, $3))))
1716 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1718 // This is going to flag a syntax error, we
1719 // know the predicate to be false.
1720 MYREPARSE (@3, $1, SCM_ARG, $3);
1722 | EXPECT_SCM function_arglist_optional lyric_markup
1725 if (scm_is_true (scm_call_1 ($1, $3)))
1726 MYREPARSE (@3, $1, SCM_ARG, $3);
1727 else if (scm_is_true
1729 ($1, make_music_from_simple (parser, @3, $3))))
1730 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1732 // This is going to flag a syntax error, we
1733 // know the predicate to be false.
1734 MYREPARSE (@3, $1, SCM_ARG, $3);
1736 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1739 SCM n = scm_difference ($4, SCM_UNDEFINED);
1740 if (scm_is_true (scm_call_1 ($1, n)))
1741 MYREPARSE (@4, $1, REAL, n);
1743 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1744 t->set_property ("digit", $4);
1745 SCM m = t->unprotect ();
1746 if (scm_is_true (scm_call_1 ($1, m)))
1747 MYREPARSE (@4, $1, SCM_ARG, m);
1749 MYREPARSE (@4, $1, SCM_ARG, $4);
1753 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1756 SCM n = scm_difference ($4, SCM_UNDEFINED);
1757 MYREPARSE (@4, $1, REAL, n);
1761 function_arglist_closed:
1762 function_arglist_closed_common
1763 | function_arglist_closed_nonbackup
1766 function_arglist_closed_common:
1767 function_arglist_bare
1768 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1770 $$ = check_scheme_arg (parser, @3,
1773 | EXPECT_SCM function_arglist_closed_optional bare_number
1775 $$ = check_scheme_arg (parser, @3,
1778 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1780 $$ = check_scheme_arg (parser, @3,
1781 scm_difference ($4, SCM_UNDEFINED),
1784 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1786 $$ = check_scheme_arg (parser, @3,
1789 | EXPECT_SCM function_arglist_optional FRACTION
1791 $$ = check_scheme_arg (parser, @3,
1794 | function_arglist_common_reparse REPARSE SCM_ARG
1796 $$ = check_scheme_arg (parser, @3,
1799 | function_arglist_common_reparse REPARSE bare_number
1801 $$ = check_scheme_arg (parser, @3,
1804 | function_arglist_common_reparse REPARSE symbol_list_arg
1806 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1810 function_arglist_optional:
1811 function_arglist_keep %prec FUNCTION_ARGLIST
1812 | function_arglist_backup BACKUP
1813 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1815 $$ = scm_cons ($1, $3);
1817 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1819 $$ = scm_cons ($1, $3);
1823 function_arglist_closed_optional:
1824 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1825 | function_arglist_backup BACKUP
1826 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1828 $$ = scm_cons ($1, $3);
1830 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1832 $$ = scm_cons ($1, $3);
1836 embedded_scm_closed:
1838 | scm_function_call_closed
1841 embedded_scm_arg_closed:
1842 embedded_scm_bare_arg
1843 | scm_function_call_closed
1847 scm_function_call_closed:
1848 SCM_FUNCTION function_arglist_closed {
1849 $$ = MAKE_SYNTAX ("music-function", @$,
1851 } %prec FUNCTION_ARGLIST
1854 function_arglist_bare:
1855 EXPECT_NO_MORE_ARGS {
1858 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1859 $$ = scm_cons ($3, $2);
1861 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1862 $$ = scm_cons ($3, $2);
1864 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1865 $$ = scm_cons ($1, $3);
1867 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1868 $$ = scm_cons ($1, $3);
1870 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1871 $$ = scm_cons ($1, $3);
1875 music_function_call:
1876 MUSIC_FUNCTION function_arglist {
1877 $$ = MAKE_SYNTAX ("music-function", @$,
1884 /**/ { $$ = SCM_EOL; }
1885 | '=' simple_string {
1892 | repeated_music { $$ = $1; }
1893 | re_rhythmed_music { $$ = $1; }
1894 | complex_music_prefix music
1896 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1900 complex_music_prefix:
1901 CONTEXT simple_string optional_id optional_context_mod {
1902 Context_mod *ctxmod = unsmob_context_mod ($4);
1905 mods = ctxmod->get_mods ();
1906 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1908 | NEWCONTEXT simple_string optional_id optional_context_mod {
1909 Context_mod *ctxmod = unsmob_context_mod ($4);
1912 mods = ctxmod->get_mods ();
1913 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1918 mode_changing_head grouped_music_list {
1919 if ($1 == ly_symbol2scm ("chords"))
1921 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1927 parser->lexer_->pop_state ();
1929 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1930 Context_mod *ctxmod = unsmob_context_mod ($2);
1933 mods = ctxmod->get_mods ();
1934 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1935 if ($1 == ly_symbol2scm ("ChordNames"))
1937 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1939 parser->lexer_->pop_state ();
1945 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1946 parser->lexer_->push_note_state (nn);
1948 $$ = ly_symbol2scm ("notes");
1952 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1953 parser->lexer_->push_note_state (nn);
1955 $$ = ly_symbol2scm ("drums");
1958 parser->lexer_->push_figuredbass_state ();
1960 $$ = ly_symbol2scm ("figures");
1963 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1964 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1965 nn = parser->lexer_->lookup_identifier ("pitchnames");
1966 parser->lexer_->push_chord_state (nn);
1967 $$ = ly_symbol2scm ("chords");
1971 { parser->lexer_->push_lyric_state ();
1972 $$ = ly_symbol2scm ("lyrics");
1976 mode_changing_head_with_context:
1978 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1979 parser->lexer_->push_note_state (nn);
1981 $$ = ly_symbol2scm ("DrumStaff");
1984 parser->lexer_->push_figuredbass_state ();
1986 $$ = ly_symbol2scm ("FiguredBass");
1989 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1990 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1991 nn = parser->lexer_->lookup_identifier ("pitchnames");
1992 parser->lexer_->push_chord_state (nn);
1993 $$ = ly_symbol2scm ("ChordNames");
1996 { parser->lexer_->push_lyric_state ();
1997 $$ = ly_symbol2scm ("Lyrics");
2002 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2005 /* Can also use music at the expensive of two S/Rs similar to
2006 \repeat \alternative */
2007 parser->lexer_->pop_state ();
2009 $$ = scm_cons ($3, SCM_EOL);
2011 | new_lyrics ADDLYRICS {
2012 parser->lexer_->push_lyric_state ();
2014 parser->lexer_->pop_state ();
2015 $$ = scm_cons ($4, $1);
2020 composite_music new_lyrics {
2021 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2023 | LYRICSTO simple_string {
2024 parser->lexer_->push_lyric_state ();
2026 parser->lexer_->pop_state ();
2027 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2032 CHANGE STRING '=' STRING {
2033 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2040 $$ = scm_reverse_x ($1, SCM_EOL);
2042 | symbol_list_rev property_path {
2043 $$ = scm_reverse_x ($1, $2);
2049 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2050 scm_string_to_symbol ($1), $3);
2052 | UNSET simple_string {
2053 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2054 scm_string_to_symbol ($2));
2056 | OVERRIDE property_path '=' scalar {
2057 if (scm_ilength ($2) < 2) {
2058 parser->parser_error (@2, _("bad grob property path"));
2061 $$ = scm_cons (ly_symbol2scm ("push"),
2062 scm_cons2 (scm_car ($2),
2067 | REVERT revert_arg {
2068 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2074 // This is all quite awkward for the sake of substantial backward
2075 // compatibility while at the same time allowing a more "natural" form
2076 // of specification not separating grob specification from grob
2077 // property path. The purpose of this definition of revert_arg is to
2078 // allow the symbol list which specifies grob and property to revert
2079 // to be optionally be split into two parts after the grob (which in
2080 // this case is just the first element of the list). symbol_list_part
2081 // is only one path component, but it can be parsed without lookahead,
2082 // so we can follow it with a synthetic BACKUP token when needed. If
2083 // the first symbol_list_part already contains multiple elements (only
2084 // possible if a Scheme expression provides them), we just parse for
2085 // additional elements introduced by '.', which is what the
2086 // SYMBOL_LIST backup in connection with the immediately following
2087 // rule using symbol_list_arg does.
2089 // As long as we don't have our coffers filled with both grob and at
2090 // least one grob property specification, the rest of the required
2091 // symbol list chain may be provided either with or without a leading
2092 // dot. This is for both allowing the traditional
2093 // \revert Accidental #'color
2094 // as well as well as the "naive" form
2095 // \revert Accidental.color
2100 if (scm_is_null ($1)
2101 || scm_is_null (scm_cdr ($1)))
2102 MYBACKUP (SCM_ARG, $1, @1);
2104 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2106 | revert_arg BACKUP symbol_list_arg
2112 // revert_arg_part delivers results in reverse
2115 | revert_arg BACKUP SCM_ARG '.' symbol_list_part
2117 $$ = scm_append_x (scm_list_2 ($5, $3));
2119 | revert_arg BACKUP SCM_ARG symbol_list_part
2121 $$ = scm_append_x (scm_list_2 ($4, $3));
2126 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2127 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2129 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2130 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2131 | DENIES { $$ = ly_symbol2scm ("denies"); }
2133 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2134 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2135 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2136 | NAME { $$ = ly_symbol2scm ("context-name"); }
2140 property_operation { $$ = $1; }
2141 | context_def_mod STRING {
2142 $$ = scm_list_2 ($1, $2);
2144 | context_def_mod embedded_scm
2146 if (!scm_is_string ($2)
2147 && ly_symbol2scm ("consists") != $1
2148 && ly_symbol2scm ("remove") != $1)
2151 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2155 $$ = scm_list_2 ($1, $2);
2160 // If defined, at least two members.
2164 SCM l = scm_reverse_x ($1, SCM_EOL);
2167 (scm_object_property (scm_car (l),
2168 ly_symbol2scm ("is-grob?"))))
2169 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2170 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2171 parser->parser_error (@1, _ ("bad grob property path"));
2178 // If defined, at least three members
2182 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2184 parser->parser_error (@1, _ ("bad grob property path"));
2188 | grob_prop_spec property_path
2190 if (!SCM_UNBNDP ($1)) {
2191 $$ = scm_append_x (scm_list_2 ($1, $2));
2192 if (scm_is_null (scm_cddr ($$))) {
2193 parser->parser_error (@$, _ ("bad grob property path"));
2201 // Exactly two elements or undefined
2205 SCM l = scm_reverse_x ($1, SCM_EOL);
2206 switch (scm_ilength (l)) {
2208 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2212 parser->parser_error (@1, _ ("bad context property path"));
2219 simple_music_property_def:
2220 OVERRIDE grob_prop_path '=' scalar {
2221 if (SCM_UNBNDP ($2))
2224 $$ = scm_list_5 (scm_car ($2),
2225 ly_symbol2scm ("OverrideProperty"),
2231 | REVERT simple_revert_context revert_arg {
2232 $$ = scm_list_4 ($2,
2233 ly_symbol2scm ("RevertProperty"),
2237 | SET context_prop_spec '=' scalar {
2238 if (SCM_UNBNDP ($2))
2241 $$ = scm_list_4 (scm_car ($2),
2242 ly_symbol2scm ("PropertySet"),
2246 | UNSET context_prop_spec {
2247 if (SCM_UNBNDP ($2))
2250 $$ = scm_list_3 (scm_car ($2),
2251 ly_symbol2scm ("PropertyUnset"),
2257 // This is all quite awkward for the sake of substantial backward
2258 // compatibility while at the same time allowing a more "natural" form
2259 // of specification not separating grob specification from grob
2260 // property path. The purpose of this definition of
2261 // simple_revert_context is to allow the symbol list which specifies
2262 // grob and property to revert to be optionally be split into two
2263 // parts after the grob (which may be preceded by a context
2264 // specification, a case which we distinguish by checking whether the
2265 // first symbol is a valid grob symbol instead).
2267 // See revert_arg above for the main work horse of this arrangement.
2268 // simple_revert_context just caters for the context and delegates the
2269 // rest of the job to revert_arg.
2271 simple_revert_context:
2274 $1 = scm_reverse_x ($1, SCM_EOL);
2275 if (scm_is_null ($1)
2277 (scm_object_property (scm_car ($1),
2278 ly_symbol2scm ("is-grob?")))) {
2279 $$ = ly_symbol2scm ("Bottom");
2280 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2283 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2290 simple_music_property_def {
2291 if (SCM_UNBNDP ($1))
2292 $$ = MAKE_SYNTAX ("void-music", @1);
2294 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2303 | string '+' string {
2304 if (!scm_is_string ($1)) {
2305 parser->parser_error (@1, (_ ("simple string expected")));
2306 $1 = scm_string (SCM_EOL);
2308 if (!scm_is_string ($3)) {
2309 parser->parser_error (@3, (_ ("simple string expected")));
2310 $3 = scm_string (SCM_EOL);
2312 $$ = scm_string_append (scm_list_2 ($1, $3));
2316 simple_string: STRING {
2324 if (scm_is_string ($1)) {
2327 parser->parser_error (@1, (_ ("simple string expected")));
2328 $$ = scm_string (SCM_EOL);
2343 embedded_scm_arg_closed
2353 simple_element post_events {
2354 // Let the rhythmic music iterator sort this mess out.
2355 if (scm_is_pair ($2)) {
2356 $$ = make_music_from_simple (parser, @1, $1);
2357 if (unsmob_music ($$))
2358 unsmob_music ($$)->set_property ("articulations",
2359 scm_reverse_x ($2, SCM_EOL));
2361 parser->parser_error (@1, _("music expected"));
2364 | simple_chord_elements post_events {
2365 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2368 /* why is this giving wrong start location? -ns
2370 i.set_location (@1, @2);
2371 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2373 | CHORD_REPETITION optional_notemode_duration post_events {
2375 i.set_location (@1, @3);
2376 $$ = MAKE_SYNTAX ("repetition-chord", i,
2377 $2, scm_reverse_x ($3, SCM_EOL));
2379 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2381 i.set_location (@1, @3);
2382 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2383 scm_reverse_x ($3, SCM_EOL));
2386 | note_chord_element
2391 chord_body optional_notemode_duration post_events
2393 Music *m = unsmob_music ($1);
2394 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2395 SCM es = m->get_property ("elements");
2396 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2398 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2399 unsmob_music (scm_car (s))->set_property ("duration", dur);
2400 es = ly_append2 (es, postevs);
2402 m-> set_property ("elements", es);
2404 $$ = m->self_scm ();
2409 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2411 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2415 chord_body_elements:
2416 /* empty */ { $$ = SCM_EOL; }
2417 | chord_body_elements chord_body_element {
2418 if (!SCM_UNBNDP ($2))
2419 $$ = scm_cons ($2, $1);
2424 pitch exclamations questions octave_check post_events
2426 bool q = to_boolean ($3);
2427 bool ex = to_boolean ($2);
2431 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2432 n->set_property ("pitch", $1);
2434 n->set_property ("cautionary", SCM_BOOL_T);
2436 n->set_property ("force-accidental", SCM_BOOL_T);
2438 if (scm_is_pair (post)) {
2439 SCM arts = scm_reverse_x (post, SCM_EOL);
2440 n->set_property ("articulations", arts);
2442 if (scm_is_number (check))
2444 int q = scm_to_int (check);
2445 n->set_property ("absolute-octave", scm_from_int (q-1));
2448 $$ = n->unprotect ();
2450 | DRUM_PITCH post_events {
2451 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2452 n->set_property ("drum-type", $1);
2454 if (scm_is_pair ($2)) {
2455 SCM arts = scm_reverse_x ($2, SCM_EOL);
2456 n->set_property ("articulations", arts);
2458 $$ = n->unprotect ();
2460 | music_function_chord_body
2462 Music *m = unsmob_music ($1);
2464 while (m && m->is_mus_type ("music-wrapper-music")) {
2465 $$ = m->get_property ("element");
2466 m = unsmob_music ($$);
2469 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2470 parser->parser_error (@$, _ ("not a rhythmic event"));
2476 music_function_chord_body:
2481 // Event functions may only take closed arglists, otherwise it would
2482 // not be clear whether a following postevent should be associated
2483 // with the last argument of the event function or with the expression
2484 // for which the function call acts itself as event.
2486 music_function_call_closed:
2487 MUSIC_FUNCTION function_arglist_closed {
2488 $$ = MAKE_SYNTAX ("music-function", @$,
2493 event_function_event:
2494 EVENT_FUNCTION function_arglist_closed {
2495 $$ = MAKE_SYNTAX ("music-function", @$,
2505 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2506 m->set_property ("span-direction", scm_from_int (START));
2507 $$ = m->unprotect();
2510 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2511 m->set_property ("span-direction", scm_from_int (STOP));
2512 $$ = m->unprotect ();
2515 $$ = MAKE_SYNTAX ("voice-separator", @$);
2518 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2520 Music *m = unsmob_music (pipe);
2525 $$ = m->unprotect ();
2528 $$ = MAKE_SYNTAX ("bar-check", @$);
2535 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2547 | post_events post_event {
2548 unsmob_music ($2)->set_spot (@2);
2549 $$ = scm_cons ($2, $$);
2553 post_event_nofinger:
2554 direction_less_event {
2557 | script_dir music_function_call_closed {
2559 if (!SCM_UNBNDP ($1))
2561 unsmob_music ($$)->set_property ("direction", $1);
2565 if (!parser->lexer_->is_lyric_state ())
2566 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2567 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2570 if (!parser->lexer_->is_lyric_state ())
2571 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2572 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2574 | script_dir direction_reqd_event {
2575 if (!SCM_UNBNDP ($1))
2577 Music *m = unsmob_music ($2);
2578 m->set_property ("direction", $1);
2582 | script_dir direction_less_event {
2583 if (!SCM_UNBNDP ($1))
2585 Music *m = unsmob_music ($2);
2586 m->set_property ("direction", $1);
2593 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2598 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2609 string_number_event:
2611 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2612 s->set_property ("string-number", $1);
2613 $$ = s->unprotect ();
2617 direction_less_char:
2619 $$ = ly_symbol2scm ("bracketOpenSymbol");
2622 $$ = ly_symbol2scm ("bracketCloseSymbol");
2625 $$ = ly_symbol2scm ("tildeSymbol");
2628 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2631 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2634 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2637 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2640 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2643 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2646 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2650 direction_less_event:
2651 direction_less_char {
2652 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2654 if (unsmob_music (predefd))
2656 m = unsmob_music (predefd)->clone ();
2661 m = MY_MAKE_MUSIC ("Music", @$);
2663 $$ = m->unprotect ();
2665 | string_number_event
2666 | EVENT_IDENTIFIER {
2670 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2671 a->set_property ("tremolo-type", $1);
2672 $$ = a->unprotect ();
2674 | event_function_event
2677 direction_reqd_event:
2681 | script_abbreviation {
2682 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2683 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2684 if (scm_is_string (s))
2685 a->set_property ("articulation-type", s);
2686 else parser->parser_error (@1, _ ("expecting string as script definition"));
2687 $$ = a->unprotect ();
2692 /**/ { $$ = SCM_EOL; }
2693 | '=' quotes { $$ = $2; }
2707 $$ = scm_from_int (1);
2710 $$ = scm_oneplus ($1);
2716 $$ = scm_from_int (-1);
2719 $$ = scm_oneminus ($1);
2724 NOTENAME_PITCH quotes {
2725 if (!scm_is_eq (SCM_INUM0, $2))
2727 Pitch p = *unsmob_pitch ($1);
2728 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2729 $$ = p.smobbed_copy ();
2739 TONICNAME_PITCH quotes {
2740 if (!scm_is_eq (SCM_INUM0, $2))
2742 Pitch p = *unsmob_pitch ($1);
2743 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2744 $$ = p.smobbed_copy ();
2754 pitch_also_in_chords:
2761 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2762 t->set_property ("text", $1);
2763 $$ = t->unprotect ();
2766 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2767 t->set_property ("text",
2768 make_simple_markup ($1));
2769 $$ = t->unprotect ();
2772 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2773 t->set_property ("text",
2774 make_simple_markup ($1));
2775 $$ = t->unprotect ();
2777 | embedded_scm_closed
2779 Music *m = unsmob_music ($1);
2780 if (m && m->is_mus_type ("post-event"))
2782 else if (Text_interface::is_markup ($1)) {
2783 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2784 t->set_property ("text", $1);
2785 $$ = t->unprotect ();
2787 parser->parser_error (@1, _ ("not an articulation"));
2793 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2794 t->set_property ("digit", $1);
2795 $$ = t->unprotect ();
2799 script_abbreviation:
2801 $$ = scm_from_locale_string ("Hat");
2804 $$ = scm_from_locale_string ("Plus");
2807 $$ = scm_from_locale_string ("Dash");
2810 $$ = scm_from_locale_string ("Bar");
2813 $$ = scm_from_locale_string ("Larger");
2816 $$ = scm_from_locale_string ("Dot");
2819 $$ = scm_from_locale_string ("Underscore");
2824 '_' { $$ = scm_from_int (DOWN); }
2825 | '^' { $$ = scm_from_int (UP); }
2826 | '-' { $$ = SCM_UNDEFINED; }
2830 multiplied_duration {
2835 maybe_notemode_duration:
2839 | multiplied_duration {
2841 parser->default_duration_ = *unsmob_duration ($$);
2846 optional_notemode_duration:
2847 maybe_notemode_duration
2849 if (SCM_UNBNDP ($$))
2850 $$ = parser->default_duration_.smobbed_copy ();
2857 int n = scm_to_int ($1);
2858 if (!is_duration (n))
2859 parser->parser_error (@1, _f ("not a duration: %d", n));
2863 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2865 | DURATION_IDENTIFIER dots {
2866 Duration *d = unsmob_duration ($1);
2867 Duration k (d->duration_log (),
2868 d->dot_count () + scm_to_int ($2));
2869 k = k.compressed (d->factor ());
2870 scm_remember_upto_here_1 ($1);
2871 $$ = k.smobbed_copy ();
2875 multiplied_duration:
2879 | multiplied_duration '*' UNSIGNED {
2880 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2882 | multiplied_duration '*' FRACTION {
2883 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2885 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2894 $$ = scm_oneplus ($1);
2903 int n = scm_to_int ($2);
2904 if (!is_duration (n))
2905 parser->parser_error (@2, _f ("not a duration: %d", n));
2911 UNSIGNED { $$ = $1; }
2912 | STRING { $$ = $1; }
2913 | full_markup { $$ = $1; }
2916 // as an integer, it needs to be non-negative, and otherwise
2917 // it needs to be suitable as a markup.
2918 if (scm_is_integer ($1)
2919 ? scm_is_true (scm_negative_p ($1))
2920 : !Text_interface::is_markup ($1))
2922 parser->parser_error (@1, _ ("bass number expected"));
2928 figured_bass_alteration:
2929 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2930 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2931 | '!' { $$ = scm_from_int (0); }
2936 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2937 $$ = bfr->unprotect ();
2940 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2941 $$ = bfr->self_scm ();
2943 if (scm_is_number ($1))
2944 bfr->set_property ("figure", $1);
2945 else if (Text_interface::is_markup ($1))
2946 bfr->set_property ("text", $1);
2952 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2954 | bass_figure figured_bass_alteration {
2955 Music *m = unsmob_music ($1);
2956 if (scm_to_double ($2)) {
2957 SCM salter = m->get_property ("alteration");
2958 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2959 m->set_property ("alteration",
2960 scm_sum (alter, $2));
2962 m->set_property ("alteration", scm_from_int (0));
2965 | bass_figure figured_bass_modification {
2966 Music *m = unsmob_music ($1);
2967 if ($2 == ly_symbol2scm ("plus"))
2969 m->set_property ("augmented", SCM_BOOL_T);
2971 else if ($2 == ly_symbol2scm ("slash"))
2973 m->set_property ("diminished", SCM_BOOL_T);
2975 else if ($2 == ly_symbol2scm ("exclamation"))
2977 m->set_property ("no-continuation", SCM_BOOL_T);
2979 else if ($2 == ly_symbol2scm ("backslash"))
2981 m->set_property ("augmented-slash", SCM_BOOL_T);
2987 figured_bass_modification:
2989 $$ = ly_symbol2scm ("plus");
2992 $$ = ly_symbol2scm ("exclamation");
2995 $$ = ly_symbol2scm ("slash");
2998 $$ = ly_symbol2scm ("backslash");
3008 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3016 | figure_list br_bass_figure {
3017 $$ = scm_cons ($2, $1);
3022 FIGURE_OPEN figure_list FIGURE_CLOSE {
3023 $$ = scm_reverse_x ($2, SCM_EOL);
3029 /**/ { $$ = SCM_BOOL_F; }
3030 | REST { $$ = SCM_BOOL_T; }
3034 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3035 if (!parser->lexer_->is_note_state ())
3036 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3037 if (!SCM_UNBNDP ($2)
3039 || scm_is_number ($4)
3041 || scm_is_true ($6))
3044 if (scm_is_true ($6))
3045 n = MY_MAKE_MUSIC ("RestEvent", @$);
3047 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3049 n->set_property ("pitch", $1);
3050 if (SCM_UNBNDP ($5))
3051 n->set_property ("duration",
3052 parser->default_duration_.smobbed_copy ());
3054 n->set_property ("duration", $5);
3056 if (scm_is_number ($4))
3058 int q = scm_to_int ($4);
3059 n->set_property ("absolute-octave", scm_from_int (q-1));
3062 if (to_boolean ($3))
3063 n->set_property ("cautionary", SCM_BOOL_T);
3064 if (to_boolean ($2) || to_boolean ($3))
3065 n->set_property ("force-accidental", SCM_BOOL_T);
3067 $$ = n->unprotect ();
3070 | DRUM_PITCH optional_notemode_duration {
3071 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3072 n->set_property ("duration", $2);
3073 n->set_property ("drum-type", $1);
3075 $$ = n->unprotect ();
3077 | RESTNAME optional_notemode_duration {
3079 if (ly_scm2string ($1) == "s") {
3081 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3084 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3087 ev->set_property ("duration", $2);
3088 $$ = ev->unprotect ();
3092 simple_chord_elements:
3094 if (!parser->lexer_->is_chord_state ())
3095 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3098 | figure_spec optional_notemode_duration {
3099 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3101 unsmob_music (scm_car (s))->set_property ("duration", $2);
3117 lyric_element_music:
3118 lyric_element optional_notemode_duration post_events {
3119 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3120 if (scm_is_pair ($3))
3121 unsmob_music ($$)->set_property
3122 ("articulations", scm_reverse_x ($3, SCM_EOL));
3127 steno_tonic_pitch optional_notemode_duration {
3128 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3130 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3131 SCM its = scm_reverse_x ($4, SCM_EOL);
3132 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3140 | chord_items chord_item {
3141 $$ = scm_cons ($2, $$);
3147 $$ = ly_symbol2scm ("chord-colon");
3150 $$ = ly_symbol2scm ("chord-caret");
3152 | CHORD_SLASH steno_tonic_pitch {
3153 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3155 | CHORD_BASS steno_tonic_pitch {
3156 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3165 $$ = scm_reverse_x ($1, SCM_EOL);
3173 step_number { $$ = scm_cons ($1, SCM_EOL); }
3174 | step_numbers '.' step_number {
3175 $$ = scm_cons ($3, $$);
3181 $$ = make_chord_step ($1, 0);
3184 $$ = make_chord_step ($1, SHARP_ALTERATION);
3186 | UNSIGNED CHORD_MINUS {
3187 $$ = make_chord_step ($1, FLAT_ALTERATION);
3195 | UNSIGNED '~' UNSIGNED {
3196 $$ = scm_cons ($1, $3);
3203 TODO: should deprecate in favor of Scheme?
3207 number_expression '+' number_term {
3208 $$ = scm_sum ($1, $3);
3210 | number_expression '-' number_term {
3211 $$ = scm_difference ($1, $3);
3220 | number_factor '*' number_factor {
3221 $$ = scm_product ($1, $3);
3223 | number_factor '/' number_factor {
3224 $$ = scm_divide ($1, $3);
3229 '-' number_factor { /* %prec UNARY_MINUS */
3230 $$ = scm_difference ($2, SCM_UNDEFINED);
3238 | UNSIGNED NUMBER_IDENTIFIER {
3239 $$ = scm_product ($1, $2);
3241 | REAL NUMBER_IDENTIFIER {
3242 $$ = scm_product ($1, $2);
3258 { $$ = SCM_UNDEFINED; }
3261 if (SCM_UNBNDP ($1))
3269 { $$ = SCM_UNDEFINED; }
3272 if (SCM_UNBNDP ($1))
3280 This should be done more dynamically if possible.
3285 { parser->lexer_->push_markup_state (); }
3288 parser->lexer_->pop_state ();
3294 { parser->lexer_->push_markup_state (); }
3297 parser->lexer_->pop_state ();
3303 { parser->lexer_->push_markup_state (); }
3306 parser->lexer_->pop_state ();
3312 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3314 | markup_head_1_list simple_markup {
3315 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3325 if (Text_interface::is_markup ($1))
3326 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3327 else if (Text_interface::is_markup_list ($1))
3328 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3330 parser->parser_error (@1, _ ("not a markup"));
3331 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3338 markup_composed_list {
3341 | markup_braced_list {
3344 | markup_command_list {
3345 $$ = scm_list_1 ($1);
3347 | markup_scm MARKUPLIST_IDENTIFIER
3353 markup_composed_list:
3354 markup_head_1_list markup_braced_list {
3355 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3361 '{' markup_braced_list_body '}' {
3362 $$ = scm_reverse_x ($2, SCM_EOL);
3366 markup_braced_list_body:
3367 /* empty */ { $$ = SCM_EOL; }
3368 | markup_braced_list_body markup {
3369 $$ = scm_cons ($2, $1);
3371 | markup_braced_list_body markup_list {
3372 $$ = scm_reverse_x ($2, $1);
3376 markup_command_list:
3377 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3378 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3382 markup_command_basic_arguments:
3383 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3384 $$ = scm_cons ($3, $2);
3386 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3387 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3389 | EXPECT_NO_MORE_ARGS {
3394 markup_command_list_arguments:
3395 markup_command_basic_arguments { $$ = $1; }
3396 | EXPECT_MARKUP markup_command_list_arguments markup {
3397 $$ = scm_cons ($3, $2);
3402 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3403 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3408 markup_head_1_item {
3409 $$ = scm_list_1 ($1);
3411 | markup_head_1_list markup_head_1_item {
3412 $$ = scm_cons ($2, $1);
3418 $$ = make_simple_markup ($1);
3421 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3422 parser->lexer_->push_note_state (nn);
3423 } '{' score_body '}' {
3424 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3425 parser->lexer_->pop_state ();
3427 | MARKUP_FUNCTION markup_command_basic_arguments {
3428 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3430 | markup_scm MARKUP_IDENTIFIER
3437 markup_head_1_list simple_markup {
3438 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3439 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3449 Lily_parser::set_yydebug (bool x)
3455 Lily_parser::do_yyparse ()
3457 SCM retval = SCM_UNDEFINED;
3458 yyparse (this, &retval);
3468 It is a little strange to have this function in this file, but
3469 otherwise, we have to import music classes into the lexer.
3473 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3475 if (unsmob_book (sid)) {
3476 Book *book = unsmob_book (sid)->clone ();
3477 *destination = book->self_scm ();
3480 return BOOK_IDENTIFIER;
3481 } else if (scm_is_number (sid)) {
3483 return NUMBER_IDENTIFIER;
3484 } else if (unsmob_context_def (sid)) {
3485 Context_def *def= unsmob_context_def (sid)->clone ();
3487 *destination = def->self_scm ();
3490 return CONTEXT_DEF_IDENTIFIER;
3491 } else if (unsmob_context_mod (sid)) {
3492 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3494 return CONTEXT_MOD_IDENTIFIER;
3495 } else if (Music *mus = unsmob_music (sid)) {
3496 mus = mus->clone ();
3497 *destination = mus->self_scm ();
3498 unsmob_music (*destination)->
3499 set_property ("origin", make_input (last_input_));
3501 bool is_event = mus->is_mus_type ("post-event");
3503 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3504 } else if (unsmob_pitch (sid)) {
3505 *destination = unsmob_pitch (sid)->smobbed_copy ();
3506 return PITCH_IDENTIFIER;
3507 } else if (unsmob_duration (sid)) {
3508 *destination = unsmob_duration (sid)->smobbed_copy ();
3509 return DURATION_IDENTIFIER;
3510 } else if (unsmob_output_def (sid)) {
3511 Output_def *p = unsmob_output_def (sid);
3514 *destination = p->self_scm ();
3516 return OUTPUT_DEF_IDENTIFIER;
3523 get_next_unique_context_id ()
3525 return scm_from_locale_string ("$uniqueContextId");
3530 get_next_unique_lyrics_context_id ()
3532 static int new_context_count;
3534 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3535 return scm_from_locale_string (s);
3538 // check_scheme_arg checks one argument with a given predicate for use
3539 // in an argument list and throws a syntax error if it is unusable.
3540 // The argument is prepended to the argument list in any case. After
3541 // throwing a syntax error, the argument list is terminated with #f as
3542 // its last cdr in order to mark it as uncallable while not losing
3543 // track of its total length.
3545 // There are a few special considerations: if optional argument disp
3546 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3547 // instead of arg in a prospective error message. This is useful if
3548 // arg is not the actual argument but rather a transformation of it.
3550 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3551 // and an error message using disp is produced unconditionally.
3553 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3554 SCM arg, SCM args, SCM pred, SCM disp)
3556 if (SCM_UNBNDP (arg))
3557 args = scm_cons (disp, args);
3559 args = scm_cons (arg, args);
3560 if (scm_is_true (scm_call_1 (pred, arg)))
3563 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3564 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3565 SCM_UNBNDP (disp) ? arg : disp);
3566 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3570 SCM loc_on_music (Input loc, SCM arg)
3572 if (Music *m = unsmob_music (arg))
3576 return m->unprotect ();
3582 try_string_variants (SCM pred, SCM str)
3584 // a matching predicate is always ok
3585 if (scm_is_true (scm_call_1 (pred, str)))
3587 // a symbol may be interpreted as a list of symbols if it helps
3588 if (scm_is_symbol (str)) {
3589 str = scm_list_1 (str);
3590 if (scm_is_true (scm_call_1 (pred, str)))
3592 return SCM_UNDEFINED;
3595 // If this cannot be a string representation of a symbol list,
3598 if (!is_regular_identifier (str, true))
3599 return SCM_UNDEFINED;
3601 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3602 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3603 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3605 // Let's attempt the symbol list interpretation first.
3607 if (scm_is_true (scm_call_1 (pred, str)))
3610 // If there is just one symbol in the list, we might interpret
3611 // it as a single symbol
3613 if (scm_is_null (scm_cdr (str)))
3615 str = scm_car (str);
3616 if (scm_is_true (scm_call_1 (pred, str)))
3620 return SCM_UNDEFINED;
3624 is_regular_identifier (SCM id, bool multiple)
3626 if (!scm_is_string (id))
3629 string str = ly_scm2string (id);
3631 bool middle = false;
3633 for (string::iterator it=str.begin(); it != str.end (); it++)
3636 if ((c >= 'a' && c <= 'z')
3637 || (c >= 'A' && c <= 'Z')
3640 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3649 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3651 if (unsmob_music (simple))
3653 if (parser->lexer_->is_note_state ()) {
3654 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3655 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3656 if (scm_is_symbol (simple))
3657 n->set_property ("drum-type", simple);
3658 else if (unsmob_pitch (simple))
3659 n->set_property ("pitch", simple);
3664 return n->unprotect ();
3665 } else if (parser->lexer_->is_lyric_state ()) {
3666 if (Text_interface::is_markup (simple))
3667 return MAKE_SYNTAX ("lyric-event", loc, simple,
3668 parser->default_duration_.smobbed_copy ());
3669 } else if (parser->lexer_->is_chord_state ()) {
3670 if (unsmob_pitch (simple))
3671 return make_chord_elements (loc, simple,
3672 parser->default_duration_.smobbed_copy (),
3679 make_music_with_input (SCM name, Input where)
3681 Music *m = make_music_by_name (name);
3682 m->set_spot (where);
3687 make_simple_markup (SCM a)
3695 return t && t == 1 << intlog2 (t);
3699 make_chord_step (SCM step_scm, Rational alter)
3701 int step = scm_to_int (step_scm);
3704 alter += FLAT_ALTERATION;
3708 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3709 return m.smobbed_copy ();
3714 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3716 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3717 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3718 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3720 unsmob_music (scm_car (s))->set_spot (loc);
3726 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3728 Lily_lexer *lex = parser->lexer_;
3732 lex->prepare_for_next_token ();
3733 return lex->yylex ();