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_music (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 try_string_variants (SCM pred, SCM str);
239 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
243 /* The third option is an alias that will be used to display the
244 syntax error. Bison CVS now correctly handles backslash escapes.
246 FIXME: Bison needs to translate some of these, eg, STRING.
250 /* Keyword tokens with plain escaped name. */
251 %token END_OF_FILE 0 "end of input"
252 %token ACCEPTS "\\accepts"
253 %token ADDLYRICS "\\addlyrics"
254 %token ALIAS "\\alias"
255 %token ALTERNATIVE "\\alternative"
257 %token BOOKPART "\\bookpart"
258 %token CHANGE "\\change"
259 %token CHORDMODE "\\chordmode"
260 %token CHORDS "\\chords"
261 %token CONSISTS "\\consists"
262 %token CONTEXT "\\context"
263 %token DEFAULT "\\default"
264 %token DEFAULTCHILD "\\defaultchild"
265 %token DENIES "\\denies"
266 %token DESCRIPTION "\\description"
267 %token DRUMMODE "\\drummode"
268 %token DRUMS "\\drums"
270 %token FIGUREMODE "\\figuremode"
271 %token FIGURES "\\figures"
272 %token HEADER "\\header"
273 %token INVALID "\\version-error"
274 %token LAYOUT "\\layout"
275 %token LYRICMODE "\\lyricmode"
276 %token LYRICS "\\lyrics"
277 %token LYRICSTO "\\lyricsto"
278 %token MARKUP "\\markup"
279 %token MARKUPLIST "\\markuplist"
282 %token NOTEMODE "\\notemode"
283 %token OVERRIDE "\\override"
284 %token PAPER "\\paper"
285 %token REMOVE "\\remove"
286 %token REPEAT "\\repeat"
288 %token REVERT "\\revert"
289 %token SCORE "\\score"
290 %token SCORELINES "\\score-lines"
291 %token SEQUENTIAL "\\sequential"
293 %token SIMULTANEOUS "\\simultaneous"
294 %token TEMPO "\\tempo"
296 %token UNSET "\\unset"
299 /* Keyword token exceptions. */
300 %token NEWCONTEXT "\\new"
303 /* Other string tokens. */
305 %token CHORD_BASS "/+"
306 %token CHORD_CARET "^"
307 %token CHORD_COLON ":"
308 %token CHORD_MINUS "-"
309 %token CHORD_SLASH "/"
310 %token ANGLE_OPEN "<"
311 %token ANGLE_CLOSE ">"
312 %token DOUBLE_ANGLE_OPEN "<<"
313 %token DOUBLE_ANGLE_CLOSE ">>"
314 %token E_BACKSLASH "\\"
315 %token E_EXCLAMATION "\\!"
320 If we give names, Bison complains.
322 %token FIGURE_CLOSE /* "\\>" */
323 %token FIGURE_OPEN /* "\\<" */
324 %token FIGURE_SPACE "_"
327 %token MULTI_MEASURE_REST
333 /* Artificial tokens, for more generic function syntax */
334 %token EXPECT_MARKUP "markup?"
335 %token EXPECT_SCM "scheme?"
336 %token BACKUP "(backed-up?)"
337 %token REPARSE "(reparsed?)"
338 %token EXPECT_MARKUP_LIST "markup-list?"
339 %token EXPECT_OPTIONAL "optional?"
340 /* After the last argument. */
341 %token EXPECT_NO_MORE_ARGS;
343 /* An artificial token for parsing embedded Lilypond */
344 %token EMBEDDED_LILY "#{"
346 %token BOOK_IDENTIFIER
347 %token CHORD_MODIFIER
348 %token CHORD_REPETITION
349 %token CONTEXT_MOD_IDENTIFIER
351 /* Artificial token for durations in argument lists */
353 %token DURATION_IDENTIFIER
354 %token EVENT_IDENTIFIER
355 %token EVENT_FUNCTION
357 %token LOOKUP_IDENTIFIER
359 %token MARKUP_FUNCTION
360 %token MARKUP_LIST_FUNCTION
361 %token MARKUP_IDENTIFIER
362 %token MARKUPLIST_IDENTIFIER
363 %token MUSIC_FUNCTION
364 %token MUSIC_IDENTIFIER
365 %token NOTENAME_PITCH
366 %token NUMBER_IDENTIFIER
367 %token PITCH_IDENTIFIER
372 %token SCM_IDENTIFIER
376 %token TONICNAME_PITCH
380 /* We don't assign precedence to / and *, because we might need varied
381 prec levels in different prods */
390 parser->lexer_->push_note_state (Lily::pitchnames);
391 } embedded_lilypond {
392 parser->lexer_->pop_state ();
397 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
398 | lilypond toplevel_expression {
400 | lilypond assignment {
403 parser->error_level_ = 1;
406 parser->error_level_ = 1;
413 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
416 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
417 scm_call_1 (proc, $1);
420 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
421 scm_call_1 (proc, $1);
424 SCM proc = parser->lexer_->lookup_identifier
425 (unsmob<Book>($1)->paper_
426 ? "toplevel-book-handler"
427 : "toplevel-bookpart-handler");
428 scm_call_1 (proc, $1);
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
432 scm_call_1 (proc, $1);
435 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
436 scm_call_1 (proc, $1);
439 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
440 scm_call_1 (proc, scm_list_1 ($1));
443 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
444 scm_call_1 (proc, $1);
447 // Evaluate and ignore #xxx, as opposed to \xxx
448 parser->lexer_->eval_scm_token ($1, @1);
450 | embedded_scm_active
452 SCM out = SCM_UNDEFINED;
453 if (Text_interface::is_markup ($1))
454 out = scm_list_1 ($1);
455 else if (Text_interface::is_markup_list ($1))
457 if (scm_is_pair (out))
459 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
460 scm_call_1 (proc, out);
461 } else if (unsmob<Score> ($1))
463 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
464 scm_call_1 (proc, $1);
465 } else if (Output_def * od = unsmob<Output_def> ($1)) {
468 if (to_boolean (od->c_variable ("is-paper")))
469 id = ly_symbol2scm ("$defaultpaper");
470 else if (to_boolean (od->c_variable ("is-midi")))
471 id = ly_symbol2scm ("$defaultmidi");
472 else if (to_boolean (od->c_variable ("is-layout")))
473 id = ly_symbol2scm ("$defaultlayout");
475 parser->lexer_->set_identifier (id, $1);
476 } else if (ly_is_module ($1))
478 SCM module = get_header (parser);
479 ly_module_copy (module, $1);
480 parser->lexer_->set_identifier
481 (ly_symbol2scm ("$defaultheader"), module);
482 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
483 parser->parser_error (@1, _("bad expression type"));
487 Output_def * od = unsmob<Output_def> ($1);
489 if (to_boolean (od->c_variable ("is-paper")))
490 id = ly_symbol2scm ("$defaultpaper");
491 else if (to_boolean (od->c_variable ("is-midi")))
492 id = ly_symbol2scm ("$defaultmidi");
493 else if (to_boolean (od->c_variable ("is-layout")))
494 id = ly_symbol2scm ("$defaultlayout");
496 parser->lexer_->set_identifier (id, $1);
502 | LOOKUP_IDENTIFIER '.' symbol_list_rev
504 $$ = loc_on_music (parser, @$,
505 nested_property ($1, scm_reverse_x ($3, SCM_EOL)));
512 $$ = parser->lexer_->eval_scm_token ($1, @1);
523 embedded_scm_bare_arg:
527 $$ = parser->lexer_->eval_scm_token ($1, @1);
532 | context_modification
535 | context_def_spec_block
542 /* The generic version may end in music, or not */
550 /* embedded_scm_arg is _not_ casting pitches to music by default, this
551 * has to be done by the function itself. Note that this may cause
552 * the results of scm_function_call or embedded_scm_bare_arg to be
553 * turned into music from pitches as well. Note that this creates a
554 * distinctly awkward situation for calculated drum pitches. Those
555 * are at the current point of time rejected as music constituents as
556 * they can't be distinguished from "proper" symbols.
560 embedded_scm_bare_arg
566 SCM_FUNCTION function_arglist {
567 $$ = MAKE_SYNTAX (music_function, @$,
572 embedded_lilypond_number:
573 '-' embedded_lilypond_number
575 $$ = scm_difference ($2, SCM_UNDEFINED);
578 | UNSIGNED NUMBER_IDENTIFIER
580 $$ = scm_product ($1, $2);
587 // FIXME: @$ does not contain a useful source location
588 // for empty rules, and the only token in the whole
589 // production, EMBEDDED_LILY, is synthetic and also
590 // contains no source location.
591 $$ = MAKE_SYNTAX (void_music, @$);
593 | identifier_init_nonumber
594 | embedded_lilypond_number
595 | post_event post_events
597 $$ = scm_reverse_x ($2, SCM_EOL);
598 if (Music *m = unsmob<Music> ($1))
600 if (m->is_mus_type ("post-event-wrapper"))
602 (scm_list_2 (m->get_property ("elements"),
605 $$ = scm_cons ($1, $$);
608 && scm_is_null (scm_cdr ($$)))
612 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
613 m->set_property ("elements", $$);
614 $$ = m->unprotect ();
617 | multiplied_duration
618 | music_embedded music_embedded music_list {
619 $3 = scm_reverse_x ($3, SCM_EOL);
620 if (unsmob<Music> ($2))
621 $3 = scm_cons ($2, $3);
622 if (unsmob<Music> ($1))
623 $3 = scm_cons ($1, $3);
624 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
627 parser->error_level_ = 1;
628 $$ = SCM_UNSPECIFIED;
630 | INVALID embedded_lilypond {
631 parser->error_level_ = 1;
637 lilypond_header_body:
638 /* empty */ { $$ = SCM_UNSPECIFIED; }
639 | lilypond_header_body assignment {
642 | lilypond_header_body SCM_TOKEN {
643 // Evaluate and ignore #xxx, as opposed to \xxx
644 parser->lexer_->eval_scm_token ($2, @2);
646 | lilypond_header_body embedded_scm_active {
647 if (ly_is_module ($2))
648 ly_module_copy (scm_current_module (), $2);
649 else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
650 parser->parser_error (@2, _("bad expression type"));
655 HEADER '{' lilypond_header_body '}' {
656 $$ = parser->lexer_->remove_scope ();
662 parser->lexer_->add_scope (get_header (parser));
676 assignment_id '=' identifier_init {
677 parser->lexer_->set_identifier ($1, $3);
678 $$ = SCM_UNSPECIFIED;
680 | assignment_id '.' property_path '=' identifier_init {
681 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
682 parser->lexer_->set_identifier (path, $5);
683 $$ = SCM_UNSPECIFIED;
685 | assignment_id ',' property_path '=' identifier_init {
686 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
687 parser->lexer_->set_identifier (path, $5);
688 $$ = SCM_UNSPECIFIED;
694 identifier_init_nonumber
696 | symbol_list_part_bare '.' property_path
698 $$ = scm_reverse_x ($1, $3);
700 | symbol_list_part_bare ',' property_path
702 $$ = scm_reverse_x ($1, $3);
704 | post_event_nofinger post_events
706 $$ = scm_reverse_x ($2, SCM_EOL);
707 if (Music *m = unsmob<Music> ($1))
709 if (m->is_mus_type ("post-event-wrapper"))
711 (scm_list_2 (m->get_property ("elements"),
714 $$ = scm_cons ($1, $$);
717 && scm_is_null (scm_cdr ($$)))
721 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
722 m->set_property ("elements", $$);
723 $$ = m->unprotect ();
728 identifier_init_nonumber:
734 | context_def_spec_block
742 | context_modification
743 | partial_function ETC
745 $$ = MAKE_SYNTAX (partial_music_function, @$,
746 scm_reverse_x ($1, SCM_EOL));
752 MUSIC_FUNCTION function_arglist_partial
754 $$ = scm_acons ($1, $2, SCM_EOL);
756 | EVENT_FUNCTION function_arglist_partial
758 $$ = scm_acons ($1, $2, SCM_EOL);
760 | SCM_FUNCTION function_arglist_partial
762 $$ = scm_acons ($1, $2, SCM_EOL);
764 | OVERRIDE grob_prop_path '='
767 $$ = scm_list_1 (SCM_BOOL_F);
770 (scm_list_3 (Syntax::property_override_function,
771 scm_cdr ($2), scm_car ($2)),
774 | SET context_prop_spec '='
777 $$ = scm_list_1 (SCM_BOOL_F);
780 (scm_list_3 (Syntax::property_set_function,
781 scm_cadr ($2), scm_car ($2)),
784 | MUSIC_FUNCTION EXPECT_SCM function_arglist_optional partial_function
786 $$ = scm_acons ($1, $3, $4);
788 | EVENT_FUNCTION EXPECT_SCM function_arglist_optional partial_function
790 $$ = scm_acons ($1, $3, $4);
792 | SCM_FUNCTION EXPECT_SCM function_arglist_optional partial_function
794 $$ = scm_acons ($1, $3, $4);
796 | OVERRIDE grob_prop_path '=' partial_function
799 $$ = scm_list_1 (SCM_BOOL_F);
802 (scm_list_3 (Syntax::property_override_function,
803 scm_cdr ($2), scm_car ($2)),
806 | SET context_prop_spec '=' partial_function
809 $$ = scm_list_1 (SCM_BOOL_F);
812 (scm_list_3 (Syntax::property_set_function,
813 scm_cadr ($2), scm_car ($2)),
816 | MUSIC_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
818 $$ = scm_acons ($1, $4, $5);
820 | EVENT_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
822 $$ = scm_acons ($1, $4, $5);
824 | SCM_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
826 $$ = scm_acons ($1, $4, $5);
830 context_def_spec_block:
831 CONTEXT '{' context_def_spec_body '}'
834 Context_def *td = unsmob<Context_def> ($$);
836 $$ = Context_def::make_scm ();
837 td = unsmob<Context_def> ($$);
839 td->origin ()->set_spot (@$);
847 parser->lexer_->push_note_state (Lily::pitchnames);
851 parser->lexer_->pop_state ();
857 context_def_spec_body:
859 $$ = SCM_UNSPECIFIED;
861 | context_def_spec_body context_mod {
862 if (!SCM_UNBNDP ($2)) {
863 Context_def *td = unsmob<Context_def> ($$);
865 $$ = Context_def::make_scm ();
866 td = unsmob<Context_def> ($$);
868 unsmob<Context_def> ($$)->add_context_mod ($2);
871 | context_def_spec_body context_modification {
872 Context_def *td = unsmob<Context_def> ($$);
874 $$ = Context_def::make_scm ();
875 td = unsmob<Context_def> ($$);
877 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
878 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
879 td->add_context_mod (scm_car (m));
882 | context_def_spec_body context_mod_arg {
883 Context_def *td = unsmob<Context_def> ($1);
884 if (scm_is_eq ($2, SCM_UNSPECIFIED))
886 else if (!td && unsmob<Context_def> ($2))
890 $$ = Context_def::make_scm ();
891 td = unsmob<Context_def> ($$);
893 if (unsmob<Music> ($2)) {
894 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
895 $2 = scm_call_1 (proc, $2);
897 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
898 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
899 td->add_context_mod (scm_car (m));
902 parser->parser_error (@2, _ ("not a context mod"));
910 BOOK '{' book_body '}' {
912 unsmob<Book> ($$)->origin ()->set_spot (@$);
914 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
919 * Use 'handlers' like for toplevel-* stuff?
920 * grok \layout and \midi? */
923 Book *book = new Book;
924 init_papers (parser);
925 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
926 book->paper_->unprotect ();
927 push_paper (parser, book->paper_);
928 book->header_ = get_header (parser);
929 $$ = book->unprotect ();
930 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
933 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
935 | book_body paper_block {
936 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
937 set_paper (parser, unsmob<Output_def> ($2));
939 | book_body bookpart_block {
940 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
941 scm_call_2 (proc, $1, $2);
943 | book_body score_block {
944 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
945 scm_call_2 (proc, $1, $2);
947 | book_body composite_music {
948 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
949 scm_call_2 (proc, $1, $2);
951 | book_body full_markup {
952 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
953 scm_call_2 (proc, $1, scm_list_1 ($2));
955 | book_body full_markup_list {
956 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
957 scm_call_2 (proc, $1, $2);
959 | book_body SCM_TOKEN {
960 // Evaluate and ignore #xxx, as opposed to \xxx
961 parser->lexer_->eval_scm_token ($2, @2);
963 | book_body embedded_scm_active
965 SCM out = SCM_UNDEFINED;
966 if (Text_interface::is_markup ($2))
967 out = scm_list_1 ($2);
968 else if (Text_interface::is_markup_list ($2))
970 if (scm_is_pair (out))
972 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
973 scm_call_2 (proc, $1, out);
974 } else if (unsmob<Score> ($2))
976 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
977 scm_call_2 (proc, $1, $2);
978 } else if (Output_def *od = unsmob<Output_def> ($2)) {
979 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper")))) {
980 unsmob<Book> ($1)->paper_ = od;
981 set_paper (parser, od);
983 parser->parser_error (@2, _ ("need \\paper for paper block"));
985 } else if (ly_is_module ($2))
987 ly_module_copy (unsmob<Book> ($1)->header_, $2);
988 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
989 parser->parser_error (@2, _("bad expression type"));
993 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
996 Book *book = unsmob<Book> ($1);
998 book->scores_ = SCM_EOL;
999 book->bookparts_ = SCM_EOL;
1004 BOOKPART '{' bookpart_body '}' {
1006 unsmob<Book> ($$)->origin ()->set_spot (@$);
1007 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
1013 Book *book = new Book;
1014 $$ = book->unprotect ();
1015 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
1018 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
1020 | bookpart_body paper_block {
1021 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
1023 | bookpart_body score_block {
1024 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1025 scm_call_2 (proc, $1, $2);
1027 | bookpart_body composite_music {
1028 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
1029 scm_call_2 (proc, $1, $2);
1031 | bookpart_body full_markup {
1032 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1033 scm_call_2 (proc, $1, scm_list_1 ($2));
1035 | bookpart_body full_markup_list {
1036 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1037 scm_call_2 (proc, $1, $2);
1039 | bookpart_body SCM_TOKEN {
1040 // Evaluate and ignore #xxx, as opposed to \xxx
1041 parser->lexer_->eval_scm_token ($2, @2);
1043 | bookpart_body embedded_scm_active
1045 SCM out = SCM_UNDEFINED;
1046 if (Text_interface::is_markup ($2))
1047 out = scm_list_1 ($2);
1048 else if (Text_interface::is_markup_list ($2))
1050 if (scm_is_pair (out))
1052 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1053 scm_call_2 (proc, $1, out);
1054 } else if (unsmob<Score> ($2))
1056 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1057 scm_call_2 (proc, $1, $2);
1058 } else if (Output_def *od = unsmob<Output_def> ($2)) {
1059 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper")))) {
1060 unsmob<Book> ($1)->paper_ = od;
1062 parser->parser_error (@2, _ ("need \\paper for paper block"));
1064 } else if (ly_is_module ($2)) {
1065 Book *book = unsmob<Book> ($1);
1066 if (!ly_is_module (book->header_))
1067 book->header_ = ly_make_module (false);
1068 ly_module_copy (book->header_, $2);
1069 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1070 parser->parser_error (@2, _("bad expression type"));
1074 Book *book = unsmob<Book> ($1);
1075 if (!ly_is_module (book->header_))
1076 book->header_ = ly_make_module (false);
1077 parser->lexer_->add_scope (book->header_);
1079 | bookpart_body error {
1080 Book *book = unsmob<Book> ($1);
1082 book->scores_ = SCM_EOL;
1087 SCORE '{' score_body '}' {
1088 unsmob<Score> ($3)->origin ()->set_spot (@$);
1095 if (!unsmob<Score> ($1)) {
1096 parser->parser_error (@1, _("Missing music in \\score"));
1097 $$ = (new Score)->unprotect ();
1098 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
1100 unsmob<Score> ($$)->set_header (scm_car ($1));
1103 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1104 scm_is_pair (p); p = scm_cdr (p))
1106 unsmob<Score> ($$)->
1107 add_output_def (unsmob<Output_def> (scm_car (p)));
1111 | score_body error {
1112 unsmob<Score> ($$)->error_found_ = true;
1127 | score_items score_item
1129 Output_def *od = unsmob<Output_def> ($2);
1131 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1133 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1135 $2 = SCM_UNSPECIFIED;
1137 } else if (!unsmob<Score> ($$)) {
1138 if (unsmob<Music> ($2)) {
1139 $2 = Lily::scorify_music ($2);
1141 if (unsmob<Score> ($2))
1144 $2 = SCM_UNSPECIFIED;
1147 Score *score = unsmob<Score> ($$);
1148 if (score && scm_is_pair ($1)) {
1149 if (ly_is_module (scm_car ($1)))
1151 score->set_header (scm_car ($1));
1154 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1155 scm_is_pair (p); p = scm_cdr (p))
1157 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1162 score->add_output_def (od);
1163 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1164 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1166 $$ = scm_cons ($2, $$);
1167 } else if (ly_is_module ($2)) {
1168 SCM module = SCM_UNSPECIFIED;
1170 module = score->get_header ();
1171 if (!ly_is_module (module))
1173 module = ly_make_module (false);
1174 score->set_header (module);
1176 } else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1177 module = scm_car ($$);
1179 module = ly_make_module (false);
1180 $$ = scm_cons (module, $$);
1182 ly_module_copy (module, $2);
1183 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1184 parser->parser_error (@2, _("Spurious expression in \\score"));
1188 if (Score *score = unsmob<Score> ($1)) {
1189 if (!ly_is_module (score->get_header ()))
1190 score->set_header (ly_make_module (false));
1191 parser->lexer_->add_scope (score->get_header ());
1193 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1194 $1 = scm_cons (ly_make_module (false), $1);
1195 parser->lexer_->add_scope (scm_car ($1));
1210 Output_def *od = unsmob<Output_def> ($1);
1212 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1214 parser->parser_error (@1, _ ("need \\paper for paper block"));
1215 $$ = get_paper (parser)->unprotect ();
1222 output_def_body '}' {
1223 if (scm_is_pair ($1))
1226 parser->lexer_->remove_scope ();
1227 parser->lexer_->pop_state ();
1233 Output_def *p = get_paper (parser);
1234 p->input_origin_ = @$;
1235 parser->lexer_->add_scope (p->scope_);
1236 $$ = p->unprotect ();
1239 Output_def *p = get_midi (parser);
1240 $$ = p->unprotect ();
1241 parser->lexer_->add_scope (p->scope_);
1244 Output_def *p = get_layout (parser);
1246 parser->lexer_->add_scope (p->scope_);
1247 $$ = p->unprotect ();
1251 output_def_head_with_mode_switch:
1253 parser->lexer_->push_initial_state ();
1258 // We need this weird nonterminal because both music as well as a
1259 // context definition can start with \context and the difference is
1260 // only apparent after looking at the next token. If it is '{', there
1261 // is still time to escape from notes mode.
1263 music_or_context_def:
1265 | context_def_spec_block
1269 output_def_head_with_mode_switch '{' {
1270 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1271 // This is a stupid trick to mark the beginning of the
1272 // body for deciding whether to allow
1273 // embedded_scm_active to have an output definition
1274 $$ = scm_list_1 ($1);
1276 | output_def_body assignment {
1277 if (scm_is_pair ($1))
1280 | output_def_body embedded_scm_active
1282 // We don't switch into note mode for Scheme functions
1283 // here. Does not seem warranted/required in output
1285 if (scm_is_pair ($1))
1287 Output_def *o = unsmob<Output_def> ($2);
1289 o->input_origin_.set_spot (@$);
1290 $1 = o->self_scm ();
1291 parser->lexer_->remove_scope ();
1292 parser->lexer_->add_scope (o->scope_);
1293 $2 = SCM_UNSPECIFIED;
1297 if (unsmob<Context_def> ($2))
1298 assign_context_def (unsmob<Output_def> ($1), $2);
1299 // Seems unlikely, but let's be complete:
1300 else if (unsmob<Music> ($2))
1302 SCM proc = parser->lexer_->lookup_identifier
1303 ("output-def-music-handler");
1304 scm_call_2 (proc, $1, $2);
1305 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1306 parser->parser_error (@2, _("bad expression type"));
1309 | output_def_body SCM_TOKEN {
1310 if (scm_is_pair ($1))
1312 // Evaluate and ignore #xxx, as opposed to \xxx
1313 parser->lexer_->eval_scm_token ($2, @2);
1317 if (scm_is_pair ($1))
1319 parser->lexer_->push_note_state (Lily::pitchnames);
1320 } music_or_context_def
1322 parser->lexer_->pop_state ();
1323 if (unsmob<Context_def> ($3))
1324 assign_context_def (unsmob<Output_def> ($1), $3);
1327 SCM proc = parser->lexer_->lookup_identifier
1328 ("output-def-music-handler");
1329 scm_call_2 (proc, $1, $3);
1333 | output_def_body error {
1339 TEMPO steno_duration '=' tempo_range {
1340 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1342 | TEMPO text steno_duration '=' tempo_range {
1343 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1346 $$ = MAKE_SYNTAX (tempo, @$, $2);
1351 The representation of a list is reversed to have efficient append. */
1357 | music_list music_embedded {
1358 if (unsmob<Music> ($2))
1359 $$ = scm_cons ($2, $1);
1361 | music_list error {
1362 Music *m = MY_MAKE_MUSIC("Music", @$);
1364 m->set_property ("error-found", SCM_BOOL_T);
1365 $$ = scm_cons (m->self_scm (), $1);
1366 m->unprotect (); /* UGH */
1373 $$ = scm_reverse_x ($2, SCM_EOL);
1378 | lyric_element_music
1385 $$ = make_music_from_simple (parser, @1, $1);
1386 if (!unsmob<Music> ($$))
1388 parser->parser_error (@1, _ ("music expected"));
1389 $$ = MAKE_SYNTAX (void_music, @$);
1397 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1398 parser->parser_error (@1, _ ("unexpected post-event"));
1399 $$ = SCM_UNSPECIFIED;
1402 | music_embedded_backup
1406 | music_embedded_backup BACKUP lyric_element_music
1410 | multiplied_duration post_events
1412 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1414 parser->default_duration_ = *unsmob<Duration> ($1);
1415 n->set_property ("duration", $1);
1417 if (scm_is_pair ($2))
1418 n->set_property ("articulations",
1419 scm_reverse_x ($2, SCM_EOL));
1420 $$ = n->unprotect ();
1424 music_embedded_backup:
1427 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1429 else if (Music *m = unsmob<Music> ($1)) {
1430 if (m->is_mus_type ("post-event")) {
1431 parser->parser_error
1432 (@1, _ ("unexpected post-event"));
1433 $$ = SCM_UNSPECIFIED;
1436 } else if (parser->lexer_->is_lyric_state ()
1437 && Text_interface::is_markup ($1))
1438 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1440 @$.warning (_ ("Ignoring non-music expression"));
1446 // music_assign does not need to contain lyrics: there are no
1447 // assignments in lyricmode.
1450 | composite_music %prec COMPOSITE
1454 REPEAT simple_string unsigned_number music
1456 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1458 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1460 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1465 SEQUENTIAL braced_music_list {
1466 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1468 | braced_music_list {
1469 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1474 SIMULTANEOUS braced_music_list {
1475 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1477 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1478 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1484 | music_property_def
1488 context_modification:
1491 parser->lexer_->push_note_state (Lily::pitchnames);
1492 } '{' context_mod_list '}'
1494 parser->lexer_->pop_state ();
1497 | WITH CONTEXT_MOD_IDENTIFIER
1501 | CONTEXT_MOD_IDENTIFIER
1505 | WITH context_modification_arg
1507 if (unsmob<Music> ($2)) {
1508 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1509 $2 = scm_call_1 (proc, $2);
1511 if (unsmob<Context_mod> ($2))
1514 parser->parser_error (@2, _ ("not a context mod"));
1515 $$ = Context_mod ().smobbed_copy ();
1520 context_modification_arg:
1525 /* A list of single mods collected from a (possibly empty) sequence of
1526 * context modifications, usually written as \with ... \with ...
1529 optional_context_mods:
1530 context_modification_mods_list
1532 if (scm_is_pair ($1))
1533 $$ = scm_append_x (scm_reverse_x ($1, SCM_EOL));
1537 /* The worker for optional_context_mods conses a (reversed) list where
1538 * each element contains the list of single context mods from one
1539 * context modification block. Context_mod::get_mods creates fresh
1540 * copies, so it's okay to use append! on them.
1543 context_modification_mods_list:
1547 | context_modification_mods_list context_modification
1549 if (Context_mod *m = unsmob<Context_mod> ($2))
1550 $$ = scm_cons (m->get_mods (), $1);
1554 /* A Context_mod is a container for a list of context mods like
1555 * \consists ... \override ... . context_mod_list produces a
1556 * Context_mod from the inside of a \with { ... } statement.
1561 $$ = Context_mod ().smobbed_copy ();
1563 | context_mod_list context_mod {
1564 if (!SCM_UNBNDP ($2))
1565 unsmob<Context_mod> ($1)->add_context_mod ($2);
1567 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1568 Context_mod *md = unsmob<Context_mod> ($2);
1570 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1572 | context_mod_list context_mod_arg {
1573 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1575 else if (unsmob<Music> ($2)) {
1576 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1577 $2 = scm_call_1 (proc, $2);
1579 if (unsmob<Context_mod> ($2))
1580 unsmob<Context_mod> ($$)->add_context_mods
1581 (unsmob<Context_mod> ($2)->get_mods ());
1583 parser->parser_error (@2, _ ("not a context mod"));
1589 CONTEXT symbol optional_id optional_context_mods {
1590 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_F);
1592 | NEWCONTEXT symbol optional_id optional_context_mods {
1593 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_T);
1598 ADDLYRICS optional_context_mods lyric_mode_music {
1599 $$ = scm_acons ($3, $2, SCM_EOL);
1601 | new_lyrics ADDLYRICS optional_context_mods lyric_mode_music {
1602 $$ = scm_acons ($4, $3, $1);
1606 /* basic_music is basically the same as composite_music but with
1607 * context-prefixed music and lyricized music explicitly removed. The
1608 * reason is that in a sequence
1610 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1612 * we need to group both \addlyrics together (as they go with the same
1613 * voice) but then combine them with \new Voice { ... }, meaning that
1614 * combining \new Voice { ... } needs higher priority than
1615 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1616 * combine before combining \new Voice { ... } \addlyrics: only one
1617 * layer of context-prefixed music should assemble before \addlyrics
1618 * is integrated. Total mess, and we sort this mess out with explicit
1619 * rules preferring a single context-prefix.
1626 | LYRICSTO simple_string lyric_mode_music {
1627 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1629 | LYRICSTO symbol '=' simple_string lyric_mode_music
1631 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1641 contexted_basic_music:
1642 context_prefix contextable_music new_lyrics
1645 i.set_location (@1, @2);
1646 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1647 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1649 | context_prefix contextable_music
1651 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1653 | context_prefix contexted_basic_music
1655 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1660 basic_music %prec COMPOSITE
1661 | contexted_basic_music
1662 | basic_music new_lyrics
1664 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1671 | grouped_music_list
1675 simultaneous_music { $$ = $1; }
1676 | sequential_music { $$ = $1; }
1679 /* Function argument lists are arguably the most complex part in the
1680 * parser. They are pretty tricky to understand because of the way
1681 * they are processed, and because of optional arguments that can be
1682 * omitted. When there are several optional arguments in a row,
1683 * omitting one automatically omits all following arguments. Optional
1684 * arguments can only be omitted when either
1686 * a) the omission is explicitly started with \default
1687 * b) the omission is implicitly started by an argument not matching
1688 * its predicate, and there is a mandatory argument later that can
1689 * "catch" the argument that does not fit.
1691 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1692 * (corresponding to mandatory arguments and having a predicate
1693 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1694 * the semantic value of the EXPECT_OPTIONAL token is the default to
1695 * use when the optional argument is omitted, and EXPECT_SCM again has
1696 * the argument predicate as semantic value) in reverse order to the
1697 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1698 * processed inside-out while actual tokens are consumed.
1700 * This means that the argument list tokens determine the actions
1701 * taken as they arrive. The structure of the argument list is known
1702 * to the parser and stored in its parse stack when the first argument
1703 * is being parsed. What the parser does not know is which predicates
1704 * will match and whether or not \default will be appearing in the
1705 * argument list, and where.
1707 * Sequences of 0 or more optional arguments are scanned using either
1708 * function_arglist_backup or function_arglist_nonbackup. The first
1709 * is used when optional arguments are followed by at least one
1710 * mandatory argument: in that case optional arguments may be skipped
1711 * by either a false predicate (in which case the expression will be
1712 * pushed back as one or more tokens, preceded by a BACKUP token) or
1713 * by using \default.
1715 * If optional arguments are at the end of the argument list, they are
1716 * instead scanned using function_arglist_nonbackup: here the only
1717 * manner to enter into skipping of optional arguments is the use of
1720 * The argument list of a normal function call is parsed using
1721 * function_arglist. The part of an argument list before a mandatory
1722 * argument is parsed using function_arglist_optional.
1724 * The difference is that leading optional arguments are scanned using
1725 * function_arglist_nonbackup and function_arglist_backup,
1728 * Most other details are obvious in the rules themselves.
1734 | SYMBOL_LIST '.' symbol_list_rev
1736 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1738 | SYMBOL_LIST ',' symbol_list_rev
1740 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1746 | symbol_list_rev '.' symbol_list_part
1748 $$ = scm_append_x (scm_list_2 ($3, $1));
1750 | symbol_list_rev ',' symbol_list_part
1752 $$ = scm_append_x (scm_list_2 ($3, $1));
1756 // symbol_list_part delivers elements in reverse copy.
1761 $$ = try_string_variants (Lily::key_list_p, $1);
1762 if (SCM_UNBNDP ($$)) {
1763 parser->parser_error (@1, _("not a key"));
1766 $$ = scm_reverse ($$);
1771 symbol_list_element:
1777 symbol_list_part_bare:
1780 $$ = try_string_variants (Lily::key_list_p, $1);
1781 if (SCM_UNBNDP ($$)) {
1782 parser->parser_error (@1, _("not a key"));
1785 $$ = scm_reverse ($$);
1789 $$ = scm_list_1 ($1);
1793 function_arglist_nonbackup:
1794 function_arglist_common
1795 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1797 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1799 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1801 SCM n = scm_difference ($5, SCM_UNDEFINED);
1802 if (scm_is_true (scm_call_1 ($2, n)))
1803 $$ = scm_cons (n, $3);
1805 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1806 t->set_property ("digit", $5);
1807 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1811 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1813 $$ = check_scheme_arg (parser, @4,
1814 scm_difference ($5, SCM_UNDEFINED),
1817 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1819 $$ = check_scheme_arg (parser, @4,
1820 scm_difference ($5, SCM_UNDEFINED),
1823 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1825 if (scm_is_true (scm_call_1 ($2, $4)))
1826 $$ = scm_cons ($4, $3);
1828 $$ = check_scheme_arg (parser, @4,
1829 make_music_from_simple
1833 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1835 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1837 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1839 if (scm_is_true (scm_call_1 ($2, $3)))
1840 $$ = scm_cons ($3, $1);
1842 $$ = check_scheme_arg (parser, @3,
1843 make_music_from_simple
1847 | function_arglist_nonbackup_reparse REPARSE multiplied_duration
1849 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1851 | function_arglist_nonbackup_reparse REPARSE reparsed_rhythm
1853 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1855 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1857 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1859 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1861 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1863 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1865 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1867 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1869 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1875 DURATION_ARG dots multipliers post_events
1877 $$ = make_music_from_simple (parser, @$,
1878 make_duration ($1, scm_to_int ($2), $3));
1879 Music *m = unsmob<Music> ($$);
1881 if (scm_is_pair ($4))
1882 m->set_property ("articulations",
1883 scm_reverse_x ($4, SCM_EOL));
1887 function_arglist_nonbackup_reparse:
1888 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1891 SCM res = try_string_variants ($2, $4);
1892 if (!SCM_UNBNDP (res))
1893 if (scm_is_pair (res))
1894 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1896 MYREPARSE (@4, $2, SCM_ARG, res);
1897 else if (scm_is_true
1899 ($2, make_music_from_simple
1901 MYREPARSE (@4, $2, STRING, $4);
1903 MYREPARSE (@4, $2, SCM_ARG, $4);
1905 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1910 ($2, make_music_from_simple
1912 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1914 MYREPARSE (@4, $2, SCM_ARG, $4);
1916 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1921 ($2, make_music_from_simple
1923 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1925 MYREPARSE (@4, $2, SCM_ARG, $4);
1927 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1930 SCM res = try_string_variants ($2, $4);
1931 if (!SCM_UNBNDP (res))
1932 if (scm_is_pair (res))
1933 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1935 MYREPARSE (@4, $2, SCM_ARG, res);
1936 else if (scm_is_true
1938 ($2, make_music_from_simple
1940 MYREPARSE (@4, $2, STRING, $4);
1942 MYREPARSE (@4, $2, SCM_ARG, $4);
1944 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1947 if (scm_is_true (scm_call_1 ($2, $4)))
1948 MYREPARSE (@4, $2, SCM_ARG, $4);
1949 else if (scm_is_true
1951 ($2, make_music_from_simple
1953 MYREPARSE (@4, $2, STRING, $4);
1955 MYREPARSE (@4, $2, SCM_ARG, $4);
1957 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1960 if (scm_is_true (scm_call_1 ($2, $4)))
1961 // May be 3 \cm or similar
1962 MYREPARSE (@4, $2, REAL, $4);
1963 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
1964 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
1966 SCM d = make_duration ($4);
1967 if (!SCM_UNBNDP (d)) {
1968 if (scm_is_true (scm_call_1 ($2, d)))
1969 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1970 else if (scm_is_true
1972 ($2, make_music_from_simple (parser, @4, d))))
1973 MYREPARSE (@4, $2, DURATION_ARG, d);
1975 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1977 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1980 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER
1983 if (scm_is_true (scm_call_1 ($2, $4)))
1984 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1985 else if (scm_is_true
1987 ($2, make_music_from_simple (parser, @4, $4))))
1988 MYREPARSE (@4, $2, DURATION_ARG, $4);
1990 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1995 // function_arglist_backup can't occur at the end of an argument
1997 function_arglist_backup:
1998 function_arglist_common
1999 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
2001 if (scm_is_true (scm_call_1 ($2, $4)))
2002 $$ = scm_cons ($4, $3);
2004 $$ = make_music_from_simple (parser, @4, $4);
2005 if (scm_is_true (scm_call_1 ($2, $$)))
2006 $$ = scm_cons ($$, $3);
2009 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2010 MYBACKUP (SCM_ARG, $4, @4);
2014 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
2016 if (scm_is_true (scm_call_1 ($2, $4)))
2018 $$ = scm_cons ($4, $3);
2020 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2021 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
2024 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
2028 ($2, make_music_from_simple
2032 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
2033 } else if (scm_is_true (scm_call_1 ($2, $4)))
2034 $$ = scm_cons ($4, $3);
2036 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2037 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
2040 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
2044 ($2, make_music_from_simple
2048 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
2049 } else if (scm_is_true (scm_call_1 ($2, $4)))
2050 $$ = scm_cons ($4, $3);
2052 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2053 MYBACKUP (TONICNAME_PITCH, $4, @4);
2056 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
2058 if (scm_is_true (scm_call_1 ($2, $4)))
2059 $$ = scm_cons ($4, $3);
2061 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2062 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2065 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
2068 if (scm_is_true (scm_call_1 ($2, $4)))
2069 // May be 3 \cm or similar
2070 MYREPARSE (@4, $2, REAL, $4);
2071 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
2072 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
2074 SCM d = make_duration ($4);
2075 if (!SCM_UNBNDP (d)) {
2076 if (scm_is_true (scm_call_1 ($2, d)))
2077 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
2078 else if (scm_is_true
2080 ($2, make_music_from_simple (parser, @4, d))))
2081 MYREPARSE (@4, $2, DURATION_ARG, d);
2083 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2084 MYBACKUP (UNSIGNED, $4, @4);
2087 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2088 MYBACKUP (UNSIGNED, $4, @4);
2092 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
2094 if (scm_is_true (scm_call_1 ($2, $4)))
2097 MYREPARSE (@4, $2, REAL, $4);
2099 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2100 MYBACKUP (REAL, $4, @4);
2103 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
2105 if (scm_is_true (scm_call_1 ($2, $4)))
2107 $$ = scm_cons ($4, $3);
2109 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2110 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
2113 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
2115 SCM n = scm_difference ($5, SCM_UNDEFINED);
2116 if (scm_is_true (scm_call_1 ($2, n))) {
2118 MYREPARSE (@5, $2, REAL, n);
2120 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
2121 t->set_property ("digit", $5);
2122 $$ = t->unprotect ();
2123 if (scm_is_true (scm_call_1 ($2, $$)))
2124 $$ = scm_cons ($$, $3);
2126 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2127 MYBACKUP (UNSIGNED, $5, @5);
2128 parser->lexer_->push_extra_token (@4, '-');
2132 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2134 SCM n = scm_difference ($5, SCM_UNDEFINED);
2135 if (scm_is_true (scm_call_1 ($2, n))) {
2136 MYREPARSE (@5, $2, REAL, n);
2139 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2140 MYBACKUP (REAL, n, @5);
2143 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2145 SCM n = scm_difference ($5, SCM_UNDEFINED);
2146 if (scm_is_true (scm_call_1 ($2, n))) {
2147 $$ = scm_cons (n, $3);
2149 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2150 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2153 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2156 if (scm_is_true (scm_call_1 ($2, $4)))
2157 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2158 else if (scm_is_true
2160 ($2, make_music_from_simple (parser, @4, $4))))
2161 MYREPARSE (@4, $2, DURATION_ARG, $4);
2163 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2164 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2167 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2169 SCM res = try_string_variants ($2, $4);
2170 if (!SCM_UNBNDP (res))
2171 if (scm_is_pair (res)) {
2173 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2176 $$ = scm_cons (res, $3);
2178 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2179 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2182 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2184 SCM res = try_string_variants ($2, $4);
2185 if (!SCM_UNBNDP (res))
2186 if (scm_is_pair (res)) {
2188 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2191 $$ = scm_cons (res, $3);
2193 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2194 MYBACKUP (STRING, $4, @4);
2197 | function_arglist_backup REPARSE pitch_or_music
2199 if (scm_is_true (scm_call_1 ($2, $3)))
2200 $$ = scm_cons ($3, $1);
2202 $$ = check_scheme_arg (parser, @3,
2203 make_music_from_simple
2207 | function_arglist_backup REPARSE bare_number_common
2209 $$ = check_scheme_arg (parser, @3,
2212 | function_arglist_backup REPARSE multiplied_duration
2214 $$ = check_scheme_arg (parser, @3,
2217 | function_arglist_backup REPARSE reparsed_rhythm
2219 $$ = check_scheme_arg (parser, @3,
2222 | function_arglist_backup REPARSE symbol_list_arg
2224 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2229 function_arglist_nonbackup
2230 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2232 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2236 function_arglist_skip_nonbackup:
2237 function_arglist_nonbackup
2238 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2240 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2244 // Partial function arglists are returned just in their incomplete
2245 // state: when combined with the music function, the missing parts of
2246 // the signature can be reconstructed
2248 // To serve as a partial arglist, the argument list must absolutely
2249 // _not_ be in "skipping optional arguments" mode since then there is
2250 // some backup token that has nowhere to go before \etc.
2252 // So we can skim off an arbitrary number of arguments from the end of
2253 // the argument list. The argument list remaining afterwards has to
2254 // be in not-skipping-optional-arguments mode.
2256 function_arglist_partial:
2257 EXPECT_SCM function_arglist_optional
2261 | EXPECT_SCM function_arglist_partial_optional
2265 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2269 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2275 function_arglist_partial_optional:
2276 EXPECT_SCM function_arglist_optional
2280 | EXPECT_SCM function_arglist_partial_optional
2284 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2288 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2294 function_arglist_common:
2295 EXPECT_NO_MORE_ARGS {
2298 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2300 if (scm_is_true (scm_call_1 ($1, $3)))
2301 $$ = scm_cons ($3, $2);
2303 $$ = check_scheme_arg (parser, @3,
2304 make_music_from_simple
2308 | EXPECT_SCM function_arglist_optional bare_number_common
2310 $$ = check_scheme_arg (parser, @3,
2313 | EXPECT_SCM function_arglist_optional post_event_nofinger
2315 $$ = check_scheme_arg (parser, @3,
2318 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2320 SCM n = scm_difference ($4, SCM_UNDEFINED);
2321 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2323 | function_arglist_common_reparse REPARSE SCM_ARG
2325 $$ = check_scheme_arg (parser, @3,
2328 | function_arglist_common_reparse REPARSE lyric_element_music
2330 $$ = check_scheme_arg (parser, @3,
2333 | function_arglist_common_reparse REPARSE pitch_or_music
2335 if (scm_is_true (scm_call_1 ($2, $3)))
2336 $$ = scm_cons ($3, $1);
2338 $$ = check_scheme_arg (parser, @3,
2339 make_music_from_simple
2343 | function_arglist_common_reparse REPARSE bare_number_common
2345 $$ = check_scheme_arg (parser, @3,
2348 | function_arglist_common_reparse REPARSE multiplied_duration
2350 $$ = check_scheme_arg (parser, @3,
2353 | function_arglist_common_reparse REPARSE reparsed_rhythm
2355 $$ = check_scheme_arg (parser, @3,
2358 | function_arglist_common_reparse REPARSE symbol_list_arg
2360 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2364 function_arglist_common_reparse:
2365 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2368 SCM res = try_string_variants ($1, $3);
2369 if (!SCM_UNBNDP (res))
2370 if (scm_is_pair (res))
2371 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2373 MYREPARSE (@3, $1, SCM_ARG, res);
2374 else if (scm_is_true
2376 ($1, make_music_from_simple (parser, @3, $3))))
2377 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2379 // This is going to flag a syntax error, we
2380 // know the predicate to be false.
2381 MYREPARSE (@3, $1, SCM_ARG, $3);
2383 | EXPECT_SCM function_arglist_optional pitch
2388 ($1, make_music_from_simple
2390 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2392 MYREPARSE (@3, $1, SCM_ARG, $3);
2394 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2399 ($1, make_music_from_simple
2401 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2403 MYREPARSE (@3, $1, SCM_ARG, $3);
2405 | EXPECT_SCM function_arglist_optional STRING
2408 SCM res = try_string_variants ($1, $3);
2409 if (!SCM_UNBNDP (res))
2410 if (scm_is_pair (res))
2411 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2413 MYREPARSE (@3, $1, SCM_ARG, res);
2414 else if (scm_is_true
2416 ($1, make_music_from_simple (parser, @3, $3))))
2417 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2419 // This is going to flag a syntax error, we
2420 // know the predicate to be false.
2421 MYREPARSE (@3, $1, SCM_ARG, $3);
2423 | EXPECT_SCM function_arglist_optional full_markup
2426 if (scm_is_true (scm_call_1 ($1, $3)))
2427 MYREPARSE (@3, $1, SCM_ARG, $3);
2428 else if (scm_is_true
2430 ($1, make_music_from_simple (parser, @3, $3))))
2431 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2433 // This is going to flag a syntax error, we
2434 // know the predicate to be false.
2435 MYREPARSE (@3, $1, SCM_ARG, $3);
2437 | EXPECT_SCM function_arglist_optional UNSIGNED
2440 if (scm_is_true (scm_call_1 ($1, $3)))
2441 // May be 3 \cm or similar
2442 MYREPARSE (@3, $1, REAL, $3);
2443 else if (scm_is_true (scm_call_1 ($1, scm_list_1 ($3))))
2444 MYREPARSE (@3, $1, SYMBOL_LIST, scm_list_1 ($3));
2446 SCM d = make_duration ($3);
2447 if (!SCM_UNBNDP (d)) {
2448 if (scm_is_true (scm_call_1 ($1, d)))
2449 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2450 else if (scm_is_true
2452 ($1, make_music_from_simple (parser, @3, d))))
2453 MYREPARSE (@3, $1, DURATION_ARG, d);
2455 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2457 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2460 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2463 if (scm_is_true (scm_call_1 ($1, $3)))
2464 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2465 else if (scm_is_true
2467 ($1, make_music_from_simple (parser, @3, $3))))
2468 MYREPARSE (@3, $1, DURATION_ARG, $3);
2470 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2472 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2475 SCM n = scm_difference ($4, SCM_UNDEFINED);
2476 if (scm_is_true (scm_call_1 ($1, n)))
2477 MYREPARSE (@4, $1, REAL, n);
2479 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2480 t->set_property ("digit", $4);
2481 SCM m = t->unprotect ();
2482 if (scm_is_true (scm_call_1 ($1, m)))
2483 MYREPARSE (@4, $1, SCM_ARG, m);
2485 MYREPARSE (@4, $1, SCM_ARG, $4);
2488 | EXPECT_SCM function_arglist_optional '-' REAL
2491 SCM n = scm_difference ($4, SCM_UNDEFINED);
2492 MYREPARSE (@4, $1, REAL, n);
2496 function_arglist_optional:
2497 function_arglist_backup
2498 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2500 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2502 | function_arglist_skip_backup BACKUP
2505 function_arglist_skip_backup:
2506 function_arglist_backup
2507 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2509 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2513 music_function_call:
2514 MUSIC_FUNCTION function_arglist {
2515 $$ = MAKE_SYNTAX (music_function, @$,
2522 /**/ { $$ = SCM_EOL; }
2523 | '=' simple_string {
2528 // We must not have lookahead tokens parsed in lyric mode. In order
2529 // to save confusion, we take almost the same set as permitted with
2530 // \lyricmode and/or \lyrics. However, music identifiers are also
2531 // allowed, and they obviously do not require switching into lyrics
2532 // mode for parsing.
2536 parser->lexer_->push_lyric_state ();
2537 } grouped_music_list
2539 parser->lexer_->pop_state ();
2546 mode_changing_head grouped_music_list {
2547 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2549 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2555 parser->lexer_->pop_state ();
2557 | mode_changing_head_with_context optional_context_mods grouped_music_list {
2558 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, $2, SCM_BOOL_T, $3);
2559 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2561 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2563 parser->lexer_->pop_state ();
2569 parser->lexer_->push_note_state (Lily::pitchnames);
2571 $$ = ly_symbol2scm ("notes");
2575 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2577 $$ = ly_symbol2scm ("drums");
2580 parser->lexer_->push_figuredbass_state ();
2582 $$ = ly_symbol2scm ("figures");
2585 parser->lexer_->chordmodifier_tab_ =
2586 alist_to_hashq (Lily::chordmodifiers);
2587 parser->lexer_->push_chord_state (Lily::pitchnames);
2588 $$ = ly_symbol2scm ("chords");
2592 { parser->lexer_->push_lyric_state ();
2593 $$ = ly_symbol2scm ("lyrics");
2597 mode_changing_head_with_context:
2599 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2601 $$ = ly_symbol2scm ("DrumStaff");
2604 parser->lexer_->push_figuredbass_state ();
2606 $$ = ly_symbol2scm ("FiguredBass");
2609 parser->lexer_->chordmodifier_tab_ =
2610 alist_to_hashq (Lily::chordmodifiers);
2611 parser->lexer_->push_chord_state (Lily::pitchnames);
2612 $$ = ly_symbol2scm ("ChordNames");
2615 { parser->lexer_->push_lyric_state ();
2616 $$ = ly_symbol2scm ("Lyrics");
2621 CHANGE symbol '=' simple_string {
2622 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2629 $$ = scm_reverse_x ($1, SCM_EOL);
2635 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2638 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2640 | OVERRIDE revert_arg '=' scalar {
2641 if (scm_ilength ($2) < 2) {
2642 parser->parser_error (@2, _("bad grob property path"));
2645 $$ = scm_cons (ly_symbol2scm ("push"),
2646 scm_cons2 (scm_car ($2),
2651 | REVERT revert_arg {
2652 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2656 // This is all quite awkward for the sake of substantial backward
2657 // compatibility while at the same time allowing a more "natural" form
2658 // of specification not separating grob specification from grob
2659 // property path. The purpose of this definition of revert_arg is to
2660 // allow the symbol list which specifies grob and property to revert
2661 // to be optionally be split into two parts after the grob (which in
2662 // this case is just the first element of the list). symbol_list_part
2663 // is only one path component, but it can be parsed without lookahead,
2664 // so we can follow it with a synthetic BACKUP token when needed. If
2665 // the first symbol_list_part already contains multiple elements (only
2666 // possible if a Scheme expression provides them), we just parse for
2667 // additional elements introduced by '.', which is what the
2668 // SYMBOL_LIST backup in connection with the immediately following
2669 // rule using symbol_list_arg does.
2671 // As long as we don't have our coffers filled with both grob and at
2672 // least one grob property specification, the rest of the required
2673 // symbol list chain may be provided either with or without a leading
2674 // dot. This is for both allowing the traditional
2675 // \revert Accidental #'color
2676 // as well as well as the "naive" form
2677 // \revert Accidental.color
2680 revert_arg_backup BACKUP symbol_list_arg
2689 if (scm_is_null ($1)
2690 || scm_is_null (scm_cdr ($1)))
2691 MYBACKUP (SCM_ARG, $1, @1);
2693 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2697 // revert_arg_part delivers results in reverse
2700 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2702 $$ = scm_append_x (scm_list_2 ($5, $3));
2704 | revert_arg_backup BACKUP SCM_ARG ',' symbol_list_part
2706 $$ = scm_append_x (scm_list_2 ($5, $3));
2708 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2710 $$ = scm_append_x (scm_list_2 ($4, $3));
2715 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2716 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2718 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2719 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2720 | DENIES { $$ = ly_symbol2scm ("denies"); }
2722 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2723 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2724 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2725 | NAME { $$ = ly_symbol2scm ("context-name"); }
2729 property_operation { $$ = $1; }
2730 | context_def_mod STRING {
2731 $$ = scm_list_2 ($1, $2);
2733 | context_def_mod embedded_scm
2735 if (!scm_is_string ($2)
2736 && ly_symbol2scm ("consists") != $1
2737 && ly_symbol2scm ("remove") != $1)
2740 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2744 $$ = scm_list_2 ($1, $2);
2749 // If defined, at least two members.
2753 SCM l = scm_reverse_x ($1, SCM_EOL);
2756 (scm_object_property (scm_car (l),
2757 ly_symbol2scm ("is-grob?"))))
2758 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2759 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2760 parser->parser_error (@1, _ ("bad grob property path"));
2767 // If defined, at least three members
2771 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2773 parser->parser_error (@1, _ ("bad grob property path"));
2777 | grob_prop_spec property_path
2779 if (!SCM_UNBNDP ($1)) {
2780 $$ = scm_append_x (scm_list_2 ($1, $2));
2781 if (scm_is_null (scm_cddr ($$))) {
2782 parser->parser_error (@$, _ ("bad grob property path"));
2790 // Exactly two elements or undefined
2794 SCM l = scm_reverse_x ($1, SCM_EOL);
2795 switch (scm_ilength (l)) {
2797 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2801 parser->parser_error (@1, _ ("bad context property path"));
2809 // This is all quite awkward for the sake of substantial backward
2810 // compatibility while at the same time allowing a more "natural" form
2811 // of specification not separating grob specification from grob
2812 // property path. The purpose of this definition of
2813 // simple_revert_context is to allow the symbol list which specifies
2814 // grob and property to revert to be optionally be split into two
2815 // parts after the grob (which may be preceded by a context
2816 // specification, a case which we distinguish by checking whether the
2817 // first symbol is a valid grob symbol instead).
2819 // See revert_arg above for the main work horse of this arrangement.
2820 // simple_revert_context just caters for the context and delegates the
2821 // rest of the job to revert_arg.
2823 simple_revert_context:
2826 $1 = scm_reverse_x ($1, SCM_EOL);
2827 if (scm_is_null ($1)
2829 (scm_object_property (scm_car ($1),
2830 ly_symbol2scm ("is-grob?")))) {
2831 $$ = ly_symbol2scm ("Bottom");
2832 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2835 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2842 OVERRIDE grob_prop_path '=' scalar {
2843 if (SCM_UNBNDP ($2))
2844 $$ = MAKE_SYNTAX (void_music, @$);
2846 $$ = MAKE_SYNTAX (property_override, @$,
2851 | REVERT simple_revert_context revert_arg {
2852 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2854 | SET context_prop_spec '=' scalar {
2855 if (SCM_UNBNDP ($2))
2856 $$ = MAKE_SYNTAX (void_music, @$);
2858 $$ = MAKE_SYNTAX (property_set, @$,
2863 | UNSET context_prop_spec {
2864 if (SCM_UNBNDP ($2))
2865 $$ = MAKE_SYNTAX (void_music, @$);
2867 $$ = MAKE_SYNTAX (property_unset, @$,
2883 if (Text_interface::is_markup ($1)) {
2886 parser->parser_error (@1, (_ ("markup expected")));
2887 $$ = scm_string (SCM_EOL);
2892 simple_string: STRING
2895 if (scm_is_string ($1)) {
2898 parser->parser_error (@1, (_ ("simple string expected")));
2899 $$ = scm_string (SCM_EOL);
2906 $$ = scm_string_to_symbol ($1);
2910 // This is a bit of overkill but makes the same
2911 // routine responsible for all symbol interpretations.
2912 $$ = try_string_variants (Guile_user::symbol_p, $1);
2913 if (SCM_UNBNDP ($$))
2915 parser->parser_error (@1, (_ ("symbol expected")));
2916 // Generate a unique symbol in case it is used
2917 // for an assignment or similar
2918 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2928 // The following is a rather defensive variant of admitting
2929 // negative numbers: the grammar would permit number_factor or
2930 // even number_expression. However, function arguments allow
2931 // only this simple kind of negative number, so to have things
2932 // like \tweak and \override behave reasonably similar, it
2933 // makes sense to rule out things like -- which are rather an
2934 // accent in function argument contexts.
2937 $$ = scm_difference ($2, SCM_UNDEFINED);
2940 | symbol_list_part_bare '.' property_path
2942 $$ = scm_reverse_x ($1, $3);
2944 | symbol_list_part_bare ',' property_path
2946 $$ = scm_reverse_x ($1, $3);
2951 simple_element post_events {
2952 // Let the rhythmic music iterator sort this mess out.
2953 if (scm_is_pair ($2)) {
2954 unsmob<Music> ($$)->set_property ("articulations",
2955 scm_reverse_x ($2, SCM_EOL));
2958 | CHORD_REPETITION optional_notemode_duration post_events {
2960 i.set_location (@1, @3);
2961 $$ = MAKE_SYNTAX (repetition_chord, i,
2962 $2, scm_reverse_x ($3, SCM_EOL));
2964 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2966 i.set_location (@1, @3);
2967 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2968 scm_reverse_x ($3, SCM_EOL));
2971 | note_chord_element
2976 chord_body optional_notemode_duration post_events
2978 Music *m = unsmob<Music> ($1);
2979 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2980 SCM es = m->get_property ("elements");
2981 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2983 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2984 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2985 es = ly_append2 (es, postevs);
2987 m->set_property ("elements", es);
2988 m->set_spot (parser->lexer_->override_input (@$));
2989 $$ = m->self_scm ();
2994 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2996 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2998 | FIGURE_OPEN figure_list FIGURE_CLOSE
3000 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
3004 chord_body_elements:
3005 /* empty */ { $$ = SCM_EOL; }
3006 | chord_body_elements chord_body_element {
3007 if (!SCM_UNBNDP ($2))
3008 $$ = scm_cons ($2, $1);
3013 pitch_or_tonic_pitch exclamations questions octave_check post_events
3015 bool q = to_boolean ($3);
3016 bool ex = to_boolean ($2);
3020 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3021 n->set_property ("pitch", $1);
3023 n->set_property ("cautionary", SCM_BOOL_T);
3025 n->set_property ("force-accidental", SCM_BOOL_T);
3027 if (scm_is_pair (post)) {
3028 SCM arts = scm_reverse_x (post, SCM_EOL);
3029 n->set_property ("articulations", arts);
3031 if (scm_is_number (check))
3033 int q = scm_to_int (check);
3034 n->set_property ("absolute-octave", scm_from_int (q-1));
3037 $$ = n->unprotect ();
3039 | DRUM_PITCH post_events {
3040 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3041 n->set_property ("drum-type", $1);
3043 if (scm_is_pair ($2)) {
3044 SCM arts = scm_reverse_x ($2, SCM_EOL);
3045 n->set_property ("articulations", arts);
3047 $$ = n->unprotect ();
3049 | music_function_chord_body
3051 Music *m = unsmob<Music> ($1);
3053 while (m && m->is_mus_type ("music-wrapper-music")) {
3054 $$ = m->get_property ("element");
3055 m = unsmob<Music> ($$);
3058 if (!(m && m->is_mus_type ("rhythmic-event"))) {
3059 parser->parser_error (@$, _ ("not a rhythmic event"));
3065 music_function_chord_body:
3071 event_function_event:
3072 EVENT_FUNCTION function_arglist {
3073 $$ = MAKE_SYNTAX (music_function, @$,
3082 | post_events post_event {
3084 if (Music *m = unsmob<Music> ($2))
3086 if (m->is_mus_type ("post-event-wrapper"))
3088 for (SCM p = m->get_property ("elements");
3092 $$ = scm_cons (scm_car (p), $$);
3095 m->set_spot (parser->lexer_->override_input (@2));
3096 $$ = scm_cons ($2, $$);
3102 post_event_nofinger:
3103 direction_less_event {
3106 | script_dir music_function_call {
3108 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
3109 parser->parser_error (@2, _ ("post-event expected"));
3110 $$ = SCM_UNSPECIFIED;
3111 } else if (!SCM_UNBNDP ($1))
3113 unsmob<Music> ($$)->set_property ("direction", $1);
3117 if (!parser->lexer_->is_lyric_state ())
3118 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3119 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
3122 if (!parser->lexer_->is_lyric_state ())
3123 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3124 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
3126 | script_dir direction_reqd_event {
3127 if (!SCM_UNBNDP ($1))
3129 Music *m = unsmob<Music> ($2);
3130 m->set_property ("direction", $1);
3134 | script_dir direction_less_event {
3135 if (!SCM_UNBNDP ($1))
3137 Music *m = unsmob<Music> ($2);
3138 m->set_property ("direction", $1);
3145 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
3150 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
3161 string_number_event:
3163 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3164 s->set_property ("string-number", $1);
3165 $$ = s->unprotect ();
3169 direction_less_event:
3171 | EVENT_IDENTIFIER {
3175 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3176 a->set_property ("tremolo-type", $1);
3177 $$ = a->unprotect ();
3179 | event_function_event
3182 direction_reqd_event:
3186 | script_abbreviation {
3187 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3188 if (scm_is_string (s)) {
3189 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3190 a->set_property ("articulation-type", s);
3191 $$ = a->unprotect ();
3193 Music *original = unsmob<Music> (s);
3194 if (original && original->is_mus_type ("post-event")) {
3195 Music *a = original->clone ();
3196 a->set_spot (parser->lexer_->override_input (@$));
3197 $$ = a->unprotect ();
3199 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3200 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3207 /**/ { $$ = SCM_EOL; }
3208 | '=' quotes { $$ = $2; }
3222 $$ = scm_from_int (1);
3225 $$ = scm_oneplus ($1);
3231 $$ = scm_from_int (-1);
3234 $$ = scm_oneminus ($1);
3239 NOTENAME_PITCH quotes {
3240 if (!scm_is_eq (SCM_INUM0, $2))
3242 Pitch p = *unsmob<Pitch> ($1);
3243 p = p.transposed (Pitch (scm_to_int ($2), 0));
3244 $$ = p.smobbed_copy ();
3254 TONICNAME_PITCH quotes {
3255 if (!scm_is_eq (SCM_INUM0, $2))
3257 Pitch p = *unsmob<Pitch> ($1);
3258 p = p.transposed (Pitch (scm_to_int ($2), 0));
3259 $$ = p.smobbed_copy ();
3266 | PITCH_IDENTIFIER quotes {
3267 if (!scm_is_eq (SCM_INUM0, $2))
3269 Pitch p = *unsmob<Pitch> ($1);
3270 p = p.transposed (Pitch (scm_to_int ($2), 0));
3271 $$ = p.smobbed_copy ();
3276 pitch_or_tonic_pitch:
3283 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3284 t->set_property ("text", $1);
3285 $$ = t->unprotect ();
3288 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3289 t->set_property ("text",
3290 make_simple_markup ($1));
3291 $$ = t->unprotect ();
3295 Music *m = unsmob<Music> ($1);
3296 if (m && m->is_mus_type ("post-event"))
3298 else if (Text_interface::is_markup ($1)) {
3299 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3300 t->set_property ("text", $1);
3301 $$ = t->unprotect ();
3303 parser->parser_error (@1, _ ("not an articulation"));
3309 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3310 t->set_property ("digit", $1);
3311 $$ = t->unprotect ();
3315 script_abbreviation:
3317 $$ = scm_from_ascii_string ("Hat");
3320 $$ = scm_from_ascii_string ("Plus");
3323 $$ = scm_from_ascii_string ("Dash");
3326 $$ = scm_from_ascii_string ("Bang");
3329 $$ = scm_from_ascii_string ("Larger");
3332 $$ = scm_from_ascii_string ("Dot");
3335 $$ = scm_from_ascii_string ("Underscore");
3340 '_' { $$ = scm_from_int (DOWN); }
3341 | '^' { $$ = scm_from_int (UP); }
3342 | '-' { $$ = SCM_UNDEFINED; }
3345 maybe_notemode_duration:
3349 | multiplied_duration {
3351 parser->default_duration_ = *unsmob<Duration> ($$);
3356 optional_notemode_duration:
3357 maybe_notemode_duration
3359 if (SCM_UNBNDP ($$))
3360 $$ = parser->default_duration_.smobbed_copy ();
3366 $$ = make_duration ($1, scm_to_int ($2));
3367 if (SCM_UNBNDP ($$))
3369 parser->parser_error (@1, _ ("not a duration"));
3370 $$ = Duration ().smobbed_copy ();
3373 | DURATION_IDENTIFIER dots {
3374 $$ = make_duration ($1, scm_to_int ($2));
3378 multiplied_duration:
3379 steno_duration multipliers {
3380 $$ = make_duration ($1, 0, $2);
3389 $$ = scm_oneplus ($1);
3398 | multipliers '*' UNSIGNED
3400 if (!SCM_UNBNDP ($1))
3401 $$ = scm_product ($1, $3);
3405 | multipliers '*' FRACTION
3407 if (!SCM_UNBNDP ($1))
3408 $$ = scm_product ($1, scm_divide (scm_car ($3),
3411 $$ = scm_divide (scm_car ($3), scm_cdr ($3));
3417 $$ = scm_from_int (parser->default_tremolo_type_);
3420 if (SCM_UNBNDP (make_duration ($2))) {
3421 parser->parser_error (@2, _ ("not a duration"));
3422 $$ = scm_from_int (parser->default_tremolo_type_);
3425 parser->default_tremolo_type_ = scm_to_int ($2);
3431 UNSIGNED { $$ = $1; }
3432 | STRING { $$ = $1; }
3433 | full_markup { $$ = $1; }
3436 // as an integer, it needs to be non-negative, and otherwise
3437 // it needs to be suitable as a markup.
3438 if (scm_is_integer ($1)
3439 ? scm_is_true (scm_negative_p ($1))
3440 : !Text_interface::is_markup ($1))
3442 parser->parser_error (@1, _ ("bass number expected"));
3448 figured_bass_alteration:
3449 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3450 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3451 | '!' { $$ = scm_from_int (0); }
3456 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3457 $$ = bfr->unprotect ();
3460 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3461 $$ = bfr->self_scm ();
3463 if (scm_is_number ($1))
3464 bfr->set_property ("figure", $1);
3465 else if (Text_interface::is_markup ($1))
3466 bfr->set_property ("text", $1);
3472 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3474 | bass_figure figured_bass_alteration {
3475 Music *m = unsmob<Music> ($1);
3476 if (scm_to_double ($2)) {
3477 SCM salter = m->get_property ("alteration");
3478 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3479 m->set_property ("alteration",
3480 scm_sum (alter, $2));
3482 m->set_property ("alteration", scm_from_int (0));
3485 | bass_figure figured_bass_modification {
3486 Music *m = unsmob<Music> ($1);
3487 m->set_property ($2, SCM_BOOL_T);
3492 figured_bass_modification:
3494 $$ = ly_symbol2scm ("augmented");
3497 $$ = ly_symbol2scm ("no-continuation");
3500 $$ = ly_symbol2scm ("diminished");
3503 $$ = ly_symbol2scm ("augmented-slash");
3513 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3521 | figure_list br_bass_figure {
3522 $$ = scm_cons ($2, $1);
3527 /**/ { $$ = SCM_BOOL_F; }
3528 | REST { $$ = SCM_BOOL_T; }
3532 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3533 if (!parser->lexer_->is_note_state ())
3534 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3535 if (!SCM_UNBNDP ($2)
3537 || scm_is_number ($4)
3540 || scm_is_pair ($7))
3543 if (scm_is_true ($6))
3544 n = MY_MAKE_MUSIC ("RestEvent", @$);
3546 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3548 n->set_property ("pitch", $1);
3549 if (SCM_UNBNDP ($5))
3550 n->set_property ("duration",
3551 parser->default_duration_.smobbed_copy ());
3553 n->set_property ("duration", $5);
3555 if (scm_is_number ($4))
3557 int q = scm_to_int ($4);
3558 n->set_property ("absolute-octave", scm_from_int (q-1));
3561 if (to_boolean ($3))
3562 n->set_property ("cautionary", SCM_BOOL_T);
3563 if (to_boolean ($2) || to_boolean ($3))
3564 n->set_property ("force-accidental", SCM_BOOL_T);
3565 if (scm_is_pair ($7))
3566 n->set_property ("articulations",
3567 scm_reverse_x ($7, SCM_EOL));
3568 $$ = n->unprotect ();
3571 | new_chord post_events {
3572 if (!parser->lexer_->is_chord_state ())
3573 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3574 if (scm_is_pair ($2)) {
3575 if (unsmob<Pitch> ($1))
3576 $1 = make_chord_elements (@1,
3578 parser->default_duration_.smobbed_copy (),
3581 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3583 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3584 } else if (!unsmob<Pitch> ($1))
3585 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3586 // A mere pitch drops through.
3591 DRUM_PITCH optional_notemode_duration {
3592 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3593 n->set_property ("duration", $2);
3594 n->set_property ("drum-type", $1);
3596 $$ = n->unprotect ();
3598 | RESTNAME optional_notemode_duration {
3600 if (ly_scm2string ($1) == "s") {
3602 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3605 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3608 ev->set_property ("duration", $2);
3609 $$ = ev->unprotect ();
3615 if (!parser->lexer_->is_lyric_state ())
3616 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3620 if (!parser->lexer_->is_lyric_state ())
3621 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3627 lyric_element_music:
3628 lyric_element optional_notemode_duration post_events {
3629 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3630 if (scm_is_pair ($3))
3631 unsmob<Music> ($$)->set_property
3632 ("articulations", scm_reverse_x ($3, SCM_EOL));
3636 // Can return a single pitch rather than a list.
3638 steno_tonic_pitch maybe_notemode_duration {
3639 if (SCM_UNBNDP ($2))
3642 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3644 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3645 SCM its = scm_reverse_x ($4, SCM_EOL);
3646 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3654 | chord_items chord_item {
3655 $$ = scm_cons ($2, $$);
3661 $$ = ly_symbol2scm ("chord-colon");
3664 $$ = ly_symbol2scm ("chord-caret");
3666 | CHORD_SLASH steno_tonic_pitch {
3667 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3669 | CHORD_BASS steno_tonic_pitch {
3670 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3679 $$ = scm_reverse_x ($1, SCM_EOL);
3687 step_number { $$ = scm_cons ($1, SCM_EOL); }
3688 | step_numbers '.' step_number {
3689 $$ = scm_cons ($3, $$);
3695 $$ = make_chord_step ($1, 0);
3698 $$ = make_chord_step ($1, SHARP_ALTERATION);
3700 | UNSIGNED CHORD_MINUS {
3701 $$ = make_chord_step ($1, FLAT_ALTERATION);
3709 | unsigned_number '-' unsigned_number {
3710 $$ = scm_cons ($1, $3);
3717 TODO: should deprecate in favor of Scheme?
3721 number_expression '+' number_term {
3722 $$ = scm_sum ($1, $3);
3724 | number_expression '-' number_term {
3725 $$ = scm_difference ($1, $3);
3734 | number_factor '*' number_factor {
3735 $$ = scm_product ($1, $3);
3737 | number_factor '/' number_factor {
3738 $$ = scm_divide ($1, $3);
3743 '-' number_factor { /* %prec UNARY_MINUS */
3744 $$ = scm_difference ($2, SCM_UNDEFINED);
3752 | REAL NUMBER_IDENTIFIER
3754 $$ = scm_product ($1, $2);
3761 | UNSIGNED NUMBER_IDENTIFIER {
3762 $$ = scm_product ($1, $2);
3770 if (!scm_is_integer ($1)
3771 || scm_is_true (scm_negative_p ($1)))
3773 parser->parser_error (@1, _("not an unsigned integer"));
3779 if (!scm_is_integer ($1)
3780 || scm_is_true (scm_negative_p ($1)))
3782 parser->parser_error (@1, _("not an unsigned integer"));
3789 { $$ = SCM_UNDEFINED; }
3792 if (SCM_UNBNDP ($1))
3800 // This precedence rule is rather weird. It triggers when '!' is
3801 // encountered after a pitch, and is used for deciding whether to save
3802 // this instead for a figure modification. This should not actually
3803 // occur in practice as pitches and figures are generated in different
3804 // modes. Using a greedy (%right) precedence makes sure that we don't
3805 // get stuck in a wrong interpretation.
3806 { $$ = SCM_UNDEFINED; } %prec ':'
3809 if (SCM_UNBNDP ($1))
3818 { parser->lexer_->push_markup_state (); }
3821 parser->lexer_->pop_state ();
3828 parser->lexer_->push_markup_state ();
3833 markup_mode markup_top {
3835 parser->lexer_->pop_state ();
3840 markup_mode markup_partial_function ETC
3842 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3843 parser->lexer_->pop_state ();
3849 $$ = scm_list_2 (Lily::line_markup, $1);
3851 | markup_head_1_list simple_markup
3853 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3854 @2, $1, scm_list_1 ($2)));
3864 if (Text_interface::is_markup ($1))
3865 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3866 else if (Text_interface::is_markup_list ($1))
3867 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3869 parser->parser_error (@1, _ ("not a markup"));
3870 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3877 markup_composed_list {
3880 | markup_uncomposed_list
3883 markup_uncomposed_list:
3884 markup_braced_list {
3887 | markup_command_list {
3888 $$ = scm_list_1 ($1);
3890 | markup_scm MARKUPLIST_IDENTIFIER
3895 parser->lexer_->push_note_state (Lily::pitchnames);
3896 } '{' score_body '}' {
3897 Score *sc = unsmob<Score> ($4);
3898 sc->origin ()->set_spot (@$);
3899 if (sc->defs_.empty ()) {
3900 Output_def *od = get_layout (parser);
3901 sc->add_output_def (od);
3904 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3905 parser->lexer_->pop_state ();
3909 markup_composed_list:
3910 markup_head_1_list markup_uncomposed_list {
3911 $$ = MAKE_SYNTAX (composed_markup_list,
3917 '{' markup_braced_list_body '}' {
3918 $$ = scm_reverse_x ($2, SCM_EOL);
3922 markup_braced_list_body:
3923 /* empty */ { $$ = SCM_EOL; }
3924 | markup_braced_list_body markup {
3925 $$ = scm_cons ($2, $1);
3927 | markup_braced_list_body markup_list {
3928 $$ = scm_reverse_x ($2, $1);
3932 markup_command_list:
3933 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3934 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3938 markup_command_basic_arguments:
3939 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3940 $$ = scm_cons ($3, $2);
3942 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3943 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3945 | EXPECT_NO_MORE_ARGS {
3950 markup_command_list_arguments:
3951 markup_command_basic_arguments { $$ = $1; }
3952 | EXPECT_MARKUP markup_command_list_arguments markup {
3953 $$ = scm_cons ($3, $2);
3957 markup_partial_function:
3958 MARKUP_FUNCTION markup_arglist_partial
3960 $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
3962 | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
3964 $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
3969 markup_arglist_partial:
3970 EXPECT_MARKUP markup_arglist_partial
3974 | EXPECT_SCM markup_arglist_partial
3978 | EXPECT_MARKUP markup_command_list_arguments
3982 | EXPECT_SCM markup_command_list_arguments
3989 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3990 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3995 markup_head_1_item {
3996 $$ = scm_list_1 ($1);
3998 | markup_head_1_list markup_head_1_item {
3999 $$ = scm_cons ($2, $1);
4005 $$ = make_simple_markup ($1);
4008 parser->lexer_->push_note_state (Lily::pitchnames);
4009 } '{' score_body '}' {
4010 Score *sc = unsmob<Score> ($4);
4011 sc->origin ()->set_spot (@$);
4012 if (sc->defs_.empty ()) {
4013 Output_def *od = get_layout (parser);
4014 sc->add_output_def (od);
4017 $$ = scm_list_2 (Lily::score_markup, $4);
4018 parser->lexer_->pop_state ();
4020 | MARKUP_FUNCTION markup_command_basic_arguments {
4021 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
4023 | markup_scm MARKUP_IDENTIFIER
4030 markup_head_1_list simple_markup
4032 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
4033 @2, $1, scm_list_1 ($2)));
4043 Lily_parser::set_yydebug (bool x)
4049 Lily_parser::do_yyparse ()
4051 return scm_c_with_fluid (Lily::f_parser,
4053 do_yyparse_trampoline,
4054 static_cast <void *>(this));
4058 Lily_parser::do_yyparse_trampoline (void *parser)
4060 SCM retval = SCM_UNDEFINED;
4061 yyparse (static_cast <Lily_parser *>(parser), &retval);
4069 It is a little strange to have this function in this file, but
4070 otherwise, we have to import music classes into the lexer.
4074 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
4076 if (unsmob<Book> (sid)) {
4077 Book *book = unsmob<Book> (sid)->clone ();
4078 *destination = book->self_scm ();
4081 return BOOK_IDENTIFIER;
4082 } else if (scm_is_number (sid)) {
4084 return NUMBER_IDENTIFIER;
4085 } else if (unsmob<Context_def> (sid))
4087 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
4088 return SCM_IDENTIFIER;
4089 } else if (unsmob<Context_mod> (sid)) {
4090 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
4091 return CONTEXT_MOD_IDENTIFIER;
4092 } else if (Music *mus = unsmob<Music> (sid)) {
4093 mus = mus->clone ();
4094 *destination = mus->self_scm ();
4095 bool is_event = mus->is_mus_type ("post-event");
4097 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
4098 } else if (unsmob<Pitch> (sid)) {
4099 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
4100 return PITCH_IDENTIFIER;
4101 } else if (unsmob<Duration> (sid)) {
4102 *destination = unsmob<Duration> (sid)->smobbed_copy ();
4103 return DURATION_IDENTIFIER;
4104 } else if (unsmob<Output_def> (sid)) {
4105 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
4106 return SCM_IDENTIFIER;
4107 } else if (unsmob<Score> (sid)) {
4108 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
4109 return SCM_IDENTIFIER;
4110 } else if (scm_is_pair (sid)
4111 && scm_is_pair (scm_car (sid))
4112 && scm_is_true (Lily::key_p (scm_caar (sid)))) {
4114 return LOOKUP_IDENTIFIER;
4120 get_next_unique_context_id ()
4122 return scm_from_ascii_string ("$uniqueContextId");
4127 get_next_unique_lyrics_context_id ()
4129 static int new_context_count;
4131 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
4132 return scm_from_ascii_string (s);
4135 // check_scheme_arg checks one argument with a given predicate for use
4136 // in an argument list and throws a syntax error if it is unusable.
4137 // The argument is prepended to the argument list in any case. After
4138 // throwing a syntax error, the argument list is terminated with #f as
4139 // its last cdr in order to mark it as uncallable while not losing
4140 // track of its total length.
4142 // There are a few special considerations: if optional argument disp
4143 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
4144 // instead of arg in a prospective error message. This is useful if
4145 // arg is not the actual argument but rather a transformation of it.
4147 // If arg itself is SCM_UNDEFINED, the predicate is considered false
4148 // and an error message using disp is produced unconditionally.
4150 SCM check_scheme_arg (Lily_parser *parser, Input loc,
4151 SCM arg, SCM args, SCM pred, SCM disp)
4153 if (SCM_UNBNDP (arg))
4154 args = scm_cons (disp, args);
4156 args = scm_cons (arg, args);
4157 if (scm_is_true (scm_call_1 (pred, arg)))
4160 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
4161 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
4162 SCM_UNBNDP (disp) ? arg : disp);
4163 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
4167 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
4169 if (Music *m = unsmob<Music> (arg))
4172 m->set_spot (parser->lexer_->override_input (loc));
4173 return m->unprotect ();
4179 try_string_variants (SCM pred, SCM str)
4181 // a matching predicate is always ok
4182 if (scm_is_true (scm_call_1 (pred, str)))
4184 // a symbol may be interpreted as a list of symbols if it helps
4185 if (scm_is_true (Lily::key_p (str))) {
4186 str = scm_list_1 (str);
4187 if (scm_is_true (scm_call_1 (pred, str)))
4189 return SCM_UNDEFINED;
4192 // If this cannot be a string representation of a symbol list,
4195 if (!is_regular_identifier (str, true))
4196 return SCM_UNDEFINED;
4198 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4199 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4200 scm_set_car_x (p, scm_string_split (scm_car (p),
4201 SCM_MAKE_CHAR (',')));
4202 str = scm_append_x (str);
4203 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4204 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4206 // Let's attempt the symbol list interpretation first.
4208 if (scm_is_true (scm_call_1 (pred, str)))
4211 // If there is just one symbol in the list, we might interpret
4212 // it as a single symbol
4214 if (scm_is_null (scm_cdr (str)))
4216 str = scm_car (str);
4217 if (scm_is_true (scm_call_1 (pred, str)))
4221 return SCM_UNDEFINED;
4225 is_regular_identifier (SCM id, bool multiple)
4227 if (!scm_is_string (id))
4230 string str = ly_scm2string (id);
4232 bool middle = false;
4234 for (string::iterator it=str.begin(); it != str.end (); it++)
4237 if ((c >= 'a' && c <= 'z')
4238 || (c >= 'A' && c <= 'Z')
4241 else if (middle && (c == '-' || c == '_' || (multiple &&
4242 (c == '.' || c == ','))))
4251 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4253 if (unsmob<Music> (simple))
4255 if (parser->lexer_->is_note_state ()) {
4256 if (scm_is_symbol (simple)) {
4257 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4258 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4259 n->set_property ("drum-type", simple);
4260 return n->unprotect ();
4262 if (unsmob<Pitch> (simple)) {
4263 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4264 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4265 n->set_property ("pitch", simple);
4266 return n->unprotect ();
4269 if (scm_is_integer (simple))
4270 d = make_duration (simple);
4271 if (unsmob<Duration> (d)) {
4272 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4273 n->set_property ("duration", d);
4274 return n->unprotect ();
4277 } else if (parser->lexer_->is_lyric_state ()) {
4278 if (Text_interface::is_markup (simple))
4279 return MAKE_SYNTAX (lyric_event, loc, simple,
4280 parser->default_duration_.smobbed_copy ());
4281 } else if (parser->lexer_->is_chord_state ()) {
4282 if (unsmob<Pitch> (simple))
4286 make_chord_elements (loc, simple,
4287 parser->default_duration_.smobbed_copy (),
4294 make_music_with_input (SCM name, Input where)
4296 Music *m = make_music_by_name (name);
4297 m->set_spot (where);
4302 make_simple_markup (SCM a)
4308 make_duration (SCM d, int dots, SCM factor)
4312 if (Duration *dur = unsmob<Duration> (d)) {
4313 if (!dots && SCM_UNBNDP (factor))
4317 k = Duration (k.duration_log (), k.dot_count () + dots)
4318 .compressed (k.factor ());
4320 int t = scm_to_int (d);
4321 if (t > 0 && (t & (t-1)) == 0)
4322 k = Duration (intlog2 (t), dots);
4324 return SCM_UNDEFINED;
4327 if (!SCM_UNBNDP (factor))
4328 k = k.compressed (ly_scm2rational (factor));
4330 return k.smobbed_copy ();
4334 make_chord_step (SCM step_scm, Rational alter)
4336 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4338 // Notename/octave are normalized
4339 if (m.get_notename () == 6)
4340 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4342 return m.smobbed_copy ();
4347 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4349 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4350 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4352 unsmob<Music> (scm_car (s))->set_spot (loc);
4358 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4360 Lily_lexer *lex = parser->lexer_;
4364 int tok = lex->pop_extra_token ();
4367 lex->prepare_for_next_token ();
4368 return lex->yylex ();