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) make_music_with_input (ly_symbol2scm (x), spot)
200 - Don't use lily module, create a new module instead.
201 - delay application of the function
203 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
204 scm_apply_0 (proc, args)
205 /* Syntactic Sugar. */
206 #define MAKE_SYNTAX(name, location, ...) \
207 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED))
208 #define START_MAKE_SYNTAX(name, ...) \
209 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
210 #define FINISH_MAKE_SYNTAX(start, location, ...) \
211 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (location), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
213 SCM get_next_unique_context_id ();
214 SCM get_next_unique_lyrics_context_id ();
221 #define _(x) gettext (x)
225 static Music *make_music_with_input (SCM name, Input where);
226 SCM check_scheme_arg (Lily_parser *parser, Input loc,
227 SCM arg, SCM args, SCM pred);
228 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
229 SCM loc_on_music (Input loc, SCM arg);
230 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
231 SCM make_chord_step (SCM step, Rational alter);
232 SCM make_simple_markup (SCM a);
233 bool is_duration (int t);
234 bool is_regular_identifier (SCM id);
235 SCM try_string_variants (SCM pred, SCM str);
236 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
240 /* The third option is an alias that will be used to display the
241 syntax error. Bison CVS now correctly handles backslash escapes.
243 FIXME: Bison needs to translate some of these, eg, STRING.
247 /* Keyword tokens with plain escaped name. */
248 %token END_OF_FILE 0 "end of input"
249 %token ACCEPTS "\\accepts"
250 %token ADDLYRICS "\\addlyrics"
251 %token ALIAS "\\alias"
252 %token ALTERNATIVE "\\alternative"
254 %token BOOKPART "\\bookpart"
255 %token CHANGE "\\change"
256 %token CHORDMODE "\\chordmode"
257 %token CHORDS "\\chords"
258 %token CONSISTS "\\consists"
259 %token CONTEXT "\\context"
260 %token DEFAULT "\\default"
261 %token DEFAULTCHILD "\\defaultchild"
262 %token DENIES "\\denies"
263 %token DESCRIPTION "\\description"
264 %token DRUMMODE "\\drummode"
265 %token DRUMS "\\drums"
266 %token FIGUREMODE "\\figuremode"
267 %token FIGURES "\\figures"
268 %token HEADER "\\header"
269 %token INVALID "\\version-error"
270 %token LAYOUT "\\layout"
271 %token LYRICMODE "\\lyricmode"
272 %token LYRICS "\\lyrics"
273 %token LYRICSTO "\\lyricsto"
274 %token MARKUP "\\markup"
275 %token MARKUPLIST "\\markuplist"
278 %token NOTEMODE "\\notemode"
279 %token OVERRIDE "\\override"
280 %token PAPER "\\paper"
281 %token REMOVE "\\remove"
282 %token REPEAT "\\repeat"
284 %token REVERT "\\revert"
285 %token SCORE "\\score"
286 %token SEQUENTIAL "\\sequential"
288 %token SIMULTANEOUS "\\simultaneous"
289 %token TEMPO "\\tempo"
291 %token UNSET "\\unset"
294 /* Keyword token exceptions. */
295 %token NEWCONTEXT "\\new"
298 /* Other string tokens. */
300 %token CHORD_BASS "/+"
301 %token CHORD_CARET "^"
302 %token CHORD_COLON ":"
303 %token CHORD_MINUS "-"
304 %token CHORD_SLASH "/"
305 %token ANGLE_OPEN "<"
306 %token ANGLE_CLOSE ">"
307 %token DOUBLE_ANGLE_OPEN "<<"
308 %token DOUBLE_ANGLE_CLOSE ">>"
309 %token E_BACKSLASH "\\"
310 %token E_ANGLE_CLOSE "\\>"
311 %token E_CHAR "\\C[haracter]"
313 %token E_EXCLAMATION "\\!"
314 %token E_BRACKET_OPEN "\\["
316 %token E_BRACKET_CLOSE "\\]"
317 %token E_ANGLE_OPEN "\\<"
323 If we give names, Bison complains.
325 %token FIGURE_CLOSE /* "\\>" */
326 %token FIGURE_OPEN /* "\\<" */
327 %token FIGURE_SPACE "_"
330 %token CHORDMODIFIERS
332 %token MULTI_MEASURE_REST
338 /* Artificial tokens, for more generic function syntax */
339 %token EXPECT_MARKUP "markup?"
340 %token EXPECT_PITCH "ly:pitch?"
341 %token EXPECT_DURATION "ly:duration?"
342 %token EXPECT_SCM "scheme?"
343 %token BACKUP "(backed-up?)"
344 %token REPARSE "(reparsed?)"
345 %token EXPECT_MARKUP_LIST "markup-list?"
346 %token EXPECT_OPTIONAL "optional?"
347 /* After the last argument. */
348 %token EXPECT_NO_MORE_ARGS;
350 /* An artificial token for parsing embedded Lilypond */
351 %token EMBEDDED_LILY "#{"
353 %token BOOK_IDENTIFIER
354 %token CHORDMODIFIER_PITCH
355 %token CHORD_MODIFIER
356 %token CHORD_REPETITION
357 %token CONTEXT_DEF_IDENTIFIER
358 %token CONTEXT_MOD_IDENTIFIER
360 %token PITCH_IDENTIFIER
361 %token DURATION_IDENTIFIER
362 %token EVENT_IDENTIFIER
363 %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
382 %token SCORE_IDENTIFIER
385 %token TONICNAME_PITCH
389 /* We don't assign precedence to / and *, because we might need varied
390 prec levels in different prods */
399 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
400 parser->lexer_->push_note_state (nn);
401 } embedded_lilypond {
402 parser->lexer_->pop_state ();
407 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
408 | lilypond toplevel_expression {
410 | lilypond assignment {
413 parser->error_level_ = 1;
416 parser->error_level_ = 1;
423 parser->lexer_->add_scope (get_header (parser));
425 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
428 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
429 scm_call_2 (proc, parser->self_scm (), $1);
432 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
433 scm_call_2 (proc, parser->self_scm (), $1);
436 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
437 scm_call_2 (proc, parser->self_scm (), $1);
440 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
441 scm_call_2 (proc, parser->self_scm (), $1);
444 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
445 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
448 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
449 scm_call_2 (proc, parser->self_scm (), $1);
452 // Evaluate and ignore #xxx, as opposed to \xxx
453 parser->lexer_->eval_scm_token ($1);
455 | embedded_scm_active
457 SCM out = SCM_UNDEFINED;
458 if (Text_interface::is_markup ($1))
459 out = scm_list_1 ($1);
460 else if (Text_interface::is_markup_list ($1))
462 if (scm_is_pair (out))
464 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
465 scm_call_2 (proc, parser->self_scm (), out);
466 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
467 parser->parser_error (@1, _("bad expression type"));
471 Output_def * od = unsmob_output_def ($1);
473 if (od->c_variable ("is-paper") == SCM_BOOL_T)
474 id = ly_symbol2scm ("$defaultpaper");
475 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
476 id = ly_symbol2scm ("$defaultmidi");
477 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
478 id = ly_symbol2scm ("$defaultlayout");
480 parser->lexer_->set_identifier (id, $1);
487 $$ = parser->lexer_->eval_scm_token ($1);
497 embedded_scm_bare_arg:
501 $$ = parser->lexer_->eval_scm_token ($1);
505 | context_modification
507 | context_def_spec_block
513 /* The generic version may end in music, or not */
521 embedded_scm_bare_arg
527 SCM_FUNCTION function_arglist {
528 $$ = MAKE_SYNTAX ("music-function", @$,
536 $$ = MAKE_SYNTAX ("void-music", @$);
539 | music_embedded music_embedded music_list {
540 $3 = scm_reverse_x ($3, SCM_EOL);
541 if (unsmob_music ($2))
542 $3 = scm_cons ($2, $3);
543 if (unsmob_music ($1))
544 $3 = scm_cons ($1, $3);
545 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
548 parser->error_level_ = 1;
549 $$ = SCM_UNSPECIFIED;
551 | INVALID embedded_lilypond {
552 parser->error_level_ = 1;
558 lilypond_header_body:
559 /* empty */ { $$ = SCM_UNSPECIFIED; }
560 | lilypond_header_body assignment {
563 | lilypond_header_body embedded_scm {
569 HEADER '{' lilypond_header_body '}' {
570 $$ = parser->lexer_->remove_scope ();
579 | LYRICS_STRING { $$ = $1; }
583 assignment_id '=' identifier_init {
584 parser->lexer_->set_identifier ($1, $3);
585 $$ = SCM_UNSPECIFIED;
587 | assignment_id property_path '=' identifier_init {
588 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
589 parser->lexer_->set_identifier (path, $4);
590 $$ = SCM_UNSPECIFIED;
600 | context_def_spec_block
602 | post_event_nofinger
608 | context_modification
611 context_def_spec_block:
612 CONTEXT '{' context_def_spec_body '}'
623 context_mod_embedded:
626 if (unsmob_music ($1)) {
627 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
628 $1 = scm_call_2 (proc, parser->self_scm (), $1);
630 if (unsmob_context_mod ($1))
633 parser->parser_error (@1, _ ("not a context mod"));
639 context_def_spec_body:
641 $$ = Context_def::make_scm ();
642 unsmob_context_def ($$)->origin ()->set_spot (@$);
644 | CONTEXT_DEF_IDENTIFIER {
646 unsmob_context_def ($$)->origin ()->set_spot (@$);
648 | context_def_spec_body context_mod {
649 if (!SCM_UNBNDP ($2))
650 unsmob_context_def ($$)->add_context_mod ($2);
652 | context_def_spec_body context_modification {
653 Context_def *td = unsmob_context_def ($$);
654 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
655 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
656 td->add_context_mod (scm_car (m));
659 | context_def_spec_body context_mod_embedded {
660 Context_def *td = unsmob_context_def ($$);
661 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
662 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
663 td->add_context_mod (scm_car (m));
671 BOOK '{' book_body '}' {
674 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
679 * Use 'handlers' like for toplevel-* stuff?
680 * grok \layout and \midi? */
683 Book *book = new Book;
684 init_papers (parser);
685 book->origin ()->set_spot (@$);
686 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
687 book->paper_->unprotect ();
688 push_paper (parser, book->paper_);
689 book->header_ = get_header (parser);
690 $$ = book->unprotect ();
691 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
694 unsmob_book ($1)->origin ()->set_spot (@$);
695 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
697 | book_body paper_block {
698 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
699 set_paper (parser, unsmob_output_def ($2));
701 | book_body bookpart_block {
702 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
703 scm_call_2 (proc, $1, $2);
705 | book_body score_block {
706 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
707 scm_call_2 (proc, $1, $2);
709 | book_body composite_music {
710 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
711 scm_call_3 (proc, parser->self_scm (), $1, $2);
713 | book_body full_markup {
714 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
715 scm_call_2 (proc, $1, scm_list_1 ($2));
717 | book_body full_markup_list {
718 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
719 scm_call_2 (proc, $1, $2);
721 | book_body SCM_TOKEN {
722 // Evaluate and ignore #xxx, as opposed to \xxx
723 parser->lexer_->eval_scm_token ($2);
725 | book_body embedded_scm_active
727 SCM out = SCM_UNDEFINED;
728 if (Text_interface::is_markup ($2))
729 out = scm_list_1 ($2);
730 else if (Text_interface::is_markup_list ($2))
732 if (scm_is_pair (out))
734 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
735 scm_call_2 (proc, $1, out);
736 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
737 parser->parser_error (@2, _("bad expression type"));
741 parser->lexer_->add_scope (unsmob_book ($1)->header_);
744 Book *book = unsmob_book ($1);
746 book->scores_ = SCM_EOL;
747 book->bookparts_ = SCM_EOL;
752 BOOKPART '{' bookpart_body '}' {
754 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
760 Book *book = new Book;
761 book->origin ()->set_spot (@$);
762 $$ = book->unprotect ();
763 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
766 unsmob_book ($1)->origin ()->set_spot (@$);
767 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
769 | bookpart_body paper_block {
770 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
772 | bookpart_body score_block {
773 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
774 scm_call_2 (proc, $1, $2);
776 | bookpart_body composite_music {
777 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
778 scm_call_3 (proc, parser->self_scm (), $1, $2);
780 | bookpart_body full_markup {
781 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
782 scm_call_2 (proc, $1, scm_list_1 ($2));
784 | bookpart_body full_markup_list {
785 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
786 scm_call_2 (proc, $1, $2);
788 | bookpart_body SCM_TOKEN {
789 // Evaluate and ignore #xxx, as opposed to \xxx
790 parser->lexer_->eval_scm_token ($2);
792 | bookpart_body embedded_scm_active
794 SCM out = SCM_UNDEFINED;
795 if (Text_interface::is_markup ($2))
796 out = scm_list_1 ($2);
797 else if (Text_interface::is_markup_list ($2))
799 if (scm_is_pair (out))
801 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
802 scm_call_2 (proc, $1, out);
803 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
804 parser->parser_error (@2, _("bad expression type"));
808 Book *book = unsmob_book ($1);
809 if (!ly_is_module (book->header_))
810 book->header_ = ly_make_module (false);
811 parser->lexer_->add_scope (book->header_);
813 | bookpart_body error {
814 Book *book = unsmob_book ($1);
816 book->scores_ = SCM_EOL;
821 SCORE '{' score_body '}' {
828 SCM scorify = ly_lily_module_constant ("scorify-music");
829 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
831 unsmob_score ($$)->origin ()->set_spot (@$);
834 unsmob_score ($$)->origin ()->set_spot (@$);
838 Score *score = unsmob_score ($1);
839 if (!ly_is_module (score->get_header ()))
840 score->set_header (ly_make_module (false));
841 parser->lexer_->add_scope (score->get_header ());
843 | score_body output_def {
844 Output_def *od = unsmob_output_def ($2);
845 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
847 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
852 unsmob_score ($1)->add_output_def (od);
856 unsmob_score ($$)->error_found_ = true;
867 Output_def *od = unsmob_output_def ($1);
869 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
871 parser->parser_error (@1, _ ("need \\paper for paper block"));
872 $$ = get_paper (parser)->unprotect ();
879 output_def_body '}' {
882 parser->lexer_->remove_scope ();
883 parser->lexer_->pop_state ();
889 Output_def *p = get_paper (parser);
890 p->input_origin_ = @$;
891 parser->lexer_->add_scope (p->scope_);
892 $$ = p->unprotect ();
895 Output_def *p = get_midi (parser);
896 $$ = p->unprotect ();
897 parser->lexer_->add_scope (p->scope_);
900 Output_def *p = get_layout (parser);
902 parser->lexer_->add_scope (p->scope_);
903 $$ = p->unprotect ();
907 output_def_head_with_mode_switch:
909 parser->lexer_->push_initial_state ();
914 // We need this weird nonterminal because both music as well as a
915 // context definition can start with \context and the difference is
916 // only apparent after looking at the next token. If it is '{', there
917 // is still time to escape from notes mode.
919 music_or_context_def:
922 parser->lexer_->pop_state ();
926 parser->lexer_->pop_state ();
927 } '{' context_def_spec_body '}'
934 output_def_head_with_mode_switch '{' {
936 unsmob_output_def ($$)->input_origin_.set_spot (@$);
938 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
939 Output_def *o = unsmob_output_def ($3);
940 o->input_origin_.set_spot (@$);
942 parser->lexer_->remove_scope ();
943 parser->lexer_->add_scope (o->scope_);
945 | output_def_body assignment {
948 | output_def_body embedded_scm {
953 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
954 parser->lexer_->push_note_state (nn);
955 } music_or_context_def
957 if (unsmob_context_def ($3))
958 assign_context_def (unsmob_output_def ($1), $3);
961 SCM proc = parser->lexer_->lookup_identifier
962 ("output-def-music-handler");
963 scm_call_3 (proc, parser->self_scm (),
967 | output_def_body error {
973 TEMPO steno_duration '=' tempo_range {
974 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
976 | TEMPO scalar_closed steno_duration '=' tempo_range {
977 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
980 $$ = MAKE_SYNTAX ("tempo", @$, $2);
985 The representation of a list is reversed to have efficient append. */
991 | music_list music_embedded {
992 if (unsmob_music ($2))
993 $$ = scm_cons ($2, $1);
996 Music *m = MY_MAKE_MUSIC("Music", @$);
998 m->set_property ("error-found", SCM_BOOL_T);
999 $$ = scm_cons (m->self_scm (), $1);
1000 m->unprotect (); /* UGH */
1007 $$ = scm_reverse_x ($2, SCM_EOL);
1012 | lyric_element_music
1019 if (unsmob_music ($1)
1020 || scm_is_eq ($1, SCM_UNSPECIFIED))
1024 @$.warning (_ ("Ignoring non-music expression"));
1025 $$ = SCM_UNSPECIFIED;
1033 $$ = make_music_from_simple (parser, @1, $1);
1034 if (!unsmob_music ($$))
1035 parser->parser_error (@1, _ ("music expected"));
1037 | composite_music %prec COMPOSITE
1042 | composite_music %prec COMPOSITE
1046 REPEAT simple_string unsigned_number music
1048 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1050 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1052 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1057 SEQUENTIAL braced_music_list {
1058 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1060 | braced_music_list {
1061 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1066 SIMULTANEOUS braced_music_list {
1067 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1069 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1070 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1076 | music_property_def
1080 context_modification:
1081 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1083 parser->lexer_->pop_state ();
1086 | WITH CONTEXT_MOD_IDENTIFIER
1090 | CONTEXT_MOD_IDENTIFIER
1094 | WITH embedded_scm_closed
1096 if (unsmob_context_mod ($2))
1099 parser->parser_error (@2, _ ("not a context mod"));
1100 $$ = Context_mod ().smobbed_copy ();
1105 optional_context_mod:
1109 | context_modification
1117 $$ = Context_mod ().smobbed_copy ();
1119 | context_mod_list context_mod {
1120 if (!SCM_UNBNDP ($2))
1121 unsmob_context_mod ($1)->add_context_mod ($2);
1123 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1124 Context_mod *md = unsmob_context_mod ($2);
1126 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1128 | context_mod_list context_mod_embedded {
1129 unsmob_context_mod ($1)->add_context_mods
1130 (unsmob_context_mod ($2)->get_mods ());
1139 /* Music that can be parsed without lookahead */
1142 | complex_music_prefix closed_music
1144 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1146 | music_function_call_closed
1152 | grouped_music_list
1156 simultaneous_music { $$ = $1; }
1157 | sequential_music { $$ = $1; }
1160 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1161 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1162 and this rule returns the reversed list of arguments. */
1164 /* Function argument lists come in a number of flavors. Whenever
1165 * LilyPond has to pick between different flavors, the decision is
1166 * either made because of tokens it has already seen, or it is
1167 * postponed until tokens suitable for making the decision come up.
1168 * For postponing decisions, it may be necessary that the competing
1169 * rules are written in a way making them compatible until a decision
1170 * can be made. Sometimes this is done by putting common traits into
1171 * a separate "common" rule set.
1173 * function_arglist: a full argument list. Optional arguments at the
1174 * end of the list can only be skipped by writing \default in their
1177 * function_arglist_backup: an argument list ending in an optional
1178 * argument that may be skipped depending on its predicate.
1180 * function_arglist_skip: an argument list _not_ ending in an optional
1181 * argument that is actually taken.
1183 * function_arglist_nonbackup: an argument list ending in an optional
1184 * argument that may not be skipped because it is in end position and
1185 * has not been shortcircuited with \default.
1187 * function_arglist* / function_arglist_closed*: The closed variants
1188 * don't end in simple music expressions that might still accept
1189 * things like a duration or a postevent.
1192 function_arglist_skip:
1193 function_arglist_common
1194 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1196 $$ = scm_cons ($1, $3);
1197 } %prec FUNCTION_ARGLIST
1198 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1200 $$ = scm_cons ($1, $3);
1201 } %prec FUNCTION_ARGLIST
1202 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1204 $$ = scm_cons ($1, $3);
1205 } %prec FUNCTION_ARGLIST
1209 function_arglist_nonbackup_common:
1210 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1211 $$ = scm_cons ($4, $3);
1213 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1214 $$ = scm_cons ($4, $3);
1216 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1218 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1220 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1222 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1224 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1226 SCM n = scm_difference ($5, SCM_UNDEFINED);
1227 if (scm_is_true (scm_call_1 ($2, n)))
1228 $$ = scm_cons (n, $3);
1230 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1231 t->set_property ("digit", $5);
1232 $$ = t->unprotect ();
1233 if (scm_is_true (scm_call_1 ($2, $$)))
1234 $$ = scm_cons ($$, $3);
1236 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1240 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1242 $$ = check_scheme_arg (parser, @4,
1243 scm_difference ($5, SCM_UNDEFINED),
1246 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1248 $$ = check_scheme_arg (parser, @4,
1249 scm_difference ($5, SCM_UNDEFINED),
1254 function_arglist_closed_nonbackup:
1255 function_arglist_nonbackup_common
1256 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1258 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1260 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1262 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1264 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1266 SCM res = try_string_variants ($2, $4);
1267 if (SCM_UNBNDP (res))
1268 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1270 $$ = scm_cons (res, $3);
1272 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1274 SCM res = try_string_variants ($2, $4);
1275 if (SCM_UNBNDP (res))
1276 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1278 $$ = scm_cons (res, $3);
1280 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_STRING
1282 SCM res = try_string_variants ($2, $4);
1283 if (SCM_UNBNDP (res))
1284 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1286 $$ = scm_cons (res, $3);
1288 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1290 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1296 | SYMBOL_LIST '.' symbol_list_rev
1298 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1304 | symbol_list_rev '.' symbol_list_part
1306 $$ = scm_append_x (scm_list_2 ($3, $1));
1310 // symbol_list_part delivers elements in reverse copy.
1315 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1316 if (scm_is_true (scm_call_1 (sym_l_p, $1)))
1317 $$ = scm_reverse ($1);
1319 $$ = try_string_variants (sym_l_p, $1);
1320 if (SCM_UNBNDP ($$)) {
1321 parser->parser_error (@1, _("not a symbol"));
1329 symbol_list_element:
1336 function_arglist_nonbackup:
1337 function_arglist_nonbackup_common
1338 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1340 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1342 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1344 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1346 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1348 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1350 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1352 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1354 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1356 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1360 function_arglist_nonbackup_reparse:
1361 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1364 SCM res = try_string_variants ($2, $4);
1365 if (!SCM_UNBNDP (res))
1366 if (scm_is_pair (res))
1367 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1369 MYREPARSE (@4, $2, SCM_ARG, res);
1370 else if (scm_is_true
1372 ($2, make_music_from_simple
1374 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1376 MYREPARSE (@4, $2, SCM_ARG, $4);
1378 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_STRING
1381 SCM res = try_string_variants ($2, $4);
1382 if (!SCM_UNBNDP (res))
1383 if (scm_is_pair (res))
1384 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1386 MYREPARSE (@4, $2, SCM_ARG, res);
1387 else if (scm_is_true
1389 ($2, make_music_from_simple
1391 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1393 MYREPARSE (@4, $2, SCM_ARG, $4);
1395 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1398 SCM res = try_string_variants ($2, $4);
1399 if (!SCM_UNBNDP (res))
1400 if (scm_is_pair (res))
1401 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1403 MYREPARSE (@4, $2, SCM_ARG, res);
1405 MYREPARSE (@4, $2, SCM_ARG, $4);
1407 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1410 if (scm_is_true (scm_call_1 ($2, $4)))
1411 MYREPARSE (@4, $2, SCM_ARG, $4);
1412 else if (scm_is_true
1414 ($2, make_music_from_simple
1416 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1418 MYREPARSE (@4, $2, SCM_ARG, $4);
1422 function_arglist_keep:
1423 function_arglist_common
1424 | function_arglist_backup
1427 function_arglist_closed_keep:
1428 function_arglist_closed_common
1429 | function_arglist_backup
1432 function_arglist_backup:
1433 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1435 if (scm_is_true (scm_call_1 ($2, $4)))
1437 $$ = scm_cons ($4, $3);
1439 $$ = scm_cons (loc_on_music (@3, $1), $3);
1440 MYBACKUP (SCM_ARG, $4, @4);
1443 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1445 if (scm_is_true (scm_call_1 ($2, $4)))
1447 $$ = scm_cons ($4, $3);
1449 $$ = scm_cons (loc_on_music (@3, $1), $3);
1450 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1453 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_markup
1455 if (scm_is_true (scm_call_1 ($2, $4)))
1456 $$ = scm_cons ($4, $3);
1458 $$ = scm_cons (loc_on_music (@3, $1), $3);
1459 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1462 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1464 if (scm_is_true (scm_call_1 ($2, $4)))
1467 MYREPARSE (@4, $2, UNSIGNED, $4);
1469 $$ = scm_cons (loc_on_music (@3, $1), $3);
1470 MYBACKUP (UNSIGNED, $4, @4);
1473 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1475 if (scm_is_true (scm_call_1 ($2, $4)))
1478 MYREPARSE (@4, $2, REAL, $4);
1480 $$ = scm_cons (loc_on_music (@3, $1), $3);
1481 MYBACKUP (REAL, $4, @4);
1484 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1486 if (scm_is_true (scm_call_1 ($2, $4)))
1488 $$ = scm_cons ($4, $3);
1490 $$ = scm_cons (loc_on_music (@3, $1), $3);
1491 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1494 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1496 if (scm_is_true (scm_call_1 ($2, $4)))
1498 $$ = scm_cons ($4, $3);
1500 $$ = scm_cons (loc_on_music (@3, $1), $3);
1501 MYBACKUP (FRACTION, $4, @4);
1504 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1506 SCM n = scm_difference ($5, SCM_UNDEFINED);
1507 if (scm_is_true (scm_call_1 ($2, n))) {
1509 MYREPARSE (@5, $2, REAL, n);
1511 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1512 t->set_property ("digit", $5);
1513 $$ = t->unprotect ();
1514 if (scm_is_true (scm_call_1 ($2, $$)))
1515 $$ = scm_cons ($$, $3);
1517 $$ = scm_cons (loc_on_music (@3, $1), $3);
1518 MYBACKUP (UNSIGNED, $5, @5);
1519 parser->lexer_->push_extra_token ('-');
1524 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1526 SCM n = scm_difference ($5, SCM_UNDEFINED);
1527 if (scm_is_true (scm_call_1 ($2, n))) {
1528 MYREPARSE (@5, $2, REAL, n);
1531 $$ = scm_cons (loc_on_music (@3, $1), $3);
1532 MYBACKUP (REAL, n, @5);
1535 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1537 SCM n = scm_difference ($5, SCM_UNDEFINED);
1538 if (scm_is_true (scm_call_1 ($2, n))) {
1539 $$ = scm_cons (n, $3);
1541 $$ = scm_cons (loc_on_music (@3, $1), $3);
1542 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1545 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1547 $$ = scm_cons ($4, $3);
1549 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1551 $$ = scm_cons ($4, $3);
1553 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
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 (SCM_IDENTIFIER, $4, @4);
1568 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1570 SCM res = try_string_variants ($2, $4);
1571 if (!SCM_UNBNDP (res))
1572 if (scm_is_pair (res)) {
1574 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1577 $$ = scm_cons (res, $3);
1579 $$ = scm_cons (loc_on_music (@3, $1), $3);
1580 MYBACKUP (STRING, $4, @4);
1583 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep LYRICS_STRING
1585 SCM res = try_string_variants ($2, $4);
1586 if (!SCM_UNBNDP (res))
1587 if (scm_is_pair (res)) {
1589 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1592 $$ = scm_cons (res, $3);
1594 $$ = scm_cons (loc_on_music (@3, $1), $3);
1595 MYBACKUP (LYRICS_STRING, $4, @4);
1598 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1600 $$ = scm_cons ($1, $3);
1601 MYBACKUP(0, SCM_UNDEFINED, @3);
1603 | function_arglist_backup REPARSE bare_number
1605 $$ = check_scheme_arg (parser, @3,
1608 | function_arglist_backup REPARSE symbol_list_arg
1610 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1615 function_arglist_common
1616 | function_arglist_nonbackup
1619 function_arglist_common:
1620 function_arglist_bare
1621 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1623 $$ = check_scheme_arg (parser, @3,
1626 | EXPECT_SCM function_arglist_closed_optional bare_number
1628 $$ = check_scheme_arg (parser, @3,
1631 | EXPECT_SCM function_arglist_optional FRACTION
1633 $$ = check_scheme_arg (parser, @3,
1636 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1638 $$ = check_scheme_arg (parser, @3,
1641 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1643 SCM n = scm_difference ($4, SCM_UNDEFINED);
1644 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1646 | function_arglist_common_reparse REPARSE SCM_ARG
1648 $$ = check_scheme_arg (parser, @3,
1651 | function_arglist_common_reparse REPARSE lyric_element_music
1653 $$ = check_scheme_arg (parser, @3,
1656 | function_arglist_common_reparse REPARSE bare_number
1658 $$ = check_scheme_arg (parser, @3,
1661 | function_arglist_common_reparse REPARSE symbol_list_arg
1663 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1667 function_arglist_common_reparse:
1668 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1671 SCM res = try_string_variants ($1, $3);
1672 if (!SCM_UNBNDP (res))
1673 if (scm_is_pair (res))
1674 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1676 MYREPARSE (@3, $1, SCM_ARG, res);
1677 else if (scm_is_true
1679 ($1, make_music_from_simple (parser, @3, $3))))
1680 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1682 // This is going to flag a syntax error, we
1683 // know the predicate to be false.
1684 MYREPARSE (@3, $1, SCM_ARG, $3);
1686 | EXPECT_SCM function_arglist_optional STRING
1689 SCM res = try_string_variants ($1, $3);
1690 if (!SCM_UNBNDP (res))
1691 if (scm_is_pair (res))
1692 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1694 MYREPARSE (@3, $1, SCM_ARG, res);
1696 // This is going to flag a syntax error, we
1697 // know the predicate to be false.
1698 MYREPARSE (@3, $1, SCM_ARG, $3);
1700 | EXPECT_SCM function_arglist_optional LYRICS_STRING
1703 SCM res = try_string_variants ($1, $3);
1704 if (!SCM_UNBNDP (res))
1705 if (scm_is_pair (res))
1706 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1708 MYREPARSE (@3, $1, SCM_ARG, res);
1709 else if (scm_is_true
1711 ($1, make_music_from_simple (parser, @3, $3))))
1712 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1714 // This is going to flag a syntax error, we
1715 // know the predicate to be false.
1716 MYREPARSE (@3, $1, SCM_ARG, $3);
1718 | EXPECT_SCM function_arglist_optional lyric_markup
1721 if (scm_is_true (scm_call_1 ($1, $3)))
1722 MYREPARSE (@3, $1, SCM_ARG, $3);
1723 else if (scm_is_true
1725 ($1, make_music_from_simple (parser, @3, $3))))
1726 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1728 // This is going to flag a syntax error, we
1729 // know the predicate to be false.
1730 MYREPARSE (@3, $1, SCM_ARG, $3);
1732 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1735 SCM n = scm_difference ($4, SCM_UNDEFINED);
1736 if (scm_is_true (scm_call_1 ($1, n)))
1737 MYREPARSE (@4, $1, REAL, n);
1739 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1740 t->set_property ("digit", $4);
1741 SCM m = t->unprotect ();
1742 if (scm_is_true (scm_call_1 ($1, m)))
1743 MYREPARSE (@4, $1, SCM_ARG, m);
1745 MYREPARSE (@4, $1, SCM_ARG, $4);
1749 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1752 SCM n = scm_difference ($4, SCM_UNDEFINED);
1753 MYREPARSE (@4, $1, REAL, n);
1757 function_arglist_closed:
1758 function_arglist_closed_common
1759 | function_arglist_closed_nonbackup
1762 function_arglist_closed_common:
1763 function_arglist_bare
1764 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1766 $$ = check_scheme_arg (parser, @3,
1769 | EXPECT_SCM function_arglist_closed_optional bare_number
1771 $$ = check_scheme_arg (parser, @3,
1774 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1776 $$ = check_scheme_arg (parser, @3,
1777 scm_difference ($4, SCM_UNDEFINED),
1780 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1782 $$ = check_scheme_arg (parser, @3,
1785 | EXPECT_SCM function_arglist_optional FRACTION
1787 $$ = check_scheme_arg (parser, @3,
1790 | function_arglist_common_reparse REPARSE SCM_ARG
1792 $$ = check_scheme_arg (parser, @3,
1795 | function_arglist_common_reparse REPARSE bare_number
1797 $$ = check_scheme_arg (parser, @3,
1800 | function_arglist_common_reparse REPARSE symbol_list_arg
1802 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1806 function_arglist_optional:
1807 function_arglist_keep %prec FUNCTION_ARGLIST
1808 | function_arglist_backup BACKUP
1809 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1811 $$ = scm_cons ($1, $3);
1813 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1815 $$ = scm_cons ($1, $3);
1819 function_arglist_closed_optional:
1820 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1821 | function_arglist_backup BACKUP
1822 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1824 $$ = scm_cons ($1, $3);
1826 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1828 $$ = scm_cons ($1, $3);
1832 embedded_scm_closed:
1834 | scm_function_call_closed
1837 embedded_scm_arg_closed:
1838 embedded_scm_bare_arg
1839 | scm_function_call_closed
1843 scm_function_call_closed:
1844 SCM_FUNCTION function_arglist_closed {
1845 $$ = MAKE_SYNTAX ("music-function", @$,
1847 } %prec FUNCTION_ARGLIST
1850 function_arglist_bare:
1851 EXPECT_NO_MORE_ARGS {
1854 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1855 $$ = scm_cons ($3, $2);
1857 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1858 $$ = scm_cons ($3, $2);
1860 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1861 $$ = scm_cons ($1, $3);
1863 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1864 $$ = scm_cons ($1, $3);
1866 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1867 $$ = scm_cons ($1, $3);
1871 music_function_call:
1872 MUSIC_FUNCTION function_arglist {
1873 $$ = MAKE_SYNTAX ("music-function", @$,
1880 /**/ { $$ = SCM_EOL; }
1881 | '=' simple_string {
1888 | repeated_music { $$ = $1; }
1889 | re_rhythmed_music { $$ = $1; }
1890 | complex_music_prefix music
1892 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1896 complex_music_prefix:
1897 CONTEXT simple_string optional_id optional_context_mod {
1898 Context_mod *ctxmod = unsmob_context_mod ($4);
1901 mods = ctxmod->get_mods ();
1902 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1904 | NEWCONTEXT simple_string optional_id optional_context_mod {
1905 Context_mod *ctxmod = unsmob_context_mod ($4);
1908 mods = ctxmod->get_mods ();
1909 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1914 mode_changing_head grouped_music_list {
1915 if ($1 == ly_symbol2scm ("chords"))
1917 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1923 parser->lexer_->pop_state ();
1925 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1926 Context_mod *ctxmod = unsmob_context_mod ($2);
1929 mods = ctxmod->get_mods ();
1930 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1931 if ($1 == ly_symbol2scm ("ChordNames"))
1933 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1935 parser->lexer_->pop_state ();
1941 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1942 parser->lexer_->push_note_state (nn);
1944 $$ = ly_symbol2scm ("notes");
1948 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1949 parser->lexer_->push_note_state (nn);
1951 $$ = ly_symbol2scm ("drums");
1954 parser->lexer_->push_figuredbass_state ();
1956 $$ = ly_symbol2scm ("figures");
1959 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1960 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1961 nn = parser->lexer_->lookup_identifier ("pitchnames");
1962 parser->lexer_->push_chord_state (nn);
1963 $$ = ly_symbol2scm ("chords");
1967 { parser->lexer_->push_lyric_state ();
1968 $$ = ly_symbol2scm ("lyrics");
1972 mode_changing_head_with_context:
1974 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1975 parser->lexer_->push_note_state (nn);
1977 $$ = ly_symbol2scm ("DrumStaff");
1980 parser->lexer_->push_figuredbass_state ();
1982 $$ = ly_symbol2scm ("FiguredBass");
1985 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1986 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1987 nn = parser->lexer_->lookup_identifier ("pitchnames");
1988 parser->lexer_->push_chord_state (nn);
1989 $$ = ly_symbol2scm ("ChordNames");
1992 { parser->lexer_->push_lyric_state ();
1993 $$ = ly_symbol2scm ("Lyrics");
1998 ADDLYRICS { parser->lexer_->push_lyric_state (); }
2001 /* Can also use music at the expensive of two S/Rs similar to
2002 \repeat \alternative */
2003 parser->lexer_->pop_state ();
2005 $$ = scm_cons ($3, SCM_EOL);
2007 | new_lyrics ADDLYRICS {
2008 parser->lexer_->push_lyric_state ();
2010 parser->lexer_->pop_state ();
2011 $$ = scm_cons ($4, $1);
2016 composite_music new_lyrics {
2017 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2019 | LYRICSTO simple_string {
2020 parser->lexer_->push_lyric_state ();
2022 parser->lexer_->pop_state ();
2023 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2028 CHANGE STRING '=' STRING {
2029 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2036 $$ = scm_reverse_x ($1, SCM_EOL);
2038 | symbol_list_rev property_path {
2039 $$ = scm_reverse_x ($1, $2);
2045 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2046 scm_string_to_symbol ($1), $3);
2048 | UNSET simple_string {
2049 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2050 scm_string_to_symbol ($2));
2052 | OVERRIDE property_path '=' scalar {
2053 if (scm_ilength ($2) < 2) {
2054 parser->parser_error (@2, _("bad grob property path"));
2057 $$ = scm_cons (ly_symbol2scm ("push"),
2058 scm_cons2 (scm_car ($2),
2063 | REVERT revert_arg {
2064 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2070 // This is all quite awkward for the sake of substantial backward
2071 // compatibility while at the same time allowing a more "natural" form
2072 // of specification not separating grob specification from grob
2073 // property path. The purpose of this definition of revert_arg is to
2074 // allow the symbol list which specifies grob and property to revert
2075 // to be optionally be split into two parts after the grob (which in
2076 // this case is just the first element of the list). symbol_list_part
2077 // is only one path component, but it can be parsed without lookahead,
2078 // so we can follow it with a synthetic BACKUP token when needed. If
2079 // the first symbol_list_part already contains multiple elements (only
2080 // possible if a Scheme expression provides them), we just parse for
2081 // additional elements introduced by '.', which is what the
2082 // SYMBOL_LIST backup in connection with the immediately following
2083 // rule using symbol_list_arg does.
2085 // As long as we don't have our coffers filled with both grob and at
2086 // least one grob property specification, the rest of the required
2087 // symbol list chain may be provided either with or without a leading
2088 // dot. This is for both allowing the traditional
2089 // \revert Accidental #'color
2090 // as well as well as the "naive" form
2091 // \revert Accidental.color
2096 if (scm_is_null ($1)
2097 || scm_is_null (scm_cdr ($1)))
2098 MYBACKUP (SCM_ARG, $1, @1);
2100 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2102 | revert_arg BACKUP symbol_list_arg
2108 // revert_arg_part delivers results in reverse
2111 | revert_arg BACKUP SCM_ARG '.' symbol_list_part
2113 $$ = scm_append_x (scm_list_2 ($5, $3));
2115 | revert_arg BACKUP SCM_ARG symbol_list_part
2117 $$ = scm_append_x (scm_list_2 ($4, $3));
2122 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2123 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2125 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2126 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2127 | DENIES { $$ = ly_symbol2scm ("denies"); }
2129 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2130 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2131 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2132 | NAME { $$ = ly_symbol2scm ("context-name"); }
2136 property_operation { $$ = $1; }
2137 | context_def_mod STRING {
2138 $$ = scm_list_2 ($1, $2);
2140 | context_def_mod embedded_scm
2142 if (!scm_is_string ($2)
2143 && ly_symbol2scm ("consists") != $1
2144 && ly_symbol2scm ("remove") != $1)
2147 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2151 $$ = scm_list_2 ($1, $2);
2156 // If defined, at least two members.
2160 SCM l = scm_reverse_x ($1, SCM_EOL);
2163 (scm_object_property (scm_car (l),
2164 ly_symbol2scm ("is-grob?"))))
2165 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2166 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2167 parser->parser_error (@1, _ ("bad grob property path"));
2174 // If defined, at least three members
2178 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2180 parser->parser_error (@1, _ ("bad grob property path"));
2184 | grob_prop_spec property_path
2186 if (!SCM_UNBNDP ($1)) {
2187 $$ = scm_append_x (scm_list_2 ($1, $2));
2188 if (scm_is_null (scm_cddr ($$))) {
2189 parser->parser_error (@$, _ ("bad grob property path"));
2197 // Exactly two elements or undefined
2201 SCM l = scm_reverse_x ($1, SCM_EOL);
2202 switch (scm_ilength (l)) {
2204 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2208 parser->parser_error (@1, _ ("bad context property path"));
2215 simple_music_property_def:
2216 OVERRIDE grob_prop_path '=' scalar {
2217 if (SCM_UNBNDP ($2))
2220 $$ = scm_list_5 (scm_car ($2),
2221 ly_symbol2scm ("OverrideProperty"),
2227 | REVERT simple_revert_context revert_arg {
2228 $$ = scm_list_4 ($2,
2229 ly_symbol2scm ("RevertProperty"),
2233 | SET context_prop_spec '=' scalar {
2234 if (SCM_UNBNDP ($2))
2237 $$ = scm_list_4 (scm_car ($2),
2238 ly_symbol2scm ("PropertySet"),
2242 | UNSET context_prop_spec {
2243 if (SCM_UNBNDP ($2))
2246 $$ = scm_list_3 (scm_car ($2),
2247 ly_symbol2scm ("PropertyUnset"),
2253 // This is all quite awkward for the sake of substantial backward
2254 // compatibility while at the same time allowing a more "natural" form
2255 // of specification not separating grob specification from grob
2256 // property path. The purpose of this definition of
2257 // simple_revert_context is to allow the symbol list which specifies
2258 // grob and property to revert to be optionally be split into two
2259 // parts after the grob (which may be preceded by a context
2260 // specification, a case which we distinguish by checking whether the
2261 // first symbol is a valid grob symbol instead).
2263 // See revert_arg above for the main work horse of this arrangement.
2264 // simple_revert_context just caters for the context and delegates the
2265 // rest of the job to revert_arg.
2267 simple_revert_context:
2270 $1 = scm_reverse_x ($1, SCM_EOL);
2271 if (scm_is_null ($1)
2273 (scm_object_property (scm_car ($1),
2274 ly_symbol2scm ("is-grob?")))) {
2275 $$ = ly_symbol2scm ("Bottom");
2276 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2279 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2286 simple_music_property_def {
2287 if (SCM_UNBNDP ($1))
2288 $$ = MAKE_SYNTAX ("void-music", @1);
2290 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2299 | string '+' string {
2300 if (!scm_is_string ($1)) {
2301 parser->parser_error (@1, (_ ("simple string expected")));
2302 $1 = scm_string (SCM_EOL);
2304 if (!scm_is_string ($3)) {
2305 parser->parser_error (@3, (_ ("simple string expected")));
2306 $3 = scm_string (SCM_EOL);
2308 $$ = scm_string_append (scm_list_2 ($1, $3));
2312 simple_string: STRING {
2320 if (scm_is_string ($1)) {
2323 parser->parser_error (@1, (_ ("simple string expected")));
2324 $$ = scm_string (SCM_EOL);
2339 embedded_scm_arg_closed
2349 simple_element post_events {
2350 // Let the rhythmic music iterator sort this mess out.
2351 if (scm_is_pair ($2)) {
2352 $$ = make_music_from_simple (parser, @1, $1);
2353 if (unsmob_music ($$))
2354 unsmob_music ($$)->set_property ("articulations",
2355 scm_reverse_x ($2, SCM_EOL));
2357 parser->parser_error (@1, _("music expected"));
2360 | simple_chord_elements post_events {
2361 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2364 /* why is this giving wrong start location? -ns
2366 i.set_location (@1, @2);
2367 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2369 | CHORD_REPETITION optional_notemode_duration post_events {
2371 i.set_location (@1, @3);
2372 $$ = MAKE_SYNTAX ("repetition-chord", i,
2373 $2, scm_reverse_x ($3, SCM_EOL));
2375 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2377 i.set_location (@1, @3);
2378 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2379 scm_reverse_x ($3, SCM_EOL));
2382 | note_chord_element
2387 chord_body optional_notemode_duration post_events
2389 Music *m = unsmob_music ($1);
2390 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2391 SCM es = m->get_property ("elements");
2392 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2394 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2395 unsmob_music (scm_car (s))->set_property ("duration", dur);
2396 es = ly_append2 (es, postevs);
2398 m-> set_property ("elements", es);
2400 $$ = m->self_scm ();
2405 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2407 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2411 chord_body_elements:
2412 /* empty */ { $$ = SCM_EOL; }
2413 | chord_body_elements chord_body_element {
2414 if (!SCM_UNBNDP ($2))
2415 $$ = scm_cons ($2, $1);
2420 pitch exclamations questions octave_check post_events
2422 bool q = to_boolean ($3);
2423 bool ex = to_boolean ($2);
2427 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2428 n->set_property ("pitch", $1);
2430 n->set_property ("cautionary", SCM_BOOL_T);
2432 n->set_property ("force-accidental", SCM_BOOL_T);
2434 if (scm_is_pair (post)) {
2435 SCM arts = scm_reverse_x (post, SCM_EOL);
2436 n->set_property ("articulations", arts);
2438 if (scm_is_number (check))
2440 int q = scm_to_int (check);
2441 n->set_property ("absolute-octave", scm_from_int (q-1));
2444 $$ = n->unprotect ();
2446 | DRUM_PITCH post_events {
2447 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2448 n->set_property ("drum-type", $1);
2450 if (scm_is_pair ($2)) {
2451 SCM arts = scm_reverse_x ($2, SCM_EOL);
2452 n->set_property ("articulations", arts);
2454 $$ = n->unprotect ();
2456 | music_function_chord_body
2458 Music *m = unsmob_music ($1);
2460 while (m && m->is_mus_type ("music-wrapper-music")) {
2461 $$ = m->get_property ("element");
2462 m = unsmob_music ($$);
2465 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2466 parser->parser_error (@$, _ ("not a rhythmic event"));
2472 music_function_chord_body:
2477 // Event functions may only take closed arglists, otherwise it would
2478 // not be clear whether a following postevent should be associated
2479 // with the last argument of the event function or with the expression
2480 // for which the function call acts itself as event.
2482 music_function_call_closed:
2483 MUSIC_FUNCTION function_arglist_closed {
2484 $$ = MAKE_SYNTAX ("music-function", @$,
2489 event_function_event:
2490 EVENT_FUNCTION function_arglist_closed {
2491 $$ = MAKE_SYNTAX ("music-function", @$,
2501 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2502 m->set_property ("span-direction", scm_from_int (START));
2503 $$ = m->unprotect();
2506 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2507 m->set_property ("span-direction", scm_from_int (STOP));
2508 $$ = m->unprotect ();
2511 $$ = MAKE_SYNTAX ("voice-separator", @$);
2514 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2516 Music *m = unsmob_music (pipe);
2521 $$ = m->unprotect ();
2524 $$ = MAKE_SYNTAX ("bar-check", @$);
2531 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2543 | post_events post_event {
2544 unsmob_music ($2)->set_spot (@2);
2545 $$ = scm_cons ($2, $$);
2549 post_event_nofinger:
2550 direction_less_event {
2553 | script_dir music_function_call_closed {
2555 if (!SCM_UNBNDP ($1))
2557 unsmob_music ($$)->set_property ("direction", $1);
2561 if (!parser->lexer_->is_lyric_state ())
2562 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2563 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2566 if (!parser->lexer_->is_lyric_state ())
2567 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2568 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2570 | script_dir direction_reqd_event {
2571 if (!SCM_UNBNDP ($1))
2573 Music *m = unsmob_music ($2);
2574 m->set_property ("direction", $1);
2578 | script_dir direction_less_event {
2579 if (!SCM_UNBNDP ($1))
2581 Music *m = unsmob_music ($2);
2582 m->set_property ("direction", $1);
2589 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2594 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2605 string_number_event:
2607 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2608 s->set_property ("string-number", $1);
2609 $$ = s->unprotect ();
2613 direction_less_char:
2615 $$ = ly_symbol2scm ("bracketOpenSymbol");
2618 $$ = ly_symbol2scm ("bracketCloseSymbol");
2621 $$ = ly_symbol2scm ("tildeSymbol");
2624 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2627 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2630 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2633 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2636 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2639 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2642 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2646 direction_less_event:
2647 direction_less_char {
2648 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2650 if (unsmob_music (predefd))
2652 m = unsmob_music (predefd)->clone ();
2657 m = MY_MAKE_MUSIC ("Music", @$);
2659 $$ = m->unprotect ();
2661 | string_number_event
2662 | EVENT_IDENTIFIER {
2666 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2667 a->set_property ("tremolo-type", $1);
2668 $$ = a->unprotect ();
2670 | event_function_event
2673 direction_reqd_event:
2677 | script_abbreviation {
2678 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2679 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2680 if (scm_is_string (s))
2681 a->set_property ("articulation-type", s);
2682 else parser->parser_error (@1, _ ("expecting string as script definition"));
2683 $$ = a->unprotect ();
2688 /**/ { $$ = SCM_EOL; }
2689 | '=' quotes { $$ = $2; }
2703 $$ = scm_from_int (1);
2706 $$ = scm_oneplus ($1);
2712 $$ = scm_from_int (-1);
2715 $$ = scm_oneminus ($1);
2720 NOTENAME_PITCH quotes {
2721 if (!scm_is_eq (SCM_INUM0, $2))
2723 Pitch p = *unsmob_pitch ($1);
2724 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2725 $$ = p.smobbed_copy ();
2735 TONICNAME_PITCH quotes {
2736 if (!scm_is_eq (SCM_INUM0, $2))
2738 Pitch p = *unsmob_pitch ($1);
2739 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2740 $$ = p.smobbed_copy ();
2750 pitch_also_in_chords:
2757 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2758 t->set_property ("text", $1);
2759 $$ = t->unprotect ();
2762 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2763 t->set_property ("text",
2764 make_simple_markup ($1));
2765 $$ = t->unprotect ();
2768 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2769 t->set_property ("text",
2770 make_simple_markup ($1));
2771 $$ = t->unprotect ();
2775 Music *m = unsmob_music ($1);
2776 if (m && m->is_mus_type ("post-event"))
2778 else if (Text_interface::is_markup ($1)) {
2779 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2780 t->set_property ("text", $1);
2781 $$ = t->unprotect ();
2783 parser->parser_error (@1, _ ("not an articulation"));
2789 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2790 t->set_property ("digit", $1);
2791 $$ = t->unprotect ();
2795 script_abbreviation:
2797 $$ = scm_from_locale_string ("Hat");
2800 $$ = scm_from_locale_string ("Plus");
2803 $$ = scm_from_locale_string ("Dash");
2806 $$ = scm_from_locale_string ("Bar");
2809 $$ = scm_from_locale_string ("Larger");
2812 $$ = scm_from_locale_string ("Dot");
2815 $$ = scm_from_locale_string ("Underscore");
2820 '_' { $$ = scm_from_int (DOWN); }
2821 | '^' { $$ = scm_from_int (UP); }
2822 | '-' { $$ = SCM_UNDEFINED; }
2826 multiplied_duration {
2831 maybe_notemode_duration:
2835 | multiplied_duration {
2837 parser->default_duration_ = *unsmob_duration ($$);
2842 optional_notemode_duration:
2843 maybe_notemode_duration
2845 if (SCM_UNBNDP ($$))
2846 $$ = parser->default_duration_.smobbed_copy ();
2853 int n = scm_to_int ($1);
2854 if (!is_duration (n))
2855 parser->parser_error (@1, _f ("not a duration: %d", n));
2859 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2861 | DURATION_IDENTIFIER dots {
2862 Duration *d = unsmob_duration ($1);
2863 Duration k (d->duration_log (),
2864 d->dot_count () + scm_to_int ($2));
2865 k = k.compressed (d->factor ());
2866 scm_remember_upto_here_1 ($1);
2867 $$ = k.smobbed_copy ();
2871 multiplied_duration:
2875 | multiplied_duration '*' UNSIGNED {
2876 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2878 | multiplied_duration '*' FRACTION {
2879 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2881 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2890 $$ = scm_oneplus ($1);
2899 int n = scm_to_int ($2);
2900 if (!is_duration (n))
2901 parser->parser_error (@2, _f ("not a duration: %d", n));
2907 UNSIGNED { $$ = $1; }
2908 | STRING { $$ = $1; }
2909 | full_markup { $$ = $1; }
2912 // as an integer, it needs to be non-negative, and otherwise
2913 // it needs to be suitable as a markup.
2914 if (scm_is_integer ($1)
2915 ? scm_is_true (scm_negative_p ($1))
2916 : !Text_interface::is_markup ($1))
2918 parser->parser_error (@1, _ ("bass number expected"));
2924 figured_bass_alteration:
2925 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2926 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2927 | '!' { $$ = scm_from_int (0); }
2932 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2933 $$ = bfr->unprotect ();
2936 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2937 $$ = bfr->self_scm ();
2939 if (scm_is_number ($1))
2940 bfr->set_property ("figure", $1);
2941 else if (Text_interface::is_markup ($1))
2942 bfr->set_property ("text", $1);
2948 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2950 | bass_figure figured_bass_alteration {
2951 Music *m = unsmob_music ($1);
2952 if (scm_to_double ($2)) {
2953 SCM salter = m->get_property ("alteration");
2954 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2955 m->set_property ("alteration",
2956 scm_sum (alter, $2));
2958 m->set_property ("alteration", scm_from_int (0));
2961 | bass_figure figured_bass_modification {
2962 Music *m = unsmob_music ($1);
2963 if ($2 == ly_symbol2scm ("plus"))
2965 m->set_property ("augmented", SCM_BOOL_T);
2967 else if ($2 == ly_symbol2scm ("slash"))
2969 m->set_property ("diminished", SCM_BOOL_T);
2971 else if ($2 == ly_symbol2scm ("exclamation"))
2973 m->set_property ("no-continuation", SCM_BOOL_T);
2975 else if ($2 == ly_symbol2scm ("backslash"))
2977 m->set_property ("augmented-slash", SCM_BOOL_T);
2983 figured_bass_modification:
2985 $$ = ly_symbol2scm ("plus");
2988 $$ = ly_symbol2scm ("exclamation");
2991 $$ = ly_symbol2scm ("slash");
2994 $$ = ly_symbol2scm ("backslash");
3004 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3012 | figure_list br_bass_figure {
3013 $$ = scm_cons ($2, $1);
3018 FIGURE_OPEN figure_list FIGURE_CLOSE {
3019 $$ = scm_reverse_x ($2, SCM_EOL);
3025 /**/ { $$ = SCM_BOOL_F; }
3026 | REST { $$ = SCM_BOOL_T; }
3030 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3031 if (!parser->lexer_->is_note_state ())
3032 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3033 if (!SCM_UNBNDP ($2)
3035 || scm_is_number ($4)
3037 || scm_is_true ($6))
3040 if (scm_is_true ($6))
3041 n = MY_MAKE_MUSIC ("RestEvent", @$);
3043 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3045 n->set_property ("pitch", $1);
3046 if (SCM_UNBNDP ($5))
3047 n->set_property ("duration",
3048 parser->default_duration_.smobbed_copy ());
3050 n->set_property ("duration", $5);
3052 if (scm_is_number ($4))
3054 int q = scm_to_int ($4);
3055 n->set_property ("absolute-octave", scm_from_int (q-1));
3058 if (to_boolean ($3))
3059 n->set_property ("cautionary", SCM_BOOL_T);
3060 if (to_boolean ($2) || to_boolean ($3))
3061 n->set_property ("force-accidental", SCM_BOOL_T);
3063 $$ = n->unprotect ();
3066 | DRUM_PITCH optional_notemode_duration {
3067 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3068 n->set_property ("duration", $2);
3069 n->set_property ("drum-type", $1);
3071 $$ = n->unprotect ();
3073 | RESTNAME optional_notemode_duration {
3075 if (ly_scm2string ($1) == "s") {
3077 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3080 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3083 ev->set_property ("duration", $2);
3084 $$ = ev->unprotect ();
3088 simple_chord_elements:
3090 if (!parser->lexer_->is_chord_state ())
3091 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3094 | figure_spec optional_notemode_duration {
3095 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3097 unsmob_music (scm_car (s))->set_property ("duration", $2);
3113 lyric_element_music:
3114 lyric_element optional_notemode_duration post_events {
3115 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3116 if (scm_is_pair ($3))
3117 unsmob_music ($$)->set_property
3118 ("articulations", scm_reverse_x ($3, SCM_EOL));
3123 steno_tonic_pitch optional_notemode_duration {
3124 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3126 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3127 SCM its = scm_reverse_x ($4, SCM_EOL);
3128 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3136 | chord_items chord_item {
3137 $$ = scm_cons ($2, $$);
3143 $$ = ly_symbol2scm ("chord-colon");
3146 $$ = ly_symbol2scm ("chord-caret");
3148 | CHORD_SLASH steno_tonic_pitch {
3149 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3151 | CHORD_BASS steno_tonic_pitch {
3152 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3161 $$ = scm_reverse_x ($1, SCM_EOL);
3169 step_number { $$ = scm_cons ($1, SCM_EOL); }
3170 | step_numbers '.' step_number {
3171 $$ = scm_cons ($3, $$);
3177 $$ = make_chord_step ($1, 0);
3180 $$ = make_chord_step ($1, SHARP_ALTERATION);
3182 | UNSIGNED CHORD_MINUS {
3183 $$ = make_chord_step ($1, FLAT_ALTERATION);
3191 | UNSIGNED '~' UNSIGNED {
3192 $$ = scm_cons ($1, $3);
3199 TODO: should deprecate in favor of Scheme?
3203 number_expression '+' number_term {
3204 $$ = scm_sum ($1, $3);
3206 | number_expression '-' number_term {
3207 $$ = scm_difference ($1, $3);
3216 | number_factor '*' number_factor {
3217 $$ = scm_product ($1, $3);
3219 | number_factor '/' number_factor {
3220 $$ = scm_divide ($1, $3);
3225 '-' number_factor { /* %prec UNARY_MINUS */
3226 $$ = scm_difference ($2, SCM_UNDEFINED);
3234 | UNSIGNED NUMBER_IDENTIFIER {
3235 $$ = scm_product ($1, $2);
3237 | REAL NUMBER_IDENTIFIER {
3238 $$ = scm_product ($1, $2);
3254 { $$ = SCM_UNDEFINED; }
3257 if (SCM_UNBNDP ($1))
3265 { $$ = SCM_UNDEFINED; }
3268 if (SCM_UNBNDP ($1))
3276 This should be done more dynamically if possible.
3281 { parser->lexer_->push_markup_state (); }
3284 parser->lexer_->pop_state ();
3290 { parser->lexer_->push_markup_state (); }
3293 parser->lexer_->pop_state ();
3299 { parser->lexer_->push_markup_state (); }
3302 parser->lexer_->pop_state ();
3308 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3310 | markup_head_1_list simple_markup {
3311 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3321 if (Text_interface::is_markup ($1))
3322 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3323 else if (Text_interface::is_markup_list ($1))
3324 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3326 parser->parser_error (@1, _ ("not a markup"));
3327 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3334 markup_composed_list {
3337 | markup_braced_list {
3340 | markup_command_list {
3341 $$ = scm_list_1 ($1);
3343 | markup_scm MARKUPLIST_IDENTIFIER
3349 markup_composed_list:
3350 markup_head_1_list markup_braced_list {
3351 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3357 '{' markup_braced_list_body '}' {
3358 $$ = scm_reverse_x ($2, SCM_EOL);
3362 markup_braced_list_body:
3363 /* empty */ { $$ = SCM_EOL; }
3364 | markup_braced_list_body markup {
3365 $$ = scm_cons ($2, $1);
3367 | markup_braced_list_body markup_list {
3368 $$ = scm_reverse_x ($2, $1);
3372 markup_command_list:
3373 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3374 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3378 markup_command_basic_arguments:
3379 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3380 $$ = scm_cons ($3, $2);
3382 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3383 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3385 | EXPECT_NO_MORE_ARGS {
3390 markup_command_list_arguments:
3391 markup_command_basic_arguments { $$ = $1; }
3392 | EXPECT_MARKUP markup_command_list_arguments markup {
3393 $$ = scm_cons ($3, $2);
3398 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3399 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3404 markup_head_1_item {
3405 $$ = scm_list_1 ($1);
3407 | markup_head_1_list markup_head_1_item {
3408 $$ = scm_cons ($2, $1);
3414 $$ = make_simple_markup ($1);
3417 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3418 parser->lexer_->push_note_state (nn);
3419 } '{' score_body '}' {
3420 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3421 parser->lexer_->pop_state ();
3423 | MARKUP_FUNCTION markup_command_basic_arguments {
3424 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3426 | markup_scm MARKUP_IDENTIFIER
3433 markup_head_1_list simple_markup {
3434 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3435 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3445 Lily_parser::set_yydebug (bool x)
3451 Lily_parser::do_yyparse ()
3453 SCM retval = SCM_UNDEFINED;
3454 yyparse (this, &retval);
3464 It is a little strange to have this function in this file, but
3465 otherwise, we have to import music classes into the lexer.
3469 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3471 if (unsmob_book (sid)) {
3472 Book *book = unsmob_book (sid)->clone ();
3473 *destination = book->self_scm ();
3476 return BOOK_IDENTIFIER;
3477 } else if (scm_is_number (sid)) {
3479 return NUMBER_IDENTIFIER;
3480 } else if (unsmob_context_def (sid)) {
3481 Context_def *def= unsmob_context_def (sid)->clone ();
3483 *destination = def->self_scm ();
3486 return CONTEXT_DEF_IDENTIFIER;
3487 } else if (unsmob_context_mod (sid)) {
3488 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3490 return CONTEXT_MOD_IDENTIFIER;
3491 } else if (unsmob_score (sid)) {
3492 Score *score = new Score (*unsmob_score (sid));
3493 *destination = score->self_scm ();
3495 score->unprotect ();
3496 return SCORE_IDENTIFIER;
3497 } else if (Music *mus = unsmob_music (sid)) {
3498 mus = mus->clone ();
3499 *destination = mus->self_scm ();
3500 unsmob_music (*destination)->
3501 set_property ("origin", make_input (last_input_));
3503 bool is_event = mus->is_mus_type ("post-event");
3505 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3506 } else if (unsmob_pitch (sid)) {
3507 *destination = unsmob_pitch (sid)->smobbed_copy ();
3508 return PITCH_IDENTIFIER;
3509 } else if (unsmob_duration (sid)) {
3510 *destination = unsmob_duration (sid)->smobbed_copy ();
3511 return DURATION_IDENTIFIER;
3512 } else if (unsmob_output_def (sid)) {
3513 Output_def *p = unsmob_output_def (sid);
3516 *destination = p->self_scm ();
3518 return OUTPUT_DEF_IDENTIFIER;
3525 get_next_unique_context_id ()
3527 return scm_from_locale_string ("$uniqueContextId");
3532 get_next_unique_lyrics_context_id ()
3534 static int new_context_count;
3536 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3537 return scm_from_locale_string (s);
3540 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3541 SCM arg, SCM args, SCM pred)
3543 args = scm_cons (arg, args);
3544 if (scm_is_true (scm_call_1 (pred, arg)))
3546 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3547 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3548 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3552 SCM loc_on_music (Input loc, SCM arg)
3554 if (Music *m = unsmob_music (arg))
3558 return m->unprotect ();
3564 try_string_variants (SCM pred, SCM str)
3566 if (scm_is_true (scm_call_1 (pred, str)))
3568 if (scm_is_string (str))
3570 if (!is_regular_identifier (str))
3571 return SCM_UNDEFINED;
3573 str = scm_string_to_symbol (str);
3574 if (scm_is_true (scm_call_1 (pred, str)))
3576 } else if (!scm_is_symbol (str))
3577 return SCM_UNDEFINED;
3579 str = scm_list_1 (str);
3580 if (scm_is_true (scm_call_1 (pred, str)))
3582 return SCM_UNDEFINED;
3586 is_regular_identifier (SCM id)
3588 if (!scm_is_string (id))
3591 string str = ly_scm2string (id);
3593 bool middle = false;
3595 for (string::iterator it=str.begin(); it != str.end (); it++)
3598 if ((c >= 'a' && c <= 'z')
3599 || (c >= 'A' && c <= 'Z')
3602 else if (middle && (c == '-' || c == '_'))
3611 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3613 if (unsmob_music (simple))
3615 if (parser->lexer_->is_note_state ()) {
3616 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3617 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3618 if (scm_is_symbol (simple))
3619 n->set_property ("drum-type", simple);
3620 else if (unsmob_pitch (simple))
3621 n->set_property ("pitch", simple);
3626 return n->unprotect ();
3627 } else if (parser->lexer_->is_lyric_state ()) {
3628 if (Text_interface::is_markup (simple))
3629 return MAKE_SYNTAX ("lyric-event", loc, simple,
3630 parser->default_duration_.smobbed_copy ());
3631 } else if (parser->lexer_->is_chord_state ()) {
3632 if (unsmob_pitch (simple))
3633 return make_chord_elements (loc, simple,
3634 parser->default_duration_.smobbed_copy (),
3641 make_music_with_input (SCM name, Input where)
3643 Music *m = make_music_by_name (name);
3644 m->set_spot (where);
3649 make_simple_markup (SCM a)
3657 return t && t == 1 << intlog2 (t);
3661 make_chord_step (SCM step_scm, Rational alter)
3663 int step = scm_to_int (step_scm);
3666 alter += FLAT_ALTERATION;
3670 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3671 return m.smobbed_copy ();
3676 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3678 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3679 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3680 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3682 unsmob_music (scm_car (s))->set_spot (loc);
3688 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3690 Lily_lexer *lex = parser->lexer_;
3694 lex->prepare_for_next_token ();
3695 return lex->yylex ();