1 /* -*- mode: c++; c-file-style: "linux"; indent-tabs-mode: t -*- */
3 This file is part of LilyPond, the GNU music typesetter.
5 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 Jan Nieuwenhuizen <janneke@gnu.org>
8 LilyPond is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 LilyPond is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
22 /* Mode and indentation are at best a rough approximation based on TAB
23 * formatting (reasonable for compatibility with unspecific editor
24 * modes as Bison modes are hard to find) and need manual correction
25 * frequently. Without a reasonably dependable way of formatting a
26 * Bison file sensibly, there is little point in trying to fix the
27 * inconsistent state of indentation.
32 #define yyerror Lily_parser::parser_error
34 /* We use custom location type: Input objects */
37 #define YYLLOC_DEFAULT(Current,Rhs,N) \
38 ((Current).set_location ((Rhs)[1], (Rhs)[N]))
40 #define YYPRINT(file, type, value) \
42 if (scm_is_eq (value, SCM_UNSPECIFIED)) \
44 char *p = scm_to_locale_string \
45 (scm_simple_format (SCM_BOOL_F, \
46 scm_from_locale_string ("~S"), \
47 scm_list_1 (value))); \
54 %parse-param {Lily_parser *parser}
55 %parse-param {SCM *retval}
56 %lex-param {Lily_parser *parser}
60 /* We use SCMs to do strings, because it saves us the trouble of
61 deleting them. Let's hope that a stack overflow doesn't trigger a move
62 of the parse stack onto the heap. */
68 /* The above precedences tackle the shift/reduce problem
71 \repeat .. \alternative
73 \repeat { \repeat .. \alternative }
77 \repeat { \repeat } \alternative
83 /* ADDLYRICS needs to have lower precedence than argument scanning,
84 * or we won't be able to tell music apart from closed_music without
85 * lookahead in the context of function calls.
90 /* \default is only applied after exhausting function arguments */
92 %nonassoc FUNCTION_ARGLIST
94 /* expressions with units are permitted into argument lists */
96 %right PITCH_IDENTIFIER NOTENAME_PITCH TONICNAME_PITCH
97 UNSIGNED REAL DURATION_IDENTIFIER ':'
99 /* The above are the symbols that can start optional function arguments
100 that are recognized in the grammar rather than by predicate
103 %nonassoc NUMBER_IDENTIFIER '/'
105 /* Number-unit expressions, where permitted, are concatenated into
106 * function arguments, just like fractions and tremoli. Tremoli must
107 * not have higher precedence than UNSIGNED, or Lilypond will not
108 * join ':' with a following optional number.
121 %{ // -*-Fundamental-*-
126 * The rules for who is protecting what are very shady. Uniformise
129 * There are too many lexical modes?
140 #include "context-def.hh"
141 #include "context-mod.hh"
142 #include "dimensions.hh"
143 #include "file-path.hh"
145 #include "international.hh"
146 #include "lily-guile.hh"
147 #include "lily-lexer.hh"
148 #include "lily-parser.hh"
152 #include "output-def.hh"
153 #include "paper-book.hh"
154 #include "scm-hash.hh"
156 #include "text-interface.hh"
160 Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, string s)
162 parser->parser_error (*i, s);
165 #define MYBACKUP(Token, Value, Location) \
167 if (yychar == YYEMPTY) \
170 parser->lexer_->push_extra_token (Token, Value); \
171 parser->lexer_->push_extra_token (BACKUP); \
173 parser->parser_error \
174 (Location, _("Too much lookahead")); \
179 #define MYREPARSE(Location, Pred, Token, Value) \
181 if (yychar == YYEMPTY) \
183 parser->lexer_->push_extra_token (Token, Value); \
184 parser->lexer_->push_extra_token (REPARSE, \
187 parser->parser_error \
188 (Location, _("Too much lookahead")); \
197 #define MY_MAKE_MUSIC(x, spot) make_music_with_input (ly_symbol2scm (x), spot)
200 - Don't use lily module, create a new module instead.
201 - delay application of the function
203 #define LOWLEVEL_MAKE_SYNTAX(proc, args) \
204 scm_apply_0 (proc, args)
205 /* Syntactic Sugar. */
206 #define MAKE_SYNTAX(name, location, ...) \
207 LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant (name), scm_list_n (parser->self_scm (), make_input (location) , ##__VA_ARGS__, SCM_UNDEFINED))
208 #define START_MAKE_SYNTAX(name, ...) \
209 scm_list_n (ly_lily_module_constant (name) , ##__VA_ARGS__, SCM_UNDEFINED)
210 #define FINISH_MAKE_SYNTAX(start, location, ...) \
211 LOWLEVEL_MAKE_SYNTAX (scm_car (start), scm_cons2 (parser->self_scm (), make_input (location), scm_append_x (scm_list_2 (scm_cdr (start), scm_list_n (__VA_ARGS__, SCM_UNDEFINED)))))
213 SCM get_next_unique_context_id ();
214 SCM get_next_unique_lyrics_context_id ();
221 #define _(x) gettext (x)
225 static Music *make_music_with_input (SCM name, Input where);
226 SCM check_scheme_arg (Lily_parser *parser, Input loc,
227 SCM arg, SCM args, SCM pred);
228 SCM loc_on_music (Input loc, SCM arg);
229 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
230 SCM make_chord_step (SCM step, Rational alter);
231 SCM make_simple_markup (SCM a);
232 bool is_duration (int t);
233 bool is_regular_identifier (SCM id);
234 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
238 /* The third option is an alias that will be used to display the
239 syntax error. Bison CVS now correctly handles backslash escapes.
241 FIXME: Bison needs to translate some of these, eg, STRING.
245 /* Keyword tokens with plain escaped name. */
246 %token END_OF_FILE 0 "end of input"
247 %token ACCEPTS "\\accepts"
248 %token ADDLYRICS "\\addlyrics"
249 %token ALIAS "\\alias"
250 %token ALTERNATIVE "\\alternative"
252 %token BOOKPART "\\bookpart"
253 %token CHANGE "\\change"
254 %token CHORDMODE "\\chordmode"
255 %token CHORDS "\\chords"
256 %token CONSISTS "\\consists"
257 %token CONTEXT "\\context"
258 %token DEFAULT "\\default"
259 %token DEFAULTCHILD "\\defaultchild"
260 %token DENIES "\\denies"
261 %token DESCRIPTION "\\description"
262 %token DRUMMODE "\\drummode"
263 %token DRUMS "\\drums"
264 %token FIGUREMODE "\\figuremode"
265 %token FIGURES "\\figures"
266 %token HEADER "\\header"
267 %token INVALID "\\version-error"
268 %token LAYOUT "\\layout"
269 %token LYRICMODE "\\lyricmode"
270 %token LYRICS "\\lyrics"
271 %token LYRICSTO "\\lyricsto"
272 %token MARKUP "\\markup"
273 %token MARKUPLIST "\\markuplist"
276 %token NOTEMODE "\\notemode"
277 %token OVERRIDE "\\override"
278 %token PAPER "\\paper"
279 %token REMOVE "\\remove"
280 %token REPEAT "\\repeat"
282 %token REVERT "\\revert"
283 %token SCORE "\\score"
284 %token SEQUENTIAL "\\sequential"
286 %token SIMULTANEOUS "\\simultaneous"
287 %token TEMPO "\\tempo"
289 %token UNSET "\\unset"
292 /* Keyword token exceptions. */
293 %token NEWCONTEXT "\\new"
296 /* Other string tokens. */
298 %token CHORD_BASS "/+"
299 %token CHORD_CARET "^"
300 %token CHORD_COLON ":"
301 %token CHORD_MINUS "-"
302 %token CHORD_SLASH "/"
303 %token ANGLE_OPEN "<"
304 %token ANGLE_CLOSE ">"
305 %token DOUBLE_ANGLE_OPEN "<<"
306 %token DOUBLE_ANGLE_CLOSE ">>"
307 %token E_BACKSLASH "\\"
308 %token E_ANGLE_CLOSE "\\>"
309 %token E_CHAR "\\C[haracter]"
311 %token E_EXCLAMATION "\\!"
312 %token E_BRACKET_OPEN "\\["
314 %token E_BRACKET_CLOSE "\\]"
315 %token E_ANGLE_OPEN "\\<"
321 If we give names, Bison complains.
323 %token FIGURE_CLOSE /* "\\>" */
324 %token FIGURE_OPEN /* "\\<" */
325 %token FIGURE_SPACE "_"
328 %token CHORDMODIFIERS
330 %token MULTI_MEASURE_REST
336 /* Artificial tokens, for more generic function syntax */
337 %token EXPECT_MARKUP "markup?"
338 %token EXPECT_PITCH "ly:pitch?"
339 %token EXPECT_DURATION "ly:duration?"
340 %token EXPECT_SCM "scheme?"
341 %token BACKUP "(backed-up?)"
342 %token REPARSE "(reparsed?)"
343 %token EXPECT_MARKUP_LIST "markup-list?"
344 %token EXPECT_OPTIONAL "optional?"
345 /* After the last argument. */
346 %token EXPECT_NO_MORE_ARGS;
348 /* An artificial token for parsing embedded Lilypond */
349 %token EMBEDDED_LILY "#{"
351 %token BOOK_IDENTIFIER
352 %token CHORDMODIFIER_PITCH
353 %token CHORD_MODIFIER
354 %token CHORD_REPETITION
355 %token CONTEXT_DEF_IDENTIFIER
356 %token CONTEXT_MOD_IDENTIFIER
358 %token PITCH_IDENTIFIER
359 %token DURATION_IDENTIFIER
360 %token EVENT_IDENTIFIER
361 %token EVENT_FUNCTION
365 %token LYRIC_MARKUP_IDENTIFIER
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
378 %token SCM_IDENTIFIER
380 %token SCORE_IDENTIFIER
382 %token TONICNAME_PITCH
386 /* We don't assign precedence to / and *, because we might need varied
387 prec levels in different prods */
396 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
397 parser->lexer_->push_note_state (nn);
398 } embedded_lilypond {
399 parser->lexer_->pop_state ();
404 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
405 | lilypond toplevel_expression {
407 | lilypond assignment {
410 parser->error_level_ = 1;
413 parser->error_level_ = 1;
420 parser->lexer_->add_scope (get_header (parser));
422 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
425 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
426 scm_call_2 (proc, parser->self_scm (), $1);
429 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
430 scm_call_2 (proc, parser->self_scm (), $1);
433 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
434 scm_call_2 (proc, parser->self_scm (), $1);
437 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
438 scm_call_2 (proc, parser->self_scm (), $1);
441 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
442 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
445 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
446 scm_call_2 (proc, parser->self_scm (), $1);
450 Output_def * od = unsmob_output_def ($1);
452 if (od->c_variable ("is-paper") == SCM_BOOL_T)
453 id = ly_symbol2scm ("$defaultpaper");
454 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
455 id = ly_symbol2scm ("$defaultmidi");
456 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
457 id = ly_symbol2scm ("$defaultlayout");
459 parser->lexer_->set_identifier (id, $1);
466 $$ = parser->lexer_->eval_scm_token ($1);
471 embedded_scm_bare_arg:
476 | context_modification
478 | context_def_spec_block
484 /* The generic version may end in music, or not */
492 embedded_scm_bare_arg
498 SCM_FUNCTION function_arglist {
499 $$ = MAKE_SYNTAX ("music-function", @$,
507 $$ = MAKE_SYNTAX ("void-music", @$);
510 | music_embedded music_embedded music_list {
511 $3 = scm_reverse_x ($3, SCM_EOL);
512 if (unsmob_music ($2))
513 $3 = scm_cons ($2, $3);
514 if (unsmob_music ($1))
515 $3 = scm_cons ($1, $3);
516 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
519 parser->error_level_ = 1;
520 $$ = SCM_UNSPECIFIED;
522 | INVALID embedded_lilypond {
523 parser->error_level_ = 1;
529 lilypond_header_body:
530 /* empty */ { $$ = SCM_UNSPECIFIED; }
531 | lilypond_header_body assignment {
537 HEADER '{' lilypond_header_body '}' {
538 $$ = parser->lexer_->remove_scope ();
547 | LYRICS_STRING { $$ = $1; }
551 assignment_id '=' identifier_init {
552 parser->lexer_->set_identifier ($1, $3);
553 $$ = SCM_UNSPECIFIED;
555 | assignment_id property_path '=' identifier_init {
556 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
557 parser->lexer_->set_identifier (path, $4);
558 $$ = SCM_UNSPECIFIED;
560 | embedded_scm { $$ = SCM_UNSPECIFIED; }
569 | context_def_spec_block
571 | post_event_nofinger
577 | context_modification
580 context_def_spec_block:
581 CONTEXT '{' context_def_spec_body '}'
592 context_mod_embedded:
595 if (unsmob_music ($1)) {
596 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
597 $1 = scm_call_2 (proc, parser->self_scm (), $1);
599 if (unsmob_context_mod ($1))
602 parser->parser_error (@1, _ ("not a context mod"));
608 context_def_spec_body:
610 $$ = Context_def::make_scm ();
611 unsmob_context_def ($$)->origin ()->set_spot (@$);
613 | CONTEXT_DEF_IDENTIFIER {
615 unsmob_context_def ($$)->origin ()->set_spot (@$);
617 | context_def_spec_body context_mod {
618 unsmob_context_def ($$)->add_context_mod ($2);
620 | context_def_spec_body context_modification {
621 Context_def *td = unsmob_context_def ($$);
622 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
623 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
624 td->add_context_mod (scm_car (m));
627 | context_def_spec_body context_mod_embedded {
628 Context_def *td = unsmob_context_def ($$);
629 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
630 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
631 td->add_context_mod (scm_car (m));
639 BOOK '{' book_body '}' {
642 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
647 * Use 'handlers' like for toplevel-* stuff?
648 * grok \layout and \midi? */
651 Book *book = new Book;
652 init_papers (parser);
653 book->origin ()->set_spot (@$);
654 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
655 book->paper_->unprotect ();
656 push_paper (parser, book->paper_);
657 book->header_ = get_header (parser);
658 $$ = book->unprotect ();
659 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
662 unsmob_book ($1)->origin ()->set_spot (@$);
663 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
665 | book_body paper_block {
666 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
667 set_paper (parser, unsmob_output_def ($2));
669 | book_body bookpart_block {
670 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
671 scm_call_2 (proc, $1, $2);
673 | book_body score_block {
674 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
675 scm_call_2 (proc, $1, $2);
677 | book_body composite_music {
678 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
679 scm_call_3 (proc, parser->self_scm (), $1, $2);
681 | book_body full_markup {
682 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
683 scm_call_2 (proc, $1, scm_list_1 ($2));
685 | book_body full_markup_list {
686 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
687 scm_call_2 (proc, $1, $2);
691 parser->lexer_->add_scope (unsmob_book ($1)->header_);
693 | book_body embedded_scm { }
695 Book *book = unsmob_book ($1);
697 book->scores_ = SCM_EOL;
698 book->bookparts_ = SCM_EOL;
703 BOOKPART '{' bookpart_body '}' {
705 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
711 Book *book = new Book;
712 book->origin ()->set_spot (@$);
713 $$ = book->unprotect ();
714 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
717 unsmob_book ($1)->origin ()->set_spot (@$);
718 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
720 | bookpart_body paper_block {
721 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
723 | bookpart_body score_block {
724 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
725 scm_call_2 (proc, $1, $2);
727 | bookpart_body composite_music {
728 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
729 scm_call_3 (proc, parser->self_scm (), $1, $2);
731 | bookpart_body full_markup {
732 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
733 scm_call_2 (proc, $1, scm_list_1 ($2));
735 | bookpart_body full_markup_list {
736 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
737 scm_call_2 (proc, $1, $2);
741 Book *book = unsmob_book ($1);
742 if (!ly_is_module (book->header_))
743 book->header_ = ly_make_module (false);
744 parser->lexer_->add_scope (book->header_);
746 | bookpart_body embedded_scm { }
747 | bookpart_body error {
748 Book *book = unsmob_book ($1);
750 book->scores_ = SCM_EOL;
755 SCORE '{' score_body '}' {
762 SCM scorify = ly_lily_module_constant ("scorify-music");
763 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
765 unsmob_score ($$)->origin ()->set_spot (@$);
768 unsmob_score ($$)->origin ()->set_spot (@$);
772 Score *score = unsmob_score ($1);
773 if (!ly_is_module (score->get_header ()))
774 score->set_header (ly_make_module (false));
775 parser->lexer_->add_scope (score->get_header ());
777 | score_body output_def {
778 Output_def *od = unsmob_output_def ($2);
779 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
781 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
786 unsmob_score ($1)->add_output_def (od);
790 unsmob_score ($$)->error_found_ = true;
801 Output_def *od = unsmob_output_def ($1);
803 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
805 parser->parser_error (@1, _ ("need \\paper for paper block"));
806 $$ = get_paper (parser)->unprotect ();
813 output_def_body '}' {
816 parser->lexer_->remove_scope ();
817 parser->lexer_->pop_state ();
823 Output_def *p = get_paper (parser);
824 p->input_origin_ = @$;
825 parser->lexer_->add_scope (p->scope_);
826 $$ = p->unprotect ();
829 Output_def *p = get_midi (parser);
830 $$ = p->unprotect ();
831 parser->lexer_->add_scope (p->scope_);
834 Output_def *p = get_layout (parser);
836 parser->lexer_->add_scope (p->scope_);
837 $$ = p->unprotect ();
841 output_def_head_with_mode_switch:
843 parser->lexer_->push_initial_state ();
848 // We need this weird nonterminal because both music as well as a
849 // context definition can start with \context and the difference is
850 // only apparent after looking at the next token. If it is '{', there
851 // is still time to escape from notes mode.
853 music_or_context_def:
856 parser->lexer_->pop_state ();
860 parser->lexer_->pop_state ();
861 } '{' context_def_spec_body '}'
868 output_def_head_with_mode_switch '{' {
870 unsmob_output_def ($$)->input_origin_.set_spot (@$);
872 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
873 Output_def *o = unsmob_output_def ($3);
874 o->input_origin_.set_spot (@$);
876 parser->lexer_->remove_scope ();
877 parser->lexer_->add_scope (o->scope_);
879 | output_def_body assignment {
884 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
885 parser->lexer_->push_note_state (nn);
886 } music_or_context_def
888 if (unsmob_context_def ($3))
889 assign_context_def (unsmob_output_def ($1), $3);
892 SCM proc = parser->lexer_->lookup_identifier
893 ("output-def-music-handler");
894 scm_call_3 (proc, parser->self_scm (),
898 | output_def_body error {
904 TEMPO steno_duration '=' tempo_range {
905 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
907 | TEMPO scalar_closed steno_duration '=' tempo_range {
908 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
911 $$ = MAKE_SYNTAX ("tempo", @$, $2);
916 The representation of a list is reversed to have efficient append. */
922 | music_list music_embedded {
923 if (unsmob_music ($2))
924 $$ = scm_cons ($2, $1);
927 Music *m = MY_MAKE_MUSIC("Music", @$);
929 m->set_property ("error-found", SCM_BOOL_T);
930 $$ = scm_cons (m->self_scm (), $1);
931 m->unprotect (); /* UGH */
938 $$ = scm_reverse_x ($2, SCM_EOL);
943 | lyric_element_music
950 if (unsmob_music ($1)
951 || scm_is_eq ($1, SCM_UNSPECIFIED))
955 @$.warning (_ ("Ignoring non-music expression"));
956 $$ = SCM_UNSPECIFIED;
964 if (unsmob_pitch ($1)) {
965 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
966 n->set_property ("pitch", $1);
967 n->set_property ("duration",
968 parser->default_duration_.smobbed_copy ());
969 $$ = n->unprotect ();
972 | composite_music %prec COMPOSITE
977 | composite_music %prec COMPOSITE
978 | lyric_element_music
982 REPEAT simple_string unsigned_number music
984 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
986 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
988 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
993 SEQUENTIAL braced_music_list {
994 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
996 | braced_music_list {
997 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1002 SIMULTANEOUS braced_music_list {
1003 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1005 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1006 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1012 | music_property_def
1016 context_modification:
1017 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1019 parser->lexer_->pop_state ();
1022 | WITH CONTEXT_MOD_IDENTIFIER
1026 | CONTEXT_MOD_IDENTIFIER
1030 | WITH embedded_scm_closed
1032 if (unsmob_context_mod ($2))
1035 parser->parser_error (@2, _ ("not a context mod"));
1036 $$ = Context_mod ().smobbed_copy ();
1041 optional_context_mod:
1045 | context_modification
1053 $$ = Context_mod ().smobbed_copy ();
1055 | context_mod_list context_mod {
1056 unsmob_context_mod ($1)->add_context_mod ($2);
1058 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1059 Context_mod *md = unsmob_context_mod ($2);
1061 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1063 | context_mod_list context_mod_embedded {
1064 unsmob_context_mod ($1)->add_context_mods
1065 (unsmob_context_mod ($2)->get_mods ());
1074 /* Music that can be parsed without lookahead */
1077 | complex_music_prefix closed_music
1079 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1081 | music_function_call_closed
1087 | grouped_music_list
1091 simultaneous_music { $$ = $1; }
1092 | sequential_music { $$ = $1; }
1095 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1096 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1097 and this rule returns the reversed list of arguments. */
1099 function_arglist_skip:
1100 function_arglist_common
1101 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1103 $$ = scm_cons ($1, $3);
1104 } %prec FUNCTION_ARGLIST
1105 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1107 $$ = scm_cons ($1, $3);
1108 } %prec FUNCTION_ARGLIST
1109 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1111 $$ = scm_cons ($1, $3);
1112 } %prec FUNCTION_ARGLIST
1116 function_arglist_nonbackup_common:
1117 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1118 $$ = scm_cons ($4, $3);
1120 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1121 $$ = scm_cons ($4, $3);
1123 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1125 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1127 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1129 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1131 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1133 SCM n = scm_difference ($5, SCM_UNDEFINED);
1134 if (scm_is_true (scm_call_1 ($2, n)))
1135 $$ = scm_cons (n, $3);
1137 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1138 t->set_property ("digit", $5);
1139 $$ = t->unprotect ();
1140 if (scm_is_true (scm_call_1 ($2, $$)))
1141 $$ = scm_cons ($$, $3);
1143 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1147 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1149 $$ = check_scheme_arg (parser, @4,
1150 scm_difference ($5, SCM_UNDEFINED),
1153 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1155 $$ = check_scheme_arg (parser, @4,
1156 scm_difference ($5, SCM_UNDEFINED),
1161 function_arglist_closed_nonbackup:
1162 function_arglist_nonbackup_common
1163 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1165 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1167 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1169 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1173 function_arglist_nonbackup:
1174 function_arglist_nonbackup_common
1175 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1177 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1179 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1181 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1185 function_arglist_keep:
1186 function_arglist_common
1187 | function_arglist_backup
1190 function_arglist_closed_keep:
1191 function_arglist_closed_common
1192 | function_arglist_backup
1195 function_arglist_backup:
1196 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1198 if (scm_is_true (scm_call_1 ($2, $4)))
1200 $$ = scm_cons ($4, $3);
1202 $$ = scm_cons (loc_on_music (@3, $1), $3);
1203 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1206 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1208 if (scm_is_true (scm_call_1 ($2, $4)))
1210 $$ = scm_cons ($4, $3);
1212 $$ = scm_cons (loc_on_music (@3, $1), $3);
1213 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1216 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1218 // There is no point interpreting a lyrics string as
1219 // an event, since we don't allow music possibly
1220 // followed by durations or postevent into closed
1221 // music, and we only accept closed music in optional
1222 // arguments at the moment. If this changes, more
1223 // complex schemes might become interesting here as
1224 // well: see how we do this at the mandatory argument
1226 if (scm_is_true (scm_call_1 ($2, $4)))
1227 $$ = scm_cons ($4, $3);
1229 $$ = scm_cons (loc_on_music (@3, $1), $3);
1230 MYBACKUP (LYRICS_STRING, $4, @4);
1233 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1235 if (scm_is_true (scm_call_1 ($2, $4)))
1238 MYREPARSE (@4, $2, UNSIGNED, $4);
1240 $$ = scm_cons (loc_on_music (@3, $1), $3);
1241 MYBACKUP (UNSIGNED, $4, @4);
1244 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1246 if (scm_is_true (scm_call_1 ($2, $4)))
1249 MYREPARSE (@4, $2, REAL, $4);
1251 $$ = scm_cons (loc_on_music (@3, $1), $3);
1252 MYBACKUP (REAL, $4, @4);
1255 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1257 if (scm_is_true (scm_call_1 ($2, $4)))
1259 $$ = scm_cons ($4, $3);
1261 $$ = scm_cons (loc_on_music (@3, $1), $3);
1262 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1265 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1267 if (scm_is_true (scm_call_1 ($2, $4)))
1269 $$ = scm_cons ($4, $3);
1271 $$ = scm_cons (loc_on_music (@3, $1), $3);
1272 MYBACKUP (FRACTION, $4, @4);
1275 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1277 SCM n = scm_difference ($5, SCM_UNDEFINED);
1278 if (scm_is_true (scm_call_1 ($2, n))) {
1280 MYREPARSE (@5, $2, REAL, n);
1282 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1283 t->set_property ("digit", $5);
1284 $$ = t->unprotect ();
1285 if (scm_is_true (scm_call_1 ($2, $$)))
1286 $$ = scm_cons ($$, $3);
1288 $$ = scm_cons (loc_on_music (@3, $1), $3);
1289 MYBACKUP (UNSIGNED, $5, @5);
1290 parser->lexer_->push_extra_token ('-');
1295 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1297 SCM n = scm_difference ($5, SCM_UNDEFINED);
1298 if (scm_is_true (scm_call_1 ($2, n))) {
1299 MYREPARSE (@5, $2, REAL, n);
1302 MYBACKUP (REAL, n, @5);
1305 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1307 SCM n = scm_difference ($5, SCM_UNDEFINED);
1308 if (scm_is_true (scm_call_1 ($2, n))) {
1309 $$ = scm_cons (n, $3);
1311 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1314 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1316 $$ = scm_cons ($4, $3);
1318 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1320 $$ = scm_cons ($4, $3);
1322 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1324 $$ = scm_cons ($1, $3);
1325 MYBACKUP(0, SCM_UNDEFINED, @3);
1327 | function_arglist_backup REPARSE embedded_scm_arg_closed
1329 $$ = check_scheme_arg (parser, @3,
1332 | function_arglist_backup REPARSE bare_number
1334 $$ = check_scheme_arg (parser, @3,
1340 function_arglist_common
1341 | function_arglist_nonbackup
1344 function_arglist_common:
1345 function_arglist_bare
1346 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1348 $$ = check_scheme_arg (parser, @3,
1351 | EXPECT_SCM function_arglist_closed_optional bare_number
1353 $$ = check_scheme_arg (parser, @3,
1356 | EXPECT_SCM function_arglist_closed_optional FRACTION
1358 $$ = check_scheme_arg (parser, @3,
1361 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1363 $$ = check_scheme_arg (parser, @3,
1366 | function_arglist_common_minus
1367 | function_arglist_common_lyric
1370 function_arglist_common_lyric:
1371 EXPECT_SCM function_arglist_optional lyric_element
1373 // We check how the predicate thinks about a lyrics
1374 // event or about a markup. If it accepts neither, we
1375 // backup the original token. Otherwise we commit to
1376 // taking the token. Depending on what the predicate
1377 // is willing to accept, we interpret as a string, as
1378 // a lyric event, or ambiguously (meaning that if
1379 // something looking like a duration or post event
1380 // follows, we take the event, otherwise the string).
1381 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1382 parser->default_duration_.smobbed_copy ());
1383 if (scm_is_true (scm_call_1 ($1, $3)))
1384 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1387 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1389 $$ = scm_cons ($3, $2);
1391 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1394 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1396 // This is going to flag a syntax error, we
1397 // know the predicate to be false.
1398 check_scheme_arg (parser, @3,
1402 | function_arglist_common_lyric REPARSE lyric_element_arg
1404 // This should never be false
1405 $$ = check_scheme_arg (parser, @3,
1410 function_arglist_common_minus:
1411 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1413 SCM n = scm_difference ($4, SCM_UNDEFINED);
1414 if (scm_is_true (scm_call_1 ($1, n))) {
1416 MYREPARSE (@4, $1, REAL, n);
1418 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1419 t->set_property ("digit", $4);
1420 $$ = t->unprotect ();
1421 if (scm_is_true (scm_call_1 ($1, $$)))
1422 $$ = scm_cons ($$, $2);
1424 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1428 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1431 SCM n = scm_difference ($4, SCM_UNDEFINED);
1432 MYREPARSE (@4, $1, REAL, n);
1434 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1436 SCM n = scm_difference ($4, SCM_UNDEFINED);
1437 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1439 | function_arglist_common_minus REPARSE bare_number
1441 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1445 function_arglist_closed:
1446 function_arglist_closed_common
1447 | function_arglist_closed_nonbackup
1450 function_arglist_closed_common:
1451 function_arglist_bare
1452 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1454 $$ = check_scheme_arg (parser, @3,
1457 | EXPECT_SCM function_arglist_closed_optional bare_number
1459 $$ = check_scheme_arg (parser, @3,
1462 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1464 SCM n = scm_difference ($4, SCM_UNDEFINED);
1465 if (scm_is_true (scm_call_1 ($1, n))) {
1466 $$ = scm_cons (n, $2);
1468 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1469 t->set_property ("digit", $4);
1470 $$ = t->unprotect ();
1471 if (scm_is_true (scm_call_1 ($1, $$)))
1472 $$ = scm_cons ($$, $2);
1474 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1478 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1480 $$ = check_scheme_arg (parser, @3,
1481 scm_difference ($4, SCM_UNDEFINED),
1484 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1486 $$ = check_scheme_arg (parser, @3,
1487 scm_difference ($4, SCM_UNDEFINED),
1490 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1492 $$ = check_scheme_arg (parser, @3,
1495 | EXPECT_SCM function_arglist_closed_optional FRACTION
1497 $$ = check_scheme_arg (parser, @3,
1500 | EXPECT_SCM function_arglist_optional lyric_element
1502 $$ = check_scheme_arg (parser, @3,
1507 function_arglist_optional:
1508 function_arglist_keep %prec FUNCTION_ARGLIST
1509 | function_arglist_backup BACKUP
1510 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1512 $$ = scm_cons ($1, $3);
1514 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1516 $$ = scm_cons ($1, $3);
1520 function_arglist_closed_optional:
1521 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1522 | function_arglist_backup BACKUP
1523 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1525 $$ = scm_cons ($1, $3);
1527 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1529 $$ = scm_cons ($1, $3);
1533 embedded_scm_closed:
1535 | scm_function_call_closed
1538 embedded_scm_arg_closed:
1539 embedded_scm_bare_arg
1540 | scm_function_call_closed
1544 scm_function_call_closed:
1545 SCM_FUNCTION function_arglist_closed {
1546 $$ = MAKE_SYNTAX ("music-function", @$,
1548 } %prec FUNCTION_ARGLIST
1551 function_arglist_bare:
1552 EXPECT_NO_MORE_ARGS {
1555 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1556 $$ = scm_cons ($3, $2);
1558 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1559 $$ = scm_cons ($3, $2);
1561 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1562 $$ = scm_cons ($1, $3);
1564 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1565 $$ = scm_cons ($1, $3);
1567 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1568 $$ = scm_cons ($1, $3);
1572 music_function_call:
1573 MUSIC_FUNCTION function_arglist {
1574 $$ = MAKE_SYNTAX ("music-function", @$,
1581 /**/ { $$ = SCM_EOL; }
1582 | '=' simple_string {
1589 | repeated_music { $$ = $1; }
1590 | re_rhythmed_music { $$ = $1; }
1591 | complex_music_prefix music
1593 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1597 complex_music_prefix:
1598 CONTEXT simple_string optional_id optional_context_mod {
1599 Context_mod *ctxmod = unsmob_context_mod ($4);
1602 mods = ctxmod->get_mods ();
1603 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1605 | NEWCONTEXT simple_string optional_id optional_context_mod {
1606 Context_mod *ctxmod = unsmob_context_mod ($4);
1609 mods = ctxmod->get_mods ();
1610 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1615 mode_changing_head grouped_music_list {
1616 if ($1 == ly_symbol2scm ("chords"))
1618 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1624 parser->lexer_->pop_state ();
1626 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1627 Context_mod *ctxmod = unsmob_context_mod ($2);
1630 mods = ctxmod->get_mods ();
1631 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1632 if ($1 == ly_symbol2scm ("ChordNames"))
1634 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1636 parser->lexer_->pop_state ();
1642 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1643 parser->lexer_->push_note_state (nn);
1645 $$ = ly_symbol2scm ("notes");
1649 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1650 parser->lexer_->push_note_state (nn);
1652 $$ = ly_symbol2scm ("drums");
1655 parser->lexer_->push_figuredbass_state ();
1657 $$ = ly_symbol2scm ("figures");
1660 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1661 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1662 nn = parser->lexer_->lookup_identifier ("pitchnames");
1663 parser->lexer_->push_chord_state (nn);
1664 $$ = ly_symbol2scm ("chords");
1668 { parser->lexer_->push_lyric_state ();
1669 $$ = ly_symbol2scm ("lyrics");
1673 mode_changing_head_with_context:
1675 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1676 parser->lexer_->push_note_state (nn);
1678 $$ = ly_symbol2scm ("DrumStaff");
1681 parser->lexer_->push_figuredbass_state ();
1683 $$ = ly_symbol2scm ("FiguredBass");
1686 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1687 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1688 nn = parser->lexer_->lookup_identifier ("pitchnames");
1689 parser->lexer_->push_chord_state (nn);
1690 $$ = ly_symbol2scm ("ChordNames");
1693 { parser->lexer_->push_lyric_state ();
1694 $$ = ly_symbol2scm ("Lyrics");
1699 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1702 /* Can also use music at the expensive of two S/Rs similar to
1703 \repeat \alternative */
1704 parser->lexer_->pop_state ();
1706 $$ = scm_cons ($3, SCM_EOL);
1708 | new_lyrics ADDLYRICS {
1709 parser->lexer_->push_lyric_state ();
1711 parser->lexer_->pop_state ();
1712 $$ = scm_cons ($4, $1);
1717 composite_music new_lyrics {
1718 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1720 | LYRICSTO simple_string {
1721 parser->lexer_->push_lyric_state ();
1723 parser->lexer_->pop_state ();
1724 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1729 CHANGE STRING '=' STRING {
1730 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1735 property_path_revved:
1736 embedded_scm_closed {
1737 $$ = scm_cons ($1, SCM_EOL);
1739 | property_path_revved embedded_scm_closed {
1740 $$ = scm_cons ($2, $1);
1745 property_path_revved {
1746 $$ = scm_reverse_x ($1, SCM_EOL);
1752 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1753 scm_string_to_symbol ($1), $3);
1755 | UNSET simple_string {
1756 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1757 scm_string_to_symbol ($2));
1759 | OVERRIDE simple_string property_path '=' scalar {
1760 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1761 scm_string_to_symbol ($2), $5),
1764 | REVERT simple_string embedded_scm {
1765 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1766 scm_string_to_symbol ($2), $3);
1771 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1772 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1774 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1775 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1776 | DENIES { $$ = ly_symbol2scm ("denies"); }
1778 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1779 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1780 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1781 | NAME { $$ = ly_symbol2scm ("context-name"); }
1785 property_operation { $$ = $1; }
1786 | context_def_mod STRING {
1787 $$ = scm_list_2 ($1, $2);
1789 | context_def_mod embedded_scm
1791 if (!scm_is_string ($2)
1792 && ly_symbol2scm ("consists") != $1
1793 && ly_symbol2scm ("remove") != $1)
1796 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1800 $$ = scm_list_2 ($1, $2);
1807 if (!is_regular_identifier ($1))
1809 @$.error (_("Grob name should be alphanumeric"));
1812 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1813 scm_string_to_symbol ($1));
1815 | simple_string '.' simple_string {
1816 $$ = scm_list_2 (scm_string_to_symbol ($1),
1817 scm_string_to_symbol ($3));
1821 simple_music_property_def:
1822 OVERRIDE context_prop_spec property_path '=' scalar {
1823 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1824 ly_symbol2scm ("OverrideProperty"),
1829 | REVERT context_prop_spec embedded_scm {
1830 $$ = scm_list_4 (scm_car ($2),
1831 ly_symbol2scm ("RevertProperty"),
1835 | SET context_prop_spec '=' scalar {
1836 $$ = scm_list_4 (scm_car ($2),
1837 ly_symbol2scm ("PropertySet"),
1841 | UNSET context_prop_spec {
1842 $$ = scm_list_3 (scm_car ($2),
1843 ly_symbol2scm ("PropertyUnset"),
1849 simple_music_property_def {
1850 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
1859 | string '+' string {
1860 if (!scm_is_string ($1)) {
1861 parser->parser_error (@1, (_ ("simple string expected")));
1862 $1 = scm_string (SCM_EOL);
1864 if (!scm_is_string ($3)) {
1865 parser->parser_error (@3, (_ ("simple string expected")));
1866 $3 = scm_string (SCM_EOL);
1868 $$ = scm_string_append (scm_list_2 ($1, $3));
1872 simple_string: STRING {
1880 if (scm_is_string ($1)) {
1883 parser->parser_error (@1, (_ ("simple string expected")));
1884 $$ = scm_string (SCM_EOL);
1887 | LYRIC_MARKUP_IDENTIFIER
1889 if (scm_is_string ($1)) {
1892 parser->parser_error (@1, (_ ("simple string expected")));
1893 $$ = scm_string (SCM_EOL);
1906 embedded_scm_arg_closed
1914 simple_element post_events {
1915 // Let the rhythmic music iterator sort this mess out.
1916 if (scm_is_pair ($2)) {
1917 if (unsmob_pitch ($1)) {
1918 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1919 n->set_property ("pitch", $1);
1920 n->set_property ("duration",
1921 parser->default_duration_.smobbed_copy ());
1922 $$ = n->unprotect ();
1924 unsmob_music ($$)->set_property ("articulations",
1925 scm_reverse_x ($2, SCM_EOL));
1928 | simple_chord_elements post_events {
1929 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1932 /* why is this giving wrong start location? -ns
1934 i.set_location (@1, @2);
1935 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1937 | CHORD_REPETITION optional_notemode_duration post_events {
1939 i.set_location (@1, @3);
1940 $$ = MAKE_SYNTAX ("repetition-chord", i,
1941 $2, scm_reverse_x ($3, SCM_EOL));
1943 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1945 i.set_location (@1, @3);
1946 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1947 scm_reverse_x ($3, SCM_EOL));
1950 | note_chord_element
1955 chord_body optional_notemode_duration post_events
1957 Music *m = unsmob_music ($1);
1958 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1959 SCM es = m->get_property ("elements");
1960 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1962 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1963 unsmob_music (scm_car (s))->set_property ("duration", dur);
1964 es = ly_append2 (es, postevs);
1966 m-> set_property ("elements", es);
1968 $$ = m->self_scm ();
1973 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1975 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1979 chord_body_elements:
1980 /* empty */ { $$ = SCM_EOL; }
1981 | chord_body_elements chord_body_element {
1982 if (!SCM_UNBNDP ($2))
1983 $$ = scm_cons ($2, $1);
1988 pitch exclamations questions octave_check post_events
1990 bool q = to_boolean ($3);
1991 bool ex = to_boolean ($2);
1995 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1996 n->set_property ("pitch", $1);
1998 n->set_property ("cautionary", SCM_BOOL_T);
2000 n->set_property ("force-accidental", SCM_BOOL_T);
2002 if (scm_is_pair (post)) {
2003 SCM arts = scm_reverse_x (post, SCM_EOL);
2004 n->set_property ("articulations", arts);
2006 if (scm_is_number (check))
2008 int q = scm_to_int (check);
2009 n->set_property ("absolute-octave", scm_from_int (q-1));
2012 $$ = n->unprotect ();
2014 | DRUM_PITCH post_events {
2015 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2016 n->set_property ("drum-type", $1);
2018 if (scm_is_pair ($2)) {
2019 SCM arts = scm_reverse_x ($2, SCM_EOL);
2020 n->set_property ("articulations", arts);
2022 $$ = n->unprotect ();
2024 | music_function_chord_body
2026 Music *m = unsmob_music ($1);
2028 while (m && m->is_mus_type ("music-wrapper-music")) {
2029 $$ = m->get_property ("element");
2030 m = unsmob_music ($$);
2033 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2034 parser->parser_error (@$, _ ("not a rhythmic event"));
2040 music_function_chord_body:
2045 // Event functions may only take closed arglists, otherwise it would
2046 // not be clear whether a following postevent should be associated
2047 // with the last argument of the event function or with the expression
2048 // for which the function call acts itself as event.
2050 music_function_call_closed:
2051 MUSIC_FUNCTION function_arglist_closed {
2052 $$ = MAKE_SYNTAX ("music-function", @$,
2057 event_function_event:
2058 EVENT_FUNCTION function_arglist_closed {
2059 $$ = MAKE_SYNTAX ("music-function", @$,
2069 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2070 m->set_property ("span-direction", scm_from_int (START));
2071 $$ = m->unprotect();
2074 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2075 m->set_property ("span-direction", scm_from_int (STOP));
2076 $$ = m->unprotect ();
2079 $$ = MAKE_SYNTAX ("voice-separator", @$);
2082 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2084 Music *m = unsmob_music (pipe);
2089 $$ = m->unprotect ();
2092 $$ = MAKE_SYNTAX ("bar-check", @$);
2099 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2111 | post_events post_event {
2112 unsmob_music ($2)->set_spot (@2);
2113 $$ = scm_cons ($2, $$);
2117 post_event_nofinger:
2118 direction_less_event {
2121 | script_dir music_function_call_closed {
2123 if (!SCM_UNBNDP ($1))
2125 unsmob_music ($$)->set_property ("direction", $1);
2129 if (!parser->lexer_->is_lyric_state ())
2130 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2131 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2134 if (!parser->lexer_->is_lyric_state ())
2135 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2136 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2138 | script_dir direction_reqd_event {
2139 if (!SCM_UNBNDP ($1))
2141 Music *m = unsmob_music ($2);
2142 m->set_property ("direction", $1);
2146 | script_dir direction_less_event {
2147 if (!SCM_UNBNDP ($1))
2149 Music *m = unsmob_music ($2);
2150 m->set_property ("direction", $1);
2157 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2162 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2173 string_number_event:
2175 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2176 s->set_property ("string-number", $1);
2177 $$ = s->unprotect ();
2181 direction_less_char:
2183 $$ = ly_symbol2scm ("bracketOpenSymbol");
2186 $$ = ly_symbol2scm ("bracketCloseSymbol");
2189 $$ = ly_symbol2scm ("tildeSymbol");
2192 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2195 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2198 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2201 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2204 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2207 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2210 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2214 direction_less_event:
2215 direction_less_char {
2216 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2218 if (unsmob_music (predefd))
2220 m = unsmob_music (predefd)->clone ();
2225 m = MY_MAKE_MUSIC ("Music", @$);
2227 $$ = m->unprotect ();
2229 | string_number_event
2230 | EVENT_IDENTIFIER {
2234 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2235 a->set_property ("tremolo-type", $1);
2236 $$ = a->unprotect ();
2238 | event_function_event
2241 direction_reqd_event:
2245 | script_abbreviation {
2246 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2247 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2248 if (scm_is_string (s))
2249 a->set_property ("articulation-type", s);
2250 else parser->parser_error (@1, _ ("expecting string as script definition"));
2251 $$ = a->unprotect ();
2256 /**/ { $$ = SCM_EOL; }
2257 | '=' quotes { $$ = $2; }
2271 $$ = scm_from_int (1);
2274 $$ = scm_oneplus ($1);
2280 $$ = scm_from_int (-1);
2283 $$ = scm_oneminus ($1);
2288 NOTENAME_PITCH quotes {
2289 if (!scm_is_eq (SCM_INUM0, $2))
2291 Pitch p = *unsmob_pitch ($1);
2292 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2293 $$ = p.smobbed_copy ();
2303 TONICNAME_PITCH quotes {
2304 if (!scm_is_eq (SCM_INUM0, $2))
2306 Pitch p = *unsmob_pitch ($1);
2307 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2308 $$ = p.smobbed_copy ();
2318 pitch_also_in_chords:
2325 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2326 t->set_property ("text", $1);
2327 $$ = t->unprotect ();
2330 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2331 t->set_property ("text",
2332 make_simple_markup ($1));
2333 $$ = t->unprotect ();
2336 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2337 t->set_property ("text",
2338 make_simple_markup ($1));
2339 $$ = t->unprotect ();
2345 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2346 t->set_property ("digit", $1);
2347 $$ = t->unprotect ();
2351 script_abbreviation:
2353 $$ = scm_from_locale_string ("Hat");
2356 $$ = scm_from_locale_string ("Plus");
2359 $$ = scm_from_locale_string ("Dash");
2362 $$ = scm_from_locale_string ("Bar");
2365 $$ = scm_from_locale_string ("Larger");
2368 $$ = scm_from_locale_string ("Dot");
2371 $$ = scm_from_locale_string ("Underscore");
2376 '_' { $$ = scm_from_int (DOWN); }
2377 | '^' { $$ = scm_from_int (UP); }
2378 | '-' { $$ = SCM_UNDEFINED; }
2382 multiplied_duration {
2387 maybe_notemode_duration:
2391 | multiplied_duration {
2393 parser->default_duration_ = *unsmob_duration ($$);
2398 optional_notemode_duration:
2399 maybe_notemode_duration
2401 if (SCM_UNBNDP ($$))
2402 $$ = parser->default_duration_.smobbed_copy ();
2409 int n = scm_to_int ($1);
2410 if (!is_duration (n))
2411 parser->parser_error (@1, _f ("not a duration: %d", n));
2415 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2417 | DURATION_IDENTIFIER dots {
2418 Duration *d = unsmob_duration ($1);
2419 Duration k (d->duration_log (),
2420 d->dot_count () + scm_to_int ($2));
2421 k = k.compressed (d->factor ());
2422 scm_remember_upto_here_1 ($1);
2423 $$ = k.smobbed_copy ();
2427 multiplied_duration:
2431 | multiplied_duration '*' UNSIGNED {
2432 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2434 | multiplied_duration '*' FRACTION {
2435 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2437 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2446 $$ = scm_oneplus ($1);
2455 int n = scm_to_int ($2);
2456 if (!is_duration (n))
2457 parser->parser_error (@2, _f ("not a duration: %d", n));
2463 UNSIGNED { $$ = $1; }
2464 | STRING { $$ = $1; }
2465 | full_markup { $$ = $1; }
2468 figured_bass_alteration:
2469 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2470 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2471 | '!' { $$ = scm_from_int (0); }
2476 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2477 $$ = bfr->unprotect ();
2480 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2481 $$ = bfr->self_scm ();
2483 if (scm_is_number ($1))
2484 bfr->set_property ("figure", $1);
2485 else if (Text_interface::is_markup ($1))
2486 bfr->set_property ("text", $1);
2492 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2494 | bass_figure figured_bass_alteration {
2495 Music *m = unsmob_music ($1);
2496 if (scm_to_double ($2)) {
2497 SCM salter = m->get_property ("alteration");
2498 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2499 m->set_property ("alteration",
2500 scm_sum (alter, $2));
2502 m->set_property ("alteration", scm_from_int (0));
2505 | bass_figure figured_bass_modification {
2506 Music *m = unsmob_music ($1);
2507 if ($2 == ly_symbol2scm ("plus"))
2509 m->set_property ("augmented", SCM_BOOL_T);
2511 else if ($2 == ly_symbol2scm ("slash"))
2513 m->set_property ("diminished", SCM_BOOL_T);
2515 else if ($2 == ly_symbol2scm ("exclamation"))
2517 m->set_property ("no-continuation", SCM_BOOL_T);
2519 else if ($2 == ly_symbol2scm ("backslash"))
2521 m->set_property ("augmented-slash", SCM_BOOL_T);
2527 figured_bass_modification:
2529 $$ = ly_symbol2scm ("plus");
2532 $$ = ly_symbol2scm ("exclamation");
2535 $$ = ly_symbol2scm ("slash");
2538 $$ = ly_symbol2scm ("backslash");
2548 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2556 | figure_list br_bass_figure {
2557 $$ = scm_cons ($2, $1);
2562 FIGURE_OPEN figure_list FIGURE_CLOSE {
2563 $$ = scm_reverse_x ($2, SCM_EOL);
2569 /**/ { $$ = SCM_BOOL_F; }
2570 | REST { $$ = SCM_BOOL_T; }
2574 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2575 if (!parser->lexer_->is_note_state ())
2576 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2577 if (!SCM_UNBNDP ($2)
2579 || scm_is_number ($4)
2581 || scm_is_true ($6))
2584 if (scm_is_true ($6))
2585 n = MY_MAKE_MUSIC ("RestEvent", @$);
2587 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2589 n->set_property ("pitch", $1);
2590 if (SCM_UNBNDP ($5))
2591 n->set_property ("duration",
2592 parser->default_duration_.smobbed_copy ());
2594 n->set_property ("duration", $5);
2596 if (scm_is_number ($4))
2598 int q = scm_to_int ($4);
2599 n->set_property ("absolute-octave", scm_from_int (q-1));
2602 if (to_boolean ($3))
2603 n->set_property ("cautionary", SCM_BOOL_T);
2604 if (to_boolean ($2) || to_boolean ($3))
2605 n->set_property ("force-accidental", SCM_BOOL_T);
2607 $$ = n->unprotect ();
2610 | DRUM_PITCH optional_notemode_duration {
2611 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2612 n->set_property ("duration", $2);
2613 n->set_property ("drum-type", $1);
2615 $$ = n->unprotect ();
2617 | RESTNAME optional_notemode_duration {
2619 if (ly_scm2string ($1) == "s") {
2621 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2624 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2627 ev->set_property ("duration", $2);
2628 $$ = ev->unprotect ();
2632 simple_chord_elements:
2634 if (!parser->lexer_->is_chord_state ())
2635 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2638 | figure_spec optional_notemode_duration {
2639 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2641 unsmob_music (scm_car (s))->set_property ("duration", $2);
2658 | lyric_element multiplied_duration post_events {
2659 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2660 if (scm_is_pair ($3))
2661 unsmob_music ($$)->set_property
2662 ("articulations", scm_reverse_x ($3, SCM_EOL));
2664 | lyric_element post_event post_events {
2665 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2666 parser->default_duration_.smobbed_copy ());
2667 unsmob_music ($$)->set_property
2668 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2670 | LYRIC_ELEMENT optional_notemode_duration post_events {
2671 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2672 if (scm_is_pair ($3))
2673 unsmob_music ($$)->set_property
2674 ("articulations", scm_reverse_x ($3, SCM_EOL));
2679 lyric_element_music:
2680 lyric_element optional_notemode_duration post_events {
2681 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2682 if (scm_is_pair ($3))
2683 unsmob_music ($$)->set_property
2684 ("articulations", scm_reverse_x ($3, SCM_EOL));
2689 steno_tonic_pitch optional_notemode_duration {
2690 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2692 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2693 SCM its = scm_reverse_x ($4, SCM_EOL);
2694 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2702 | chord_items chord_item {
2703 $$ = scm_cons ($2, $$);
2709 $$ = ly_symbol2scm ("chord-colon");
2712 $$ = ly_symbol2scm ("chord-caret");
2714 | CHORD_SLASH steno_tonic_pitch {
2715 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2717 | CHORD_BASS steno_tonic_pitch {
2718 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2727 $$ = scm_reverse_x ($1, SCM_EOL);
2735 step_number { $$ = scm_cons ($1, SCM_EOL); }
2736 | step_numbers '.' step_number {
2737 $$ = scm_cons ($3, $$);
2743 $$ = make_chord_step ($1, 0);
2746 $$ = make_chord_step ($1, SHARP_ALTERATION);
2748 | UNSIGNED CHORD_MINUS {
2749 $$ = make_chord_step ($1, FLAT_ALTERATION);
2757 | UNSIGNED '~' UNSIGNED {
2758 $$ = scm_cons ($1, $3);
2765 TODO: should deprecate in favor of Scheme?
2769 number_expression '+' number_term {
2770 $$ = scm_sum ($1, $3);
2772 | number_expression '-' number_term {
2773 $$ = scm_difference ($1, $3);
2782 | number_factor '*' number_factor {
2783 $$ = scm_product ($1, $3);
2785 | number_factor '/' number_factor {
2786 $$ = scm_divide ($1, $3);
2791 '-' number_factor { /* %prec UNARY_MINUS */
2792 $$ = scm_difference ($2, SCM_UNDEFINED);
2800 | UNSIGNED NUMBER_IDENTIFIER {
2801 $$ = scm_product ($1, $2);
2803 | REAL NUMBER_IDENTIFIER {
2804 $$ = scm_product ($1, $2);
2820 { $$ = SCM_UNDEFINED; }
2823 if (SCM_UNBNDP ($1))
2831 { $$ = SCM_UNDEFINED; }
2834 if (SCM_UNBNDP ($1))
2842 This should be done more dynamically if possible.
2846 LYRIC_MARKUP_IDENTIFIER {
2850 { parser->lexer_->push_markup_state (); }
2853 parser->lexer_->pop_state ();
2858 MARKUPLIST_IDENTIFIER {
2862 { parser->lexer_->push_markup_state (); }
2865 parser->lexer_->pop_state ();
2874 { parser->lexer_->push_markup_state (); }
2877 parser->lexer_->pop_state ();
2883 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2885 | markup_head_1_list simple_markup {
2886 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2896 if (Text_interface::is_markup ($1))
2897 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
2898 else if (Text_interface::is_markup_list ($1))
2899 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
2901 parser->parser_error (@1, _ ("not a markup"));
2902 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
2909 MARKUPLIST_IDENTIFIER {
2912 | markup_composed_list {
2915 | markup_braced_list {
2918 | markup_command_list {
2919 $$ = scm_list_1 ($1);
2921 | markup_scm MARKUPLIST_IDENTIFIER
2927 markup_composed_list:
2928 markup_head_1_list markup_braced_list {
2929 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2935 '{' markup_braced_list_body '}' {
2936 $$ = scm_reverse_x ($2, SCM_EOL);
2940 markup_braced_list_body:
2941 /* empty */ { $$ = SCM_EOL; }
2942 | markup_braced_list_body markup {
2943 $$ = scm_cons ($2, $1);
2945 | markup_braced_list_body markup_list {
2946 $$ = scm_reverse_x ($2, $1);
2950 markup_command_list:
2951 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2952 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2956 markup_command_basic_arguments:
2957 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2958 $$ = scm_cons ($3, $2);
2960 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2961 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
2963 | EXPECT_NO_MORE_ARGS {
2968 markup_command_list_arguments:
2969 markup_command_basic_arguments { $$ = $1; }
2970 | EXPECT_MARKUP markup_command_list_arguments markup {
2971 $$ = scm_cons ($3, $2);
2976 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2977 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2982 markup_head_1_item {
2983 $$ = scm_list_1 ($1);
2985 | markup_head_1_list markup_head_1_item {
2986 $$ = scm_cons ($2, $1);
2992 $$ = make_simple_markup ($1);
2994 | MARKUP_IDENTIFIER {
2997 | LYRIC_MARKUP_IDENTIFIER {
3001 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
3002 parser->lexer_->push_note_state (nn);
3003 } '{' score_body '}' {
3004 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
3005 parser->lexer_->pop_state ();
3007 | MARKUP_FUNCTION markup_command_basic_arguments {
3008 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
3010 | markup_scm MARKUP_IDENTIFIER
3017 markup_head_1_list simple_markup {
3018 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
3019 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3029 Lily_parser::set_yydebug (bool x)
3035 Lily_parser::do_yyparse ()
3037 SCM retval = SCM_UNDEFINED;
3038 yyparse (this, &retval);
3048 It is a little strange to have this function in this file, but
3049 otherwise, we have to import music classes into the lexer.
3053 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3055 if (unsmob_book (sid)) {
3056 Book *book = unsmob_book (sid)->clone ();
3057 *destination = book->self_scm ();
3060 return BOOK_IDENTIFIER;
3061 } else if (scm_is_number (sid)) {
3063 return NUMBER_IDENTIFIER;
3064 } else if (unsmob_context_def (sid)) {
3065 Context_def *def= unsmob_context_def (sid)->clone ();
3067 *destination = def->self_scm ();
3070 return CONTEXT_DEF_IDENTIFIER;
3071 } else if (unsmob_context_mod (sid)) {
3072 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3074 return CONTEXT_MOD_IDENTIFIER;
3075 } else if (unsmob_score (sid)) {
3076 Score *score = new Score (*unsmob_score (sid));
3077 *destination = score->self_scm ();
3079 score->unprotect ();
3080 return SCORE_IDENTIFIER;
3081 } else if (Music *mus = unsmob_music (sid)) {
3082 mus = mus->clone ();
3083 *destination = mus->self_scm ();
3084 unsmob_music (*destination)->
3085 set_property ("origin", make_input (last_input_));
3087 bool is_event = mus->is_mus_type ("post-event");
3089 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3090 } else if (unsmob_pitch (sid)) {
3091 *destination = unsmob_pitch (sid)->smobbed_copy ();
3092 return PITCH_IDENTIFIER;
3093 } else if (unsmob_duration (sid)) {
3094 *destination = unsmob_duration (sid)->smobbed_copy ();
3095 return DURATION_IDENTIFIER;
3096 } else if (unsmob_output_def (sid)) {
3097 Output_def *p = unsmob_output_def (sid);
3100 *destination = p->self_scm ();
3102 return OUTPUT_DEF_IDENTIFIER;
3103 } else if (Text_interface::is_markup (sid)) {
3105 if (is_lyric_state ())
3106 return LYRIC_MARKUP_IDENTIFIER;
3107 return MARKUP_IDENTIFIER;
3108 } else if (Text_interface::is_markup_list (sid)) {
3110 return MARKUPLIST_IDENTIFIER;
3117 get_next_unique_context_id ()
3119 return scm_from_locale_string ("$uniqueContextId");
3124 get_next_unique_lyrics_context_id ()
3126 static int new_context_count;
3128 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3129 return scm_from_locale_string (s);
3132 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3133 SCM arg, SCM args, SCM pred)
3135 args = scm_cons (arg, args);
3136 if (scm_is_true (scm_call_1 (pred, arg)))
3138 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3139 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3140 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3144 SCM loc_on_music (Input loc, SCM arg)
3146 if (Music *m = unsmob_music (arg))
3150 return m->unprotect ();
3156 is_regular_identifier (SCM id)
3158 string str = ly_scm2string (id);
3159 char const *s = str.c_str ();
3168 v = v && isalnum (*s);
3175 make_music_with_input (SCM name, Input where)
3177 Music *m = make_music_by_name (name);
3178 m->set_spot (where);
3183 make_simple_markup (SCM a)
3191 return t && t == 1 << intlog2 (t);
3195 make_chord_step (SCM step_scm, Rational alter)
3197 int step = scm_to_int (step_scm);
3200 alter += FLAT_ALTERATION;
3204 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3205 return m.smobbed_copy ();
3210 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3212 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3213 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3214 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3216 unsmob_music (scm_car (s))->set_spot (loc);
3222 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3224 Lily_lexer *lex = parser->lexer_;
3228 lex->prepare_for_next_token ();
3229 return lex->yylex ();