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)) {
981 if (to_boolean (od->c_variable ("is-paper")))
982 id = ly_symbol2scm ("$defaultpaper");
983 else if (to_boolean (od->c_variable ("is-midi")))
984 id = ly_symbol2scm ("$defaultmidi");
985 else if (to_boolean (od->c_variable ("is-layout")))
986 id = ly_symbol2scm ("$defaultlayout");
988 parser->lexer_->set_identifier (id, $2);
989 } else if (ly_is_module ($2))
991 ly_module_copy (unsmob<Book> ($1)->header_, $2);
992 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
993 parser->parser_error (@2, _("bad expression type"));
997 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
1000 Book *book = unsmob<Book> ($1);
1002 book->scores_ = SCM_EOL;
1003 book->bookparts_ = SCM_EOL;
1008 BOOKPART '{' bookpart_body '}' {
1010 unsmob<Book> ($$)->origin ()->set_spot (@$);
1011 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
1017 Book *book = new Book;
1018 $$ = book->unprotect ();
1019 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
1022 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
1024 | bookpart_body paper_block {
1025 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
1027 | bookpart_body score_block {
1028 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1029 scm_call_2 (proc, $1, $2);
1031 | bookpart_body composite_music {
1032 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
1033 scm_call_2 (proc, $1, $2);
1035 | bookpart_body full_markup {
1036 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1037 scm_call_2 (proc, $1, scm_list_1 ($2));
1039 | bookpart_body full_markup_list {
1040 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1041 scm_call_2 (proc, $1, $2);
1043 | bookpart_body SCM_TOKEN {
1044 // Evaluate and ignore #xxx, as opposed to \xxx
1045 parser->lexer_->eval_scm_token ($2, @2);
1047 | bookpart_body embedded_scm_active
1049 SCM out = SCM_UNDEFINED;
1050 if (Text_interface::is_markup ($2))
1051 out = scm_list_1 ($2);
1052 else if (Text_interface::is_markup_list ($2))
1054 if (scm_is_pair (out))
1056 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1057 scm_call_2 (proc, $1, out);
1058 } else if (unsmob<Score> ($2))
1060 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1061 scm_call_2 (proc, $1, $2);
1062 } else if (Output_def *od = unsmob<Output_def> ($2)) {
1065 if (to_boolean (od->c_variable ("is-paper")))
1066 id = ly_symbol2scm ("$defaultpaper");
1067 else if (to_boolean (od->c_variable ("is-midi")))
1068 id = ly_symbol2scm ("$defaultmidi");
1069 else if (to_boolean (od->c_variable ("is-layout")))
1070 id = ly_symbol2scm ("$defaultlayout");
1072 parser->lexer_->set_identifier (id, $2);
1073 } else if (ly_is_module ($2)) {
1074 Book *book = unsmob<Book> ($1);
1075 if (!ly_is_module (book->header_))
1076 book->header_ = ly_make_module (false);
1077 ly_module_copy (book->header_, $2);
1078 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1079 parser->parser_error (@2, _("bad expression type"));
1083 Book *book = unsmob<Book> ($1);
1084 if (!ly_is_module (book->header_))
1085 book->header_ = ly_make_module (false);
1086 parser->lexer_->add_scope (book->header_);
1088 | bookpart_body error {
1089 Book *book = unsmob<Book> ($1);
1091 book->scores_ = SCM_EOL;
1096 SCORE '{' score_body '}' {
1097 unsmob<Score> ($3)->origin ()->set_spot (@$);
1104 if (!unsmob<Score> ($1)) {
1105 parser->parser_error (@1, _("Missing music in \\score"));
1106 $$ = (new Score)->unprotect ();
1107 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
1109 unsmob<Score> ($$)->set_header (scm_car ($1));
1112 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1113 scm_is_pair (p); p = scm_cdr (p))
1115 unsmob<Score> ($$)->
1116 add_output_def (unsmob<Output_def> (scm_car (p)));
1120 | score_body error {
1121 unsmob<Score> ($$)->error_found_ = true;
1136 | score_items score_item
1138 Output_def *od = unsmob<Output_def> ($2);
1140 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1142 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1144 $2 = SCM_UNSPECIFIED;
1146 } else if (!unsmob<Score> ($$)) {
1147 if (unsmob<Music> ($2)) {
1148 $2 = Lily::scorify_music ($2);
1150 if (unsmob<Score> ($2))
1153 $2 = SCM_UNSPECIFIED;
1156 Score *score = unsmob<Score> ($$);
1157 if (score && scm_is_pair ($1)) {
1158 if (ly_is_module (scm_car ($1)))
1160 score->set_header (scm_car ($1));
1163 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1164 scm_is_pair (p); p = scm_cdr (p))
1166 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1171 score->add_output_def (od);
1172 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1173 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1175 $$ = scm_cons ($2, $$);
1176 } else if (ly_is_module ($2)) {
1177 SCM module = SCM_UNSPECIFIED;
1179 module = score->get_header ();
1180 if (!ly_is_module (module))
1182 module = ly_make_module (false);
1183 score->set_header (module);
1185 } else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1186 module = scm_car ($$);
1188 module = ly_make_module (false);
1189 $$ = scm_cons (module, $$);
1191 ly_module_copy (module, $2);
1192 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1193 parser->parser_error (@2, _("Spurious expression in \\score"));
1197 if (Score *score = unsmob<Score> ($1)) {
1198 if (!ly_is_module (score->get_header ()))
1199 score->set_header (ly_make_module (false));
1200 parser->lexer_->add_scope (score->get_header ());
1202 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1203 $1 = scm_cons (ly_make_module (false), $1);
1204 parser->lexer_->add_scope (scm_car ($1));
1219 Output_def *od = unsmob<Output_def> ($1);
1221 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1223 parser->parser_error (@1, _ ("need \\paper for paper block"));
1224 $$ = get_paper (parser)->unprotect ();
1231 output_def_body '}' {
1232 if (scm_is_pair ($1))
1235 parser->lexer_->remove_scope ();
1236 parser->lexer_->pop_state ();
1242 Output_def *p = get_paper (parser);
1243 p->input_origin_ = @$;
1244 parser->lexer_->add_scope (p->scope_);
1245 $$ = p->unprotect ();
1248 Output_def *p = get_midi (parser);
1249 $$ = p->unprotect ();
1250 parser->lexer_->add_scope (p->scope_);
1253 Output_def *p = get_layout (parser);
1255 parser->lexer_->add_scope (p->scope_);
1256 $$ = p->unprotect ();
1260 output_def_head_with_mode_switch:
1262 parser->lexer_->push_initial_state ();
1267 // We need this weird nonterminal because both music as well as a
1268 // context definition can start with \context and the difference is
1269 // only apparent after looking at the next token. If it is '{', there
1270 // is still time to escape from notes mode.
1272 music_or_context_def:
1274 | context_def_spec_block
1278 output_def_head_with_mode_switch '{' {
1279 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1280 // This is a stupid trick to mark the beginning of the
1281 // body for deciding whether to allow
1282 // embedded_scm_active to have an output definition
1283 $$ = scm_list_1 ($1);
1285 | output_def_body assignment {
1286 if (scm_is_pair ($1))
1289 | output_def_body embedded_scm_active
1291 // We don't switch into note mode for Scheme functions
1292 // here. Does not seem warranted/required in output
1294 if (scm_is_pair ($1))
1296 Output_def *o = unsmob<Output_def> ($2);
1298 o->input_origin_.set_spot (@$);
1299 $1 = o->self_scm ();
1300 parser->lexer_->remove_scope ();
1301 parser->lexer_->add_scope (o->scope_);
1302 $2 = SCM_UNSPECIFIED;
1306 if (unsmob<Context_def> ($2))
1307 assign_context_def (unsmob<Output_def> ($1), $2);
1308 // Seems unlikely, but let's be complete:
1309 else if (unsmob<Music> ($2))
1311 SCM proc = parser->lexer_->lookup_identifier
1312 ("output-def-music-handler");
1313 scm_call_2 (proc, $1, $2);
1314 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1315 parser->parser_error (@2, _("bad expression type"));
1318 | output_def_body SCM_TOKEN {
1319 if (scm_is_pair ($1))
1321 // Evaluate and ignore #xxx, as opposed to \xxx
1322 parser->lexer_->eval_scm_token ($2, @2);
1326 if (scm_is_pair ($1))
1328 parser->lexer_->push_note_state (Lily::pitchnames);
1329 } music_or_context_def
1331 parser->lexer_->pop_state ();
1332 if (unsmob<Context_def> ($3))
1333 assign_context_def (unsmob<Output_def> ($1), $3);
1336 SCM proc = parser->lexer_->lookup_identifier
1337 ("output-def-music-handler");
1338 scm_call_2 (proc, $1, $3);
1342 | output_def_body error {
1348 TEMPO steno_duration '=' tempo_range {
1349 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1351 | TEMPO text steno_duration '=' tempo_range {
1352 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1355 $$ = MAKE_SYNTAX (tempo, @$, $2);
1360 The representation of a list is reversed to have efficient append. */
1366 | music_list music_embedded {
1367 if (unsmob<Music> ($2))
1368 $$ = scm_cons ($2, $1);
1370 | music_list error {
1371 Music *m = MY_MAKE_MUSIC("Music", @$);
1373 m->set_property ("error-found", SCM_BOOL_T);
1374 $$ = scm_cons (m->self_scm (), $1);
1375 m->unprotect (); /* UGH */
1382 $$ = scm_reverse_x ($2, SCM_EOL);
1387 | lyric_element_music
1394 $$ = make_music_from_simple (parser, @1, $1);
1395 if (!unsmob<Music> ($$))
1397 parser->parser_error (@1, _ ("music expected"));
1398 $$ = MAKE_SYNTAX (void_music, @$);
1406 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1407 parser->parser_error (@1, _ ("unexpected post-event"));
1408 $$ = SCM_UNSPECIFIED;
1411 | music_embedded_backup
1415 | music_embedded_backup BACKUP lyric_element_music
1419 | multiplied_duration post_events
1421 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1423 parser->default_duration_ = *unsmob<Duration> ($1);
1424 n->set_property ("duration", $1);
1426 if (scm_is_pair ($2))
1427 n->set_property ("articulations",
1428 scm_reverse_x ($2, SCM_EOL));
1429 $$ = n->unprotect ();
1433 music_embedded_backup:
1436 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1438 else if (Music *m = unsmob<Music> ($1)) {
1439 if (m->is_mus_type ("post-event")) {
1440 parser->parser_error
1441 (@1, _ ("unexpected post-event"));
1442 $$ = SCM_UNSPECIFIED;
1445 } else if (parser->lexer_->is_lyric_state ()
1446 && Text_interface::is_markup ($1))
1447 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1449 @$.warning (_ ("Ignoring non-music expression"));
1455 // music_assign does not need to contain lyrics: there are no
1456 // assignments in lyricmode.
1459 | composite_music %prec COMPOSITE
1463 REPEAT simple_string unsigned_number music
1465 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1467 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1469 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1474 SEQUENTIAL braced_music_list {
1475 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1477 | braced_music_list {
1478 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1483 SIMULTANEOUS braced_music_list {
1484 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1486 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1487 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1493 | music_property_def
1497 context_modification:
1500 parser->lexer_->push_note_state (Lily::pitchnames);
1501 } '{' context_mod_list '}'
1503 parser->lexer_->pop_state ();
1506 | WITH CONTEXT_MOD_IDENTIFIER
1510 | CONTEXT_MOD_IDENTIFIER
1514 | WITH context_modification_arg
1516 if (unsmob<Music> ($2)) {
1517 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1518 $2 = scm_call_1 (proc, $2);
1520 if (unsmob<Context_mod> ($2))
1523 parser->parser_error (@2, _ ("not a context mod"));
1524 $$ = Context_mod ().smobbed_copy ();
1529 context_modification_arg:
1534 /* A list of single mods collected from a (possibly empty) sequence of
1535 * context modifications, usually written as \with ... \with ...
1538 optional_context_mods:
1539 context_modification_mods_list
1541 if (scm_is_pair ($1))
1542 $$ = scm_append_x (scm_reverse_x ($1, SCM_EOL));
1546 /* The worker for optional_context_mods conses a (reversed) list where
1547 * each element contains the list of single context mods from one
1548 * context modification block. Context_mod::get_mods creates fresh
1549 * copies, so it's okay to use append! on them.
1552 context_modification_mods_list:
1556 | context_modification_mods_list context_modification
1558 if (Context_mod *m = unsmob<Context_mod> ($2))
1559 $$ = scm_cons (m->get_mods (), $1);
1563 /* A Context_mod is a container for a list of context mods like
1564 * \consists ... \override ... . context_mod_list produces a
1565 * Context_mod from the inside of a \with { ... } statement.
1570 $$ = Context_mod ().smobbed_copy ();
1572 | context_mod_list context_mod {
1573 if (!SCM_UNBNDP ($2))
1574 unsmob<Context_mod> ($1)->add_context_mod ($2);
1576 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1577 Context_mod *md = unsmob<Context_mod> ($2);
1579 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1581 | context_mod_list context_mod_arg {
1582 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1584 else if (unsmob<Music> ($2)) {
1585 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1586 $2 = scm_call_1 (proc, $2);
1588 if (unsmob<Context_mod> ($2))
1589 unsmob<Context_mod> ($$)->add_context_mods
1590 (unsmob<Context_mod> ($2)->get_mods ());
1592 parser->parser_error (@2, _ ("not a context mod"));
1598 CONTEXT symbol optional_id optional_context_mods {
1599 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_F);
1601 | NEWCONTEXT symbol optional_id optional_context_mods {
1602 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_T);
1607 ADDLYRICS optional_context_mods lyric_mode_music {
1608 $$ = scm_acons ($3, $2, SCM_EOL);
1610 | new_lyrics ADDLYRICS optional_context_mods lyric_mode_music {
1611 $$ = scm_acons ($4, $3, $1);
1615 /* basic_music is basically the same as composite_music but with
1616 * context-prefixed music and lyricized music explicitly removed. The
1617 * reason is that in a sequence
1619 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1621 * we need to group both \addlyrics together (as they go with the same
1622 * voice) but then combine them with \new Voice { ... }, meaning that
1623 * combining \new Voice { ... } needs higher priority than
1624 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1625 * combine before combining \new Voice { ... } \addlyrics: only one
1626 * layer of context-prefixed music should assemble before \addlyrics
1627 * is integrated. Total mess, and we sort this mess out with explicit
1628 * rules preferring a single context-prefix.
1635 | LYRICSTO simple_string lyric_mode_music {
1636 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1638 | LYRICSTO symbol '=' simple_string lyric_mode_music
1640 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1650 contexted_basic_music:
1651 context_prefix contextable_music new_lyrics
1654 i.set_location (@1, @2);
1655 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1656 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1658 | context_prefix contextable_music
1660 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1662 | context_prefix contexted_basic_music
1664 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1669 basic_music %prec COMPOSITE
1670 | contexted_basic_music
1671 | basic_music new_lyrics
1673 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1680 | grouped_music_list
1684 simultaneous_music { $$ = $1; }
1685 | sequential_music { $$ = $1; }
1688 /* Function argument lists are arguably the most complex part in the
1689 * parser. They are pretty tricky to understand because of the way
1690 * they are processed, and because of optional arguments that can be
1691 * omitted. When there are several optional arguments in a row,
1692 * omitting one automatically omits all following arguments. Optional
1693 * arguments can only be omitted when either
1695 * a) the omission is explicitly started with \default
1696 * b) the omission is implicitly started by an argument not matching
1697 * its predicate, and there is a mandatory argument later that can
1698 * "catch" the argument that does not fit.
1700 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1701 * (corresponding to mandatory arguments and having a predicate
1702 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1703 * the semantic value of the EXPECT_OPTIONAL token is the default to
1704 * use when the optional argument is omitted, and EXPECT_SCM again has
1705 * the argument predicate as semantic value) in reverse order to the
1706 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1707 * processed inside-out while actual tokens are consumed.
1709 * This means that the argument list tokens determine the actions
1710 * taken as they arrive. The structure of the argument list is known
1711 * to the parser and stored in its parse stack when the first argument
1712 * is being parsed. What the parser does not know is which predicates
1713 * will match and whether or not \default will be appearing in the
1714 * argument list, and where.
1716 * Sequences of 0 or more optional arguments are scanned using either
1717 * function_arglist_backup or function_arglist_nonbackup. The first
1718 * is used when optional arguments are followed by at least one
1719 * mandatory argument: in that case optional arguments may be skipped
1720 * by either a false predicate (in which case the expression will be
1721 * pushed back as one or more tokens, preceded by a BACKUP token) or
1722 * by using \default.
1724 * If optional arguments are at the end of the argument list, they are
1725 * instead scanned using function_arglist_nonbackup: here the only
1726 * manner to enter into skipping of optional arguments is the use of
1729 * The argument list of a normal function call is parsed using
1730 * function_arglist. The part of an argument list before a mandatory
1731 * argument is parsed using function_arglist_optional.
1733 * The difference is that leading optional arguments are scanned using
1734 * function_arglist_nonbackup and function_arglist_backup,
1737 * Most other details are obvious in the rules themselves.
1743 | SYMBOL_LIST '.' symbol_list_rev
1745 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1747 | SYMBOL_LIST ',' symbol_list_rev
1749 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1755 | symbol_list_rev '.' symbol_list_part
1757 $$ = scm_append_x (scm_list_2 ($3, $1));
1759 | symbol_list_rev ',' symbol_list_part
1761 $$ = scm_append_x (scm_list_2 ($3, $1));
1765 // symbol_list_part delivers elements in reverse copy.
1770 $$ = try_string_variants (Lily::key_list_p, $1);
1771 if (SCM_UNBNDP ($$)) {
1772 parser->parser_error (@1, _("not a key"));
1775 $$ = scm_reverse ($$);
1780 symbol_list_element:
1786 symbol_list_part_bare:
1789 $$ = try_string_variants (Lily::key_list_p, $1);
1790 if (SCM_UNBNDP ($$)) {
1791 parser->parser_error (@1, _("not a key"));
1794 $$ = scm_reverse ($$);
1798 $$ = scm_list_1 ($1);
1802 function_arglist_nonbackup:
1803 function_arglist_common
1804 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1806 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1808 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1810 SCM n = scm_difference ($5, SCM_UNDEFINED);
1811 if (scm_is_true (scm_call_1 ($2, n)))
1812 $$ = scm_cons (n, $3);
1814 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1815 t->set_property ("digit", $5);
1816 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1820 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1822 $$ = check_scheme_arg (parser, @4,
1823 scm_difference ($5, SCM_UNDEFINED),
1826 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1828 $$ = check_scheme_arg (parser, @4,
1829 scm_difference ($5, SCM_UNDEFINED),
1832 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1834 if (scm_is_true (scm_call_1 ($2, $4)))
1835 $$ = scm_cons ($4, $3);
1837 $$ = check_scheme_arg (parser, @4,
1838 make_music_from_simple
1842 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1844 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1846 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1848 if (scm_is_true (scm_call_1 ($2, $3)))
1849 $$ = scm_cons ($3, $1);
1851 $$ = check_scheme_arg (parser, @3,
1852 make_music_from_simple
1856 | function_arglist_nonbackup_reparse REPARSE multiplied_duration
1858 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1860 | function_arglist_nonbackup_reparse REPARSE reparsed_rhythm
1862 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1864 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1866 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1868 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1870 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1872 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1874 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1876 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1878 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1884 DURATION_ARG dots multipliers post_events
1886 $$ = make_music_from_simple (parser, @$,
1887 make_duration ($1, scm_to_int ($2), $3));
1888 Music *m = unsmob<Music> ($$);
1890 if (scm_is_pair ($4))
1891 m->set_property ("articulations",
1892 scm_reverse_x ($4, SCM_EOL));
1896 function_arglist_nonbackup_reparse:
1897 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1900 SCM res = try_string_variants ($2, $4);
1901 if (!SCM_UNBNDP (res))
1902 if (scm_is_pair (res))
1903 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1905 MYREPARSE (@4, $2, SCM_ARG, res);
1906 else if (scm_is_true
1908 ($2, make_music_from_simple
1910 MYREPARSE (@4, $2, STRING, $4);
1912 MYREPARSE (@4, $2, SCM_ARG, $4);
1914 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1919 ($2, make_music_from_simple
1921 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1923 MYREPARSE (@4, $2, SCM_ARG, $4);
1925 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1930 ($2, make_music_from_simple
1932 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1934 MYREPARSE (@4, $2, SCM_ARG, $4);
1936 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1939 SCM res = try_string_variants ($2, $4);
1940 if (!SCM_UNBNDP (res))
1941 if (scm_is_pair (res))
1942 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1944 MYREPARSE (@4, $2, SCM_ARG, res);
1945 else if (scm_is_true
1947 ($2, make_music_from_simple
1949 MYREPARSE (@4, $2, STRING, $4);
1951 MYREPARSE (@4, $2, SCM_ARG, $4);
1953 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1956 if (scm_is_true (scm_call_1 ($2, $4)))
1957 MYREPARSE (@4, $2, SCM_ARG, $4);
1958 else if (scm_is_true
1960 ($2, make_music_from_simple
1962 MYREPARSE (@4, $2, STRING, $4);
1964 MYREPARSE (@4, $2, SCM_ARG, $4);
1966 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1969 if (scm_is_true (scm_call_1 ($2, $4)))
1970 // May be 3 \cm or similar
1971 MYREPARSE (@4, $2, REAL, $4);
1972 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
1973 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
1975 SCM d = make_duration ($4);
1976 if (!SCM_UNBNDP (d)) {
1977 if (scm_is_true (scm_call_1 ($2, d)))
1978 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1979 else if (scm_is_true
1981 ($2, make_music_from_simple (parser, @4, d))))
1982 MYREPARSE (@4, $2, DURATION_ARG, d);
1984 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1986 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1989 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER
1992 if (scm_is_true (scm_call_1 ($2, $4)))
1993 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1994 else if (scm_is_true
1996 ($2, make_music_from_simple (parser, @4, $4))))
1997 MYREPARSE (@4, $2, DURATION_ARG, $4);
1999 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
2004 // function_arglist_backup can't occur at the end of an argument
2006 function_arglist_backup:
2007 function_arglist_common
2008 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
2010 if (scm_is_true (scm_call_1 ($2, $4)))
2011 $$ = scm_cons ($4, $3);
2013 $$ = make_music_from_simple (parser, @4, $4);
2014 if (scm_is_true (scm_call_1 ($2, $$)))
2015 $$ = scm_cons ($$, $3);
2018 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2019 MYBACKUP (SCM_ARG, $4, @4);
2023 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
2025 if (scm_is_true (scm_call_1 ($2, $4)))
2027 $$ = scm_cons ($4, $3);
2029 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2030 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
2033 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
2037 ($2, make_music_from_simple
2041 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
2042 } else if (scm_is_true (scm_call_1 ($2, $4)))
2043 $$ = scm_cons ($4, $3);
2045 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2046 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
2049 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
2053 ($2, make_music_from_simple
2057 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
2058 } else 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 (TONICNAME_PITCH, $4, @4);
2065 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
2067 if (scm_is_true (scm_call_1 ($2, $4)))
2068 $$ = scm_cons ($4, $3);
2070 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2071 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2074 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
2077 if (scm_is_true (scm_call_1 ($2, $4)))
2078 // May be 3 \cm or similar
2079 MYREPARSE (@4, $2, REAL, $4);
2080 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
2081 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
2083 SCM d = make_duration ($4);
2084 if (!SCM_UNBNDP (d)) {
2085 if (scm_is_true (scm_call_1 ($2, d)))
2086 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
2087 else if (scm_is_true
2089 ($2, make_music_from_simple (parser, @4, d))))
2090 MYREPARSE (@4, $2, DURATION_ARG, d);
2092 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2093 MYBACKUP (UNSIGNED, $4, @4);
2096 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2097 MYBACKUP (UNSIGNED, $4, @4);
2101 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
2103 if (scm_is_true (scm_call_1 ($2, $4)))
2106 MYREPARSE (@4, $2, REAL, $4);
2108 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2109 MYBACKUP (REAL, $4, @4);
2112 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
2114 if (scm_is_true (scm_call_1 ($2, $4)))
2116 $$ = scm_cons ($4, $3);
2118 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2119 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
2122 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
2124 SCM n = scm_difference ($5, SCM_UNDEFINED);
2125 if (scm_is_true (scm_call_1 ($2, n))) {
2127 MYREPARSE (@5, $2, REAL, n);
2129 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
2130 t->set_property ("digit", $5);
2131 $$ = t->unprotect ();
2132 if (scm_is_true (scm_call_1 ($2, $$)))
2133 $$ = scm_cons ($$, $3);
2135 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2136 MYBACKUP (UNSIGNED, $5, @5);
2137 parser->lexer_->push_extra_token (@4, '-');
2141 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2143 SCM n = scm_difference ($5, SCM_UNDEFINED);
2144 if (scm_is_true (scm_call_1 ($2, n))) {
2145 MYREPARSE (@5, $2, REAL, n);
2148 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2149 MYBACKUP (REAL, n, @5);
2152 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2154 SCM n = scm_difference ($5, SCM_UNDEFINED);
2155 if (scm_is_true (scm_call_1 ($2, n))) {
2156 $$ = scm_cons (n, $3);
2158 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2159 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2162 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2165 if (scm_is_true (scm_call_1 ($2, $4)))
2166 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2167 else if (scm_is_true
2169 ($2, make_music_from_simple (parser, @4, $4))))
2170 MYREPARSE (@4, $2, DURATION_ARG, $4);
2172 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2173 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2176 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2178 SCM res = try_string_variants ($2, $4);
2179 if (!SCM_UNBNDP (res))
2180 if (scm_is_pair (res)) {
2182 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2185 $$ = scm_cons (res, $3);
2187 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2188 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2191 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2193 SCM res = try_string_variants ($2, $4);
2194 if (!SCM_UNBNDP (res))
2195 if (scm_is_pair (res)) {
2197 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2200 $$ = scm_cons (res, $3);
2202 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2203 MYBACKUP (STRING, $4, @4);
2206 | function_arglist_backup REPARSE pitch_or_music
2208 if (scm_is_true (scm_call_1 ($2, $3)))
2209 $$ = scm_cons ($3, $1);
2211 $$ = check_scheme_arg (parser, @3,
2212 make_music_from_simple
2216 | function_arglist_backup REPARSE bare_number_common
2218 $$ = check_scheme_arg (parser, @3,
2221 | function_arglist_backup REPARSE multiplied_duration
2223 $$ = check_scheme_arg (parser, @3,
2226 | function_arglist_backup REPARSE reparsed_rhythm
2228 $$ = check_scheme_arg (parser, @3,
2231 | function_arglist_backup REPARSE symbol_list_arg
2233 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2238 function_arglist_nonbackup
2239 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2241 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2245 function_arglist_skip_nonbackup:
2246 function_arglist_nonbackup
2247 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2249 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2253 // Partial function arglists are returned just in their incomplete
2254 // state: when combined with the music function, the missing parts of
2255 // the signature can be reconstructed
2257 // To serve as a partial arglist, the argument list must absolutely
2258 // _not_ be in "skipping optional arguments" mode since then there is
2259 // some backup token that has nowhere to go before \etc.
2261 // So we can skim off an arbitrary number of arguments from the end of
2262 // the argument list. The argument list remaining afterwards has to
2263 // be in not-skipping-optional-arguments mode.
2265 function_arglist_partial:
2266 EXPECT_SCM function_arglist_optional
2270 | EXPECT_SCM function_arglist_partial_optional
2274 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2278 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2284 function_arglist_partial_optional:
2285 EXPECT_SCM function_arglist_optional
2289 | EXPECT_SCM function_arglist_partial_optional
2293 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2297 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2303 function_arglist_common:
2304 EXPECT_NO_MORE_ARGS {
2307 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2309 if (scm_is_true (scm_call_1 ($1, $3)))
2310 $$ = scm_cons ($3, $2);
2312 $$ = check_scheme_arg (parser, @3,
2313 make_music_from_simple
2317 | EXPECT_SCM function_arglist_optional bare_number_common
2319 $$ = check_scheme_arg (parser, @3,
2322 | EXPECT_SCM function_arglist_optional post_event_nofinger
2324 $$ = check_scheme_arg (parser, @3,
2327 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2329 SCM n = scm_difference ($4, SCM_UNDEFINED);
2330 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2332 | function_arglist_common_reparse REPARSE SCM_ARG
2334 $$ = check_scheme_arg (parser, @3,
2337 | function_arglist_common_reparse REPARSE lyric_element_music
2339 $$ = check_scheme_arg (parser, @3,
2342 | function_arglist_common_reparse REPARSE pitch_or_music
2344 if (scm_is_true (scm_call_1 ($2, $3)))
2345 $$ = scm_cons ($3, $1);
2347 $$ = check_scheme_arg (parser, @3,
2348 make_music_from_simple
2352 | function_arglist_common_reparse REPARSE bare_number_common
2354 $$ = check_scheme_arg (parser, @3,
2357 | function_arglist_common_reparse REPARSE multiplied_duration
2359 $$ = check_scheme_arg (parser, @3,
2362 | function_arglist_common_reparse REPARSE reparsed_rhythm
2364 $$ = check_scheme_arg (parser, @3,
2367 | function_arglist_common_reparse REPARSE symbol_list_arg
2369 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2373 function_arglist_common_reparse:
2374 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2377 SCM res = try_string_variants ($1, $3);
2378 if (!SCM_UNBNDP (res))
2379 if (scm_is_pair (res))
2380 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2382 MYREPARSE (@3, $1, SCM_ARG, res);
2383 else if (scm_is_true
2385 ($1, make_music_from_simple (parser, @3, $3))))
2386 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2388 // This is going to flag a syntax error, we
2389 // know the predicate to be false.
2390 MYREPARSE (@3, $1, SCM_ARG, $3);
2392 | EXPECT_SCM function_arglist_optional pitch
2397 ($1, make_music_from_simple
2399 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2401 MYREPARSE (@3, $1, SCM_ARG, $3);
2403 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2408 ($1, make_music_from_simple
2410 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2412 MYREPARSE (@3, $1, SCM_ARG, $3);
2414 | EXPECT_SCM function_arglist_optional STRING
2417 SCM res = try_string_variants ($1, $3);
2418 if (!SCM_UNBNDP (res))
2419 if (scm_is_pair (res))
2420 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2422 MYREPARSE (@3, $1, SCM_ARG, res);
2423 else if (scm_is_true
2425 ($1, make_music_from_simple (parser, @3, $3))))
2426 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2428 // This is going to flag a syntax error, we
2429 // know the predicate to be false.
2430 MYREPARSE (@3, $1, SCM_ARG, $3);
2432 | EXPECT_SCM function_arglist_optional full_markup
2435 if (scm_is_true (scm_call_1 ($1, $3)))
2436 MYREPARSE (@3, $1, SCM_ARG, $3);
2437 else if (scm_is_true
2439 ($1, make_music_from_simple (parser, @3, $3))))
2440 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2442 // This is going to flag a syntax error, we
2443 // know the predicate to be false.
2444 MYREPARSE (@3, $1, SCM_ARG, $3);
2446 | EXPECT_SCM function_arglist_optional UNSIGNED
2449 if (scm_is_true (scm_call_1 ($1, $3)))
2450 // May be 3 \cm or similar
2451 MYREPARSE (@3, $1, REAL, $3);
2452 else if (scm_is_true (scm_call_1 ($1, scm_list_1 ($3))))
2453 MYREPARSE (@3, $1, SYMBOL_LIST, scm_list_1 ($3));
2455 SCM d = make_duration ($3);
2456 if (!SCM_UNBNDP (d)) {
2457 if (scm_is_true (scm_call_1 ($1, d)))
2458 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2459 else if (scm_is_true
2461 ($1, make_music_from_simple (parser, @3, d))))
2462 MYREPARSE (@3, $1, DURATION_ARG, d);
2464 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2466 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2469 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2472 if (scm_is_true (scm_call_1 ($1, $3)))
2473 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2474 else if (scm_is_true
2476 ($1, make_music_from_simple (parser, @3, $3))))
2477 MYREPARSE (@3, $1, DURATION_ARG, $3);
2479 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2481 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2484 SCM n = scm_difference ($4, SCM_UNDEFINED);
2485 if (scm_is_true (scm_call_1 ($1, n)))
2486 MYREPARSE (@4, $1, REAL, n);
2488 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2489 t->set_property ("digit", $4);
2490 SCM m = t->unprotect ();
2491 if (scm_is_true (scm_call_1 ($1, m)))
2492 MYREPARSE (@4, $1, SCM_ARG, m);
2494 MYREPARSE (@4, $1, SCM_ARG, $4);
2497 | EXPECT_SCM function_arglist_optional '-' REAL
2500 SCM n = scm_difference ($4, SCM_UNDEFINED);
2501 MYREPARSE (@4, $1, REAL, n);
2505 function_arglist_optional:
2506 function_arglist_backup
2507 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2509 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2511 | function_arglist_skip_backup BACKUP
2514 function_arglist_skip_backup:
2515 function_arglist_backup
2516 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2518 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2522 music_function_call:
2523 MUSIC_FUNCTION function_arglist {
2524 $$ = MAKE_SYNTAX (music_function, @$,
2531 /**/ { $$ = SCM_EOL; }
2532 | '=' simple_string {
2537 // We must not have lookahead tokens parsed in lyric mode. In order
2538 // to save confusion, we take almost the same set as permitted with
2539 // \lyricmode and/or \lyrics. However, music identifiers are also
2540 // allowed, and they obviously do not require switching into lyrics
2541 // mode for parsing.
2545 parser->lexer_->push_lyric_state ();
2546 } grouped_music_list
2548 parser->lexer_->pop_state ();
2555 mode_changing_head grouped_music_list {
2556 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2558 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2564 parser->lexer_->pop_state ();
2566 | mode_changing_head_with_context optional_context_mods grouped_music_list {
2567 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, $2, SCM_BOOL_T, $3);
2568 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2570 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2572 parser->lexer_->pop_state ();
2578 parser->lexer_->push_note_state (Lily::pitchnames);
2580 $$ = ly_symbol2scm ("notes");
2584 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2586 $$ = ly_symbol2scm ("drums");
2589 parser->lexer_->push_figuredbass_state ();
2591 $$ = ly_symbol2scm ("figures");
2594 parser->lexer_->chordmodifier_tab_ =
2595 alist_to_hashq (Lily::chordmodifiers);
2596 parser->lexer_->push_chord_state (Lily::pitchnames);
2597 $$ = ly_symbol2scm ("chords");
2601 { parser->lexer_->push_lyric_state ();
2602 $$ = ly_symbol2scm ("lyrics");
2606 mode_changing_head_with_context:
2608 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2610 $$ = ly_symbol2scm ("DrumStaff");
2613 parser->lexer_->push_figuredbass_state ();
2615 $$ = ly_symbol2scm ("FiguredBass");
2618 parser->lexer_->chordmodifier_tab_ =
2619 alist_to_hashq (Lily::chordmodifiers);
2620 parser->lexer_->push_chord_state (Lily::pitchnames);
2621 $$ = ly_symbol2scm ("ChordNames");
2624 { parser->lexer_->push_lyric_state ();
2625 $$ = ly_symbol2scm ("Lyrics");
2630 CHANGE symbol '=' simple_string {
2631 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2638 $$ = scm_reverse_x ($1, SCM_EOL);
2644 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2647 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2649 | OVERRIDE revert_arg '=' scalar {
2650 if (scm_ilength ($2) < 2) {
2651 parser->parser_error (@2, _("bad grob property path"));
2654 $$ = scm_cons (ly_symbol2scm ("push"),
2655 scm_cons2 (scm_car ($2),
2660 | REVERT revert_arg {
2661 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2665 // This is all quite awkward for the sake of substantial backward
2666 // compatibility while at the same time allowing a more "natural" form
2667 // of specification not separating grob specification from grob
2668 // property path. The purpose of this definition of revert_arg is to
2669 // allow the symbol list which specifies grob and property to revert
2670 // to be optionally be split into two parts after the grob (which in
2671 // this case is just the first element of the list). symbol_list_part
2672 // is only one path component, but it can be parsed without lookahead,
2673 // so we can follow it with a synthetic BACKUP token when needed. If
2674 // the first symbol_list_part already contains multiple elements (only
2675 // possible if a Scheme expression provides them), we just parse for
2676 // additional elements introduced by '.', which is what the
2677 // SYMBOL_LIST backup in connection with the immediately following
2678 // rule using symbol_list_arg does.
2680 // As long as we don't have our coffers filled with both grob and at
2681 // least one grob property specification, the rest of the required
2682 // symbol list chain may be provided either with or without a leading
2683 // dot. This is for both allowing the traditional
2684 // \revert Accidental #'color
2685 // as well as well as the "naive" form
2686 // \revert Accidental.color
2689 revert_arg_backup BACKUP symbol_list_arg
2698 if (scm_is_null ($1)
2699 || scm_is_null (scm_cdr ($1)))
2700 MYBACKUP (SCM_ARG, $1, @1);
2702 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2706 // revert_arg_part delivers results in reverse
2709 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2711 $$ = scm_append_x (scm_list_2 ($5, $3));
2713 | revert_arg_backup BACKUP SCM_ARG ',' symbol_list_part
2715 $$ = scm_append_x (scm_list_2 ($5, $3));
2717 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2719 $$ = scm_append_x (scm_list_2 ($4, $3));
2724 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2725 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2727 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2728 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2729 | DENIES { $$ = ly_symbol2scm ("denies"); }
2731 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2732 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2733 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2734 | NAME { $$ = ly_symbol2scm ("context-name"); }
2738 property_operation { $$ = $1; }
2739 | context_def_mod STRING {
2740 $$ = scm_list_2 ($1, $2);
2742 | context_def_mod embedded_scm
2744 if (!scm_is_string ($2)
2745 && ly_symbol2scm ("consists") != $1
2746 && ly_symbol2scm ("remove") != $1)
2749 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2753 $$ = scm_list_2 ($1, $2);
2758 // If defined, at least two members.
2762 SCM l = scm_reverse_x ($1, SCM_EOL);
2765 (scm_object_property (scm_car (l),
2766 ly_symbol2scm ("is-grob?"))))
2767 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2768 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2769 parser->parser_error (@1, _ ("bad grob property path"));
2776 // If defined, at least three members
2780 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2782 parser->parser_error (@1, _ ("bad grob property path"));
2786 | grob_prop_spec property_path
2788 if (!SCM_UNBNDP ($1)) {
2789 $$ = scm_append_x (scm_list_2 ($1, $2));
2790 if (scm_is_null (scm_cddr ($$))) {
2791 parser->parser_error (@$, _ ("bad grob property path"));
2799 // Exactly two elements or undefined
2803 SCM l = scm_reverse_x ($1, SCM_EOL);
2804 switch (scm_ilength (l)) {
2806 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2810 parser->parser_error (@1, _ ("bad context property path"));
2818 // This is all quite awkward for the sake of substantial backward
2819 // compatibility while at the same time allowing a more "natural" form
2820 // of specification not separating grob specification from grob
2821 // property path. The purpose of this definition of
2822 // simple_revert_context is to allow the symbol list which specifies
2823 // grob and property to revert to be optionally be split into two
2824 // parts after the grob (which may be preceded by a context
2825 // specification, a case which we distinguish by checking whether the
2826 // first symbol is a valid grob symbol instead).
2828 // See revert_arg above for the main work horse of this arrangement.
2829 // simple_revert_context just caters for the context and delegates the
2830 // rest of the job to revert_arg.
2832 simple_revert_context:
2835 $1 = scm_reverse_x ($1, SCM_EOL);
2836 if (scm_is_null ($1)
2838 (scm_object_property (scm_car ($1),
2839 ly_symbol2scm ("is-grob?")))) {
2840 $$ = ly_symbol2scm ("Bottom");
2841 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2844 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2851 OVERRIDE grob_prop_path '=' scalar {
2852 if (SCM_UNBNDP ($2))
2853 $$ = MAKE_SYNTAX (void_music, @$);
2855 $$ = MAKE_SYNTAX (property_override, @$,
2860 | REVERT simple_revert_context revert_arg {
2861 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2863 | SET context_prop_spec '=' scalar {
2864 if (SCM_UNBNDP ($2))
2865 $$ = MAKE_SYNTAX (void_music, @$);
2867 $$ = MAKE_SYNTAX (property_set, @$,
2872 | UNSET context_prop_spec {
2873 if (SCM_UNBNDP ($2))
2874 $$ = MAKE_SYNTAX (void_music, @$);
2876 $$ = MAKE_SYNTAX (property_unset, @$,
2892 if (Text_interface::is_markup ($1)) {
2895 parser->parser_error (@1, (_ ("markup expected")));
2896 $$ = scm_string (SCM_EOL);
2901 simple_string: STRING
2904 if (scm_is_string ($1)) {
2907 parser->parser_error (@1, (_ ("simple string expected")));
2908 $$ = scm_string (SCM_EOL);
2915 $$ = scm_string_to_symbol ($1);
2919 // This is a bit of overkill but makes the same
2920 // routine responsible for all symbol interpretations.
2921 $$ = try_string_variants (Guile_user::symbol_p, $1);
2922 if (SCM_UNBNDP ($$))
2924 parser->parser_error (@1, (_ ("symbol expected")));
2925 // Generate a unique symbol in case it is used
2926 // for an assignment or similar
2927 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2937 // The following is a rather defensive variant of admitting
2938 // negative numbers: the grammar would permit number_factor or
2939 // even number_expression. However, function arguments allow
2940 // only this simple kind of negative number, so to have things
2941 // like \tweak and \override behave reasonably similar, it
2942 // makes sense to rule out things like -- which are rather an
2943 // accent in function argument contexts.
2946 $$ = scm_difference ($2, SCM_UNDEFINED);
2949 | symbol_list_part_bare '.' property_path
2951 $$ = scm_reverse_x ($1, $3);
2953 | symbol_list_part_bare ',' property_path
2955 $$ = scm_reverse_x ($1, $3);
2960 simple_element post_events {
2961 // Let the rhythmic music iterator sort this mess out.
2962 if (scm_is_pair ($2)) {
2963 unsmob<Music> ($$)->set_property ("articulations",
2964 scm_reverse_x ($2, SCM_EOL));
2967 | CHORD_REPETITION optional_notemode_duration post_events {
2969 i.set_location (@1, @3);
2970 $$ = MAKE_SYNTAX (repetition_chord, i,
2971 $2, scm_reverse_x ($3, SCM_EOL));
2973 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2975 i.set_location (@1, @3);
2976 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2977 scm_reverse_x ($3, SCM_EOL));
2980 | note_chord_element
2985 chord_body optional_notemode_duration post_events
2987 Music *m = unsmob<Music> ($1);
2988 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2989 SCM es = m->get_property ("elements");
2990 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2992 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2993 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2994 es = ly_append2 (es, postevs);
2996 m->set_property ("elements", es);
2997 m->set_spot (parser->lexer_->override_input (@$));
2998 $$ = m->self_scm ();
3003 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
3005 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
3007 | FIGURE_OPEN figure_list FIGURE_CLOSE
3009 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
3013 chord_body_elements:
3014 /* empty */ { $$ = SCM_EOL; }
3015 | chord_body_elements chord_body_element {
3016 if (!SCM_UNBNDP ($2))
3017 $$ = scm_cons ($2, $1);
3022 pitch_or_tonic_pitch exclamations questions octave_check post_events
3024 bool q = to_boolean ($3);
3025 bool ex = to_boolean ($2);
3029 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3030 n->set_property ("pitch", $1);
3032 n->set_property ("cautionary", SCM_BOOL_T);
3034 n->set_property ("force-accidental", SCM_BOOL_T);
3036 if (scm_is_pair (post)) {
3037 SCM arts = scm_reverse_x (post, SCM_EOL);
3038 n->set_property ("articulations", arts);
3040 if (scm_is_number (check))
3042 int q = scm_to_int (check);
3043 n->set_property ("absolute-octave", scm_from_int (q-1));
3046 $$ = n->unprotect ();
3048 | DRUM_PITCH post_events {
3049 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3050 n->set_property ("drum-type", $1);
3052 if (scm_is_pair ($2)) {
3053 SCM arts = scm_reverse_x ($2, SCM_EOL);
3054 n->set_property ("articulations", arts);
3056 $$ = n->unprotect ();
3058 | music_function_chord_body
3060 Music *m = unsmob<Music> ($1);
3062 while (m && m->is_mus_type ("music-wrapper-music")) {
3063 $$ = m->get_property ("element");
3064 m = unsmob<Music> ($$);
3067 if (!(m && m->is_mus_type ("rhythmic-event"))) {
3068 parser->parser_error (@$, _ ("not a rhythmic event"));
3074 music_function_chord_body:
3080 event_function_event:
3081 EVENT_FUNCTION function_arglist {
3082 $$ = MAKE_SYNTAX (music_function, @$,
3091 | post_events post_event {
3093 if (Music *m = unsmob<Music> ($2))
3095 if (m->is_mus_type ("post-event-wrapper"))
3097 for (SCM p = m->get_property ("elements");
3101 $$ = scm_cons (scm_car (p), $$);
3104 m->set_spot (parser->lexer_->override_input (@2));
3105 $$ = scm_cons ($2, $$);
3111 post_event_nofinger:
3112 direction_less_event {
3115 | script_dir music_function_call {
3117 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
3118 parser->parser_error (@2, _ ("post-event expected"));
3119 $$ = SCM_UNSPECIFIED;
3120 } else if (!SCM_UNBNDP ($1))
3122 unsmob<Music> ($$)->set_property ("direction", $1);
3126 if (!parser->lexer_->is_lyric_state ())
3127 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3128 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
3131 if (!parser->lexer_->is_lyric_state ())
3132 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3133 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
3135 | script_dir direction_reqd_event {
3136 if (!SCM_UNBNDP ($1))
3138 Music *m = unsmob<Music> ($2);
3139 m->set_property ("direction", $1);
3143 | script_dir direction_less_event {
3144 if (!SCM_UNBNDP ($1))
3146 Music *m = unsmob<Music> ($2);
3147 m->set_property ("direction", $1);
3154 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
3159 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
3170 string_number_event:
3172 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3173 s->set_property ("string-number", $1);
3174 $$ = s->unprotect ();
3178 direction_less_event:
3180 | EVENT_IDENTIFIER {
3184 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3185 a->set_property ("tremolo-type", $1);
3186 $$ = a->unprotect ();
3188 | event_function_event
3191 direction_reqd_event:
3195 | script_abbreviation {
3196 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3197 if (scm_is_string (s)) {
3198 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3199 a->set_property ("articulation-type", s);
3200 $$ = a->unprotect ();
3202 Music *original = unsmob<Music> (s);
3203 if (original && original->is_mus_type ("post-event")) {
3204 Music *a = original->clone ();
3205 a->set_spot (parser->lexer_->override_input (@$));
3206 $$ = a->unprotect ();
3208 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3209 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3216 /**/ { $$ = SCM_EOL; }
3217 | '=' quotes { $$ = $2; }
3231 $$ = scm_from_int (1);
3234 $$ = scm_oneplus ($1);
3240 $$ = scm_from_int (-1);
3243 $$ = scm_oneminus ($1);
3248 NOTENAME_PITCH quotes {
3249 if (!scm_is_eq (SCM_INUM0, $2))
3251 Pitch p = *unsmob<Pitch> ($1);
3252 p = p.transposed (Pitch (scm_to_int ($2), 0));
3253 $$ = p.smobbed_copy ();
3263 TONICNAME_PITCH quotes {
3264 if (!scm_is_eq (SCM_INUM0, $2))
3266 Pitch p = *unsmob<Pitch> ($1);
3267 p = p.transposed (Pitch (scm_to_int ($2), 0));
3268 $$ = p.smobbed_copy ();
3275 | PITCH_IDENTIFIER quotes {
3276 if (!scm_is_eq (SCM_INUM0, $2))
3278 Pitch p = *unsmob<Pitch> ($1);
3279 p = p.transposed (Pitch (scm_to_int ($2), 0));
3280 $$ = p.smobbed_copy ();
3285 pitch_or_tonic_pitch:
3292 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3293 t->set_property ("text", $1);
3294 $$ = t->unprotect ();
3297 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3298 t->set_property ("text",
3299 make_simple_markup ($1));
3300 $$ = t->unprotect ();
3304 Music *m = unsmob<Music> ($1);
3305 if (m && m->is_mus_type ("post-event"))
3307 else if (Text_interface::is_markup ($1)) {
3308 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3309 t->set_property ("text", $1);
3310 $$ = t->unprotect ();
3312 parser->parser_error (@1, _ ("not an articulation"));
3318 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3319 t->set_property ("digit", $1);
3320 $$ = t->unprotect ();
3324 script_abbreviation:
3326 $$ = scm_from_ascii_string ("Hat");
3329 $$ = scm_from_ascii_string ("Plus");
3332 $$ = scm_from_ascii_string ("Dash");
3335 $$ = scm_from_ascii_string ("Bang");
3338 $$ = scm_from_ascii_string ("Larger");
3341 $$ = scm_from_ascii_string ("Dot");
3344 $$ = scm_from_ascii_string ("Underscore");
3349 '_' { $$ = scm_from_int (DOWN); }
3350 | '^' { $$ = scm_from_int (UP); }
3351 | '-' { $$ = SCM_UNDEFINED; }
3354 maybe_notemode_duration:
3358 | multiplied_duration {
3360 parser->default_duration_ = *unsmob<Duration> ($$);
3365 optional_notemode_duration:
3366 maybe_notemode_duration
3368 if (SCM_UNBNDP ($$))
3369 $$ = parser->default_duration_.smobbed_copy ();
3375 $$ = make_duration ($1, scm_to_int ($2));
3376 if (SCM_UNBNDP ($$))
3378 parser->parser_error (@1, _ ("not a duration"));
3379 $$ = Duration ().smobbed_copy ();
3382 | DURATION_IDENTIFIER dots {
3383 $$ = make_duration ($1, scm_to_int ($2));
3387 multiplied_duration:
3388 steno_duration multipliers {
3389 $$ = make_duration ($1, 0, $2);
3398 $$ = scm_oneplus ($1);
3407 | multipliers '*' UNSIGNED
3409 if (!SCM_UNBNDP ($1))
3410 $$ = scm_product ($1, $3);
3414 | multipliers '*' FRACTION
3416 if (!SCM_UNBNDP ($1))
3417 $$ = scm_product ($1, scm_divide (scm_car ($3),
3420 $$ = scm_divide (scm_car ($3), scm_cdr ($3));
3426 $$ = scm_from_int (parser->default_tremolo_type_);
3429 if (SCM_UNBNDP (make_duration ($2))) {
3430 parser->parser_error (@2, _ ("not a duration"));
3431 $$ = scm_from_int (parser->default_tremolo_type_);
3434 parser->default_tremolo_type_ = scm_to_int ($2);
3440 UNSIGNED { $$ = $1; }
3441 | STRING { $$ = $1; }
3442 | full_markup { $$ = $1; }
3445 // as an integer, it needs to be non-negative, and otherwise
3446 // it needs to be suitable as a markup.
3447 if (scm_is_integer ($1)
3448 ? scm_is_true (scm_negative_p ($1))
3449 : !Text_interface::is_markup ($1))
3451 parser->parser_error (@1, _ ("bass number expected"));
3457 figured_bass_alteration:
3458 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3459 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3460 | '!' { $$ = scm_from_int (0); }
3465 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3466 $$ = bfr->unprotect ();
3469 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3470 $$ = bfr->self_scm ();
3472 if (scm_is_number ($1))
3473 bfr->set_property ("figure", $1);
3474 else if (Text_interface::is_markup ($1))
3475 bfr->set_property ("text", $1);
3481 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3483 | bass_figure figured_bass_alteration {
3484 Music *m = unsmob<Music> ($1);
3485 if (scm_to_double ($2)) {
3486 SCM salter = m->get_property ("alteration");
3487 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3488 m->set_property ("alteration",
3489 scm_sum (alter, $2));
3491 m->set_property ("alteration", scm_from_int (0));
3494 | bass_figure figured_bass_modification {
3495 Music *m = unsmob<Music> ($1);
3496 m->set_property ($2, SCM_BOOL_T);
3501 figured_bass_modification:
3503 $$ = ly_symbol2scm ("augmented");
3506 $$ = ly_symbol2scm ("no-continuation");
3509 $$ = ly_symbol2scm ("diminished");
3512 $$ = ly_symbol2scm ("augmented-slash");
3522 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3530 | figure_list br_bass_figure {
3531 $$ = scm_cons ($2, $1);
3536 /**/ { $$ = SCM_BOOL_F; }
3537 | REST { $$ = SCM_BOOL_T; }
3541 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3542 if (!parser->lexer_->is_note_state ())
3543 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3544 if (!SCM_UNBNDP ($2)
3546 || scm_is_number ($4)
3549 || scm_is_pair ($7))
3552 if (scm_is_true ($6))
3553 n = MY_MAKE_MUSIC ("RestEvent", @$);
3555 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3557 n->set_property ("pitch", $1);
3558 if (SCM_UNBNDP ($5))
3559 n->set_property ("duration",
3560 parser->default_duration_.smobbed_copy ());
3562 n->set_property ("duration", $5);
3564 if (scm_is_number ($4))
3566 int q = scm_to_int ($4);
3567 n->set_property ("absolute-octave", scm_from_int (q-1));
3570 if (to_boolean ($3))
3571 n->set_property ("cautionary", SCM_BOOL_T);
3572 if (to_boolean ($2) || to_boolean ($3))
3573 n->set_property ("force-accidental", SCM_BOOL_T);
3574 if (scm_is_pair ($7))
3575 n->set_property ("articulations",
3576 scm_reverse_x ($7, SCM_EOL));
3577 $$ = n->unprotect ();
3580 | new_chord post_events {
3581 if (!parser->lexer_->is_chord_state ())
3582 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3583 if (scm_is_pair ($2)) {
3584 if (unsmob<Pitch> ($1))
3585 $1 = make_chord_elements (@1,
3587 parser->default_duration_.smobbed_copy (),
3590 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3592 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3593 } else if (!unsmob<Pitch> ($1))
3594 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3595 // A mere pitch drops through.
3600 DRUM_PITCH optional_notemode_duration {
3601 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3602 n->set_property ("duration", $2);
3603 n->set_property ("drum-type", $1);
3605 $$ = n->unprotect ();
3607 | RESTNAME optional_notemode_duration {
3609 if (ly_scm2string ($1) == "s") {
3611 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3614 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3617 ev->set_property ("duration", $2);
3618 $$ = ev->unprotect ();
3624 if (!parser->lexer_->is_lyric_state ())
3625 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3629 if (!parser->lexer_->is_lyric_state ())
3630 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3636 lyric_element_music:
3637 lyric_element optional_notemode_duration post_events {
3638 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3639 if (scm_is_pair ($3))
3640 unsmob<Music> ($$)->set_property
3641 ("articulations", scm_reverse_x ($3, SCM_EOL));
3645 // Can return a single pitch rather than a list.
3647 steno_tonic_pitch maybe_notemode_duration {
3648 if (SCM_UNBNDP ($2))
3651 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3653 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3654 SCM its = scm_reverse_x ($4, SCM_EOL);
3655 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3663 | chord_items chord_item {
3664 $$ = scm_cons ($2, $$);
3670 $$ = ly_symbol2scm ("chord-colon");
3673 $$ = ly_symbol2scm ("chord-caret");
3675 | CHORD_SLASH steno_tonic_pitch {
3676 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3678 | CHORD_BASS steno_tonic_pitch {
3679 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3688 $$ = scm_reverse_x ($1, SCM_EOL);
3696 step_number { $$ = scm_cons ($1, SCM_EOL); }
3697 | step_numbers '.' step_number {
3698 $$ = scm_cons ($3, $$);
3704 $$ = make_chord_step ($1, 0);
3707 $$ = make_chord_step ($1, SHARP_ALTERATION);
3709 | UNSIGNED CHORD_MINUS {
3710 $$ = make_chord_step ($1, FLAT_ALTERATION);
3718 | unsigned_number '-' unsigned_number {
3719 $$ = scm_cons ($1, $3);
3726 TODO: should deprecate in favor of Scheme?
3730 number_expression '+' number_term {
3731 $$ = scm_sum ($1, $3);
3733 | number_expression '-' number_term {
3734 $$ = scm_difference ($1, $3);
3743 | number_factor '*' number_factor {
3744 $$ = scm_product ($1, $3);
3746 | number_factor '/' number_factor {
3747 $$ = scm_divide ($1, $3);
3752 '-' number_factor { /* %prec UNARY_MINUS */
3753 $$ = scm_difference ($2, SCM_UNDEFINED);
3761 | REAL NUMBER_IDENTIFIER
3763 $$ = scm_product ($1, $2);
3770 | UNSIGNED NUMBER_IDENTIFIER {
3771 $$ = scm_product ($1, $2);
3779 if (!scm_is_integer ($1)
3780 || scm_is_true (scm_negative_p ($1)))
3782 parser->parser_error (@1, _("not an unsigned integer"));
3788 if (!scm_is_integer ($1)
3789 || scm_is_true (scm_negative_p ($1)))
3791 parser->parser_error (@1, _("not an unsigned integer"));
3798 { $$ = SCM_UNDEFINED; }
3801 if (SCM_UNBNDP ($1))
3809 // This precedence rule is rather weird. It triggers when '!' is
3810 // encountered after a pitch, and is used for deciding whether to save
3811 // this instead for a figure modification. This should not actually
3812 // occur in practice as pitches and figures are generated in different
3813 // modes. Using a greedy (%right) precedence makes sure that we don't
3814 // get stuck in a wrong interpretation.
3815 { $$ = SCM_UNDEFINED; } %prec ':'
3818 if (SCM_UNBNDP ($1))
3827 { parser->lexer_->push_markup_state (); }
3830 parser->lexer_->pop_state ();
3837 parser->lexer_->push_markup_state ();
3842 markup_mode markup_top {
3844 parser->lexer_->pop_state ();
3849 markup_mode markup_partial_function ETC
3851 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3852 parser->lexer_->pop_state ();
3858 $$ = scm_list_2 (Lily::line_markup, $1);
3860 | markup_head_1_list simple_markup
3862 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3863 @2, $1, scm_list_1 ($2)));
3873 if (Text_interface::is_markup ($1))
3874 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3875 else if (Text_interface::is_markup_list ($1))
3876 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3878 parser->parser_error (@1, _ ("not a markup"));
3879 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3886 markup_composed_list {
3889 | markup_uncomposed_list
3892 markup_uncomposed_list:
3893 markup_braced_list {
3896 | markup_command_list {
3897 $$ = scm_list_1 ($1);
3899 | markup_scm MARKUPLIST_IDENTIFIER
3904 parser->lexer_->push_note_state (Lily::pitchnames);
3905 } '{' score_body '}' {
3906 Score *sc = unsmob<Score> ($4);
3907 sc->origin ()->set_spot (@$);
3908 if (sc->defs_.empty ()) {
3909 Output_def *od = get_layout (parser);
3910 sc->add_output_def (od);
3913 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3914 parser->lexer_->pop_state ();
3918 markup_composed_list:
3919 markup_head_1_list markup_uncomposed_list {
3920 $$ = MAKE_SYNTAX (composed_markup_list,
3926 '{' markup_braced_list_body '}' {
3927 $$ = scm_reverse_x ($2, SCM_EOL);
3931 markup_braced_list_body:
3932 /* empty */ { $$ = SCM_EOL; }
3933 | markup_braced_list_body markup {
3934 $$ = scm_cons ($2, $1);
3936 | markup_braced_list_body markup_list {
3937 $$ = scm_reverse_x ($2, $1);
3941 markup_command_list:
3942 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3943 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3947 markup_command_basic_arguments:
3948 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3949 $$ = scm_cons ($3, $2);
3951 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3952 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3954 | EXPECT_NO_MORE_ARGS {
3959 markup_command_list_arguments:
3960 markup_command_basic_arguments { $$ = $1; }
3961 | EXPECT_MARKUP markup_command_list_arguments markup {
3962 $$ = scm_cons ($3, $2);
3966 markup_partial_function:
3967 MARKUP_FUNCTION markup_arglist_partial
3969 $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
3971 | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
3973 $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
3978 markup_arglist_partial:
3979 EXPECT_MARKUP markup_arglist_partial
3983 | EXPECT_SCM markup_arglist_partial
3987 | EXPECT_MARKUP markup_command_list_arguments
3991 | EXPECT_SCM markup_command_list_arguments
3998 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3999 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
4004 markup_head_1_item {
4005 $$ = scm_list_1 ($1);
4007 | markup_head_1_list markup_head_1_item {
4008 $$ = scm_cons ($2, $1);
4014 $$ = make_simple_markup ($1);
4017 parser->lexer_->push_note_state (Lily::pitchnames);
4018 } '{' score_body '}' {
4019 Score *sc = unsmob<Score> ($4);
4020 sc->origin ()->set_spot (@$);
4021 if (sc->defs_.empty ()) {
4022 Output_def *od = get_layout (parser);
4023 sc->add_output_def (od);
4026 $$ = scm_list_2 (Lily::score_markup, $4);
4027 parser->lexer_->pop_state ();
4029 | MARKUP_FUNCTION markup_command_basic_arguments {
4030 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
4032 | markup_scm MARKUP_IDENTIFIER
4039 markup_head_1_list simple_markup
4041 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
4042 @2, $1, scm_list_1 ($2)));
4052 Lily_parser::set_yydebug (bool x)
4058 Lily_parser::do_yyparse ()
4060 return scm_c_with_fluid (Lily::f_parser,
4062 do_yyparse_trampoline,
4063 static_cast <void *>(this));
4067 Lily_parser::do_yyparse_trampoline (void *parser)
4069 SCM retval = SCM_UNDEFINED;
4070 yyparse (static_cast <Lily_parser *>(parser), &retval);
4078 It is a little strange to have this function in this file, but
4079 otherwise, we have to import music classes into the lexer.
4083 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
4085 if (unsmob<Book> (sid)) {
4086 Book *book = unsmob<Book> (sid)->clone ();
4087 *destination = book->self_scm ();
4090 return BOOK_IDENTIFIER;
4091 } else if (scm_is_number (sid)) {
4093 return NUMBER_IDENTIFIER;
4094 } else if (unsmob<Context_def> (sid))
4096 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
4097 return SCM_IDENTIFIER;
4098 } else if (unsmob<Context_mod> (sid)) {
4099 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
4100 return CONTEXT_MOD_IDENTIFIER;
4101 } else if (Music *mus = unsmob<Music> (sid)) {
4102 mus = mus->clone ();
4103 *destination = mus->self_scm ();
4104 bool is_event = mus->is_mus_type ("post-event");
4106 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
4107 } else if (unsmob<Pitch> (sid)) {
4108 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
4109 return PITCH_IDENTIFIER;
4110 } else if (unsmob<Duration> (sid)) {
4111 *destination = unsmob<Duration> (sid)->smobbed_copy ();
4112 return DURATION_IDENTIFIER;
4113 } else if (unsmob<Output_def> (sid)) {
4114 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
4115 return SCM_IDENTIFIER;
4116 } else if (unsmob<Score> (sid)) {
4117 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
4118 return SCM_IDENTIFIER;
4119 } else if (scm_is_pair (sid)
4120 && scm_is_pair (scm_car (sid))
4121 && scm_is_true (Lily::key_p (scm_caar (sid)))) {
4123 return LOOKUP_IDENTIFIER;
4129 get_next_unique_context_id ()
4131 return scm_from_ascii_string ("$uniqueContextId");
4136 get_next_unique_lyrics_context_id ()
4138 static int new_context_count;
4140 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
4141 return scm_from_ascii_string (s);
4144 // check_scheme_arg checks one argument with a given predicate for use
4145 // in an argument list and throws a syntax error if it is unusable.
4146 // The argument is prepended to the argument list in any case. After
4147 // throwing a syntax error, the argument list is terminated with #f as
4148 // its last cdr in order to mark it as uncallable while not losing
4149 // track of its total length.
4151 // There are a few special considerations: if optional argument disp
4152 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
4153 // instead of arg in a prospective error message. This is useful if
4154 // arg is not the actual argument but rather a transformation of it.
4156 // If arg itself is SCM_UNDEFINED, the predicate is considered false
4157 // and an error message using disp is produced unconditionally.
4159 SCM check_scheme_arg (Lily_parser *parser, Input loc,
4160 SCM arg, SCM args, SCM pred, SCM disp)
4162 if (SCM_UNBNDP (arg))
4163 args = scm_cons (disp, args);
4165 args = scm_cons (arg, args);
4166 if (scm_is_true (scm_call_1 (pred, arg)))
4169 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
4170 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
4171 SCM_UNBNDP (disp) ? arg : disp);
4172 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
4176 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
4178 if (Music *m = unsmob<Music> (arg))
4181 m->set_spot (parser->lexer_->override_input (loc));
4182 return m->unprotect ();
4188 try_string_variants (SCM pred, SCM str)
4190 // a matching predicate is always ok
4191 if (scm_is_true (scm_call_1 (pred, str)))
4193 // a symbol may be interpreted as a list of symbols if it helps
4194 if (scm_is_true (Lily::key_p (str))) {
4195 str = scm_list_1 (str);
4196 if (scm_is_true (scm_call_1 (pred, str)))
4198 return SCM_UNDEFINED;
4201 // If this cannot be a string representation of a symbol list,
4204 if (!is_regular_identifier (str, true))
4205 return SCM_UNDEFINED;
4207 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4208 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4209 scm_set_car_x (p, scm_string_split (scm_car (p),
4210 SCM_MAKE_CHAR (',')));
4211 str = scm_append_x (str);
4212 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4213 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4215 // Let's attempt the symbol list interpretation first.
4217 if (scm_is_true (scm_call_1 (pred, str)))
4220 // If there is just one symbol in the list, we might interpret
4221 // it as a single symbol
4223 if (scm_is_null (scm_cdr (str)))
4225 str = scm_car (str);
4226 if (scm_is_true (scm_call_1 (pred, str)))
4230 return SCM_UNDEFINED;
4234 is_regular_identifier (SCM id, bool multiple)
4236 if (!scm_is_string (id))
4239 string str = ly_scm2string (id);
4241 bool middle = false;
4243 for (string::iterator it=str.begin(); it != str.end (); it++)
4246 if ((c >= 'a' && c <= 'z')
4247 || (c >= 'A' && c <= 'Z')
4250 else if (middle && (c == '-' || c == '_' || (multiple &&
4251 (c == '.' || c == ','))))
4260 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4262 if (unsmob<Music> (simple))
4264 if (parser->lexer_->is_note_state ()) {
4265 if (scm_is_symbol (simple)) {
4266 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4267 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4268 n->set_property ("drum-type", simple);
4269 return n->unprotect ();
4271 if (unsmob<Pitch> (simple)) {
4272 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4273 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4274 n->set_property ("pitch", simple);
4275 return n->unprotect ();
4278 if (scm_is_integer (simple))
4279 d = make_duration (simple);
4280 if (unsmob<Duration> (d)) {
4281 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4282 n->set_property ("duration", d);
4283 return n->unprotect ();
4286 } else if (parser->lexer_->is_lyric_state ()) {
4287 if (Text_interface::is_markup (simple))
4288 return MAKE_SYNTAX (lyric_event, loc, simple,
4289 parser->default_duration_.smobbed_copy ());
4290 } else if (parser->lexer_->is_chord_state ()) {
4291 if (unsmob<Pitch> (simple))
4295 make_chord_elements (loc, simple,
4296 parser->default_duration_.smobbed_copy (),
4303 make_music_with_input (SCM name, Input where)
4305 Music *m = make_music_by_name (name);
4306 m->set_spot (where);
4311 make_simple_markup (SCM a)
4317 make_duration (SCM d, int dots, SCM factor)
4321 if (Duration *dur = unsmob<Duration> (d)) {
4322 if (!dots && SCM_UNBNDP (factor))
4326 k = Duration (k.duration_log (), k.dot_count () + dots)
4327 .compressed (k.factor ());
4329 int t = scm_to_int (d);
4330 if (t > 0 && (t & (t-1)) == 0)
4331 k = Duration (intlog2 (t), dots);
4333 return SCM_UNDEFINED;
4336 if (!SCM_UNBNDP (factor))
4337 k = k.compressed (ly_scm2rational (factor));
4339 return k.smobbed_copy ();
4343 make_chord_step (SCM step_scm, Rational alter)
4345 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4347 // Notename/octave are normalized
4348 if (m.get_notename () == 6)
4349 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4351 return m.smobbed_copy ();
4356 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4358 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4359 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4361 unsmob<Music> (scm_car (s))->set_spot (loc);
4367 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4369 Lily_lexer *lex = parser->lexer_;
4373 int tok = lex->pop_extra_token ();
4376 lex->prepare_for_next_token ();
4377 return lex->yylex ();