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_->add_scope (get_header (parser));
415 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
418 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
419 scm_call_1 (proc, $1);
422 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
423 scm_call_1 (proc, $1);
426 SCM proc = parser->lexer_->lookup_identifier
427 (unsmob<Book>($1)->paper_
428 ? "toplevel-book-handler"
429 : "toplevel-bookpart-handler");
430 scm_call_1 (proc, $1);
433 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
434 scm_call_1 (proc, $1);
437 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
438 scm_call_1 (proc, $1);
441 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
442 scm_call_1 (proc, scm_list_1 ($1));
445 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
446 scm_call_1 (proc, $1);
449 // Evaluate and ignore #xxx, as opposed to \xxx
450 parser->lexer_->eval_scm_token ($1, @1);
452 | embedded_scm_active
454 SCM out = SCM_UNDEFINED;
455 if (Text_interface::is_markup ($1))
456 out = scm_list_1 ($1);
457 else if (Text_interface::is_markup_list ($1))
459 if (scm_is_pair (out))
461 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
462 scm_call_1 (proc, out);
463 } else if (unsmob<Score> ($1))
465 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
466 scm_call_1 (proc, $1);
467 } else if (Output_def * od = unsmob<Output_def> ($1)) {
470 if (to_boolean (od->c_variable ("is-paper")))
471 id = ly_symbol2scm ("$defaultpaper");
472 else if (to_boolean (od->c_variable ("is-midi")))
473 id = ly_symbol2scm ("$defaultmidi");
474 else if (to_boolean (od->c_variable ("is-layout")))
475 id = ly_symbol2scm ("$defaultlayout");
477 parser->lexer_->set_identifier (id, $1);
478 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
479 parser->parser_error (@1, _("bad expression type"));
483 Output_def * od = unsmob<Output_def> ($1);
485 if (to_boolean (od->c_variable ("is-paper")))
486 id = ly_symbol2scm ("$defaultpaper");
487 else if (to_boolean (od->c_variable ("is-midi")))
488 id = ly_symbol2scm ("$defaultmidi");
489 else if (to_boolean (od->c_variable ("is-layout")))
490 id = ly_symbol2scm ("$defaultlayout");
492 parser->lexer_->set_identifier (id, $1);
498 | LOOKUP_IDENTIFIER '.' symbol_list_rev
500 $$ = loc_on_music (parser, @$,
501 nested_property ($1, scm_reverse_x ($3, SCM_EOL)));
508 $$ = parser->lexer_->eval_scm_token ($1, @1);
519 embedded_scm_bare_arg:
523 $$ = parser->lexer_->eval_scm_token ($1, @1);
528 | context_modification
530 | context_def_spec_block
537 /* The generic version may end in music, or not */
545 /* embedded_scm_arg is _not_ casting pitches to music by default, this
546 * has to be done by the function itself. Note that this may cause
547 * the results of scm_function_call or embedded_scm_bare_arg to be
548 * turned into music from pitches as well. Note that this creates a
549 * distinctly awkward situation for calculated drum pitches. Those
550 * are at the current point of time rejected as music constituents as
551 * they can't be distinguished from "proper" symbols.
555 embedded_scm_bare_arg
561 SCM_FUNCTION function_arglist {
562 $$ = MAKE_SYNTAX (music_function, @$,
567 embedded_lilypond_number:
568 '-' embedded_lilypond_number
570 $$ = scm_difference ($2, SCM_UNDEFINED);
573 | UNSIGNED NUMBER_IDENTIFIER
575 $$ = scm_product ($1, $2);
582 // FIXME: @$ does not contain a useful source location
583 // for empty rules, and the only token in the whole
584 // production, EMBEDDED_LILY, is synthetic and also
585 // contains no source location.
586 $$ = MAKE_SYNTAX (void_music, @$);
588 | identifier_init_nonumber
589 | embedded_lilypond_number
590 | post_event post_events
592 $$ = scm_reverse_x ($2, SCM_EOL);
593 if (Music *m = unsmob<Music> ($1))
595 if (m->is_mus_type ("post-event-wrapper"))
597 (scm_list_2 (m->get_property ("elements"),
600 $$ = scm_cons ($1, $$);
603 && scm_is_null (scm_cdr ($$)))
607 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
608 m->set_property ("elements", $$);
609 $$ = m->unprotect ();
612 | multiplied_duration
613 | music_embedded music_embedded music_list {
614 $3 = scm_reverse_x ($3, SCM_EOL);
615 if (unsmob<Music> ($2))
616 $3 = scm_cons ($2, $3);
617 if (unsmob<Music> ($1))
618 $3 = scm_cons ($1, $3);
619 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
622 parser->error_level_ = 1;
623 $$ = SCM_UNSPECIFIED;
625 | INVALID embedded_lilypond {
626 parser->error_level_ = 1;
632 lilypond_header_body:
633 /* empty */ { $$ = SCM_UNSPECIFIED; }
634 | lilypond_header_body assignment {
637 | lilypond_header_body embedded_scm {
643 HEADER '{' lilypond_header_body '}' {
644 $$ = parser->lexer_->remove_scope ();
656 assignment_id '=' identifier_init {
657 parser->lexer_->set_identifier ($1, $3);
658 $$ = SCM_UNSPECIFIED;
660 | assignment_id '.' property_path '=' identifier_init {
661 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
662 parser->lexer_->set_identifier (path, $5);
663 $$ = SCM_UNSPECIFIED;
665 | assignment_id ',' property_path '=' identifier_init {
666 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
667 parser->lexer_->set_identifier (path, $5);
668 $$ = SCM_UNSPECIFIED;
674 identifier_init_nonumber
676 | symbol_list_part_bare '.' property_path
678 $$ = scm_reverse_x ($1, $3);
680 | symbol_list_part_bare ',' property_path
682 $$ = scm_reverse_x ($1, $3);
684 | post_event_nofinger post_events
686 $$ = scm_reverse_x ($2, SCM_EOL);
687 if (Music *m = unsmob<Music> ($1))
689 if (m->is_mus_type ("post-event-wrapper"))
691 (scm_list_2 (m->get_property ("elements"),
694 $$ = scm_cons ($1, $$);
697 && scm_is_null (scm_cdr ($$)))
701 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
702 m->set_property ("elements", $$);
703 $$ = m->unprotect ();
708 identifier_init_nonumber:
713 | context_def_spec_block
721 | context_modification
722 | partial_function ETC
724 $$ = MAKE_SYNTAX (partial_music_function, @$,
725 scm_reverse_x ($1, SCM_EOL));
731 MUSIC_FUNCTION function_arglist_partial
733 $$ = scm_acons ($1, $2, SCM_EOL);
735 | EVENT_FUNCTION function_arglist_partial
737 $$ = scm_acons ($1, $2, SCM_EOL);
739 | SCM_FUNCTION function_arglist_partial
741 $$ = scm_acons ($1, $2, SCM_EOL);
743 | OVERRIDE grob_prop_path '='
746 $$ = scm_list_1 (SCM_BOOL_F);
749 (scm_list_3 (Syntax::property_override_function,
750 scm_cdr ($2), scm_car ($2)),
753 | SET context_prop_spec '='
756 $$ = scm_list_1 (SCM_BOOL_F);
759 (scm_list_3 (Syntax::property_set_function,
760 scm_cadr ($2), scm_car ($2)),
763 | MUSIC_FUNCTION EXPECT_SCM function_arglist_optional partial_function
765 $$ = scm_acons ($1, $3, $4);
767 | EVENT_FUNCTION EXPECT_SCM function_arglist_optional partial_function
769 $$ = scm_acons ($1, $3, $4);
771 | SCM_FUNCTION EXPECT_SCM function_arglist_optional partial_function
773 $$ = scm_acons ($1, $3, $4);
775 | OVERRIDE grob_prop_path '=' partial_function
778 $$ = scm_list_1 (SCM_BOOL_F);
781 (scm_list_3 (Syntax::property_override_function,
782 scm_cdr ($2), scm_car ($2)),
785 | SET context_prop_spec '=' partial_function
788 $$ = scm_list_1 (SCM_BOOL_F);
791 (scm_list_3 (Syntax::property_set_function,
792 scm_cadr ($2), scm_car ($2)),
795 | MUSIC_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
797 $$ = scm_acons ($1, $4, $5);
799 | EVENT_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
801 $$ = scm_acons ($1, $4, $5);
803 | SCM_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
805 $$ = scm_acons ($1, $4, $5);
809 context_def_spec_block:
810 CONTEXT '{' context_def_spec_body '}'
813 Context_def *td = unsmob<Context_def> ($$);
815 $$ = Context_def::make_scm ();
816 td = unsmob<Context_def> ($$);
818 td->origin ()->set_spot (@$);
826 parser->lexer_->push_note_state (Lily::pitchnames);
830 parser->lexer_->pop_state ();
836 context_def_spec_body:
838 $$ = SCM_UNSPECIFIED;
840 | context_def_spec_body context_mod {
841 if (!SCM_UNBNDP ($2)) {
842 Context_def *td = unsmob<Context_def> ($$);
844 $$ = Context_def::make_scm ();
845 td = unsmob<Context_def> ($$);
847 unsmob<Context_def> ($$)->add_context_mod ($2);
850 | context_def_spec_body context_modification {
851 Context_def *td = unsmob<Context_def> ($$);
853 $$ = Context_def::make_scm ();
854 td = unsmob<Context_def> ($$);
856 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
857 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
858 td->add_context_mod (scm_car (m));
861 | context_def_spec_body context_mod_arg {
862 Context_def *td = unsmob<Context_def> ($1);
863 if (scm_is_eq ($2, SCM_UNSPECIFIED))
865 else if (!td && unsmob<Context_def> ($2))
869 $$ = Context_def::make_scm ();
870 td = unsmob<Context_def> ($$);
872 if (unsmob<Music> ($2)) {
873 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
874 $2 = scm_call_1 (proc, $2);
876 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
877 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
878 td->add_context_mod (scm_car (m));
881 parser->parser_error (@2, _ ("not a context mod"));
889 BOOK '{' book_body '}' {
891 unsmob<Book> ($$)->origin ()->set_spot (@$);
893 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
898 * Use 'handlers' like for toplevel-* stuff?
899 * grok \layout and \midi? */
902 Book *book = new Book;
903 init_papers (parser);
904 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
905 book->paper_->unprotect ();
906 push_paper (parser, book->paper_);
907 book->header_ = get_header (parser);
908 $$ = book->unprotect ();
909 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
912 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
914 | book_body paper_block {
915 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
916 set_paper (parser, unsmob<Output_def> ($2));
918 | book_body bookpart_block {
919 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
920 scm_call_2 (proc, $1, $2);
922 | book_body score_block {
923 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
924 scm_call_2 (proc, $1, $2);
926 | book_body composite_music {
927 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
928 scm_call_2 (proc, $1, $2);
930 | book_body full_markup {
931 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
932 scm_call_2 (proc, $1, scm_list_1 ($2));
934 | book_body full_markup_list {
935 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
936 scm_call_2 (proc, $1, $2);
938 | book_body SCM_TOKEN {
939 // Evaluate and ignore #xxx, as opposed to \xxx
940 parser->lexer_->eval_scm_token ($2, @2);
942 | book_body embedded_scm_active
944 SCM out = SCM_UNDEFINED;
945 if (Text_interface::is_markup ($2))
946 out = scm_list_1 ($2);
947 else if (Text_interface::is_markup_list ($2))
949 if (scm_is_pair (out))
951 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
952 scm_call_2 (proc, $1, out);
953 } else if (unsmob<Score> ($2))
955 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
956 scm_call_2 (proc, $1, $2);
957 } else if (Output_def *od = unsmob<Output_def> ($2)) {
960 if (to_boolean (od->c_variable ("is-paper")))
961 id = ly_symbol2scm ("$defaultpaper");
962 else if (to_boolean (od->c_variable ("is-midi")))
963 id = ly_symbol2scm ("$defaultmidi");
964 else if (to_boolean (od->c_variable ("is-layout")))
965 id = ly_symbol2scm ("$defaultlayout");
967 parser->lexer_->set_identifier (id, $2);
968 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
969 parser->parser_error (@2, _("bad expression type"));
973 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
976 Book *book = unsmob<Book> ($1);
978 book->scores_ = SCM_EOL;
979 book->bookparts_ = SCM_EOL;
984 BOOKPART '{' bookpart_body '}' {
986 unsmob<Book> ($$)->origin ()->set_spot (@$);
987 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
993 Book *book = new Book;
994 $$ = book->unprotect ();
995 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
998 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
1000 | bookpart_body paper_block {
1001 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
1003 | bookpart_body score_block {
1004 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1005 scm_call_2 (proc, $1, $2);
1007 | bookpart_body composite_music {
1008 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
1009 scm_call_2 (proc, $1, $2);
1011 | bookpart_body full_markup {
1012 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1013 scm_call_2 (proc, $1, scm_list_1 ($2));
1015 | bookpart_body full_markup_list {
1016 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1017 scm_call_2 (proc, $1, $2);
1019 | bookpart_body SCM_TOKEN {
1020 // Evaluate and ignore #xxx, as opposed to \xxx
1021 parser->lexer_->eval_scm_token ($2, @2);
1023 | bookpart_body embedded_scm_active
1025 SCM out = SCM_UNDEFINED;
1026 if (Text_interface::is_markup ($2))
1027 out = scm_list_1 ($2);
1028 else if (Text_interface::is_markup_list ($2))
1030 if (scm_is_pair (out))
1032 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1033 scm_call_2 (proc, $1, out);
1034 } else if (unsmob<Score> ($2))
1036 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1037 scm_call_2 (proc, $1, $2);
1038 } else if (Output_def *od = unsmob<Output_def> ($2)) {
1041 if (to_boolean (od->c_variable ("is-paper")))
1042 id = ly_symbol2scm ("$defaultpaper");
1043 else if (to_boolean (od->c_variable ("is-midi")))
1044 id = ly_symbol2scm ("$defaultmidi");
1045 else if (to_boolean (od->c_variable ("is-layout")))
1046 id = ly_symbol2scm ("$defaultlayout");
1048 parser->lexer_->set_identifier (id, $2);
1049 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1050 parser->parser_error (@2, _("bad expression type"));
1054 Book *book = unsmob<Book> ($1);
1055 if (!ly_is_module (book->header_))
1056 book->header_ = ly_make_module (false);
1057 parser->lexer_->add_scope (book->header_);
1059 | bookpart_body error {
1060 Book *book = unsmob<Book> ($1);
1062 book->scores_ = SCM_EOL;
1067 SCORE '{' score_body '}' {
1068 unsmob<Score> ($3)->origin ()->set_spot (@$);
1075 if (!unsmob<Score> ($1)) {
1076 parser->parser_error (@1, _("Missing music in \\score"));
1077 $$ = (new Score)->unprotect ();
1078 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
1080 unsmob<Score> ($$)->set_header (scm_car ($1));
1083 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1084 scm_is_pair (p); p = scm_cdr (p))
1086 unsmob<Score> ($$)->
1087 add_output_def (unsmob<Output_def> (scm_car (p)));
1091 | score_body error {
1092 unsmob<Score> ($$)->error_found_ = true;
1107 | score_items score_item
1109 Output_def *od = unsmob<Output_def> ($2);
1111 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1113 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1115 $2 = SCM_UNSPECIFIED;
1117 } else if (!unsmob<Score> ($$)) {
1118 if (unsmob<Music> ($2)) {
1119 $2 = Lily::scorify_music ($2);
1121 if (unsmob<Score> ($2))
1124 $2 = SCM_UNSPECIFIED;
1127 Score *score = unsmob<Score> ($$);
1128 if (score && scm_is_pair ($1)) {
1129 if (ly_is_module (scm_car ($1)))
1131 score->set_header (scm_car ($1));
1134 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1135 scm_is_pair (p); p = scm_cdr (p))
1137 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1142 score->add_output_def (od);
1143 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1144 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1146 $$ = scm_cons ($2, $$);
1147 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1148 parser->parser_error (@2, _("Spurious expression in \\score"));
1152 if (Score *score = unsmob<Score> ($1)) {
1153 if (!ly_is_module (score->get_header ()))
1154 score->set_header (ly_make_module (false));
1155 parser->lexer_->add_scope (score->get_header ());
1157 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1158 $1 = scm_cons (ly_make_module (false), $1);
1159 parser->lexer_->add_scope (scm_car ($1));
1174 Output_def *od = unsmob<Output_def> ($1);
1176 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1178 parser->parser_error (@1, _ ("need \\paper for paper block"));
1179 $$ = get_paper (parser)->unprotect ();
1186 output_def_body '}' {
1187 if (scm_is_pair ($1))
1190 parser->lexer_->remove_scope ();
1191 parser->lexer_->pop_state ();
1197 Output_def *p = get_paper (parser);
1198 p->input_origin_ = @$;
1199 parser->lexer_->add_scope (p->scope_);
1200 $$ = p->unprotect ();
1203 Output_def *p = get_midi (parser);
1204 $$ = p->unprotect ();
1205 parser->lexer_->add_scope (p->scope_);
1208 Output_def *p = get_layout (parser);
1210 parser->lexer_->add_scope (p->scope_);
1211 $$ = p->unprotect ();
1215 output_def_head_with_mode_switch:
1217 parser->lexer_->push_initial_state ();
1222 // We need this weird nonterminal because both music as well as a
1223 // context definition can start with \context and the difference is
1224 // only apparent after looking at the next token. If it is '{', there
1225 // is still time to escape from notes mode.
1227 music_or_context_def:
1229 | context_def_spec_block
1233 output_def_head_with_mode_switch '{' {
1234 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1235 // This is a stupid trick to mark the beginning of the
1236 // body for deciding whether to allow
1237 // embedded_scm_active to have an output definition
1238 $$ = scm_list_1 ($1);
1240 | output_def_body assignment {
1241 if (scm_is_pair ($1))
1244 | output_def_body embedded_scm_active
1246 // We don't switch into note mode for Scheme functions
1247 // here. Does not seem warranted/required in output
1249 if (scm_is_pair ($1))
1251 Output_def *o = unsmob<Output_def> ($2);
1253 o->input_origin_.set_spot (@$);
1254 $1 = o->self_scm ();
1255 parser->lexer_->remove_scope ();
1256 parser->lexer_->add_scope (o->scope_);
1257 $2 = SCM_UNSPECIFIED;
1261 if (unsmob<Context_def> ($2))
1262 assign_context_def (unsmob<Output_def> ($1), $2);
1263 // Seems unlikely, but let's be complete:
1264 else if (unsmob<Music> ($2))
1266 SCM proc = parser->lexer_->lookup_identifier
1267 ("output-def-music-handler");
1268 scm_call_2 (proc, $1, $2);
1269 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1270 parser->parser_error (@2, _("bad expression type"));
1273 | output_def_body SCM_TOKEN {
1274 if (scm_is_pair ($1))
1276 // Evaluate and ignore #xxx, as opposed to \xxx
1277 parser->lexer_->eval_scm_token ($2, @2);
1281 if (scm_is_pair ($1))
1283 parser->lexer_->push_note_state (Lily::pitchnames);
1284 } music_or_context_def
1286 parser->lexer_->pop_state ();
1287 if (unsmob<Context_def> ($3))
1288 assign_context_def (unsmob<Output_def> ($1), $3);
1291 SCM proc = parser->lexer_->lookup_identifier
1292 ("output-def-music-handler");
1293 scm_call_2 (proc, $1, $3);
1297 | output_def_body error {
1303 TEMPO steno_duration '=' tempo_range {
1304 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1306 | TEMPO text steno_duration '=' tempo_range {
1307 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1310 $$ = MAKE_SYNTAX (tempo, @$, $2);
1315 The representation of a list is reversed to have efficient append. */
1321 | music_list music_embedded {
1322 if (unsmob<Music> ($2))
1323 $$ = scm_cons ($2, $1);
1325 | music_list error {
1326 Music *m = MY_MAKE_MUSIC("Music", @$);
1328 m->set_property ("error-found", SCM_BOOL_T);
1329 $$ = scm_cons (m->self_scm (), $1);
1330 m->unprotect (); /* UGH */
1337 $$ = scm_reverse_x ($2, SCM_EOL);
1342 | lyric_element_music
1349 $$ = make_music_from_simple (parser, @1, $1);
1350 if (!unsmob<Music> ($$))
1352 parser->parser_error (@1, _ ("music expected"));
1353 $$ = MAKE_SYNTAX (void_music, @$);
1361 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1362 parser->parser_error (@1, _ ("unexpected post-event"));
1363 $$ = SCM_UNSPECIFIED;
1366 | music_embedded_backup
1370 | music_embedded_backup BACKUP lyric_element_music
1374 | multiplied_duration post_events
1376 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1378 parser->default_duration_ = *unsmob<Duration> ($1);
1379 n->set_property ("duration", $1);
1381 if (scm_is_pair ($2))
1382 n->set_property ("articulations",
1383 scm_reverse_x ($2, SCM_EOL));
1384 $$ = n->unprotect ();
1388 music_embedded_backup:
1391 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1393 else if (Music *m = unsmob<Music> ($1)) {
1394 if (m->is_mus_type ("post-event")) {
1395 parser->parser_error
1396 (@1, _ ("unexpected post-event"));
1397 $$ = SCM_UNSPECIFIED;
1400 } else if (parser->lexer_->is_lyric_state ()
1401 && Text_interface::is_markup ($1))
1402 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1404 @$.warning (_ ("Ignoring non-music expression"));
1410 // music_assign does not need to contain lyrics: there are no
1411 // assignments in lyricmode.
1414 | composite_music %prec COMPOSITE
1418 REPEAT simple_string unsigned_number music
1420 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1422 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1424 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1429 SEQUENTIAL braced_music_list {
1430 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1432 | braced_music_list {
1433 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1438 SIMULTANEOUS braced_music_list {
1439 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1441 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1442 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1448 | music_property_def
1452 context_modification:
1455 parser->lexer_->push_note_state (Lily::pitchnames);
1456 } '{' context_mod_list '}'
1458 parser->lexer_->pop_state ();
1461 | WITH CONTEXT_MOD_IDENTIFIER
1465 | CONTEXT_MOD_IDENTIFIER
1469 | WITH context_modification_arg
1471 if (unsmob<Music> ($2)) {
1472 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1473 $2 = scm_call_1 (proc, $2);
1475 if (unsmob<Context_mod> ($2))
1478 parser->parser_error (@2, _ ("not a context mod"));
1479 $$ = Context_mod ().smobbed_copy ();
1484 context_modification_arg:
1489 /* A list of single mods collected from a (possibly empty) sequence of
1490 * context modifications, usually written as \with ... \with ...
1493 optional_context_mods:
1494 context_modification_mods_list
1496 if (scm_is_pair ($1))
1497 $$ = scm_append_x (scm_reverse_x ($1, SCM_EOL));
1501 /* The worker for optional_context_mods conses a (reversed) list where
1502 * each element contains the list of single context mods from one
1503 * context modification block. Context_mod::get_mods creates fresh
1504 * copies, so it's okay to use append! on them.
1507 context_modification_mods_list:
1511 | context_modification_mods_list context_modification
1513 if (Context_mod *m = unsmob<Context_mod> ($2))
1514 $$ = scm_cons (m->get_mods (), $1);
1518 /* A Context_mod is a container for a list of context mods like
1519 * \consists ... \override ... . context_mod_list produces a
1520 * Context_mod from the inside of a \with { ... } statement.
1525 $$ = Context_mod ().smobbed_copy ();
1527 | context_mod_list context_mod {
1528 if (!SCM_UNBNDP ($2))
1529 unsmob<Context_mod> ($1)->add_context_mod ($2);
1531 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1532 Context_mod *md = unsmob<Context_mod> ($2);
1534 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1536 | context_mod_list context_mod_arg {
1537 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1539 else if (unsmob<Music> ($2)) {
1540 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1541 $2 = scm_call_1 (proc, $2);
1543 if (unsmob<Context_mod> ($2))
1544 unsmob<Context_mod> ($$)->add_context_mods
1545 (unsmob<Context_mod> ($2)->get_mods ());
1547 parser->parser_error (@2, _ ("not a context mod"));
1553 CONTEXT symbol optional_id optional_context_mods {
1554 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_F);
1556 | NEWCONTEXT symbol optional_id optional_context_mods {
1557 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_T);
1562 ADDLYRICS optional_context_mods lyric_mode_music {
1563 $$ = scm_acons ($3, $2, SCM_EOL);
1565 | new_lyrics ADDLYRICS optional_context_mods lyric_mode_music {
1566 $$ = scm_acons ($4, $3, $1);
1570 /* basic_music is basically the same as composite_music but with
1571 * context-prefixed music and lyricized music explicitly removed. The
1572 * reason is that in a sequence
1574 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1576 * we need to group both \addlyrics together (as they go with the same
1577 * voice) but then combine them with \new Voice { ... }, meaning that
1578 * combining \new Voice { ... } needs higher priority than
1579 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1580 * combine before combining \new Voice { ... } \addlyrics: only one
1581 * layer of context-prefixed music should assemble before \addlyrics
1582 * is integrated. Total mess, and we sort this mess out with explicit
1583 * rules preferring a single context-prefix.
1590 | LYRICSTO simple_string lyric_mode_music {
1591 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1593 | LYRICSTO symbol '=' simple_string lyric_mode_music
1595 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1605 contexted_basic_music:
1606 context_prefix contextable_music new_lyrics
1609 i.set_location (@1, @2);
1610 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1611 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1613 | context_prefix contextable_music
1615 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1617 | context_prefix contexted_basic_music
1619 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1624 basic_music %prec COMPOSITE
1625 | contexted_basic_music
1626 | basic_music new_lyrics
1628 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1635 | grouped_music_list
1639 simultaneous_music { $$ = $1; }
1640 | sequential_music { $$ = $1; }
1643 /* Function argument lists are arguably the most complex part in the
1644 * parser. They are pretty tricky to understand because of the way
1645 * they are processed, and because of optional arguments that can be
1646 * omitted. When there are several optional arguments in a row,
1647 * omitting one automatically omits all following arguments. Optional
1648 * arguments can only be omitted when either
1650 * a) the omission is explicitly started with \default
1651 * b) the omission is implicitly started by an argument not matching
1652 * its predicate, and there is a mandatory argument later that can
1653 * "catch" the argument that does not fit.
1655 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1656 * (corresponding to mandatory arguments and having a predicate
1657 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1658 * the semantic value of the EXPECT_OPTIONAL token is the default to
1659 * use when the optional argument is omitted, and EXPECT_SCM again has
1660 * the argument predicate as semantic value) in reverse order to the
1661 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1662 * processed inside-out while actual tokens are consumed.
1664 * This means that the argument list tokens determine the actions
1665 * taken as they arrive. The structure of the argument list is known
1666 * to the parser and stored in its parse stack when the first argument
1667 * is being parsed. What the parser does not know is which predicates
1668 * will match and whether or not \default will be appearing in the
1669 * argument list, and where.
1671 * Sequences of 0 or more optional arguments are scanned using either
1672 * function_arglist_backup or function_arglist_nonbackup. The first
1673 * is used when optional arguments are followed by at least one
1674 * mandatory argument: in that case optional arguments may be skipped
1675 * by either a false predicate (in which case the expression will be
1676 * pushed back as one or more tokens, preceded by a BACKUP token) or
1677 * by using \default.
1679 * If optional arguments are at the end of the argument list, they are
1680 * instead scanned using function_arglist_nonbackup: here the only
1681 * manner to enter into skipping of optional arguments is the use of
1684 * The argument list of a normal function call is parsed using
1685 * function_arglist. The part of an argument list before a mandatory
1686 * argument is parsed using function_arglist_optional.
1688 * The difference is that leading optional arguments are scanned using
1689 * function_arglist_nonbackup and function_arglist_backup,
1692 * Most other details are obvious in the rules themselves.
1698 | SYMBOL_LIST '.' symbol_list_rev
1700 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1702 | SYMBOL_LIST ',' symbol_list_rev
1704 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1710 | symbol_list_rev '.' symbol_list_part
1712 $$ = scm_append_x (scm_list_2 ($3, $1));
1714 | symbol_list_rev ',' symbol_list_part
1716 $$ = scm_append_x (scm_list_2 ($3, $1));
1720 // symbol_list_part delivers elements in reverse copy.
1725 $$ = try_string_variants (Lily::key_list_p, $1);
1726 if (SCM_UNBNDP ($$)) {
1727 parser->parser_error (@1, _("not a key"));
1730 $$ = scm_reverse ($$);
1735 symbol_list_element:
1741 symbol_list_part_bare:
1744 $$ = try_string_variants (Lily::key_list_p, $1);
1745 if (SCM_UNBNDP ($$)) {
1746 parser->parser_error (@1, _("not a key"));
1749 $$ = scm_reverse ($$);
1753 $$ = scm_list_1 ($1);
1757 function_arglist_nonbackup:
1758 function_arglist_common
1759 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1761 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1763 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1765 SCM n = scm_difference ($5, SCM_UNDEFINED);
1766 if (scm_is_true (scm_call_1 ($2, n)))
1767 $$ = scm_cons (n, $3);
1769 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1770 t->set_property ("digit", $5);
1771 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1775 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1777 $$ = check_scheme_arg (parser, @4,
1778 scm_difference ($5, SCM_UNDEFINED),
1781 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1783 $$ = check_scheme_arg (parser, @4,
1784 scm_difference ($5, SCM_UNDEFINED),
1787 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1789 if (scm_is_true (scm_call_1 ($2, $4)))
1790 $$ = scm_cons ($4, $3);
1792 $$ = check_scheme_arg (parser, @4,
1793 make_music_from_simple
1797 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1799 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1801 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1803 if (scm_is_true (scm_call_1 ($2, $3)))
1804 $$ = scm_cons ($3, $1);
1806 $$ = check_scheme_arg (parser, @3,
1807 make_music_from_simple
1811 | function_arglist_nonbackup_reparse REPARSE multiplied_duration
1813 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1815 | function_arglist_nonbackup_reparse REPARSE reparsed_rhythm
1817 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1819 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1821 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1823 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1825 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1827 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1829 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1831 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1833 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1839 DURATION_ARG dots multipliers post_events
1841 $$ = make_music_from_simple (parser, @$,
1842 make_duration ($1, scm_to_int ($2), $3));
1843 Music *m = unsmob<Music> ($$);
1845 if (scm_is_pair ($4))
1846 m->set_property ("articulations",
1847 scm_reverse_x ($4, SCM_EOL));
1851 function_arglist_nonbackup_reparse:
1852 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1855 SCM res = try_string_variants ($2, $4);
1856 if (!SCM_UNBNDP (res))
1857 if (scm_is_pair (res))
1858 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1860 MYREPARSE (@4, $2, SCM_ARG, res);
1861 else if (scm_is_true
1863 ($2, make_music_from_simple
1865 MYREPARSE (@4, $2, STRING, $4);
1867 MYREPARSE (@4, $2, SCM_ARG, $4);
1869 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1874 ($2, make_music_from_simple
1876 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1878 MYREPARSE (@4, $2, SCM_ARG, $4);
1880 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1885 ($2, make_music_from_simple
1887 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1889 MYREPARSE (@4, $2, SCM_ARG, $4);
1891 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1894 SCM res = try_string_variants ($2, $4);
1895 if (!SCM_UNBNDP (res))
1896 if (scm_is_pair (res))
1897 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1899 MYREPARSE (@4, $2, SCM_ARG, res);
1900 else if (scm_is_true
1902 ($2, make_music_from_simple
1904 MYREPARSE (@4, $2, STRING, $4);
1906 MYREPARSE (@4, $2, SCM_ARG, $4);
1908 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1911 if (scm_is_true (scm_call_1 ($2, $4)))
1912 MYREPARSE (@4, $2, SCM_ARG, $4);
1913 else if (scm_is_true
1915 ($2, make_music_from_simple
1917 MYREPARSE (@4, $2, STRING, $4);
1919 MYREPARSE (@4, $2, SCM_ARG, $4);
1921 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1924 if (scm_is_true (scm_call_1 ($2, $4)))
1925 // May be 3 \cm or similar
1926 MYREPARSE (@4, $2, REAL, $4);
1927 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
1928 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
1930 SCM d = make_duration ($4);
1931 if (!SCM_UNBNDP (d)) {
1932 if (scm_is_true (scm_call_1 ($2, d)))
1933 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1934 else if (scm_is_true
1936 ($2, make_music_from_simple (parser, @4, d))))
1937 MYREPARSE (@4, $2, DURATION_ARG, d);
1939 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1941 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1944 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER
1947 if (scm_is_true (scm_call_1 ($2, $4)))
1948 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1949 else if (scm_is_true
1951 ($2, make_music_from_simple (parser, @4, $4))))
1952 MYREPARSE (@4, $2, DURATION_ARG, $4);
1954 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1959 // function_arglist_backup can't occur at the end of an argument
1961 function_arglist_backup:
1962 function_arglist_common
1963 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1965 if (scm_is_true (scm_call_1 ($2, $4)))
1966 $$ = scm_cons ($4, $3);
1968 $$ = make_music_from_simple (parser, @4, $4);
1969 if (scm_is_true (scm_call_1 ($2, $$)))
1970 $$ = scm_cons ($$, $3);
1973 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1974 MYBACKUP (SCM_ARG, $4, @4);
1978 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1980 if (scm_is_true (scm_call_1 ($2, $4)))
1982 $$ = scm_cons ($4, $3);
1984 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1985 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1988 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1992 ($2, make_music_from_simple
1996 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1997 } else if (scm_is_true (scm_call_1 ($2, $4)))
1998 $$ = scm_cons ($4, $3);
2000 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2001 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
2004 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
2008 ($2, make_music_from_simple
2012 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
2013 } else if (scm_is_true (scm_call_1 ($2, $4)))
2014 $$ = scm_cons ($4, $3);
2016 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2017 MYBACKUP (TONICNAME_PITCH, $4, @4);
2020 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
2022 if (scm_is_true (scm_call_1 ($2, $4)))
2023 $$ = scm_cons ($4, $3);
2025 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2026 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2029 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
2032 if (scm_is_true (scm_call_1 ($2, $4)))
2033 // May be 3 \cm or similar
2034 MYREPARSE (@4, $2, REAL, $4);
2035 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
2036 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
2038 SCM d = make_duration ($4);
2039 if (!SCM_UNBNDP (d)) {
2040 if (scm_is_true (scm_call_1 ($2, d)))
2041 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
2042 else if (scm_is_true
2044 ($2, make_music_from_simple (parser, @4, d))))
2045 MYREPARSE (@4, $2, DURATION_ARG, d);
2047 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2048 MYBACKUP (UNSIGNED, $4, @4);
2051 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2052 MYBACKUP (UNSIGNED, $4, @4);
2056 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
2058 if (scm_is_true (scm_call_1 ($2, $4)))
2061 MYREPARSE (@4, $2, REAL, $4);
2063 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2064 MYBACKUP (REAL, $4, @4);
2067 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
2069 if (scm_is_true (scm_call_1 ($2, $4)))
2071 $$ = scm_cons ($4, $3);
2073 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2074 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
2077 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
2079 SCM n = scm_difference ($5, SCM_UNDEFINED);
2080 if (scm_is_true (scm_call_1 ($2, n))) {
2082 MYREPARSE (@5, $2, REAL, n);
2084 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
2085 t->set_property ("digit", $5);
2086 $$ = t->unprotect ();
2087 if (scm_is_true (scm_call_1 ($2, $$)))
2088 $$ = scm_cons ($$, $3);
2090 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2091 MYBACKUP (UNSIGNED, $5, @5);
2092 parser->lexer_->push_extra_token (@4, '-');
2096 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2098 SCM n = scm_difference ($5, SCM_UNDEFINED);
2099 if (scm_is_true (scm_call_1 ($2, n))) {
2100 MYREPARSE (@5, $2, REAL, n);
2103 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2104 MYBACKUP (REAL, n, @5);
2107 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2109 SCM n = scm_difference ($5, SCM_UNDEFINED);
2110 if (scm_is_true (scm_call_1 ($2, n))) {
2111 $$ = scm_cons (n, $3);
2113 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2114 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2117 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2120 if (scm_is_true (scm_call_1 ($2, $4)))
2121 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2122 else if (scm_is_true
2124 ($2, make_music_from_simple (parser, @4, $4))))
2125 MYREPARSE (@4, $2, DURATION_ARG, $4);
2127 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2128 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2131 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2133 SCM res = try_string_variants ($2, $4);
2134 if (!SCM_UNBNDP (res))
2135 if (scm_is_pair (res)) {
2137 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2140 $$ = scm_cons (res, $3);
2142 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2143 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2146 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2148 SCM res = try_string_variants ($2, $4);
2149 if (!SCM_UNBNDP (res))
2150 if (scm_is_pair (res)) {
2152 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2155 $$ = scm_cons (res, $3);
2157 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2158 MYBACKUP (STRING, $4, @4);
2161 | function_arglist_backup REPARSE pitch_or_music
2163 if (scm_is_true (scm_call_1 ($2, $3)))
2164 $$ = scm_cons ($3, $1);
2166 $$ = check_scheme_arg (parser, @3,
2167 make_music_from_simple
2171 | function_arglist_backup REPARSE bare_number_common
2173 $$ = check_scheme_arg (parser, @3,
2176 | function_arglist_backup REPARSE multiplied_duration
2178 $$ = check_scheme_arg (parser, @3,
2181 | function_arglist_backup REPARSE reparsed_rhythm
2183 $$ = check_scheme_arg (parser, @3,
2186 | function_arglist_backup REPARSE symbol_list_arg
2188 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2193 function_arglist_nonbackup
2194 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2196 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2200 function_arglist_skip_nonbackup:
2201 function_arglist_nonbackup
2202 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2204 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2208 // Partial function arglists are returned just in their incomplete
2209 // state: when combined with the music function, the missing parts of
2210 // the signature can be reconstructed
2212 // To serve as a partial arglist, the argument list must absolutely
2213 // _not_ be in "skipping optional arguments" mode since then there is
2214 // some backup token that has nowhere to go before \etc.
2216 // So we can skim off an arbitrary number of arguments from the end of
2217 // the argument list. The argument list remaining afterwards has to
2218 // be in not-skipping-optional-arguments mode.
2220 function_arglist_partial:
2221 EXPECT_SCM function_arglist_optional
2225 | EXPECT_SCM function_arglist_partial_optional
2229 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2233 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2239 function_arglist_partial_optional:
2240 EXPECT_SCM function_arglist_optional
2244 | EXPECT_SCM function_arglist_partial_optional
2248 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2252 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2258 function_arglist_common:
2259 EXPECT_NO_MORE_ARGS {
2262 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2264 if (scm_is_true (scm_call_1 ($1, $3)))
2265 $$ = scm_cons ($3, $2);
2267 $$ = check_scheme_arg (parser, @3,
2268 make_music_from_simple
2272 | EXPECT_SCM function_arglist_optional bare_number_common
2274 $$ = check_scheme_arg (parser, @3,
2277 | EXPECT_SCM function_arglist_optional post_event_nofinger
2279 $$ = check_scheme_arg (parser, @3,
2282 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2284 SCM n = scm_difference ($4, SCM_UNDEFINED);
2285 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2287 | function_arglist_common_reparse REPARSE SCM_ARG
2289 $$ = check_scheme_arg (parser, @3,
2292 | function_arglist_common_reparse REPARSE lyric_element_music
2294 $$ = check_scheme_arg (parser, @3,
2297 | function_arglist_common_reparse REPARSE pitch_or_music
2299 if (scm_is_true (scm_call_1 ($2, $3)))
2300 $$ = scm_cons ($3, $1);
2302 $$ = check_scheme_arg (parser, @3,
2303 make_music_from_simple
2307 | function_arglist_common_reparse REPARSE bare_number_common
2309 $$ = check_scheme_arg (parser, @3,
2312 | function_arglist_common_reparse REPARSE multiplied_duration
2314 $$ = check_scheme_arg (parser, @3,
2317 | function_arglist_common_reparse REPARSE reparsed_rhythm
2319 $$ = check_scheme_arg (parser, @3,
2322 | function_arglist_common_reparse REPARSE symbol_list_arg
2324 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2328 function_arglist_common_reparse:
2329 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2332 SCM res = try_string_variants ($1, $3);
2333 if (!SCM_UNBNDP (res))
2334 if (scm_is_pair (res))
2335 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2337 MYREPARSE (@3, $1, SCM_ARG, res);
2338 else if (scm_is_true
2340 ($1, make_music_from_simple (parser, @3, $3))))
2341 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2343 // This is going to flag a syntax error, we
2344 // know the predicate to be false.
2345 MYREPARSE (@3, $1, SCM_ARG, $3);
2347 | EXPECT_SCM function_arglist_optional pitch
2352 ($1, make_music_from_simple
2354 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2356 MYREPARSE (@3, $1, SCM_ARG, $3);
2358 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2363 ($1, make_music_from_simple
2365 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2367 MYREPARSE (@3, $1, SCM_ARG, $3);
2369 | EXPECT_SCM function_arglist_optional STRING
2372 SCM res = try_string_variants ($1, $3);
2373 if (!SCM_UNBNDP (res))
2374 if (scm_is_pair (res))
2375 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2377 MYREPARSE (@3, $1, SCM_ARG, res);
2378 else if (scm_is_true
2380 ($1, make_music_from_simple (parser, @3, $3))))
2381 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2383 // This is going to flag a syntax error, we
2384 // know the predicate to be false.
2385 MYREPARSE (@3, $1, SCM_ARG, $3);
2387 | EXPECT_SCM function_arglist_optional full_markup
2390 if (scm_is_true (scm_call_1 ($1, $3)))
2391 MYREPARSE (@3, $1, SCM_ARG, $3);
2392 else if (scm_is_true
2394 ($1, make_music_from_simple (parser, @3, $3))))
2395 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2397 // This is going to flag a syntax error, we
2398 // know the predicate to be false.
2399 MYREPARSE (@3, $1, SCM_ARG, $3);
2401 | EXPECT_SCM function_arglist_optional UNSIGNED
2404 if (scm_is_true (scm_call_1 ($1, $3)))
2405 // May be 3 \cm or similar
2406 MYREPARSE (@3, $1, REAL, $3);
2407 else if (scm_is_true (scm_call_1 ($1, scm_list_1 ($3))))
2408 MYREPARSE (@3, $1, SYMBOL_LIST, scm_list_1 ($3));
2410 SCM d = make_duration ($3);
2411 if (!SCM_UNBNDP (d)) {
2412 if (scm_is_true (scm_call_1 ($1, d)))
2413 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2414 else if (scm_is_true
2416 ($1, make_music_from_simple (parser, @3, d))))
2417 MYREPARSE (@3, $1, DURATION_ARG, d);
2419 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2421 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2424 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2427 if (scm_is_true (scm_call_1 ($1, $3)))
2428 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2429 else if (scm_is_true
2431 ($1, make_music_from_simple (parser, @3, $3))))
2432 MYREPARSE (@3, $1, DURATION_ARG, $3);
2434 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2436 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2439 SCM n = scm_difference ($4, SCM_UNDEFINED);
2440 if (scm_is_true (scm_call_1 ($1, n)))
2441 MYREPARSE (@4, $1, REAL, n);
2443 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2444 t->set_property ("digit", $4);
2445 SCM m = t->unprotect ();
2446 if (scm_is_true (scm_call_1 ($1, m)))
2447 MYREPARSE (@4, $1, SCM_ARG, m);
2449 MYREPARSE (@4, $1, SCM_ARG, $4);
2452 | EXPECT_SCM function_arglist_optional '-' REAL
2455 SCM n = scm_difference ($4, SCM_UNDEFINED);
2456 MYREPARSE (@4, $1, REAL, n);
2460 function_arglist_optional:
2461 function_arglist_backup
2462 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2464 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2466 | function_arglist_skip_backup BACKUP
2469 function_arglist_skip_backup:
2470 function_arglist_backup
2471 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2473 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2477 music_function_call:
2478 MUSIC_FUNCTION function_arglist {
2479 $$ = MAKE_SYNTAX (music_function, @$,
2486 /**/ { $$ = SCM_EOL; }
2487 | '=' simple_string {
2492 // We must not have lookahead tokens parsed in lyric mode. In order
2493 // to save confusion, we take almost the same set as permitted with
2494 // \lyricmode and/or \lyrics. However, music identifiers are also
2495 // allowed, and they obviously do not require switching into lyrics
2496 // mode for parsing.
2500 parser->lexer_->push_lyric_state ();
2501 } grouped_music_list
2503 parser->lexer_->pop_state ();
2510 mode_changing_head grouped_music_list {
2511 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2513 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2519 parser->lexer_->pop_state ();
2521 | mode_changing_head_with_context optional_context_mods grouped_music_list {
2522 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, $2, SCM_BOOL_T, $3);
2523 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2525 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2527 parser->lexer_->pop_state ();
2533 parser->lexer_->push_note_state (Lily::pitchnames);
2535 $$ = ly_symbol2scm ("notes");
2539 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2541 $$ = ly_symbol2scm ("drums");
2544 parser->lexer_->push_figuredbass_state ();
2546 $$ = ly_symbol2scm ("figures");
2549 parser->lexer_->chordmodifier_tab_ =
2550 alist_to_hashq (Lily::chordmodifiers);
2551 parser->lexer_->push_chord_state (Lily::pitchnames);
2552 $$ = ly_symbol2scm ("chords");
2556 { parser->lexer_->push_lyric_state ();
2557 $$ = ly_symbol2scm ("lyrics");
2561 mode_changing_head_with_context:
2563 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2565 $$ = ly_symbol2scm ("DrumStaff");
2568 parser->lexer_->push_figuredbass_state ();
2570 $$ = ly_symbol2scm ("FiguredBass");
2573 parser->lexer_->chordmodifier_tab_ =
2574 alist_to_hashq (Lily::chordmodifiers);
2575 parser->lexer_->push_chord_state (Lily::pitchnames);
2576 $$ = ly_symbol2scm ("ChordNames");
2579 { parser->lexer_->push_lyric_state ();
2580 $$ = ly_symbol2scm ("Lyrics");
2585 CHANGE symbol '=' simple_string {
2586 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2593 $$ = scm_reverse_x ($1, SCM_EOL);
2599 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2602 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2604 | OVERRIDE revert_arg '=' scalar {
2605 if (scm_ilength ($2) < 2) {
2606 parser->parser_error (@2, _("bad grob property path"));
2609 $$ = scm_cons (ly_symbol2scm ("push"),
2610 scm_cons2 (scm_car ($2),
2615 | REVERT revert_arg {
2616 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2620 // This is all quite awkward for the sake of substantial backward
2621 // compatibility while at the same time allowing a more "natural" form
2622 // of specification not separating grob specification from grob
2623 // property path. The purpose of this definition of revert_arg is to
2624 // allow the symbol list which specifies grob and property to revert
2625 // to be optionally be split into two parts after the grob (which in
2626 // this case is just the first element of the list). symbol_list_part
2627 // is only one path component, but it can be parsed without lookahead,
2628 // so we can follow it with a synthetic BACKUP token when needed. If
2629 // the first symbol_list_part already contains multiple elements (only
2630 // possible if a Scheme expression provides them), we just parse for
2631 // additional elements introduced by '.', which is what the
2632 // SYMBOL_LIST backup in connection with the immediately following
2633 // rule using symbol_list_arg does.
2635 // As long as we don't have our coffers filled with both grob and at
2636 // least one grob property specification, the rest of the required
2637 // symbol list chain may be provided either with or without a leading
2638 // dot. This is for both allowing the traditional
2639 // \revert Accidental #'color
2640 // as well as well as the "naive" form
2641 // \revert Accidental.color
2644 revert_arg_backup BACKUP symbol_list_arg
2653 if (scm_is_null ($1)
2654 || scm_is_null (scm_cdr ($1)))
2655 MYBACKUP (SCM_ARG, $1, @1);
2657 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2661 // revert_arg_part delivers results in reverse
2664 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2666 $$ = scm_append_x (scm_list_2 ($5, $3));
2668 | revert_arg_backup BACKUP SCM_ARG ',' symbol_list_part
2670 $$ = scm_append_x (scm_list_2 ($5, $3));
2672 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2674 $$ = scm_append_x (scm_list_2 ($4, $3));
2679 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2680 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2682 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2683 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2684 | DENIES { $$ = ly_symbol2scm ("denies"); }
2686 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2687 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2688 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2689 | NAME { $$ = ly_symbol2scm ("context-name"); }
2693 property_operation { $$ = $1; }
2694 | context_def_mod STRING {
2695 $$ = scm_list_2 ($1, $2);
2697 | context_def_mod embedded_scm
2699 if (!scm_is_string ($2)
2700 && ly_symbol2scm ("consists") != $1
2701 && ly_symbol2scm ("remove") != $1)
2704 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2708 $$ = scm_list_2 ($1, $2);
2713 // If defined, at least two members.
2717 SCM l = scm_reverse_x ($1, SCM_EOL);
2720 (scm_object_property (scm_car (l),
2721 ly_symbol2scm ("is-grob?"))))
2722 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2723 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2724 parser->parser_error (@1, _ ("bad grob property path"));
2731 // If defined, at least three members
2735 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2737 parser->parser_error (@1, _ ("bad grob property path"));
2741 | grob_prop_spec property_path
2743 if (!SCM_UNBNDP ($1)) {
2744 $$ = scm_append_x (scm_list_2 ($1, $2));
2745 if (scm_is_null (scm_cddr ($$))) {
2746 parser->parser_error (@$, _ ("bad grob property path"));
2754 // Exactly two elements or undefined
2758 SCM l = scm_reverse_x ($1, SCM_EOL);
2759 switch (scm_ilength (l)) {
2761 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2765 parser->parser_error (@1, _ ("bad context property path"));
2773 // This is all quite awkward for the sake of substantial backward
2774 // compatibility while at the same time allowing a more "natural" form
2775 // of specification not separating grob specification from grob
2776 // property path. The purpose of this definition of
2777 // simple_revert_context is to allow the symbol list which specifies
2778 // grob and property to revert to be optionally be split into two
2779 // parts after the grob (which may be preceded by a context
2780 // specification, a case which we distinguish by checking whether the
2781 // first symbol is a valid grob symbol instead).
2783 // See revert_arg above for the main work horse of this arrangement.
2784 // simple_revert_context just caters for the context and delegates the
2785 // rest of the job to revert_arg.
2787 simple_revert_context:
2790 $1 = scm_reverse_x ($1, SCM_EOL);
2791 if (scm_is_null ($1)
2793 (scm_object_property (scm_car ($1),
2794 ly_symbol2scm ("is-grob?")))) {
2795 $$ = ly_symbol2scm ("Bottom");
2796 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2799 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2806 OVERRIDE grob_prop_path '=' scalar {
2807 if (SCM_UNBNDP ($2))
2808 $$ = MAKE_SYNTAX (void_music, @$);
2810 $$ = MAKE_SYNTAX (property_override, @$,
2815 | REVERT simple_revert_context revert_arg {
2816 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2818 | SET context_prop_spec '=' scalar {
2819 if (SCM_UNBNDP ($2))
2820 $$ = MAKE_SYNTAX (void_music, @$);
2822 $$ = MAKE_SYNTAX (property_set, @$,
2827 | UNSET context_prop_spec {
2828 if (SCM_UNBNDP ($2))
2829 $$ = MAKE_SYNTAX (void_music, @$);
2831 $$ = MAKE_SYNTAX (property_unset, @$,
2847 if (Text_interface::is_markup ($1)) {
2850 parser->parser_error (@1, (_ ("markup expected")));
2851 $$ = scm_string (SCM_EOL);
2856 simple_string: STRING
2859 if (scm_is_string ($1)) {
2862 parser->parser_error (@1, (_ ("simple string expected")));
2863 $$ = scm_string (SCM_EOL);
2870 $$ = scm_string_to_symbol ($1);
2874 // This is a bit of overkill but makes the same
2875 // routine responsible for all symbol interpretations.
2876 $$ = try_string_variants (Guile_user::symbol_p, $1);
2877 if (SCM_UNBNDP ($$))
2879 parser->parser_error (@1, (_ ("symbol expected")));
2880 // Generate a unique symbol in case it is used
2881 // for an assignment or similar
2882 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2892 // The following is a rather defensive variant of admitting
2893 // negative numbers: the grammar would permit number_factor or
2894 // even number_expression. However, function arguments allow
2895 // only this simple kind of negative number, so to have things
2896 // like \tweak and \override behave reasonably similar, it
2897 // makes sense to rule out things like -- which are rather an
2898 // accent in function argument contexts.
2901 $$ = scm_difference ($2, SCM_UNDEFINED);
2904 | symbol_list_part_bare '.' property_path
2906 $$ = scm_reverse_x ($1, $3);
2908 | symbol_list_part_bare ',' property_path
2910 $$ = scm_reverse_x ($1, $3);
2915 simple_element post_events {
2916 // Let the rhythmic music iterator sort this mess out.
2917 if (scm_is_pair ($2)) {
2918 unsmob<Music> ($$)->set_property ("articulations",
2919 scm_reverse_x ($2, SCM_EOL));
2922 | CHORD_REPETITION optional_notemode_duration post_events {
2924 i.set_location (@1, @3);
2925 $$ = MAKE_SYNTAX (repetition_chord, i,
2926 $2, scm_reverse_x ($3, SCM_EOL));
2928 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2930 i.set_location (@1, @3);
2931 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2932 scm_reverse_x ($3, SCM_EOL));
2935 | note_chord_element
2940 chord_body optional_notemode_duration post_events
2942 Music *m = unsmob<Music> ($1);
2943 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2944 SCM es = m->get_property ("elements");
2945 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2947 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2948 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2949 es = ly_append2 (es, postevs);
2951 m->set_property ("elements", es);
2952 m->set_spot (parser->lexer_->override_input (@$));
2953 $$ = m->self_scm ();
2958 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2960 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2962 | FIGURE_OPEN figure_list FIGURE_CLOSE
2964 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2968 chord_body_elements:
2969 /* empty */ { $$ = SCM_EOL; }
2970 | chord_body_elements chord_body_element {
2971 if (!SCM_UNBNDP ($2))
2972 $$ = scm_cons ($2, $1);
2977 pitch_or_tonic_pitch exclamations questions octave_check post_events
2979 bool q = to_boolean ($3);
2980 bool ex = to_boolean ($2);
2984 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2985 n->set_property ("pitch", $1);
2987 n->set_property ("cautionary", SCM_BOOL_T);
2989 n->set_property ("force-accidental", SCM_BOOL_T);
2991 if (scm_is_pair (post)) {
2992 SCM arts = scm_reverse_x (post, SCM_EOL);
2993 n->set_property ("articulations", arts);
2995 if (scm_is_number (check))
2997 int q = scm_to_int (check);
2998 n->set_property ("absolute-octave", scm_from_int (q-1));
3001 $$ = n->unprotect ();
3003 | DRUM_PITCH post_events {
3004 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3005 n->set_property ("drum-type", $1);
3007 if (scm_is_pair ($2)) {
3008 SCM arts = scm_reverse_x ($2, SCM_EOL);
3009 n->set_property ("articulations", arts);
3011 $$ = n->unprotect ();
3013 | music_function_chord_body
3015 Music *m = unsmob<Music> ($1);
3017 while (m && m->is_mus_type ("music-wrapper-music")) {
3018 $$ = m->get_property ("element");
3019 m = unsmob<Music> ($$);
3022 if (!(m && m->is_mus_type ("rhythmic-event"))) {
3023 parser->parser_error (@$, _ ("not a rhythmic event"));
3029 music_function_chord_body:
3035 event_function_event:
3036 EVENT_FUNCTION function_arglist {
3037 $$ = MAKE_SYNTAX (music_function, @$,
3046 | post_events post_event {
3048 if (Music *m = unsmob<Music> ($2))
3050 if (m->is_mus_type ("post-event-wrapper"))
3052 for (SCM p = m->get_property ("elements");
3056 $$ = scm_cons (scm_car (p), $$);
3059 m->set_spot (parser->lexer_->override_input (@2));
3060 $$ = scm_cons ($2, $$);
3066 post_event_nofinger:
3067 direction_less_event {
3070 | script_dir music_function_call {
3072 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
3073 parser->parser_error (@2, _ ("post-event expected"));
3074 $$ = SCM_UNSPECIFIED;
3075 } else if (!SCM_UNBNDP ($1))
3077 unsmob<Music> ($$)->set_property ("direction", $1);
3081 if (!parser->lexer_->is_lyric_state ())
3082 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3083 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
3086 if (!parser->lexer_->is_lyric_state ())
3087 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3088 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
3090 | script_dir direction_reqd_event {
3091 if (!SCM_UNBNDP ($1))
3093 Music *m = unsmob<Music> ($2);
3094 m->set_property ("direction", $1);
3098 | script_dir direction_less_event {
3099 if (!SCM_UNBNDP ($1))
3101 Music *m = unsmob<Music> ($2);
3102 m->set_property ("direction", $1);
3109 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
3114 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
3125 string_number_event:
3127 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3128 s->set_property ("string-number", $1);
3129 $$ = s->unprotect ();
3133 direction_less_event:
3135 | EVENT_IDENTIFIER {
3139 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3140 a->set_property ("tremolo-type", $1);
3141 $$ = a->unprotect ();
3143 | event_function_event
3146 direction_reqd_event:
3150 | script_abbreviation {
3151 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3152 if (scm_is_string (s)) {
3153 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3154 a->set_property ("articulation-type", s);
3155 $$ = a->unprotect ();
3157 Music *original = unsmob<Music> (s);
3158 if (original && original->is_mus_type ("post-event")) {
3159 Music *a = original->clone ();
3160 a->set_spot (parser->lexer_->override_input (@$));
3161 $$ = a->unprotect ();
3163 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3164 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3171 /**/ { $$ = SCM_EOL; }
3172 | '=' quotes { $$ = $2; }
3186 $$ = scm_from_int (1);
3189 $$ = scm_oneplus ($1);
3195 $$ = scm_from_int (-1);
3198 $$ = scm_oneminus ($1);
3203 NOTENAME_PITCH quotes {
3204 if (!scm_is_eq (SCM_INUM0, $2))
3206 Pitch p = *unsmob<Pitch> ($1);
3207 p = p.transposed (Pitch (scm_to_int ($2), 0));
3208 $$ = p.smobbed_copy ();
3218 TONICNAME_PITCH quotes {
3219 if (!scm_is_eq (SCM_INUM0, $2))
3221 Pitch p = *unsmob<Pitch> ($1);
3222 p = p.transposed (Pitch (scm_to_int ($2), 0));
3223 $$ = p.smobbed_copy ();
3230 | PITCH_IDENTIFIER quotes {
3231 if (!scm_is_eq (SCM_INUM0, $2))
3233 Pitch p = *unsmob<Pitch> ($1);
3234 p = p.transposed (Pitch (scm_to_int ($2), 0));
3235 $$ = p.smobbed_copy ();
3240 pitch_or_tonic_pitch:
3247 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3248 t->set_property ("text", $1);
3249 $$ = t->unprotect ();
3252 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3253 t->set_property ("text",
3254 make_simple_markup ($1));
3255 $$ = t->unprotect ();
3259 Music *m = unsmob<Music> ($1);
3260 if (m && m->is_mus_type ("post-event"))
3262 else if (Text_interface::is_markup ($1)) {
3263 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3264 t->set_property ("text", $1);
3265 $$ = t->unprotect ();
3267 parser->parser_error (@1, _ ("not an articulation"));
3273 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3274 t->set_property ("digit", $1);
3275 $$ = t->unprotect ();
3279 script_abbreviation:
3281 $$ = scm_from_ascii_string ("Hat");
3284 $$ = scm_from_ascii_string ("Plus");
3287 $$ = scm_from_ascii_string ("Dash");
3290 $$ = scm_from_ascii_string ("Bang");
3293 $$ = scm_from_ascii_string ("Larger");
3296 $$ = scm_from_ascii_string ("Dot");
3299 $$ = scm_from_ascii_string ("Underscore");
3304 '_' { $$ = scm_from_int (DOWN); }
3305 | '^' { $$ = scm_from_int (UP); }
3306 | '-' { $$ = SCM_UNDEFINED; }
3309 maybe_notemode_duration:
3313 | multiplied_duration {
3315 parser->default_duration_ = *unsmob<Duration> ($$);
3320 optional_notemode_duration:
3321 maybe_notemode_duration
3323 if (SCM_UNBNDP ($$))
3324 $$ = parser->default_duration_.smobbed_copy ();
3330 $$ = make_duration ($1, scm_to_int ($2));
3331 if (SCM_UNBNDP ($$))
3333 parser->parser_error (@1, _ ("not a duration"));
3334 $$ = Duration ().smobbed_copy ();
3337 | DURATION_IDENTIFIER dots {
3338 $$ = make_duration ($1, scm_to_int ($2));
3342 multiplied_duration:
3343 steno_duration multipliers {
3344 $$ = make_duration ($1, 0, $2);
3353 $$ = scm_oneplus ($1);
3362 | multipliers '*' UNSIGNED
3364 if (!SCM_UNBNDP ($1))
3365 $$ = scm_product ($1, $3);
3369 | multipliers '*' FRACTION
3371 if (!SCM_UNBNDP ($1))
3372 $$ = scm_product ($1, scm_divide (scm_car ($3),
3375 $$ = scm_divide (scm_car ($3), scm_cdr ($3));
3381 $$ = scm_from_int (parser->default_tremolo_type_);
3384 if (SCM_UNBNDP (make_duration ($2))) {
3385 parser->parser_error (@2, _ ("not a duration"));
3386 $$ = scm_from_int (parser->default_tremolo_type_);
3389 parser->default_tremolo_type_ = scm_to_int ($2);
3395 UNSIGNED { $$ = $1; }
3396 | STRING { $$ = $1; }
3397 | full_markup { $$ = $1; }
3400 // as an integer, it needs to be non-negative, and otherwise
3401 // it needs to be suitable as a markup.
3402 if (scm_is_integer ($1)
3403 ? scm_is_true (scm_negative_p ($1))
3404 : !Text_interface::is_markup ($1))
3406 parser->parser_error (@1, _ ("bass number expected"));
3412 figured_bass_alteration:
3413 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3414 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3415 | '!' { $$ = scm_from_int (0); }
3420 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3421 $$ = bfr->unprotect ();
3424 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3425 $$ = bfr->self_scm ();
3427 if (scm_is_number ($1))
3428 bfr->set_property ("figure", $1);
3429 else if (Text_interface::is_markup ($1))
3430 bfr->set_property ("text", $1);
3436 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3438 | bass_figure figured_bass_alteration {
3439 Music *m = unsmob<Music> ($1);
3440 if (scm_to_double ($2)) {
3441 SCM salter = m->get_property ("alteration");
3442 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3443 m->set_property ("alteration",
3444 scm_sum (alter, $2));
3446 m->set_property ("alteration", scm_from_int (0));
3449 | bass_figure figured_bass_modification {
3450 Music *m = unsmob<Music> ($1);
3451 m->set_property ($2, SCM_BOOL_T);
3456 figured_bass_modification:
3458 $$ = ly_symbol2scm ("augmented");
3461 $$ = ly_symbol2scm ("no-continuation");
3464 $$ = ly_symbol2scm ("diminished");
3467 $$ = ly_symbol2scm ("augmented-slash");
3477 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3485 | figure_list br_bass_figure {
3486 $$ = scm_cons ($2, $1);
3491 /**/ { $$ = SCM_BOOL_F; }
3492 | REST { $$ = SCM_BOOL_T; }
3496 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3497 if (!parser->lexer_->is_note_state ())
3498 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3499 if (!SCM_UNBNDP ($2)
3501 || scm_is_number ($4)
3504 || scm_is_pair ($7))
3507 if (scm_is_true ($6))
3508 n = MY_MAKE_MUSIC ("RestEvent", @$);
3510 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3512 n->set_property ("pitch", $1);
3513 if (SCM_UNBNDP ($5))
3514 n->set_property ("duration",
3515 parser->default_duration_.smobbed_copy ());
3517 n->set_property ("duration", $5);
3519 if (scm_is_number ($4))
3521 int q = scm_to_int ($4);
3522 n->set_property ("absolute-octave", scm_from_int (q-1));
3525 if (to_boolean ($3))
3526 n->set_property ("cautionary", SCM_BOOL_T);
3527 if (to_boolean ($2) || to_boolean ($3))
3528 n->set_property ("force-accidental", SCM_BOOL_T);
3529 if (scm_is_pair ($7))
3530 n->set_property ("articulations",
3531 scm_reverse_x ($7, SCM_EOL));
3532 $$ = n->unprotect ();
3535 | new_chord post_events {
3536 if (!parser->lexer_->is_chord_state ())
3537 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3538 if (scm_is_pair ($2)) {
3539 if (unsmob<Pitch> ($1))
3540 $1 = make_chord_elements (@1,
3542 parser->default_duration_.smobbed_copy (),
3545 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3547 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3548 } else if (!unsmob<Pitch> ($1))
3549 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3550 // A mere pitch drops through.
3555 DRUM_PITCH optional_notemode_duration {
3556 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3557 n->set_property ("duration", $2);
3558 n->set_property ("drum-type", $1);
3560 $$ = n->unprotect ();
3562 | RESTNAME optional_notemode_duration {
3564 if (ly_scm2string ($1) == "s") {
3566 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3569 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3572 ev->set_property ("duration", $2);
3573 $$ = ev->unprotect ();
3579 if (!parser->lexer_->is_lyric_state ())
3580 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3584 if (!parser->lexer_->is_lyric_state ())
3585 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3591 lyric_element_music:
3592 lyric_element optional_notemode_duration post_events {
3593 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3594 if (scm_is_pair ($3))
3595 unsmob<Music> ($$)->set_property
3596 ("articulations", scm_reverse_x ($3, SCM_EOL));
3600 // Can return a single pitch rather than a list.
3602 steno_tonic_pitch maybe_notemode_duration {
3603 if (SCM_UNBNDP ($2))
3606 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3608 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3609 SCM its = scm_reverse_x ($4, SCM_EOL);
3610 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3618 | chord_items chord_item {
3619 $$ = scm_cons ($2, $$);
3625 $$ = ly_symbol2scm ("chord-colon");
3628 $$ = ly_symbol2scm ("chord-caret");
3630 | CHORD_SLASH steno_tonic_pitch {
3631 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3633 | CHORD_BASS steno_tonic_pitch {
3634 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3643 $$ = scm_reverse_x ($1, SCM_EOL);
3651 step_number { $$ = scm_cons ($1, SCM_EOL); }
3652 | step_numbers '.' step_number {
3653 $$ = scm_cons ($3, $$);
3659 $$ = make_chord_step ($1, 0);
3662 $$ = make_chord_step ($1, SHARP_ALTERATION);
3664 | UNSIGNED CHORD_MINUS {
3665 $$ = make_chord_step ($1, FLAT_ALTERATION);
3673 | unsigned_number '-' unsigned_number {
3674 $$ = scm_cons ($1, $3);
3681 TODO: should deprecate in favor of Scheme?
3685 number_expression '+' number_term {
3686 $$ = scm_sum ($1, $3);
3688 | number_expression '-' number_term {
3689 $$ = scm_difference ($1, $3);
3698 | number_factor '*' number_factor {
3699 $$ = scm_product ($1, $3);
3701 | number_factor '/' number_factor {
3702 $$ = scm_divide ($1, $3);
3707 '-' number_factor { /* %prec UNARY_MINUS */
3708 $$ = scm_difference ($2, SCM_UNDEFINED);
3716 | REAL NUMBER_IDENTIFIER
3718 $$ = scm_product ($1, $2);
3725 | UNSIGNED NUMBER_IDENTIFIER {
3726 $$ = scm_product ($1, $2);
3734 if (!scm_is_integer ($1)
3735 || scm_is_true (scm_negative_p ($1)))
3737 parser->parser_error (@1, _("not an unsigned integer"));
3743 if (!scm_is_integer ($1)
3744 || scm_is_true (scm_negative_p ($1)))
3746 parser->parser_error (@1, _("not an unsigned integer"));
3753 { $$ = SCM_UNDEFINED; }
3756 if (SCM_UNBNDP ($1))
3764 // This precedence rule is rather weird. It triggers when '!' is
3765 // encountered after a pitch, and is used for deciding whether to save
3766 // this instead for a figure modification. This should not actually
3767 // occur in practice as pitches and figures are generated in different
3768 // modes. Using a greedy (%right) precedence makes sure that we don't
3769 // get stuck in a wrong interpretation.
3770 { $$ = SCM_UNDEFINED; } %prec ':'
3773 if (SCM_UNBNDP ($1))
3782 { parser->lexer_->push_markup_state (); }
3785 parser->lexer_->pop_state ();
3792 parser->lexer_->push_markup_state ();
3797 markup_mode markup_top {
3799 parser->lexer_->pop_state ();
3804 markup_mode markup_partial_function ETC
3806 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3807 parser->lexer_->pop_state ();
3813 $$ = scm_list_2 (Lily::line_markup, $1);
3815 | markup_head_1_list simple_markup
3817 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3818 @2, $1, scm_list_1 ($2)));
3828 if (Text_interface::is_markup ($1))
3829 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3830 else if (Text_interface::is_markup_list ($1))
3831 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3833 parser->parser_error (@1, _ ("not a markup"));
3834 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3841 markup_composed_list {
3844 | markup_uncomposed_list
3847 markup_uncomposed_list:
3848 markup_braced_list {
3851 | markup_command_list {
3852 $$ = scm_list_1 ($1);
3854 | markup_scm MARKUPLIST_IDENTIFIER
3859 parser->lexer_->push_note_state (Lily::pitchnames);
3860 } '{' score_body '}' {
3861 Score *sc = unsmob<Score> ($4);
3862 sc->origin ()->set_spot (@$);
3863 if (sc->defs_.empty ()) {
3864 Output_def *od = get_layout (parser);
3865 sc->add_output_def (od);
3868 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3869 parser->lexer_->pop_state ();
3873 markup_composed_list:
3874 markup_head_1_list markup_uncomposed_list {
3875 $$ = MAKE_SYNTAX (composed_markup_list,
3881 '{' markup_braced_list_body '}' {
3882 $$ = scm_reverse_x ($2, SCM_EOL);
3886 markup_braced_list_body:
3887 /* empty */ { $$ = SCM_EOL; }
3888 | markup_braced_list_body markup {
3889 $$ = scm_cons ($2, $1);
3891 | markup_braced_list_body markup_list {
3892 $$ = scm_reverse_x ($2, $1);
3896 markup_command_list:
3897 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3898 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3902 markup_command_basic_arguments:
3903 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3904 $$ = scm_cons ($3, $2);
3906 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3907 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3909 | EXPECT_NO_MORE_ARGS {
3914 markup_command_list_arguments:
3915 markup_command_basic_arguments { $$ = $1; }
3916 | EXPECT_MARKUP markup_command_list_arguments markup {
3917 $$ = scm_cons ($3, $2);
3921 markup_partial_function:
3922 MARKUP_FUNCTION markup_arglist_partial
3924 $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
3926 | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
3928 $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
3933 markup_arglist_partial:
3934 EXPECT_MARKUP markup_arglist_partial
3938 | EXPECT_SCM markup_arglist_partial
3942 | EXPECT_MARKUP markup_command_list_arguments
3946 | EXPECT_SCM markup_command_list_arguments
3953 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3954 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3959 markup_head_1_item {
3960 $$ = scm_list_1 ($1);
3962 | markup_head_1_list markup_head_1_item {
3963 $$ = scm_cons ($2, $1);
3969 $$ = make_simple_markup ($1);
3972 parser->lexer_->push_note_state (Lily::pitchnames);
3973 } '{' score_body '}' {
3974 Score *sc = unsmob<Score> ($4);
3975 sc->origin ()->set_spot (@$);
3976 if (sc->defs_.empty ()) {
3977 Output_def *od = get_layout (parser);
3978 sc->add_output_def (od);
3981 $$ = scm_list_2 (Lily::score_markup, $4);
3982 parser->lexer_->pop_state ();
3984 | MARKUP_FUNCTION markup_command_basic_arguments {
3985 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3987 | markup_scm MARKUP_IDENTIFIER
3994 markup_head_1_list simple_markup
3996 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3997 @2, $1, scm_list_1 ($2)));
4007 Lily_parser::set_yydebug (bool x)
4013 Lily_parser::do_yyparse ()
4015 return scm_c_with_fluid (Lily::f_parser,
4017 do_yyparse_trampoline,
4018 static_cast <void *>(this));
4022 Lily_parser::do_yyparse_trampoline (void *parser)
4024 SCM retval = SCM_UNDEFINED;
4025 yyparse (static_cast <Lily_parser *>(parser), &retval);
4033 It is a little strange to have this function in this file, but
4034 otherwise, we have to import music classes into the lexer.
4038 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
4040 if (unsmob<Book> (sid)) {
4041 Book *book = unsmob<Book> (sid)->clone ();
4042 *destination = book->self_scm ();
4045 return BOOK_IDENTIFIER;
4046 } else if (scm_is_number (sid)) {
4048 return NUMBER_IDENTIFIER;
4049 } else if (unsmob<Context_def> (sid))
4051 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
4052 return SCM_IDENTIFIER;
4053 } else if (unsmob<Context_mod> (sid)) {
4054 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
4055 return CONTEXT_MOD_IDENTIFIER;
4056 } else if (Music *mus = unsmob<Music> (sid)) {
4057 mus = mus->clone ();
4058 *destination = mus->self_scm ();
4059 bool is_event = mus->is_mus_type ("post-event");
4061 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
4062 } else if (unsmob<Pitch> (sid)) {
4063 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
4064 return PITCH_IDENTIFIER;
4065 } else if (unsmob<Duration> (sid)) {
4066 *destination = unsmob<Duration> (sid)->smobbed_copy ();
4067 return DURATION_IDENTIFIER;
4068 } else if (unsmob<Output_def> (sid)) {
4069 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
4070 return SCM_IDENTIFIER;
4071 } else if (unsmob<Score> (sid)) {
4072 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
4073 return SCM_IDENTIFIER;
4074 } else if (scm_is_pair (sid)
4075 && scm_is_pair (scm_car (sid))
4076 && scm_is_true (Lily::key_p (scm_caar (sid)))) {
4078 return LOOKUP_IDENTIFIER;
4084 get_next_unique_context_id ()
4086 return scm_from_ascii_string ("$uniqueContextId");
4091 get_next_unique_lyrics_context_id ()
4093 static int new_context_count;
4095 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
4096 return scm_from_ascii_string (s);
4099 // check_scheme_arg checks one argument with a given predicate for use
4100 // in an argument list and throws a syntax error if it is unusable.
4101 // The argument is prepended to the argument list in any case. After
4102 // throwing a syntax error, the argument list is terminated with #f as
4103 // its last cdr in order to mark it as uncallable while not losing
4104 // track of its total length.
4106 // There are a few special considerations: if optional argument disp
4107 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
4108 // instead of arg in a prospective error message. This is useful if
4109 // arg is not the actual argument but rather a transformation of it.
4111 // If arg itself is SCM_UNDEFINED, the predicate is considered false
4112 // and an error message using disp is produced unconditionally.
4114 SCM check_scheme_arg (Lily_parser *parser, Input loc,
4115 SCM arg, SCM args, SCM pred, SCM disp)
4117 if (SCM_UNBNDP (arg))
4118 args = scm_cons (disp, args);
4120 args = scm_cons (arg, args);
4121 if (scm_is_true (scm_call_1 (pred, arg)))
4124 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
4125 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
4126 SCM_UNBNDP (disp) ? arg : disp);
4127 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
4131 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
4133 if (Music *m = unsmob<Music> (arg))
4136 m->set_spot (parser->lexer_->override_input (loc));
4137 return m->unprotect ();
4143 try_string_variants (SCM pred, SCM str)
4145 // a matching predicate is always ok
4146 if (scm_is_true (scm_call_1 (pred, str)))
4148 // a symbol may be interpreted as a list of symbols if it helps
4149 if (scm_is_true (Lily::key_p (str))) {
4150 str = scm_list_1 (str);
4151 if (scm_is_true (scm_call_1 (pred, str)))
4153 return SCM_UNDEFINED;
4156 // If this cannot be a string representation of a symbol list,
4159 if (!is_regular_identifier (str, true))
4160 return SCM_UNDEFINED;
4162 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4163 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4164 scm_set_car_x (p, scm_string_split (scm_car (p),
4165 SCM_MAKE_CHAR (',')));
4166 str = scm_append_x (str);
4167 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4168 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4170 // Let's attempt the symbol list interpretation first.
4172 if (scm_is_true (scm_call_1 (pred, str)))
4175 // If there is just one symbol in the list, we might interpret
4176 // it as a single symbol
4178 if (scm_is_null (scm_cdr (str)))
4180 str = scm_car (str);
4181 if (scm_is_true (scm_call_1 (pred, str)))
4185 return SCM_UNDEFINED;
4189 is_regular_identifier (SCM id, bool multiple)
4191 if (!scm_is_string (id))
4194 string str = ly_scm2string (id);
4196 bool middle = false;
4198 for (string::iterator it=str.begin(); it != str.end (); it++)
4201 if ((c >= 'a' && c <= 'z')
4202 || (c >= 'A' && c <= 'Z')
4205 else if (middle && (c == '-' || c == '_' || (multiple &&
4206 (c == '.' || c == ','))))
4215 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4217 if (unsmob<Music> (simple))
4219 if (parser->lexer_->is_note_state ()) {
4220 if (scm_is_symbol (simple)) {
4221 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4222 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4223 n->set_property ("drum-type", simple);
4224 return n->unprotect ();
4226 if (unsmob<Pitch> (simple)) {
4227 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4228 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4229 n->set_property ("pitch", simple);
4230 return n->unprotect ();
4233 if (scm_is_integer (simple))
4234 d = make_duration (simple);
4235 if (unsmob<Duration> (d)) {
4236 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4237 n->set_property ("duration", d);
4238 return n->unprotect ();
4241 } else if (parser->lexer_->is_lyric_state ()) {
4242 if (Text_interface::is_markup (simple))
4243 return MAKE_SYNTAX (lyric_event, loc, simple,
4244 parser->default_duration_.smobbed_copy ());
4245 } else if (parser->lexer_->is_chord_state ()) {
4246 if (unsmob<Pitch> (simple))
4250 make_chord_elements (loc, simple,
4251 parser->default_duration_.smobbed_copy (),
4258 make_music_with_input (SCM name, Input where)
4260 Music *m = make_music_by_name (name);
4261 m->set_spot (where);
4266 make_simple_markup (SCM a)
4272 make_duration (SCM d, int dots, SCM factor)
4276 if (Duration *dur = unsmob<Duration> (d)) {
4277 if (!dots && SCM_UNBNDP (factor))
4281 k = Duration (k.duration_log (), k.dot_count () + dots)
4282 .compressed (k.factor ());
4284 int t = scm_to_int (d);
4285 if (t > 0 && (t & (t-1)) == 0)
4286 k = Duration (intlog2 (t), dots);
4288 return SCM_UNDEFINED;
4291 if (!SCM_UNBNDP (factor))
4292 k = k.compressed (ly_scm2rational (factor));
4294 return k.smobbed_copy ();
4298 make_chord_step (SCM step_scm, Rational alter)
4300 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4302 // Notename/octave are normalized
4303 if (m.get_notename () == 6)
4304 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4306 return m.smobbed_copy ();
4311 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4313 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4314 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4316 unsmob<Music> (scm_car (s))->set_spot (loc);
4322 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4324 Lily_lexer *lex = parser->lexer_;
4328 int tok = lex->pop_extra_token ();
4331 lex->prepare_for_next_token ();
4332 return lex->yylex ();