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 *, const 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) \
198 make_music_with_input (ly_symbol2scm (x), \
199 parser->lexer_->override_input (spot))
202 - Don't use lily module, create a new module instead.
203 - delay application of the function
205 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
206 scm_apply_0 (proc, args)
207 /* Syntactic Sugar. */
208 #define MAKE_SYNTAX(name, location, ...) \
209 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (parser->lexer_->override_input (location)), ##__VA_ARGS__, SCM_UNDEFINED))
210 #define START_MAKE_SYNTAX(name, ...) \
211 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
212 #define FINISH_MAKE_SYNTAX(start, location, ...) \
213 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (parser->lexer_->override_input (location)), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
215 SCM get_next_unique_context_id ();
216 SCM get_next_unique_lyrics_context_id ();
223 #define _(x) gettext (x)
227 static Music *make_music_with_input (SCM name, Input where);
228 SCM check_scheme_arg (Lily_parser *parser, Input loc,
229 SCM arg, SCM args, SCM pred, SCM disp = SCM_UNDEFINED);
230 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
231 SCM loc_on_music (Input loc, SCM arg);
232 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
233 SCM make_chord_step (SCM step, Rational alter);
234 SCM make_simple_markup (SCM a);
235 bool is_duration (int t);
236 bool is_regular_identifier (SCM id, bool multiple=false);
237 SCM try_string_variants (SCM pred, SCM str);
238 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
242 /* The third option is an alias that will be used to display the
243 syntax error. Bison CVS now correctly handles backslash escapes.
245 FIXME: Bison needs to translate some of these, eg, STRING.
249 /* Keyword tokens with plain escaped name. */
250 %token END_OF_FILE 0 "end of input"
251 %token ACCEPTS "\\accepts"
252 %token ADDLYRICS "\\addlyrics"
253 %token ALIAS "\\alias"
254 %token ALTERNATIVE "\\alternative"
256 %token BOOKPART "\\bookpart"
257 %token CHANGE "\\change"
258 %token CHORDMODE "\\chordmode"
259 %token CHORDS "\\chords"
260 %token CONSISTS "\\consists"
261 %token CONTEXT "\\context"
262 %token DEFAULT "\\default"
263 %token DEFAULTCHILD "\\defaultchild"
264 %token DENIES "\\denies"
265 %token DESCRIPTION "\\description"
266 %token DRUMMODE "\\drummode"
267 %token DRUMS "\\drums"
268 %token FIGUREMODE "\\figuremode"
269 %token FIGURES "\\figures"
270 %token HEADER "\\header"
271 %token INVALID "\\version-error"
272 %token LAYOUT "\\layout"
273 %token LYRICMODE "\\lyricmode"
274 %token LYRICS "\\lyrics"
275 %token LYRICSTO "\\lyricsto"
276 %token MARKUP "\\markup"
277 %token MARKUPLIST "\\markuplist"
280 %token NOTEMODE "\\notemode"
281 %token OVERRIDE "\\override"
282 %token PAPER "\\paper"
283 %token REMOVE "\\remove"
284 %token REPEAT "\\repeat"
286 %token REVERT "\\revert"
287 %token SCORE "\\score"
288 %token SEQUENTIAL "\\sequential"
290 %token SIMULTANEOUS "\\simultaneous"
291 %token TEMPO "\\tempo"
293 %token UNSET "\\unset"
296 /* Keyword token exceptions. */
297 %token NEWCONTEXT "\\new"
300 /* Other string tokens. */
302 %token CHORD_BASS "/+"
303 %token CHORD_CARET "^"
304 %token CHORD_COLON ":"
305 %token CHORD_MINUS "-"
306 %token CHORD_SLASH "/"
307 %token ANGLE_OPEN "<"
308 %token ANGLE_CLOSE ">"
309 %token DOUBLE_ANGLE_OPEN "<<"
310 %token DOUBLE_ANGLE_CLOSE ">>"
311 %token E_BACKSLASH "\\"
312 %token E_EXCLAMATION "\\!"
317 If we give names, Bison complains.
319 %token FIGURE_CLOSE /* "\\>" */
320 %token FIGURE_OPEN /* "\\<" */
321 %token FIGURE_SPACE "_"
324 %token CHORDMODIFIERS
325 %token MULTI_MEASURE_REST
331 /* Artificial tokens, for more generic function syntax */
332 %token EXPECT_MARKUP "markup?"
333 %token EXPECT_PITCH "ly:pitch?"
334 %token EXPECT_DURATION "ly:duration?"
335 %token EXPECT_SCM "scheme?"
336 %token BACKUP "(backed-up?)"
337 %token REPARSE "(reparsed?)"
338 %token EXPECT_MARKUP_LIST "markup-list?"
339 %token EXPECT_OPTIONAL "optional?"
340 /* After the last argument. */
341 %token EXPECT_NO_MORE_ARGS;
343 /* An artificial token for parsing embedded Lilypond */
344 %token EMBEDDED_LILY "#{"
346 %token BOOK_IDENTIFIER
347 %token CHORDMODIFIER_PITCH
348 %token CHORD_MODIFIER
349 %token CHORD_REPETITION
350 %token CONTEXT_DEF_IDENTIFIER
351 %token CONTEXT_MOD_IDENTIFIER
353 %token PITCH_IDENTIFIER
354 %token DURATION_IDENTIFIER
355 %token EVENT_IDENTIFIER
356 %token EVENT_FUNCTION
359 %token MARKUP_FUNCTION
360 %token MARKUP_LIST_FUNCTION
361 %token MARKUP_IDENTIFIER
362 %token MARKUPLIST_IDENTIFIER
363 %token MUSIC_FUNCTION
364 %token MUSIC_IDENTIFIER
365 %token NOTENAME_PITCH
366 %token NUMBER_IDENTIFIER
367 %token OUTPUT_DEF_IDENTIFIER
372 %token SCM_IDENTIFIER
376 %token TONICNAME_PITCH
380 /* We don't assign precedence to / and *, because we might need varied
381 prec levels in different prods */
390 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
391 parser->lexer_->push_note_state (nn);
392 } embedded_lilypond {
393 parser->lexer_->pop_state ();
398 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
399 | lilypond toplevel_expression {
401 | lilypond assignment {
404 parser->error_level_ = 1;
407 parser->error_level_ = 1;
414 parser->lexer_->add_scope (get_header (parser));
416 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
419 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
420 scm_call_2 (proc, parser->self_scm (), $1);
423 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
424 scm_call_2 (proc, parser->self_scm (), $1);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
428 scm_call_2 (proc, parser->self_scm (), $1);
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
432 scm_call_2 (proc, parser->self_scm (), $1);
435 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
436 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
439 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
440 scm_call_2 (proc, parser->self_scm (), $1);
443 // Evaluate and ignore #xxx, as opposed to \xxx
444 parser->lexer_->eval_scm_token ($1);
446 | embedded_scm_active
448 SCM out = SCM_UNDEFINED;
449 if (Text_interface::is_markup ($1))
450 out = scm_list_1 ($1);
451 else if (Text_interface::is_markup_list ($1))
453 if (scm_is_pair (out))
455 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
456 scm_call_2 (proc, parser->self_scm (), out);
457 } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
458 parser->parser_error (@1, _("bad expression type"));
462 Output_def * od = unsmob_output_def ($1);
464 if (od->c_variable ("is-paper") == SCM_BOOL_T)
465 id = ly_symbol2scm ("$defaultpaper");
466 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
467 id = ly_symbol2scm ("$defaultmidi");
468 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
469 id = ly_symbol2scm ("$defaultlayout");
471 parser->lexer_->set_identifier (id, $1);
478 $$ = parser->lexer_->eval_scm_token ($1);
488 embedded_scm_bare_arg:
492 $$ = parser->lexer_->eval_scm_token ($1);
495 | context_modification
497 | context_def_spec_block
503 /* The generic version may end in music, or not */
511 embedded_scm_bare_arg
517 SCM_FUNCTION function_arglist {
518 $$ = MAKE_SYNTAX ("music-function", @$,
526 $$ = MAKE_SYNTAX ("void-music", @$);
529 | music_embedded music_embedded music_list {
530 $3 = scm_reverse_x ($3, SCM_EOL);
531 if (unsmob_music ($2))
532 $3 = scm_cons ($2, $3);
533 if (unsmob_music ($1))
534 $3 = scm_cons ($1, $3);
535 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
538 parser->error_level_ = 1;
539 $$ = SCM_UNSPECIFIED;
541 | INVALID embedded_lilypond {
542 parser->error_level_ = 1;
548 lilypond_header_body:
549 /* empty */ { $$ = SCM_UNSPECIFIED; }
550 | lilypond_header_body assignment {
553 | lilypond_header_body embedded_scm {
559 HEADER '{' lilypond_header_body '}' {
560 $$ = parser->lexer_->remove_scope ();
572 assignment_id '=' identifier_init {
573 parser->lexer_->set_identifier ($1, $3);
574 $$ = SCM_UNSPECIFIED;
576 | assignment_id property_path '=' identifier_init {
577 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
578 parser->lexer_->set_identifier (path, $4);
579 $$ = SCM_UNSPECIFIED;
589 | context_def_spec_block
591 | post_event_nofinger post_events
593 $$ = scm_reverse_x ($2, SCM_EOL);
594 if (Music *m = unsmob_music ($1))
596 if (m->is_mus_type ("post-event-wrapper"))
598 (scm_list_2 (m->get_property ("elements"),
601 $$ = scm_cons ($1, $$);
604 && scm_is_null (scm_cdr ($$)))
608 Music * m = MY_MAKE_MUSIC ("PostEvents", @$);
609 m->set_property ("elements", $$);
610 $$ = m->unprotect ();
618 | context_modification
621 context_def_spec_block:
622 CONTEXT '{' context_def_spec_body '}'
632 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
633 parser->lexer_->push_note_state (nn);
637 parser->lexer_->pop_state ();
642 context_mod_embedded:
645 if (unsmob_music ($1)) {
646 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
647 $1 = scm_call_2 (proc, parser->self_scm (), $1);
649 if (unsmob_context_mod ($1))
652 parser->parser_error (@1, _ ("not a context mod"));
658 context_def_spec_body:
660 $$ = Context_def::make_scm ();
661 unsmob_context_def ($$)->origin ()->set_spot (@$);
663 | CONTEXT_DEF_IDENTIFIER {
665 unsmob_context_def ($$)->origin ()->set_spot (@$);
667 | context_def_spec_body context_mod {
668 if (!SCM_UNBNDP ($2))
669 unsmob_context_def ($$)->add_context_mod ($2);
671 | context_def_spec_body context_modification {
672 Context_def *td = unsmob_context_def ($$);
673 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
674 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
675 td->add_context_mod (scm_car (m));
678 | context_def_spec_body context_mod_embedded {
679 Context_def *td = unsmob_context_def ($$);
680 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
681 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
682 td->add_context_mod (scm_car (m));
690 BOOK '{' book_body '}' {
693 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
698 * Use 'handlers' like for toplevel-* stuff?
699 * grok \layout and \midi? */
702 Book *book = new Book;
703 init_papers (parser);
704 book->origin ()->set_spot (@$);
705 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
706 book->paper_->unprotect ();
707 push_paper (parser, book->paper_);
708 book->header_ = get_header (parser);
709 $$ = book->unprotect ();
710 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
713 unsmob_book ($1)->origin ()->set_spot (@$);
714 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
716 | book_body paper_block {
717 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
718 set_paper (parser, unsmob_output_def ($2));
720 | book_body bookpart_block {
721 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
722 scm_call_2 (proc, $1, $2);
724 | book_body score_block {
725 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
726 scm_call_2 (proc, $1, $2);
728 | book_body composite_music {
729 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
730 scm_call_3 (proc, parser->self_scm (), $1, $2);
732 | book_body full_markup {
733 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
734 scm_call_2 (proc, $1, scm_list_1 ($2));
736 | book_body full_markup_list {
737 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
738 scm_call_2 (proc, $1, $2);
740 | book_body SCM_TOKEN {
741 // Evaluate and ignore #xxx, as opposed to \xxx
742 parser->lexer_->eval_scm_token ($2);
744 | book_body embedded_scm_active
746 SCM out = SCM_UNDEFINED;
747 if (Text_interface::is_markup ($2))
748 out = scm_list_1 ($2);
749 else if (Text_interface::is_markup_list ($2))
751 if (scm_is_pair (out))
753 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
754 scm_call_2 (proc, $1, out);
755 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
756 parser->parser_error (@2, _("bad expression type"));
760 parser->lexer_->add_scope (unsmob_book ($1)->header_);
763 Book *book = unsmob_book ($1);
765 book->scores_ = SCM_EOL;
766 book->bookparts_ = SCM_EOL;
771 BOOKPART '{' bookpart_body '}' {
773 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
779 Book *book = new Book;
780 book->origin ()->set_spot (@$);
781 $$ = book->unprotect ();
782 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
785 unsmob_book ($1)->origin ()->set_spot (@$);
786 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
788 | bookpart_body paper_block {
789 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
791 | bookpart_body score_block {
792 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
793 scm_call_2 (proc, $1, $2);
795 | bookpart_body composite_music {
796 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
797 scm_call_3 (proc, parser->self_scm (), $1, $2);
799 | bookpart_body full_markup {
800 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
801 scm_call_2 (proc, $1, scm_list_1 ($2));
803 | bookpart_body full_markup_list {
804 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
805 scm_call_2 (proc, $1, $2);
807 | bookpart_body SCM_TOKEN {
808 // Evaluate and ignore #xxx, as opposed to \xxx
809 parser->lexer_->eval_scm_token ($2);
811 | bookpart_body embedded_scm_active
813 SCM out = SCM_UNDEFINED;
814 if (Text_interface::is_markup ($2))
815 out = scm_list_1 ($2);
816 else if (Text_interface::is_markup_list ($2))
818 if (scm_is_pair (out))
820 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
821 scm_call_2 (proc, $1, out);
822 } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
823 parser->parser_error (@2, _("bad expression type"));
827 Book *book = unsmob_book ($1);
828 if (!ly_is_module (book->header_))
829 book->header_ = ly_make_module (false);
830 parser->lexer_->add_scope (book->header_);
832 | bookpart_body error {
833 Book *book = unsmob_book ($1);
835 book->scores_ = SCM_EOL;
840 SCORE '{' score_body '}' {
847 SCM scorify = ly_lily_module_constant ("scorify-music");
848 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
850 unsmob_score ($$)->origin ()->set_spot (@$);
852 | embedded_scm_active {
854 if (unsmob_score ($1))
855 score = new Score (*unsmob_score ($1));
858 parser->parser_error (@1, _("score expected"));
860 unsmob_score ($$)->origin ()->set_spot (@$);
861 $$ = score->unprotect ();
865 Score *score = unsmob_score ($1);
866 if (!ly_is_module (score->get_header ()))
867 score->set_header (ly_make_module (false));
868 parser->lexer_->add_scope (score->get_header ());
870 | score_body output_def {
871 Output_def *od = unsmob_output_def ($2);
872 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
874 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
879 unsmob_score ($1)->add_output_def (od);
883 unsmob_score ($$)->error_found_ = true;
894 Output_def *od = unsmob_output_def ($1);
896 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
898 parser->parser_error (@1, _ ("need \\paper for paper block"));
899 $$ = get_paper (parser)->unprotect ();
906 output_def_body '}' {
909 parser->lexer_->remove_scope ();
910 parser->lexer_->pop_state ();
916 Output_def *p = get_paper (parser);
917 p->input_origin_ = @$;
918 parser->lexer_->add_scope (p->scope_);
919 $$ = p->unprotect ();
922 Output_def *p = get_midi (parser);
923 $$ = p->unprotect ();
924 parser->lexer_->add_scope (p->scope_);
927 Output_def *p = get_layout (parser);
929 parser->lexer_->add_scope (p->scope_);
930 $$ = p->unprotect ();
934 output_def_head_with_mode_switch:
936 parser->lexer_->push_initial_state ();
941 // We need this weird nonterminal because both music as well as a
942 // context definition can start with \context and the difference is
943 // only apparent after looking at the next token. If it is '{', there
944 // is still time to escape from notes mode.
946 music_or_context_def:
949 parser->lexer_->pop_state ();
953 parser->lexer_->pop_state ();
954 } '{' context_def_spec_body '}'
961 output_def_head_with_mode_switch '{' {
963 unsmob_output_def ($$)->input_origin_.set_spot (@$);
965 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
966 Output_def *o = unsmob_output_def ($3);
967 o->input_origin_.set_spot (@$);
969 parser->lexer_->remove_scope ();
970 parser->lexer_->add_scope (o->scope_);
972 | output_def_body assignment {
975 | output_def_body embedded_scm {
980 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
981 parser->lexer_->push_note_state (nn);
982 } music_or_context_def
984 if (unsmob_context_def ($3))
985 assign_context_def (unsmob_output_def ($1), $3);
988 SCM proc = parser->lexer_->lookup_identifier
989 ("output-def-music-handler");
990 scm_call_3 (proc, parser->self_scm (),
994 | output_def_body error {
1000 TEMPO steno_duration '=' tempo_range {
1001 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
1003 | TEMPO scalar_closed steno_duration '=' tempo_range {
1004 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
1007 $$ = MAKE_SYNTAX ("tempo", @$, $2);
1012 The representation of a list is reversed to have efficient append. */
1018 | music_list music_embedded {
1019 if (unsmob_music ($2))
1020 $$ = scm_cons ($2, $1);
1022 | music_list error {
1023 Music *m = MY_MAKE_MUSIC("Music", @$);
1025 m->set_property ("error-found", SCM_BOOL_T);
1026 $$ = scm_cons (m->self_scm (), $1);
1027 m->unprotect (); /* UGH */
1034 $$ = scm_reverse_x ($2, SCM_EOL);
1039 | lyric_element_music
1045 if (unsmob_music ($1)->is_mus_type ("post-event")) {
1046 parser->parser_error (@1, _ ("unexpected post-event"));
1047 $$ = SCM_UNSPECIFIED;
1050 | music_embedded_backup
1054 | music_embedded_backup BACKUP lyric_element_music
1060 music_embedded_backup:
1063 if (scm_is_eq ($1, SCM_UNSPECIFIED))
1065 else if (Music *m = unsmob_music ($1)) {
1066 if (m->is_mus_type ("post-event")) {
1067 parser->parser_error
1068 (@1, _ ("unexpected post-event"));
1069 $$ = SCM_UNSPECIFIED;
1072 } else if (parser->lexer_->is_lyric_state ()
1073 && Text_interface::is_markup ($1))
1074 MYBACKUP (LYRIC_ELEMENT, $1, @1);
1076 @$.warning (_ ("Ignoring non-music expression"));
1085 $$ = make_music_from_simple (parser, @1, $1);
1086 if (!unsmob_music ($$))
1087 parser->parser_error (@1, _ ("music expected"));
1089 | composite_music %prec COMPOSITE
1094 | composite_music %prec COMPOSITE
1098 REPEAT simple_string unsigned_number music
1100 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
1102 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
1104 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
1109 SEQUENTIAL braced_music_list {
1110 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1112 | braced_music_list {
1113 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1118 SIMULTANEOUS braced_music_list {
1119 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1121 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1122 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1128 | music_property_def
1132 context_modification:
1133 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1135 parser->lexer_->pop_state ();
1138 | WITH CONTEXT_MOD_IDENTIFIER
1142 | CONTEXT_MOD_IDENTIFIER
1146 | WITH embedded_scm_closed
1148 if (unsmob_context_mod ($2))
1151 parser->parser_error (@2, _ ("not a context mod"));
1152 $$ = Context_mod ().smobbed_copy ();
1157 optional_context_mod:
1161 | context_modification
1169 $$ = Context_mod ().smobbed_copy ();
1171 | context_mod_list context_mod {
1172 if (!SCM_UNBNDP ($2))
1173 unsmob_context_mod ($1)->add_context_mod ($2);
1175 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1176 Context_mod *md = unsmob_context_mod ($2);
1178 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1180 | context_mod_list context_mod_embedded {
1181 unsmob_context_mod ($1)->add_context_mods
1182 (unsmob_context_mod ($2)->get_mods ());
1191 /* Music that can be parsed without lookahead */
1194 | complex_music_prefix closed_music
1196 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1198 | music_function_call_closed
1204 | grouped_music_list
1208 simultaneous_music { $$ = $1; }
1209 | sequential_music { $$ = $1; }
1212 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1213 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1214 and this rule returns the reversed list of arguments. */
1216 /* Function argument lists come in a number of flavors. Whenever
1217 * LilyPond has to pick between different flavors, the decision is
1218 * either made because of tokens it has already seen, or it is
1219 * postponed until tokens suitable for making the decision come up.
1220 * For postponing decisions, it may be necessary that the competing
1221 * rules are written in a way making them compatible until a decision
1222 * can be made. Sometimes this is done by putting common traits into
1223 * a separate "common" rule set.
1225 * function_arglist: a full argument list. Optional arguments at the
1226 * end of the list can only be skipped by writing \default in their
1229 * function_arglist_backup: an argument list ending in an optional
1230 * argument that may be skipped depending on its predicate.
1232 * function_arglist_skip: an argument list _not_ ending in an optional
1233 * argument that is actually taken.
1235 * function_arglist_nonbackup: an argument list ending in an optional
1236 * argument that may not be skipped because it is in end position and
1237 * has not been shortcircuited with \default.
1239 * function_arglist* / function_arglist_closed*: The closed variants
1240 * don't end in simple music expressions that might still accept
1241 * things like a duration or a postevent.
1244 function_arglist_skip:
1245 function_arglist_common
1246 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1248 $$ = scm_cons ($1, $3);
1249 } %prec FUNCTION_ARGLIST
1250 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1252 $$ = scm_cons ($1, $3);
1253 } %prec FUNCTION_ARGLIST
1254 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1256 $$ = scm_cons ($1, $3);
1257 } %prec FUNCTION_ARGLIST
1261 function_arglist_nonbackup_common:
1262 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1263 $$ = scm_cons ($4, $3);
1265 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1266 $$ = scm_cons ($4, $3);
1268 | EXPECT_OPTIONAL EXPECT_SCM function_arglist FRACTION
1270 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1272 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1274 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1276 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1278 SCM n = scm_difference ($5, SCM_UNDEFINED);
1279 if (scm_is_true (scm_call_1 ($2, n)))
1280 $$ = scm_cons (n, $3);
1282 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1283 t->set_property ("digit", $5);
1284 $$ = check_scheme_arg (parser, @4, t->unprotect (),
1289 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1291 $$ = check_scheme_arg (parser, @4,
1292 scm_difference ($5, SCM_UNDEFINED),
1295 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1297 $$ = check_scheme_arg (parser, @4,
1298 scm_difference ($5, SCM_UNDEFINED),
1303 function_arglist_closed_nonbackup:
1304 function_arglist_nonbackup_common
1305 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1307 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1309 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1311 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1313 | EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1315 $$ = check_scheme_arg (parser, @4,
1316 try_string_variants ($2, $4),
1319 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1321 $$ = check_scheme_arg (parser, @4,
1322 try_string_variants ($2, $4),
1325 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1327 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1333 | SYMBOL_LIST '.' symbol_list_rev
1335 $$ = scm_append (scm_list_2 ($1, scm_reverse_x ($3, SCM_EOL)));
1341 | symbol_list_rev '.' symbol_list_part
1343 $$ = scm_append_x (scm_list_2 ($3, $1));
1347 // symbol_list_part delivers elements in reverse copy.
1352 SCM sym_l_p = ly_lily_module_constant ("symbol-list?");
1353 $$ = try_string_variants (sym_l_p, $1);
1354 if (SCM_UNBNDP ($$)) {
1355 parser->parser_error (@1, _("not a symbol"));
1358 $$ = scm_reverse ($$);
1363 symbol_list_element:
1369 function_arglist_nonbackup:
1370 function_arglist_nonbackup_common
1371 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1373 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1375 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1377 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1379 | function_arglist_nonbackup_reparse REPARSE SCM_ARG
1381 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1383 | function_arglist_nonbackup_reparse REPARSE lyric_element_music
1385 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1387 | function_arglist_nonbackup_reparse REPARSE symbol_list_arg
1389 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1393 function_arglist_nonbackup_reparse:
1394 EXPECT_OPTIONAL EXPECT_SCM function_arglist SCM_IDENTIFIER
1397 SCM res = try_string_variants ($2, $4);
1398 if (!SCM_UNBNDP (res))
1399 if (scm_is_pair (res))
1400 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1402 MYREPARSE (@4, $2, SCM_ARG, res);
1403 else if (scm_is_true
1405 ($2, make_music_from_simple
1407 MYREPARSE (@4, $2, STRING, $4);
1409 MYREPARSE (@4, $2, SCM_ARG, $4);
1411 | EXPECT_OPTIONAL EXPECT_SCM function_arglist STRING
1414 SCM res = try_string_variants ($2, $4);
1415 if (!SCM_UNBNDP (res))
1416 if (scm_is_pair (res))
1417 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1419 MYREPARSE (@4, $2, SCM_ARG, res);
1420 else if (scm_is_true
1422 ($2, make_music_from_simple
1424 MYREPARSE (@4, $2, STRING, $4);
1426 MYREPARSE (@4, $2, SCM_ARG, $4);
1428 | EXPECT_OPTIONAL EXPECT_SCM function_arglist full_markup
1431 if (scm_is_true (scm_call_1 ($2, $4)))
1432 MYREPARSE (@4, $2, SCM_ARG, $4);
1433 else if (scm_is_true
1435 ($2, make_music_from_simple
1437 MYREPARSE (@4, $2, STRING, $4);
1439 MYREPARSE (@4, $2, SCM_ARG, $4);
1443 function_arglist_keep:
1444 function_arglist_common
1445 | function_arglist_backup
1448 function_arglist_closed_keep:
1449 function_arglist_closed_common
1450 | function_arglist_backup
1453 function_arglist_backup:
1454 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1456 if (scm_is_true (scm_call_1 ($2, $4)))
1458 $$ = scm_cons ($4, $3);
1460 $$ = scm_cons (loc_on_music (@3, $1), $3);
1461 MYBACKUP (SCM_ARG, $4, @4);
1464 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1466 if (scm_is_true (scm_call_1 ($2, $4)))
1468 $$ = scm_cons ($4, $3);
1470 $$ = scm_cons (loc_on_music (@3, $1), $3);
1471 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1474 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep full_markup
1476 if (scm_is_true (scm_call_1 ($2, $4)))
1477 $$ = scm_cons ($4, $3);
1479 $$ = scm_cons (loc_on_music (@3, $1), $3);
1480 MYBACKUP (LYRIC_ELEMENT, $4, @4);
1483 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1485 if (scm_is_true (scm_call_1 ($2, $4)))
1488 MYREPARSE (@4, $2, UNSIGNED, $4);
1490 $$ = scm_cons (loc_on_music (@3, $1), $3);
1491 MYBACKUP (UNSIGNED, $4, @4);
1494 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1496 if (scm_is_true (scm_call_1 ($2, $4)))
1499 MYREPARSE (@4, $2, REAL, $4);
1501 $$ = scm_cons (loc_on_music (@3, $1), $3);
1502 MYBACKUP (REAL, $4, @4);
1505 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1507 if (scm_is_true (scm_call_1 ($2, $4)))
1509 $$ = scm_cons ($4, $3);
1511 $$ = scm_cons (loc_on_music (@3, $1), $3);
1512 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1515 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep FRACTION
1517 if (scm_is_true (scm_call_1 ($2, $4)))
1519 $$ = scm_cons ($4, $3);
1521 $$ = scm_cons (loc_on_music (@3, $1), $3);
1522 MYBACKUP (FRACTION, $4, @4);
1525 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1527 SCM n = scm_difference ($5, SCM_UNDEFINED);
1528 if (scm_is_true (scm_call_1 ($2, n))) {
1530 MYREPARSE (@5, $2, REAL, n);
1532 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1533 t->set_property ("digit", $5);
1534 $$ = t->unprotect ();
1535 if (scm_is_true (scm_call_1 ($2, $$)))
1536 $$ = scm_cons ($$, $3);
1538 $$ = scm_cons (loc_on_music (@3, $1), $3);
1539 MYBACKUP (UNSIGNED, $5, @5);
1540 parser->lexer_->push_extra_token ('-');
1545 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1547 SCM n = scm_difference ($5, SCM_UNDEFINED);
1548 if (scm_is_true (scm_call_1 ($2, n))) {
1549 MYREPARSE (@5, $2, REAL, n);
1552 $$ = scm_cons (loc_on_music (@3, $1), $3);
1553 MYBACKUP (REAL, n, @5);
1556 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1558 SCM n = scm_difference ($5, SCM_UNDEFINED);
1559 if (scm_is_true (scm_call_1 ($2, n))) {
1560 $$ = scm_cons (n, $3);
1562 $$ = scm_cons (loc_on_music (@3, $1), $3);
1563 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1566 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1568 $$ = scm_cons ($4, $3);
1570 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1572 $$ = scm_cons ($4, $3);
1574 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep SCM_IDENTIFIER
1576 SCM res = try_string_variants ($2, $4);
1577 if (!SCM_UNBNDP (res))
1578 if (scm_is_pair (res)) {
1580 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1583 $$ = scm_cons (res, $3);
1585 $$ = scm_cons (loc_on_music (@3, $1), $3);
1586 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1589 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep STRING
1591 SCM res = try_string_variants ($2, $4);
1592 if (!SCM_UNBNDP (res))
1593 if (scm_is_pair (res)) {
1595 MYREPARSE (@4, $2, SYMBOL_LIST, res);
1598 $$ = scm_cons (res, $3);
1600 $$ = scm_cons (loc_on_music (@3, $1), $3);
1601 MYBACKUP (STRING, $4, @4);
1604 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1606 $$ = scm_cons ($1, $3);
1607 MYBACKUP(0, SCM_UNDEFINED, @3);
1609 | function_arglist_backup REPARSE bare_number
1611 $$ = check_scheme_arg (parser, @3,
1614 | function_arglist_backup REPARSE symbol_list_arg
1616 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1621 function_arglist_common
1622 | function_arglist_nonbackup
1625 function_arglist_common:
1626 function_arglist_bare
1627 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1629 $$ = check_scheme_arg (parser, @3,
1632 | EXPECT_SCM function_arglist_closed_optional bare_number
1634 $$ = check_scheme_arg (parser, @3,
1637 | EXPECT_SCM function_arglist_optional FRACTION
1639 $$ = check_scheme_arg (parser, @3,
1642 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1644 $$ = check_scheme_arg (parser, @3,
1647 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1649 SCM n = scm_difference ($4, SCM_UNDEFINED);
1650 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1652 | function_arglist_common_reparse REPARSE SCM_ARG
1654 $$ = check_scheme_arg (parser, @3,
1657 | function_arglist_common_reparse REPARSE lyric_element_music
1659 $$ = check_scheme_arg (parser, @3,
1662 | function_arglist_common_reparse REPARSE bare_number
1664 $$ = check_scheme_arg (parser, @3,
1667 | function_arglist_common_reparse REPARSE symbol_list_arg
1669 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1673 function_arglist_common_reparse:
1674 EXPECT_SCM function_arglist_optional SCM_IDENTIFIER
1677 SCM res = try_string_variants ($1, $3);
1678 if (!SCM_UNBNDP (res))
1679 if (scm_is_pair (res))
1680 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1682 MYREPARSE (@3, $1, SCM_ARG, res);
1683 else if (scm_is_true
1685 ($1, make_music_from_simple (parser, @3, $3))))
1686 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1688 // This is going to flag a syntax error, we
1689 // know the predicate to be false.
1690 MYREPARSE (@3, $1, SCM_ARG, $3);
1692 | EXPECT_SCM function_arglist_optional STRING
1695 SCM res = try_string_variants ($1, $3);
1696 if (!SCM_UNBNDP (res))
1697 if (scm_is_pair (res))
1698 MYREPARSE (@3, $1, SYMBOL_LIST, res);
1700 MYREPARSE (@3, $1, SCM_ARG, res);
1701 else if (scm_is_true
1703 ($1, make_music_from_simple (parser, @3, $3))))
1704 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1706 // This is going to flag a syntax error, we
1707 // know the predicate to be false.
1708 MYREPARSE (@3, $1, SCM_ARG, $3);
1710 | EXPECT_SCM function_arglist_optional full_markup
1713 if (scm_is_true (scm_call_1 ($1, $3)))
1714 MYREPARSE (@3, $1, SCM_ARG, $3);
1715 else if (scm_is_true
1717 ($1, make_music_from_simple (parser, @3, $3))))
1718 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1720 // This is going to flag a syntax error, we
1721 // know the predicate to be false.
1722 MYREPARSE (@3, $1, SCM_ARG, $3);
1724 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1727 SCM n = scm_difference ($4, SCM_UNDEFINED);
1728 if (scm_is_true (scm_call_1 ($1, n)))
1729 MYREPARSE (@4, $1, REAL, n);
1731 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1732 t->set_property ("digit", $4);
1733 SCM m = t->unprotect ();
1734 if (scm_is_true (scm_call_1 ($1, m)))
1735 MYREPARSE (@4, $1, SCM_ARG, m);
1737 MYREPARSE (@4, $1, SCM_ARG, $4);
1741 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1744 SCM n = scm_difference ($4, SCM_UNDEFINED);
1745 MYREPARSE (@4, $1, REAL, n);
1749 function_arglist_closed:
1750 function_arglist_closed_common
1751 | function_arglist_closed_nonbackup
1754 function_arglist_closed_common:
1755 function_arglist_bare
1756 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1758 $$ = check_scheme_arg (parser, @3,
1761 | EXPECT_SCM function_arglist_closed_optional bare_number
1763 $$ = check_scheme_arg (parser, @3,
1766 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1768 $$ = check_scheme_arg (parser, @3,
1769 scm_difference ($4, SCM_UNDEFINED),
1772 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1774 $$ = check_scheme_arg (parser, @3,
1777 | EXPECT_SCM function_arglist_optional FRACTION
1779 $$ = check_scheme_arg (parser, @3,
1782 | function_arglist_common_reparse REPARSE SCM_ARG
1784 $$ = check_scheme_arg (parser, @3,
1787 | function_arglist_common_reparse REPARSE bare_number
1789 $$ = check_scheme_arg (parser, @3,
1792 | function_arglist_common_reparse REPARSE symbol_list_arg
1794 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1798 function_arglist_optional:
1799 function_arglist_keep %prec FUNCTION_ARGLIST
1800 | function_arglist_backup BACKUP
1801 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1803 $$ = scm_cons ($1, $3);
1805 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1807 $$ = scm_cons ($1, $3);
1811 function_arglist_closed_optional:
1812 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1813 | function_arglist_backup BACKUP
1814 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1816 $$ = scm_cons ($1, $3);
1818 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1820 $$ = scm_cons ($1, $3);
1824 embedded_scm_closed:
1826 | scm_function_call_closed
1829 embedded_scm_arg_closed:
1830 embedded_scm_bare_arg
1831 | scm_function_call_closed
1835 scm_function_call_closed:
1836 SCM_FUNCTION function_arglist_closed {
1837 $$ = MAKE_SYNTAX ("music-function", @$,
1839 } %prec FUNCTION_ARGLIST
1842 function_arglist_bare:
1843 EXPECT_NO_MORE_ARGS {
1846 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1847 $$ = scm_cons ($3, $2);
1849 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1850 $$ = scm_cons ($3, $2);
1852 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1853 $$ = scm_cons ($1, $3);
1855 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1856 $$ = scm_cons ($1, $3);
1858 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1859 $$ = scm_cons ($1, $3);
1863 music_function_call:
1864 MUSIC_FUNCTION function_arglist {
1865 $$ = MAKE_SYNTAX ("music-function", @$,
1872 /**/ { $$ = SCM_EOL; }
1873 | '=' simple_string {
1880 | repeated_music { $$ = $1; }
1881 | re_rhythmed_music { $$ = $1; }
1882 | complex_music_prefix music
1884 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1888 complex_music_prefix:
1889 CONTEXT symbol optional_id optional_context_mod {
1890 Context_mod *ctxmod = unsmob_context_mod ($4);
1893 mods = ctxmod->get_mods ();
1894 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1896 | NEWCONTEXT symbol optional_id optional_context_mod {
1897 Context_mod *ctxmod = unsmob_context_mod ($4);
1900 mods = ctxmod->get_mods ();
1901 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1906 mode_changing_head grouped_music_list {
1907 if ($1 == ly_symbol2scm ("chords"))
1909 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1915 parser->lexer_->pop_state ();
1917 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1918 Context_mod *ctxmod = unsmob_context_mod ($2);
1921 mods = ctxmod->get_mods ();
1922 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1923 if ($1 == ly_symbol2scm ("ChordNames"))
1925 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1927 parser->lexer_->pop_state ();
1933 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1934 parser->lexer_->push_note_state (nn);
1936 $$ = ly_symbol2scm ("notes");
1940 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1941 parser->lexer_->push_note_state (nn);
1943 $$ = ly_symbol2scm ("drums");
1946 parser->lexer_->push_figuredbass_state ();
1948 $$ = ly_symbol2scm ("figures");
1951 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1952 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1953 nn = parser->lexer_->lookup_identifier ("pitchnames");
1954 parser->lexer_->push_chord_state (nn);
1955 $$ = ly_symbol2scm ("chords");
1959 { parser->lexer_->push_lyric_state ();
1960 $$ = ly_symbol2scm ("lyrics");
1964 mode_changing_head_with_context:
1966 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1967 parser->lexer_->push_note_state (nn);
1969 $$ = ly_symbol2scm ("DrumStaff");
1972 parser->lexer_->push_figuredbass_state ();
1974 $$ = ly_symbol2scm ("FiguredBass");
1977 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1978 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1979 nn = parser->lexer_->lookup_identifier ("pitchnames");
1980 parser->lexer_->push_chord_state (nn);
1981 $$ = ly_symbol2scm ("ChordNames");
1984 { parser->lexer_->push_lyric_state ();
1985 $$ = ly_symbol2scm ("Lyrics");
1990 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1993 /* Can also use music at the expensive of two S/Rs similar to
1994 \repeat \alternative */
1995 parser->lexer_->pop_state ();
1997 $$ = scm_cons ($3, SCM_EOL);
1999 | new_lyrics ADDLYRICS {
2000 parser->lexer_->push_lyric_state ();
2002 parser->lexer_->pop_state ();
2003 $$ = scm_cons ($4, $1);
2008 composite_music new_lyrics {
2009 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
2011 | LYRICSTO simple_string {
2012 parser->lexer_->push_lyric_state ();
2014 parser->lexer_->pop_state ();
2015 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
2020 CHANGE STRING '=' STRING {
2021 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
2028 $$ = scm_reverse_x ($1, SCM_EOL);
2030 | symbol_list_rev property_path {
2031 $$ = scm_reverse_x ($1, $2);
2037 $$ = scm_list_3 (ly_symbol2scm ("assign"), $1, $3);
2040 $$ = scm_list_2 (ly_symbol2scm ("unset"), $2);
2042 | OVERRIDE property_path '=' scalar {
2043 if (scm_ilength ($2) < 2) {
2044 parser->parser_error (@2, _("bad grob property path"));
2047 $$ = scm_cons (ly_symbol2scm ("push"),
2048 scm_cons2 (scm_car ($2),
2053 | REVERT revert_arg {
2054 $$ = scm_cons (ly_symbol2scm ("pop"), $2);
2058 // This is all quite awkward for the sake of substantial backward
2059 // compatibility while at the same time allowing a more "natural" form
2060 // of specification not separating grob specification from grob
2061 // property path. The purpose of this definition of revert_arg is to
2062 // allow the symbol list which specifies grob and property to revert
2063 // to be optionally be split into two parts after the grob (which in
2064 // this case is just the first element of the list). symbol_list_part
2065 // is only one path component, but it can be parsed without lookahead,
2066 // so we can follow it with a synthetic BACKUP token when needed. If
2067 // the first symbol_list_part already contains multiple elements (only
2068 // possible if a Scheme expression provides them), we just parse for
2069 // additional elements introduced by '.', which is what the
2070 // SYMBOL_LIST backup in connection with the immediately following
2071 // rule using symbol_list_arg does.
2073 // As long as we don't have our coffers filled with both grob and at
2074 // least one grob property specification, the rest of the required
2075 // symbol list chain may be provided either with or without a leading
2076 // dot. This is for both allowing the traditional
2077 // \revert Accidental #'color
2078 // as well as well as the "naive" form
2079 // \revert Accidental.color
2082 revert_arg_backup BACKUP symbol_list_arg
2091 if (scm_is_null ($1)
2092 || scm_is_null (scm_cdr ($1)))
2093 MYBACKUP (SCM_ARG, $1, @1);
2095 MYBACKUP (SYMBOL_LIST, scm_reverse_x ($1, SCM_EOL), @1);
2099 // revert_arg_part delivers results in reverse
2102 | revert_arg_backup BACKUP SCM_ARG '.' symbol_list_part
2104 $$ = scm_append_x (scm_list_2 ($5, $3));
2106 | revert_arg_backup BACKUP SCM_ARG symbol_list_part
2108 $$ = scm_append_x (scm_list_2 ($4, $3));
2113 CONSISTS { $$ = ly_symbol2scm ("consists"); }
2114 | REMOVE { $$ = ly_symbol2scm ("remove"); }
2116 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
2117 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
2118 | DENIES { $$ = ly_symbol2scm ("denies"); }
2120 | ALIAS { $$ = ly_symbol2scm ("alias"); }
2121 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
2122 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
2123 | NAME { $$ = ly_symbol2scm ("context-name"); }
2127 property_operation { $$ = $1; }
2128 | context_def_mod STRING {
2129 $$ = scm_list_2 ($1, $2);
2131 | context_def_mod embedded_scm
2133 if (!scm_is_string ($2)
2134 && ly_symbol2scm ("consists") != $1
2135 && ly_symbol2scm ("remove") != $1)
2138 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
2142 $$ = scm_list_2 ($1, $2);
2147 // If defined, at least two members.
2151 SCM l = scm_reverse_x ($1, SCM_EOL);
2154 (scm_object_property (scm_car (l),
2155 ly_symbol2scm ("is-grob?"))))
2156 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2157 if (scm_is_null (l) || scm_is_null (scm_cdr (l))) {
2158 parser->parser_error (@1, _ ("bad grob property path"));
2165 // If defined, at least three members
2169 if (!SCM_UNBNDP ($1) && scm_is_null (scm_cddr ($1)))
2171 parser->parser_error (@1, _ ("bad grob property path"));
2175 | grob_prop_spec property_path
2177 if (!SCM_UNBNDP ($1)) {
2178 $$ = scm_append_x (scm_list_2 ($1, $2));
2179 if (scm_is_null (scm_cddr ($$))) {
2180 parser->parser_error (@$, _ ("bad grob property path"));
2188 // Exactly two elements or undefined
2192 SCM l = scm_reverse_x ($1, SCM_EOL);
2193 switch (scm_ilength (l)) {
2195 l = scm_cons (ly_symbol2scm ("Bottom"), l);
2199 parser->parser_error (@1, _ ("bad context property path"));
2206 simple_music_property_def:
2207 OVERRIDE grob_prop_path '=' scalar {
2208 if (SCM_UNBNDP ($2))
2211 $$ = scm_list_5 (scm_car ($2),
2212 ly_symbol2scm ("OverrideProperty"),
2218 | REVERT simple_revert_context revert_arg {
2219 $$ = scm_list_4 ($2,
2220 ly_symbol2scm ("RevertProperty"),
2224 | SET context_prop_spec '=' scalar {
2225 if (SCM_UNBNDP ($2))
2228 $$ = scm_list_4 (scm_car ($2),
2229 ly_symbol2scm ("PropertySet"),
2233 | UNSET context_prop_spec {
2234 if (SCM_UNBNDP ($2))
2237 $$ = scm_list_3 (scm_car ($2),
2238 ly_symbol2scm ("PropertyUnset"),
2244 // This is all quite awkward for the sake of substantial backward
2245 // compatibility while at the same time allowing a more "natural" form
2246 // of specification not separating grob specification from grob
2247 // property path. The purpose of this definition of
2248 // simple_revert_context is to allow the symbol list which specifies
2249 // grob and property to revert to be optionally be split into two
2250 // parts after the grob (which may be preceded by a context
2251 // specification, a case which we distinguish by checking whether the
2252 // first symbol is a valid grob symbol instead).
2254 // See revert_arg above for the main work horse of this arrangement.
2255 // simple_revert_context just caters for the context and delegates the
2256 // rest of the job to revert_arg.
2258 simple_revert_context:
2261 $1 = scm_reverse_x ($1, SCM_EOL);
2262 if (scm_is_null ($1)
2264 (scm_object_property (scm_car ($1),
2265 ly_symbol2scm ("is-grob?")))) {
2266 $$ = ly_symbol2scm ("Bottom");
2267 parser->lexer_->push_extra_token (SCM_IDENTIFIER, $1);
2270 parser->lexer_->push_extra_token (SCM_IDENTIFIER,
2277 simple_music_property_def {
2278 if (SCM_UNBNDP ($1))
2279 $$ = MAKE_SYNTAX ("void-music", @1);
2281 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
2292 simple_string: STRING {
2297 if (scm_is_string ($1)) {
2300 parser->parser_error (@1, (_ ("simple string expected")));
2301 $$ = scm_string (SCM_EOL);
2308 $$ = scm_string_to_symbol ($1);
2312 // This is a bit of overkill but makes the same
2313 // routine responsible for all symbol interpretations.
2314 $$ = try_string_variants (ly_lily_module_constant ("symbol?"),
2316 if (SCM_UNBNDP ($$))
2318 parser->parser_error (@1, (_ ("symbol expected")));
2319 // Generate a unique symbol in case it is used
2320 // for an assignment or similar
2321 $$ = scm_make_symbol (ly_string2scm ("undefined"));
2330 // The following is a rather defensive variant of admitting
2331 // negative numbers: the grammar would permit number_factor or
2332 // even number_expression. However, function arguments allow
2333 // only this simple kind of negative number, so to have things
2334 // like \tweak and \override behave reasonably similar, it
2335 // makes sense to rule out things like -- which are rather an
2336 // accent in function argument contexts.
2339 $$ = scm_difference ($2, SCM_UNDEFINED);
2347 embedded_scm_arg_closed
2349 // for scalar_closed to be an actually closed (no lookahead)
2350 // expression, we'd need to use bare_number_closed here. It
2351 // turns out that the only use of scalar_closed in TEMPO is
2352 // not of the kind requiring the full closedness criterion.
2356 $$ = scm_difference ($2, SCM_UNDEFINED);
2365 simple_element post_events {
2366 // Let the rhythmic music iterator sort this mess out.
2367 if (scm_is_pair ($2)) {
2368 $$ = make_music_from_simple (parser, @1, $1);
2369 if (unsmob_music ($$))
2370 unsmob_music ($$)->set_property ("articulations",
2371 scm_reverse_x ($2, SCM_EOL));
2373 parser->parser_error (@1, _("music expected"));
2376 | simple_chord_elements post_events {
2377 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
2380 /* why is this giving wrong start location? -ns
2382 i.set_location (@1, @2);
2383 $$ = MAKE_SYNTAX ("event-chord", i, elts);
2385 | CHORD_REPETITION optional_notemode_duration post_events {
2387 i.set_location (@1, @3);
2388 $$ = MAKE_SYNTAX ("repetition-chord", i,
2389 $2, scm_reverse_x ($3, SCM_EOL));
2391 | MULTI_MEASURE_REST optional_notemode_duration post_events {
2393 i.set_location (@1, @3);
2394 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
2395 scm_reverse_x ($3, SCM_EOL));
2398 | note_chord_element
2403 chord_body optional_notemode_duration post_events
2405 Music *m = unsmob_music ($1);
2406 SCM dur = unsmob_duration ($2)->smobbed_copy ();
2407 SCM es = m->get_property ("elements");
2408 SCM postevs = scm_reverse_x ($3, SCM_EOL);
2410 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
2411 unsmob_music (scm_car (s))->set_property ("duration", dur);
2412 es = ly_append2 (es, postevs);
2414 m-> set_property ("elements", es);
2416 $$ = m->self_scm ();
2421 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
2423 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
2427 chord_body_elements:
2428 /* empty */ { $$ = SCM_EOL; }
2429 | chord_body_elements chord_body_element {
2430 if (!SCM_UNBNDP ($2))
2431 $$ = scm_cons ($2, $1);
2436 pitch exclamations questions octave_check post_events
2438 bool q = to_boolean ($3);
2439 bool ex = to_boolean ($2);
2443 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2444 n->set_property ("pitch", $1);
2446 n->set_property ("cautionary", SCM_BOOL_T);
2448 n->set_property ("force-accidental", SCM_BOOL_T);
2450 if (scm_is_pair (post)) {
2451 SCM arts = scm_reverse_x (post, SCM_EOL);
2452 n->set_property ("articulations", arts);
2454 if (scm_is_number (check))
2456 int q = scm_to_int (check);
2457 n->set_property ("absolute-octave", scm_from_int (q-1));
2460 $$ = n->unprotect ();
2462 | DRUM_PITCH post_events {
2463 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2464 n->set_property ("drum-type", $1);
2466 if (scm_is_pair ($2)) {
2467 SCM arts = scm_reverse_x ($2, SCM_EOL);
2468 n->set_property ("articulations", arts);
2470 $$ = n->unprotect ();
2472 | music_function_chord_body
2474 Music *m = unsmob_music ($1);
2476 while (m && m->is_mus_type ("music-wrapper-music")) {
2477 $$ = m->get_property ("element");
2478 m = unsmob_music ($$);
2481 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2482 parser->parser_error (@$, _ ("not a rhythmic event"));
2488 music_function_chord_body:
2493 // Event functions may only take closed arglists, otherwise it would
2494 // not be clear whether a following postevent should be associated
2495 // with the last argument of the event function or with the expression
2496 // for which the function call acts itself as event.
2498 music_function_call_closed:
2499 MUSIC_FUNCTION function_arglist_closed {
2500 $$ = MAKE_SYNTAX ("music-function", @$,
2505 event_function_event:
2506 EVENT_FUNCTION function_arglist_closed {
2507 $$ = MAKE_SYNTAX ("music-function", @$,
2529 | post_events post_event {
2531 if (Music *m = unsmob_music ($2))
2533 if (m->is_mus_type ("post-event-wrapper"))
2535 for (SCM p = m->get_property ("elements");
2539 $$ = scm_cons (scm_car (p), $$);
2543 $$ = scm_cons ($2, $$);
2549 post_event_nofinger:
2550 direction_less_event {
2553 | script_dir music_function_call_closed {
2555 if (!unsmob_music ($2)->is_mus_type ("post-event")) {
2556 parser->parser_error (@2, _ ("post-event expected"));
2557 $$ = SCM_UNSPECIFIED;
2558 } else if (!SCM_UNBNDP ($1))
2560 unsmob_music ($$)->set_property ("direction", $1);
2564 if (!parser->lexer_->is_lyric_state ())
2565 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2566 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2569 if (!parser->lexer_->is_lyric_state ())
2570 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2571 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2573 | script_dir direction_reqd_event {
2574 if (!SCM_UNBNDP ($1))
2576 Music *m = unsmob_music ($2);
2577 m->set_property ("direction", $1);
2581 | script_dir direction_less_event {
2582 if (!SCM_UNBNDP ($1))
2584 Music *m = unsmob_music ($2);
2585 m->set_property ("direction", $1);
2592 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2597 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2608 string_number_event:
2610 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2611 s->set_property ("string-number", $1);
2612 $$ = s->unprotect ();
2616 direction_less_event:
2618 | EVENT_IDENTIFIER {
2622 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2623 a->set_property ("tremolo-type", $1);
2624 $$ = a->unprotect ();
2626 | event_function_event
2629 direction_reqd_event:
2633 | script_abbreviation {
2634 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2635 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2636 if (scm_is_string (s))
2637 a->set_property ("articulation-type", s);
2638 else parser->parser_error (@1, _ ("expecting string as script definition"));
2639 $$ = a->unprotect ();
2644 /**/ { $$ = SCM_EOL; }
2645 | '=' quotes { $$ = $2; }
2659 $$ = scm_from_int (1);
2662 $$ = scm_oneplus ($1);
2668 $$ = scm_from_int (-1);
2671 $$ = scm_oneminus ($1);
2676 NOTENAME_PITCH quotes {
2677 if (!scm_is_eq (SCM_INUM0, $2))
2679 Pitch p = *unsmob_pitch ($1);
2680 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2681 $$ = p.smobbed_copy ();
2691 TONICNAME_PITCH quotes {
2692 if (!scm_is_eq (SCM_INUM0, $2))
2694 Pitch p = *unsmob_pitch ($1);
2695 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2696 $$ = p.smobbed_copy ();
2706 pitch_also_in_chords:
2713 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2714 t->set_property ("text", $1);
2715 $$ = t->unprotect ();
2718 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2719 t->set_property ("text",
2720 make_simple_markup ($1));
2721 $$ = t->unprotect ();
2723 | embedded_scm_closed
2725 Music *m = unsmob_music ($1);
2726 if (m && m->is_mus_type ("post-event"))
2728 else if (Text_interface::is_markup ($1)) {
2729 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2730 t->set_property ("text", $1);
2731 $$ = t->unprotect ();
2733 parser->parser_error (@1, _ ("not an articulation"));
2739 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2740 t->set_property ("digit", $1);
2741 $$ = t->unprotect ();
2745 script_abbreviation:
2747 $$ = scm_from_locale_string ("Hat");
2750 $$ = scm_from_locale_string ("Plus");
2753 $$ = scm_from_locale_string ("Dash");
2756 $$ = scm_from_locale_string ("Bang");
2759 $$ = scm_from_locale_string ("Larger");
2762 $$ = scm_from_locale_string ("Dot");
2765 $$ = scm_from_locale_string ("Underscore");
2770 '_' { $$ = scm_from_int (DOWN); }
2771 | '^' { $$ = scm_from_int (UP); }
2772 | '-' { $$ = SCM_UNDEFINED; }
2776 multiplied_duration {
2781 maybe_notemode_duration:
2785 | multiplied_duration {
2787 parser->default_duration_ = *unsmob_duration ($$);
2792 optional_notemode_duration:
2793 maybe_notemode_duration
2795 if (SCM_UNBNDP ($$))
2796 $$ = parser->default_duration_.smobbed_copy ();
2803 int n = scm_to_int ($1);
2804 if (!is_duration (n))
2805 parser->parser_error (@1, _f ("not a duration: %d", n));
2809 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2811 | DURATION_IDENTIFIER dots {
2812 Duration *d = unsmob_duration ($1);
2813 Duration k (d->duration_log (),
2814 d->dot_count () + scm_to_int ($2));
2815 k = k.compressed (d->factor ());
2816 scm_remember_upto_here_1 ($1);
2817 $$ = k.smobbed_copy ();
2821 multiplied_duration:
2825 | multiplied_duration '*' UNSIGNED {
2826 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2828 | multiplied_duration '*' FRACTION {
2829 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2831 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2840 $$ = scm_oneplus ($1);
2849 int n = scm_to_int ($2);
2850 if (!is_duration (n))
2851 parser->parser_error (@2, _f ("not a duration: %d", n));
2857 UNSIGNED { $$ = $1; }
2858 | STRING { $$ = $1; }
2859 | full_markup { $$ = $1; }
2862 // as an integer, it needs to be non-negative, and otherwise
2863 // it needs to be suitable as a markup.
2864 if (scm_is_integer ($1)
2865 ? scm_is_true (scm_negative_p ($1))
2866 : !Text_interface::is_markup ($1))
2868 parser->parser_error (@1, _ ("bass number expected"));
2874 figured_bass_alteration:
2875 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2876 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2877 | '!' { $$ = scm_from_int (0); }
2882 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2883 $$ = bfr->unprotect ();
2886 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2887 $$ = bfr->self_scm ();
2889 if (scm_is_number ($1))
2890 bfr->set_property ("figure", $1);
2891 else if (Text_interface::is_markup ($1))
2892 bfr->set_property ("text", $1);
2898 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2900 | bass_figure figured_bass_alteration {
2901 Music *m = unsmob_music ($1);
2902 if (scm_to_double ($2)) {
2903 SCM salter = m->get_property ("alteration");
2904 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2905 m->set_property ("alteration",
2906 scm_sum (alter, $2));
2908 m->set_property ("alteration", scm_from_int (0));
2911 | bass_figure figured_bass_modification {
2912 Music *m = unsmob_music ($1);
2913 m->set_property ($2, SCM_BOOL_T);
2918 figured_bass_modification:
2920 $$ = ly_symbol2scm ("augmented");
2923 $$ = ly_symbol2scm ("no-continuation");
2926 $$ = ly_symbol2scm ("diminished");
2929 $$ = ly_symbol2scm ("augmented-slash");
2939 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2947 | figure_list br_bass_figure {
2948 $$ = scm_cons ($2, $1);
2953 FIGURE_OPEN figure_list FIGURE_CLOSE {
2954 $$ = scm_reverse_x ($2, SCM_EOL);
2960 /**/ { $$ = SCM_BOOL_F; }
2961 | REST { $$ = SCM_BOOL_T; }
2965 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2966 if (!parser->lexer_->is_note_state ())
2967 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2968 if (!SCM_UNBNDP ($2)
2970 || scm_is_number ($4)
2972 || scm_is_true ($6))
2975 if (scm_is_true ($6))
2976 n = MY_MAKE_MUSIC ("RestEvent", @$);
2978 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2980 n->set_property ("pitch", $1);
2981 if (SCM_UNBNDP ($5))
2982 n->set_property ("duration",
2983 parser->default_duration_.smobbed_copy ());
2985 n->set_property ("duration", $5);
2987 if (scm_is_number ($4))
2989 int q = scm_to_int ($4);
2990 n->set_property ("absolute-octave", scm_from_int (q-1));
2993 if (to_boolean ($3))
2994 n->set_property ("cautionary", SCM_BOOL_T);
2995 if (to_boolean ($2) || to_boolean ($3))
2996 n->set_property ("force-accidental", SCM_BOOL_T);
2998 $$ = n->unprotect ();
3001 | DRUM_PITCH optional_notemode_duration {
3002 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
3003 n->set_property ("duration", $2);
3004 n->set_property ("drum-type", $1);
3006 $$ = n->unprotect ();
3008 | RESTNAME optional_notemode_duration {
3010 if (ly_scm2string ($1) == "s") {
3012 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
3015 ev = MY_MAKE_MUSIC ("RestEvent", @$);
3018 ev->set_property ("duration", $2);
3019 $$ = ev->unprotect ();
3023 simple_chord_elements:
3025 if (!parser->lexer_->is_chord_state ())
3026 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
3029 | figure_spec optional_notemode_duration {
3030 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
3032 unsmob_music (scm_car (s))->set_property ("duration", $2);
3040 if (!parser->lexer_->is_lyric_state ())
3041 parser->parser_error (@1, _ ("markup outside of text script or \\lyricmode"));
3045 if (!parser->lexer_->is_lyric_state ())
3046 parser->parser_error (@1, _ ("unrecognized string, not in text script or \\lyricmode"));
3052 lyric_element_music:
3053 lyric_element optional_notemode_duration post_events {
3054 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
3055 if (scm_is_pair ($3))
3056 unsmob_music ($$)->set_property
3057 ("articulations", scm_reverse_x ($3, SCM_EOL));
3062 steno_tonic_pitch optional_notemode_duration {
3063 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
3065 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
3066 SCM its = scm_reverse_x ($4, SCM_EOL);
3067 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
3075 | chord_items chord_item {
3076 $$ = scm_cons ($2, $$);
3082 $$ = ly_symbol2scm ("chord-colon");
3085 $$ = ly_symbol2scm ("chord-caret");
3087 | CHORD_SLASH steno_tonic_pitch {
3088 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
3090 | CHORD_BASS steno_tonic_pitch {
3091 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
3100 $$ = scm_reverse_x ($1, SCM_EOL);
3108 step_number { $$ = scm_cons ($1, SCM_EOL); }
3109 | step_numbers '.' step_number {
3110 $$ = scm_cons ($3, $$);
3116 $$ = make_chord_step ($1, 0);
3119 $$ = make_chord_step ($1, SHARP_ALTERATION);
3121 | UNSIGNED CHORD_MINUS {
3122 $$ = make_chord_step ($1, FLAT_ALTERATION);
3130 | UNSIGNED '-' UNSIGNED {
3131 $$ = scm_cons ($1, $3);
3138 TODO: should deprecate in favor of Scheme?
3142 number_expression '+' number_term {
3143 $$ = scm_sum ($1, $3);
3145 | number_expression '-' number_term {
3146 $$ = scm_difference ($1, $3);
3155 | number_factor '*' number_factor {
3156 $$ = scm_product ($1, $3);
3158 | number_factor '/' number_factor {
3159 $$ = scm_divide ($1, $3);
3164 '-' number_factor { /* %prec UNARY_MINUS */
3165 $$ = scm_difference ($2, SCM_UNDEFINED);
3173 | UNSIGNED NUMBER_IDENTIFIER {
3174 $$ = scm_product ($1, $2);
3176 | REAL NUMBER_IDENTIFIER {
3177 $$ = scm_product ($1, $2);
3193 { $$ = SCM_UNDEFINED; }
3196 if (SCM_UNBNDP ($1))
3204 { $$ = SCM_UNDEFINED; }
3207 if (SCM_UNBNDP ($1))
3216 { parser->lexer_->push_markup_state (); }
3219 parser->lexer_->pop_state ();
3225 { parser->lexer_->push_markup_state (); }
3228 parser->lexer_->pop_state ();
3233 simple_markup_list {
3234 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
3236 | markup_head_1_list simple_markup
3238 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3239 @2, $1, scm_list_1 ($2)));
3249 if (Text_interface::is_markup ($1))
3250 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
3251 else if (Text_interface::is_markup_list ($1))
3252 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
3254 parser->parser_error (@1, _ ("not a markup"));
3255 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
3262 markup_composed_list {
3265 | markup_uncomposed_list
3268 markup_uncomposed_list:
3269 markup_braced_list {
3272 | markup_command_list {
3273 $$ = scm_list_1 ($1);
3275 | markup_scm MARKUPLIST_IDENTIFIER
3285 $$ = scm_list_1 (scm_list_2 (ly_lily_module_constant ("score-lines-markup-list"), $1));
3291 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3292 parser->lexer_->push_note_state (nn);
3293 } '{' score_body '}' {
3295 parser->lexer_->pop_state ();
3299 markup_composed_list:
3300 markup_head_1_list markup_uncomposed_list {
3301 $$ = MAKE_SYNTAX ("composed-markup-list",
3307 '{' markup_braced_list_body '}' {
3308 $$ = scm_reverse_x ($2, SCM_EOL);
3312 markup_braced_list_body:
3313 /* empty */ { $$ = SCM_EOL; }
3314 | markup_braced_list_body markup {
3315 $$ = scm_cons ($2, $1);
3317 | markup_braced_list_body simple_markup_list {
3318 $$ = scm_reverse_x ($2, $1);
3322 markup_command_list:
3323 MARKUP_LIST_FUNCTION markup_command_list_arguments {
3324 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
3328 markup_command_basic_arguments:
3329 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
3330 $$ = scm_cons ($3, $2);
3332 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
3333 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
3335 | EXPECT_NO_MORE_ARGS {
3340 markup_command_list_arguments:
3341 markup_command_basic_arguments { $$ = $1; }
3342 | EXPECT_MARKUP markup_command_list_arguments markup {
3343 $$ = scm_cons ($3, $2);
3348 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
3349 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
3354 markup_head_1_item {
3355 $$ = scm_list_1 ($1);
3357 | markup_head_1_list markup_head_1_item {
3358 $$ = scm_cons ($2, $1);
3364 $$ = make_simple_markup ($1);
3366 | MARKUP_FUNCTION markup_command_basic_arguments {
3367 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3369 | markup_scm MARKUP_IDENTIFIER
3375 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $1);
3380 markup_head_1_list simple_markup
3382 $$ = scm_car (MAKE_SYNTAX ("composed-markup-list",
3383 @2, $1, scm_list_1 ($2)));
3393 Lily_parser::set_yydebug (bool x)
3399 Lily_parser::do_yyparse ()
3401 SCM retval = SCM_UNDEFINED;
3402 yyparse (this, &retval);
3412 It is a little strange to have this function in this file, but
3413 otherwise, we have to import music classes into the lexer.
3417 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3419 if (unsmob_book (sid)) {
3420 Book *book = unsmob_book (sid)->clone ();
3421 *destination = book->self_scm ();
3424 return BOOK_IDENTIFIER;
3425 } else if (scm_is_number (sid)) {
3427 return NUMBER_IDENTIFIER;
3428 } else if (unsmob_context_def (sid)) {
3429 Context_def *def= unsmob_context_def (sid)->clone ();
3431 *destination = def->self_scm ();
3434 return CONTEXT_DEF_IDENTIFIER;
3435 } else if (unsmob_context_mod (sid)) {
3436 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3438 return CONTEXT_MOD_IDENTIFIER;
3439 } else if (Music *mus = unsmob_music (sid)) {
3440 mus = mus->clone ();
3441 *destination = mus->self_scm ();
3442 bool is_event = mus->is_mus_type ("post-event");
3444 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3445 } else if (unsmob_pitch (sid)) {
3446 *destination = unsmob_pitch (sid)->smobbed_copy ();
3447 return PITCH_IDENTIFIER;
3448 } else if (unsmob_duration (sid)) {
3449 *destination = unsmob_duration (sid)->smobbed_copy ();
3450 return DURATION_IDENTIFIER;
3451 } else if (unsmob_output_def (sid)) {
3452 Output_def *p = unsmob_output_def (sid);
3455 *destination = p->self_scm ();
3457 return OUTPUT_DEF_IDENTIFIER;
3464 get_next_unique_context_id ()
3466 return scm_from_locale_string ("$uniqueContextId");
3471 get_next_unique_lyrics_context_id ()
3473 static int new_context_count;
3475 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3476 return scm_from_locale_string (s);
3479 // check_scheme_arg checks one argument with a given predicate for use
3480 // in an argument list and throws a syntax error if it is unusable.
3481 // The argument is prepended to the argument list in any case. After
3482 // throwing a syntax error, the argument list is terminated with #f as
3483 // its last cdr in order to mark it as uncallable while not losing
3484 // track of its total length.
3486 // There are a few special considerations: if optional argument disp
3487 // is given (otherwise it defaults to SCM_UNDEFINED), it will be used
3488 // instead of arg in a prospective error message. This is useful if
3489 // arg is not the actual argument but rather a transformation of it.
3491 // If arg itself is SCM_UNDEFINED, the predicate is considered false
3492 // and an error message using disp is produced unconditionally.
3494 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3495 SCM arg, SCM args, SCM pred, SCM disp)
3497 if (SCM_UNBNDP (arg))
3498 args = scm_cons (disp, args);
3500 args = scm_cons (arg, args);
3501 if (scm_is_true (scm_call_1 (pred, arg)))
3504 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3505 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred,
3506 SCM_UNBNDP (disp) ? arg : disp);
3507 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3511 SCM loc_on_music (Input loc, SCM arg)
3513 if (Music *m = unsmob_music (arg))
3517 return m->unprotect ();
3523 try_string_variants (SCM pred, SCM str)
3525 // a matching predicate is always ok
3526 if (scm_is_true (scm_call_1 (pred, str)))
3528 // a symbol may be interpreted as a list of symbols if it helps
3529 if (scm_is_symbol (str)) {
3530 str = scm_list_1 (str);
3531 if (scm_is_true (scm_call_1 (pred, str)))
3533 return SCM_UNDEFINED;
3536 // If this cannot be a string representation of a symbol list,
3539 if (!is_regular_identifier (str, true))
3540 return SCM_UNDEFINED;
3542 str = scm_string_split (str, SCM_MAKE_CHAR ('.'));
3543 for (SCM p = str; scm_is_pair (p); p = scm_cdr (p))
3544 scm_set_car_x (p, scm_string_to_symbol (scm_car (p)));
3546 // Let's attempt the symbol list interpretation first.
3548 if (scm_is_true (scm_call_1 (pred, str)))
3551 // If there is just one symbol in the list, we might interpret
3552 // it as a single symbol
3554 if (scm_is_null (scm_cdr (str)))
3556 str = scm_car (str);
3557 if (scm_is_true (scm_call_1 (pred, str)))
3561 return SCM_UNDEFINED;
3565 is_regular_identifier (SCM id, bool multiple)
3567 if (!scm_is_string (id))
3570 string str = ly_scm2string (id);
3572 bool middle = false;
3574 for (string::iterator it=str.begin(); it != str.end (); it++)
3577 if ((c >= 'a' && c <= 'z')
3578 || (c >= 'A' && c <= 'Z')
3581 else if (middle && (c == '-' || c == '_' || (multiple && c == '.')))
3590 make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
3592 if (unsmob_music (simple))
3594 if (parser->lexer_->is_note_state ()) {
3595 if (scm_is_symbol (simple)) {
3596 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3597 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3598 n->set_property ("drum-type", simple);
3599 return n->unprotect ();
3601 if (unsmob_pitch (simple)) {
3602 Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
3603 n->set_property ("duration", parser->default_duration_.smobbed_copy ());
3604 n->set_property ("pitch", simple);
3605 return n->unprotect ();
3608 } else if (parser->lexer_->is_lyric_state ()) {
3609 if (Text_interface::is_markup (simple))
3610 return MAKE_SYNTAX ("lyric-event", loc, simple,
3611 parser->default_duration_.smobbed_copy ());
3612 } else if (parser->lexer_->is_chord_state ()) {
3613 if (unsmob_pitch (simple))
3614 return make_chord_elements (loc, simple,
3615 parser->default_duration_.smobbed_copy (),
3622 make_music_with_input (SCM name, Input where)
3624 Music *m = make_music_by_name (name);
3625 m->set_spot (where);
3630 make_simple_markup (SCM a)
3638 return t && t == 1 << intlog2 (t);
3642 make_chord_step (SCM step_scm, Rational alter)
3644 int step = scm_to_int (step_scm);
3647 alter += FLAT_ALTERATION;
3651 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3652 return m.smobbed_copy ();
3657 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3659 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3660 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3661 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3663 unsmob_music (scm_car (s))->set_spot (loc);
3669 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3671 Lily_lexer *lex = parser->lexer_;
3675 lex->prepare_for_next_token ();
3676 return lex->yylex ();