1 /* -*- mode: c++; c-file-style: "linux" -*- */
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);
235 void set_music_properties (Music *p, SCM a);
239 /* The third option is an alias that will be used to display the
240 syntax error. Bison CVS now correctly handles backslash escapes.
242 FIXME: Bison needs to translate some of these, eg, STRING.
246 /* Keyword tokens with plain escaped name. */
247 %token END_OF_FILE 0 "end of input"
248 %token ACCEPTS "\\accepts"
249 %token ADDLYRICS "\\addlyrics"
250 %token ALIAS "\\alias"
251 %token ALTERNATIVE "\\alternative"
253 %token BOOKPART "\\bookpart"
254 %token CHANGE "\\change"
255 %token CHORDMODE "\\chordmode"
256 %token CHORDS "\\chords"
257 %token CONSISTS "\\consists"
258 %token CONTEXT "\\context"
259 %token DEFAULT "\\default"
260 %token DEFAULTCHILD "\\defaultchild"
261 %token DENIES "\\denies"
262 %token DESCRIPTION "\\description"
263 %token DRUMMODE "\\drummode"
264 %token DRUMS "\\drums"
265 %token FIGUREMODE "\\figuremode"
266 %token FIGURES "\\figures"
267 %token HEADER "\\header"
268 %token INVALID "\\version-error"
269 %token LAYOUT "\\layout"
270 %token LYRICMODE "\\lyricmode"
271 %token LYRICS "\\lyrics"
272 %token LYRICSTO "\\lyricsto"
273 %token MARKUP "\\markup"
274 %token MARKUPLIST "\\markuplist"
277 %token NOTEMODE "\\notemode"
278 %token OVERRIDE "\\override"
279 %token PAPER "\\paper"
280 %token REMOVE "\\remove"
281 %token REPEAT "\\repeat"
283 %token REVERT "\\revert"
284 %token SCORE "\\score"
285 %token SEQUENTIAL "\\sequential"
287 %token SIMULTANEOUS "\\simultaneous"
288 %token TEMPO "\\tempo"
290 %token UNSET "\\unset"
293 /* Keyword token exceptions. */
294 %token NEWCONTEXT "\\new"
297 /* Other string tokens. */
299 %token CHORD_BASS "/+"
300 %token CHORD_CARET "^"
301 %token CHORD_COLON ":"
302 %token CHORD_MINUS "-"
303 %token CHORD_SLASH "/"
304 %token ANGLE_OPEN "<"
305 %token ANGLE_CLOSE ">"
306 %token DOUBLE_ANGLE_OPEN "<<"
307 %token DOUBLE_ANGLE_CLOSE ">>"
308 %token E_BACKSLASH "\\"
309 %token E_ANGLE_CLOSE "\\>"
310 %token E_CHAR "\\C[haracter]"
312 %token E_EXCLAMATION "\\!"
313 %token E_BRACKET_OPEN "\\["
315 %token E_BRACKET_CLOSE "\\]"
316 %token E_ANGLE_OPEN "\\<"
322 If we give names, Bison complains.
324 %token FIGURE_CLOSE /* "\\>" */
325 %token FIGURE_OPEN /* "\\<" */
326 %token FIGURE_SPACE "_"
329 %token CHORDMODIFIERS
331 %token MULTI_MEASURE_REST
337 /* Artificial tokens, for more generic function syntax */
338 %token EXPECT_MARKUP "markup?"
339 %token EXPECT_PITCH "ly:pitch?"
340 %token EXPECT_DURATION "ly:duration?"
341 %token EXPECT_SCM "scheme?"
342 %token BACKUP "(backed-up?)"
343 %token REPARSE "(reparsed?)"
344 %token EXPECT_MARKUP_LIST "markup-list?"
345 %token EXPECT_OPTIONAL "optional?"
346 /* After the last argument. */
347 %token EXPECT_NO_MORE_ARGS;
349 /* An artificial token for parsing embedded Lilypond */
350 %token EMBEDDED_LILY "#{"
352 %token BOOK_IDENTIFIER
353 %token CHORDMODIFIER_PITCH
354 %token CHORD_MODIFIER
355 %token CHORD_REPETITION
356 %token CONTEXT_DEF_IDENTIFIER
357 %token CONTEXT_MOD_IDENTIFIER
359 %token PITCH_IDENTIFIER
360 %token DURATION_IDENTIFIER
361 %token EVENT_IDENTIFIER
362 %token EVENT_FUNCTION
366 %token LYRIC_MARKUP_IDENTIFIER
367 %token MARKUP_FUNCTION
368 %token MARKUP_LIST_FUNCTION
369 %token MARKUP_IDENTIFIER
370 %token MARKUPLIST_IDENTIFIER
371 %token MUSIC_FUNCTION
372 %token MUSIC_IDENTIFIER
373 %token NOTENAME_PITCH
374 %token NUMBER_IDENTIFIER
375 %token OUTPUT_DEF_IDENTIFIER
379 %token SCM_IDENTIFIER
381 %token SCORE_IDENTIFIER
383 %token STRING_IDENTIFIER
384 %token TONICNAME_PITCH
388 /* We don't assign precedence to / and *, because we might need varied
389 prec levels in different prods */
398 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
399 parser->lexer_->push_note_state (nn);
400 } embedded_lilypond {
401 parser->lexer_->pop_state ();
406 lilypond: /* empty */ { $$ = SCM_UNSPECIFIED; }
407 | lilypond toplevel_expression {
409 | lilypond assignment {
412 parser->error_level_ = 1;
415 parser->error_level_ = 1;
422 parser->lexer_->add_scope (get_header (parser));
424 parser->lexer_->set_identifier (ly_symbol2scm ("$defaultheader"), $2);
427 SCM proc = parser->lexer_->lookup_identifier ("toplevel-book-handler");
428 scm_call_2 (proc, parser->self_scm (), $1);
431 SCM proc = parser->lexer_->lookup_identifier ("toplevel-bookpart-handler");
432 scm_call_2 (proc, parser->self_scm (), $1);
435 SCM proc = parser->lexer_->lookup_identifier ("toplevel-score-handler");
436 scm_call_2 (proc, parser->self_scm (), $1);
439 SCM proc = parser->lexer_->lookup_identifier ("toplevel-music-handler");
440 scm_call_2 (proc, parser->self_scm (), $1);
443 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
444 scm_call_2 (proc, parser->self_scm (), scm_list_1 ($1));
447 SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
448 scm_call_2 (proc, parser->self_scm (), $1);
452 Output_def * od = unsmob_output_def ($1);
454 if (od->c_variable ("is-paper") == SCM_BOOL_T)
455 id = ly_symbol2scm ("$defaultpaper");
456 else if (od->c_variable ("is-midi") == SCM_BOOL_T)
457 id = ly_symbol2scm ("$defaultmidi");
458 else if (od->c_variable ("is-layout") == SCM_BOOL_T)
459 id = ly_symbol2scm ("$defaultlayout");
461 parser->lexer_->set_identifier (id, $1);
468 $$ = parser->lexer_->eval_scm_token ($1);
473 embedded_scm_bare_arg:
479 | context_modification
481 | context_def_spec_block
487 /* The generic version may end in music, or not */
495 embedded_scm_bare_arg
501 SCM_FUNCTION function_arglist {
502 $$ = MAKE_SYNTAX ("music-function", @$,
510 $$ = MAKE_SYNTAX ("void-music", @$);
513 | music_embedded music_embedded music_list {
514 $3 = scm_reverse_x ($3, SCM_EOL);
515 if (unsmob_music ($2))
516 $3 = scm_cons ($2, $3);
517 if (unsmob_music ($1))
518 $3 = scm_cons ($1, $3);
519 $$ = MAKE_SYNTAX ("sequential-music", @$, $3);
522 parser->error_level_ = 1;
523 $$ = SCM_UNSPECIFIED;
525 | INVALID embedded_lilypond {
526 parser->error_level_ = 1;
532 lilypond_header_body:
533 /* empty */ { $$ = SCM_UNSPECIFIED; }
534 | lilypond_header_body assignment {
540 HEADER '{' lilypond_header_body '}' {
541 $$ = parser->lexer_->remove_scope ();
550 | LYRICS_STRING { $$ = $1; }
554 assignment_id '=' identifier_init {
555 parser->lexer_->set_identifier ($1, $3);
556 $$ = SCM_UNSPECIFIED;
558 | assignment_id property_path '=' identifier_init {
559 SCM path = scm_cons (scm_string_to_symbol ($1), $2);
560 parser->lexer_->set_identifier (path, $4);
561 $$ = SCM_UNSPECIFIED;
563 | embedded_scm { $$ = SCM_UNSPECIFIED; }
572 | context_def_spec_block
574 | post_event_nofinger
581 | context_modification
584 context_def_spec_block:
585 CONTEXT '{' context_def_spec_body '}'
596 context_mod_embedded:
599 if (unsmob_music ($1)) {
600 SCM proc = parser->lexer_->lookup_identifier ("context-mod-music-handler");
601 $1 = scm_call_2 (proc, parser->self_scm (), $1);
603 if (unsmob_context_mod ($1))
606 parser->parser_error (@1, _ ("not a context mod"));
612 context_def_spec_body:
614 $$ = Context_def::make_scm ();
615 unsmob_context_def ($$)->origin ()->set_spot (@$);
617 | CONTEXT_DEF_IDENTIFIER {
619 unsmob_context_def ($$)->origin ()->set_spot (@$);
621 | context_def_spec_body context_mod {
622 unsmob_context_def ($$)->add_context_mod ($2);
624 | context_def_spec_body context_modification {
625 Context_def *td = unsmob_context_def ($$);
626 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
627 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
628 td->add_context_mod (scm_car (m));
631 | context_def_spec_body context_mod_embedded {
632 Context_def *td = unsmob_context_def ($$);
633 SCM new_mods = unsmob_context_mod ($2)->get_mods ();
634 for (SCM m = new_mods; scm_is_pair (m); m = scm_cdr (m)) {
635 td->add_context_mod (scm_car (m));
643 BOOK '{' book_body '}' {
646 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), SCM_BOOL_F);
651 * Use 'handlers' like for toplevel-* stuff?
652 * grok \layout and \midi? */
655 Book *book = new Book;
656 init_papers (parser);
657 book->origin ()->set_spot (@$);
658 book->paper_ = dynamic_cast<Output_def*> (unsmob_output_def (parser->lexer_->lookup_identifier ("$defaultpaper"))->clone ());
659 book->paper_->unprotect ();
660 push_paper (parser, book->paper_);
661 book->header_ = get_header (parser);
662 $$ = book->unprotect ();
663 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $$);
666 unsmob_book ($1)->origin ()->set_spot (@$);
667 parser->lexer_->set_identifier (ly_symbol2scm ("$current-book"), $1);
669 | book_body paper_block {
670 unsmob_book ($1)->paper_ = unsmob_output_def ($2);
671 set_paper (parser, unsmob_output_def ($2));
673 | book_body bookpart_block {
674 SCM proc = parser->lexer_->lookup_identifier ("book-bookpart-handler");
675 scm_call_2 (proc, $1, $2);
677 | book_body score_block {
678 SCM proc = parser->lexer_->lookup_identifier ("book-score-handler");
679 scm_call_2 (proc, $1, $2);
681 | book_body composite_music {
682 SCM proc = parser->lexer_->lookup_identifier ("book-music-handler");
683 scm_call_3 (proc, parser->self_scm (), $1, $2);
685 | book_body full_markup {
686 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
687 scm_call_2 (proc, $1, scm_list_1 ($2));
689 | book_body full_markup_list {
690 SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
691 scm_call_2 (proc, $1, $2);
695 parser->lexer_->add_scope (unsmob_book ($1)->header_);
697 | book_body embedded_scm { }
699 Book *book = unsmob_book ($1);
701 book->scores_ = SCM_EOL;
702 book->bookparts_ = SCM_EOL;
707 BOOKPART '{' bookpart_body '}' {
709 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), SCM_BOOL_F);
715 Book *book = new Book;
716 book->origin ()->set_spot (@$);
717 $$ = book->unprotect ();
718 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $$);
721 unsmob_book ($1)->origin ()->set_spot (@$);
722 parser->lexer_->set_identifier (ly_symbol2scm ("$current-bookpart"), $1);
724 | bookpart_body paper_block {
725 unsmob_book ($$)->paper_ = unsmob_output_def ($2);
727 | bookpart_body score_block {
728 SCM proc = parser->lexer_->lookup_identifier ("bookpart-score-handler");
729 scm_call_2 (proc, $1, $2);
731 | bookpart_body composite_music {
732 SCM proc = parser->lexer_->lookup_identifier ("bookpart-music-handler");
733 scm_call_3 (proc, parser->self_scm (), $1, $2);
735 | bookpart_body full_markup {
736 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
737 scm_call_2 (proc, $1, scm_list_1 ($2));
739 | bookpart_body full_markup_list {
740 SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
741 scm_call_2 (proc, $1, $2);
745 Book *book = unsmob_book ($1);
746 if (!ly_is_module (book->header_))
747 book->header_ = ly_make_module (false);
748 parser->lexer_->add_scope (book->header_);
750 | bookpart_body embedded_scm { }
751 | bookpart_body error {
752 Book *book = unsmob_book ($1);
754 book->scores_ = SCM_EOL;
759 SCORE '{' score_body '}' {
766 SCM scorify = ly_lily_module_constant ("scorify-music");
767 $$ = scm_call_2 (scorify, $1, parser->self_scm ());
769 unsmob_score ($$)->origin ()->set_spot (@$);
772 unsmob_score ($$)->origin ()->set_spot (@$);
776 Score *score = unsmob_score ($1);
777 if (!ly_is_module (score->get_header ()))
778 score->set_header (ly_make_module (false));
779 parser->lexer_->add_scope (score->get_header ());
781 | score_body output_def {
782 Output_def *od = unsmob_output_def ($2);
783 if (od->lookup_variable (ly_symbol2scm ("is-paper")) == SCM_BOOL_T)
785 parser->parser_error (@2, _("\\paper cannot be used in \\score, use \\layout instead"));
790 unsmob_score ($1)->add_output_def (od);
794 unsmob_score ($$)->error_found_ = true;
805 Output_def *od = unsmob_output_def ($1);
807 if (od->lookup_variable (ly_symbol2scm ("is-paper")) != SCM_BOOL_T)
809 parser->parser_error (@1, _ ("need \\paper for paper block"));
810 $$ = get_paper (parser)->unprotect ();
817 output_def_body '}' {
820 parser->lexer_->remove_scope ();
821 parser->lexer_->pop_state ();
827 Output_def *p = get_paper (parser);
828 p->input_origin_ = @$;
829 parser->lexer_->add_scope (p->scope_);
830 $$ = p->unprotect ();
833 Output_def *p = get_midi (parser);
834 $$ = p->unprotect ();
835 parser->lexer_->add_scope (p->scope_);
838 Output_def *p = get_layout (parser);
840 parser->lexer_->add_scope (p->scope_);
841 $$ = p->unprotect ();
845 output_def_head_with_mode_switch:
847 parser->lexer_->push_initial_state ();
852 // We need this weird nonterminal because both music as well as a
853 // context definition can start with \context and the difference is
854 // only apparent after looking at the next token. If it is '{', there
855 // is still time to escape from notes mode.
857 music_or_context_def:
860 parser->lexer_->pop_state ();
864 parser->lexer_->pop_state ();
865 } '{' context_def_spec_body '}'
872 output_def_head_with_mode_switch '{' {
874 unsmob_output_def ($$)->input_origin_.set_spot (@$);
876 | output_def_head_with_mode_switch '{' OUTPUT_DEF_IDENTIFIER {
877 Output_def *o = unsmob_output_def ($3);
878 o->input_origin_.set_spot (@$);
880 parser->lexer_->remove_scope ();
881 parser->lexer_->add_scope (o->scope_);
883 | output_def_body assignment {
888 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
889 parser->lexer_->push_note_state (nn);
890 } music_or_context_def
892 if (unsmob_context_def ($3))
893 assign_context_def (unsmob_output_def ($1), $3);
896 SCM proc = parser->lexer_->lookup_identifier
897 ("output-def-music-handler");
898 scm_call_3 (proc, parser->self_scm (),
902 | output_def_body error {
908 TEMPO steno_duration '=' tempo_range {
909 $$ = MAKE_SYNTAX ("tempo", @$, SCM_EOL, $2, $4);
911 | TEMPO scalar_closed steno_duration '=' tempo_range {
912 $$ = MAKE_SYNTAX ("tempo", @$, $2, $3, $5);
915 $$ = MAKE_SYNTAX ("tempo", @$, $2);
920 The representation of a list is reversed to have efficient append. */
926 | music_list music_embedded {
927 if (unsmob_music ($2))
928 $$ = scm_cons ($2, $1);
931 Music *m = MY_MAKE_MUSIC("Music", @$);
933 m->set_property ("error-found", SCM_BOOL_T);
934 $$ = scm_cons (m->self_scm (), $1);
935 m->unprotect (); /* UGH */
942 $$ = scm_reverse_x ($2, SCM_EOL);
947 | lyric_element_music
954 if (unsmob_music ($1)
955 || scm_is_eq ($1, SCM_UNSPECIFIED))
959 @$.warning (_ ("Ignoring non-music expression"));
960 $$ = SCM_UNSPECIFIED;
968 if (unsmob_pitch ($1)) {
969 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
970 n->set_property ("pitch", $1);
971 n->set_property ("duration",
972 parser->default_duration_.smobbed_copy ());
973 $$ = n->unprotect ();
976 | composite_music %prec COMPOSITE
981 | composite_music %prec COMPOSITE
982 | lyric_element_music
986 REPEAT simple_string unsigned_number music
988 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, SCM_EOL);
990 | REPEAT simple_string unsigned_number music ALTERNATIVE braced_music_list
992 $$ = MAKE_SYNTAX ("repeat", @$, $2, $3, $4, $6);
997 SEQUENTIAL braced_music_list {
998 $$ = MAKE_SYNTAX ("sequential-music", @$, $2);
1000 | braced_music_list {
1001 $$ = MAKE_SYNTAX ("sequential-music", @$, $1);
1006 SIMULTANEOUS braced_music_list {
1007 $$ = MAKE_SYNTAX ("simultaneous-music", @$, $2);
1009 | DOUBLE_ANGLE_OPEN music_list DOUBLE_ANGLE_CLOSE {
1010 $$ = MAKE_SYNTAX ("simultaneous-music", @$, scm_reverse_x ($2, SCM_EOL));
1016 | music_property_def
1020 context_modification:
1021 WITH { parser->lexer_->push_initial_state (); } '{' context_mod_list '}'
1023 parser->lexer_->pop_state ();
1026 | WITH CONTEXT_MOD_IDENTIFIER
1030 | CONTEXT_MOD_IDENTIFIER
1034 | WITH embedded_scm_closed
1036 if (unsmob_context_mod ($2))
1039 parser->parser_error (@2, _ ("not a context mod"));
1040 $$ = Context_mod ().smobbed_copy ();
1045 optional_context_mod:
1049 | context_modification
1057 $$ = Context_mod ().smobbed_copy ();
1059 | context_mod_list context_mod {
1060 unsmob_context_mod ($1)->add_context_mod ($2);
1062 | context_mod_list CONTEXT_MOD_IDENTIFIER {
1063 Context_mod *md = unsmob_context_mod ($2);
1065 unsmob_context_mod ($1)->add_context_mods (md->get_mods ());
1067 | context_mod_list context_mod_embedded {
1068 unsmob_context_mod ($1)->add_context_mods
1069 (unsmob_context_mod ($2)->get_mods ());
1078 /* Music that can be parsed without lookahead */
1081 | complex_music_prefix closed_music
1083 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1090 | grouped_music_list
1094 simultaneous_music { $$ = $1; }
1095 | sequential_music { $$ = $1; }
1098 /* An argument list. If a function \foo expects scm scm pitch, then the lexer expands \foo into the token sequence:
1099 MUSIC_FUNCTION EXPECT_PITCH EXPECT_SCM EXPECT_SCM EXPECT_NO_MORE_ARGS
1100 and this rule returns the reversed list of arguments. */
1102 function_arglist_skip:
1103 function_arglist_common
1104 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip
1106 $$ = scm_cons ($1, $3);
1107 } %prec FUNCTION_ARGLIST
1108 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip
1110 $$ = scm_cons ($1, $3);
1111 } %prec FUNCTION_ARGLIST
1112 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip
1114 $$ = scm_cons ($1, $3);
1115 } %prec FUNCTION_ARGLIST
1119 function_arglist_nonbackup_common:
1120 EXPECT_OPTIONAL EXPECT_PITCH function_arglist pitch_also_in_chords {
1121 $$ = scm_cons ($4, $3);
1123 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed duration_length {
1124 $$ = scm_cons ($4, $3);
1126 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed FRACTION
1128 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1130 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed post_event_nofinger
1132 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1134 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' UNSIGNED
1136 SCM n = scm_difference ($5, SCM_UNDEFINED);
1137 if (scm_is_true (scm_call_1 ($2, n)))
1138 $$ = scm_cons (n, $3);
1140 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1141 t->set_property ("digit", $5);
1142 $$ = t->unprotect ();
1143 if (scm_is_true (scm_call_1 ($2, $$)))
1144 $$ = scm_cons ($$, $3);
1146 $$ = check_scheme_arg (parser, @4, n, $3, $2);
1150 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' REAL
1152 $$ = check_scheme_arg (parser, @4,
1153 scm_difference ($5, SCM_UNDEFINED),
1156 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed '-' NUMBER_IDENTIFIER
1158 $$ = check_scheme_arg (parser, @4,
1159 scm_difference ($5, SCM_UNDEFINED),
1164 function_arglist_closed_nonbackup:
1165 function_arglist_nonbackup_common
1166 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg_closed
1168 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1170 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number_closed
1172 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1176 function_arglist_nonbackup:
1177 function_arglist_nonbackup_common
1178 | EXPECT_OPTIONAL EXPECT_SCM function_arglist embedded_scm_arg
1180 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1182 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed bare_number
1184 $$ = check_scheme_arg (parser, @4, $4, $3, $2);
1188 function_arglist_keep:
1189 function_arglist_common
1190 | function_arglist_backup
1193 function_arglist_closed_keep:
1194 function_arglist_closed_common
1195 | function_arglist_backup
1198 function_arglist_backup:
1199 EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_arg_closed
1201 if (scm_is_true (scm_call_1 ($2, $4)))
1203 $$ = scm_cons ($4, $3);
1205 $$ = scm_cons (loc_on_music (@3, $1), $3);
1206 MYBACKUP (SCM_IDENTIFIER, $4, @4);
1209 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep post_event_nofinger
1211 if (scm_is_true (scm_call_1 ($2, $4)))
1213 $$ = scm_cons ($4, $3);
1215 $$ = scm_cons (loc_on_music (@3, $1), $3);
1216 MYBACKUP (EVENT_IDENTIFIER, $4, @4);
1219 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep lyric_element
1221 // There is no point interpreting a lyrics string as
1222 // an event, since we don't allow music possibly
1223 // followed by durations or postevent into closed
1224 // music, and we only accept closed music in optional
1225 // arguments at the moment. If this changes, more
1226 // complex schemes might become interesting here as
1227 // well: see how we do this at the mandatory argument
1229 if (scm_is_true (scm_call_1 ($2, $4)))
1230 $$ = scm_cons ($4, $3);
1232 $$ = scm_cons (loc_on_music (@3, $1), $3);
1233 MYBACKUP (LYRICS_STRING, $4, @4);
1236 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep UNSIGNED
1238 if (scm_is_true (scm_call_1 ($2, $4)))
1241 MYREPARSE (@4, $2, UNSIGNED, $4);
1243 $$ = scm_cons (loc_on_music (@3, $1), $3);
1244 MYBACKUP (UNSIGNED, $4, @4);
1247 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep REAL
1249 if (scm_is_true (scm_call_1 ($2, $4)))
1252 MYREPARSE (@4, $2, REAL, $4);
1254 $$ = scm_cons (loc_on_music (@3, $1), $3);
1255 MYBACKUP (REAL, $4, @4);
1258 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep NUMBER_IDENTIFIER
1260 if (scm_is_true (scm_call_1 ($2, $4)))
1262 $$ = scm_cons ($4, $3);
1264 $$ = scm_cons (loc_on_music (@3, $1), $3);
1265 MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
1268 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep FRACTION
1270 if (scm_is_true (scm_call_1 ($2, $4)))
1272 $$ = scm_cons ($4, $3);
1274 $$ = scm_cons (loc_on_music (@3, $1), $3);
1275 MYBACKUP (FRACTION, $4, @4);
1278 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' UNSIGNED
1280 SCM n = scm_difference ($5, SCM_UNDEFINED);
1281 if (scm_is_true (scm_call_1 ($2, n))) {
1283 MYREPARSE (@5, $2, REAL, n);
1285 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @5);
1286 t->set_property ("digit", $5);
1287 $$ = t->unprotect ();
1288 if (scm_is_true (scm_call_1 ($2, $$)))
1289 $$ = scm_cons ($$, $3);
1291 $$ = scm_cons (loc_on_music (@3, $1), $3);
1292 MYBACKUP (UNSIGNED, $5, @5);
1293 parser->lexer_->push_extra_token ('-');
1298 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' REAL
1300 SCM n = scm_difference ($5, SCM_UNDEFINED);
1301 if (scm_is_true (scm_call_1 ($2, n))) {
1302 MYREPARSE (@5, $2, REAL, n);
1305 MYBACKUP (REAL, n, @5);
1308 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_closed_keep '-' NUMBER_IDENTIFIER
1310 SCM n = scm_difference ($5, SCM_UNDEFINED);
1311 if (scm_is_true (scm_call_1 ($2, n))) {
1312 $$ = scm_cons (n, $3);
1314 MYBACKUP (NUMBER_IDENTIFIER, n, @5);
1317 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_keep pitch_also_in_chords
1319 $$ = scm_cons ($4, $3);
1321 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length
1323 $$ = scm_cons ($4, $3);
1325 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_backup BACKUP
1327 $$ = scm_cons ($1, $3);
1328 MYBACKUP(0, SCM_UNDEFINED, @3);
1330 | function_arglist_backup REPARSE embedded_scm_arg_closed
1332 $$ = check_scheme_arg (parser, @3,
1335 | function_arglist_backup REPARSE bare_number
1337 $$ = check_scheme_arg (parser, @3,
1343 function_arglist_common
1344 | function_arglist_nonbackup
1347 function_arglist_common:
1348 function_arglist_bare
1349 | EXPECT_SCM function_arglist_optional embedded_scm_arg
1351 $$ = check_scheme_arg (parser, @3,
1354 | EXPECT_SCM function_arglist_closed_optional bare_number
1356 $$ = check_scheme_arg (parser, @3,
1359 | EXPECT_SCM function_arglist_closed_optional FRACTION
1361 $$ = check_scheme_arg (parser, @3,
1364 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1366 $$ = check_scheme_arg (parser, @3,
1369 | function_arglist_common_minus
1370 | function_arglist_common_lyric
1373 function_arglist_common_lyric:
1374 EXPECT_SCM function_arglist_optional lyric_element
1376 // We check how the predicate thinks about a lyrics
1377 // event or about a markup. If it accepts neither, we
1378 // backup the original token. Otherwise we commit to
1379 // taking the token. Depending on what the predicate
1380 // is willing to accept, we interpret as a string, as
1381 // a lyric event, or ambiguously (meaning that if
1382 // something looking like a duration or post event
1383 // follows, we take the event, otherwise the string).
1384 SCM lyric_event = MAKE_SYNTAX ("lyric-event", @3, $3,
1385 parser->default_duration_.smobbed_copy ());
1386 if (scm_is_true (scm_call_1 ($1, $3)))
1387 if (scm_is_true (scm_call_1 ($1, lyric_event)))
1390 MYREPARSE (@3, $1, LYRICS_STRING, $3);
1392 $$ = scm_cons ($3, $2);
1394 else if (scm_is_true (scm_call_1 ($1, lyric_event)))
1397 MYREPARSE (@3, $1, LYRIC_ELEMENT, $3);
1399 // This is going to flag a syntax error, we
1400 // know the predicate to be false.
1401 check_scheme_arg (parser, @3,
1405 | function_arglist_common_lyric REPARSE lyric_element_arg
1407 // This should never be false
1408 $$ = check_scheme_arg (parser, @3,
1413 function_arglist_common_minus:
1414 EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1416 SCM n = scm_difference ($4, SCM_UNDEFINED);
1417 if (scm_is_true (scm_call_1 ($1, n))) {
1419 MYREPARSE (@4, $1, REAL, n);
1421 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1422 t->set_property ("digit", $4);
1423 $$ = t->unprotect ();
1424 if (scm_is_true (scm_call_1 ($1, $$)))
1425 $$ = scm_cons ($$, $2);
1427 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1431 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1434 SCM n = scm_difference ($4, SCM_UNDEFINED);
1435 MYREPARSE (@4, $1, REAL, n);
1437 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1439 SCM n = scm_difference ($4, SCM_UNDEFINED);
1440 $$ = check_scheme_arg (parser, @4, n, $2, $1);
1442 | function_arglist_common_minus REPARSE bare_number
1444 $$ = check_scheme_arg (parser, @3, $3, $1, $2);
1448 function_arglist_closed:
1449 function_arglist_closed_common
1450 | function_arglist_closed_nonbackup
1453 function_arglist_closed_common:
1454 function_arglist_bare
1455 | EXPECT_SCM function_arglist_optional embedded_scm_arg_closed
1457 $$ = check_scheme_arg (parser, @3,
1460 | EXPECT_SCM function_arglist_closed_optional bare_number
1462 $$ = check_scheme_arg (parser, @3,
1465 | EXPECT_SCM function_arglist_closed_optional '-' UNSIGNED
1467 SCM n = scm_difference ($4, SCM_UNDEFINED);
1468 if (scm_is_true (scm_call_1 ($1, n))) {
1469 $$ = scm_cons (n, $2);
1471 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @4);
1472 t->set_property ("digit", $4);
1473 $$ = t->unprotect ();
1474 if (scm_is_true (scm_call_1 ($1, $$)))
1475 $$ = scm_cons ($$, $2);
1477 $$ = check_scheme_arg (parser, @3, n, $2, $1);
1481 | EXPECT_SCM function_arglist_closed_optional '-' REAL
1483 $$ = check_scheme_arg (parser, @3,
1484 scm_difference ($4, SCM_UNDEFINED),
1487 | EXPECT_SCM function_arglist_closed_optional '-' NUMBER_IDENTIFIER
1489 $$ = check_scheme_arg (parser, @3,
1490 scm_difference ($4, SCM_UNDEFINED),
1493 | EXPECT_SCM function_arglist_closed_optional post_event_nofinger
1495 $$ = check_scheme_arg (parser, @3,
1498 | EXPECT_SCM function_arglist_closed_optional FRACTION
1500 $$ = check_scheme_arg (parser, @3,
1503 | EXPECT_SCM function_arglist_optional lyric_element
1505 $$ = check_scheme_arg (parser, @3,
1510 function_arglist_optional:
1511 function_arglist_keep %prec FUNCTION_ARGLIST
1512 | function_arglist_backup BACKUP
1513 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_optional
1515 $$ = scm_cons ($1, $3);
1517 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_optional
1519 $$ = scm_cons ($1, $3);
1523 function_arglist_closed_optional:
1524 function_arglist_closed_keep %prec FUNCTION_ARGLIST
1525 | function_arglist_backup BACKUP
1526 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_closed_optional
1528 $$ = scm_cons ($1, $3);
1530 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_optional
1532 $$ = scm_cons ($1, $3);
1536 embedded_scm_closed:
1538 | scm_function_call_closed
1541 embedded_scm_arg_closed:
1542 embedded_scm_bare_arg
1543 | scm_function_call_closed
1547 scm_function_call_closed:
1548 SCM_FUNCTION function_arglist_closed {
1549 $$ = MAKE_SYNTAX ("music-function", @$,
1551 } %prec FUNCTION_ARGLIST
1554 function_arglist_bare:
1555 EXPECT_NO_MORE_ARGS {
1558 | EXPECT_PITCH function_arglist_optional pitch_also_in_chords {
1559 $$ = scm_cons ($3, $2);
1561 | EXPECT_DURATION function_arglist_closed_optional duration_length {
1562 $$ = scm_cons ($3, $2);
1564 | EXPECT_OPTIONAL EXPECT_PITCH function_arglist_skip DEFAULT {
1565 $$ = scm_cons ($1, $3);
1567 | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_skip DEFAULT {
1568 $$ = scm_cons ($1, $3);
1570 | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip DEFAULT {
1571 $$ = scm_cons ($1, $3);
1575 music_function_call:
1576 MUSIC_FUNCTION function_arglist {
1577 $$ = MAKE_SYNTAX ("music-function", @$,
1584 /**/ { $$ = SCM_EOL; }
1585 | '=' simple_string {
1592 | repeated_music { $$ = $1; }
1593 | re_rhythmed_music { $$ = $1; }
1594 | complex_music_prefix music
1596 $$ = FINISH_MAKE_SYNTAX ($1, @$, $2);
1600 complex_music_prefix:
1601 CONTEXT simple_string optional_id optional_context_mod {
1602 Context_mod *ctxmod = unsmob_context_mod ($4);
1605 mods = ctxmod->get_mods ();
1606 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_F);
1608 | NEWCONTEXT simple_string optional_id optional_context_mod {
1609 Context_mod *ctxmod = unsmob_context_mod ($4);
1612 mods = ctxmod->get_mods ();
1613 $$ = START_MAKE_SYNTAX ("context-specification", $2, $3, mods, SCM_BOOL_T);
1618 mode_changing_head grouped_music_list {
1619 if ($1 == ly_symbol2scm ("chords"))
1621 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $2);
1627 parser->lexer_->pop_state ();
1629 | mode_changing_head_with_context optional_context_mod grouped_music_list {
1630 Context_mod *ctxmod = unsmob_context_mod ($2);
1633 mods = ctxmod->get_mods ();
1634 $$ = MAKE_SYNTAX ("context-specification", @$, $1, SCM_EOL, mods, SCM_BOOL_T, $3);
1635 if ($1 == ly_symbol2scm ("ChordNames"))
1637 $$ = MAKE_SYNTAX ("unrelativable-music", @$, $$);
1639 parser->lexer_->pop_state ();
1645 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
1646 parser->lexer_->push_note_state (nn);
1648 $$ = ly_symbol2scm ("notes");
1652 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1653 parser->lexer_->push_note_state (nn);
1655 $$ = ly_symbol2scm ("drums");
1658 parser->lexer_->push_figuredbass_state ();
1660 $$ = ly_symbol2scm ("figures");
1663 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1664 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1665 nn = parser->lexer_->lookup_identifier ("pitchnames");
1666 parser->lexer_->push_chord_state (nn);
1667 $$ = ly_symbol2scm ("chords");
1671 { parser->lexer_->push_lyric_state ();
1672 $$ = ly_symbol2scm ("lyrics");
1676 mode_changing_head_with_context:
1678 SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
1679 parser->lexer_->push_note_state (nn);
1681 $$ = ly_symbol2scm ("DrumStaff");
1684 parser->lexer_->push_figuredbass_state ();
1686 $$ = ly_symbol2scm ("FiguredBass");
1689 SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
1690 parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
1691 nn = parser->lexer_->lookup_identifier ("pitchnames");
1692 parser->lexer_->push_chord_state (nn);
1693 $$ = ly_symbol2scm ("ChordNames");
1696 { parser->lexer_->push_lyric_state ();
1697 $$ = ly_symbol2scm ("Lyrics");
1702 ADDLYRICS { parser->lexer_->push_lyric_state (); }
1705 /* Can also use music at the expensive of two S/Rs similar to
1706 \repeat \alternative */
1707 parser->lexer_->pop_state ();
1709 $$ = scm_cons ($3, SCM_EOL);
1711 | new_lyrics ADDLYRICS {
1712 parser->lexer_->push_lyric_state ();
1714 parser->lexer_->pop_state ();
1715 $$ = scm_cons ($4, $1);
1720 composite_music new_lyrics {
1721 $$ = MAKE_SYNTAX ("add-lyrics", @$, $1, scm_reverse_x ($2, SCM_EOL));
1723 | LYRICSTO simple_string {
1724 parser->lexer_->push_lyric_state ();
1726 parser->lexer_->pop_state ();
1727 $$ = MAKE_SYNTAX ("lyric-combine", @$, $2, $4);
1732 CHANGE STRING '=' STRING {
1733 $$ = MAKE_SYNTAX ("context-change", @$, scm_string_to_symbol ($2), $4);
1738 property_path_revved:
1739 embedded_scm_closed {
1740 $$ = scm_cons ($1, SCM_EOL);
1742 | property_path_revved embedded_scm_closed {
1743 $$ = scm_cons ($2, $1);
1748 property_path_revved {
1749 $$ = scm_reverse_x ($1, SCM_EOL);
1755 $$ = scm_list_3 (ly_symbol2scm ("assign"),
1756 scm_string_to_symbol ($1), $3);
1758 | UNSET simple_string {
1759 $$ = scm_list_2 (ly_symbol2scm ("unset"),
1760 scm_string_to_symbol ($2));
1762 | OVERRIDE simple_string property_path '=' scalar {
1763 $$ = scm_append (scm_list_2 (scm_list_3 (ly_symbol2scm ("push"),
1764 scm_string_to_symbol ($2), $5),
1767 | REVERT simple_string embedded_scm {
1768 $$ = scm_list_3 (ly_symbol2scm ("pop"),
1769 scm_string_to_symbol ($2), $3);
1774 CONSISTS { $$ = ly_symbol2scm ("consists"); }
1775 | REMOVE { $$ = ly_symbol2scm ("remove"); }
1777 | ACCEPTS { $$ = ly_symbol2scm ("accepts"); }
1778 | DEFAULTCHILD { $$ = ly_symbol2scm ("default-child"); }
1779 | DENIES { $$ = ly_symbol2scm ("denies"); }
1781 | ALIAS { $$ = ly_symbol2scm ("alias"); }
1782 | TYPE { $$ = ly_symbol2scm ("translator-type"); }
1783 | DESCRIPTION { $$ = ly_symbol2scm ("description"); }
1784 | NAME { $$ = ly_symbol2scm ("context-name"); }
1788 property_operation { $$ = $1; }
1789 | context_def_mod STRING {
1790 $$ = scm_list_2 ($1, $2);
1792 | context_def_mod embedded_scm
1794 if (!scm_is_string ($2)
1795 && ly_symbol2scm ("consists") != $1
1796 && ly_symbol2scm ("remove") != $1)
1799 parser->parser_error (@1, _ ("only \\consists and \\remove take non-string argument."));
1803 $$ = scm_list_2 ($1, $2);
1810 if (!is_regular_identifier ($1))
1812 @$.error (_("Grob name should be alphanumeric"));
1815 $$ = scm_list_2 (ly_symbol2scm ("Bottom"),
1816 scm_string_to_symbol ($1));
1818 | simple_string '.' simple_string {
1819 $$ = scm_list_2 (scm_string_to_symbol ($1),
1820 scm_string_to_symbol ($3));
1824 simple_music_property_def:
1825 OVERRIDE context_prop_spec property_path '=' scalar {
1826 $$ = scm_append (scm_list_2 (scm_list_n (scm_car ($2),
1827 ly_symbol2scm ("OverrideProperty"),
1832 | REVERT context_prop_spec embedded_scm {
1833 $$ = scm_list_4 (scm_car ($2),
1834 ly_symbol2scm ("RevertProperty"),
1838 | SET context_prop_spec '=' scalar {
1839 $$ = scm_list_4 (scm_car ($2),
1840 ly_symbol2scm ("PropertySet"),
1844 | UNSET context_prop_spec {
1845 $$ = scm_list_3 (scm_car ($2),
1846 ly_symbol2scm ("PropertyUnset"),
1852 simple_music_property_def {
1853 $$ = LOWLEVEL_MAKE_SYNTAX (ly_lily_module_constant ("property-operation"), scm_cons2 (parser->self_scm (), make_input (@$), $1));
1861 | STRING_IDENTIFIER {
1864 | string '+' string {
1865 $$ = scm_string_append (scm_list_2 ($1, $3));
1869 simple_string: STRING {
1875 | STRING_IDENTIFIER {
1888 embedded_scm_arg_closed
1896 simple_element post_events {
1897 // Let the rhythmic music iterator sort this mess out.
1898 if (scm_is_pair ($2)) {
1899 if (unsmob_pitch ($1)) {
1900 Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
1901 n->set_property ("pitch", $1);
1902 n->set_property ("duration",
1903 parser->default_duration_.smobbed_copy ());
1904 $$ = n->unprotect ();
1906 unsmob_music ($$)->set_property ("articulations",
1907 scm_reverse_x ($2, SCM_EOL));
1910 | simple_chord_elements post_events {
1911 SCM elts = ly_append2 ($1, scm_reverse_x ($2, SCM_EOL));
1914 /* why is this giving wrong start location? -ns
1916 i.set_location (@1, @2);
1917 $$ = MAKE_SYNTAX ("event-chord", i, elts);
1919 | CHORD_REPETITION optional_notemode_duration post_events {
1921 i.set_location (@1, @3);
1922 $$ = MAKE_SYNTAX ("repetition-chord", i,
1923 $2, scm_reverse_x ($3, SCM_EOL));
1925 | MULTI_MEASURE_REST optional_notemode_duration post_events {
1927 i.set_location (@1, @3);
1928 $$ = MAKE_SYNTAX ("multi-measure-rest", i, $2,
1929 scm_reverse_x ($3, SCM_EOL));
1932 | note_chord_element
1937 chord_body optional_notemode_duration post_events
1939 Music *m = unsmob_music ($1);
1940 SCM dur = unsmob_duration ($2)->smobbed_copy ();
1941 SCM es = m->get_property ("elements");
1942 SCM postevs = scm_reverse_x ($3, SCM_EOL);
1944 for (SCM s = es; scm_is_pair (s); s = scm_cdr (s))
1945 unsmob_music (scm_car (s))->set_property ("duration", dur);
1946 es = ly_append2 (es, postevs);
1948 m-> set_property ("elements", es);
1950 $$ = m->self_scm ();
1955 ANGLE_OPEN chord_body_elements ANGLE_CLOSE
1957 $$ = MAKE_SYNTAX ("event-chord", @$, scm_reverse_x ($2, SCM_EOL));
1961 chord_body_elements:
1962 /* empty */ { $$ = SCM_EOL; }
1963 | chord_body_elements chord_body_element {
1964 if (!SCM_UNBNDP ($2))
1965 $$ = scm_cons ($2, $1);
1970 pitch exclamations questions octave_check post_events
1972 bool q = to_boolean ($3);
1973 bool ex = to_boolean ($2);
1977 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1978 n->set_property ("pitch", $1);
1980 n->set_property ("cautionary", SCM_BOOL_T);
1982 n->set_property ("force-accidental", SCM_BOOL_T);
1984 if (scm_is_pair (post)) {
1985 SCM arts = scm_reverse_x (post, SCM_EOL);
1986 n->set_property ("articulations", arts);
1988 if (scm_is_number (check))
1990 int q = scm_to_int (check);
1991 n->set_property ("absolute-octave", scm_from_int (q-1));
1994 $$ = n->unprotect ();
1996 | DRUM_PITCH post_events {
1997 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
1998 n->set_property ("drum-type", $1);
2000 if (scm_is_pair ($2)) {
2001 SCM arts = scm_reverse_x ($2, SCM_EOL);
2002 n->set_property ("articulations", arts);
2004 $$ = n->unprotect ();
2006 | music_function_chord_body
2008 Music *m = unsmob_music ($1);
2010 while (m && m->is_mus_type ("music-wrapper-music")) {
2011 $$ = m->get_property ("element");
2012 m = unsmob_music ($$);
2015 if (!(m && m->is_mus_type ("rhythmic-event"))) {
2016 parser->parser_error (@$, _ ("not a rhythmic event"));
2022 music_function_chord_body:
2027 // Event functions may only take closed arglists, otherwise it would
2028 // not be clear whether a following postevent should be associated
2029 // with the last argument of the event function or with the expression
2030 // for which the function call acts itself as event.
2032 music_function_event:
2033 MUSIC_FUNCTION function_arglist_closed {
2034 $$ = MAKE_SYNTAX ("music-function", @$,
2039 event_function_event:
2040 EVENT_FUNCTION function_arglist_closed {
2041 $$ = MAKE_SYNTAX ("music-function", @$,
2051 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2052 m->set_property ("span-direction", scm_from_int (START));
2053 $$ = m->unprotect();
2056 Music *m = MY_MAKE_MUSIC ("LigatureEvent", @$);
2057 m->set_property ("span-direction", scm_from_int (STOP));
2058 $$ = m->unprotect ();
2061 $$ = MAKE_SYNTAX ("voice-separator", @$);
2064 SCM pipe = parser->lexer_->lookup_identifier ("pipeSymbol");
2066 Music *m = unsmob_music (pipe);
2071 $$ = m->unprotect ();
2074 $$ = MAKE_SYNTAX ("bar-check", @$);
2081 $$ = MY_MAKE_MUSIC ("PesOrFlexaEvent", @$)->unprotect ();
2093 | post_events post_event {
2094 unsmob_music ($2)->set_spot (@2);
2095 $$ = scm_cons ($2, $$);
2099 post_event_nofinger:
2100 direction_less_event {
2103 | script_dir music_function_event {
2105 if (!SCM_UNBNDP ($1))
2107 unsmob_music ($$)->set_property ("direction", $1);
2111 if (!parser->lexer_->is_lyric_state ())
2112 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2113 $$ = MY_MAKE_MUSIC ("HyphenEvent", @$)->unprotect ();
2116 if (!parser->lexer_->is_lyric_state ())
2117 parser->parser_error (@1, _ ("have to be in Lyric mode for lyrics"));
2118 $$ = MY_MAKE_MUSIC ("ExtenderEvent", @$)->unprotect ();
2120 | script_dir direction_reqd_event {
2121 if (!SCM_UNBNDP ($1))
2123 Music *m = unsmob_music ($2);
2124 m->set_property ("direction", $1);
2128 | script_dir direction_less_event {
2129 if (!SCM_UNBNDP ($1))
2131 Music *m = unsmob_music ($2);
2132 m->set_property ("direction", $1);
2139 unsmob_music ($$)->set_property ("direction", scm_from_int (UP));
2144 unsmob_music ($$)->set_property ("direction", scm_from_int (DOWN));
2155 string_number_event:
2157 Music *s = MY_MAKE_MUSIC ("StringNumberEvent", @$);
2158 s->set_property ("string-number", $1);
2159 $$ = s->unprotect ();
2163 direction_less_char:
2165 $$ = ly_symbol2scm ("bracketOpenSymbol");
2168 $$ = ly_symbol2scm ("bracketCloseSymbol");
2171 $$ = ly_symbol2scm ("tildeSymbol");
2174 $$ = ly_symbol2scm ("parenthesisOpenSymbol");
2177 $$ = ly_symbol2scm ("parenthesisCloseSymbol");
2180 $$ = ly_symbol2scm ("escapedExclamationSymbol");
2183 $$ = ly_symbol2scm ("escapedParenthesisOpenSymbol");
2186 $$ = ly_symbol2scm ("escapedParenthesisCloseSymbol");
2189 $$ = ly_symbol2scm ("escapedBiggerSymbol");
2192 $$ = ly_symbol2scm ("escapedSmallerSymbol");
2196 direction_less_event:
2197 direction_less_char {
2198 SCM predefd = parser->lexer_->lookup_identifier_symbol ($1);
2200 if (unsmob_music (predefd))
2202 m = unsmob_music (predefd)->clone ();
2207 m = MY_MAKE_MUSIC ("Music", @$);
2209 $$ = m->unprotect ();
2211 | string_number_event
2212 | EVENT_IDENTIFIER {
2216 Music *a = MY_MAKE_MUSIC ("TremoloEvent", @$);
2217 a->set_property ("tremolo-type", $1);
2218 $$ = a->unprotect ();
2220 | event_function_event
2223 direction_reqd_event:
2227 | script_abbreviation {
2228 SCM s = parser->lexer_->lookup_identifier ("dash" + ly_scm2string ($1));
2229 Music *a = MY_MAKE_MUSIC ("ArticulationEvent", @$);
2230 if (scm_is_string (s))
2231 a->set_property ("articulation-type", s);
2232 else parser->parser_error (@1, _ ("expecting string as script definition"));
2233 $$ = a->unprotect ();
2238 /**/ { $$ = SCM_EOL; }
2239 | '=' quotes { $$ = $2; }
2253 $$ = scm_from_int (1);
2256 $$ = scm_oneplus ($1);
2262 $$ = scm_from_int (-1);
2265 $$ = scm_oneminus ($1);
2270 NOTENAME_PITCH quotes {
2271 if (!scm_is_eq (SCM_INUM0, $2))
2273 Pitch p = *unsmob_pitch ($1);
2274 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2275 $$ = p.smobbed_copy ();
2285 TONICNAME_PITCH quotes {
2286 if (!scm_is_eq (SCM_INUM0, $2))
2288 Pitch p = *unsmob_pitch ($1);
2289 p = p.transposed (Pitch (scm_to_int ($2),0,0));
2290 $$ = p.smobbed_copy ();
2300 pitch_also_in_chords:
2307 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2308 t->set_property ("text", $1);
2309 $$ = t->unprotect ();
2312 Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
2313 t->set_property ("text",
2314 make_simple_markup ($1));
2315 $$ = t->unprotect ();
2321 Music *t = MY_MAKE_MUSIC ("FingeringEvent", @$);
2322 t->set_property ("digit", $1);
2323 $$ = t->unprotect ();
2327 script_abbreviation:
2329 $$ = scm_from_locale_string ("Hat");
2332 $$ = scm_from_locale_string ("Plus");
2335 $$ = scm_from_locale_string ("Dash");
2338 $$ = scm_from_locale_string ("Bar");
2341 $$ = scm_from_locale_string ("Larger");
2344 $$ = scm_from_locale_string ("Dot");
2347 $$ = scm_from_locale_string ("Underscore");
2352 '_' { $$ = scm_from_int (DOWN); }
2353 | '^' { $$ = scm_from_int (UP); }
2354 | '-' { $$ = SCM_UNDEFINED; }
2358 multiplied_duration {
2363 maybe_notemode_duration:
2367 | multiplied_duration {
2369 parser->default_duration_ = *unsmob_duration ($$);
2374 optional_notemode_duration:
2375 maybe_notemode_duration
2377 if (SCM_UNBNDP ($$))
2378 $$ = parser->default_duration_.smobbed_copy ();
2385 int n = scm_to_int ($1);
2386 if (!is_duration (n))
2387 parser->parser_error (@1, _f ("not a duration: %d", n));
2391 $$ = Duration (len, scm_to_int ($2)).smobbed_copy ();
2393 | DURATION_IDENTIFIER dots {
2394 Duration *d = unsmob_duration ($1);
2395 Duration k (d->duration_log (),
2396 d->dot_count () + scm_to_int ($2));
2397 k = k.compressed (d->factor ());
2398 scm_remember_upto_here_1 ($1);
2399 $$ = k.smobbed_copy ();
2403 multiplied_duration:
2407 | multiplied_duration '*' UNSIGNED {
2408 $$ = unsmob_duration ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
2410 | multiplied_duration '*' FRACTION {
2411 Rational m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
2413 $$ = unsmob_duration ($$)->compressed (m).smobbed_copy ();
2422 $$ = scm_oneplus ($1);
2431 int n = scm_to_int ($2);
2432 if (!is_duration (n))
2433 parser->parser_error (@2, _f ("not a duration: %d", n));
2439 UNSIGNED { $$ = $1; }
2440 | STRING { $$ = $1; }
2441 | full_markup { $$ = $1; }
2444 figured_bass_alteration:
2445 '-' { $$ = ly_rational2scm (FLAT_ALTERATION); }
2446 | '+' { $$ = ly_rational2scm (SHARP_ALTERATION); }
2447 | '!' { $$ = scm_from_int (0); }
2452 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2453 $$ = bfr->unprotect ();
2456 Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent", @$);
2457 $$ = bfr->self_scm ();
2459 if (scm_is_number ($1))
2460 bfr->set_property ("figure", $1);
2461 else if (Text_interface::is_markup ($1))
2462 bfr->set_property ("text", $1);
2468 unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
2470 | bass_figure figured_bass_alteration {
2471 Music *m = unsmob_music ($1);
2472 if (scm_to_double ($2)) {
2473 SCM salter = m->get_property ("alteration");
2474 SCM alter = scm_is_number (salter) ? salter : scm_from_int (0);
2475 m->set_property ("alteration",
2476 scm_sum (alter, $2));
2478 m->set_property ("alteration", scm_from_int (0));
2481 | bass_figure figured_bass_modification {
2482 Music *m = unsmob_music ($1);
2483 if ($2 == ly_symbol2scm ("plus"))
2485 m->set_property ("augmented", SCM_BOOL_T);
2487 else if ($2 == ly_symbol2scm ("slash"))
2489 m->set_property ("diminished", SCM_BOOL_T);
2491 else if ($2 == ly_symbol2scm ("exclamation"))
2493 m->set_property ("no-continuation", SCM_BOOL_T);
2495 else if ($2 == ly_symbol2scm ("backslash"))
2497 m->set_property ("augmented-slash", SCM_BOOL_T);
2503 figured_bass_modification:
2505 $$ = ly_symbol2scm ("plus");
2508 $$ = ly_symbol2scm ("exclamation");
2511 $$ = ly_symbol2scm ("slash");
2514 $$ = ly_symbol2scm ("backslash");
2524 unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
2532 | figure_list br_bass_figure {
2533 $$ = scm_cons ($2, $1);
2538 FIGURE_OPEN figure_list FIGURE_CLOSE {
2539 $$ = scm_reverse_x ($2, SCM_EOL);
2545 /**/ { $$ = SCM_BOOL_F; }
2546 | REST { $$ = SCM_BOOL_T; }
2550 pitch exclamations questions octave_check maybe_notemode_duration optional_rest {
2551 if (!parser->lexer_->is_note_state ())
2552 parser->parser_error (@1, _ ("have to be in Note mode for notes"));
2553 if (!SCM_UNBNDP ($2)
2555 || scm_is_number ($4)
2557 || scm_is_true ($6))
2560 if (scm_is_true ($6))
2561 n = MY_MAKE_MUSIC ("RestEvent", @$);
2563 n = MY_MAKE_MUSIC ("NoteEvent", @$);
2565 n->set_property ("pitch", $1);
2566 if (SCM_UNBNDP ($5))
2567 n->set_property ("duration",
2568 parser->default_duration_.smobbed_copy ());
2570 n->set_property ("duration", $5);
2572 if (scm_is_number ($4))
2574 int q = scm_to_int ($4);
2575 n->set_property ("absolute-octave", scm_from_int (q-1));
2578 if (to_boolean ($3))
2579 n->set_property ("cautionary", SCM_BOOL_T);
2580 if (to_boolean ($2) || to_boolean ($3))
2581 n->set_property ("force-accidental", SCM_BOOL_T);
2583 $$ = n->unprotect ();
2586 | DRUM_PITCH optional_notemode_duration {
2587 Music *n = MY_MAKE_MUSIC ("NoteEvent", @$);
2588 n->set_property ("duration", $2);
2589 n->set_property ("drum-type", $1);
2591 $$ = n->unprotect ();
2593 | RESTNAME optional_notemode_duration {
2595 if (ly_scm2string ($1) == "s") {
2597 ev = MY_MAKE_MUSIC ("SkipEvent", @$);
2600 ev = MY_MAKE_MUSIC ("RestEvent", @$);
2603 ev->set_property ("duration", $2);
2604 $$ = ev->unprotect ();
2608 simple_chord_elements:
2610 if (!parser->lexer_->is_chord_state ())
2611 parser->parser_error (@1, _ ("have to be in Chord mode for chords"));
2614 | figure_spec optional_notemode_duration {
2615 for (SCM s = $1; scm_is_pair (s); s = scm_cdr (s))
2617 unsmob_music (scm_car (s))->set_property ("duration", $2);
2634 | lyric_element multiplied_duration post_events {
2635 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2636 if (scm_is_pair ($3))
2637 unsmob_music ($$)->set_property
2638 ("articulations", scm_reverse_x ($3, SCM_EOL));
2640 | lyric_element post_event post_events {
2641 $$ = MAKE_SYNTAX ("lyric-event", @$, $1,
2642 parser->default_duration_.smobbed_copy ());
2643 unsmob_music ($$)->set_property
2644 ("articulations", scm_cons ($2, scm_reverse_x ($3, SCM_EOL)));
2646 | LYRIC_ELEMENT optional_notemode_duration post_events {
2647 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2648 if (scm_is_pair ($3))
2649 unsmob_music ($$)->set_property
2650 ("articulations", scm_reverse_x ($3, SCM_EOL));
2655 lyric_element_music:
2656 lyric_element optional_notemode_duration post_events {
2657 $$ = MAKE_SYNTAX ("lyric-event", @$, $1, $2);
2658 if (scm_is_pair ($3))
2659 unsmob_music ($$)->set_property
2660 ("articulations", scm_reverse_x ($3, SCM_EOL));
2665 steno_tonic_pitch optional_notemode_duration {
2666 $$ = make_chord_elements (@$, $1, $2, SCM_EOL);
2668 | steno_tonic_pitch optional_notemode_duration chord_separator chord_items {
2669 SCM its = scm_reverse_x ($4, SCM_EOL);
2670 $$ = make_chord_elements (@$, $1, $2, scm_cons ($3, its));
2678 | chord_items chord_item {
2679 $$ = scm_cons ($2, $$);
2685 $$ = ly_symbol2scm ("chord-colon");
2688 $$ = ly_symbol2scm ("chord-caret");
2690 | CHORD_SLASH steno_tonic_pitch {
2691 $$ = scm_list_2 (ly_symbol2scm ("chord-slash"), $2);
2693 | CHORD_BASS steno_tonic_pitch {
2694 $$ = scm_list_2 (ly_symbol2scm ("chord-bass"), $2);
2703 $$ = scm_reverse_x ($1, SCM_EOL);
2711 step_number { $$ = scm_cons ($1, SCM_EOL); }
2712 | step_numbers '.' step_number {
2713 $$ = scm_cons ($3, $$);
2719 $$ = make_chord_step ($1, 0);
2722 $$ = make_chord_step ($1, SHARP_ALTERATION);
2724 | UNSIGNED CHORD_MINUS {
2725 $$ = make_chord_step ($1, FLAT_ALTERATION);
2733 | UNSIGNED '~' UNSIGNED {
2734 $$ = scm_cons ($1, $3);
2741 TODO: should deprecate in favor of Scheme?
2745 number_expression '+' number_term {
2746 $$ = scm_sum ($1, $3);
2748 | number_expression '-' number_term {
2749 $$ = scm_difference ($1, $3);
2758 | number_factor '*' number_factor {
2759 $$ = scm_product ($1, $3);
2761 | number_factor '/' number_factor {
2762 $$ = scm_divide ($1, $3);
2767 '-' number_factor { /* %prec UNARY_MINUS */
2768 $$ = scm_difference ($2, SCM_UNDEFINED);
2776 | UNSIGNED NUMBER_IDENTIFIER {
2777 $$ = scm_product ($1, $2);
2779 | REAL NUMBER_IDENTIFIER {
2780 $$ = scm_product ($1, $2);
2796 { $$ = SCM_UNDEFINED; }
2799 if (SCM_UNBNDP ($1))
2807 { $$ = SCM_UNDEFINED; }
2810 if (SCM_UNBNDP ($1))
2818 This should be done more dynamically if possible.
2822 LYRIC_MARKUP_IDENTIFIER {
2826 { parser->lexer_->push_markup_state (); }
2829 parser->lexer_->pop_state ();
2834 MARKUPLIST_IDENTIFIER {
2838 { parser->lexer_->push_markup_state (); }
2841 parser->lexer_->pop_state ();
2850 { parser->lexer_->push_markup_state (); }
2853 parser->lexer_->pop_state ();
2859 $$ = scm_list_2 (ly_lily_module_constant ("line-markup"), $1);
2861 | markup_head_1_list simple_markup {
2862 $$ = scm_car (scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, scm_list_1 ($2)));
2872 if (Text_interface::is_markup ($1))
2873 MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
2874 else if (Text_interface::is_markup_list ($1))
2875 MYBACKUP (MARKUPLIST_IDENTIFIER, $1, @1);
2877 parser->parser_error (@1, _ ("not a markup"));
2878 MYBACKUP (MARKUP_IDENTIFIER, scm_string (SCM_EOL), @1);
2885 MARKUPLIST_IDENTIFIER {
2888 | markup_composed_list {
2891 | markup_braced_list {
2894 | markup_command_list {
2895 $$ = scm_list_1 ($1);
2897 | markup_scm MARKUPLIST_IDENTIFIER
2903 markup_composed_list:
2904 markup_head_1_list markup_braced_list {
2905 $$ = scm_call_2 (ly_lily_module_constant ("map-markup-command-list"), $1, $2);
2911 '{' markup_braced_list_body '}' {
2912 $$ = scm_reverse_x ($2, SCM_EOL);
2916 markup_braced_list_body:
2917 /* empty */ { $$ = SCM_EOL; }
2918 | markup_braced_list_body markup {
2919 $$ = scm_cons ($2, $1);
2921 | markup_braced_list_body markup_list {
2922 $$ = scm_reverse_x ($2, $1);
2926 markup_command_list:
2927 MARKUP_LIST_FUNCTION markup_command_list_arguments {
2928 $$ = scm_cons ($1, scm_reverse_x($2, SCM_EOL));
2932 markup_command_basic_arguments:
2933 EXPECT_MARKUP_LIST markup_command_list_arguments markup_list {
2934 $$ = scm_cons ($3, $2);
2936 | EXPECT_SCM markup_command_list_arguments embedded_scm_closed {
2937 $$ = check_scheme_arg (parser, @3, $3, $2, $1);
2939 | EXPECT_NO_MORE_ARGS {
2944 markup_command_list_arguments:
2945 markup_command_basic_arguments { $$ = $1; }
2946 | EXPECT_MARKUP markup_command_list_arguments markup {
2947 $$ = scm_cons ($3, $2);
2952 MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
2953 $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
2958 markup_head_1_item {
2959 $$ = scm_list_1 ($1);
2961 | markup_head_1_list markup_head_1_item {
2962 $$ = scm_cons ($2, $1);
2968 $$ = make_simple_markup ($1);
2970 | MARKUP_IDENTIFIER {
2973 | LYRIC_MARKUP_IDENTIFIER {
2976 | STRING_IDENTIFIER {
2980 SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
2981 parser->lexer_->push_note_state (nn);
2982 } '{' score_body '}' {
2983 $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), $4);
2984 parser->lexer_->pop_state ();
2986 | MARKUP_FUNCTION markup_command_basic_arguments {
2987 $$ = scm_cons ($1, scm_reverse_x ($2, SCM_EOL));
2989 | markup_scm MARKUP_IDENTIFIER
2996 markup_head_1_list simple_markup {
2997 SCM mapper = ly_lily_module_constant ("map-markup-command-list");
2998 $$ = scm_car (scm_call_2 (mapper, $1, scm_list_1 ($2)));
3008 Lily_parser::set_yydebug (bool x)
3014 Lily_parser::do_yyparse ()
3016 SCM retval = SCM_UNDEFINED;
3017 yyparse (this, &retval);
3027 It is a little strange to have this function in this file, but
3028 otherwise, we have to import music classes into the lexer.
3032 Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
3034 if (scm_is_string (sid)) {
3036 return STRING_IDENTIFIER;
3037 } else if (unsmob_book (sid)) {
3038 Book *book = unsmob_book (sid)->clone ();
3039 *destination = book->self_scm ();
3042 return BOOK_IDENTIFIER;
3043 } else if (scm_is_number (sid)) {
3045 return NUMBER_IDENTIFIER;
3046 } else if (unsmob_context_def (sid)) {
3047 Context_def *def= unsmob_context_def (sid)->clone ();
3049 *destination = def->self_scm ();
3052 return CONTEXT_DEF_IDENTIFIER;
3053 } else if (unsmob_context_mod (sid)) {
3054 *destination = unsmob_context_mod (sid)->smobbed_copy ();
3056 return CONTEXT_MOD_IDENTIFIER;
3057 } else if (unsmob_score (sid)) {
3058 Score *score = new Score (*unsmob_score (sid));
3059 *destination = score->self_scm ();
3061 score->unprotect ();
3062 return SCORE_IDENTIFIER;
3063 } else if (Music *mus = unsmob_music (sid)) {
3064 mus = mus->clone ();
3065 *destination = mus->self_scm ();
3066 unsmob_music (*destination)->
3067 set_property ("origin", make_input (last_input_));
3069 bool is_event = mus->is_mus_type ("post-event");
3071 return is_event ? EVENT_IDENTIFIER : MUSIC_IDENTIFIER;
3072 } else if (unsmob_pitch (sid)) {
3073 *destination = unsmob_pitch (sid)->smobbed_copy ();
3074 return PITCH_IDENTIFIER;
3075 } else if (unsmob_duration (sid)) {
3076 *destination = unsmob_duration (sid)->smobbed_copy ();
3077 return DURATION_IDENTIFIER;
3078 } else if (unsmob_output_def (sid)) {
3079 Output_def *p = unsmob_output_def (sid);
3082 *destination = p->self_scm ();
3084 return OUTPUT_DEF_IDENTIFIER;
3085 } else if (Text_interface::is_markup (sid)) {
3087 if (is_lyric_state ())
3088 return LYRIC_MARKUP_IDENTIFIER;
3089 return MARKUP_IDENTIFIER;
3090 } else if (Text_interface::is_markup_list (sid)) {
3092 return MARKUPLIST_IDENTIFIER;
3099 get_next_unique_context_id ()
3101 return scm_from_locale_string ("$uniqueContextId");
3106 get_next_unique_lyrics_context_id ()
3108 static int new_context_count;
3110 snprintf (s, sizeof (s)-1, "uniqueContext%d", new_context_count++);
3111 return scm_from_locale_string (s);
3114 SCM check_scheme_arg (Lily_parser *parser, Input loc,
3115 SCM arg, SCM args, SCM pred)
3117 args = scm_cons (arg, args);
3118 if (scm_is_true (scm_call_1 (pred, arg)))
3120 scm_set_cdr_x (scm_last_pair (args), SCM_EOL);
3121 MAKE_SYNTAX ("argument-error", loc, scm_length (args), pred, arg);
3122 scm_set_cdr_x (scm_last_pair (args), SCM_BOOL_F);
3126 SCM loc_on_music (Input loc, SCM arg)
3128 if (Music *m = unsmob_music (arg))
3132 return m->unprotect ();
3138 is_regular_identifier (SCM id)
3140 string str = ly_scm2string (id);
3141 char const *s = str.c_str ();
3150 v = v && isalnum (*s);
3157 make_music_with_input (SCM name, Input where)
3159 Music *m = make_music_by_name (name);
3160 m->set_spot (where);
3165 make_simple_markup (SCM a)
3173 return t && t == 1 << intlog2 (t);
3177 set_music_properties (Music *p, SCM a)
3179 for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
3180 p->set_property (scm_caar (k), scm_cdar (k));
3185 make_chord_step (SCM step_scm, Rational alter)
3187 int step = scm_to_int (step_scm);
3190 alter += FLAT_ALTERATION;
3194 Pitch m ((step -1) / 7, (step - 1) % 7, alter);
3195 return m.smobbed_copy ();
3200 make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list)
3202 SCM chord_ctor = ly_lily_module_constant ("construct-chord-elements");
3203 SCM res = scm_call_3 (chord_ctor, pitch, dur, modification_list);
3204 for (SCM s = res; scm_is_pair (s); s = scm_cdr (s))
3206 unsmob_music (scm_car (s))->set_spot (loc);
3212 yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser)
3214 Lily_lexer *lex = parser->lexer_;
3218 lex->prepare_for_next_token ();
3219 return lex->yylex ();