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--2012 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 char *p = scm_to_locale_string \
45 (scm_simple_format (SCM_BOOL_F, \
46 scm_from_locale_string ("~S"), \
47 scm_list_1 (value))); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 /* ADDLYRICS needs to have lower precedence than argument scanning,
84 * or we won't be able to tell music apart from closed_music without
85 * lookahead in the context of function calls.
90 /* \default is only applied after exhausting function arguments */
92 %nonassoc FUNCTION_ARGLIST
94 /* expressions with units are permitted into argument lists */
96 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
97 UNSIGNED REAL DURATION_IDENTIFIER ':'
99 /* The above are the symbols that can start optional function arguments
100 that are recognized in the grammar rather than by predicate
103 %nonassoc NUMBER_IDENTIFIER '/'
105 /* Number-unit expressions, where permitted, are concatenated into
106 * function arguments, just like fractions and tremoli. Tremoli must
107 * not have higher precedence than UNSIGNED, or Lilypond will not
108 * join ':' with a following optional number.
121 %{ // -*-Fundamental-*-
126 * The rules for who is protecting what are very shady. Uniformise
129 * There are too many lexical modes?
140 #include "context-def.hh"
141 #include "context-mod.hh"
142 #include "dimensions.hh"
143 #include "file-path.hh"
145 #include "international.hh"
146 #include "lily-guile.hh"
147 #include "lily-lexer.hh"
148 #include "lily-parser.hh"
152 #include "output-def.hh"
153 #include "paper-book.hh"
154 #include "scm-hash.hh"
156 #include "text-interface.hh"
160 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
162 parser->parser_error (*i, s);
165 #define MYBACKUP(Token, Value, Location) \
167 if (yychar == YYEMPTY) \
170 parser->lexer_->push_extra_token (Token, Value); \
171 parser->lexer_->push_extra_token (BACKUP); \
173 parser->parser_error \
174 (Location, _("Too much lookahead")); \
179 #define MYREPARSE(Location, Pred, Token, Value) \
181 if (yychar == YYEMPTY) \
183 parser->lexer_->push_extra_token (Token, Value); \
184 parser->lexer_->push_extra_token (REPARSE, \
187 parser->parser_error \
188 (Location, _("Too much lookahead")); \
197 #define MY_MAKE_MUSIC(x, spot) \
198 make_music_with_input (ly_symbol2scm (x), \
199 parser->lexer_->override_input (spot))
202 - Don't use lily module, create a new module instead.
203 - delay application of the function
205 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
206 scm_apply_0 (proc, args)
207 /* Syntactic Sugar. */
208 #define MAKE_SYNTAX(name, location, ...) \
209 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
210 #define START_MAKE_SYNTAX(name, ...) \
211 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
212 #define FINISH_MAKE_SYNTAX(start, location, ...) \
213 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
215 SCM get_next_unique_context_id ();
216 SCM get_next_unique_lyrics_context_id ();
223 #define _(x) gettext (x)
227 static Music *make_music_with_input (SCM name, Input where);
228 SCM check_scheme_arg (Lily_parser *parser, Input loc,
229 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
230 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
231 SCM loc_on_music (Input loc, SCM arg);
232 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
233 SCM make_chord_step (SCM step, Rational alter);
234 SCM make_simple_markup (SCM a);
235 SCM make_duration (SCM t, int dots = 0);
236 bool is_regular_identifier (SCM id, bool multiple=false);
237 SCM try_string_variants (SCM pred, SCM str);
238 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
242 /* The third option is an alias that will be used to display the
243 syntax error. Bison CVS now correctly handles backslash escapes.
245 FIXME: Bison needs to translate some of these, eg, STRING.
249 /* Keyword tokens with plain escaped name. */
250 %token END_OF_FILE 0 "end of input"
251 %token ACCEPTS "\\accepts"
252 %token ADDLYRICS "\\addlyrics"
253 %token ALIAS "\\alias"
254 %token ALTERNATIVE "\\alternative"
256 %token BOOKPART "\\bookpart"
257 %token CHANGE "\\change"
258 %token CHORDMODE "\\chordmode"
259 %token CHORDS "\\chords"
260 %token CONSISTS "\\consists"
261 %token CONTEXT "\\context"
262 %token DEFAULT "\\default"
263 %token DEFAULTCHILD "\\defaultchild"
264 %token DENIES "\\denies"
265 %token DESCRIPTION "\\description"
266 %token DRUMMODE "\\drummode"
267 %token DRUMS "\\drums"
268 %token FIGUREMODE "\\figuremode"
269 %token FIGURES "\\figures"
270 %token HEADER "\\header"
271 %token INVALID "\\version-error"
272 %token LAYOUT "\\layout"
273 %token LYRICMODE "\\lyricmode"
274 %token LYRICS "\\lyrics"
275 %token LYRICSTO "\\lyricsto"
276 %token MARKUP "\\markup"
277 %token MARKUPLIST "\\markuplist"
280 %token NOTEMODE "\\notemode"
281 %token OVERRIDE "\\override"
282 %token PAPER "\\paper"
283 %token REMOVE "\\remove"
284 %token REPEAT "\\repeat"
286 %token REVERT "\\revert"
287 %token SCORE "\\score"
288 %token SEQUENTIAL "\\sequential"
290 %token SIMULTANEOUS "\\simultaneous"
291 %token TEMPO "\\tempo"
293 %token UNSET "\\unset"
296 /* Keyword token exceptions. */
297 %token NEWCONTEXT "\\new"
300 /* Other string tokens. */
302 %token CHORD_BASS "/+"
303 %token CHORD_CARET "^"
304 %token CHORD_COLON ":"
305 %token CHORD_MINUS "-"
306 %token CHORD_SLASH "/"
307 %token ANGLE_OPEN "<"
308 %token ANGLE_CLOSE ">"
309 %token DOUBLE_ANGLE_OPEN "<<"
310 %token DOUBLE_ANGLE_CLOSE ">>"
311 %token E_BACKSLASH "\\"
312 %token E_EXCLAMATION "\\!"
317 If we give names, Bison complains.
319 %token FIGURE_CLOSE /* "\\>" */
320 %token FIGURE_OPEN /* "\\<" */
321 %token FIGURE_SPACE "_"
324 %token MULTI_MEASURE_REST
330 /* Artificial tokens, for more generic function syntax */
331 %token EXPECT_MARKUP "markup?"
332 %token EXPECT_SCM "scheme?"
333 %token BACKUP "(backed-up?)"
334 %token REPARSE "(reparsed?)"
335 %token EXPECT_MARKUP_LIST "markup-list?"
336 %token EXPECT_OPTIONAL "optional?"
337 /* After the last argument. */
338 %token EXPECT_NO_MORE_ARGS;
340 /* An artificial token for parsing embedded Lilypond */
341 %token EMBEDDED_LILY "#{"
343 %token BOOK_IDENTIFIER
344 %token CHORD_MODIFIER
345 %token CHORD_REPETITION
346 %token CONTEXT_DEF_IDENTIFIER
347 %token CONTEXT_MOD_IDENTIFIER
349 %token PITCH_IDENTIFIER
350 %token DURATION_IDENTIFIER
351 %token EVENT_IDENTIFIER
352 %token EVENT_FUNCTION
355 %token MARKUP_FUNCTION
356 %token MARKUP_LIST_FUNCTION
357 %token MARKUP_IDENTIFIER
358 %token MARKUPLIST_IDENTIFIER
359 %token MUSIC_FUNCTION
360 %token MUSIC_IDENTIFIER
361 %token NOTENAME_PITCH
362 %token NUMBER_IDENTIFIER
363 %token OUTPUT_DEF_IDENTIFIER
368 %token SCM_IDENTIFIER
372 %token TONICNAME_PITCH
376 /* We don't assign precedence to / and *, because we might need varied
377 prec levels in different prods */
386 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
387 parser->lexer_->push_note_state (nn);
388 } embedded_lilypond {
389 parser->lexer_->pop_state ();
394 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
395 | lilypond toplevel_expression {
397 | lilypond assignment {
400 parser->error_level_ = 1;
403 parser->error_level_ = 1;
410 parser->lexer_->add_scope (get_header (parser));
412 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
415 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
416 scm_call_2 (proc, parser->self_scm (), $1);
419 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
420 scm_call_2 (proc, parser->self_scm (), $1);
423 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
424 scm_call_2 (proc, parser->self_scm (), $1);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
428 scm_call_2 (proc, parser->self_scm (), $1);
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
432 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
435 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
436 scm_call_2 (proc, parser->self_scm (), $1);
439 // Evaluate and ignore #xxx, as opposed to \xxx
440 parser->lexer_->eval_scm_token ($1);
442 | embedded_scm_active
444 SCM out = SCM_UNDEFINED;
445 if (Text_interface::is_markup ($1))
446 out = scm_list_1 ($1);
447 else if (Text_interface::is_markup_list ($1))
449 if (scm_is_pair (out))
451 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
452 scm_call_2 (proc, parser->self_scm (), out);
453 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
454 parser->parser_error (@1, _("bad expression type"));
458 Output_def * od = unsmob_output_def ($1);
460 if (od->c_variable ("is-paper") == SCM_BOOL_T)
461 id = ly_symbol2scm ("$defaultpaper");
462 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
463 id = ly_symbol2scm ("$defaultmidi");
464 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
465 id = ly_symbol2scm ("$defaultlayout");
467 parser->lexer_->set_identifier (id, $1);
474 $$ = parser->lexer_->eval_scm_token ($1);
484 embedded_scm_bare_arg:
488 $$ = parser->lexer_->eval_scm_token ($1);
491 | context_modification
493 | context_def_spec_block
499 /* The generic version may end in music, or not */
506 /* embedded_scm_arg is _not_ casting pitches to music by default, this
507 * has to be done by the function itself. Note that this may cause
508 * the results of scm_function_call or embedded_scm_bare_arg to be
509 * turned into music from pitches as well. Note that this creates a
510 * distinctly awkward situation for calculated drum pitches. Those
511 * are at the current point of time rejected as music constituents as
512 * they can't be distinguished from "proper" symbols.
516 embedded_scm_bare_arg
522 SCM_FUNCTION function_arglist {
523 $$ = MAKE_SYNTAX ("music-function", @$,
531 // FIXME: @$ does not contain a useful source location
532 // for empty rules, and the only token in the whole
533 // production, EMBEDDED_LILY, is synthetic and also
534 // contains no source location.
535 $$ = MAKE_SYNTAX ("void-music", @$);
538 | music_embedded music_embedded music_list {
539 $3 = scm_reverse_x ($3, SCM_EOL);
540 if (unsmob_music ($2))
541 $3 = scm_cons ($2, $3);
542 if (unsmob_music ($1))
543 $3 = scm_cons ($1, $3);
544 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
547 parser->error_level_ = 1;
548 $$ = SCM_UNSPECIFIED;
550 | INVALID embedded_lilypond {
551 parser->error_level_ = 1;
557 lilypond_header_body:
558 /* empty */ { $$ = SCM_UNSPECIFIED; }
559 | lilypond_header_body assignment {
562 | lilypond_header_body embedded_scm {
568 HEADER '{' lilypond_header_body '}' {
569 $$ = parser->lexer_->remove_scope ();
581 assignment_id '=' identifier_init {
582 parser->lexer_->set_identifier ($1, $3);
583 $$ = SCM_UNSPECIFIED;
585 | assignment_id property_path '=' identifier_init {
586 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
587 parser->lexer_->set_identifier (path, $4);
588 $$ = SCM_UNSPECIFIED;
598 | context_def_spec_block
600 | post_event_nofinger post_events
602 $$ = scm_reverse_x ($2, SCM_EOL);
603 if (Music *m = unsmob_music ($1))
605 if (m->is_mus_type ("post-event-wrapper"))
607 (scm_list_2 (m->get_property ("elements"),
610 $$ = scm_cons ($1, $$);
613 && scm_is_null (scm_cdr ($$)))
617 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
618 m->set_property ("elements", $$);
619 $$ = m->unprotect ();
627 | context_modification
630 context_def_spec_block:
631 CONTEXT '{' context_def_spec_body '}'
634 unsmob_context_def ($$)->origin ()->set_spot (@$);
642 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
643 parser->lexer_->push_note_state (nn);
647 parser->lexer_->pop_state ();
652 context_mod_embedded:
655 if (unsmob_music ($1)) {
656 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
657 $1 = scm_call_2 (proc, parser->self_scm (), $1);
659 if (unsmob_context_mod ($1))
662 parser->parser_error (@1, _ ("not a context mod"));
663 $$ = Context_mod ().smobbed_copy ();
669 context_def_spec_body:
671 $$ = Context_def::make_scm ();
673 | CONTEXT_DEF_IDENTIFIER {
676 | context_def_spec_body context_mod {
677 if (!SCM_UNBNDP ($2))
678 unsmob_context_def ($$)->add_context_mod ($2);
680 | context_def_spec_body context_modification {
681 Context_def *td = unsmob_context_def ($$);
682 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
683 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
684 td->add_context_mod (scm_car (m));
687 | context_def_spec_body context_mod_embedded {
688 Context_def *td = unsmob_context_def ($$);
689 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
690 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
691 td->add_context_mod (scm_car (m));
699 BOOK '{' book_body '}' {
701 unsmob_book ($$)->origin ()->set_spot (@$);
703 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
708 * Use 'handlers' like for toplevel-* stuff?
709 * grok \layout and \midi? */
712 Book *book = new Book;
713 init_papers (parser);
714 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
715 book->paper_->unprotect ();
716 push_paper (parser, book->paper_);
717 book->header_ = get_header (parser);
718 $$ = book->unprotect ();
719 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
722 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
724 | book_body paper_block {
725 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
726 set_paper (parser, unsmob_output_def ($2));
728 | book_body bookpart_block {
729 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
730 scm_call_2 (proc, $1, $2);
732 | book_body score_block {
733 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
734 scm_call_2 (proc, $1, $2);
736 | book_body composite_music {
737 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
738 scm_call_3 (proc, parser->self_scm (), $1, $2);
740 | book_body full_markup {
741 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
742 scm_call_2 (proc, $1, scm_list_1 ($2));
744 | book_body full_markup_list {
745 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
746 scm_call_2 (proc, $1, $2);
748 | book_body SCM_TOKEN {
749 // Evaluate and ignore #xxx, as opposed to \xxx
750 parser->lexer_->eval_scm_token ($2);
752 | book_body embedded_scm_active
754 SCM out = SCM_UNDEFINED;
755 if (Text_interface::is_markup ($2))
756 out = scm_list_1 ($2);
757 else if (Text_interface::is_markup_list ($2))
759 if (scm_is_pair (out))
761 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
762 scm_call_2 (proc, $1, out);
763 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
764 parser->parser_error (@2, _("bad expression type"));
768 parser->lexer_->add_scope (unsmob_book ($1)->header_);
771 Book *book = unsmob_book ($1);
773 book->scores_ = SCM_EOL;
774 book->bookparts_ = SCM_EOL;
779 BOOKPART '{' bookpart_body '}' {
781 unsmob_book ($$)->origin ()->set_spot (@$);
782 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
788 Book *book = new Book;
789 $$ = book->unprotect ();
790 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
793 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
795 | bookpart_body paper_block {
796 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
798 | bookpart_body score_block {
799 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
800 scm_call_2 (proc, $1, $2);
802 | bookpart_body composite_music {
803 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
804 scm_call_3 (proc, parser->self_scm (), $1, $2);
806 | bookpart_body full_markup {
807 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
808 scm_call_2 (proc, $1, scm_list_1 ($2));
810 | bookpart_body full_markup_list {
811 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
812 scm_call_2 (proc, $1, $2);
814 | bookpart_body SCM_TOKEN {
815 // Evaluate and ignore #xxx, as opposed to \xxx
816 parser->lexer_->eval_scm_token ($2);
818 | bookpart_body embedded_scm_active
820 SCM out = SCM_UNDEFINED;
821 if (Text_interface::is_markup ($2))
822 out = scm_list_1 ($2);
823 else if (Text_interface::is_markup_list ($2))
825 if (scm_is_pair (out))
827 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
828 scm_call_2 (proc, $1, out);
829 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
830 parser->parser_error (@2, _("bad expression type"));
834 Book *book = unsmob_book ($1);
835 if (!ly_is_module (book->header_))
836 book->header_ = ly_make_module (false);
837 parser->lexer_->add_scope (book->header_);
839 | bookpart_body error {
840 Book *book = unsmob_book ($1);
842 book->scores_ = SCM_EOL;
847 SCORE '{' score_body '}' {
854 SCM scorify = ly_lily_module_constant ("scorify-music");
855 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
857 unsmob_score ($$)->origin ()->set_spot (@$);
859 | embedded_scm_active {
861 if (unsmob_score ($1))
862 score = new Score (*unsmob_score ($1));
865 parser->parser_error (@1, _("score expected"));
867 unsmob_score ($$)->origin ()->set_spot (@$);
868 $$ = score->unprotect ();
872 Score *score = unsmob_score ($1);
873 if (!ly_is_module (score->get_header ()))
874 score->set_header (ly_make_module (false));
875 parser->lexer_->add_scope (score->get_header ());
877 | score_body output_def {
878 Output_def *od = unsmob_output_def ($2);
879 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
881 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
886 unsmob_score ($1)->add_output_def (od);
890 unsmob_score ($$)->error_found_ = true;
901 Output_def *od = unsmob_output_def ($1);
903 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
905 parser->parser_error (@1, _ ("need \\paper for paper block"));
906 $$ = get_paper (parser)->unprotect ();
913 output_def_body '}' {
916 parser->lexer_->remove_scope ();
917 parser->lexer_->pop_state ();
923 Output_def *p = get_paper (parser);
924 p->input_origin_ = @$;
925 parser->lexer_->add_scope (p->scope_);
926 $$ = p->unprotect ();
929 Output_def *p = get_midi (parser);
930 $$ = p->unprotect ();
931 parser->lexer_->add_scope (p->scope_);
934 Output_def *p = get_layout (parser);
936 parser->lexer_->add_scope (p->scope_);
937 $$ = p->unprotect ();
941 output_def_head_with_mode_switch:
943 parser->lexer_->push_initial_state ();
948 // We need this weird nonterminal because both music as well as a
949 // context definition can start with \context and the difference is
950 // only apparent after looking at the next token. If it is '{', there
951 // is still time to escape from notes mode.
953 music_or_context_def:
955 | context_def_spec_block
959 output_def_head_with_mode_switch '{' {
961 unsmob_output_def ($$)->input_origin_.set_spot (@$);
963 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
964 Output_def *o = unsmob_output_def ($3);
965 o->input_origin_.set_spot (@$);
967 parser->lexer_->remove_scope ();
968 parser->lexer_->add_scope (o->scope_);
970 | output_def_body assignment {
973 | output_def_body embedded_scm {
978 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
979 parser->lexer_->push_note_state (nn);
980 } music_or_context_def
982 parser->lexer_->pop_state ();
983 if (unsmob_context_def ($3))
984 assign_context_def (unsmob_output_def ($1), $3);
987 SCM proc = parser->lexer_->lookup_identifier
988 ("output-def-music-handler");
989 scm_call_3 (proc, parser->self_scm (),
993 | output_def_body error {
999 TEMPO steno_duration '=' tempo_range {
1000 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1002 | TEMPO scalar_closed steno_duration '=' tempo_range {
1003 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1006 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1011 The representation of a list is reversed to have efficient append. */
1017 | music_list music_embedded {
1018 if (unsmob_music ($2))
1019 $$ = scm_cons ($2, $1);
1021 | music_list error {
1022 Music *m = MY_MAKE_MUSIC("Music", @$);
1024 m->set_property ("error-found", SCM_BOOL_T);
1025 $$ = scm_cons (m->self_scm (), $1);
1026 m->unprotect (); /* UGH */
1033 $$ = scm_reverse_x ($2, SCM_EOL);
1038 | lyric_element_music
1044 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1045 parser->parser_error (@1, _ ("unexpected post-event"));
1046 $$ = SCM_UNSPECIFIED;
1049 | music_embedded_backup
1053 | music_embedded_backup BACKUP lyric_element_music
1059 music_embedded_backup:
1062 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1064 else if (Music *m = unsmob_music ($1)) {
1065 if (m->is_mus_type ("post-event")) {
1066 parser->parser_error
1067 (@1, _ ("unexpected post-event"));
1068 $$ = SCM_UNSPECIFIED;
1071 } else if (parser->lexer_->is_lyric_state ()
1072 && Text_interface::is_markup ($1))
1073 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1075 @$.warning (_ ("Ignoring non-music expression"));
1084 $$ = make_music_from_simple (parser, @1, $1);
1085 if (!unsmob_music ($$))
1086 parser->parser_error (@1, _ ("music expected"));
1088 | composite_music %prec COMPOSITE
1093 | composite_music %prec COMPOSITE
1097 REPEAT simple_string unsigned_number music
1099 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1101 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1103 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1108 SEQUENTIAL braced_music_list {
1109 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1111 | braced_music_list {
1112 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1117 SIMULTANEOUS braced_music_list {
1118 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1120 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1121 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1127 | music_property_def
1131 context_modification:
1134 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1135 parser->lexer_->push_note_state (nn);
1136 } '{' context_mod_list '}'
1138 parser->lexer_->pop_state ();
1141 | WITH CONTEXT_MOD_IDENTIFIER
1145 | CONTEXT_MOD_IDENTIFIER
1149 | WITH context_modification_arg
1151 if (unsmob_music ($2)) {
1152 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
1153 $2 = scm_call_2 (proc, parser->self_scm (), $2);
1155 if (unsmob_context_mod ($2))
1158 parser->parser_error (@2, _ ("not a context mod"));
1159 $$ = Context_mod ().smobbed_copy ();
1164 context_modification_arg:
1169 optional_context_mod:
1173 | context_modification
1181 $$ = Context_mod ().smobbed_copy ();
1183 | context_mod_list context_mod {
1184 if (!SCM_UNBNDP ($2))
1185 unsmob_context_mod ($1)->add_context_mod ($2);
1187 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1188 Context_mod *md = unsmob_context_mod ($2);
1190 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1192 | context_mod_list context_mod_embedded {
1193 unsmob_context_mod ($1)->add_context_mods
1194 (unsmob_context_mod ($2)->get_mods ());
1203 /* Music that can be parsed without lookahead */
1206 | complex_music_prefix closed_music
1208 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1210 | music_function_call_closed
1216 | grouped_music_list
1220 simultaneous_music { $$ = $1; }
1221 | sequential_music { $$ = $1; }
1224 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1225 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1226 and this rule returns the reversed list of arguments. */
1228 /* Function argument lists come in a number of flavors. Whenever
1229 * LilyPond has to pick between different flavors, the decision is
1230 * either made because of tokens it has already seen, or it is
1231 * postponed until tokens suitable for making the decision come up.
1232 * For postponing decisions, it may be necessary that the competing
1233 * rules are written in a way making them compatible until a decision
1234 * can be made. Sometimes this is done by putting common traits into
1235 * a separate "common" rule set.
1237 * function_arglist: a full argument list. Optional arguments at the
1238 * end of the list can only be skipped by writing \default in their
1241 * function_arglist_backup: an argument list ending in an optional
1242 * argument that may be skipped depending on its predicate.
1244 * function_arglist_skip: an argument list _not_ ending in an optional
1245 * argument that is actually taken.
1247 * function_arglist_nonbackup: an argument list ending in an optional
1248 * argument that may not be skipped because it is in end position and
1249 * has not been shortcircuited with \default.
1251 * function_arglist* / function_arglist_closed*: The closed variants
1252 * don't end in simple music expressions that might still accept
1253 * things like a duration or a postevent.
1256 function_arglist_skip:
1257 function_arglist_common
1258 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1260 $$ = scm_cons ($1, $3);
1261 } %prec FUNCTION_ARGLIST
1265 function_arglist_nonbackup_common:
1266 EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1268 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1270 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1272 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1274 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1276 SCM n = scm_difference ($5, SCM_UNDEFINED);
1277 if (scm_is_true (scm_call_1 ($2, n)))
1278 $$ = scm_cons (n, $3);
1280 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1281 t->set_property ("digit", $5);
1282 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1287 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1289 $$ = check_scheme_arg (parser, @4,
1290 scm_difference ($5, SCM_UNDEFINED),
1293 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1295 $$ = check_scheme_arg (parser, @4,
1296 scm_difference ($5, SCM_UNDEFINED),
1301 function_arglist_closed_nonbackup:
1302 function_arglist_nonbackup_common
1303 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1305 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1307 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1309 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1311 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1313 $$ = check_scheme_arg (parser, @4,
1314 try_string_variants ($2, $4),
1317 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1319 $$ = check_scheme_arg (parser, @4,
1320 try_string_variants ($2, $4),
1323 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1325 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1331 | SYMBOL_LIST '.' symbol_list_rev
1333 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1339 | symbol_list_rev '.' symbol_list_part
1341 $$ = scm_append_x (scm_list_2 ($3, $1));
1345 // symbol_list_part delivers elements in reverse copy.
1350 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1351 $$ = try_string_variants (sym_l_p, $1);
1352 if (SCM_UNBNDP ($$)) {
1353 parser->parser_error (@1, _("not a symbol"));
1356 $$ = scm_reverse ($$);
1361 symbol_list_element:
1367 function_arglist_nonbackup:
1368 function_arglist_nonbackup_common
1369 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1371 if (scm_is_true (scm_call_1 ($2, $4)))
1372 $$ = scm_cons ($4, $3);
1374 $$ = check_scheme_arg (parser, @4,
1375 make_music_from_simple
1379 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_common
1381 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1383 | function_arglist_nonbackup_reparse REPARSE duration_length
1385 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1387 | function_arglist_nonbackup_reparse REPARSE bare_number_common
1389 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1391 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1393 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1395 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1397 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1399 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1401 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1405 function_arglist_nonbackup_reparse:
1406 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1409 SCM res = try_string_variants ($2, $4);
1410 if (!SCM_UNBNDP (res))
1411 if (scm_is_pair (res))
1412 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1414 MYREPARSE (@4, $2, SCM_ARG, res);
1415 else if (scm_is_true
1417 ($2, make_music_from_simple
1419 MYREPARSE (@4, $2, STRING, $4);
1421 MYREPARSE (@4, $2, SCM_ARG, $4);
1423 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1426 SCM res = try_string_variants ($2, $4);
1427 if (!SCM_UNBNDP (res))
1428 if (scm_is_pair (res))
1429 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1431 MYREPARSE (@4, $2, SCM_ARG, res);
1432 else if (scm_is_true
1434 ($2, make_music_from_simple
1436 MYREPARSE (@4, $2, STRING, $4);
1438 MYREPARSE (@4, $2, SCM_ARG, $4);
1440 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1443 if (scm_is_true (scm_call_1 ($2, $4)))
1444 MYREPARSE (@4, $2, SCM_ARG, $4);
1445 else if (scm_is_true
1447 ($2, make_music_from_simple
1449 MYREPARSE (@4, $2, STRING, $4);
1451 MYREPARSE (@4, $2, SCM_ARG, $4);
1453 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed UNSIGNED
1456 if (scm_is_true (scm_call_1 ($2, $4)))
1457 MYREPARSE (@4, $2, REAL, $4);
1459 SCM d = make_duration ($4);
1460 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1461 MYREPARSE (@4, $2, REAL, $4); // trigger error
1463 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1466 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed DURATION_IDENTIFIER {
1468 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1472 function_arglist_keep:
1473 function_arglist_common
1474 | function_arglist_backup
1477 function_arglist_closed_keep:
1478 function_arglist_closed_common
1479 | function_arglist_backup
1482 function_arglist_backup:
1483 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1485 if (scm_is_true (scm_call_1 ($2, $4)))
1487 $$ = scm_cons ($4, $3);
1489 $$ = scm_cons (loc_on_music (@3, $1), $3);
1490 MYBACKUP (SCM_ARG, $4, @4);
1493 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1495 if (scm_is_true (scm_call_1 ($2, $4)))
1497 $$ = scm_cons ($4, $3);
1499 $$ = scm_cons (loc_on_music (@3, $1), $3);
1500 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1503 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep full_markup
1505 if (scm_is_true (scm_call_1 ($2, $4)))
1506 $$ = scm_cons ($4, $3);
1508 $$ = scm_cons (loc_on_music (@3, $1), $3);
1509 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1512 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1514 if (scm_is_true (scm_call_1 ($2, $4)))
1516 MYREPARSE (@4, $2, REAL, $4);
1519 SCM d = make_duration ($4);
1520 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
1522 $$ = scm_cons (loc_on_music (@3, $1), $3);
1523 MYBACKUP (UNSIGNED, $4, @4);
1525 MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
1530 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1532 if (scm_is_true (scm_call_1 ($2, $4)))
1535 MYREPARSE (@4, $2, REAL, $4);
1537 $$ = scm_cons (loc_on_music (@3, $1), $3);
1538 MYBACKUP (REAL, $4, @4);
1541 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1543 if (scm_is_true (scm_call_1 ($2, $4)))
1545 $$ = scm_cons ($4, $3);
1547 $$ = scm_cons (loc_on_music (@3, $1), $3);
1548 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1551 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1553 if (scm_is_true (scm_call_1 ($2, $4)))
1555 $$ = scm_cons ($4, $3);
1557 $$ = scm_cons (loc_on_music (@3, $1), $3);
1558 MYBACKUP (FRACTION, $4, @4);
1561 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1563 SCM n = scm_difference ($5, SCM_UNDEFINED);
1564 if (scm_is_true (scm_call_1 ($2, n))) {
1566 MYREPARSE (@5, $2, REAL, n);
1568 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1569 t->set_property ("digit", $5);
1570 $$ = t->unprotect ();
1571 if (scm_is_true (scm_call_1 ($2, $$)))
1572 $$ = scm_cons ($$, $3);
1574 $$ = scm_cons (loc_on_music (@3, $1), $3);
1575 MYBACKUP (UNSIGNED, $5, @5);
1576 parser->lexer_->push_extra_token ('-');
1581 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1583 SCM n = scm_difference ($5, SCM_UNDEFINED);
1584 if (scm_is_true (scm_call_1 ($2, n))) {
1585 MYREPARSE (@5, $2, REAL, n);
1588 $$ = scm_cons (loc_on_music (@3, $1), $3);
1589 MYBACKUP (REAL, n, @5);
1592 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1594 SCM n = scm_difference ($5, SCM_UNDEFINED);
1595 if (scm_is_true (scm_call_1 ($2, n))) {
1596 $$ = scm_cons (n, $3);
1598 $$ = scm_cons (loc_on_music (@3, $1), $3);
1599 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1602 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep PITCH_IDENTIFIER
1604 if (scm_is_true (scm_call_1 ($2, $4)))
1606 $$ = scm_cons ($4, $3);
1608 $$ = scm_cons (loc_on_music (@3, $1), $3);
1609 MYBACKUP (PITCH_IDENTIFIER, $4, @4);
1612 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep NOTENAME_PITCH
1614 if (scm_is_true (scm_call_1 ($2, $4)))
1616 MYREPARSE (@4, $2, NOTENAME_PITCH, $4);
1619 $$ = scm_cons (loc_on_music (@3, $1), $3);
1620 MYBACKUP (NOTENAME_PITCH, $4, @4);
1623 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep TONICNAME_PITCH
1625 if (scm_is_true (scm_call_1 ($2, $4)))
1627 MYREPARSE (@4, $2, TONICNAME_PITCH, $4);
1630 $$ = scm_cons (loc_on_music (@3, $1), $3);
1631 MYBACKUP (TONICNAME_PITCH, $4, @4);
1634 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep DURATION_IDENTIFIER
1636 if (scm_is_true (scm_call_1 ($2, $4)))
1638 MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
1641 $$ = scm_cons (loc_on_music (@3, $1), $3);
1642 MYBACKUP (DURATION_IDENTIFIER, $4, @4);
1645 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1647 SCM res = try_string_variants ($2, $4);
1648 if (!SCM_UNBNDP (res))
1649 if (scm_is_pair (res)) {
1651 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1654 $$ = scm_cons (res, $3);
1656 $$ = scm_cons (loc_on_music (@3, $1), $3);
1657 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1660 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1662 SCM res = try_string_variants ($2, $4);
1663 if (!SCM_UNBNDP (res))
1664 if (scm_is_pair (res)) {
1666 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1669 $$ = scm_cons (res, $3);
1671 $$ = scm_cons (loc_on_music (@3, $1), $3);
1672 MYBACKUP (STRING, $4, @4);
1675 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1677 $$ = scm_cons ($1, $3);
1678 MYBACKUP(0, SCM_UNDEFINED, @3);
1680 | function_arglist_backup REPARSE bare_number_common
1682 $$ = check_scheme_arg (parser, @3,
1685 | function_arglist_backup REPARSE duration_length
1687 $$ = check_scheme_arg (parser, @3,
1690 | function_arglist_backup REPARSE symbol_list_arg
1692 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1694 | function_arglist_backup REPARSE pitch_also_in_chords
1696 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1701 function_arglist_common
1702 | function_arglist_nonbackup
1705 function_arglist_common:
1706 function_arglist_bare
1707 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1709 if (scm_is_true (scm_call_1 ($1, $3)))
1710 $$ = scm_cons ($3, $2);
1712 $$ = check_scheme_arg (parser, @3,
1713 make_music_from_simple
1717 | EXPECT_SCM function_arglist_closed_optional bare_number_common
1719 $$ = check_scheme_arg (parser, @3,
1722 | EXPECT_SCM function_arglist_optional FRACTION
1724 $$ = check_scheme_arg (parser, @3,
1727 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1729 $$ = check_scheme_arg (parser, @3,
1732 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1734 SCM n = scm_difference ($4, SCM_UNDEFINED);
1735 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1737 | function_arglist_common_reparse REPARSE SCM_ARG
1739 $$ = check_scheme_arg (parser, @3,
1742 | function_arglist_common_reparse REPARSE lyric_element_music
1744 $$ = check_scheme_arg (parser, @3,
1747 | function_arglist_common_reparse REPARSE bare_number_common
1749 $$ = check_scheme_arg (parser, @3,
1752 | function_arglist_common_reparse REPARSE duration_length
1754 $$ = check_scheme_arg (parser, @3,
1757 | function_arglist_common_reparse REPARSE symbol_list_arg
1759 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1763 function_arglist_common_reparse:
1764 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1767 SCM res = try_string_variants ($1, $3);
1768 if (!SCM_UNBNDP (res))
1769 if (scm_is_pair (res))
1770 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1772 MYREPARSE (@3, $1, SCM_ARG, res);
1773 else if (scm_is_true
1775 ($1, make_music_from_simple (parser, @3, $3))))
1776 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1778 // This is going to flag a syntax error, we
1779 // know the predicate to be false.
1780 MYREPARSE (@3, $1, SCM_ARG, $3);
1782 | EXPECT_SCM function_arglist_optional STRING
1785 SCM res = try_string_variants ($1, $3);
1786 if (!SCM_UNBNDP (res))
1787 if (scm_is_pair (res))
1788 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1790 MYREPARSE (@3, $1, SCM_ARG, res);
1791 else if (scm_is_true
1793 ($1, make_music_from_simple (parser, @3, $3))))
1794 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1796 // This is going to flag a syntax error, we
1797 // know the predicate to be false.
1798 MYREPARSE (@3, $1, SCM_ARG, $3);
1800 | EXPECT_SCM function_arglist_optional full_markup
1803 if (scm_is_true (scm_call_1 ($1, $3)))
1804 MYREPARSE (@3, $1, SCM_ARG, $3);
1805 else if (scm_is_true
1807 ($1, make_music_from_simple (parser, @3, $3))))
1808 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1810 // This is going to flag a syntax error, we
1811 // know the predicate to be false.
1812 MYREPARSE (@3, $1, SCM_ARG, $3);
1814 | EXPECT_SCM function_arglist_closed_optional UNSIGNED
1817 if (scm_is_true (scm_call_1 ($1, $3)))
1818 MYREPARSE (@3, $1, REAL, $3);
1820 SCM d = make_duration ($3);
1821 if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($1, d)))
1822 MYREPARSE (@3, $1, REAL, $3);
1824 MYREPARSE (@3, $1, DURATION_IDENTIFIER, d);
1827 | EXPECT_SCM function_arglist_closed_optional DURATION_IDENTIFIER
1830 MYREPARSE (@3, $1, DURATION_IDENTIFIER, $3);
1832 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1835 SCM n = scm_difference ($4, SCM_UNDEFINED);
1836 if (scm_is_true (scm_call_1 ($1, n)))
1837 MYREPARSE (@4, $1, REAL, n);
1839 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1840 t->set_property ("digit", $4);
1841 SCM m = t->unprotect ();
1842 if (scm_is_true (scm_call_1 ($1, m)))
1843 MYREPARSE (@4, $1, SCM_ARG, m);
1845 MYREPARSE (@4, $1, SCM_ARG, $4);
1849 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1852 SCM n = scm_difference ($4, SCM_UNDEFINED);
1853 MYREPARSE (@4, $1, REAL, n);
1857 function_arglist_closed:
1858 function_arglist_closed_common
1859 | function_arglist_closed_nonbackup
1862 function_arglist_closed_common:
1863 function_arglist_bare
1864 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1866 $$ = check_scheme_arg (parser, @3,
1869 | EXPECT_SCM function_arglist_closed_optional bare_number_common_closed
1871 $$ = check_scheme_arg (parser, @3,
1874 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1876 $$ = check_scheme_arg (parser, @3,
1877 scm_difference ($4, SCM_UNDEFINED),
1880 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1882 $$ = check_scheme_arg (parser, @3,
1885 | EXPECT_SCM function_arglist_optional FRACTION
1887 $$ = check_scheme_arg (parser, @3,
1890 | function_arglist_common_reparse REPARSE SCM_ARG
1892 $$ = check_scheme_arg (parser, @3,
1895 | function_arglist_common_reparse REPARSE bare_number_common_closed
1897 $$ = check_scheme_arg (parser, @3,
1900 | function_arglist_common_reparse REPARSE symbol_list_arg
1902 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1906 function_arglist_optional:
1907 function_arglist_keep %prec FUNCTION_ARGLIST
1908 | function_arglist_backup BACKUP
1911 function_arglist_closed_optional:
1912 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1913 | function_arglist_backup BACKUP
1916 embedded_scm_closed:
1918 | scm_function_call_closed
1921 embedded_scm_arg_closed:
1922 embedded_scm_bare_arg
1923 | scm_function_call_closed
1927 scm_function_call_closed:
1928 SCM_FUNCTION function_arglist_closed {
1929 $$ = MAKE_SYNTAX ("music-function", @$,
1931 } %prec FUNCTION_ARGLIST
1934 function_arglist_bare:
1935 EXPECT_NO_MORE_ARGS {
1938 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1939 $$ = scm_cons ($1, $3);
1943 music_function_call:
1944 MUSIC_FUNCTION function_arglist {
1945 $$ = MAKE_SYNTAX ("music-function", @$,
1952 /**/ { $$ = SCM_EOL; }
1953 | '=' simple_string {
1960 | repeated_music { $$ = $1; }
1961 | re_rhythmed_music { $$ = $1; }
1962 | complex_music_prefix music
1964 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1968 complex_music_prefix:
1969 CONTEXT symbol optional_id optional_context_mod {
1970 Context_mod *ctxmod = unsmob_context_mod ($4);
1973 mods = ctxmod->get_mods ();
1974 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1976 | NEWCONTEXT symbol optional_id optional_context_mod {
1977 Context_mod *ctxmod = unsmob_context_mod ($4);
1980 mods = ctxmod->get_mods ();
1981 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1986 mode_changing_head grouped_music_list {
1987 if ($1 == ly_symbol2scm ("chords"))
1989 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1995 parser->lexer_->pop_state ();
1997 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1998 Context_mod *ctxmod = unsmob_context_mod ($2);
2001 mods = ctxmod->get_mods ();
2002 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
2003 if ($1 == ly_symbol2scm ("ChordNames"))
2005 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
2007 parser->lexer_->pop_state ();
2013 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2014 parser->lexer_->push_note_state (nn);
2016 $$ = ly_symbol2scm ("notes");
2020 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2021 parser->lexer_->push_note_state (nn);
2023 $$ = ly_symbol2scm ("drums");
2026 parser->lexer_->push_figuredbass_state ();
2028 $$ = ly_symbol2scm ("figures");
2031 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2032 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2033 nn = parser->lexer_->lookup_identifier ("pitchnames");
2034 parser->lexer_->push_chord_state (nn);
2035 $$ = ly_symbol2scm ("chords");
2039 { parser->lexer_->push_lyric_state ();
2040 $$ = ly_symbol2scm ("lyrics");
2044 mode_changing_head_with_context:
2046 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
2047 parser->lexer_->push_note_state (nn);
2049 $$ = ly_symbol2scm ("DrumStaff");
2052 parser->lexer_->push_figuredbass_state ();
2054 $$ = ly_symbol2scm ("FiguredBass");
2057 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
2058 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
2059 nn = parser->lexer_->lookup_identifier ("pitchnames");
2060 parser->lexer_->push_chord_state (nn);
2061 $$ = ly_symbol2scm ("ChordNames");
2064 { parser->lexer_->push_lyric_state ();
2065 $$ = ly_symbol2scm ("Lyrics");
2070 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2073 /* Can also use music at the expensive of two S/Rs similar to
2074 \repeat \alternative */
2075 parser->lexer_->pop_state ();
2077 $$ = scm_cons ($3, SCM_EOL);
2079 | new_lyrics ADDLYRICS {
2080 parser->lexer_->push_lyric_state ();
2082 parser->lexer_->pop_state ();
2083 $$ = scm_cons ($4, $1);
2088 composite_music new_lyrics {
2089 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2091 | LYRICSTO simple_string {
2092 parser->lexer_->push_lyric_state ();
2094 parser->lexer_->pop_state ();
2095 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2100 CHANGE STRING '=' STRING {
2101 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2108 $$ = scm_reverse_x ($1, SCM_EOL);
2110 | symbol_list_rev property_path {
2111 $$ = scm_reverse_x ($1, $2);
2117 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2120 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2122 | OVERRIDE property_path '=' scalar {
2123 if (scm_ilength ($2) < 2) {
2124 parser->parser_error (@2, _("bad grob property path"));
2127 $$ = scm_cons (ly_symbol2scm ("push"),
2128 scm_cons2 (scm_car ($2),
2133 | REVERT revert_arg {
2134 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2138 // This is all quite awkward for the sake of substantial backward
2139 // compatibility while at the same time allowing a more "natural" form
2140 // of specification not separating grob specification from grob
2141 // property path. The purpose of this definition of revert_arg is to
2142 // allow the symbol list which specifies grob and property to revert
2143 // to be optionally be split into two parts after the grob (which in
2144 // this case is just the first element of the list). symbol_list_part
2145 // is only one path component, but it can be parsed without lookahead,
2146 // so we can follow it with a synthetic BACKUP token when needed. If
2147 // the first symbol_list_part already contains multiple elements (only
2148 // possible if a Scheme expression provides them), we just parse for
2149 // additional elements introduced by '.', which is what the
2150 // SYMBOL_LIST backup in connection with the immediately following
2151 // rule using symbol_list_arg does.
2153 // As long as we don't have our coffers filled with both grob and at
2154 // least one grob property specification, the rest of the required
2155 // symbol list chain may be provided either with or without a leading
2156 // dot. This is for both allowing the traditional
2157 // \revert Accidental #'color
2158 // as well as well as the "naive" form
2159 // \revert Accidental.color
2162 revert_arg_backup BACKUP symbol_list_arg
2171 if (scm_is_null ($1)
2172 || scm_is_null (scm_cdr ($1)))
2173 MYBACKUP (SCM_ARG, $1, @1);
2175 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2179 // revert_arg_part delivers results in reverse
2182 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2184 $$ = scm_append_x (scm_list_2 ($5, $3));
2186 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2188 $$ = scm_append_x (scm_list_2 ($4, $3));
2193 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2194 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2196 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2197 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2198 | DENIES { $$ = ly_symbol2scm ("denies"); }
2200 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2201 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2202 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2203 | NAME { $$ = ly_symbol2scm ("context-name"); }
2207 property_operation { $$ = $1; }
2208 | context_def_mod STRING {
2209 $$ = scm_list_2 ($1, $2);
2211 | context_def_mod embedded_scm
2213 if (!scm_is_string ($2)
2214 && ly_symbol2scm ("consists") != $1
2215 && ly_symbol2scm ("remove") != $1)
2218 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2222 $$ = scm_list_2 ($1, $2);
2227 // If defined, at least two members.
2231 SCM l = scm_reverse_x ($1, SCM_EOL);
2234 (scm_object_property (scm_car (l),
2235 ly_symbol2scm ("is-grob?"))))
2236 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2237 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2238 parser->parser_error (@1, _ ("bad grob property path"));
2245 // If defined, at least three members
2249 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2251 parser->parser_error (@1, _ ("bad grob property path"));
2255 | grob_prop_spec property_path
2257 if (!SCM_UNBNDP ($1)) {
2258 $$ = scm_append_x (scm_list_2 ($1, $2));
2259 if (scm_is_null (scm_cddr ($$))) {
2260 parser->parser_error (@$, _ ("bad grob property path"));
2268 // Exactly two elements or undefined
2272 SCM l = scm_reverse_x ($1, SCM_EOL);
2273 switch (scm_ilength (l)) {
2275 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2279 parser->parser_error (@1, _ ("bad context property path"));
2286 simple_music_property_def:
2287 OVERRIDE grob_prop_path '=' scalar {
2288 if (SCM_UNBNDP ($2))
2291 $$ = scm_list_5 (scm_car ($2),
2292 ly_symbol2scm ("OverrideProperty"),
2298 | REVERT simple_revert_context revert_arg {
2299 $$ = scm_list_4 ($2,
2300 ly_symbol2scm ("RevertProperty"),
2304 | SET context_prop_spec '=' scalar {
2305 if (SCM_UNBNDP ($2))
2308 $$ = scm_list_4 (scm_car ($2),
2309 ly_symbol2scm ("PropertySet"),
2313 | UNSET context_prop_spec {
2314 if (SCM_UNBNDP ($2))
2317 $$ = scm_list_3 (scm_car ($2),
2318 ly_symbol2scm ("PropertyUnset"),
2324 // This is all quite awkward for the sake of substantial backward
2325 // compatibility while at the same time allowing a more "natural" form
2326 // of specification not separating grob specification from grob
2327 // property path. The purpose of this definition of
2328 // simple_revert_context is to allow the symbol list which specifies
2329 // grob and property to revert to be optionally be split into two
2330 // parts after the grob (which may be preceded by a context
2331 // specification, a case which we distinguish by checking whether the
2332 // first symbol is a valid grob symbol instead).
2334 // See revert_arg above for the main work horse of this arrangement.
2335 // simple_revert_context just caters for the context and delegates the
2336 // rest of the job to revert_arg.
2338 simple_revert_context:
2341 $1 = scm_reverse_x ($1, SCM_EOL);
2342 if (scm_is_null ($1)
2344 (scm_object_property (scm_car ($1),
2345 ly_symbol2scm ("is-grob?")))) {
2346 $$ = ly_symbol2scm ("Bottom");
2347 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2350 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2357 simple_music_property_def {
2358 if (SCM_UNBNDP ($1))
2359 $$ = MAKE_SYNTAX ("void-music", @1);
2361 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2372 simple_string: STRING {
2377 if (scm_is_string ($1)) {
2380 parser->parser_error (@1, (_ ("simple string expected")));
2381 $$ = scm_string (SCM_EOL);
2388 $$ = scm_string_to_symbol ($1);
2392 // This is a bit of overkill but makes the same
2393 // routine responsible for all symbol interpretations.
2394 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2396 if (SCM_UNBNDP ($$))
2398 parser->parser_error (@1, (_ ("symbol expected")));
2399 // Generate a unique symbol in case it is used
2400 // for an assignment or similar
2401 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2410 // The following is a rather defensive variant of admitting
2411 // negative numbers: the grammar would permit number_factor or
2412 // even number_expression. However, function arguments allow
2413 // only this simple kind of negative number, so to have things
2414 // like \tweak and \override behave reasonably similar, it
2415 // makes sense to rule out things like -- which are rather an
2416 // accent in function argument contexts.
2419 $$ = scm_difference ($2, SCM_UNDEFINED);
2427 embedded_scm_arg_closed
2429 // for scalar_closed to be an actually closed (no lookahead)
2430 // expression, we'd need to use bare_number_closed here. It
2431 // turns out that the only use of scalar_closed in TEMPO is
2432 // not of the kind requiring the full closedness criterion.
2436 $$ = scm_difference ($2, SCM_UNDEFINED);
2445 simple_element post_events {
2446 // Let the rhythmic music iterator sort this mess out.
2447 if (scm_is_pair ($2)) {
2448 $$ = make_music_from_simple (parser, @1, $1);
2449 if (unsmob_music ($$))
2450 unsmob_music ($$)->set_property ("articulations",
2451 scm_reverse_x ($2, SCM_EOL));
2453 parser->parser_error (@1, _("music expected"));
2456 | simple_chord_elements post_events {
2457 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2460 /* why is this giving wrong start location? -ns
2462 i.set_location (@1, @2);
2463 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2465 | CHORD_REPETITION optional_notemode_duration post_events {
2467 i.set_location (@1, @3);
2468 $$ = MAKE_SYNTAX ("repetition-chord", i,
2469 $2, scm_reverse_x ($3, SCM_EOL));
2471 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2473 i.set_location (@1, @3);
2474 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2475 scm_reverse_x ($3, SCM_EOL));
2478 | note_chord_element
2483 chord_body optional_notemode_duration post_events
2485 Music *m = unsmob_music ($1);
2486 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2487 SCM es = m->get_property ("elements");
2488 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2490 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2491 unsmob_music (scm_car (s))->set_property ("duration", dur);
2492 es = ly_append2 (es, postevs);
2494 m-> set_property ("elements", es);
2496 $$ = m->self_scm ();
2501 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2503 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2507 chord_body_elements:
2508 /* empty */ { $$ = SCM_EOL; }
2509 | chord_body_elements chord_body_element {
2510 if (!SCM_UNBNDP ($2))
2511 $$ = scm_cons ($2, $1);
2516 pitch exclamations questions octave_check post_events
2518 bool q = to_boolean ($3);
2519 bool ex = to_boolean ($2);
2523 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2524 n->set_property ("pitch", $1);
2526 n->set_property ("cautionary", SCM_BOOL_T);
2528 n->set_property ("force-accidental", SCM_BOOL_T);
2530 if (scm_is_pair (post)) {
2531 SCM arts = scm_reverse_x (post, SCM_EOL);
2532 n->set_property ("articulations", arts);
2534 if (scm_is_number (check))
2536 int q = scm_to_int (check);
2537 n->set_property ("absolute-octave", scm_from_int (q-1));
2540 $$ = n->unprotect ();
2542 | DRUM_PITCH post_events {
2543 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2544 n->set_property ("drum-type", $1);
2546 if (scm_is_pair ($2)) {
2547 SCM arts = scm_reverse_x ($2, SCM_EOL);
2548 n->set_property ("articulations", arts);
2550 $$ = n->unprotect ();
2552 | music_function_chord_body
2554 Music *m = unsmob_music ($1);
2556 while (m && m->is_mus_type ("music-wrapper-music")) {
2557 $$ = m->get_property ("element");
2558 m = unsmob_music ($$);
2561 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2562 parser->parser_error (@$, _ ("not a rhythmic event"));
2568 music_function_chord_body:
2573 // Event functions may only take closed arglists, otherwise it would
2574 // not be clear whether a following postevent should be associated
2575 // with the last argument of the event function or with the expression
2576 // for which the function call acts itself as event.
2578 music_function_call_closed:
2579 MUSIC_FUNCTION function_arglist_closed {
2580 $$ = MAKE_SYNTAX ("music-function", @$,
2585 event_function_event:
2586 EVENT_FUNCTION function_arglist_closed {
2587 $$ = MAKE_SYNTAX ("music-function", @$,
2609 | post_events post_event {
2611 if (Music *m = unsmob_music ($2))
2613 if (m->is_mus_type ("post-event-wrapper"))
2615 for (SCM p = m->get_property ("elements");
2619 $$ = scm_cons (scm_car (p), $$);
2623 $$ = scm_cons ($2, $$);
2629 post_event_nofinger:
2630 direction_less_event {
2633 | script_dir music_function_call_closed {
2635 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2636 parser->parser_error (@2, _ ("post-event expected"));
2637 $$ = SCM_UNSPECIFIED;
2638 } else if (!SCM_UNBNDP ($1))
2640 unsmob_music ($$)->set_property ("direction", $1);
2644 if (!parser->lexer_->is_lyric_state ())
2645 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2646 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2649 if (!parser->lexer_->is_lyric_state ())
2650 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2651 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2653 | script_dir direction_reqd_event {
2654 if (!SCM_UNBNDP ($1))
2656 Music *m = unsmob_music ($2);
2657 m->set_property ("direction", $1);
2661 | script_dir direction_less_event {
2662 if (!SCM_UNBNDP ($1))
2664 Music *m = unsmob_music ($2);
2665 m->set_property ("direction", $1);
2672 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2677 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2688 string_number_event:
2690 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2691 s->set_property ("string-number", $1);
2692 $$ = s->unprotect ();
2696 direction_less_event:
2698 | EVENT_IDENTIFIER {
2702 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2703 a->set_property ("tremolo-type", $1);
2704 $$ = a->unprotect ();
2706 | event_function_event
2709 direction_reqd_event:
2713 | script_abbreviation {
2714 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2715 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2716 if (scm_is_string (s))
2717 a->set_property ("articulation-type", s);
2718 else parser->parser_error (@1, _ ("expecting string as script definition"));
2719 $$ = a->unprotect ();
2724 /**/ { $$ = SCM_EOL; }
2725 | '=' quotes { $$ = $2; }
2739 $$ = scm_from_int (1);
2742 $$ = scm_oneplus ($1);
2748 $$ = scm_from_int (-1);
2751 $$ = scm_oneminus ($1);
2756 NOTENAME_PITCH quotes {
2757 if (!scm_is_eq (SCM_INUM0, $2))
2759 Pitch p = *unsmob_pitch ($1);
2760 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2761 $$ = p.smobbed_copy ();
2771 TONICNAME_PITCH quotes {
2772 if (!scm_is_eq (SCM_INUM0, $2))
2774 Pitch p = *unsmob_pitch ($1);
2775 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2776 $$ = p.smobbed_copy ();
2786 pitch_also_in_chords:
2793 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2794 t->set_property ("text", $1);
2795 $$ = t->unprotect ();
2798 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2799 t->set_property ("text",
2800 make_simple_markup ($1));
2801 $$ = t->unprotect ();
2803 | embedded_scm_closed
2805 Music *m = unsmob_music ($1);
2806 if (m && m->is_mus_type ("post-event"))
2808 else if (Text_interface::is_markup ($1)) {
2809 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2810 t->set_property ("text", $1);
2811 $$ = t->unprotect ();
2813 parser->parser_error (@1, _ ("not an articulation"));
2819 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2820 t->set_property ("digit", $1);
2821 $$ = t->unprotect ();
2825 script_abbreviation:
2827 $$ = scm_from_locale_string ("Hat");
2830 $$ = scm_from_locale_string ("Plus");
2833 $$ = scm_from_locale_string ("Dash");
2836 $$ = scm_from_locale_string ("Bang");
2839 $$ = scm_from_locale_string ("Larger");
2842 $$ = scm_from_locale_string ("Dot");
2845 $$ = scm_from_locale_string ("Underscore");
2850 '_' { $$ = scm_from_int (DOWN); }
2851 | '^' { $$ = scm_from_int (UP); }
2852 | '-' { $$ = SCM_UNDEFINED; }
2856 multiplied_duration {
2861 maybe_notemode_duration:
2865 | multiplied_duration {
2867 parser->default_duration_ = *unsmob_duration ($$);
2872 optional_notemode_duration:
2873 maybe_notemode_duration
2875 if (SCM_UNBNDP ($$))
2876 $$ = parser->default_duration_.smobbed_copy ();
2882 $$ = make_duration ($1, scm_to_int ($2));
2883 if (SCM_UNBNDP ($$))
2885 parser->parser_error (@1, _ ("not a duration"));
2886 $$ = Duration ().smobbed_copy ();
2889 | DURATION_IDENTIFIER dots {
2890 Duration *d = unsmob_duration ($1);
2891 Duration k (d->duration_log (),
2892 d->dot_count () + scm_to_int ($2));
2893 k = k.compressed (d->factor ());
2894 scm_remember_upto_here_1 ($1);
2895 $$ = k.smobbed_copy ();
2899 multiplied_duration:
2903 | multiplied_duration '*' UNSIGNED {
2904 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2906 | multiplied_duration '*' FRACTION {
2907 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2909 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2918 $$ = scm_oneplus ($1);
2927 if (SCM_UNBNDP (make_duration ($2)))
2928 parser->parser_error (@2, _ ("not a duration"));
2934 UNSIGNED { $$ = $1; }
2935 | STRING { $$ = $1; }
2936 | full_markup { $$ = $1; }
2939 // as an integer, it needs to be non-negative, and otherwise
2940 // it needs to be suitable as a markup.
2941 if (scm_is_integer ($1)
2942 ? scm_is_true (scm_negative_p ($1))
2943 : !Text_interface::is_markup ($1))
2945 parser->parser_error (@1, _ ("bass number expected"));
2951 figured_bass_alteration:
2952 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2953 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2954 | '!' { $$ = scm_from_int (0); }
2959 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2960 $$ = bfr->unprotect ();
2963 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2964 $$ = bfr->self_scm ();
2966 if (scm_is_number ($1))
2967 bfr->set_property ("figure", $1);
2968 else if (Text_interface::is_markup ($1))
2969 bfr->set_property ("text", $1);
2975 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2977 | bass_figure figured_bass_alteration {
2978 Music *m = unsmob_music ($1);
2979 if (scm_to_double ($2)) {
2980 SCM salter = m->get_property ("alteration");
2981 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2982 m->set_property ("alteration",
2983 scm_sum (alter, $2));
2985 m->set_property ("alteration", scm_from_int (0));
2988 | bass_figure figured_bass_modification {
2989 Music *m = unsmob_music ($1);
2990 m->set_property ($2, SCM_BOOL_T);
2995 figured_bass_modification:
2997 $$ = ly_symbol2scm ("augmented");
3000 $$ = ly_symbol2scm ("no-continuation");
3003 $$ = ly_symbol2scm ("diminished");
3006 $$ = ly_symbol2scm ("augmented-slash");
3016 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3024 | figure_list br_bass_figure {
3025 $$ = scm_cons ($2, $1);
3030 FIGURE_OPEN figure_list FIGURE_CLOSE {
3031 $$ = scm_reverse_x ($2, SCM_EOL);
3037 /**/ { $$ = SCM_BOOL_F; }
3038 | REST { $$ = SCM_BOOL_T; }
3042 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3043 if (!parser->lexer_->is_note_state ())
3044 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3045 if (!SCM_UNBNDP ($2)
3047 || scm_is_number ($4)
3049 || scm_is_true ($6))
3052 if (scm_is_true ($6))
3053 n = MY_MAKE_MUSIC ("RestEvent", @$);
3055 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3057 n->set_property ("pitch", $1);
3058 if (SCM_UNBNDP ($5))
3059 n->set_property ("duration",
3060 parser->default_duration_.smobbed_copy ());
3062 n->set_property ("duration", $5);
3064 if (scm_is_number ($4))
3066 int q = scm_to_int ($4);
3067 n->set_property ("absolute-octave", scm_from_int (q-1));
3070 if (to_boolean ($3))
3071 n->set_property ("cautionary", SCM_BOOL_T);
3072 if (to_boolean ($2) || to_boolean ($3))
3073 n->set_property ("force-accidental", SCM_BOOL_T);
3075 $$ = n->unprotect ();
3078 | DRUM_PITCH optional_notemode_duration {
3079 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3080 n->set_property ("duration", $2);
3081 n->set_property ("drum-type", $1);
3083 $$ = n->unprotect ();
3085 | RESTNAME optional_notemode_duration {
3087 if (ly_scm2string ($1) == "s") {
3089 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3092 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3095 ev->set_property ("duration", $2);
3096 $$ = ev->unprotect ();
3100 simple_chord_elements:
3102 if (!parser->lexer_->is_chord_state ())
3103 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3106 | figure_spec optional_notemode_duration {
3107 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3109 unsmob_music (scm_car (s))->set_property ("duration", $2);
3117 if (!parser->lexer_->is_lyric_state ())
3118 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3122 if (!parser->lexer_->is_lyric_state ())
3123 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3129 lyric_element_music:
3130 lyric_element optional_notemode_duration post_events {
3131 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3132 if (scm_is_pair ($3))
3133 unsmob_music ($$)->set_property
3134 ("articulations", scm_reverse_x ($3, SCM_EOL));
3139 steno_tonic_pitch optional_notemode_duration {
3140 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3142 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3143 SCM its = scm_reverse_x ($4, SCM_EOL);
3144 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3152 | chord_items chord_item {
3153 $$ = scm_cons ($2, $$);
3159 $$ = ly_symbol2scm ("chord-colon");
3162 $$ = ly_symbol2scm ("chord-caret");
3164 | CHORD_SLASH steno_tonic_pitch {
3165 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3167 | CHORD_BASS steno_tonic_pitch {
3168 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3177 $$ = scm_reverse_x ($1, SCM_EOL);
3185 step_number { $$ = scm_cons ($1, SCM_EOL); }
3186 | step_numbers '.' step_number {
3187 $$ = scm_cons ($3, $$);
3193 $$ = make_chord_step ($1, 0);
3196 $$ = make_chord_step ($1, SHARP_ALTERATION);
3198 | UNSIGNED CHORD_MINUS {
3199 $$ = make_chord_step ($1, FLAT_ALTERATION);
3207 | UNSIGNED '-' UNSIGNED {
3208 $$ = scm_cons ($1, $3);
3215 TODO: should deprecate in favor of Scheme?
3219 number_expression '+' number_term {
3220 $$ = scm_sum ($1, $3);
3222 | number_expression '-' number_term {
3223 $$ = scm_difference ($1, $3);
3232 | number_factor '*' number_factor {
3233 $$ = scm_product ($1, $3);
3235 | number_factor '/' number_factor {
3236 $$ = scm_divide ($1, $3);
3241 '-' number_factor { /* %prec UNARY_MINUS */
3242 $$ = scm_difference ($2, SCM_UNDEFINED);
3248 bare_number_common_closed
3249 | REAL NUMBER_IDENTIFIER
3251 $$ = scm_product ($1, $2);
3255 bare_number_common_closed:
3263 | UNSIGNED NUMBER_IDENTIFIER {
3264 $$ = scm_product ($1, $2);
3270 | bare_number_common_closed
3279 { $$ = SCM_UNDEFINED; }
3282 if (SCM_UNBNDP ($1))
3290 { $$ = SCM_UNDEFINED; }
3293 if (SCM_UNBNDP ($1))
3302 { parser->lexer_->push_markup_state (); }
3305 parser->lexer_->pop_state ();
3311 { parser->lexer_->push_markup_state (); }
3314 parser->lexer_->pop_state ();
3319 simple_markup_list {
3320 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3322 | markup_head_1_list simple_markup
3324 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3325 @2, $1, scm_list_1 ($2)));
3335 if (Text_interface::is_markup ($1))
3336 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3337 else if (Text_interface::is_markup_list ($1))
3338 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3340 parser->parser_error (@1, _ ("not a markup"));
3341 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3348 markup_composed_list {
3351 | markup_uncomposed_list
3354 markup_uncomposed_list:
3355 markup_braced_list {
3358 | markup_command_list {
3359 $$ = scm_list_1 ($1);
3361 | markup_scm MARKUPLIST_IDENTIFIER
3371 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $1));
3377 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3378 parser->lexer_->push_note_state (nn);
3379 } '{' score_body '}' {
3381 parser->lexer_->pop_state ();
3385 markup_composed_list:
3386 markup_head_1_list markup_uncomposed_list {
3387 $$ = MAKE_SYNTAX ("composed-markup-list",
3393 '{' markup_braced_list_body '}' {
3394 $$ = scm_reverse_x ($2, SCM_EOL);
3398 markup_braced_list_body:
3399 /* empty */ { $$ = SCM_EOL; }
3400 | markup_braced_list_body markup {
3401 $$ = scm_cons ($2, $1);
3403 | markup_braced_list_body simple_markup_list {
3404 $$ = scm_reverse_x ($2, $1);
3408 markup_command_list:
3409 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3410 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3414 markup_command_basic_arguments:
3415 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3416 $$ = scm_cons ($3, $2);
3418 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3419 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3421 | EXPECT_NO_MORE_ARGS {
3426 markup_command_list_arguments:
3427 markup_command_basic_arguments { $$ = $1; }
3428 | EXPECT_MARKUP markup_command_list_arguments markup {
3429 $$ = scm_cons ($3, $2);
3434 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3435 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3440 markup_head_1_item {
3441 $$ = scm_list_1 ($1);
3443 | markup_head_1_list markup_head_1_item {
3444 $$ = scm_cons ($2, $1);
3450 $$ = make_simple_markup ($1);
3452 | MARKUP_FUNCTION markup_command_basic_arguments {
3453 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3455 | markup_scm MARKUP_IDENTIFIER
3461 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $1);
3466 markup_head_1_list simple_markup
3468 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3469 @2, $1, scm_list_1 ($2)));
3479 Lily_parser::set_yydebug (bool x)
3485 Lily_parser::do_yyparse ()
3487 SCM retval = SCM_UNDEFINED;
3488 yyparse (this, &retval);
3498 It is a little strange to have this function in this file, but
3499 otherwise, we have to import music classes into the lexer.
3503 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3505 if (unsmob_book (sid)) {
3506 Book *book = unsmob_book (sid)->clone ();
3507 *destination = book->self_scm ();
3510 return BOOK_IDENTIFIER;
3511 } else if (scm_is_number (sid)) {
3513 return NUMBER_IDENTIFIER;
3514 } else if (unsmob_context_def (sid)) {
3515 Context_def *def= unsmob_context_def (sid)->clone ();
3517 *destination = def->self_scm ();
3520 return CONTEXT_DEF_IDENTIFIER;
3521 } else if (unsmob_context_mod (sid)) {
3522 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3524 return CONTEXT_MOD_IDENTIFIER;
3525 } else if (Music *mus = unsmob_music (sid)) {
3526 mus = mus->clone ();
3527 *destination = mus->self_scm ();
3528 bool is_event = mus->is_mus_type ("post-event");
3530 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3531 } else if (unsmob_pitch (sid)) {
3532 *destination = unsmob_pitch (sid)->smobbed_copy ();
3533 return PITCH_IDENTIFIER;
3534 } else if (unsmob_duration (sid)) {
3535 *destination = unsmob_duration (sid)->smobbed_copy ();
3536 return DURATION_IDENTIFIER;
3537 } else if (unsmob_output_def (sid)) {
3538 Output_def *p = unsmob_output_def (sid);
3541 *destination = p->self_scm ();
3543 return OUTPUT_DEF_IDENTIFIER;
3550 get_next_unique_context_id ()
3552 return scm_from_locale_string ("$uniqueContextId");
3557 get_next_unique_lyrics_context_id ()
3559 static int new_context_count;
3561 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3562 return scm_from_locale_string (s);
3565 // check_scheme_arg checks one argument with a given predicate for use
3566 // in an argument list and throws a syntax error if it is unusable.
3567 // The argument is prepended to the argument list in any case. After
3568 // throwing a syntax error, the argument list is terminated with #f as
3569 // its last cdr in order to mark it as uncallable while not losing
3570 // track of its total length.
3572 // There are a few special considerations: if optional argument disp
3573 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3574 // instead of arg in a prospective error message. This is useful if
3575 // arg is not the actual argument but rather a transformation of it.
3577 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3578 // and an error message using disp is produced unconditionally.
3580 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3581 SCM arg, SCM args, SCM pred, SCM disp)
3583 if (SCM_UNBNDP (arg))
3584 args = scm_cons (disp, args);
3586 args = scm_cons (arg, args);
3587 if (scm_is_true (scm_call_1 (pred, arg)))
3590 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3591 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3592 SCM_UNBNDP (disp) ? arg : disp);
3593 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3597 SCM loc_on_music (Input loc, SCM arg)
3599 if (Music *m = unsmob_music (arg))
3603 return m->unprotect ();
3609 try_string_variants (SCM pred, SCM str)
3611 // a matching predicate is always ok
3612 if (scm_is_true (scm_call_1 (pred, str)))
3614 // a symbol may be interpreted as a list of symbols if it helps
3615 if (scm_is_symbol (str)) {
3616 str = scm_list_1 (str);
3617 if (scm_is_true (scm_call_1 (pred, str)))
3619 return SCM_UNDEFINED;
3622 // If this cannot be a string representation of a symbol list,
3625 if (!is_regular_identifier (str, true))
3626 return SCM_UNDEFINED;
3628 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3629 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3630 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3632 // Let's attempt the symbol list interpretation first.
3634 if (scm_is_true (scm_call_1 (pred, str)))
3637 // If there is just one symbol in the list, we might interpret
3638 // it as a single symbol
3640 if (scm_is_null (scm_cdr (str)))
3642 str = scm_car (str);
3643 if (scm_is_true (scm_call_1 (pred, str)))
3647 return SCM_UNDEFINED;
3651 is_regular_identifier (SCM id, bool multiple)
3653 if (!scm_is_string (id))
3656 string str = ly_scm2string (id);
3658 bool middle = false;
3660 for (string::iterator it=str.begin(); it != str.end (); it++)
3663 if ((c >= 'a' && c <= 'z')
3664 || (c >= 'A' && c <= 'Z')
3667 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3676 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3678 if (unsmob_music (simple))
3680 if (parser->lexer_->is_note_state ()) {
3681 if (scm_is_symbol (simple)) {
3682 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3683 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3684 n->set_property ("drum-type", simple);
3685 return n->unprotect ();
3687 if (unsmob_pitch (simple)) {
3688 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3689 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3690 n->set_property ("pitch", simple);
3691 return n->unprotect ();
3694 } else if (parser->lexer_->is_lyric_state ()) {
3695 if (Text_interface::is_markup (simple))
3696 return MAKE_SYNTAX ("lyric-event", loc, simple,
3697 parser->default_duration_.smobbed_copy ());
3698 } else if (parser->lexer_->is_chord_state ()) {
3699 if (unsmob_pitch (simple))
3700 return make_chord_elements (loc, simple,
3701 parser->default_duration_.smobbed_copy (),
3708 make_music_with_input (SCM name, Input where)
3710 Music *m = make_music_by_name (name);
3711 m->set_spot (where);
3716 make_simple_markup (SCM a)
3722 make_duration (SCM d, int dots)
3724 int t = scm_to_int (d);
3725 if (t > 0 && (t & (t-1)) == 0)
3726 return Duration (intlog2 (t), dots).smobbed_copy ();
3728 return SCM_UNDEFINED;
3732 make_chord_step (SCM step_scm, Rational alter)
3734 int step = scm_to_int (step_scm);
3737 alter += FLAT_ALTERATION;
3741 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3742 return m.smobbed_copy ();
3747 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3749 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3750 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3751 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3753 unsmob_music (scm_car (s))->set_spot (loc);
3759 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3761 Lily_lexer *lex = parser->lexer_;
3765 lex->prepare_for_next_token ();
3766 return lex->yylex ();