1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 SCM s = Display::value_to_lily_string (value); \
45 char *p = scm_to_locale_string (s); \
52 %parse-param {Lily_parser *parser}
53 %parse-param {SCM *retval}
54 %lex-param {Lily_parser *parser}
58 /* We use SCMs to do strings, because it saves us the trouble of
59 deleting them. Let's hope that a stack overflow doesn't trigger a move
60 of the parse stack onto the heap. */
66 /* The above precedences tackle the shift/reduce problem
69 \repeat .. \alternative
71 \repeat { \repeat .. \alternative }
75 \repeat { \repeat } \alternative
81 %right ':' UNSIGNED REAL E_UNSIGNED EVENT_IDENTIFIER EVENT_FUNCTION '^' '_'
82 HYPHEN EXTENDER DURATION_IDENTIFIER '!'
84 /* The above are needed for collecting tremoli and other items (that
85 could otherwise be interpreted as belonging to the next function
86 argument) greedily, and together with the next rule will serve to
87 join numbers and units greedily instead of allowing them into
88 separate function arguments
91 %nonassoc NUMBER_IDENTIFIER
103 %{ // -*-Fundamental-*-
108 * The rules for who is protecting what are very shady. Uniformise
111 * There are too many lexical modes?
122 #include "context-def.hh"
123 #include "context-mod.hh"
124 #include "dimensions.hh"
125 #include "file-path.hh"
127 #include "international.hh"
128 #include "lily-guile.hh"
129 #include "lily-lexer.hh"
130 #include "lily-parser.hh"
131 #include "ly-module.hh"
135 #include "output-def.hh"
136 #include "paper-book.hh"
137 #include "scm-hash.hh"
139 #include "text-interface.hh"
141 #include "lily-imports.hh"
144 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const std::string &s)
146 parser->parser_error (*i, s);
149 // The following are somewhat precarious constructs as they may change
150 // the value of the lookahead token. That implies that the lookahead
151 // token must not yet have made an impact on the state stack other
152 // than causing the reduction of the current rule, or switching the
153 // lookahead token while Bison is mulling it over will cause trouble.
155 #define MYBACKUP(Token, Value, Location) \
157 if (yychar != YYEMPTY) \
158 parser->lexer_->push_extra_token \
159 (yylloc, yychar, yylval); \
161 parser->lexer_->push_extra_token \
162 (Location, Token, Value); \
163 parser->lexer_->push_extra_token (Location, BACKUP); \
168 #define MYREPARSE(Location, Pred, Token, Value) \
170 if (yychar != YYEMPTY) \
171 parser->lexer_->push_extra_token \
172 (yylloc, yychar, yylval); \
173 parser->lexer_->push_extra_token \
174 (Location, Token, Value); \
175 parser->lexer_->push_extra_token \
176 (Location, REPARSE, Pred); \
185 #define MY_MAKE_MUSIC(x, spot) \
186 make_music_with_input (ly_symbol2scm (x), \
187 parser->lexer_->override_input (spot))
190 - delay application of the function
193 #define LOWLEVEL_MAKE_SYNTAX(location, proc, ...) \
195 (parser->lexer_->override_input (location).smobbed_copy (), \
199 /* Syntactic Sugar. */
200 #define MAKE_SYNTAX(name, location, ...) \
201 LOWLEVEL_MAKE_SYNTAX (location, Syntax::name, ##__VA_ARGS__)
203 #define START_MAKE_SYNTAX(name, ...) \
204 scm_list_n (Syntax::name, ##__VA_ARGS__, SCM_UNDEFINED)
206 #define FINISH_MAKE_SYNTAX(start, location, ...) \
207 LOWLEVEL_MAKE_SYNTAX \
212 (scm_list_2 (scm_cdr (start), \
213 scm_list_n (__VA_ARGS__, SCM_UNDEFINED))))
215 SCM get_next_unique_context_id ();
216 SCM get_next_unique_lyrics_context_id ();
223 #define _(x) gettext (x)
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);
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 %token PITCH_IDENTIFIER
352 %token DURATION_IDENTIFIER
353 %token EVENT_IDENTIFIER
354 %token EVENT_FUNCTION
357 %token MARKUP_FUNCTION
358 %token MARKUP_LIST_FUNCTION
359 %token MARKUP_IDENTIFIER
360 %token MARKUPLIST_IDENTIFIER
361 %token MUSIC_FUNCTION
362 %token MUSIC_IDENTIFIER
363 %token NOTENAME_PITCH
364 %token NUMBER_IDENTIFIER
369 %token SCM_IDENTIFIER
373 %token TONICNAME_PITCH
377 /* We don't assign precedence to / and *, because we might need varied
378 prec levels in different prods */
387 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
388 parser->lexer_->push_note_state (nn);
389 } embedded_lilypond {
390 parser->lexer_->pop_state ();
395 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
396 | lilypond toplevel_expression {
398 | lilypond assignment {
401 parser->error_level_ = 1;
404 parser->error_level_ = 1;
411 parser->lexer_->add_scope (get_header (parser));
413 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
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);
497 $$ = parser->lexer_->eval_scm_token ($1, @1);
507 embedded_scm_bare_arg:
511 $$ = parser->lexer_->eval_scm_token ($1, @1);
516 | context_modification
518 | context_def_spec_block
524 /* The generic version may end in music, or not */
531 /* embedded_scm_arg is _not_ casting pitches to music by default, this
532 * has to be done by the function itself. Note that this may cause
533 * the results of scm_function_call or embedded_scm_bare_arg to be
534 * turned into music from pitches as well. Note that this creates a
535 * distinctly awkward situation for calculated drum pitches. Those
536 * are at the current point of time rejected as music constituents as
537 * they can't be distinguished from "proper" symbols.
541 embedded_scm_bare_arg
547 SCM_FUNCTION function_arglist {
548 $$ = MAKE_SYNTAX (music_function, @$,
553 embedded_lilypond_number:
554 '-' embedded_lilypond_number
556 $$ = scm_difference ($2, SCM_UNDEFINED);
559 | UNSIGNED NUMBER_IDENTIFIER
561 $$ = scm_product ($1, $2);
568 // FIXME: @$ does not contain a useful source location
569 // for empty rules, and the only token in the whole
570 // production, EMBEDDED_LILY, is synthetic and also
571 // contains no source location.
572 $$ = MAKE_SYNTAX (void_music, @$);
574 | identifier_init_nonumber
575 | embedded_lilypond_number
576 | post_event post_events
578 $$ = scm_reverse_x ($2, SCM_EOL);
579 if (Music *m = unsmob<Music> ($1))
581 if (m->is_mus_type ("post-event-wrapper"))
583 (scm_list_2 (m->get_property ("elements"),
586 $$ = scm_cons ($1, $$);
589 && scm_is_null (scm_cdr ($$)))
593 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
594 m->set_property ("elements", $$);
595 $$ = m->unprotect ();
598 | multiplied_duration
599 | music_embedded music_embedded music_list {
600 $3 = scm_reverse_x ($3, SCM_EOL);
601 if (unsmob<Music> ($2))
602 $3 = scm_cons ($2, $3);
603 if (unsmob<Music> ($1))
604 $3 = scm_cons ($1, $3);
605 $$ = MAKE_SYNTAX (sequential_music, @$, $3);
608 parser->error_level_ = 1;
609 $$ = SCM_UNSPECIFIED;
611 | INVALID embedded_lilypond {
612 parser->error_level_ = 1;
618 lilypond_header_body:
619 /* empty */ { $$ = SCM_UNSPECIFIED; }
620 | lilypond_header_body assignment {
623 | lilypond_header_body embedded_scm {
629 HEADER '{' lilypond_header_body '}' {
630 $$ = parser->lexer_->remove_scope ();
642 assignment_id '=' identifier_init {
643 parser->lexer_->set_identifier ($1, $3);
644 $$ = SCM_UNSPECIFIED;
646 | assignment_id property_path '=' identifier_init {
647 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
648 parser->lexer_->set_identifier (path, $4);
649 $$ = SCM_UNSPECIFIED;
651 | assignment_id '.' property_path '=' identifier_init {
652 SCM path = scm_cons (scm_string_to_symbol ($1), $3);
653 parser->lexer_->set_identifier (path, $5);
654 $$ = SCM_UNSPECIFIED;
660 identifier_init_nonumber
662 | post_event_nofinger post_events
664 $$ = scm_reverse_x ($2, SCM_EOL);
665 if (Music *m = unsmob<Music> ($1))
667 if (m->is_mus_type ("post-event-wrapper"))
669 (scm_list_2 (m->get_property ("elements"),
672 $$ = scm_cons ($1, $$);
675 && scm_is_null (scm_cdr ($$)))
679 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
680 m->set_property ("elements", $$);
681 $$ = m->unprotect ();
686 identifier_init_nonumber:
691 | context_def_spec_block
699 | context_modification
700 | partial_function ETC
702 $$ = MAKE_SYNTAX (partial_music_function, @$,
703 scm_reverse_x ($1, SCM_EOL));
709 MUSIC_FUNCTION function_arglist_partial
711 $$ = scm_acons ($1, $2, SCM_EOL);
713 | EVENT_FUNCTION function_arglist_partial
715 $$ = scm_acons ($1, $2, SCM_EOL);
717 | SCM_FUNCTION function_arglist_partial
719 $$ = scm_acons ($1, $2, SCM_EOL);
721 | OVERRIDE grob_prop_path '='
724 $$ = scm_list_1 (SCM_BOOL_F);
727 (scm_list_3 (Syntax::property_override_function,
728 scm_cdr ($2), scm_car ($2)),
731 | SET context_prop_spec '='
734 $$ = scm_list_1 (SCM_BOOL_F);
737 (scm_list_3 (Syntax::property_set_function,
738 scm_cadr ($2), scm_car ($2)),
741 | MUSIC_FUNCTION EXPECT_SCM function_arglist_optional partial_function
743 $$ = scm_acons ($1, $3, $4);
745 | EVENT_FUNCTION EXPECT_SCM function_arglist_optional partial_function
747 $$ = scm_acons ($1, $3, $4);
749 | SCM_FUNCTION EXPECT_SCM function_arglist_optional partial_function
751 $$ = scm_acons ($1, $3, $4);
753 | OVERRIDE grob_prop_path '=' partial_function
756 $$ = scm_list_1 (SCM_BOOL_F);
759 (scm_list_3 (Syntax::property_override_function,
760 scm_cdr ($2), scm_car ($2)),
763 | SET context_prop_spec '=' partial_function
766 $$ = scm_list_1 (SCM_BOOL_F);
769 (scm_list_3 (Syntax::property_set_function,
770 scm_cadr ($2), scm_car ($2)),
773 | MUSIC_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
775 $$ = scm_acons ($1, $4, $5);
777 | EVENT_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
779 $$ = scm_acons ($1, $4, $5);
781 | SCM_FUNCTION EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup partial_function
783 $$ = scm_acons ($1, $4, $5);
787 context_def_spec_block:
788 CONTEXT '{' context_def_spec_body '}'
791 Context_def *td = unsmob<Context_def> ($$);
793 $$ = Context_def::make_scm ();
794 td = unsmob<Context_def> ($$);
796 td->origin ()->set_spot (@$);
804 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
805 parser->lexer_->push_note_state (nn);
809 parser->lexer_->pop_state ();
815 context_def_spec_body:
817 $$ = SCM_UNSPECIFIED;
819 | context_def_spec_body context_mod {
820 if (!SCM_UNBNDP ($2)) {
821 Context_def *td = unsmob<Context_def> ($$);
823 $$ = Context_def::make_scm ();
824 td = unsmob<Context_def> ($$);
826 unsmob<Context_def> ($$)->add_context_mod ($2);
829 | context_def_spec_body context_modification {
830 Context_def *td = unsmob<Context_def> ($$);
832 $$ = Context_def::make_scm ();
833 td = unsmob<Context_def> ($$);
835 SCM new_mods = unsmob<Context_mod> ($2)->get_mods ();
836 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
837 td->add_context_mod (scm_car (m));
840 | context_def_spec_body context_mod_arg {
841 Context_def *td = unsmob<Context_def> ($1);
842 if (scm_is_eq ($2, SCM_UNSPECIFIED))
844 else if (!td && unsmob<Context_def> ($2))
848 $$ = Context_def::make_scm ();
849 td = unsmob<Context_def> ($$);
851 if (unsmob<Music> ($2)) {
852 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
853 $2 = scm_call_1 (proc, $2);
855 if (Context_mod *cm = unsmob<Context_mod> ($2)) {
856 for (SCM m = cm->get_mods (); scm_is_pair (m); m = scm_cdr (m)) {
857 td->add_context_mod (scm_car (m));
860 parser->parser_error (@2, _ ("not a context mod"));
868 BOOK '{' book_body '}' {
870 unsmob<Book> ($$)->origin ()->set_spot (@$);
872 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
877 * Use 'handlers' like for toplevel-* stuff?
878 * grok \layout and \midi? */
881 Book *book = new Book;
882 init_papers (parser);
883 book->paper_ = dynamic_cast<Output_def*> (unsmob<Output_def> (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
884 book->paper_->unprotect ();
885 push_paper (parser, book->paper_);
886 book->header_ = get_header (parser);
887 $$ = book->unprotect ();
888 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
891 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
893 | book_body paper_block {
894 unsmob<Book> ($1)->paper_ = unsmob<Output_def> ($2);
895 set_paper (parser, unsmob<Output_def> ($2));
897 | book_body bookpart_block {
898 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
899 scm_call_2 (proc, $1, $2);
901 | book_body score_block {
902 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
903 scm_call_2 (proc, $1, $2);
905 | book_body composite_music {
906 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
907 scm_call_2 (proc, $1, $2);
909 | book_body full_markup {
910 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
911 scm_call_2 (proc, $1, scm_list_1 ($2));
913 | book_body full_markup_list {
914 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
915 scm_call_2 (proc, $1, $2);
917 | book_body SCM_TOKEN {
918 // Evaluate and ignore #xxx, as opposed to \xxx
919 parser->lexer_->eval_scm_token ($2, @2);
921 | book_body embedded_scm_active
923 SCM out = SCM_UNDEFINED;
924 if (Text_interface::is_markup ($2))
925 out = scm_list_1 ($2);
926 else if (Text_interface::is_markup_list ($2))
928 if (scm_is_pair (out))
930 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
931 scm_call_2 (proc, $1, out);
932 } else if (unsmob<Score> ($2))
934 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
935 scm_call_2 (proc, $1, $2);
936 } else if (Output_def *od = unsmob<Output_def> ($2)) {
939 if (to_boolean (od->c_variable ("is-paper")))
940 id = ly_symbol2scm ("$defaultpaper");
941 else if (to_boolean (od->c_variable ("is-midi")))
942 id = ly_symbol2scm ("$defaultmidi");
943 else if (to_boolean (od->c_variable ("is-layout")))
944 id = ly_symbol2scm ("$defaultlayout");
946 parser->lexer_->set_identifier (id, $2);
947 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
948 parser->parser_error (@2, _("bad expression type"));
952 parser->lexer_->add_scope (unsmob<Book> ($1)->header_);
955 Book *book = unsmob<Book> ($1);
957 book->scores_ = SCM_EOL;
958 book->bookparts_ = SCM_EOL;
963 BOOKPART '{' bookpart_body '}' {
965 unsmob<Book> ($$)->origin ()->set_spot (@$);
966 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
972 Book *book = new Book;
973 $$ = book->unprotect ();
974 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
977 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
979 | bookpart_body paper_block {
980 unsmob<Book> ($$)->paper_ = unsmob<Output_def> ($2);
982 | bookpart_body score_block {
983 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
984 scm_call_2 (proc, $1, $2);
986 | bookpart_body composite_music {
987 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
988 scm_call_2 (proc, $1, $2);
990 | bookpart_body full_markup {
991 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
992 scm_call_2 (proc, $1, scm_list_1 ($2));
994 | bookpart_body full_markup_list {
995 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
996 scm_call_2 (proc, $1, $2);
998 | bookpart_body SCM_TOKEN {
999 // Evaluate and ignore #xxx, as opposed to \xxx
1000 parser->lexer_->eval_scm_token ($2, @2);
1002 | bookpart_body embedded_scm_active
1004 SCM out = SCM_UNDEFINED;
1005 if (Text_interface::is_markup ($2))
1006 out = scm_list_1 ($2);
1007 else if (Text_interface::is_markup_list ($2))
1009 if (scm_is_pair (out))
1011 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
1012 scm_call_2 (proc, $1, out);
1013 } else if (unsmob<Score> ($2))
1015 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
1016 scm_call_2 (proc, $1, $2);
1017 } else if (Output_def *od = unsmob<Output_def> ($2)) {
1020 if (to_boolean (od->c_variable ("is-paper")))
1021 id = ly_symbol2scm ("$defaultpaper");
1022 else if (to_boolean (od->c_variable ("is-midi")))
1023 id = ly_symbol2scm ("$defaultmidi");
1024 else if (to_boolean (od->c_variable ("is-layout")))
1025 id = ly_symbol2scm ("$defaultlayout");
1027 parser->lexer_->set_identifier (id, $2);
1028 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1029 parser->parser_error (@2, _("bad expression type"));
1033 Book *book = unsmob<Book> ($1);
1034 if (!ly_is_module (book->header_))
1035 book->header_ = ly_make_module (false);
1036 parser->lexer_->add_scope (book->header_);
1038 | bookpart_body error {
1039 Book *book = unsmob<Book> ($1);
1041 book->scores_ = SCM_EOL;
1046 SCORE '{' score_body '}' {
1047 unsmob<Score> ($3)->origin ()->set_spot (@$);
1054 if (!unsmob<Score> ($1)) {
1055 parser->parser_error (@1, _("Missing music in \\score"));
1056 $$ = (new Score)->unprotect ();
1057 if (scm_is_pair ($1) && ly_is_module (scm_car ($1)))
1059 unsmob<Score> ($$)->set_header (scm_car ($1));
1062 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1063 scm_is_pair (p); p = scm_cdr (p))
1065 unsmob<Score> ($$)->
1066 add_output_def (unsmob<Output_def> (scm_car (p)));
1070 | score_body error {
1071 unsmob<Score> ($$)->error_found_ = true;
1086 | score_items score_item
1088 Output_def *od = unsmob<Output_def> ($2);
1090 if (to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1092 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
1094 $2 = SCM_UNSPECIFIED;
1096 } else if (!unsmob<Score> ($$)) {
1097 if (unsmob<Music> ($2)) {
1098 $2 = Lily::scorify_music ($2);
1100 if (unsmob<Score> ($2))
1103 $2 = SCM_UNSPECIFIED;
1106 Score *score = unsmob<Score> ($$);
1107 if (score && scm_is_pair ($1)) {
1108 if (ly_is_module (scm_car ($1)))
1110 score->set_header (scm_car ($1));
1113 for (SCM p = scm_reverse_x ($1, SCM_EOL);
1114 scm_is_pair (p); p = scm_cdr (p))
1116 score->add_output_def (unsmob<Output_def> (scm_car (p)));
1121 score->add_output_def (od);
1122 else if (scm_is_pair ($$) && ly_is_module (scm_car ($$)))
1123 scm_set_cdr_x ($$, scm_cons ($2, scm_cdr ($$)));
1125 $$ = scm_cons ($2, $$);
1126 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1127 parser->parser_error (@2, _("Spurious expression in \\score"));
1131 if (Score *score = unsmob<Score> ($1)) {
1132 if (!ly_is_module (score->get_header ()))
1133 score->set_header (ly_make_module (false));
1134 parser->lexer_->add_scope (score->get_header ());
1136 if (!scm_is_pair ($1) || !ly_is_module (scm_car ($1)))
1137 $1 = scm_cons (ly_make_module (false), $1);
1138 parser->lexer_->add_scope (scm_car ($1));
1153 Output_def *od = unsmob<Output_def> ($1);
1155 if (!to_boolean (od->lookup_variable (ly_symbol2scm ("is-paper"))))
1157 parser->parser_error (@1, _ ("need \\paper for paper block"));
1158 $$ = get_paper (parser)->unprotect ();
1165 output_def_body '}' {
1166 if (scm_is_pair ($1))
1169 parser->lexer_->remove_scope ();
1170 parser->lexer_->pop_state ();
1176 Output_def *p = get_paper (parser);
1177 p->input_origin_ = @$;
1178 parser->lexer_->add_scope (p->scope_);
1179 $$ = p->unprotect ();
1182 Output_def *p = get_midi (parser);
1183 $$ = p->unprotect ();
1184 parser->lexer_->add_scope (p->scope_);
1187 Output_def *p = get_layout (parser);
1189 parser->lexer_->add_scope (p->scope_);
1190 $$ = p->unprotect ();
1194 output_def_head_with_mode_switch:
1196 parser->lexer_->push_initial_state ();
1201 // We need this weird nonterminal because both music as well as a
1202 // context definition can start with \context and the difference is
1203 // only apparent after looking at the next token. If it is '{', there
1204 // is still time to escape from notes mode.
1206 music_or_context_def:
1208 | context_def_spec_block
1212 output_def_head_with_mode_switch '{' {
1213 unsmob<Output_def> ($1)->input_origin_.set_spot (@$);
1214 // This is a stupid trick to mark the beginning of the
1215 // body for deciding whether to allow
1216 // embedded_scm_active to have an output definition
1217 $$ = scm_list_1 ($1);
1219 | output_def_body assignment {
1220 if (scm_is_pair ($1))
1223 | output_def_body embedded_scm_active
1225 // We don't switch into note mode for Scheme functions
1226 // here. Does not seem warranted/required in output
1228 if (scm_is_pair ($1))
1230 Output_def *o = unsmob<Output_def> ($2);
1232 o->input_origin_.set_spot (@$);
1233 $1 = o->self_scm ();
1234 parser->lexer_->remove_scope ();
1235 parser->lexer_->add_scope (o->scope_);
1236 $2 = SCM_UNSPECIFIED;
1240 if (unsmob<Context_def> ($2))
1241 assign_context_def (unsmob<Output_def> ($1), $2);
1242 // Seems unlikely, but let's be complete:
1243 else if (unsmob<Music> ($2))
1245 SCM proc = parser->lexer_->lookup_identifier
1246 ("output-def-music-handler");
1247 scm_call_2 (proc, $1, $2);
1248 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
1249 parser->parser_error (@2, _("bad expression type"));
1252 | output_def_body SCM_TOKEN {
1253 if (scm_is_pair ($1))
1255 // Evaluate and ignore #xxx, as opposed to \xxx
1256 parser->lexer_->eval_scm_token ($2, @2);
1260 if (scm_is_pair ($1))
1262 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1263 parser->lexer_->push_note_state (nn);
1264 } music_or_context_def
1266 parser->lexer_->pop_state ();
1267 if (unsmob<Context_def> ($3))
1268 assign_context_def (unsmob<Output_def> ($1), $3);
1271 SCM proc = parser->lexer_->lookup_identifier
1272 ("output-def-music-handler");
1273 scm_call_2 (proc, $1, $3);
1277 | output_def_body error {
1283 TEMPO steno_duration '=' tempo_range {
1284 $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
1286 | TEMPO text steno_duration '=' tempo_range {
1287 $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
1290 $$ = MAKE_SYNTAX (tempo, @$, $2);
1295 The representation of a list is reversed to have efficient append. */
1301 | music_list music_embedded {
1302 if (unsmob<Music> ($2))
1303 $$ = scm_cons ($2, $1);
1305 | music_list error {
1306 Music *m = MY_MAKE_MUSIC("Music", @$);
1308 m->set_property ("error-found", SCM_BOOL_T);
1309 $$ = scm_cons (m->self_scm (), $1);
1310 m->unprotect (); /* UGH */
1317 $$ = scm_reverse_x ($2, SCM_EOL);
1322 | lyric_element_music
1329 $$ = make_music_from_simple (parser, @1, $1);
1330 if (!unsmob<Music> ($$))
1332 parser->parser_error (@1, _ ("music expected"));
1333 $$ = MAKE_SYNTAX (void_music, @$);
1341 if (unsmob<Music> ($1)->is_mus_type ("post-event")) {
1342 parser->parser_error (@1, _ ("unexpected post-event"));
1343 $$ = SCM_UNSPECIFIED;
1346 | music_embedded_backup
1350 | music_embedded_backup BACKUP lyric_element_music
1354 | multiplied_duration post_events
1356 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1358 parser->default_duration_ = *unsmob<Duration> ($1);
1359 n->set_property ("duration", $1);
1361 if (scm_is_pair ($2))
1362 n->set_property ("articulations",
1363 scm_reverse_x ($2, SCM_EOL));
1364 $$ = n->unprotect ();
1368 music_embedded_backup:
1371 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1373 else if (Music *m = unsmob<Music> ($1)) {
1374 if (m->is_mus_type ("post-event")) {
1375 parser->parser_error
1376 (@1, _ ("unexpected post-event"));
1377 $$ = SCM_UNSPECIFIED;
1380 } else if (parser->lexer_->is_lyric_state ()
1381 && Text_interface::is_markup ($1))
1382 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1384 @$.warning (_ ("Ignoring non-music expression"));
1390 // music_assign does not need to contain lyrics: there are no
1391 // assignments in lyricmode.
1394 | composite_music %prec COMPOSITE
1398 REPEAT simple_string unsigned_number music
1400 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, SCM_EOL);
1402 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1404 $$ = MAKE_SYNTAX (repeat, @$, $2, $3, $4, $6);
1409 SEQUENTIAL braced_music_list {
1410 $$ = MAKE_SYNTAX (sequential_music, @$, $2);
1412 | braced_music_list {
1413 $$ = MAKE_SYNTAX (sequential_music, @$, $1);
1418 SIMULTANEOUS braced_music_list {
1419 $$ = MAKE_SYNTAX (simultaneous_music, @$, $2);
1421 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1422 $$ = MAKE_SYNTAX (simultaneous_music, @$, scm_reverse_x ($2, SCM_EOL));
1428 | music_property_def
1432 context_modification:
1435 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1436 parser->lexer_->push_note_state (nn);
1437 } '{' context_mod_list '}'
1439 parser->lexer_->pop_state ();
1442 | WITH CONTEXT_MOD_IDENTIFIER
1446 | CONTEXT_MOD_IDENTIFIER
1450 | WITH context_modification_arg
1452 if (unsmob<Music> ($2)) {
1453 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1454 $2 = scm_call_1 (proc, $2);
1456 if (unsmob<Context_mod> ($2))
1459 parser->parser_error (@2, _ ("not a context mod"));
1460 $$ = Context_mod ().smobbed_copy ();
1465 context_modification_arg:
1470 optional_context_mod:
1474 | context_modification
1482 $$ = Context_mod ().smobbed_copy ();
1484 | context_mod_list context_mod {
1485 if (!SCM_UNBNDP ($2))
1486 unsmob<Context_mod> ($1)->add_context_mod ($2);
1488 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1489 Context_mod *md = unsmob<Context_mod> ($2);
1491 unsmob<Context_mod> ($1)->add_context_mods (md->get_mods ());
1493 | context_mod_list context_mod_arg {
1494 if (scm_is_eq ($2, SCM_UNSPECIFIED))
1496 else if (unsmob<Music> ($2)) {
1497 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1498 $2 = scm_call_1 (proc, $2);
1500 if (unsmob<Context_mod> ($2))
1501 unsmob<Context_mod> ($$)->add_context_mods
1502 (unsmob<Context_mod> ($2)->get_mods ());
1504 parser->parser_error (@2, _ ("not a context mod"));
1510 CONTEXT symbol optional_id optional_context_mod {
1511 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1514 mods = ctxmod->get_mods ();
1515 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_F);
1517 | NEWCONTEXT symbol optional_id optional_context_mod {
1518 Context_mod *ctxmod = unsmob<Context_mod> ($4);
1521 mods = ctxmod->get_mods ();
1522 $$ = START_MAKE_SYNTAX (context_specification, $2, $3, mods, SCM_BOOL_T);
1527 ADDLYRICS optional_context_mod lyric_mode_music {
1528 Context_mod *ctxmod = unsmob<Context_mod> ($2);
1531 mods = ctxmod->get_mods ();
1532 $$ = scm_acons ($3, mods, SCM_EOL);
1534 | new_lyrics ADDLYRICS optional_context_mod lyric_mode_music {
1535 Context_mod *ctxmod = unsmob<Context_mod> ($3);
1538 mods = ctxmod->get_mods ();
1539 $$ = scm_acons ($4, mods, $1);
1543 /* basic_music is basically the same as composite_music but with
1544 * context-prefixed music and lyricized music explicitly removed. The
1545 * reason is that in a sequence
1547 * \new Staff \new Voice { ... } \addlyrics { ... } \addlyrics { ... }
1549 * we need to group both \addlyrics together (as they go with the same
1550 * voice) but then combine them with \new Voice { ... }, meaning that
1551 * combining \new Voice { ... } needs higher priority than
1552 * { ... } \addlyrics, and *not* have \new Staff \new Voice { ... }
1553 * combine before combining \new Voice { ... } \addlyrics: only one
1554 * layer of context-prefixed music should assemble before \addlyrics
1555 * is integrated. Total mess, and we sort this mess out with explicit
1556 * rules preferring a single context-prefix.
1563 | LYRICSTO simple_string lyric_mode_music {
1564 $$ = MAKE_SYNTAX (lyric_combine, @$, $2, SCM_EOL, $3);
1566 | LYRICSTO symbol '=' simple_string lyric_mode_music
1568 $$ = MAKE_SYNTAX (lyric_combine, @$, $3, $2, $4);
1578 contexted_basic_music:
1579 context_prefix contextable_music new_lyrics
1582 i.set_location (@1, @2);
1583 $$ = FINISH_MAKE_SYNTAX ($1, i, $2);
1584 $$ = MAKE_SYNTAX (add_lyrics, @$, $$, scm_reverse_x ($3, SCM_EOL));
1586 | context_prefix contextable_music
1588 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1590 | context_prefix contexted_basic_music
1592 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1597 basic_music %prec COMPOSITE
1598 | contexted_basic_music
1599 | basic_music new_lyrics
1601 $$ = MAKE_SYNTAX (add_lyrics, @$, $1, scm_reverse_x ($2, SCM_EOL));
1608 | grouped_music_list
1612 simultaneous_music { $$ = $1; }
1613 | sequential_music { $$ = $1; }
1616 /* Function argument lists are arguably the most complex part in the
1617 * parser. They are pretty tricky to understand because of the way
1618 * they are processed, and because of optional arguments that can be
1619 * omitted. When there are several optional arguments in a row,
1620 * omitting one automatically omits all following arguments. Optional
1621 * arguments can only be omitted when either
1623 * a) the omission is explicitly started with \default
1624 * b) the omission is implicitly started by an argument not matching
1625 * its predicate, and there is a mandatory argument later that can
1626 * "catch" the argument that does not fit.
1628 * When argument parsing starts, the lexer pushes EXPECT_SCM tokens
1629 * (corresponding to mandatory arguments and having a predicate
1630 * function as semantic value) or EXPECT_OPTIONAL EXPECT_SCM (where
1631 * the semantic value of the EXPECT_OPTIONAL token is the default to
1632 * use when the optional argument is omitted, and EXPECT_SCM again has
1633 * the argument predicate as semantic value) in reverse order to the
1634 * parser, followed by EXPECT_NO_MORE_ARGS. The argument list is then
1635 * processed inside-out while actual tokens are consumed.
1637 * This means that the argument list tokens determine the actions
1638 * taken as they arrive. The structure of the argument list is known
1639 * to the parser and stored in its parse stack when the first argument
1640 * is being parsed. What the parser does not know is which predicates
1641 * will match and whether or not \default will be appearing in the
1642 * argument list, and where.
1644 * Sequences of 0 or more optional arguments are scanned using either
1645 * function_arglist_backup or function_arglist_nonbackup. The first
1646 * is used when optional arguments are followed by at least one
1647 * mandatory argument: in that case optional arguments may be skipped
1648 * by either a false predicate (in which case the expression will be
1649 * pushed back as one or more tokens, preceded by a BACKUP token) or
1650 * by using \default.
1652 * If optional arguments are at the end of the argument list, they are
1653 * instead scanned using function_arglist_nonbackup: here the only
1654 * manner to enter into skipping of optional arguments is the use of
1657 * The argument list of a normal function call is parsed using
1658 * function_arglist. The part of an argument list before a mandatory
1659 * argument is parsed using function_arglist_optional.
1661 * The difference is that leading optional arguments are scanned using
1662 * function_arglist_nonbackup and function_arglist_backup,
1665 * Most other details are obvious in the rules themselves.
1671 | SYMBOL_LIST '.' symbol_list_rev
1673 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1679 | symbol_list_rev '.' symbol_list_part
1681 $$ = scm_append_x (scm_list_2 ($3, $1));
1685 // symbol_list_part delivers elements in reverse copy.
1690 $$ = try_string_variants (Lily::symbol_list_p, $1);
1691 if (SCM_UNBNDP ($$)) {
1692 parser->parser_error (@1, _("not a symbol"));
1695 $$ = scm_reverse ($$);
1700 symbol_list_element:
1706 function_arglist_nonbackup:
1707 function_arglist_common
1708 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup post_event_nofinger
1710 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1712 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' UNSIGNED
1714 SCM n = scm_difference ($5, SCM_UNDEFINED);
1715 if (scm_is_true (scm_call_1 ($2, n)))
1716 $$ = scm_cons (n, $3);
1718 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1719 t->set_property ("digit", $5);
1720 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1724 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' REAL
1726 $$ = check_scheme_arg (parser, @4,
1727 scm_difference ($5, SCM_UNDEFINED),
1730 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup '-' NUMBER_IDENTIFIER
1732 $$ = check_scheme_arg (parser, @4,
1733 scm_difference ($5, SCM_UNDEFINED),
1736 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup embedded_scm_arg
1738 if (scm_is_true (scm_call_1 ($2, $4)))
1739 $$ = scm_cons ($4, $3);
1741 $$ = check_scheme_arg (parser, @4,
1742 make_music_from_simple
1746 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup bare_number_common
1748 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1750 | function_arglist_nonbackup_reparse REPARSE pitch_or_music
1752 if (scm_is_true (scm_call_1 ($2, $3)))
1753 $$ = scm_cons ($3, $1);
1755 $$ = check_scheme_arg (parser, @3,
1756 make_music_from_simple
1760 | function_arglist_nonbackup_reparse REPARSE duration_length
1762 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1764 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1766 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1768 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1770 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1772 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1774 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1776 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1778 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1782 function_arglist_nonbackup_reparse:
1783 EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup SCM_IDENTIFIER
1786 SCM res = try_string_variants ($2, $4);
1787 if (!SCM_UNBNDP (res))
1788 if (scm_is_pair (res))
1789 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1791 MYREPARSE (@4, $2, SCM_ARG, res);
1792 else if (scm_is_true
1794 ($2, make_music_from_simple
1796 MYREPARSE (@4, $2, STRING, $4);
1798 MYREPARSE (@4, $2, SCM_ARG, $4);
1800 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup pitch
1805 ($2, make_music_from_simple
1807 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1809 MYREPARSE (@4, $2, SCM_ARG, $4);
1811 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup steno_tonic_pitch
1816 ($2, make_music_from_simple
1818 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1820 MYREPARSE (@4, $2, SCM_ARG, $4);
1822 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup STRING
1825 SCM res = try_string_variants ($2, $4);
1826 if (!SCM_UNBNDP (res))
1827 if (scm_is_pair (res))
1828 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1830 MYREPARSE (@4, $2, SCM_ARG, res);
1831 else if (scm_is_true
1833 ($2, make_music_from_simple
1835 MYREPARSE (@4, $2, STRING, $4);
1837 MYREPARSE (@4, $2, SCM_ARG, $4);
1839 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup full_markup
1842 if (scm_is_true (scm_call_1 ($2, $4)))
1843 MYREPARSE (@4, $2, SCM_ARG, $4);
1844 else if (scm_is_true
1846 ($2, make_music_from_simple
1848 MYREPARSE (@4, $2, STRING, $4);
1850 MYREPARSE (@4, $2, SCM_ARG, $4);
1852 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup UNSIGNED
1855 if (scm_is_true (scm_call_1 ($2, $4)))
1856 MYREPARSE (@4, $2, REAL, $4);
1858 SCM d = make_duration ($4);
1859 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1860 MYREPARSE (@4, $2, REAL, $4); // trigger error
1862 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1865 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup DURATION_IDENTIFIER {
1867 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1872 // function_arglist_backup can't occur at the end of an argument
1874 function_arglist_backup:
1875 function_arglist_common
1876 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup embedded_scm_arg
1878 if (scm_is_true (scm_call_1 ($2, $4)))
1879 $$ = scm_cons ($4, $3);
1881 $$ = make_music_from_simple (parser, @4, $4);
1882 if (scm_is_true (scm_call_1 ($2, $$)))
1883 $$ = scm_cons ($$, $3);
1886 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1887 MYBACKUP (SCM_ARG, $4, @4);
1891 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup post_event_nofinger
1893 if (scm_is_true (scm_call_1 ($2, $4)))
1895 $$ = scm_cons ($4, $3);
1897 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1898 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1901 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup pitch
1905 ($2, make_music_from_simple
1909 MYREPARSE (@4, $2, PITCH_IDENTIFIER, $4);
1910 } else if (scm_is_true (scm_call_1 ($2, $4)))
1911 $$ = scm_cons ($4, $3);
1913 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1914 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1917 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup steno_tonic_pitch
1921 ($2, make_music_from_simple
1925 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1926 } else if (scm_is_true (scm_call_1 ($2, $4)))
1927 $$ = scm_cons ($4, $3);
1929 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1930 MYBACKUP (TONICNAME_PITCH, $4, @4);
1933 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup full_markup
1935 if (scm_is_true (scm_call_1 ($2, $4)))
1936 $$ = scm_cons ($4, $3);
1938 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1939 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1942 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup UNSIGNED
1944 if (scm_is_true (scm_call_1 ($2, $4)))
1946 MYREPARSE (@4, $2, REAL, $4);
1949 SCM d = make_duration ($4);
1950 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1952 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1953 MYBACKUP (UNSIGNED, $4, @4);
1955 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1960 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup REAL
1962 if (scm_is_true (scm_call_1 ($2, $4)))
1965 MYREPARSE (@4, $2, REAL, $4);
1967 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1968 MYBACKUP (REAL, $4, @4);
1971 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup NUMBER_IDENTIFIER
1973 if (scm_is_true (scm_call_1 ($2, $4)))
1975 $$ = scm_cons ($4, $3);
1977 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1978 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1981 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' UNSIGNED
1983 SCM n = scm_difference ($5, SCM_UNDEFINED);
1984 if (scm_is_true (scm_call_1 ($2, n))) {
1986 MYREPARSE (@5, $2, REAL, n);
1988 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1989 t->set_property ("digit", $5);
1990 $$ = t->unprotect ();
1991 if (scm_is_true (scm_call_1 ($2, $$)))
1992 $$ = scm_cons ($$, $3);
1994 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
1995 MYBACKUP (UNSIGNED, $5, @5);
1996 parser->lexer_->push_extra_token (@4, '-');
2000 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' REAL
2002 SCM n = scm_difference ($5, SCM_UNDEFINED);
2003 if (scm_is_true (scm_call_1 ($2, n))) {
2004 MYREPARSE (@5, $2, REAL, n);
2007 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2008 MYBACKUP (REAL, n, @5);
2011 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup '-' NUMBER_IDENTIFIER
2013 SCM n = scm_difference ($5, SCM_UNDEFINED);
2014 if (scm_is_true (scm_call_1 ($2, n))) {
2015 $$ = scm_cons (n, $3);
2017 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2018 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
2021 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup DURATION_IDENTIFIER
2023 if (scm_is_true (scm_call_1 ($2, $4)))
2025 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
2028 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2029 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
2032 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup SCM_IDENTIFIER
2034 SCM res = try_string_variants ($2, $4);
2035 if (!SCM_UNBNDP (res))
2036 if (scm_is_pair (res)) {
2038 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2041 $$ = scm_cons (res, $3);
2043 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2044 MYBACKUP (SCM_IDENTIFIER, $4, @4);
2047 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup STRING
2049 SCM res = try_string_variants ($2, $4);
2050 if (!SCM_UNBNDP (res))
2051 if (scm_is_pair (res)) {
2053 MYREPARSE (@4, $2, SYMBOL_LIST, res);
2056 $$ = scm_cons (res, $3);
2058 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2059 MYBACKUP (STRING, $4, @4);
2062 | function_arglist_backup REPARSE pitch_or_music
2064 if (scm_is_true (scm_call_1 ($2, $3)))
2065 $$ = scm_cons ($3, $1);
2067 $$ = check_scheme_arg (parser, @3,
2068 make_music_from_simple
2072 | function_arglist_backup REPARSE bare_number_common
2074 $$ = check_scheme_arg (parser, @3,
2077 | function_arglist_backup REPARSE duration_length
2079 $$ = check_scheme_arg (parser, @3,
2082 | function_arglist_backup REPARSE symbol_list_arg
2084 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2089 function_arglist_nonbackup
2090 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
2092 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2096 function_arglist_skip_nonbackup:
2097 function_arglist_nonbackup
2098 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
2100 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2104 // Partial function arglists are returned just in their incomplete
2105 // state: when combined with the music function, the missing parts of
2106 // the signature can be reconstructed
2108 // To serve as a partial arglist, the argument list must absolutely
2109 // _not_ be in "skipping optional arguments" mode since then there is
2110 // some backup token that has nowhere to go before \etc.
2112 // So we can skim off an arbitrary number of arguments from the end of
2113 // the argument list. The argument list remaining afterwards has to
2114 // be in not-skipping-optional-arguments mode.
2116 function_arglist_partial:
2117 EXPECT_SCM function_arglist_optional
2121 | EXPECT_SCM function_arglist_partial_optional
2125 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_nonbackup
2129 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial
2135 function_arglist_partial_optional:
2136 EXPECT_SCM function_arglist_optional
2140 | EXPECT_SCM function_arglist_partial_optional
2144 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup
2148 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_partial_optional
2154 function_arglist_common:
2155 EXPECT_NO_MORE_ARGS {
2158 | EXPECT_SCM function_arglist_optional embedded_scm_arg
2160 if (scm_is_true (scm_call_1 ($1, $3)))
2161 $$ = scm_cons ($3, $2);
2163 $$ = check_scheme_arg (parser, @3,
2164 make_music_from_simple
2168 | EXPECT_SCM function_arglist_optional bare_number_common
2170 $$ = check_scheme_arg (parser, @3,
2173 | EXPECT_SCM function_arglist_optional post_event_nofinger
2175 $$ = check_scheme_arg (parser, @3,
2178 | EXPECT_SCM function_arglist_optional '-' NUMBER_IDENTIFIER
2180 SCM n = scm_difference ($4, SCM_UNDEFINED);
2181 $$ = check_scheme_arg (parser, @4, n, $2, $1);
2183 | function_arglist_common_reparse REPARSE SCM_ARG
2185 $$ = check_scheme_arg (parser, @3,
2188 | function_arglist_common_reparse REPARSE lyric_element_music
2190 $$ = check_scheme_arg (parser, @3,
2193 | function_arglist_common_reparse REPARSE pitch_or_music
2195 if (scm_is_true (scm_call_1 ($2, $3)))
2196 $$ = scm_cons ($3, $1);
2198 $$ = check_scheme_arg (parser, @3,
2199 make_music_from_simple
2203 | function_arglist_common_reparse REPARSE bare_number_common
2205 $$ = check_scheme_arg (parser, @3,
2208 | function_arglist_common_reparse REPARSE duration_length
2210 $$ = check_scheme_arg (parser, @3,
2213 | function_arglist_common_reparse REPARSE symbol_list_arg
2215 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
2219 function_arglist_common_reparse:
2220 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
2223 SCM res = try_string_variants ($1, $3);
2224 if (!SCM_UNBNDP (res))
2225 if (scm_is_pair (res))
2226 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2228 MYREPARSE (@3, $1, SCM_ARG, res);
2229 else if (scm_is_true
2231 ($1, make_music_from_simple (parser, @3, $3))))
2232 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2234 // This is going to flag a syntax error, we
2235 // know the predicate to be false.
2236 MYREPARSE (@3, $1, SCM_ARG, $3);
2238 | EXPECT_SCM function_arglist_optional pitch
2243 ($1, make_music_from_simple
2245 MYREPARSE (@3, $1, PITCH_IDENTIFIER, $3);
2247 MYREPARSE (@3, $1, SCM_ARG, $3);
2249 | EXPECT_SCM function_arglist_optional steno_tonic_pitch
2254 ($1, make_music_from_simple
2256 MYREPARSE (@3, $1, TONICNAME_PITCH, $3);
2258 MYREPARSE (@3, $1, SCM_ARG, $3);
2260 | EXPECT_SCM function_arglist_optional STRING
2263 SCM res = try_string_variants ($1, $3);
2264 if (!SCM_UNBNDP (res))
2265 if (scm_is_pair (res))
2266 MYREPARSE (@3, $1, SYMBOL_LIST, res);
2268 MYREPARSE (@3, $1, SCM_ARG, res);
2269 else if (scm_is_true
2271 ($1, make_music_from_simple (parser, @3, $3))))
2272 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2274 // This is going to flag a syntax error, we
2275 // know the predicate to be false.
2276 MYREPARSE (@3, $1, SCM_ARG, $3);
2278 | EXPECT_SCM function_arglist_optional full_markup
2281 if (scm_is_true (scm_call_1 ($1, $3)))
2282 MYREPARSE (@3, $1, SCM_ARG, $3);
2283 else if (scm_is_true
2285 ($1, make_music_from_simple (parser, @3, $3))))
2286 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
2288 // This is going to flag a syntax error, we
2289 // know the predicate to be false.
2290 MYREPARSE (@3, $1, SCM_ARG, $3);
2292 | EXPECT_SCM function_arglist_optional UNSIGNED
2295 if (scm_is_true (scm_call_1 ($1, $3)))
2296 MYREPARSE (@3, $1, REAL, $3);
2298 SCM d = make_duration ($3);
2299 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
2300 MYREPARSE (@3, $1, REAL, $3);
2302 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
2305 | EXPECT_SCM function_arglist_optional DURATION_IDENTIFIER
2308 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
2310 | EXPECT_SCM function_arglist_optional '-' UNSIGNED
2313 SCM n = scm_difference ($4, SCM_UNDEFINED);
2314 if (scm_is_true (scm_call_1 ($1, n)))
2315 MYREPARSE (@4, $1, REAL, n);
2317 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
2318 t->set_property ("digit", $4);
2319 SCM m = t->unprotect ();
2320 if (scm_is_true (scm_call_1 ($1, m)))
2321 MYREPARSE (@4, $1, SCM_ARG, m);
2323 MYREPARSE (@4, $1, SCM_ARG, $4);
2326 | EXPECT_SCM function_arglist_optional '-' REAL
2329 SCM n = scm_difference ($4, SCM_UNDEFINED);
2330 MYREPARSE (@4, $1, REAL, n);
2334 function_arglist_optional:
2335 function_arglist_backup
2336 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
2338 $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
2340 | function_arglist_skip_backup BACKUP
2343 function_arglist_skip_backup:
2344 function_arglist_backup
2345 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
2347 $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
2351 music_function_call:
2352 MUSIC_FUNCTION function_arglist {
2353 $$ = MAKE_SYNTAX (music_function, @$,
2360 /**/ { $$ = SCM_EOL; }
2361 | '=' simple_string {
2366 // We must not have lookahead tokens parsed in lyric mode. In order
2367 // to save confusion, we take almost the same set as permitted with
2368 // \lyricmode and/or \lyrics. However, music identifiers are also
2369 // allowed, and they obviously do not require switching into lyrics
2370 // mode for parsing.
2374 parser->lexer_->push_lyric_state ();
2375 } grouped_music_list
2377 parser->lexer_->pop_state ();
2384 mode_changing_head grouped_music_list {
2385 if (scm_is_eq ($1, ly_symbol2scm ("chords")))
2387 $$ = MAKE_SYNTAX (unrelativable_music, @$, $2);
2393 parser->lexer_->pop_state ();
2395 | mode_changing_head_with_context optional_context_mod grouped_music_list {
2396 Context_mod *ctxmod = unsmob<Context_mod> ($2);
2399 mods = ctxmod->get_mods ();
2400 $$ = MAKE_SYNTAX (context_specification, @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2401 if (scm_is_eq ($1, ly_symbol2scm ("ChordNames")))
2403 $$ = MAKE_SYNTAX (unrelativable_music, @$, $$);
2405 parser->lexer_->pop_state ();
2411 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2412 parser->lexer_->push_note_state (nn);
2414 $$ = ly_symbol2scm ("notes");
2418 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2419 parser->lexer_->push_note_state (nn);
2421 $$ = ly_symbol2scm ("drums");
2424 parser->lexer_->push_figuredbass_state ();
2426 $$ = ly_symbol2scm ("figures");
2429 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2430 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2431 nn = parser->lexer_->lookup_identifier ("pitchnames");
2432 parser->lexer_->push_chord_state (nn);
2433 $$ = ly_symbol2scm ("chords");
2437 { parser->lexer_->push_lyric_state ();
2438 $$ = ly_symbol2scm ("lyrics");
2442 mode_changing_head_with_context:
2444 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2445 parser->lexer_->push_note_state (nn);
2447 $$ = ly_symbol2scm ("DrumStaff");
2450 parser->lexer_->push_figuredbass_state ();
2452 $$ = ly_symbol2scm ("FiguredBass");
2455 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2456 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2457 nn = parser->lexer_->lookup_identifier ("pitchnames");
2458 parser->lexer_->push_chord_state (nn);
2459 $$ = ly_symbol2scm ("ChordNames");
2462 { parser->lexer_->push_lyric_state ();
2463 $$ = ly_symbol2scm ("Lyrics");
2468 CHANGE symbol '=' simple_string {
2469 $$ = MAKE_SYNTAX (context_change, @$, $2, $4);
2476 $$ = scm_reverse_x ($1, SCM_EOL);
2478 | symbol_list_rev property_path {
2479 $$ = scm_reverse_x ($1, $2);
2485 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2488 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2490 | OVERRIDE property_path '=' scalar {
2491 if (scm_ilength ($2) < 2) {
2492 parser->parser_error (@2, _("bad grob property path"));
2495 $$ = scm_cons (ly_symbol2scm ("push"),
2496 scm_cons2 (scm_car ($2),
2501 | REVERT revert_arg {
2502 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2506 // This is all quite awkward for the sake of substantial backward
2507 // compatibility while at the same time allowing a more "natural" form
2508 // of specification not separating grob specification from grob
2509 // property path. The purpose of this definition of revert_arg is to
2510 // allow the symbol list which specifies grob and property to revert
2511 // to be optionally be split into two parts after the grob (which in
2512 // this case is just the first element of the list). symbol_list_part
2513 // is only one path component, but it can be parsed without lookahead,
2514 // so we can follow it with a synthetic BACKUP token when needed. If
2515 // the first symbol_list_part already contains multiple elements (only
2516 // possible if a Scheme expression provides them), we just parse for
2517 // additional elements introduced by '.', which is what the
2518 // SYMBOL_LIST backup in connection with the immediately following
2519 // rule using symbol_list_arg does.
2521 // As long as we don't have our coffers filled with both grob and at
2522 // least one grob property specification, the rest of the required
2523 // symbol list chain may be provided either with or without a leading
2524 // dot. This is for both allowing the traditional
2525 // \revert Accidental #'color
2526 // as well as well as the "naive" form
2527 // \revert Accidental.color
2530 revert_arg_backup BACKUP symbol_list_arg
2539 if (scm_is_null ($1)
2540 || scm_is_null (scm_cdr ($1)))
2541 MYBACKUP (SCM_ARG, $1, @1);
2543 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2547 // revert_arg_part delivers results in reverse
2550 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2552 $$ = scm_append_x (scm_list_2 ($5, $3));
2554 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2556 $$ = scm_append_x (scm_list_2 ($4, $3));
2561 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2562 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2564 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2565 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2566 | DENIES { $$ = ly_symbol2scm ("denies"); }
2568 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2569 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2570 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2571 | NAME { $$ = ly_symbol2scm ("context-name"); }
2575 property_operation { $$ = $1; }
2576 | context_def_mod STRING {
2577 $$ = scm_list_2 ($1, $2);
2579 | context_def_mod embedded_scm
2581 if (!scm_is_string ($2)
2582 && ly_symbol2scm ("consists") != $1
2583 && ly_symbol2scm ("remove") != $1)
2586 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2590 $$ = scm_list_2 ($1, $2);
2595 // If defined, at least two members.
2599 SCM l = scm_reverse_x ($1, SCM_EOL);
2602 (scm_object_property (scm_car (l),
2603 ly_symbol2scm ("is-grob?"))))
2604 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2605 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2606 parser->parser_error (@1, _ ("bad grob property path"));
2613 // If defined, at least three members
2617 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2619 parser->parser_error (@1, _ ("bad grob property path"));
2623 | grob_prop_spec property_path
2625 if (!SCM_UNBNDP ($1)) {
2626 $$ = scm_append_x (scm_list_2 ($1, $2));
2627 if (scm_is_null (scm_cddr ($$))) {
2628 parser->parser_error (@$, _ ("bad grob property path"));
2636 // Exactly two elements or undefined
2640 SCM l = scm_reverse_x ($1, SCM_EOL);
2641 switch (scm_ilength (l)) {
2643 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2647 parser->parser_error (@1, _ ("bad context property path"));
2655 // This is all quite awkward for the sake of substantial backward
2656 // compatibility while at the same time allowing a more "natural" form
2657 // of specification not separating grob specification from grob
2658 // property path. The purpose of this definition of
2659 // simple_revert_context is to allow the symbol list which specifies
2660 // grob and property to revert to be optionally be split into two
2661 // parts after the grob (which may be preceded by a context
2662 // specification, a case which we distinguish by checking whether the
2663 // first symbol is a valid grob symbol instead).
2665 // See revert_arg above for the main work horse of this arrangement.
2666 // simple_revert_context just caters for the context and delegates the
2667 // rest of the job to revert_arg.
2669 simple_revert_context:
2672 $1 = scm_reverse_x ($1, SCM_EOL);
2673 if (scm_is_null ($1)
2675 (scm_object_property (scm_car ($1),
2676 ly_symbol2scm ("is-grob?")))) {
2677 $$ = ly_symbol2scm ("Bottom");
2678 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER, $1);
2681 parser->lexer_->push_extra_token (@1, SCM_IDENTIFIER,
2688 OVERRIDE grob_prop_path '=' scalar {
2689 if (SCM_UNBNDP ($2))
2690 $$ = MAKE_SYNTAX (void_music, @$);
2692 $$ = MAKE_SYNTAX (property_override, @$,
2697 | REVERT simple_revert_context revert_arg {
2698 $$ = MAKE_SYNTAX (property_revert, @$, $2, $3);
2700 | SET context_prop_spec '=' scalar {
2701 if (SCM_UNBNDP ($2))
2702 $$ = MAKE_SYNTAX (void_music, @$);
2704 $$ = MAKE_SYNTAX (property_set, @$,
2709 | UNSET context_prop_spec {
2710 if (SCM_UNBNDP ($2))
2711 $$ = MAKE_SYNTAX (void_music, @$);
2713 $$ = MAKE_SYNTAX (property_unset, @$,
2729 if (Text_interface::is_markup ($1)) {
2732 parser->parser_error (@1, (_ ("markup expected")));
2733 $$ = scm_string (SCM_EOL);
2738 simple_string: STRING
2741 if (scm_is_string ($1)) {
2744 parser->parser_error (@1, (_ ("simple string expected")));
2745 $$ = scm_string (SCM_EOL);
2752 $$ = scm_string_to_symbol ($1);
2756 // This is a bit of overkill but makes the same
2757 // routine responsible for all symbol interpretations.
2758 $$ = try_string_variants (Guile_user::symbol_p, $1);
2759 if (SCM_UNBNDP ($$))
2761 parser->parser_error (@1, (_ ("symbol expected")));
2762 // Generate a unique symbol in case it is used
2763 // for an assignment or similar
2764 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2774 // The following is a rather defensive variant of admitting
2775 // negative numbers: the grammar would permit number_factor or
2776 // even number_expression. However, function arguments allow
2777 // only this simple kind of negative number, so to have things
2778 // like \tweak and \override behave reasonably similar, it
2779 // makes sense to rule out things like -- which are rather an
2780 // accent in function argument contexts.
2783 $$ = scm_difference ($2, SCM_UNDEFINED);
2789 simple_element post_events {
2790 // Let the rhythmic music iterator sort this mess out.
2791 if (scm_is_pair ($2)) {
2792 unsmob<Music> ($$)->set_property ("articulations",
2793 scm_reverse_x ($2, SCM_EOL));
2796 | CHORD_REPETITION optional_notemode_duration post_events {
2798 i.set_location (@1, @3);
2799 $$ = MAKE_SYNTAX (repetition_chord, i,
2800 $2, scm_reverse_x ($3, SCM_EOL));
2802 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2804 i.set_location (@1, @3);
2805 $$ = MAKE_SYNTAX (multi_measure_rest, i, $2,
2806 scm_reverse_x ($3, SCM_EOL));
2809 | note_chord_element
2814 chord_body optional_notemode_duration post_events
2816 Music *m = unsmob<Music> ($1);
2817 SCM dur = unsmob<Duration> ($2)->smobbed_copy ();
2818 SCM es = m->get_property ("elements");
2819 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2821 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2822 unsmob<Music> (scm_car (s))->set_property ("duration", dur);
2823 es = ly_append2 (es, postevs);
2825 m->set_property ("elements", es);
2826 m->set_spot (parser->lexer_->override_input (@$));
2827 $$ = m->self_scm ();
2832 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2834 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2836 | FIGURE_OPEN figure_list FIGURE_CLOSE
2838 $$ = MAKE_SYNTAX (event_chord, @$, scm_reverse_x ($2, SCM_EOL));
2842 chord_body_elements:
2843 /* empty */ { $$ = SCM_EOL; }
2844 | chord_body_elements chord_body_element {
2845 if (!SCM_UNBNDP ($2))
2846 $$ = scm_cons ($2, $1);
2851 pitch_or_tonic_pitch exclamations questions octave_check post_events
2853 bool q = to_boolean ($3);
2854 bool ex = to_boolean ($2);
2858 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2859 n->set_property ("pitch", $1);
2861 n->set_property ("cautionary", SCM_BOOL_T);
2863 n->set_property ("force-accidental", SCM_BOOL_T);
2865 if (scm_is_pair (post)) {
2866 SCM arts = scm_reverse_x (post, SCM_EOL);
2867 n->set_property ("articulations", arts);
2869 if (scm_is_number (check))
2871 int q = scm_to_int (check);
2872 n->set_property ("absolute-octave", scm_from_int (q-1));
2875 $$ = n->unprotect ();
2877 | DRUM_PITCH post_events {
2878 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2879 n->set_property ("drum-type", $1);
2881 if (scm_is_pair ($2)) {
2882 SCM arts = scm_reverse_x ($2, SCM_EOL);
2883 n->set_property ("articulations", arts);
2885 $$ = n->unprotect ();
2887 | music_function_chord_body
2889 Music *m = unsmob<Music> ($1);
2891 while (m && m->is_mus_type ("music-wrapper-music")) {
2892 $$ = m->get_property ("element");
2893 m = unsmob<Music> ($$);
2896 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2897 parser->parser_error (@$, _ ("not a rhythmic event"));
2903 music_function_chord_body:
2909 event_function_event:
2910 EVENT_FUNCTION function_arglist {
2911 $$ = MAKE_SYNTAX (music_function, @$,
2920 | post_events post_event {
2922 if (Music *m = unsmob<Music> ($2))
2924 if (m->is_mus_type ("post-event-wrapper"))
2926 for (SCM p = m->get_property ("elements");
2930 $$ = scm_cons (scm_car (p), $$);
2933 m->set_spot (parser->lexer_->override_input (@2));
2934 $$ = scm_cons ($2, $$);
2940 post_event_nofinger:
2941 direction_less_event {
2944 | script_dir music_function_call {
2946 if (!unsmob<Music> ($2)->is_mus_type ("post-event")) {
2947 parser->parser_error (@2, _ ("post-event expected"));
2948 $$ = SCM_UNSPECIFIED;
2949 } else if (!SCM_UNBNDP ($1))
2951 unsmob<Music> ($$)->set_property ("direction", $1);
2955 if (!parser->lexer_->is_lyric_state ())
2956 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2957 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2960 if (!parser->lexer_->is_lyric_state ())
2961 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2962 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2964 | script_dir direction_reqd_event {
2965 if (!SCM_UNBNDP ($1))
2967 Music *m = unsmob<Music> ($2);
2968 m->set_property ("direction", $1);
2972 | script_dir direction_less_event {
2973 if (!SCM_UNBNDP ($1))
2975 Music *m = unsmob<Music> ($2);
2976 m->set_property ("direction", $1);
2983 unsmob<Music> ($$)->set_property ("direction", scm_from_int (UP));
2988 unsmob<Music> ($$)->set_property ("direction", scm_from_int (DOWN));
2999 string_number_event:
3001 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
3002 s->set_property ("string-number", $1);
3003 $$ = s->unprotect ();
3007 direction_less_event:
3009 | EVENT_IDENTIFIER {
3013 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
3014 a->set_property ("tremolo-type", $1);
3015 $$ = a->unprotect ();
3017 | event_function_event
3020 direction_reqd_event:
3024 | script_abbreviation {
3025 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
3026 if (scm_is_string (s)) {
3027 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
3028 a->set_property ("articulation-type", s);
3029 $$ = a->unprotect ();
3031 Music *original = unsmob<Music> (s);
3032 if (original && original->is_mus_type ("post-event")) {
3033 Music *a = original->clone ();
3034 a->set_spot (parser->lexer_->override_input (@$));
3035 $$ = a->unprotect ();
3037 parser->parser_error (@1, _ ("expecting string or post-event as script definition"));
3038 $$ = MY_MAKE_MUSIC ("PostEvents", @$)->unprotect ();
3045 /**/ { $$ = SCM_EOL; }
3046 | '=' quotes { $$ = $2; }
3060 $$ = scm_from_int (1);
3063 $$ = scm_oneplus ($1);
3069 $$ = scm_from_int (-1);
3072 $$ = scm_oneminus ($1);
3077 NOTENAME_PITCH quotes {
3078 if (!scm_is_eq (SCM_INUM0, $2))
3080 Pitch p = *unsmob<Pitch> ($1);
3081 p = p.transposed (Pitch (scm_to_int ($2), 0));
3082 $$ = p.smobbed_copy ();
3092 TONICNAME_PITCH quotes {
3093 if (!scm_is_eq (SCM_INUM0, $2))
3095 Pitch p = *unsmob<Pitch> ($1);
3096 p = p.transposed (Pitch (scm_to_int ($2), 0));
3097 $$ = p.smobbed_copy ();
3104 | PITCH_IDENTIFIER quotes {
3105 if (!scm_is_eq (SCM_INUM0, $2))
3107 Pitch p = *unsmob<Pitch> ($1);
3108 p = p.transposed (Pitch (scm_to_int ($2), 0));
3109 $$ = p.smobbed_copy ();
3114 pitch_or_tonic_pitch:
3121 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3122 t->set_property ("text", $1);
3123 $$ = t->unprotect ();
3126 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3127 t->set_property ("text",
3128 make_simple_markup ($1));
3129 $$ = t->unprotect ();
3133 Music *m = unsmob<Music> ($1);
3134 if (m && m->is_mus_type ("post-event"))
3136 else if (Text_interface::is_markup ($1)) {
3137 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
3138 t->set_property ("text", $1);
3139 $$ = t->unprotect ();
3141 parser->parser_error (@1, _ ("not an articulation"));
3147 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
3148 t->set_property ("digit", $1);
3149 $$ = t->unprotect ();
3153 script_abbreviation:
3155 $$ = scm_from_ascii_string ("Hat");
3158 $$ = scm_from_ascii_string ("Plus");
3161 $$ = scm_from_ascii_string ("Dash");
3164 $$ = scm_from_ascii_string ("Bang");
3167 $$ = scm_from_ascii_string ("Larger");
3170 $$ = scm_from_ascii_string ("Dot");
3173 $$ = scm_from_ascii_string ("Underscore");
3178 '_' { $$ = scm_from_int (DOWN); }
3179 | '^' { $$ = scm_from_int (UP); }
3180 | '-' { $$ = SCM_UNDEFINED; }
3184 multiplied_duration {
3189 maybe_notemode_duration:
3193 | multiplied_duration {
3195 parser->default_duration_ = *unsmob<Duration> ($$);
3200 optional_notemode_duration:
3201 maybe_notemode_duration
3203 if (SCM_UNBNDP ($$))
3204 $$ = parser->default_duration_.smobbed_copy ();
3210 $$ = make_duration ($1, scm_to_int ($2));
3211 if (SCM_UNBNDP ($$))
3213 parser->parser_error (@1, _ ("not a duration"));
3214 $$ = Duration ().smobbed_copy ();
3217 | DURATION_IDENTIFIER dots {
3218 Duration *d = unsmob<Duration> ($1);
3219 Duration k (d->duration_log (),
3220 d->dot_count () + scm_to_int ($2));
3221 k = k.compressed (d->factor ());
3222 scm_remember_upto_here_1 ($1);
3223 $$ = k.smobbed_copy ();
3227 multiplied_duration:
3231 | multiplied_duration '*' UNSIGNED {
3232 $$ = unsmob<Duration> ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
3234 | multiplied_duration '*' FRACTION {
3235 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
3237 $$ = unsmob<Duration> ($$)->compressed (m).smobbed_copy ();
3246 $$ = scm_oneplus ($1);
3252 $$ = scm_from_int (parser->default_tremolo_type_);
3255 if (SCM_UNBNDP (make_duration ($2))) {
3256 parser->parser_error (@2, _ ("not a duration"));
3257 $$ = scm_from_int (parser->default_tremolo_type_);
3260 parser->default_tremolo_type_ = scm_to_int ($2);
3266 UNSIGNED { $$ = $1; }
3267 | STRING { $$ = $1; }
3268 | full_markup { $$ = $1; }
3271 // as an integer, it needs to be non-negative, and otherwise
3272 // it needs to be suitable as a markup.
3273 if (scm_is_integer ($1)
3274 ? scm_is_true (scm_negative_p ($1))
3275 : !Text_interface::is_markup ($1))
3277 parser->parser_error (@1, _ ("bass number expected"));
3283 figured_bass_alteration:
3284 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
3285 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
3286 | '!' { $$ = scm_from_int (0); }
3291 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3292 $$ = bfr->unprotect ();
3295 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
3296 $$ = bfr->self_scm ();
3298 if (scm_is_number ($1))
3299 bfr->set_property ("figure", $1);
3300 else if (Text_interface::is_markup ($1))
3301 bfr->set_property ("text", $1);
3307 unsmob<Music> ($1)->set_property ("bracket-stop", SCM_BOOL_T);
3309 | bass_figure figured_bass_alteration {
3310 Music *m = unsmob<Music> ($1);
3311 if (scm_to_double ($2)) {
3312 SCM salter = m->get_property ("alteration");
3313 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
3314 m->set_property ("alteration",
3315 scm_sum (alter, $2));
3317 m->set_property ("alteration", scm_from_int (0));
3320 | bass_figure figured_bass_modification {
3321 Music *m = unsmob<Music> ($1);
3322 m->set_property ($2, SCM_BOOL_T);
3327 figured_bass_modification:
3329 $$ = ly_symbol2scm ("augmented");
3332 $$ = ly_symbol2scm ("no-continuation");
3335 $$ = ly_symbol2scm ("diminished");
3338 $$ = ly_symbol2scm ("augmented-slash");
3348 unsmob<Music> ($$)->set_property ("bracket-start", SCM_BOOL_T);
3356 | figure_list br_bass_figure {
3357 $$ = scm_cons ($2, $1);
3362 /**/ { $$ = SCM_BOOL_F; }
3363 | REST { $$ = SCM_BOOL_T; }
3367 pitch exclamations questions octave_check maybe_notemode_duration optional_rest post_events {
3368 if (!parser->lexer_->is_note_state ())
3369 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3370 if (!SCM_UNBNDP ($2)
3372 || scm_is_number ($4)
3375 || scm_is_pair ($7))
3378 if (scm_is_true ($6))
3379 n = MY_MAKE_MUSIC ("RestEvent", @$);
3381 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3383 n->set_property ("pitch", $1);
3384 if (SCM_UNBNDP ($5))
3385 n->set_property ("duration",
3386 parser->default_duration_.smobbed_copy ());
3388 n->set_property ("duration", $5);
3390 if (scm_is_number ($4))
3392 int q = scm_to_int ($4);
3393 n->set_property ("absolute-octave", scm_from_int (q-1));
3396 if (to_boolean ($3))
3397 n->set_property ("cautionary", SCM_BOOL_T);
3398 if (to_boolean ($2) || to_boolean ($3))
3399 n->set_property ("force-accidental", SCM_BOOL_T);
3400 if (scm_is_pair ($7))
3401 n->set_property ("articulations",
3402 scm_reverse_x ($7, SCM_EOL));
3403 $$ = n->unprotect ();
3406 | new_chord post_events {
3407 if (!parser->lexer_->is_chord_state ())
3408 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3409 if (scm_is_pair ($2)) {
3410 if (unsmob<Pitch> ($1))
3411 $1 = make_chord_elements (@1,
3413 parser->default_duration_.smobbed_copy (),
3416 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
3418 $$ = MAKE_SYNTAX (event_chord, @1, elts);
3419 } else if (!unsmob<Pitch> ($1))
3420 $$ = MAKE_SYNTAX (event_chord, @1, $1);
3421 // A mere pitch drops through.
3426 DRUM_PITCH optional_notemode_duration {
3427 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3428 n->set_property ("duration", $2);
3429 n->set_property ("drum-type", $1);
3431 $$ = n->unprotect ();
3433 | RESTNAME optional_notemode_duration {
3435 if (ly_scm2string ($1) == "s") {
3437 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3440 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3443 ev->set_property ("duration", $2);
3444 $$ = ev->unprotect ();
3450 if (!parser->lexer_->is_lyric_state ())
3451 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3455 if (!parser->lexer_->is_lyric_state ())
3456 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3462 lyric_element_music:
3463 lyric_element optional_notemode_duration post_events {
3464 $$ = MAKE_SYNTAX (lyric_event, @$, $1, $2);
3465 if (scm_is_pair ($3))
3466 unsmob<Music> ($$)->set_property
3467 ("articulations", scm_reverse_x ($3, SCM_EOL));
3471 // Can return a single pitch rather than a list.
3473 steno_tonic_pitch maybe_notemode_duration {
3474 if (SCM_UNBNDP ($2))
3477 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3479 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3480 SCM its = scm_reverse_x ($4, SCM_EOL);
3481 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3489 | chord_items chord_item {
3490 $$ = scm_cons ($2, $$);
3496 $$ = ly_symbol2scm ("chord-colon");
3499 $$ = ly_symbol2scm ("chord-caret");
3501 | CHORD_SLASH steno_tonic_pitch {
3502 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3504 | CHORD_BASS steno_tonic_pitch {
3505 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3514 $$ = scm_reverse_x ($1, SCM_EOL);
3522 step_number { $$ = scm_cons ($1, SCM_EOL); }
3523 | step_numbers '.' step_number {
3524 $$ = scm_cons ($3, $$);
3530 $$ = make_chord_step ($1, 0);
3533 $$ = make_chord_step ($1, SHARP_ALTERATION);
3535 | UNSIGNED CHORD_MINUS {
3536 $$ = make_chord_step ($1, FLAT_ALTERATION);
3544 | unsigned_number '-' unsigned_number {
3545 $$ = scm_cons ($1, $3);
3552 TODO: should deprecate in favor of Scheme?
3556 number_expression '+' number_term {
3557 $$ = scm_sum ($1, $3);
3559 | number_expression '-' number_term {
3560 $$ = scm_difference ($1, $3);
3569 | number_factor '*' number_factor {
3570 $$ = scm_product ($1, $3);
3572 | number_factor '/' number_factor {
3573 $$ = scm_divide ($1, $3);
3578 '-' number_factor { /* %prec UNARY_MINUS */
3579 $$ = scm_difference ($2, SCM_UNDEFINED);
3587 | REAL NUMBER_IDENTIFIER
3589 $$ = scm_product ($1, $2);
3596 | UNSIGNED NUMBER_IDENTIFIER {
3597 $$ = scm_product ($1, $2);
3605 if (!scm_is_integer ($1)
3606 || scm_is_true (scm_negative_p ($1)))
3608 parser->parser_error (@1, _("not an unsigned integer"));
3614 if (!scm_is_integer ($1)
3615 || scm_is_true (scm_negative_p ($1)))
3617 parser->parser_error (@1, _("not an unsigned integer"));
3624 { $$ = SCM_UNDEFINED; }
3627 if (SCM_UNBNDP ($1))
3635 // This precedence rule is rather weird. It triggers when '!' is
3636 // encountered after a pitch, and is used for deciding whether to save
3637 // this instead for a figure modification. This should not actually
3638 // occur in practice as pitches and figures are generated in different
3639 // modes. Using a greedy (%right) precedence makes sure that we don't
3640 // get stuck in a wrong interpretation.
3641 { $$ = SCM_UNDEFINED; } %prec ':'
3644 if (SCM_UNBNDP ($1))
3653 { parser->lexer_->push_markup_state (); }
3656 parser->lexer_->pop_state ();
3663 parser->lexer_->push_markup_state ();
3668 markup_mode markup_top {
3670 parser->lexer_->pop_state ();
3675 markup_mode markup_head_1_list ETC
3677 $$ = MAKE_SYNTAX (partial_markup, @2, $2);
3678 parser->lexer_->pop_state ();
3684 $$ = scm_list_2 (Lily::line_markup, $1);
3686 | markup_head_1_list simple_markup
3688 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3689 @2, $1, scm_list_1 ($2)));
3699 if (Text_interface::is_markup ($1))
3700 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3701 else if (Text_interface::is_markup_list ($1))
3702 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3704 parser->parser_error (@1, _ ("not a markup"));
3705 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3712 markup_composed_list {
3715 | markup_uncomposed_list
3718 markup_uncomposed_list:
3719 markup_braced_list {
3722 | markup_command_list {
3723 $$ = scm_list_1 ($1);
3725 | markup_scm MARKUPLIST_IDENTIFIER
3730 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3731 parser->lexer_->push_note_state (nn);
3732 } '{' score_body '}' {
3733 Score *sc = unsmob<Score> ($4);
3734 sc->origin ()->set_spot (@$);
3735 if (sc->defs_.empty ()) {
3736 Output_def *od = get_layout (parser);
3737 sc->add_output_def (od);
3740 $$ = scm_list_1 (scm_list_2 (Lily::score_lines_markup_list, $4));
3741 parser->lexer_->pop_state ();
3745 markup_composed_list:
3746 markup_head_1_list markup_uncomposed_list {
3747 $$ = MAKE_SYNTAX (composed_markup_list,
3753 '{' markup_braced_list_body '}' {
3754 $$ = scm_reverse_x ($2, SCM_EOL);
3758 markup_braced_list_body:
3759 /* empty */ { $$ = SCM_EOL; }
3760 | markup_braced_list_body markup {
3761 $$ = scm_cons ($2, $1);
3763 | markup_braced_list_body markup_list {
3764 $$ = scm_reverse_x ($2, $1);
3768 markup_command_list:
3769 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3770 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3774 markup_command_basic_arguments:
3775 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3776 $$ = scm_cons ($3, $2);
3778 | EXPECT_SCM markup_command_list_arguments embedded_scm {
3779 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3781 | EXPECT_NO_MORE_ARGS {
3786 markup_command_list_arguments:
3787 markup_command_basic_arguments { $$ = $1; }
3788 | EXPECT_MARKUP markup_command_list_arguments markup {
3789 $$ = scm_cons ($3, $2);
3794 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3795 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3800 markup_head_1_item {
3801 $$ = scm_list_1 ($1);
3803 | markup_head_1_list markup_head_1_item {
3804 $$ = scm_cons ($2, $1);
3810 $$ = make_simple_markup ($1);
3813 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3814 parser->lexer_->push_note_state (nn);
3815 } '{' score_body '}' {
3816 Score *sc = unsmob<Score> ($4);
3817 sc->origin ()->set_spot (@$);
3818 if (sc->defs_.empty ()) {
3819 Output_def *od = get_layout (parser);
3820 sc->add_output_def (od);
3823 $$ = scm_list_2 (Lily::score_markup, $4);
3824 parser->lexer_->pop_state ();
3826 | MARKUP_FUNCTION markup_command_basic_arguments {
3827 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3829 | markup_scm MARKUP_IDENTIFIER
3836 markup_head_1_list simple_markup
3838 $$ = scm_car (MAKE_SYNTAX (composed_markup_list,
3839 @2, $1, scm_list_1 ($2)));
3849 Lily_parser::set_yydebug (bool x)
3855 Lily_parser::do_yyparse ()
3857 return scm_c_with_fluid (Lily::f_parser,
3859 do_yyparse_trampoline,
3860 static_cast <void *>(this));
3864 Lily_parser::do_yyparse_trampoline (void *parser)
3866 SCM retval = SCM_UNDEFINED;
3867 yyparse (static_cast <Lily_parser *>(parser), &retval);
3875 It is a little strange to have this function in this file, but
3876 otherwise, we have to import music classes into the lexer.
3880 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3882 if (unsmob<Book> (sid)) {
3883 Book *book = unsmob<Book> (sid)->clone ();
3884 *destination = book->self_scm ();
3887 return BOOK_IDENTIFIER;
3888 } else if (scm_is_number (sid)) {
3890 return NUMBER_IDENTIFIER;
3891 } else if (unsmob<Context_def> (sid))
3893 *destination = unsmob<Context_def> (sid)->clone ()->unprotect ();
3894 return SCM_IDENTIFIER;
3895 } else if (unsmob<Context_mod> (sid)) {
3896 *destination = unsmob<Context_mod> (sid)->smobbed_copy ();
3897 return CONTEXT_MOD_IDENTIFIER;
3898 } else if (Music *mus = unsmob<Music> (sid)) {
3899 mus = mus->clone ();
3900 *destination = mus->self_scm ();
3901 bool is_event = mus->is_mus_type ("post-event");
3903 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3904 } else if (unsmob<Pitch> (sid)) {
3905 *destination = unsmob<Pitch> (sid)->smobbed_copy ();
3906 return PITCH_IDENTIFIER;
3907 } else if (unsmob<Duration> (sid)) {
3908 *destination = unsmob<Duration> (sid)->smobbed_copy ();
3909 return DURATION_IDENTIFIER;
3910 } else if (unsmob<Output_def> (sid)) {
3911 *destination = unsmob<Output_def> (sid)->clone ()->unprotect ();
3912 return SCM_IDENTIFIER;
3913 } else if (unsmob<Score> (sid)) {
3914 *destination = unsmob<Score> (sid)->clone ()->unprotect ();
3915 return SCM_IDENTIFIER;
3922 get_next_unique_context_id ()
3924 return scm_from_ascii_string ("$uniqueContextId");
3929 get_next_unique_lyrics_context_id ()
3931 static int new_context_count;
3933 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3934 return scm_from_ascii_string (s);
3937 // check_scheme_arg checks one argument with a given predicate for use
3938 // in an argument list and throws a syntax error if it is unusable.
3939 // The argument is prepended to the argument list in any case. After
3940 // throwing a syntax error, the argument list is terminated with #f as
3941 // its last cdr in order to mark it as uncallable while not losing
3942 // track of its total length.
3944 // There are a few special considerations: if optional argument disp
3945 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3946 // instead of arg in a prospective error message. This is useful if
3947 // arg is not the actual argument but rather a transformation of it.
3949 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3950 // and an error message using disp is produced unconditionally.
3952 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3953 SCM arg, SCM args, SCM pred, SCM disp)
3955 if (SCM_UNBNDP (arg))
3956 args = scm_cons (disp, args);
3958 args = scm_cons (arg, args);
3959 if (scm_is_true (scm_call_1 (pred, arg)))
3962 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3963 MAKE_SYNTAX (argument_error, loc, scm_length (args), pred,
3964 SCM_UNBNDP (disp) ? arg : disp);
3965 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3969 SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
3971 if (Music *m = unsmob<Music> (arg))
3974 m->set_spot (parser->lexer_->override_input (loc));
3975 return m->unprotect ();
3981 try_string_variants (SCM pred, SCM str)
3983 // a matching predicate is always ok
3984 if (scm_is_true (scm_call_1 (pred, str)))
3986 // a symbol may be interpreted as a list of symbols if it helps
3987 if (scm_is_symbol (str)) {
3988 str = scm_list_1 (str);
3989 if (scm_is_true (scm_call_1 (pred, str)))
3991 return SCM_UNDEFINED;
3994 // If this cannot be a string representation of a symbol list,
3997 if (!is_regular_identifier (str, true))
3998 return SCM_UNDEFINED;
4000 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
4001 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
4002 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
4004 // Let's attempt the symbol list interpretation first.
4006 if (scm_is_true (scm_call_1 (pred, str)))
4009 // If there is just one symbol in the list, we might interpret
4010 // it as a single symbol
4012 if (scm_is_null (scm_cdr (str)))
4014 str = scm_car (str);
4015 if (scm_is_true (scm_call_1 (pred, str)))
4019 return SCM_UNDEFINED;
4023 is_regular_identifier (SCM id, bool multiple)
4025 if (!scm_is_string (id))
4028 string str = ly_scm2string (id);
4030 bool middle = false;
4032 for (string::iterator it=str.begin(); it != str.end (); it++)
4035 if ((c >= 'a' && c <= 'z')
4036 || (c >= 'A' && c <= 'Z')
4039 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
4048 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
4050 if (unsmob<Music> (simple))
4052 if (parser->lexer_->is_note_state ()) {
4053 if (scm_is_symbol (simple)) {
4054 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4055 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4056 n->set_property ("drum-type", simple);
4057 return n->unprotect ();
4059 if (unsmob<Pitch> (simple)) {
4060 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
4061 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
4062 n->set_property ("pitch", simple);
4063 return n->unprotect ();
4066 } else if (parser->lexer_->is_lyric_state ()) {
4067 if (Text_interface::is_markup (simple))
4068 return MAKE_SYNTAX (lyric_event, loc, simple,
4069 parser->default_duration_.smobbed_copy ());
4070 } else if (parser->lexer_->is_chord_state ()) {
4071 if (unsmob<Pitch> (simple))
4075 make_chord_elements (loc, simple,
4076 parser->default_duration_.smobbed_copy (),
4083 make_music_with_input (SCM name, Input where)
4085 Music *m = make_music_by_name (name);
4086 m->set_spot (where);
4091 make_simple_markup (SCM a)
4097 make_duration (SCM d, int dots)
4099 int t = scm_to_int (d);
4100 if (t > 0 && (t & (t-1)) == 0)
4101 return Duration (intlog2 (t), dots).smobbed_copy ();
4103 return SCM_UNDEFINED;
4107 make_chord_step (SCM step_scm, Rational alter)
4109 Pitch m (0, scm_to_int (step_scm) - 1, alter);
4111 // Notename/octave are normalized
4112 if (m.get_notename () == 6)
4113 m = m.transposed (Pitch (0, 0, FLAT_ALTERATION));
4115 return m.smobbed_copy ();
4120 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
4122 SCM res = Lily::construct_chord_elements (pitch, dur, modification_list);
4123 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
4125 unsmob<Music> (scm_car (s))->set_spot (loc);
4131 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
4133 Lily_lexer *lex = parser->lexer_;
4137 int tok = lex->pop_extra_token ();
4140 lex->prepare_for_next_token ();
4141 return lex->yylex ();