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 (!scm_is_eq ($2, SCM_UNSPECIFIED))
1177 parser->parser_error (@2, _("Spurious expression in \\score"));
1181 if (Score *score = unsmob<Score> ($1)) {
1182 if (!ly_is_module (score->get_header ()))
1183 score->set_header (ly_make_module (false));
1184 parser->lexer_->add_scope (score->get_header ());
1186 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1187 $1 = scm_cons (ly_make_module (false), $1);
1188 parser->lexer_->add_scope (scm_car ($1));
1203 Output_def *od = unsmob<Output_def> ($1);
1205 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1207 parser->parser_error (@1, _ ("need \\paper for paper block"));
1208 $$ = get_paper (parser)->unprotect ();
1215 output_def_body '}' {
1216 if (scm_is_pair ($1))
1219 parser->lexer_->remove_scope ();
1220 parser->lexer_->pop_state ();
1226 Output_def *p = get_paper (parser);
1227 p->input_origin_ = @$;
1228 parser->lexer_->add_scope (p->scope_);
1229 $$ = p->unprotect ();
1232 Output_def *p = get_midi (parser);
1233 $$ = p->unprotect ();
1234 parser->lexer_->add_scope (p->scope_);
1237 Output_def *p = get_layout (parser);
1239 parser->lexer_->add_scope (p->scope_);
1240 $$ = p->unprotect ();
1244 output_def_head_with_mode_switch:
1246 parser->lexer_->push_initial_state ();
1251 // We need this weird nonterminal because both music as well as a
1252 // context definition can start with \context and the difference is
1253 // only apparent after looking at the next token. If it is '{', there
1254 // is still time to escape from notes mode.
1256 music_or_context_def:
1258 | context_def_spec_block
1262 output_def_head_with_mode_switch '{' {
1263 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1264 // This is a stupid trick to mark the beginning of the
1265 // body for deciding whether to allow
1266 // embedded_scm_active to have an output definition
1267 $$ = scm_list_1 ($1);
1269 | output_def_body assignment {
1270 if (scm_is_pair ($1))
1273 | output_def_body embedded_scm_active
1275 // We don't switch into note mode for Scheme functions
1276 // here. Does not seem warranted/required in output
1278 if (scm_is_pair ($1))
1280 Output_def *o = unsmob<Output_def> ($2);
1282 o->input_origin_.set_spot (@$);
1283 $1 = o->self_scm ();
1284 parser->lexer_->remove_scope ();
1285 parser->lexer_->add_scope (o->scope_);
1286 $2 = SCM_UNSPECIFIED;
1290 if (unsmob<Context_def> ($2))
1291 assign_context_def (unsmob<Output_def> ($1), $2);
1292 // Seems unlikely, but let's be complete:
1293 else if (unsmob<Music> ($2))
1295 SCM proc = parser->lexer_->lookup_identifier
1296 ("output-def-music-handler");
1297 scm_call_2 (proc, $1, $2);
1298 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1299 parser->parser_error (@2, _("bad expression type"));
1302 | output_def_body SCM_TOKEN {
1303 if (scm_is_pair ($1))
1305 // Evaluate and ignore #xxx, as opposed to \xxx
1306 parser->lexer_->eval_scm_token ($2, @2);
1310 if (scm_is_pair ($1))
1312 parser->lexer_->push_note_state (Lily::pitchnames);
1313 } music_or_context_def
1315 parser->lexer_->pop_state ();
1316 if (unsmob<Context_def> ($3))
1317 assign_context_def (unsmob<Output_def> ($1), $3);
1320 SCM proc = parser->lexer_->lookup_identifier
1321 ("output-def-music-handler");
1322 scm_call_2 (proc, $1, $3);
1326 | output_def_body error {
1332 TEMPO steno_duration '=' tempo_range {
1333 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1335 | TEMPO text steno_duration '=' tempo_range {
1336 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1339 $$ = MAKE_SYNTAX (tempo, @$, $2);
1344 The representation of a list is reversed to have efficient append. */
1350 | music_list music_embedded {
1351 if (unsmob<Music> ($2))
1352 $$ = scm_cons ($2, $1);
1354 | music_list error {
1355 Music *m = MY_MAKE_MUSIC("Music", @$);
1357 m->set_property ("error-found", SCM_BOOL_T);
1358 $$ = scm_cons (m->self_scm (), $1);
1359 m->unprotect (); /* UGH */
1366 $$ = scm_reverse_x ($2, SCM_EOL);
1371 | lyric_element_music
1378 $$ = make_music_from_simple (parser, @1, $1);
1379 if (!unsmob<Music> ($$))
1381 parser->parser_error (@1, _ ("music expected"));
1382 $$ = MAKE_SYNTAX (void_music, @$);
1390 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1391 parser->parser_error (@1, _ ("unexpected post-event"));
1392 $$ = SCM_UNSPECIFIED;
1395 | music_embedded_backup
1399 | music_embedded_backup BACKUP lyric_element_music
1403 | multiplied_duration post_events
1405 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1407 parser->default_duration_ = *unsmob<Duration> ($1);
1408 n->set_property ("duration", $1);
1410 if (scm_is_pair ($2))
1411 n->set_property ("articulations",
1412 scm_reverse_x ($2, SCM_EOL));
1413 $$ = n->unprotect ();
1417 music_embedded_backup:
1420 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1422 else if (Music *m = unsmob<Music> ($1)) {
1423 if (m->is_mus_type ("post-event")) {
1424 parser->parser_error
1425 (@1, _ ("unexpected post-event"));
1426 $$ = SCM_UNSPECIFIED;
1429 } else if (parser->lexer_->is_lyric_state ()
1430 && Text_interface::is_markup ($1))
1431 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1433 @$.warning (_ ("Ignoring non-music expression"));
1439 // music_assign does not need to contain lyrics: there are no
1440 // assignments in lyricmode.
1443 | composite_music %prec COMPOSITE
1447 REPEAT simple_string unsigned_number music
1449 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1451 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1453 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1458 SEQUENTIAL braced_music_list {
1459 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1461 | braced_music_list {
1462 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1467 SIMULTANEOUS braced_music_list {
1468 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1470 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1471 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1477 | music_property_def
1481 context_modification:
1484 parser->lexer_->push_note_state (Lily::pitchnames);
1485 } '{' context_mod_list '}'
1487 parser->lexer_->pop_state ();
1490 | WITH CONTEXT_MOD_IDENTIFIER
1494 | CONTEXT_MOD_IDENTIFIER
1498 | WITH context_modification_arg
1500 if (unsmob<Music> ($2)) {
1501 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1502 $2 = scm_call_1 (proc, $2);
1504 if (unsmob<Context_mod> ($2))
1507 parser->parser_error (@2, _ ("not a context mod"));
1508 $$ = Context_mod ().smobbed_copy ();
1513 context_modification_arg:
1518 /* A list of single mods collected from a (possibly empty) sequence of
1519 * context modifications, usually written as \with ... \with ...
1522 optional_context_mods:
1523 context_modification_mods_list
1525 if (scm_is_pair ($1))
1526 $$ = scm_append_x (scm_reverse_x ($1, SCM_EOL));
1530 /* The worker for optional_context_mods conses a (reversed) list where
1531 * each element contains the list of single context mods from one
1532 * context modification block. Context_mod::get_mods creates fresh
1533 * copies, so it's okay to use append! on them.
1536 context_modification_mods_list:
1540 | context_modification_mods_list context_modification
1542 if (Context_mod *m = unsmob<Context_mod> ($2))
1543 $$ = scm_cons (m->get_mods (), $1);
1547 /* A Context_mod is a container for a list of context mods like
1548 * \consists ... \override ... . context_mod_list produces a
1549 * Context_mod from the inside of a \with { ... } statement.
1554 $$ = Context_mod ().smobbed_copy ();
1556 | context_mod_list context_mod {
1557 if (!SCM_UNBNDP ($2))
1558 unsmob<Context_mod> ($1)->add_context_mod ($2);
1560 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1561 Context_mod *md = unsmob<Context_mod> ($2);
1563 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1565 | context_mod_list context_mod_arg {
1566 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1568 else if (unsmob<Music> ($2)) {
1569 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1570 $2 = scm_call_1 (proc, $2);
1572 if (unsmob<Context_mod> ($2))
1573 unsmob<Context_mod> ($$)->add_context_mods
1574 (unsmob<Context_mod> ($2)->get_mods ());
1576 parser->parser_error (@2, _ ("not a context mod"));
1582 CONTEXT symbol optional_id optional_context_mods {
1583 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_F);
1585 | NEWCONTEXT symbol optional_id optional_context_mods {
1586 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_T);
1591 ADDLYRICS optional_context_mods lyric_mode_music {
1592 $$ = scm_acons ($3, $2, SCM_EOL);
1594 | new_lyrics ADDLYRICS optional_context_mods lyric_mode_music {
1595 $$ = scm_acons ($4, $3, $1);
1599 /* basic_music is basically the same as composite_music but with
1600 * context-prefixed music and lyricized music explicitly removed. The
1601 * reason is that in a sequence
1603 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1605 * we need to group both \addlyrics together (as they go with the same
1606 * voice) but then combine them with \new Voice { ... }, meaning that
1607 * combining \new Voice { ... } needs higher priority than
1608 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1609 * combine before combining \new Voice { ... } \addlyrics: only one
1610 * layer of context-prefixed music should assemble before \addlyrics
1611 * is integrated. Total mess, and we sort this mess out with explicit
1612 * rules preferring a single context-prefix.
1619 | LYRICSTO simple_string lyric_mode_music {
1620 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1622 | LYRICSTO symbol '=' simple_string lyric_mode_music
1624 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1634 contexted_basic_music:
1635 context_prefix contextable_music new_lyrics
1638 i.set_location (@1, @2);
1639 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1640 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1642 | context_prefix contextable_music
1644 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1646 | context_prefix contexted_basic_music
1648 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1653 basic_music %prec COMPOSITE
1654 | contexted_basic_music
1655 | basic_music new_lyrics
1657 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1664 | grouped_music_list
1668 simultaneous_music { $$ = $1; }
1669 | sequential_music { $$ = $1; }
1672 /* Function argument lists are arguably the most complex part in the
1673 * parser. They are pretty tricky to understand because of the way
1674 * they are processed, and because of optional arguments that can be
1675 * omitted. When there are several optional arguments in a row,
1676 * omitting one automatically omits all following arguments. Optional
1677 * arguments can only be omitted when either
1679 * a) the omission is explicitly started with \default
1680 * b) the omission is implicitly started by an argument not matching
1681 * its predicate, and there is a mandatory argument later that can
1682 * "catch" the argument that does not fit.
1684 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1685 * (corresponding to mandatory arguments and having a predicate
1686 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1687 * the semantic value of the EXPECT_OPTIONAL token is the default to
1688 * use when the optional argument is omitted, and EXPECT_SCM again has
1689 * the argument predicate as semantic value) in reverse order to the
1690 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1691 * processed inside-out while actual tokens are consumed.
1693 * This means that the argument list tokens determine the actions
1694 * taken as they arrive. The structure of the argument list is known
1695 * to the parser and stored in its parse stack when the first argument
1696 * is being parsed. What the parser does not know is which predicates
1697 * will match and whether or not \default will be appearing in the
1698 * argument list, and where.
1700 * Sequences of 0 or more optional arguments are scanned using either
1701 * function_arglist_backup or function_arglist_nonbackup. The first
1702 * is used when optional arguments are followed by at least one
1703 * mandatory argument: in that case optional arguments may be skipped
1704 * by either a false predicate (in which case the expression will be
1705 * pushed back as one or more tokens, preceded by a BACKUP token) or
1706 * by using \default.
1708 * If optional arguments are at the end of the argument list, they are
1709 * instead scanned using function_arglist_nonbackup: here the only
1710 * manner to enter into skipping of optional arguments is the use of
1713 * The argument list of a normal function call is parsed using
1714 * function_arglist. The part of an argument list before a mandatory
1715 * argument is parsed using function_arglist_optional.
1717 * The difference is that leading optional arguments are scanned using
1718 * function_arglist_nonbackup and function_arglist_backup,
1721 * Most other details are obvious in the rules themselves.
1727 | SYMBOL_LIST '.' symbol_list_rev
1729 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1731 | SYMBOL_LIST ',' symbol_list_rev
1733 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1739 | symbol_list_rev '.' symbol_list_part
1741 $$ = scm_append_x (scm_list_2 ($3, $1));
1743 | symbol_list_rev ',' symbol_list_part
1745 $$ = scm_append_x (scm_list_2 ($3, $1));
1749 // symbol_list_part delivers elements in reverse copy.
1754 $$ = try_string_variants (Lily::key_list_p, $1);
1755 if (SCM_UNBNDP ($$)) {
1756 parser->parser_error (@1, _("not a key"));
1759 $$ = scm_reverse ($$);
1764 symbol_list_element:
1770 symbol_list_part_bare:
1773 $$ = try_string_variants (Lily::key_list_p, $1);
1774 if (SCM_UNBNDP ($$)) {
1775 parser->parser_error (@1, _("not a key"));
1778 $$ = scm_reverse ($$);
1782 $$ = scm_list_1 ($1);
1786 function_arglist_nonbackup:
1787 function_arglist_common
1788 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1790 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1792 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1794 SCM n = scm_difference ($5, SCM_UNDEFINED);
1795 if (scm_is_true (scm_call_1 ($2, n)))
1796 $$ = scm_cons (n, $3);
1798 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1799 t->set_property ("digit", $5);
1800 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1804 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1806 $$ = check_scheme_arg (parser, @4,
1807 scm_difference ($5, SCM_UNDEFINED),
1810 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1812 $$ = check_scheme_arg (parser, @4,
1813 scm_difference ($5, SCM_UNDEFINED),
1816 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1818 if (scm_is_true (scm_call_1 ($2, $4)))
1819 $$ = scm_cons ($4, $3);
1821 $$ = check_scheme_arg (parser, @4,
1822 make_music_from_simple
1826 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1828 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1830 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1832 if (scm_is_true (scm_call_1 ($2, $3)))
1833 $$ = scm_cons ($3, $1);
1835 $$ = check_scheme_arg (parser, @3,
1836 make_music_from_simple
1840 | function_arglist_nonbackup_reparse REPARSE multiplied_duration
1842 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1844 | function_arglist_nonbackup_reparse REPARSE reparsed_rhythm
1846 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1848 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1850 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1852 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1854 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1856 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1858 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1860 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1862 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1868 DURATION_ARG dots multipliers post_events
1870 $$ = make_music_from_simple (parser, @$,
1871 make_duration ($1, scm_to_int ($2), $3));
1872 Music *m = unsmob<Music> ($$);
1874 if (scm_is_pair ($4))
1875 m->set_property ("articulations",
1876 scm_reverse_x ($4, SCM_EOL));
1880 function_arglist_nonbackup_reparse:
1881 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1884 SCM res = try_string_variants ($2, $4);
1885 if (!SCM_UNBNDP (res))
1886 if (scm_is_pair (res))
1887 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1889 MYREPARSE (@4, $2, SCM_ARG, res);
1890 else if (scm_is_true
1892 ($2, make_music_from_simple
1894 MYREPARSE (@4, $2, STRING, $4);
1896 MYREPARSE (@4, $2, SCM_ARG, $4);
1898 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1903 ($2, make_music_from_simple
1905 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1907 MYREPARSE (@4, $2, SCM_ARG, $4);
1909 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1914 ($2, make_music_from_simple
1916 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1918 MYREPARSE (@4, $2, SCM_ARG, $4);
1920 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1923 SCM res = try_string_variants ($2, $4);
1924 if (!SCM_UNBNDP (res))
1925 if (scm_is_pair (res))
1926 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1928 MYREPARSE (@4, $2, SCM_ARG, res);
1929 else if (scm_is_true
1931 ($2, make_music_from_simple
1933 MYREPARSE (@4, $2, STRING, $4);
1935 MYREPARSE (@4, $2, SCM_ARG, $4);
1937 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1940 if (scm_is_true (scm_call_1 ($2, $4)))
1941 MYREPARSE (@4, $2, SCM_ARG, $4);
1942 else if (scm_is_true
1944 ($2, make_music_from_simple
1946 MYREPARSE (@4, $2, STRING, $4);
1948 MYREPARSE (@4, $2, SCM_ARG, $4);
1950 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1953 if (scm_is_true (scm_call_1 ($2, $4)))
1954 // May be 3 \cm or similar
1955 MYREPARSE (@4, $2, REAL, $4);
1956 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
1957 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
1959 SCM d = make_duration ($4);
1960 if (!SCM_UNBNDP (d)) {
1961 if (scm_is_true (scm_call_1 ($2, d)))
1962 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1963 else if (scm_is_true
1965 ($2, make_music_from_simple (parser, @4, d))))
1966 MYREPARSE (@4, $2, DURATION_ARG, d);
1968 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1970 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1973 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER
1976 if (scm_is_true (scm_call_1 ($2, $4)))
1977 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1978 else if (scm_is_true
1980 ($2, make_music_from_simple (parser, @4, $4))))
1981 MYREPARSE (@4, $2, DURATION_ARG, $4);
1983 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1988 // function_arglist_backup can't occur at the end of an argument
1990 function_arglist_backup:
1991 function_arglist_common
1992 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1994 if (scm_is_true (scm_call_1 ($2, $4)))
1995 $$ = scm_cons ($4, $3);
1997 $$ = make_music_from_simple (parser, @4, $4);
1998 if (scm_is_true (scm_call_1 ($2, $$)))
1999 $$ = scm_cons ($$, $3);
2002 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2003 MYBACKUP (SCM_ARG, $4, @4);
2007 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
2009 if (scm_is_true (scm_call_1 ($2, $4)))
2011 $$ = scm_cons ($4, $3);
2013 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2014 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
2017 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
2021 ($2, make_music_from_simple
2025 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
2026 } else 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 (PITCH_IDENTIFIER, $4, @4);
2033 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
2037 ($2, make_music_from_simple
2041 MYREPARSE (@4, $2, TONICNAME_PITCH, $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 (TONICNAME_PITCH, $4, @4);
2049 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
2051 if (scm_is_true (scm_call_1 ($2, $4)))
2052 $$ = scm_cons ($4, $3);
2054 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2055 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2058 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
2061 if (scm_is_true (scm_call_1 ($2, $4)))
2062 // May be 3 \cm or similar
2063 MYREPARSE (@4, $2, REAL, $4);
2064 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
2065 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
2067 SCM d = make_duration ($4);
2068 if (!SCM_UNBNDP (d)) {
2069 if (scm_is_true (scm_call_1 ($2, d)))
2070 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
2071 else if (scm_is_true
2073 ($2, make_music_from_simple (parser, @4, d))))
2074 MYREPARSE (@4, $2, DURATION_ARG, d);
2076 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2077 MYBACKUP (UNSIGNED, $4, @4);
2080 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2081 MYBACKUP (UNSIGNED, $4, @4);
2085 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
2087 if (scm_is_true (scm_call_1 ($2, $4)))
2090 MYREPARSE (@4, $2, REAL, $4);
2092 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2093 MYBACKUP (REAL, $4, @4);
2096 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
2098 if (scm_is_true (scm_call_1 ($2, $4)))
2100 $$ = scm_cons ($4, $3);
2102 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2103 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
2106 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
2108 SCM n = scm_difference ($5, SCM_UNDEFINED);
2109 if (scm_is_true (scm_call_1 ($2, n))) {
2111 MYREPARSE (@5, $2, REAL, n);
2113 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
2114 t->set_property ("digit", $5);
2115 $$ = t->unprotect ();
2116 if (scm_is_true (scm_call_1 ($2, $$)))
2117 $$ = scm_cons ($$, $3);
2119 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2120 MYBACKUP (UNSIGNED, $5, @5);
2121 parser->lexer_->push_extra_token (@4, '-');
2125 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2127 SCM n = scm_difference ($5, SCM_UNDEFINED);
2128 if (scm_is_true (scm_call_1 ($2, n))) {
2129 MYREPARSE (@5, $2, REAL, n);
2132 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2133 MYBACKUP (REAL, n, @5);
2136 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2138 SCM n = scm_difference ($5, SCM_UNDEFINED);
2139 if (scm_is_true (scm_call_1 ($2, n))) {
2140 $$ = scm_cons (n, $3);
2142 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2143 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2146 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2149 if (scm_is_true (scm_call_1 ($2, $4)))
2150 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2151 else if (scm_is_true
2153 ($2, make_music_from_simple (parser, @4, $4))))
2154 MYREPARSE (@4, $2, DURATION_ARG, $4);
2156 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2157 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2160 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2162 SCM res = try_string_variants ($2, $4);
2163 if (!SCM_UNBNDP (res))
2164 if (scm_is_pair (res)) {
2166 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2169 $$ = scm_cons (res, $3);
2171 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2172 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2175 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2177 SCM res = try_string_variants ($2, $4);
2178 if (!SCM_UNBNDP (res))
2179 if (scm_is_pair (res)) {
2181 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2184 $$ = scm_cons (res, $3);
2186 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2187 MYBACKUP (STRING, $4, @4);
2190 | function_arglist_backup REPARSE pitch_or_music
2192 if (scm_is_true (scm_call_1 ($2, $3)))
2193 $$ = scm_cons ($3, $1);
2195 $$ = check_scheme_arg (parser, @3,
2196 make_music_from_simple
2200 | function_arglist_backup REPARSE bare_number_common
2202 $$ = check_scheme_arg (parser, @3,
2205 | function_arglist_backup REPARSE multiplied_duration
2207 $$ = check_scheme_arg (parser, @3,
2210 | function_arglist_backup REPARSE reparsed_rhythm
2212 $$ = check_scheme_arg (parser, @3,
2215 | function_arglist_backup REPARSE symbol_list_arg
2217 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2222 function_arglist_nonbackup
2223 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2225 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2229 function_arglist_skip_nonbackup:
2230 function_arglist_nonbackup
2231 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2233 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2237 // Partial function arglists are returned just in their incomplete
2238 // state: when combined with the music function, the missing parts of
2239 // the signature can be reconstructed
2241 // To serve as a partial arglist, the argument list must absolutely
2242 // _not_ be in "skipping optional arguments" mode since then there is
2243 // some backup token that has nowhere to go before \etc.
2245 // So we can skim off an arbitrary number of arguments from the end of
2246 // the argument list. The argument list remaining afterwards has to
2247 // be in not-skipping-optional-arguments mode.
2249 function_arglist_partial:
2250 EXPECT_SCM function_arglist_optional
2254 | EXPECT_SCM function_arglist_partial_optional
2258 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2262 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2268 function_arglist_partial_optional:
2269 EXPECT_SCM function_arglist_optional
2273 | EXPECT_SCM function_arglist_partial_optional
2277 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2281 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2287 function_arglist_common:
2288 EXPECT_NO_MORE_ARGS {
2291 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2293 if (scm_is_true (scm_call_1 ($1, $3)))
2294 $$ = scm_cons ($3, $2);
2296 $$ = check_scheme_arg (parser, @3,
2297 make_music_from_simple
2301 | EXPECT_SCM function_arglist_optional bare_number_common
2303 $$ = check_scheme_arg (parser, @3,
2306 | EXPECT_SCM function_arglist_optional post_event_nofinger
2308 $$ = check_scheme_arg (parser, @3,
2311 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2313 SCM n = scm_difference ($4, SCM_UNDEFINED);
2314 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2316 | function_arglist_common_reparse REPARSE SCM_ARG
2318 $$ = check_scheme_arg (parser, @3,
2321 | function_arglist_common_reparse REPARSE lyric_element_music
2323 $$ = check_scheme_arg (parser, @3,
2326 | function_arglist_common_reparse REPARSE pitch_or_music
2328 if (scm_is_true (scm_call_1 ($2, $3)))
2329 $$ = scm_cons ($3, $1);
2331 $$ = check_scheme_arg (parser, @3,
2332 make_music_from_simple
2336 | function_arglist_common_reparse REPARSE bare_number_common
2338 $$ = check_scheme_arg (parser, @3,
2341 | function_arglist_common_reparse REPARSE multiplied_duration
2343 $$ = check_scheme_arg (parser, @3,
2346 | function_arglist_common_reparse REPARSE reparsed_rhythm
2348 $$ = check_scheme_arg (parser, @3,
2351 | function_arglist_common_reparse REPARSE symbol_list_arg
2353 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2357 function_arglist_common_reparse:
2358 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2361 SCM res = try_string_variants ($1, $3);
2362 if (!SCM_UNBNDP (res))
2363 if (scm_is_pair (res))
2364 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2366 MYREPARSE (@3, $1, SCM_ARG, res);
2367 else if (scm_is_true
2369 ($1, make_music_from_simple (parser, @3, $3))))
2370 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2372 // This is going to flag a syntax error, we
2373 // know the predicate to be false.
2374 MYREPARSE (@3, $1, SCM_ARG, $3);
2376 | EXPECT_SCM function_arglist_optional pitch
2381 ($1, make_music_from_simple
2383 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2385 MYREPARSE (@3, $1, SCM_ARG, $3);
2387 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2392 ($1, make_music_from_simple
2394 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2396 MYREPARSE (@3, $1, SCM_ARG, $3);
2398 | EXPECT_SCM function_arglist_optional STRING
2401 SCM res = try_string_variants ($1, $3);
2402 if (!SCM_UNBNDP (res))
2403 if (scm_is_pair (res))
2404 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2406 MYREPARSE (@3, $1, SCM_ARG, res);
2407 else if (scm_is_true
2409 ($1, make_music_from_simple (parser, @3, $3))))
2410 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2412 // This is going to flag a syntax error, we
2413 // know the predicate to be false.
2414 MYREPARSE (@3, $1, SCM_ARG, $3);
2416 | EXPECT_SCM function_arglist_optional full_markup
2419 if (scm_is_true (scm_call_1 ($1, $3)))
2420 MYREPARSE (@3, $1, SCM_ARG, $3);
2421 else if (scm_is_true
2423 ($1, make_music_from_simple (parser, @3, $3))))
2424 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2426 // This is going to flag a syntax error, we
2427 // know the predicate to be false.
2428 MYREPARSE (@3, $1, SCM_ARG, $3);
2430 | EXPECT_SCM function_arglist_optional UNSIGNED
2433 if (scm_is_true (scm_call_1 ($1, $3)))
2434 // May be 3 \cm or similar
2435 MYREPARSE (@3, $1, REAL, $3);
2436 else if (scm_is_true (scm_call_1 ($1, scm_list_1 ($3))))
2437 MYREPARSE (@3, $1, SYMBOL_LIST, scm_list_1 ($3));
2439 SCM d = make_duration ($3);
2440 if (!SCM_UNBNDP (d)) {
2441 if (scm_is_true (scm_call_1 ($1, d)))
2442 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2443 else if (scm_is_true
2445 ($1, make_music_from_simple (parser, @3, d))))
2446 MYREPARSE (@3, $1, DURATION_ARG, d);
2448 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2450 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2453 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2456 if (scm_is_true (scm_call_1 ($1, $3)))
2457 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2458 else if (scm_is_true
2460 ($1, make_music_from_simple (parser, @3, $3))))
2461 MYREPARSE (@3, $1, DURATION_ARG, $3);
2463 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2465 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2468 SCM n = scm_difference ($4, SCM_UNDEFINED);
2469 if (scm_is_true (scm_call_1 ($1, n)))
2470 MYREPARSE (@4, $1, REAL, n);
2472 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2473 t->set_property ("digit", $4);
2474 SCM m = t->unprotect ();
2475 if (scm_is_true (scm_call_1 ($1, m)))
2476 MYREPARSE (@4, $1, SCM_ARG, m);
2478 MYREPARSE (@4, $1, SCM_ARG, $4);
2481 | EXPECT_SCM function_arglist_optional '-' REAL
2484 SCM n = scm_difference ($4, SCM_UNDEFINED);
2485 MYREPARSE (@4, $1, REAL, n);
2489 function_arglist_optional:
2490 function_arglist_backup
2491 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2493 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2495 | function_arglist_skip_backup BACKUP
2498 function_arglist_skip_backup:
2499 function_arglist_backup
2500 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2502 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2506 music_function_call:
2507 MUSIC_FUNCTION function_arglist {
2508 $$ = MAKE_SYNTAX (music_function, @$,
2515 /**/ { $$ = SCM_EOL; }
2516 | '=' simple_string {
2521 // We must not have lookahead tokens parsed in lyric mode. In order
2522 // to save confusion, we take almost the same set as permitted with
2523 // \lyricmode and/or \lyrics. However, music identifiers are also
2524 // allowed, and they obviously do not require switching into lyrics
2525 // mode for parsing.
2529 parser->lexer_->push_lyric_state ();
2530 } grouped_music_list
2532 parser->lexer_->pop_state ();
2539 mode_changing_head grouped_music_list {
2540 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2542 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2548 parser->lexer_->pop_state ();
2550 | mode_changing_head_with_context optional_context_mods grouped_music_list {
2551 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, $2, SCM_BOOL_T, $3);
2552 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2554 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2556 parser->lexer_->pop_state ();
2562 parser->lexer_->push_note_state (Lily::pitchnames);
2564 $$ = ly_symbol2scm ("notes");
2568 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2570 $$ = ly_symbol2scm ("drums");
2573 parser->lexer_->push_figuredbass_state ();
2575 $$ = ly_symbol2scm ("figures");
2578 parser->lexer_->chordmodifier_tab_ =
2579 alist_to_hashq (Lily::chordmodifiers);
2580 parser->lexer_->push_chord_state (Lily::pitchnames);
2581 $$ = ly_symbol2scm ("chords");
2585 { parser->lexer_->push_lyric_state ();
2586 $$ = ly_symbol2scm ("lyrics");
2590 mode_changing_head_with_context:
2592 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2594 $$ = ly_symbol2scm ("DrumStaff");
2597 parser->lexer_->push_figuredbass_state ();
2599 $$ = ly_symbol2scm ("FiguredBass");
2602 parser->lexer_->chordmodifier_tab_ =
2603 alist_to_hashq (Lily::chordmodifiers);
2604 parser->lexer_->push_chord_state (Lily::pitchnames);
2605 $$ = ly_symbol2scm ("ChordNames");
2608 { parser->lexer_->push_lyric_state ();
2609 $$ = ly_symbol2scm ("Lyrics");
2614 CHANGE symbol '=' simple_string {
2615 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2622 $$ = scm_reverse_x ($1, SCM_EOL);
2628 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2631 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2633 | OVERRIDE revert_arg '=' scalar {
2634 if (scm_ilength ($2) < 2) {
2635 parser->parser_error (@2, _("bad grob property path"));
2638 $$ = scm_cons (ly_symbol2scm ("push"),
2639 scm_cons2 (scm_car ($2),
2644 | REVERT revert_arg {
2645 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2649 // This is all quite awkward for the sake of substantial backward
2650 // compatibility while at the same time allowing a more "natural" form
2651 // of specification not separating grob specification from grob
2652 // property path. The purpose of this definition of revert_arg is to
2653 // allow the symbol list which specifies grob and property to revert
2654 // to be optionally be split into two parts after the grob (which in
2655 // this case is just the first element of the list). symbol_list_part
2656 // is only one path component, but it can be parsed without lookahead,
2657 // so we can follow it with a synthetic BACKUP token when needed. If
2658 // the first symbol_list_part already contains multiple elements (only
2659 // possible if a Scheme expression provides them), we just parse for
2660 // additional elements introduced by '.', which is what the
2661 // SYMBOL_LIST backup in connection with the immediately following
2662 // rule using symbol_list_arg does.
2664 // As long as we don't have our coffers filled with both grob and at
2665 // least one grob property specification, the rest of the required
2666 // symbol list chain may be provided either with or without a leading
2667 // dot. This is for both allowing the traditional
2668 // \revert Accidental #'color
2669 // as well as well as the "naive" form
2670 // \revert Accidental.color
2673 revert_arg_backup BACKUP symbol_list_arg
2682 if (scm_is_null ($1)
2683 || scm_is_null (scm_cdr ($1)))
2684 MYBACKUP (SCM_ARG, $1, @1);
2686 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2690 // revert_arg_part delivers results in reverse
2693 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2695 $$ = scm_append_x (scm_list_2 ($5, $3));
2697 | revert_arg_backup BACKUP SCM_ARG ',' symbol_list_part
2699 $$ = scm_append_x (scm_list_2 ($5, $3));
2701 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2703 $$ = scm_append_x (scm_list_2 ($4, $3));
2708 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2709 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2711 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2712 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2713 | DENIES { $$ = ly_symbol2scm ("denies"); }
2715 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2716 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2717 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2718 | NAME { $$ = ly_symbol2scm ("context-name"); }
2722 property_operation { $$ = $1; }
2723 | context_def_mod STRING {
2724 $$ = scm_list_2 ($1, $2);
2726 | context_def_mod embedded_scm
2728 if (!scm_is_string ($2)
2729 && ly_symbol2scm ("consists") != $1
2730 && ly_symbol2scm ("remove") != $1)
2733 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2737 $$ = scm_list_2 ($1, $2);
2742 // If defined, at least two members.
2746 SCM l = scm_reverse_x ($1, SCM_EOL);
2749 (scm_object_property (scm_car (l),
2750 ly_symbol2scm ("is-grob?"))))
2751 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2752 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2753 parser->parser_error (@1, _ ("bad grob property path"));
2760 // If defined, at least three members
2764 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2766 parser->parser_error (@1, _ ("bad grob property path"));
2770 | grob_prop_spec property_path
2772 if (!SCM_UNBNDP ($1)) {
2773 $$ = scm_append_x (scm_list_2 ($1, $2));
2774 if (scm_is_null (scm_cddr ($$))) {
2775 parser->parser_error (@$, _ ("bad grob property path"));
2783 // Exactly two elements or undefined
2787 SCM l = scm_reverse_x ($1, SCM_EOL);
2788 switch (scm_ilength (l)) {
2790 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2794 parser->parser_error (@1, _ ("bad context property path"));
2802 // This is all quite awkward for the sake of substantial backward
2803 // compatibility while at the same time allowing a more "natural" form
2804 // of specification not separating grob specification from grob
2805 // property path. The purpose of this definition of
2806 // simple_revert_context is to allow the symbol list which specifies
2807 // grob and property to revert to be optionally be split into two
2808 // parts after the grob (which may be preceded by a context
2809 // specification, a case which we distinguish by checking whether the
2810 // first symbol is a valid grob symbol instead).
2812 // See revert_arg above for the main work horse of this arrangement.
2813 // simple_revert_context just caters for the context and delegates the
2814 // rest of the job to revert_arg.
2816 simple_revert_context:
2819 $1 = scm_reverse_x ($1, SCM_EOL);
2820 if (scm_is_null ($1)
2822 (scm_object_property (scm_car ($1),
2823 ly_symbol2scm ("is-grob?")))) {
2824 $$ = ly_symbol2scm ("Bottom");
2825 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2828 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2835 OVERRIDE grob_prop_path '=' scalar {
2836 if (SCM_UNBNDP ($2))
2837 $$ = MAKE_SYNTAX (void_music, @$);
2839 $$ = MAKE_SYNTAX (property_override, @$,
2844 | REVERT simple_revert_context revert_arg {
2845 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2847 | SET context_prop_spec '=' scalar {
2848 if (SCM_UNBNDP ($2))
2849 $$ = MAKE_SYNTAX (void_music, @$);
2851 $$ = MAKE_SYNTAX (property_set, @$,
2856 | UNSET context_prop_spec {
2857 if (SCM_UNBNDP ($2))
2858 $$ = MAKE_SYNTAX (void_music, @$);
2860 $$ = MAKE_SYNTAX (property_unset, @$,
2876 if (Text_interface::is_markup ($1)) {
2879 parser->parser_error (@1, (_ ("markup expected")));
2880 $$ = scm_string (SCM_EOL);
2885 simple_string: STRING
2888 if (scm_is_string ($1)) {
2891 parser->parser_error (@1, (_ ("simple string expected")));
2892 $$ = scm_string (SCM_EOL);
2899 $$ = scm_string_to_symbol ($1);
2903 // This is a bit of overkill but makes the same
2904 // routine responsible for all symbol interpretations.
2905 $$ = try_string_variants (Guile_user::symbol_p, $1);
2906 if (SCM_UNBNDP ($$))
2908 parser->parser_error (@1, (_ ("symbol expected")));
2909 // Generate a unique symbol in case it is used
2910 // for an assignment or similar
2911 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2921 // The following is a rather defensive variant of admitting
2922 // negative numbers: the grammar would permit number_factor or
2923 // even number_expression. However, function arguments allow
2924 // only this simple kind of negative number, so to have things
2925 // like \tweak and \override behave reasonably similar, it
2926 // makes sense to rule out things like -- which are rather an
2927 // accent in function argument contexts.
2930 $$ = scm_difference ($2, SCM_UNDEFINED);
2933 | symbol_list_part_bare '.' property_path
2935 $$ = scm_reverse_x ($1, $3);
2937 | symbol_list_part_bare ',' property_path
2939 $$ = scm_reverse_x ($1, $3);
2944 simple_element post_events {
2945 // Let the rhythmic music iterator sort this mess out.
2946 if (scm_is_pair ($2)) {
2947 unsmob<Music> ($$)->set_property ("articulations",
2948 scm_reverse_x ($2, SCM_EOL));
2951 | CHORD_REPETITION optional_notemode_duration post_events {
2953 i.set_location (@1, @3);
2954 $$ = MAKE_SYNTAX (repetition_chord, i,
2955 $2, scm_reverse_x ($3, SCM_EOL));
2957 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2959 i.set_location (@1, @3);
2960 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2961 scm_reverse_x ($3, SCM_EOL));
2964 | note_chord_element
2969 chord_body optional_notemode_duration post_events
2971 Music *m = unsmob<Music> ($1);
2972 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2973 SCM es = m->get_property ("elements");
2974 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2976 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2977 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2978 es = ly_append2 (es, postevs);
2980 m->set_property ("elements", es);
2981 m->set_spot (parser->lexer_->override_input (@$));
2982 $$ = m->self_scm ();
2987 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2989 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2991 | FIGURE_OPEN figure_list FIGURE_CLOSE
2993 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2997 chord_body_elements:
2998 /* empty */ { $$ = SCM_EOL; }
2999 | chord_body_elements chord_body_element {
3000 if (!SCM_UNBNDP ($2))
3001 $$ = scm_cons ($2, $1);
3006 pitch_or_tonic_pitch exclamations questions octave_check post_events
3008 bool q = to_boolean ($3);
3009 bool ex = to_boolean ($2);
3013 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3014 n->set_property ("pitch", $1);
3016 n->set_property ("cautionary", SCM_BOOL_T);
3018 n->set_property ("force-accidental", SCM_BOOL_T);
3020 if (scm_is_pair (post)) {
3021 SCM arts = scm_reverse_x (post, SCM_EOL);
3022 n->set_property ("articulations", arts);
3024 if (scm_is_number (check))
3026 int q = scm_to_int (check);
3027 n->set_property ("absolute-octave", scm_from_int (q-1));
3030 $$ = n->unprotect ();
3032 | DRUM_PITCH post_events {
3033 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3034 n->set_property ("drum-type", $1);
3036 if (scm_is_pair ($2)) {
3037 SCM arts = scm_reverse_x ($2, SCM_EOL);
3038 n->set_property ("articulations", arts);
3040 $$ = n->unprotect ();
3042 | music_function_chord_body
3044 Music *m = unsmob<Music> ($1);
3046 while (m && m->is_mus_type ("music-wrapper-music")) {
3047 $$ = m->get_property ("element");
3048 m = unsmob<Music> ($$);
3051 if (!(m && m->is_mus_type ("rhythmic-event"))) {
3052 parser->parser_error (@$, _ ("not a rhythmic event"));
3058 music_function_chord_body:
3064 event_function_event:
3065 EVENT_FUNCTION function_arglist {
3066 $$ = MAKE_SYNTAX (music_function, @$,
3075 | post_events post_event {
3077 if (Music *m = unsmob<Music> ($2))
3079 if (m->is_mus_type ("post-event-wrapper"))
3081 for (SCM p = m->get_property ("elements");
3085 $$ = scm_cons (scm_car (p), $$);
3088 m->set_spot (parser->lexer_->override_input (@2));
3089 $$ = scm_cons ($2, $$);
3095 post_event_nofinger:
3096 direction_less_event {
3099 | script_dir music_function_call {
3101 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
3102 parser->parser_error (@2, _ ("post-event expected"));
3103 $$ = SCM_UNSPECIFIED;
3104 } else if (!SCM_UNBNDP ($1))
3106 unsmob<Music> ($$)->set_property ("direction", $1);
3110 if (!parser->lexer_->is_lyric_state ())
3111 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3112 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
3115 if (!parser->lexer_->is_lyric_state ())
3116 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3117 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
3119 | script_dir direction_reqd_event {
3120 if (!SCM_UNBNDP ($1))
3122 Music *m = unsmob<Music> ($2);
3123 m->set_property ("direction", $1);
3127 | script_dir direction_less_event {
3128 if (!SCM_UNBNDP ($1))
3130 Music *m = unsmob<Music> ($2);
3131 m->set_property ("direction", $1);
3138 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
3143 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
3154 string_number_event:
3156 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3157 s->set_property ("string-number", $1);
3158 $$ = s->unprotect ();
3162 direction_less_event:
3164 | EVENT_IDENTIFIER {
3168 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3169 a->set_property ("tremolo-type", $1);
3170 $$ = a->unprotect ();
3172 | event_function_event
3175 direction_reqd_event:
3179 | script_abbreviation {
3180 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3181 if (scm_is_string (s)) {
3182 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3183 a->set_property ("articulation-type", s);
3184 $$ = a->unprotect ();
3186 Music *original = unsmob<Music> (s);
3187 if (original && original->is_mus_type ("post-event")) {
3188 Music *a = original->clone ();
3189 a->set_spot (parser->lexer_->override_input (@$));
3190 $$ = a->unprotect ();
3192 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3193 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3200 /**/ { $$ = SCM_EOL; }
3201 | '=' quotes { $$ = $2; }
3215 $$ = scm_from_int (1);
3218 $$ = scm_oneplus ($1);
3224 $$ = scm_from_int (-1);
3227 $$ = scm_oneminus ($1);
3232 NOTENAME_PITCH quotes {
3233 if (!scm_is_eq (SCM_INUM0, $2))
3235 Pitch p = *unsmob<Pitch> ($1);
3236 p = p.transposed (Pitch (scm_to_int ($2), 0));
3237 $$ = p.smobbed_copy ();
3247 TONICNAME_PITCH quotes {
3248 if (!scm_is_eq (SCM_INUM0, $2))
3250 Pitch p = *unsmob<Pitch> ($1);
3251 p = p.transposed (Pitch (scm_to_int ($2), 0));
3252 $$ = p.smobbed_copy ();
3259 | PITCH_IDENTIFIER quotes {
3260 if (!scm_is_eq (SCM_INUM0, $2))
3262 Pitch p = *unsmob<Pitch> ($1);
3263 p = p.transposed (Pitch (scm_to_int ($2), 0));
3264 $$ = p.smobbed_copy ();
3269 pitch_or_tonic_pitch:
3276 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3277 t->set_property ("text", $1);
3278 $$ = t->unprotect ();
3281 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3282 t->set_property ("text",
3283 make_simple_markup ($1));
3284 $$ = t->unprotect ();
3288 Music *m = unsmob<Music> ($1);
3289 if (m && m->is_mus_type ("post-event"))
3291 else if (Text_interface::is_markup ($1)) {
3292 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3293 t->set_property ("text", $1);
3294 $$ = t->unprotect ();
3296 parser->parser_error (@1, _ ("not an articulation"));
3302 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3303 t->set_property ("digit", $1);
3304 $$ = t->unprotect ();
3308 script_abbreviation:
3310 $$ = scm_from_ascii_string ("Hat");
3313 $$ = scm_from_ascii_string ("Plus");
3316 $$ = scm_from_ascii_string ("Dash");
3319 $$ = scm_from_ascii_string ("Bang");
3322 $$ = scm_from_ascii_string ("Larger");
3325 $$ = scm_from_ascii_string ("Dot");
3328 $$ = scm_from_ascii_string ("Underscore");
3333 '_' { $$ = scm_from_int (DOWN); }
3334 | '^' { $$ = scm_from_int (UP); }
3335 | '-' { $$ = SCM_UNDEFINED; }
3338 maybe_notemode_duration:
3342 | multiplied_duration {
3344 parser->default_duration_ = *unsmob<Duration> ($$);
3349 optional_notemode_duration:
3350 maybe_notemode_duration
3352 if (SCM_UNBNDP ($$))
3353 $$ = parser->default_duration_.smobbed_copy ();
3359 $$ = make_duration ($1, scm_to_int ($2));
3360 if (SCM_UNBNDP ($$))
3362 parser->parser_error (@1, _ ("not a duration"));
3363 $$ = Duration ().smobbed_copy ();
3366 | DURATION_IDENTIFIER dots {
3367 $$ = make_duration ($1, scm_to_int ($2));
3371 multiplied_duration:
3372 steno_duration multipliers {
3373 $$ = make_duration ($1, 0, $2);
3382 $$ = scm_oneplus ($1);
3391 | multipliers '*' UNSIGNED
3393 if (!SCM_UNBNDP ($1))
3394 $$ = scm_product ($1, $3);
3398 | multipliers '*' FRACTION
3400 if (!SCM_UNBNDP ($1))
3401 $$ = scm_product ($1, scm_divide (scm_car ($3),
3404 $$ = scm_divide (scm_car ($3), scm_cdr ($3));
3410 $$ = scm_from_int (parser->default_tremolo_type_);
3413 if (SCM_UNBNDP (make_duration ($2))) {
3414 parser->parser_error (@2, _ ("not a duration"));
3415 $$ = scm_from_int (parser->default_tremolo_type_);
3418 parser->default_tremolo_type_ = scm_to_int ($2);
3424 UNSIGNED { $$ = $1; }
3425 | STRING { $$ = $1; }
3426 | full_markup { $$ = $1; }
3429 // as an integer, it needs to be non-negative, and otherwise
3430 // it needs to be suitable as a markup.
3431 if (scm_is_integer ($1)
3432 ? scm_is_true (scm_negative_p ($1))
3433 : !Text_interface::is_markup ($1))
3435 parser->parser_error (@1, _ ("bass number expected"));
3441 figured_bass_alteration:
3442 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3443 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3444 | '!' { $$ = scm_from_int (0); }
3449 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3450 $$ = bfr->unprotect ();
3453 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3454 $$ = bfr->self_scm ();
3456 if (scm_is_number ($1))
3457 bfr->set_property ("figure", $1);
3458 else if (Text_interface::is_markup ($1))
3459 bfr->set_property ("text", $1);
3465 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3467 | bass_figure figured_bass_alteration {
3468 Music *m = unsmob<Music> ($1);
3469 if (scm_to_double ($2)) {
3470 SCM salter = m->get_property ("alteration");
3471 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3472 m->set_property ("alteration",
3473 scm_sum (alter, $2));
3475 m->set_property ("alteration", scm_from_int (0));
3478 | bass_figure figured_bass_modification {
3479 Music *m = unsmob<Music> ($1);
3480 m->set_property ($2, SCM_BOOL_T);
3485 figured_bass_modification:
3487 $$ = ly_symbol2scm ("augmented");
3490 $$ = ly_symbol2scm ("no-continuation");
3493 $$ = ly_symbol2scm ("diminished");
3496 $$ = ly_symbol2scm ("augmented-slash");
3506 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3514 | figure_list br_bass_figure {
3515 $$ = scm_cons ($2, $1);
3520 /**/ { $$ = SCM_BOOL_F; }
3521 | REST { $$ = SCM_BOOL_T; }
3525 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3526 if (!parser->lexer_->is_note_state ())
3527 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3528 if (!SCM_UNBNDP ($2)
3530 || scm_is_number ($4)
3533 || scm_is_pair ($7))
3536 if (scm_is_true ($6))
3537 n = MY_MAKE_MUSIC ("RestEvent", @$);
3539 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3541 n->set_property ("pitch", $1);
3542 if (SCM_UNBNDP ($5))
3543 n->set_property ("duration",
3544 parser->default_duration_.smobbed_copy ());
3546 n->set_property ("duration", $5);
3548 if (scm_is_number ($4))
3550 int q = scm_to_int ($4);
3551 n->set_property ("absolute-octave", scm_from_int (q-1));
3554 if (to_boolean ($3))
3555 n->set_property ("cautionary", SCM_BOOL_T);
3556 if (to_boolean ($2) || to_boolean ($3))
3557 n->set_property ("force-accidental", SCM_BOOL_T);
3558 if (scm_is_pair ($7))
3559 n->set_property ("articulations",
3560 scm_reverse_x ($7, SCM_EOL));
3561 $$ = n->unprotect ();
3564 | new_chord post_events {
3565 if (!parser->lexer_->is_chord_state ())
3566 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3567 if (scm_is_pair ($2)) {
3568 if (unsmob<Pitch> ($1))
3569 $1 = make_chord_elements (@1,
3571 parser->default_duration_.smobbed_copy (),
3574 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3576 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3577 } else if (!unsmob<Pitch> ($1))
3578 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3579 // A mere pitch drops through.
3584 DRUM_PITCH optional_notemode_duration {
3585 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3586 n->set_property ("duration", $2);
3587 n->set_property ("drum-type", $1);
3589 $$ = n->unprotect ();
3591 | RESTNAME optional_notemode_duration {
3593 if (ly_scm2string ($1) == "s") {
3595 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3598 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3601 ev->set_property ("duration", $2);
3602 $$ = ev->unprotect ();
3608 if (!parser->lexer_->is_lyric_state ())
3609 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3613 if (!parser->lexer_->is_lyric_state ())
3614 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3620 lyric_element_music:
3621 lyric_element optional_notemode_duration post_events {
3622 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3623 if (scm_is_pair ($3))
3624 unsmob<Music> ($$)->set_property
3625 ("articulations", scm_reverse_x ($3, SCM_EOL));
3629 // Can return a single pitch rather than a list.
3631 steno_tonic_pitch maybe_notemode_duration {
3632 if (SCM_UNBNDP ($2))
3635 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3637 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3638 SCM its = scm_reverse_x ($4, SCM_EOL);
3639 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3647 | chord_items chord_item {
3648 $$ = scm_cons ($2, $$);
3654 $$ = ly_symbol2scm ("chord-colon");
3657 $$ = ly_symbol2scm ("chord-caret");
3659 | CHORD_SLASH steno_tonic_pitch {
3660 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3662 | CHORD_BASS steno_tonic_pitch {
3663 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3672 $$ = scm_reverse_x ($1, SCM_EOL);
3680 step_number { $$ = scm_cons ($1, SCM_EOL); }
3681 | step_numbers '.' step_number {
3682 $$ = scm_cons ($3, $$);
3688 $$ = make_chord_step ($1, 0);
3691 $$ = make_chord_step ($1, SHARP_ALTERATION);
3693 | UNSIGNED CHORD_MINUS {
3694 $$ = make_chord_step ($1, FLAT_ALTERATION);
3702 | unsigned_number '-' unsigned_number {
3703 $$ = scm_cons ($1, $3);
3710 TODO: should deprecate in favor of Scheme?
3714 number_expression '+' number_term {
3715 $$ = scm_sum ($1, $3);
3717 | number_expression '-' number_term {
3718 $$ = scm_difference ($1, $3);
3727 | number_factor '*' number_factor {
3728 $$ = scm_product ($1, $3);
3730 | number_factor '/' number_factor {
3731 $$ = scm_divide ($1, $3);
3736 '-' number_factor { /* %prec UNARY_MINUS */
3737 $$ = scm_difference ($2, SCM_UNDEFINED);
3745 | REAL NUMBER_IDENTIFIER
3747 $$ = scm_product ($1, $2);
3754 | UNSIGNED NUMBER_IDENTIFIER {
3755 $$ = scm_product ($1, $2);
3763 if (!scm_is_integer ($1)
3764 || scm_is_true (scm_negative_p ($1)))
3766 parser->parser_error (@1, _("not an unsigned integer"));
3772 if (!scm_is_integer ($1)
3773 || scm_is_true (scm_negative_p ($1)))
3775 parser->parser_error (@1, _("not an unsigned integer"));
3782 { $$ = SCM_UNDEFINED; }
3785 if (SCM_UNBNDP ($1))
3793 // This precedence rule is rather weird. It triggers when '!' is
3794 // encountered after a pitch, and is used for deciding whether to save
3795 // this instead for a figure modification. This should not actually
3796 // occur in practice as pitches and figures are generated in different
3797 // modes. Using a greedy (%right) precedence makes sure that we don't
3798 // get stuck in a wrong interpretation.
3799 { $$ = SCM_UNDEFINED; } %prec ':'
3802 if (SCM_UNBNDP ($1))
3811 { parser->lexer_->push_markup_state (); }
3814 parser->lexer_->pop_state ();
3821 parser->lexer_->push_markup_state ();
3826 markup_mode markup_top {
3828 parser->lexer_->pop_state ();
3833 markup_mode markup_partial_function ETC
3835 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3836 parser->lexer_->pop_state ();
3842 $$ = scm_list_2 (Lily::line_markup, $1);
3844 | markup_head_1_list simple_markup
3846 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3847 @2, $1, scm_list_1 ($2)));
3857 if (Text_interface::is_markup ($1))
3858 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3859 else if (Text_interface::is_markup_list ($1))
3860 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3862 parser->parser_error (@1, _ ("not a markup"));
3863 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3870 markup_composed_list {
3873 | markup_uncomposed_list
3876 markup_uncomposed_list:
3877 markup_braced_list {
3880 | markup_command_list {
3881 $$ = scm_list_1 ($1);
3883 | markup_scm MARKUPLIST_IDENTIFIER
3888 parser->lexer_->push_note_state (Lily::pitchnames);
3889 } '{' score_body '}' {
3890 Score *sc = unsmob<Score> ($4);
3891 sc->origin ()->set_spot (@$);
3892 if (sc->defs_.empty ()) {
3893 Output_def *od = get_layout (parser);
3894 sc->add_output_def (od);
3897 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3898 parser->lexer_->pop_state ();
3902 markup_composed_list:
3903 markup_head_1_list markup_uncomposed_list {
3904 $$ = MAKE_SYNTAX (composed_markup_list,
3910 '{' markup_braced_list_body '}' {
3911 $$ = scm_reverse_x ($2, SCM_EOL);
3915 markup_braced_list_body:
3916 /* empty */ { $$ = SCM_EOL; }
3917 | markup_braced_list_body markup {
3918 $$ = scm_cons ($2, $1);
3920 | markup_braced_list_body markup_list {
3921 $$ = scm_reverse_x ($2, $1);
3925 markup_command_list:
3926 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3927 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3931 markup_command_basic_arguments:
3932 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3933 $$ = scm_cons ($3, $2);
3935 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3936 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3938 | EXPECT_NO_MORE_ARGS {
3943 markup_command_list_arguments:
3944 markup_command_basic_arguments { $$ = $1; }
3945 | EXPECT_MARKUP markup_command_list_arguments markup {
3946 $$ = scm_cons ($3, $2);
3950 markup_partial_function:
3951 MARKUP_FUNCTION markup_arglist_partial
3953 $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
3955 | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
3957 $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
3962 markup_arglist_partial:
3963 EXPECT_MARKUP markup_arglist_partial
3967 | EXPECT_SCM markup_arglist_partial
3971 | EXPECT_MARKUP markup_command_list_arguments
3975 | EXPECT_SCM markup_command_list_arguments
3982 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3983 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3988 markup_head_1_item {
3989 $$ = scm_list_1 ($1);
3991 | markup_head_1_list markup_head_1_item {
3992 $$ = scm_cons ($2, $1);
3998 $$ = make_simple_markup ($1);
4001 parser->lexer_->push_note_state (Lily::pitchnames);
4002 } '{' score_body '}' {
4003 Score *sc = unsmob<Score> ($4);
4004 sc->origin ()->set_spot (@$);
4005 if (sc->defs_.empty ()) {
4006 Output_def *od = get_layout (parser);
4007 sc->add_output_def (od);
4010 $$ = scm_list_2 (Lily::score_markup, $4);
4011 parser->lexer_->pop_state ();
4013 | MARKUP_FUNCTION markup_command_basic_arguments {
4014 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
4016 | markup_scm MARKUP_IDENTIFIER
4023 markup_head_1_list simple_markup
4025 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
4026 @2, $1, scm_list_1 ($2)));
4036 Lily_parser::set_yydebug (bool x)
4042 Lily_parser::do_yyparse ()
4044 return scm_c_with_fluid (Lily::f_parser,
4046 do_yyparse_trampoline,
4047 static_cast <void *>(this));
4051 Lily_parser::do_yyparse_trampoline (void *parser)
4053 SCM retval = SCM_UNDEFINED;
4054 yyparse (static_cast <Lily_parser *>(parser), &retval);
4062 It is a little strange to have this function in this file, but
4063 otherwise, we have to import music classes into the lexer.
4067 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
4069 if (unsmob<Book> (sid)) {
4070 Book *book = unsmob<Book> (sid)->clone ();
4071 *destination = book->self_scm ();
4074 return BOOK_IDENTIFIER;
4075 } else if (scm_is_number (sid)) {
4077 return NUMBER_IDENTIFIER;
4078 } else if (unsmob<Context_def> (sid))
4080 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
4081 return SCM_IDENTIFIER;
4082 } else if (unsmob<Context_mod> (sid)) {
4083 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
4084 return CONTEXT_MOD_IDENTIFIER;
4085 } else if (Music *mus = unsmob<Music> (sid)) {
4086 mus = mus->clone ();
4087 *destination = mus->self_scm ();
4088 bool is_event = mus->is_mus_type ("post-event");
4090 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
4091 } else if (unsmob<Pitch> (sid)) {
4092 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
4093 return PITCH_IDENTIFIER;
4094 } else if (unsmob<Duration> (sid)) {
4095 *destination = unsmob<Duration> (sid)->smobbed_copy ();
4096 return DURATION_IDENTIFIER;
4097 } else if (unsmob<Output_def> (sid)) {
4098 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
4099 return SCM_IDENTIFIER;
4100 } else if (unsmob<Score> (sid)) {
4101 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
4102 return SCM_IDENTIFIER;
4103 } else if (scm_is_pair (sid)
4104 && scm_is_pair (scm_car (sid))
4105 && scm_is_true (Lily::key_p (scm_caar (sid)))) {
4107 return LOOKUP_IDENTIFIER;
4113 get_next_unique_context_id ()
4115 return scm_from_ascii_string ("$uniqueContextId");
4120 get_next_unique_lyrics_context_id ()
4122 static int new_context_count;
4124 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
4125 return scm_from_ascii_string (s);
4128 // check_scheme_arg checks one argument with a given predicate for use
4129 // in an argument list and throws a syntax error if it is unusable.
4130 // The argument is prepended to the argument list in any case. After
4131 // throwing a syntax error, the argument list is terminated with #f as
4132 // its last cdr in order to mark it as uncallable while not losing
4133 // track of its total length.
4135 // There are a few special considerations: if optional argument disp
4136 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
4137 // instead of arg in a prospective error message. This is useful if
4138 // arg is not the actual argument but rather a transformation of it.
4140 // If arg itself is SCM_UNDEFINED, the predicate is considered false
4141 // and an error message using disp is produced unconditionally.
4143 SCM check_scheme_arg (Lily_parser *parser, Input loc,
4144 SCM arg, SCM args, SCM pred, SCM disp)
4146 if (SCM_UNBNDP (arg))
4147 args = scm_cons (disp, args);
4149 args = scm_cons (arg, args);
4150 if (scm_is_true (scm_call_1 (pred, arg)))
4153 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
4154 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
4155 SCM_UNBNDP (disp) ? arg : disp);
4156 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
4160 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
4162 if (Music *m = unsmob<Music> (arg))
4165 m->set_spot (parser->lexer_->override_input (loc));
4166 return m->unprotect ();
4172 try_string_variants (SCM pred, SCM str)
4174 // a matching predicate is always ok
4175 if (scm_is_true (scm_call_1 (pred, str)))
4177 // a symbol may be interpreted as a list of symbols if it helps
4178 if (scm_is_true (Lily::key_p (str))) {
4179 str = scm_list_1 (str);
4180 if (scm_is_true (scm_call_1 (pred, str)))
4182 return SCM_UNDEFINED;
4185 // If this cannot be a string representation of a symbol list,
4188 if (!is_regular_identifier (str, true))
4189 return SCM_UNDEFINED;
4191 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4192 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4193 scm_set_car_x (p, scm_string_split (scm_car (p),
4194 SCM_MAKE_CHAR (',')));
4195 str = scm_append_x (str);
4196 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4197 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4199 // Let's attempt the symbol list interpretation first.
4201 if (scm_is_true (scm_call_1 (pred, str)))
4204 // If there is just one symbol in the list, we might interpret
4205 // it as a single symbol
4207 if (scm_is_null (scm_cdr (str)))
4209 str = scm_car (str);
4210 if (scm_is_true (scm_call_1 (pred, str)))
4214 return SCM_UNDEFINED;
4218 is_regular_identifier (SCM id, bool multiple)
4220 if (!scm_is_string (id))
4223 string str = ly_scm2string (id);
4225 bool middle = false;
4227 for (string::iterator it=str.begin(); it != str.end (); it++)
4230 if ((c >= 'a' && c <= 'z')
4231 || (c >= 'A' && c <= 'Z')
4234 else if (middle && (c == '-' || c == '_' || (multiple &&
4235 (c == '.' || c == ','))))
4244 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4246 if (unsmob<Music> (simple))
4248 if (parser->lexer_->is_note_state ()) {
4249 if (scm_is_symbol (simple)) {
4250 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4251 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4252 n->set_property ("drum-type", simple);
4253 return n->unprotect ();
4255 if (unsmob<Pitch> (simple)) {
4256 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4257 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4258 n->set_property ("pitch", simple);
4259 return n->unprotect ();
4262 if (scm_is_integer (simple))
4263 d = make_duration (simple);
4264 if (unsmob<Duration> (d)) {
4265 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4266 n->set_property ("duration", d);
4267 return n->unprotect ();
4270 } else if (parser->lexer_->is_lyric_state ()) {
4271 if (Text_interface::is_markup (simple))
4272 return MAKE_SYNTAX (lyric_event, loc, simple,
4273 parser->default_duration_.smobbed_copy ());
4274 } else if (parser->lexer_->is_chord_state ()) {
4275 if (unsmob<Pitch> (simple))
4279 make_chord_elements (loc, simple,
4280 parser->default_duration_.smobbed_copy (),
4287 make_music_with_input (SCM name, Input where)
4289 Music *m = make_music_by_name (name);
4290 m->set_spot (where);
4295 make_simple_markup (SCM a)
4301 make_duration (SCM d, int dots, SCM factor)
4305 if (Duration *dur = unsmob<Duration> (d)) {
4306 if (!dots && SCM_UNBNDP (factor))
4310 k = Duration (k.duration_log (), k.dot_count () + dots)
4311 .compressed (k.factor ());
4313 int t = scm_to_int (d);
4314 if (t > 0 && (t & (t-1)) == 0)
4315 k = Duration (intlog2 (t), dots);
4317 return SCM_UNDEFINED;
4320 if (!SCM_UNBNDP (factor))
4321 k = k.compressed (ly_scm2rational (factor));
4323 return k.smobbed_copy ();
4327 make_chord_step (SCM step_scm, Rational alter)
4329 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4331 // Notename/octave are normalized
4332 if (m.get_notename () == 6)
4333 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4335 return m.smobbed_copy ();
4340 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4342 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4343 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4345 unsmob<Music> (scm_car (s))->set_spot (loc);
4351 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4353 Lily_lexer *lex = parser->lexer_;
4357 int tok = lex->pop_extra_token ();
4360 lex->prepare_for_next_token ();
4361 return lex->yylex ();