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-def.hh"
123 #include "context-mod.hh"
124 #include "dimensions.hh"
125 #include "file-path.hh"
127 #include "international.hh"
128 #include "lily-guile.hh"
129 #include "lily-lexer.hh"
130 #include "lily-parser.hh"
131 #include "ly-module.hh"
135 #include "output-def.hh"
136 #include "paper-book.hh"
137 #include "scm-hash.hh"
139 #include "text-interface.hh"
141 #include "lily-imports.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
146 parser->parser_error (*i, s);
149 // The following are somewhat precarious constructs as they may change
150 // the value of the lookahead token. That implies that the lookahead
151 // token must not yet have made an impact on the state stack other
152 // than causing the reduction of the current rule, or switching the
153 // lookahead token while Bison is mulling it over will cause trouble.
155 #define MYBACKUP(Token, Value, Location) \
157 if (yychar != YYEMPTY) \
158 parser->lexer_->push_extra_token \
159 (yylloc, yychar, yylval); \
161 parser->lexer_->push_extra_token \
162 (Location, Token, Value); \
163 parser->lexer_->push_extra_token (Location, BACKUP); \
168 #define MYREPARSE(Location, Pred, Token, Value) \
170 if (yychar != YYEMPTY) \
171 parser->lexer_->push_extra_token \
172 (yylloc, yychar, yylval); \
173 parser->lexer_->push_extra_token \
174 (Location, Token, Value); \
175 parser->lexer_->push_extra_token \
176 (Location, REPARSE, Pred); \
185 #define MY_MAKE_MUSIC(x, spot) \
186 make_music_with_input (ly_symbol2scm (x), \
187 parser->lexer_->override_input (spot))
190 - delay application of the function
193 #define LOWLEVEL_MAKE_SYNTAX(location, proc, ...) \
195 (parser->lexer_->override_input (location).smobbed_copy (), \
199 /* Syntactic Sugar. */
200 #define MAKE_SYNTAX(name, location, ...) \
201 LOWLEVEL_MAKE_SYNTAX (location, Syntax::name, ##__VA_ARGS__)
203 #define START_MAKE_SYNTAX(name, ...) \
204 scm_list_n (Syntax::name, ##__VA_ARGS__, SCM_UNDEFINED)
206 #define FINISH_MAKE_SYNTAX(start, location, ...) \
207 LOWLEVEL_MAKE_SYNTAX \
212 (scm_list_2 (scm_cdr (start), \
213 scm_list_n (__VA_ARGS__, SCM_UNDEFINED))))
215 SCM get_next_unique_context_id ();
216 SCM get_next_unique_lyrics_context_id ();
223 #define _(x) gettext (x)
227 static Music *make_music_with_input (SCM name, Input where);
228 SCM check_scheme_arg (Lily_parser *parser, Input loc,
229 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
230 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
231 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg);
232 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
233 SCM make_chord_step (SCM step, Rational alter);
234 SCM make_simple_markup (SCM a);
235 SCM make_duration (SCM t, int dots = 0, SCM factor = SCM_UNDEFINED);
236 bool is_regular_identifier (SCM id, bool multiple=false);
237 SCM try_string_variants (SCM pred, SCM str);
238 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
242 /* The third option is an alias that will be used to display the
243 syntax error. Bison CVS now correctly handles backslash escapes.
245 FIXME: Bison needs to translate some of these, eg, STRING.
249 /* Keyword tokens with plain escaped name. */
250 %token END_OF_FILE 0 "end of input"
251 %token ACCEPTS "\\accepts"
252 %token ADDLYRICS "\\addlyrics"
253 %token ALIAS "\\alias"
254 %token ALTERNATIVE "\\alternative"
256 %token BOOKPART "\\bookpart"
257 %token CHANGE "\\change"
258 %token CHORDMODE "\\chordmode"
259 %token CHORDS "\\chords"
260 %token CONSISTS "\\consists"
261 %token CONTEXT "\\context"
262 %token DEFAULT "\\default"
263 %token DEFAULTCHILD "\\defaultchild"
264 %token DENIES "\\denies"
265 %token DESCRIPTION "\\description"
266 %token DRUMMODE "\\drummode"
267 %token DRUMS "\\drums"
269 %token FIGUREMODE "\\figuremode"
270 %token FIGURES "\\figures"
271 %token HEADER "\\header"
272 %token INVALID "\\version-error"
273 %token LAYOUT "\\layout"
274 %token LYRICMODE "\\lyricmode"
275 %token LYRICS "\\lyrics"
276 %token LYRICSTO "\\lyricsto"
277 %token MARKUP "\\markup"
278 %token MARKUPLIST "\\markuplist"
281 %token NOTEMODE "\\notemode"
282 %token OVERRIDE "\\override"
283 %token PAPER "\\paper"
284 %token REMOVE "\\remove"
285 %token REPEAT "\\repeat"
287 %token REVERT "\\revert"
288 %token SCORE "\\score"
289 %token SCORELINES "\\score-lines"
290 %token SEQUENTIAL "\\sequential"
292 %token SIMULTANEOUS "\\simultaneous"
293 %token TEMPO "\\tempo"
295 %token UNSET "\\unset"
298 /* Keyword token exceptions. */
299 %token NEWCONTEXT "\\new"
302 /* Other string tokens. */
304 %token CHORD_BASS "/+"
305 %token CHORD_CARET "^"
306 %token CHORD_COLON ":"
307 %token CHORD_MINUS "-"
308 %token CHORD_SLASH "/"
309 %token ANGLE_OPEN "<"
310 %token ANGLE_CLOSE ">"
311 %token DOUBLE_ANGLE_OPEN "<<"
312 %token DOUBLE_ANGLE_CLOSE ">>"
313 %token E_BACKSLASH "\\"
314 %token E_EXCLAMATION "\\!"
319 If we give names, Bison complains.
321 %token FIGURE_CLOSE /* "\\>" */
322 %token FIGURE_OPEN /* "\\<" */
323 %token FIGURE_SPACE "_"
326 %token MULTI_MEASURE_REST
332 /* Artificial tokens, for more generic function syntax */
333 %token EXPECT_MARKUP "markup?"
334 %token EXPECT_SCM "scheme?"
335 %token BACKUP "(backed-up?)"
336 %token REPARSE "(reparsed?)"
337 %token EXPECT_MARKUP_LIST "markup-list?"
338 %token EXPECT_OPTIONAL "optional?"
339 /* After the last argument. */
340 %token EXPECT_NO_MORE_ARGS;
342 /* An artificial token for parsing embedded Lilypond */
343 %token EMBEDDED_LILY "#{"
345 %token BOOK_IDENTIFIER
346 %token CHORD_MODIFIER
347 %token CHORD_REPETITION
348 %token CONTEXT_MOD_IDENTIFIER
350 /* Artificial token for durations in argument lists */
352 %token DURATION_IDENTIFIER
353 %token EVENT_IDENTIFIER
354 %token EVENT_FUNCTION
357 %token MARKUP_FUNCTION
358 %token MARKUP_LIST_FUNCTION
359 %token MARKUP_IDENTIFIER
360 %token MARKUPLIST_IDENTIFIER
361 %token MUSIC_FUNCTION
362 %token MUSIC_IDENTIFIER
363 %token NOTENAME_PITCH
364 %token NUMBER_IDENTIFIER
365 %token PITCH_IDENTIFIER
370 %token SCM_IDENTIFIER
374 %token TONICNAME_PITCH
378 /* We don't assign precedence to / and *, because we might need varied
379 prec levels in different prods */
388 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
389 parser->lexer_->push_note_state (nn);
390 } embedded_lilypond {
391 parser->lexer_->pop_state ();
396 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
397 | lilypond toplevel_expression {
399 | lilypond assignment {
402 parser->error_level_ = 1;
405 parser->error_level_ = 1;
412 parser->lexer_->add_scope (get_header (parser));
414 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
417 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
418 scm_call_1 (proc, $1);
421 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
422 scm_call_1 (proc, $1);
425 SCM proc = parser->lexer_->lookup_identifier
426 (unsmob<Book>($1)->paper_
427 ? "toplevel-book-handler"
428 : "toplevel-bookpart-handler");
429 scm_call_1 (proc, $1);
432 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
433 scm_call_1 (proc, $1);
436 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
437 scm_call_1 (proc, $1);
440 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
441 scm_call_1 (proc, scm_list_1 ($1));
444 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
445 scm_call_1 (proc, $1);
448 // Evaluate and ignore #xxx, as opposed to \xxx
449 parser->lexer_->eval_scm_token ($1, @1);
451 | embedded_scm_active
453 SCM out = SCM_UNDEFINED;
454 if (Text_interface::is_markup ($1))
455 out = scm_list_1 ($1);
456 else if (Text_interface::is_markup_list ($1))
458 if (scm_is_pair (out))
460 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
461 scm_call_1 (proc, out);
462 } else if (unsmob<Score> ($1))
464 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
465 scm_call_1 (proc, $1);
466 } else if (Output_def * od = unsmob<Output_def> ($1)) {
469 if (to_boolean (od->c_variable ("is-paper")))
470 id = ly_symbol2scm ("$defaultpaper");
471 else if (to_boolean (od->c_variable ("is-midi")))
472 id = ly_symbol2scm ("$defaultmidi");
473 else if (to_boolean (od->c_variable ("is-layout")))
474 id = ly_symbol2scm ("$defaultlayout");
476 parser->lexer_->set_identifier (id, $1);
477 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
478 parser->parser_error (@1, _("bad expression type"));
482 Output_def * od = unsmob<Output_def> ($1);
484 if (to_boolean (od->c_variable ("is-paper")))
485 id = ly_symbol2scm ("$defaultpaper");
486 else if (to_boolean (od->c_variable ("is-midi")))
487 id = ly_symbol2scm ("$defaultmidi");
488 else if (to_boolean (od->c_variable ("is-layout")))
489 id = ly_symbol2scm ("$defaultlayout");
491 parser->lexer_->set_identifier (id, $1);
498 $$ = parser->lexer_->eval_scm_token ($1, @1);
508 embedded_scm_bare_arg:
512 $$ = parser->lexer_->eval_scm_token ($1, @1);
517 | context_modification
519 | context_def_spec_block
525 /* The generic version may end in music, or not */
532 /* embedded_scm_arg is _not_ casting pitches to music by default, this
533 * has to be done by the function itself. Note that this may cause
534 * the results of scm_function_call or embedded_scm_bare_arg to be
535 * turned into music from pitches as well. Note that this creates a
536 * distinctly awkward situation for calculated drum pitches. Those
537 * are at the current point of time rejected as music constituents as
538 * they can't be distinguished from "proper" symbols.
542 embedded_scm_bare_arg
548 SCM_FUNCTION function_arglist {
549 $$ = MAKE_SYNTAX (music_function, @$,
554 embedded_lilypond_number:
555 '-' embedded_lilypond_number
557 $$ = scm_difference ($2, SCM_UNDEFINED);
560 | UNSIGNED NUMBER_IDENTIFIER
562 $$ = scm_product ($1, $2);
569 // FIXME: @$ does not contain a useful source location
570 // for empty rules, and the only token in the whole
571 // production, EMBEDDED_LILY, is synthetic and also
572 // contains no source location.
573 $$ = MAKE_SYNTAX (void_music, @$);
575 | identifier_init_nonumber
576 | embedded_lilypond_number
577 | post_event post_events
579 $$ = scm_reverse_x ($2, SCM_EOL);
580 if (Music *m = unsmob<Music> ($1))
582 if (m->is_mus_type ("post-event-wrapper"))
584 (scm_list_2 (m->get_property ("elements"),
587 $$ = scm_cons ($1, $$);
590 && scm_is_null (scm_cdr ($$)))
594 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
595 m->set_property ("elements", $$);
596 $$ = m->unprotect ();
599 | multiplied_duration
600 | music_embedded music_embedded music_list {
601 $3 = scm_reverse_x ($3, SCM_EOL);
602 if (unsmob<Music> ($2))
603 $3 = scm_cons ($2, $3);
604 if (unsmob<Music> ($1))
605 $3 = scm_cons ($1, $3);
606 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
609 parser->error_level_ = 1;
610 $$ = SCM_UNSPECIFIED;
612 | INVALID embedded_lilypond {
613 parser->error_level_ = 1;
619 lilypond_header_body:
620 /* empty */ { $$ = SCM_UNSPECIFIED; }
621 | lilypond_header_body assignment {
624 | lilypond_header_body embedded_scm {
630 HEADER '{' lilypond_header_body '}' {
631 $$ = parser->lexer_->remove_scope ();
643 assignment_id '=' identifier_init {
644 parser->lexer_->set_identifier ($1, $3);
645 $$ = SCM_UNSPECIFIED;
647 | assignment_id property_path '=' identifier_init {
648 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
649 parser->lexer_->set_identifier (path, $4);
650 $$ = SCM_UNSPECIFIED;
652 | assignment_id '.' property_path '=' identifier_init {
653 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
654 parser->lexer_->set_identifier (path, $5);
655 $$ = SCM_UNSPECIFIED;
657 | assignment_id ',' property_path '=' identifier_init {
658 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
659 parser->lexer_->set_identifier (path, $5);
660 $$ = SCM_UNSPECIFIED;
666 identifier_init_nonumber
668 | post_event_nofinger post_events
670 $$ = scm_reverse_x ($2, SCM_EOL);
671 if (Music *m = unsmob<Music> ($1))
673 if (m->is_mus_type ("post-event-wrapper"))
675 (scm_list_2 (m->get_property ("elements"),
678 $$ = scm_cons ($1, $$);
681 && scm_is_null (scm_cdr ($$)))
685 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
686 m->set_property ("elements", $$);
687 $$ = m->unprotect ();
692 identifier_init_nonumber:
697 | context_def_spec_block
705 | context_modification
706 | partial_function ETC
708 $$ = MAKE_SYNTAX (partial_music_function, @$,
709 scm_reverse_x ($1, SCM_EOL));
715 MUSIC_FUNCTION function_arglist_partial
717 $$ = scm_acons ($1, $2, SCM_EOL);
719 | EVENT_FUNCTION function_arglist_partial
721 $$ = scm_acons ($1, $2, SCM_EOL);
723 | SCM_FUNCTION function_arglist_partial
725 $$ = scm_acons ($1, $2, SCM_EOL);
727 | OVERRIDE grob_prop_path '='
730 $$ = scm_list_1 (SCM_BOOL_F);
733 (scm_list_3 (Syntax::property_override_function,
734 scm_cdr ($2), scm_car ($2)),
737 | SET context_prop_spec '='
740 $$ = scm_list_1 (SCM_BOOL_F);
743 (scm_list_3 (Syntax::property_set_function,
744 scm_cadr ($2), scm_car ($2)),
747 | MUSIC_FUNCTION EXPECT_SCM function_arglist_optional partial_function
749 $$ = scm_acons ($1, $3, $4);
751 | EVENT_FUNCTION EXPECT_SCM function_arglist_optional partial_function
753 $$ = scm_acons ($1, $3, $4);
755 | SCM_FUNCTION EXPECT_SCM function_arglist_optional partial_function
757 $$ = scm_acons ($1, $3, $4);
759 | OVERRIDE grob_prop_path '=' partial_function
762 $$ = scm_list_1 (SCM_BOOL_F);
765 (scm_list_3 (Syntax::property_override_function,
766 scm_cdr ($2), scm_car ($2)),
769 | SET context_prop_spec '=' partial_function
772 $$ = scm_list_1 (SCM_BOOL_F);
775 (scm_list_3 (Syntax::property_set_function,
776 scm_cadr ($2), scm_car ($2)),
779 | MUSIC_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
781 $$ = scm_acons ($1, $4, $5);
783 | EVENT_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
785 $$ = scm_acons ($1, $4, $5);
787 | SCM_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
789 $$ = scm_acons ($1, $4, $5);
793 context_def_spec_block:
794 CONTEXT '{' context_def_spec_body '}'
797 Context_def *td = unsmob<Context_def> ($$);
799 $$ = Context_def::make_scm ();
800 td = unsmob<Context_def> ($$);
802 td->origin ()->set_spot (@$);
810 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
811 parser->lexer_->push_note_state (nn);
815 parser->lexer_->pop_state ();
821 context_def_spec_body:
823 $$ = SCM_UNSPECIFIED;
825 | context_def_spec_body context_mod {
826 if (!SCM_UNBNDP ($2)) {
827 Context_def *td = unsmob<Context_def> ($$);
829 $$ = Context_def::make_scm ();
830 td = unsmob<Context_def> ($$);
832 unsmob<Context_def> ($$)->add_context_mod ($2);
835 | context_def_spec_body context_modification {
836 Context_def *td = unsmob<Context_def> ($$);
838 $$ = Context_def::make_scm ();
839 td = unsmob<Context_def> ($$);
841 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
842 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
843 td->add_context_mod (scm_car (m));
846 | context_def_spec_body context_mod_arg {
847 Context_def *td = unsmob<Context_def> ($1);
848 if (scm_is_eq ($2, SCM_UNSPECIFIED))
850 else if (!td && unsmob<Context_def> ($2))
854 $$ = Context_def::make_scm ();
855 td = unsmob<Context_def> ($$);
857 if (unsmob<Music> ($2)) {
858 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
859 $2 = scm_call_1 (proc, $2);
861 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
862 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
863 td->add_context_mod (scm_car (m));
866 parser->parser_error (@2, _ ("not a context mod"));
874 BOOK '{' book_body '}' {
876 unsmob<Book> ($$)->origin ()->set_spot (@$);
878 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
883 * Use 'handlers' like for toplevel-* stuff?
884 * grok \layout and \midi? */
887 Book *book = new Book;
888 init_papers (parser);
889 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
890 book->paper_->unprotect ();
891 push_paper (parser, book->paper_);
892 book->header_ = get_header (parser);
893 $$ = book->unprotect ();
894 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
897 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
899 | book_body paper_block {
900 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
901 set_paper (parser, unsmob<Output_def> ($2));
903 | book_body bookpart_block {
904 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
905 scm_call_2 (proc, $1, $2);
907 | book_body score_block {
908 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
909 scm_call_2 (proc, $1, $2);
911 | book_body composite_music {
912 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
913 scm_call_2 (proc, $1, $2);
915 | book_body full_markup {
916 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
917 scm_call_2 (proc, $1, scm_list_1 ($2));
919 | book_body full_markup_list {
920 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
921 scm_call_2 (proc, $1, $2);
923 | book_body SCM_TOKEN {
924 // Evaluate and ignore #xxx, as opposed to \xxx
925 parser->lexer_->eval_scm_token ($2, @2);
927 | book_body embedded_scm_active
929 SCM out = SCM_UNDEFINED;
930 if (Text_interface::is_markup ($2))
931 out = scm_list_1 ($2);
932 else if (Text_interface::is_markup_list ($2))
934 if (scm_is_pair (out))
936 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
937 scm_call_2 (proc, $1, out);
938 } else if (unsmob<Score> ($2))
940 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
941 scm_call_2 (proc, $1, $2);
942 } else if (Output_def *od = unsmob<Output_def> ($2)) {
945 if (to_boolean (od->c_variable ("is-paper")))
946 id = ly_symbol2scm ("$defaultpaper");
947 else if (to_boolean (od->c_variable ("is-midi")))
948 id = ly_symbol2scm ("$defaultmidi");
949 else if (to_boolean (od->c_variable ("is-layout")))
950 id = ly_symbol2scm ("$defaultlayout");
952 parser->lexer_->set_identifier (id, $2);
953 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
954 parser->parser_error (@2, _("bad expression type"));
958 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
961 Book *book = unsmob<Book> ($1);
963 book->scores_ = SCM_EOL;
964 book->bookparts_ = SCM_EOL;
969 BOOKPART '{' bookpart_body '}' {
971 unsmob<Book> ($$)->origin ()->set_spot (@$);
972 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
978 Book *book = new Book;
979 $$ = book->unprotect ();
980 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
983 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
985 | bookpart_body paper_block {
986 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
988 | bookpart_body score_block {
989 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
990 scm_call_2 (proc, $1, $2);
992 | bookpart_body composite_music {
993 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
994 scm_call_2 (proc, $1, $2);
996 | bookpart_body full_markup {
997 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
998 scm_call_2 (proc, $1, scm_list_1 ($2));
1000 | bookpart_body full_markup_list {
1001 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1002 scm_call_2 (proc, $1, $2);
1004 | bookpart_body SCM_TOKEN {
1005 // Evaluate and ignore #xxx, as opposed to \xxx
1006 parser->lexer_->eval_scm_token ($2, @2);
1008 | bookpart_body embedded_scm_active
1010 SCM out = SCM_UNDEFINED;
1011 if (Text_interface::is_markup ($2))
1012 out = scm_list_1 ($2);
1013 else if (Text_interface::is_markup_list ($2))
1015 if (scm_is_pair (out))
1017 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1018 scm_call_2 (proc, $1, out);
1019 } else if (unsmob<Score> ($2))
1021 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1022 scm_call_2 (proc, $1, $2);
1023 } else if (Output_def *od = unsmob<Output_def> ($2)) {
1026 if (to_boolean (od->c_variable ("is-paper")))
1027 id = ly_symbol2scm ("$defaultpaper");
1028 else if (to_boolean (od->c_variable ("is-midi")))
1029 id = ly_symbol2scm ("$defaultmidi");
1030 else if (to_boolean (od->c_variable ("is-layout")))
1031 id = ly_symbol2scm ("$defaultlayout");
1033 parser->lexer_->set_identifier (id, $2);
1034 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1035 parser->parser_error (@2, _("bad expression type"));
1039 Book *book = unsmob<Book> ($1);
1040 if (!ly_is_module (book->header_))
1041 book->header_ = ly_make_module (false);
1042 parser->lexer_->add_scope (book->header_);
1044 | bookpart_body error {
1045 Book *book = unsmob<Book> ($1);
1047 book->scores_ = SCM_EOL;
1052 SCORE '{' score_body '}' {
1053 unsmob<Score> ($3)->origin ()->set_spot (@$);
1060 if (!unsmob<Score> ($1)) {
1061 parser->parser_error (@1, _("Missing music in \\score"));
1062 $$ = (new Score)->unprotect ();
1063 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
1065 unsmob<Score> ($$)->set_header (scm_car ($1));
1068 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1069 scm_is_pair (p); p = scm_cdr (p))
1071 unsmob<Score> ($$)->
1072 add_output_def (unsmob<Output_def> (scm_car (p)));
1076 | score_body error {
1077 unsmob<Score> ($$)->error_found_ = true;
1092 | score_items score_item
1094 Output_def *od = unsmob<Output_def> ($2);
1096 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1098 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1100 $2 = SCM_UNSPECIFIED;
1102 } else if (!unsmob<Score> ($$)) {
1103 if (unsmob<Music> ($2)) {
1104 $2 = Lily::scorify_music ($2);
1106 if (unsmob<Score> ($2))
1109 $2 = SCM_UNSPECIFIED;
1112 Score *score = unsmob<Score> ($$);
1113 if (score && scm_is_pair ($1)) {
1114 if (ly_is_module (scm_car ($1)))
1116 score->set_header (scm_car ($1));
1119 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1120 scm_is_pair (p); p = scm_cdr (p))
1122 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1127 score->add_output_def (od);
1128 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1129 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1131 $$ = scm_cons ($2, $$);
1132 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1133 parser->parser_error (@2, _("Spurious expression in \\score"));
1137 if (Score *score = unsmob<Score> ($1)) {
1138 if (!ly_is_module (score->get_header ()))
1139 score->set_header (ly_make_module (false));
1140 parser->lexer_->add_scope (score->get_header ());
1142 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1143 $1 = scm_cons (ly_make_module (false), $1);
1144 parser->lexer_->add_scope (scm_car ($1));
1159 Output_def *od = unsmob<Output_def> ($1);
1161 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1163 parser->parser_error (@1, _ ("need \\paper for paper block"));
1164 $$ = get_paper (parser)->unprotect ();
1171 output_def_body '}' {
1172 if (scm_is_pair ($1))
1175 parser->lexer_->remove_scope ();
1176 parser->lexer_->pop_state ();
1182 Output_def *p = get_paper (parser);
1183 p->input_origin_ = @$;
1184 parser->lexer_->add_scope (p->scope_);
1185 $$ = p->unprotect ();
1188 Output_def *p = get_midi (parser);
1189 $$ = p->unprotect ();
1190 parser->lexer_->add_scope (p->scope_);
1193 Output_def *p = get_layout (parser);
1195 parser->lexer_->add_scope (p->scope_);
1196 $$ = p->unprotect ();
1200 output_def_head_with_mode_switch:
1202 parser->lexer_->push_initial_state ();
1207 // We need this weird nonterminal because both music as well as a
1208 // context definition can start with \context and the difference is
1209 // only apparent after looking at the next token. If it is '{', there
1210 // is still time to escape from notes mode.
1212 music_or_context_def:
1214 | context_def_spec_block
1218 output_def_head_with_mode_switch '{' {
1219 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1220 // This is a stupid trick to mark the beginning of the
1221 // body for deciding whether to allow
1222 // embedded_scm_active to have an output definition
1223 $$ = scm_list_1 ($1);
1225 | output_def_body assignment {
1226 if (scm_is_pair ($1))
1229 | output_def_body embedded_scm_active
1231 // We don't switch into note mode for Scheme functions
1232 // here. Does not seem warranted/required in output
1234 if (scm_is_pair ($1))
1236 Output_def *o = unsmob<Output_def> ($2);
1238 o->input_origin_.set_spot (@$);
1239 $1 = o->self_scm ();
1240 parser->lexer_->remove_scope ();
1241 parser->lexer_->add_scope (o->scope_);
1242 $2 = SCM_UNSPECIFIED;
1246 if (unsmob<Context_def> ($2))
1247 assign_context_def (unsmob<Output_def> ($1), $2);
1248 // Seems unlikely, but let's be complete:
1249 else if (unsmob<Music> ($2))
1251 SCM proc = parser->lexer_->lookup_identifier
1252 ("output-def-music-handler");
1253 scm_call_2 (proc, $1, $2);
1254 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1255 parser->parser_error (@2, _("bad expression type"));
1258 | output_def_body SCM_TOKEN {
1259 if (scm_is_pair ($1))
1261 // Evaluate and ignore #xxx, as opposed to \xxx
1262 parser->lexer_->eval_scm_token ($2, @2);
1266 if (scm_is_pair ($1))
1268 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1269 parser->lexer_->push_note_state (nn);
1270 } music_or_context_def
1272 parser->lexer_->pop_state ();
1273 if (unsmob<Context_def> ($3))
1274 assign_context_def (unsmob<Output_def> ($1), $3);
1277 SCM proc = parser->lexer_->lookup_identifier
1278 ("output-def-music-handler");
1279 scm_call_2 (proc, $1, $3);
1283 | output_def_body error {
1289 TEMPO steno_duration '=' tempo_range {
1290 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1292 | TEMPO text steno_duration '=' tempo_range {
1293 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1296 $$ = MAKE_SYNTAX (tempo, @$, $2);
1301 The representation of a list is reversed to have efficient append. */
1307 | music_list music_embedded {
1308 if (unsmob<Music> ($2))
1309 $$ = scm_cons ($2, $1);
1311 | music_list error {
1312 Music *m = MY_MAKE_MUSIC("Music", @$);
1314 m->set_property ("error-found", SCM_BOOL_T);
1315 $$ = scm_cons (m->self_scm (), $1);
1316 m->unprotect (); /* UGH */
1323 $$ = scm_reverse_x ($2, SCM_EOL);
1328 | lyric_element_music
1335 $$ = make_music_from_simple (parser, @1, $1);
1336 if (!unsmob<Music> ($$))
1338 parser->parser_error (@1, _ ("music expected"));
1339 $$ = MAKE_SYNTAX (void_music, @$);
1347 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1348 parser->parser_error (@1, _ ("unexpected post-event"));
1349 $$ = SCM_UNSPECIFIED;
1352 | music_embedded_backup
1356 | music_embedded_backup BACKUP lyric_element_music
1360 | multiplied_duration post_events
1362 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1364 parser->default_duration_ = *unsmob<Duration> ($1);
1365 n->set_property ("duration", $1);
1367 if (scm_is_pair ($2))
1368 n->set_property ("articulations",
1369 scm_reverse_x ($2, SCM_EOL));
1370 $$ = n->unprotect ();
1374 music_embedded_backup:
1377 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1379 else if (Music *m = unsmob<Music> ($1)) {
1380 if (m->is_mus_type ("post-event")) {
1381 parser->parser_error
1382 (@1, _ ("unexpected post-event"));
1383 $$ = SCM_UNSPECIFIED;
1386 } else if (parser->lexer_->is_lyric_state ()
1387 && Text_interface::is_markup ($1))
1388 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1390 @$.warning (_ ("Ignoring non-music expression"));
1396 // music_assign does not need to contain lyrics: there are no
1397 // assignments in lyricmode.
1400 | composite_music %prec COMPOSITE
1404 REPEAT simple_string unsigned_number music
1406 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1408 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1410 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1415 SEQUENTIAL braced_music_list {
1416 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1418 | braced_music_list {
1419 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1424 SIMULTANEOUS braced_music_list {
1425 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1427 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1428 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1434 | music_property_def
1438 context_modification:
1441 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1442 parser->lexer_->push_note_state (nn);
1443 } '{' context_mod_list '}'
1445 parser->lexer_->pop_state ();
1448 | WITH CONTEXT_MOD_IDENTIFIER
1452 | CONTEXT_MOD_IDENTIFIER
1456 | WITH context_modification_arg
1458 if (unsmob<Music> ($2)) {
1459 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1460 $2 = scm_call_1 (proc, $2);
1462 if (unsmob<Context_mod> ($2))
1465 parser->parser_error (@2, _ ("not a context mod"));
1466 $$ = Context_mod ().smobbed_copy ();
1471 context_modification_arg:
1476 optional_context_mod:
1480 | context_modification
1488 $$ = Context_mod ().smobbed_copy ();
1490 | context_mod_list context_mod {
1491 if (!SCM_UNBNDP ($2))
1492 unsmob<Context_mod> ($1)->add_context_mod ($2);
1494 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1495 Context_mod *md = unsmob<Context_mod> ($2);
1497 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1499 | context_mod_list context_mod_arg {
1500 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1502 else if (unsmob<Music> ($2)) {
1503 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1504 $2 = scm_call_1 (proc, $2);
1506 if (unsmob<Context_mod> ($2))
1507 unsmob<Context_mod> ($$)->add_context_mods
1508 (unsmob<Context_mod> ($2)->get_mods ());
1510 parser->parser_error (@2, _ ("not a context mod"));
1516 CONTEXT symbol optional_id optional_context_mod {
1517 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1520 mods = ctxmod->get_mods ();
1521 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_F);
1523 | NEWCONTEXT symbol optional_id optional_context_mod {
1524 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1527 mods = ctxmod->get_mods ();
1528 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_T);
1533 ADDLYRICS optional_context_mod lyric_mode_music {
1534 Context_mod *ctxmod = unsmob<Context_mod> ($2);
1537 mods = ctxmod->get_mods ();
1538 $$ = scm_acons ($3, mods, SCM_EOL);
1540 | new_lyrics ADDLYRICS optional_context_mod lyric_mode_music {
1541 Context_mod *ctxmod = unsmob<Context_mod> ($3);
1544 mods = ctxmod->get_mods ();
1545 $$ = scm_acons ($4, mods, $1);
1549 /* basic_music is basically the same as composite_music but with
1550 * context-prefixed music and lyricized music explicitly removed. The
1551 * reason is that in a sequence
1553 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1555 * we need to group both \addlyrics together (as they go with the same
1556 * voice) but then combine them with \new Voice { ... }, meaning that
1557 * combining \new Voice { ... } needs higher priority than
1558 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1559 * combine before combining \new Voice { ... } \addlyrics: only one
1560 * layer of context-prefixed music should assemble before \addlyrics
1561 * is integrated. Total mess, and we sort this mess out with explicit
1562 * rules preferring a single context-prefix.
1569 | LYRICSTO simple_string lyric_mode_music {
1570 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1572 | LYRICSTO symbol '=' simple_string lyric_mode_music
1574 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1584 contexted_basic_music:
1585 context_prefix contextable_music new_lyrics
1588 i.set_location (@1, @2);
1589 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1590 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1592 | context_prefix contextable_music
1594 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1596 | context_prefix contexted_basic_music
1598 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1603 basic_music %prec COMPOSITE
1604 | contexted_basic_music
1605 | basic_music new_lyrics
1607 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1614 | grouped_music_list
1618 simultaneous_music { $$ = $1; }
1619 | sequential_music { $$ = $1; }
1622 /* Function argument lists are arguably the most complex part in the
1623 * parser. They are pretty tricky to understand because of the way
1624 * they are processed, and because of optional arguments that can be
1625 * omitted. When there are several optional arguments in a row,
1626 * omitting one automatically omits all following arguments. Optional
1627 * arguments can only be omitted when either
1629 * a) the omission is explicitly started with \default
1630 * b) the omission is implicitly started by an argument not matching
1631 * its predicate, and there is a mandatory argument later that can
1632 * "catch" the argument that does not fit.
1634 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1635 * (corresponding to mandatory arguments and having a predicate
1636 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1637 * the semantic value of the EXPECT_OPTIONAL token is the default to
1638 * use when the optional argument is omitted, and EXPECT_SCM again has
1639 * the argument predicate as semantic value) in reverse order to the
1640 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1641 * processed inside-out while actual tokens are consumed.
1643 * This means that the argument list tokens determine the actions
1644 * taken as they arrive. The structure of the argument list is known
1645 * to the parser and stored in its parse stack when the first argument
1646 * is being parsed. What the parser does not know is which predicates
1647 * will match and whether or not \default will be appearing in the
1648 * argument list, and where.
1650 * Sequences of 0 or more optional arguments are scanned using either
1651 * function_arglist_backup or function_arglist_nonbackup. The first
1652 * is used when optional arguments are followed by at least one
1653 * mandatory argument: in that case optional arguments may be skipped
1654 * by either a false predicate (in which case the expression will be
1655 * pushed back as one or more tokens, preceded by a BACKUP token) or
1656 * by using \default.
1658 * If optional arguments are at the end of the argument list, they are
1659 * instead scanned using function_arglist_nonbackup: here the only
1660 * manner to enter into skipping of optional arguments is the use of
1663 * The argument list of a normal function call is parsed using
1664 * function_arglist. The part of an argument list before a mandatory
1665 * argument is parsed using function_arglist_optional.
1667 * The difference is that leading optional arguments are scanned using
1668 * function_arglist_nonbackup and function_arglist_backup,
1671 * Most other details are obvious in the rules themselves.
1677 | SYMBOL_LIST '.' symbol_list_rev
1679 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1681 | SYMBOL_LIST ',' symbol_list_rev
1683 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1689 | symbol_list_rev '.' symbol_list_part
1691 $$ = scm_append_x (scm_list_2 ($3, $1));
1693 | symbol_list_rev ',' symbol_list_part
1695 $$ = scm_append_x (scm_list_2 ($3, $1));
1699 // symbol_list_part delivers elements in reverse copy.
1704 $$ = try_string_variants (Lily::symbol_list_p, $1);
1705 if (SCM_UNBNDP ($$)) {
1706 parser->parser_error (@1, _("not a symbol"));
1709 $$ = scm_reverse ($$);
1714 symbol_list_element:
1720 function_arglist_nonbackup:
1721 function_arglist_common
1722 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1724 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1726 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1728 SCM n = scm_difference ($5, SCM_UNDEFINED);
1729 if (scm_is_true (scm_call_1 ($2, n)))
1730 $$ = scm_cons (n, $3);
1732 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1733 t->set_property ("digit", $5);
1734 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1738 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1740 $$ = check_scheme_arg (parser, @4,
1741 scm_difference ($5, SCM_UNDEFINED),
1744 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1746 $$ = check_scheme_arg (parser, @4,
1747 scm_difference ($5, SCM_UNDEFINED),
1750 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1752 if (scm_is_true (scm_call_1 ($2, $4)))
1753 $$ = scm_cons ($4, $3);
1755 $$ = check_scheme_arg (parser, @4,
1756 make_music_from_simple
1760 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1762 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1764 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1766 if (scm_is_true (scm_call_1 ($2, $3)))
1767 $$ = scm_cons ($3, $1);
1769 $$ = check_scheme_arg (parser, @3,
1770 make_music_from_simple
1774 | function_arglist_nonbackup_reparse REPARSE multiplied_duration
1776 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1778 | function_arglist_nonbackup_reparse REPARSE reparsed_rhythm
1780 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1782 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1784 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1786 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1788 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1790 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1792 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1794 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1796 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1802 DURATION_ARG dots multipliers post_events
1804 $$ = make_music_from_simple (parser, @$,
1805 make_duration ($1, scm_to_int ($2), $3));
1806 Music *m = unsmob<Music> ($$);
1808 if (scm_is_pair ($4))
1809 m->set_property ("articulations",
1810 scm_reverse_x ($4, SCM_EOL));
1814 function_arglist_nonbackup_reparse:
1815 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1818 SCM res = try_string_variants ($2, $4);
1819 if (!SCM_UNBNDP (res))
1820 if (scm_is_pair (res))
1821 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1823 MYREPARSE (@4, $2, SCM_ARG, res);
1824 else if (scm_is_true
1826 ($2, make_music_from_simple
1828 MYREPARSE (@4, $2, STRING, $4);
1830 MYREPARSE (@4, $2, SCM_ARG, $4);
1832 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1837 ($2, make_music_from_simple
1839 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1841 MYREPARSE (@4, $2, SCM_ARG, $4);
1843 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1848 ($2, make_music_from_simple
1850 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1852 MYREPARSE (@4, $2, SCM_ARG, $4);
1854 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1857 SCM res = try_string_variants ($2, $4);
1858 if (!SCM_UNBNDP (res))
1859 if (scm_is_pair (res))
1860 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1862 MYREPARSE (@4, $2, SCM_ARG, res);
1863 else if (scm_is_true
1865 ($2, make_music_from_simple
1867 MYREPARSE (@4, $2, STRING, $4);
1869 MYREPARSE (@4, $2, SCM_ARG, $4);
1871 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1874 if (scm_is_true (scm_call_1 ($2, $4)))
1875 MYREPARSE (@4, $2, SCM_ARG, $4);
1876 else if (scm_is_true
1878 ($2, make_music_from_simple
1880 MYREPARSE (@4, $2, STRING, $4);
1882 MYREPARSE (@4, $2, SCM_ARG, $4);
1884 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1887 if (scm_is_true (scm_call_1 ($2, $4)))
1888 // May be 3 \cm or similar
1889 MYREPARSE (@4, $2, REAL, $4);
1891 SCM d = make_duration ($4);
1892 if (!SCM_UNBNDP (d)) {
1893 if (scm_is_true (scm_call_1 ($2, d)))
1894 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1895 else if (scm_is_true
1897 ($2, make_music_from_simple (parser, @4, d))))
1898 MYREPARSE (@4, $2, DURATION_ARG, d);
1900 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1902 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1905 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER
1908 if (scm_is_true (scm_call_1 ($2, $4)))
1909 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1910 else if (scm_is_true
1912 ($2, make_music_from_simple (parser, @4, $4))))
1913 MYREPARSE (@4, $2, DURATION_ARG, $4);
1915 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1920 // function_arglist_backup can't occur at the end of an argument
1922 function_arglist_backup:
1923 function_arglist_common
1924 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1926 if (scm_is_true (scm_call_1 ($2, $4)))
1927 $$ = scm_cons ($4, $3);
1929 $$ = make_music_from_simple (parser, @4, $4);
1930 if (scm_is_true (scm_call_1 ($2, $$)))
1931 $$ = scm_cons ($$, $3);
1934 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1935 MYBACKUP (SCM_ARG, $4, @4);
1939 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1941 if (scm_is_true (scm_call_1 ($2, $4)))
1943 $$ = scm_cons ($4, $3);
1945 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1946 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1949 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1953 ($2, make_music_from_simple
1957 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1958 } else if (scm_is_true (scm_call_1 ($2, $4)))
1959 $$ = scm_cons ($4, $3);
1961 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1962 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1965 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1969 ($2, make_music_from_simple
1973 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1974 } else if (scm_is_true (scm_call_1 ($2, $4)))
1975 $$ = scm_cons ($4, $3);
1977 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1978 MYBACKUP (TONICNAME_PITCH, $4, @4);
1981 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1983 if (scm_is_true (scm_call_1 ($2, $4)))
1984 $$ = scm_cons ($4, $3);
1986 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1987 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1990 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1993 if (scm_is_true (scm_call_1 ($2, $4)))
1994 // May be 3 \cm or similar
1995 MYREPARSE (@4, $2, REAL, $4);
1997 SCM d = make_duration ($4);
1998 if (!SCM_UNBNDP (d)) {
1999 if (scm_is_true (scm_call_1 ($2, d)))
2000 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
2001 else if (scm_is_true
2003 ($2, make_music_from_simple (parser, @4, d))))
2004 MYREPARSE (@4, $2, DURATION_ARG, d);
2006 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2007 MYBACKUP (UNSIGNED, $4, @4);
2010 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2011 MYBACKUP (UNSIGNED, $4, @4);
2015 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
2017 if (scm_is_true (scm_call_1 ($2, $4)))
2020 MYREPARSE (@4, $2, REAL, $4);
2022 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2023 MYBACKUP (REAL, $4, @4);
2026 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
2028 if (scm_is_true (scm_call_1 ($2, $4)))
2030 $$ = scm_cons ($4, $3);
2032 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2033 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
2036 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
2038 SCM n = scm_difference ($5, SCM_UNDEFINED);
2039 if (scm_is_true (scm_call_1 ($2, n))) {
2041 MYREPARSE (@5, $2, REAL, n);
2043 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
2044 t->set_property ("digit", $5);
2045 $$ = t->unprotect ();
2046 if (scm_is_true (scm_call_1 ($2, $$)))
2047 $$ = scm_cons ($$, $3);
2049 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2050 MYBACKUP (UNSIGNED, $5, @5);
2051 parser->lexer_->push_extra_token (@4, '-');
2055 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2057 SCM n = scm_difference ($5, SCM_UNDEFINED);
2058 if (scm_is_true (scm_call_1 ($2, n))) {
2059 MYREPARSE (@5, $2, REAL, n);
2062 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2063 MYBACKUP (REAL, n, @5);
2066 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2068 SCM n = scm_difference ($5, SCM_UNDEFINED);
2069 if (scm_is_true (scm_call_1 ($2, n))) {
2070 $$ = scm_cons (n, $3);
2072 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2073 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2076 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2079 if (scm_is_true (scm_call_1 ($2, $4)))
2080 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2081 else if (scm_is_true
2083 ($2, make_music_from_simple (parser, @4, $4))))
2084 MYREPARSE (@4, $2, DURATION_ARG, $4);
2086 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2087 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2090 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2092 SCM res = try_string_variants ($2, $4);
2093 if (!SCM_UNBNDP (res))
2094 if (scm_is_pair (res)) {
2096 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2099 $$ = scm_cons (res, $3);
2101 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2102 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2105 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2107 SCM res = try_string_variants ($2, $4);
2108 if (!SCM_UNBNDP (res))
2109 if (scm_is_pair (res)) {
2111 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2114 $$ = scm_cons (res, $3);
2116 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2117 MYBACKUP (STRING, $4, @4);
2120 | function_arglist_backup REPARSE pitch_or_music
2122 if (scm_is_true (scm_call_1 ($2, $3)))
2123 $$ = scm_cons ($3, $1);
2125 $$ = check_scheme_arg (parser, @3,
2126 make_music_from_simple
2130 | function_arglist_backup REPARSE bare_number_common
2132 $$ = check_scheme_arg (parser, @3,
2135 | function_arglist_backup REPARSE multiplied_duration
2137 $$ = check_scheme_arg (parser, @3,
2140 | function_arglist_backup REPARSE reparsed_rhythm
2142 $$ = check_scheme_arg (parser, @3,
2145 | function_arglist_backup REPARSE symbol_list_arg
2147 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2152 function_arglist_nonbackup
2153 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2155 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2159 function_arglist_skip_nonbackup:
2160 function_arglist_nonbackup
2161 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2163 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2167 // Partial function arglists are returned just in their incomplete
2168 // state: when combined with the music function, the missing parts of
2169 // the signature can be reconstructed
2171 // To serve as a partial arglist, the argument list must absolutely
2172 // _not_ be in "skipping optional arguments" mode since then there is
2173 // some backup token that has nowhere to go before \etc.
2175 // So we can skim off an arbitrary number of arguments from the end of
2176 // the argument list. The argument list remaining afterwards has to
2177 // be in not-skipping-optional-arguments mode.
2179 function_arglist_partial:
2180 EXPECT_SCM function_arglist_optional
2184 | EXPECT_SCM function_arglist_partial_optional
2188 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2192 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2198 function_arglist_partial_optional:
2199 EXPECT_SCM function_arglist_optional
2203 | EXPECT_SCM function_arglist_partial_optional
2207 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2211 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2217 function_arglist_common:
2218 EXPECT_NO_MORE_ARGS {
2221 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2223 if (scm_is_true (scm_call_1 ($1, $3)))
2224 $$ = scm_cons ($3, $2);
2226 $$ = check_scheme_arg (parser, @3,
2227 make_music_from_simple
2231 | EXPECT_SCM function_arglist_optional bare_number_common
2233 $$ = check_scheme_arg (parser, @3,
2236 | EXPECT_SCM function_arglist_optional post_event_nofinger
2238 $$ = check_scheme_arg (parser, @3,
2241 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2243 SCM n = scm_difference ($4, SCM_UNDEFINED);
2244 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2246 | function_arglist_common_reparse REPARSE SCM_ARG
2248 $$ = check_scheme_arg (parser, @3,
2251 | function_arglist_common_reparse REPARSE lyric_element_music
2253 $$ = check_scheme_arg (parser, @3,
2256 | function_arglist_common_reparse REPARSE pitch_or_music
2258 if (scm_is_true (scm_call_1 ($2, $3)))
2259 $$ = scm_cons ($3, $1);
2261 $$ = check_scheme_arg (parser, @3,
2262 make_music_from_simple
2266 | function_arglist_common_reparse REPARSE bare_number_common
2268 $$ = check_scheme_arg (parser, @3,
2271 | function_arglist_common_reparse REPARSE multiplied_duration
2273 $$ = check_scheme_arg (parser, @3,
2276 | function_arglist_common_reparse REPARSE reparsed_rhythm
2278 $$ = check_scheme_arg (parser, @3,
2281 | function_arglist_common_reparse REPARSE symbol_list_arg
2283 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2287 function_arglist_common_reparse:
2288 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2291 SCM res = try_string_variants ($1, $3);
2292 if (!SCM_UNBNDP (res))
2293 if (scm_is_pair (res))
2294 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2296 MYREPARSE (@3, $1, SCM_ARG, res);
2297 else if (scm_is_true
2299 ($1, make_music_from_simple (parser, @3, $3))))
2300 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2302 // This is going to flag a syntax error, we
2303 // know the predicate to be false.
2304 MYREPARSE (@3, $1, SCM_ARG, $3);
2306 | EXPECT_SCM function_arglist_optional pitch
2311 ($1, make_music_from_simple
2313 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2315 MYREPARSE (@3, $1, SCM_ARG, $3);
2317 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2322 ($1, make_music_from_simple
2324 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2326 MYREPARSE (@3, $1, SCM_ARG, $3);
2328 | EXPECT_SCM function_arglist_optional STRING
2331 SCM res = try_string_variants ($1, $3);
2332 if (!SCM_UNBNDP (res))
2333 if (scm_is_pair (res))
2334 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2336 MYREPARSE (@3, $1, SCM_ARG, res);
2337 else if (scm_is_true
2339 ($1, make_music_from_simple (parser, @3, $3))))
2340 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2342 // This is going to flag a syntax error, we
2343 // know the predicate to be false.
2344 MYREPARSE (@3, $1, SCM_ARG, $3);
2346 | EXPECT_SCM function_arglist_optional full_markup
2349 if (scm_is_true (scm_call_1 ($1, $3)))
2350 MYREPARSE (@3, $1, SCM_ARG, $3);
2351 else if (scm_is_true
2353 ($1, make_music_from_simple (parser, @3, $3))))
2354 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2356 // This is going to flag a syntax error, we
2357 // know the predicate to be false.
2358 MYREPARSE (@3, $1, SCM_ARG, $3);
2360 | EXPECT_SCM function_arglist_optional UNSIGNED
2363 if (scm_is_true (scm_call_1 ($1, $3)))
2364 // May be 3 \cm or similar
2365 MYREPARSE (@3, $1, REAL, $3);
2367 SCM d = make_duration ($3);
2368 if (!SCM_UNBNDP (d)) {
2369 if (scm_is_true (scm_call_1 ($1, d)))
2370 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2371 else if (scm_is_true
2373 ($1, make_music_from_simple (parser, @3, d))))
2374 MYREPARSE (@3, $1, DURATION_ARG, d);
2376 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2378 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2381 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2384 if (scm_is_true (scm_call_1 ($1, $3)))
2385 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2386 else if (scm_is_true
2388 ($1, make_music_from_simple (parser, @3, $3))))
2389 MYREPARSE (@3, $1, DURATION_ARG, $3);
2391 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2393 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2396 SCM n = scm_difference ($4, SCM_UNDEFINED);
2397 if (scm_is_true (scm_call_1 ($1, n)))
2398 MYREPARSE (@4, $1, REAL, n);
2400 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2401 t->set_property ("digit", $4);
2402 SCM m = t->unprotect ();
2403 if (scm_is_true (scm_call_1 ($1, m)))
2404 MYREPARSE (@4, $1, SCM_ARG, m);
2406 MYREPARSE (@4, $1, SCM_ARG, $4);
2409 | EXPECT_SCM function_arglist_optional '-' REAL
2412 SCM n = scm_difference ($4, SCM_UNDEFINED);
2413 MYREPARSE (@4, $1, REAL, n);
2417 function_arglist_optional:
2418 function_arglist_backup
2419 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2421 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2423 | function_arglist_skip_backup BACKUP
2426 function_arglist_skip_backup:
2427 function_arglist_backup
2428 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2430 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2434 music_function_call:
2435 MUSIC_FUNCTION function_arglist {
2436 $$ = MAKE_SYNTAX (music_function, @$,
2443 /**/ { $$ = SCM_EOL; }
2444 | '=' simple_string {
2449 // We must not have lookahead tokens parsed in lyric mode. In order
2450 // to save confusion, we take almost the same set as permitted with
2451 // \lyricmode and/or \lyrics. However, music identifiers are also
2452 // allowed, and they obviously do not require switching into lyrics
2453 // mode for parsing.
2457 parser->lexer_->push_lyric_state ();
2458 } grouped_music_list
2460 parser->lexer_->pop_state ();
2467 mode_changing_head grouped_music_list {
2468 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2470 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2476 parser->lexer_->pop_state ();
2478 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2479 Context_mod *ctxmod = unsmob<Context_mod> ($2);
2482 mods = ctxmod->get_mods ();
2483 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2484 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2486 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2488 parser->lexer_->pop_state ();
2494 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2495 parser->lexer_->push_note_state (nn);
2497 $$ = ly_symbol2scm ("notes");
2501 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2502 parser->lexer_->push_note_state (nn);
2504 $$ = ly_symbol2scm ("drums");
2507 parser->lexer_->push_figuredbass_state ();
2509 $$ = ly_symbol2scm ("figures");
2512 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2513 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2514 nn = parser->lexer_->lookup_identifier ("pitchnames");
2515 parser->lexer_->push_chord_state (nn);
2516 $$ = ly_symbol2scm ("chords");
2520 { parser->lexer_->push_lyric_state ();
2521 $$ = ly_symbol2scm ("lyrics");
2525 mode_changing_head_with_context:
2527 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2528 parser->lexer_->push_note_state (nn);
2530 $$ = ly_symbol2scm ("DrumStaff");
2533 parser->lexer_->push_figuredbass_state ();
2535 $$ = ly_symbol2scm ("FiguredBass");
2538 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2539 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2540 nn = parser->lexer_->lookup_identifier ("pitchnames");
2541 parser->lexer_->push_chord_state (nn);
2542 $$ = ly_symbol2scm ("ChordNames");
2545 { parser->lexer_->push_lyric_state ();
2546 $$ = ly_symbol2scm ("Lyrics");
2551 CHANGE symbol '=' simple_string {
2552 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2559 $$ = scm_reverse_x ($1, SCM_EOL);
2561 | symbol_list_rev property_path {
2562 $$ = scm_reverse_x ($1, $2);
2568 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2571 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2573 | OVERRIDE property_path '=' scalar {
2574 if (scm_ilength ($2) < 2) {
2575 parser->parser_error (@2, _("bad grob property path"));
2578 $$ = scm_cons (ly_symbol2scm ("push"),
2579 scm_cons2 (scm_car ($2),
2584 | REVERT revert_arg {
2585 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2589 // This is all quite awkward for the sake of substantial backward
2590 // compatibility while at the same time allowing a more "natural" form
2591 // of specification not separating grob specification from grob
2592 // property path. The purpose of this definition of revert_arg is to
2593 // allow the symbol list which specifies grob and property to revert
2594 // to be optionally be split into two parts after the grob (which in
2595 // this case is just the first element of the list). symbol_list_part
2596 // is only one path component, but it can be parsed without lookahead,
2597 // so we can follow it with a synthetic BACKUP token when needed. If
2598 // the first symbol_list_part already contains multiple elements (only
2599 // possible if a Scheme expression provides them), we just parse for
2600 // additional elements introduced by '.', which is what the
2601 // SYMBOL_LIST backup in connection with the immediately following
2602 // rule using symbol_list_arg does.
2604 // As long as we don't have our coffers filled with both grob and at
2605 // least one grob property specification, the rest of the required
2606 // symbol list chain may be provided either with or without a leading
2607 // dot. This is for both allowing the traditional
2608 // \revert Accidental #'color
2609 // as well as well as the "naive" form
2610 // \revert Accidental.color
2613 revert_arg_backup BACKUP symbol_list_arg
2622 if (scm_is_null ($1)
2623 || scm_is_null (scm_cdr ($1)))
2624 MYBACKUP (SCM_ARG, $1, @1);
2626 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2630 // revert_arg_part delivers results in reverse
2633 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2635 $$ = scm_append_x (scm_list_2 ($5, $3));
2637 | revert_arg_backup BACKUP SCM_ARG ',' symbol_list_part
2639 $$ = scm_append_x (scm_list_2 ($5, $3));
2641 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2643 $$ = scm_append_x (scm_list_2 ($4, $3));
2648 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2649 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2651 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2652 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2653 | DENIES { $$ = ly_symbol2scm ("denies"); }
2655 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2656 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2657 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2658 | NAME { $$ = ly_symbol2scm ("context-name"); }
2662 property_operation { $$ = $1; }
2663 | context_def_mod STRING {
2664 $$ = scm_list_2 ($1, $2);
2666 | context_def_mod embedded_scm
2668 if (!scm_is_string ($2)
2669 && ly_symbol2scm ("consists") != $1
2670 && ly_symbol2scm ("remove") != $1)
2673 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2677 $$ = scm_list_2 ($1, $2);
2682 // If defined, at least two members.
2686 SCM l = scm_reverse_x ($1, SCM_EOL);
2689 (scm_object_property (scm_car (l),
2690 ly_symbol2scm ("is-grob?"))))
2691 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2692 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2693 parser->parser_error (@1, _ ("bad grob property path"));
2700 // If defined, at least three members
2704 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2706 parser->parser_error (@1, _ ("bad grob property path"));
2710 | grob_prop_spec property_path
2712 if (!SCM_UNBNDP ($1)) {
2713 $$ = scm_append_x (scm_list_2 ($1, $2));
2714 if (scm_is_null (scm_cddr ($$))) {
2715 parser->parser_error (@$, _ ("bad grob property path"));
2723 // Exactly two elements or undefined
2727 SCM l = scm_reverse_x ($1, SCM_EOL);
2728 switch (scm_ilength (l)) {
2730 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2734 parser->parser_error (@1, _ ("bad context property path"));
2742 // This is all quite awkward for the sake of substantial backward
2743 // compatibility while at the same time allowing a more "natural" form
2744 // of specification not separating grob specification from grob
2745 // property path. The purpose of this definition of
2746 // simple_revert_context is to allow the symbol list which specifies
2747 // grob and property to revert to be optionally be split into two
2748 // parts after the grob (which may be preceded by a context
2749 // specification, a case which we distinguish by checking whether the
2750 // first symbol is a valid grob symbol instead).
2752 // See revert_arg above for the main work horse of this arrangement.
2753 // simple_revert_context just caters for the context and delegates the
2754 // rest of the job to revert_arg.
2756 simple_revert_context:
2759 $1 = scm_reverse_x ($1, SCM_EOL);
2760 if (scm_is_null ($1)
2762 (scm_object_property (scm_car ($1),
2763 ly_symbol2scm ("is-grob?")))) {
2764 $$ = ly_symbol2scm ("Bottom");
2765 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2768 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2775 OVERRIDE grob_prop_path '=' scalar {
2776 if (SCM_UNBNDP ($2))
2777 $$ = MAKE_SYNTAX (void_music, @$);
2779 $$ = MAKE_SYNTAX (property_override, @$,
2784 | REVERT simple_revert_context revert_arg {
2785 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2787 | SET context_prop_spec '=' scalar {
2788 if (SCM_UNBNDP ($2))
2789 $$ = MAKE_SYNTAX (void_music, @$);
2791 $$ = MAKE_SYNTAX (property_set, @$,
2796 | UNSET context_prop_spec {
2797 if (SCM_UNBNDP ($2))
2798 $$ = MAKE_SYNTAX (void_music, @$);
2800 $$ = MAKE_SYNTAX (property_unset, @$,
2816 if (Text_interface::is_markup ($1)) {
2819 parser->parser_error (@1, (_ ("markup expected")));
2820 $$ = scm_string (SCM_EOL);
2825 simple_string: STRING
2828 if (scm_is_string ($1)) {
2831 parser->parser_error (@1, (_ ("simple string expected")));
2832 $$ = scm_string (SCM_EOL);
2839 $$ = scm_string_to_symbol ($1);
2843 // This is a bit of overkill but makes the same
2844 // routine responsible for all symbol interpretations.
2845 $$ = try_string_variants (Guile_user::symbol_p, $1);
2846 if (SCM_UNBNDP ($$))
2848 parser->parser_error (@1, (_ ("symbol expected")));
2849 // Generate a unique symbol in case it is used
2850 // for an assignment or similar
2851 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2861 // The following is a rather defensive variant of admitting
2862 // negative numbers: the grammar would permit number_factor or
2863 // even number_expression. However, function arguments allow
2864 // only this simple kind of negative number, so to have things
2865 // like \tweak and \override behave reasonably similar, it
2866 // makes sense to rule out things like -- which are rather an
2867 // accent in function argument contexts.
2870 $$ = scm_difference ($2, SCM_UNDEFINED);
2876 simple_element post_events {
2877 // Let the rhythmic music iterator sort this mess out.
2878 if (scm_is_pair ($2)) {
2879 unsmob<Music> ($$)->set_property ("articulations",
2880 scm_reverse_x ($2, SCM_EOL));
2883 | CHORD_REPETITION optional_notemode_duration post_events {
2885 i.set_location (@1, @3);
2886 $$ = MAKE_SYNTAX (repetition_chord, i,
2887 $2, scm_reverse_x ($3, SCM_EOL));
2889 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2891 i.set_location (@1, @3);
2892 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2893 scm_reverse_x ($3, SCM_EOL));
2896 | note_chord_element
2901 chord_body optional_notemode_duration post_events
2903 Music *m = unsmob<Music> ($1);
2904 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2905 SCM es = m->get_property ("elements");
2906 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2908 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2909 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2910 es = ly_append2 (es, postevs);
2912 m->set_property ("elements", es);
2913 m->set_spot (parser->lexer_->override_input (@$));
2914 $$ = m->self_scm ();
2919 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2921 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2923 | FIGURE_OPEN figure_list FIGURE_CLOSE
2925 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2929 chord_body_elements:
2930 /* empty */ { $$ = SCM_EOL; }
2931 | chord_body_elements chord_body_element {
2932 if (!SCM_UNBNDP ($2))
2933 $$ = scm_cons ($2, $1);
2938 pitch_or_tonic_pitch exclamations questions octave_check post_events
2940 bool q = to_boolean ($3);
2941 bool ex = to_boolean ($2);
2945 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2946 n->set_property ("pitch", $1);
2948 n->set_property ("cautionary", SCM_BOOL_T);
2950 n->set_property ("force-accidental", SCM_BOOL_T);
2952 if (scm_is_pair (post)) {
2953 SCM arts = scm_reverse_x (post, SCM_EOL);
2954 n->set_property ("articulations", arts);
2956 if (scm_is_number (check))
2958 int q = scm_to_int (check);
2959 n->set_property ("absolute-octave", scm_from_int (q-1));
2962 $$ = n->unprotect ();
2964 | DRUM_PITCH post_events {
2965 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2966 n->set_property ("drum-type", $1);
2968 if (scm_is_pair ($2)) {
2969 SCM arts = scm_reverse_x ($2, SCM_EOL);
2970 n->set_property ("articulations", arts);
2972 $$ = n->unprotect ();
2974 | music_function_chord_body
2976 Music *m = unsmob<Music> ($1);
2978 while (m && m->is_mus_type ("music-wrapper-music")) {
2979 $$ = m->get_property ("element");
2980 m = unsmob<Music> ($$);
2983 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2984 parser->parser_error (@$, _ ("not a rhythmic event"));
2990 music_function_chord_body:
2996 event_function_event:
2997 EVENT_FUNCTION function_arglist {
2998 $$ = MAKE_SYNTAX (music_function, @$,
3007 | post_events post_event {
3009 if (Music *m = unsmob<Music> ($2))
3011 if (m->is_mus_type ("post-event-wrapper"))
3013 for (SCM p = m->get_property ("elements");
3017 $$ = scm_cons (scm_car (p), $$);
3020 m->set_spot (parser->lexer_->override_input (@2));
3021 $$ = scm_cons ($2, $$);
3027 post_event_nofinger:
3028 direction_less_event {
3031 | script_dir music_function_call {
3033 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
3034 parser->parser_error (@2, _ ("post-event expected"));
3035 $$ = SCM_UNSPECIFIED;
3036 } else if (!SCM_UNBNDP ($1))
3038 unsmob<Music> ($$)->set_property ("direction", $1);
3042 if (!parser->lexer_->is_lyric_state ())
3043 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3044 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
3047 if (!parser->lexer_->is_lyric_state ())
3048 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3049 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
3051 | script_dir direction_reqd_event {
3052 if (!SCM_UNBNDP ($1))
3054 Music *m = unsmob<Music> ($2);
3055 m->set_property ("direction", $1);
3059 | script_dir direction_less_event {
3060 if (!SCM_UNBNDP ($1))
3062 Music *m = unsmob<Music> ($2);
3063 m->set_property ("direction", $1);
3070 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
3075 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
3086 string_number_event:
3088 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3089 s->set_property ("string-number", $1);
3090 $$ = s->unprotect ();
3094 direction_less_event:
3096 | EVENT_IDENTIFIER {
3100 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3101 a->set_property ("tremolo-type", $1);
3102 $$ = a->unprotect ();
3104 | event_function_event
3107 direction_reqd_event:
3111 | script_abbreviation {
3112 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3113 if (scm_is_string (s)) {
3114 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3115 a->set_property ("articulation-type", s);
3116 $$ = a->unprotect ();
3118 Music *original = unsmob<Music> (s);
3119 if (original && original->is_mus_type ("post-event")) {
3120 Music *a = original->clone ();
3121 a->set_spot (parser->lexer_->override_input (@$));
3122 $$ = a->unprotect ();
3124 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3125 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3132 /**/ { $$ = SCM_EOL; }
3133 | '=' quotes { $$ = $2; }
3147 $$ = scm_from_int (1);
3150 $$ = scm_oneplus ($1);
3156 $$ = scm_from_int (-1);
3159 $$ = scm_oneminus ($1);
3164 NOTENAME_PITCH quotes {
3165 if (!scm_is_eq (SCM_INUM0, $2))
3167 Pitch p = *unsmob<Pitch> ($1);
3168 p = p.transposed (Pitch (scm_to_int ($2), 0));
3169 $$ = p.smobbed_copy ();
3179 TONICNAME_PITCH quotes {
3180 if (!scm_is_eq (SCM_INUM0, $2))
3182 Pitch p = *unsmob<Pitch> ($1);
3183 p = p.transposed (Pitch (scm_to_int ($2), 0));
3184 $$ = p.smobbed_copy ();
3191 | PITCH_IDENTIFIER quotes {
3192 if (!scm_is_eq (SCM_INUM0, $2))
3194 Pitch p = *unsmob<Pitch> ($1);
3195 p = p.transposed (Pitch (scm_to_int ($2), 0));
3196 $$ = p.smobbed_copy ();
3201 pitch_or_tonic_pitch:
3208 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3209 t->set_property ("text", $1);
3210 $$ = t->unprotect ();
3213 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3214 t->set_property ("text",
3215 make_simple_markup ($1));
3216 $$ = t->unprotect ();
3220 Music *m = unsmob<Music> ($1);
3221 if (m && m->is_mus_type ("post-event"))
3223 else if (Text_interface::is_markup ($1)) {
3224 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3225 t->set_property ("text", $1);
3226 $$ = t->unprotect ();
3228 parser->parser_error (@1, _ ("not an articulation"));
3234 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3235 t->set_property ("digit", $1);
3236 $$ = t->unprotect ();
3240 script_abbreviation:
3242 $$ = scm_from_ascii_string ("Hat");
3245 $$ = scm_from_ascii_string ("Plus");
3248 $$ = scm_from_ascii_string ("Dash");
3251 $$ = scm_from_ascii_string ("Bang");
3254 $$ = scm_from_ascii_string ("Larger");
3257 $$ = scm_from_ascii_string ("Dot");
3260 $$ = scm_from_ascii_string ("Underscore");
3265 '_' { $$ = scm_from_int (DOWN); }
3266 | '^' { $$ = scm_from_int (UP); }
3267 | '-' { $$ = SCM_UNDEFINED; }
3270 maybe_notemode_duration:
3274 | multiplied_duration {
3276 parser->default_duration_ = *unsmob<Duration> ($$);
3281 optional_notemode_duration:
3282 maybe_notemode_duration
3284 if (SCM_UNBNDP ($$))
3285 $$ = parser->default_duration_.smobbed_copy ();
3291 $$ = make_duration ($1, scm_to_int ($2));
3292 if (SCM_UNBNDP ($$))
3294 parser->parser_error (@1, _ ("not a duration"));
3295 $$ = Duration ().smobbed_copy ();
3298 | DURATION_IDENTIFIER dots {
3299 $$ = make_duration ($1, scm_to_int ($2));
3303 multiplied_duration:
3304 steno_duration multipliers {
3305 $$ = make_duration ($1, 0, $2);
3314 $$ = scm_oneplus ($1);
3323 | multipliers '*' UNSIGNED
3325 if (!SCM_UNBNDP ($1))
3326 $$ = scm_product ($1, $3);
3330 | multipliers '*' FRACTION
3332 if (!SCM_UNBNDP ($1))
3333 $$ = scm_product ($1, scm_divide (scm_car ($3),
3336 $$ = scm_divide (scm_car ($3), scm_cdr ($3));
3342 $$ = scm_from_int (parser->default_tremolo_type_);
3345 if (SCM_UNBNDP (make_duration ($2))) {
3346 parser->parser_error (@2, _ ("not a duration"));
3347 $$ = scm_from_int (parser->default_tremolo_type_);
3350 parser->default_tremolo_type_ = scm_to_int ($2);
3356 UNSIGNED { $$ = $1; }
3357 | STRING { $$ = $1; }
3358 | full_markup { $$ = $1; }
3361 // as an integer, it needs to be non-negative, and otherwise
3362 // it needs to be suitable as a markup.
3363 if (scm_is_integer ($1)
3364 ? scm_is_true (scm_negative_p ($1))
3365 : !Text_interface::is_markup ($1))
3367 parser->parser_error (@1, _ ("bass number expected"));
3373 figured_bass_alteration:
3374 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3375 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3376 | '!' { $$ = scm_from_int (0); }
3381 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3382 $$ = bfr->unprotect ();
3385 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3386 $$ = bfr->self_scm ();
3388 if (scm_is_number ($1))
3389 bfr->set_property ("figure", $1);
3390 else if (Text_interface::is_markup ($1))
3391 bfr->set_property ("text", $1);
3397 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3399 | bass_figure figured_bass_alteration {
3400 Music *m = unsmob<Music> ($1);
3401 if (scm_to_double ($2)) {
3402 SCM salter = m->get_property ("alteration");
3403 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3404 m->set_property ("alteration",
3405 scm_sum (alter, $2));
3407 m->set_property ("alteration", scm_from_int (0));
3410 | bass_figure figured_bass_modification {
3411 Music *m = unsmob<Music> ($1);
3412 m->set_property ($2, SCM_BOOL_T);
3417 figured_bass_modification:
3419 $$ = ly_symbol2scm ("augmented");
3422 $$ = ly_symbol2scm ("no-continuation");
3425 $$ = ly_symbol2scm ("diminished");
3428 $$ = ly_symbol2scm ("augmented-slash");
3438 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3446 | figure_list br_bass_figure {
3447 $$ = scm_cons ($2, $1);
3452 /**/ { $$ = SCM_BOOL_F; }
3453 | REST { $$ = SCM_BOOL_T; }
3457 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3458 if (!parser->lexer_->is_note_state ())
3459 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3460 if (!SCM_UNBNDP ($2)
3462 || scm_is_number ($4)
3465 || scm_is_pair ($7))
3468 if (scm_is_true ($6))
3469 n = MY_MAKE_MUSIC ("RestEvent", @$);
3471 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3473 n->set_property ("pitch", $1);
3474 if (SCM_UNBNDP ($5))
3475 n->set_property ("duration",
3476 parser->default_duration_.smobbed_copy ());
3478 n->set_property ("duration", $5);
3480 if (scm_is_number ($4))
3482 int q = scm_to_int ($4);
3483 n->set_property ("absolute-octave", scm_from_int (q-1));
3486 if (to_boolean ($3))
3487 n->set_property ("cautionary", SCM_BOOL_T);
3488 if (to_boolean ($2) || to_boolean ($3))
3489 n->set_property ("force-accidental", SCM_BOOL_T);
3490 if (scm_is_pair ($7))
3491 n->set_property ("articulations",
3492 scm_reverse_x ($7, SCM_EOL));
3493 $$ = n->unprotect ();
3496 | new_chord post_events {
3497 if (!parser->lexer_->is_chord_state ())
3498 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3499 if (scm_is_pair ($2)) {
3500 if (unsmob<Pitch> ($1))
3501 $1 = make_chord_elements (@1,
3503 parser->default_duration_.smobbed_copy (),
3506 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3508 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3509 } else if (!unsmob<Pitch> ($1))
3510 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3511 // A mere pitch drops through.
3516 DRUM_PITCH optional_notemode_duration {
3517 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3518 n->set_property ("duration", $2);
3519 n->set_property ("drum-type", $1);
3521 $$ = n->unprotect ();
3523 | RESTNAME optional_notemode_duration {
3525 if (ly_scm2string ($1) == "s") {
3527 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3530 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3533 ev->set_property ("duration", $2);
3534 $$ = ev->unprotect ();
3540 if (!parser->lexer_->is_lyric_state ())
3541 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3545 if (!parser->lexer_->is_lyric_state ())
3546 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3552 lyric_element_music:
3553 lyric_element optional_notemode_duration post_events {
3554 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3555 if (scm_is_pair ($3))
3556 unsmob<Music> ($$)->set_property
3557 ("articulations", scm_reverse_x ($3, SCM_EOL));
3561 // Can return a single pitch rather than a list.
3563 steno_tonic_pitch maybe_notemode_duration {
3564 if (SCM_UNBNDP ($2))
3567 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3569 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3570 SCM its = scm_reverse_x ($4, SCM_EOL);
3571 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3579 | chord_items chord_item {
3580 $$ = scm_cons ($2, $$);
3586 $$ = ly_symbol2scm ("chord-colon");
3589 $$ = ly_symbol2scm ("chord-caret");
3591 | CHORD_SLASH steno_tonic_pitch {
3592 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3594 | CHORD_BASS steno_tonic_pitch {
3595 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3604 $$ = scm_reverse_x ($1, SCM_EOL);
3612 step_number { $$ = scm_cons ($1, SCM_EOL); }
3613 | step_numbers '.' step_number {
3614 $$ = scm_cons ($3, $$);
3620 $$ = make_chord_step ($1, 0);
3623 $$ = make_chord_step ($1, SHARP_ALTERATION);
3625 | UNSIGNED CHORD_MINUS {
3626 $$ = make_chord_step ($1, FLAT_ALTERATION);
3634 | unsigned_number '-' unsigned_number {
3635 $$ = scm_cons ($1, $3);
3642 TODO: should deprecate in favor of Scheme?
3646 number_expression '+' number_term {
3647 $$ = scm_sum ($1, $3);
3649 | number_expression '-' number_term {
3650 $$ = scm_difference ($1, $3);
3659 | number_factor '*' number_factor {
3660 $$ = scm_product ($1, $3);
3662 | number_factor '/' number_factor {
3663 $$ = scm_divide ($1, $3);
3668 '-' number_factor { /* %prec UNARY_MINUS */
3669 $$ = scm_difference ($2, SCM_UNDEFINED);
3677 | REAL NUMBER_IDENTIFIER
3679 $$ = scm_product ($1, $2);
3686 | UNSIGNED NUMBER_IDENTIFIER {
3687 $$ = scm_product ($1, $2);
3695 if (!scm_is_integer ($1)
3696 || scm_is_true (scm_negative_p ($1)))
3698 parser->parser_error (@1, _("not an unsigned integer"));
3704 if (!scm_is_integer ($1)
3705 || scm_is_true (scm_negative_p ($1)))
3707 parser->parser_error (@1, _("not an unsigned integer"));
3714 { $$ = SCM_UNDEFINED; }
3717 if (SCM_UNBNDP ($1))
3725 // This precedence rule is rather weird. It triggers when '!' is
3726 // encountered after a pitch, and is used for deciding whether to save
3727 // this instead for a figure modification. This should not actually
3728 // occur in practice as pitches and figures are generated in different
3729 // modes. Using a greedy (%right) precedence makes sure that we don't
3730 // get stuck in a wrong interpretation.
3731 { $$ = SCM_UNDEFINED; } %prec ':'
3734 if (SCM_UNBNDP ($1))
3743 { parser->lexer_->push_markup_state (); }
3746 parser->lexer_->pop_state ();
3753 parser->lexer_->push_markup_state ();
3758 markup_mode markup_top {
3760 parser->lexer_->pop_state ();
3765 markup_mode markup_partial_function ETC
3767 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3768 parser->lexer_->pop_state ();
3774 $$ = scm_list_2 (Lily::line_markup, $1);
3776 | markup_head_1_list simple_markup
3778 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3779 @2, $1, scm_list_1 ($2)));
3789 if (Text_interface::is_markup ($1))
3790 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3791 else if (Text_interface::is_markup_list ($1))
3792 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3794 parser->parser_error (@1, _ ("not a markup"));
3795 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3802 markup_composed_list {
3805 | markup_uncomposed_list
3808 markup_uncomposed_list:
3809 markup_braced_list {
3812 | markup_command_list {
3813 $$ = scm_list_1 ($1);
3815 | markup_scm MARKUPLIST_IDENTIFIER
3820 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3821 parser->lexer_->push_note_state (nn);
3822 } '{' score_body '}' {
3823 Score *sc = unsmob<Score> ($4);
3824 sc->origin ()->set_spot (@$);
3825 if (sc->defs_.empty ()) {
3826 Output_def *od = get_layout (parser);
3827 sc->add_output_def (od);
3830 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3831 parser->lexer_->pop_state ();
3835 markup_composed_list:
3836 markup_head_1_list markup_uncomposed_list {
3837 $$ = MAKE_SYNTAX (composed_markup_list,
3843 '{' markup_braced_list_body '}' {
3844 $$ = scm_reverse_x ($2, SCM_EOL);
3848 markup_braced_list_body:
3849 /* empty */ { $$ = SCM_EOL; }
3850 | markup_braced_list_body markup {
3851 $$ = scm_cons ($2, $1);
3853 | markup_braced_list_body markup_list {
3854 $$ = scm_reverse_x ($2, $1);
3858 markup_command_list:
3859 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3860 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3864 markup_command_basic_arguments:
3865 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3866 $$ = scm_cons ($3, $2);
3868 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3869 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3871 | EXPECT_NO_MORE_ARGS {
3876 markup_command_list_arguments:
3877 markup_command_basic_arguments { $$ = $1; }
3878 | EXPECT_MARKUP markup_command_list_arguments markup {
3879 $$ = scm_cons ($3, $2);
3883 markup_partial_function:
3884 MARKUP_FUNCTION markup_arglist_partial
3886 $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
3888 | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
3890 $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
3895 markup_arglist_partial:
3896 EXPECT_MARKUP markup_arglist_partial
3900 | EXPECT_SCM markup_arglist_partial
3904 | EXPECT_MARKUP markup_command_list_arguments
3908 | EXPECT_SCM markup_command_list_arguments
3915 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3916 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3921 markup_head_1_item {
3922 $$ = scm_list_1 ($1);
3924 | markup_head_1_list markup_head_1_item {
3925 $$ = scm_cons ($2, $1);
3931 $$ = make_simple_markup ($1);
3934 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3935 parser->lexer_->push_note_state (nn);
3936 } '{' score_body '}' {
3937 Score *sc = unsmob<Score> ($4);
3938 sc->origin ()->set_spot (@$);
3939 if (sc->defs_.empty ()) {
3940 Output_def *od = get_layout (parser);
3941 sc->add_output_def (od);
3944 $$ = scm_list_2 (Lily::score_markup, $4);
3945 parser->lexer_->pop_state ();
3947 | MARKUP_FUNCTION markup_command_basic_arguments {
3948 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3950 | markup_scm MARKUP_IDENTIFIER
3957 markup_head_1_list simple_markup
3959 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3960 @2, $1, scm_list_1 ($2)));
3970 Lily_parser::set_yydebug (bool x)
3976 Lily_parser::do_yyparse ()
3978 return scm_c_with_fluid (Lily::f_parser,
3980 do_yyparse_trampoline,
3981 static_cast <void *>(this));
3985 Lily_parser::do_yyparse_trampoline (void *parser)
3987 SCM retval = SCM_UNDEFINED;
3988 yyparse (static_cast <Lily_parser *>(parser), &retval);
3996 It is a little strange to have this function in this file, but
3997 otherwise, we have to import music classes into the lexer.
4001 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
4003 if (unsmob<Book> (sid)) {
4004 Book *book = unsmob<Book> (sid)->clone ();
4005 *destination = book->self_scm ();
4008 return BOOK_IDENTIFIER;
4009 } else if (scm_is_number (sid)) {
4011 return NUMBER_IDENTIFIER;
4012 } else if (unsmob<Context_def> (sid))
4014 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
4015 return SCM_IDENTIFIER;
4016 } else if (unsmob<Context_mod> (sid)) {
4017 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
4018 return CONTEXT_MOD_IDENTIFIER;
4019 } else if (Music *mus = unsmob<Music> (sid)) {
4020 mus = mus->clone ();
4021 *destination = mus->self_scm ();
4022 bool is_event = mus->is_mus_type ("post-event");
4024 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
4025 } else if (unsmob<Pitch> (sid)) {
4026 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
4027 return PITCH_IDENTIFIER;
4028 } else if (unsmob<Duration> (sid)) {
4029 *destination = unsmob<Duration> (sid)->smobbed_copy ();
4030 return DURATION_IDENTIFIER;
4031 } else if (unsmob<Output_def> (sid)) {
4032 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
4033 return SCM_IDENTIFIER;
4034 } else if (unsmob<Score> (sid)) {
4035 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
4036 return SCM_IDENTIFIER;
4043 get_next_unique_context_id ()
4045 return scm_from_ascii_string ("$uniqueContextId");
4050 get_next_unique_lyrics_context_id ()
4052 static int new_context_count;
4054 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
4055 return scm_from_ascii_string (s);
4058 // check_scheme_arg checks one argument with a given predicate for use
4059 // in an argument list and throws a syntax error if it is unusable.
4060 // The argument is prepended to the argument list in any case. After
4061 // throwing a syntax error, the argument list is terminated with #f as
4062 // its last cdr in order to mark it as uncallable while not losing
4063 // track of its total length.
4065 // There are a few special considerations: if optional argument disp
4066 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
4067 // instead of arg in a prospective error message. This is useful if
4068 // arg is not the actual argument but rather a transformation of it.
4070 // If arg itself is SCM_UNDEFINED, the predicate is considered false
4071 // and an error message using disp is produced unconditionally.
4073 SCM check_scheme_arg (Lily_parser *parser, Input loc,
4074 SCM arg, SCM args, SCM pred, SCM disp)
4076 if (SCM_UNBNDP (arg))
4077 args = scm_cons (disp, args);
4079 args = scm_cons (arg, args);
4080 if (scm_is_true (scm_call_1 (pred, arg)))
4083 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
4084 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
4085 SCM_UNBNDP (disp) ? arg : disp);
4086 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
4090 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
4092 if (Music *m = unsmob<Music> (arg))
4095 m->set_spot (parser->lexer_->override_input (loc));
4096 return m->unprotect ();
4102 try_string_variants (SCM pred, SCM str)
4104 // a matching predicate is always ok
4105 if (scm_is_true (scm_call_1 (pred, str)))
4107 // a symbol may be interpreted as a list of symbols if it helps
4108 if (scm_is_symbol (str)) {
4109 str = scm_list_1 (str);
4110 if (scm_is_true (scm_call_1 (pred, str)))
4112 return SCM_UNDEFINED;
4115 // If this cannot be a string representation of a symbol list,
4118 if (!is_regular_identifier (str, true))
4119 return SCM_UNDEFINED;
4121 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4122 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4123 scm_set_car_x (p, scm_string_split (scm_car (p),
4124 SCM_MAKE_CHAR (',')));
4125 str = scm_append_x (str);
4126 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4127 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4129 // Let's attempt the symbol list interpretation first.
4131 if (scm_is_true (scm_call_1 (pred, str)))
4134 // If there is just one symbol in the list, we might interpret
4135 // it as a single symbol
4137 if (scm_is_null (scm_cdr (str)))
4139 str = scm_car (str);
4140 if (scm_is_true (scm_call_1 (pred, str)))
4144 return SCM_UNDEFINED;
4148 is_regular_identifier (SCM id, bool multiple)
4150 if (!scm_is_string (id))
4153 string str = ly_scm2string (id);
4155 bool middle = false;
4157 for (string::iterator it=str.begin(); it != str.end (); it++)
4160 if ((c >= 'a' && c <= 'z')
4161 || (c >= 'A' && c <= 'Z')
4164 else if (middle && (c == '-' || c == '_' || (multiple &&
4165 (c == '.' || c == ','))))
4174 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4176 if (unsmob<Music> (simple))
4178 if (parser->lexer_->is_note_state ()) {
4179 if (scm_is_symbol (simple)) {
4180 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4181 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4182 n->set_property ("drum-type", simple);
4183 return n->unprotect ();
4185 if (unsmob<Pitch> (simple)) {
4186 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4187 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4188 n->set_property ("pitch", simple);
4189 return n->unprotect ();
4192 if (scm_is_integer (simple))
4193 d = make_duration (simple);
4194 if (unsmob<Duration> (d)) {
4195 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4196 n->set_property ("duration", d);
4197 return n->unprotect ();
4200 } else if (parser->lexer_->is_lyric_state ()) {
4201 if (Text_interface::is_markup (simple))
4202 return MAKE_SYNTAX (lyric_event, loc, simple,
4203 parser->default_duration_.smobbed_copy ());
4204 } else if (parser->lexer_->is_chord_state ()) {
4205 if (unsmob<Pitch> (simple))
4209 make_chord_elements (loc, simple,
4210 parser->default_duration_.smobbed_copy (),
4217 make_music_with_input (SCM name, Input where)
4219 Music *m = make_music_by_name (name);
4220 m->set_spot (where);
4225 make_simple_markup (SCM a)
4231 make_duration (SCM d, int dots, SCM factor)
4235 if (Duration *dur = unsmob<Duration> (d)) {
4236 if (!dots && SCM_UNBNDP (factor))
4240 k = Duration (k.duration_log (), k.dot_count () + dots)
4241 .compressed (k.factor ());
4243 int t = scm_to_int (d);
4244 if (t > 0 && (t & (t-1)) == 0)
4245 k = Duration (intlog2 (t), dots);
4247 return SCM_UNDEFINED;
4250 if (!SCM_UNBNDP (factor))
4251 k = k.compressed (ly_scm2rational (factor));
4253 return k.smobbed_copy ();
4257 make_chord_step (SCM step_scm, Rational alter)
4259 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4261 // Notename/octave are normalized
4262 if (m.get_notename () == 6)
4263 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4265 return m.smobbed_copy ();
4270 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4272 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4273 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4275 unsmob<Music> (scm_car (s))->set_spot (loc);
4281 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4283 Lily_lexer *lex = parser->lexer_;
4287 int tok = lex->pop_extra_token ();
4290 lex->prepare_for_next_token ();
4291 return lex->yylex ();