1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 SCM s = Display::value_to_lily_string (value); \
45 char *p = scm_to_locale_string (s); \
52 %parse-param {Lily_parser *parser}
53 %parse-param {SCM *retval}
54 %lex-param {Lily_parser *parser}
58 /* We use SCMs to do strings, because it saves us the trouble of
59 deleting them. Let's hope that a stack overflow doesn't trigger a move
60 of the parse stack onto the heap. */
66 /* The above precedences tackle the shift/reduce problem
69 \repeat .. \alternative
71 \repeat { \repeat .. \alternative }
75 \repeat { \repeat } \alternative
81 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
82 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
84 /* The above are needed for collecting tremoli and other items (that
85 could otherwise be interpreted as belonging to the next function
86 argument) greedily, and together with the next rule will serve to
87 join numbers and units greedily instead of allowing them into
88 separate function arguments
91 %nonassoc NUMBER_IDENTIFIER
103 %{ // -*-Fundamental-*-
108 * The rules for who is protecting what are very shady. Uniformise
111 * There are too many lexical modes?
122 #include "context.hh"
123 #include "context-def.hh"
124 #include "context-mod.hh"
125 #include "dimensions.hh"
126 #include "file-path.hh"
128 #include "international.hh"
129 #include "lily-guile.hh"
130 #include "lily-lexer.hh"
131 #include "lily-parser.hh"
132 #include "ly-module.hh"
136 #include "output-def.hh"
137 #include "paper-book.hh"
138 #include "scm-hash.hh"
140 #include "text-interface.hh"
142 #include "lily-imports.hh"
145 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
147 parser->parser_error (*i, s);
150 // The following are somewhat precarious constructs as they may change
151 // the value of the lookahead token. That implies that the lookahead
152 // token must not yet have made an impact on the state stack other
153 // than causing the reduction of the current rule, or switching the
154 // lookahead token while Bison is mulling it over will cause trouble.
156 #define MYBACKUP(Token, Value, Location) \
158 if (yychar != YYEMPTY) \
159 parser->lexer_->push_extra_token \
160 (yylloc, yychar, yylval); \
162 parser->lexer_->push_extra_token \
163 (Location, Token, Value); \
164 parser->lexer_->push_extra_token (Location, BACKUP); \
169 #define MYREPARSE(Location, Pred, Token, Value) \
171 if (yychar != YYEMPTY) \
172 parser->lexer_->push_extra_token \
173 (yylloc, yychar, yylval); \
174 parser->lexer_->push_extra_token \
175 (Location, Token, Value); \
176 parser->lexer_->push_extra_token \
177 (Location, REPARSE, Pred); \
186 #define MY_MAKE_MUSIC(x, spot) \
187 make_music_with_input (ly_symbol2scm (x), \
188 parser->lexer_->override_input (spot))
191 - delay application of the function
194 #define LOWLEVEL_MAKE_SYNTAX(location, proc, ...) \
196 (parser->lexer_->override_input (location).smobbed_copy (), \
200 /* Syntactic Sugar. */
201 #define MAKE_SYNTAX(name, location, ...) \
202 LOWLEVEL_MAKE_SYNTAX (location, Syntax::name, ##__VA_ARGS__)
204 #define START_MAKE_SYNTAX(name, ...) \
205 scm_list_n (Syntax::name, ##__VA_ARGS__, SCM_UNDEFINED)
207 #define FINISH_MAKE_SYNTAX(start, location, ...) \
208 LOWLEVEL_MAKE_SYNTAX \
213 (scm_list_2 (scm_cdr (start), \
214 scm_list_n (__VA_ARGS__, SCM_UNDEFINED))))
216 SCM get_next_unique_context_id ();
217 SCM get_next_unique_lyrics_context_id ();
224 #define _(x) gettext (x)
228 static Music *make_music_with_input (SCM name, Input where);
229 SCM check_scheme_arg (Lily_parser *parser, Input loc,
230 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
231 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
232 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg);
233 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
234 SCM make_chord_step (SCM step, Rational alter);
235 SCM make_simple_markup (SCM a);
236 SCM make_duration (SCM t, int dots = 0, SCM factor = SCM_UNDEFINED);
237 bool is_regular_identifier (SCM id, bool multiple=false);
238 SCM try_string_variants (SCM pred, SCM str);
239 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
243 /* The third option is an alias that will be used to display the
244 syntax error. Bison CVS now correctly handles backslash escapes.
246 FIXME: Bison needs to translate some of these, eg, STRING.
250 /* Keyword tokens with plain escaped name. */
251 %token END_OF_FILE 0 "end of input"
252 %token ACCEPTS "\\accepts"
253 %token ADDLYRICS "\\addlyrics"
254 %token ALIAS "\\alias"
255 %token ALTERNATIVE "\\alternative"
257 %token BOOKPART "\\bookpart"
258 %token CHANGE "\\change"
259 %token CHORDMODE "\\chordmode"
260 %token CHORDS "\\chords"
261 %token CONSISTS "\\consists"
262 %token CONTEXT "\\context"
263 %token DEFAULT "\\default"
264 %token DEFAULTCHILD "\\defaultchild"
265 %token DENIES "\\denies"
266 %token DESCRIPTION "\\description"
267 %token DRUMMODE "\\drummode"
268 %token DRUMS "\\drums"
270 %token FIGUREMODE "\\figuremode"
271 %token FIGURES "\\figures"
272 %token HEADER "\\header"
273 %token INVALID "\\version-error"
274 %token LAYOUT "\\layout"
275 %token LYRICMODE "\\lyricmode"
276 %token LYRICS "\\lyrics"
277 %token LYRICSTO "\\lyricsto"
278 %token MARKUP "\\markup"
279 %token MARKUPLIST "\\markuplist"
282 %token NOTEMODE "\\notemode"
283 %token OVERRIDE "\\override"
284 %token PAPER "\\paper"
285 %token REMOVE "\\remove"
286 %token REPEAT "\\repeat"
288 %token REVERT "\\revert"
289 %token SCORE "\\score"
290 %token SCORELINES "\\score-lines"
291 %token SEQUENTIAL "\\sequential"
293 %token SIMULTANEOUS "\\simultaneous"
294 %token TEMPO "\\tempo"
296 %token UNSET "\\unset"
299 /* Keyword token exceptions. */
300 %token NEWCONTEXT "\\new"
303 /* Other string tokens. */
305 %token CHORD_BASS "/+"
306 %token CHORD_CARET "^"
307 %token CHORD_COLON ":"
308 %token CHORD_MINUS "-"
309 %token CHORD_SLASH "/"
310 %token ANGLE_OPEN "<"
311 %token ANGLE_CLOSE ">"
312 %token DOUBLE_ANGLE_OPEN "<<"
313 %token DOUBLE_ANGLE_CLOSE ">>"
314 %token E_BACKSLASH "\\"
315 %token E_EXCLAMATION "\\!"
320 If we give names, Bison complains.
322 %token FIGURE_CLOSE /* "\\>" */
323 %token FIGURE_OPEN /* "\\<" */
324 %token FIGURE_SPACE "_"
327 %token MULTI_MEASURE_REST
333 /* Artificial tokens, for more generic function syntax */
334 %token EXPECT_MARKUP "markup?"
335 %token EXPECT_SCM "scheme?"
336 %token BACKUP "(backed-up?)"
337 %token REPARSE "(reparsed?)"
338 %token EXPECT_MARKUP_LIST "markup-list?"
339 %token EXPECT_OPTIONAL "optional?"
340 /* After the last argument. */
341 %token EXPECT_NO_MORE_ARGS;
343 /* An artificial token for parsing embedded Lilypond */
344 %token EMBEDDED_LILY "#{"
346 %token BOOK_IDENTIFIER
347 %token CHORD_MODIFIER
348 %token CHORD_REPETITION
349 %token CONTEXT_MOD_IDENTIFIER
351 /* Artificial token for durations in argument lists */
353 %token DURATION_IDENTIFIER
354 %token EVENT_IDENTIFIER
355 %token EVENT_FUNCTION
357 %token LOOKUP_IDENTIFIER
359 %token MARKUP_FUNCTION
360 %token MARKUP_LIST_FUNCTION
361 %token MARKUP_IDENTIFIER
362 %token MARKUPLIST_IDENTIFIER
363 %token MUSIC_FUNCTION
364 %token MUSIC_IDENTIFIER
365 %token NOTENAME_PITCH
366 %token NUMBER_IDENTIFIER
367 %token PITCH_IDENTIFIER
372 %token SCM_IDENTIFIER
376 %token TONICNAME_PITCH
380 /* We don't assign precedence to / and *, because we might need varied
381 prec levels in different prods */
390 parser->lexer_->push_note_state (Lily::pitchnames);
391 } embedded_lilypond {
392 parser->lexer_->pop_state ();
397 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
398 | lilypond toplevel_expression {
400 | lilypond assignment {
403 parser->error_level_ = 1;
406 parser->error_level_ = 1;
413 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $1);
416 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
417 scm_call_1 (proc, $1);
420 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
421 scm_call_1 (proc, $1);
424 SCM proc = parser->lexer_->lookup_identifier
425 (unsmob<Book>($1)->paper_
426 ? "toplevel-book-handler"
427 : "toplevel-bookpart-handler");
428 scm_call_1 (proc, $1);
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
432 scm_call_1 (proc, $1);
435 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
436 scm_call_1 (proc, $1);
439 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
440 scm_call_1 (proc, scm_list_1 ($1));
443 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
444 scm_call_1 (proc, $1);
447 // Evaluate and ignore #xxx, as opposed to \xxx
448 parser->lexer_->eval_scm_token ($1, @1);
450 | embedded_scm_active
452 SCM out = SCM_UNDEFINED;
453 if (Text_interface::is_markup ($1))
454 out = scm_list_1 ($1);
455 else if (Text_interface::is_markup_list ($1))
457 if (scm_is_pair (out))
459 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
460 scm_call_1 (proc, out);
461 } else if (unsmob<Score> ($1))
463 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
464 scm_call_1 (proc, $1);
465 } else if (Output_def * od = unsmob<Output_def> ($1)) {
468 if (to_boolean (od->c_variable ("is-paper")))
469 id = ly_symbol2scm ("$defaultpaper");
470 else if (to_boolean (od->c_variable ("is-midi")))
471 id = ly_symbol2scm ("$defaultmidi");
472 else if (to_boolean (od->c_variable ("is-layout")))
473 id = ly_symbol2scm ("$defaultlayout");
475 parser->lexer_->set_identifier (id, $1);
476 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
477 parser->parser_error (@1, _("bad expression type"));
481 Output_def * od = unsmob<Output_def> ($1);
483 if (to_boolean (od->c_variable ("is-paper")))
484 id = ly_symbol2scm ("$defaultpaper");
485 else if (to_boolean (od->c_variable ("is-midi")))
486 id = ly_symbol2scm ("$defaultmidi");
487 else if (to_boolean (od->c_variable ("is-layout")))
488 id = ly_symbol2scm ("$defaultlayout");
490 parser->lexer_->set_identifier (id, $1);
496 | LOOKUP_IDENTIFIER '.' symbol_list_rev
498 $$ = loc_on_music (parser, @$,
499 nested_property ($1, scm_reverse_x ($3, SCM_EOL)));
506 $$ = parser->lexer_->eval_scm_token ($1, @1);
517 embedded_scm_bare_arg:
521 $$ = parser->lexer_->eval_scm_token ($1, @1);
526 | context_modification
529 | context_def_spec_block
536 /* The generic version may end in music, or not */
544 /* embedded_scm_arg is _not_ casting pitches to music by default, this
545 * has to be done by the function itself. Note that this may cause
546 * the results of scm_function_call or embedded_scm_bare_arg to be
547 * turned into music from pitches as well. Note that this creates a
548 * distinctly awkward situation for calculated drum pitches. Those
549 * are at the current point of time rejected as music constituents as
550 * they can't be distinguished from "proper" symbols.
554 embedded_scm_bare_arg
560 SCM_FUNCTION function_arglist {
561 $$ = MAKE_SYNTAX (music_function, @$,
566 embedded_lilypond_number:
567 '-' embedded_lilypond_number
569 $$ = scm_difference ($2, SCM_UNDEFINED);
572 | UNSIGNED NUMBER_IDENTIFIER
574 $$ = scm_product ($1, $2);
581 // FIXME: @$ does not contain a useful source location
582 // for empty rules, and the only token in the whole
583 // production, EMBEDDED_LILY, is synthetic and also
584 // contains no source location.
585 $$ = MAKE_SYNTAX (void_music, @$);
587 | identifier_init_nonumber
588 | embedded_lilypond_number
589 | post_event post_events
591 $$ = scm_reverse_x ($2, SCM_EOL);
592 if (Music *m = unsmob<Music> ($1))
594 if (m->is_mus_type ("post-event-wrapper"))
596 (scm_list_2 (m->get_property ("elements"),
599 $$ = scm_cons ($1, $$);
602 && scm_is_null (scm_cdr ($$)))
606 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
607 m->set_property ("elements", $$);
608 $$ = m->unprotect ();
611 | multiplied_duration
612 | music_embedded music_embedded music_list {
613 $3 = scm_reverse_x ($3, SCM_EOL);
614 if (unsmob<Music> ($2))
615 $3 = scm_cons ($2, $3);
616 if (unsmob<Music> ($1))
617 $3 = scm_cons ($1, $3);
618 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
621 parser->error_level_ = 1;
622 $$ = SCM_UNSPECIFIED;
624 | INVALID embedded_lilypond {
625 parser->error_level_ = 1;
631 lilypond_header_body:
632 /* empty */ { $$ = SCM_UNSPECIFIED; }
633 | lilypond_header_body assignment {
636 | lilypond_header_body embedded_scm {
642 HEADER '{' lilypond_header_body '}' {
643 $$ = parser->lexer_->remove_scope ();
649 parser->lexer_->add_scope (get_header (parser));
663 assignment_id '=' identifier_init {
664 parser->lexer_->set_identifier ($1, $3);
665 $$ = SCM_UNSPECIFIED;
667 | assignment_id '.' property_path '=' identifier_init {
668 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
669 parser->lexer_->set_identifier (path, $5);
670 $$ = SCM_UNSPECIFIED;
672 | assignment_id ',' property_path '=' identifier_init {
673 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
674 parser->lexer_->set_identifier (path, $5);
675 $$ = SCM_UNSPECIFIED;
681 identifier_init_nonumber
683 | symbol_list_part_bare '.' property_path
685 $$ = scm_reverse_x ($1, $3);
687 | symbol_list_part_bare ',' property_path
689 $$ = scm_reverse_x ($1, $3);
691 | post_event_nofinger post_events
693 $$ = scm_reverse_x ($2, SCM_EOL);
694 if (Music *m = unsmob<Music> ($1))
696 if (m->is_mus_type ("post-event-wrapper"))
698 (scm_list_2 (m->get_property ("elements"),
701 $$ = scm_cons ($1, $$);
704 && scm_is_null (scm_cdr ($$)))
708 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
709 m->set_property ("elements", $$);
710 $$ = m->unprotect ();
715 identifier_init_nonumber:
721 | context_def_spec_block
729 | context_modification
730 | partial_function ETC
732 $$ = MAKE_SYNTAX (partial_music_function, @$,
733 scm_reverse_x ($1, SCM_EOL));
739 MUSIC_FUNCTION function_arglist_partial
741 $$ = scm_acons ($1, $2, SCM_EOL);
743 | EVENT_FUNCTION function_arglist_partial
745 $$ = scm_acons ($1, $2, SCM_EOL);
747 | SCM_FUNCTION function_arglist_partial
749 $$ = scm_acons ($1, $2, SCM_EOL);
751 | OVERRIDE grob_prop_path '='
754 $$ = scm_list_1 (SCM_BOOL_F);
757 (scm_list_3 (Syntax::property_override_function,
758 scm_cdr ($2), scm_car ($2)),
761 | SET context_prop_spec '='
764 $$ = scm_list_1 (SCM_BOOL_F);
767 (scm_list_3 (Syntax::property_set_function,
768 scm_cadr ($2), scm_car ($2)),
771 | MUSIC_FUNCTION EXPECT_SCM function_arglist_optional partial_function
773 $$ = scm_acons ($1, $3, $4);
775 | EVENT_FUNCTION EXPECT_SCM function_arglist_optional partial_function
777 $$ = scm_acons ($1, $3, $4);
779 | SCM_FUNCTION EXPECT_SCM function_arglist_optional partial_function
781 $$ = scm_acons ($1, $3, $4);
783 | OVERRIDE grob_prop_path '=' partial_function
786 $$ = scm_list_1 (SCM_BOOL_F);
789 (scm_list_3 (Syntax::property_override_function,
790 scm_cdr ($2), scm_car ($2)),
793 | SET context_prop_spec '=' partial_function
796 $$ = scm_list_1 (SCM_BOOL_F);
799 (scm_list_3 (Syntax::property_set_function,
800 scm_cadr ($2), scm_car ($2)),
803 | MUSIC_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
805 $$ = scm_acons ($1, $4, $5);
807 | EVENT_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
809 $$ = scm_acons ($1, $4, $5);
811 | SCM_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
813 $$ = scm_acons ($1, $4, $5);
817 context_def_spec_block:
818 CONTEXT '{' context_def_spec_body '}'
821 Context_def *td = unsmob<Context_def> ($$);
823 $$ = Context_def::make_scm ();
824 td = unsmob<Context_def> ($$);
826 td->origin ()->set_spot (@$);
834 parser->lexer_->push_note_state (Lily::pitchnames);
838 parser->lexer_->pop_state ();
844 context_def_spec_body:
846 $$ = SCM_UNSPECIFIED;
848 | context_def_spec_body context_mod {
849 if (!SCM_UNBNDP ($2)) {
850 Context_def *td = unsmob<Context_def> ($$);
852 $$ = Context_def::make_scm ();
853 td = unsmob<Context_def> ($$);
855 unsmob<Context_def> ($$)->add_context_mod ($2);
858 | context_def_spec_body context_modification {
859 Context_def *td = unsmob<Context_def> ($$);
861 $$ = Context_def::make_scm ();
862 td = unsmob<Context_def> ($$);
864 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
865 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
866 td->add_context_mod (scm_car (m));
869 | context_def_spec_body context_mod_arg {
870 Context_def *td = unsmob<Context_def> ($1);
871 if (scm_is_eq ($2, SCM_UNSPECIFIED))
873 else if (!td && unsmob<Context_def> ($2))
877 $$ = Context_def::make_scm ();
878 td = unsmob<Context_def> ($$);
880 if (unsmob<Music> ($2)) {
881 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
882 $2 = scm_call_1 (proc, $2);
884 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
885 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
886 td->add_context_mod (scm_car (m));
889 parser->parser_error (@2, _ ("not a context mod"));
897 BOOK '{' book_body '}' {
899 unsmob<Book> ($$)->origin ()->set_spot (@$);
901 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
906 * Use 'handlers' like for toplevel-* stuff?
907 * grok \layout and \midi? */
910 Book *book = new Book;
911 init_papers (parser);
912 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
913 book->paper_->unprotect ();
914 push_paper (parser, book->paper_);
915 book->header_ = get_header (parser);
916 $$ = book->unprotect ();
917 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
920 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
922 | book_body paper_block {
923 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
924 set_paper (parser, unsmob<Output_def> ($2));
926 | book_body bookpart_block {
927 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
928 scm_call_2 (proc, $1, $2);
930 | book_body score_block {
931 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
932 scm_call_2 (proc, $1, $2);
934 | book_body composite_music {
935 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
936 scm_call_2 (proc, $1, $2);
938 | book_body full_markup {
939 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
940 scm_call_2 (proc, $1, scm_list_1 ($2));
942 | book_body full_markup_list {
943 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
944 scm_call_2 (proc, $1, $2);
946 | book_body SCM_TOKEN {
947 // Evaluate and ignore #xxx, as opposed to \xxx
948 parser->lexer_->eval_scm_token ($2, @2);
950 | book_body embedded_scm_active
952 SCM out = SCM_UNDEFINED;
953 if (Text_interface::is_markup ($2))
954 out = scm_list_1 ($2);
955 else if (Text_interface::is_markup_list ($2))
957 if (scm_is_pair (out))
959 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
960 scm_call_2 (proc, $1, out);
961 } else if (unsmob<Score> ($2))
963 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
964 scm_call_2 (proc, $1, $2);
965 } else if (Output_def *od = unsmob<Output_def> ($2)) {
968 if (to_boolean (od->c_variable ("is-paper")))
969 id = ly_symbol2scm ("$defaultpaper");
970 else if (to_boolean (od->c_variable ("is-midi")))
971 id = ly_symbol2scm ("$defaultmidi");
972 else if (to_boolean (od->c_variable ("is-layout")))
973 id = ly_symbol2scm ("$defaultlayout");
975 parser->lexer_->set_identifier (id, $2);
976 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
977 parser->parser_error (@2, _("bad expression type"));
981 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
984 Book *book = unsmob<Book> ($1);
986 book->scores_ = SCM_EOL;
987 book->bookparts_ = SCM_EOL;
992 BOOKPART '{' bookpart_body '}' {
994 unsmob<Book> ($$)->origin ()->set_spot (@$);
995 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
1001 Book *book = new Book;
1002 $$ = book->unprotect ();
1003 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
1006 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
1008 | bookpart_body paper_block {
1009 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
1011 | bookpart_body score_block {
1012 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1013 scm_call_2 (proc, $1, $2);
1015 | bookpart_body composite_music {
1016 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
1017 scm_call_2 (proc, $1, $2);
1019 | bookpart_body full_markup {
1020 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1021 scm_call_2 (proc, $1, scm_list_1 ($2));
1023 | bookpart_body full_markup_list {
1024 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1025 scm_call_2 (proc, $1, $2);
1027 | bookpart_body SCM_TOKEN {
1028 // Evaluate and ignore #xxx, as opposed to \xxx
1029 parser->lexer_->eval_scm_token ($2, @2);
1031 | bookpart_body embedded_scm_active
1033 SCM out = SCM_UNDEFINED;
1034 if (Text_interface::is_markup ($2))
1035 out = scm_list_1 ($2);
1036 else if (Text_interface::is_markup_list ($2))
1038 if (scm_is_pair (out))
1040 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1041 scm_call_2 (proc, $1, out);
1042 } else if (unsmob<Score> ($2))
1044 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1045 scm_call_2 (proc, $1, $2);
1046 } else if (Output_def *od = unsmob<Output_def> ($2)) {
1049 if (to_boolean (od->c_variable ("is-paper")))
1050 id = ly_symbol2scm ("$defaultpaper");
1051 else if (to_boolean (od->c_variable ("is-midi")))
1052 id = ly_symbol2scm ("$defaultmidi");
1053 else if (to_boolean (od->c_variable ("is-layout")))
1054 id = ly_symbol2scm ("$defaultlayout");
1056 parser->lexer_->set_identifier (id, $2);
1057 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1058 parser->parser_error (@2, _("bad expression type"));
1062 Book *book = unsmob<Book> ($1);
1063 if (!ly_is_module (book->header_))
1064 book->header_ = ly_make_module (false);
1065 parser->lexer_->add_scope (book->header_);
1067 | bookpart_body error {
1068 Book *book = unsmob<Book> ($1);
1070 book->scores_ = SCM_EOL;
1075 SCORE '{' score_body '}' {
1076 unsmob<Score> ($3)->origin ()->set_spot (@$);
1083 if (!unsmob<Score> ($1)) {
1084 parser->parser_error (@1, _("Missing music in \\score"));
1085 $$ = (new Score)->unprotect ();
1086 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
1088 unsmob<Score> ($$)->set_header (scm_car ($1));
1091 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1092 scm_is_pair (p); p = scm_cdr (p))
1094 unsmob<Score> ($$)->
1095 add_output_def (unsmob<Output_def> (scm_car (p)));
1099 | score_body error {
1100 unsmob<Score> ($$)->error_found_ = true;
1115 | score_items score_item
1117 Output_def *od = unsmob<Output_def> ($2);
1119 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1121 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1123 $2 = SCM_UNSPECIFIED;
1125 } else if (!unsmob<Score> ($$)) {
1126 if (unsmob<Music> ($2)) {
1127 $2 = Lily::scorify_music ($2);
1129 if (unsmob<Score> ($2))
1132 $2 = SCM_UNSPECIFIED;
1135 Score *score = unsmob<Score> ($$);
1136 if (score && scm_is_pair ($1)) {
1137 if (ly_is_module (scm_car ($1)))
1139 score->set_header (scm_car ($1));
1142 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1143 scm_is_pair (p); p = scm_cdr (p))
1145 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1150 score->add_output_def (od);
1151 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1152 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1154 $$ = scm_cons ($2, $$);
1155 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1156 parser->parser_error (@2, _("Spurious expression in \\score"));
1160 if (Score *score = unsmob<Score> ($1)) {
1161 if (!ly_is_module (score->get_header ()))
1162 score->set_header (ly_make_module (false));
1163 parser->lexer_->add_scope (score->get_header ());
1165 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1166 $1 = scm_cons (ly_make_module (false), $1);
1167 parser->lexer_->add_scope (scm_car ($1));
1182 Output_def *od = unsmob<Output_def> ($1);
1184 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1186 parser->parser_error (@1, _ ("need \\paper for paper block"));
1187 $$ = get_paper (parser)->unprotect ();
1194 output_def_body '}' {
1195 if (scm_is_pair ($1))
1198 parser->lexer_->remove_scope ();
1199 parser->lexer_->pop_state ();
1205 Output_def *p = get_paper (parser);
1206 p->input_origin_ = @$;
1207 parser->lexer_->add_scope (p->scope_);
1208 $$ = p->unprotect ();
1211 Output_def *p = get_midi (parser);
1212 $$ = p->unprotect ();
1213 parser->lexer_->add_scope (p->scope_);
1216 Output_def *p = get_layout (parser);
1218 parser->lexer_->add_scope (p->scope_);
1219 $$ = p->unprotect ();
1223 output_def_head_with_mode_switch:
1225 parser->lexer_->push_initial_state ();
1230 // We need this weird nonterminal because both music as well as a
1231 // context definition can start with \context and the difference is
1232 // only apparent after looking at the next token. If it is '{', there
1233 // is still time to escape from notes mode.
1235 music_or_context_def:
1237 | context_def_spec_block
1241 output_def_head_with_mode_switch '{' {
1242 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1243 // This is a stupid trick to mark the beginning of the
1244 // body for deciding whether to allow
1245 // embedded_scm_active to have an output definition
1246 $$ = scm_list_1 ($1);
1248 | output_def_body assignment {
1249 if (scm_is_pair ($1))
1252 | output_def_body embedded_scm_active
1254 // We don't switch into note mode for Scheme functions
1255 // here. Does not seem warranted/required in output
1257 if (scm_is_pair ($1))
1259 Output_def *o = unsmob<Output_def> ($2);
1261 o->input_origin_.set_spot (@$);
1262 $1 = o->self_scm ();
1263 parser->lexer_->remove_scope ();
1264 parser->lexer_->add_scope (o->scope_);
1265 $2 = SCM_UNSPECIFIED;
1269 if (unsmob<Context_def> ($2))
1270 assign_context_def (unsmob<Output_def> ($1), $2);
1271 // Seems unlikely, but let's be complete:
1272 else if (unsmob<Music> ($2))
1274 SCM proc = parser->lexer_->lookup_identifier
1275 ("output-def-music-handler");
1276 scm_call_2 (proc, $1, $2);
1277 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1278 parser->parser_error (@2, _("bad expression type"));
1281 | output_def_body SCM_TOKEN {
1282 if (scm_is_pair ($1))
1284 // Evaluate and ignore #xxx, as opposed to \xxx
1285 parser->lexer_->eval_scm_token ($2, @2);
1289 if (scm_is_pair ($1))
1291 parser->lexer_->push_note_state (Lily::pitchnames);
1292 } music_or_context_def
1294 parser->lexer_->pop_state ();
1295 if (unsmob<Context_def> ($3))
1296 assign_context_def (unsmob<Output_def> ($1), $3);
1299 SCM proc = parser->lexer_->lookup_identifier
1300 ("output-def-music-handler");
1301 scm_call_2 (proc, $1, $3);
1305 | output_def_body error {
1311 TEMPO steno_duration '=' tempo_range {
1312 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1314 | TEMPO text steno_duration '=' tempo_range {
1315 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1318 $$ = MAKE_SYNTAX (tempo, @$, $2);
1323 The representation of a list is reversed to have efficient append. */
1329 | music_list music_embedded {
1330 if (unsmob<Music> ($2))
1331 $$ = scm_cons ($2, $1);
1333 | music_list error {
1334 Music *m = MY_MAKE_MUSIC("Music", @$);
1336 m->set_property ("error-found", SCM_BOOL_T);
1337 $$ = scm_cons (m->self_scm (), $1);
1338 m->unprotect (); /* UGH */
1345 $$ = scm_reverse_x ($2, SCM_EOL);
1350 | lyric_element_music
1357 $$ = make_music_from_simple (parser, @1, $1);
1358 if (!unsmob<Music> ($$))
1360 parser->parser_error (@1, _ ("music expected"));
1361 $$ = MAKE_SYNTAX (void_music, @$);
1369 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1370 parser->parser_error (@1, _ ("unexpected post-event"));
1371 $$ = SCM_UNSPECIFIED;
1374 | music_embedded_backup
1378 | music_embedded_backup BACKUP lyric_element_music
1382 | multiplied_duration post_events
1384 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1386 parser->default_duration_ = *unsmob<Duration> ($1);
1387 n->set_property ("duration", $1);
1389 if (scm_is_pair ($2))
1390 n->set_property ("articulations",
1391 scm_reverse_x ($2, SCM_EOL));
1392 $$ = n->unprotect ();
1396 music_embedded_backup:
1399 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1401 else if (Music *m = unsmob<Music> ($1)) {
1402 if (m->is_mus_type ("post-event")) {
1403 parser->parser_error
1404 (@1, _ ("unexpected post-event"));
1405 $$ = SCM_UNSPECIFIED;
1408 } else if (parser->lexer_->is_lyric_state ()
1409 && Text_interface::is_markup ($1))
1410 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1412 @$.warning (_ ("Ignoring non-music expression"));
1418 // music_assign does not need to contain lyrics: there are no
1419 // assignments in lyricmode.
1422 | composite_music %prec COMPOSITE
1426 REPEAT simple_string unsigned_number music
1428 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1430 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1432 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1437 SEQUENTIAL braced_music_list {
1438 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1440 | braced_music_list {
1441 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1446 SIMULTANEOUS braced_music_list {
1447 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1449 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1450 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1456 | music_property_def
1460 context_modification:
1463 parser->lexer_->push_note_state (Lily::pitchnames);
1464 } '{' context_mod_list '}'
1466 parser->lexer_->pop_state ();
1469 | WITH CONTEXT_MOD_IDENTIFIER
1473 | CONTEXT_MOD_IDENTIFIER
1477 | WITH context_modification_arg
1479 if (unsmob<Music> ($2)) {
1480 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1481 $2 = scm_call_1 (proc, $2);
1483 if (unsmob<Context_mod> ($2))
1486 parser->parser_error (@2, _ ("not a context mod"));
1487 $$ = Context_mod ().smobbed_copy ();
1492 context_modification_arg:
1497 /* A list of single mods collected from a (possibly empty) sequence of
1498 * context modifications, usually written as \with ... \with ...
1501 optional_context_mods:
1502 context_modification_mods_list
1504 if (scm_is_pair ($1))
1505 $$ = scm_append_x (scm_reverse_x ($1, SCM_EOL));
1509 /* The worker for optional_context_mods conses a (reversed) list where
1510 * each element contains the list of single context mods from one
1511 * context modification block. Context_mod::get_mods creates fresh
1512 * copies, so it's okay to use append! on them.
1515 context_modification_mods_list:
1519 | context_modification_mods_list context_modification
1521 if (Context_mod *m = unsmob<Context_mod> ($2))
1522 $$ = scm_cons (m->get_mods (), $1);
1526 /* A Context_mod is a container for a list of context mods like
1527 * \consists ... \override ... . context_mod_list produces a
1528 * Context_mod from the inside of a \with { ... } statement.
1533 $$ = Context_mod ().smobbed_copy ();
1535 | context_mod_list context_mod {
1536 if (!SCM_UNBNDP ($2))
1537 unsmob<Context_mod> ($1)->add_context_mod ($2);
1539 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1540 Context_mod *md = unsmob<Context_mod> ($2);
1542 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1544 | context_mod_list context_mod_arg {
1545 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1547 else if (unsmob<Music> ($2)) {
1548 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1549 $2 = scm_call_1 (proc, $2);
1551 if (unsmob<Context_mod> ($2))
1552 unsmob<Context_mod> ($$)->add_context_mods
1553 (unsmob<Context_mod> ($2)->get_mods ());
1555 parser->parser_error (@2, _ ("not a context mod"));
1561 CONTEXT symbol optional_id optional_context_mods {
1562 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_F);
1564 | NEWCONTEXT symbol optional_id optional_context_mods {
1565 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, $4, SCM_BOOL_T);
1570 ADDLYRICS optional_context_mods lyric_mode_music {
1571 $$ = scm_acons ($3, $2, SCM_EOL);
1573 | new_lyrics ADDLYRICS optional_context_mods lyric_mode_music {
1574 $$ = scm_acons ($4, $3, $1);
1578 /* basic_music is basically the same as composite_music but with
1579 * context-prefixed music and lyricized music explicitly removed. The
1580 * reason is that in a sequence
1582 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1584 * we need to group both \addlyrics together (as they go with the same
1585 * voice) but then combine them with \new Voice { ... }, meaning that
1586 * combining \new Voice { ... } needs higher priority than
1587 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1588 * combine before combining \new Voice { ... } \addlyrics: only one
1589 * layer of context-prefixed music should assemble before \addlyrics
1590 * is integrated. Total mess, and we sort this mess out with explicit
1591 * rules preferring a single context-prefix.
1598 | LYRICSTO simple_string lyric_mode_music {
1599 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1601 | LYRICSTO symbol '=' simple_string lyric_mode_music
1603 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1613 contexted_basic_music:
1614 context_prefix contextable_music new_lyrics
1617 i.set_location (@1, @2);
1618 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1619 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1621 | context_prefix contextable_music
1623 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1625 | context_prefix contexted_basic_music
1627 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1632 basic_music %prec COMPOSITE
1633 | contexted_basic_music
1634 | basic_music new_lyrics
1636 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1643 | grouped_music_list
1647 simultaneous_music { $$ = $1; }
1648 | sequential_music { $$ = $1; }
1651 /* Function argument lists are arguably the most complex part in the
1652 * parser. They are pretty tricky to understand because of the way
1653 * they are processed, and because of optional arguments that can be
1654 * omitted. When there are several optional arguments in a row,
1655 * omitting one automatically omits all following arguments. Optional
1656 * arguments can only be omitted when either
1658 * a) the omission is explicitly started with \default
1659 * b) the omission is implicitly started by an argument not matching
1660 * its predicate, and there is a mandatory argument later that can
1661 * "catch" the argument that does not fit.
1663 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1664 * (corresponding to mandatory arguments and having a predicate
1665 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1666 * the semantic value of the EXPECT_OPTIONAL token is the default to
1667 * use when the optional argument is omitted, and EXPECT_SCM again has
1668 * the argument predicate as semantic value) in reverse order to the
1669 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1670 * processed inside-out while actual tokens are consumed.
1672 * This means that the argument list tokens determine the actions
1673 * taken as they arrive. The structure of the argument list is known
1674 * to the parser and stored in its parse stack when the first argument
1675 * is being parsed. What the parser does not know is which predicates
1676 * will match and whether or not \default will be appearing in the
1677 * argument list, and where.
1679 * Sequences of 0 or more optional arguments are scanned using either
1680 * function_arglist_backup or function_arglist_nonbackup. The first
1681 * is used when optional arguments are followed by at least one
1682 * mandatory argument: in that case optional arguments may be skipped
1683 * by either a false predicate (in which case the expression will be
1684 * pushed back as one or more tokens, preceded by a BACKUP token) or
1685 * by using \default.
1687 * If optional arguments are at the end of the argument list, they are
1688 * instead scanned using function_arglist_nonbackup: here the only
1689 * manner to enter into skipping of optional arguments is the use of
1692 * The argument list of a normal function call is parsed using
1693 * function_arglist. The part of an argument list before a mandatory
1694 * argument is parsed using function_arglist_optional.
1696 * The difference is that leading optional arguments are scanned using
1697 * function_arglist_nonbackup and function_arglist_backup,
1700 * Most other details are obvious in the rules themselves.
1706 | SYMBOL_LIST '.' symbol_list_rev
1708 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1710 | SYMBOL_LIST ',' symbol_list_rev
1712 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1718 | symbol_list_rev '.' symbol_list_part
1720 $$ = scm_append_x (scm_list_2 ($3, $1));
1722 | symbol_list_rev ',' symbol_list_part
1724 $$ = scm_append_x (scm_list_2 ($3, $1));
1728 // symbol_list_part delivers elements in reverse copy.
1733 $$ = try_string_variants (Lily::key_list_p, $1);
1734 if (SCM_UNBNDP ($$)) {
1735 parser->parser_error (@1, _("not a key"));
1738 $$ = scm_reverse ($$);
1743 symbol_list_element:
1749 symbol_list_part_bare:
1752 $$ = try_string_variants (Lily::key_list_p, $1);
1753 if (SCM_UNBNDP ($$)) {
1754 parser->parser_error (@1, _("not a key"));
1757 $$ = scm_reverse ($$);
1761 $$ = scm_list_1 ($1);
1765 function_arglist_nonbackup:
1766 function_arglist_common
1767 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1769 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1771 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1773 SCM n = scm_difference ($5, SCM_UNDEFINED);
1774 if (scm_is_true (scm_call_1 ($2, n)))
1775 $$ = scm_cons (n, $3);
1777 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1778 t->set_property ("digit", $5);
1779 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1783 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1785 $$ = check_scheme_arg (parser, @4,
1786 scm_difference ($5, SCM_UNDEFINED),
1789 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1791 $$ = check_scheme_arg (parser, @4,
1792 scm_difference ($5, SCM_UNDEFINED),
1795 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1797 if (scm_is_true (scm_call_1 ($2, $4)))
1798 $$ = scm_cons ($4, $3);
1800 $$ = check_scheme_arg (parser, @4,
1801 make_music_from_simple
1805 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1807 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1809 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1811 if (scm_is_true (scm_call_1 ($2, $3)))
1812 $$ = scm_cons ($3, $1);
1814 $$ = check_scheme_arg (parser, @3,
1815 make_music_from_simple
1819 | function_arglist_nonbackup_reparse REPARSE multiplied_duration
1821 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1823 | function_arglist_nonbackup_reparse REPARSE reparsed_rhythm
1825 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1827 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1829 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1831 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1833 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1835 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1837 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1839 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1841 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1847 DURATION_ARG dots multipliers post_events
1849 $$ = make_music_from_simple (parser, @$,
1850 make_duration ($1, scm_to_int ($2), $3));
1851 Music *m = unsmob<Music> ($$);
1853 if (scm_is_pair ($4))
1854 m->set_property ("articulations",
1855 scm_reverse_x ($4, SCM_EOL));
1859 function_arglist_nonbackup_reparse:
1860 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1863 SCM res = try_string_variants ($2, $4);
1864 if (!SCM_UNBNDP (res))
1865 if (scm_is_pair (res))
1866 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1868 MYREPARSE (@4, $2, SCM_ARG, res);
1869 else if (scm_is_true
1871 ($2, make_music_from_simple
1873 MYREPARSE (@4, $2, STRING, $4);
1875 MYREPARSE (@4, $2, SCM_ARG, $4);
1877 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1882 ($2, make_music_from_simple
1884 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1886 MYREPARSE (@4, $2, SCM_ARG, $4);
1888 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1893 ($2, make_music_from_simple
1895 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1897 MYREPARSE (@4, $2, SCM_ARG, $4);
1899 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1902 SCM res = try_string_variants ($2, $4);
1903 if (!SCM_UNBNDP (res))
1904 if (scm_is_pair (res))
1905 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1907 MYREPARSE (@4, $2, SCM_ARG, res);
1908 else if (scm_is_true
1910 ($2, make_music_from_simple
1912 MYREPARSE (@4, $2, STRING, $4);
1914 MYREPARSE (@4, $2, SCM_ARG, $4);
1916 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1919 if (scm_is_true (scm_call_1 ($2, $4)))
1920 MYREPARSE (@4, $2, SCM_ARG, $4);
1921 else if (scm_is_true
1923 ($2, make_music_from_simple
1925 MYREPARSE (@4, $2, STRING, $4);
1927 MYREPARSE (@4, $2, SCM_ARG, $4);
1929 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1932 if (scm_is_true (scm_call_1 ($2, $4)))
1933 // May be 3 \cm or similar
1934 MYREPARSE (@4, $2, REAL, $4);
1935 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
1936 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
1938 SCM d = make_duration ($4);
1939 if (!SCM_UNBNDP (d)) {
1940 if (scm_is_true (scm_call_1 ($2, d)))
1941 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1942 else if (scm_is_true
1944 ($2, make_music_from_simple (parser, @4, d))))
1945 MYREPARSE (@4, $2, DURATION_ARG, d);
1947 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1949 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1952 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER
1955 if (scm_is_true (scm_call_1 ($2, $4)))
1956 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1957 else if (scm_is_true
1959 ($2, make_music_from_simple (parser, @4, $4))))
1960 MYREPARSE (@4, $2, DURATION_ARG, $4);
1962 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1967 // function_arglist_backup can't occur at the end of an argument
1969 function_arglist_backup:
1970 function_arglist_common
1971 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1973 if (scm_is_true (scm_call_1 ($2, $4)))
1974 $$ = scm_cons ($4, $3);
1976 $$ = make_music_from_simple (parser, @4, $4);
1977 if (scm_is_true (scm_call_1 ($2, $$)))
1978 $$ = scm_cons ($$, $3);
1981 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1982 MYBACKUP (SCM_ARG, $4, @4);
1986 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1988 if (scm_is_true (scm_call_1 ($2, $4)))
1990 $$ = scm_cons ($4, $3);
1992 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1993 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1996 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
2000 ($2, make_music_from_simple
2004 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
2005 } else if (scm_is_true (scm_call_1 ($2, $4)))
2006 $$ = scm_cons ($4, $3);
2008 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2009 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
2012 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
2016 ($2, make_music_from_simple
2020 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
2021 } else if (scm_is_true (scm_call_1 ($2, $4)))
2022 $$ = scm_cons ($4, $3);
2024 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2025 MYBACKUP (TONICNAME_PITCH, $4, @4);
2028 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
2030 if (scm_is_true (scm_call_1 ($2, $4)))
2031 $$ = scm_cons ($4, $3);
2033 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2034 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2037 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
2040 if (scm_is_true (scm_call_1 ($2, $4)))
2041 // May be 3 \cm or similar
2042 MYREPARSE (@4, $2, REAL, $4);
2043 else if (scm_is_true (scm_call_1 ($2, scm_list_1 ($4))))
2044 MYREPARSE (@4, $2, SYMBOL_LIST, scm_list_1 ($4));
2046 SCM d = make_duration ($4);
2047 if (!SCM_UNBNDP (d)) {
2048 if (scm_is_true (scm_call_1 ($2, d)))
2049 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
2050 else if (scm_is_true
2052 ($2, make_music_from_simple (parser, @4, d))))
2053 MYREPARSE (@4, $2, DURATION_ARG, d);
2055 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2056 MYBACKUP (UNSIGNED, $4, @4);
2059 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2060 MYBACKUP (UNSIGNED, $4, @4);
2064 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
2066 if (scm_is_true (scm_call_1 ($2, $4)))
2069 MYREPARSE (@4, $2, REAL, $4);
2071 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2072 MYBACKUP (REAL, $4, @4);
2075 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
2077 if (scm_is_true (scm_call_1 ($2, $4)))
2079 $$ = scm_cons ($4, $3);
2081 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2082 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
2085 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
2087 SCM n = scm_difference ($5, SCM_UNDEFINED);
2088 if (scm_is_true (scm_call_1 ($2, n))) {
2090 MYREPARSE (@5, $2, REAL, n);
2092 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
2093 t->set_property ("digit", $5);
2094 $$ = t->unprotect ();
2095 if (scm_is_true (scm_call_1 ($2, $$)))
2096 $$ = scm_cons ($$, $3);
2098 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2099 MYBACKUP (UNSIGNED, $5, @5);
2100 parser->lexer_->push_extra_token (@4, '-');
2104 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2106 SCM n = scm_difference ($5, SCM_UNDEFINED);
2107 if (scm_is_true (scm_call_1 ($2, n))) {
2108 MYREPARSE (@5, $2, REAL, n);
2111 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2112 MYBACKUP (REAL, n, @5);
2115 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2117 SCM n = scm_difference ($5, SCM_UNDEFINED);
2118 if (scm_is_true (scm_call_1 ($2, n))) {
2119 $$ = scm_cons (n, $3);
2121 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2122 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2125 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2128 if (scm_is_true (scm_call_1 ($2, $4)))
2129 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2130 else if (scm_is_true
2132 ($2, make_music_from_simple (parser, @4, $4))))
2133 MYREPARSE (@4, $2, DURATION_ARG, $4);
2135 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2136 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2139 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2141 SCM res = try_string_variants ($2, $4);
2142 if (!SCM_UNBNDP (res))
2143 if (scm_is_pair (res)) {
2145 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2148 $$ = scm_cons (res, $3);
2150 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2151 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2154 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2156 SCM res = try_string_variants ($2, $4);
2157 if (!SCM_UNBNDP (res))
2158 if (scm_is_pair (res)) {
2160 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2163 $$ = scm_cons (res, $3);
2165 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2166 MYBACKUP (STRING, $4, @4);
2169 | function_arglist_backup REPARSE pitch_or_music
2171 if (scm_is_true (scm_call_1 ($2, $3)))
2172 $$ = scm_cons ($3, $1);
2174 $$ = check_scheme_arg (parser, @3,
2175 make_music_from_simple
2179 | function_arglist_backup REPARSE bare_number_common
2181 $$ = check_scheme_arg (parser, @3,
2184 | function_arglist_backup REPARSE multiplied_duration
2186 $$ = check_scheme_arg (parser, @3,
2189 | function_arglist_backup REPARSE reparsed_rhythm
2191 $$ = check_scheme_arg (parser, @3,
2194 | function_arglist_backup REPARSE symbol_list_arg
2196 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2201 function_arglist_nonbackup
2202 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2204 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2208 function_arglist_skip_nonbackup:
2209 function_arglist_nonbackup
2210 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2212 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2216 // Partial function arglists are returned just in their incomplete
2217 // state: when combined with the music function, the missing parts of
2218 // the signature can be reconstructed
2220 // To serve as a partial arglist, the argument list must absolutely
2221 // _not_ be in "skipping optional arguments" mode since then there is
2222 // some backup token that has nowhere to go before \etc.
2224 // So we can skim off an arbitrary number of arguments from the end of
2225 // the argument list. The argument list remaining afterwards has to
2226 // be in not-skipping-optional-arguments mode.
2228 function_arglist_partial:
2229 EXPECT_SCM function_arglist_optional
2233 | EXPECT_SCM function_arglist_partial_optional
2237 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2241 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2247 function_arglist_partial_optional:
2248 EXPECT_SCM function_arglist_optional
2252 | EXPECT_SCM function_arglist_partial_optional
2256 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2260 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2266 function_arglist_common:
2267 EXPECT_NO_MORE_ARGS {
2270 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2272 if (scm_is_true (scm_call_1 ($1, $3)))
2273 $$ = scm_cons ($3, $2);
2275 $$ = check_scheme_arg (parser, @3,
2276 make_music_from_simple
2280 | EXPECT_SCM function_arglist_optional bare_number_common
2282 $$ = check_scheme_arg (parser, @3,
2285 | EXPECT_SCM function_arglist_optional post_event_nofinger
2287 $$ = check_scheme_arg (parser, @3,
2290 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2292 SCM n = scm_difference ($4, SCM_UNDEFINED);
2293 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2295 | function_arglist_common_reparse REPARSE SCM_ARG
2297 $$ = check_scheme_arg (parser, @3,
2300 | function_arglist_common_reparse REPARSE lyric_element_music
2302 $$ = check_scheme_arg (parser, @3,
2305 | function_arglist_common_reparse REPARSE pitch_or_music
2307 if (scm_is_true (scm_call_1 ($2, $3)))
2308 $$ = scm_cons ($3, $1);
2310 $$ = check_scheme_arg (parser, @3,
2311 make_music_from_simple
2315 | function_arglist_common_reparse REPARSE bare_number_common
2317 $$ = check_scheme_arg (parser, @3,
2320 | function_arglist_common_reparse REPARSE multiplied_duration
2322 $$ = check_scheme_arg (parser, @3,
2325 | function_arglist_common_reparse REPARSE reparsed_rhythm
2327 $$ = check_scheme_arg (parser, @3,
2330 | function_arglist_common_reparse REPARSE symbol_list_arg
2332 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2336 function_arglist_common_reparse:
2337 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2340 SCM res = try_string_variants ($1, $3);
2341 if (!SCM_UNBNDP (res))
2342 if (scm_is_pair (res))
2343 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2345 MYREPARSE (@3, $1, SCM_ARG, res);
2346 else if (scm_is_true
2348 ($1, make_music_from_simple (parser, @3, $3))))
2349 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2351 // This is going to flag a syntax error, we
2352 // know the predicate to be false.
2353 MYREPARSE (@3, $1, SCM_ARG, $3);
2355 | EXPECT_SCM function_arglist_optional pitch
2360 ($1, make_music_from_simple
2362 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2364 MYREPARSE (@3, $1, SCM_ARG, $3);
2366 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2371 ($1, make_music_from_simple
2373 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2375 MYREPARSE (@3, $1, SCM_ARG, $3);
2377 | EXPECT_SCM function_arglist_optional STRING
2380 SCM res = try_string_variants ($1, $3);
2381 if (!SCM_UNBNDP (res))
2382 if (scm_is_pair (res))
2383 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2385 MYREPARSE (@3, $1, SCM_ARG, res);
2386 else if (scm_is_true
2388 ($1, make_music_from_simple (parser, @3, $3))))
2389 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2391 // This is going to flag a syntax error, we
2392 // know the predicate to be false.
2393 MYREPARSE (@3, $1, SCM_ARG, $3);
2395 | EXPECT_SCM function_arglist_optional full_markup
2398 if (scm_is_true (scm_call_1 ($1, $3)))
2399 MYREPARSE (@3, $1, SCM_ARG, $3);
2400 else if (scm_is_true
2402 ($1, make_music_from_simple (parser, @3, $3))))
2403 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2405 // This is going to flag a syntax error, we
2406 // know the predicate to be false.
2407 MYREPARSE (@3, $1, SCM_ARG, $3);
2409 | EXPECT_SCM function_arglist_optional UNSIGNED
2412 if (scm_is_true (scm_call_1 ($1, $3)))
2413 // May be 3 \cm or similar
2414 MYREPARSE (@3, $1, REAL, $3);
2415 else if (scm_is_true (scm_call_1 ($1, scm_list_1 ($3))))
2416 MYREPARSE (@3, $1, SYMBOL_LIST, scm_list_1 ($3));
2418 SCM d = make_duration ($3);
2419 if (!SCM_UNBNDP (d)) {
2420 if (scm_is_true (scm_call_1 ($1, d)))
2421 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2422 else if (scm_is_true
2424 ($1, make_music_from_simple (parser, @3, d))))
2425 MYREPARSE (@3, $1, DURATION_ARG, d);
2427 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2429 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2432 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2435 if (scm_is_true (scm_call_1 ($1, $3)))
2436 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2437 else if (scm_is_true
2439 ($1, make_music_from_simple (parser, @3, $3))))
2440 MYREPARSE (@3, $1, DURATION_ARG, $3);
2442 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2444 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2447 SCM n = scm_difference ($4, SCM_UNDEFINED);
2448 if (scm_is_true (scm_call_1 ($1, n)))
2449 MYREPARSE (@4, $1, REAL, n);
2451 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2452 t->set_property ("digit", $4);
2453 SCM m = t->unprotect ();
2454 if (scm_is_true (scm_call_1 ($1, m)))
2455 MYREPARSE (@4, $1, SCM_ARG, m);
2457 MYREPARSE (@4, $1, SCM_ARG, $4);
2460 | EXPECT_SCM function_arglist_optional '-' REAL
2463 SCM n = scm_difference ($4, SCM_UNDEFINED);
2464 MYREPARSE (@4, $1, REAL, n);
2468 function_arglist_optional:
2469 function_arglist_backup
2470 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2472 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2474 | function_arglist_skip_backup BACKUP
2477 function_arglist_skip_backup:
2478 function_arglist_backup
2479 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2481 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2485 music_function_call:
2486 MUSIC_FUNCTION function_arglist {
2487 $$ = MAKE_SYNTAX (music_function, @$,
2494 /**/ { $$ = SCM_EOL; }
2495 | '=' simple_string {
2500 // We must not have lookahead tokens parsed in lyric mode. In order
2501 // to save confusion, we take almost the same set as permitted with
2502 // \lyricmode and/or \lyrics. However, music identifiers are also
2503 // allowed, and they obviously do not require switching into lyrics
2504 // mode for parsing.
2508 parser->lexer_->push_lyric_state ();
2509 } grouped_music_list
2511 parser->lexer_->pop_state ();
2518 mode_changing_head grouped_music_list {
2519 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2521 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2527 parser->lexer_->pop_state ();
2529 | mode_changing_head_with_context optional_context_mods grouped_music_list {
2530 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, $2, SCM_BOOL_T, $3);
2531 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2533 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2535 parser->lexer_->pop_state ();
2541 parser->lexer_->push_note_state (Lily::pitchnames);
2543 $$ = ly_symbol2scm ("notes");
2547 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2549 $$ = ly_symbol2scm ("drums");
2552 parser->lexer_->push_figuredbass_state ();
2554 $$ = ly_symbol2scm ("figures");
2557 parser->lexer_->chordmodifier_tab_ =
2558 alist_to_hashq (Lily::chordmodifiers);
2559 parser->lexer_->push_chord_state (Lily::pitchnames);
2560 $$ = ly_symbol2scm ("chords");
2564 { parser->lexer_->push_lyric_state ();
2565 $$ = ly_symbol2scm ("lyrics");
2569 mode_changing_head_with_context:
2571 parser->lexer_->push_note_state (Lily::drum_pitch_names);
2573 $$ = ly_symbol2scm ("DrumStaff");
2576 parser->lexer_->push_figuredbass_state ();
2578 $$ = ly_symbol2scm ("FiguredBass");
2581 parser->lexer_->chordmodifier_tab_ =
2582 alist_to_hashq (Lily::chordmodifiers);
2583 parser->lexer_->push_chord_state (Lily::pitchnames);
2584 $$ = ly_symbol2scm ("ChordNames");
2587 { parser->lexer_->push_lyric_state ();
2588 $$ = ly_symbol2scm ("Lyrics");
2593 CHANGE symbol '=' simple_string {
2594 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2601 $$ = scm_reverse_x ($1, SCM_EOL);
2607 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2610 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2612 | OVERRIDE revert_arg '=' scalar {
2613 if (scm_ilength ($2) < 2) {
2614 parser->parser_error (@2, _("bad grob property path"));
2617 $$ = scm_cons (ly_symbol2scm ("push"),
2618 scm_cons2 (scm_car ($2),
2623 | REVERT revert_arg {
2624 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2628 // This is all quite awkward for the sake of substantial backward
2629 // compatibility while at the same time allowing a more "natural" form
2630 // of specification not separating grob specification from grob
2631 // property path. The purpose of this definition of revert_arg is to
2632 // allow the symbol list which specifies grob and property to revert
2633 // to be optionally be split into two parts after the grob (which in
2634 // this case is just the first element of the list). symbol_list_part
2635 // is only one path component, but it can be parsed without lookahead,
2636 // so we can follow it with a synthetic BACKUP token when needed. If
2637 // the first symbol_list_part already contains multiple elements (only
2638 // possible if a Scheme expression provides them), we just parse for
2639 // additional elements introduced by '.', which is what the
2640 // SYMBOL_LIST backup in connection with the immediately following
2641 // rule using symbol_list_arg does.
2643 // As long as we don't have our coffers filled with both grob and at
2644 // least one grob property specification, the rest of the required
2645 // symbol list chain may be provided either with or without a leading
2646 // dot. This is for both allowing the traditional
2647 // \revert Accidental #'color
2648 // as well as well as the "naive" form
2649 // \revert Accidental.color
2652 revert_arg_backup BACKUP symbol_list_arg
2661 if (scm_is_null ($1)
2662 || scm_is_null (scm_cdr ($1)))
2663 MYBACKUP (SCM_ARG, $1, @1);
2665 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2669 // revert_arg_part delivers results in reverse
2672 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2674 $$ = scm_append_x (scm_list_2 ($5, $3));
2676 | revert_arg_backup BACKUP SCM_ARG ',' symbol_list_part
2678 $$ = scm_append_x (scm_list_2 ($5, $3));
2680 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2682 $$ = scm_append_x (scm_list_2 ($4, $3));
2687 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2688 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2690 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2691 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2692 | DENIES { $$ = ly_symbol2scm ("denies"); }
2694 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2695 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2696 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2697 | NAME { $$ = ly_symbol2scm ("context-name"); }
2701 property_operation { $$ = $1; }
2702 | context_def_mod STRING {
2703 $$ = scm_list_2 ($1, $2);
2705 | context_def_mod embedded_scm
2707 if (!scm_is_string ($2)
2708 && ly_symbol2scm ("consists") != $1
2709 && ly_symbol2scm ("remove") != $1)
2712 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2716 $$ = scm_list_2 ($1, $2);
2721 // If defined, at least two members.
2725 SCM l = scm_reverse_x ($1, SCM_EOL);
2728 (scm_object_property (scm_car (l),
2729 ly_symbol2scm ("is-grob?"))))
2730 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2731 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2732 parser->parser_error (@1, _ ("bad grob property path"));
2739 // If defined, at least three members
2743 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2745 parser->parser_error (@1, _ ("bad grob property path"));
2749 | grob_prop_spec property_path
2751 if (!SCM_UNBNDP ($1)) {
2752 $$ = scm_append_x (scm_list_2 ($1, $2));
2753 if (scm_is_null (scm_cddr ($$))) {
2754 parser->parser_error (@$, _ ("bad grob property path"));
2762 // Exactly two elements or undefined
2766 SCM l = scm_reverse_x ($1, SCM_EOL);
2767 switch (scm_ilength (l)) {
2769 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2773 parser->parser_error (@1, _ ("bad context property path"));
2781 // This is all quite awkward for the sake of substantial backward
2782 // compatibility while at the same time allowing a more "natural" form
2783 // of specification not separating grob specification from grob
2784 // property path. The purpose of this definition of
2785 // simple_revert_context is to allow the symbol list which specifies
2786 // grob and property to revert to be optionally be split into two
2787 // parts after the grob (which may be preceded by a context
2788 // specification, a case which we distinguish by checking whether the
2789 // first symbol is a valid grob symbol instead).
2791 // See revert_arg above for the main work horse of this arrangement.
2792 // simple_revert_context just caters for the context and delegates the
2793 // rest of the job to revert_arg.
2795 simple_revert_context:
2798 $1 = scm_reverse_x ($1, SCM_EOL);
2799 if (scm_is_null ($1)
2801 (scm_object_property (scm_car ($1),
2802 ly_symbol2scm ("is-grob?")))) {
2803 $$ = ly_symbol2scm ("Bottom");
2804 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2807 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2814 OVERRIDE grob_prop_path '=' scalar {
2815 if (SCM_UNBNDP ($2))
2816 $$ = MAKE_SYNTAX (void_music, @$);
2818 $$ = MAKE_SYNTAX (property_override, @$,
2823 | REVERT simple_revert_context revert_arg {
2824 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2826 | SET context_prop_spec '=' scalar {
2827 if (SCM_UNBNDP ($2))
2828 $$ = MAKE_SYNTAX (void_music, @$);
2830 $$ = MAKE_SYNTAX (property_set, @$,
2835 | UNSET context_prop_spec {
2836 if (SCM_UNBNDP ($2))
2837 $$ = MAKE_SYNTAX (void_music, @$);
2839 $$ = MAKE_SYNTAX (property_unset, @$,
2855 if (Text_interface::is_markup ($1)) {
2858 parser->parser_error (@1, (_ ("markup expected")));
2859 $$ = scm_string (SCM_EOL);
2864 simple_string: STRING
2867 if (scm_is_string ($1)) {
2870 parser->parser_error (@1, (_ ("simple string expected")));
2871 $$ = scm_string (SCM_EOL);
2878 $$ = scm_string_to_symbol ($1);
2882 // This is a bit of overkill but makes the same
2883 // routine responsible for all symbol interpretations.
2884 $$ = try_string_variants (Guile_user::symbol_p, $1);
2885 if (SCM_UNBNDP ($$))
2887 parser->parser_error (@1, (_ ("symbol expected")));
2888 // Generate a unique symbol in case it is used
2889 // for an assignment or similar
2890 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2900 // The following is a rather defensive variant of admitting
2901 // negative numbers: the grammar would permit number_factor or
2902 // even number_expression. However, function arguments allow
2903 // only this simple kind of negative number, so to have things
2904 // like \tweak and \override behave reasonably similar, it
2905 // makes sense to rule out things like -- which are rather an
2906 // accent in function argument contexts.
2909 $$ = scm_difference ($2, SCM_UNDEFINED);
2912 | symbol_list_part_bare '.' property_path
2914 $$ = scm_reverse_x ($1, $3);
2916 | symbol_list_part_bare ',' property_path
2918 $$ = scm_reverse_x ($1, $3);
2923 simple_element post_events {
2924 // Let the rhythmic music iterator sort this mess out.
2925 if (scm_is_pair ($2)) {
2926 unsmob<Music> ($$)->set_property ("articulations",
2927 scm_reverse_x ($2, SCM_EOL));
2930 | CHORD_REPETITION optional_notemode_duration post_events {
2932 i.set_location (@1, @3);
2933 $$ = MAKE_SYNTAX (repetition_chord, i,
2934 $2, scm_reverse_x ($3, SCM_EOL));
2936 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2938 i.set_location (@1, @3);
2939 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2940 scm_reverse_x ($3, SCM_EOL));
2943 | note_chord_element
2948 chord_body optional_notemode_duration post_events
2950 Music *m = unsmob<Music> ($1);
2951 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2952 SCM es = m->get_property ("elements");
2953 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2955 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2956 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2957 es = ly_append2 (es, postevs);
2959 m->set_property ("elements", es);
2960 m->set_spot (parser->lexer_->override_input (@$));
2961 $$ = m->self_scm ();
2966 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2968 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2970 | FIGURE_OPEN figure_list FIGURE_CLOSE
2972 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2976 chord_body_elements:
2977 /* empty */ { $$ = SCM_EOL; }
2978 | chord_body_elements chord_body_element {
2979 if (!SCM_UNBNDP ($2))
2980 $$ = scm_cons ($2, $1);
2985 pitch_or_tonic_pitch exclamations questions octave_check post_events
2987 bool q = to_boolean ($3);
2988 bool ex = to_boolean ($2);
2992 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2993 n->set_property ("pitch", $1);
2995 n->set_property ("cautionary", SCM_BOOL_T);
2997 n->set_property ("force-accidental", SCM_BOOL_T);
2999 if (scm_is_pair (post)) {
3000 SCM arts = scm_reverse_x (post, SCM_EOL);
3001 n->set_property ("articulations", arts);
3003 if (scm_is_number (check))
3005 int q = scm_to_int (check);
3006 n->set_property ("absolute-octave", scm_from_int (q-1));
3009 $$ = n->unprotect ();
3011 | DRUM_PITCH post_events {
3012 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3013 n->set_property ("drum-type", $1);
3015 if (scm_is_pair ($2)) {
3016 SCM arts = scm_reverse_x ($2, SCM_EOL);
3017 n->set_property ("articulations", arts);
3019 $$ = n->unprotect ();
3021 | music_function_chord_body
3023 Music *m = unsmob<Music> ($1);
3025 while (m && m->is_mus_type ("music-wrapper-music")) {
3026 $$ = m->get_property ("element");
3027 m = unsmob<Music> ($$);
3030 if (!(m && m->is_mus_type ("rhythmic-event"))) {
3031 parser->parser_error (@$, _ ("not a rhythmic event"));
3037 music_function_chord_body:
3043 event_function_event:
3044 EVENT_FUNCTION function_arglist {
3045 $$ = MAKE_SYNTAX (music_function, @$,
3054 | post_events post_event {
3056 if (Music *m = unsmob<Music> ($2))
3058 if (m->is_mus_type ("post-event-wrapper"))
3060 for (SCM p = m->get_property ("elements");
3064 $$ = scm_cons (scm_car (p), $$);
3067 m->set_spot (parser->lexer_->override_input (@2));
3068 $$ = scm_cons ($2, $$);
3074 post_event_nofinger:
3075 direction_less_event {
3078 | script_dir music_function_call {
3080 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
3081 parser->parser_error (@2, _ ("post-event expected"));
3082 $$ = SCM_UNSPECIFIED;
3083 } else if (!SCM_UNBNDP ($1))
3085 unsmob<Music> ($$)->set_property ("direction", $1);
3089 if (!parser->lexer_->is_lyric_state ())
3090 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3091 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
3094 if (!parser->lexer_->is_lyric_state ())
3095 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3096 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
3098 | script_dir direction_reqd_event {
3099 if (!SCM_UNBNDP ($1))
3101 Music *m = unsmob<Music> ($2);
3102 m->set_property ("direction", $1);
3106 | script_dir direction_less_event {
3107 if (!SCM_UNBNDP ($1))
3109 Music *m = unsmob<Music> ($2);
3110 m->set_property ("direction", $1);
3117 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
3122 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
3133 string_number_event:
3135 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3136 s->set_property ("string-number", $1);
3137 $$ = s->unprotect ();
3141 direction_less_event:
3143 | EVENT_IDENTIFIER {
3147 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3148 a->set_property ("tremolo-type", $1);
3149 $$ = a->unprotect ();
3151 | event_function_event
3154 direction_reqd_event:
3158 | script_abbreviation {
3159 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3160 if (scm_is_string (s)) {
3161 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3162 a->set_property ("articulation-type", s);
3163 $$ = a->unprotect ();
3165 Music *original = unsmob<Music> (s);
3166 if (original && original->is_mus_type ("post-event")) {
3167 Music *a = original->clone ();
3168 a->set_spot (parser->lexer_->override_input (@$));
3169 $$ = a->unprotect ();
3171 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3172 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3179 /**/ { $$ = SCM_EOL; }
3180 | '=' quotes { $$ = $2; }
3194 $$ = scm_from_int (1);
3197 $$ = scm_oneplus ($1);
3203 $$ = scm_from_int (-1);
3206 $$ = scm_oneminus ($1);
3211 NOTENAME_PITCH quotes {
3212 if (!scm_is_eq (SCM_INUM0, $2))
3214 Pitch p = *unsmob<Pitch> ($1);
3215 p = p.transposed (Pitch (scm_to_int ($2), 0));
3216 $$ = p.smobbed_copy ();
3226 TONICNAME_PITCH quotes {
3227 if (!scm_is_eq (SCM_INUM0, $2))
3229 Pitch p = *unsmob<Pitch> ($1);
3230 p = p.transposed (Pitch (scm_to_int ($2), 0));
3231 $$ = p.smobbed_copy ();
3238 | PITCH_IDENTIFIER quotes {
3239 if (!scm_is_eq (SCM_INUM0, $2))
3241 Pitch p = *unsmob<Pitch> ($1);
3242 p = p.transposed (Pitch (scm_to_int ($2), 0));
3243 $$ = p.smobbed_copy ();
3248 pitch_or_tonic_pitch:
3255 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3256 t->set_property ("text", $1);
3257 $$ = t->unprotect ();
3260 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3261 t->set_property ("text",
3262 make_simple_markup ($1));
3263 $$ = t->unprotect ();
3267 Music *m = unsmob<Music> ($1);
3268 if (m && m->is_mus_type ("post-event"))
3270 else if (Text_interface::is_markup ($1)) {
3271 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3272 t->set_property ("text", $1);
3273 $$ = t->unprotect ();
3275 parser->parser_error (@1, _ ("not an articulation"));
3281 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3282 t->set_property ("digit", $1);
3283 $$ = t->unprotect ();
3287 script_abbreviation:
3289 $$ = scm_from_ascii_string ("Hat");
3292 $$ = scm_from_ascii_string ("Plus");
3295 $$ = scm_from_ascii_string ("Dash");
3298 $$ = scm_from_ascii_string ("Bang");
3301 $$ = scm_from_ascii_string ("Larger");
3304 $$ = scm_from_ascii_string ("Dot");
3307 $$ = scm_from_ascii_string ("Underscore");
3312 '_' { $$ = scm_from_int (DOWN); }
3313 | '^' { $$ = scm_from_int (UP); }
3314 | '-' { $$ = SCM_UNDEFINED; }
3317 maybe_notemode_duration:
3321 | multiplied_duration {
3323 parser->default_duration_ = *unsmob<Duration> ($$);
3328 optional_notemode_duration:
3329 maybe_notemode_duration
3331 if (SCM_UNBNDP ($$))
3332 $$ = parser->default_duration_.smobbed_copy ();
3338 $$ = make_duration ($1, scm_to_int ($2));
3339 if (SCM_UNBNDP ($$))
3341 parser->parser_error (@1, _ ("not a duration"));
3342 $$ = Duration ().smobbed_copy ();
3345 | DURATION_IDENTIFIER dots {
3346 $$ = make_duration ($1, scm_to_int ($2));
3350 multiplied_duration:
3351 steno_duration multipliers {
3352 $$ = make_duration ($1, 0, $2);
3361 $$ = scm_oneplus ($1);
3370 | multipliers '*' UNSIGNED
3372 if (!SCM_UNBNDP ($1))
3373 $$ = scm_product ($1, $3);
3377 | multipliers '*' FRACTION
3379 if (!SCM_UNBNDP ($1))
3380 $$ = scm_product ($1, scm_divide (scm_car ($3),
3383 $$ = scm_divide (scm_car ($3), scm_cdr ($3));
3389 $$ = scm_from_int (parser->default_tremolo_type_);
3392 if (SCM_UNBNDP (make_duration ($2))) {
3393 parser->parser_error (@2, _ ("not a duration"));
3394 $$ = scm_from_int (parser->default_tremolo_type_);
3397 parser->default_tremolo_type_ = scm_to_int ($2);
3403 UNSIGNED { $$ = $1; }
3404 | STRING { $$ = $1; }
3405 | full_markup { $$ = $1; }
3408 // as an integer, it needs to be non-negative, and otherwise
3409 // it needs to be suitable as a markup.
3410 if (scm_is_integer ($1)
3411 ? scm_is_true (scm_negative_p ($1))
3412 : !Text_interface::is_markup ($1))
3414 parser->parser_error (@1, _ ("bass number expected"));
3420 figured_bass_alteration:
3421 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3422 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3423 | '!' { $$ = scm_from_int (0); }
3428 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3429 $$ = bfr->unprotect ();
3432 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3433 $$ = bfr->self_scm ();
3435 if (scm_is_number ($1))
3436 bfr->set_property ("figure", $1);
3437 else if (Text_interface::is_markup ($1))
3438 bfr->set_property ("text", $1);
3444 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3446 | bass_figure figured_bass_alteration {
3447 Music *m = unsmob<Music> ($1);
3448 if (scm_to_double ($2)) {
3449 SCM salter = m->get_property ("alteration");
3450 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3451 m->set_property ("alteration",
3452 scm_sum (alter, $2));
3454 m->set_property ("alteration", scm_from_int (0));
3457 | bass_figure figured_bass_modification {
3458 Music *m = unsmob<Music> ($1);
3459 m->set_property ($2, SCM_BOOL_T);
3464 figured_bass_modification:
3466 $$ = ly_symbol2scm ("augmented");
3469 $$ = ly_symbol2scm ("no-continuation");
3472 $$ = ly_symbol2scm ("diminished");
3475 $$ = ly_symbol2scm ("augmented-slash");
3485 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3493 | figure_list br_bass_figure {
3494 $$ = scm_cons ($2, $1);
3499 /**/ { $$ = SCM_BOOL_F; }
3500 | REST { $$ = SCM_BOOL_T; }
3504 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3505 if (!parser->lexer_->is_note_state ())
3506 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3507 if (!SCM_UNBNDP ($2)
3509 || scm_is_number ($4)
3512 || scm_is_pair ($7))
3515 if (scm_is_true ($6))
3516 n = MY_MAKE_MUSIC ("RestEvent", @$);
3518 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3520 n->set_property ("pitch", $1);
3521 if (SCM_UNBNDP ($5))
3522 n->set_property ("duration",
3523 parser->default_duration_.smobbed_copy ());
3525 n->set_property ("duration", $5);
3527 if (scm_is_number ($4))
3529 int q = scm_to_int ($4);
3530 n->set_property ("absolute-octave", scm_from_int (q-1));
3533 if (to_boolean ($3))
3534 n->set_property ("cautionary", SCM_BOOL_T);
3535 if (to_boolean ($2) || to_boolean ($3))
3536 n->set_property ("force-accidental", SCM_BOOL_T);
3537 if (scm_is_pair ($7))
3538 n->set_property ("articulations",
3539 scm_reverse_x ($7, SCM_EOL));
3540 $$ = n->unprotect ();
3543 | new_chord post_events {
3544 if (!parser->lexer_->is_chord_state ())
3545 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3546 if (scm_is_pair ($2)) {
3547 if (unsmob<Pitch> ($1))
3548 $1 = make_chord_elements (@1,
3550 parser->default_duration_.smobbed_copy (),
3553 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3555 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3556 } else if (!unsmob<Pitch> ($1))
3557 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3558 // A mere pitch drops through.
3563 DRUM_PITCH optional_notemode_duration {
3564 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3565 n->set_property ("duration", $2);
3566 n->set_property ("drum-type", $1);
3568 $$ = n->unprotect ();
3570 | RESTNAME optional_notemode_duration {
3572 if (ly_scm2string ($1) == "s") {
3574 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3577 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3580 ev->set_property ("duration", $2);
3581 $$ = ev->unprotect ();
3587 if (!parser->lexer_->is_lyric_state ())
3588 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3592 if (!parser->lexer_->is_lyric_state ())
3593 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3599 lyric_element_music:
3600 lyric_element optional_notemode_duration post_events {
3601 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3602 if (scm_is_pair ($3))
3603 unsmob<Music> ($$)->set_property
3604 ("articulations", scm_reverse_x ($3, SCM_EOL));
3608 // Can return a single pitch rather than a list.
3610 steno_tonic_pitch maybe_notemode_duration {
3611 if (SCM_UNBNDP ($2))
3614 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3616 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3617 SCM its = scm_reverse_x ($4, SCM_EOL);
3618 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3626 | chord_items chord_item {
3627 $$ = scm_cons ($2, $$);
3633 $$ = ly_symbol2scm ("chord-colon");
3636 $$ = ly_symbol2scm ("chord-caret");
3638 | CHORD_SLASH steno_tonic_pitch {
3639 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3641 | CHORD_BASS steno_tonic_pitch {
3642 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3651 $$ = scm_reverse_x ($1, SCM_EOL);
3659 step_number { $$ = scm_cons ($1, SCM_EOL); }
3660 | step_numbers '.' step_number {
3661 $$ = scm_cons ($3, $$);
3667 $$ = make_chord_step ($1, 0);
3670 $$ = make_chord_step ($1, SHARP_ALTERATION);
3672 | UNSIGNED CHORD_MINUS {
3673 $$ = make_chord_step ($1, FLAT_ALTERATION);
3681 | unsigned_number '-' unsigned_number {
3682 $$ = scm_cons ($1, $3);
3689 TODO: should deprecate in favor of Scheme?
3693 number_expression '+' number_term {
3694 $$ = scm_sum ($1, $3);
3696 | number_expression '-' number_term {
3697 $$ = scm_difference ($1, $3);
3706 | number_factor '*' number_factor {
3707 $$ = scm_product ($1, $3);
3709 | number_factor '/' number_factor {
3710 $$ = scm_divide ($1, $3);
3715 '-' number_factor { /* %prec UNARY_MINUS */
3716 $$ = scm_difference ($2, SCM_UNDEFINED);
3724 | REAL NUMBER_IDENTIFIER
3726 $$ = scm_product ($1, $2);
3733 | UNSIGNED NUMBER_IDENTIFIER {
3734 $$ = scm_product ($1, $2);
3742 if (!scm_is_integer ($1)
3743 || scm_is_true (scm_negative_p ($1)))
3745 parser->parser_error (@1, _("not an unsigned integer"));
3751 if (!scm_is_integer ($1)
3752 || scm_is_true (scm_negative_p ($1)))
3754 parser->parser_error (@1, _("not an unsigned integer"));
3761 { $$ = SCM_UNDEFINED; }
3764 if (SCM_UNBNDP ($1))
3772 // This precedence rule is rather weird. It triggers when '!' is
3773 // encountered after a pitch, and is used for deciding whether to save
3774 // this instead for a figure modification. This should not actually
3775 // occur in practice as pitches and figures are generated in different
3776 // modes. Using a greedy (%right) precedence makes sure that we don't
3777 // get stuck in a wrong interpretation.
3778 { $$ = SCM_UNDEFINED; } %prec ':'
3781 if (SCM_UNBNDP ($1))
3790 { parser->lexer_->push_markup_state (); }
3793 parser->lexer_->pop_state ();
3800 parser->lexer_->push_markup_state ();
3805 markup_mode markup_top {
3807 parser->lexer_->pop_state ();
3812 markup_mode markup_partial_function ETC
3814 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3815 parser->lexer_->pop_state ();
3821 $$ = scm_list_2 (Lily::line_markup, $1);
3823 | markup_head_1_list simple_markup
3825 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3826 @2, $1, scm_list_1 ($2)));
3836 if (Text_interface::is_markup ($1))
3837 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3838 else if (Text_interface::is_markup_list ($1))
3839 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3841 parser->parser_error (@1, _ ("not a markup"));
3842 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3849 markup_composed_list {
3852 | markup_uncomposed_list
3855 markup_uncomposed_list:
3856 markup_braced_list {
3859 | markup_command_list {
3860 $$ = scm_list_1 ($1);
3862 | markup_scm MARKUPLIST_IDENTIFIER
3867 parser->lexer_->push_note_state (Lily::pitchnames);
3868 } '{' score_body '}' {
3869 Score *sc = unsmob<Score> ($4);
3870 sc->origin ()->set_spot (@$);
3871 if (sc->defs_.empty ()) {
3872 Output_def *od = get_layout (parser);
3873 sc->add_output_def (od);
3876 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3877 parser->lexer_->pop_state ();
3881 markup_composed_list:
3882 markup_head_1_list markup_uncomposed_list {
3883 $$ = MAKE_SYNTAX (composed_markup_list,
3889 '{' markup_braced_list_body '}' {
3890 $$ = scm_reverse_x ($2, SCM_EOL);
3894 markup_braced_list_body:
3895 /* empty */ { $$ = SCM_EOL; }
3896 | markup_braced_list_body markup {
3897 $$ = scm_cons ($2, $1);
3899 | markup_braced_list_body markup_list {
3900 $$ = scm_reverse_x ($2, $1);
3904 markup_command_list:
3905 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3906 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3910 markup_command_basic_arguments:
3911 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3912 $$ = scm_cons ($3, $2);
3914 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3915 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3917 | EXPECT_NO_MORE_ARGS {
3922 markup_command_list_arguments:
3923 markup_command_basic_arguments { $$ = $1; }
3924 | EXPECT_MARKUP markup_command_list_arguments markup {
3925 $$ = scm_cons ($3, $2);
3929 markup_partial_function:
3930 MARKUP_FUNCTION markup_arglist_partial
3932 $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
3934 | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
3936 $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
3941 markup_arglist_partial:
3942 EXPECT_MARKUP markup_arglist_partial
3946 | EXPECT_SCM markup_arglist_partial
3950 | EXPECT_MARKUP markup_command_list_arguments
3954 | EXPECT_SCM markup_command_list_arguments
3961 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3962 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3967 markup_head_1_item {
3968 $$ = scm_list_1 ($1);
3970 | markup_head_1_list markup_head_1_item {
3971 $$ = scm_cons ($2, $1);
3977 $$ = make_simple_markup ($1);
3980 parser->lexer_->push_note_state (Lily::pitchnames);
3981 } '{' score_body '}' {
3982 Score *sc = unsmob<Score> ($4);
3983 sc->origin ()->set_spot (@$);
3984 if (sc->defs_.empty ()) {
3985 Output_def *od = get_layout (parser);
3986 sc->add_output_def (od);
3989 $$ = scm_list_2 (Lily::score_markup, $4);
3990 parser->lexer_->pop_state ();
3992 | MARKUP_FUNCTION markup_command_basic_arguments {
3993 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3995 | markup_scm MARKUP_IDENTIFIER
4002 markup_head_1_list simple_markup
4004 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
4005 @2, $1, scm_list_1 ($2)));
4015 Lily_parser::set_yydebug (bool x)
4021 Lily_parser::do_yyparse ()
4023 return scm_c_with_fluid (Lily::f_parser,
4025 do_yyparse_trampoline,
4026 static_cast <void *>(this));
4030 Lily_parser::do_yyparse_trampoline (void *parser)
4032 SCM retval = SCM_UNDEFINED;
4033 yyparse (static_cast <Lily_parser *>(parser), &retval);
4041 It is a little strange to have this function in this file, but
4042 otherwise, we have to import music classes into the lexer.
4046 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
4048 if (unsmob<Book> (sid)) {
4049 Book *book = unsmob<Book> (sid)->clone ();
4050 *destination = book->self_scm ();
4053 return BOOK_IDENTIFIER;
4054 } else if (scm_is_number (sid)) {
4056 return NUMBER_IDENTIFIER;
4057 } else if (unsmob<Context_def> (sid))
4059 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
4060 return SCM_IDENTIFIER;
4061 } else if (unsmob<Context_mod> (sid)) {
4062 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
4063 return CONTEXT_MOD_IDENTIFIER;
4064 } else if (Music *mus = unsmob<Music> (sid)) {
4065 mus = mus->clone ();
4066 *destination = mus->self_scm ();
4067 bool is_event = mus->is_mus_type ("post-event");
4069 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
4070 } else if (unsmob<Pitch> (sid)) {
4071 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
4072 return PITCH_IDENTIFIER;
4073 } else if (unsmob<Duration> (sid)) {
4074 *destination = unsmob<Duration> (sid)->smobbed_copy ();
4075 return DURATION_IDENTIFIER;
4076 } else if (unsmob<Output_def> (sid)) {
4077 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
4078 return SCM_IDENTIFIER;
4079 } else if (unsmob<Score> (sid)) {
4080 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
4081 return SCM_IDENTIFIER;
4082 } else if (scm_is_pair (sid)
4083 && scm_is_pair (scm_car (sid))
4084 && scm_is_true (Lily::key_p (scm_caar (sid)))) {
4086 return LOOKUP_IDENTIFIER;
4092 get_next_unique_context_id ()
4094 return scm_from_ascii_string ("$uniqueContextId");
4099 get_next_unique_lyrics_context_id ()
4101 static int new_context_count;
4103 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
4104 return scm_from_ascii_string (s);
4107 // check_scheme_arg checks one argument with a given predicate for use
4108 // in an argument list and throws a syntax error if it is unusable.
4109 // The argument is prepended to the argument list in any case. After
4110 // throwing a syntax error, the argument list is terminated with #f as
4111 // its last cdr in order to mark it as uncallable while not losing
4112 // track of its total length.
4114 // There are a few special considerations: if optional argument disp
4115 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
4116 // instead of arg in a prospective error message. This is useful if
4117 // arg is not the actual argument but rather a transformation of it.
4119 // If arg itself is SCM_UNDEFINED, the predicate is considered false
4120 // and an error message using disp is produced unconditionally.
4122 SCM check_scheme_arg (Lily_parser *parser, Input loc,
4123 SCM arg, SCM args, SCM pred, SCM disp)
4125 if (SCM_UNBNDP (arg))
4126 args = scm_cons (disp, args);
4128 args = scm_cons (arg, args);
4129 if (scm_is_true (scm_call_1 (pred, arg)))
4132 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
4133 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
4134 SCM_UNBNDP (disp) ? arg : disp);
4135 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
4139 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
4141 if (Music *m = unsmob<Music> (arg))
4144 m->set_spot (parser->lexer_->override_input (loc));
4145 return m->unprotect ();
4151 try_string_variants (SCM pred, SCM str)
4153 // a matching predicate is always ok
4154 if (scm_is_true (scm_call_1 (pred, str)))
4156 // a symbol may be interpreted as a list of symbols if it helps
4157 if (scm_is_true (Lily::key_p (str))) {
4158 str = scm_list_1 (str);
4159 if (scm_is_true (scm_call_1 (pred, str)))
4161 return SCM_UNDEFINED;
4164 // If this cannot be a string representation of a symbol list,
4167 if (!is_regular_identifier (str, true))
4168 return SCM_UNDEFINED;
4170 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4171 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4172 scm_set_car_x (p, scm_string_split (scm_car (p),
4173 SCM_MAKE_CHAR (',')));
4174 str = scm_append_x (str);
4175 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4176 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4178 // Let's attempt the symbol list interpretation first.
4180 if (scm_is_true (scm_call_1 (pred, str)))
4183 // If there is just one symbol in the list, we might interpret
4184 // it as a single symbol
4186 if (scm_is_null (scm_cdr (str)))
4188 str = scm_car (str);
4189 if (scm_is_true (scm_call_1 (pred, str)))
4193 return SCM_UNDEFINED;
4197 is_regular_identifier (SCM id, bool multiple)
4199 if (!scm_is_string (id))
4202 string str = ly_scm2string (id);
4204 bool middle = false;
4206 for (string::iterator it=str.begin(); it != str.end (); it++)
4209 if ((c >= 'a' && c <= 'z')
4210 || (c >= 'A' && c <= 'Z')
4213 else if (middle && (c == '-' || c == '_' || (multiple &&
4214 (c == '.' || c == ','))))
4223 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4225 if (unsmob<Music> (simple))
4227 if (parser->lexer_->is_note_state ()) {
4228 if (scm_is_symbol (simple)) {
4229 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4230 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4231 n->set_property ("drum-type", simple);
4232 return n->unprotect ();
4234 if (unsmob<Pitch> (simple)) {
4235 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4236 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4237 n->set_property ("pitch", simple);
4238 return n->unprotect ();
4241 if (scm_is_integer (simple))
4242 d = make_duration (simple);
4243 if (unsmob<Duration> (d)) {
4244 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4245 n->set_property ("duration", d);
4246 return n->unprotect ();
4249 } else if (parser->lexer_->is_lyric_state ()) {
4250 if (Text_interface::is_markup (simple))
4251 return MAKE_SYNTAX (lyric_event, loc, simple,
4252 parser->default_duration_.smobbed_copy ());
4253 } else if (parser->lexer_->is_chord_state ()) {
4254 if (unsmob<Pitch> (simple))
4258 make_chord_elements (loc, simple,
4259 parser->default_duration_.smobbed_copy (),
4266 make_music_with_input (SCM name, Input where)
4268 Music *m = make_music_by_name (name);
4269 m->set_spot (where);
4274 make_simple_markup (SCM a)
4280 make_duration (SCM d, int dots, SCM factor)
4284 if (Duration *dur = unsmob<Duration> (d)) {
4285 if (!dots && SCM_UNBNDP (factor))
4289 k = Duration (k.duration_log (), k.dot_count () + dots)
4290 .compressed (k.factor ());
4292 int t = scm_to_int (d);
4293 if (t > 0 && (t & (t-1)) == 0)
4294 k = Duration (intlog2 (t), dots);
4296 return SCM_UNDEFINED;
4299 if (!SCM_UNBNDP (factor))
4300 k = k.compressed (ly_scm2rational (factor));
4302 return k.smobbed_copy ();
4306 make_chord_step (SCM step_scm, Rational alter)
4308 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4310 // Notename/octave are normalized
4311 if (m.get_notename () == 6)
4312 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4314 return m.smobbed_copy ();
4319 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4321 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4322 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4324 unsmob<Music> (scm_car (s))->set_spot (loc);
4330 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4332 Lily_lexer *lex = parser->lexer_;
4336 int tok = lex->pop_extra_token ();
4339 lex->prepare_for_next_token ();
4340 return lex->yylex ();