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 *, 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 bool is_duration (int t);
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_ANGLE_CLOSE "\\>"
313 %token E_CHAR "\\C[haracter]"
315 %token E_EXCLAMATION "\\!"
316 %token E_BRACKET_OPEN "\\["
318 %token E_BRACKET_CLOSE "\\]"
319 %token E_ANGLE_OPEN "\\<"
325 If we give names, Bison complains.
327 %token FIGURE_CLOSE /* "\\>" */
328 %token FIGURE_OPEN /* "\\<" */
329 %token FIGURE_SPACE "_"
332 %token CHORDMODIFIERS
333 %token MULTI_MEASURE_REST
339 /* Artificial tokens, for more generic function syntax */
340 %token EXPECT_MARKUP "markup?"
341 %token EXPECT_PITCH "ly:pitch?"
342 %token EXPECT_DURATION "ly:duration?"
343 %token EXPECT_SCM "scheme?"
344 %token BACKUP "(backed-up?)"
345 %token REPARSE "(reparsed?)"
346 %token EXPECT_MARKUP_LIST "markup-list?"
347 %token EXPECT_OPTIONAL "optional?"
348 /* After the last argument. */
349 %token EXPECT_NO_MORE_ARGS;
351 /* An artificial token for parsing embedded Lilypond */
352 %token EMBEDDED_LILY "#{"
354 %token BOOK_IDENTIFIER
355 %token CHORDMODIFIER_PITCH
356 %token CHORD_MODIFIER
357 %token CHORD_REPETITION
358 %token CONTEXT_DEF_IDENTIFIER
359 %token CONTEXT_MOD_IDENTIFIER
361 %token PITCH_IDENTIFIER
362 %token DURATION_IDENTIFIER
363 %token EVENT_IDENTIFIER
364 %token EVENT_FUNCTION
367 %token MARKUP_FUNCTION
368 %token MARKUP_LIST_FUNCTION
369 %token MARKUP_IDENTIFIER
370 %token MARKUPLIST_IDENTIFIER
371 %token MUSIC_FUNCTION
372 %token MUSIC_IDENTIFIER
373 %token NOTENAME_PITCH
374 %token NUMBER_IDENTIFIER
375 %token OUTPUT_DEF_IDENTIFIER
380 %token SCM_IDENTIFIER
384 %token TONICNAME_PITCH
388 /* We don't assign precedence to / and *, because we might need varied
389 prec levels in different prods */
398 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
399 parser->lexer_->push_note_state (nn);
400 } embedded_lilypond {
401 parser->lexer_->pop_state ();
406 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
407 | lilypond toplevel_expression {
409 | lilypond assignment {
412 parser->error_level_ = 1;
415 parser->error_level_ = 1;
422 parser->lexer_->add_scope (get_header (parser));
424 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
428 scm_call_2 (proc, parser->self_scm (), $1);
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
432 scm_call_2 (proc, parser->self_scm (), $1);
435 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
436 scm_call_2 (proc, parser->self_scm (), $1);
439 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
440 scm_call_2 (proc, parser->self_scm (), $1);
443 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
444 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
447 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
448 scm_call_2 (proc, parser->self_scm (), $1);
451 // Evaluate and ignore #xxx, as opposed to \xxx
452 parser->lexer_->eval_scm_token ($1);
454 | embedded_scm_active
456 SCM out = SCM_UNDEFINED;
457 if (Text_interface::is_markup ($1))
458 out = scm_list_1 ($1);
459 else if (Text_interface::is_markup_list ($1))
461 if (scm_is_pair (out))
463 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
464 scm_call_2 (proc, parser->self_scm (), out);
465 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
466 parser->parser_error (@1, _("bad expression type"));
470 Output_def * od = unsmob_output_def ($1);
472 if (od->c_variable ("is-paper") == SCM_BOOL_T)
473 id = ly_symbol2scm ("$defaultpaper");
474 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
475 id = ly_symbol2scm ("$defaultmidi");
476 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
477 id = ly_symbol2scm ("$defaultlayout");
479 parser->lexer_->set_identifier (id, $1);
486 $$ = parser->lexer_->eval_scm_token ($1);
496 embedded_scm_bare_arg:
500 $$ = parser->lexer_->eval_scm_token ($1);
503 | context_modification
505 | context_def_spec_block
511 /* The generic version may end in music, or not */
519 embedded_scm_bare_arg
525 SCM_FUNCTION function_arglist {
526 $$ = MAKE_SYNTAX ("music-function", @$,
534 $$ = MAKE_SYNTAX ("void-music", @$);
537 | music_embedded music_embedded music_list {
538 $3 = scm_reverse_x ($3, SCM_EOL);
539 if (unsmob_music ($2))
540 $3 = scm_cons ($2, $3);
541 if (unsmob_music ($1))
542 $3 = scm_cons ($1, $3);
543 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
546 parser->error_level_ = 1;
547 $$ = SCM_UNSPECIFIED;
549 | INVALID embedded_lilypond {
550 parser->error_level_ = 1;
556 lilypond_header_body:
557 /* empty */ { $$ = SCM_UNSPECIFIED; }
558 | lilypond_header_body assignment {
561 | lilypond_header_body embedded_scm {
567 HEADER '{' lilypond_header_body '}' {
568 $$ = parser->lexer_->remove_scope ();
580 assignment_id '=' identifier_init {
581 parser->lexer_->set_identifier ($1, $3);
582 $$ = SCM_UNSPECIFIED;
584 | assignment_id property_path '=' identifier_init {
585 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
586 parser->lexer_->set_identifier (path, $4);
587 $$ = SCM_UNSPECIFIED;
597 | context_def_spec_block
599 | post_event_nofinger
605 | context_modification
608 context_def_spec_block:
609 CONTEXT '{' context_def_spec_body '}'
620 context_mod_embedded:
623 if (unsmob_music ($1)) {
624 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
625 $1 = scm_call_2 (proc, parser->self_scm (), $1);
627 if (unsmob_context_mod ($1))
630 parser->parser_error (@1, _ ("not a context mod"));
636 context_def_spec_body:
638 $$ = Context_def::make_scm ();
639 unsmob_context_def ($$)->origin ()->set_spot (@$);
641 | CONTEXT_DEF_IDENTIFIER {
643 unsmob_context_def ($$)->origin ()->set_spot (@$);
645 | context_def_spec_body context_mod {
646 if (!SCM_UNBNDP ($2))
647 unsmob_context_def ($$)->add_context_mod ($2);
649 | context_def_spec_body context_modification {
650 Context_def *td = unsmob_context_def ($$);
651 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
652 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
653 td->add_context_mod (scm_car (m));
656 | context_def_spec_body context_mod_embedded {
657 Context_def *td = unsmob_context_def ($$);
658 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
659 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
660 td->add_context_mod (scm_car (m));
668 BOOK '{' book_body '}' {
671 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
676 * Use 'handlers' like for toplevel-* stuff?
677 * grok \layout and \midi? */
680 Book *book = new Book;
681 init_papers (parser);
682 book->origin ()->set_spot (@$);
683 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
684 book->paper_->unprotect ();
685 push_paper (parser, book->paper_);
686 book->header_ = get_header (parser);
687 $$ = book->unprotect ();
688 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
691 unsmob_book ($1)->origin ()->set_spot (@$);
692 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
694 | book_body paper_block {
695 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
696 set_paper (parser, unsmob_output_def ($2));
698 | book_body bookpart_block {
699 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
700 scm_call_2 (proc, $1, $2);
702 | book_body score_block {
703 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
704 scm_call_2 (proc, $1, $2);
706 | book_body composite_music {
707 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
708 scm_call_3 (proc, parser->self_scm (), $1, $2);
710 | book_body full_markup {
711 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
712 scm_call_2 (proc, $1, scm_list_1 ($2));
714 | book_body full_markup_list {
715 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
716 scm_call_2 (proc, $1, $2);
718 | book_body SCM_TOKEN {
719 // Evaluate and ignore #xxx, as opposed to \xxx
720 parser->lexer_->eval_scm_token ($2);
722 | book_body embedded_scm_active
724 SCM out = SCM_UNDEFINED;
725 if (Text_interface::is_markup ($2))
726 out = scm_list_1 ($2);
727 else if (Text_interface::is_markup_list ($2))
729 if (scm_is_pair (out))
731 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
732 scm_call_2 (proc, $1, out);
733 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
734 parser->parser_error (@2, _("bad expression type"));
738 parser->lexer_->add_scope (unsmob_book ($1)->header_);
741 Book *book = unsmob_book ($1);
743 book->scores_ = SCM_EOL;
744 book->bookparts_ = SCM_EOL;
749 BOOKPART '{' bookpart_body '}' {
751 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
757 Book *book = new Book;
758 book->origin ()->set_spot (@$);
759 $$ = book->unprotect ();
760 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
763 unsmob_book ($1)->origin ()->set_spot (@$);
764 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
766 | bookpart_body paper_block {
767 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
769 | bookpart_body score_block {
770 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
771 scm_call_2 (proc, $1, $2);
773 | bookpart_body composite_music {
774 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
775 scm_call_3 (proc, parser->self_scm (), $1, $2);
777 | bookpart_body full_markup {
778 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
779 scm_call_2 (proc, $1, scm_list_1 ($2));
781 | bookpart_body full_markup_list {
782 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
783 scm_call_2 (proc, $1, $2);
785 | bookpart_body SCM_TOKEN {
786 // Evaluate and ignore #xxx, as opposed to \xxx
787 parser->lexer_->eval_scm_token ($2);
789 | bookpart_body embedded_scm_active
791 SCM out = SCM_UNDEFINED;
792 if (Text_interface::is_markup ($2))
793 out = scm_list_1 ($2);
794 else if (Text_interface::is_markup_list ($2))
796 if (scm_is_pair (out))
798 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
799 scm_call_2 (proc, $1, out);
800 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
801 parser->parser_error (@2, _("bad expression type"));
805 Book *book = unsmob_book ($1);
806 if (!ly_is_module (book->header_))
807 book->header_ = ly_make_module (false);
808 parser->lexer_->add_scope (book->header_);
810 | bookpart_body error {
811 Book *book = unsmob_book ($1);
813 book->scores_ = SCM_EOL;
818 SCORE '{' score_body '}' {
825 SCM scorify = ly_lily_module_constant ("scorify-music");
826 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
828 unsmob_score ($$)->origin ()->set_spot (@$);
830 | embedded_scm_active {
832 if (unsmob_score ($1))
833 score = new Score (*unsmob_score ($1));
836 parser->parser_error (@1, _("score expected"));
838 unsmob_score ($$)->origin ()->set_spot (@$);
839 $$ = score->unprotect ();
843 Score *score = unsmob_score ($1);
844 if (!ly_is_module (score->get_header ()))
845 score->set_header (ly_make_module (false));
846 parser->lexer_->add_scope (score->get_header ());
848 | score_body output_def {
849 Output_def *od = unsmob_output_def ($2);
850 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
852 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
857 unsmob_score ($1)->add_output_def (od);
861 unsmob_score ($$)->error_found_ = true;
872 Output_def *od = unsmob_output_def ($1);
874 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
876 parser->parser_error (@1, _ ("need \\paper for paper block"));
877 $$ = get_paper (parser)->unprotect ();
884 output_def_body '}' {
887 parser->lexer_->remove_scope ();
888 parser->lexer_->pop_state ();
894 Output_def *p = get_paper (parser);
895 p->input_origin_ = @$;
896 parser->lexer_->add_scope (p->scope_);
897 $$ = p->unprotect ();
900 Output_def *p = get_midi (parser);
901 $$ = p->unprotect ();
902 parser->lexer_->add_scope (p->scope_);
905 Output_def *p = get_layout (parser);
907 parser->lexer_->add_scope (p->scope_);
908 $$ = p->unprotect ();
912 output_def_head_with_mode_switch:
914 parser->lexer_->push_initial_state ();
919 // We need this weird nonterminal because both music as well as a
920 // context definition can start with \context and the difference is
921 // only apparent after looking at the next token. If it is '{', there
922 // is still time to escape from notes mode.
924 music_or_context_def:
927 parser->lexer_->pop_state ();
931 parser->lexer_->pop_state ();
932 } '{' context_def_spec_body '}'
939 output_def_head_with_mode_switch '{' {
941 unsmob_output_def ($$)->input_origin_.set_spot (@$);
943 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
944 Output_def *o = unsmob_output_def ($3);
945 o->input_origin_.set_spot (@$);
947 parser->lexer_->remove_scope ();
948 parser->lexer_->add_scope (o->scope_);
950 | output_def_body assignment {
953 | output_def_body embedded_scm {
958 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
959 parser->lexer_->push_note_state (nn);
960 } music_or_context_def
962 if (unsmob_context_def ($3))
963 assign_context_def (unsmob_output_def ($1), $3);
966 SCM proc = parser->lexer_->lookup_identifier
967 ("output-def-music-handler");
968 scm_call_3 (proc, parser->self_scm (),
972 | output_def_body error {
978 TEMPO steno_duration '=' tempo_range {
979 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
981 | TEMPO scalar_closed steno_duration '=' tempo_range {
982 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
985 $$ = MAKE_SYNTAX ("tempo", @$, $2);
990 The representation of a list is reversed to have efficient append. */
996 | music_list music_embedded {
997 if (unsmob_music ($2))
998 $$ = scm_cons ($2, $1);
1000 | music_list error {
1001 Music *m = MY_MAKE_MUSIC("Music", @$);
1003 m->set_property ("error-found", SCM_BOOL_T);
1004 $$ = scm_cons (m->self_scm (), $1);
1005 m->unprotect (); /* UGH */
1012 $$ = scm_reverse_x ($2, SCM_EOL);
1017 | lyric_element_music
1023 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1024 parser->parser_error (@1, _ ("unexpected post-event"));
1025 $$ = SCM_UNSPECIFIED;
1030 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1032 else if (Music *m = unsmob_music ($1)) {
1033 if (m->is_mus_type ("post-event")) {
1034 parser->parser_error
1035 (@1, _ ("unexpected post-event"));
1036 $$ = SCM_UNSPECIFIED;
1040 @$.warning (_ ("Ignoring non-music expression"));
1041 $$ = SCM_UNSPECIFIED;
1049 $$ = make_music_from_simple (parser, @1, $1);
1050 if (!unsmob_music ($$))
1051 parser->parser_error (@1, _ ("music expected"));
1053 | composite_music %prec COMPOSITE
1058 | composite_music %prec COMPOSITE
1062 REPEAT simple_string unsigned_number music
1064 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1066 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1068 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1073 SEQUENTIAL braced_music_list {
1074 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1076 | braced_music_list {
1077 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1082 SIMULTANEOUS braced_music_list {
1083 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1085 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1086 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1092 | music_property_def
1096 context_modification:
1097 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1099 parser->lexer_->pop_state ();
1102 | WITH CONTEXT_MOD_IDENTIFIER
1106 | CONTEXT_MOD_IDENTIFIER
1110 | WITH embedded_scm_closed
1112 if (unsmob_context_mod ($2))
1115 parser->parser_error (@2, _ ("not a context mod"));
1116 $$ = Context_mod ().smobbed_copy ();
1121 optional_context_mod:
1125 | context_modification
1133 $$ = Context_mod ().smobbed_copy ();
1135 | context_mod_list context_mod {
1136 if (!SCM_UNBNDP ($2))
1137 unsmob_context_mod ($1)->add_context_mod ($2);
1139 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1140 Context_mod *md = unsmob_context_mod ($2);
1142 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1144 | context_mod_list context_mod_embedded {
1145 unsmob_context_mod ($1)->add_context_mods
1146 (unsmob_context_mod ($2)->get_mods ());
1155 /* Music that can be parsed without lookahead */
1158 | complex_music_prefix closed_music
1160 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1162 | music_function_call_closed
1168 | grouped_music_list
1172 simultaneous_music { $$ = $1; }
1173 | sequential_music { $$ = $1; }
1176 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1177 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1178 and this rule returns the reversed list of arguments. */
1180 /* Function argument lists come in a number of flavors. Whenever
1181 * LilyPond has to pick between different flavors, the decision is
1182 * either made because of tokens it has already seen, or it is
1183 * postponed until tokens suitable for making the decision come up.
1184 * For postponing decisions, it may be necessary that the competing
1185 * rules are written in a way making them compatible until a decision
1186 * can be made. Sometimes this is done by putting common traits into
1187 * a separate "common" rule set.
1189 * function_arglist: a full argument list. Optional arguments at the
1190 * end of the list can only be skipped by writing \default in their
1193 * function_arglist_backup: an argument list ending in an optional
1194 * argument that may be skipped depending on its predicate.
1196 * function_arglist_skip: an argument list _not_ ending in an optional
1197 * argument that is actually taken.
1199 * function_arglist_nonbackup: an argument list ending in an optional
1200 * argument that may not be skipped because it is in end position and
1201 * has not been shortcircuited with \default.
1203 * function_arglist* / function_arglist_closed*: The closed variants
1204 * don't end in simple music expressions that might still accept
1205 * things like a duration or a postevent.
1208 function_arglist_skip:
1209 function_arglist_common
1210 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1212 $$ = scm_cons ($1, $3);
1213 } %prec FUNCTION_ARGLIST
1214 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1216 $$ = scm_cons ($1, $3);
1217 } %prec FUNCTION_ARGLIST
1218 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1220 $$ = scm_cons ($1, $3);
1221 } %prec FUNCTION_ARGLIST
1225 function_arglist_nonbackup_common:
1226 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1227 $$ = scm_cons ($4, $3);
1229 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1230 $$ = scm_cons ($4, $3);
1232 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1234 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1236 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1238 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1240 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1242 SCM n = scm_difference ($5, SCM_UNDEFINED);
1243 if (scm_is_true (scm_call_1 ($2, n)))
1244 $$ = scm_cons (n, $3);
1246 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1247 t->set_property ("digit", $5);
1248 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1253 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1255 $$ = check_scheme_arg (parser, @4,
1256 scm_difference ($5, SCM_UNDEFINED),
1259 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1261 $$ = check_scheme_arg (parser, @4,
1262 scm_difference ($5, SCM_UNDEFINED),
1267 function_arglist_closed_nonbackup:
1268 function_arglist_nonbackup_common
1269 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1271 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1273 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1275 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1277 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1279 $$ = check_scheme_arg (parser, @4,
1280 try_string_variants ($2, $4),
1283 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1285 $$ = check_scheme_arg (parser, @4,
1286 try_string_variants ($2, $4),
1289 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1291 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1297 | SYMBOL_LIST '.' symbol_list_rev
1299 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1305 | symbol_list_rev '.' symbol_list_part
1307 $$ = scm_append_x (scm_list_2 ($3, $1));
1311 // symbol_list_part delivers elements in reverse copy.
1316 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1317 $$ = try_string_variants (sym_l_p, $1);
1318 if (SCM_UNBNDP ($$)) {
1319 parser->parser_error (@1, _("not a symbol"));
1322 $$ = scm_reverse ($$);
1327 symbol_list_element:
1333 function_arglist_nonbackup:
1334 function_arglist_nonbackup_common
1335 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1337 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1339 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1341 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1343 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1345 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1347 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1349 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1351 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1353 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1357 function_arglist_nonbackup_reparse:
1358 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1361 SCM res = try_string_variants ($2, $4);
1362 if (!SCM_UNBNDP (res))
1363 if (scm_is_pair (res))
1364 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1366 MYREPARSE (@4, $2, SCM_ARG, res);
1367 else if (scm_is_true
1369 ($2, make_music_from_simple
1371 MYREPARSE (@4, $2, STRING, $4);
1373 MYREPARSE (@4, $2, SCM_ARG, $4);
1375 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1378 SCM res = try_string_variants ($2, $4);
1379 if (!SCM_UNBNDP (res))
1380 if (scm_is_pair (res))
1381 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1383 MYREPARSE (@4, $2, SCM_ARG, res);
1384 else if (scm_is_true
1386 ($2, make_music_from_simple
1388 MYREPARSE (@4, $2, STRING, $4);
1390 MYREPARSE (@4, $2, SCM_ARG, $4);
1392 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1395 if (scm_is_true (scm_call_1 ($2, $4)))
1396 MYREPARSE (@4, $2, SCM_ARG, $4);
1397 else if (scm_is_true
1399 ($2, make_music_from_simple
1401 MYREPARSE (@4, $2, STRING, $4);
1403 MYREPARSE (@4, $2, SCM_ARG, $4);
1407 function_arglist_keep:
1408 function_arglist_common
1409 | function_arglist_backup
1412 function_arglist_closed_keep:
1413 function_arglist_closed_common
1414 | function_arglist_backup
1417 function_arglist_backup:
1418 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1420 if (scm_is_true (scm_call_1 ($2, $4)))
1422 $$ = scm_cons ($4, $3);
1424 $$ = scm_cons (loc_on_music (@3, $1), $3);
1425 MYBACKUP (SCM_ARG, $4, @4);
1428 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1430 if (scm_is_true (scm_call_1 ($2, $4)))
1432 $$ = scm_cons ($4, $3);
1434 $$ = scm_cons (loc_on_music (@3, $1), $3);
1435 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1438 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep full_markup
1440 if (scm_is_true (scm_call_1 ($2, $4)))
1441 $$ = scm_cons ($4, $3);
1443 $$ = scm_cons (loc_on_music (@3, $1), $3);
1444 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1447 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1449 if (scm_is_true (scm_call_1 ($2, $4)))
1452 MYREPARSE (@4, $2, UNSIGNED, $4);
1454 $$ = scm_cons (loc_on_music (@3, $1), $3);
1455 MYBACKUP (UNSIGNED, $4, @4);
1458 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1460 if (scm_is_true (scm_call_1 ($2, $4)))
1463 MYREPARSE (@4, $2, REAL, $4);
1465 $$ = scm_cons (loc_on_music (@3, $1), $3);
1466 MYBACKUP (REAL, $4, @4);
1469 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1471 if (scm_is_true (scm_call_1 ($2, $4)))
1473 $$ = scm_cons ($4, $3);
1475 $$ = scm_cons (loc_on_music (@3, $1), $3);
1476 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1479 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1481 if (scm_is_true (scm_call_1 ($2, $4)))
1483 $$ = scm_cons ($4, $3);
1485 $$ = scm_cons (loc_on_music (@3, $1), $3);
1486 MYBACKUP (FRACTION, $4, @4);
1489 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1491 SCM n = scm_difference ($5, SCM_UNDEFINED);
1492 if (scm_is_true (scm_call_1 ($2, n))) {
1494 MYREPARSE (@5, $2, REAL, n);
1496 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1497 t->set_property ("digit", $5);
1498 $$ = t->unprotect ();
1499 if (scm_is_true (scm_call_1 ($2, $$)))
1500 $$ = scm_cons ($$, $3);
1502 $$ = scm_cons (loc_on_music (@3, $1), $3);
1503 MYBACKUP (UNSIGNED, $5, @5);
1504 parser->lexer_->push_extra_token ('-');
1509 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1511 SCM n = scm_difference ($5, SCM_UNDEFINED);
1512 if (scm_is_true (scm_call_1 ($2, n))) {
1513 MYREPARSE (@5, $2, REAL, n);
1516 $$ = scm_cons (loc_on_music (@3, $1), $3);
1517 MYBACKUP (REAL, n, @5);
1520 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1522 SCM n = scm_difference ($5, SCM_UNDEFINED);
1523 if (scm_is_true (scm_call_1 ($2, n))) {
1524 $$ = scm_cons (n, $3);
1526 $$ = scm_cons (loc_on_music (@3, $1), $3);
1527 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1530 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1532 $$ = scm_cons ($4, $3);
1534 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1536 $$ = scm_cons ($4, $3);
1538 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1540 SCM res = try_string_variants ($2, $4);
1541 if (!SCM_UNBNDP (res))
1542 if (scm_is_pair (res)) {
1544 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1547 $$ = scm_cons (res, $3);
1549 $$ = scm_cons (loc_on_music (@3, $1), $3);
1550 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1553 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1555 SCM res = try_string_variants ($2, $4);
1556 if (!SCM_UNBNDP (res))
1557 if (scm_is_pair (res)) {
1559 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1562 $$ = scm_cons (res, $3);
1564 $$ = scm_cons (loc_on_music (@3, $1), $3);
1565 MYBACKUP (STRING, $4, @4);
1568 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1570 $$ = scm_cons ($1, $3);
1571 MYBACKUP(0, SCM_UNDEFINED, @3);
1573 | function_arglist_backup REPARSE bare_number
1575 $$ = check_scheme_arg (parser, @3,
1578 | function_arglist_backup REPARSE symbol_list_arg
1580 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1585 function_arglist_common
1586 | function_arglist_nonbackup
1589 function_arglist_common:
1590 function_arglist_bare
1591 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1593 $$ = check_scheme_arg (parser, @3,
1596 | EXPECT_SCM function_arglist_closed_optional bare_number
1598 $$ = check_scheme_arg (parser, @3,
1601 | EXPECT_SCM function_arglist_optional FRACTION
1603 $$ = check_scheme_arg (parser, @3,
1606 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1608 $$ = check_scheme_arg (parser, @3,
1611 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1613 SCM n = scm_difference ($4, SCM_UNDEFINED);
1614 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1616 | function_arglist_common_reparse REPARSE SCM_ARG
1618 $$ = check_scheme_arg (parser, @3,
1621 | function_arglist_common_reparse REPARSE lyric_element_music
1623 $$ = check_scheme_arg (parser, @3,
1626 | function_arglist_common_reparse REPARSE bare_number
1628 $$ = check_scheme_arg (parser, @3,
1631 | function_arglist_common_reparse REPARSE symbol_list_arg
1633 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1637 function_arglist_common_reparse:
1638 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1641 SCM res = try_string_variants ($1, $3);
1642 if (!SCM_UNBNDP (res))
1643 if (scm_is_pair (res))
1644 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1646 MYREPARSE (@3, $1, SCM_ARG, res);
1647 else if (scm_is_true
1649 ($1, make_music_from_simple (parser, @3, $3))))
1650 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1652 // This is going to flag a syntax error, we
1653 // know the predicate to be false.
1654 MYREPARSE (@3, $1, SCM_ARG, $3);
1656 | EXPECT_SCM function_arglist_optional STRING
1659 SCM res = try_string_variants ($1, $3);
1660 if (!SCM_UNBNDP (res))
1661 if (scm_is_pair (res))
1662 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1664 MYREPARSE (@3, $1, SCM_ARG, res);
1665 else if (scm_is_true
1667 ($1, make_music_from_simple (parser, @3, $3))))
1668 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1670 // This is going to flag a syntax error, we
1671 // know the predicate to be false.
1672 MYREPARSE (@3, $1, SCM_ARG, $3);
1674 | EXPECT_SCM function_arglist_optional full_markup
1677 if (scm_is_true (scm_call_1 ($1, $3)))
1678 MYREPARSE (@3, $1, SCM_ARG, $3);
1679 else if (scm_is_true
1681 ($1, make_music_from_simple (parser, @3, $3))))
1682 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1684 // This is going to flag a syntax error, we
1685 // know the predicate to be false.
1686 MYREPARSE (@3, $1, SCM_ARG, $3);
1688 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1691 SCM n = scm_difference ($4, SCM_UNDEFINED);
1692 if (scm_is_true (scm_call_1 ($1, n)))
1693 MYREPARSE (@4, $1, REAL, n);
1695 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1696 t->set_property ("digit", $4);
1697 SCM m = t->unprotect ();
1698 if (scm_is_true (scm_call_1 ($1, m)))
1699 MYREPARSE (@4, $1, SCM_ARG, m);
1701 MYREPARSE (@4, $1, SCM_ARG, $4);
1705 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1708 SCM n = scm_difference ($4, SCM_UNDEFINED);
1709 MYREPARSE (@4, $1, REAL, n);
1713 function_arglist_closed:
1714 function_arglist_closed_common
1715 | function_arglist_closed_nonbackup
1718 function_arglist_closed_common:
1719 function_arglist_bare
1720 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1722 $$ = check_scheme_arg (parser, @3,
1725 | EXPECT_SCM function_arglist_closed_optional bare_number
1727 $$ = check_scheme_arg (parser, @3,
1730 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1732 $$ = check_scheme_arg (parser, @3,
1733 scm_difference ($4, SCM_UNDEFINED),
1736 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1738 $$ = check_scheme_arg (parser, @3,
1741 | EXPECT_SCM function_arglist_optional FRACTION
1743 $$ = check_scheme_arg (parser, @3,
1746 | function_arglist_common_reparse REPARSE SCM_ARG
1748 $$ = check_scheme_arg (parser, @3,
1751 | function_arglist_common_reparse REPARSE bare_number
1753 $$ = check_scheme_arg (parser, @3,
1756 | function_arglist_common_reparse REPARSE symbol_list_arg
1758 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1762 function_arglist_optional:
1763 function_arglist_keep %prec FUNCTION_ARGLIST
1764 | function_arglist_backup BACKUP
1765 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1767 $$ = scm_cons ($1, $3);
1769 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1771 $$ = scm_cons ($1, $3);
1775 function_arglist_closed_optional:
1776 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1777 | function_arglist_backup BACKUP
1778 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1780 $$ = scm_cons ($1, $3);
1782 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1784 $$ = scm_cons ($1, $3);
1788 embedded_scm_closed:
1790 | scm_function_call_closed
1793 embedded_scm_arg_closed:
1794 embedded_scm_bare_arg
1795 | scm_function_call_closed
1799 scm_function_call_closed:
1800 SCM_FUNCTION function_arglist_closed {
1801 $$ = MAKE_SYNTAX ("music-function", @$,
1803 } %prec FUNCTION_ARGLIST
1806 function_arglist_bare:
1807 EXPECT_NO_MORE_ARGS {
1810 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1811 $$ = scm_cons ($3, $2);
1813 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1814 $$ = scm_cons ($3, $2);
1816 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1817 $$ = scm_cons ($1, $3);
1819 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1820 $$ = scm_cons ($1, $3);
1822 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1823 $$ = scm_cons ($1, $3);
1827 music_function_call:
1828 MUSIC_FUNCTION function_arglist {
1829 $$ = MAKE_SYNTAX ("music-function", @$,
1836 /**/ { $$ = SCM_EOL; }
1837 | '=' simple_string {
1844 | repeated_music { $$ = $1; }
1845 | re_rhythmed_music { $$ = $1; }
1846 | complex_music_prefix music
1848 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1852 complex_music_prefix:
1853 CONTEXT simple_string optional_id optional_context_mod {
1854 Context_mod *ctxmod = unsmob_context_mod ($4);
1857 mods = ctxmod->get_mods ();
1858 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1860 | NEWCONTEXT simple_string optional_id optional_context_mod {
1861 Context_mod *ctxmod = unsmob_context_mod ($4);
1864 mods = ctxmod->get_mods ();
1865 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1870 mode_changing_head grouped_music_list {
1871 if ($1 == ly_symbol2scm ("chords"))
1873 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1879 parser->lexer_->pop_state ();
1881 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1882 Context_mod *ctxmod = unsmob_context_mod ($2);
1885 mods = ctxmod->get_mods ();
1886 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1887 if ($1 == ly_symbol2scm ("ChordNames"))
1889 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1891 parser->lexer_->pop_state ();
1897 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1898 parser->lexer_->push_note_state (nn);
1900 $$ = ly_symbol2scm ("notes");
1904 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1905 parser->lexer_->push_note_state (nn);
1907 $$ = ly_symbol2scm ("drums");
1910 parser->lexer_->push_figuredbass_state ();
1912 $$ = ly_symbol2scm ("figures");
1915 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1916 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1917 nn = parser->lexer_->lookup_identifier ("pitchnames");
1918 parser->lexer_->push_chord_state (nn);
1919 $$ = ly_symbol2scm ("chords");
1923 { parser->lexer_->push_lyric_state ();
1924 $$ = ly_symbol2scm ("lyrics");
1928 mode_changing_head_with_context:
1930 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1931 parser->lexer_->push_note_state (nn);
1933 $$ = ly_symbol2scm ("DrumStaff");
1936 parser->lexer_->push_figuredbass_state ();
1938 $$ = ly_symbol2scm ("FiguredBass");
1941 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1942 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1943 nn = parser->lexer_->lookup_identifier ("pitchnames");
1944 parser->lexer_->push_chord_state (nn);
1945 $$ = ly_symbol2scm ("ChordNames");
1948 { parser->lexer_->push_lyric_state ();
1949 $$ = ly_symbol2scm ("Lyrics");
1954 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1957 /* Can also use music at the expensive of two S/Rs similar to
1958 \repeat \alternative */
1959 parser->lexer_->pop_state ();
1961 $$ = scm_cons ($3, SCM_EOL);
1963 | new_lyrics ADDLYRICS {
1964 parser->lexer_->push_lyric_state ();
1966 parser->lexer_->pop_state ();
1967 $$ = scm_cons ($4, $1);
1972 composite_music new_lyrics {
1973 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1975 | LYRICSTO simple_string {
1976 parser->lexer_->push_lyric_state ();
1978 parser->lexer_->pop_state ();
1979 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1984 CHANGE STRING '=' STRING {
1985 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1992 $$ = scm_reverse_x ($1, SCM_EOL);
1994 | symbol_list_rev property_path {
1995 $$ = scm_reverse_x ($1, $2);
2001 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2002 scm_string_to_symbol ($1), $3);
2004 | UNSET simple_string {
2005 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2006 scm_string_to_symbol ($2));
2008 | OVERRIDE property_path '=' scalar {
2009 if (scm_ilength ($2) < 2) {
2010 parser->parser_error (@2, _("bad grob property path"));
2013 $$ = scm_cons (ly_symbol2scm ("push"),
2014 scm_cons2 (scm_car ($2),
2019 | REVERT revert_arg {
2020 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2024 // This is all quite awkward for the sake of substantial backward
2025 // compatibility while at the same time allowing a more "natural" form
2026 // of specification not separating grob specification from grob
2027 // property path. The purpose of this definition of revert_arg is to
2028 // allow the symbol list which specifies grob and property to revert
2029 // to be optionally be split into two parts after the grob (which in
2030 // this case is just the first element of the list). symbol_list_part
2031 // is only one path component, but it can be parsed without lookahead,
2032 // so we can follow it with a synthetic BACKUP token when needed. If
2033 // the first symbol_list_part already contains multiple elements (only
2034 // possible if a Scheme expression provides them), we just parse for
2035 // additional elements introduced by '.', which is what the
2036 // SYMBOL_LIST backup in connection with the immediately following
2037 // rule using symbol_list_arg does.
2039 // As long as we don't have our coffers filled with both grob and at
2040 // least one grob property specification, the rest of the required
2041 // symbol list chain may be provided either with or without a leading
2042 // dot. This is for both allowing the traditional
2043 // \revert Accidental #'color
2044 // as well as well as the "naive" form
2045 // \revert Accidental.color
2050 if (scm_is_null ($1)
2051 || scm_is_null (scm_cdr ($1)))
2052 MYBACKUP (SCM_ARG, $1, @1);
2054 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2056 | revert_arg BACKUP symbol_list_arg
2062 // revert_arg_part delivers results in reverse
2065 | revert_arg BACKUP SCM_ARG '.' symbol_list_part
2067 $$ = scm_append_x (scm_list_2 ($5, $3));
2069 | revert_arg BACKUP SCM_ARG symbol_list_part
2071 $$ = scm_append_x (scm_list_2 ($4, $3));
2076 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2077 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2079 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2080 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2081 | DENIES { $$ = ly_symbol2scm ("denies"); }
2083 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2084 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2085 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2086 | NAME { $$ = ly_symbol2scm ("context-name"); }
2090 property_operation { $$ = $1; }
2091 | context_def_mod STRING {
2092 $$ = scm_list_2 ($1, $2);
2094 | context_def_mod embedded_scm
2096 if (!scm_is_string ($2)
2097 && ly_symbol2scm ("consists") != $1
2098 && ly_symbol2scm ("remove") != $1)
2101 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2105 $$ = scm_list_2 ($1, $2);
2110 // If defined, at least two members.
2114 SCM l = scm_reverse_x ($1, SCM_EOL);
2117 (scm_object_property (scm_car (l),
2118 ly_symbol2scm ("is-grob?"))))
2119 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2120 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2121 parser->parser_error (@1, _ ("bad grob property path"));
2128 // If defined, at least three members
2132 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2134 parser->parser_error (@1, _ ("bad grob property path"));
2138 | grob_prop_spec property_path
2140 if (!SCM_UNBNDP ($1)) {
2141 $$ = scm_append_x (scm_list_2 ($1, $2));
2142 if (scm_is_null (scm_cddr ($$))) {
2143 parser->parser_error (@$, _ ("bad grob property path"));
2151 // Exactly two elements or undefined
2155 SCM l = scm_reverse_x ($1, SCM_EOL);
2156 switch (scm_ilength (l)) {
2158 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2162 parser->parser_error (@1, _ ("bad context property path"));
2169 simple_music_property_def:
2170 OVERRIDE grob_prop_path '=' scalar {
2171 if (SCM_UNBNDP ($2))
2174 $$ = scm_list_5 (scm_car ($2),
2175 ly_symbol2scm ("OverrideProperty"),
2181 | REVERT simple_revert_context revert_arg {
2182 $$ = scm_list_4 ($2,
2183 ly_symbol2scm ("RevertProperty"),
2187 | SET context_prop_spec '=' scalar {
2188 if (SCM_UNBNDP ($2))
2191 $$ = scm_list_4 (scm_car ($2),
2192 ly_symbol2scm ("PropertySet"),
2196 | UNSET context_prop_spec {
2197 if (SCM_UNBNDP ($2))
2200 $$ = scm_list_3 (scm_car ($2),
2201 ly_symbol2scm ("PropertyUnset"),
2207 // This is all quite awkward for the sake of substantial backward
2208 // compatibility while at the same time allowing a more "natural" form
2209 // of specification not separating grob specification from grob
2210 // property path. The purpose of this definition of
2211 // simple_revert_context is to allow the symbol list which specifies
2212 // grob and property to revert to be optionally be split into two
2213 // parts after the grob (which may be preceded by a context
2214 // specification, a case which we distinguish by checking whether the
2215 // first symbol is a valid grob symbol instead).
2217 // See revert_arg above for the main work horse of this arrangement.
2218 // simple_revert_context just caters for the context and delegates the
2219 // rest of the job to revert_arg.
2221 simple_revert_context:
2224 $1 = scm_reverse_x ($1, SCM_EOL);
2225 if (scm_is_null ($1)
2227 (scm_object_property (scm_car ($1),
2228 ly_symbol2scm ("is-grob?")))) {
2229 $$ = ly_symbol2scm ("Bottom");
2230 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2233 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2240 simple_music_property_def {
2241 if (SCM_UNBNDP ($1))
2242 $$ = MAKE_SYNTAX ("void-music", @1);
2244 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2253 | string '+' string {
2254 if (!scm_is_string ($1)) {
2255 parser->parser_error (@1, (_ ("simple string expected")));
2256 $1 = scm_string (SCM_EOL);
2258 if (!scm_is_string ($3)) {
2259 parser->parser_error (@3, (_ ("simple string expected")));
2260 $3 = scm_string (SCM_EOL);
2262 $$ = scm_string_append (scm_list_2 ($1, $3));
2266 simple_string: STRING {
2271 if (scm_is_string ($1)) {
2274 parser->parser_error (@1, (_ ("simple string expected")));
2275 $$ = scm_string (SCM_EOL);
2289 embedded_scm_arg_closed
2298 simple_element post_events {
2299 // Let the rhythmic music iterator sort this mess out.
2300 if (scm_is_pair ($2)) {
2301 $$ = make_music_from_simple (parser, @1, $1);
2302 if (unsmob_music ($$))
2303 unsmob_music ($$)->set_property ("articulations",
2304 scm_reverse_x ($2, SCM_EOL));
2306 parser->parser_error (@1, _("music expected"));
2309 | simple_chord_elements post_events {
2310 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2313 /* why is this giving wrong start location? -ns
2315 i.set_location (@1, @2);
2316 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2318 | CHORD_REPETITION optional_notemode_duration post_events {
2320 i.set_location (@1, @3);
2321 $$ = MAKE_SYNTAX ("repetition-chord", i,
2322 $2, scm_reverse_x ($3, SCM_EOL));
2324 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2326 i.set_location (@1, @3);
2327 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2328 scm_reverse_x ($3, SCM_EOL));
2331 | note_chord_element
2336 chord_body optional_notemode_duration post_events
2338 Music *m = unsmob_music ($1);
2339 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2340 SCM es = m->get_property ("elements");
2341 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2343 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2344 unsmob_music (scm_car (s))->set_property ("duration", dur);
2345 es = ly_append2 (es, postevs);
2347 m-> set_property ("elements", es);
2349 $$ = m->self_scm ();
2354 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2356 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2360 chord_body_elements:
2361 /* empty */ { $$ = SCM_EOL; }
2362 | chord_body_elements chord_body_element {
2363 if (!SCM_UNBNDP ($2))
2364 $$ = scm_cons ($2, $1);
2369 pitch exclamations questions octave_check post_events
2371 bool q = to_boolean ($3);
2372 bool ex = to_boolean ($2);
2376 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2377 n->set_property ("pitch", $1);
2379 n->set_property ("cautionary", SCM_BOOL_T);
2381 n->set_property ("force-accidental", SCM_BOOL_T);
2383 if (scm_is_pair (post)) {
2384 SCM arts = scm_reverse_x (post, SCM_EOL);
2385 n->set_property ("articulations", arts);
2387 if (scm_is_number (check))
2389 int q = scm_to_int (check);
2390 n->set_property ("absolute-octave", scm_from_int (q-1));
2393 $$ = n->unprotect ();
2395 | DRUM_PITCH post_events {
2396 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2397 n->set_property ("drum-type", $1);
2399 if (scm_is_pair ($2)) {
2400 SCM arts = scm_reverse_x ($2, SCM_EOL);
2401 n->set_property ("articulations", arts);
2403 $$ = n->unprotect ();
2405 | music_function_chord_body
2407 Music *m = unsmob_music ($1);
2409 while (m && m->is_mus_type ("music-wrapper-music")) {
2410 $$ = m->get_property ("element");
2411 m = unsmob_music ($$);
2414 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2415 parser->parser_error (@$, _ ("not a rhythmic event"));
2421 music_function_chord_body:
2426 // Event functions may only take closed arglists, otherwise it would
2427 // not be clear whether a following postevent should be associated
2428 // with the last argument of the event function or with the expression
2429 // for which the function call acts itself as event.
2431 music_function_call_closed:
2432 MUSIC_FUNCTION function_arglist_closed {
2433 $$ = MAKE_SYNTAX ("music-function", @$,
2438 event_function_event:
2439 EVENT_FUNCTION function_arglist_closed {
2440 $$ = MAKE_SYNTAX ("music-function", @$,
2450 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2451 m->set_property ("span-direction", scm_from_int (START));
2452 $$ = m->unprotect();
2455 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2456 m->set_property ("span-direction", scm_from_int (STOP));
2457 $$ = m->unprotect ();
2460 $$ = MAKE_SYNTAX ("voice-separator", @$);
2463 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2465 Music *m = unsmob_music (pipe);
2470 $$ = m->unprotect ();
2473 $$ = MAKE_SYNTAX ("bar-check", @$);
2480 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2492 | post_events post_event {
2493 unsmob_music ($2)->set_spot (@2);
2494 $$ = scm_cons ($2, $$);
2498 post_event_nofinger:
2499 direction_less_event {
2502 | script_dir music_function_call_closed {
2504 if (!SCM_UNBNDP ($1))
2506 unsmob_music ($$)->set_property ("direction", $1);
2510 if (!parser->lexer_->is_lyric_state ())
2511 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2512 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2515 if (!parser->lexer_->is_lyric_state ())
2516 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2517 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2519 | script_dir direction_reqd_event {
2520 if (!SCM_UNBNDP ($1))
2522 Music *m = unsmob_music ($2);
2523 m->set_property ("direction", $1);
2527 | script_dir direction_less_event {
2528 if (!SCM_UNBNDP ($1))
2530 Music *m = unsmob_music ($2);
2531 m->set_property ("direction", $1);
2538 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2543 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2554 string_number_event:
2556 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2557 s->set_property ("string-number", $1);
2558 $$ = s->unprotect ();
2562 direction_less_char:
2564 $$ = ly_symbol2scm ("bracketOpenSymbol");
2567 $$ = ly_symbol2scm ("bracketCloseSymbol");
2570 $$ = ly_symbol2scm ("tildeSymbol");
2573 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2576 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2579 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2582 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2585 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2588 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2591 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2595 direction_less_event:
2596 direction_less_char {
2597 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2599 if (unsmob_music (predefd))
2601 m = unsmob_music (predefd)->clone ();
2606 m = MY_MAKE_MUSIC ("Music", @$);
2608 $$ = m->unprotect ();
2610 | string_number_event
2611 | EVENT_IDENTIFIER {
2615 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2616 a->set_property ("tremolo-type", $1);
2617 $$ = a->unprotect ();
2619 | event_function_event
2622 direction_reqd_event:
2626 | script_abbreviation {
2627 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2628 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2629 if (scm_is_string (s))
2630 a->set_property ("articulation-type", s);
2631 else parser->parser_error (@1, _ ("expecting string as script definition"));
2632 $$ = a->unprotect ();
2637 /**/ { $$ = SCM_EOL; }
2638 | '=' quotes { $$ = $2; }
2652 $$ = scm_from_int (1);
2655 $$ = scm_oneplus ($1);
2661 $$ = scm_from_int (-1);
2664 $$ = scm_oneminus ($1);
2669 NOTENAME_PITCH quotes {
2670 if (!scm_is_eq (SCM_INUM0, $2))
2672 Pitch p = *unsmob_pitch ($1);
2673 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2674 $$ = p.smobbed_copy ();
2684 TONICNAME_PITCH quotes {
2685 if (!scm_is_eq (SCM_INUM0, $2))
2687 Pitch p = *unsmob_pitch ($1);
2688 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2689 $$ = p.smobbed_copy ();
2699 pitch_also_in_chords:
2706 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2707 t->set_property ("text", $1);
2708 $$ = t->unprotect ();
2711 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2712 t->set_property ("text",
2713 make_simple_markup ($1));
2714 $$ = t->unprotect ();
2716 | embedded_scm_closed
2718 Music *m = unsmob_music ($1);
2719 if (m && m->is_mus_type ("post-event"))
2721 else if (Text_interface::is_markup ($1)) {
2722 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2723 t->set_property ("text", $1);
2724 $$ = t->unprotect ();
2726 parser->parser_error (@1, _ ("not an articulation"));
2732 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2733 t->set_property ("digit", $1);
2734 $$ = t->unprotect ();
2738 script_abbreviation:
2740 $$ = scm_from_locale_string ("Hat");
2743 $$ = scm_from_locale_string ("Plus");
2746 $$ = scm_from_locale_string ("Dash");
2749 $$ = scm_from_locale_string ("Bar");
2752 $$ = scm_from_locale_string ("Larger");
2755 $$ = scm_from_locale_string ("Dot");
2758 $$ = scm_from_locale_string ("Underscore");
2763 '_' { $$ = scm_from_int (DOWN); }
2764 | '^' { $$ = scm_from_int (UP); }
2765 | '-' { $$ = SCM_UNDEFINED; }
2769 multiplied_duration {
2774 maybe_notemode_duration:
2778 | multiplied_duration {
2780 parser->default_duration_ = *unsmob_duration ($$);
2785 optional_notemode_duration:
2786 maybe_notemode_duration
2788 if (SCM_UNBNDP ($$))
2789 $$ = parser->default_duration_.smobbed_copy ();
2796 int n = scm_to_int ($1);
2797 if (!is_duration (n))
2798 parser->parser_error (@1, _f ("not a duration: %d", n));
2802 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2804 | DURATION_IDENTIFIER dots {
2805 Duration *d = unsmob_duration ($1);
2806 Duration k (d->duration_log (),
2807 d->dot_count () + scm_to_int ($2));
2808 k = k.compressed (d->factor ());
2809 scm_remember_upto_here_1 ($1);
2810 $$ = k.smobbed_copy ();
2814 multiplied_duration:
2818 | multiplied_duration '*' UNSIGNED {
2819 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2821 | multiplied_duration '*' FRACTION {
2822 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2824 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2833 $$ = scm_oneplus ($1);
2842 int n = scm_to_int ($2);
2843 if (!is_duration (n))
2844 parser->parser_error (@2, _f ("not a duration: %d", n));
2850 UNSIGNED { $$ = $1; }
2851 | STRING { $$ = $1; }
2852 | full_markup { $$ = $1; }
2855 // as an integer, it needs to be non-negative, and otherwise
2856 // it needs to be suitable as a markup.
2857 if (scm_is_integer ($1)
2858 ? scm_is_true (scm_negative_p ($1))
2859 : !Text_interface::is_markup ($1))
2861 parser->parser_error (@1, _ ("bass number expected"));
2867 figured_bass_alteration:
2868 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2869 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2870 | '!' { $$ = scm_from_int (0); }
2875 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2876 $$ = bfr->unprotect ();
2879 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2880 $$ = bfr->self_scm ();
2882 if (scm_is_number ($1))
2883 bfr->set_property ("figure", $1);
2884 else if (Text_interface::is_markup ($1))
2885 bfr->set_property ("text", $1);
2891 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2893 | bass_figure figured_bass_alteration {
2894 Music *m = unsmob_music ($1);
2895 if (scm_to_double ($2)) {
2896 SCM salter = m->get_property ("alteration");
2897 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2898 m->set_property ("alteration",
2899 scm_sum (alter, $2));
2901 m->set_property ("alteration", scm_from_int (0));
2904 | bass_figure figured_bass_modification {
2905 Music *m = unsmob_music ($1);
2906 if ($2 == ly_symbol2scm ("plus"))
2908 m->set_property ("augmented", SCM_BOOL_T);
2910 else if ($2 == ly_symbol2scm ("slash"))
2912 m->set_property ("diminished", SCM_BOOL_T);
2914 else if ($2 == ly_symbol2scm ("exclamation"))
2916 m->set_property ("no-continuation", SCM_BOOL_T);
2918 else if ($2 == ly_symbol2scm ("backslash"))
2920 m->set_property ("augmented-slash", SCM_BOOL_T);
2926 figured_bass_modification:
2928 $$ = ly_symbol2scm ("plus");
2931 $$ = ly_symbol2scm ("exclamation");
2934 $$ = ly_symbol2scm ("slash");
2937 $$ = ly_symbol2scm ("backslash");
2947 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2955 | figure_list br_bass_figure {
2956 $$ = scm_cons ($2, $1);
2961 FIGURE_OPEN figure_list FIGURE_CLOSE {
2962 $$ = scm_reverse_x ($2, SCM_EOL);
2968 /**/ { $$ = SCM_BOOL_F; }
2969 | REST { $$ = SCM_BOOL_T; }
2973 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2974 if (!parser->lexer_->is_note_state ())
2975 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2976 if (!SCM_UNBNDP ($2)
2978 || scm_is_number ($4)
2980 || scm_is_true ($6))
2983 if (scm_is_true ($6))
2984 n = MY_MAKE_MUSIC ("RestEvent", @$);
2986 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2988 n->set_property ("pitch", $1);
2989 if (SCM_UNBNDP ($5))
2990 n->set_property ("duration",
2991 parser->default_duration_.smobbed_copy ());
2993 n->set_property ("duration", $5);
2995 if (scm_is_number ($4))
2997 int q = scm_to_int ($4);
2998 n->set_property ("absolute-octave", scm_from_int (q-1));
3001 if (to_boolean ($3))
3002 n->set_property ("cautionary", SCM_BOOL_T);
3003 if (to_boolean ($2) || to_boolean ($3))
3004 n->set_property ("force-accidental", SCM_BOOL_T);
3006 $$ = n->unprotect ();
3009 | DRUM_PITCH optional_notemode_duration {
3010 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3011 n->set_property ("duration", $2);
3012 n->set_property ("drum-type", $1);
3014 $$ = n->unprotect ();
3016 | RESTNAME optional_notemode_duration {
3018 if (ly_scm2string ($1) == "s") {
3020 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3023 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3026 ev->set_property ("duration", $2);
3027 $$ = ev->unprotect ();
3031 simple_chord_elements:
3033 if (!parser->lexer_->is_chord_state ())
3034 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3037 | figure_spec optional_notemode_duration {
3038 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3040 unsmob_music (scm_car (s))->set_property ("duration", $2);
3056 lyric_element_music:
3057 lyric_element optional_notemode_duration post_events {
3058 if (!parser->lexer_->is_lyric_state ())
3059 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
3060 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3061 if (scm_is_pair ($3))
3062 unsmob_music ($$)->set_property
3063 ("articulations", scm_reverse_x ($3, SCM_EOL));
3068 steno_tonic_pitch optional_notemode_duration {
3069 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3071 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3072 SCM its = scm_reverse_x ($4, SCM_EOL);
3073 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3081 | chord_items chord_item {
3082 $$ = scm_cons ($2, $$);
3088 $$ = ly_symbol2scm ("chord-colon");
3091 $$ = ly_symbol2scm ("chord-caret");
3093 | CHORD_SLASH steno_tonic_pitch {
3094 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3096 | CHORD_BASS steno_tonic_pitch {
3097 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3106 $$ = scm_reverse_x ($1, SCM_EOL);
3114 step_number { $$ = scm_cons ($1, SCM_EOL); }
3115 | step_numbers '.' step_number {
3116 $$ = scm_cons ($3, $$);
3122 $$ = make_chord_step ($1, 0);
3125 $$ = make_chord_step ($1, SHARP_ALTERATION);
3127 | UNSIGNED CHORD_MINUS {
3128 $$ = make_chord_step ($1, FLAT_ALTERATION);
3136 | UNSIGNED '~' UNSIGNED {
3137 $$ = scm_cons ($1, $3);
3144 TODO: should deprecate in favor of Scheme?
3148 number_expression '+' number_term {
3149 $$ = scm_sum ($1, $3);
3151 | number_expression '-' number_term {
3152 $$ = scm_difference ($1, $3);
3161 | number_factor '*' number_factor {
3162 $$ = scm_product ($1, $3);
3164 | number_factor '/' number_factor {
3165 $$ = scm_divide ($1, $3);
3170 '-' number_factor { /* %prec UNARY_MINUS */
3171 $$ = scm_difference ($2, SCM_UNDEFINED);
3179 | UNSIGNED NUMBER_IDENTIFIER {
3180 $$ = scm_product ($1, $2);
3182 | REAL NUMBER_IDENTIFIER {
3183 $$ = scm_product ($1, $2);
3199 { $$ = SCM_UNDEFINED; }
3202 if (SCM_UNBNDP ($1))
3210 { $$ = SCM_UNDEFINED; }
3213 if (SCM_UNBNDP ($1))
3222 { parser->lexer_->push_markup_state (); }
3225 parser->lexer_->pop_state ();
3231 { parser->lexer_->push_markup_state (); }
3234 parser->lexer_->pop_state ();
3239 simple_markup_list {
3240 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3242 | markup_head_1_list simple_markup {
3243 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3253 if (Text_interface::is_markup ($1))
3254 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3255 else if (Text_interface::is_markup_list ($1))
3256 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3258 parser->parser_error (@1, _ ("not a markup"));
3259 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3266 markup_composed_list {
3269 | markup_braced_list {
3272 | markup_command_list {
3273 $$ = scm_list_1 ($1);
3275 | markup_scm MARKUPLIST_IDENTIFIER
3285 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $1));
3291 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3292 parser->lexer_->push_note_state (nn);
3293 } '{' score_body '}' {
3295 parser->lexer_->pop_state ();
3299 markup_composed_list:
3300 markup_head_1_list markup_braced_list {
3301 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3307 '{' markup_braced_list_body '}' {
3308 $$ = scm_reverse_x ($2, SCM_EOL);
3312 markup_braced_list_body:
3313 /* empty */ { $$ = SCM_EOL; }
3314 | markup_braced_list_body markup {
3315 $$ = scm_cons ($2, $1);
3317 | markup_braced_list_body simple_markup_list {
3318 $$ = scm_reverse_x ($2, $1);
3322 markup_command_list:
3323 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3324 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3328 markup_command_basic_arguments:
3329 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3330 $$ = scm_cons ($3, $2);
3332 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3333 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3335 | EXPECT_NO_MORE_ARGS {
3340 markup_command_list_arguments:
3341 markup_command_basic_arguments { $$ = $1; }
3342 | EXPECT_MARKUP markup_command_list_arguments markup {
3343 $$ = scm_cons ($3, $2);
3348 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3349 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3354 markup_head_1_item {
3355 $$ = scm_list_1 ($1);
3357 | markup_head_1_list markup_head_1_item {
3358 $$ = scm_cons ($2, $1);
3364 $$ = make_simple_markup ($1);
3366 | MARKUP_FUNCTION markup_command_basic_arguments {
3367 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3369 | markup_scm MARKUP_IDENTIFIER
3375 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $1);
3380 markup_head_1_list simple_markup {
3381 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3382 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3392 Lily_parser::set_yydebug (bool x)
3398 Lily_parser::do_yyparse ()
3400 SCM retval = SCM_UNDEFINED;
3401 yyparse (this, &retval);
3411 It is a little strange to have this function in this file, but
3412 otherwise, we have to import music classes into the lexer.
3416 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3418 if (unsmob_book (sid)) {
3419 Book *book = unsmob_book (sid)->clone ();
3420 *destination = book->self_scm ();
3423 return BOOK_IDENTIFIER;
3424 } else if (scm_is_number (sid)) {
3426 return NUMBER_IDENTIFIER;
3427 } else if (unsmob_context_def (sid)) {
3428 Context_def *def= unsmob_context_def (sid)->clone ();
3430 *destination = def->self_scm ();
3433 return CONTEXT_DEF_IDENTIFIER;
3434 } else if (unsmob_context_mod (sid)) {
3435 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3437 return CONTEXT_MOD_IDENTIFIER;
3438 } else if (Music *mus = unsmob_music (sid)) {
3439 mus = mus->clone ();
3440 *destination = mus->self_scm ();
3441 unsmob_music (*destination)->
3442 set_property ("origin",
3443 make_input (override_input (last_input_)));
3445 bool is_event = mus->is_mus_type ("post-event");
3447 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3448 } else if (unsmob_pitch (sid)) {
3449 *destination = unsmob_pitch (sid)->smobbed_copy ();
3450 return PITCH_IDENTIFIER;
3451 } else if (unsmob_duration (sid)) {
3452 *destination = unsmob_duration (sid)->smobbed_copy ();
3453 return DURATION_IDENTIFIER;
3454 } else if (unsmob_output_def (sid)) {
3455 Output_def *p = unsmob_output_def (sid);
3458 *destination = p->self_scm ();
3460 return OUTPUT_DEF_IDENTIFIER;
3467 get_next_unique_context_id ()
3469 return scm_from_locale_string ("$uniqueContextId");
3474 get_next_unique_lyrics_context_id ()
3476 static int new_context_count;
3478 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3479 return scm_from_locale_string (s);
3482 // check_scheme_arg checks one argument with a given predicate for use
3483 // in an argument list and throws a syntax error if it is unusable.
3484 // The argument is prepended to the argument list in any case. After
3485 // throwing a syntax error, the argument list is terminated with #f as
3486 // its last cdr in order to mark it as uncallable while not losing
3487 // track of its total length.
3489 // There are a few special considerations: if optional argument disp
3490 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3491 // instead of arg in a prospective error message. This is useful if
3492 // arg is not the actual argument but rather a transformation of it.
3494 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3495 // and an error message using disp is produced unconditionally.
3497 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3498 SCM arg, SCM args, SCM pred, SCM disp)
3500 if (SCM_UNBNDP (arg))
3501 args = scm_cons (disp, args);
3503 args = scm_cons (arg, args);
3504 if (scm_is_true (scm_call_1 (pred, arg)))
3507 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3508 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3509 SCM_UNBNDP (disp) ? arg : disp);
3510 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3514 SCM loc_on_music (Input loc, SCM arg)
3516 if (Music *m = unsmob_music (arg))
3520 return m->unprotect ();
3526 try_string_variants (SCM pred, SCM str)
3528 // a matching predicate is always ok
3529 if (scm_is_true (scm_call_1 (pred, str)))
3531 // a symbol may be interpreted as a list of symbols if it helps
3532 if (scm_is_symbol (str)) {
3533 str = scm_list_1 (str);
3534 if (scm_is_true (scm_call_1 (pred, str)))
3536 return SCM_UNDEFINED;
3539 // If this cannot be a string representation of a symbol list,
3542 if (!is_regular_identifier (str, true))
3543 return SCM_UNDEFINED;
3545 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3546 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3547 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3549 // Let's attempt the symbol list interpretation first.
3551 if (scm_is_true (scm_call_1 (pred, str)))
3554 // If there is just one symbol in the list, we might interpret
3555 // it as a single symbol
3557 if (scm_is_null (scm_cdr (str)))
3559 str = scm_car (str);
3560 if (scm_is_true (scm_call_1 (pred, str)))
3564 return SCM_UNDEFINED;
3568 is_regular_identifier (SCM id, bool multiple)
3570 if (!scm_is_string (id))
3573 string str = ly_scm2string (id);
3575 bool middle = false;
3577 for (string::iterator it=str.begin(); it != str.end (); it++)
3580 if ((c >= 'a' && c <= 'z')
3581 || (c >= 'A' && c <= 'Z')
3584 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3593 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3595 if (unsmob_music (simple))
3597 if (parser->lexer_->is_note_state ()) {
3598 if (scm_is_symbol (simple)) {
3599 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3600 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3601 n->set_property ("drum-type", simple);
3602 return n->unprotect ();
3604 if (unsmob_pitch (simple)) {
3605 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3606 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3607 n->set_property ("pitch", simple);
3608 return n->unprotect ();
3611 } else if (parser->lexer_->is_lyric_state ()) {
3612 if (Text_interface::is_markup (simple))
3613 return MAKE_SYNTAX ("lyric-event", loc, simple,
3614 parser->default_duration_.smobbed_copy ());
3615 } else if (parser->lexer_->is_chord_state ()) {
3616 if (unsmob_pitch (simple))
3617 return make_chord_elements (loc, simple,
3618 parser->default_duration_.smobbed_copy (),
3625 make_music_with_input (SCM name, Input where)
3627 Music *m = make_music_by_name (name);
3628 m->set_spot (where);
3633 make_simple_markup (SCM a)
3641 return t && t == 1 << intlog2 (t);
3645 make_chord_step (SCM step_scm, Rational alter)
3647 int step = scm_to_int (step_scm);
3650 alter += FLAT_ALTERATION;
3654 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3655 return m.smobbed_copy ();
3660 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3662 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3663 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3664 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3666 unsmob_music (scm_car (s))->set_spot (loc);
3672 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3674 Lily_lexer *lex = parser->lexer_;
3678 lex->prepare_for_next_token ();
3679 return lex->yylex ();