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, bool multiple=false);
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 $$ = try_string_variants (sym_l_p, $1);
1317 if (SCM_UNBNDP ($$)) {
1318 parser->parser_error (@1, _("not a symbol"));
1321 $$ = scm_reverse ($$);
1326 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, LYRICS_STRING, $4);
1373 MYREPARSE (@4, $2, SCM_ARG, $4);
1375 | EXPECT_OPTIONAL EXPECT_SCM function_arglist LYRICS_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, LYRICS_STRING, $4);
1390 MYREPARSE (@4, $2, SCM_ARG, $4);
1392 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1395 SCM res = try_string_variants ($2, $4);
1396 if (!SCM_UNBNDP (res))
1397 if (scm_is_pair (res))
1398 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1400 MYREPARSE (@4, $2, SCM_ARG, res);
1402 MYREPARSE (@4, $2, SCM_ARG, $4);
1404 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1407 if (scm_is_true (scm_call_1 ($2, $4)))
1408 MYREPARSE (@4, $2, SCM_ARG, $4);
1409 else if (scm_is_true
1411 ($2, make_music_from_simple
1413 MYREPARSE (@4, $2, LYRICS_STRING, $4);
1415 MYREPARSE (@4, $2, SCM_ARG, $4);
1419 function_arglist_keep:
1420 function_arglist_common
1421 | function_arglist_backup
1424 function_arglist_closed_keep:
1425 function_arglist_closed_common
1426 | function_arglist_backup
1429 function_arglist_backup:
1430 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1432 if (scm_is_true (scm_call_1 ($2, $4)))
1434 $$ = scm_cons ($4, $3);
1436 $$ = scm_cons (loc_on_music (@3, $1), $3);
1437 MYBACKUP (SCM_ARG, $4, @4);
1440 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1442 if (scm_is_true (scm_call_1 ($2, $4)))
1444 $$ = scm_cons ($4, $3);
1446 $$ = scm_cons (loc_on_music (@3, $1), $3);
1447 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1450 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_markup
1452 if (scm_is_true (scm_call_1 ($2, $4)))
1453 $$ = scm_cons ($4, $3);
1455 $$ = scm_cons (loc_on_music (@3, $1), $3);
1456 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1459 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1461 if (scm_is_true (scm_call_1 ($2, $4)))
1464 MYREPARSE (@4, $2, UNSIGNED, $4);
1466 $$ = scm_cons (loc_on_music (@3, $1), $3);
1467 MYBACKUP (UNSIGNED, $4, @4);
1470 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1472 if (scm_is_true (scm_call_1 ($2, $4)))
1475 MYREPARSE (@4, $2, REAL, $4);
1477 $$ = scm_cons (loc_on_music (@3, $1), $3);
1478 MYBACKUP (REAL, $4, @4);
1481 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1483 if (scm_is_true (scm_call_1 ($2, $4)))
1485 $$ = scm_cons ($4, $3);
1487 $$ = scm_cons (loc_on_music (@3, $1), $3);
1488 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1491 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1493 if (scm_is_true (scm_call_1 ($2, $4)))
1495 $$ = scm_cons ($4, $3);
1497 $$ = scm_cons (loc_on_music (@3, $1), $3);
1498 MYBACKUP (FRACTION, $4, @4);
1501 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1503 SCM n = scm_difference ($5, SCM_UNDEFINED);
1504 if (scm_is_true (scm_call_1 ($2, n))) {
1506 MYREPARSE (@5, $2, REAL, n);
1508 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1509 t->set_property ("digit", $5);
1510 $$ = t->unprotect ();
1511 if (scm_is_true (scm_call_1 ($2, $$)))
1512 $$ = scm_cons ($$, $3);
1514 $$ = scm_cons (loc_on_music (@3, $1), $3);
1515 MYBACKUP (UNSIGNED, $5, @5);
1516 parser->lexer_->push_extra_token ('-');
1521 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1523 SCM n = scm_difference ($5, SCM_UNDEFINED);
1524 if (scm_is_true (scm_call_1 ($2, n))) {
1525 MYREPARSE (@5, $2, REAL, n);
1528 $$ = scm_cons (loc_on_music (@3, $1), $3);
1529 MYBACKUP (REAL, n, @5);
1532 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1534 SCM n = scm_difference ($5, SCM_UNDEFINED);
1535 if (scm_is_true (scm_call_1 ($2, n))) {
1536 $$ = scm_cons (n, $3);
1538 $$ = scm_cons (loc_on_music (@3, $1), $3);
1539 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1542 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1544 $$ = scm_cons ($4, $3);
1546 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1548 $$ = scm_cons ($4, $3);
1550 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1552 SCM res = try_string_variants ($2, $4);
1553 if (!SCM_UNBNDP (res))
1554 if (scm_is_pair (res)) {
1556 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1559 $$ = scm_cons (res, $3);
1561 $$ = scm_cons (loc_on_music (@3, $1), $3);
1562 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1565 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1567 SCM res = try_string_variants ($2, $4);
1568 if (!SCM_UNBNDP (res))
1569 if (scm_is_pair (res)) {
1571 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1574 $$ = scm_cons (res, $3);
1576 $$ = scm_cons (loc_on_music (@3, $1), $3);
1577 MYBACKUP (STRING, $4, @4);
1580 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep LYRICS_STRING
1582 SCM res = try_string_variants ($2, $4);
1583 if (!SCM_UNBNDP (res))
1584 if (scm_is_pair (res)) {
1586 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1589 $$ = scm_cons (res, $3);
1591 $$ = scm_cons (loc_on_music (@3, $1), $3);
1592 MYBACKUP (LYRICS_STRING, $4, @4);
1595 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1597 $$ = scm_cons ($1, $3);
1598 MYBACKUP(0, SCM_UNDEFINED, @3);
1600 | function_arglist_backup REPARSE bare_number
1602 $$ = check_scheme_arg (parser, @3,
1605 | function_arglist_backup REPARSE symbol_list_arg
1607 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1612 function_arglist_common
1613 | function_arglist_nonbackup
1616 function_arglist_common:
1617 function_arglist_bare
1618 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1620 $$ = check_scheme_arg (parser, @3,
1623 | EXPECT_SCM function_arglist_closed_optional bare_number
1625 $$ = check_scheme_arg (parser, @3,
1628 | EXPECT_SCM function_arglist_optional FRACTION
1630 $$ = check_scheme_arg (parser, @3,
1633 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1635 $$ = check_scheme_arg (parser, @3,
1638 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1640 SCM n = scm_difference ($4, SCM_UNDEFINED);
1641 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1643 | function_arglist_common_reparse REPARSE SCM_ARG
1645 $$ = check_scheme_arg (parser, @3,
1648 | function_arglist_common_reparse REPARSE lyric_element_music
1650 $$ = check_scheme_arg (parser, @3,
1653 | function_arglist_common_reparse REPARSE bare_number
1655 $$ = check_scheme_arg (parser, @3,
1658 | function_arglist_common_reparse REPARSE symbol_list_arg
1660 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1664 function_arglist_common_reparse:
1665 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1668 SCM res = try_string_variants ($1, $3);
1669 if (!SCM_UNBNDP (res))
1670 if (scm_is_pair (res))
1671 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1673 MYREPARSE (@3, $1, SCM_ARG, res);
1674 else if (scm_is_true
1676 ($1, make_music_from_simple (parser, @3, $3))))
1677 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1679 // This is going to flag a syntax error, we
1680 // know the predicate to be false.
1681 MYREPARSE (@3, $1, SCM_ARG, $3);
1683 | EXPECT_SCM function_arglist_optional STRING
1686 SCM res = try_string_variants ($1, $3);
1687 if (!SCM_UNBNDP (res))
1688 if (scm_is_pair (res))
1689 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1691 MYREPARSE (@3, $1, SCM_ARG, res);
1693 // This is going to flag a syntax error, we
1694 // know the predicate to be false.
1695 MYREPARSE (@3, $1, SCM_ARG, $3);
1697 | EXPECT_SCM function_arglist_optional LYRICS_STRING
1700 SCM res = try_string_variants ($1, $3);
1701 if (!SCM_UNBNDP (res))
1702 if (scm_is_pair (res))
1703 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1705 MYREPARSE (@3, $1, SCM_ARG, res);
1706 else if (scm_is_true
1708 ($1, make_music_from_simple (parser, @3, $3))))
1709 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1711 // This is going to flag a syntax error, we
1712 // know the predicate to be false.
1713 MYREPARSE (@3, $1, SCM_ARG, $3);
1715 | EXPECT_SCM function_arglist_optional lyric_markup
1718 if (scm_is_true (scm_call_1 ($1, $3)))
1719 MYREPARSE (@3, $1, SCM_ARG, $3);
1720 else if (scm_is_true
1722 ($1, make_music_from_simple (parser, @3, $3))))
1723 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1725 // This is going to flag a syntax error, we
1726 // know the predicate to be false.
1727 MYREPARSE (@3, $1, SCM_ARG, $3);
1729 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1732 SCM n = scm_difference ($4, SCM_UNDEFINED);
1733 if (scm_is_true (scm_call_1 ($1, n)))
1734 MYREPARSE (@4, $1, REAL, n);
1736 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1737 t->set_property ("digit", $4);
1738 SCM m = t->unprotect ();
1739 if (scm_is_true (scm_call_1 ($1, m)))
1740 MYREPARSE (@4, $1, SCM_ARG, m);
1742 MYREPARSE (@4, $1, SCM_ARG, $4);
1746 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1749 SCM n = scm_difference ($4, SCM_UNDEFINED);
1750 MYREPARSE (@4, $1, REAL, n);
1754 function_arglist_closed:
1755 function_arglist_closed_common
1756 | function_arglist_closed_nonbackup
1759 function_arglist_closed_common:
1760 function_arglist_bare
1761 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1763 $$ = check_scheme_arg (parser, @3,
1766 | EXPECT_SCM function_arglist_closed_optional bare_number
1768 $$ = check_scheme_arg (parser, @3,
1771 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1773 $$ = check_scheme_arg (parser, @3,
1774 scm_difference ($4, SCM_UNDEFINED),
1777 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1779 $$ = check_scheme_arg (parser, @3,
1782 | EXPECT_SCM function_arglist_optional FRACTION
1784 $$ = check_scheme_arg (parser, @3,
1787 | function_arglist_common_reparse REPARSE SCM_ARG
1789 $$ = check_scheme_arg (parser, @3,
1792 | function_arglist_common_reparse REPARSE bare_number
1794 $$ = check_scheme_arg (parser, @3,
1797 | function_arglist_common_reparse REPARSE symbol_list_arg
1799 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1803 function_arglist_optional:
1804 function_arglist_keep %prec FUNCTION_ARGLIST
1805 | function_arglist_backup BACKUP
1806 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1808 $$ = scm_cons ($1, $3);
1810 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1812 $$ = scm_cons ($1, $3);
1816 function_arglist_closed_optional:
1817 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1818 | function_arglist_backup BACKUP
1819 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1821 $$ = scm_cons ($1, $3);
1823 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1825 $$ = scm_cons ($1, $3);
1829 embedded_scm_closed:
1831 | scm_function_call_closed
1834 embedded_scm_arg_closed:
1835 embedded_scm_bare_arg
1836 | scm_function_call_closed
1840 scm_function_call_closed:
1841 SCM_FUNCTION function_arglist_closed {
1842 $$ = MAKE_SYNTAX ("music-function", @$,
1844 } %prec FUNCTION_ARGLIST
1847 function_arglist_bare:
1848 EXPECT_NO_MORE_ARGS {
1851 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1852 $$ = scm_cons ($3, $2);
1854 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1855 $$ = scm_cons ($3, $2);
1857 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1858 $$ = scm_cons ($1, $3);
1860 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1861 $$ = scm_cons ($1, $3);
1863 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1864 $$ = scm_cons ($1, $3);
1868 music_function_call:
1869 MUSIC_FUNCTION function_arglist {
1870 $$ = MAKE_SYNTAX ("music-function", @$,
1877 /**/ { $$ = SCM_EOL; }
1878 | '=' simple_string {
1885 | repeated_music { $$ = $1; }
1886 | re_rhythmed_music { $$ = $1; }
1887 | complex_music_prefix music
1889 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1893 complex_music_prefix:
1894 CONTEXT simple_string optional_id optional_context_mod {
1895 Context_mod *ctxmod = unsmob_context_mod ($4);
1898 mods = ctxmod->get_mods ();
1899 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1901 | NEWCONTEXT simple_string optional_id optional_context_mod {
1902 Context_mod *ctxmod = unsmob_context_mod ($4);
1905 mods = ctxmod->get_mods ();
1906 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1911 mode_changing_head grouped_music_list {
1912 if ($1 == ly_symbol2scm ("chords"))
1914 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1920 parser->lexer_->pop_state ();
1922 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1923 Context_mod *ctxmod = unsmob_context_mod ($2);
1926 mods = ctxmod->get_mods ();
1927 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1928 if ($1 == ly_symbol2scm ("ChordNames"))
1930 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1932 parser->lexer_->pop_state ();
1938 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1939 parser->lexer_->push_note_state (nn);
1941 $$ = ly_symbol2scm ("notes");
1945 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1946 parser->lexer_->push_note_state (nn);
1948 $$ = ly_symbol2scm ("drums");
1951 parser->lexer_->push_figuredbass_state ();
1953 $$ = ly_symbol2scm ("figures");
1956 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1957 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1958 nn = parser->lexer_->lookup_identifier ("pitchnames");
1959 parser->lexer_->push_chord_state (nn);
1960 $$ = ly_symbol2scm ("chords");
1964 { parser->lexer_->push_lyric_state ();
1965 $$ = ly_symbol2scm ("lyrics");
1969 mode_changing_head_with_context:
1971 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1972 parser->lexer_->push_note_state (nn);
1974 $$ = ly_symbol2scm ("DrumStaff");
1977 parser->lexer_->push_figuredbass_state ();
1979 $$ = ly_symbol2scm ("FiguredBass");
1982 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1983 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1984 nn = parser->lexer_->lookup_identifier ("pitchnames");
1985 parser->lexer_->push_chord_state (nn);
1986 $$ = ly_symbol2scm ("ChordNames");
1989 { parser->lexer_->push_lyric_state ();
1990 $$ = ly_symbol2scm ("Lyrics");
1995 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1998 /* Can also use music at the expensive of two S/Rs similar to
1999 \repeat \alternative */
2000 parser->lexer_->pop_state ();
2002 $$ = scm_cons ($3, SCM_EOL);
2004 | new_lyrics ADDLYRICS {
2005 parser->lexer_->push_lyric_state ();
2007 parser->lexer_->pop_state ();
2008 $$ = scm_cons ($4, $1);
2013 composite_music new_lyrics {
2014 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2016 | LYRICSTO simple_string {
2017 parser->lexer_->push_lyric_state ();
2019 parser->lexer_->pop_state ();
2020 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2025 CHANGE STRING '=' STRING {
2026 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2033 $$ = scm_reverse_x ($1, SCM_EOL);
2035 | symbol_list_rev property_path {
2036 $$ = scm_reverse_x ($1, $2);
2042 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2043 scm_string_to_symbol ($1), $3);
2045 | UNSET simple_string {
2046 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2047 scm_string_to_symbol ($2));
2049 | OVERRIDE property_path '=' scalar {
2050 if (scm_ilength ($2) < 2) {
2051 parser->parser_error (@2, _("bad grob property path"));
2054 $$ = scm_cons (ly_symbol2scm ("push"),
2055 scm_cons2 (scm_car ($2),
2060 | REVERT revert_arg {
2061 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2067 // This is all quite awkward for the sake of substantial backward
2068 // compatibility while at the same time allowing a more "natural" form
2069 // of specification not separating grob specification from grob
2070 // property path. The purpose of this definition of revert_arg is to
2071 // allow the symbol list which specifies grob and property to revert
2072 // to be optionally be split into two parts after the grob (which in
2073 // this case is just the first element of the list). symbol_list_part
2074 // is only one path component, but it can be parsed without lookahead,
2075 // so we can follow it with a synthetic BACKUP token when needed. If
2076 // the first symbol_list_part already contains multiple elements (only
2077 // possible if a Scheme expression provides them), we just parse for
2078 // additional elements introduced by '.', which is what the
2079 // SYMBOL_LIST backup in connection with the immediately following
2080 // rule using symbol_list_arg does.
2082 // As long as we don't have our coffers filled with both grob and at
2083 // least one grob property specification, the rest of the required
2084 // symbol list chain may be provided either with or without a leading
2085 // dot. This is for both allowing the traditional
2086 // \revert Accidental #'color
2087 // as well as well as the "naive" form
2088 // \revert Accidental.color
2093 if (scm_is_null ($1)
2094 || scm_is_null (scm_cdr ($1)))
2095 MYBACKUP (SCM_ARG, $1, @1);
2097 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2099 | revert_arg BACKUP symbol_list_arg
2105 // revert_arg_part delivers results in reverse
2108 | revert_arg BACKUP SCM_ARG '.' symbol_list_part
2110 $$ = scm_append_x (scm_list_2 ($5, $3));
2112 | revert_arg BACKUP SCM_ARG symbol_list_part
2114 $$ = scm_append_x (scm_list_2 ($4, $3));
2119 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2120 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2122 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2123 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2124 | DENIES { $$ = ly_symbol2scm ("denies"); }
2126 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2127 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2128 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2129 | NAME { $$ = ly_symbol2scm ("context-name"); }
2133 property_operation { $$ = $1; }
2134 | context_def_mod STRING {
2135 $$ = scm_list_2 ($1, $2);
2137 | context_def_mod embedded_scm
2139 if (!scm_is_string ($2)
2140 && ly_symbol2scm ("consists") != $1
2141 && ly_symbol2scm ("remove") != $1)
2144 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2148 $$ = scm_list_2 ($1, $2);
2153 // If defined, at least two members.
2157 SCM l = scm_reverse_x ($1, SCM_EOL);
2160 (scm_object_property (scm_car (l),
2161 ly_symbol2scm ("is-grob?"))))
2162 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2163 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2164 parser->parser_error (@1, _ ("bad grob property path"));
2171 // If defined, at least three members
2175 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2177 parser->parser_error (@1, _ ("bad grob property path"));
2181 | grob_prop_spec property_path
2183 if (!SCM_UNBNDP ($1)) {
2184 $$ = scm_append_x (scm_list_2 ($1, $2));
2185 if (scm_is_null (scm_cddr ($$))) {
2186 parser->parser_error (@$, _ ("bad grob property path"));
2194 // Exactly two elements or undefined
2198 SCM l = scm_reverse_x ($1, SCM_EOL);
2199 switch (scm_ilength (l)) {
2201 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2205 parser->parser_error (@1, _ ("bad context property path"));
2212 simple_music_property_def:
2213 OVERRIDE grob_prop_path '=' scalar {
2214 if (SCM_UNBNDP ($2))
2217 $$ = scm_list_5 (scm_car ($2),
2218 ly_symbol2scm ("OverrideProperty"),
2224 | REVERT simple_revert_context revert_arg {
2225 $$ = scm_list_4 ($2,
2226 ly_symbol2scm ("RevertProperty"),
2230 | SET context_prop_spec '=' scalar {
2231 if (SCM_UNBNDP ($2))
2234 $$ = scm_list_4 (scm_car ($2),
2235 ly_symbol2scm ("PropertySet"),
2239 | UNSET context_prop_spec {
2240 if (SCM_UNBNDP ($2))
2243 $$ = scm_list_3 (scm_car ($2),
2244 ly_symbol2scm ("PropertyUnset"),
2250 // This is all quite awkward for the sake of substantial backward
2251 // compatibility while at the same time allowing a more "natural" form
2252 // of specification not separating grob specification from grob
2253 // property path. The purpose of this definition of
2254 // simple_revert_context is to allow the symbol list which specifies
2255 // grob and property to revert to be optionally be split into two
2256 // parts after the grob (which may be preceded by a context
2257 // specification, a case which we distinguish by checking whether the
2258 // first symbol is a valid grob symbol instead).
2260 // See revert_arg above for the main work horse of this arrangement.
2261 // simple_revert_context just caters for the context and delegates the
2262 // rest of the job to revert_arg.
2264 simple_revert_context:
2267 $1 = scm_reverse_x ($1, SCM_EOL);
2268 if (scm_is_null ($1)
2270 (scm_object_property (scm_car ($1),
2271 ly_symbol2scm ("is-grob?")))) {
2272 $$ = ly_symbol2scm ("Bottom");
2273 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2276 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2283 simple_music_property_def {
2284 if (SCM_UNBNDP ($1))
2285 $$ = MAKE_SYNTAX ("void-music", @1);
2287 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2296 | string '+' string {
2297 if (!scm_is_string ($1)) {
2298 parser->parser_error (@1, (_ ("simple string expected")));
2299 $1 = scm_string (SCM_EOL);
2301 if (!scm_is_string ($3)) {
2302 parser->parser_error (@3, (_ ("simple string expected")));
2303 $3 = scm_string (SCM_EOL);
2305 $$ = scm_string_append (scm_list_2 ($1, $3));
2309 simple_string: STRING {
2317 if (scm_is_string ($1)) {
2320 parser->parser_error (@1, (_ ("simple string expected")));
2321 $$ = scm_string (SCM_EOL);
2336 embedded_scm_arg_closed
2346 simple_element post_events {
2347 // Let the rhythmic music iterator sort this mess out.
2348 if (scm_is_pair ($2)) {
2349 $$ = make_music_from_simple (parser, @1, $1);
2350 if (unsmob_music ($$))
2351 unsmob_music ($$)->set_property ("articulations",
2352 scm_reverse_x ($2, SCM_EOL));
2354 parser->parser_error (@1, _("music expected"));
2357 | simple_chord_elements post_events {
2358 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2361 /* why is this giving wrong start location? -ns
2363 i.set_location (@1, @2);
2364 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2366 | CHORD_REPETITION optional_notemode_duration post_events {
2368 i.set_location (@1, @3);
2369 $$ = MAKE_SYNTAX ("repetition-chord", i,
2370 $2, scm_reverse_x ($3, SCM_EOL));
2372 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2374 i.set_location (@1, @3);
2375 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2376 scm_reverse_x ($3, SCM_EOL));
2379 | note_chord_element
2384 chord_body optional_notemode_duration post_events
2386 Music *m = unsmob_music ($1);
2387 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2388 SCM es = m->get_property ("elements");
2389 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2391 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2392 unsmob_music (scm_car (s))->set_property ("duration", dur);
2393 es = ly_append2 (es, postevs);
2395 m-> set_property ("elements", es);
2397 $$ = m->self_scm ();
2402 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2404 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2408 chord_body_elements:
2409 /* empty */ { $$ = SCM_EOL; }
2410 | chord_body_elements chord_body_element {
2411 if (!SCM_UNBNDP ($2))
2412 $$ = scm_cons ($2, $1);
2417 pitch exclamations questions octave_check post_events
2419 bool q = to_boolean ($3);
2420 bool ex = to_boolean ($2);
2424 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2425 n->set_property ("pitch", $1);
2427 n->set_property ("cautionary", SCM_BOOL_T);
2429 n->set_property ("force-accidental", SCM_BOOL_T);
2431 if (scm_is_pair (post)) {
2432 SCM arts = scm_reverse_x (post, SCM_EOL);
2433 n->set_property ("articulations", arts);
2435 if (scm_is_number (check))
2437 int q = scm_to_int (check);
2438 n->set_property ("absolute-octave", scm_from_int (q-1));
2441 $$ = n->unprotect ();
2443 | DRUM_PITCH post_events {
2444 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2445 n->set_property ("drum-type", $1);
2447 if (scm_is_pair ($2)) {
2448 SCM arts = scm_reverse_x ($2, SCM_EOL);
2449 n->set_property ("articulations", arts);
2451 $$ = n->unprotect ();
2453 | music_function_chord_body
2455 Music *m = unsmob_music ($1);
2457 while (m && m->is_mus_type ("music-wrapper-music")) {
2458 $$ = m->get_property ("element");
2459 m = unsmob_music ($$);
2462 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2463 parser->parser_error (@$, _ ("not a rhythmic event"));
2469 music_function_chord_body:
2474 // Event functions may only take closed arglists, otherwise it would
2475 // not be clear whether a following postevent should be associated
2476 // with the last argument of the event function or with the expression
2477 // for which the function call acts itself as event.
2479 music_function_call_closed:
2480 MUSIC_FUNCTION function_arglist_closed {
2481 $$ = MAKE_SYNTAX ("music-function", @$,
2486 event_function_event:
2487 EVENT_FUNCTION function_arglist_closed {
2488 $$ = MAKE_SYNTAX ("music-function", @$,
2498 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2499 m->set_property ("span-direction", scm_from_int (START));
2500 $$ = m->unprotect();
2503 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2504 m->set_property ("span-direction", scm_from_int (STOP));
2505 $$ = m->unprotect ();
2508 $$ = MAKE_SYNTAX ("voice-separator", @$);
2511 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2513 Music *m = unsmob_music (pipe);
2518 $$ = m->unprotect ();
2521 $$ = MAKE_SYNTAX ("bar-check", @$);
2528 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2540 | post_events post_event {
2541 unsmob_music ($2)->set_spot (@2);
2542 $$ = scm_cons ($2, $$);
2546 post_event_nofinger:
2547 direction_less_event {
2550 | script_dir music_function_call_closed {
2552 if (!SCM_UNBNDP ($1))
2554 unsmob_music ($$)->set_property ("direction", $1);
2558 if (!parser->lexer_->is_lyric_state ())
2559 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2560 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2563 if (!parser->lexer_->is_lyric_state ())
2564 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2565 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2567 | script_dir direction_reqd_event {
2568 if (!SCM_UNBNDP ($1))
2570 Music *m = unsmob_music ($2);
2571 m->set_property ("direction", $1);
2575 | script_dir direction_less_event {
2576 if (!SCM_UNBNDP ($1))
2578 Music *m = unsmob_music ($2);
2579 m->set_property ("direction", $1);
2586 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2591 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2602 string_number_event:
2604 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2605 s->set_property ("string-number", $1);
2606 $$ = s->unprotect ();
2610 direction_less_char:
2612 $$ = ly_symbol2scm ("bracketOpenSymbol");
2615 $$ = ly_symbol2scm ("bracketCloseSymbol");
2618 $$ = ly_symbol2scm ("tildeSymbol");
2621 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2624 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2627 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2630 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2633 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2636 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2639 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2643 direction_less_event:
2644 direction_less_char {
2645 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2647 if (unsmob_music (predefd))
2649 m = unsmob_music (predefd)->clone ();
2654 m = MY_MAKE_MUSIC ("Music", @$);
2656 $$ = m->unprotect ();
2658 | string_number_event
2659 | EVENT_IDENTIFIER {
2663 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2664 a->set_property ("tremolo-type", $1);
2665 $$ = a->unprotect ();
2667 | event_function_event
2670 direction_reqd_event:
2674 | script_abbreviation {
2675 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2676 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2677 if (scm_is_string (s))
2678 a->set_property ("articulation-type", s);
2679 else parser->parser_error (@1, _ ("expecting string as script definition"));
2680 $$ = a->unprotect ();
2685 /**/ { $$ = SCM_EOL; }
2686 | '=' quotes { $$ = $2; }
2700 $$ = scm_from_int (1);
2703 $$ = scm_oneplus ($1);
2709 $$ = scm_from_int (-1);
2712 $$ = scm_oneminus ($1);
2717 NOTENAME_PITCH quotes {
2718 if (!scm_is_eq (SCM_INUM0, $2))
2720 Pitch p = *unsmob_pitch ($1);
2721 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2722 $$ = p.smobbed_copy ();
2732 TONICNAME_PITCH quotes {
2733 if (!scm_is_eq (SCM_INUM0, $2))
2735 Pitch p = *unsmob_pitch ($1);
2736 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2737 $$ = p.smobbed_copy ();
2747 pitch_also_in_chords:
2754 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2755 t->set_property ("text", $1);
2756 $$ = t->unprotect ();
2759 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2760 t->set_property ("text",
2761 make_simple_markup ($1));
2762 $$ = t->unprotect ();
2765 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2766 t->set_property ("text",
2767 make_simple_markup ($1));
2768 $$ = t->unprotect ();
2772 Music *m = unsmob_music ($1);
2773 if (m && m->is_mus_type ("post-event"))
2775 else if (Text_interface::is_markup ($1)) {
2776 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2777 t->set_property ("text", $1);
2778 $$ = t->unprotect ();
2780 parser->parser_error (@1, _ ("not an articulation"));
2786 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2787 t->set_property ("digit", $1);
2788 $$ = t->unprotect ();
2792 script_abbreviation:
2794 $$ = scm_from_locale_string ("Hat");
2797 $$ = scm_from_locale_string ("Plus");
2800 $$ = scm_from_locale_string ("Dash");
2803 $$ = scm_from_locale_string ("Bar");
2806 $$ = scm_from_locale_string ("Larger");
2809 $$ = scm_from_locale_string ("Dot");
2812 $$ = scm_from_locale_string ("Underscore");
2817 '_' { $$ = scm_from_int (DOWN); }
2818 | '^' { $$ = scm_from_int (UP); }
2819 | '-' { $$ = SCM_UNDEFINED; }
2823 multiplied_duration {
2828 maybe_notemode_duration:
2832 | multiplied_duration {
2834 parser->default_duration_ = *unsmob_duration ($$);
2839 optional_notemode_duration:
2840 maybe_notemode_duration
2842 if (SCM_UNBNDP ($$))
2843 $$ = parser->default_duration_.smobbed_copy ();
2850 int n = scm_to_int ($1);
2851 if (!is_duration (n))
2852 parser->parser_error (@1, _f ("not a duration: %d", n));
2856 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2858 | DURATION_IDENTIFIER dots {
2859 Duration *d = unsmob_duration ($1);
2860 Duration k (d->duration_log (),
2861 d->dot_count () + scm_to_int ($2));
2862 k = k.compressed (d->factor ());
2863 scm_remember_upto_here_1 ($1);
2864 $$ = k.smobbed_copy ();
2868 multiplied_duration:
2872 | multiplied_duration '*' UNSIGNED {
2873 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2875 | multiplied_duration '*' FRACTION {
2876 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2878 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2887 $$ = scm_oneplus ($1);
2896 int n = scm_to_int ($2);
2897 if (!is_duration (n))
2898 parser->parser_error (@2, _f ("not a duration: %d", n));
2904 UNSIGNED { $$ = $1; }
2905 | STRING { $$ = $1; }
2906 | full_markup { $$ = $1; }
2909 // as an integer, it needs to be non-negative, and otherwise
2910 // it needs to be suitable as a markup.
2911 if (scm_is_integer ($1)
2912 ? scm_is_true (scm_negative_p ($1))
2913 : !Text_interface::is_markup ($1))
2915 parser->parser_error (@1, _ ("bass number expected"));
2921 figured_bass_alteration:
2922 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2923 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2924 | '!' { $$ = scm_from_int (0); }
2929 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2930 $$ = bfr->unprotect ();
2933 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2934 $$ = bfr->self_scm ();
2936 if (scm_is_number ($1))
2937 bfr->set_property ("figure", $1);
2938 else if (Text_interface::is_markup ($1))
2939 bfr->set_property ("text", $1);
2945 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2947 | bass_figure figured_bass_alteration {
2948 Music *m = unsmob_music ($1);
2949 if (scm_to_double ($2)) {
2950 SCM salter = m->get_property ("alteration");
2951 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2952 m->set_property ("alteration",
2953 scm_sum (alter, $2));
2955 m->set_property ("alteration", scm_from_int (0));
2958 | bass_figure figured_bass_modification {
2959 Music *m = unsmob_music ($1);
2960 if ($2 == ly_symbol2scm ("plus"))
2962 m->set_property ("augmented", SCM_BOOL_T);
2964 else if ($2 == ly_symbol2scm ("slash"))
2966 m->set_property ("diminished", SCM_BOOL_T);
2968 else if ($2 == ly_symbol2scm ("exclamation"))
2970 m->set_property ("no-continuation", SCM_BOOL_T);
2972 else if ($2 == ly_symbol2scm ("backslash"))
2974 m->set_property ("augmented-slash", SCM_BOOL_T);
2980 figured_bass_modification:
2982 $$ = ly_symbol2scm ("plus");
2985 $$ = ly_symbol2scm ("exclamation");
2988 $$ = ly_symbol2scm ("slash");
2991 $$ = ly_symbol2scm ("backslash");
3001 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
3009 | figure_list br_bass_figure {
3010 $$ = scm_cons ($2, $1);
3015 FIGURE_OPEN figure_list FIGURE_CLOSE {
3016 $$ = scm_reverse_x ($2, SCM_EOL);
3022 /**/ { $$ = SCM_BOOL_F; }
3023 | REST { $$ = SCM_BOOL_T; }
3027 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
3028 if (!parser->lexer_->is_note_state ())
3029 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
3030 if (!SCM_UNBNDP ($2)
3032 || scm_is_number ($4)
3034 || scm_is_true ($6))
3037 if (scm_is_true ($6))
3038 n = MY_MAKE_MUSIC ("RestEvent", @$);
3040 n = MY_MAKE_MUSIC ("NoteEvent", @$);
3042 n->set_property ("pitch", $1);
3043 if (SCM_UNBNDP ($5))
3044 n->set_property ("duration",
3045 parser->default_duration_.smobbed_copy ());
3047 n->set_property ("duration", $5);
3049 if (scm_is_number ($4))
3051 int q = scm_to_int ($4);
3052 n->set_property ("absolute-octave", scm_from_int (q-1));
3055 if (to_boolean ($3))
3056 n->set_property ("cautionary", SCM_BOOL_T);
3057 if (to_boolean ($2) || to_boolean ($3))
3058 n->set_property ("force-accidental", SCM_BOOL_T);
3060 $$ = n->unprotect ();
3063 | DRUM_PITCH optional_notemode_duration {
3064 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3065 n->set_property ("duration", $2);
3066 n->set_property ("drum-type", $1);
3068 $$ = n->unprotect ();
3070 | RESTNAME optional_notemode_duration {
3072 if (ly_scm2string ($1) == "s") {
3074 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3077 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3080 ev->set_property ("duration", $2);
3081 $$ = ev->unprotect ();
3085 simple_chord_elements:
3087 if (!parser->lexer_->is_chord_state ())
3088 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3091 | figure_spec optional_notemode_duration {
3092 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3094 unsmob_music (scm_car (s))->set_property ("duration", $2);
3110 lyric_element_music:
3111 lyric_element optional_notemode_duration post_events {
3112 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3113 if (scm_is_pair ($3))
3114 unsmob_music ($$)->set_property
3115 ("articulations", scm_reverse_x ($3, SCM_EOL));
3120 steno_tonic_pitch optional_notemode_duration {
3121 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3123 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3124 SCM its = scm_reverse_x ($4, SCM_EOL);
3125 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3133 | chord_items chord_item {
3134 $$ = scm_cons ($2, $$);
3140 $$ = ly_symbol2scm ("chord-colon");
3143 $$ = ly_symbol2scm ("chord-caret");
3145 | CHORD_SLASH steno_tonic_pitch {
3146 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3148 | CHORD_BASS steno_tonic_pitch {
3149 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3158 $$ = scm_reverse_x ($1, SCM_EOL);
3166 step_number { $$ = scm_cons ($1, SCM_EOL); }
3167 | step_numbers '.' step_number {
3168 $$ = scm_cons ($3, $$);
3174 $$ = make_chord_step ($1, 0);
3177 $$ = make_chord_step ($1, SHARP_ALTERATION);
3179 | UNSIGNED CHORD_MINUS {
3180 $$ = make_chord_step ($1, FLAT_ALTERATION);
3188 | UNSIGNED '~' UNSIGNED {
3189 $$ = scm_cons ($1, $3);
3196 TODO: should deprecate in favor of Scheme?
3200 number_expression '+' number_term {
3201 $$ = scm_sum ($1, $3);
3203 | number_expression '-' number_term {
3204 $$ = scm_difference ($1, $3);
3213 | number_factor '*' number_factor {
3214 $$ = scm_product ($1, $3);
3216 | number_factor '/' number_factor {
3217 $$ = scm_divide ($1, $3);
3222 '-' number_factor { /* %prec UNARY_MINUS */
3223 $$ = scm_difference ($2, SCM_UNDEFINED);
3231 | UNSIGNED NUMBER_IDENTIFIER {
3232 $$ = scm_product ($1, $2);
3234 | REAL NUMBER_IDENTIFIER {
3235 $$ = scm_product ($1, $2);
3251 { $$ = SCM_UNDEFINED; }
3254 if (SCM_UNBNDP ($1))
3262 { $$ = SCM_UNDEFINED; }
3265 if (SCM_UNBNDP ($1))
3273 This should be done more dynamically if possible.
3278 { parser->lexer_->push_markup_state (); }
3281 parser->lexer_->pop_state ();
3287 { parser->lexer_->push_markup_state (); }
3290 parser->lexer_->pop_state ();
3296 { parser->lexer_->push_markup_state (); }
3299 parser->lexer_->pop_state ();
3305 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3307 | markup_head_1_list simple_markup {
3308 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3318 if (Text_interface::is_markup ($1))
3319 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3320 else if (Text_interface::is_markup_list ($1))
3321 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3323 parser->parser_error (@1, _ ("not a markup"));
3324 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3331 markup_composed_list {
3334 | markup_braced_list {
3337 | markup_command_list {
3338 $$ = scm_list_1 ($1);
3340 | markup_scm MARKUPLIST_IDENTIFIER
3346 markup_composed_list:
3347 markup_head_1_list markup_braced_list {
3348 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3354 '{' markup_braced_list_body '}' {
3355 $$ = scm_reverse_x ($2, SCM_EOL);
3359 markup_braced_list_body:
3360 /* empty */ { $$ = SCM_EOL; }
3361 | markup_braced_list_body markup {
3362 $$ = scm_cons ($2, $1);
3364 | markup_braced_list_body markup_list {
3365 $$ = scm_reverse_x ($2, $1);
3369 markup_command_list:
3370 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3371 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3375 markup_command_basic_arguments:
3376 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3377 $$ = scm_cons ($3, $2);
3379 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3380 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3382 | EXPECT_NO_MORE_ARGS {
3387 markup_command_list_arguments:
3388 markup_command_basic_arguments { $$ = $1; }
3389 | EXPECT_MARKUP markup_command_list_arguments markup {
3390 $$ = scm_cons ($3, $2);
3395 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3396 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3401 markup_head_1_item {
3402 $$ = scm_list_1 ($1);
3404 | markup_head_1_list markup_head_1_item {
3405 $$ = scm_cons ($2, $1);
3411 $$ = make_simple_markup ($1);
3414 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3415 parser->lexer_->push_note_state (nn);
3416 } '{' score_body '}' {
3417 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3418 parser->lexer_->pop_state ();
3420 | MARKUP_FUNCTION markup_command_basic_arguments {
3421 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3423 | markup_scm MARKUP_IDENTIFIER
3430 markup_head_1_list simple_markup {
3431 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3432 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3442 Lily_parser::set_yydebug (bool x)
3448 Lily_parser::do_yyparse ()
3450 SCM retval = SCM_UNDEFINED;
3451 yyparse (this, &retval);
3461 It is a little strange to have this function in this file, but
3462 otherwise, we have to import music classes into the lexer.
3466 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3468 if (unsmob_book (sid)) {
3469 Book *book = unsmob_book (sid)->clone ();
3470 *destination = book->self_scm ();
3473 return BOOK_IDENTIFIER;
3474 } else if (scm_is_number (sid)) {
3476 return NUMBER_IDENTIFIER;
3477 } else if (unsmob_context_def (sid)) {
3478 Context_def *def= unsmob_context_def (sid)->clone ();
3480 *destination = def->self_scm ();
3483 return CONTEXT_DEF_IDENTIFIER;
3484 } else if (unsmob_context_mod (sid)) {
3485 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3487 return CONTEXT_MOD_IDENTIFIER;
3488 } else if (unsmob_score (sid)) {
3489 Score *score = new Score (*unsmob_score (sid));
3490 *destination = score->self_scm ();
3492 score->unprotect ();
3493 return SCORE_IDENTIFIER;
3494 } else if (Music *mus = unsmob_music (sid)) {
3495 mus = mus->clone ();
3496 *destination = mus->self_scm ();
3497 unsmob_music (*destination)->
3498 set_property ("origin", make_input (last_input_));
3500 bool is_event = mus->is_mus_type ("post-event");
3502 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3503 } else if (unsmob_pitch (sid)) {
3504 *destination = unsmob_pitch (sid)->smobbed_copy ();
3505 return PITCH_IDENTIFIER;
3506 } else if (unsmob_duration (sid)) {
3507 *destination = unsmob_duration (sid)->smobbed_copy ();
3508 return DURATION_IDENTIFIER;
3509 } else if (unsmob_output_def (sid)) {
3510 Output_def *p = unsmob_output_def (sid);
3513 *destination = p->self_scm ();
3515 return OUTPUT_DEF_IDENTIFIER;
3522 get_next_unique_context_id ()
3524 return scm_from_locale_string ("$uniqueContextId");
3529 get_next_unique_lyrics_context_id ()
3531 static int new_context_count;
3533 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3534 return scm_from_locale_string (s);
3537 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3538 SCM arg, SCM args, SCM pred)
3540 args = scm_cons (arg, args);
3541 if (scm_is_true (scm_call_1 (pred, arg)))
3543 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3544 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3545 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3549 SCM loc_on_music (Input loc, SCM arg)
3551 if (Music *m = unsmob_music (arg))
3555 return m->unprotect ();
3561 try_string_variants (SCM pred, SCM str)
3563 // a matching predicate is always ok
3564 if (scm_is_true (scm_call_1 (pred, str)))
3566 // a symbol may be interpreted as a list of symbols if it helps
3567 if (scm_is_symbol (str)) {
3568 str = scm_list_1 (str);
3569 if (scm_is_true (scm_call_1 (pred, str)))
3571 return SCM_UNDEFINED;
3574 // If this cannot be a string representation of a symbol list,
3577 if (!is_regular_identifier (str, true))
3578 return SCM_UNDEFINED;
3580 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3581 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3582 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3584 // Let's attempt the symbol list interpretation first.
3586 if (scm_is_true (scm_call_1 (pred, str)))
3589 // If there is just one symbol in the list, we might interpret
3590 // it as a single symbol
3592 if (scm_is_null (scm_cdr (str)))
3594 str = scm_car (str);
3595 if (scm_is_true (scm_call_1 (pred, str)))
3599 return SCM_UNDEFINED;
3603 is_regular_identifier (SCM id, bool multiple)
3605 if (!scm_is_string (id))
3608 string str = ly_scm2string (id);
3610 bool middle = false;
3612 for (string::iterator it=str.begin(); it != str.end (); it++)
3615 if ((c >= 'a' && c <= 'z')
3616 || (c >= 'A' && c <= 'Z')
3619 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3628 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3630 if (unsmob_music (simple))
3632 if (parser->lexer_->is_note_state ()) {
3633 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3634 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3635 if (scm_is_symbol (simple))
3636 n->set_property ("drum-type", simple);
3637 else if (unsmob_pitch (simple))
3638 n->set_property ("pitch", simple);
3643 return n->unprotect ();
3644 } else if (parser->lexer_->is_lyric_state ()) {
3645 if (Text_interface::is_markup (simple))
3646 return MAKE_SYNTAX ("lyric-event", loc, simple,
3647 parser->default_duration_.smobbed_copy ());
3648 } else if (parser->lexer_->is_chord_state ()) {
3649 if (unsmob_pitch (simple))
3650 return make_chord_elements (loc, simple,
3651 parser->default_duration_.smobbed_copy (),
3658 make_music_with_input (SCM name, Input where)
3660 Music *m = make_music_by_name (name);
3661 m->set_spot (where);
3666 make_simple_markup (SCM a)
3674 return t && t == 1 << intlog2 (t);
3678 make_chord_step (SCM step_scm, Rational alter)
3680 int step = scm_to_int (step_scm);
3683 alter += FLAT_ALTERATION;
3687 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3688 return m.smobbed_copy ();
3693 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3695 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3696 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3697 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3699 unsmob_music (scm_car (s))->set_spot (loc);
3705 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3707 Lily_lexer *lex = parser->lexer_;
3711 lex->prepare_for_next_token ();
3712 return lex->yylex ();