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 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
391 parser->lexer_->push_note_state (nn);
392 } embedded_lilypond {
393 parser->lexer_->pop_state ();
398 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
399 | lilypond toplevel_expression {
401 | lilypond assignment {
404 parser->error_level_ = 1;
407 parser->error_level_ = 1;
414 parser->lexer_->add_scope (get_header (parser));
416 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
419 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
420 scm_call_1 (proc, $1);
423 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
424 scm_call_1 (proc, $1);
427 SCM proc = parser->lexer_->lookup_identifier
428 (unsmob<Book>($1)->paper_
429 ? "toplevel-book-handler"
430 : "toplevel-bookpart-handler");
431 scm_call_1 (proc, $1);
434 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
435 scm_call_1 (proc, $1);
438 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
439 scm_call_1 (proc, $1);
442 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
443 scm_call_1 (proc, scm_list_1 ($1));
446 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
447 scm_call_1 (proc, $1);
450 // Evaluate and ignore #xxx, as opposed to \xxx
451 parser->lexer_->eval_scm_token ($1, @1);
453 | embedded_scm_active
455 SCM out = SCM_UNDEFINED;
456 if (Text_interface::is_markup ($1))
457 out = scm_list_1 ($1);
458 else if (Text_interface::is_markup_list ($1))
460 if (scm_is_pair (out))
462 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
463 scm_call_1 (proc, out);
464 } else if (unsmob<Score> ($1))
466 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
467 scm_call_1 (proc, $1);
468 } else if (Output_def * od = unsmob<Output_def> ($1)) {
471 if (to_boolean (od->c_variable ("is-paper")))
472 id = ly_symbol2scm ("$defaultpaper");
473 else if (to_boolean (od->c_variable ("is-midi")))
474 id = ly_symbol2scm ("$defaultmidi");
475 else if (to_boolean (od->c_variable ("is-layout")))
476 id = ly_symbol2scm ("$defaultlayout");
478 parser->lexer_->set_identifier (id, $1);
479 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
480 parser->parser_error (@1, _("bad expression type"));
484 Output_def * od = unsmob<Output_def> ($1);
486 if (to_boolean (od->c_variable ("is-paper")))
487 id = ly_symbol2scm ("$defaultpaper");
488 else if (to_boolean (od->c_variable ("is-midi")))
489 id = ly_symbol2scm ("$defaultmidi");
490 else if (to_boolean (od->c_variable ("is-layout")))
491 id = ly_symbol2scm ("$defaultlayout");
493 parser->lexer_->set_identifier (id, $1);
499 | LOOKUP_IDENTIFIER '.' symbol_list_rev
501 $$ = loc_on_music (parser, @$,
502 nested_property ($1, scm_reverse_x ($3, SCM_EOL)));
509 $$ = parser->lexer_->eval_scm_token ($1, @1);
520 embedded_scm_bare_arg:
524 $$ = parser->lexer_->eval_scm_token ($1, @1);
529 | context_modification
531 | context_def_spec_block
538 /* The generic version may end in music, or not */
546 /* embedded_scm_arg is _not_ casting pitches to music by default, this
547 * has to be done by the function itself. Note that this may cause
548 * the results of scm_function_call or embedded_scm_bare_arg to be
549 * turned into music from pitches as well. Note that this creates a
550 * distinctly awkward situation for calculated drum pitches. Those
551 * are at the current point of time rejected as music constituents as
552 * they can't be distinguished from "proper" symbols.
556 embedded_scm_bare_arg
562 SCM_FUNCTION function_arglist {
563 $$ = MAKE_SYNTAX (music_function, @$,
568 embedded_lilypond_number:
569 '-' embedded_lilypond_number
571 $$ = scm_difference ($2, SCM_UNDEFINED);
574 | UNSIGNED NUMBER_IDENTIFIER
576 $$ = scm_product ($1, $2);
583 // FIXME: @$ does not contain a useful source location
584 // for empty rules, and the only token in the whole
585 // production, EMBEDDED_LILY, is synthetic and also
586 // contains no source location.
587 $$ = MAKE_SYNTAX (void_music, @$);
589 | identifier_init_nonumber
590 | embedded_lilypond_number
591 | post_event post_events
593 $$ = scm_reverse_x ($2, SCM_EOL);
594 if (Music *m = unsmob<Music> ($1))
596 if (m->is_mus_type ("post-event-wrapper"))
598 (scm_list_2 (m->get_property ("elements"),
601 $$ = scm_cons ($1, $$);
604 && scm_is_null (scm_cdr ($$)))
608 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
609 m->set_property ("elements", $$);
610 $$ = m->unprotect ();
613 | multiplied_duration
614 | music_embedded music_embedded music_list {
615 $3 = scm_reverse_x ($3, SCM_EOL);
616 if (unsmob<Music> ($2))
617 $3 = scm_cons ($2, $3);
618 if (unsmob<Music> ($1))
619 $3 = scm_cons ($1, $3);
620 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
623 parser->error_level_ = 1;
624 $$ = SCM_UNSPECIFIED;
626 | INVALID embedded_lilypond {
627 parser->error_level_ = 1;
633 lilypond_header_body:
634 /* empty */ { $$ = SCM_UNSPECIFIED; }
635 | lilypond_header_body assignment {
638 | lilypond_header_body embedded_scm {
644 HEADER '{' lilypond_header_body '}' {
645 $$ = parser->lexer_->remove_scope ();
657 assignment_id '=' identifier_init {
658 parser->lexer_->set_identifier ($1, $3);
659 $$ = SCM_UNSPECIFIED;
661 | assignment_id property_path '=' identifier_init {
662 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
663 parser->lexer_->set_identifier (path, $4);
664 $$ = SCM_UNSPECIFIED;
666 | assignment_id '.' property_path '=' identifier_init {
667 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
668 parser->lexer_->set_identifier (path, $5);
669 $$ = SCM_UNSPECIFIED;
671 | assignment_id ',' property_path '=' identifier_init {
672 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
673 parser->lexer_->set_identifier (path, $5);
674 $$ = SCM_UNSPECIFIED;
680 identifier_init_nonumber
682 | post_event_nofinger post_events
684 $$ = scm_reverse_x ($2, SCM_EOL);
685 if (Music *m = unsmob<Music> ($1))
687 if (m->is_mus_type ("post-event-wrapper"))
689 (scm_list_2 (m->get_property ("elements"),
692 $$ = scm_cons ($1, $$);
695 && scm_is_null (scm_cdr ($$)))
699 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
700 m->set_property ("elements", $$);
701 $$ = m->unprotect ();
706 identifier_init_nonumber:
711 | context_def_spec_block
719 | context_modification
720 | partial_function ETC
722 $$ = MAKE_SYNTAX (partial_music_function, @$,
723 scm_reverse_x ($1, SCM_EOL));
729 MUSIC_FUNCTION function_arglist_partial
731 $$ = scm_acons ($1, $2, SCM_EOL);
733 | EVENT_FUNCTION function_arglist_partial
735 $$ = scm_acons ($1, $2, SCM_EOL);
737 | SCM_FUNCTION function_arglist_partial
739 $$ = scm_acons ($1, $2, SCM_EOL);
741 | OVERRIDE grob_prop_path '='
744 $$ = scm_list_1 (SCM_BOOL_F);
747 (scm_list_3 (Syntax::property_override_function,
748 scm_cdr ($2), scm_car ($2)),
751 | SET context_prop_spec '='
754 $$ = scm_list_1 (SCM_BOOL_F);
757 (scm_list_3 (Syntax::property_set_function,
758 scm_cadr ($2), scm_car ($2)),
761 | MUSIC_FUNCTION EXPECT_SCM function_arglist_optional partial_function
763 $$ = scm_acons ($1, $3, $4);
765 | EVENT_FUNCTION EXPECT_SCM function_arglist_optional partial_function
767 $$ = scm_acons ($1, $3, $4);
769 | SCM_FUNCTION EXPECT_SCM function_arglist_optional partial_function
771 $$ = scm_acons ($1, $3, $4);
773 | OVERRIDE grob_prop_path '=' partial_function
776 $$ = scm_list_1 (SCM_BOOL_F);
779 (scm_list_3 (Syntax::property_override_function,
780 scm_cdr ($2), scm_car ($2)),
783 | SET context_prop_spec '=' partial_function
786 $$ = scm_list_1 (SCM_BOOL_F);
789 (scm_list_3 (Syntax::property_set_function,
790 scm_cadr ($2), scm_car ($2)),
793 | MUSIC_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
795 $$ = scm_acons ($1, $4, $5);
797 | EVENT_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
799 $$ = scm_acons ($1, $4, $5);
801 | SCM_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
803 $$ = scm_acons ($1, $4, $5);
807 context_def_spec_block:
808 CONTEXT '{' context_def_spec_body '}'
811 Context_def *td = unsmob<Context_def> ($$);
813 $$ = Context_def::make_scm ();
814 td = unsmob<Context_def> ($$);
816 td->origin ()->set_spot (@$);
824 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
825 parser->lexer_->push_note_state (nn);
829 parser->lexer_->pop_state ();
835 context_def_spec_body:
837 $$ = SCM_UNSPECIFIED;
839 | context_def_spec_body context_mod {
840 if (!SCM_UNBNDP ($2)) {
841 Context_def *td = unsmob<Context_def> ($$);
843 $$ = Context_def::make_scm ();
844 td = unsmob<Context_def> ($$);
846 unsmob<Context_def> ($$)->add_context_mod ($2);
849 | context_def_spec_body context_modification {
850 Context_def *td = unsmob<Context_def> ($$);
852 $$ = Context_def::make_scm ();
853 td = unsmob<Context_def> ($$);
855 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
856 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
857 td->add_context_mod (scm_car (m));
860 | context_def_spec_body context_mod_arg {
861 Context_def *td = unsmob<Context_def> ($1);
862 if (scm_is_eq ($2, SCM_UNSPECIFIED))
864 else if (!td && unsmob<Context_def> ($2))
868 $$ = Context_def::make_scm ();
869 td = unsmob<Context_def> ($$);
871 if (unsmob<Music> ($2)) {
872 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
873 $2 = scm_call_1 (proc, $2);
875 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
876 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
877 td->add_context_mod (scm_car (m));
880 parser->parser_error (@2, _ ("not a context mod"));
888 BOOK '{' book_body '}' {
890 unsmob<Book> ($$)->origin ()->set_spot (@$);
892 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
897 * Use 'handlers' like for toplevel-* stuff?
898 * grok \layout and \midi? */
901 Book *book = new Book;
902 init_papers (parser);
903 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
904 book->paper_->unprotect ();
905 push_paper (parser, book->paper_);
906 book->header_ = get_header (parser);
907 $$ = book->unprotect ();
908 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
911 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
913 | book_body paper_block {
914 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
915 set_paper (parser, unsmob<Output_def> ($2));
917 | book_body bookpart_block {
918 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
919 scm_call_2 (proc, $1, $2);
921 | book_body score_block {
922 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
923 scm_call_2 (proc, $1, $2);
925 | book_body composite_music {
926 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
927 scm_call_2 (proc, $1, $2);
929 | book_body full_markup {
930 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
931 scm_call_2 (proc, $1, scm_list_1 ($2));
933 | book_body full_markup_list {
934 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
935 scm_call_2 (proc, $1, $2);
937 | book_body SCM_TOKEN {
938 // Evaluate and ignore #xxx, as opposed to \xxx
939 parser->lexer_->eval_scm_token ($2, @2);
941 | book_body embedded_scm_active
943 SCM out = SCM_UNDEFINED;
944 if (Text_interface::is_markup ($2))
945 out = scm_list_1 ($2);
946 else if (Text_interface::is_markup_list ($2))
948 if (scm_is_pair (out))
950 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
951 scm_call_2 (proc, $1, out);
952 } else if (unsmob<Score> ($2))
954 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
955 scm_call_2 (proc, $1, $2);
956 } else if (Output_def *od = unsmob<Output_def> ($2)) {
959 if (to_boolean (od->c_variable ("is-paper")))
960 id = ly_symbol2scm ("$defaultpaper");
961 else if (to_boolean (od->c_variable ("is-midi")))
962 id = ly_symbol2scm ("$defaultmidi");
963 else if (to_boolean (od->c_variable ("is-layout")))
964 id = ly_symbol2scm ("$defaultlayout");
966 parser->lexer_->set_identifier (id, $2);
967 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
968 parser->parser_error (@2, _("bad expression type"));
972 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
975 Book *book = unsmob<Book> ($1);
977 book->scores_ = SCM_EOL;
978 book->bookparts_ = SCM_EOL;
983 BOOKPART '{' bookpart_body '}' {
985 unsmob<Book> ($$)->origin ()->set_spot (@$);
986 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
992 Book *book = new Book;
993 $$ = book->unprotect ();
994 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
997 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
999 | bookpart_body paper_block {
1000 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
1002 | bookpart_body score_block {
1003 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1004 scm_call_2 (proc, $1, $2);
1006 | bookpart_body composite_music {
1007 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
1008 scm_call_2 (proc, $1, $2);
1010 | bookpart_body full_markup {
1011 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1012 scm_call_2 (proc, $1, scm_list_1 ($2));
1014 | bookpart_body full_markup_list {
1015 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1016 scm_call_2 (proc, $1, $2);
1018 | bookpart_body SCM_TOKEN {
1019 // Evaluate and ignore #xxx, as opposed to \xxx
1020 parser->lexer_->eval_scm_token ($2, @2);
1022 | bookpart_body embedded_scm_active
1024 SCM out = SCM_UNDEFINED;
1025 if (Text_interface::is_markup ($2))
1026 out = scm_list_1 ($2);
1027 else if (Text_interface::is_markup_list ($2))
1029 if (scm_is_pair (out))
1031 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1032 scm_call_2 (proc, $1, out);
1033 } else if (unsmob<Score> ($2))
1035 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1036 scm_call_2 (proc, $1, $2);
1037 } else if (Output_def *od = unsmob<Output_def> ($2)) {
1040 if (to_boolean (od->c_variable ("is-paper")))
1041 id = ly_symbol2scm ("$defaultpaper");
1042 else if (to_boolean (od->c_variable ("is-midi")))
1043 id = ly_symbol2scm ("$defaultmidi");
1044 else if (to_boolean (od->c_variable ("is-layout")))
1045 id = ly_symbol2scm ("$defaultlayout");
1047 parser->lexer_->set_identifier (id, $2);
1048 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1049 parser->parser_error (@2, _("bad expression type"));
1053 Book *book = unsmob<Book> ($1);
1054 if (!ly_is_module (book->header_))
1055 book->header_ = ly_make_module (false);
1056 parser->lexer_->add_scope (book->header_);
1058 | bookpart_body error {
1059 Book *book = unsmob<Book> ($1);
1061 book->scores_ = SCM_EOL;
1066 SCORE '{' score_body '}' {
1067 unsmob<Score> ($3)->origin ()->set_spot (@$);
1074 if (!unsmob<Score> ($1)) {
1075 parser->parser_error (@1, _("Missing music in \\score"));
1076 $$ = (new Score)->unprotect ();
1077 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
1079 unsmob<Score> ($$)->set_header (scm_car ($1));
1082 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1083 scm_is_pair (p); p = scm_cdr (p))
1085 unsmob<Score> ($$)->
1086 add_output_def (unsmob<Output_def> (scm_car (p)));
1090 | score_body error {
1091 unsmob<Score> ($$)->error_found_ = true;
1106 | score_items score_item
1108 Output_def *od = unsmob<Output_def> ($2);
1110 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1112 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1114 $2 = SCM_UNSPECIFIED;
1116 } else if (!unsmob<Score> ($$)) {
1117 if (unsmob<Music> ($2)) {
1118 $2 = Lily::scorify_music ($2);
1120 if (unsmob<Score> ($2))
1123 $2 = SCM_UNSPECIFIED;
1126 Score *score = unsmob<Score> ($$);
1127 if (score && scm_is_pair ($1)) {
1128 if (ly_is_module (scm_car ($1)))
1130 score->set_header (scm_car ($1));
1133 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1134 scm_is_pair (p); p = scm_cdr (p))
1136 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1141 score->add_output_def (od);
1142 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1143 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1145 $$ = scm_cons ($2, $$);
1146 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1147 parser->parser_error (@2, _("Spurious expression in \\score"));
1151 if (Score *score = unsmob<Score> ($1)) {
1152 if (!ly_is_module (score->get_header ()))
1153 score->set_header (ly_make_module (false));
1154 parser->lexer_->add_scope (score->get_header ());
1156 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1157 $1 = scm_cons (ly_make_module (false), $1);
1158 parser->lexer_->add_scope (scm_car ($1));
1173 Output_def *od = unsmob<Output_def> ($1);
1175 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1177 parser->parser_error (@1, _ ("need \\paper for paper block"));
1178 $$ = get_paper (parser)->unprotect ();
1185 output_def_body '}' {
1186 if (scm_is_pair ($1))
1189 parser->lexer_->remove_scope ();
1190 parser->lexer_->pop_state ();
1196 Output_def *p = get_paper (parser);
1197 p->input_origin_ = @$;
1198 parser->lexer_->add_scope (p->scope_);
1199 $$ = p->unprotect ();
1202 Output_def *p = get_midi (parser);
1203 $$ = p->unprotect ();
1204 parser->lexer_->add_scope (p->scope_);
1207 Output_def *p = get_layout (parser);
1209 parser->lexer_->add_scope (p->scope_);
1210 $$ = p->unprotect ();
1214 output_def_head_with_mode_switch:
1216 parser->lexer_->push_initial_state ();
1221 // We need this weird nonterminal because both music as well as a
1222 // context definition can start with \context and the difference is
1223 // only apparent after looking at the next token. If it is '{', there
1224 // is still time to escape from notes mode.
1226 music_or_context_def:
1228 | context_def_spec_block
1232 output_def_head_with_mode_switch '{' {
1233 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1234 // This is a stupid trick to mark the beginning of the
1235 // body for deciding whether to allow
1236 // embedded_scm_active to have an output definition
1237 $$ = scm_list_1 ($1);
1239 | output_def_body assignment {
1240 if (scm_is_pair ($1))
1243 | output_def_body embedded_scm_active
1245 // We don't switch into note mode for Scheme functions
1246 // here. Does not seem warranted/required in output
1248 if (scm_is_pair ($1))
1250 Output_def *o = unsmob<Output_def> ($2);
1252 o->input_origin_.set_spot (@$);
1253 $1 = o->self_scm ();
1254 parser->lexer_->remove_scope ();
1255 parser->lexer_->add_scope (o->scope_);
1256 $2 = SCM_UNSPECIFIED;
1260 if (unsmob<Context_def> ($2))
1261 assign_context_def (unsmob<Output_def> ($1), $2);
1262 // Seems unlikely, but let's be complete:
1263 else if (unsmob<Music> ($2))
1265 SCM proc = parser->lexer_->lookup_identifier
1266 ("output-def-music-handler");
1267 scm_call_2 (proc, $1, $2);
1268 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1269 parser->parser_error (@2, _("bad expression type"));
1272 | output_def_body SCM_TOKEN {
1273 if (scm_is_pair ($1))
1275 // Evaluate and ignore #xxx, as opposed to \xxx
1276 parser->lexer_->eval_scm_token ($2, @2);
1280 if (scm_is_pair ($1))
1282 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1283 parser->lexer_->push_note_state (nn);
1284 } music_or_context_def
1286 parser->lexer_->pop_state ();
1287 if (unsmob<Context_def> ($3))
1288 assign_context_def (unsmob<Output_def> ($1), $3);
1291 SCM proc = parser->lexer_->lookup_identifier
1292 ("output-def-music-handler");
1293 scm_call_2 (proc, $1, $3);
1297 | output_def_body error {
1303 TEMPO steno_duration '=' tempo_range {
1304 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1306 | TEMPO text steno_duration '=' tempo_range {
1307 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1310 $$ = MAKE_SYNTAX (tempo, @$, $2);
1315 The representation of a list is reversed to have efficient append. */
1321 | music_list music_embedded {
1322 if (unsmob<Music> ($2))
1323 $$ = scm_cons ($2, $1);
1325 | music_list error {
1326 Music *m = MY_MAKE_MUSIC("Music", @$);
1328 m->set_property ("error-found", SCM_BOOL_T);
1329 $$ = scm_cons (m->self_scm (), $1);
1330 m->unprotect (); /* UGH */
1337 $$ = scm_reverse_x ($2, SCM_EOL);
1342 | lyric_element_music
1349 $$ = make_music_from_simple (parser, @1, $1);
1350 if (!unsmob<Music> ($$))
1352 parser->parser_error (@1, _ ("music expected"));
1353 $$ = MAKE_SYNTAX (void_music, @$);
1361 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1362 parser->parser_error (@1, _ ("unexpected post-event"));
1363 $$ = SCM_UNSPECIFIED;
1366 | music_embedded_backup
1370 | music_embedded_backup BACKUP lyric_element_music
1374 | multiplied_duration post_events
1376 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1378 parser->default_duration_ = *unsmob<Duration> ($1);
1379 n->set_property ("duration", $1);
1381 if (scm_is_pair ($2))
1382 n->set_property ("articulations",
1383 scm_reverse_x ($2, SCM_EOL));
1384 $$ = n->unprotect ();
1388 music_embedded_backup:
1391 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1393 else if (Music *m = unsmob<Music> ($1)) {
1394 if (m->is_mus_type ("post-event")) {
1395 parser->parser_error
1396 (@1, _ ("unexpected post-event"));
1397 $$ = SCM_UNSPECIFIED;
1400 } else if (parser->lexer_->is_lyric_state ()
1401 && Text_interface::is_markup ($1))
1402 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1404 @$.warning (_ ("Ignoring non-music expression"));
1410 // music_assign does not need to contain lyrics: there are no
1411 // assignments in lyricmode.
1414 | composite_music %prec COMPOSITE
1418 REPEAT simple_string unsigned_number music
1420 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1422 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1424 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1429 SEQUENTIAL braced_music_list {
1430 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1432 | braced_music_list {
1433 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1438 SIMULTANEOUS braced_music_list {
1439 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1441 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1442 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1448 | music_property_def
1452 context_modification:
1455 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1456 parser->lexer_->push_note_state (nn);
1457 } '{' context_mod_list '}'
1459 parser->lexer_->pop_state ();
1462 | WITH CONTEXT_MOD_IDENTIFIER
1466 | CONTEXT_MOD_IDENTIFIER
1470 | WITH context_modification_arg
1472 if (unsmob<Music> ($2)) {
1473 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1474 $2 = scm_call_1 (proc, $2);
1476 if (unsmob<Context_mod> ($2))
1479 parser->parser_error (@2, _ ("not a context mod"));
1480 $$ = Context_mod ().smobbed_copy ();
1485 context_modification_arg:
1490 optional_context_mod:
1494 | context_modification
1502 $$ = Context_mod ().smobbed_copy ();
1504 | context_mod_list context_mod {
1505 if (!SCM_UNBNDP ($2))
1506 unsmob<Context_mod> ($1)->add_context_mod ($2);
1508 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1509 Context_mod *md = unsmob<Context_mod> ($2);
1511 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1513 | context_mod_list context_mod_arg {
1514 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1516 else if (unsmob<Music> ($2)) {
1517 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1518 $2 = scm_call_1 (proc, $2);
1520 if (unsmob<Context_mod> ($2))
1521 unsmob<Context_mod> ($$)->add_context_mods
1522 (unsmob<Context_mod> ($2)->get_mods ());
1524 parser->parser_error (@2, _ ("not a context mod"));
1530 CONTEXT symbol optional_id optional_context_mod {
1531 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1534 mods = ctxmod->get_mods ();
1535 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_F);
1537 | NEWCONTEXT symbol optional_id optional_context_mod {
1538 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1541 mods = ctxmod->get_mods ();
1542 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_T);
1547 ADDLYRICS optional_context_mod lyric_mode_music {
1548 Context_mod *ctxmod = unsmob<Context_mod> ($2);
1551 mods = ctxmod->get_mods ();
1552 $$ = scm_acons ($3, mods, SCM_EOL);
1554 | new_lyrics ADDLYRICS optional_context_mod lyric_mode_music {
1555 Context_mod *ctxmod = unsmob<Context_mod> ($3);
1558 mods = ctxmod->get_mods ();
1559 $$ = scm_acons ($4, mods, $1);
1563 /* basic_music is basically the same as composite_music but with
1564 * context-prefixed music and lyricized music explicitly removed. The
1565 * reason is that in a sequence
1567 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1569 * we need to group both \addlyrics together (as they go with the same
1570 * voice) but then combine them with \new Voice { ... }, meaning that
1571 * combining \new Voice { ... } needs higher priority than
1572 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1573 * combine before combining \new Voice { ... } \addlyrics: only one
1574 * layer of context-prefixed music should assemble before \addlyrics
1575 * is integrated. Total mess, and we sort this mess out with explicit
1576 * rules preferring a single context-prefix.
1583 | LYRICSTO simple_string lyric_mode_music {
1584 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1586 | LYRICSTO symbol '=' simple_string lyric_mode_music
1588 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1598 contexted_basic_music:
1599 context_prefix contextable_music new_lyrics
1602 i.set_location (@1, @2);
1603 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1604 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1606 | context_prefix contextable_music
1608 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1610 | context_prefix contexted_basic_music
1612 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1617 basic_music %prec COMPOSITE
1618 | contexted_basic_music
1619 | basic_music new_lyrics
1621 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1628 | grouped_music_list
1632 simultaneous_music { $$ = $1; }
1633 | sequential_music { $$ = $1; }
1636 /* Function argument lists are arguably the most complex part in the
1637 * parser. They are pretty tricky to understand because of the way
1638 * they are processed, and because of optional arguments that can be
1639 * omitted. When there are several optional arguments in a row,
1640 * omitting one automatically omits all following arguments. Optional
1641 * arguments can only be omitted when either
1643 * a) the omission is explicitly started with \default
1644 * b) the omission is implicitly started by an argument not matching
1645 * its predicate, and there is a mandatory argument later that can
1646 * "catch" the argument that does not fit.
1648 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1649 * (corresponding to mandatory arguments and having a predicate
1650 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1651 * the semantic value of the EXPECT_OPTIONAL token is the default to
1652 * use when the optional argument is omitted, and EXPECT_SCM again has
1653 * the argument predicate as semantic value) in reverse order to the
1654 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1655 * processed inside-out while actual tokens are consumed.
1657 * This means that the argument list tokens determine the actions
1658 * taken as they arrive. The structure of the argument list is known
1659 * to the parser and stored in its parse stack when the first argument
1660 * is being parsed. What the parser does not know is which predicates
1661 * will match and whether or not \default will be appearing in the
1662 * argument list, and where.
1664 * Sequences of 0 or more optional arguments are scanned using either
1665 * function_arglist_backup or function_arglist_nonbackup. The first
1666 * is used when optional arguments are followed by at least one
1667 * mandatory argument: in that case optional arguments may be skipped
1668 * by either a false predicate (in which case the expression will be
1669 * pushed back as one or more tokens, preceded by a BACKUP token) or
1670 * by using \default.
1672 * If optional arguments are at the end of the argument list, they are
1673 * instead scanned using function_arglist_nonbackup: here the only
1674 * manner to enter into skipping of optional arguments is the use of
1677 * The argument list of a normal function call is parsed using
1678 * function_arglist. The part of an argument list before a mandatory
1679 * argument is parsed using function_arglist_optional.
1681 * The difference is that leading optional arguments are scanned using
1682 * function_arglist_nonbackup and function_arglist_backup,
1685 * Most other details are obvious in the rules themselves.
1691 | SYMBOL_LIST '.' symbol_list_rev
1693 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1695 | SYMBOL_LIST ',' symbol_list_rev
1697 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1703 | symbol_list_rev '.' symbol_list_part
1705 $$ = scm_append_x (scm_list_2 ($3, $1));
1707 | symbol_list_rev ',' symbol_list_part
1709 $$ = scm_append_x (scm_list_2 ($3, $1));
1713 // symbol_list_part delivers elements in reverse copy.
1718 $$ = try_string_variants (Lily::key_list_p, $1);
1719 if (SCM_UNBNDP ($$)) {
1720 parser->parser_error (@1, _("not a key"));
1723 $$ = scm_reverse ($$);
1728 symbol_list_element:
1735 function_arglist_nonbackup:
1736 function_arglist_common
1737 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1739 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1741 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1743 SCM n = scm_difference ($5, SCM_UNDEFINED);
1744 if (scm_is_true (scm_call_1 ($2, n)))
1745 $$ = scm_cons (n, $3);
1747 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1748 t->set_property ("digit", $5);
1749 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1753 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1755 $$ = check_scheme_arg (parser, @4,
1756 scm_difference ($5, SCM_UNDEFINED),
1759 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1761 $$ = check_scheme_arg (parser, @4,
1762 scm_difference ($5, SCM_UNDEFINED),
1765 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1767 if (scm_is_true (scm_call_1 ($2, $4)))
1768 $$ = scm_cons ($4, $3);
1770 $$ = check_scheme_arg (parser, @4,
1771 make_music_from_simple
1775 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1777 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1779 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1781 if (scm_is_true (scm_call_1 ($2, $3)))
1782 $$ = scm_cons ($3, $1);
1784 $$ = check_scheme_arg (parser, @3,
1785 make_music_from_simple
1789 | function_arglist_nonbackup_reparse REPARSE multiplied_duration
1791 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1793 | function_arglist_nonbackup_reparse REPARSE reparsed_rhythm
1795 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1797 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1799 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1801 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1803 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1805 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1807 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1809 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1811 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1817 DURATION_ARG dots multipliers post_events
1819 $$ = make_music_from_simple (parser, @$,
1820 make_duration ($1, scm_to_int ($2), $3));
1821 Music *m = unsmob<Music> ($$);
1823 if (scm_is_pair ($4))
1824 m->set_property ("articulations",
1825 scm_reverse_x ($4, SCM_EOL));
1829 function_arglist_nonbackup_reparse:
1830 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1833 SCM res = try_string_variants ($2, $4);
1834 if (!SCM_UNBNDP (res))
1835 if (scm_is_pair (res))
1836 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1838 MYREPARSE (@4, $2, SCM_ARG, res);
1839 else if (scm_is_true
1841 ($2, make_music_from_simple
1843 MYREPARSE (@4, $2, STRING, $4);
1845 MYREPARSE (@4, $2, SCM_ARG, $4);
1847 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1852 ($2, make_music_from_simple
1854 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1856 MYREPARSE (@4, $2, SCM_ARG, $4);
1858 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1863 ($2, make_music_from_simple
1865 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1867 MYREPARSE (@4, $2, SCM_ARG, $4);
1869 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1872 SCM res = try_string_variants ($2, $4);
1873 if (!SCM_UNBNDP (res))
1874 if (scm_is_pair (res))
1875 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1877 MYREPARSE (@4, $2, SCM_ARG, res);
1878 else if (scm_is_true
1880 ($2, make_music_from_simple
1882 MYREPARSE (@4, $2, STRING, $4);
1884 MYREPARSE (@4, $2, SCM_ARG, $4);
1886 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1889 if (scm_is_true (scm_call_1 ($2, $4)))
1890 MYREPARSE (@4, $2, SCM_ARG, $4);
1891 else if (scm_is_true
1893 ($2, make_music_from_simple
1895 MYREPARSE (@4, $2, STRING, $4);
1897 MYREPARSE (@4, $2, SCM_ARG, $4);
1899 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1902 if (scm_is_true (scm_call_1 ($2, $4)))
1903 // May be 3 \cm or similar
1904 MYREPARSE (@4, $2, REAL, $4);
1906 SCM d = make_duration ($4);
1907 if (!SCM_UNBNDP (d)) {
1908 if (scm_is_true (scm_call_1 ($2, d)))
1909 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1910 else if (scm_is_true
1912 ($2, make_music_from_simple (parser, @4, d))))
1913 MYREPARSE (@4, $2, DURATION_ARG, d);
1915 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1917 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1920 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER
1923 if (scm_is_true (scm_call_1 ($2, $4)))
1924 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1925 else if (scm_is_true
1927 ($2, make_music_from_simple (parser, @4, $4))))
1928 MYREPARSE (@4, $2, DURATION_ARG, $4);
1930 MYREPARSE (@4, $2, SCM_ARG, $4); // trigger error
1935 // function_arglist_backup can't occur at the end of an argument
1937 function_arglist_backup:
1938 function_arglist_common
1939 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1941 if (scm_is_true (scm_call_1 ($2, $4)))
1942 $$ = scm_cons ($4, $3);
1944 $$ = make_music_from_simple (parser, @4, $4);
1945 if (scm_is_true (scm_call_1 ($2, $$)))
1946 $$ = scm_cons ($$, $3);
1949 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1950 MYBACKUP (SCM_ARG, $4, @4);
1954 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1956 if (scm_is_true (scm_call_1 ($2, $4)))
1958 $$ = scm_cons ($4, $3);
1960 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1961 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1964 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1968 ($2, make_music_from_simple
1972 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1973 } else if (scm_is_true (scm_call_1 ($2, $4)))
1974 $$ = scm_cons ($4, $3);
1976 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1977 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1980 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1984 ($2, make_music_from_simple
1988 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1989 } else 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 (TONICNAME_PITCH, $4, @4);
1996 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1998 if (scm_is_true (scm_call_1 ($2, $4)))
1999 $$ = scm_cons ($4, $3);
2001 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2002 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2005 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
2008 if (scm_is_true (scm_call_1 ($2, $4)))
2009 // May be 3 \cm or similar
2010 MYREPARSE (@4, $2, REAL, $4);
2012 SCM d = make_duration ($4);
2013 if (!SCM_UNBNDP (d)) {
2014 if (scm_is_true (scm_call_1 ($2, d)))
2015 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
2016 else if (scm_is_true
2018 ($2, make_music_from_simple (parser, @4, d))))
2019 MYREPARSE (@4, $2, DURATION_ARG, d);
2021 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2022 MYBACKUP (UNSIGNED, $4, @4);
2025 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2026 MYBACKUP (UNSIGNED, $4, @4);
2030 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
2032 if (scm_is_true (scm_call_1 ($2, $4)))
2035 MYREPARSE (@4, $2, REAL, $4);
2037 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2038 MYBACKUP (REAL, $4, @4);
2041 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
2043 if (scm_is_true (scm_call_1 ($2, $4)))
2045 $$ = scm_cons ($4, $3);
2047 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2048 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
2051 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
2053 SCM n = scm_difference ($5, SCM_UNDEFINED);
2054 if (scm_is_true (scm_call_1 ($2, n))) {
2056 MYREPARSE (@5, $2, REAL, n);
2058 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
2059 t->set_property ("digit", $5);
2060 $$ = t->unprotect ();
2061 if (scm_is_true (scm_call_1 ($2, $$)))
2062 $$ = scm_cons ($$, $3);
2064 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2065 MYBACKUP (UNSIGNED, $5, @5);
2066 parser->lexer_->push_extra_token (@4, '-');
2070 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2072 SCM n = scm_difference ($5, SCM_UNDEFINED);
2073 if (scm_is_true (scm_call_1 ($2, n))) {
2074 MYREPARSE (@5, $2, REAL, n);
2077 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2078 MYBACKUP (REAL, n, @5);
2081 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2083 SCM n = scm_difference ($5, SCM_UNDEFINED);
2084 if (scm_is_true (scm_call_1 ($2, n))) {
2085 $$ = scm_cons (n, $3);
2087 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2088 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2091 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2094 if (scm_is_true (scm_call_1 ($2, $4)))
2095 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2096 else if (scm_is_true
2098 ($2, make_music_from_simple (parser, @4, $4))))
2099 MYREPARSE (@4, $2, DURATION_ARG, $4);
2101 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2102 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2105 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2107 SCM res = try_string_variants ($2, $4);
2108 if (!SCM_UNBNDP (res))
2109 if (scm_is_pair (res)) {
2111 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2114 $$ = scm_cons (res, $3);
2116 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2117 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2120 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2122 SCM res = try_string_variants ($2, $4);
2123 if (!SCM_UNBNDP (res))
2124 if (scm_is_pair (res)) {
2126 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2129 $$ = scm_cons (res, $3);
2131 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2132 MYBACKUP (STRING, $4, @4);
2135 | function_arglist_backup REPARSE pitch_or_music
2137 if (scm_is_true (scm_call_1 ($2, $3)))
2138 $$ = scm_cons ($3, $1);
2140 $$ = check_scheme_arg (parser, @3,
2141 make_music_from_simple
2145 | function_arglist_backup REPARSE bare_number_common
2147 $$ = check_scheme_arg (parser, @3,
2150 | function_arglist_backup REPARSE multiplied_duration
2152 $$ = check_scheme_arg (parser, @3,
2155 | function_arglist_backup REPARSE reparsed_rhythm
2157 $$ = check_scheme_arg (parser, @3,
2160 | function_arglist_backup REPARSE symbol_list_arg
2162 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2167 function_arglist_nonbackup
2168 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2170 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2174 function_arglist_skip_nonbackup:
2175 function_arglist_nonbackup
2176 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2178 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2182 // Partial function arglists are returned just in their incomplete
2183 // state: when combined with the music function, the missing parts of
2184 // the signature can be reconstructed
2186 // To serve as a partial arglist, the argument list must absolutely
2187 // _not_ be in "skipping optional arguments" mode since then there is
2188 // some backup token that has nowhere to go before \etc.
2190 // So we can skim off an arbitrary number of arguments from the end of
2191 // the argument list. The argument list remaining afterwards has to
2192 // be in not-skipping-optional-arguments mode.
2194 function_arglist_partial:
2195 EXPECT_SCM function_arglist_optional
2199 | EXPECT_SCM function_arglist_partial_optional
2203 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2207 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2213 function_arglist_partial_optional:
2214 EXPECT_SCM function_arglist_optional
2218 | EXPECT_SCM function_arglist_partial_optional
2222 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2226 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2232 function_arglist_common:
2233 EXPECT_NO_MORE_ARGS {
2236 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2238 if (scm_is_true (scm_call_1 ($1, $3)))
2239 $$ = scm_cons ($3, $2);
2241 $$ = check_scheme_arg (parser, @3,
2242 make_music_from_simple
2246 | EXPECT_SCM function_arglist_optional bare_number_common
2248 $$ = check_scheme_arg (parser, @3,
2251 | EXPECT_SCM function_arglist_optional post_event_nofinger
2253 $$ = check_scheme_arg (parser, @3,
2256 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2258 SCM n = scm_difference ($4, SCM_UNDEFINED);
2259 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2261 | function_arglist_common_reparse REPARSE SCM_ARG
2263 $$ = check_scheme_arg (parser, @3,
2266 | function_arglist_common_reparse REPARSE lyric_element_music
2268 $$ = check_scheme_arg (parser, @3,
2271 | function_arglist_common_reparse REPARSE pitch_or_music
2273 if (scm_is_true (scm_call_1 ($2, $3)))
2274 $$ = scm_cons ($3, $1);
2276 $$ = check_scheme_arg (parser, @3,
2277 make_music_from_simple
2281 | function_arglist_common_reparse REPARSE bare_number_common
2283 $$ = check_scheme_arg (parser, @3,
2286 | function_arglist_common_reparse REPARSE multiplied_duration
2288 $$ = check_scheme_arg (parser, @3,
2291 | function_arglist_common_reparse REPARSE reparsed_rhythm
2293 $$ = check_scheme_arg (parser, @3,
2296 | function_arglist_common_reparse REPARSE symbol_list_arg
2298 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2302 function_arglist_common_reparse:
2303 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2306 SCM res = try_string_variants ($1, $3);
2307 if (!SCM_UNBNDP (res))
2308 if (scm_is_pair (res))
2309 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2311 MYREPARSE (@3, $1, SCM_ARG, res);
2312 else if (scm_is_true
2314 ($1, make_music_from_simple (parser, @3, $3))))
2315 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2317 // This is going to flag a syntax error, we
2318 // know the predicate to be false.
2319 MYREPARSE (@3, $1, SCM_ARG, $3);
2321 | EXPECT_SCM function_arglist_optional pitch
2326 ($1, make_music_from_simple
2328 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2330 MYREPARSE (@3, $1, SCM_ARG, $3);
2332 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2337 ($1, make_music_from_simple
2339 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2341 MYREPARSE (@3, $1, SCM_ARG, $3);
2343 | EXPECT_SCM function_arglist_optional STRING
2346 SCM res = try_string_variants ($1, $3);
2347 if (!SCM_UNBNDP (res))
2348 if (scm_is_pair (res))
2349 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2351 MYREPARSE (@3, $1, SCM_ARG, res);
2352 else if (scm_is_true
2354 ($1, make_music_from_simple (parser, @3, $3))))
2355 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2357 // This is going to flag a syntax error, we
2358 // know the predicate to be false.
2359 MYREPARSE (@3, $1, SCM_ARG, $3);
2361 | EXPECT_SCM function_arglist_optional full_markup
2364 if (scm_is_true (scm_call_1 ($1, $3)))
2365 MYREPARSE (@3, $1, SCM_ARG, $3);
2366 else if (scm_is_true
2368 ($1, make_music_from_simple (parser, @3, $3))))
2369 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2371 // This is going to flag a syntax error, we
2372 // know the predicate to be false.
2373 MYREPARSE (@3, $1, SCM_ARG, $3);
2375 | EXPECT_SCM function_arglist_optional UNSIGNED
2378 if (scm_is_true (scm_call_1 ($1, $3)))
2379 // May be 3 \cm or similar
2380 MYREPARSE (@3, $1, REAL, $3);
2382 SCM d = make_duration ($3);
2383 if (!SCM_UNBNDP (d)) {
2384 if (scm_is_true (scm_call_1 ($1, d)))
2385 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2386 else if (scm_is_true
2388 ($1, make_music_from_simple (parser, @3, d))))
2389 MYREPARSE (@3, $1, DURATION_ARG, d);
2391 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2393 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2396 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2399 if (scm_is_true (scm_call_1 ($1, $3)))
2400 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2401 else if (scm_is_true
2403 ($1, make_music_from_simple (parser, @3, $3))))
2404 MYREPARSE (@3, $1, DURATION_ARG, $3);
2406 MYREPARSE (@3, $1, SCM_ARG, $3); // trigger error
2408 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2411 SCM n = scm_difference ($4, SCM_UNDEFINED);
2412 if (scm_is_true (scm_call_1 ($1, n)))
2413 MYREPARSE (@4, $1, REAL, n);
2415 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2416 t->set_property ("digit", $4);
2417 SCM m = t->unprotect ();
2418 if (scm_is_true (scm_call_1 ($1, m)))
2419 MYREPARSE (@4, $1, SCM_ARG, m);
2421 MYREPARSE (@4, $1, SCM_ARG, $4);
2424 | EXPECT_SCM function_arglist_optional '-' REAL
2427 SCM n = scm_difference ($4, SCM_UNDEFINED);
2428 MYREPARSE (@4, $1, REAL, n);
2432 function_arglist_optional:
2433 function_arglist_backup
2434 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2436 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2438 | function_arglist_skip_backup BACKUP
2441 function_arglist_skip_backup:
2442 function_arglist_backup
2443 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2445 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2449 music_function_call:
2450 MUSIC_FUNCTION function_arglist {
2451 $$ = MAKE_SYNTAX (music_function, @$,
2458 /**/ { $$ = SCM_EOL; }
2459 | '=' simple_string {
2464 // We must not have lookahead tokens parsed in lyric mode. In order
2465 // to save confusion, we take almost the same set as permitted with
2466 // \lyricmode and/or \lyrics. However, music identifiers are also
2467 // allowed, and they obviously do not require switching into lyrics
2468 // mode for parsing.
2472 parser->lexer_->push_lyric_state ();
2473 } grouped_music_list
2475 parser->lexer_->pop_state ();
2482 mode_changing_head grouped_music_list {
2483 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2485 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2491 parser->lexer_->pop_state ();
2493 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2494 Context_mod *ctxmod = unsmob<Context_mod> ($2);
2497 mods = ctxmod->get_mods ();
2498 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2499 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2501 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2503 parser->lexer_->pop_state ();
2509 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2510 parser->lexer_->push_note_state (nn);
2512 $$ = ly_symbol2scm ("notes");
2516 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2517 parser->lexer_->push_note_state (nn);
2519 $$ = ly_symbol2scm ("drums");
2522 parser->lexer_->push_figuredbass_state ();
2524 $$ = ly_symbol2scm ("figures");
2527 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2528 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2529 nn = parser->lexer_->lookup_identifier ("pitchnames");
2530 parser->lexer_->push_chord_state (nn);
2531 $$ = ly_symbol2scm ("chords");
2535 { parser->lexer_->push_lyric_state ();
2536 $$ = ly_symbol2scm ("lyrics");
2540 mode_changing_head_with_context:
2542 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2543 parser->lexer_->push_note_state (nn);
2545 $$ = ly_symbol2scm ("DrumStaff");
2548 parser->lexer_->push_figuredbass_state ();
2550 $$ = ly_symbol2scm ("FiguredBass");
2553 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2554 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2555 nn = parser->lexer_->lookup_identifier ("pitchnames");
2556 parser->lexer_->push_chord_state (nn);
2557 $$ = ly_symbol2scm ("ChordNames");
2560 { parser->lexer_->push_lyric_state ();
2561 $$ = ly_symbol2scm ("Lyrics");
2566 CHANGE symbol '=' simple_string {
2567 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2574 $$ = scm_reverse_x ($1, SCM_EOL);
2576 | symbol_list_rev property_path {
2577 $$ = scm_reverse_x ($1, $2);
2583 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2586 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2588 | OVERRIDE property_path '=' scalar {
2589 if (scm_ilength ($2) < 2) {
2590 parser->parser_error (@2, _("bad grob property path"));
2593 $$ = scm_cons (ly_symbol2scm ("push"),
2594 scm_cons2 (scm_car ($2),
2599 | REVERT revert_arg {
2600 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2604 // This is all quite awkward for the sake of substantial backward
2605 // compatibility while at the same time allowing a more "natural" form
2606 // of specification not separating grob specification from grob
2607 // property path. The purpose of this definition of revert_arg is to
2608 // allow the symbol list which specifies grob and property to revert
2609 // to be optionally be split into two parts after the grob (which in
2610 // this case is just the first element of the list). symbol_list_part
2611 // is only one path component, but it can be parsed without lookahead,
2612 // so we can follow it with a synthetic BACKUP token when needed. If
2613 // the first symbol_list_part already contains multiple elements (only
2614 // possible if a Scheme expression provides them), we just parse for
2615 // additional elements introduced by '.', which is what the
2616 // SYMBOL_LIST backup in connection with the immediately following
2617 // rule using symbol_list_arg does.
2619 // As long as we don't have our coffers filled with both grob and at
2620 // least one grob property specification, the rest of the required
2621 // symbol list chain may be provided either with or without a leading
2622 // dot. This is for both allowing the traditional
2623 // \revert Accidental #'color
2624 // as well as well as the "naive" form
2625 // \revert Accidental.color
2628 revert_arg_backup BACKUP symbol_list_arg
2637 if (scm_is_null ($1)
2638 || scm_is_null (scm_cdr ($1)))
2639 MYBACKUP (SCM_ARG, $1, @1);
2641 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2645 // revert_arg_part delivers results in reverse
2648 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2650 $$ = scm_append_x (scm_list_2 ($5, $3));
2652 | revert_arg_backup BACKUP SCM_ARG ',' symbol_list_part
2654 $$ = scm_append_x (scm_list_2 ($5, $3));
2656 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2658 $$ = scm_append_x (scm_list_2 ($4, $3));
2663 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2664 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2666 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2667 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2668 | DENIES { $$ = ly_symbol2scm ("denies"); }
2670 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2671 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2672 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2673 | NAME { $$ = ly_symbol2scm ("context-name"); }
2677 property_operation { $$ = $1; }
2678 | context_def_mod STRING {
2679 $$ = scm_list_2 ($1, $2);
2681 | context_def_mod embedded_scm
2683 if (!scm_is_string ($2)
2684 && ly_symbol2scm ("consists") != $1
2685 && ly_symbol2scm ("remove") != $1)
2688 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2692 $$ = scm_list_2 ($1, $2);
2697 // If defined, at least two members.
2701 SCM l = scm_reverse_x ($1, SCM_EOL);
2704 (scm_object_property (scm_car (l),
2705 ly_symbol2scm ("is-grob?"))))
2706 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2707 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2708 parser->parser_error (@1, _ ("bad grob property path"));
2715 // If defined, at least three members
2719 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2721 parser->parser_error (@1, _ ("bad grob property path"));
2725 | grob_prop_spec property_path
2727 if (!SCM_UNBNDP ($1)) {
2728 $$ = scm_append_x (scm_list_2 ($1, $2));
2729 if (scm_is_null (scm_cddr ($$))) {
2730 parser->parser_error (@$, _ ("bad grob property path"));
2738 // Exactly two elements or undefined
2742 SCM l = scm_reverse_x ($1, SCM_EOL);
2743 switch (scm_ilength (l)) {
2745 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2749 parser->parser_error (@1, _ ("bad context property path"));
2757 // This is all quite awkward for the sake of substantial backward
2758 // compatibility while at the same time allowing a more "natural" form
2759 // of specification not separating grob specification from grob
2760 // property path. The purpose of this definition of
2761 // simple_revert_context is to allow the symbol list which specifies
2762 // grob and property to revert to be optionally be split into two
2763 // parts after the grob (which may be preceded by a context
2764 // specification, a case which we distinguish by checking whether the
2765 // first symbol is a valid grob symbol instead).
2767 // See revert_arg above for the main work horse of this arrangement.
2768 // simple_revert_context just caters for the context and delegates the
2769 // rest of the job to revert_arg.
2771 simple_revert_context:
2774 $1 = scm_reverse_x ($1, SCM_EOL);
2775 if (scm_is_null ($1)
2777 (scm_object_property (scm_car ($1),
2778 ly_symbol2scm ("is-grob?")))) {
2779 $$ = ly_symbol2scm ("Bottom");
2780 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2783 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2790 OVERRIDE grob_prop_path '=' scalar {
2791 if (SCM_UNBNDP ($2))
2792 $$ = MAKE_SYNTAX (void_music, @$);
2794 $$ = MAKE_SYNTAX (property_override, @$,
2799 | REVERT simple_revert_context revert_arg {
2800 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2802 | SET context_prop_spec '=' scalar {
2803 if (SCM_UNBNDP ($2))
2804 $$ = MAKE_SYNTAX (void_music, @$);
2806 $$ = MAKE_SYNTAX (property_set, @$,
2811 | UNSET context_prop_spec {
2812 if (SCM_UNBNDP ($2))
2813 $$ = MAKE_SYNTAX (void_music, @$);
2815 $$ = MAKE_SYNTAX (property_unset, @$,
2831 if (Text_interface::is_markup ($1)) {
2834 parser->parser_error (@1, (_ ("markup expected")));
2835 $$ = scm_string (SCM_EOL);
2840 simple_string: STRING
2843 if (scm_is_string ($1)) {
2846 parser->parser_error (@1, (_ ("simple string expected")));
2847 $$ = scm_string (SCM_EOL);
2854 $$ = scm_string_to_symbol ($1);
2858 // This is a bit of overkill but makes the same
2859 // routine responsible for all symbol interpretations.
2860 $$ = try_string_variants (Guile_user::symbol_p, $1);
2861 if (SCM_UNBNDP ($$))
2863 parser->parser_error (@1, (_ ("symbol expected")));
2864 // Generate a unique symbol in case it is used
2865 // for an assignment or similar
2866 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2876 // The following is a rather defensive variant of admitting
2877 // negative numbers: the grammar would permit number_factor or
2878 // even number_expression. However, function arguments allow
2879 // only this simple kind of negative number, so to have things
2880 // like \tweak and \override behave reasonably similar, it
2881 // makes sense to rule out things like -- which are rather an
2882 // accent in function argument contexts.
2885 $$ = scm_difference ($2, SCM_UNDEFINED);
2891 simple_element post_events {
2892 // Let the rhythmic music iterator sort this mess out.
2893 if (scm_is_pair ($2)) {
2894 unsmob<Music> ($$)->set_property ("articulations",
2895 scm_reverse_x ($2, SCM_EOL));
2898 | CHORD_REPETITION optional_notemode_duration post_events {
2900 i.set_location (@1, @3);
2901 $$ = MAKE_SYNTAX (repetition_chord, i,
2902 $2, scm_reverse_x ($3, SCM_EOL));
2904 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2906 i.set_location (@1, @3);
2907 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2908 scm_reverse_x ($3, SCM_EOL));
2911 | note_chord_element
2916 chord_body optional_notemode_duration post_events
2918 Music *m = unsmob<Music> ($1);
2919 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2920 SCM es = m->get_property ("elements");
2921 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2923 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2924 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2925 es = ly_append2 (es, postevs);
2927 m->set_property ("elements", es);
2928 m->set_spot (parser->lexer_->override_input (@$));
2929 $$ = m->self_scm ();
2934 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2936 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2938 | FIGURE_OPEN figure_list FIGURE_CLOSE
2940 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2944 chord_body_elements:
2945 /* empty */ { $$ = SCM_EOL; }
2946 | chord_body_elements chord_body_element {
2947 if (!SCM_UNBNDP ($2))
2948 $$ = scm_cons ($2, $1);
2953 pitch_or_tonic_pitch exclamations questions octave_check post_events
2955 bool q = to_boolean ($3);
2956 bool ex = to_boolean ($2);
2960 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2961 n->set_property ("pitch", $1);
2963 n->set_property ("cautionary", SCM_BOOL_T);
2965 n->set_property ("force-accidental", SCM_BOOL_T);
2967 if (scm_is_pair (post)) {
2968 SCM arts = scm_reverse_x (post, SCM_EOL);
2969 n->set_property ("articulations", arts);
2971 if (scm_is_number (check))
2973 int q = scm_to_int (check);
2974 n->set_property ("absolute-octave", scm_from_int (q-1));
2977 $$ = n->unprotect ();
2979 | DRUM_PITCH post_events {
2980 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2981 n->set_property ("drum-type", $1);
2983 if (scm_is_pair ($2)) {
2984 SCM arts = scm_reverse_x ($2, SCM_EOL);
2985 n->set_property ("articulations", arts);
2987 $$ = n->unprotect ();
2989 | music_function_chord_body
2991 Music *m = unsmob<Music> ($1);
2993 while (m && m->is_mus_type ("music-wrapper-music")) {
2994 $$ = m->get_property ("element");
2995 m = unsmob<Music> ($$);
2998 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2999 parser->parser_error (@$, _ ("not a rhythmic event"));
3005 music_function_chord_body:
3011 event_function_event:
3012 EVENT_FUNCTION function_arglist {
3013 $$ = MAKE_SYNTAX (music_function, @$,
3022 | post_events post_event {
3024 if (Music *m = unsmob<Music> ($2))
3026 if (m->is_mus_type ("post-event-wrapper"))
3028 for (SCM p = m->get_property ("elements");
3032 $$ = scm_cons (scm_car (p), $$);
3035 m->set_spot (parser->lexer_->override_input (@2));
3036 $$ = scm_cons ($2, $$);
3042 post_event_nofinger:
3043 direction_less_event {
3046 | script_dir music_function_call {
3048 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
3049 parser->parser_error (@2, _ ("post-event expected"));
3050 $$ = SCM_UNSPECIFIED;
3051 } else if (!SCM_UNBNDP ($1))
3053 unsmob<Music> ($$)->set_property ("direction", $1);
3057 if (!parser->lexer_->is_lyric_state ())
3058 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3059 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
3062 if (!parser->lexer_->is_lyric_state ())
3063 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3064 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
3066 | script_dir direction_reqd_event {
3067 if (!SCM_UNBNDP ($1))
3069 Music *m = unsmob<Music> ($2);
3070 m->set_property ("direction", $1);
3074 | script_dir direction_less_event {
3075 if (!SCM_UNBNDP ($1))
3077 Music *m = unsmob<Music> ($2);
3078 m->set_property ("direction", $1);
3085 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
3090 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
3101 string_number_event:
3103 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3104 s->set_property ("string-number", $1);
3105 $$ = s->unprotect ();
3109 direction_less_event:
3111 | EVENT_IDENTIFIER {
3115 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3116 a->set_property ("tremolo-type", $1);
3117 $$ = a->unprotect ();
3119 | event_function_event
3122 direction_reqd_event:
3126 | script_abbreviation {
3127 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3128 if (scm_is_string (s)) {
3129 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3130 a->set_property ("articulation-type", s);
3131 $$ = a->unprotect ();
3133 Music *original = unsmob<Music> (s);
3134 if (original && original->is_mus_type ("post-event")) {
3135 Music *a = original->clone ();
3136 a->set_spot (parser->lexer_->override_input (@$));
3137 $$ = a->unprotect ();
3139 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3140 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3147 /**/ { $$ = SCM_EOL; }
3148 | '=' quotes { $$ = $2; }
3162 $$ = scm_from_int (1);
3165 $$ = scm_oneplus ($1);
3171 $$ = scm_from_int (-1);
3174 $$ = scm_oneminus ($1);
3179 NOTENAME_PITCH quotes {
3180 if (!scm_is_eq (SCM_INUM0, $2))
3182 Pitch p = *unsmob<Pitch> ($1);
3183 p = p.transposed (Pitch (scm_to_int ($2), 0));
3184 $$ = p.smobbed_copy ();
3194 TONICNAME_PITCH quotes {
3195 if (!scm_is_eq (SCM_INUM0, $2))
3197 Pitch p = *unsmob<Pitch> ($1);
3198 p = p.transposed (Pitch (scm_to_int ($2), 0));
3199 $$ = p.smobbed_copy ();
3206 | PITCH_IDENTIFIER quotes {
3207 if (!scm_is_eq (SCM_INUM0, $2))
3209 Pitch p = *unsmob<Pitch> ($1);
3210 p = p.transposed (Pitch (scm_to_int ($2), 0));
3211 $$ = p.smobbed_copy ();
3216 pitch_or_tonic_pitch:
3223 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3224 t->set_property ("text", $1);
3225 $$ = t->unprotect ();
3228 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3229 t->set_property ("text",
3230 make_simple_markup ($1));
3231 $$ = t->unprotect ();
3235 Music *m = unsmob<Music> ($1);
3236 if (m && m->is_mus_type ("post-event"))
3238 else if (Text_interface::is_markup ($1)) {
3239 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3240 t->set_property ("text", $1);
3241 $$ = t->unprotect ();
3243 parser->parser_error (@1, _ ("not an articulation"));
3249 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3250 t->set_property ("digit", $1);
3251 $$ = t->unprotect ();
3255 script_abbreviation:
3257 $$ = scm_from_ascii_string ("Hat");
3260 $$ = scm_from_ascii_string ("Plus");
3263 $$ = scm_from_ascii_string ("Dash");
3266 $$ = scm_from_ascii_string ("Bang");
3269 $$ = scm_from_ascii_string ("Larger");
3272 $$ = scm_from_ascii_string ("Dot");
3275 $$ = scm_from_ascii_string ("Underscore");
3280 '_' { $$ = scm_from_int (DOWN); }
3281 | '^' { $$ = scm_from_int (UP); }
3282 | '-' { $$ = SCM_UNDEFINED; }
3285 maybe_notemode_duration:
3289 | multiplied_duration {
3291 parser->default_duration_ = *unsmob<Duration> ($$);
3296 optional_notemode_duration:
3297 maybe_notemode_duration
3299 if (SCM_UNBNDP ($$))
3300 $$ = parser->default_duration_.smobbed_copy ();
3306 $$ = make_duration ($1, scm_to_int ($2));
3307 if (SCM_UNBNDP ($$))
3309 parser->parser_error (@1, _ ("not a duration"));
3310 $$ = Duration ().smobbed_copy ();
3313 | DURATION_IDENTIFIER dots {
3314 $$ = make_duration ($1, scm_to_int ($2));
3318 multiplied_duration:
3319 steno_duration multipliers {
3320 $$ = make_duration ($1, 0, $2);
3329 $$ = scm_oneplus ($1);
3338 | multipliers '*' UNSIGNED
3340 if (!SCM_UNBNDP ($1))
3341 $$ = scm_product ($1, $3);
3345 | multipliers '*' FRACTION
3347 if (!SCM_UNBNDP ($1))
3348 $$ = scm_product ($1, scm_divide (scm_car ($3),
3351 $$ = scm_divide (scm_car ($3), scm_cdr ($3));
3357 $$ = scm_from_int (parser->default_tremolo_type_);
3360 if (SCM_UNBNDP (make_duration ($2))) {
3361 parser->parser_error (@2, _ ("not a duration"));
3362 $$ = scm_from_int (parser->default_tremolo_type_);
3365 parser->default_tremolo_type_ = scm_to_int ($2);
3371 UNSIGNED { $$ = $1; }
3372 | STRING { $$ = $1; }
3373 | full_markup { $$ = $1; }
3376 // as an integer, it needs to be non-negative, and otherwise
3377 // it needs to be suitable as a markup.
3378 if (scm_is_integer ($1)
3379 ? scm_is_true (scm_negative_p ($1))
3380 : !Text_interface::is_markup ($1))
3382 parser->parser_error (@1, _ ("bass number expected"));
3388 figured_bass_alteration:
3389 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3390 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3391 | '!' { $$ = scm_from_int (0); }
3396 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3397 $$ = bfr->unprotect ();
3400 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3401 $$ = bfr->self_scm ();
3403 if (scm_is_number ($1))
3404 bfr->set_property ("figure", $1);
3405 else if (Text_interface::is_markup ($1))
3406 bfr->set_property ("text", $1);
3412 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3414 | bass_figure figured_bass_alteration {
3415 Music *m = unsmob<Music> ($1);
3416 if (scm_to_double ($2)) {
3417 SCM salter = m->get_property ("alteration");
3418 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3419 m->set_property ("alteration",
3420 scm_sum (alter, $2));
3422 m->set_property ("alteration", scm_from_int (0));
3425 | bass_figure figured_bass_modification {
3426 Music *m = unsmob<Music> ($1);
3427 m->set_property ($2, SCM_BOOL_T);
3432 figured_bass_modification:
3434 $$ = ly_symbol2scm ("augmented");
3437 $$ = ly_symbol2scm ("no-continuation");
3440 $$ = ly_symbol2scm ("diminished");
3443 $$ = ly_symbol2scm ("augmented-slash");
3453 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3461 | figure_list br_bass_figure {
3462 $$ = scm_cons ($2, $1);
3467 /**/ { $$ = SCM_BOOL_F; }
3468 | REST { $$ = SCM_BOOL_T; }
3472 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3473 if (!parser->lexer_->is_note_state ())
3474 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3475 if (!SCM_UNBNDP ($2)
3477 || scm_is_number ($4)
3480 || scm_is_pair ($7))
3483 if (scm_is_true ($6))
3484 n = MY_MAKE_MUSIC ("RestEvent", @$);
3486 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3488 n->set_property ("pitch", $1);
3489 if (SCM_UNBNDP ($5))
3490 n->set_property ("duration",
3491 parser->default_duration_.smobbed_copy ());
3493 n->set_property ("duration", $5);
3495 if (scm_is_number ($4))
3497 int q = scm_to_int ($4);
3498 n->set_property ("absolute-octave", scm_from_int (q-1));
3501 if (to_boolean ($3))
3502 n->set_property ("cautionary", SCM_BOOL_T);
3503 if (to_boolean ($2) || to_boolean ($3))
3504 n->set_property ("force-accidental", SCM_BOOL_T);
3505 if (scm_is_pair ($7))
3506 n->set_property ("articulations",
3507 scm_reverse_x ($7, SCM_EOL));
3508 $$ = n->unprotect ();
3511 | new_chord post_events {
3512 if (!parser->lexer_->is_chord_state ())
3513 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3514 if (scm_is_pair ($2)) {
3515 if (unsmob<Pitch> ($1))
3516 $1 = make_chord_elements (@1,
3518 parser->default_duration_.smobbed_copy (),
3521 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3523 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3524 } else if (!unsmob<Pitch> ($1))
3525 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3526 // A mere pitch drops through.
3531 DRUM_PITCH optional_notemode_duration {
3532 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3533 n->set_property ("duration", $2);
3534 n->set_property ("drum-type", $1);
3536 $$ = n->unprotect ();
3538 | RESTNAME optional_notemode_duration {
3540 if (ly_scm2string ($1) == "s") {
3542 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3545 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3548 ev->set_property ("duration", $2);
3549 $$ = ev->unprotect ();
3555 if (!parser->lexer_->is_lyric_state ())
3556 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3560 if (!parser->lexer_->is_lyric_state ())
3561 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3567 lyric_element_music:
3568 lyric_element optional_notemode_duration post_events {
3569 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3570 if (scm_is_pair ($3))
3571 unsmob<Music> ($$)->set_property
3572 ("articulations", scm_reverse_x ($3, SCM_EOL));
3576 // Can return a single pitch rather than a list.
3578 steno_tonic_pitch maybe_notemode_duration {
3579 if (SCM_UNBNDP ($2))
3582 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3584 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3585 SCM its = scm_reverse_x ($4, SCM_EOL);
3586 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3594 | chord_items chord_item {
3595 $$ = scm_cons ($2, $$);
3601 $$ = ly_symbol2scm ("chord-colon");
3604 $$ = ly_symbol2scm ("chord-caret");
3606 | CHORD_SLASH steno_tonic_pitch {
3607 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3609 | CHORD_BASS steno_tonic_pitch {
3610 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3619 $$ = scm_reverse_x ($1, SCM_EOL);
3627 step_number { $$ = scm_cons ($1, SCM_EOL); }
3628 | step_numbers '.' step_number {
3629 $$ = scm_cons ($3, $$);
3635 $$ = make_chord_step ($1, 0);
3638 $$ = make_chord_step ($1, SHARP_ALTERATION);
3640 | UNSIGNED CHORD_MINUS {
3641 $$ = make_chord_step ($1, FLAT_ALTERATION);
3649 | unsigned_number '-' unsigned_number {
3650 $$ = scm_cons ($1, $3);
3657 TODO: should deprecate in favor of Scheme?
3661 number_expression '+' number_term {
3662 $$ = scm_sum ($1, $3);
3664 | number_expression '-' number_term {
3665 $$ = scm_difference ($1, $3);
3674 | number_factor '*' number_factor {
3675 $$ = scm_product ($1, $3);
3677 | number_factor '/' number_factor {
3678 $$ = scm_divide ($1, $3);
3683 '-' number_factor { /* %prec UNARY_MINUS */
3684 $$ = scm_difference ($2, SCM_UNDEFINED);
3692 | REAL NUMBER_IDENTIFIER
3694 $$ = scm_product ($1, $2);
3701 | UNSIGNED NUMBER_IDENTIFIER {
3702 $$ = scm_product ($1, $2);
3710 if (!scm_is_integer ($1)
3711 || scm_is_true (scm_negative_p ($1)))
3713 parser->parser_error (@1, _("not an unsigned integer"));
3719 if (!scm_is_integer ($1)
3720 || scm_is_true (scm_negative_p ($1)))
3722 parser->parser_error (@1, _("not an unsigned integer"));
3729 { $$ = SCM_UNDEFINED; }
3732 if (SCM_UNBNDP ($1))
3740 // This precedence rule is rather weird. It triggers when '!' is
3741 // encountered after a pitch, and is used for deciding whether to save
3742 // this instead for a figure modification. This should not actually
3743 // occur in practice as pitches and figures are generated in different
3744 // modes. Using a greedy (%right) precedence makes sure that we don't
3745 // get stuck in a wrong interpretation.
3746 { $$ = SCM_UNDEFINED; } %prec ':'
3749 if (SCM_UNBNDP ($1))
3758 { parser->lexer_->push_markup_state (); }
3761 parser->lexer_->pop_state ();
3768 parser->lexer_->push_markup_state ();
3773 markup_mode markup_top {
3775 parser->lexer_->pop_state ();
3780 markup_mode markup_partial_function ETC
3782 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3783 parser->lexer_->pop_state ();
3789 $$ = scm_list_2 (Lily::line_markup, $1);
3791 | markup_head_1_list simple_markup
3793 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3794 @2, $1, scm_list_1 ($2)));
3804 if (Text_interface::is_markup ($1))
3805 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3806 else if (Text_interface::is_markup_list ($1))
3807 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3809 parser->parser_error (@1, _ ("not a markup"));
3810 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3817 markup_composed_list {
3820 | markup_uncomposed_list
3823 markup_uncomposed_list:
3824 markup_braced_list {
3827 | markup_command_list {
3828 $$ = scm_list_1 ($1);
3830 | markup_scm MARKUPLIST_IDENTIFIER
3835 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3836 parser->lexer_->push_note_state (nn);
3837 } '{' score_body '}' {
3838 Score *sc = unsmob<Score> ($4);
3839 sc->origin ()->set_spot (@$);
3840 if (sc->defs_.empty ()) {
3841 Output_def *od = get_layout (parser);
3842 sc->add_output_def (od);
3845 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3846 parser->lexer_->pop_state ();
3850 markup_composed_list:
3851 markup_head_1_list markup_uncomposed_list {
3852 $$ = MAKE_SYNTAX (composed_markup_list,
3858 '{' markup_braced_list_body '}' {
3859 $$ = scm_reverse_x ($2, SCM_EOL);
3863 markup_braced_list_body:
3864 /* empty */ { $$ = SCM_EOL; }
3865 | markup_braced_list_body markup {
3866 $$ = scm_cons ($2, $1);
3868 | markup_braced_list_body markup_list {
3869 $$ = scm_reverse_x ($2, $1);
3873 markup_command_list:
3874 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3875 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3879 markup_command_basic_arguments:
3880 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3881 $$ = scm_cons ($3, $2);
3883 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3884 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3886 | EXPECT_NO_MORE_ARGS {
3891 markup_command_list_arguments:
3892 markup_command_basic_arguments { $$ = $1; }
3893 | EXPECT_MARKUP markup_command_list_arguments markup {
3894 $$ = scm_cons ($3, $2);
3898 markup_partial_function:
3899 MARKUP_FUNCTION markup_arglist_partial
3901 $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
3903 | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
3905 $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
3910 markup_arglist_partial:
3911 EXPECT_MARKUP markup_arglist_partial
3915 | EXPECT_SCM markup_arglist_partial
3919 | EXPECT_MARKUP markup_command_list_arguments
3923 | EXPECT_SCM markup_command_list_arguments
3930 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3931 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3936 markup_head_1_item {
3937 $$ = scm_list_1 ($1);
3939 | markup_head_1_list markup_head_1_item {
3940 $$ = scm_cons ($2, $1);
3946 $$ = make_simple_markup ($1);
3949 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3950 parser->lexer_->push_note_state (nn);
3951 } '{' score_body '}' {
3952 Score *sc = unsmob<Score> ($4);
3953 sc->origin ()->set_spot (@$);
3954 if (sc->defs_.empty ()) {
3955 Output_def *od = get_layout (parser);
3956 sc->add_output_def (od);
3959 $$ = scm_list_2 (Lily::score_markup, $4);
3960 parser->lexer_->pop_state ();
3962 | MARKUP_FUNCTION markup_command_basic_arguments {
3963 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3965 | markup_scm MARKUP_IDENTIFIER
3972 markup_head_1_list simple_markup
3974 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3975 @2, $1, scm_list_1 ($2)));
3985 Lily_parser::set_yydebug (bool x)
3991 Lily_parser::do_yyparse ()
3993 return scm_c_with_fluid (Lily::f_parser,
3995 do_yyparse_trampoline,
3996 static_cast <void *>(this));
4000 Lily_parser::do_yyparse_trampoline (void *parser)
4002 SCM retval = SCM_UNDEFINED;
4003 yyparse (static_cast <Lily_parser *>(parser), &retval);
4011 It is a little strange to have this function in this file, but
4012 otherwise, we have to import music classes into the lexer.
4016 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
4018 if (unsmob<Book> (sid)) {
4019 Book *book = unsmob<Book> (sid)->clone ();
4020 *destination = book->self_scm ();
4023 return BOOK_IDENTIFIER;
4024 } else if (scm_is_number (sid)) {
4026 return NUMBER_IDENTIFIER;
4027 } else if (unsmob<Context_def> (sid))
4029 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
4030 return SCM_IDENTIFIER;
4031 } else if (unsmob<Context_mod> (sid)) {
4032 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
4033 return CONTEXT_MOD_IDENTIFIER;
4034 } else if (Music *mus = unsmob<Music> (sid)) {
4035 mus = mus->clone ();
4036 *destination = mus->self_scm ();
4037 bool is_event = mus->is_mus_type ("post-event");
4039 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
4040 } else if (unsmob<Pitch> (sid)) {
4041 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
4042 return PITCH_IDENTIFIER;
4043 } else if (unsmob<Duration> (sid)) {
4044 *destination = unsmob<Duration> (sid)->smobbed_copy ();
4045 return DURATION_IDENTIFIER;
4046 } else if (unsmob<Output_def> (sid)) {
4047 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
4048 return SCM_IDENTIFIER;
4049 } else if (unsmob<Score> (sid)) {
4050 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
4051 return SCM_IDENTIFIER;
4052 } else if (scm_is_pair (sid)
4053 && scm_is_true (Lily::key_list_p (sid))) {
4055 return LOOKUP_IDENTIFIER;
4061 get_next_unique_context_id ()
4063 return scm_from_ascii_string ("$uniqueContextId");
4068 get_next_unique_lyrics_context_id ()
4070 static int new_context_count;
4072 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
4073 return scm_from_ascii_string (s);
4076 // check_scheme_arg checks one argument with a given predicate for use
4077 // in an argument list and throws a syntax error if it is unusable.
4078 // The argument is prepended to the argument list in any case. After
4079 // throwing a syntax error, the argument list is terminated with #f as
4080 // its last cdr in order to mark it as uncallable while not losing
4081 // track of its total length.
4083 // There are a few special considerations: if optional argument disp
4084 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
4085 // instead of arg in a prospective error message. This is useful if
4086 // arg is not the actual argument but rather a transformation of it.
4088 // If arg itself is SCM_UNDEFINED, the predicate is considered false
4089 // and an error message using disp is produced unconditionally.
4091 SCM check_scheme_arg (Lily_parser *parser, Input loc,
4092 SCM arg, SCM args, SCM pred, SCM disp)
4094 if (SCM_UNBNDP (arg))
4095 args = scm_cons (disp, args);
4097 args = scm_cons (arg, args);
4098 if (scm_is_true (scm_call_1 (pred, arg)))
4101 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
4102 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
4103 SCM_UNBNDP (disp) ? arg : disp);
4104 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
4108 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
4110 if (Music *m = unsmob<Music> (arg))
4113 m->set_spot (parser->lexer_->override_input (loc));
4114 return m->unprotect ();
4120 try_string_variants (SCM pred, SCM str)
4122 // a matching predicate is always ok
4123 if (scm_is_true (scm_call_1 (pred, str)))
4125 // a symbol may be interpreted as a list of symbols if it helps
4126 if (scm_is_true (Lily::key_p (str))) {
4127 str = scm_list_1 (str);
4128 if (scm_is_true (scm_call_1 (pred, str)))
4130 return SCM_UNDEFINED;
4133 // If this cannot be a string representation of a symbol list,
4136 if (!is_regular_identifier (str, true))
4137 return SCM_UNDEFINED;
4139 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4140 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4141 scm_set_car_x (p, scm_string_split (scm_car (p),
4142 SCM_MAKE_CHAR (',')));
4143 str = scm_append_x (str);
4144 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4145 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4147 // Let's attempt the symbol list interpretation first.
4149 if (scm_is_true (scm_call_1 (pred, str)))
4152 // If there is just one symbol in the list, we might interpret
4153 // it as a single symbol
4155 if (scm_is_null (scm_cdr (str)))
4157 str = scm_car (str);
4158 if (scm_is_true (scm_call_1 (pred, str)))
4162 return SCM_UNDEFINED;
4166 is_regular_identifier (SCM id, bool multiple)
4168 if (!scm_is_string (id))
4171 string str = ly_scm2string (id);
4173 bool middle = false;
4175 for (string::iterator it=str.begin(); it != str.end (); it++)
4178 if ((c >= 'a' && c <= 'z')
4179 || (c >= 'A' && c <= 'Z')
4182 else if (middle && (c == '-' || c == '_' || (multiple &&
4183 (c == '.' || c == ','))))
4192 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4194 if (unsmob<Music> (simple))
4196 if (parser->lexer_->is_note_state ()) {
4197 if (scm_is_symbol (simple)) {
4198 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4199 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4200 n->set_property ("drum-type", simple);
4201 return n->unprotect ();
4203 if (unsmob<Pitch> (simple)) {
4204 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4205 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4206 n->set_property ("pitch", simple);
4207 return n->unprotect ();
4210 if (scm_is_integer (simple))
4211 d = make_duration (simple);
4212 if (unsmob<Duration> (d)) {
4213 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4214 n->set_property ("duration", d);
4215 return n->unprotect ();
4218 } else if (parser->lexer_->is_lyric_state ()) {
4219 if (Text_interface::is_markup (simple))
4220 return MAKE_SYNTAX (lyric_event, loc, simple,
4221 parser->default_duration_.smobbed_copy ());
4222 } else if (parser->lexer_->is_chord_state ()) {
4223 if (unsmob<Pitch> (simple))
4227 make_chord_elements (loc, simple,
4228 parser->default_duration_.smobbed_copy (),
4235 make_music_with_input (SCM name, Input where)
4237 Music *m = make_music_by_name (name);
4238 m->set_spot (where);
4243 make_simple_markup (SCM a)
4249 make_duration (SCM d, int dots, SCM factor)
4253 if (Duration *dur = unsmob<Duration> (d)) {
4254 if (!dots && SCM_UNBNDP (factor))
4258 k = Duration (k.duration_log (), k.dot_count () + dots)
4259 .compressed (k.factor ());
4261 int t = scm_to_int (d);
4262 if (t > 0 && (t & (t-1)) == 0)
4263 k = Duration (intlog2 (t), dots);
4265 return SCM_UNDEFINED;
4268 if (!SCM_UNBNDP (factor))
4269 k = k.compressed (ly_scm2rational (factor));
4271 return k.smobbed_copy ();
4275 make_chord_step (SCM step_scm, Rational alter)
4277 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4279 // Notename/octave are normalized
4280 if (m.get_notename () == 6)
4281 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4283 return m.smobbed_copy ();
4288 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4290 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4291 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4293 unsmob<Music> (scm_car (s))->set_spot (loc);
4299 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4301 Lily_lexer *lex = parser->lexer_;
4305 int tok = lex->pop_extra_token ();
4308 lex->prepare_for_next_token ();
4309 return lex->yylex ();