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
1022 if (unsmob_music ($1)
1023 || scm_is_eq ($1, SCM_UNSPECIFIED))
1027 @$.warning (_ ("Ignoring non-music expression"));
1028 $$ = SCM_UNSPECIFIED;
1036 $$ = make_music_from_simple (parser, @1, $1);
1037 if (!unsmob_music ($$))
1038 parser->parser_error (@1, _ ("music expected"));
1040 | composite_music %prec COMPOSITE
1045 | composite_music %prec COMPOSITE
1049 REPEAT simple_string unsigned_number music
1051 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1053 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1055 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1060 SEQUENTIAL braced_music_list {
1061 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1063 | braced_music_list {
1064 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1069 SIMULTANEOUS braced_music_list {
1070 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1072 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1073 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1079 | music_property_def
1083 context_modification:
1084 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1086 parser->lexer_->pop_state ();
1089 | WITH CONTEXT_MOD_IDENTIFIER
1093 | CONTEXT_MOD_IDENTIFIER
1097 | WITH embedded_scm_closed
1099 if (unsmob_context_mod ($2))
1102 parser->parser_error (@2, _ ("not a context mod"));
1103 $$ = Context_mod ().smobbed_copy ();
1108 optional_context_mod:
1112 | context_modification
1120 $$ = Context_mod ().smobbed_copy ();
1122 | context_mod_list context_mod {
1123 if (!SCM_UNBNDP ($2))
1124 unsmob_context_mod ($1)->add_context_mod ($2);
1126 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1127 Context_mod *md = unsmob_context_mod ($2);
1129 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1131 | context_mod_list context_mod_embedded {
1132 unsmob_context_mod ($1)->add_context_mods
1133 (unsmob_context_mod ($2)->get_mods ());
1142 /* Music that can be parsed without lookahead */
1145 | complex_music_prefix closed_music
1147 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1149 | music_function_call_closed
1155 | grouped_music_list
1159 simultaneous_music { $$ = $1; }
1160 | sequential_music { $$ = $1; }
1163 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1164 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1165 and this rule returns the reversed list of arguments. */
1167 /* Function argument lists come in a number of flavors. Whenever
1168 * LilyPond has to pick between different flavors, the decision is
1169 * either made because of tokens it has already seen, or it is
1170 * postponed until tokens suitable for making the decision come up.
1171 * For postponing decisions, it may be necessary that the competing
1172 * rules are written in a way making them compatible until a decision
1173 * can be made. Sometimes this is done by putting common traits into
1174 * a separate "common" rule set.
1176 * function_arglist: a full argument list. Optional arguments at the
1177 * end of the list can only be skipped by writing \default in their
1180 * function_arglist_backup: an argument list ending in an optional
1181 * argument that may be skipped depending on its predicate.
1183 * function_arglist_skip: an argument list _not_ ending in an optional
1184 * argument that is actually taken.
1186 * function_arglist_nonbackup: an argument list ending in an optional
1187 * argument that may not be skipped because it is in end position and
1188 * has not been shortcircuited with \default.
1190 * function_arglist* / function_arglist_closed*: The closed variants
1191 * don't end in simple music expressions that might still accept
1192 * things like a duration or a postevent.
1195 function_arglist_skip:
1196 function_arglist_common
1197 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1199 $$ = scm_cons ($1, $3);
1200 } %prec FUNCTION_ARGLIST
1201 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1203 $$ = scm_cons ($1, $3);
1204 } %prec FUNCTION_ARGLIST
1205 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1207 $$ = scm_cons ($1, $3);
1208 } %prec FUNCTION_ARGLIST
1212 function_arglist_nonbackup_common:
1213 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1214 $$ = scm_cons ($4, $3);
1216 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1217 $$ = scm_cons ($4, $3);
1219 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1221 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1223 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1225 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1227 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1229 SCM n = scm_difference ($5, SCM_UNDEFINED);
1230 if (scm_is_true (scm_call_1 ($2, n)))
1231 $$ = scm_cons (n, $3);
1233 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1234 t->set_property ("digit", $5);
1235 $$ = check_scheme_arg (parser, @4, t->unprotect (),
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 $$ = check_scheme_arg (parser, @4,
1267 try_string_variants ($2, $4),
1270 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1272 $$ = check_scheme_arg (parser, @4,
1273 try_string_variants ($2, $4),
1276 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1278 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1284 | SYMBOL_LIST '.' symbol_list_rev
1286 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1292 | symbol_list_rev '.' symbol_list_part
1294 $$ = scm_append_x (scm_list_2 ($3, $1));
1298 // symbol_list_part delivers elements in reverse copy.
1303 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1304 $$ = try_string_variants (sym_l_p, $1);
1305 if (SCM_UNBNDP ($$)) {
1306 parser->parser_error (@1, _("not a symbol"));
1309 $$ = scm_reverse ($$);
1314 symbol_list_element:
1320 function_arglist_nonbackup:
1321 function_arglist_nonbackup_common
1322 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1324 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1326 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1328 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1330 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1332 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1334 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1336 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1338 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1340 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1344 function_arglist_nonbackup_reparse:
1345 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1348 SCM res = try_string_variants ($2, $4);
1349 if (!SCM_UNBNDP (res))
1350 if (scm_is_pair (res))
1351 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1353 MYREPARSE (@4, $2, SCM_ARG, res);
1354 else if (scm_is_true
1356 ($2, make_music_from_simple
1358 MYREPARSE (@4, $2, STRING, $4);
1360 MYREPARSE (@4, $2, SCM_ARG, $4);
1362 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1365 SCM res = try_string_variants ($2, $4);
1366 if (!SCM_UNBNDP (res))
1367 if (scm_is_pair (res))
1368 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1370 MYREPARSE (@4, $2, SCM_ARG, res);
1371 else if (scm_is_true
1373 ($2, make_music_from_simple
1375 MYREPARSE (@4, $2, STRING, $4);
1377 MYREPARSE (@4, $2, SCM_ARG, $4);
1379 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1382 if (scm_is_true (scm_call_1 ($2, $4)))
1383 MYREPARSE (@4, $2, SCM_ARG, $4);
1384 else if (scm_is_true
1386 ($2, make_music_from_simple
1388 MYREPARSE (@4, $2, STRING, $4);
1390 MYREPARSE (@4, $2, SCM_ARG, $4);
1394 function_arglist_keep:
1395 function_arglist_common
1396 | function_arglist_backup
1399 function_arglist_closed_keep:
1400 function_arglist_closed_common
1401 | function_arglist_backup
1404 function_arglist_backup:
1405 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1407 if (scm_is_true (scm_call_1 ($2, $4)))
1409 $$ = scm_cons ($4, $3);
1411 $$ = scm_cons (loc_on_music (@3, $1), $3);
1412 MYBACKUP (SCM_ARG, $4, @4);
1415 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1417 if (scm_is_true (scm_call_1 ($2, $4)))
1419 $$ = scm_cons ($4, $3);
1421 $$ = scm_cons (loc_on_music (@3, $1), $3);
1422 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1425 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep full_markup
1427 if (scm_is_true (scm_call_1 ($2, $4)))
1428 $$ = scm_cons ($4, $3);
1430 $$ = scm_cons (loc_on_music (@3, $1), $3);
1431 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1434 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1436 if (scm_is_true (scm_call_1 ($2, $4)))
1439 MYREPARSE (@4, $2, UNSIGNED, $4);
1441 $$ = scm_cons (loc_on_music (@3, $1), $3);
1442 MYBACKUP (UNSIGNED, $4, @4);
1445 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1447 if (scm_is_true (scm_call_1 ($2, $4)))
1450 MYREPARSE (@4, $2, REAL, $4);
1452 $$ = scm_cons (loc_on_music (@3, $1), $3);
1453 MYBACKUP (REAL, $4, @4);
1456 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1458 if (scm_is_true (scm_call_1 ($2, $4)))
1460 $$ = scm_cons ($4, $3);
1462 $$ = scm_cons (loc_on_music (@3, $1), $3);
1463 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1466 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1468 if (scm_is_true (scm_call_1 ($2, $4)))
1470 $$ = scm_cons ($4, $3);
1472 $$ = scm_cons (loc_on_music (@3, $1), $3);
1473 MYBACKUP (FRACTION, $4, @4);
1476 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1478 SCM n = scm_difference ($5, SCM_UNDEFINED);
1479 if (scm_is_true (scm_call_1 ($2, n))) {
1481 MYREPARSE (@5, $2, REAL, n);
1483 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1484 t->set_property ("digit", $5);
1485 $$ = t->unprotect ();
1486 if (scm_is_true (scm_call_1 ($2, $$)))
1487 $$ = scm_cons ($$, $3);
1489 $$ = scm_cons (loc_on_music (@3, $1), $3);
1490 MYBACKUP (UNSIGNED, $5, @5);
1491 parser->lexer_->push_extra_token ('-');
1496 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1498 SCM n = scm_difference ($5, SCM_UNDEFINED);
1499 if (scm_is_true (scm_call_1 ($2, n))) {
1500 MYREPARSE (@5, $2, REAL, n);
1503 $$ = scm_cons (loc_on_music (@3, $1), $3);
1504 MYBACKUP (REAL, n, @5);
1507 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1509 SCM n = scm_difference ($5, SCM_UNDEFINED);
1510 if (scm_is_true (scm_call_1 ($2, n))) {
1511 $$ = scm_cons (n, $3);
1513 $$ = scm_cons (loc_on_music (@3, $1), $3);
1514 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1517 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1519 $$ = scm_cons ($4, $3);
1521 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1523 $$ = scm_cons ($4, $3);
1525 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1527 SCM res = try_string_variants ($2, $4);
1528 if (!SCM_UNBNDP (res))
1529 if (scm_is_pair (res)) {
1531 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1534 $$ = scm_cons (res, $3);
1536 $$ = scm_cons (loc_on_music (@3, $1), $3);
1537 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1540 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1542 SCM res = try_string_variants ($2, $4);
1543 if (!SCM_UNBNDP (res))
1544 if (scm_is_pair (res)) {
1546 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1549 $$ = scm_cons (res, $3);
1551 $$ = scm_cons (loc_on_music (@3, $1), $3);
1552 MYBACKUP (STRING, $4, @4);
1555 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1557 $$ = scm_cons ($1, $3);
1558 MYBACKUP(0, SCM_UNDEFINED, @3);
1560 | function_arglist_backup REPARSE bare_number
1562 $$ = check_scheme_arg (parser, @3,
1565 | function_arglist_backup REPARSE symbol_list_arg
1567 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1572 function_arglist_common
1573 | function_arglist_nonbackup
1576 function_arglist_common:
1577 function_arglist_bare
1578 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1580 $$ = check_scheme_arg (parser, @3,
1583 | EXPECT_SCM function_arglist_closed_optional bare_number
1585 $$ = check_scheme_arg (parser, @3,
1588 | EXPECT_SCM function_arglist_optional FRACTION
1590 $$ = check_scheme_arg (parser, @3,
1593 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1595 $$ = check_scheme_arg (parser, @3,
1598 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1600 SCM n = scm_difference ($4, SCM_UNDEFINED);
1601 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1603 | function_arglist_common_reparse REPARSE SCM_ARG
1605 $$ = check_scheme_arg (parser, @3,
1608 | function_arglist_common_reparse REPARSE lyric_element_music
1610 $$ = check_scheme_arg (parser, @3,
1613 | function_arglist_common_reparse REPARSE bare_number
1615 $$ = check_scheme_arg (parser, @3,
1618 | function_arglist_common_reparse REPARSE symbol_list_arg
1620 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1624 function_arglist_common_reparse:
1625 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1628 SCM res = try_string_variants ($1, $3);
1629 if (!SCM_UNBNDP (res))
1630 if (scm_is_pair (res))
1631 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1633 MYREPARSE (@3, $1, SCM_ARG, res);
1634 else if (scm_is_true
1636 ($1, make_music_from_simple (parser, @3, $3))))
1637 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1639 // This is going to flag a syntax error, we
1640 // know the predicate to be false.
1641 MYREPARSE (@3, $1, SCM_ARG, $3);
1643 | EXPECT_SCM function_arglist_optional STRING
1646 SCM res = try_string_variants ($1, $3);
1647 if (!SCM_UNBNDP (res))
1648 if (scm_is_pair (res))
1649 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1651 MYREPARSE (@3, $1, SCM_ARG, res);
1652 else if (scm_is_true
1654 ($1, make_music_from_simple (parser, @3, $3))))
1655 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1657 // This is going to flag a syntax error, we
1658 // know the predicate to be false.
1659 MYREPARSE (@3, $1, SCM_ARG, $3);
1661 | EXPECT_SCM function_arglist_optional full_markup
1664 if (scm_is_true (scm_call_1 ($1, $3)))
1665 MYREPARSE (@3, $1, SCM_ARG, $3);
1666 else if (scm_is_true
1668 ($1, make_music_from_simple (parser, @3, $3))))
1669 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1671 // This is going to flag a syntax error, we
1672 // know the predicate to be false.
1673 MYREPARSE (@3, $1, SCM_ARG, $3);
1675 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1678 SCM n = scm_difference ($4, SCM_UNDEFINED);
1679 if (scm_is_true (scm_call_1 ($1, n)))
1680 MYREPARSE (@4, $1, REAL, n);
1682 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1683 t->set_property ("digit", $4);
1684 SCM m = t->unprotect ();
1685 if (scm_is_true (scm_call_1 ($1, m)))
1686 MYREPARSE (@4, $1, SCM_ARG, m);
1688 MYREPARSE (@4, $1, SCM_ARG, $4);
1692 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1695 SCM n = scm_difference ($4, SCM_UNDEFINED);
1696 MYREPARSE (@4, $1, REAL, n);
1700 function_arglist_closed:
1701 function_arglist_closed_common
1702 | function_arglist_closed_nonbackup
1705 function_arglist_closed_common:
1706 function_arglist_bare
1707 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1709 $$ = check_scheme_arg (parser, @3,
1712 | EXPECT_SCM function_arglist_closed_optional bare_number
1714 $$ = check_scheme_arg (parser, @3,
1717 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1719 $$ = check_scheme_arg (parser, @3,
1720 scm_difference ($4, SCM_UNDEFINED),
1723 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1725 $$ = check_scheme_arg (parser, @3,
1728 | EXPECT_SCM function_arglist_optional FRACTION
1730 $$ = check_scheme_arg (parser, @3,
1733 | function_arglist_common_reparse REPARSE SCM_ARG
1735 $$ = check_scheme_arg (parser, @3,
1738 | function_arglist_common_reparse REPARSE bare_number
1740 $$ = check_scheme_arg (parser, @3,
1743 | function_arglist_common_reparse REPARSE symbol_list_arg
1745 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1749 function_arglist_optional:
1750 function_arglist_keep %prec FUNCTION_ARGLIST
1751 | function_arglist_backup BACKUP
1752 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1754 $$ = scm_cons ($1, $3);
1756 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1758 $$ = scm_cons ($1, $3);
1762 function_arglist_closed_optional:
1763 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1764 | function_arglist_backup BACKUP
1765 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1767 $$ = scm_cons ($1, $3);
1769 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1771 $$ = scm_cons ($1, $3);
1775 embedded_scm_closed:
1777 | scm_function_call_closed
1780 embedded_scm_arg_closed:
1781 embedded_scm_bare_arg
1782 | scm_function_call_closed
1786 scm_function_call_closed:
1787 SCM_FUNCTION function_arglist_closed {
1788 $$ = MAKE_SYNTAX ("music-function", @$,
1790 } %prec FUNCTION_ARGLIST
1793 function_arglist_bare:
1794 EXPECT_NO_MORE_ARGS {
1797 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1798 $$ = scm_cons ($3, $2);
1800 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1801 $$ = scm_cons ($3, $2);
1803 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1804 $$ = scm_cons ($1, $3);
1806 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1807 $$ = scm_cons ($1, $3);
1809 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1810 $$ = scm_cons ($1, $3);
1814 music_function_call:
1815 MUSIC_FUNCTION function_arglist {
1816 $$ = MAKE_SYNTAX ("music-function", @$,
1823 /**/ { $$ = SCM_EOL; }
1824 | '=' simple_string {
1831 | repeated_music { $$ = $1; }
1832 | re_rhythmed_music { $$ = $1; }
1833 | complex_music_prefix music
1835 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1839 complex_music_prefix:
1840 CONTEXT simple_string optional_id optional_context_mod {
1841 Context_mod *ctxmod = unsmob_context_mod ($4);
1844 mods = ctxmod->get_mods ();
1845 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1847 | NEWCONTEXT simple_string optional_id optional_context_mod {
1848 Context_mod *ctxmod = unsmob_context_mod ($4);
1851 mods = ctxmod->get_mods ();
1852 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1857 mode_changing_head grouped_music_list {
1858 if ($1 == ly_symbol2scm ("chords"))
1860 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1866 parser->lexer_->pop_state ();
1868 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1869 Context_mod *ctxmod = unsmob_context_mod ($2);
1872 mods = ctxmod->get_mods ();
1873 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1874 if ($1 == ly_symbol2scm ("ChordNames"))
1876 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1878 parser->lexer_->pop_state ();
1884 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1885 parser->lexer_->push_note_state (nn);
1887 $$ = ly_symbol2scm ("notes");
1891 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1892 parser->lexer_->push_note_state (nn);
1894 $$ = ly_symbol2scm ("drums");
1897 parser->lexer_->push_figuredbass_state ();
1899 $$ = ly_symbol2scm ("figures");
1902 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1903 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1904 nn = parser->lexer_->lookup_identifier ("pitchnames");
1905 parser->lexer_->push_chord_state (nn);
1906 $$ = ly_symbol2scm ("chords");
1910 { parser->lexer_->push_lyric_state ();
1911 $$ = ly_symbol2scm ("lyrics");
1915 mode_changing_head_with_context:
1917 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1918 parser->lexer_->push_note_state (nn);
1920 $$ = ly_symbol2scm ("DrumStaff");
1923 parser->lexer_->push_figuredbass_state ();
1925 $$ = ly_symbol2scm ("FiguredBass");
1928 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1929 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1930 nn = parser->lexer_->lookup_identifier ("pitchnames");
1931 parser->lexer_->push_chord_state (nn);
1932 $$ = ly_symbol2scm ("ChordNames");
1935 { parser->lexer_->push_lyric_state ();
1936 $$ = ly_symbol2scm ("Lyrics");
1941 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1944 /* Can also use music at the expensive of two S/Rs similar to
1945 \repeat \alternative */
1946 parser->lexer_->pop_state ();
1948 $$ = scm_cons ($3, SCM_EOL);
1950 | new_lyrics ADDLYRICS {
1951 parser->lexer_->push_lyric_state ();
1953 parser->lexer_->pop_state ();
1954 $$ = scm_cons ($4, $1);
1959 composite_music new_lyrics {
1960 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1962 | LYRICSTO simple_string {
1963 parser->lexer_->push_lyric_state ();
1965 parser->lexer_->pop_state ();
1966 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1971 CHANGE STRING '=' STRING {
1972 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1979 $$ = scm_reverse_x ($1, SCM_EOL);
1981 | symbol_list_rev property_path {
1982 $$ = scm_reverse_x ($1, $2);
1988 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1989 scm_string_to_symbol ($1), $3);
1991 | UNSET simple_string {
1992 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1993 scm_string_to_symbol ($2));
1995 | OVERRIDE property_path '=' scalar {
1996 if (scm_ilength ($2) < 2) {
1997 parser->parser_error (@2, _("bad grob property path"));
2000 $$ = scm_cons (ly_symbol2scm ("push"),
2001 scm_cons2 (scm_car ($2),
2006 | REVERT revert_arg {
2007 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2011 // This is all quite awkward for the sake of substantial backward
2012 // compatibility while at the same time allowing a more "natural" form
2013 // of specification not separating grob specification from grob
2014 // property path. The purpose of this definition of revert_arg is to
2015 // allow the symbol list which specifies grob and property to revert
2016 // to be optionally be split into two parts after the grob (which in
2017 // this case is just the first element of the list). symbol_list_part
2018 // is only one path component, but it can be parsed without lookahead,
2019 // so we can follow it with a synthetic BACKUP token when needed. If
2020 // the first symbol_list_part already contains multiple elements (only
2021 // possible if a Scheme expression provides them), we just parse for
2022 // additional elements introduced by '.', which is what the
2023 // SYMBOL_LIST backup in connection with the immediately following
2024 // rule using symbol_list_arg does.
2026 // As long as we don't have our coffers filled with both grob and at
2027 // least one grob property specification, the rest of the required
2028 // symbol list chain may be provided either with or without a leading
2029 // dot. This is for both allowing the traditional
2030 // \revert Accidental #'color
2031 // as well as well as the "naive" form
2032 // \revert Accidental.color
2037 if (scm_is_null ($1)
2038 || scm_is_null (scm_cdr ($1)))
2039 MYBACKUP (SCM_ARG, $1, @1);
2041 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2043 | revert_arg BACKUP symbol_list_arg
2049 // revert_arg_part delivers results in reverse
2052 | revert_arg BACKUP SCM_ARG '.' symbol_list_part
2054 $$ = scm_append_x (scm_list_2 ($5, $3));
2056 | revert_arg BACKUP SCM_ARG symbol_list_part
2058 $$ = scm_append_x (scm_list_2 ($4, $3));
2063 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2064 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2066 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2067 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2068 | DENIES { $$ = ly_symbol2scm ("denies"); }
2070 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2071 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2072 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2073 | NAME { $$ = ly_symbol2scm ("context-name"); }
2077 property_operation { $$ = $1; }
2078 | context_def_mod STRING {
2079 $$ = scm_list_2 ($1, $2);
2081 | context_def_mod embedded_scm
2083 if (!scm_is_string ($2)
2084 && ly_symbol2scm ("consists") != $1
2085 && ly_symbol2scm ("remove") != $1)
2088 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2092 $$ = scm_list_2 ($1, $2);
2097 // If defined, at least two members.
2101 SCM l = scm_reverse_x ($1, SCM_EOL);
2104 (scm_object_property (scm_car (l),
2105 ly_symbol2scm ("is-grob?"))))
2106 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2107 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2108 parser->parser_error (@1, _ ("bad grob property path"));
2115 // If defined, at least three members
2119 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2121 parser->parser_error (@1, _ ("bad grob property path"));
2125 | grob_prop_spec property_path
2127 if (!SCM_UNBNDP ($1)) {
2128 $$ = scm_append_x (scm_list_2 ($1, $2));
2129 if (scm_is_null (scm_cddr ($$))) {
2130 parser->parser_error (@$, _ ("bad grob property path"));
2138 // Exactly two elements or undefined
2142 SCM l = scm_reverse_x ($1, SCM_EOL);
2143 switch (scm_ilength (l)) {
2145 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2149 parser->parser_error (@1, _ ("bad context property path"));
2156 simple_music_property_def:
2157 OVERRIDE grob_prop_path '=' scalar {
2158 if (SCM_UNBNDP ($2))
2161 $$ = scm_list_5 (scm_car ($2),
2162 ly_symbol2scm ("OverrideProperty"),
2168 | REVERT simple_revert_context revert_arg {
2169 $$ = scm_list_4 ($2,
2170 ly_symbol2scm ("RevertProperty"),
2174 | SET context_prop_spec '=' scalar {
2175 if (SCM_UNBNDP ($2))
2178 $$ = scm_list_4 (scm_car ($2),
2179 ly_symbol2scm ("PropertySet"),
2183 | UNSET context_prop_spec {
2184 if (SCM_UNBNDP ($2))
2187 $$ = scm_list_3 (scm_car ($2),
2188 ly_symbol2scm ("PropertyUnset"),
2194 // This is all quite awkward for the sake of substantial backward
2195 // compatibility while at the same time allowing a more "natural" form
2196 // of specification not separating grob specification from grob
2197 // property path. The purpose of this definition of
2198 // simple_revert_context is to allow the symbol list which specifies
2199 // grob and property to revert to be optionally be split into two
2200 // parts after the grob (which may be preceded by a context
2201 // specification, a case which we distinguish by checking whether the
2202 // first symbol is a valid grob symbol instead).
2204 // See revert_arg above for the main work horse of this arrangement.
2205 // simple_revert_context just caters for the context and delegates the
2206 // rest of the job to revert_arg.
2208 simple_revert_context:
2211 $1 = scm_reverse_x ($1, SCM_EOL);
2212 if (scm_is_null ($1)
2214 (scm_object_property (scm_car ($1),
2215 ly_symbol2scm ("is-grob?")))) {
2216 $$ = ly_symbol2scm ("Bottom");
2217 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2220 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2227 simple_music_property_def {
2228 if (SCM_UNBNDP ($1))
2229 $$ = MAKE_SYNTAX ("void-music", @1);
2231 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2240 | string '+' string {
2241 if (!scm_is_string ($1)) {
2242 parser->parser_error (@1, (_ ("simple string expected")));
2243 $1 = scm_string (SCM_EOL);
2245 if (!scm_is_string ($3)) {
2246 parser->parser_error (@3, (_ ("simple string expected")));
2247 $3 = scm_string (SCM_EOL);
2249 $$ = scm_string_append (scm_list_2 ($1, $3));
2253 simple_string: STRING {
2258 if (scm_is_string ($1)) {
2261 parser->parser_error (@1, (_ ("simple string expected")));
2262 $$ = scm_string (SCM_EOL);
2276 embedded_scm_arg_closed
2285 simple_element post_events {
2286 // Let the rhythmic music iterator sort this mess out.
2287 if (scm_is_pair ($2)) {
2288 $$ = make_music_from_simple (parser, @1, $1);
2289 if (unsmob_music ($$))
2290 unsmob_music ($$)->set_property ("articulations",
2291 scm_reverse_x ($2, SCM_EOL));
2293 parser->parser_error (@1, _("music expected"));
2296 | simple_chord_elements post_events {
2297 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2300 /* why is this giving wrong start location? -ns
2302 i.set_location (@1, @2);
2303 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2305 | CHORD_REPETITION optional_notemode_duration post_events {
2307 i.set_location (@1, @3);
2308 $$ = MAKE_SYNTAX ("repetition-chord", i,
2309 $2, scm_reverse_x ($3, SCM_EOL));
2311 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2313 i.set_location (@1, @3);
2314 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2315 scm_reverse_x ($3, SCM_EOL));
2318 | note_chord_element
2323 chord_body optional_notemode_duration post_events
2325 Music *m = unsmob_music ($1);
2326 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2327 SCM es = m->get_property ("elements");
2328 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2330 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2331 unsmob_music (scm_car (s))->set_property ("duration", dur);
2332 es = ly_append2 (es, postevs);
2334 m-> set_property ("elements", es);
2336 $$ = m->self_scm ();
2341 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2343 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2347 chord_body_elements:
2348 /* empty */ { $$ = SCM_EOL; }
2349 | chord_body_elements chord_body_element {
2350 if (!SCM_UNBNDP ($2))
2351 $$ = scm_cons ($2, $1);
2356 pitch exclamations questions octave_check post_events
2358 bool q = to_boolean ($3);
2359 bool ex = to_boolean ($2);
2363 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2364 n->set_property ("pitch", $1);
2366 n->set_property ("cautionary", SCM_BOOL_T);
2368 n->set_property ("force-accidental", SCM_BOOL_T);
2370 if (scm_is_pair (post)) {
2371 SCM arts = scm_reverse_x (post, SCM_EOL);
2372 n->set_property ("articulations", arts);
2374 if (scm_is_number (check))
2376 int q = scm_to_int (check);
2377 n->set_property ("absolute-octave", scm_from_int (q-1));
2380 $$ = n->unprotect ();
2382 | DRUM_PITCH post_events {
2383 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2384 n->set_property ("drum-type", $1);
2386 if (scm_is_pair ($2)) {
2387 SCM arts = scm_reverse_x ($2, SCM_EOL);
2388 n->set_property ("articulations", arts);
2390 $$ = n->unprotect ();
2392 | music_function_chord_body
2394 Music *m = unsmob_music ($1);
2396 while (m && m->is_mus_type ("music-wrapper-music")) {
2397 $$ = m->get_property ("element");
2398 m = unsmob_music ($$);
2401 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2402 parser->parser_error (@$, _ ("not a rhythmic event"));
2408 music_function_chord_body:
2413 // Event functions may only take closed arglists, otherwise it would
2414 // not be clear whether a following postevent should be associated
2415 // with the last argument of the event function or with the expression
2416 // for which the function call acts itself as event.
2418 music_function_call_closed:
2419 MUSIC_FUNCTION function_arglist_closed {
2420 $$ = MAKE_SYNTAX ("music-function", @$,
2425 event_function_event:
2426 EVENT_FUNCTION function_arglist_closed {
2427 $$ = MAKE_SYNTAX ("music-function", @$,
2437 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2438 m->set_property ("span-direction", scm_from_int (START));
2439 $$ = m->unprotect();
2442 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2443 m->set_property ("span-direction", scm_from_int (STOP));
2444 $$ = m->unprotect ();
2447 $$ = MAKE_SYNTAX ("voice-separator", @$);
2450 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2452 Music *m = unsmob_music (pipe);
2457 $$ = m->unprotect ();
2460 $$ = MAKE_SYNTAX ("bar-check", @$);
2467 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2479 | post_events post_event {
2480 unsmob_music ($2)->set_spot (@2);
2481 $$ = scm_cons ($2, $$);
2485 post_event_nofinger:
2486 direction_less_event {
2489 | script_dir music_function_call_closed {
2491 if (!SCM_UNBNDP ($1))
2493 unsmob_music ($$)->set_property ("direction", $1);
2497 if (!parser->lexer_->is_lyric_state ())
2498 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2499 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2502 if (!parser->lexer_->is_lyric_state ())
2503 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2504 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2506 | script_dir direction_reqd_event {
2507 if (!SCM_UNBNDP ($1))
2509 Music *m = unsmob_music ($2);
2510 m->set_property ("direction", $1);
2514 | script_dir direction_less_event {
2515 if (!SCM_UNBNDP ($1))
2517 Music *m = unsmob_music ($2);
2518 m->set_property ("direction", $1);
2525 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2530 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2541 string_number_event:
2543 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2544 s->set_property ("string-number", $1);
2545 $$ = s->unprotect ();
2549 direction_less_char:
2551 $$ = ly_symbol2scm ("bracketOpenSymbol");
2554 $$ = ly_symbol2scm ("bracketCloseSymbol");
2557 $$ = ly_symbol2scm ("tildeSymbol");
2560 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2563 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2566 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2569 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2572 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2575 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2578 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2582 direction_less_event:
2583 direction_less_char {
2584 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2586 if (unsmob_music (predefd))
2588 m = unsmob_music (predefd)->clone ();
2593 m = MY_MAKE_MUSIC ("Music", @$);
2595 $$ = m->unprotect ();
2597 | string_number_event
2598 | EVENT_IDENTIFIER {
2602 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2603 a->set_property ("tremolo-type", $1);
2604 $$ = a->unprotect ();
2606 | event_function_event
2609 direction_reqd_event:
2613 | script_abbreviation {
2614 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2615 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2616 if (scm_is_string (s))
2617 a->set_property ("articulation-type", s);
2618 else parser->parser_error (@1, _ ("expecting string as script definition"));
2619 $$ = a->unprotect ();
2624 /**/ { $$ = SCM_EOL; }
2625 | '=' quotes { $$ = $2; }
2639 $$ = scm_from_int (1);
2642 $$ = scm_oneplus ($1);
2648 $$ = scm_from_int (-1);
2651 $$ = scm_oneminus ($1);
2656 NOTENAME_PITCH quotes {
2657 if (!scm_is_eq (SCM_INUM0, $2))
2659 Pitch p = *unsmob_pitch ($1);
2660 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2661 $$ = p.smobbed_copy ();
2671 TONICNAME_PITCH quotes {
2672 if (!scm_is_eq (SCM_INUM0, $2))
2674 Pitch p = *unsmob_pitch ($1);
2675 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2676 $$ = p.smobbed_copy ();
2686 pitch_also_in_chords:
2693 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2694 t->set_property ("text", $1);
2695 $$ = t->unprotect ();
2698 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2699 t->set_property ("text",
2700 make_simple_markup ($1));
2701 $$ = t->unprotect ();
2703 | embedded_scm_closed
2705 Music *m = unsmob_music ($1);
2706 if (m && m->is_mus_type ("post-event"))
2708 else if (Text_interface::is_markup ($1)) {
2709 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2710 t->set_property ("text", $1);
2711 $$ = t->unprotect ();
2713 parser->parser_error (@1, _ ("not an articulation"));
2719 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2720 t->set_property ("digit", $1);
2721 $$ = t->unprotect ();
2725 script_abbreviation:
2727 $$ = scm_from_locale_string ("Hat");
2730 $$ = scm_from_locale_string ("Plus");
2733 $$ = scm_from_locale_string ("Dash");
2736 $$ = scm_from_locale_string ("Bar");
2739 $$ = scm_from_locale_string ("Larger");
2742 $$ = scm_from_locale_string ("Dot");
2745 $$ = scm_from_locale_string ("Underscore");
2750 '_' { $$ = scm_from_int (DOWN); }
2751 | '^' { $$ = scm_from_int (UP); }
2752 | '-' { $$ = SCM_UNDEFINED; }
2756 multiplied_duration {
2761 maybe_notemode_duration:
2765 | multiplied_duration {
2767 parser->default_duration_ = *unsmob_duration ($$);
2772 optional_notemode_duration:
2773 maybe_notemode_duration
2775 if (SCM_UNBNDP ($$))
2776 $$ = parser->default_duration_.smobbed_copy ();
2783 int n = scm_to_int ($1);
2784 if (!is_duration (n))
2785 parser->parser_error (@1, _f ("not a duration: %d", n));
2789 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2791 | DURATION_IDENTIFIER dots {
2792 Duration *d = unsmob_duration ($1);
2793 Duration k (d->duration_log (),
2794 d->dot_count () + scm_to_int ($2));
2795 k = k.compressed (d->factor ());
2796 scm_remember_upto_here_1 ($1);
2797 $$ = k.smobbed_copy ();
2801 multiplied_duration:
2805 | multiplied_duration '*' UNSIGNED {
2806 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2808 | multiplied_duration '*' FRACTION {
2809 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2811 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2820 $$ = scm_oneplus ($1);
2829 int n = scm_to_int ($2);
2830 if (!is_duration (n))
2831 parser->parser_error (@2, _f ("not a duration: %d", n));
2837 UNSIGNED { $$ = $1; }
2838 | STRING { $$ = $1; }
2839 | full_markup { $$ = $1; }
2842 // as an integer, it needs to be non-negative, and otherwise
2843 // it needs to be suitable as a markup.
2844 if (scm_is_integer ($1)
2845 ? scm_is_true (scm_negative_p ($1))
2846 : !Text_interface::is_markup ($1))
2848 parser->parser_error (@1, _ ("bass number expected"));
2854 figured_bass_alteration:
2855 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2856 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2857 | '!' { $$ = scm_from_int (0); }
2862 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2863 $$ = bfr->unprotect ();
2866 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2867 $$ = bfr->self_scm ();
2869 if (scm_is_number ($1))
2870 bfr->set_property ("figure", $1);
2871 else if (Text_interface::is_markup ($1))
2872 bfr->set_property ("text", $1);
2878 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2880 | bass_figure figured_bass_alteration {
2881 Music *m = unsmob_music ($1);
2882 if (scm_to_double ($2)) {
2883 SCM salter = m->get_property ("alteration");
2884 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2885 m->set_property ("alteration",
2886 scm_sum (alter, $2));
2888 m->set_property ("alteration", scm_from_int (0));
2891 | bass_figure figured_bass_modification {
2892 Music *m = unsmob_music ($1);
2893 if ($2 == ly_symbol2scm ("plus"))
2895 m->set_property ("augmented", SCM_BOOL_T);
2897 else if ($2 == ly_symbol2scm ("slash"))
2899 m->set_property ("diminished", SCM_BOOL_T);
2901 else if ($2 == ly_symbol2scm ("exclamation"))
2903 m->set_property ("no-continuation", SCM_BOOL_T);
2905 else if ($2 == ly_symbol2scm ("backslash"))
2907 m->set_property ("augmented-slash", SCM_BOOL_T);
2913 figured_bass_modification:
2915 $$ = ly_symbol2scm ("plus");
2918 $$ = ly_symbol2scm ("exclamation");
2921 $$ = ly_symbol2scm ("slash");
2924 $$ = ly_symbol2scm ("backslash");
2934 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2942 | figure_list br_bass_figure {
2943 $$ = scm_cons ($2, $1);
2948 FIGURE_OPEN figure_list FIGURE_CLOSE {
2949 $$ = scm_reverse_x ($2, SCM_EOL);
2955 /**/ { $$ = SCM_BOOL_F; }
2956 | REST { $$ = SCM_BOOL_T; }
2960 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2961 if (!parser->lexer_->is_note_state ())
2962 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2963 if (!SCM_UNBNDP ($2)
2965 || scm_is_number ($4)
2967 || scm_is_true ($6))
2970 if (scm_is_true ($6))
2971 n = MY_MAKE_MUSIC ("RestEvent", @$);
2973 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2975 n->set_property ("pitch", $1);
2976 if (SCM_UNBNDP ($5))
2977 n->set_property ("duration",
2978 parser->default_duration_.smobbed_copy ());
2980 n->set_property ("duration", $5);
2982 if (scm_is_number ($4))
2984 int q = scm_to_int ($4);
2985 n->set_property ("absolute-octave", scm_from_int (q-1));
2988 if (to_boolean ($3))
2989 n->set_property ("cautionary", SCM_BOOL_T);
2990 if (to_boolean ($2) || to_boolean ($3))
2991 n->set_property ("force-accidental", SCM_BOOL_T);
2993 $$ = n->unprotect ();
2996 | DRUM_PITCH optional_notemode_duration {
2997 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2998 n->set_property ("duration", $2);
2999 n->set_property ("drum-type", $1);
3001 $$ = n->unprotect ();
3003 | RESTNAME optional_notemode_duration {
3005 if (ly_scm2string ($1) == "s") {
3007 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3010 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3013 ev->set_property ("duration", $2);
3014 $$ = ev->unprotect ();
3018 simple_chord_elements:
3020 if (!parser->lexer_->is_chord_state ())
3021 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3024 | figure_spec optional_notemode_duration {
3025 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3027 unsmob_music (scm_car (s))->set_property ("duration", $2);
3043 lyric_element_music:
3044 lyric_element optional_notemode_duration post_events {
3045 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3046 if (scm_is_pair ($3))
3047 unsmob_music ($$)->set_property
3048 ("articulations", scm_reverse_x ($3, SCM_EOL));
3053 steno_tonic_pitch optional_notemode_duration {
3054 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3056 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3057 SCM its = scm_reverse_x ($4, SCM_EOL);
3058 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3066 | chord_items chord_item {
3067 $$ = scm_cons ($2, $$);
3073 $$ = ly_symbol2scm ("chord-colon");
3076 $$ = ly_symbol2scm ("chord-caret");
3078 | CHORD_SLASH steno_tonic_pitch {
3079 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3081 | CHORD_BASS steno_tonic_pitch {
3082 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3091 $$ = scm_reverse_x ($1, SCM_EOL);
3099 step_number { $$ = scm_cons ($1, SCM_EOL); }
3100 | step_numbers '.' step_number {
3101 $$ = scm_cons ($3, $$);
3107 $$ = make_chord_step ($1, 0);
3110 $$ = make_chord_step ($1, SHARP_ALTERATION);
3112 | UNSIGNED CHORD_MINUS {
3113 $$ = make_chord_step ($1, FLAT_ALTERATION);
3121 | UNSIGNED '~' UNSIGNED {
3122 $$ = scm_cons ($1, $3);
3129 TODO: should deprecate in favor of Scheme?
3133 number_expression '+' number_term {
3134 $$ = scm_sum ($1, $3);
3136 | number_expression '-' number_term {
3137 $$ = scm_difference ($1, $3);
3146 | number_factor '*' number_factor {
3147 $$ = scm_product ($1, $3);
3149 | number_factor '/' number_factor {
3150 $$ = scm_divide ($1, $3);
3155 '-' number_factor { /* %prec UNARY_MINUS */
3156 $$ = scm_difference ($2, SCM_UNDEFINED);
3164 | UNSIGNED NUMBER_IDENTIFIER {
3165 $$ = scm_product ($1, $2);
3167 | REAL NUMBER_IDENTIFIER {
3168 $$ = scm_product ($1, $2);
3184 { $$ = SCM_UNDEFINED; }
3187 if (SCM_UNBNDP ($1))
3195 { $$ = SCM_UNDEFINED; }
3198 if (SCM_UNBNDP ($1))
3207 { parser->lexer_->push_markup_state (); }
3210 parser->lexer_->pop_state ();
3216 { parser->lexer_->push_markup_state (); }
3219 parser->lexer_->pop_state ();
3225 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3227 | markup_head_1_list simple_markup {
3228 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3238 if (Text_interface::is_markup ($1))
3239 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3240 else if (Text_interface::is_markup_list ($1))
3241 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3243 parser->parser_error (@1, _ ("not a markup"));
3244 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3251 markup_composed_list {
3254 | markup_braced_list {
3257 | markup_command_list {
3258 $$ = scm_list_1 ($1);
3260 | markup_scm MARKUPLIST_IDENTIFIER
3266 markup_composed_list:
3267 markup_head_1_list markup_braced_list {
3268 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3274 '{' markup_braced_list_body '}' {
3275 $$ = scm_reverse_x ($2, SCM_EOL);
3279 markup_braced_list_body:
3280 /* empty */ { $$ = SCM_EOL; }
3281 | markup_braced_list_body markup {
3282 $$ = scm_cons ($2, $1);
3284 | markup_braced_list_body markup_list {
3285 $$ = scm_reverse_x ($2, $1);
3289 markup_command_list:
3290 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3291 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3295 markup_command_basic_arguments:
3296 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3297 $$ = scm_cons ($3, $2);
3299 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3300 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3302 | EXPECT_NO_MORE_ARGS {
3307 markup_command_list_arguments:
3308 markup_command_basic_arguments { $$ = $1; }
3309 | EXPECT_MARKUP markup_command_list_arguments markup {
3310 $$ = scm_cons ($3, $2);
3315 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3316 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3321 markup_head_1_item {
3322 $$ = scm_list_1 ($1);
3324 | markup_head_1_list markup_head_1_item {
3325 $$ = scm_cons ($2, $1);
3331 $$ = make_simple_markup ($1);
3334 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3335 parser->lexer_->push_note_state (nn);
3336 } '{' score_body '}' {
3337 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3338 parser->lexer_->pop_state ();
3340 | MARKUP_FUNCTION markup_command_basic_arguments {
3341 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3343 | markup_scm MARKUP_IDENTIFIER
3350 markup_head_1_list simple_markup {
3351 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3352 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3362 Lily_parser::set_yydebug (bool x)
3368 Lily_parser::do_yyparse ()
3370 SCM retval = SCM_UNDEFINED;
3371 yyparse (this, &retval);
3381 It is a little strange to have this function in this file, but
3382 otherwise, we have to import music classes into the lexer.
3386 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3388 if (unsmob_book (sid)) {
3389 Book *book = unsmob_book (sid)->clone ();
3390 *destination = book->self_scm ();
3393 return BOOK_IDENTIFIER;
3394 } else if (scm_is_number (sid)) {
3396 return NUMBER_IDENTIFIER;
3397 } else if (unsmob_context_def (sid)) {
3398 Context_def *def= unsmob_context_def (sid)->clone ();
3400 *destination = def->self_scm ();
3403 return CONTEXT_DEF_IDENTIFIER;
3404 } else if (unsmob_context_mod (sid)) {
3405 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3407 return CONTEXT_MOD_IDENTIFIER;
3408 } else if (Music *mus = unsmob_music (sid)) {
3409 mus = mus->clone ();
3410 *destination = mus->self_scm ();
3411 unsmob_music (*destination)->
3412 set_property ("origin", make_input (last_input_));
3414 bool is_event = mus->is_mus_type ("post-event");
3416 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3417 } else if (unsmob_pitch (sid)) {
3418 *destination = unsmob_pitch (sid)->smobbed_copy ();
3419 return PITCH_IDENTIFIER;
3420 } else if (unsmob_duration (sid)) {
3421 *destination = unsmob_duration (sid)->smobbed_copy ();
3422 return DURATION_IDENTIFIER;
3423 } else if (unsmob_output_def (sid)) {
3424 Output_def *p = unsmob_output_def (sid);
3427 *destination = p->self_scm ();
3429 return OUTPUT_DEF_IDENTIFIER;
3436 get_next_unique_context_id ()
3438 return scm_from_locale_string ("$uniqueContextId");
3443 get_next_unique_lyrics_context_id ()
3445 static int new_context_count;
3447 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3448 return scm_from_locale_string (s);
3451 // check_scheme_arg checks one argument with a given predicate for use
3452 // in an argument list and throws a syntax error if it is unusable.
3453 // The argument is prepended to the argument list in any case. After
3454 // throwing a syntax error, the argument list is terminated with #f as
3455 // its last cdr in order to mark it as uncallable while not losing
3456 // track of its total length.
3458 // There are a few special considerations: if optional argument disp
3459 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3460 // instead of arg in a prospective error message. This is useful if
3461 // arg is not the actual argument but rather a transformation of it.
3463 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3464 // and an error message using disp is produced unconditionally.
3466 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3467 SCM arg, SCM args, SCM pred, SCM disp)
3469 if (SCM_UNBNDP (arg))
3470 args = scm_cons (disp, args);
3472 args = scm_cons (arg, args);
3473 if (scm_is_true (scm_call_1 (pred, arg)))
3476 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3477 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3478 SCM_UNBNDP (disp) ? arg : disp);
3479 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3483 SCM loc_on_music (Input loc, SCM arg)
3485 if (Music *m = unsmob_music (arg))
3489 return m->unprotect ();
3495 try_string_variants (SCM pred, SCM str)
3497 // a matching predicate is always ok
3498 if (scm_is_true (scm_call_1 (pred, str)))
3500 // a symbol may be interpreted as a list of symbols if it helps
3501 if (scm_is_symbol (str)) {
3502 str = scm_list_1 (str);
3503 if (scm_is_true (scm_call_1 (pred, str)))
3505 return SCM_UNDEFINED;
3508 // If this cannot be a string representation of a symbol list,
3511 if (!is_regular_identifier (str, true))
3512 return SCM_UNDEFINED;
3514 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3515 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3516 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3518 // Let's attempt the symbol list interpretation first.
3520 if (scm_is_true (scm_call_1 (pred, str)))
3523 // If there is just one symbol in the list, we might interpret
3524 // it as a single symbol
3526 if (scm_is_null (scm_cdr (str)))
3528 str = scm_car (str);
3529 if (scm_is_true (scm_call_1 (pred, str)))
3533 return SCM_UNDEFINED;
3537 is_regular_identifier (SCM id, bool multiple)
3539 if (!scm_is_string (id))
3542 string str = ly_scm2string (id);
3544 bool middle = false;
3546 for (string::iterator it=str.begin(); it != str.end (); it++)
3549 if ((c >= 'a' && c <= 'z')
3550 || (c >= 'A' && c <= 'Z')
3553 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3562 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3564 if (unsmob_music (simple))
3566 if (parser->lexer_->is_note_state ()) {
3567 if (scm_is_symbol (simple)) {
3568 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3569 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3570 n->set_property ("drum-type", simple);
3571 return n->unprotect ();
3573 if (unsmob_pitch (simple)) {
3574 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3575 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3576 n->set_property ("pitch", simple);
3577 return n->unprotect ();
3580 } else if (parser->lexer_->is_lyric_state ()) {
3581 if (Text_interface::is_markup (simple))
3582 return MAKE_SYNTAX ("lyric-event", loc, simple,
3583 parser->default_duration_.smobbed_copy ());
3584 } else if (parser->lexer_->is_chord_state ()) {
3585 if (unsmob_pitch (simple))
3586 return make_chord_elements (loc, simple,
3587 parser->default_duration_.smobbed_copy (),
3594 make_music_with_input (SCM name, Input where)
3596 Music *m = make_music_by_name (name);
3597 m->set_spot (where);
3602 make_simple_markup (SCM a)
3610 return t && t == 1 << intlog2 (t);
3614 make_chord_step (SCM step_scm, Rational alter)
3616 int step = scm_to_int (step_scm);
3619 alter += FLAT_ALTERATION;
3623 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3624 return m.smobbed_copy ();
3629 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3631 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3632 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3633 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3635 unsmob_music (scm_car (s))->set_spot (loc);
3641 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3643 Lily_lexer *lex = parser->lexer_;
3647 lex->prepare_for_next_token ();
3648 return lex->yylex ();