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
332 %token MULTI_MEASURE_REST
338 /* Artificial tokens, for more generic function syntax */
339 %token EXPECT_MARKUP "markup?"
340 %token EXPECT_PITCH "ly:pitch?"
341 %token EXPECT_DURATION "ly:duration?"
342 %token EXPECT_SCM "scheme?"
343 %token BACKUP "(backed-up?)"
344 %token REPARSE "(reparsed?)"
345 %token EXPECT_MARKUP_LIST "markup-list?"
346 %token EXPECT_OPTIONAL "optional?"
347 /* After the last argument. */
348 %token EXPECT_NO_MORE_ARGS;
350 /* An artificial token for parsing embedded Lilypond */
351 %token EMBEDDED_LILY "#{"
353 %token BOOK_IDENTIFIER
354 %token CHORDMODIFIER_PITCH
355 %token CHORD_MODIFIER
356 %token CHORD_REPETITION
357 %token CONTEXT_DEF_IDENTIFIER
358 %token CONTEXT_MOD_IDENTIFIER
360 %token PITCH_IDENTIFIER
361 %token DURATION_IDENTIFIER
362 %token EVENT_IDENTIFIER
363 %token EVENT_FUNCTION
366 %token MARKUP_FUNCTION
367 %token MARKUP_LIST_FUNCTION
368 %token MARKUP_IDENTIFIER
369 %token MARKUPLIST_IDENTIFIER
370 %token MUSIC_FUNCTION
371 %token MUSIC_IDENTIFIER
372 %token NOTENAME_PITCH
373 %token NUMBER_IDENTIFIER
374 %token OUTPUT_DEF_IDENTIFIER
379 %token SCM_IDENTIFIER
383 %token TONICNAME_PITCH
387 /* We don't assign precedence to / and *, because we might need varied
388 prec levels in different prods */
397 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
398 parser->lexer_->push_note_state (nn);
399 } embedded_lilypond {
400 parser->lexer_->pop_state ();
405 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
406 | lilypond toplevel_expression {
408 | lilypond assignment {
411 parser->error_level_ = 1;
414 parser->error_level_ = 1;
421 parser->lexer_->add_scope (get_header (parser));
423 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
426 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
427 scm_call_2 (proc, parser->self_scm (), $1);
430 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
431 scm_call_2 (proc, parser->self_scm (), $1);
434 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
435 scm_call_2 (proc, parser->self_scm (), $1);
438 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
439 scm_call_2 (proc, parser->self_scm (), $1);
442 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
443 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
446 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
447 scm_call_2 (proc, parser->self_scm (), $1);
450 // Evaluate and ignore #xxx, as opposed to \xxx
451 parser->lexer_->eval_scm_token ($1);
453 | embedded_scm_active
455 SCM out = SCM_UNDEFINED;
456 if (Text_interface::is_markup ($1))
457 out = scm_list_1 ($1);
458 else if (Text_interface::is_markup_list ($1))
460 if (scm_is_pair (out))
462 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
463 scm_call_2 (proc, parser->self_scm (), out);
464 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
465 parser->parser_error (@1, _("bad expression type"));
469 Output_def * od = unsmob_output_def ($1);
471 if (od->c_variable ("is-paper") == SCM_BOOL_T)
472 id = ly_symbol2scm ("$defaultpaper");
473 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
474 id = ly_symbol2scm ("$defaultmidi");
475 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
476 id = ly_symbol2scm ("$defaultlayout");
478 parser->lexer_->set_identifier (id, $1);
485 $$ = parser->lexer_->eval_scm_token ($1);
495 embedded_scm_bare_arg:
499 $$ = parser->lexer_->eval_scm_token ($1);
503 | context_modification
505 | context_def_spec_block
511 /* The generic version may end in music, or not */
519 embedded_scm_bare_arg
525 SCM_FUNCTION function_arglist {
526 $$ = MAKE_SYNTAX ("music-function", @$,
534 $$ = MAKE_SYNTAX ("void-music", @$);
537 | music_embedded music_embedded music_list {
538 $3 = scm_reverse_x ($3, SCM_EOL);
539 if (unsmob_music ($2))
540 $3 = scm_cons ($2, $3);
541 if (unsmob_music ($1))
542 $3 = scm_cons ($1, $3);
543 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
546 parser->error_level_ = 1;
547 $$ = SCM_UNSPECIFIED;
549 | INVALID embedded_lilypond {
550 parser->error_level_ = 1;
556 lilypond_header_body:
557 /* empty */ { $$ = SCM_UNSPECIFIED; }
558 | lilypond_header_body assignment {
561 | lilypond_header_body embedded_scm {
567 HEADER '{' lilypond_header_body '}' {
568 $$ = parser->lexer_->remove_scope ();
580 assignment_id '=' identifier_init {
581 parser->lexer_->set_identifier ($1, $3);
582 $$ = SCM_UNSPECIFIED;
584 | assignment_id property_path '=' identifier_init {
585 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
586 parser->lexer_->set_identifier (path, $4);
587 $$ = SCM_UNSPECIFIED;
597 | context_def_spec_block
599 | post_event_nofinger
605 | context_modification
608 context_def_spec_block:
609 CONTEXT '{' context_def_spec_body '}'
620 context_mod_embedded:
623 if (unsmob_music ($1)) {
624 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
625 $1 = scm_call_2 (proc, parser->self_scm (), $1);
627 if (unsmob_context_mod ($1))
630 parser->parser_error (@1, _ ("not a context mod"));
636 context_def_spec_body:
638 $$ = Context_def::make_scm ();
639 unsmob_context_def ($$)->origin ()->set_spot (@$);
641 | CONTEXT_DEF_IDENTIFIER {
643 unsmob_context_def ($$)->origin ()->set_spot (@$);
645 | context_def_spec_body context_mod {
646 if (!SCM_UNBNDP ($2))
647 unsmob_context_def ($$)->add_context_mod ($2);
649 | context_def_spec_body context_modification {
650 Context_def *td = unsmob_context_def ($$);
651 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
652 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
653 td->add_context_mod (scm_car (m));
656 | context_def_spec_body context_mod_embedded {
657 Context_def *td = unsmob_context_def ($$);
658 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
659 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
660 td->add_context_mod (scm_car (m));
668 BOOK '{' book_body '}' {
671 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
676 * Use 'handlers' like for toplevel-* stuff?
677 * grok \layout and \midi? */
680 Book *book = new Book;
681 init_papers (parser);
682 book->origin ()->set_spot (@$);
683 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
684 book->paper_->unprotect ();
685 push_paper (parser, book->paper_);
686 book->header_ = get_header (parser);
687 $$ = book->unprotect ();
688 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
691 unsmob_book ($1)->origin ()->set_spot (@$);
692 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
694 | book_body paper_block {
695 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
696 set_paper (parser, unsmob_output_def ($2));
698 | book_body bookpart_block {
699 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
700 scm_call_2 (proc, $1, $2);
702 | book_body score_block {
703 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
704 scm_call_2 (proc, $1, $2);
706 | book_body composite_music {
707 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
708 scm_call_3 (proc, parser->self_scm (), $1, $2);
710 | book_body full_markup {
711 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
712 scm_call_2 (proc, $1, scm_list_1 ($2));
714 | book_body full_markup_list {
715 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
716 scm_call_2 (proc, $1, $2);
718 | book_body SCM_TOKEN {
719 // Evaluate and ignore #xxx, as opposed to \xxx
720 parser->lexer_->eval_scm_token ($2);
722 | book_body embedded_scm_active
724 SCM out = SCM_UNDEFINED;
725 if (Text_interface::is_markup ($2))
726 out = scm_list_1 ($2);
727 else if (Text_interface::is_markup_list ($2))
729 if (scm_is_pair (out))
731 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
732 scm_call_2 (proc, $1, out);
733 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
734 parser->parser_error (@2, _("bad expression type"));
738 parser->lexer_->add_scope (unsmob_book ($1)->header_);
741 Book *book = unsmob_book ($1);
743 book->scores_ = SCM_EOL;
744 book->bookparts_ = SCM_EOL;
749 BOOKPART '{' bookpart_body '}' {
751 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
757 Book *book = new Book;
758 book->origin ()->set_spot (@$);
759 $$ = book->unprotect ();
760 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
763 unsmob_book ($1)->origin ()->set_spot (@$);
764 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
766 | bookpart_body paper_block {
767 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
769 | bookpart_body score_block {
770 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
771 scm_call_2 (proc, $1, $2);
773 | bookpart_body composite_music {
774 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
775 scm_call_3 (proc, parser->self_scm (), $1, $2);
777 | bookpart_body full_markup {
778 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
779 scm_call_2 (proc, $1, scm_list_1 ($2));
781 | bookpart_body full_markup_list {
782 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
783 scm_call_2 (proc, $1, $2);
785 | bookpart_body SCM_TOKEN {
786 // Evaluate and ignore #xxx, as opposed to \xxx
787 parser->lexer_->eval_scm_token ($2);
789 | bookpart_body embedded_scm_active
791 SCM out = SCM_UNDEFINED;
792 if (Text_interface::is_markup ($2))
793 out = scm_list_1 ($2);
794 else if (Text_interface::is_markup_list ($2))
796 if (scm_is_pair (out))
798 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
799 scm_call_2 (proc, $1, out);
800 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
801 parser->parser_error (@2, _("bad expression type"));
805 Book *book = unsmob_book ($1);
806 if (!ly_is_module (book->header_))
807 book->header_ = ly_make_module (false);
808 parser->lexer_->add_scope (book->header_);
810 | bookpart_body error {
811 Book *book = unsmob_book ($1);
813 book->scores_ = SCM_EOL;
818 SCORE '{' score_body '}' {
825 SCM scorify = ly_lily_module_constant ("scorify-music");
826 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
828 unsmob_score ($$)->origin ()->set_spot (@$);
830 | embedded_scm_active {
832 if (unsmob_score ($1))
833 score = new Score (*unsmob_score ($1));
836 parser->parser_error (@1, _("score expected"));
838 unsmob_score ($$)->origin ()->set_spot (@$);
839 $$ = score->unprotect ();
843 Score *score = unsmob_score ($1);
844 if (!ly_is_module (score->get_header ()))
845 score->set_header (ly_make_module (false));
846 parser->lexer_->add_scope (score->get_header ());
848 | score_body output_def {
849 Output_def *od = unsmob_output_def ($2);
850 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
852 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
857 unsmob_score ($1)->add_output_def (od);
861 unsmob_score ($$)->error_found_ = true;
872 Output_def *od = unsmob_output_def ($1);
874 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
876 parser->parser_error (@1, _ ("need \\paper for paper block"));
877 $$ = get_paper (parser)->unprotect ();
884 output_def_body '}' {
887 parser->lexer_->remove_scope ();
888 parser->lexer_->pop_state ();
894 Output_def *p = get_paper (parser);
895 p->input_origin_ = @$;
896 parser->lexer_->add_scope (p->scope_);
897 $$ = p->unprotect ();
900 Output_def *p = get_midi (parser);
901 $$ = p->unprotect ();
902 parser->lexer_->add_scope (p->scope_);
905 Output_def *p = get_layout (parser);
907 parser->lexer_->add_scope (p->scope_);
908 $$ = p->unprotect ();
912 output_def_head_with_mode_switch:
914 parser->lexer_->push_initial_state ();
919 // We need this weird nonterminal because both music as well as a
920 // context definition can start with \context and the difference is
921 // only apparent after looking at the next token. If it is '{', there
922 // is still time to escape from notes mode.
924 music_or_context_def:
927 parser->lexer_->pop_state ();
931 parser->lexer_->pop_state ();
932 } '{' context_def_spec_body '}'
939 output_def_head_with_mode_switch '{' {
941 unsmob_output_def ($$)->input_origin_.set_spot (@$);
943 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
944 Output_def *o = unsmob_output_def ($3);
945 o->input_origin_.set_spot (@$);
947 parser->lexer_->remove_scope ();
948 parser->lexer_->add_scope (o->scope_);
950 | output_def_body assignment {
953 | output_def_body embedded_scm {
958 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
959 parser->lexer_->push_note_state (nn);
960 } music_or_context_def
962 if (unsmob_context_def ($3))
963 assign_context_def (unsmob_output_def ($1), $3);
966 SCM proc = parser->lexer_->lookup_identifier
967 ("output-def-music-handler");
968 scm_call_3 (proc, parser->self_scm (),
972 | output_def_body error {
978 TEMPO steno_duration '=' tempo_range {
979 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
981 | TEMPO scalar_closed steno_duration '=' tempo_range {
982 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
985 $$ = MAKE_SYNTAX ("tempo", @$, $2);
990 The representation of a list is reversed to have efficient append. */
996 | music_list music_embedded {
997 if (unsmob_music ($2))
998 $$ = scm_cons ($2, $1);
1000 | music_list error {
1001 Music *m = MY_MAKE_MUSIC("Music", @$);
1003 m->set_property ("error-found", SCM_BOOL_T);
1004 $$ = scm_cons (m->self_scm (), $1);
1005 m->unprotect (); /* UGH */
1012 $$ = scm_reverse_x ($2, SCM_EOL);
1017 | lyric_element_music
1024 if (unsmob_music ($1)
1025 || scm_is_eq ($1, SCM_UNSPECIFIED))
1029 @$.warning (_ ("Ignoring non-music expression"));
1030 $$ = SCM_UNSPECIFIED;
1038 $$ = make_music_from_simple (parser, @1, $1);
1039 if (!unsmob_music ($$))
1040 parser->parser_error (@1, _ ("music expected"));
1042 | composite_music %prec COMPOSITE
1047 | composite_music %prec COMPOSITE
1051 REPEAT simple_string unsigned_number music
1053 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1055 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1057 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1062 SEQUENTIAL braced_music_list {
1063 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1065 | braced_music_list {
1066 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1071 SIMULTANEOUS braced_music_list {
1072 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1074 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1075 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1081 | music_property_def
1085 context_modification:
1086 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1088 parser->lexer_->pop_state ();
1091 | WITH CONTEXT_MOD_IDENTIFIER
1095 | CONTEXT_MOD_IDENTIFIER
1099 | WITH embedded_scm_closed
1101 if (unsmob_context_mod ($2))
1104 parser->parser_error (@2, _ ("not a context mod"));
1105 $$ = Context_mod ().smobbed_copy ();
1110 optional_context_mod:
1114 | context_modification
1122 $$ = Context_mod ().smobbed_copy ();
1124 | context_mod_list context_mod {
1125 if (!SCM_UNBNDP ($2))
1126 unsmob_context_mod ($1)->add_context_mod ($2);
1128 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1129 Context_mod *md = unsmob_context_mod ($2);
1131 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1133 | context_mod_list context_mod_embedded {
1134 unsmob_context_mod ($1)->add_context_mods
1135 (unsmob_context_mod ($2)->get_mods ());
1144 /* Music that can be parsed without lookahead */
1147 | complex_music_prefix closed_music
1149 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1151 | music_function_call_closed
1157 | grouped_music_list
1161 simultaneous_music { $$ = $1; }
1162 | sequential_music { $$ = $1; }
1165 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1166 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1167 and this rule returns the reversed list of arguments. */
1169 /* Function argument lists come in a number of flavors. Whenever
1170 * LilyPond has to pick between different flavors, the decision is
1171 * either made because of tokens it has already seen, or it is
1172 * postponed until tokens suitable for making the decision come up.
1173 * For postponing decisions, it may be necessary that the competing
1174 * rules are written in a way making them compatible until a decision
1175 * can be made. Sometimes this is done by putting common traits into
1176 * a separate "common" rule set.
1178 * function_arglist: a full argument list. Optional arguments at the
1179 * end of the list can only be skipped by writing \default in their
1182 * function_arglist_backup: an argument list ending in an optional
1183 * argument that may be skipped depending on its predicate.
1185 * function_arglist_skip: an argument list _not_ ending in an optional
1186 * argument that is actually taken.
1188 * function_arglist_nonbackup: an argument list ending in an optional
1189 * argument that may not be skipped because it is in end position and
1190 * has not been shortcircuited with \default.
1192 * function_arglist* / function_arglist_closed*: The closed variants
1193 * don't end in simple music expressions that might still accept
1194 * things like a duration or a postevent.
1197 function_arglist_skip:
1198 function_arglist_common
1199 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1201 $$ = scm_cons ($1, $3);
1202 } %prec FUNCTION_ARGLIST
1203 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1205 $$ = scm_cons ($1, $3);
1206 } %prec FUNCTION_ARGLIST
1207 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1209 $$ = scm_cons ($1, $3);
1210 } %prec FUNCTION_ARGLIST
1214 function_arglist_nonbackup_common:
1215 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1216 $$ = scm_cons ($4, $3);
1218 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1219 $$ = scm_cons ($4, $3);
1221 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1223 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1225 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1227 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1229 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1231 SCM n = scm_difference ($5, SCM_UNDEFINED);
1232 if (scm_is_true (scm_call_1 ($2, n)))
1233 $$ = scm_cons (n, $3);
1235 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1236 t->set_property ("digit", $5);
1237 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1242 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1244 $$ = check_scheme_arg (parser, @4,
1245 scm_difference ($5, SCM_UNDEFINED),
1248 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1250 $$ = check_scheme_arg (parser, @4,
1251 scm_difference ($5, SCM_UNDEFINED),
1256 function_arglist_closed_nonbackup:
1257 function_arglist_nonbackup_common
1258 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1260 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1262 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1264 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1266 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1268 $$ = check_scheme_arg (parser, @4,
1269 try_string_variants ($2, $4),
1272 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1274 $$ = check_scheme_arg (parser, @4,
1275 try_string_variants ($2, $4),
1278 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1280 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1286 | SYMBOL_LIST '.' symbol_list_rev
1288 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1294 | symbol_list_rev '.' symbol_list_part
1296 $$ = scm_append_x (scm_list_2 ($3, $1));
1300 // symbol_list_part delivers elements in reverse copy.
1305 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1306 $$ = try_string_variants (sym_l_p, $1);
1307 if (SCM_UNBNDP ($$)) {
1308 parser->parser_error (@1, _("not a symbol"));
1311 $$ = scm_reverse ($$);
1316 symbol_list_element:
1322 function_arglist_nonbackup:
1323 function_arglist_nonbackup_common
1324 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1326 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1328 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1330 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1332 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1334 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1336 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1338 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1340 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1342 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1346 function_arglist_nonbackup_reparse:
1347 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1350 SCM res = try_string_variants ($2, $4);
1351 if (!SCM_UNBNDP (res))
1352 if (scm_is_pair (res))
1353 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1355 MYREPARSE (@4, $2, SCM_ARG, res);
1356 else if (scm_is_true
1358 ($2, make_music_from_simple
1360 MYREPARSE (@4, $2, STRING, $4);
1362 MYREPARSE (@4, $2, SCM_ARG, $4);
1364 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1367 SCM res = try_string_variants ($2, $4);
1368 if (!SCM_UNBNDP (res))
1369 if (scm_is_pair (res))
1370 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1372 MYREPARSE (@4, $2, SCM_ARG, res);
1373 else if (scm_is_true
1375 ($2, make_music_from_simple
1377 MYREPARSE (@4, $2, STRING, $4);
1379 MYREPARSE (@4, $2, SCM_ARG, $4);
1381 | EXPECT_OPTIONAL EXPECT_SCM function_arglist lyric_markup
1384 if (scm_is_true (scm_call_1 ($2, $4)))
1385 MYREPARSE (@4, $2, SCM_ARG, $4);
1386 else if (scm_is_true
1388 ($2, make_music_from_simple
1390 MYREPARSE (@4, $2, STRING, $4);
1392 MYREPARSE (@4, $2, SCM_ARG, $4);
1396 function_arglist_keep:
1397 function_arglist_common
1398 | function_arglist_backup
1401 function_arglist_closed_keep:
1402 function_arglist_closed_common
1403 | function_arglist_backup
1406 function_arglist_backup:
1407 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1409 if (scm_is_true (scm_call_1 ($2, $4)))
1411 $$ = scm_cons ($4, $3);
1413 $$ = scm_cons (loc_on_music (@3, $1), $3);
1414 MYBACKUP (SCM_ARG, $4, @4);
1417 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1419 if (scm_is_true (scm_call_1 ($2, $4)))
1421 $$ = scm_cons ($4, $3);
1423 $$ = scm_cons (loc_on_music (@3, $1), $3);
1424 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1427 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_markup
1429 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 (LYRIC_ELEMENT, $4, @4);
1436 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1438 if (scm_is_true (scm_call_1 ($2, $4)))
1441 MYREPARSE (@4, $2, UNSIGNED, $4);
1443 $$ = scm_cons (loc_on_music (@3, $1), $3);
1444 MYBACKUP (UNSIGNED, $4, @4);
1447 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1449 if (scm_is_true (scm_call_1 ($2, $4)))
1452 MYREPARSE (@4, $2, REAL, $4);
1454 $$ = scm_cons (loc_on_music (@3, $1), $3);
1455 MYBACKUP (REAL, $4, @4);
1458 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1460 if (scm_is_true (scm_call_1 ($2, $4)))
1462 $$ = scm_cons ($4, $3);
1464 $$ = scm_cons (loc_on_music (@3, $1), $3);
1465 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1468 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1470 if (scm_is_true (scm_call_1 ($2, $4)))
1472 $$ = scm_cons ($4, $3);
1474 $$ = scm_cons (loc_on_music (@3, $1), $3);
1475 MYBACKUP (FRACTION, $4, @4);
1478 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1480 SCM n = scm_difference ($5, SCM_UNDEFINED);
1481 if (scm_is_true (scm_call_1 ($2, n))) {
1483 MYREPARSE (@5, $2, REAL, n);
1485 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1486 t->set_property ("digit", $5);
1487 $$ = t->unprotect ();
1488 if (scm_is_true (scm_call_1 ($2, $$)))
1489 $$ = scm_cons ($$, $3);
1491 $$ = scm_cons (loc_on_music (@3, $1), $3);
1492 MYBACKUP (UNSIGNED, $5, @5);
1493 parser->lexer_->push_extra_token ('-');
1498 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1500 SCM n = scm_difference ($5, SCM_UNDEFINED);
1501 if (scm_is_true (scm_call_1 ($2, n))) {
1502 MYREPARSE (@5, $2, REAL, n);
1505 $$ = scm_cons (loc_on_music (@3, $1), $3);
1506 MYBACKUP (REAL, n, @5);
1509 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1511 SCM n = scm_difference ($5, SCM_UNDEFINED);
1512 if (scm_is_true (scm_call_1 ($2, n))) {
1513 $$ = scm_cons (n, $3);
1515 $$ = scm_cons (loc_on_music (@3, $1), $3);
1516 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1519 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1521 $$ = scm_cons ($4, $3);
1523 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1525 $$ = scm_cons ($4, $3);
1527 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1529 SCM res = try_string_variants ($2, $4);
1530 if (!SCM_UNBNDP (res))
1531 if (scm_is_pair (res)) {
1533 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1536 $$ = scm_cons (res, $3);
1538 $$ = scm_cons (loc_on_music (@3, $1), $3);
1539 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1542 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1544 SCM res = try_string_variants ($2, $4);
1545 if (!SCM_UNBNDP (res))
1546 if (scm_is_pair (res)) {
1548 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1551 $$ = scm_cons (res, $3);
1553 $$ = scm_cons (loc_on_music (@3, $1), $3);
1554 MYBACKUP (STRING, $4, @4);
1557 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1559 $$ = scm_cons ($1, $3);
1560 MYBACKUP(0, SCM_UNDEFINED, @3);
1562 | function_arglist_backup REPARSE bare_number
1564 $$ = check_scheme_arg (parser, @3,
1567 | function_arglist_backup REPARSE symbol_list_arg
1569 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1574 function_arglist_common
1575 | function_arglist_nonbackup
1578 function_arglist_common:
1579 function_arglist_bare
1580 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1582 $$ = check_scheme_arg (parser, @3,
1585 | EXPECT_SCM function_arglist_closed_optional bare_number
1587 $$ = check_scheme_arg (parser, @3,
1590 | EXPECT_SCM function_arglist_optional FRACTION
1592 $$ = check_scheme_arg (parser, @3,
1595 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1597 $$ = check_scheme_arg (parser, @3,
1600 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1602 SCM n = scm_difference ($4, SCM_UNDEFINED);
1603 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1605 | function_arglist_common_reparse REPARSE SCM_ARG
1607 $$ = check_scheme_arg (parser, @3,
1610 | function_arglist_common_reparse REPARSE lyric_element_music
1612 $$ = check_scheme_arg (parser, @3,
1615 | function_arglist_common_reparse REPARSE bare_number
1617 $$ = check_scheme_arg (parser, @3,
1620 | function_arglist_common_reparse REPARSE symbol_list_arg
1622 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1626 function_arglist_common_reparse:
1627 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1630 SCM res = try_string_variants ($1, $3);
1631 if (!SCM_UNBNDP (res))
1632 if (scm_is_pair (res))
1633 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1635 MYREPARSE (@3, $1, SCM_ARG, res);
1636 else if (scm_is_true
1638 ($1, make_music_from_simple (parser, @3, $3))))
1639 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1641 // This is going to flag a syntax error, we
1642 // know the predicate to be false.
1643 MYREPARSE (@3, $1, SCM_ARG, $3);
1645 | EXPECT_SCM function_arglist_optional STRING
1648 SCM res = try_string_variants ($1, $3);
1649 if (!SCM_UNBNDP (res))
1650 if (scm_is_pair (res))
1651 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1653 MYREPARSE (@3, $1, SCM_ARG, res);
1654 else if (scm_is_true
1656 ($1, make_music_from_simple (parser, @3, $3))))
1657 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1659 // This is going to flag a syntax error, we
1660 // know the predicate to be false.
1661 MYREPARSE (@3, $1, SCM_ARG, $3);
1663 | EXPECT_SCM function_arglist_optional lyric_markup
1666 if (scm_is_true (scm_call_1 ($1, $3)))
1667 MYREPARSE (@3, $1, SCM_ARG, $3);
1668 else if (scm_is_true
1670 ($1, make_music_from_simple (parser, @3, $3))))
1671 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1673 // This is going to flag a syntax error, we
1674 // know the predicate to be false.
1675 MYREPARSE (@3, $1, SCM_ARG, $3);
1677 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1680 SCM n = scm_difference ($4, SCM_UNDEFINED);
1681 if (scm_is_true (scm_call_1 ($1, n)))
1682 MYREPARSE (@4, $1, REAL, n);
1684 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1685 t->set_property ("digit", $4);
1686 SCM m = t->unprotect ();
1687 if (scm_is_true (scm_call_1 ($1, m)))
1688 MYREPARSE (@4, $1, SCM_ARG, m);
1690 MYREPARSE (@4, $1, SCM_ARG, $4);
1694 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1697 SCM n = scm_difference ($4, SCM_UNDEFINED);
1698 MYREPARSE (@4, $1, REAL, n);
1702 function_arglist_closed:
1703 function_arglist_closed_common
1704 | function_arglist_closed_nonbackup
1707 function_arglist_closed_common:
1708 function_arglist_bare
1709 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1711 $$ = check_scheme_arg (parser, @3,
1714 | EXPECT_SCM function_arglist_closed_optional bare_number
1716 $$ = check_scheme_arg (parser, @3,
1719 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1721 $$ = check_scheme_arg (parser, @3,
1722 scm_difference ($4, SCM_UNDEFINED),
1725 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1727 $$ = check_scheme_arg (parser, @3,
1730 | EXPECT_SCM function_arglist_optional FRACTION
1732 $$ = check_scheme_arg (parser, @3,
1735 | function_arglist_common_reparse REPARSE SCM_ARG
1737 $$ = check_scheme_arg (parser, @3,
1740 | function_arglist_common_reparse REPARSE bare_number
1742 $$ = check_scheme_arg (parser, @3,
1745 | function_arglist_common_reparse REPARSE symbol_list_arg
1747 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1751 function_arglist_optional:
1752 function_arglist_keep %prec FUNCTION_ARGLIST
1753 | function_arglist_backup BACKUP
1754 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1756 $$ = scm_cons ($1, $3);
1758 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1760 $$ = scm_cons ($1, $3);
1764 function_arglist_closed_optional:
1765 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1766 | function_arglist_backup BACKUP
1767 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1769 $$ = scm_cons ($1, $3);
1771 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1773 $$ = scm_cons ($1, $3);
1777 embedded_scm_closed:
1779 | scm_function_call_closed
1782 embedded_scm_arg_closed:
1783 embedded_scm_bare_arg
1784 | scm_function_call_closed
1788 scm_function_call_closed:
1789 SCM_FUNCTION function_arglist_closed {
1790 $$ = MAKE_SYNTAX ("music-function", @$,
1792 } %prec FUNCTION_ARGLIST
1795 function_arglist_bare:
1796 EXPECT_NO_MORE_ARGS {
1799 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1800 $$ = scm_cons ($3, $2);
1802 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1803 $$ = scm_cons ($3, $2);
1805 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1806 $$ = scm_cons ($1, $3);
1808 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1809 $$ = scm_cons ($1, $3);
1811 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1812 $$ = scm_cons ($1, $3);
1816 music_function_call:
1817 MUSIC_FUNCTION function_arglist {
1818 $$ = MAKE_SYNTAX ("music-function", @$,
1825 /**/ { $$ = SCM_EOL; }
1826 | '=' simple_string {
1833 | repeated_music { $$ = $1; }
1834 | re_rhythmed_music { $$ = $1; }
1835 | complex_music_prefix music
1837 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1841 complex_music_prefix:
1842 CONTEXT simple_string optional_id optional_context_mod {
1843 Context_mod *ctxmod = unsmob_context_mod ($4);
1846 mods = ctxmod->get_mods ();
1847 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1849 | NEWCONTEXT simple_string optional_id optional_context_mod {
1850 Context_mod *ctxmod = unsmob_context_mod ($4);
1853 mods = ctxmod->get_mods ();
1854 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1859 mode_changing_head grouped_music_list {
1860 if ($1 == ly_symbol2scm ("chords"))
1862 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1868 parser->lexer_->pop_state ();
1870 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1871 Context_mod *ctxmod = unsmob_context_mod ($2);
1874 mods = ctxmod->get_mods ();
1875 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1876 if ($1 == ly_symbol2scm ("ChordNames"))
1878 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1880 parser->lexer_->pop_state ();
1886 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1887 parser->lexer_->push_note_state (nn);
1889 $$ = ly_symbol2scm ("notes");
1893 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1894 parser->lexer_->push_note_state (nn);
1896 $$ = ly_symbol2scm ("drums");
1899 parser->lexer_->push_figuredbass_state ();
1901 $$ = ly_symbol2scm ("figures");
1904 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1905 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1906 nn = parser->lexer_->lookup_identifier ("pitchnames");
1907 parser->lexer_->push_chord_state (nn);
1908 $$ = ly_symbol2scm ("chords");
1912 { parser->lexer_->push_lyric_state ();
1913 $$ = ly_symbol2scm ("lyrics");
1917 mode_changing_head_with_context:
1919 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1920 parser->lexer_->push_note_state (nn);
1922 $$ = ly_symbol2scm ("DrumStaff");
1925 parser->lexer_->push_figuredbass_state ();
1927 $$ = ly_symbol2scm ("FiguredBass");
1930 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1931 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1932 nn = parser->lexer_->lookup_identifier ("pitchnames");
1933 parser->lexer_->push_chord_state (nn);
1934 $$ = ly_symbol2scm ("ChordNames");
1937 { parser->lexer_->push_lyric_state ();
1938 $$ = ly_symbol2scm ("Lyrics");
1943 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1946 /* Can also use music at the expensive of two S/Rs similar to
1947 \repeat \alternative */
1948 parser->lexer_->pop_state ();
1950 $$ = scm_cons ($3, SCM_EOL);
1952 | new_lyrics ADDLYRICS {
1953 parser->lexer_->push_lyric_state ();
1955 parser->lexer_->pop_state ();
1956 $$ = scm_cons ($4, $1);
1961 composite_music new_lyrics {
1962 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1964 | LYRICSTO simple_string {
1965 parser->lexer_->push_lyric_state ();
1967 parser->lexer_->pop_state ();
1968 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1973 CHANGE STRING '=' STRING {
1974 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1981 $$ = scm_reverse_x ($1, SCM_EOL);
1983 | symbol_list_rev property_path {
1984 $$ = scm_reverse_x ($1, $2);
1990 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1991 scm_string_to_symbol ($1), $3);
1993 | UNSET simple_string {
1994 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1995 scm_string_to_symbol ($2));
1997 | OVERRIDE property_path '=' scalar {
1998 if (scm_ilength ($2) < 2) {
1999 parser->parser_error (@2, _("bad grob property path"));
2002 $$ = scm_cons (ly_symbol2scm ("push"),
2003 scm_cons2 (scm_car ($2),
2008 | REVERT revert_arg {
2009 $$ = scm_list_3 (ly_symbol2scm ("pop"),
2015 // This is all quite awkward for the sake of substantial backward
2016 // compatibility while at the same time allowing a more "natural" form
2017 // of specification not separating grob specification from grob
2018 // property path. The purpose of this definition of revert_arg is to
2019 // allow the symbol list which specifies grob and property to revert
2020 // to be optionally be split into two parts after the grob (which in
2021 // this case is just the first element of the list). symbol_list_part
2022 // is only one path component, but it can be parsed without lookahead,
2023 // so we can follow it with a synthetic BACKUP token when needed. If
2024 // the first symbol_list_part already contains multiple elements (only
2025 // possible if a Scheme expression provides them), we just parse for
2026 // additional elements introduced by '.', which is what the
2027 // SYMBOL_LIST backup in connection with the immediately following
2028 // rule using symbol_list_arg does.
2030 // As long as we don't have our coffers filled with both grob and at
2031 // least one grob property specification, the rest of the required
2032 // symbol list chain may be provided either with or without a leading
2033 // dot. This is for both allowing the traditional
2034 // \revert Accidental #'color
2035 // as well as well as the "naive" form
2036 // \revert Accidental.color
2041 if (scm_is_null ($1)
2042 || scm_is_null (scm_cdr ($1)))
2043 MYBACKUP (SCM_ARG, $1, @1);
2045 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2047 | revert_arg BACKUP symbol_list_arg
2053 // revert_arg_part delivers results in reverse
2056 | revert_arg BACKUP SCM_ARG '.' symbol_list_part
2058 $$ = scm_append_x (scm_list_2 ($5, $3));
2060 | revert_arg BACKUP SCM_ARG symbol_list_part
2062 $$ = scm_append_x (scm_list_2 ($4, $3));
2067 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2068 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2070 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2071 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2072 | DENIES { $$ = ly_symbol2scm ("denies"); }
2074 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2075 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2076 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2077 | NAME { $$ = ly_symbol2scm ("context-name"); }
2081 property_operation { $$ = $1; }
2082 | context_def_mod STRING {
2083 $$ = scm_list_2 ($1, $2);
2085 | context_def_mod embedded_scm
2087 if (!scm_is_string ($2)
2088 && ly_symbol2scm ("consists") != $1
2089 && ly_symbol2scm ("remove") != $1)
2092 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2096 $$ = scm_list_2 ($1, $2);
2101 // If defined, at least two members.
2105 SCM l = scm_reverse_x ($1, SCM_EOL);
2108 (scm_object_property (scm_car (l),
2109 ly_symbol2scm ("is-grob?"))))
2110 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2111 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2112 parser->parser_error (@1, _ ("bad grob property path"));
2119 // If defined, at least three members
2123 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2125 parser->parser_error (@1, _ ("bad grob property path"));
2129 | grob_prop_spec property_path
2131 if (!SCM_UNBNDP ($1)) {
2132 $$ = scm_append_x (scm_list_2 ($1, $2));
2133 if (scm_is_null (scm_cddr ($$))) {
2134 parser->parser_error (@$, _ ("bad grob property path"));
2142 // Exactly two elements or undefined
2146 SCM l = scm_reverse_x ($1, SCM_EOL);
2147 switch (scm_ilength (l)) {
2149 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2153 parser->parser_error (@1, _ ("bad context property path"));
2160 simple_music_property_def:
2161 OVERRIDE grob_prop_path '=' scalar {
2162 if (SCM_UNBNDP ($2))
2165 $$ = scm_list_5 (scm_car ($2),
2166 ly_symbol2scm ("OverrideProperty"),
2172 | REVERT simple_revert_context revert_arg {
2173 $$ = scm_list_4 ($2,
2174 ly_symbol2scm ("RevertProperty"),
2178 | SET context_prop_spec '=' scalar {
2179 if (SCM_UNBNDP ($2))
2182 $$ = scm_list_4 (scm_car ($2),
2183 ly_symbol2scm ("PropertySet"),
2187 | UNSET context_prop_spec {
2188 if (SCM_UNBNDP ($2))
2191 $$ = scm_list_3 (scm_car ($2),
2192 ly_symbol2scm ("PropertyUnset"),
2198 // This is all quite awkward for the sake of substantial backward
2199 // compatibility while at the same time allowing a more "natural" form
2200 // of specification not separating grob specification from grob
2201 // property path. The purpose of this definition of
2202 // simple_revert_context is to allow the symbol list which specifies
2203 // grob and property to revert to be optionally be split into two
2204 // parts after the grob (which may be preceded by a context
2205 // specification, a case which we distinguish by checking whether the
2206 // first symbol is a valid grob symbol instead).
2208 // See revert_arg above for the main work horse of this arrangement.
2209 // simple_revert_context just caters for the context and delegates the
2210 // rest of the job to revert_arg.
2212 simple_revert_context:
2215 $1 = scm_reverse_x ($1, SCM_EOL);
2216 if (scm_is_null ($1)
2218 (scm_object_property (scm_car ($1),
2219 ly_symbol2scm ("is-grob?")))) {
2220 $$ = ly_symbol2scm ("Bottom");
2221 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2224 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2231 simple_music_property_def {
2232 if (SCM_UNBNDP ($1))
2233 $$ = MAKE_SYNTAX ("void-music", @1);
2235 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2244 | string '+' string {
2245 if (!scm_is_string ($1)) {
2246 parser->parser_error (@1, (_ ("simple string expected")));
2247 $1 = scm_string (SCM_EOL);
2249 if (!scm_is_string ($3)) {
2250 parser->parser_error (@3, (_ ("simple string expected")));
2251 $3 = scm_string (SCM_EOL);
2253 $$ = scm_string_append (scm_list_2 ($1, $3));
2257 simple_string: STRING {
2262 if (scm_is_string ($1)) {
2265 parser->parser_error (@1, (_ ("simple string expected")));
2266 $$ = scm_string (SCM_EOL);
2280 embedded_scm_arg_closed
2289 simple_element post_events {
2290 // Let the rhythmic music iterator sort this mess out.
2291 if (scm_is_pair ($2)) {
2292 $$ = make_music_from_simple (parser, @1, $1);
2293 if (unsmob_music ($$))
2294 unsmob_music ($$)->set_property ("articulations",
2295 scm_reverse_x ($2, SCM_EOL));
2297 parser->parser_error (@1, _("music expected"));
2300 | simple_chord_elements post_events {
2301 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2304 /* why is this giving wrong start location? -ns
2306 i.set_location (@1, @2);
2307 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2309 | CHORD_REPETITION optional_notemode_duration post_events {
2311 i.set_location (@1, @3);
2312 $$ = MAKE_SYNTAX ("repetition-chord", i,
2313 $2, scm_reverse_x ($3, SCM_EOL));
2315 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2317 i.set_location (@1, @3);
2318 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2319 scm_reverse_x ($3, SCM_EOL));
2322 | note_chord_element
2327 chord_body optional_notemode_duration post_events
2329 Music *m = unsmob_music ($1);
2330 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2331 SCM es = m->get_property ("elements");
2332 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2334 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2335 unsmob_music (scm_car (s))->set_property ("duration", dur);
2336 es = ly_append2 (es, postevs);
2338 m-> set_property ("elements", es);
2340 $$ = m->self_scm ();
2345 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2347 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2351 chord_body_elements:
2352 /* empty */ { $$ = SCM_EOL; }
2353 | chord_body_elements chord_body_element {
2354 if (!SCM_UNBNDP ($2))
2355 $$ = scm_cons ($2, $1);
2360 pitch exclamations questions octave_check post_events
2362 bool q = to_boolean ($3);
2363 bool ex = to_boolean ($2);
2367 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2368 n->set_property ("pitch", $1);
2370 n->set_property ("cautionary", SCM_BOOL_T);
2372 n->set_property ("force-accidental", SCM_BOOL_T);
2374 if (scm_is_pair (post)) {
2375 SCM arts = scm_reverse_x (post, SCM_EOL);
2376 n->set_property ("articulations", arts);
2378 if (scm_is_number (check))
2380 int q = scm_to_int (check);
2381 n->set_property ("absolute-octave", scm_from_int (q-1));
2384 $$ = n->unprotect ();
2386 | DRUM_PITCH post_events {
2387 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2388 n->set_property ("drum-type", $1);
2390 if (scm_is_pair ($2)) {
2391 SCM arts = scm_reverse_x ($2, SCM_EOL);
2392 n->set_property ("articulations", arts);
2394 $$ = n->unprotect ();
2396 | music_function_chord_body
2398 Music *m = unsmob_music ($1);
2400 while (m && m->is_mus_type ("music-wrapper-music")) {
2401 $$ = m->get_property ("element");
2402 m = unsmob_music ($$);
2405 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2406 parser->parser_error (@$, _ ("not a rhythmic event"));
2412 music_function_chord_body:
2417 // Event functions may only take closed arglists, otherwise it would
2418 // not be clear whether a following postevent should be associated
2419 // with the last argument of the event function or with the expression
2420 // for which the function call acts itself as event.
2422 music_function_call_closed:
2423 MUSIC_FUNCTION function_arglist_closed {
2424 $$ = MAKE_SYNTAX ("music-function", @$,
2429 event_function_event:
2430 EVENT_FUNCTION function_arglist_closed {
2431 $$ = MAKE_SYNTAX ("music-function", @$,
2441 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2442 m->set_property ("span-direction", scm_from_int (START));
2443 $$ = m->unprotect();
2446 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2447 m->set_property ("span-direction", scm_from_int (STOP));
2448 $$ = m->unprotect ();
2451 $$ = MAKE_SYNTAX ("voice-separator", @$);
2454 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2456 Music *m = unsmob_music (pipe);
2461 $$ = m->unprotect ();
2464 $$ = MAKE_SYNTAX ("bar-check", @$);
2471 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2483 | post_events post_event {
2484 unsmob_music ($2)->set_spot (@2);
2485 $$ = scm_cons ($2, $$);
2489 post_event_nofinger:
2490 direction_less_event {
2493 | script_dir music_function_call_closed {
2495 if (!SCM_UNBNDP ($1))
2497 unsmob_music ($$)->set_property ("direction", $1);
2501 if (!parser->lexer_->is_lyric_state ())
2502 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2503 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2506 if (!parser->lexer_->is_lyric_state ())
2507 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2508 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2510 | script_dir direction_reqd_event {
2511 if (!SCM_UNBNDP ($1))
2513 Music *m = unsmob_music ($2);
2514 m->set_property ("direction", $1);
2518 | script_dir direction_less_event {
2519 if (!SCM_UNBNDP ($1))
2521 Music *m = unsmob_music ($2);
2522 m->set_property ("direction", $1);
2529 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2534 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2545 string_number_event:
2547 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2548 s->set_property ("string-number", $1);
2549 $$ = s->unprotect ();
2553 direction_less_char:
2555 $$ = ly_symbol2scm ("bracketOpenSymbol");
2558 $$ = ly_symbol2scm ("bracketCloseSymbol");
2561 $$ = ly_symbol2scm ("tildeSymbol");
2564 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2567 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2570 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2573 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2576 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2579 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2582 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2586 direction_less_event:
2587 direction_less_char {
2588 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2590 if (unsmob_music (predefd))
2592 m = unsmob_music (predefd)->clone ();
2597 m = MY_MAKE_MUSIC ("Music", @$);
2599 $$ = m->unprotect ();
2601 | string_number_event
2602 | EVENT_IDENTIFIER {
2606 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2607 a->set_property ("tremolo-type", $1);
2608 $$ = a->unprotect ();
2610 | event_function_event
2613 direction_reqd_event:
2617 | script_abbreviation {
2618 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2619 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2620 if (scm_is_string (s))
2621 a->set_property ("articulation-type", s);
2622 else parser->parser_error (@1, _ ("expecting string as script definition"));
2623 $$ = a->unprotect ();
2628 /**/ { $$ = SCM_EOL; }
2629 | '=' quotes { $$ = $2; }
2643 $$ = scm_from_int (1);
2646 $$ = scm_oneplus ($1);
2652 $$ = scm_from_int (-1);
2655 $$ = scm_oneminus ($1);
2660 NOTENAME_PITCH quotes {
2661 if (!scm_is_eq (SCM_INUM0, $2))
2663 Pitch p = *unsmob_pitch ($1);
2664 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2665 $$ = p.smobbed_copy ();
2675 TONICNAME_PITCH quotes {
2676 if (!scm_is_eq (SCM_INUM0, $2))
2678 Pitch p = *unsmob_pitch ($1);
2679 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2680 $$ = p.smobbed_copy ();
2690 pitch_also_in_chords:
2697 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2698 t->set_property ("text", $1);
2699 $$ = t->unprotect ();
2702 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2703 t->set_property ("text",
2704 make_simple_markup ($1));
2705 $$ = t->unprotect ();
2707 | embedded_scm_closed
2709 Music *m = unsmob_music ($1);
2710 if (m && m->is_mus_type ("post-event"))
2712 else if (Text_interface::is_markup ($1)) {
2713 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2714 t->set_property ("text", $1);
2715 $$ = t->unprotect ();
2717 parser->parser_error (@1, _ ("not an articulation"));
2723 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2724 t->set_property ("digit", $1);
2725 $$ = t->unprotect ();
2729 script_abbreviation:
2731 $$ = scm_from_locale_string ("Hat");
2734 $$ = scm_from_locale_string ("Plus");
2737 $$ = scm_from_locale_string ("Dash");
2740 $$ = scm_from_locale_string ("Bar");
2743 $$ = scm_from_locale_string ("Larger");
2746 $$ = scm_from_locale_string ("Dot");
2749 $$ = scm_from_locale_string ("Underscore");
2754 '_' { $$ = scm_from_int (DOWN); }
2755 | '^' { $$ = scm_from_int (UP); }
2756 | '-' { $$ = SCM_UNDEFINED; }
2760 multiplied_duration {
2765 maybe_notemode_duration:
2769 | multiplied_duration {
2771 parser->default_duration_ = *unsmob_duration ($$);
2776 optional_notemode_duration:
2777 maybe_notemode_duration
2779 if (SCM_UNBNDP ($$))
2780 $$ = parser->default_duration_.smobbed_copy ();
2787 int n = scm_to_int ($1);
2788 if (!is_duration (n))
2789 parser->parser_error (@1, _f ("not a duration: %d", n));
2793 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2795 | DURATION_IDENTIFIER dots {
2796 Duration *d = unsmob_duration ($1);
2797 Duration k (d->duration_log (),
2798 d->dot_count () + scm_to_int ($2));
2799 k = k.compressed (d->factor ());
2800 scm_remember_upto_here_1 ($1);
2801 $$ = k.smobbed_copy ();
2805 multiplied_duration:
2809 | multiplied_duration '*' UNSIGNED {
2810 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2812 | multiplied_duration '*' FRACTION {
2813 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2815 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2824 $$ = scm_oneplus ($1);
2833 int n = scm_to_int ($2);
2834 if (!is_duration (n))
2835 parser->parser_error (@2, _f ("not a duration: %d", n));
2841 UNSIGNED { $$ = $1; }
2842 | STRING { $$ = $1; }
2843 | full_markup { $$ = $1; }
2846 // as an integer, it needs to be non-negative, and otherwise
2847 // it needs to be suitable as a markup.
2848 if (scm_is_integer ($1)
2849 ? scm_is_true (scm_negative_p ($1))
2850 : !Text_interface::is_markup ($1))
2852 parser->parser_error (@1, _ ("bass number expected"));
2858 figured_bass_alteration:
2859 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2860 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2861 | '!' { $$ = scm_from_int (0); }
2866 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2867 $$ = bfr->unprotect ();
2870 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2871 $$ = bfr->self_scm ();
2873 if (scm_is_number ($1))
2874 bfr->set_property ("figure", $1);
2875 else if (Text_interface::is_markup ($1))
2876 bfr->set_property ("text", $1);
2882 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2884 | bass_figure figured_bass_alteration {
2885 Music *m = unsmob_music ($1);
2886 if (scm_to_double ($2)) {
2887 SCM salter = m->get_property ("alteration");
2888 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2889 m->set_property ("alteration",
2890 scm_sum (alter, $2));
2892 m->set_property ("alteration", scm_from_int (0));
2895 | bass_figure figured_bass_modification {
2896 Music *m = unsmob_music ($1);
2897 if ($2 == ly_symbol2scm ("plus"))
2899 m->set_property ("augmented", SCM_BOOL_T);
2901 else if ($2 == ly_symbol2scm ("slash"))
2903 m->set_property ("diminished", SCM_BOOL_T);
2905 else if ($2 == ly_symbol2scm ("exclamation"))
2907 m->set_property ("no-continuation", SCM_BOOL_T);
2909 else if ($2 == ly_symbol2scm ("backslash"))
2911 m->set_property ("augmented-slash", SCM_BOOL_T);
2917 figured_bass_modification:
2919 $$ = ly_symbol2scm ("plus");
2922 $$ = ly_symbol2scm ("exclamation");
2925 $$ = ly_symbol2scm ("slash");
2928 $$ = ly_symbol2scm ("backslash");
2938 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2946 | figure_list br_bass_figure {
2947 $$ = scm_cons ($2, $1);
2952 FIGURE_OPEN figure_list FIGURE_CLOSE {
2953 $$ = scm_reverse_x ($2, SCM_EOL);
2959 /**/ { $$ = SCM_BOOL_F; }
2960 | REST { $$ = SCM_BOOL_T; }
2964 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2965 if (!parser->lexer_->is_note_state ())
2966 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2967 if (!SCM_UNBNDP ($2)
2969 || scm_is_number ($4)
2971 || scm_is_true ($6))
2974 if (scm_is_true ($6))
2975 n = MY_MAKE_MUSIC ("RestEvent", @$);
2977 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2979 n->set_property ("pitch", $1);
2980 if (SCM_UNBNDP ($5))
2981 n->set_property ("duration",
2982 parser->default_duration_.smobbed_copy ());
2984 n->set_property ("duration", $5);
2986 if (scm_is_number ($4))
2988 int q = scm_to_int ($4);
2989 n->set_property ("absolute-octave", scm_from_int (q-1));
2992 if (to_boolean ($3))
2993 n->set_property ("cautionary", SCM_BOOL_T);
2994 if (to_boolean ($2) || to_boolean ($3))
2995 n->set_property ("force-accidental", SCM_BOOL_T);
2997 $$ = n->unprotect ();
3000 | DRUM_PITCH optional_notemode_duration {
3001 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3002 n->set_property ("duration", $2);
3003 n->set_property ("drum-type", $1);
3005 $$ = n->unprotect ();
3007 | RESTNAME optional_notemode_duration {
3009 if (ly_scm2string ($1) == "s") {
3011 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3014 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3017 ev->set_property ("duration", $2);
3018 $$ = ev->unprotect ();
3022 simple_chord_elements:
3024 if (!parser->lexer_->is_chord_state ())
3025 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3028 | figure_spec optional_notemode_duration {
3029 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3031 unsmob_music (scm_car (s))->set_property ("duration", $2);
3047 lyric_element_music:
3048 lyric_element optional_notemode_duration post_events {
3049 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3050 if (scm_is_pair ($3))
3051 unsmob_music ($$)->set_property
3052 ("articulations", scm_reverse_x ($3, SCM_EOL));
3057 steno_tonic_pitch optional_notemode_duration {
3058 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3060 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3061 SCM its = scm_reverse_x ($4, SCM_EOL);
3062 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3070 | chord_items chord_item {
3071 $$ = scm_cons ($2, $$);
3077 $$ = ly_symbol2scm ("chord-colon");
3080 $$ = ly_symbol2scm ("chord-caret");
3082 | CHORD_SLASH steno_tonic_pitch {
3083 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3085 | CHORD_BASS steno_tonic_pitch {
3086 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3095 $$ = scm_reverse_x ($1, SCM_EOL);
3103 step_number { $$ = scm_cons ($1, SCM_EOL); }
3104 | step_numbers '.' step_number {
3105 $$ = scm_cons ($3, $$);
3111 $$ = make_chord_step ($1, 0);
3114 $$ = make_chord_step ($1, SHARP_ALTERATION);
3116 | UNSIGNED CHORD_MINUS {
3117 $$ = make_chord_step ($1, FLAT_ALTERATION);
3125 | UNSIGNED '~' UNSIGNED {
3126 $$ = scm_cons ($1, $3);
3133 TODO: should deprecate in favor of Scheme?
3137 number_expression '+' number_term {
3138 $$ = scm_sum ($1, $3);
3140 | number_expression '-' number_term {
3141 $$ = scm_difference ($1, $3);
3150 | number_factor '*' number_factor {
3151 $$ = scm_product ($1, $3);
3153 | number_factor '/' number_factor {
3154 $$ = scm_divide ($1, $3);
3159 '-' number_factor { /* %prec UNARY_MINUS */
3160 $$ = scm_difference ($2, SCM_UNDEFINED);
3168 | UNSIGNED NUMBER_IDENTIFIER {
3169 $$ = scm_product ($1, $2);
3171 | REAL NUMBER_IDENTIFIER {
3172 $$ = scm_product ($1, $2);
3188 { $$ = SCM_UNDEFINED; }
3191 if (SCM_UNBNDP ($1))
3199 { $$ = SCM_UNDEFINED; }
3202 if (SCM_UNBNDP ($1))
3210 This should be done more dynamically if possible.
3215 { parser->lexer_->push_markup_state (); }
3218 parser->lexer_->pop_state ();
3224 { parser->lexer_->push_markup_state (); }
3227 parser->lexer_->pop_state ();
3233 { parser->lexer_->push_markup_state (); }
3236 parser->lexer_->pop_state ();
3242 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3244 | markup_head_1_list simple_markup {
3245 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
3255 if (Text_interface::is_markup ($1))
3256 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3257 else if (Text_interface::is_markup_list ($1))
3258 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3260 parser->parser_error (@1, _ ("not a markup"));
3261 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3268 markup_composed_list {
3271 | markup_braced_list {
3274 | markup_command_list {
3275 $$ = scm_list_1 ($1);
3277 | markup_scm MARKUPLIST_IDENTIFIER
3283 markup_composed_list:
3284 markup_head_1_list markup_braced_list {
3285 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
3291 '{' markup_braced_list_body '}' {
3292 $$ = scm_reverse_x ($2, SCM_EOL);
3296 markup_braced_list_body:
3297 /* empty */ { $$ = SCM_EOL; }
3298 | markup_braced_list_body markup {
3299 $$ = scm_cons ($2, $1);
3301 | markup_braced_list_body markup_list {
3302 $$ = scm_reverse_x ($2, $1);
3306 markup_command_list:
3307 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3308 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3312 markup_command_basic_arguments:
3313 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3314 $$ = scm_cons ($3, $2);
3316 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3317 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3319 | EXPECT_NO_MORE_ARGS {
3324 markup_command_list_arguments:
3325 markup_command_basic_arguments { $$ = $1; }
3326 | EXPECT_MARKUP markup_command_list_arguments markup {
3327 $$ = scm_cons ($3, $2);
3332 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3333 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3338 markup_head_1_item {
3339 $$ = scm_list_1 ($1);
3341 | markup_head_1_list markup_head_1_item {
3342 $$ = scm_cons ($2, $1);
3348 $$ = make_simple_markup ($1);
3351 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3352 parser->lexer_->push_note_state (nn);
3353 } '{' score_body '}' {
3354 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3355 parser->lexer_->pop_state ();
3357 | MARKUP_FUNCTION markup_command_basic_arguments {
3358 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3360 | markup_scm MARKUP_IDENTIFIER
3367 markup_head_1_list simple_markup {
3368 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3369 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3379 Lily_parser::set_yydebug (bool x)
3385 Lily_parser::do_yyparse ()
3387 SCM retval = SCM_UNDEFINED;
3388 yyparse (this, &retval);
3398 It is a little strange to have this function in this file, but
3399 otherwise, we have to import music classes into the lexer.
3403 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3405 if (unsmob_book (sid)) {
3406 Book *book = unsmob_book (sid)->clone ();
3407 *destination = book->self_scm ();
3410 return BOOK_IDENTIFIER;
3411 } else if (scm_is_number (sid)) {
3413 return NUMBER_IDENTIFIER;
3414 } else if (unsmob_context_def (sid)) {
3415 Context_def *def= unsmob_context_def (sid)->clone ();
3417 *destination = def->self_scm ();
3420 return CONTEXT_DEF_IDENTIFIER;
3421 } else if (unsmob_context_mod (sid)) {
3422 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3424 return CONTEXT_MOD_IDENTIFIER;
3425 } else if (Music *mus = unsmob_music (sid)) {
3426 mus = mus->clone ();
3427 *destination = mus->self_scm ();
3428 unsmob_music (*destination)->
3429 set_property ("origin", make_input (last_input_));
3431 bool is_event = mus->is_mus_type ("post-event");
3433 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3434 } else if (unsmob_pitch (sid)) {
3435 *destination = unsmob_pitch (sid)->smobbed_copy ();
3436 return PITCH_IDENTIFIER;
3437 } else if (unsmob_duration (sid)) {
3438 *destination = unsmob_duration (sid)->smobbed_copy ();
3439 return DURATION_IDENTIFIER;
3440 } else if (unsmob_output_def (sid)) {
3441 Output_def *p = unsmob_output_def (sid);
3444 *destination = p->self_scm ();
3446 return OUTPUT_DEF_IDENTIFIER;
3453 get_next_unique_context_id ()
3455 return scm_from_locale_string ("$uniqueContextId");
3460 get_next_unique_lyrics_context_id ()
3462 static int new_context_count;
3464 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3465 return scm_from_locale_string (s);
3468 // check_scheme_arg checks one argument with a given predicate for use
3469 // in an argument list and throws a syntax error if it is unusable.
3470 // The argument is prepended to the argument list in any case. After
3471 // throwing a syntax error, the argument list is terminated with #f as
3472 // its last cdr in order to mark it as uncallable while not losing
3473 // track of its total length.
3475 // There are a few special considerations: if optional argument disp
3476 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3477 // instead of arg in a prospective error message. This is useful if
3478 // arg is not the actual argument but rather a transformation of it.
3480 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3481 // and an error message using disp is produced unconditionally.
3483 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3484 SCM arg, SCM args, SCM pred, SCM disp)
3486 if (SCM_UNBNDP (arg))
3487 args = scm_cons (disp, args);
3489 args = scm_cons (arg, args);
3490 if (scm_is_true (scm_call_1 (pred, arg)))
3493 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3494 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3495 SCM_UNBNDP (disp) ? arg : disp);
3496 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3500 SCM loc_on_music (Input loc, SCM arg)
3502 if (Music *m = unsmob_music (arg))
3506 return m->unprotect ();
3512 try_string_variants (SCM pred, SCM str)
3514 // a matching predicate is always ok
3515 if (scm_is_true (scm_call_1 (pred, str)))
3517 // a symbol may be interpreted as a list of symbols if it helps
3518 if (scm_is_symbol (str)) {
3519 str = scm_list_1 (str);
3520 if (scm_is_true (scm_call_1 (pred, str)))
3522 return SCM_UNDEFINED;
3525 // If this cannot be a string representation of a symbol list,
3528 if (!is_regular_identifier (str, true))
3529 return SCM_UNDEFINED;
3531 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3532 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3533 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3535 // Let's attempt the symbol list interpretation first.
3537 if (scm_is_true (scm_call_1 (pred, str)))
3540 // If there is just one symbol in the list, we might interpret
3541 // it as a single symbol
3543 if (scm_is_null (scm_cdr (str)))
3545 str = scm_car (str);
3546 if (scm_is_true (scm_call_1 (pred, str)))
3550 return SCM_UNDEFINED;
3554 is_regular_identifier (SCM id, bool multiple)
3556 if (!scm_is_string (id))
3559 string str = ly_scm2string (id);
3561 bool middle = false;
3563 for (string::iterator it=str.begin(); it != str.end (); it++)
3566 if ((c >= 'a' && c <= 'z')
3567 || (c >= 'A' && c <= 'Z')
3570 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3579 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3581 if (unsmob_music (simple))
3583 if (parser->lexer_->is_note_state ()) {
3584 if (scm_is_symbol (simple)) {
3585 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3586 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3587 n->set_property ("drum-type", simple);
3588 return n->unprotect ();
3590 if (unsmob_pitch (simple)) {
3591 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3592 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3593 n->set_property ("pitch", simple);
3594 return n->unprotect ();
3597 } else if (parser->lexer_->is_lyric_state ()) {
3598 if (Text_interface::is_markup (simple))
3599 return MAKE_SYNTAX ("lyric-event", loc, simple,
3600 parser->default_duration_.smobbed_copy ());
3601 } else if (parser->lexer_->is_chord_state ()) {
3602 if (unsmob_pitch (simple))
3603 return make_chord_elements (loc, simple,
3604 parser->default_duration_.smobbed_copy (),
3611 make_music_with_input (SCM name, Input where)
3613 Music *m = make_music_by_name (name);
3614 m->set_spot (where);
3619 make_simple_markup (SCM a)
3627 return t && t == 1 << intlog2 (t);
3631 make_chord_step (SCM step_scm, Rational alter)
3633 int step = scm_to_int (step_scm);
3636 alter += FLAT_ALTERATION;
3640 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3641 return m.smobbed_copy ();
3646 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3648 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3649 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3650 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3652 unsmob_music (scm_car (s))->set_spot (loc);
3658 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3660 Lily_lexer *lex = parser->lexer_;
3664 lex->prepare_for_next_token ();
3665 return lex->yylex ();