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--2015 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 SCM s = Display::value_to_lily_string (value); \
45 char *p = scm_to_locale_string (s); \
52 %parse-param {Lily_parser *parser}
53 %parse-param {SCM *retval}
54 %lex-param {Lily_parser *parser}
58 /* We use SCMs to do strings, because it saves us the trouble of
59 deleting them. Let's hope that a stack overflow doesn't trigger a move
60 of the parse stack onto the heap. */
66 /* The above precedences tackle the shift/reduce problem
69 \repeat .. \alternative
71 \repeat { \repeat .. \alternative }
75 \repeat { \repeat } \alternative
81 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
82 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
84 /* The above are needed for collecting tremoli and other items (that
85 could otherwise be interpreted as belonging to the next function
86 argument) greedily, and together with the next rule will serve to
87 join numbers and units greedily instead of allowing them into
88 separate function arguments
91 %nonassoc NUMBER_IDENTIFIER
103 %{ // -*-Fundamental-*-
108 * The rules for who is protecting what are very shady. Uniformise
111 * There are too many lexical modes?
122 #include "context.hh"
123 #include "context-def.hh"
124 #include "context-mod.hh"
125 #include "dimensions.hh"
126 #include "file-path.hh"
128 #include "international.hh"
129 #include "lily-guile.hh"
130 #include "lily-lexer.hh"
131 #include "lily-parser.hh"
132 #include "ly-module.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
142 #include "lily-imports.hh"
145 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
147 parser->parser_error (*i, s);
150 // The following are somewhat precarious constructs as they may change
151 // the value of the lookahead token. That implies that the lookahead
152 // token must not yet have made an impact on the state stack other
153 // than causing the reduction of the current rule, or switching the
154 // lookahead token while Bison is mulling it over will cause trouble.
156 #define MYBACKUP(Token, Value, Location) \
158 if (yychar != YYEMPTY) \
159 parser->lexer_->push_extra_token \
160 (yylloc, yychar, yylval); \
162 parser->lexer_->push_extra_token \
163 (Location, Token, Value); \
164 parser->lexer_->push_extra_token (Location, BACKUP); \
169 #define MYREPARSE(Location, Pred, Token, Value) \
171 if (yychar != YYEMPTY) \
172 parser->lexer_->push_extra_token \
173 (yylloc, yychar, yylval); \
174 parser->lexer_->push_extra_token \
175 (Location, Token, Value); \
176 parser->lexer_->push_extra_token \
177 (Location, REPARSE, Pred); \
186 #define MY_MAKE_MUSIC(x, spot) \
187 make_music_with_input (ly_symbol2scm (x), \
188 parser->lexer_->override_input (spot))
191 - delay application of the function
194 #define LOWLEVEL_MAKE_SYNTAX(location, proc, ...) \
196 (parser->lexer_->override_input (location).smobbed_copy (), \
200 /* Syntactic Sugar. */
201 #define MAKE_SYNTAX(name, location, ...) \
202 LOWLEVEL_MAKE_SYNTAX (location, Syntax::name, ##__VA_ARGS__)
204 #define START_MAKE_SYNTAX(name, ...) \
205 scm_list_n (Syntax::name, ##__VA_ARGS__, SCM_UNDEFINED)
207 #define FINISH_MAKE_SYNTAX(start, location, ...) \
208 LOWLEVEL_MAKE_SYNTAX \
213 (scm_list_2 (scm_cdr (start), \
214 scm_list_n (__VA_ARGS__, SCM_UNDEFINED))))
216 SCM get_next_unique_context_id ();
217 SCM get_next_unique_lyrics_context_id ();
224 #define _(x) gettext (x)
228 static Music *make_music_with_input (SCM name, Input where);
229 SCM check_scheme_arg (Lily_parser *parser, Input loc,
230 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
231 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
232 SCM loc_on_copy (Lily_parser *parser, Input loc, SCM arg);
233 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
234 SCM make_chord_step (SCM step, Rational alter);
235 SCM make_simple_markup (SCM a);
236 SCM make_duration (SCM t, int dots = 0, SCM factor = SCM_UNDEFINED);
237 bool is_regular_identifier (SCM id, bool multiple=false);
238 SCM make_reverse_key_list (SCM keys);
239 SCM try_word_variants (SCM pred, SCM str);
240 SCM try_string_variants (SCM pred, SCM str);
241 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
245 /* The third option is an alias that will be used to display the
246 syntax error. Bison CVS now correctly handles backslash escapes.
248 FIXME: Bison needs to translate some of these, eg, STRING.
252 /* Keyword tokens with plain escaped name. */
253 %token END_OF_FILE 0 "end of input"
254 %token ACCEPTS "\\accepts"
255 %token ADDLYRICS "\\addlyrics"
256 %token ALIAS "\\alias"
257 %token ALTERNATIVE "\\alternative"
259 %token BOOKPART "\\bookpart"
260 %token CHANGE "\\change"
261 %token CHORDMODE "\\chordmode"
262 %token CHORDS "\\chords"
263 %token CONSISTS "\\consists"
264 %token CONTEXT "\\context"
265 %token DEFAULT "\\default"
266 %token DEFAULTCHILD "\\defaultchild"
267 %token DENIES "\\denies"
268 %token DESCRIPTION "\\description"
269 %token DRUMMODE "\\drummode"
270 %token DRUMS "\\drums"
272 %token FIGUREMODE "\\figuremode"
273 %token FIGURES "\\figures"
274 %token HEADER "\\header"
275 %token INVALID "\\version-error"
276 %token LAYOUT "\\layout"
277 %token LYRICMODE "\\lyricmode"
278 %token LYRICS "\\lyrics"
279 %token LYRICSTO "\\lyricsto"
280 %token MARKUP "\\markup"
281 %token MARKUPLIST "\\markuplist"
284 %token NOTEMODE "\\notemode"
285 %token OVERRIDE "\\override"
286 %token PAPER "\\paper"
287 %token REMOVE "\\remove"
288 %token REPEAT "\\repeat"
290 %token REVERT "\\revert"
291 %token SCORE "\\score"
292 %token SCORELINES "\\score-lines"
293 %token SEQUENTIAL "\\sequential"
295 %token SIMULTANEOUS "\\simultaneous"
296 %token TEMPO "\\tempo"
298 %token UNSET "\\unset"
301 /* Keyword token exceptions. */
302 %token NEWCONTEXT "\\new"
305 /* Other string tokens. */
307 %token CHORD_BASS "/+"
308 %token CHORD_CARET "^"
309 %token CHORD_COLON ":"
310 %token CHORD_MINUS "-"
311 %token CHORD_SLASH "/"
312 %token ANGLE_OPEN "<"
313 %token ANGLE_CLOSE ">"
314 %token DOUBLE_ANGLE_OPEN "<<"
315 %token DOUBLE_ANGLE_CLOSE ">>"
316 %token E_BACKSLASH "\\"
317 %token E_EXCLAMATION "\\!"
322 If we give names, Bison complains.
324 %token FIGURE_CLOSE /* "\\>" */
325 %token FIGURE_OPEN /* "\\<" */
326 %token FIGURE_SPACE "_"
329 %token MULTI_MEASURE_REST
335 /* Artificial tokens, for more generic function syntax */
336 %token EXPECT_MARKUP "markup?"
337 %token EXPECT_SCM "scheme?"
338 %token BACKUP "(backed-up?)"
339 %token REPARSE "(reparsed?)"
340 %token EXPECT_MARKUP_LIST "markup-list?"
341 %token EXPECT_OPTIONAL "optional?"
342 /* After the last argument. */
343 %token EXPECT_NO_MORE_ARGS;
345 /* An artificial token for parsing embedded Lilypond */
346 %token EMBEDDED_LILY "#{"
348 %token BOOK_IDENTIFIER
349 %token CHORD_MODIFIER
350 %token CHORD_REPETITION
352 /* Artificial token for durations in argument lists */
354 %token DURATION_IDENTIFIER
355 %token EVENT_IDENTIFIER
356 %token EVENT_FUNCTION
358 %token LOOKUP_IDENTIFIER
360 %token MARKUP_FUNCTION
361 %token MARKUP_LIST_FUNCTION
362 %token MARKUP_IDENTIFIER
363 %token MARKUPLIST_IDENTIFIER
364 %token MUSIC_FUNCTION
365 %token MUSIC_IDENTIFIER
366 %token NOTENAME_PITCH
367 %token NUMBER_IDENTIFIER
368 %token PITCH_IDENTIFIER
373 %token SCM_IDENTIFIER
377 %token TONICNAME_PITCH
382 /* We don't assign precedence to / and *, because we might need varied
383 prec levels in different prods */
392 parser->lexer_->push_note_state (Lily::pitchnames);
393 } embedded_lilypond {
394 parser->lexer_->pop_state ();
399 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
400 | lilypond toplevel_expression {
402 | lilypond assignment {
405 parser->error_level_ = 1;
408 parser->error_level_ = 1;
415 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
418 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
419 scm_call_1 (proc, $1);
422 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
423 scm_call_1 (proc, $1);
426 SCM proc = parser->lexer_->lookup_identifier
427 (unsmob<Book>($1)->paper_
428 ? "toplevel-book-handler"
429 : "toplevel-bookpart-handler");
430 scm_call_1 (proc, $1);
433 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
434 scm_call_1 (proc, $1);
437 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
438 scm_call_1 (proc, $1);
441 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
442 scm_call_1 (proc, scm_list_1 ($1));
445 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
446 scm_call_1 (proc, $1);
449 // Evaluate and ignore #xxx, as opposed to \xxx
450 parser->lexer_->eval_scm_token ($1, @1);
452 | embedded_scm_active
454 SCM out = SCM_UNDEFINED;
455 if (Text_interface::is_markup ($1))
456 out = scm_list_1 ($1);
457 else if (Text_interface::is_markup_list ($1))
459 if (scm_is_pair (out))
461 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
462 scm_call_1 (proc, out);
463 } else if (unsmob<Score> ($1))
465 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
466 scm_call_1 (proc, $1);
467 } else if (Output_def * od = unsmob<Output_def> ($1)) {
470 if (to_boolean (od->c_variable ("is-paper")))
471 id = ly_symbol2scm ("$defaultpaper");
472 else if (to_boolean (od->c_variable ("is-midi")))
473 id = ly_symbol2scm ("$defaultmidi");
474 else if (to_boolean (od->c_variable ("is-layout")))
475 id = ly_symbol2scm ("$defaultlayout");
477 parser->lexer_->set_identifier (id, $1);
478 } else if (ly_is_module ($1))
480 SCM module = get_header (parser);
481 ly_module_copy (module, $1);
482 parser->lexer_->set_identifier
483 (ly_symbol2scm ("$defaultheader"), module);
484 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
485 parser->parser_error (@1, _("bad expression type"));
489 Output_def * od = unsmob<Output_def> ($1);
491 if (to_boolean (od->c_variable ("is-paper")))
492 id = ly_symbol2scm ("$defaultpaper");
493 else if (to_boolean (od->c_variable ("is-midi")))
494 id = ly_symbol2scm ("$defaultmidi");
495 else if (to_boolean (od->c_variable ("is-layout")))
496 id = ly_symbol2scm ("$defaultlayout");
498 parser->lexer_->set_identifier (id, $1);
504 | LOOKUP_IDENTIFIER '.' symbol_list_rev
506 $$ = loc_on_copy (parser, @$,
507 nested_property ($1, scm_reverse_x ($3, SCM_EOL)));
514 $$ = parser->lexer_->eval_scm_token ($1, @1);
525 embedded_scm_bare_arg:
529 $$ = parser->lexer_->eval_scm_token ($1, @1);
534 | context_modification
537 | context_def_spec_block
544 /* The generic version may end in music, or not */
552 /* embedded_scm_arg is _not_ casting pitches to music by default, this
553 * has to be done by the function itself. Note that this may cause
554 * the results of scm_function_call or embedded_scm_bare_arg to be
555 * turned into music from pitches as well. Note that this creates a
556 * distinctly awkward situation for calculated drum pitches. Those
557 * are at the current point of time rejected as music constituents as
558 * they can't be distinguished from "proper" symbols.
562 embedded_scm_bare_arg
568 SCM_FUNCTION function_arglist {
569 $$ = MAKE_SYNTAX (music_function, @$,
574 embedded_lilypond_number:
575 '-' embedded_lilypond_number
577 $$ = scm_difference ($2, SCM_UNDEFINED);
580 | UNSIGNED NUMBER_IDENTIFIER
582 $$ = scm_product ($1, $2);
589 // FIXME: @$ does not contain a useful source location
590 // for empty rules, and the only token in the whole
591 // production, EMBEDDED_LILY, is synthetic and also
592 // contains no source location.
593 $$ = MAKE_SYNTAX (void_music, @$);
595 | identifier_init_nonumber
596 | embedded_lilypond_number
597 | post_event post_events
599 $$ = scm_reverse_x ($2, SCM_EOL);
600 if (Music *m = unsmob<Music> ($1))
602 if (m->is_mus_type ("post-event-wrapper"))
604 (scm_list_2 (m->get_property ("elements"),
607 $$ = scm_cons ($1, $$);
610 && scm_is_null (scm_cdr ($$)))
614 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
615 m->set_property ("elements", $$);
616 $$ = m->unprotect ();
619 | multiplied_duration
620 | music_embedded music_embedded music_list {
621 $3 = scm_reverse_x ($3, SCM_EOL);
622 if (unsmob<Music> ($2))
623 $3 = scm_cons ($2, $3);
624 if (unsmob<Music> ($1))
625 $3 = scm_cons ($1, $3);
626 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
629 parser->error_level_ = 1;
630 $$ = SCM_UNSPECIFIED;
632 | INVALID embedded_lilypond {
633 parser->error_level_ = 1;
639 lilypond_header_body:
640 /* empty */ { $$ = SCM_UNSPECIFIED; }
641 | lilypond_header_body assignment {
644 | lilypond_header_body SCM_TOKEN {
645 // Evaluate and ignore #xxx, as opposed to \xxx
646 parser->lexer_->eval_scm_token ($2, @2);
648 | lilypond_header_body embedded_scm_active {
649 if (ly_is_module ($2))
650 ly_module_copy (scm_current_module (), $2);
651 else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
652 parser->parser_error (@2, _("bad expression type"));
657 HEADER '{' lilypond_header_body '}' {
658 $$ = parser->lexer_->remove_scope ();
664 parser->lexer_->add_scope (get_header (parser));
676 $$ = scm_string_to_symbol ($1);
680 $$ = scm_string_to_symbol ($1);
685 assignment_id '=' identifier_init {
686 parser->lexer_->set_identifier ($1, $3);
687 $$ = SCM_UNSPECIFIED;
689 | assignment_id '.' property_path '=' identifier_init {
690 SCM path = scm_cons ($1, $3);
691 parser->lexer_->set_identifier (path, $5);
692 $$ = SCM_UNSPECIFIED;
694 | assignment_id ',' property_path '=' identifier_init {
695 SCM path = scm_cons ($1, $3);
696 parser->lexer_->set_identifier (path, $5);
697 $$ = SCM_UNSPECIFIED;
703 identifier_init_nonumber
705 | symbol_list_part_bare '.' property_path
707 $$ = scm_reverse_x ($1, $3);
709 | symbol_list_part_bare ',' property_path
711 $$ = scm_reverse_x ($1, $3);
713 | post_event_nofinger post_events
715 $$ = scm_reverse_x ($2, SCM_EOL);
716 if (Music *m = unsmob<Music> ($1))
718 if (m->is_mus_type ("post-event-wrapper"))
720 (scm_list_2 (m->get_property ("elements"),
723 $$ = scm_cons ($1, $$);
726 && scm_is_null (scm_cdr ($$)))
730 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
731 m->set_property ("elements", $$);
732 $$ = m->unprotect ();
737 identifier_init_nonumber:
743 | context_def_spec_block
751 | context_modification
752 | partial_function ETC
754 $$ = MAKE_SYNTAX (partial_music_function, @$,
755 scm_reverse_x ($1, SCM_EOL));
761 MUSIC_FUNCTION function_arglist_partial
763 $$ = scm_acons ($1, $2, SCM_EOL);
765 | EVENT_FUNCTION function_arglist_partial
767 $$ = scm_acons ($1, $2, SCM_EOL);
769 | SCM_FUNCTION function_arglist_partial
771 $$ = scm_acons ($1, $2, SCM_EOL);
773 | OVERRIDE grob_prop_path '='
776 $$ = scm_list_1 (SCM_BOOL_F);
779 (scm_list_3 (Syntax::property_override_function,
780 scm_cdr ($2), scm_car ($2)),
783 | SET context_prop_spec '='
786 $$ = scm_list_1 (SCM_BOOL_F);
789 (scm_list_3 (Syntax::property_set_function,
790 scm_cadr ($2), scm_car ($2)),
793 | MUSIC_FUNCTION EXPECT_SCM function_arglist_optional partial_function
795 $$ = scm_acons ($1, $3, $4);
797 | EVENT_FUNCTION EXPECT_SCM function_arglist_optional partial_function
799 $$ = scm_acons ($1, $3, $4);
801 | SCM_FUNCTION EXPECT_SCM function_arglist_optional partial_function
803 $$ = scm_acons ($1, $3, $4);
805 | OVERRIDE grob_prop_path '=' partial_function
808 $$ = scm_list_1 (SCM_BOOL_F);
811 (scm_list_3 (Syntax::property_override_function,
812 scm_cdr ($2), scm_car ($2)),
815 | SET context_prop_spec '=' partial_function
818 $$ = scm_list_1 (SCM_BOOL_F);
821 (scm_list_3 (Syntax::property_set_function,
822 scm_cadr ($2), scm_car ($2)),
825 | MUSIC_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
827 $$ = scm_acons ($1, $4, $5);
829 | EVENT_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
831 $$ = scm_acons ($1, $4, $5);
833 | SCM_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
835 $$ = scm_acons ($1, $4, $5);
839 context_def_spec_block:
840 CONTEXT '{' context_def_spec_body '}'
843 Context_def *td = unsmob<Context_def> ($$);
845 $$ = Context_def::make_scm ();
846 td = unsmob<Context_def> ($$);
848 td->origin ()->set_spot (@$);
856 parser->lexer_->push_note_state (Lily::pitchnames);
860 parser->lexer_->pop_state ();
866 context_def_spec_body:
868 $$ = SCM_UNSPECIFIED;
870 | context_def_spec_body context_mod {
871 if (!SCM_UNBNDP ($2)) {
872 Context_def *td = unsmob<Context_def> ($$);
874 $$ = Context_def::make_scm ();
875 td = unsmob<Context_def> ($$);
877 unsmob<Context_def> ($$)->add_context_mod ($2);
880 | context_def_spec_body context_modification {
881 Context_def *td = unsmob<Context_def> ($$);
883 $$ = Context_def::make_scm ();
884 td = unsmob<Context_def> ($$);
886 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
887 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
888 td->add_context_mod (scm_car (m));
891 | context_def_spec_body context_mod_arg {
892 Context_def *td = unsmob<Context_def> ($1);
893 if (scm_is_eq ($2, SCM_UNSPECIFIED))
895 else if (!td && unsmob<Context_def> ($2))
899 $$ = Context_def::make_scm ();
900 td = unsmob<Context_def> ($$);
902 if (unsmob<Music> ($2)) {
903 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
904 $2 = scm_call_1 (proc, $2);
906 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
907 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
908 td->add_context_mod (scm_car (m));
911 parser->parser_error (@2, _ ("not a context mod"));
919 BOOK '{' book_body '}' {
921 unsmob<Book> ($$)->origin ()->set_spot (@$);
923 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
928 * Use 'handlers' like for toplevel-* stuff?
929 * grok \layout and \midi? */
932 Book *book = new Book;
933 init_papers (parser);
934 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
935 book->paper_->unprotect ();
936 push_paper (parser, book->paper_);
937 book->header_ = get_header (parser);
938 $$ = book->unprotect ();
939 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
942 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
944 | book_body paper_block {
945 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
946 set_paper (parser, unsmob<Output_def> ($2));
948 | book_body bookpart_block {
949 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
950 scm_call_2 (proc, $1, $2);
952 | book_body score_block {
953 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
954 scm_call_2 (proc, $1, $2);
956 | book_body composite_music {
957 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
958 scm_call_2 (proc, $1, $2);
960 | book_body full_markup {
961 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
962 scm_call_2 (proc, $1, scm_list_1 ($2));
964 | book_body full_markup_list {
965 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
966 scm_call_2 (proc, $1, $2);
968 | book_body SCM_TOKEN {
969 // Evaluate and ignore #xxx, as opposed to \xxx
970 parser->lexer_->eval_scm_token ($2, @2);
972 | book_body embedded_scm_active
974 SCM out = SCM_UNDEFINED;
975 if (Text_interface::is_markup ($2))
976 out = scm_list_1 ($2);
977 else if (Text_interface::is_markup_list ($2))
979 if (scm_is_pair (out))
981 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
982 scm_call_2 (proc, $1, out);
983 } else if (unsmob<Score> ($2))
985 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
986 scm_call_2 (proc, $1, $2);
987 } else if (Output_def *od = unsmob<Output_def> ($2)) {
988 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper")))) {
989 unsmob<Book> ($1)->paper_ = od;
990 set_paper (parser, od);
992 parser->parser_error (@2, _ ("need \\paper for paper block"));
994 } else if (ly_is_module ($2))
996 ly_module_copy (unsmob<Book> ($1)->header_, $2);
997 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
998 parser->parser_error (@2, _("bad expression type"));
1002 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
1005 Book *book = unsmob<Book> ($1);
1007 book->scores_ = SCM_EOL;
1008 book->bookparts_ = SCM_EOL;
1013 BOOKPART '{' bookpart_body '}' {
1015 unsmob<Book> ($$)->origin ()->set_spot (@$);
1016 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
1022 Book *book = new Book;
1023 $$ = book->unprotect ();
1024 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
1027 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
1029 | bookpart_body paper_block {
1030 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
1032 | bookpart_body score_block {
1033 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1034 scm_call_2 (proc, $1, $2);
1036 | bookpart_body composite_music {
1037 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
1038 scm_call_2 (proc, $1, $2);
1040 | bookpart_body full_markup {
1041 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1042 scm_call_2 (proc, $1, scm_list_1 ($2));
1044 | bookpart_body full_markup_list {
1045 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1046 scm_call_2 (proc, $1, $2);
1048 | bookpart_body SCM_TOKEN {
1049 // Evaluate and ignore #xxx, as opposed to \xxx
1050 parser->lexer_->eval_scm_token ($2, @2);
1052 | bookpart_body embedded_scm_active
1054 SCM out = SCM_UNDEFINED;
1055 if (Text_interface::is_markup ($2))
1056 out = scm_list_1 ($2);
1057 else if (Text_interface::is_markup_list ($2))
1059 if (scm_is_pair (out))
1061 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1062 scm_call_2 (proc, $1, out);
1063 } else if (unsmob<Score> ($2))
1065 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1066 scm_call_2 (proc, $1, $2);
1067 } else if (Output_def *od = unsmob<Output_def> ($2)) {
1068 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper")))) {
1069 unsmob<Book> ($1)->paper_ = od;
1071 parser->parser_error (@2, _ ("need \\paper for paper block"));
1073 } else if (ly_is_module ($2)) {
1074 Book *book = unsmob<Book> ($1);
1075 if (!ly_is_module (book->header_))
1076 book->header_ = ly_make_module (false);
1077 ly_module_copy (book->header_, $2);
1078 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1079 parser->parser_error (@2, _("bad expression type"));
1083 Book *book = unsmob<Book> ($1);
1084 if (!ly_is_module (book->header_))
1085 book->header_ = ly_make_module (false);
1086 parser->lexer_->add_scope (book->header_);
1088 | bookpart_body error {
1089 Book *book = unsmob<Book> ($1);
1091 book->scores_ = SCM_EOL;
1096 SCORE '{' score_body '}' {
1097 unsmob<Score> ($3)->origin ()->set_spot (@$);
1104 if (!unsmob<Score> ($1)) {
1105 parser->parser_error (@1, _("Missing music in \\score"));
1106 $$ = (new Score)->unprotect ();
1107 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
1109 unsmob<Score> ($$)->set_header (scm_car ($1));
1112 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1113 scm_is_pair (p); p = scm_cdr (p))
1115 unsmob<Score> ($$)->
1116 add_output_def (unsmob<Output_def> (scm_car (p)));
1120 | score_body error {
1121 unsmob<Score> ($$)->error_found_ = true;
1136 | score_items score_item
1138 Output_def *od = unsmob<Output_def> ($2);
1140 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1142 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1144 $2 = SCM_UNSPECIFIED;
1146 } else if (!unsmob<Score> ($$)) {
1147 if (unsmob<Music> ($2)) {
1148 $2 = Lily::scorify_music ($2);
1150 if (unsmob<Score> ($2))
1153 $2 = SCM_UNSPECIFIED;
1156 Score *score = unsmob<Score> ($$);
1157 if (score && scm_is_pair ($1)) {
1158 if (ly_is_module (scm_car ($1)))
1160 score->set_header (scm_car ($1));
1163 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1164 scm_is_pair (p); p = scm_cdr (p))
1166 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1171 score->add_output_def (od);
1172 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1173 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1175 $$ = scm_cons ($2, $$);
1176 } else if (ly_is_module ($2)) {
1177 SCM module = SCM_UNSPECIFIED;
1179 module = score->get_header ();
1180 if (!ly_is_module (module))
1182 module = ly_make_module (false);
1183 score->set_header (module);
1185 } else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1186 module = scm_car ($$);
1188 module = ly_make_module (false);
1189 $$ = scm_cons (module, $$);
1191 ly_module_copy (module, $2);
1192 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1193 parser->parser_error (@2, _("Spurious expression in \\score"));
1197 if (Score *score = unsmob<Score> ($1)) {
1198 if (!ly_is_module (score->get_header ()))
1199 score->set_header (ly_make_module (false));
1200 parser->lexer_->add_scope (score->get_header ());
1202 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1203 $1 = scm_cons (ly_make_module (false), $1);
1204 parser->lexer_->add_scope (scm_car ($1));
1219 Output_def *od = unsmob<Output_def> ($1);
1221 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1223 parser->parser_error (@1, _ ("need \\paper for paper block"));
1224 $$ = get_paper (parser)->unprotect ();
1231 output_def_body '}' {
1232 if (scm_is_pair ($1))
1235 parser->lexer_->remove_scope ();
1236 parser->lexer_->pop_state ();
1242 Output_def *p = get_paper (parser);
1243 p->input_origin_ = @$;
1244 parser->lexer_->add_scope (p->scope_);
1245 $$ = p->unprotect ();
1248 Output_def *p = get_midi (parser);
1249 $$ = p->unprotect ();
1250 parser->lexer_->add_scope (p->scope_);
1253 Output_def *p = get_layout (parser);
1255 parser->lexer_->add_scope (p->scope_);
1256 $$ = p->unprotect ();
1260 output_def_head_with_mode_switch:
1262 parser->lexer_->push_initial_state ();
1267 // We need this weird nonterminal because both music as well as a
1268 // context definition can start with \context and the difference is
1269 // only apparent after looking at the next token. If it is '{', there
1270 // is still time to escape from notes mode.
1272 music_or_context_def:
1274 | context_def_spec_block
1278 output_def_head_with_mode_switch '{' {
1279 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1280 // This is a stupid trick to mark the beginning of the
1281 // body for deciding whether to allow
1282 // embedded_scm_active to have an output definition
1283 $$ = scm_list_1 ($1);
1285 | output_def_body assignment {
1286 if (scm_is_pair ($1))
1289 | output_def_body embedded_scm_active
1291 // We don't switch into note mode for Scheme functions
1292 // here. Does not seem warranted/required in output
1294 if (scm_is_pair ($1))
1296 Output_def *o = unsmob<Output_def> ($2);
1298 o->input_origin_.set_spot (@$);
1299 $1 = o->self_scm ();
1300 parser->lexer_->remove_scope ();
1301 parser->lexer_->add_scope (o->scope_);
1302 $2 = SCM_UNSPECIFIED;
1306 if (unsmob<Context_def> ($2))
1307 assign_context_def (unsmob<Output_def> ($1), $2);
1308 // Seems unlikely, but let's be complete:
1309 else if (unsmob<Music> ($2))
1311 SCM proc = parser->lexer_->lookup_identifier
1312 ("output-def-music-handler");
1313 scm_call_2 (proc, $1, $2);
1314 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1315 parser->parser_error (@2, _("bad expression type"));
1318 | output_def_body SCM_TOKEN {
1319 if (scm_is_pair ($1))
1321 // Evaluate and ignore #xxx, as opposed to \xxx
1322 parser->lexer_->eval_scm_token ($2, @2);
1326 if (scm_is_pair ($1))
1328 parser->lexer_->push_note_state (Lily::pitchnames);
1329 } music_or_context_def
1331 parser->lexer_->pop_state ();
1332 if (unsmob<Context_def> ($3))
1333 assign_context_def (unsmob<Output_def> ($1), $3);
1336 SCM proc = parser->lexer_->lookup_identifier
1337 ("output-def-music-handler");
1338 scm_call_2 (proc, $1, $3);
1342 | output_def_body error {
1348 TEMPO steno_duration '=' tempo_range {
1349 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1351 | TEMPO text steno_duration '=' tempo_range {
1352 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1355 $$ = MAKE_SYNTAX (tempo, @$, $2);
1360 The representation of a list is reversed to have efficient append. */
1366 | music_list music_embedded {
1367 if (unsmob<Music> ($2))
1368 $$ = scm_cons ($2, $1);
1370 | music_list error {
1371 Music *m = MY_MAKE_MUSIC("Music", @$);
1373 m->set_property ("error-found", SCM_BOOL_T);
1374 $$ = scm_cons (m->self_scm (), $1);
1375 m->unprotect (); /* UGH */
1382 $$ = scm_reverse_x ($2, SCM_EOL);
1387 | lyric_element_music
1394 $$ = make_music_from_simple (parser, @1, $1);
1395 if (!unsmob<Music> ($$))
1397 parser->parser_error (@1, _ ("music expected"));
1398 $$ = MAKE_SYNTAX (void_music, @$);
1406 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1407 parser->parser_error (@1, _ ("unexpected post-event"));
1408 $$ = SCM_UNSPECIFIED;
1411 | music_embedded_backup
1415 | music_embedded_backup BACKUP lyric_element_music
1419 | multiplied_duration post_events
1421 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1423 parser->default_duration_ = *unsmob<Duration> ($1);
1424 n->set_property ("duration", $1);
1426 if (scm_is_pair ($2))
1427 n->set_property ("articulations",
1428 scm_reverse_x ($2, SCM_EOL));
1429 $$ = n->unprotect ();
1433 music_embedded_backup:
1436 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1438 else if (Music *m = unsmob<Music> ($1)) {
1439 if (m->is_mus_type ("post-event")) {
1440 parser->parser_error
1441 (@1, _ ("unexpected post-event"));
1442 $$ = SCM_UNSPECIFIED;
1445 } else if (parser->lexer_->is_lyric_state ()
1446 && Text_interface::is_markup ($1))
1447 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1449 @$.warning (_ ("Ignoring non-music expression"));
1455 // music_assign does not need to contain lyrics: there are no
1456 // assignments in lyricmode.
1459 | composite_music %prec COMPOSITE
1463 REPEAT simple_string unsigned_number music
1465 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1467 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1469 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1474 SEQUENTIAL braced_music_list {
1475 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1477 | braced_music_list {
1478 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1483 SIMULTANEOUS braced_music_list {
1484 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1486 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1487 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1493 | music_property_def
1497 context_modification:
1500 parser->lexer_->push_note_state (Lily::pitchnames);
1501 } '{' context_mod_list '}'
1503 parser->lexer_->pop_state ();
1506 | WITH context_modification_arg
1508 if (unsmob<Music> ($2)) {
1509 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1510 $2 = scm_call_1 (proc, $2);
1512 if (unsmob<Context_mod> ($2))
1515 // let's permit \with #*unspecified* to go for
1516 // an empty context mod
1517 if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1518 parser->parser_error (@2, _ ("not a context mod"));
1519 $$ = Context_mod ().smobbed_copy ();
1524 context_modification_arg:
1529 /* A list of single mods collected from a (possibly empty) sequence of
1530 * context modifications, usually written as \with ... \with ...
1533 optional_context_mods:
1534 context_modification_mods_list
1536 if (scm_is_pair ($1))
1537 $$ = scm_append_x (scm_reverse_x ($1, SCM_EOL));
1541 /* The worker for optional_context_mods conses a (reversed) list where
1542 * each element contains the list of single context mods from one
1543 * context modification block. Context_mod::get_mods creates fresh
1544 * copies, so it's okay to use append! on them.
1547 context_modification_mods_list:
1551 | context_modification_mods_list context_modification
1553 if (Context_mod *m = unsmob<Context_mod> ($2))
1554 $$ = scm_cons (m->get_mods (), $1);
1558 /* A Context_mod is a container for a list of context mods like
1559 * \consists ... \override ... . context_mod_list produces a
1560 * Context_mod from the inside of a \with { ... } statement.
1565 $$ = Context_mod ().smobbed_copy ();
1567 | context_mod_list context_mod {
1568 if (!SCM_UNBNDP ($2))
1569 unsmob<Context_mod> ($1)->add_context_mod ($2);
1571 | context_mod_list context_mod_arg {
1572 if (unsmob<Music> ($2)) {
1573 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1574 $2 = scm_call_1 (proc, $2);
1576 if (unsmob<Context_mod> ($2))
1577 unsmob<Context_mod> ($$)->add_context_mods
1578 (unsmob<Context_mod> ($2)->get_mods ());
1579 else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1580 parser->parser_error (@2, _ ("not a context mod"));
1585 CONTEXT symbol optional_id optional_context_mods {
1586 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_F);
1588 | NEWCONTEXT symbol optional_id optional_context_mods {
1589 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_T);
1594 ADDLYRICS optional_context_mods lyric_mode_music {
1595 $$ = scm_acons ($3, $2, SCM_EOL);
1597 | new_lyrics ADDLYRICS optional_context_mods lyric_mode_music {
1598 $$ = scm_acons ($4, $3, $1);
1602 /* basic_music is basically the same as composite_music but with
1603 * context-prefixed music and lyricized music explicitly removed. The
1604 * reason is that in a sequence
1606 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1608 * we need to group both \addlyrics together (as they go with the same
1609 * voice) but then combine them with \new Voice { ... }, meaning that
1610 * combining \new Voice { ... } needs higher priority than
1611 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1612 * combine before combining \new Voice { ... } \addlyrics: only one
1613 * layer of context-prefixed music should assemble before \addlyrics
1614 * is integrated. Total mess, and we sort this mess out with explicit
1615 * rules preferring a single context-prefix.
1622 | LYRICSTO simple_string lyric_mode_music {
1623 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1625 | LYRICSTO symbol '=' simple_string lyric_mode_music
1627 $$ = MAKE_SYNTAX (lyric_combine, @$, $4, $2, $5);
1637 contexted_basic_music:
1638 context_prefix contextable_music new_lyrics
1641 i.set_location (@1, @2);
1642 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1643 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1645 | context_prefix contextable_music
1647 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1649 | context_prefix contexted_basic_music
1651 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1656 basic_music %prec COMPOSITE
1657 | contexted_basic_music
1658 | basic_music new_lyrics
1660 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1667 | grouped_music_list
1671 simultaneous_music { $$ = $1; }
1672 | sequential_music { $$ = $1; }
1675 /* Function argument lists are arguably the most complex part in the
1676 * parser. They are pretty tricky to understand because of the way
1677 * they are processed, and because of optional arguments that can be
1678 * omitted. When there are several optional arguments in a row,
1679 * omitting one automatically omits all following arguments. Optional
1680 * arguments can only be omitted when either
1682 * a) the omission is explicitly started with \default
1683 * b) the omission is implicitly started by an argument not matching
1684 * its predicate, and there is a mandatory argument later that can
1685 * "catch" the argument that does not fit.
1687 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1688 * (corresponding to mandatory arguments and having a predicate
1689 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1690 * the semantic value of the EXPECT_OPTIONAL token is the default to
1691 * use when the optional argument is omitted, and EXPECT_SCM again has
1692 * the argument predicate as semantic value) in reverse order to the
1693 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1694 * processed inside-out while actual tokens are consumed.
1696 * This means that the argument list tokens determine the actions
1697 * taken as they arrive. The structure of the argument list is known
1698 * to the parser and stored in its parse stack when the first argument
1699 * is being parsed. What the parser does not know is which predicates
1700 * will match and whether or not \default will be appearing in the
1701 * argument list, and where.
1703 * Sequences of 0 or more optional arguments are scanned using either
1704 * function_arglist_backup or function_arglist_nonbackup. The first
1705 * is used when optional arguments are followed by at least one
1706 * mandatory argument: in that case optional arguments may be skipped
1707 * by either a false predicate (in which case the expression will be
1708 * pushed back as one or more tokens, preceded by a BACKUP token) or
1709 * by using \default.
1711 * If optional arguments are at the end of the argument list, they are
1712 * instead scanned using function_arglist_nonbackup: here the only
1713 * manner to enter into skipping of optional arguments is the use of
1716 * The argument list of a normal function call is parsed using
1717 * function_arglist. The part of an argument list before a mandatory
1718 * argument is parsed using function_arglist_optional.
1720 * The difference is that leading optional arguments are scanned using
1721 * function_arglist_nonbackup and function_arglist_backup,
1724 * Most other details are obvious in the rules themselves.
1730 | SYMBOL_LIST '.' symbol_list_rev
1732 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1734 | SYMBOL_LIST ',' symbol_list_rev
1736 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1742 | symbol_list_rev '.' symbol_list_part
1744 $$ = scm_append_x (scm_list_2 ($3, $1));
1746 | symbol_list_rev ',' symbol_list_part
1748 $$ = scm_append_x (scm_list_2 ($3, $1));
1752 // symbol_list_part delivers elements in reverse copy, no lookahead
1755 symbol_list_part_bare
1758 $$ = make_reverse_key_list ($1);
1759 if (SCM_UNBNDP ($$)) {
1760 parser->parser_error (@1, _("not a key"));
1767 symbol_list_element:
1770 $$ = scm_string_to_symbol ($1);
1776 symbol_list_part_bare:
1779 $$ = try_word_variants (Lily::key_list_p, $1);
1780 if (SCM_UNBNDP ($$)) {
1781 parser->parser_error (@1, _("not a key"));
1784 $$ = scm_reverse ($$);
1786 | symbol_list_element
1788 $$ = scm_list_1 ($1);
1792 function_arglist_nonbackup:
1793 function_arglist_common
1794 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1796 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1798 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1800 SCM n = scm_difference ($5, SCM_UNDEFINED);
1801 if (scm_is_true (scm_call_1 ($2, n)))
1802 $$ = scm_cons (n, $3);
1804 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1805 t->set_property ("digit", $5);
1806 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1810 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1812 $$ = check_scheme_arg (parser, @4,
1813 scm_difference ($5, SCM_UNDEFINED),
1816 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1818 $$ = check_scheme_arg (parser, @4,
1819 scm_difference ($5, SCM_UNDEFINED),
1822 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1824 if (scm_is_true (scm_call_1 ($2, $4)))
1825 $$ = scm_cons ($4, $3);
1827 $$ = check_scheme_arg (parser, @4,
1828 make_music_from_simple
1832 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1834 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1836 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1838 if (scm_is_true (scm_call_1 ($2, $3)))
1839 $$ = scm_cons ($3, $1);
1841 $$ = check_scheme_arg (parser, @3,
1842 make_music_from_simple
1846 | function_arglist_nonbackup_reparse REPARSE multiplied_duration
1848 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1850 | function_arglist_nonbackup_reparse REPARSE reparsed_rhythm
1852 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1854 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1856 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1858 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1860 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1862 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1864 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1866 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1868 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1874 DURATION_ARG dots multipliers post_events
1876 $$ = make_music_from_simple (parser, @$,
1877 make_duration ($1, scm_to_int ($2), $3));
1878 Music *m = unsmob<Music> ($$);
1880 if (scm_is_pair ($4))
1881 m->set_property ("articulations",
1882 scm_reverse_x ($4, SCM_EOL));
1886 function_arglist_nonbackup_reparse:
1887 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1890 SCM res = try_string_variants ($2, $4);
1891 if (!SCM_UNBNDP (res))
1892 if (scm_is_pair (res))
1893 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1895 MYREPARSE (@4, $2, SCM_ARG, res);
1896 else if (scm_is_true
1898 ($2, make_music_from_simple
1900 MYREPARSE (@4, $2, STRING, $4);
1902 MYREPARSE (@4, $2, SCM_ARG, $4);
1904 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1909 ($2, make_music_from_simple
1911 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1913 MYREPARSE (@4, $2, SCM_ARG, $4);
1915 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1920 ($2, make_music_from_simple
1922 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1924 MYREPARSE (@4, $2, SCM_ARG, $4);
1926 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1929 SCM res = try_string_variants ($2, $4);
1930 if (!SCM_UNBNDP (res))
1931 if (scm_is_pair (res))
1932 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1934 MYREPARSE (@4, $2, SCM_ARG, res);
1935 else if (scm_is_true
1937 ($2, make_music_from_simple
1939 MYREPARSE (@4, $2, STRING, $4);
1941 MYREPARSE (@4, $2, SCM_ARG, $4);
1943 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SYMBOL
1946 SCM res = try_word_variants ($2, $4);
1947 if (!SCM_UNBNDP (res))
1948 if (scm_is_pair (res))
1949 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1951 MYREPARSE (@4, $2, SCM_ARG, res);
1952 else if (scm_is_true
1954 ($2, make_music_from_simple
1956 MYREPARSE (@4, $2, STRING, $4);
1958 MYREPARSE (@4, $2, SCM_ARG, $4);
1960 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1963 if (scm_is_true (scm_call_1 ($2, $4)))
1964 MYREPARSE (@4, $2, SCM_ARG, $4);
1965 else if (scm_is_true
1967 ($2, make_music_from_simple
1969 MYREPARSE (@4, $2, STRING, $4);
1971 MYREPARSE (@4, $2, SCM_ARG, $4);
1973 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1976 if (scm_is_true (scm_call_1 ($2, $4)))
1977 // May be 3 \cm or similar
1978 MYREPARSE (@4, $2, REAL, $4);
1979 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
1980 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
1982 SCM d = make_duration ($4);
1983 if (!SCM_UNBNDP (d)) {
1984 if (scm_is_true (scm_call_1 ($2, d)))
1985 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1986 else if (scm_is_true
1988 ($2, make_music_from_simple (parser, @4, d))))
1989 MYREPARSE (@4, $2, DURATION_ARG, d);
1991 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1993 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1996 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER
1999 if (scm_is_true (scm_call_1 ($2, $4)))
2000 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2001 else if (scm_is_true
2003 ($2, make_music_from_simple (parser, @4, $4))))
2004 MYREPARSE (@4, $2, DURATION_ARG, $4);
2006 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
2011 // function_arglist_backup can't occur at the end of an argument
2013 function_arglist_backup:
2014 function_arglist_common
2015 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
2017 if (scm_is_true (scm_call_1 ($2, $4)))
2018 $$ = scm_cons ($4, $3);
2020 $$ = make_music_from_simple (parser, @4, $4);
2021 if (scm_is_true (scm_call_1 ($2, $$)))
2022 $$ = scm_cons ($$, $3);
2025 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2026 MYBACKUP (SCM_ARG, $4, @4);
2030 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
2032 if (scm_is_true (scm_call_1 ($2, $4)))
2034 $$ = scm_cons ($4, $3);
2036 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2037 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
2040 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
2044 ($2, make_music_from_simple
2048 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
2049 } else if (scm_is_true (scm_call_1 ($2, $4)))
2050 $$ = scm_cons ($4, $3);
2052 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2053 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
2056 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
2060 ($2, make_music_from_simple
2064 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
2065 } else if (scm_is_true (scm_call_1 ($2, $4)))
2066 $$ = scm_cons ($4, $3);
2068 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2069 MYBACKUP (TONICNAME_PITCH, $4, @4);
2072 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
2074 if (scm_is_true (scm_call_1 ($2, $4)))
2075 $$ = scm_cons ($4, $3);
2077 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2078 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2081 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
2084 if (scm_is_true (scm_call_1 ($2, $4)))
2085 // May be 3 \cm or similar
2086 MYREPARSE (@4, $2, REAL, $4);
2087 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
2088 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
2090 SCM d = make_duration ($4);
2091 if (!SCM_UNBNDP (d)) {
2092 if (scm_is_true (scm_call_1 ($2, d)))
2093 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
2094 else if (scm_is_true
2096 ($2, make_music_from_simple (parser, @4, d))))
2097 MYREPARSE (@4, $2, DURATION_ARG, d);
2099 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2100 MYBACKUP (UNSIGNED, $4, @4);
2103 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2104 MYBACKUP (UNSIGNED, $4, @4);
2108 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
2110 if (scm_is_true (scm_call_1 ($2, $4)))
2113 MYREPARSE (@4, $2, REAL, $4);
2115 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2116 MYBACKUP (REAL, $4, @4);
2119 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
2121 if (scm_is_true (scm_call_1 ($2, $4)))
2123 $$ = scm_cons ($4, $3);
2125 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2126 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
2129 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
2131 SCM n = scm_difference ($5, SCM_UNDEFINED);
2132 if (scm_is_true (scm_call_1 ($2, n))) {
2134 MYREPARSE (@5, $2, REAL, n);
2136 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
2137 t->set_property ("digit", $5);
2138 $$ = t->unprotect ();
2139 if (scm_is_true (scm_call_1 ($2, $$)))
2140 $$ = scm_cons ($$, $3);
2142 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2143 MYBACKUP (UNSIGNED, $5, @5);
2144 parser->lexer_->push_extra_token (@4, '-');
2148 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2150 SCM n = scm_difference ($5, SCM_UNDEFINED);
2151 if (scm_is_true (scm_call_1 ($2, n))) {
2152 MYREPARSE (@5, $2, REAL, n);
2155 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2156 MYBACKUP (REAL, n, @5);
2159 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2161 SCM n = scm_difference ($5, SCM_UNDEFINED);
2162 if (scm_is_true (scm_call_1 ($2, n))) {
2163 $$ = scm_cons (n, $3);
2165 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2166 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2169 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2172 if (scm_is_true (scm_call_1 ($2, $4)))
2173 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2174 else if (scm_is_true
2176 ($2, make_music_from_simple (parser, @4, $4))))
2177 MYREPARSE (@4, $2, DURATION_ARG, $4);
2179 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2180 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2183 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2185 SCM res = try_string_variants ($2, $4);
2186 if (!SCM_UNBNDP (res))
2187 if (scm_is_pair (res)) {
2189 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2192 $$ = scm_cons (res, $3);
2194 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2195 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2198 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2200 SCM res = try_string_variants ($2, $4);
2201 if (!SCM_UNBNDP (res))
2202 if (scm_is_pair (res)) {
2204 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2207 $$ = scm_cons (res, $3);
2209 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2210 MYBACKUP (STRING, $4, @4);
2213 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SYMBOL
2215 SCM res = try_word_variants ($2, $4);
2216 if (!SCM_UNBNDP (res))
2217 if (scm_is_pair (res)) {
2219 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2222 $$ = scm_cons (res, $3);
2224 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2225 MYBACKUP (STRING, $4, @4);
2228 | function_arglist_backup REPARSE pitch_or_music
2230 if (scm_is_true (scm_call_1 ($2, $3)))
2231 $$ = scm_cons ($3, $1);
2233 $$ = check_scheme_arg (parser, @3,
2234 make_music_from_simple
2238 | function_arglist_backup REPARSE bare_number_common
2240 $$ = check_scheme_arg (parser, @3,
2243 | function_arglist_backup REPARSE multiplied_duration
2245 $$ = check_scheme_arg (parser, @3,
2248 | function_arglist_backup REPARSE reparsed_rhythm
2250 $$ = check_scheme_arg (parser, @3,
2253 | function_arglist_backup REPARSE symbol_list_arg
2255 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2260 function_arglist_nonbackup
2261 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2263 $$ = scm_cons (loc_on_copy (parser, @4, $1), $3);
2267 function_arglist_skip_nonbackup:
2268 function_arglist_nonbackup
2269 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2271 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2275 // Partial function arglists are returned just in their incomplete
2276 // state: when combined with the music function, the missing parts of
2277 // the signature can be reconstructed
2279 // To serve as a partial arglist, the argument list must absolutely
2280 // _not_ be in "skipping optional arguments" mode since then there is
2281 // some backup token that has nowhere to go before \etc.
2283 // So we can skim off an arbitrary number of arguments from the end of
2284 // the argument list. The argument list remaining afterwards has to
2285 // be in not-skipping-optional-arguments mode.
2287 function_arglist_partial:
2288 EXPECT_SCM function_arglist_optional
2292 | EXPECT_SCM function_arglist_partial_optional
2296 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2300 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2306 function_arglist_partial_optional:
2307 EXPECT_SCM function_arglist_optional
2311 | EXPECT_SCM function_arglist_partial_optional
2315 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2319 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2325 function_arglist_common:
2326 EXPECT_NO_MORE_ARGS {
2329 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2331 if (scm_is_true (scm_call_1 ($1, $3)))
2332 $$ = scm_cons ($3, $2);
2334 $$ = check_scheme_arg (parser, @3,
2335 make_music_from_simple
2339 | EXPECT_SCM function_arglist_optional bare_number_common
2341 $$ = check_scheme_arg (parser, @3,
2344 | EXPECT_SCM function_arglist_optional post_event_nofinger
2346 $$ = check_scheme_arg (parser, @3,
2349 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2351 SCM n = scm_difference ($4, SCM_UNDEFINED);
2352 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2354 | function_arglist_common_reparse REPARSE SCM_ARG
2356 $$ = check_scheme_arg (parser, @3,
2359 | function_arglist_common_reparse REPARSE lyric_element_music
2361 $$ = check_scheme_arg (parser, @3,
2364 | function_arglist_common_reparse REPARSE pitch_or_music
2366 if (scm_is_true (scm_call_1 ($2, $3)))
2367 $$ = scm_cons ($3, $1);
2369 $$ = check_scheme_arg (parser, @3,
2370 make_music_from_simple
2374 | function_arglist_common_reparse REPARSE bare_number_common
2376 $$ = check_scheme_arg (parser, @3,
2379 | function_arglist_common_reparse REPARSE multiplied_duration
2381 $$ = check_scheme_arg (parser, @3,
2384 | function_arglist_common_reparse REPARSE reparsed_rhythm
2386 $$ = check_scheme_arg (parser, @3,
2389 | function_arglist_common_reparse REPARSE symbol_list_arg
2391 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2395 function_arglist_common_reparse:
2396 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2399 SCM res = try_string_variants ($1, $3);
2400 if (!SCM_UNBNDP (res))
2401 if (scm_is_pair (res))
2402 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2404 MYREPARSE (@3, $1, SCM_ARG, res);
2405 else if (scm_is_true
2407 ($1, make_music_from_simple (parser, @3, $3))))
2408 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2410 // This is going to flag a syntax error, we
2411 // know the predicate to be false.
2412 MYREPARSE (@3, $1, SCM_ARG, $3);
2414 | EXPECT_SCM function_arglist_optional pitch
2419 ($1, make_music_from_simple
2421 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2423 MYREPARSE (@3, $1, SCM_ARG, $3);
2425 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2430 ($1, make_music_from_simple
2432 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2434 MYREPARSE (@3, $1, SCM_ARG, $3);
2436 | EXPECT_SCM function_arglist_optional STRING
2439 SCM res = try_string_variants ($1, $3);
2440 if (!SCM_UNBNDP (res))
2441 if (scm_is_pair (res))
2442 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2444 MYREPARSE (@3, $1, SCM_ARG, res);
2445 else if (scm_is_true
2447 ($1, make_music_from_simple (parser, @3, $3))))
2448 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2450 // This is going to flag a syntax error, we
2451 // know the predicate to be false.
2452 MYREPARSE (@3, $1, SCM_ARG, $3);
2454 | EXPECT_SCM function_arglist_optional SYMBOL
2457 SCM res = try_word_variants ($1, $3);
2458 if (!SCM_UNBNDP (res))
2459 if (scm_is_pair (res))
2460 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2462 MYREPARSE (@3, $1, SCM_ARG, res);
2463 else if (scm_is_true
2465 ($1, make_music_from_simple (parser, @3, $3))))
2466 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2468 // This is going to flag a syntax error, we
2469 // know the predicate to be false.
2470 MYREPARSE (@3, $1, SCM_ARG, $3);
2472 | EXPECT_SCM function_arglist_optional full_markup
2475 if (scm_is_true (scm_call_1 ($1, $3)))
2476 MYREPARSE (@3, $1, SCM_ARG, $3);
2477 else if (scm_is_true
2479 ($1, make_music_from_simple (parser, @3, $3))))
2480 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2482 // This is going to flag a syntax error, we
2483 // know the predicate to be false.
2484 MYREPARSE (@3, $1, SCM_ARG, $3);
2486 | EXPECT_SCM function_arglist_optional UNSIGNED
2489 if (scm_is_true (scm_call_1 ($1, $3)))
2490 // May be 3 \cm or similar
2491 MYREPARSE (@3, $1, REAL, $3);
2492 else if (scm_is_true (scm_call_1 ($1, scm_list_1 ($3))))
2493 MYREPARSE (@3, $1, SYMBOL_LIST, scm_list_1 ($3));
2495 SCM d = make_duration ($3);
2496 if (!SCM_UNBNDP (d)) {
2497 if (scm_is_true (scm_call_1 ($1, d)))
2498 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2499 else if (scm_is_true
2501 ($1, make_music_from_simple (parser, @3, d))))
2502 MYREPARSE (@3, $1, DURATION_ARG, d);
2504 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2506 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2509 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2512 if (scm_is_true (scm_call_1 ($1, $3)))
2513 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2514 else if (scm_is_true
2516 ($1, make_music_from_simple (parser, @3, $3))))
2517 MYREPARSE (@3, $1, DURATION_ARG, $3);
2519 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2521 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2524 SCM n = scm_difference ($4, SCM_UNDEFINED);
2525 if (scm_is_true (scm_call_1 ($1, n)))
2526 MYREPARSE (@4, $1, REAL, n);
2528 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2529 t->set_property ("digit", $4);
2530 SCM m = t->unprotect ();
2531 if (scm_is_true (scm_call_1 ($1, m)))
2532 MYREPARSE (@4, $1, SCM_ARG, m);
2534 MYREPARSE (@4, $1, SCM_ARG, $4);
2537 | EXPECT_SCM function_arglist_optional '-' REAL
2540 SCM n = scm_difference ($4, SCM_UNDEFINED);
2541 MYREPARSE (@4, $1, REAL, n);
2545 function_arglist_optional:
2546 function_arglist_backup
2547 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2549 $$ = scm_cons (loc_on_copy (parser, @4, $1), $3);
2551 | function_arglist_skip_backup BACKUP
2554 function_arglist_skip_backup:
2555 function_arglist_backup
2556 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2558 $$ = scm_cons (loc_on_copy (parser, @3, $1), $3);
2562 music_function_call:
2563 MUSIC_FUNCTION function_arglist {
2564 $$ = MAKE_SYNTAX (music_function, @$,
2571 /**/ { $$ = SCM_EOL; }
2572 | '=' simple_string {
2577 // We must not have lookahead tokens parsed in lyric mode. In order
2578 // to save confusion, we take almost the same set as permitted with
2579 // \lyricmode and/or \lyrics. However, music identifiers are also
2580 // allowed, and they obviously do not require switching into lyrics
2581 // mode for parsing.
2585 parser->lexer_->push_lyric_state ();
2586 } grouped_music_list
2588 parser->lexer_->pop_state ();
2595 mode_changing_head grouped_music_list {
2596 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2598 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2604 parser->lexer_->pop_state ();
2606 | mode_changing_head_with_context optional_context_mods grouped_music_list {
2607 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, $2, SCM_BOOL_T, $3);
2608 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2610 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2612 parser->lexer_->pop_state ();
2618 parser->lexer_->push_note_state (Lily::pitchnames);
2620 $$ = ly_symbol2scm ("notes");
2624 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2626 $$ = ly_symbol2scm ("drums");
2629 parser->lexer_->push_figuredbass_state ();
2631 $$ = ly_symbol2scm ("figures");
2634 parser->lexer_->chordmodifier_tab_ =
2635 alist_to_hashq (Lily::chordmodifiers);
2636 parser->lexer_->push_chord_state (Lily::pitchnames);
2637 $$ = ly_symbol2scm ("chords");
2641 { parser->lexer_->push_lyric_state ();
2642 $$ = ly_symbol2scm ("lyrics");
2646 mode_changing_head_with_context:
2648 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2650 $$ = ly_symbol2scm ("DrumStaff");
2653 parser->lexer_->push_figuredbass_state ();
2655 $$ = ly_symbol2scm ("FiguredBass");
2658 parser->lexer_->chordmodifier_tab_ =
2659 alist_to_hashq (Lily::chordmodifiers);
2660 parser->lexer_->push_chord_state (Lily::pitchnames);
2661 $$ = ly_symbol2scm ("ChordNames");
2664 { parser->lexer_->push_lyric_state ();
2665 $$ = ly_symbol2scm ("Lyrics");
2670 CHANGE symbol '=' simple_string {
2671 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2678 $$ = scm_reverse_x ($1, SCM_EOL);
2684 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2687 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2689 | OVERRIDE revert_arg '=' scalar {
2690 if (scm_ilength ($2) < 2) {
2691 parser->parser_error (@2, _("bad grob property path"));
2694 $$ = scm_cons (ly_symbol2scm ("push"),
2695 scm_cons2 (scm_car ($2),
2700 | REVERT revert_arg {
2701 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2705 // This is all quite awkward for the sake of substantial backward
2706 // compatibility while at the same time allowing a more "natural" form
2707 // of specification not separating grob specification from grob
2708 // property path. The purpose of this definition of revert_arg is to
2709 // allow the symbol list which specifies grob and property to revert
2710 // to be optionally be split into two parts after the grob (which in
2711 // this case is just the first element of the list). symbol_list_part
2712 // is only one path component, but it can be parsed without lookahead,
2713 // so we can follow it with a synthetic BACKUP token when needed. If
2714 // the first symbol_list_part already contains multiple elements (only
2715 // possible if a Scheme expression provides them), we just parse for
2716 // additional elements introduced by '.', which is what the
2717 // SYMBOL_LIST backup in connection with the immediately following
2718 // rule using symbol_list_arg does.
2720 // As long as we don't have our coffers filled with both grob and at
2721 // least one grob property specification, the rest of the required
2722 // symbol list chain may be provided either with or without a leading
2723 // dot. This is for both allowing the traditional
2724 // \revert Accidental #'color
2725 // as well as well as the "naive" form
2726 // \revert Accidental.color
2729 revert_arg_backup BACKUP symbol_list_arg
2738 if (scm_is_null ($1)
2739 || scm_is_null (scm_cdr ($1)))
2740 MYBACKUP (SCM_ARG, $1, @1);
2742 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2746 // revert_arg_part delivers results in reverse
2749 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2751 $$ = scm_append_x (scm_list_2 ($5, $3));
2753 | revert_arg_backup BACKUP SCM_ARG ',' symbol_list_part
2755 $$ = scm_append_x (scm_list_2 ($5, $3));
2757 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2759 $$ = scm_append_x (scm_list_2 ($4, $3));
2764 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2765 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2767 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2768 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2769 | DENIES { $$ = ly_symbol2scm ("denies"); }
2771 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2772 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2773 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2774 | NAME { $$ = ly_symbol2scm ("context-name"); }
2778 property_operation { $$ = $1; }
2779 | context_def_mod STRING {
2780 $$ = scm_list_2 ($1, $2);
2782 | context_def_mod SYMBOL {
2783 $$ = scm_list_2 ($1, $2);
2785 | context_def_mod embedded_scm
2787 if (!scm_is_string ($2)
2788 && !scm_is_eq ($1, ly_symbol2scm ("consists"))
2789 && !scm_is_eq ($1, ly_symbol2scm ("remove")))
2792 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2796 $$ = scm_list_2 ($1, $2);
2801 // If defined, at least two members.
2805 SCM l = scm_reverse_x ($1, SCM_EOL);
2808 (scm_object_property (scm_car (l),
2809 ly_symbol2scm ("is-grob?"))))
2810 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2811 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2812 parser->parser_error (@1, _ ("bad grob property path"));
2819 // If defined, at least three members
2823 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2825 parser->parser_error (@1, _ ("bad grob property path"));
2829 | grob_prop_spec property_path
2831 if (!SCM_UNBNDP ($1)) {
2832 $$ = scm_append_x (scm_list_2 ($1, $2));
2833 if (scm_is_null (scm_cddr ($$))) {
2834 parser->parser_error (@$, _ ("bad grob property path"));
2842 // Exactly two elements or undefined
2846 SCM l = scm_reverse_x ($1, SCM_EOL);
2847 switch (scm_ilength (l)) {
2849 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2853 parser->parser_error (@1, _ ("bad context property path"));
2861 // This is all quite awkward for the sake of substantial backward
2862 // compatibility while at the same time allowing a more "natural" form
2863 // of specification not separating grob specification from grob
2864 // property path. The purpose of this definition of
2865 // simple_revert_context is to allow the symbol list which specifies
2866 // grob and property to revert to be optionally be split into two
2867 // parts after the grob (which may be preceded by a context
2868 // specification, a case which we distinguish by checking whether the
2869 // first symbol is a valid grob symbol instead).
2871 // See revert_arg above for the main work horse of this arrangement.
2872 // simple_revert_context just caters for the context and delegates the
2873 // rest of the job to revert_arg.
2875 simple_revert_context:
2878 $1 = scm_reverse_x ($1, SCM_EOL);
2879 if (scm_is_null ($1)
2881 (scm_object_property (scm_car ($1),
2882 ly_symbol2scm ("is-grob?")))) {
2883 $$ = ly_symbol2scm ("Bottom");
2884 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2887 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2894 OVERRIDE grob_prop_path '=' scalar {
2895 if (SCM_UNBNDP ($2))
2896 $$ = MAKE_SYNTAX (void_music, @$);
2898 $$ = MAKE_SYNTAX (property_override, @$,
2903 | REVERT simple_revert_context revert_arg {
2904 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2906 | SET context_prop_spec '=' scalar {
2907 if (SCM_UNBNDP ($2))
2908 $$ = MAKE_SYNTAX (void_music, @$);
2910 $$ = MAKE_SYNTAX (property_set, @$,
2915 | UNSET context_prop_spec {
2916 if (SCM_UNBNDP ($2))
2917 $$ = MAKE_SYNTAX (void_music, @$);
2919 $$ = MAKE_SYNTAX (property_unset, @$,
2937 if (Text_interface::is_markup ($1)) {
2940 parser->parser_error (@1, (_ ("markup expected")));
2941 $$ = scm_string (SCM_EOL);
2946 simple_string: STRING
2950 if (scm_is_string ($1)) {
2953 parser->parser_error (@1, (_ ("simple string expected")));
2954 $$ = scm_string (SCM_EOL);
2961 $$ = scm_string_to_symbol ($1);
2965 if (!is_regular_identifier ($1, false))
2966 parser->parser_error (@1, (_ ("symbol expected")));
2967 $$ = scm_string_to_symbol ($1);
2971 // This is a bit of overkill but makes the same
2972 // routine responsible for all symbol interpretations.
2973 $$ = try_string_variants (Guile_user::symbol_p, $1);
2974 if (SCM_UNBNDP ($$))
2976 parser->parser_error (@1, (_ ("symbol expected")));
2977 // Generate a unique symbol in case it is used
2978 // for an assignment or similar
2979 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2989 // The following is a rather defensive variant of admitting
2990 // negative numbers: the grammar would permit number_factor or
2991 // even number_expression. However, function arguments allow
2992 // only this simple kind of negative number, so to have things
2993 // like \tweak and \override behave reasonably similar, it
2994 // makes sense to rule out things like -- which are rather an
2995 // accent in function argument contexts.
2998 $$ = scm_difference ($2, SCM_UNDEFINED);
3001 | symbol_list_part_bare '.' property_path
3003 $$ = scm_reverse_x ($1, $3);
3005 | symbol_list_part_bare ',' property_path
3007 $$ = scm_reverse_x ($1, $3);
3012 simple_element post_events {
3013 // Let the rhythmic music iterator sort this mess out.
3014 if (scm_is_pair ($2)) {
3015 unsmob<Music> ($$)->set_property ("articulations",
3016 scm_reverse_x ($2, SCM_EOL));
3019 | CHORD_REPETITION optional_notemode_duration post_events {
3020 $$ = MAKE_SYNTAX (repetition_chord, @$,
3021 $2, scm_reverse_x ($3, SCM_EOL));
3023 | MULTI_MEASURE_REST optional_notemode_duration post_events {
3024 $$ = MAKE_SYNTAX (multi_measure_rest, @$, $2,
3025 scm_reverse_x ($3, SCM_EOL));
3028 | note_chord_element
3033 chord_body optional_notemode_duration post_events
3035 Music *m = unsmob<Music> ($1);
3036 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
3037 SCM es = m->get_property ("elements");
3038 SCM postevs = scm_reverse_x ($3, SCM_EOL);
3040 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
3041 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
3042 es = ly_append2 (es, postevs);
3044 m->set_property ("elements", es);
3045 m->set_spot (parser->lexer_->override_input (@$));
3046 $$ = m->self_scm ();
3051 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
3053 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
3055 | FIGURE_OPEN figure_list FIGURE_CLOSE
3057 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
3061 chord_body_elements:
3062 /* empty */ { $$ = SCM_EOL; }
3063 | chord_body_elements chord_body_element {
3064 if (!SCM_UNBNDP ($2))
3065 $$ = scm_cons ($2, $1);
3070 pitch_or_tonic_pitch exclamations questions octave_check post_events
3072 bool q = to_boolean ($3);
3073 bool ex = to_boolean ($2);
3077 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3078 n->set_property ("pitch", $1);
3080 n->set_property ("cautionary", SCM_BOOL_T);
3082 n->set_property ("force-accidental", SCM_BOOL_T);
3084 if (scm_is_pair (post)) {
3085 SCM arts = scm_reverse_x (post, SCM_EOL);
3086 n->set_property ("articulations", arts);
3088 if (scm_is_number (check))
3090 int q = scm_to_int (check);
3091 n->set_property ("absolute-octave", scm_from_int (q-1));
3094 $$ = n->unprotect ();
3096 | DRUM_PITCH post_events {
3097 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3098 n->set_property ("drum-type", $1);
3100 if (scm_is_pair ($2)) {
3101 SCM arts = scm_reverse_x ($2, SCM_EOL);
3102 n->set_property ("articulations", arts);
3104 $$ = n->unprotect ();
3106 | music_function_chord_body
3108 Music *m = unsmob<Music> ($1);
3110 while (m && m->is_mus_type ("music-wrapper-music")) {
3111 $$ = m->get_property ("element");
3112 m = unsmob<Music> ($$);
3115 if (!(m && m->is_mus_type ("rhythmic-event"))) {
3116 parser->parser_error (@$, _ ("not a rhythmic event"));
3122 music_function_chord_body:
3128 event_function_event:
3129 EVENT_FUNCTION function_arglist {
3130 $$ = MAKE_SYNTAX (music_function, @$,
3139 | post_events post_event {
3141 if (Music *m = unsmob<Music> ($2))
3143 if (m->is_mus_type ("post-event-wrapper"))
3145 for (SCM p = m->get_property ("elements");
3149 $$ = scm_cons (scm_car (p), $$);
3152 m->set_spot (parser->lexer_->override_input (@2));
3153 $$ = scm_cons ($2, $$);
3159 post_event_nofinger:
3160 direction_less_event {
3163 | script_dir music_function_call {
3165 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
3166 parser->parser_error (@2, _ ("post-event expected"));
3167 $$ = SCM_UNSPECIFIED;
3168 } else if (!SCM_UNBNDP ($1))
3170 unsmob<Music> ($$)->set_property ("direction", $1);
3174 if (!parser->lexer_->is_lyric_state ())
3175 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3176 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
3179 if (!parser->lexer_->is_lyric_state ())
3180 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3181 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
3183 | script_dir direction_reqd_event {
3184 if (!SCM_UNBNDP ($1))
3186 Music *m = unsmob<Music> ($2);
3187 m->set_property ("direction", $1);
3191 | script_dir direction_less_event {
3192 if (!SCM_UNBNDP ($1))
3194 Music *m = unsmob<Music> ($2);
3195 m->set_property ("direction", $1);
3202 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
3207 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
3218 string_number_event:
3220 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3221 s->set_property ("string-number", $1);
3222 $$ = s->unprotect ();
3226 direction_less_event:
3228 | EVENT_IDENTIFIER {
3232 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3233 a->set_property ("tremolo-type", $1);
3234 $$ = a->unprotect ();
3236 | event_function_event
3239 direction_reqd_event:
3243 | script_abbreviation {
3244 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3245 if (scm_is_string (s)) {
3246 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3247 a->set_property ("articulation-type", s);
3248 $$ = a->unprotect ();
3250 Music *original = unsmob<Music> (s);
3251 if (original && original->is_mus_type ("post-event")) {
3252 Music *a = original->clone ();
3253 a->set_spot (parser->lexer_->override_input (@$));
3254 $$ = a->unprotect ();
3256 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3257 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3264 /**/ { $$ = SCM_EOL; }
3265 | '=' quotes { $$ = $2; }
3279 $$ = scm_from_int (1);
3282 $$ = scm_oneplus ($1);
3288 $$ = scm_from_int (-1);
3291 $$ = scm_oneminus ($1);
3296 NOTENAME_PITCH quotes {
3297 if (!scm_is_eq (SCM_INUM0, $2))
3299 Pitch p = *unsmob<Pitch> ($1);
3300 p = p.transposed (Pitch (scm_to_int ($2), 0));
3301 $$ = p.smobbed_copy ();
3311 TONICNAME_PITCH quotes {
3312 if (!scm_is_eq (SCM_INUM0, $2))
3314 Pitch p = *unsmob<Pitch> ($1);
3315 p = p.transposed (Pitch (scm_to_int ($2), 0));
3316 $$ = p.smobbed_copy ();
3323 | PITCH_IDENTIFIER quotes {
3324 if (!scm_is_eq (SCM_INUM0, $2))
3326 Pitch p = *unsmob<Pitch> ($1);
3327 p = p.transposed (Pitch (scm_to_int ($2), 0));
3328 $$ = p.smobbed_copy ();
3333 pitch_or_tonic_pitch:
3340 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3341 t->set_property ("text", $1);
3342 $$ = t->unprotect ();
3345 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3346 t->set_property ("text",
3347 make_simple_markup ($1));
3348 $$ = t->unprotect ();
3351 // Flag a warning? could be unintentional
3352 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3353 t->set_property ("text",
3354 make_simple_markup ($1));
3355 $$ = t->unprotect ();
3359 Music *m = unsmob<Music> ($1);
3360 if (m && m->is_mus_type ("post-event"))
3362 else if (Text_interface::is_markup ($1)) {
3363 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3364 t->set_property ("text", $1);
3365 $$ = t->unprotect ();
3367 parser->parser_error (@1, _ ("not an articulation"));
3373 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3374 t->set_property ("digit", $1);
3375 $$ = t->unprotect ();
3379 script_abbreviation:
3381 $$ = scm_from_ascii_string ("Hat");
3384 $$ = scm_from_ascii_string ("Plus");
3387 $$ = scm_from_ascii_string ("Dash");
3390 $$ = scm_from_ascii_string ("Bang");
3393 $$ = scm_from_ascii_string ("Larger");
3396 $$ = scm_from_ascii_string ("Dot");
3399 $$ = scm_from_ascii_string ("Underscore");
3404 '_' { $$ = scm_from_int (DOWN); }
3405 | '^' { $$ = scm_from_int (UP); }
3406 | '-' { $$ = SCM_UNDEFINED; }
3409 maybe_notemode_duration:
3413 | multiplied_duration {
3415 parser->default_duration_ = *unsmob<Duration> ($$);
3420 optional_notemode_duration:
3421 maybe_notemode_duration
3423 if (SCM_UNBNDP ($$))
3424 $$ = parser->default_duration_.smobbed_copy ();
3430 $$ = make_duration ($1, scm_to_int ($2));
3431 if (SCM_UNBNDP ($$))
3433 parser->parser_error (@1, _ ("not a duration"));
3434 $$ = Duration ().smobbed_copy ();
3437 | DURATION_IDENTIFIER dots {
3438 $$ = make_duration ($1, scm_to_int ($2));
3442 multiplied_duration:
3443 steno_duration multipliers {
3444 $$ = make_duration ($1, 0, $2);
3453 $$ = scm_oneplus ($1);
3462 | multipliers '*' UNSIGNED
3464 if (!SCM_UNBNDP ($1))
3465 $$ = scm_product ($1, $3);
3469 | multipliers '*' FRACTION
3471 if (!SCM_UNBNDP ($1))
3472 $$ = scm_product ($1, scm_divide (scm_car ($3),
3475 $$ = scm_divide (scm_car ($3), scm_cdr ($3));
3481 $$ = scm_from_int (parser->default_tremolo_type_);
3484 if (SCM_UNBNDP (make_duration ($2))) {
3485 parser->parser_error (@2, _ ("not a duration"));
3486 $$ = scm_from_int (parser->default_tremolo_type_);
3489 parser->default_tremolo_type_ = scm_to_int ($2);
3501 // as an integer, it needs to be non-negative, and otherwise
3502 // it needs to be suitable as a markup.
3503 if (scm_is_integer ($1)
3504 ? scm_is_true (scm_negative_p ($1))
3505 : !Text_interface::is_markup ($1))
3507 parser->parser_error (@1, _ ("bass number expected"));
3513 figured_bass_alteration:
3514 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3515 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3516 | '!' { $$ = scm_from_int (0); }
3521 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3522 $$ = bfr->unprotect ();
3525 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3526 $$ = bfr->self_scm ();
3528 if (scm_is_number ($1))
3529 bfr->set_property ("figure", $1);
3530 else if (Text_interface::is_markup ($1))
3531 bfr->set_property ("text", $1);
3537 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3539 | bass_figure figured_bass_alteration {
3540 Music *m = unsmob<Music> ($1);
3541 if (scm_to_double ($2)) {
3542 SCM salter = m->get_property ("alteration");
3543 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3544 m->set_property ("alteration",
3545 scm_sum (alter, $2));
3547 m->set_property ("alteration", scm_from_int (0));
3550 | bass_figure figured_bass_modification {
3551 Music *m = unsmob<Music> ($1);
3552 m->set_property ($2, SCM_BOOL_T);
3557 figured_bass_modification:
3559 $$ = ly_symbol2scm ("augmented");
3562 $$ = ly_symbol2scm ("no-continuation");
3565 $$ = ly_symbol2scm ("diminished");
3568 $$ = ly_symbol2scm ("augmented-slash");
3578 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3586 | figure_list br_bass_figure {
3587 $$ = scm_cons ($2, $1);
3592 /**/ { $$ = SCM_BOOL_F; }
3593 | REST { $$ = SCM_BOOL_T; }
3597 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3598 if (!parser->lexer_->is_note_state ())
3599 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3600 if (!SCM_UNBNDP ($2)
3602 || scm_is_number ($4)
3605 || scm_is_pair ($7))
3608 if (scm_is_true ($6))
3609 n = MY_MAKE_MUSIC ("RestEvent", @$);
3611 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3613 n->set_property ("pitch", $1);
3614 if (SCM_UNBNDP ($5))
3615 n->set_property ("duration",
3616 parser->default_duration_.smobbed_copy ());
3618 n->set_property ("duration", $5);
3620 if (scm_is_number ($4))
3622 int q = scm_to_int ($4);
3623 n->set_property ("absolute-octave", scm_from_int (q-1));
3626 if (to_boolean ($3))
3627 n->set_property ("cautionary", SCM_BOOL_T);
3628 if (to_boolean ($2) || to_boolean ($3))
3629 n->set_property ("force-accidental", SCM_BOOL_T);
3630 if (scm_is_pair ($7))
3631 n->set_property ("articulations",
3632 scm_reverse_x ($7, SCM_EOL));
3633 $$ = n->unprotect ();
3636 | new_chord post_events {
3637 if (!parser->lexer_->is_chord_state ())
3638 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3639 if (scm_is_pair ($2)) {
3640 if (unsmob<Pitch> ($1))
3641 $1 = make_chord_elements (@1,
3643 parser->default_duration_.smobbed_copy (),
3646 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3648 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3649 } else if (!unsmob<Pitch> ($1))
3650 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3651 // A mere pitch drops through.
3656 DRUM_PITCH optional_notemode_duration {
3657 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3658 n->set_property ("duration", $2);
3659 n->set_property ("drum-type", $1);
3661 $$ = n->unprotect ();
3663 | RESTNAME optional_notemode_duration {
3665 if (ly_scm2string ($1) == "s") {
3667 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3670 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3673 ev->set_property ("duration", $2);
3674 $$ = ev->unprotect ();
3680 if (!parser->lexer_->is_lyric_state ())
3681 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3685 if (!parser->lexer_->is_lyric_state ())
3686 parser->parser_error (@1, _f ("not a note name: %s", ly_scm2string ($1)));
3690 if (!parser->lexer_->is_lyric_state ())
3691 parser->parser_error (@1, _ ("string outside of text script or \\lyricmode"));
3697 lyric_element_music:
3698 lyric_element optional_notemode_duration post_events {
3699 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3700 if (scm_is_pair ($3))
3701 unsmob<Music> ($$)->set_property
3702 ("articulations", scm_reverse_x ($3, SCM_EOL));
3706 // Can return a single pitch rather than a list.
3708 steno_tonic_pitch maybe_notemode_duration {
3709 if (SCM_UNBNDP ($2))
3712 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3714 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3715 SCM its = scm_reverse_x ($4, SCM_EOL);
3716 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3724 | chord_items chord_item {
3725 $$ = scm_cons ($2, $$);
3731 $$ = ly_symbol2scm ("chord-colon");
3734 $$ = ly_symbol2scm ("chord-caret");
3736 | CHORD_SLASH steno_tonic_pitch {
3737 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3739 | CHORD_BASS steno_tonic_pitch {
3740 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3749 $$ = scm_reverse_x ($1, SCM_EOL);
3757 step_number { $$ = scm_cons ($1, SCM_EOL); }
3758 | step_numbers '.' step_number {
3759 $$ = scm_cons ($3, $$);
3765 $$ = make_chord_step ($1, 0);
3768 $$ = make_chord_step ($1, SHARP_ALTERATION);
3770 | UNSIGNED CHORD_MINUS {
3771 $$ = make_chord_step ($1, FLAT_ALTERATION);
3779 | unsigned_number '-' unsigned_number {
3780 $$ = scm_cons ($1, $3);
3787 TODO: should deprecate in favor of Scheme?
3791 number_expression '+' number_term {
3792 $$ = scm_sum ($1, $3);
3794 | number_expression '-' number_term {
3795 $$ = scm_difference ($1, $3);
3804 | number_factor '*' number_factor {
3805 $$ = scm_product ($1, $3);
3807 | number_factor '/' number_factor {
3808 $$ = scm_divide ($1, $3);
3813 '-' number_factor { /* %prec UNARY_MINUS */
3814 $$ = scm_difference ($2, SCM_UNDEFINED);
3822 | REAL NUMBER_IDENTIFIER
3824 $$ = scm_product ($1, $2);
3831 | UNSIGNED NUMBER_IDENTIFIER {
3832 $$ = scm_product ($1, $2);
3840 if (!scm_is_integer ($1)
3841 || scm_is_true (scm_negative_p ($1)))
3843 parser->parser_error (@1, _("not an unsigned integer"));
3849 if (!scm_is_integer ($1)
3850 || scm_is_true (scm_negative_p ($1)))
3852 parser->parser_error (@1, _("not an unsigned integer"));
3859 { $$ = SCM_UNDEFINED; }
3862 if (SCM_UNBNDP ($1))
3870 // This precedence rule is rather weird. It triggers when '!' is
3871 // encountered after a pitch, and is used for deciding whether to save
3872 // this instead for a figure modification. This should not actually
3873 // occur in practice as pitches and figures are generated in different
3874 // modes. Using a greedy (%right) precedence makes sure that we don't
3875 // get stuck in a wrong interpretation.
3876 { $$ = SCM_UNDEFINED; } %prec ':'
3879 if (SCM_UNBNDP ($1))
3888 { parser->lexer_->push_markup_state (); }
3891 parser->lexer_->pop_state ();
3898 parser->lexer_->push_markup_state ();
3903 markup_mode markup_top {
3905 parser->lexer_->pop_state ();
3910 markup_mode markup_partial_function ETC
3912 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3913 parser->lexer_->pop_state ();
3919 $$ = scm_list_2 (Lily::line_markup, $1);
3921 | markup_head_1_list simple_markup
3923 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3924 @2, $1, scm_list_1 ($2)));
3934 if (Text_interface::is_markup ($1))
3935 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3936 else if (Text_interface::is_markup_list ($1))
3937 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3939 parser->parser_error (@1, _ ("not a markup"));
3940 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3947 markup_composed_list {
3950 | markup_uncomposed_list
3953 markup_uncomposed_list:
3954 markup_braced_list {
3957 | markup_command_list {
3958 $$ = scm_list_1 ($1);
3960 | markup_scm MARKUPLIST_IDENTIFIER
3965 parser->lexer_->push_note_state (Lily::pitchnames);
3966 } '{' score_body '}' {
3967 Score *sc = unsmob<Score> ($4);
3968 sc->origin ()->set_spot (@$);
3969 if (sc->defs_.empty ()) {
3970 Output_def *od = get_layout (parser);
3971 sc->add_output_def (od);
3974 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3975 parser->lexer_->pop_state ();
3979 markup_composed_list:
3980 markup_head_1_list markup_uncomposed_list {
3981 $$ = MAKE_SYNTAX (composed_markup_list,
3987 '{' markup_braced_list_body '}' {
3988 $$ = scm_reverse_x ($2, SCM_EOL);
3992 markup_braced_list_body:
3993 /* empty */ { $$ = SCM_EOL; }
3994 | markup_braced_list_body markup {
3995 $$ = scm_cons ($2, $1);
3997 | markup_braced_list_body markup_list {
3998 $$ = scm_reverse_x ($2, $1);
4002 markup_command_list:
4003 MARKUP_LIST_FUNCTION markup_command_list_arguments {
4004 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
4008 markup_command_basic_arguments:
4009 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
4010 $$ = scm_cons ($3, $2);
4012 | EXPECT_SCM markup_command_list_arguments embedded_scm {
4013 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
4015 | EXPECT_NO_MORE_ARGS {
4020 markup_command_list_arguments:
4021 markup_command_basic_arguments { $$ = $1; }
4022 | EXPECT_MARKUP markup_command_list_arguments markup {
4023 $$ = scm_cons ($3, $2);
4027 markup_partial_function:
4028 MARKUP_FUNCTION markup_arglist_partial
4030 $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
4032 | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
4034 $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
4039 markup_arglist_partial:
4040 EXPECT_MARKUP markup_arglist_partial
4044 | EXPECT_SCM markup_arglist_partial
4048 | EXPECT_MARKUP markup_command_list_arguments
4052 | EXPECT_SCM markup_command_list_arguments
4059 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
4060 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
4065 markup_head_1_item {
4066 $$ = scm_list_1 ($1);
4068 | markup_head_1_list markup_head_1_item {
4069 $$ = scm_cons ($2, $1);
4075 $$ = make_simple_markup ($1);
4078 $$ = make_simple_markup ($1);
4081 parser->lexer_->push_note_state (Lily::pitchnames);
4082 } '{' score_body '}' {
4083 Score *sc = unsmob<Score> ($4);
4084 sc->origin ()->set_spot (@$);
4085 if (sc->defs_.empty ()) {
4086 Output_def *od = get_layout (parser);
4087 sc->add_output_def (od);
4090 $$ = scm_list_2 (Lily::score_markup, $4);
4091 parser->lexer_->pop_state ();
4093 | MARKUP_FUNCTION markup_command_basic_arguments {
4094 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
4096 | markup_scm MARKUP_IDENTIFIER
4103 markup_head_1_list simple_markup
4105 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
4106 @2, $1, scm_list_1 ($2)));
4116 Lily_parser::set_yydebug (bool x)
4122 Lily_parser::do_yyparse ()
4124 return scm_c_with_fluid (Lily::f_parser,
4126 do_yyparse_trampoline,
4127 static_cast <void *>(this));
4131 Lily_parser::do_yyparse_trampoline (void *parser)
4133 SCM retval = SCM_UNDEFINED;
4134 yyparse (static_cast <Lily_parser *>(parser), &retval);
4142 It is a little strange to have this function in this file, but
4143 otherwise, we have to import music classes into the lexer.
4147 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
4149 if (unsmob<Book> (sid)) {
4150 Book *book = unsmob<Book> (sid)->clone ();
4151 *destination = book->self_scm ();
4154 return BOOK_IDENTIFIER;
4155 } else if (scm_is_number (sid)) {
4157 return NUMBER_IDENTIFIER;
4158 } else if (unsmob<Context_def> (sid))
4160 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
4161 return SCM_IDENTIFIER;
4162 } else if (unsmob<Context_mod> (sid)) {
4163 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
4164 return SCM_IDENTIFIER;
4165 } else if (Music *mus = unsmob<Music> (sid)) {
4166 mus = mus->clone ();
4167 *destination = mus->self_scm ();
4168 bool is_event = mus->is_mus_type ("post-event");
4170 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
4171 } else if (unsmob<Pitch> (sid)) {
4172 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
4173 return PITCH_IDENTIFIER;
4174 } else if (unsmob<Duration> (sid)) {
4175 *destination = unsmob<Duration> (sid)->smobbed_copy ();
4176 return DURATION_IDENTIFIER;
4177 } else if (unsmob<Output_def> (sid)) {
4178 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
4179 return SCM_IDENTIFIER;
4180 } else if (unsmob<Score> (sid)) {
4181 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
4182 return SCM_IDENTIFIER;
4183 } else if (scm_is_pair (sid)
4184 && scm_is_pair (scm_car (sid))
4185 && scm_is_true (Lily::key_p (scm_caar (sid)))) {
4187 return LOOKUP_IDENTIFIER;
4193 get_next_unique_context_id ()
4195 return scm_from_ascii_string ("$uniqueContextId");
4200 get_next_unique_lyrics_context_id ()
4202 static int new_context_count;
4204 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
4205 return scm_from_ascii_string (s);
4208 // check_scheme_arg checks one argument with a given predicate for use
4209 // in an argument list and throws a syntax error if it is unusable.
4210 // The argument is prepended to the argument list in any case. After
4211 // throwing a syntax error, the argument list is terminated with #f as
4212 // its last cdr in order to mark it as uncallable while not losing
4213 // track of its total length.
4215 // There are a few special considerations: if optional argument disp
4216 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
4217 // instead of arg in a prospective error message. This is useful if
4218 // arg is not the actual argument but rather a transformation of it.
4220 // If arg itself is SCM_UNDEFINED, the predicate is considered false
4221 // and an error message using disp is produced unconditionally.
4223 SCM check_scheme_arg (Lily_parser *parser, Input loc,
4224 SCM arg, SCM args, SCM pred, SCM disp)
4226 if (SCM_UNBNDP (arg))
4227 args = scm_cons (disp, args);
4229 args = scm_cons (arg, args);
4230 if (scm_is_true (scm_call_1 (pred, arg)))
4233 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
4234 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
4235 SCM_UNBNDP (disp) ? arg : disp);
4236 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
4240 SCM loc_on_copy (Lily_parser *parser, Input loc, SCM arg)
4242 if (Music *m = unsmob<Music> (arg))
4245 m->set_spot (parser->lexer_->override_input (loc));
4246 return m->unprotect ();
4248 if (Book *b = unsmob<Book> (arg))
4251 b->origin ()->set_spot (parser->lexer_->override_input (loc));
4252 return b->unprotect ();
4254 if (Context_def *cd = unsmob<Context_def> (arg))
4257 cd->origin ()->set_spot (parser->lexer_->override_input (loc));
4258 return cd->unprotect ();
4260 if (Output_def *od = unsmob<Output_def> (arg))
4263 od->input_origin_ = parser->lexer_->override_input (loc);
4264 return od->unprotect ();
4266 if (Score *s = unsmob<Score> (arg))
4269 s->origin ()->set_spot (parser->lexer_->override_input (loc));
4270 return s->unprotect ();
4272 if (Context_mod *cm = unsmob<Context_mod> (arg))
4274 return cm->smobbed_copy ();
4280 make_reverse_key_list (SCM keys)
4282 if (scm_is_true (Lily::key_p (keys)))
4283 return scm_list_1 (keys);
4284 if (scm_is_string (keys))
4285 return scm_list_1 (scm_string_to_symbol (keys));
4286 if (!ly_is_list (keys))
4287 return SCM_UNDEFINED;
4289 for (; scm_is_pair (keys); keys = scm_cdr (keys))
4291 SCM elt = scm_car (keys);
4292 if (scm_is_true (Lily::key_p (elt)))
4293 res = scm_cons (elt, res);
4294 else if (scm_is_string (elt))
4295 res = scm_cons (scm_string_to_symbol (elt), res);
4296 else return SCM_UNDEFINED;
4302 try_string_variants (SCM pred, SCM str)
4304 // a matching predicate is always ok
4305 if (scm_is_true (scm_call_1 (pred, str)))
4307 // a key may be interpreted as a list of keys if it helps
4308 if (scm_is_true (Lily::key_p (str))) {
4309 str = scm_list_1 (str);
4310 if (scm_is_true (scm_call_1 (pred, str)))
4312 return SCM_UNDEFINED;
4315 if (!scm_is_string (str))
4316 return SCM_UNDEFINED;
4318 // Let's attempt the symbol list interpretation first.
4320 str = scm_string_to_symbol (str);
4322 SCM lst = scm_list_1 (str);
4324 if (scm_is_true (scm_call_1 (pred, lst)))
4327 // Try the single symbol interpretation
4329 if (scm_is_true (scm_call_1 (pred, str)))
4332 return SCM_UNDEFINED;
4336 try_word_variants (SCM pred, SCM str)
4338 // str is always a string when we come here
4340 if (scm_is_true (scm_call_1 (pred, str)))
4343 // If this cannot be a string representation of a symbol list,
4346 if (!is_regular_identifier (str, true))
4347 return SCM_UNDEFINED;
4349 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4350 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4351 scm_set_car_x (p, scm_string_split (scm_car (p),
4352 SCM_MAKE_CHAR (',')));
4353 str = scm_append_x (str);
4354 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4355 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4357 // Let's attempt the symbol list interpretation first.
4359 if (scm_is_true (scm_call_1 (pred, str)))
4362 // If there is just one symbol in the list, we might interpret
4363 // it as a single symbol
4365 if (scm_is_null (scm_cdr (str)))
4367 str = scm_car (str);
4368 if (scm_is_true (scm_call_1 (pred, str)))
4372 return SCM_UNDEFINED;
4376 is_regular_identifier (SCM id, bool multiple)
4378 if (!scm_is_string (id))
4381 string str = ly_scm2string (id);
4383 bool middle = false;
4385 for (string::iterator it=str.begin(); it != str.end (); it++)
4388 if ((c >= 'a' && c <= 'z')
4389 || (c >= 'A' && c <= 'Z')
4392 else if (middle && (c == '-' || c == '_' || (multiple &&
4393 (c == '.' || c == ','))))
4402 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4404 if (unsmob<Music> (simple))
4407 if (scm_is_symbol (simple))
4409 SCM out = SCM_UNDEFINED;
4410 switch (parser->lexer_->scan_word (out, simple))
4414 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4415 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4416 n->set_property ("drum-type", out);
4417 return n->unprotect ();
4419 case NOTENAME_PITCH:
4420 case TONICNAME_PITCH:
4421 // Take the parsed pitch
4424 // Don't scan CHORD_MODIFIER etc.
4428 if (parser->lexer_->is_note_state ()) {
4429 if (unsmob<Pitch> (simple)) {
4430 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4431 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4432 n->set_property ("pitch", simple);
4433 return n->unprotect ();
4436 if (scm_is_integer (simple))
4437 d = make_duration (simple);
4438 if (unsmob<Duration> (d)) {
4439 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4440 n->set_property ("duration", d);
4441 return n->unprotect ();
4444 } else if (parser->lexer_->is_lyric_state ()) {
4445 if (Text_interface::is_markup (simple))
4446 return MAKE_SYNTAX (lyric_event, loc, simple,
4447 parser->default_duration_.smobbed_copy ());
4448 } else if (parser->lexer_->is_chord_state ()) {
4449 if (unsmob<Pitch> (simple))
4453 make_chord_elements (loc, simple,
4454 parser->default_duration_.smobbed_copy (),
4461 make_music_with_input (SCM name, Input where)
4463 Music *m = make_music_by_name (name);
4464 m->set_spot (where);
4469 make_simple_markup (SCM a)
4475 make_duration (SCM d, int dots, SCM factor)
4479 if (Duration *dur = unsmob<Duration> (d)) {
4480 if (!dots && SCM_UNBNDP (factor))
4484 k = Duration (k.duration_log (), k.dot_count () + dots)
4485 .compressed (k.factor ());
4487 int t = scm_to_int (d);
4488 if (t > 0 && (t & (t-1)) == 0)
4489 k = Duration (intlog2 (t), dots);
4491 return SCM_UNDEFINED;
4494 if (!SCM_UNBNDP (factor))
4495 k = k.compressed (ly_scm2rational (factor));
4497 return k.smobbed_copy ();
4501 make_chord_step (SCM step_scm, Rational alter)
4503 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4505 // Notename/octave are normalized
4506 if (m.get_notename () == 6)
4507 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4509 return m.smobbed_copy ();
4514 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4516 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4517 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4519 unsmob<Music> (scm_car (s))->set_spot (loc);
4525 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4527 Lily_lexer *lex = parser->lexer_;
4531 int tok = lex->pop_extra_token ();
4534 lex->prepare_for_next_token ();
4535 return lex->yylex ();