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, SCM disp = SCM_UNDEFINED);
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
331 %token MULTI_MEASURE_REST
337 /* Artificial tokens, for more generic function syntax */
338 %token EXPECT_MARKUP "markup?"
339 %token EXPECT_PITCH "ly:pitch?"
340 %token EXPECT_DURATION "ly:duration?"
341 %token EXPECT_SCM "scheme?"
342 %token BACKUP "(backed-up?)"
343 %token REPARSE "(reparsed?)"
344 %token EXPECT_MARKUP_LIST "markup-list?"
345 %token EXPECT_OPTIONAL "optional?"
346 /* After the last argument. */
347 %token EXPECT_NO_MORE_ARGS;
349 /* An artificial token for parsing embedded Lilypond */
350 %token EMBEDDED_LILY "#{"
352 %token BOOK_IDENTIFIER
353 %token CHORDMODIFIER_PITCH
354 %token CHORD_MODIFIER
355 %token CHORD_REPETITION
356 %token CONTEXT_DEF_IDENTIFIER
357 %token CONTEXT_MOD_IDENTIFIER
359 %token PITCH_IDENTIFIER
360 %token DURATION_IDENTIFIER
361 %token EVENT_IDENTIFIER
362 %token EVENT_FUNCTION
365 %token MARKUP_FUNCTION
366 %token MARKUP_LIST_FUNCTION
367 %token MARKUP_IDENTIFIER
368 %token MARKUPLIST_IDENTIFIER
369 %token MUSIC_FUNCTION
370 %token MUSIC_IDENTIFIER
371 %token NOTENAME_PITCH
372 %token NUMBER_IDENTIFIER
373 %token OUTPUT_DEF_IDENTIFIER
378 %token SCM_IDENTIFIER
382 %token TONICNAME_PITCH
386 /* We don't assign precedence to / and *, because we might need varied
387 prec levels in different prods */
396 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
397 parser->lexer_->push_note_state (nn);
398 } embedded_lilypond {
399 parser->lexer_->pop_state ();
404 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
405 | lilypond toplevel_expression {
407 | lilypond assignment {
410 parser->error_level_ = 1;
413 parser->error_level_ = 1;
420 parser->lexer_->add_scope (get_header (parser));
422 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
425 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
426 scm_call_2 (proc, parser->self_scm (), $1);
429 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
430 scm_call_2 (proc, parser->self_scm (), $1);
433 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
434 scm_call_2 (proc, parser->self_scm (), $1);
437 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
438 scm_call_2 (proc, parser->self_scm (), $1);
441 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
442 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
445 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
446 scm_call_2 (proc, parser->self_scm (), $1);
449 // Evaluate and ignore #xxx, as opposed to \xxx
450 parser->lexer_->eval_scm_token ($1);
452 | embedded_scm_active
454 SCM out = SCM_UNDEFINED;
455 if (Text_interface::is_markup ($1))
456 out = scm_list_1 ($1);
457 else if (Text_interface::is_markup_list ($1))
459 if (scm_is_pair (out))
461 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
462 scm_call_2 (proc, parser->self_scm (), out);
463 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
464 parser->parser_error (@1, _("bad expression type"));
468 Output_def * od = unsmob_output_def ($1);
470 if (od->c_variable ("is-paper") == SCM_BOOL_T)
471 id = ly_symbol2scm ("$defaultpaper");
472 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
473 id = ly_symbol2scm ("$defaultmidi");
474 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
475 id = ly_symbol2scm ("$defaultlayout");
477 parser->lexer_->set_identifier (id, $1);
484 $$ = parser->lexer_->eval_scm_token ($1);
494 embedded_scm_bare_arg:
498 $$ = parser->lexer_->eval_scm_token ($1);
501 | context_modification
503 | context_def_spec_block
509 /* The generic version may end in music, or not */
517 embedded_scm_bare_arg
523 SCM_FUNCTION function_arglist {
524 $$ = MAKE_SYNTAX ("music-function", @$,
532 $$ = MAKE_SYNTAX ("void-music", @$);
535 | music_embedded music_embedded music_list {
536 $3 = scm_reverse_x ($3, SCM_EOL);
537 if (unsmob_music ($2))
538 $3 = scm_cons ($2, $3);
539 if (unsmob_music ($1))
540 $3 = scm_cons ($1, $3);
541 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
544 parser->error_level_ = 1;
545 $$ = SCM_UNSPECIFIED;
547 | INVALID embedded_lilypond {
548 parser->error_level_ = 1;
554 lilypond_header_body:
555 /* empty */ { $$ = SCM_UNSPECIFIED; }
556 | lilypond_header_body assignment {
559 | lilypond_header_body embedded_scm {
565 HEADER '{' lilypond_header_body '}' {
566 $$ = parser->lexer_->remove_scope ();
578 assignment_id '=' identifier_init {
579 parser->lexer_->set_identifier ($1, $3);
580 $$ = SCM_UNSPECIFIED;
582 | assignment_id property_path '=' identifier_init {
583 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
584 parser->lexer_->set_identifier (path, $4);
585 $$ = SCM_UNSPECIFIED;
595 | context_def_spec_block
597 | post_event_nofinger
603 | context_modification
606 context_def_spec_block:
607 CONTEXT '{' context_def_spec_body '}'
618 context_mod_embedded:
621 if (unsmob_music ($1)) {
622 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
623 $1 = scm_call_2 (proc, parser->self_scm (), $1);
625 if (unsmob_context_mod ($1))
628 parser->parser_error (@1, _ ("not a context mod"));
634 context_def_spec_body:
636 $$ = Context_def::make_scm ();
637 unsmob_context_def ($$)->origin ()->set_spot (@$);
639 | CONTEXT_DEF_IDENTIFIER {
641 unsmob_context_def ($$)->origin ()->set_spot (@$);
643 | context_def_spec_body context_mod {
644 if (!SCM_UNBNDP ($2))
645 unsmob_context_def ($$)->add_context_mod ($2);
647 | context_def_spec_body context_modification {
648 Context_def *td = unsmob_context_def ($$);
649 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
650 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
651 td->add_context_mod (scm_car (m));
654 | context_def_spec_body context_mod_embedded {
655 Context_def *td = unsmob_context_def ($$);
656 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
657 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
658 td->add_context_mod (scm_car (m));
666 BOOK '{' book_body '}' {
669 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
674 * Use 'handlers' like for toplevel-* stuff?
675 * grok \layout and \midi? */
678 Book *book = new Book;
679 init_papers (parser);
680 book->origin ()->set_spot (@$);
681 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
682 book->paper_->unprotect ();
683 push_paper (parser, book->paper_);
684 book->header_ = get_header (parser);
685 $$ = book->unprotect ();
686 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
689 unsmob_book ($1)->origin ()->set_spot (@$);
690 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
692 | book_body paper_block {
693 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
694 set_paper (parser, unsmob_output_def ($2));
696 | book_body bookpart_block {
697 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
698 scm_call_2 (proc, $1, $2);
700 | book_body score_block {
701 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
702 scm_call_2 (proc, $1, $2);
704 | book_body composite_music {
705 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
706 scm_call_3 (proc, parser->self_scm (), $1, $2);
708 | book_body full_markup {
709 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
710 scm_call_2 (proc, $1, scm_list_1 ($2));
712 | book_body full_markup_list {
713 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
714 scm_call_2 (proc, $1, $2);
716 | book_body SCM_TOKEN {
717 // Evaluate and ignore #xxx, as opposed to \xxx
718 parser->lexer_->eval_scm_token ($2);
720 | book_body embedded_scm_active
722 SCM out = SCM_UNDEFINED;
723 if (Text_interface::is_markup ($2))
724 out = scm_list_1 ($2);
725 else if (Text_interface::is_markup_list ($2))
727 if (scm_is_pair (out))
729 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
730 scm_call_2 (proc, $1, out);
731 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
732 parser->parser_error (@2, _("bad expression type"));
736 parser->lexer_->add_scope (unsmob_book ($1)->header_);
739 Book *book = unsmob_book ($1);
741 book->scores_ = SCM_EOL;
742 book->bookparts_ = SCM_EOL;
747 BOOKPART '{' bookpart_body '}' {
749 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
755 Book *book = new Book;
756 book->origin ()->set_spot (@$);
757 $$ = book->unprotect ();
758 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
761 unsmob_book ($1)->origin ()->set_spot (@$);
762 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
764 | bookpart_body paper_block {
765 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
767 | bookpart_body score_block {
768 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
769 scm_call_2 (proc, $1, $2);
771 | bookpart_body composite_music {
772 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
773 scm_call_3 (proc, parser->self_scm (), $1, $2);
775 | bookpart_body full_markup {
776 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
777 scm_call_2 (proc, $1, scm_list_1 ($2));
779 | bookpart_body full_markup_list {
780 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
781 scm_call_2 (proc, $1, $2);
783 | bookpart_body SCM_TOKEN {
784 // Evaluate and ignore #xxx, as opposed to \xxx
785 parser->lexer_->eval_scm_token ($2);
787 | bookpart_body embedded_scm_active
789 SCM out = SCM_UNDEFINED;
790 if (Text_interface::is_markup ($2))
791 out = scm_list_1 ($2);
792 else if (Text_interface::is_markup_list ($2))
794 if (scm_is_pair (out))
796 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
797 scm_call_2 (proc, $1, out);
798 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
799 parser->parser_error (@2, _("bad expression type"));
803 Book *book = unsmob_book ($1);
804 if (!ly_is_module (book->header_))
805 book->header_ = ly_make_module (false);
806 parser->lexer_->add_scope (book->header_);
808 | bookpart_body error {
809 Book *book = unsmob_book ($1);
811 book->scores_ = SCM_EOL;
816 SCORE '{' score_body '}' {
823 SCM scorify = ly_lily_module_constant ("scorify-music");
824 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
826 unsmob_score ($$)->origin ()->set_spot (@$);
828 | embedded_scm_active {
830 if (unsmob_score ($1))
831 score = new Score (*unsmob_score ($1));
834 parser->parser_error (@1, _("score expected"));
836 unsmob_score ($$)->origin ()->set_spot (@$);
837 $$ = score->unprotect ();
841 Score *score = unsmob_score ($1);
842 if (!ly_is_module (score->get_header ()))
843 score->set_header (ly_make_module (false));
844 parser->lexer_->add_scope (score->get_header ());
846 | score_body output_def {
847 Output_def *od = unsmob_output_def ($2);
848 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
850 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
855 unsmob_score ($1)->add_output_def (od);
859 unsmob_score ($$)->error_found_ = true;
870 Output_def *od = unsmob_output_def ($1);
872 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
874 parser->parser_error (@1, _ ("need \\paper for paper block"));
875 $$ = get_paper (parser)->unprotect ();
882 output_def_body '}' {
885 parser->lexer_->remove_scope ();
886 parser->lexer_->pop_state ();
892 Output_def *p = get_paper (parser);
893 p->input_origin_ = @$;
894 parser->lexer_->add_scope (p->scope_);
895 $$ = p->unprotect ();
898 Output_def *p = get_midi (parser);
899 $$ = p->unprotect ();
900 parser->lexer_->add_scope (p->scope_);
903 Output_def *p = get_layout (parser);
905 parser->lexer_->add_scope (p->scope_);
906 $$ = p->unprotect ();
910 output_def_head_with_mode_switch:
912 parser->lexer_->push_initial_state ();
917 // We need this weird nonterminal because both music as well as a
918 // context definition can start with \context and the difference is
919 // only apparent after looking at the next token. If it is '{', there
920 // is still time to escape from notes mode.
922 music_or_context_def:
925 parser->lexer_->pop_state ();
929 parser->lexer_->pop_state ();
930 } '{' context_def_spec_body '}'
937 output_def_head_with_mode_switch '{' {
939 unsmob_output_def ($$)->input_origin_.set_spot (@$);
941 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
942 Output_def *o = unsmob_output_def ($3);
943 o->input_origin_.set_spot (@$);
945 parser->lexer_->remove_scope ();
946 parser->lexer_->add_scope (o->scope_);
948 | output_def_body assignment {
951 | output_def_body embedded_scm {
956 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
957 parser->lexer_->push_note_state (nn);
958 } music_or_context_def
960 if (unsmob_context_def ($3))
961 assign_context_def (unsmob_output_def ($1), $3);
964 SCM proc = parser->lexer_->lookup_identifier
965 ("output-def-music-handler");
966 scm_call_3 (proc, parser->self_scm (),
970 | output_def_body error {
976 TEMPO steno_duration '=' tempo_range {
977 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
979 | TEMPO scalar_closed steno_duration '=' tempo_range {
980 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
983 $$ = MAKE_SYNTAX ("tempo", @$, $2);
988 The representation of a list is reversed to have efficient append. */
994 | music_list music_embedded {
995 if (unsmob_music ($2))
996 $$ = scm_cons ($2, $1);
999 Music *m = MY_MAKE_MUSIC("Music", @$);
1001 m->set_property ("error-found", SCM_BOOL_T);
1002 $$ = scm_cons (m->self_scm (), $1);
1003 m->unprotect (); /* UGH */
1010 $$ = scm_reverse_x ($2, SCM_EOL);
1015 | lyric_element_music
1021 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1022 parser->parser_error (@1, _ ("unexpected post-event"));
1023 $$ = SCM_UNSPECIFIED;
1028 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1030 else if (Music *m = unsmob_music ($1)) {
1031 if (m->is_mus_type ("post-event")) {
1032 parser->parser_error
1033 (@1, _ ("unexpected post-event"));
1034 $$ = SCM_UNSPECIFIED;
1038 @$.warning (_ ("Ignoring non-music expression"));
1039 $$ = SCM_UNSPECIFIED;
1047 $$ = make_music_from_simple (parser, @1, $1);
1048 if (!unsmob_music ($$))
1049 parser->parser_error (@1, _ ("music expected"));
1051 | composite_music %prec COMPOSITE
1056 | composite_music %prec COMPOSITE
1060 REPEAT simple_string unsigned_number music
1062 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1064 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1066 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1071 SEQUENTIAL braced_music_list {
1072 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1074 | braced_music_list {
1075 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1080 SIMULTANEOUS braced_music_list {
1081 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1083 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1084 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1090 | music_property_def
1094 context_modification:
1095 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1097 parser->lexer_->pop_state ();
1100 | WITH CONTEXT_MOD_IDENTIFIER
1104 | CONTEXT_MOD_IDENTIFIER
1108 | WITH embedded_scm_closed
1110 if (unsmob_context_mod ($2))
1113 parser->parser_error (@2, _ ("not a context mod"));
1114 $$ = Context_mod ().smobbed_copy ();
1119 optional_context_mod:
1123 | context_modification
1131 $$ = Context_mod ().smobbed_copy ();
1133 | context_mod_list context_mod {
1134 if (!SCM_UNBNDP ($2))
1135 unsmob_context_mod ($1)->add_context_mod ($2);
1137 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1138 Context_mod *md = unsmob_context_mod ($2);
1140 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1142 | context_mod_list context_mod_embedded {
1143 unsmob_context_mod ($1)->add_context_mods
1144 (unsmob_context_mod ($2)->get_mods ());
1153 /* Music that can be parsed without lookahead */
1156 | complex_music_prefix closed_music
1158 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1160 | music_function_call_closed
1166 | grouped_music_list
1170 simultaneous_music { $$ = $1; }
1171 | sequential_music { $$ = $1; }
1174 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1175 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1176 and this rule returns the reversed list of arguments. */
1178 /* Function argument lists come in a number of flavors. Whenever
1179 * LilyPond has to pick between different flavors, the decision is
1180 * either made because of tokens it has already seen, or it is
1181 * postponed until tokens suitable for making the decision come up.
1182 * For postponing decisions, it may be necessary that the competing
1183 * rules are written in a way making them compatible until a decision
1184 * can be made. Sometimes this is done by putting common traits into
1185 * a separate "common" rule set.
1187 * function_arglist: a full argument list. Optional arguments at the
1188 * end of the list can only be skipped by writing \default in their
1191 * function_arglist_backup: an argument list ending in an optional
1192 * argument that may be skipped depending on its predicate.
1194 * function_arglist_skip: an argument list _not_ ending in an optional
1195 * argument that is actually taken.
1197 * function_arglist_nonbackup: an argument list ending in an optional
1198 * argument that may not be skipped because it is in end position and
1199 * has not been shortcircuited with \default.
1201 * function_arglist* / function_arglist_closed*: The closed variants
1202 * don't end in simple music expressions that might still accept
1203 * things like a duration or a postevent.
1206 function_arglist_skip:
1207 function_arglist_common
1208 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1210 $$ = scm_cons ($1, $3);
1211 } %prec FUNCTION_ARGLIST
1212 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1214 $$ = scm_cons ($1, $3);
1215 } %prec FUNCTION_ARGLIST
1216 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1218 $$ = scm_cons ($1, $3);
1219 } %prec FUNCTION_ARGLIST
1223 function_arglist_nonbackup_common:
1224 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1225 $$ = scm_cons ($4, $3);
1227 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1228 $$ = scm_cons ($4, $3);
1230 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1232 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1234 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1236 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1238 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1240 SCM n = scm_difference ($5, SCM_UNDEFINED);
1241 if (scm_is_true (scm_call_1 ($2, n)))
1242 $$ = scm_cons (n, $3);
1244 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1245 t->set_property ("digit", $5);
1246 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1251 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1253 $$ = check_scheme_arg (parser, @4,
1254 scm_difference ($5, SCM_UNDEFINED),
1257 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1259 $$ = check_scheme_arg (parser, @4,
1260 scm_difference ($5, SCM_UNDEFINED),
1265 function_arglist_closed_nonbackup:
1266 function_arglist_nonbackup_common
1267 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1269 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1271 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1273 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1275 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1277 $$ = check_scheme_arg (parser, @4,
1278 try_string_variants ($2, $4),
1281 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1283 $$ = check_scheme_arg (parser, @4,
1284 try_string_variants ($2, $4),
1287 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1289 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1295 | SYMBOL_LIST '.' symbol_list_rev
1297 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1303 | symbol_list_rev '.' symbol_list_part
1305 $$ = scm_append_x (scm_list_2 ($3, $1));
1309 // symbol_list_part delivers elements in reverse copy.
1314 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1315 $$ = try_string_variants (sym_l_p, $1);
1316 if (SCM_UNBNDP ($$)) {
1317 parser->parser_error (@1, _("not a symbol"));
1320 $$ = scm_reverse ($$);
1325 symbol_list_element:
1331 function_arglist_nonbackup:
1332 function_arglist_nonbackup_common
1333 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1335 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1337 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1339 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1341 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1343 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1345 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1347 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1349 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1351 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1355 function_arglist_nonbackup_reparse:
1356 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1359 SCM res = try_string_variants ($2, $4);
1360 if (!SCM_UNBNDP (res))
1361 if (scm_is_pair (res))
1362 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1364 MYREPARSE (@4, $2, SCM_ARG, res);
1365 else if (scm_is_true
1367 ($2, make_music_from_simple
1369 MYREPARSE (@4, $2, STRING, $4);
1371 MYREPARSE (@4, $2, SCM_ARG, $4);
1373 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1376 SCM res = try_string_variants ($2, $4);
1377 if (!SCM_UNBNDP (res))
1378 if (scm_is_pair (res))
1379 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1381 MYREPARSE (@4, $2, SCM_ARG, res);
1382 else if (scm_is_true
1384 ($2, make_music_from_simple
1386 MYREPARSE (@4, $2, STRING, $4);
1388 MYREPARSE (@4, $2, SCM_ARG, $4);
1390 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1393 if (scm_is_true (scm_call_1 ($2, $4)))
1394 MYREPARSE (@4, $2, SCM_ARG, $4);
1395 else if (scm_is_true
1397 ($2, make_music_from_simple
1399 MYREPARSE (@4, $2, STRING, $4);
1401 MYREPARSE (@4, $2, SCM_ARG, $4);
1405 function_arglist_keep:
1406 function_arglist_common
1407 | function_arglist_backup
1410 function_arglist_closed_keep:
1411 function_arglist_closed_common
1412 | function_arglist_backup
1415 function_arglist_backup:
1416 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1418 if (scm_is_true (scm_call_1 ($2, $4)))
1420 $$ = scm_cons ($4, $3);
1422 $$ = scm_cons (loc_on_music (@3, $1), $3);
1423 MYBACKUP (SCM_ARG, $4, @4);
1426 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1428 if (scm_is_true (scm_call_1 ($2, $4)))
1430 $$ = scm_cons ($4, $3);
1432 $$ = scm_cons (loc_on_music (@3, $1), $3);
1433 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1436 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep full_markup
1438 if (scm_is_true (scm_call_1 ($2, $4)))
1439 $$ = scm_cons ($4, $3);
1441 $$ = scm_cons (loc_on_music (@3, $1), $3);
1442 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1445 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1447 if (scm_is_true (scm_call_1 ($2, $4)))
1450 MYREPARSE (@4, $2, UNSIGNED, $4);
1452 $$ = scm_cons (loc_on_music (@3, $1), $3);
1453 MYBACKUP (UNSIGNED, $4, @4);
1456 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1458 if (scm_is_true (scm_call_1 ($2, $4)))
1461 MYREPARSE (@4, $2, REAL, $4);
1463 $$ = scm_cons (loc_on_music (@3, $1), $3);
1464 MYBACKUP (REAL, $4, @4);
1467 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1469 if (scm_is_true (scm_call_1 ($2, $4)))
1471 $$ = scm_cons ($4, $3);
1473 $$ = scm_cons (loc_on_music (@3, $1), $3);
1474 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1477 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1479 if (scm_is_true (scm_call_1 ($2, $4)))
1481 $$ = scm_cons ($4, $3);
1483 $$ = scm_cons (loc_on_music (@3, $1), $3);
1484 MYBACKUP (FRACTION, $4, @4);
1487 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1489 SCM n = scm_difference ($5, SCM_UNDEFINED);
1490 if (scm_is_true (scm_call_1 ($2, n))) {
1492 MYREPARSE (@5, $2, REAL, n);
1494 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1495 t->set_property ("digit", $5);
1496 $$ = t->unprotect ();
1497 if (scm_is_true (scm_call_1 ($2, $$)))
1498 $$ = scm_cons ($$, $3);
1500 $$ = scm_cons (loc_on_music (@3, $1), $3);
1501 MYBACKUP (UNSIGNED, $5, @5);
1502 parser->lexer_->push_extra_token ('-');
1507 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1509 SCM n = scm_difference ($5, SCM_UNDEFINED);
1510 if (scm_is_true (scm_call_1 ($2, n))) {
1511 MYREPARSE (@5, $2, REAL, n);
1514 $$ = scm_cons (loc_on_music (@3, $1), $3);
1515 MYBACKUP (REAL, n, @5);
1518 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1520 SCM n = scm_difference ($5, SCM_UNDEFINED);
1521 if (scm_is_true (scm_call_1 ($2, n))) {
1522 $$ = scm_cons (n, $3);
1524 $$ = scm_cons (loc_on_music (@3, $1), $3);
1525 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1528 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1530 $$ = scm_cons ($4, $3);
1532 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1534 $$ = scm_cons ($4, $3);
1536 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1538 SCM res = try_string_variants ($2, $4);
1539 if (!SCM_UNBNDP (res))
1540 if (scm_is_pair (res)) {
1542 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1545 $$ = scm_cons (res, $3);
1547 $$ = scm_cons (loc_on_music (@3, $1), $3);
1548 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1551 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1553 SCM res = try_string_variants ($2, $4);
1554 if (!SCM_UNBNDP (res))
1555 if (scm_is_pair (res)) {
1557 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1560 $$ = scm_cons (res, $3);
1562 $$ = scm_cons (loc_on_music (@3, $1), $3);
1563 MYBACKUP (STRING, $4, @4);
1566 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1568 $$ = scm_cons ($1, $3);
1569 MYBACKUP(0, SCM_UNDEFINED, @3);
1571 | function_arglist_backup REPARSE bare_number
1573 $$ = check_scheme_arg (parser, @3,
1576 | function_arglist_backup REPARSE symbol_list_arg
1578 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1583 function_arglist_common
1584 | function_arglist_nonbackup
1587 function_arglist_common:
1588 function_arglist_bare
1589 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1591 $$ = check_scheme_arg (parser, @3,
1594 | EXPECT_SCM function_arglist_closed_optional bare_number
1596 $$ = check_scheme_arg (parser, @3,
1599 | EXPECT_SCM function_arglist_optional FRACTION
1601 $$ = check_scheme_arg (parser, @3,
1604 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1606 $$ = check_scheme_arg (parser, @3,
1609 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1611 SCM n = scm_difference ($4, SCM_UNDEFINED);
1612 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1614 | function_arglist_common_reparse REPARSE SCM_ARG
1616 $$ = check_scheme_arg (parser, @3,
1619 | function_arglist_common_reparse REPARSE lyric_element_music
1621 $$ = check_scheme_arg (parser, @3,
1624 | function_arglist_common_reparse REPARSE bare_number
1626 $$ = check_scheme_arg (parser, @3,
1629 | function_arglist_common_reparse REPARSE symbol_list_arg
1631 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1635 function_arglist_common_reparse:
1636 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1639 SCM res = try_string_variants ($1, $3);
1640 if (!SCM_UNBNDP (res))
1641 if (scm_is_pair (res))
1642 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1644 MYREPARSE (@3, $1, SCM_ARG, res);
1645 else if (scm_is_true
1647 ($1, make_music_from_simple (parser, @3, $3))))
1648 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1650 // This is going to flag a syntax error, we
1651 // know the predicate to be false.
1652 MYREPARSE (@3, $1, SCM_ARG, $3);
1654 | EXPECT_SCM function_arglist_optional STRING
1657 SCM res = try_string_variants ($1, $3);
1658 if (!SCM_UNBNDP (res))
1659 if (scm_is_pair (res))
1660 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1662 MYREPARSE (@3, $1, SCM_ARG, res);
1663 else if (scm_is_true
1665 ($1, make_music_from_simple (parser, @3, $3))))
1666 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1668 // This is going to flag a syntax error, we
1669 // know the predicate to be false.
1670 MYREPARSE (@3, $1, SCM_ARG, $3);
1672 | EXPECT_SCM function_arglist_optional full_markup
1675 if (scm_is_true (scm_call_1 ($1, $3)))
1676 MYREPARSE (@3, $1, SCM_ARG, $3);
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_closed_optional '-' UNSIGNED
1689 SCM n = scm_difference ($4, SCM_UNDEFINED);
1690 if (scm_is_true (scm_call_1 ($1, n)))
1691 MYREPARSE (@4, $1, REAL, n);
1693 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1694 t->set_property ("digit", $4);
1695 SCM m = t->unprotect ();
1696 if (scm_is_true (scm_call_1 ($1, m)))
1697 MYREPARSE (@4, $1, SCM_ARG, m);
1699 MYREPARSE (@4, $1, SCM_ARG, $4);
1703 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1706 SCM n = scm_difference ($4, SCM_UNDEFINED);
1707 MYREPARSE (@4, $1, REAL, n);
1711 function_arglist_closed:
1712 function_arglist_closed_common
1713 | function_arglist_closed_nonbackup
1716 function_arglist_closed_common:
1717 function_arglist_bare
1718 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1720 $$ = check_scheme_arg (parser, @3,
1723 | EXPECT_SCM function_arglist_closed_optional bare_number
1725 $$ = check_scheme_arg (parser, @3,
1728 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1730 $$ = check_scheme_arg (parser, @3,
1731 scm_difference ($4, SCM_UNDEFINED),
1734 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1736 $$ = check_scheme_arg (parser, @3,
1739 | EXPECT_SCM function_arglist_optional FRACTION
1741 $$ = check_scheme_arg (parser, @3,
1744 | function_arglist_common_reparse REPARSE SCM_ARG
1746 $$ = check_scheme_arg (parser, @3,
1749 | function_arglist_common_reparse REPARSE bare_number
1751 $$ = check_scheme_arg (parser, @3,
1754 | function_arglist_common_reparse REPARSE symbol_list_arg
1756 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1760 function_arglist_optional:
1761 function_arglist_keep %prec FUNCTION_ARGLIST
1762 | function_arglist_backup BACKUP
1763 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1765 $$ = scm_cons ($1, $3);
1767 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1769 $$ = scm_cons ($1, $3);
1773 function_arglist_closed_optional:
1774 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1775 | function_arglist_backup BACKUP
1776 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1778 $$ = scm_cons ($1, $3);
1780 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1782 $$ = scm_cons ($1, $3);
1786 embedded_scm_closed:
1788 | scm_function_call_closed
1791 embedded_scm_arg_closed:
1792 embedded_scm_bare_arg
1793 | scm_function_call_closed
1797 scm_function_call_closed:
1798 SCM_FUNCTION function_arglist_closed {
1799 $$ = MAKE_SYNTAX ("music-function", @$,
1801 } %prec FUNCTION_ARGLIST
1804 function_arglist_bare:
1805 EXPECT_NO_MORE_ARGS {
1808 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1809 $$ = scm_cons ($3, $2);
1811 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1812 $$ = scm_cons ($3, $2);
1814 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1815 $$ = scm_cons ($1, $3);
1817 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1818 $$ = scm_cons ($1, $3);
1820 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1821 $$ = scm_cons ($1, $3);
1825 music_function_call:
1826 MUSIC_FUNCTION function_arglist {
1827 $$ = MAKE_SYNTAX ("music-function", @$,
1834 /**/ { $$ = SCM_EOL; }
1835 | '=' simple_string {
1842 | repeated_music { $$ = $1; }
1843 | re_rhythmed_music { $$ = $1; }
1844 | complex_music_prefix music
1846 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1850 complex_music_prefix:
1851 CONTEXT simple_string optional_id optional_context_mod {
1852 Context_mod *ctxmod = unsmob_context_mod ($4);
1855 mods = ctxmod->get_mods ();
1856 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1858 | NEWCONTEXT simple_string optional_id optional_context_mod {
1859 Context_mod *ctxmod = unsmob_context_mod ($4);
1862 mods = ctxmod->get_mods ();
1863 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1868 mode_changing_head grouped_music_list {
1869 if ($1 == ly_symbol2scm ("chords"))
1871 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1877 parser->lexer_->pop_state ();
1879 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1880 Context_mod *ctxmod = unsmob_context_mod ($2);
1883 mods = ctxmod->get_mods ();
1884 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1885 if ($1 == ly_symbol2scm ("ChordNames"))
1887 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1889 parser->lexer_->pop_state ();
1895 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1896 parser->lexer_->push_note_state (nn);
1898 $$ = ly_symbol2scm ("notes");
1902 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1903 parser->lexer_->push_note_state (nn);
1905 $$ = ly_symbol2scm ("drums");
1908 parser->lexer_->push_figuredbass_state ();
1910 $$ = ly_symbol2scm ("figures");
1913 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1914 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1915 nn = parser->lexer_->lookup_identifier ("pitchnames");
1916 parser->lexer_->push_chord_state (nn);
1917 $$ = ly_symbol2scm ("chords");
1921 { parser->lexer_->push_lyric_state ();
1922 $$ = ly_symbol2scm ("lyrics");
1926 mode_changing_head_with_context:
1928 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1929 parser->lexer_->push_note_state (nn);
1931 $$ = ly_symbol2scm ("DrumStaff");
1934 parser->lexer_->push_figuredbass_state ();
1936 $$ = ly_symbol2scm ("FiguredBass");
1939 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1940 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1941 nn = parser->lexer_->lookup_identifier ("pitchnames");
1942 parser->lexer_->push_chord_state (nn);
1943 $$ = ly_symbol2scm ("ChordNames");
1946 { parser->lexer_->push_lyric_state ();
1947 $$ = ly_symbol2scm ("Lyrics");
1952 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1955 /* Can also use music at the expensive of two S/Rs similar to
1956 \repeat \alternative */
1957 parser->lexer_->pop_state ();
1959 $$ = scm_cons ($3, SCM_EOL);
1961 | new_lyrics ADDLYRICS {
1962 parser->lexer_->push_lyric_state ();
1964 parser->lexer_->pop_state ();
1965 $$ = scm_cons ($4, $1);
1970 composite_music new_lyrics {
1971 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1973 | LYRICSTO simple_string {
1974 parser->lexer_->push_lyric_state ();
1976 parser->lexer_->pop_state ();
1977 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1982 CHANGE STRING '=' STRING {
1983 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1990 $$ = scm_reverse_x ($1, SCM_EOL);
1992 | symbol_list_rev property_path {
1993 $$ = scm_reverse_x ($1, $2);
1999 $$ = scm_list_3 (ly_symbol2scm ("assign"),
2000 scm_string_to_symbol ($1), $3);
2002 | UNSET simple_string {
2003 $$ = scm_list_2 (ly_symbol2scm ("unset"),
2004 scm_string_to_symbol ($2));
2006 | OVERRIDE property_path '=' scalar {
2007 if (scm_ilength ($2) < 2) {
2008 parser->parser_error (@2, _("bad grob property path"));
2011 $$ = scm_cons (ly_symbol2scm ("push"),
2012 scm_cons2 (scm_car ($2),
2017 | REVERT revert_arg {
2018 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2022 // This is all quite awkward for the sake of substantial backward
2023 // compatibility while at the same time allowing a more "natural" form
2024 // of specification not separating grob specification from grob
2025 // property path. The purpose of this definition of revert_arg is to
2026 // allow the symbol list which specifies grob and property to revert
2027 // to be optionally be split into two parts after the grob (which in
2028 // this case is just the first element of the list). symbol_list_part
2029 // is only one path component, but it can be parsed without lookahead,
2030 // so we can follow it with a synthetic BACKUP token when needed. If
2031 // the first symbol_list_part already contains multiple elements (only
2032 // possible if a Scheme expression provides them), we just parse for
2033 // additional elements introduced by '.', which is what the
2034 // SYMBOL_LIST backup in connection with the immediately following
2035 // rule using symbol_list_arg does.
2037 // As long as we don't have our coffers filled with both grob and at
2038 // least one grob property specification, the rest of the required
2039 // symbol list chain may be provided either with or without a leading
2040 // dot. This is for both allowing the traditional
2041 // \revert Accidental #'color
2042 // as well as well as the "naive" form
2043 // \revert Accidental.color
2048 if (scm_is_null ($1)
2049 || scm_is_null (scm_cdr ($1)))
2050 MYBACKUP (SCM_ARG, $1, @1);
2052 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2054 | revert_arg BACKUP symbol_list_arg
2060 // revert_arg_part delivers results in reverse
2063 | revert_arg BACKUP SCM_ARG '.' symbol_list_part
2065 $$ = scm_append_x (scm_list_2 ($5, $3));
2067 | revert_arg BACKUP SCM_ARG symbol_list_part
2069 $$ = scm_append_x (scm_list_2 ($4, $3));
2074 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2075 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2077 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2078 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2079 | DENIES { $$ = ly_symbol2scm ("denies"); }
2081 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2082 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2083 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2084 | NAME { $$ = ly_symbol2scm ("context-name"); }
2088 property_operation { $$ = $1; }
2089 | context_def_mod STRING {
2090 $$ = scm_list_2 ($1, $2);
2092 | context_def_mod embedded_scm
2094 if (!scm_is_string ($2)
2095 && ly_symbol2scm ("consists") != $1
2096 && ly_symbol2scm ("remove") != $1)
2099 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2103 $$ = scm_list_2 ($1, $2);
2108 // If defined, at least two members.
2112 SCM l = scm_reverse_x ($1, SCM_EOL);
2115 (scm_object_property (scm_car (l),
2116 ly_symbol2scm ("is-grob?"))))
2117 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2118 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2119 parser->parser_error (@1, _ ("bad grob property path"));
2126 // If defined, at least three members
2130 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2132 parser->parser_error (@1, _ ("bad grob property path"));
2136 | grob_prop_spec property_path
2138 if (!SCM_UNBNDP ($1)) {
2139 $$ = scm_append_x (scm_list_2 ($1, $2));
2140 if (scm_is_null (scm_cddr ($$))) {
2141 parser->parser_error (@$, _ ("bad grob property path"));
2149 // Exactly two elements or undefined
2153 SCM l = scm_reverse_x ($1, SCM_EOL);
2154 switch (scm_ilength (l)) {
2156 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2160 parser->parser_error (@1, _ ("bad context property path"));
2167 simple_music_property_def:
2168 OVERRIDE grob_prop_path '=' scalar {
2169 if (SCM_UNBNDP ($2))
2172 $$ = scm_list_5 (scm_car ($2),
2173 ly_symbol2scm ("OverrideProperty"),
2179 | REVERT simple_revert_context revert_arg {
2180 $$ = scm_list_4 ($2,
2181 ly_symbol2scm ("RevertProperty"),
2185 | SET context_prop_spec '=' scalar {
2186 if (SCM_UNBNDP ($2))
2189 $$ = scm_list_4 (scm_car ($2),
2190 ly_symbol2scm ("PropertySet"),
2194 | UNSET context_prop_spec {
2195 if (SCM_UNBNDP ($2))
2198 $$ = scm_list_3 (scm_car ($2),
2199 ly_symbol2scm ("PropertyUnset"),
2205 // This is all quite awkward for the sake of substantial backward
2206 // compatibility while at the same time allowing a more "natural" form
2207 // of specification not separating grob specification from grob
2208 // property path. The purpose of this definition of
2209 // simple_revert_context is to allow the symbol list which specifies
2210 // grob and property to revert to be optionally be split into two
2211 // parts after the grob (which may be preceded by a context
2212 // specification, a case which we distinguish by checking whether the
2213 // first symbol is a valid grob symbol instead).
2215 // See revert_arg above for the main work horse of this arrangement.
2216 // simple_revert_context just caters for the context and delegates the
2217 // rest of the job to revert_arg.
2219 simple_revert_context:
2222 $1 = scm_reverse_x ($1, SCM_EOL);
2223 if (scm_is_null ($1)
2225 (scm_object_property (scm_car ($1),
2226 ly_symbol2scm ("is-grob?")))) {
2227 $$ = ly_symbol2scm ("Bottom");
2228 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2231 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2238 simple_music_property_def {
2239 if (SCM_UNBNDP ($1))
2240 $$ = MAKE_SYNTAX ("void-music", @1);
2242 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2251 | string '+' string {
2252 if (!scm_is_string ($1)) {
2253 parser->parser_error (@1, (_ ("simple string expected")));
2254 $1 = scm_string (SCM_EOL);
2256 if (!scm_is_string ($3)) {
2257 parser->parser_error (@3, (_ ("simple string expected")));
2258 $3 = scm_string (SCM_EOL);
2260 $$ = scm_string_append (scm_list_2 ($1, $3));
2264 simple_string: STRING {
2269 if (scm_is_string ($1)) {
2272 parser->parser_error (@1, (_ ("simple string expected")));
2273 $$ = scm_string (SCM_EOL);
2287 embedded_scm_arg_closed
2296 simple_element post_events {
2297 // Let the rhythmic music iterator sort this mess out.
2298 if (scm_is_pair ($2)) {
2299 $$ = make_music_from_simple (parser, @1, $1);
2300 if (unsmob_music ($$))
2301 unsmob_music ($$)->set_property ("articulations",
2302 scm_reverse_x ($2, SCM_EOL));
2304 parser->parser_error (@1, _("music expected"));
2307 | simple_chord_elements post_events {
2308 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2311 /* why is this giving wrong start location? -ns
2313 i.set_location (@1, @2);
2314 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2316 | CHORD_REPETITION optional_notemode_duration post_events {
2318 i.set_location (@1, @3);
2319 $$ = MAKE_SYNTAX ("repetition-chord", i,
2320 $2, scm_reverse_x ($3, SCM_EOL));
2322 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2324 i.set_location (@1, @3);
2325 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2326 scm_reverse_x ($3, SCM_EOL));
2329 | note_chord_element
2334 chord_body optional_notemode_duration post_events
2336 Music *m = unsmob_music ($1);
2337 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2338 SCM es = m->get_property ("elements");
2339 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2341 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2342 unsmob_music (scm_car (s))->set_property ("duration", dur);
2343 es = ly_append2 (es, postevs);
2345 m-> set_property ("elements", es);
2347 $$ = m->self_scm ();
2352 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2354 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2358 chord_body_elements:
2359 /* empty */ { $$ = SCM_EOL; }
2360 | chord_body_elements chord_body_element {
2361 if (!SCM_UNBNDP ($2))
2362 $$ = scm_cons ($2, $1);
2367 pitch exclamations questions octave_check post_events
2369 bool q = to_boolean ($3);
2370 bool ex = to_boolean ($2);
2374 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2375 n->set_property ("pitch", $1);
2377 n->set_property ("cautionary", SCM_BOOL_T);
2379 n->set_property ("force-accidental", SCM_BOOL_T);
2381 if (scm_is_pair (post)) {
2382 SCM arts = scm_reverse_x (post, SCM_EOL);
2383 n->set_property ("articulations", arts);
2385 if (scm_is_number (check))
2387 int q = scm_to_int (check);
2388 n->set_property ("absolute-octave", scm_from_int (q-1));
2391 $$ = n->unprotect ();
2393 | DRUM_PITCH post_events {
2394 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2395 n->set_property ("drum-type", $1);
2397 if (scm_is_pair ($2)) {
2398 SCM arts = scm_reverse_x ($2, SCM_EOL);
2399 n->set_property ("articulations", arts);
2401 $$ = n->unprotect ();
2403 | music_function_chord_body
2405 Music *m = unsmob_music ($1);
2407 while (m && m->is_mus_type ("music-wrapper-music")) {
2408 $$ = m->get_property ("element");
2409 m = unsmob_music ($$);
2412 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2413 parser->parser_error (@$, _ ("not a rhythmic event"));
2419 music_function_chord_body:
2424 // Event functions may only take closed arglists, otherwise it would
2425 // not be clear whether a following postevent should be associated
2426 // with the last argument of the event function or with the expression
2427 // for which the function call acts itself as event.
2429 music_function_call_closed:
2430 MUSIC_FUNCTION function_arglist_closed {
2431 $$ = MAKE_SYNTAX ("music-function", @$,
2436 event_function_event:
2437 EVENT_FUNCTION function_arglist_closed {
2438 $$ = MAKE_SYNTAX ("music-function", @$,
2448 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2449 m->set_property ("span-direction", scm_from_int (START));
2450 $$ = m->unprotect();
2453 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2454 m->set_property ("span-direction", scm_from_int (STOP));
2455 $$ = m->unprotect ();
2458 $$ = MAKE_SYNTAX ("voice-separator", @$);
2461 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2463 Music *m = unsmob_music (pipe);
2468 $$ = m->unprotect ();
2471 $$ = MAKE_SYNTAX ("bar-check", @$);
2478 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2490 | post_events post_event {
2491 unsmob_music ($2)->set_spot (@2);
2492 $$ = scm_cons ($2, $$);
2496 post_event_nofinger:
2497 direction_less_event {
2500 | script_dir music_function_call_closed {
2502 if (!SCM_UNBNDP ($1))
2504 unsmob_music ($$)->set_property ("direction", $1);
2508 if (!parser->lexer_->is_lyric_state ())
2509 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2510 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2513 if (!parser->lexer_->is_lyric_state ())
2514 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2515 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2517 | script_dir direction_reqd_event {
2518 if (!SCM_UNBNDP ($1))
2520 Music *m = unsmob_music ($2);
2521 m->set_property ("direction", $1);
2525 | script_dir direction_less_event {
2526 if (!SCM_UNBNDP ($1))
2528 Music *m = unsmob_music ($2);
2529 m->set_property ("direction", $1);
2536 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2541 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2552 string_number_event:
2554 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2555 s->set_property ("string-number", $1);
2556 $$ = s->unprotect ();
2560 direction_less_char:
2562 $$ = ly_symbol2scm ("bracketOpenSymbol");
2565 $$ = ly_symbol2scm ("bracketCloseSymbol");
2568 $$ = ly_symbol2scm ("tildeSymbol");
2571 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2574 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2577 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2580 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2583 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2586 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2589 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2593 direction_less_event:
2594 direction_less_char {
2595 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2597 if (unsmob_music (predefd))
2599 m = unsmob_music (predefd)->clone ();
2604 m = MY_MAKE_MUSIC ("Music", @$);
2606 $$ = m->unprotect ();
2608 | string_number_event
2609 | EVENT_IDENTIFIER {
2613 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2614 a->set_property ("tremolo-type", $1);
2615 $$ = a->unprotect ();
2617 | event_function_event
2620 direction_reqd_event:
2624 | script_abbreviation {
2625 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2626 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2627 if (scm_is_string (s))
2628 a->set_property ("articulation-type", s);
2629 else parser->parser_error (@1, _ ("expecting string as script definition"));
2630 $$ = a->unprotect ();
2635 /**/ { $$ = SCM_EOL; }
2636 | '=' quotes { $$ = $2; }
2650 $$ = scm_from_int (1);
2653 $$ = scm_oneplus ($1);
2659 $$ = scm_from_int (-1);
2662 $$ = scm_oneminus ($1);
2667 NOTENAME_PITCH quotes {
2668 if (!scm_is_eq (SCM_INUM0, $2))
2670 Pitch p = *unsmob_pitch ($1);
2671 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2672 $$ = p.smobbed_copy ();
2682 TONICNAME_PITCH quotes {
2683 if (!scm_is_eq (SCM_INUM0, $2))
2685 Pitch p = *unsmob_pitch ($1);
2686 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2687 $$ = p.smobbed_copy ();
2697 pitch_also_in_chords:
2704 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2705 t->set_property ("text", $1);
2706 $$ = t->unprotect ();
2709 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2710 t->set_property ("text",
2711 make_simple_markup ($1));
2712 $$ = t->unprotect ();
2714 | embedded_scm_closed
2716 Music *m = unsmob_music ($1);
2717 if (m && m->is_mus_type ("post-event"))
2719 else if (Text_interface::is_markup ($1)) {
2720 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2721 t->set_property ("text", $1);
2722 $$ = t->unprotect ();
2724 parser->parser_error (@1, _ ("not an articulation"));
2730 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2731 t->set_property ("digit", $1);
2732 $$ = t->unprotect ();
2736 script_abbreviation:
2738 $$ = scm_from_locale_string ("Hat");
2741 $$ = scm_from_locale_string ("Plus");
2744 $$ = scm_from_locale_string ("Dash");
2747 $$ = scm_from_locale_string ("Bar");
2750 $$ = scm_from_locale_string ("Larger");
2753 $$ = scm_from_locale_string ("Dot");
2756 $$ = scm_from_locale_string ("Underscore");
2761 '_' { $$ = scm_from_int (DOWN); }
2762 | '^' { $$ = scm_from_int (UP); }
2763 | '-' { $$ = SCM_UNDEFINED; }
2767 multiplied_duration {
2772 maybe_notemode_duration:
2776 | multiplied_duration {
2778 parser->default_duration_ = *unsmob_duration ($$);
2783 optional_notemode_duration:
2784 maybe_notemode_duration
2786 if (SCM_UNBNDP ($$))
2787 $$ = parser->default_duration_.smobbed_copy ();
2794 int n = scm_to_int ($1);
2795 if (!is_duration (n))
2796 parser->parser_error (@1, _f ("not a duration: %d", n));
2800 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2802 | DURATION_IDENTIFIER dots {
2803 Duration *d = unsmob_duration ($1);
2804 Duration k (d->duration_log (),
2805 d->dot_count () + scm_to_int ($2));
2806 k = k.compressed (d->factor ());
2807 scm_remember_upto_here_1 ($1);
2808 $$ = k.smobbed_copy ();
2812 multiplied_duration:
2816 | multiplied_duration '*' UNSIGNED {
2817 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2819 | multiplied_duration '*' FRACTION {
2820 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2822 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2831 $$ = scm_oneplus ($1);
2840 int n = scm_to_int ($2);
2841 if (!is_duration (n))
2842 parser->parser_error (@2, _f ("not a duration: %d", n));
2848 UNSIGNED { $$ = $1; }
2849 | STRING { $$ = $1; }
2850 | full_markup { $$ = $1; }
2853 // as an integer, it needs to be non-negative, and otherwise
2854 // it needs to be suitable as a markup.
2855 if (scm_is_integer ($1)
2856 ? scm_is_true (scm_negative_p ($1))
2857 : !Text_interface::is_markup ($1))
2859 parser->parser_error (@1, _ ("bass number expected"));
2865 figured_bass_alteration:
2866 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2867 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2868 | '!' { $$ = scm_from_int (0); }
2873 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2874 $$ = bfr->unprotect ();
2877 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2878 $$ = bfr->self_scm ();
2880 if (scm_is_number ($1))
2881 bfr->set_property ("figure", $1);
2882 else if (Text_interface::is_markup ($1))
2883 bfr->set_property ("text", $1);
2889 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2891 | bass_figure figured_bass_alteration {
2892 Music *m = unsmob_music ($1);
2893 if (scm_to_double ($2)) {
2894 SCM salter = m->get_property ("alteration");
2895 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2896 m->set_property ("alteration",
2897 scm_sum (alter, $2));
2899 m->set_property ("alteration", scm_from_int (0));
2902 | bass_figure figured_bass_modification {
2903 Music *m = unsmob_music ($1);
2904 if ($2 == ly_symbol2scm ("plus"))
2906 m->set_property ("augmented", SCM_BOOL_T);
2908 else if ($2 == ly_symbol2scm ("slash"))
2910 m->set_property ("diminished", SCM_BOOL_T);
2912 else if ($2 == ly_symbol2scm ("exclamation"))
2914 m->set_property ("no-continuation", SCM_BOOL_T);
2916 else if ($2 == ly_symbol2scm ("backslash"))
2918 m->set_property ("augmented-slash", SCM_BOOL_T);
2924 figured_bass_modification:
2926 $$ = ly_symbol2scm ("plus");
2929 $$ = ly_symbol2scm ("exclamation");
2932 $$ = ly_symbol2scm ("slash");
2935 $$ = ly_symbol2scm ("backslash");
2945 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2953 | figure_list br_bass_figure {
2954 $$ = scm_cons ($2, $1);
2959 FIGURE_OPEN figure_list FIGURE_CLOSE {
2960 $$ = scm_reverse_x ($2, SCM_EOL);
2966 /**/ { $$ = SCM_BOOL_F; }
2967 | REST { $$ = SCM_BOOL_T; }
2971 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2972 if (!parser->lexer_->is_note_state ())
2973 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2974 if (!SCM_UNBNDP ($2)
2976 || scm_is_number ($4)
2978 || scm_is_true ($6))
2981 if (scm_is_true ($6))
2982 n = MY_MAKE_MUSIC ("RestEvent", @$);
2984 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2986 n->set_property ("pitch", $1);
2987 if (SCM_UNBNDP ($5))
2988 n->set_property ("duration",
2989 parser->default_duration_.smobbed_copy ());
2991 n->set_property ("duration", $5);
2993 if (scm_is_number ($4))
2995 int q = scm_to_int ($4);
2996 n->set_property ("absolute-octave", scm_from_int (q-1));
2999 if (to_boolean ($3))
3000 n->set_property ("cautionary", SCM_BOOL_T);
3001 if (to_boolean ($2) || to_boolean ($3))
3002 n->set_property ("force-accidental", SCM_BOOL_T);
3004 $$ = n->unprotect ();
3007 | DRUM_PITCH optional_notemode_duration {
3008 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3009 n->set_property ("duration", $2);
3010 n->set_property ("drum-type", $1);
3012 $$ = n->unprotect ();
3014 | RESTNAME optional_notemode_duration {
3016 if (ly_scm2string ($1) == "s") {
3018 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3021 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3024 ev->set_property ("duration", $2);
3025 $$ = ev->unprotect ();
3029 simple_chord_elements:
3031 if (!parser->lexer_->is_chord_state ())
3032 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3035 | figure_spec optional_notemode_duration {
3036 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3038 unsmob_music (scm_car (s))->set_property ("duration", $2);
3054 lyric_element_music:
3055 lyric_element optional_notemode_duration post_events {
3056 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3057 if (scm_is_pair ($3))
3058 unsmob_music ($$)->set_property
3059 ("articulations", scm_reverse_x ($3, SCM_EOL));
3064 steno_tonic_pitch optional_notemode_duration {
3065 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3067 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3068 SCM its = scm_reverse_x ($4, SCM_EOL);
3069 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3077 | chord_items chord_item {
3078 $$ = scm_cons ($2, $$);
3084 $$ = ly_symbol2scm ("chord-colon");
3087 $$ = ly_symbol2scm ("chord-caret");
3089 | CHORD_SLASH steno_tonic_pitch {
3090 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3092 | CHORD_BASS steno_tonic_pitch {
3093 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3102 $$ = scm_reverse_x ($1, SCM_EOL);
3110 step_number { $$ = scm_cons ($1, SCM_EOL); }
3111 | step_numbers '.' step_number {
3112 $$ = scm_cons ($3, $$);
3118 $$ = make_chord_step ($1, 0);
3121 $$ = make_chord_step ($1, SHARP_ALTERATION);
3123 | UNSIGNED CHORD_MINUS {
3124 $$ = make_chord_step ($1, FLAT_ALTERATION);
3132 | UNSIGNED '~' UNSIGNED {
3133 $$ = scm_cons ($1, $3);
3140 TODO: should deprecate in favor of Scheme?
3144 number_expression '+' number_term {
3145 $$ = scm_sum ($1, $3);
3147 | number_expression '-' number_term {
3148 $$ = scm_difference ($1, $3);
3157 | number_factor '*' number_factor {
3158 $$ = scm_product ($1, $3);
3160 | number_factor '/' number_factor {
3161 $$ = scm_divide ($1, $3);
3166 '-' number_factor { /* %prec UNARY_MINUS */
3167 $$ = scm_difference ($2, SCM_UNDEFINED);
3175 | UNSIGNED NUMBER_IDENTIFIER {
3176 $$ = scm_product ($1, $2);
3178 | REAL NUMBER_IDENTIFIER {
3179 $$ = scm_product ($1, $2);
3195 { $$ = SCM_UNDEFINED; }
3198 if (SCM_UNBNDP ($1))
3206 { $$ = SCM_UNDEFINED; }
3209 if (SCM_UNBNDP ($1))
3218 { parser->lexer_->push_markup_state (); }
3221 parser->lexer_->pop_state ();
3227 { parser->lexer_->push_markup_state (); }
3230 parser->lexer_->pop_state ();
3236 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3238 | markup_head_1_list simple_markup {
3239 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3249 if (Text_interface::is_markup ($1))
3250 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3251 else if (Text_interface::is_markup_list ($1))
3252 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3254 parser->parser_error (@1, _ ("not a markup"));
3255 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3262 markup_composed_list {
3265 | markup_braced_list {
3268 | markup_command_list {
3269 $$ = scm_list_1 ($1);
3271 | markup_scm MARKUPLIST_IDENTIFIER
3277 markup_composed_list:
3278 markup_head_1_list markup_braced_list {
3279 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3285 '{' markup_braced_list_body '}' {
3286 $$ = scm_reverse_x ($2, SCM_EOL);
3290 markup_braced_list_body:
3291 /* empty */ { $$ = SCM_EOL; }
3292 | markup_braced_list_body markup {
3293 $$ = scm_cons ($2, $1);
3295 | markup_braced_list_body markup_list {
3296 $$ = scm_reverse_x ($2, $1);
3300 markup_command_list:
3301 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3302 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3306 markup_command_basic_arguments:
3307 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3308 $$ = scm_cons ($3, $2);
3310 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3311 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3313 | EXPECT_NO_MORE_ARGS {
3318 markup_command_list_arguments:
3319 markup_command_basic_arguments { $$ = $1; }
3320 | EXPECT_MARKUP markup_command_list_arguments markup {
3321 $$ = scm_cons ($3, $2);
3326 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3327 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3332 markup_head_1_item {
3333 $$ = scm_list_1 ($1);
3335 | markup_head_1_list markup_head_1_item {
3336 $$ = scm_cons ($2, $1);
3342 $$ = make_simple_markup ($1);
3345 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3346 parser->lexer_->push_note_state (nn);
3347 } '{' score_body '}' {
3348 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3349 parser->lexer_->pop_state ();
3351 | MARKUP_FUNCTION markup_command_basic_arguments {
3352 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3354 | markup_scm MARKUP_IDENTIFIER
3361 markup_head_1_list simple_markup {
3362 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3363 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3373 Lily_parser::set_yydebug (bool x)
3379 Lily_parser::do_yyparse ()
3381 SCM retval = SCM_UNDEFINED;
3382 yyparse (this, &retval);
3392 It is a little strange to have this function in this file, but
3393 otherwise, we have to import music classes into the lexer.
3397 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3399 if (unsmob_book (sid)) {
3400 Book *book = unsmob_book (sid)->clone ();
3401 *destination = book->self_scm ();
3404 return BOOK_IDENTIFIER;
3405 } else if (scm_is_number (sid)) {
3407 return NUMBER_IDENTIFIER;
3408 } else if (unsmob_context_def (sid)) {
3409 Context_def *def= unsmob_context_def (sid)->clone ();
3411 *destination = def->self_scm ();
3414 return CONTEXT_DEF_IDENTIFIER;
3415 } else if (unsmob_context_mod (sid)) {
3416 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3418 return CONTEXT_MOD_IDENTIFIER;
3419 } else if (Music *mus = unsmob_music (sid)) {
3420 mus = mus->clone ();
3421 *destination = mus->self_scm ();
3422 unsmob_music (*destination)->
3423 set_property ("origin", make_input (last_input_));
3425 bool is_event = mus->is_mus_type ("post-event");
3427 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3428 } else if (unsmob_pitch (sid)) {
3429 *destination = unsmob_pitch (sid)->smobbed_copy ();
3430 return PITCH_IDENTIFIER;
3431 } else if (unsmob_duration (sid)) {
3432 *destination = unsmob_duration (sid)->smobbed_copy ();
3433 return DURATION_IDENTIFIER;
3434 } else if (unsmob_output_def (sid)) {
3435 Output_def *p = unsmob_output_def (sid);
3438 *destination = p->self_scm ();
3440 return OUTPUT_DEF_IDENTIFIER;
3447 get_next_unique_context_id ()
3449 return scm_from_locale_string ("$uniqueContextId");
3454 get_next_unique_lyrics_context_id ()
3456 static int new_context_count;
3458 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3459 return scm_from_locale_string (s);
3462 // check_scheme_arg checks one argument with a given predicate for use
3463 // in an argument list and throws a syntax error if it is unusable.
3464 // The argument is prepended to the argument list in any case. After
3465 // throwing a syntax error, the argument list is terminated with #f as
3466 // its last cdr in order to mark it as uncallable while not losing
3467 // track of its total length.
3469 // There are a few special considerations: if optional argument disp
3470 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3471 // instead of arg in a prospective error message. This is useful if
3472 // arg is not the actual argument but rather a transformation of it.
3474 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3475 // and an error message using disp is produced unconditionally.
3477 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3478 SCM arg, SCM args, SCM pred, SCM disp)
3480 if (SCM_UNBNDP (arg))
3481 args = scm_cons (disp, args);
3483 args = scm_cons (arg, args);
3484 if (scm_is_true (scm_call_1 (pred, arg)))
3487 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3488 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3489 SCM_UNBNDP (disp) ? arg : disp);
3490 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3494 SCM loc_on_music (Input loc, SCM arg)
3496 if (Music *m = unsmob_music (arg))
3500 return m->unprotect ();
3506 try_string_variants (SCM pred, SCM str)
3508 // a matching predicate is always ok
3509 if (scm_is_true (scm_call_1 (pred, str)))
3511 // a symbol may be interpreted as a list of symbols if it helps
3512 if (scm_is_symbol (str)) {
3513 str = scm_list_1 (str);
3514 if (scm_is_true (scm_call_1 (pred, str)))
3516 return SCM_UNDEFINED;
3519 // If this cannot be a string representation of a symbol list,
3522 if (!is_regular_identifier (str, true))
3523 return SCM_UNDEFINED;
3525 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3526 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3527 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3529 // Let's attempt the symbol list interpretation first.
3531 if (scm_is_true (scm_call_1 (pred, str)))
3534 // If there is just one symbol in the list, we might interpret
3535 // it as a single symbol
3537 if (scm_is_null (scm_cdr (str)))
3539 str = scm_car (str);
3540 if (scm_is_true (scm_call_1 (pred, str)))
3544 return SCM_UNDEFINED;
3548 is_regular_identifier (SCM id, bool multiple)
3550 if (!scm_is_string (id))
3553 string str = ly_scm2string (id);
3555 bool middle = false;
3557 for (string::iterator it=str.begin(); it != str.end (); it++)
3560 if ((c >= 'a' && c <= 'z')
3561 || (c >= 'A' && c <= 'Z')
3564 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3573 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3575 if (unsmob_music (simple))
3577 if (parser->lexer_->is_note_state ()) {
3578 if (scm_is_symbol (simple)) {
3579 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3580 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3581 n->set_property ("drum-type", simple);
3582 return n->unprotect ();
3584 if (unsmob_pitch (simple)) {
3585 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3586 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3587 n->set_property ("pitch", simple);
3588 return n->unprotect ();
3591 } else if (parser->lexer_->is_lyric_state ()) {
3592 if (Text_interface::is_markup (simple))
3593 return MAKE_SYNTAX ("lyric-event", loc, simple,
3594 parser->default_duration_.smobbed_copy ());
3595 } else if (parser->lexer_->is_chord_state ()) {
3596 if (unsmob_pitch (simple))
3597 return make_chord_elements (loc, simple,
3598 parser->default_duration_.smobbed_copy (),
3605 make_music_with_input (SCM name, Input where)
3607 Music *m = make_music_by_name (name);
3608 m->set_spot (where);
3613 make_simple_markup (SCM a)
3621 return t && t == 1 << intlog2 (t);
3625 make_chord_step (SCM step_scm, Rational alter)
3627 int step = scm_to_int (step_scm);
3630 alter += FLAT_ALTERATION;
3634 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3635 return m.smobbed_copy ();
3640 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3642 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3643 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3644 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3646 unsmob_music (scm_car (s))->set_spot (loc);
3652 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3654 Lily_lexer *lex = parser->lexer_;
3658 lex->prepare_for_next_token ();
3659 return lex->yylex ();